EclGenericProblem: add serialization support

This commit is contained in:
Arne Morten Kvarving 2023-02-01 15:55:55 +01:00
parent d86956d6d7
commit 1bec857445
3 changed files with 108 additions and 0 deletions

View File

@ -104,6 +104,37 @@ EclGenericProblem(const EclipseState& eclState,
{
}
template<class GridView, class FluidSystem, class Scalar>
EclGenericProblem<GridView,FluidSystem,Scalar>
EclGenericProblem<GridView,FluidSystem,Scalar>::
serializationTestObject(const EclipseState& eclState,
const Schedule& schedule,
const GridView& gridView)
{
EclGenericProblem result(eclState, schedule, gridView);
result.maxOilSaturation_ = {1.0, 2.0};
result.maxPolymerAdsorption_ = {3.0, 4.0, 5.0};
result.maxWaterSaturation_ = {6.0};
result.minOilPressure_ = {7.0, 8.0, 9.0, 10.0};
result.overburdenPressure_ = {11.0};
result.polymerConcentration_ = {12.0};
result.polymerMoleWeight_ = {13.0, 14.0};
result.solventSaturation_ = {15.0};
result.microbialConcentration_ = {16.0};
result.oxygenConcentration_ = {17.0};
result.ureaConcentration_ = {18.0};
result.biofilmConcentration_ = {19.0};
result.calciteConcentration_ = {20.0};
result.lastRv_ = {21.0};
result.maxDRv_ = {22.0, 23.0};
result.convectiveDrs_ = {24.0, 25.0, 26.0};
result.lastRs_ = {27.0};
result.maxDRs_ = {28.0};
result.dRsDtOnlyFreeGas_ = {false, true};
return result;
}
template<class GridView, class FluidSystem, class Scalar>
std::string
EclGenericProblem<GridView,FluidSystem,Scalar>::
@ -755,6 +786,31 @@ initDRSDT_(size_t numDof,
}
}
template<class GridView, class FluidSystem, class Scalar>
bool EclGenericProblem<GridView,FluidSystem,Scalar>::
operator==(const EclGenericProblem& rhs) const
{
return this->maxOilSaturation_ == rhs.maxOilSaturation_ &&
this->maxPolymerAdsorption_ == rhs.maxPolymerAdsorption_ &&
this->maxWaterSaturation_ == rhs.maxWaterSaturation_ &&
this->minOilPressure_ == rhs.minOilPressure_ &&
this->overburdenPressure_ == rhs.overburdenPressure_ &&
this->polymerConcentration_ == rhs.polymerConcentration_ &&
this->polymerMoleWeight_ == rhs.polymerMoleWeight_ &&
this->solventSaturation_ == rhs.solventSaturation_ &&
this->microbialConcentration_ == rhs.microbialConcentration_ &&
this->oxygenConcentration_ == rhs.oxygenConcentration_ &&
this->ureaConcentration_ == rhs.ureaConcentration_ &&
this->biofilmConcentration_ == rhs.biofilmConcentration_ &&
this->calciteConcentration_ == rhs.calciteConcentration_ &&
this->lastRv_ == rhs.lastRv_ &&
this->maxDRv_ == rhs.maxDRv_ &&
this->convectiveDrs_ == rhs.convectiveDrs_ &&
this->lastRs_ == rhs.lastRs_ &&
this->maxDRs_ == rhs.maxDRs_ &&
this->dRsDtOnlyFreeGas_ == rhs.dRsDtOnlyFreeGas_;
}
#if HAVE_DUNE_FEM
template class EclGenericProblem<Dune::GridView<Dune::Fem::GridPart2GridViewTraits<Dune::Fem::AdaptiveLeafGridPart<Dune::CpGrid, Dune::PartitionIteratorType(4), false>>>,
BlackOilFluidSystem<double,BlackOilDefaultIndexTraits>,

View File

@ -74,6 +74,11 @@ public:
const Schedule& schedule,
const GridView& gridView);
static EclGenericProblem serializationTestObject(const EclipseState& eclState,
const Schedule& schedule,
const GridView& gridView);
/*!
* \copydoc FvBaseProblem::helpPreamble
*/
@ -257,6 +262,32 @@ public:
bool vapparsActive(int episodeIdx) const;
bool operator==(const EclGenericProblem& rhs) const;
template<class Serializer>
void serializeOp(Serializer& serializer)
{
serializer(maxOilSaturation_);
serializer(maxPolymerAdsorption_);
serializer(maxWaterSaturation_);
serializer(minOilPressure_);
serializer(overburdenPressure_);
serializer(polymerConcentration_);
serializer(polymerMoleWeight_);
serializer(solventSaturation_);
serializer(microbialConcentration_);
serializer(oxygenConcentration_);
serializer(ureaConcentration_);
serializer(biofilmConcentration_);
serializer(calciteConcentration_);
serializer(lastRv_);
serializer(maxDRv_);
serializer(convectiveDrs_);
serializer(lastRs_);
serializer(maxDRs_);
serializer(dRsDtOnlyFreeGas_);
}
protected:
bool drsdtActive_(int episodeIdx) const;
bool drvdtActive_(int episodeIdx) const;

View File

@ -114,6 +114,26 @@ BOOST_AUTO_TEST_CASE(EclGenericVanguard)
BOOST_CHECK_MESSAGE(val1 == val2, "Deserialized EclGenericVanguard differ");
}
BOOST_AUTO_TEST_CASE(EclGenericProblem)
{
Opm::EclipseState eclState;
Opm::Schedule schedule;
Dune::CpGrid grid;
auto data_out = Opm::EclGenericProblem<Dune::GridView<Dune::DefaultLeafGridViewTraits<Dune::CpGrid>>,
Opm::BlackOilFluidSystem<double,Opm::BlackOilDefaultIndexTraits>,
double>::
serializationTestObject(eclState, schedule, grid.leafGridView());
Opm::Serialization::MemPacker packer;
Opm::Serializer ser(packer);
ser.pack(data_out);
const size_t pos1 = ser.position();
decltype(data_out) data_in(eclState, schedule, grid.leafGridView());
ser.unpack(data_in);
const size_t pos2 = ser.position();
BOOST_CHECK_MESSAGE(pos1 == pos2, "Packed size differ from unpack size for EclGenericProblem");
BOOST_CHECK_MESSAGE(data_out == data_in, "Deserialized EclGenericProblem differ");
}
bool init_unit_test_func()
{
return true;
@ -121,5 +141,6 @@ bool init_unit_test_func()
int main(int argc, char** argv)
{
Dune::MPIHelper::instance(argc, argv);
return boost::unit_test::unit_test_main(&init_unit_test_func, argc, argv);
}