HardcodedTimeStepControl: add serialization support

This commit is contained in:
Arne Morten Kvarving 2023-01-31 12:38:54 +01:00
parent bd538cf61d
commit 87bc1d8c10
3 changed files with 27 additions and 1 deletions

View File

@ -108,7 +108,7 @@ namespace Opm
////////////////////////////////////////////////////////
HardcodedTimeStepControl::
HardcodedTimeStepControl( const std::string& filename)
HardcodedTimeStepControl(const std::string& filename)
{
std::ifstream infile (filename);
if (!infile.is_open()) {
@ -125,6 +125,14 @@ namespace Opm
}
}
HardcodedTimeStepControl HardcodedTimeStepControl::serializationTestObject()
{
HardcodedTimeStepControl result;
result.subStepTime_ = {1.0, 2.0};
return result;
}
double HardcodedTimeStepControl::
computeTimeStepSize( const double /*dt */, const int /*iterations */, const RelativeChangeInterface& /* relativeChange */ , const double simulationTimeElapsed) const
{
@ -132,6 +140,11 @@ namespace Opm
return (*nextTime - simulationTimeElapsed);
}
bool HardcodedTimeStepControl::operator==(const HardcodedTimeStepControl& ctrl) const
{
return this->subStepTime_ == ctrl.subStepTime_;
}
////////////////////////////////////////////////////////

View File

@ -148,13 +148,25 @@ namespace Opm
class HardcodedTimeStepControl : public TimeStepControlInterface
{
public:
HardcodedTimeStepControl() = default;
/// \brief constructor
/// \param filename filename contaning the timesteps
explicit HardcodedTimeStepControl( const std::string& filename);
static HardcodedTimeStepControl serializationTestObject();
/// \brief \copydoc TimeStepControlInterface::computeTimeStepSize
double computeTimeStepSize( const double dt, const int /* iterations */, const RelativeChangeInterface& /*relativeChange */, const double simulationTimeElapsed) const;
template<class Serializer>
void serializeOp(Serializer& serializer)
{
serializer(subStepTime_);
}
bool operator==(const HardcodedTimeStepControl&) const;
protected:
// store the time (in days) of the substeps the simulator should use
std::vector<double> subStepTime_;

View File

@ -60,6 +60,7 @@ BOOST_AUTO_TEST_CASE(NAME) \
#define TEST_FOR_TYPE(TYPE) \
TEST_FOR_TYPE_NAMED(TYPE, TYPE)
TEST_FOR_TYPE(HardcodedTimeStepControl)
TEST_FOR_TYPE(SimpleIterationCountTimeStepControl)
TEST_FOR_TYPE(SimulatorTimer)