mirror of
https://github.com/OPM/opm-simulators.git
synced 2024-11-21 08:54:08 -06:00
SimulatorTimer: add serialization support
This commit is contained in:
parent
4786deeffc
commit
f2a14b2d07
@ -199,6 +199,7 @@ list (APPEND TEST_SOURCE_FILES
|
||||
tests/test_parallelwellinfo.cpp
|
||||
tests/test_preconditionerfactory.cpp
|
||||
tests/test_relpermdiagnostics.cpp
|
||||
tests/test_RestartSerialization.cpp
|
||||
tests/test_stoppedwells.cpp
|
||||
tests/test_timer.cpp
|
||||
tests/test_vfpproperties.cpp
|
||||
|
@ -20,11 +20,12 @@
|
||||
#include "config.h"
|
||||
#include <opm/simulators/timestepping/SimulatorTimer.hpp>
|
||||
#include <opm/common/utility/parameters/ParameterGroup.hpp>
|
||||
#include <opm/input/eclipse/Schedule/Schedule.hpp>
|
||||
#include <opm/input/eclipse/Units/Units.hpp>
|
||||
#include <ostream>
|
||||
#include <numeric>
|
||||
|
||||
#include <boost/date_time/gregorian_calendar.hpp>
|
||||
#include <boost/date_time/gregorian/gregorian_types.hpp>
|
||||
#include <boost/date_time/posix_time/conversion.hpp>
|
||||
|
||||
namespace Opm
|
||||
@ -38,6 +39,18 @@ namespace Opm
|
||||
{
|
||||
}
|
||||
|
||||
SimulatorTimer SimulatorTimer::serializationTestObject()
|
||||
{
|
||||
SimulatorTimer res;
|
||||
res.timesteps_ = {1.0, 2.0, 3.0};
|
||||
res.current_step_ = 4;
|
||||
res.current_time_ = 5.0;
|
||||
res.total_time_ = 6.0;
|
||||
res.start_date_ = boost::gregorian::date(2023,1,31);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
/// Initialize from parameters. Accepts the following:
|
||||
/// num_psteps (default 1)
|
||||
/// stepsize_days (default 1)
|
||||
@ -162,6 +175,13 @@ namespace Opm
|
||||
return std::make_unique<SimulatorTimer>(*this);
|
||||
}
|
||||
|
||||
|
||||
bool SimulatorTimer::operator==(const SimulatorTimer& rhs) const
|
||||
{
|
||||
return this->timesteps_ == rhs.timesteps_ &&
|
||||
this->current_step_ == rhs.current_step_ &&
|
||||
this->current_time_ == rhs.current_time_ &&
|
||||
this->total_time_ == rhs.total_time_ &&
|
||||
this->start_date_ == rhs.start_date_;
|
||||
}
|
||||
|
||||
} // namespace Opm
|
||||
|
@ -20,7 +20,6 @@
|
||||
#ifndef OPM_SIMULATORTIMER_HEADER_INCLUDED
|
||||
#define OPM_SIMULATORTIMER_HEADER_INCLUDED
|
||||
|
||||
#include <opm/input/eclipse/Schedule/Schedule.hpp>
|
||||
#include <opm/simulators/timestepping/SimulatorTimerInterface.hpp>
|
||||
|
||||
#include <boost/date_time/gregorian/gregorian_types.hpp>
|
||||
@ -33,6 +32,7 @@ namespace Opm
|
||||
{
|
||||
|
||||
class ParameterGroup;
|
||||
class Schedule;
|
||||
|
||||
class SimulatorTimer : public SimulatorTimerInterface
|
||||
{
|
||||
@ -44,6 +44,8 @@ namespace Opm
|
||||
/// Default constructor.
|
||||
SimulatorTimer();
|
||||
|
||||
static SimulatorTimer serializationTestObject();
|
||||
|
||||
/// Initialize from parameters. Accepts the following:
|
||||
/// num_psteps (default 1)
|
||||
/// stepsize_days (default 1)
|
||||
@ -117,6 +119,18 @@ namespace Opm
|
||||
/// return copy of object
|
||||
std::unique_ptr<SimulatorTimerInterface> clone() const override;
|
||||
|
||||
template<class Serializer>
|
||||
void serializeOp(Serializer& serializer)
|
||||
{
|
||||
serializer(timesteps_);
|
||||
serializer(current_step_);
|
||||
serializer(current_time_);
|
||||
serializer(total_time_);
|
||||
serializer(start_date_);
|
||||
}
|
||||
|
||||
bool operator==(const SimulatorTimer& rhs) const;
|
||||
|
||||
private:
|
||||
std::vector<double> timesteps_;
|
||||
int current_step_;
|
||||
|
72
tests/test_RestartSerialization.cpp
Normal file
72
tests/test_RestartSerialization.cpp
Normal file
@ -0,0 +1,72 @@
|
||||
/*
|
||||
Copyright 2019 SINTEF Digital, Mathematics and Cybernetics.
|
||||
|
||||
This file is part of the Open Porous Media project (OPM).
|
||||
|
||||
OPM is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OPM is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <opm/common/utility/Serializer.hpp>
|
||||
|
||||
#include <opm/simulators/timestepping/SimulatorTimer.hpp>
|
||||
#include <opm/simulators/utils/SerializationPackers.hpp>
|
||||
|
||||
#define BOOST_TEST_MODULE TestRestartSerialization
|
||||
#define BOOST_TEST_NO_MAIN
|
||||
|
||||
#include <boost/date_time/gregorian/gregorian.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
template<class T>
|
||||
std::tuple<T,int,int> PackUnpack(T& in)
|
||||
{
|
||||
Opm::Serialization::MemPacker packer;
|
||||
Opm::Serializer ser(packer);
|
||||
ser.pack(in);
|
||||
size_t pos1 = ser.position();
|
||||
T out{};
|
||||
ser.unpack(out);
|
||||
size_t pos2 = ser.position();
|
||||
|
||||
return std::make_tuple(out, pos1, pos2);
|
||||
}
|
||||
|
||||
#define TEST_FOR_TYPE_NAMED_OBJ(TYPE, NAME, OBJ) \
|
||||
BOOST_AUTO_TEST_CASE(NAME) \
|
||||
{ \
|
||||
auto val1 = Opm::TYPE::OBJ(); \
|
||||
auto val2 = PackUnpack(val1); \
|
||||
BOOST_CHECK_MESSAGE(std::get<1>(val2) == std::get<2>(val2), "Packed size differ from unpack size for " #TYPE); \
|
||||
BOOST_CHECK_MESSAGE(val1 == std::get<0>(val2), "Deserialized " #TYPE " differ"); \
|
||||
}
|
||||
|
||||
#define TEST_FOR_TYPE_NAMED(TYPE, NAME) \
|
||||
TEST_FOR_TYPE_NAMED_OBJ(TYPE, NAME, serializationTestObject)
|
||||
|
||||
#define TEST_FOR_TYPE(TYPE) \
|
||||
TEST_FOR_TYPE_NAMED(TYPE, TYPE)
|
||||
|
||||
TEST_FOR_TYPE(SimulatorTimer)
|
||||
|
||||
bool init_unit_test_func()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
return boost::unit_test::unit_test_main(&init_unit_test_func, argc, argv);
|
||||
}
|
@ -33,6 +33,7 @@
|
||||
#include <opm/input/eclipse/EclipseState/Grid/FieldPropsManager.hpp>
|
||||
#include <opm/input/eclipse/EclipseState/Grid/EclipseGrid.hpp>
|
||||
#include <opm/input/eclipse/EclipseState/Tables/TableManager.hpp>
|
||||
#include <opm/input/eclipse/Schedule/Schedule.hpp>
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
Loading…
Reference in New Issue
Block a user