From 24798e68d5923cdaf177d87d9dc36b8d0fa13403 Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Thu, 2 Feb 2023 11:52:08 +0100 Subject: [PATCH 1/2] EclGenericTracerModel: add serialization of dynamic state --- ebos/eclgenerictracermodel.hh | 7 +++ tests/test_RestartSerialization.cpp | 69 +++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+) diff --git a/ebos/eclgenerictracermodel.hh b/ebos/eclgenerictracermodel.hh index 867c2bd07..9ea7435be 100644 --- a/ebos/eclgenerictracermodel.hh +++ b/ebos/eclgenerictracermodel.hh @@ -78,6 +78,13 @@ public: const std::map, double>& getWellTracerRates() const {return wellTracerRate_;} + template + void serializeOp(Serializer& serializer) + { + serializer(tracerConcentration_); + serializer(wellTracerRate_); + } + protected: EclGenericTracerModel(const GridView& gridView, const EclipseState& eclState, diff --git a/tests/test_RestartSerialization.cpp b/tests/test_RestartSerialization.cpp index 5385938bf..f73e7c3c0 100644 --- a/tests/test_RestartSerialization.cpp +++ b/tests/test_RestartSerialization.cpp @@ -42,6 +42,8 @@ #include #include +#include + template std::tuple PackUnpack(T& in) { @@ -134,6 +136,73 @@ BOOST_AUTO_TEST_CASE(EclGenericProblem) BOOST_CHECK_MESSAGE(data_out == data_in, "Deserialized EclGenericProblem differ"); } +template +class EclGenericTracerModelTest : public Opm::EclGenericTracerModel { + using Base = Opm::EclGenericTracerModel; +public: + EclGenericTracerModelTest(const GridView& gridView, + const Opm::EclipseState& eclState, + const Dune::CartesianIndexMapper& cartMapper, + const DofMapper& dofMapper, + const std::function(int)> centroids) : + Base(gridView, eclState, cartMapper, dofMapper, centroids) + {} + + static EclGenericTracerModelTest + serializationTestObject(const GridView& gridView, + const Opm::EclipseState& eclState, + const Dune::CartesianIndexMapper& cartMapper, + const DofMapper& dofMapper, + const std::function(int)> centroids) + { + EclGenericTracerModelTest result(gridView, eclState, cartMapper, dofMapper, centroids); + result.tracerConcentration_ = {{1.0}, {2.0}, {3.0}}; + result.wellTracerRate_.insert({{"foo", "bar"}, 4.0}); + + return result; + } + + bool operator==(const EclGenericTracerModelTest& rhs) const + { + if (this->tracerConcentration_.size() != rhs.tracerConcentration_.size()) { + return false; + } + for (size_t i = 0; i < this->tracerConcentration_.size(); ++i) { + if (!std::equal(this->tracerConcentration_[i].begin(), + this->tracerConcentration_[i].end(), + rhs.tracerConcentration_[i].begin(), + rhs.tracerConcentration_[i].end())) { + return false; + } + } + return this->wellTracerRate_ == rhs.wellTracerRate_; + } +}; + +BOOST_AUTO_TEST_CASE(EclGenericTracerModel) +{ + Dune::CpGrid grid; + Opm::EclipseState eclState; + Dune::CartesianIndexMapper mapper(grid); + Dune::MultipleCodimMultipleGeomTypeMapper dofMapper(grid.leafGridView(), Dune::mcmgElementLayout()); + auto centroids = [](int) { return std::array{}; }; + auto data_out = EclGenericTracerModelTest>, + Dune::MultipleCodimMultipleGeomTypeMapper>>, + Opm::EcfvStencil>,false,false>, + double>::serializationTestObject(grid.leafGridView(), eclState, mapper, dofMapper, centroids); + Opm::Serialization::MemPacker packer; + Opm::Serializer ser(packer); + ser.pack(data_out); + const size_t pos1 = ser.position(); + decltype(data_out) data_in(grid.leafGridView(), eclState, mapper, dofMapper, centroids); + ser.unpack(data_in); + const size_t pos2 = ser.position(); + BOOST_CHECK_MESSAGE(pos1 == pos2, "Packed size differ from unpack size for EclGenericTracerModel"); + BOOST_CHECK_MESSAGE(data_out == data_in, "Deserialized EclGenericTracerModel differ"); +} + + namespace { struct AquiferFixture { From 87c242a468c2f8eb972c7a5b0c866f38782b523a Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Thu, 2 Feb 2023 11:52:08 +0100 Subject: [PATCH 2/2] EclTracerModel: add serialization of dynamic state --- ebos/ecltracermodel.hh | 34 ++++++++++++++++++++++++++++- tests/test_RestartSerialization.cpp | 10 +++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/ebos/ecltracermodel.hh b/ebos/ecltracermodel.hh index 3418b136b..1fd1e887c 100644 --- a/ebos/ecltracermodel.hh +++ b/ebos/ecltracermodel.hh @@ -205,6 +205,13 @@ public: void deserialize(Restarter&) { /* not implemented */ } + template + void serializeOp(Serializer& serializer) + { + serializer(static_cast(*this)); + serializer(tbatch); + } + protected: // evaluate water storage volume(s) in a single cell @@ -555,7 +562,32 @@ protected: std::vector residual_; std::unique_ptr mat; - TracerBatch(int phaseIdx) : phaseIdx_(phaseIdx) {} + bool operator==(const TracerBatch& rhs) const + { + return this->concentrationInitial_ == rhs.concentrationInitial_ && + this->concentration_ == rhs.concentration_; + } + + static TracerBatch serializationTestObject() + { + TracerBatch result(4); + result.idx_ = {1,2,3}; + result.concentrationInitial_ = {5.0, 6.0}; + result.concentration_ = {7.0, 8.0}; + result.storageOfTimeIndex1_ = {9.0, 10.0, 11.0}; + result.residual_ = {12.0, 13.0}; + + return result; + } + + template + void serializeOp(Serializer& serializer) + { + serializer(concentrationInitial_); + serializer(concentration_); + } + + TracerBatch(int phaseIdx = 0) : phaseIdx_(phaseIdx) {} int numTracer() const {return idx_.size(); } diff --git a/tests/test_RestartSerialization.cpp b/tests/test_RestartSerialization.cpp index f73e7c3c0..fb718e800 100644 --- a/tests/test_RestartSerialization.cpp +++ b/tests/test_RestartSerialization.cpp @@ -202,6 +202,16 @@ BOOST_AUTO_TEST_CASE(EclGenericTracerModel) BOOST_CHECK_MESSAGE(data_out == data_in, "Deserialized EclGenericTracerModel differ"); } +namespace Opm { + +class TBatchExport : public EclTracerModel { +public: + using TBatch = TracerBatch; +}; + +} + +TEST_FOR_TYPE_NAMED(TBatchExport::TBatch, TracerBatch) namespace {