Merge pull request #4446 from akva2/blackoilwellmodel_serialize

BlackOilWellModel: add serialization support
This commit is contained in:
Bård Skaflestad 2023-02-16 11:55:56 +01:00 committed by GitHub
commit b5f186c6a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 133 additions and 0 deletions

View File

@ -177,6 +177,40 @@ public:
const std::size_t recursion_level,
const double network_imbalance) const;
template<class Serializer>
void serializeOp(Serializer& serializer)
{
serializer(initial_step_);
serializer(report_step_starts_);
serializer(last_run_wellpi_);
serializer(local_shut_wells_);
serializer(closed_this_step_);
serializer(guideRate_);
serializer(node_pressures_);
serializer(active_wgstate_);
serializer(last_valid_wgstate_);
serializer(nupcol_wgstate_);
serializer(last_glift_opt_time_);
serializer(switched_prod_groups_);
serializer(switched_inj_groups_);
}
bool operator==(const BlackoilWellModelGeneric& rhs) const
{
return this->initial_step_ == rhs.initial_step_ &&
this->report_step_starts_ == rhs.report_step_starts_ &&
this->last_run_wellpi_ == rhs.last_run_wellpi_ &&
this->local_shut_wells_ == rhs.local_shut_wells_ &&
this->closed_this_step_ == rhs.closed_this_step_ &&
this->node_pressures_ == rhs.node_pressures_ &&
this->active_wgstate_ == rhs.active_wgstate_ &&
this->last_valid_wgstate_ == rhs.last_valid_wgstate_ &&
this->nupcol_wgstate_ == rhs.nupcol_wgstate_ &&
this->last_glift_opt_time_ == rhs.last_glift_opt_time_ &&
this->switched_prod_groups_ == rhs.switched_prod_groups_ &&
this->switched_inj_groups_ == rhs.switched_inj_groups_;
}
protected:
/*

View File

@ -37,6 +37,7 @@
#include <opm/simulators/timestepping/TimeStepControl.hpp>
#include <opm/simulators/utils/SerializationPackers.hpp>
#include <opm/simulators/wells/ALQState.hpp>
#include <opm/simulators/wells/BlackoilWellModelGeneric.hpp>
#include <opm/simulators/wells/GroupState.hpp>
#include <opm/simulators/wells/SegmentState.hpp>
#include <opm/simulators/wells/SingleWellState.hpp>
@ -212,6 +213,104 @@ BOOST_AUTO_TEST_CASE(EclGenericProblem)
BOOST_CHECK_MESSAGE(data_out == data_in, "Deserialized EclGenericProblem differ");
}
namespace Opm {
class BlackoilWellModelGenericTest : public BlackoilWellModelGeneric
{
public:
BlackoilWellModelGenericTest(Schedule& schedule,
const SummaryState& summaryState,
const EclipseState& eclState,
const PhaseUsage& phase_usage,
const Parallel::Communication& comm,
bool deserialize)
: BlackoilWellModelGeneric(schedule, summaryState,
eclState, phase_usage, comm)
{
if (deserialize) {
active_wgstate_.well_state = WellState(dummy);
last_valid_wgstate_.well_state = WellState(dummy);
nupcol_wgstate_.well_state = WellState(dummy);
}
}
void setSerializationTestData()
{
initial_step_ = true;
report_step_starts_ = true;
last_run_wellpi_ = 1;
local_shut_wells_ = {2, 3};
closed_this_step_ = {"test1", "test2"};
guideRate_.setSerializationTestData();
node_pressures_ = {{"test3", 4.0}};
active_wgstate_ = WGState::serializationTestObject(dummy);
last_valid_wgstate_ = WGState::serializationTestObject(dummy);
nupcol_wgstate_ = WGState::serializationTestObject(dummy);
last_glift_opt_time_ = 5.0;
switched_prod_groups_ = {{"test4", "test5"}};
switched_inj_groups_ = {{{"test4", Phase::SOLVENT}, "test5"}};
}
void calcRates(const int, const int, std::vector<double>&) override
{}
void calcInjRates(const int, const int, std::vector<double>&) override
{}
void computePotentials(const std::size_t,
const WellState&,
std::string&,
ExceptionType::ExcEnum&,
DeferredLogger&) override
{}
void createWellContainer(const int) override
{}
void initWellContainer(const int) override
{}
void calculateProductivityIndexValuesShutWells(const int,
DeferredLogger&) override
{}
void calculateProductivityIndexValues(DeferredLogger&) override
{}
int compressedIndexForInterior(int) const override
{
return 0;
}
private:
ParallelWellInfo dummy;
};
}
BOOST_AUTO_TEST_CASE(BlackoilWellModelGeneric)
{
Opm::Schedule schedule{};
Opm::SummaryState summaryState{};
Opm::EclipseState eclState{};
Opm::PhaseUsage phase_usage{};
Opm::Parallel::Communication comm{};
Opm::BlackoilWellModelGenericTest data_out(schedule, summaryState,
eclState, phase_usage, comm, false);
data_out.setSerializationTestData();
Opm::Serialization::MemPacker packer;
Opm::Serializer ser(packer);
ser.pack(data_out);
const size_t pos1 = ser.position();
Opm::BlackoilWellModelGenericTest data_in(schedule, summaryState,
eclState, phase_usage, comm, true);
ser.unpack(data_in);
const size_t pos2 = ser.position();
BOOST_CHECK_MESSAGE(pos1 == pos2, "Packed size differ from unpack size for BlackoilWellModelGeneric");
BOOST_CHECK_MESSAGE(data_out == data_in, "Deserialized BlackoilWellModelGeneric differ");
}
template<class Grid, class GridView, class DofMapper, class Stencil, class Scalar>
class EclGenericTracerModelTest : public Opm::EclGenericTracerModel<Grid,GridView,DofMapper,Stencil,Scalar> {
using Base = Opm::EclGenericTracerModel<Grid,GridView,DofMapper,Stencil,Scalar>;