mirror of
https://github.com/OPM/opm-simulators.git
synced 2025-02-25 18:55:30 -06:00
Merge pull request #4426 from akva2/blackoilaquifermodel_serialize
BlackoilAquiferModel: add serialization of dynamic state
This commit is contained in:
commit
0a1df9d6f7
@ -22,25 +22,29 @@
|
|||||||
#ifndef OPM_AQUIFERANALYTICAL_HEADER_INCLUDED
|
#ifndef OPM_AQUIFERANALYTICAL_HEADER_INCLUDED
|
||||||
#define OPM_AQUIFERANALYTICAL_HEADER_INCLUDED
|
#define OPM_AQUIFERANALYTICAL_HEADER_INCLUDED
|
||||||
|
|
||||||
#include <opm/simulators/aquifers/AquiferInterface.hpp>
|
|
||||||
|
|
||||||
#include <opm/common/utility/numeric/linearInterpolation.hpp>
|
#include <opm/common/utility/numeric/linearInterpolation.hpp>
|
||||||
|
|
||||||
#include <opm/input/eclipse/EclipseState/Aquifer/Aquancon.hpp>
|
#include <opm/input/eclipse/EclipseState/Aquifer/Aquancon.hpp>
|
||||||
|
|
||||||
#include <opm/output/data/Aquifer.hpp>
|
|
||||||
|
|
||||||
#include <opm/simulators/utils/DeferredLoggingErrorHelpers.hpp>
|
|
||||||
|
|
||||||
#include <opm/material/common/MathToolbox.hpp>
|
#include <opm/material/common/MathToolbox.hpp>
|
||||||
#include <opm/material/densead/Evaluation.hpp>
|
#include <opm/material/densead/Evaluation.hpp>
|
||||||
#include <opm/material/densead/Math.hpp>
|
#include <opm/material/densead/Math.hpp>
|
||||||
#include <opm/material/fluidstates/BlackOilFluidState.hpp>
|
#include <opm/material/fluidstates/BlackOilFluidState.hpp>
|
||||||
|
|
||||||
|
#include <opm/models/blackoil/blackoilproperties.hh>
|
||||||
|
#include <opm/models/utils/basicproperties.hh>
|
||||||
|
|
||||||
|
#include <opm/output/data/Aquifer.hpp>
|
||||||
|
|
||||||
|
#include <opm/simulators/aquifers/AquiferInterface.hpp>
|
||||||
|
#include <opm/simulators/utils/DeferredLoggingErrorHelpers.hpp>
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
#include <numeric>
|
#include <numeric>
|
||||||
|
#include <optional>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@ -183,6 +187,25 @@ public:
|
|||||||
return this->connections_.size();
|
return this->connections_.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<class Serializer>
|
||||||
|
void serializeOp(Serializer& serializer)
|
||||||
|
{
|
||||||
|
serializer(pressure_previous_);
|
||||||
|
serializer(pressure_current_);
|
||||||
|
serializer(Qai_);
|
||||||
|
serializer(rhow_);
|
||||||
|
serializer(W_flux_);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator==(const AquiferAnalytical& rhs) const
|
||||||
|
{
|
||||||
|
return this->pressure_previous_ == rhs.pressure_previous_ &&
|
||||||
|
this->pressure_current_ == rhs.pressure_current_ &&
|
||||||
|
this->Qai_ == rhs.Qai_ &&
|
||||||
|
this->rhow_ == rhs.rhow_ &&
|
||||||
|
this->W_flux_ == rhs.W_flux_;
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void assignRestartData(const data::AquiferData& xaq) = 0;
|
virtual void assignRestartData(const data::AquiferData& xaq) = 0;
|
||||||
virtual void calculateInflowRate(int idx, const Simulator& simulator) = 0;
|
virtual void calculateInflowRate(int idx, const Simulator& simulator) = 0;
|
||||||
|
@ -23,6 +23,8 @@
|
|||||||
|
|
||||||
#include <opm/simulators/aquifers/AquiferAnalytical.hpp>
|
#include <opm/simulators/aquifers/AquiferAnalytical.hpp>
|
||||||
|
|
||||||
|
#include <opm/input/eclipse/EclipseState/Aquifer/AquiferCT.hpp>
|
||||||
|
|
||||||
#include <opm/output/data/Aquifer.hpp>
|
#include <opm/output/data/Aquifer.hpp>
|
||||||
|
|
||||||
#include <exception>
|
#include <exception>
|
||||||
@ -57,6 +59,22 @@ public:
|
|||||||
, aquct_data_(aquct_data)
|
, aquct_data_(aquct_data)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
static AquiferCarterTracy serializationTestObject(const Simulator& ebosSimulator)
|
||||||
|
{
|
||||||
|
AquiferCarterTracy result({}, ebosSimulator, {});
|
||||||
|
|
||||||
|
result.pressure_previous_ = {1.0, 2.0, 3.0};
|
||||||
|
result.pressure_current_ = {4.0, 5.0};
|
||||||
|
result.Qai_ = {{6.0}};
|
||||||
|
result.rhow_ = 7.0;
|
||||||
|
result.W_flux_ = 8.0;
|
||||||
|
result.fluxValue_ = 9.0;
|
||||||
|
result.dimensionless_time_ = 10.0;
|
||||||
|
result.dimensionless_pressure_ = 11.0;
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
void endTimeStep() override
|
void endTimeStep() override
|
||||||
{
|
{
|
||||||
for (const auto& q : this->Qai_) {
|
for (const auto& q : this->Qai_) {
|
||||||
@ -100,6 +118,23 @@ public:
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<class Serializer>
|
||||||
|
void serializeOp(Serializer& serializer)
|
||||||
|
{
|
||||||
|
serializer(static_cast<Base&>(*this));
|
||||||
|
serializer(fluxValue_);
|
||||||
|
serializer(dimensionless_time_);
|
||||||
|
serializer(dimensionless_pressure_);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator==(const AquiferCarterTracy& rhs) const
|
||||||
|
{
|
||||||
|
return static_cast<const AquiferAnalytical<TypeTag>&>(*this) == rhs &&
|
||||||
|
this->fluxValue_ == rhs.fluxValue_ &&
|
||||||
|
this->dimensionless_time_ == rhs.dimensionless_time_ &&
|
||||||
|
this->dimensionless_pressure_ == rhs.dimensionless_pressure_;
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// Variables constants
|
// Variables constants
|
||||||
AquiferCT::AQUCT_data aquct_data_;
|
AquiferCT::AQUCT_data aquct_data_;
|
||||||
|
@ -23,6 +23,8 @@ along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
|
|
||||||
#include <opm/simulators/aquifers/AquiferAnalytical.hpp>
|
#include <opm/simulators/aquifers/AquiferAnalytical.hpp>
|
||||||
|
|
||||||
|
#include <opm/input/eclipse/EclipseState/Aquifer/Aquifetp.hpp>
|
||||||
|
|
||||||
#include <opm/output/data/Aquifer.hpp>
|
#include <opm/output/data/Aquifer.hpp>
|
||||||
|
|
||||||
#include <exception>
|
#include <exception>
|
||||||
@ -58,6 +60,20 @@ public:
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static AquiferFetkovich serializationTestObject(const Simulator& ebosSimulator)
|
||||||
|
{
|
||||||
|
AquiferFetkovich result({}, ebosSimulator, {});
|
||||||
|
|
||||||
|
result.pressure_previous_ = {1.0, 2.0, 3.0};
|
||||||
|
result.pressure_current_ = {4.0, 5.0};
|
||||||
|
result.Qai_ = {{6.0}};
|
||||||
|
result.rhow_ = 7.0;
|
||||||
|
result.W_flux_ = 8.0;
|
||||||
|
result.aquifer_pressure_ = 9.0;
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
void endTimeStep() override
|
void endTimeStep() override
|
||||||
{
|
{
|
||||||
for (const auto& q : this->Qai_) {
|
for (const auto& q : this->Qai_) {
|
||||||
@ -89,6 +105,19 @@ public:
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<class Serializer>
|
||||||
|
void serializeOp(Serializer& serializer)
|
||||||
|
{
|
||||||
|
serializer(static_cast<Base&>(*this));
|
||||||
|
serializer(aquifer_pressure_);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator==(const AquiferFetkovich& rhs) const
|
||||||
|
{
|
||||||
|
return static_cast<const Base&>(*this) == rhs &&
|
||||||
|
this->aquifer_pressure_ == rhs.aquifer_pressure_;
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// Aquifer Fetkovich Specific Variables
|
// Aquifer Fetkovich Specific Variables
|
||||||
Aquifetp::AQUFETP_data aqufetp_data_;
|
Aquifetp::AQUFETP_data aqufetp_data_;
|
||||||
|
@ -22,6 +22,9 @@
|
|||||||
#ifndef OPM_AQUIFERINTERFACE_HEADER_INCLUDED
|
#ifndef OPM_AQUIFERINTERFACE_HEADER_INCLUDED
|
||||||
#define OPM_AQUIFERINTERFACE_HEADER_INCLUDED
|
#define OPM_AQUIFERINTERFACE_HEADER_INCLUDED
|
||||||
|
|
||||||
|
#include <opm/models/common/multiphasebaseproperties.hh>
|
||||||
|
#include <opm/models/discretization/common/fvbaseproperties.hh>
|
||||||
|
|
||||||
#include <opm/output/data/Aquifer.hpp>
|
#include <opm/output/data/Aquifer.hpp>
|
||||||
|
|
||||||
namespace Opm
|
namespace Opm
|
||||||
|
@ -21,10 +21,13 @@
|
|||||||
#ifndef OPM_AQUIFERNUMERICAL_HEADER_INCLUDED
|
#ifndef OPM_AQUIFERNUMERICAL_HEADER_INCLUDED
|
||||||
#define OPM_AQUIFERNUMERICAL_HEADER_INCLUDED
|
#define OPM_AQUIFERNUMERICAL_HEADER_INCLUDED
|
||||||
|
|
||||||
#include <opm/output/data/Aquifer.hpp>
|
|
||||||
|
|
||||||
#include <opm/input/eclipse/EclipseState/Aquifer/NumericalAquifer/SingleNumericalAquifer.hpp>
|
#include <opm/input/eclipse/EclipseState/Aquifer/NumericalAquifer/SingleNumericalAquifer.hpp>
|
||||||
|
|
||||||
|
#include <opm/material/common/MathToolbox.hpp>
|
||||||
|
#include <opm/material/densead/Evaluation.hpp>
|
||||||
|
|
||||||
|
#include <opm/output/data/Aquifer.hpp>
|
||||||
|
|
||||||
#include <opm/simulators/aquifers/AquiferInterface.hpp>
|
#include <opm/simulators/aquifers/AquiferInterface.hpp>
|
||||||
#include <opm/simulators/utils/DeferredLoggingErrorHelpers.hpp>
|
#include <opm/simulators/utils/DeferredLoggingErrorHelpers.hpp>
|
||||||
|
|
||||||
@ -86,6 +89,17 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static AquiferNumerical serializationTestObject(const Simulator& ebos_simulator)
|
||||||
|
{
|
||||||
|
AquiferNumerical result({}, ebos_simulator);
|
||||||
|
result.flux_rate_ = 1.0;
|
||||||
|
result.cumulative_flux_ = 2.0;
|
||||||
|
result.init_pressure_ = {3.0, 4.0};
|
||||||
|
result.pressure_ = 5.0;
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
void initFromRestart(const data::Aquifers& aquiferSoln) override
|
void initFromRestart(const data::Aquifers& aquiferSoln) override
|
||||||
{
|
{
|
||||||
auto xaqPos = aquiferSoln.find(this->aquiferID());
|
auto xaqPos = aquiferSoln.find(this->aquiferID());
|
||||||
@ -140,6 +154,23 @@ public:
|
|||||||
this->cumulative_flux_ = 0.;
|
this->cumulative_flux_ = 0.;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<class Serializer>
|
||||||
|
void serializeOp(Serializer& serializer)
|
||||||
|
{
|
||||||
|
serializer(flux_rate_);
|
||||||
|
serializer(cumulative_flux_);
|
||||||
|
serializer(init_pressure_);
|
||||||
|
serializer(pressure_);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator==(const AquiferNumerical& rhs) const
|
||||||
|
{
|
||||||
|
return this->flux_rate_ == rhs.flux_rate_ &&
|
||||||
|
this->cumulative_flux_ == rhs.cumulative_flux_ &&
|
||||||
|
this->init_pressure_ == rhs.init_pressure_ &&
|
||||||
|
this->pressure_ == rhs.pressure_;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void checkConnectsToReservoir()
|
void checkConnectsToReservoir()
|
||||||
{
|
{
|
||||||
|
@ -112,6 +112,9 @@ public:
|
|||||||
template <class Restarter>
|
template <class Restarter>
|
||||||
void deserialize(Restarter& res);
|
void deserialize(Restarter& res);
|
||||||
|
|
||||||
|
template<class Serializer>
|
||||||
|
void serializeOp(Serializer& serializer);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// --------- Types ---------
|
// --------- Types ---------
|
||||||
using ElementContext = GetPropType<TypeTag, Properties::ElementContext>;
|
using ElementContext = GetPropType<TypeTag, Properties::ElementContext>;
|
||||||
|
@ -18,6 +18,9 @@
|
|||||||
along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <opm/common/ErrorMacros.hpp>
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
namespace Opm
|
namespace Opm
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -184,4 +187,25 @@ data::Aquifers BlackoilAquiferModel<TypeTag>::aquiferData() const
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename TypeTag>
|
||||||
|
template<class Serializer>
|
||||||
|
void BlackoilAquiferModel<TypeTag>::
|
||||||
|
serializeOp(Serializer& serializer)
|
||||||
|
{
|
||||||
|
for (auto& aiPtr : aquifers) {
|
||||||
|
auto* ct = dynamic_cast<AquiferCarterTracy<TypeTag>*>(aiPtr.get());
|
||||||
|
auto* fetp = dynamic_cast<AquiferFetkovich<TypeTag>*>(aiPtr.get());
|
||||||
|
auto* num = dynamic_cast<AquiferNumerical<TypeTag>*>(aiPtr.get());
|
||||||
|
if (ct) {
|
||||||
|
serializer(*ct);
|
||||||
|
} else if (fetp) {
|
||||||
|
serializer(*fetp);
|
||||||
|
} else if (num) {
|
||||||
|
serializer(*num);
|
||||||
|
} else {
|
||||||
|
OPM_THROW(std::logic_error, "Error serializing BlackoilAquiferModel: unknown aquifer type");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Opm
|
} // namespace Opm
|
||||||
|
@ -134,6 +134,64 @@ 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");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
struct AquiferFixture {
|
||||||
|
AquiferFixture() {
|
||||||
|
using TT = Opm::Properties::TTag::EbosTypeTag;
|
||||||
|
const char* argv[] = {
|
||||||
|
"test_RestartSerialization",
|
||||||
|
"--ecl-deck-file-name=GLIFT1.DATA"
|
||||||
|
};
|
||||||
|
Opm::setupParameters_<TT>(2, argv, /*registerParams=*/true);
|
||||||
|
Opm::EclGenericVanguard::setCommunication(std::make_unique<Opm::Parallel::Communication>());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_GLOBAL_FIXTURE(AquiferFixture);
|
||||||
|
|
||||||
|
#define TEST_FOR_AQUIFER(TYPE) \
|
||||||
|
BOOST_AUTO_TEST_CASE(TYPE) \
|
||||||
|
{ \
|
||||||
|
using TT = Opm::Properties::TTag::EbosTypeTag; \
|
||||||
|
Opm::EclGenericVanguard::readDeck("GLIFT1.DATA"); \
|
||||||
|
using Simulator = Opm::GetPropType<TT, Opm::Properties::Simulator>; \
|
||||||
|
Simulator sim; \
|
||||||
|
auto data_out = Opm::TYPE<TT>::serializationTestObject(sim); \
|
||||||
|
Opm::Serialization::MemPacker packer; \
|
||||||
|
Opm::Serializer ser(packer); \
|
||||||
|
ser.pack(data_out); \
|
||||||
|
const size_t pos1 = ser.position(); \
|
||||||
|
decltype(data_out) data_in({}, sim, {}); \
|
||||||
|
ser.unpack(data_in); \
|
||||||
|
const size_t pos2 = ser.position(); \
|
||||||
|
BOOST_CHECK_MESSAGE(pos1 == pos2, "Packed size differ from unpack size for " #TYPE); \
|
||||||
|
BOOST_CHECK_MESSAGE(data_out == data_in, "Deserialized " #TYPE " differ"); \
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_FOR_AQUIFER(AquiferCarterTracy)
|
||||||
|
TEST_FOR_AQUIFER(AquiferFetkovich)
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(AquiferNumerical)
|
||||||
|
{
|
||||||
|
using TT = Opm::Properties::TTag::EbosTypeTag;
|
||||||
|
Opm::EclGenericVanguard::readDeck("GLIFT1.DATA");
|
||||||
|
using Simulator = Opm::GetPropType<TT, Opm::Properties::Simulator>;
|
||||||
|
Simulator sim;
|
||||||
|
auto data_out = Opm::AquiferNumerical<TT>::serializationTestObject(sim);
|
||||||
|
Opm::Serialization::MemPacker packer;
|
||||||
|
Opm::Serializer ser(packer);
|
||||||
|
ser.pack(data_out);
|
||||||
|
const size_t pos1 = ser.position();
|
||||||
|
decltype(data_out) data_in({}, sim);
|
||||||
|
ser.unpack(data_in);
|
||||||
|
const size_t pos2 = ser.position();
|
||||||
|
BOOST_CHECK_MESSAGE(pos1 == pos2, "Packed size differ from unpack size for AquiferNumerical");
|
||||||
|
BOOST_CHECK_MESSAGE(data_out == data_in, "Deserialized AquiferNumerical differ");
|
||||||
|
}
|
||||||
|
|
||||||
bool init_unit_test_func()
|
bool init_unit_test_func()
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
|
Loading…
Reference in New Issue
Block a user