mirror of
https://github.com/OPM/opm-simulators.git
synced 2025-01-13 09:51:57 -06:00
Merge pull request #4433 from akva2/ecltracermodel_serialize
EclTracerModel: add serialization of dynamic state
This commit is contained in:
commit
3dc13c234c
@ -78,6 +78,13 @@ public:
|
|||||||
const std::map<std::pair<std::string, std::string>, double>&
|
const std::map<std::pair<std::string, std::string>, double>&
|
||||||
getWellTracerRates() const {return wellTracerRate_;}
|
getWellTracerRates() const {return wellTracerRate_;}
|
||||||
|
|
||||||
|
template<class Serializer>
|
||||||
|
void serializeOp(Serializer& serializer)
|
||||||
|
{
|
||||||
|
serializer(tracerConcentration_);
|
||||||
|
serializer(wellTracerRate_);
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
EclGenericTracerModel(const GridView& gridView,
|
EclGenericTracerModel(const GridView& gridView,
|
||||||
const EclipseState& eclState,
|
const EclipseState& eclState,
|
||||||
|
@ -205,6 +205,13 @@ public:
|
|||||||
void deserialize(Restarter&)
|
void deserialize(Restarter&)
|
||||||
{ /* not implemented */ }
|
{ /* not implemented */ }
|
||||||
|
|
||||||
|
template<class Serializer>
|
||||||
|
void serializeOp(Serializer& serializer)
|
||||||
|
{
|
||||||
|
serializer(static_cast<BaseType&>(*this));
|
||||||
|
serializer(tbatch);
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
// evaluate water storage volume(s) in a single cell
|
// evaluate water storage volume(s) in a single cell
|
||||||
@ -555,7 +562,32 @@ protected:
|
|||||||
std::vector<TV> residual_;
|
std::vector<TV> residual_;
|
||||||
std::unique_ptr<TracerMatrix> mat;
|
std::unique_ptr<TracerMatrix> 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<TV> 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<class Serializer>
|
||||||
|
void serializeOp(Serializer& serializer)
|
||||||
|
{
|
||||||
|
serializer(concentrationInitial_);
|
||||||
|
serializer(concentration_);
|
||||||
|
}
|
||||||
|
|
||||||
|
TracerBatch(int phaseIdx = 0) : phaseIdx_(phaseIdx) {}
|
||||||
|
|
||||||
int numTracer() const {return idx_.size(); }
|
int numTracer() const {return idx_.size(); }
|
||||||
|
|
||||||
|
@ -42,6 +42,8 @@
|
|||||||
#include <boost/date_time/gregorian/gregorian.hpp>
|
#include <boost/date_time/gregorian/gregorian.hpp>
|
||||||
#include <boost/test/unit_test.hpp>
|
#include <boost/test/unit_test.hpp>
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
std::tuple<T,int,int> PackUnpack(T& in)
|
std::tuple<T,int,int> PackUnpack(T& in)
|
||||||
{
|
{
|
||||||
@ -134,6 +136,83 @@ BOOST_AUTO_TEST_CASE(EclGenericProblem)
|
|||||||
BOOST_CHECK_MESSAGE(data_out == data_in, "Deserialized EclGenericProblem differ");
|
BOOST_CHECK_MESSAGE(data_out == data_in, "Deserialized EclGenericProblem 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>;
|
||||||
|
public:
|
||||||
|
EclGenericTracerModelTest(const GridView& gridView,
|
||||||
|
const Opm::EclipseState& eclState,
|
||||||
|
const Dune::CartesianIndexMapper<Grid>& cartMapper,
|
||||||
|
const DofMapper& dofMapper,
|
||||||
|
const std::function<std::array<double,Grid::dimensionworld>(int)> centroids) :
|
||||||
|
Base(gridView, eclState, cartMapper, dofMapper, centroids)
|
||||||
|
{}
|
||||||
|
|
||||||
|
static EclGenericTracerModelTest
|
||||||
|
serializationTestObject(const GridView& gridView,
|
||||||
|
const Opm::EclipseState& eclState,
|
||||||
|
const Dune::CartesianIndexMapper<Grid>& cartMapper,
|
||||||
|
const DofMapper& dofMapper,
|
||||||
|
const std::function<std::array<double,Grid::dimensionworld>(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<Dune::CpGrid> mapper(grid);
|
||||||
|
Dune::MultipleCodimMultipleGeomTypeMapper<Dune::CpGrid::LeafGridView> dofMapper(grid.leafGridView(), Dune::mcmgElementLayout());
|
||||||
|
auto centroids = [](int) { return std::array<double,Dune::CpGrid::dimensionworld>{}; };
|
||||||
|
auto data_out = EclGenericTracerModelTest<Dune::CpGrid,
|
||||||
|
Dune::GridView<Dune::DefaultLeafGridViewTraits<Dune::CpGrid>>,
|
||||||
|
Dune::MultipleCodimMultipleGeomTypeMapper<Dune::GridView<Dune::DefaultLeafGridViewTraits<Dune::CpGrid>>>,
|
||||||
|
Opm::EcfvStencil<double,Dune::GridView<Dune::DefaultLeafGridViewTraits<Dune::CpGrid>>,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 Opm {
|
||||||
|
|
||||||
|
class TBatchExport : public EclTracerModel<Properties::TTag::EbosTypeTag> {
|
||||||
|
public:
|
||||||
|
using TBatch = TracerBatch<double>;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_FOR_TYPE_NAMED(TBatchExport::TBatch, TracerBatch)
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
struct AquiferFixture {
|
struct AquiferFixture {
|
||||||
|
Loading…
Reference in New Issue
Block a user