WellState: add serialization support

This commit is contained in:
Arne Morten Kvarving
2023-02-02 11:52:08 +01:00
parent f526e1a6ca
commit b7a531b93a
3 changed files with 69 additions and 7 deletions

View File

@@ -21,6 +21,8 @@
#ifndef OPM_WELLSTATEFULLYIMPLICITBLACKOIL_HEADER_INCLUDED
#define OPM_WELLSTATEFULLYIMPLICITBLACKOIL_HEADER_INCLUDED
#include <opm/common/ErrorMacros.hpp>
#include <opm/core/props/BlackoilPhases.hpp>
#include <opm/simulators/wells/ALQState.hpp>
@@ -58,18 +60,19 @@ class WellState
{
public:
static const uint64_t event_mask = ScheduleEvents::WELL_STATUS_CHANGE + ScheduleEvents::PRODUCTION_UPDATE + ScheduleEvents::INJECTION_UPDATE;
virtual ~WellState() = default;
// TODO: same definition with WellInterface, eventually they should go to a common header file.
static const int Water = BlackoilPhases::Aqua;
static const int Oil = BlackoilPhases::Liquid;
static const int Gas = BlackoilPhases::Vapour;
// Only usable for testing purposes
explicit WellState(const ParallelWellInfo& pinfo);
explicit WellState(const PhaseUsage& pu)
{
this->phase_usage_ = pu;
}
: phase_usage_(pu)
{}
static WellState serializationTestObject(const ParallelWellInfo& pinfo);
std::size_t size() const {
return this->wells_.size();
@@ -275,6 +278,27 @@ public:
return this->wells_.has(well_name);
}
bool operator==(const WellState&) const;
template<class Serializer>
void serializeOp(Serializer& serializer)
{
serializer(alq_state);
serializer(well_rates);
if (serializer.isSerializing()) {
serializer(wells_.size());
} else {
std::size_t size = 0;
serializer(size);
if (size != wells_.size()) {
OPM_THROW(std::runtime_error, "Error deserializing WellState: size mismatch");
}
}
for (auto& w : wells_) {
serializer(w);
}
}
private:
PhaseUsage phase_usage_;