SimpleIterationCountTimeStepControl: add serialization support

This commit is contained in:
Arne Morten Kvarving
2023-01-31 12:38:54 +01:00
parent e89b28c9a2
commit bd538cf61d
3 changed files with 36 additions and 4 deletions

View File

@@ -66,6 +66,12 @@ namespace Opm
} }
} }
SimpleIterationCountTimeStepControl
SimpleIterationCountTimeStepControl::serializationTestObject()
{
return {1, 1.0, 2.0, true};
}
double SimpleIterationCountTimeStepControl:: double SimpleIterationCountTimeStepControl::
computeTimeStepSize( const double dt, const int iterations, const RelativeChangeInterface& /* relativeChange */, const double /*simulationTimeElapsed */) const computeTimeStepSize( const double dt, const int iterations, const RelativeChangeInterface& /* relativeChange */, const double /*simulationTimeElapsed */) const
{ {
@@ -86,6 +92,15 @@ namespace Opm
return dtEstimate; return dtEstimate;
} }
bool SimpleIterationCountTimeStepControl::
operator==(const SimpleIterationCountTimeStepControl& ctrl) const
{
return this->target_iterations_ == ctrl.target_iterations_ &&
this->decayrate_ == ctrl.decayrate_ &&
this->growthrate_ == ctrl.growthrate_ &&
this->verbose_ == ctrl.verbose_;
}
//////////////////////////////////////////////////////// ////////////////////////////////////////////////////////
// //
// HardcodedTimeStepControl Implementation // HardcodedTimeStepControl Implementation

View File

@@ -35,6 +35,8 @@ namespace Opm
class SimpleIterationCountTimeStepControl : public TimeStepControlInterface class SimpleIterationCountTimeStepControl : public TimeStepControlInterface
{ {
public: public:
SimpleIterationCountTimeStepControl() = default;
/// \brief constructor /// \brief constructor
/// \param target_iterations number of desired iterations (e.g. Newton iterations) per time step in one time step /// \param target_iterations number of desired iterations (e.g. Newton iterations) per time step in one time step
// \param decayrate decayrate of time step when target iterations are not met (should be <= 1) // \param decayrate decayrate of time step when target iterations are not met (should be <= 1)
@@ -45,14 +47,27 @@ namespace Opm
const double growthrate, const double growthrate,
const bool verbose = false); const bool verbose = false);
static SimpleIterationCountTimeStepControl serializationTestObject();
/// \brief \copydoc TimeStepControlInterface::computeTimeStepSize /// \brief \copydoc TimeStepControlInterface::computeTimeStepSize
double computeTimeStepSize( const double dt, const int iterations, const RelativeChangeInterface& /* relativeChange */, const double /*simulationTimeElapsed */ ) const; double computeTimeStepSize( const double dt, const int iterations, const RelativeChangeInterface& /* relativeChange */, const double /*simulationTimeElapsed */ ) const;
template<class Serializer>
void serializeOp(Serializer& serializer)
{
serializer(target_iterations_);
serializer(decayrate_);
serializer(growthrate_);
serializer(verbose_);
}
bool operator==(const SimpleIterationCountTimeStepControl&) const;
protected: protected:
const int target_iterations_; const int target_iterations_ = 0;
const double decayrate_; const double decayrate_ = 0.0;
const double growthrate_; const double growthrate_ = 0.0;
const bool verbose_; const bool verbose_ = false;
}; };
/////////////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////

View File

@@ -22,6 +22,7 @@
#include <opm/common/utility/Serializer.hpp> #include <opm/common/utility/Serializer.hpp>
#include <opm/simulators/timestepping/SimulatorTimer.hpp> #include <opm/simulators/timestepping/SimulatorTimer.hpp>
#include <opm/simulators/timestepping/TimeStepControl.hpp>
#include <opm/simulators/utils/SerializationPackers.hpp> #include <opm/simulators/utils/SerializationPackers.hpp>
#define BOOST_TEST_MODULE TestRestartSerialization #define BOOST_TEST_MODULE TestRestartSerialization
@@ -59,6 +60,7 @@ BOOST_AUTO_TEST_CASE(NAME) \
#define TEST_FOR_TYPE(TYPE) \ #define TEST_FOR_TYPE(TYPE) \
TEST_FOR_TYPE_NAMED(TYPE, TYPE) TEST_FOR_TYPE_NAMED(TYPE, TYPE)
TEST_FOR_TYPE(SimpleIterationCountTimeStepControl)
TEST_FOR_TYPE(SimulatorTimer) TEST_FOR_TYPE(SimulatorTimer)
bool init_unit_test_func() bool init_unit_test_func()