SingleWellState: add serialization of dynamic state

This commit is contained in:
Arne Morten Kvarving 2023-02-02 11:52:08 +01:00
parent 70152b67ff
commit 60a5273d0e
3 changed files with 72 additions and 4 deletions

View File

@ -55,6 +55,12 @@ SingleWellState::SingleWellState(const std::string& name_,
}
}
SingleWellState SingleWellState::serializationTestObject(const ParallelWellInfo& pinfo)
{
SingleWellState result("testing", pinfo, true, 1.0, {}, PhaseUsage{}, 2.0);
return result;
}
void SingleWellState::init_timestep(const SingleWellState& other) {
if (this->producer != other.producer)
@ -276,9 +282,27 @@ void SingleWellState::update_targets(const Well& ecl_well, const SummaryState& s
this->update_injector_targets(ecl_well, st);
}
bool SingleWellState::operator==(const SingleWellState& rhs) const
{
return this->name == rhs.name &&
this->status == rhs.status &&
this->producer == rhs.producer &&
this->bhp == rhs.bhp &&
this->thp == rhs.thp &&
this->temperature == rhs.temperature &&
this->dissolved_gas_rate == rhs.dissolved_gas_rate &&
this->dissolved_gas_rate_in_water == rhs.dissolved_gas_rate_in_water &&
this->vaporized_oil_rate == rhs.vaporized_oil_rate &&
this->vaporized_wat_rate == rhs.vaporized_wat_rate &&
this->well_potentials == rhs.well_potentials &&
this->productivity_index == rhs.productivity_index &&
this->surface_rates == rhs.surface_rates &&
this->reservoir_rates == rhs.reservoir_rates &&
this->trivial_target == rhs.trivial_target &&
this->segments == rhs.segments &&
this->events == rhs.events &&
this->injection_cmode == rhs.injection_cmode &&
this->production_cmode == rhs.production_cmode;
}
}

View File

@ -47,6 +47,34 @@ public:
const PhaseUsage& pu,
double temp);
static SingleWellState serializationTestObject(const ParallelWellInfo& pinfo);
template<class Serializer>
void serializeOp(Serializer& serializer)
{
serializer(name);
serializer(status);
serializer(producer);
serializer(bhp);
serializer(thp);
serializer(temperature);
serializer(dissolved_gas_rate);
serializer(dissolved_gas_rate_in_water);
serializer(vaporized_oil_rate);
serializer(vaporized_wat_rate);
serializer(well_potentials);
serializer(productivity_index);
serializer(surface_rates);
serializer(reservoir_rates);
serializer(trivial_target);
serializer(segments);
serializer(events);
serializer(injection_cmode);
serializer(production_cmode);
}
bool operator==(const SingleWellState&) const;
std::string name;
std::reference_wrapper<const ParallelWellInfo> parallel_info;

View File

@ -36,6 +36,7 @@
#include <opm/simulators/timestepping/TimeStepControl.hpp>
#include <opm/simulators/utils/SerializationPackers.hpp>
#include <opm/simulators/wells/SegmentState.hpp>
#include <opm/simulators/wells/SingleWellState.hpp>
#define BOOST_TEST_MODULE TestRestartSerialization
#define BOOST_TEST_NO_MAIN
@ -96,6 +97,21 @@ namespace Opm {
}
TEST_FOR_TYPE_NAMED(BVec, BlockVectorWrapper)
BOOST_AUTO_TEST_CASE(SingleWellState)
{
Opm::ParallelWellInfo dummy;
auto data_out = Opm::SingleWellState::serializationTestObject(dummy);
Opm::Serialization::MemPacker packer;
Opm::Serializer ser(packer);
ser.pack(data_out);
const size_t pos1 = ser.position();
decltype(data_out) data_in("", dummy, false, 0.0, {}, Opm::PhaseUsage{}, 0.0);
ser.unpack(data_in);
const size_t pos2 = ser.position();
BOOST_CHECK_MESSAGE(pos1 == pos2, "Packed size differ from unpack size for SingleWellState");
BOOST_CHECK_MESSAGE(data_out == data_in, "Deserialized SingleWellState differ");
}
BOOST_AUTO_TEST_CASE(EclGenericVanguard)
{
auto in_params = Opm::EclGenericVanguard::serializationTestParams();