2012-06-14 07:02:22 -05:00
|
|
|
/*
|
|
|
|
Copyright 2012 SINTEF ICT, Applied Mathematics.
|
|
|
|
|
|
|
|
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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef OPM_SIMULATORTIMER_HEADER_INCLUDED
|
|
|
|
#define OPM_SIMULATORTIMER_HEADER_INCLUDED
|
|
|
|
|
2017-02-10 06:01:50 -06:00
|
|
|
#include <opm/simulators/timestepping/SimulatorTimerInterface.hpp>
|
2014-02-20 10:59:41 -06:00
|
|
|
|
2023-02-13 10:59:35 -06:00
|
|
|
#include <boost/date_time/gregorian/gregorian_types.hpp>
|
|
|
|
|
2012-06-14 07:02:22 -05:00
|
|
|
#include <iosfwd>
|
2023-02-13 10:59:35 -06:00
|
|
|
#include <memory>
|
2012-06-14 07:02:22 -05:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace Opm
|
|
|
|
{
|
|
|
|
|
2017-04-28 08:36:25 -05:00
|
|
|
class ParameterGroup;
|
2023-01-31 05:09:20 -06:00
|
|
|
class Schedule;
|
2012-06-14 07:02:22 -05:00
|
|
|
|
2015-01-08 05:06:37 -06:00
|
|
|
class SimulatorTimer : public SimulatorTimerInterface
|
2012-06-14 07:02:22 -05:00
|
|
|
{
|
|
|
|
public:
|
2015-01-08 05:06:37 -06:00
|
|
|
// use default implementation of these methods
|
|
|
|
using SimulatorTimerInterface::currentDateTime;
|
|
|
|
using SimulatorTimerInterface::currentPosixTime;
|
|
|
|
|
2012-11-07 07:53:26 -06:00
|
|
|
/// Default constructor.
|
|
|
|
SimulatorTimer();
|
2012-06-14 07:02:22 -05:00
|
|
|
|
2023-01-31 05:09:20 -06:00
|
|
|
static SimulatorTimer serializationTestObject();
|
|
|
|
|
2012-11-07 07:53:26 -06:00
|
|
|
/// Initialize from parameters. Accepts the following:
|
|
|
|
/// num_psteps (default 1)
|
|
|
|
/// stepsize_days (default 1)
|
2017-04-28 08:36:25 -05:00
|
|
|
void init(const ParameterGroup& param);
|
2012-06-14 07:02:22 -05:00
|
|
|
|
2021-02-22 11:43:56 -06:00
|
|
|
/// Use the SimulatorTimer as a shim around opm-commons Schedule class
|
|
|
|
void init(const Schedule& schedule, size_t report_step = 0);
|
2014-02-20 10:59:41 -06:00
|
|
|
|
2016-07-04 04:12:53 -05:00
|
|
|
/// Whether the current step is the first step.
|
2021-06-08 08:20:15 -05:00
|
|
|
bool initialStep() const override;
|
2016-07-04 04:12:53 -05:00
|
|
|
|
2012-11-07 07:53:26 -06:00
|
|
|
/// Total number of steps.
|
|
|
|
int numSteps() const;
|
2012-06-14 07:02:22 -05:00
|
|
|
|
2013-11-26 17:23:00 -06:00
|
|
|
/// Current step number. This is the number of timesteps that
|
|
|
|
/// has been completed from the start of the run. The time
|
|
|
|
/// after initialization but before the simulation has started
|
|
|
|
/// is timestep number zero.
|
2021-06-08 08:20:15 -05:00
|
|
|
int currentStepNum() const override;
|
2012-06-14 07:02:22 -05:00
|
|
|
|
|
|
|
/// Set current step number.
|
|
|
|
void setCurrentStepNum(int step);
|
|
|
|
|
2013-11-26 17:36:17 -06:00
|
|
|
/// Current step length. This is the length of the step
|
|
|
|
/// the simulator will take in the next iteration.
|
|
|
|
///
|
|
|
|
/// @note if done(), it is an error to call currentStepLength().
|
2021-06-08 08:20:15 -05:00
|
|
|
double currentStepLength() const override;
|
2012-06-14 07:02:22 -05:00
|
|
|
|
2013-11-26 17:36:17 -06:00
|
|
|
/// Previous step length. This is the length of the step that
|
|
|
|
/// was taken to arrive at this time.
|
|
|
|
///
|
|
|
|
/// @note if no increments have been done (i.e. the timer is
|
|
|
|
/// still in its constructed state and currentStepNum() == 0),
|
|
|
|
/// it is an error to call stepLengthTaken().
|
2021-06-08 08:20:15 -05:00
|
|
|
double stepLengthTaken () const override;
|
2013-11-26 17:36:17 -06:00
|
|
|
|
2014-03-11 09:06:07 -05:00
|
|
|
/// Time elapsed since the start of the simulation until the
|
|
|
|
/// beginning of the current time step [s].
|
2021-06-08 08:20:15 -05:00
|
|
|
double simulationTimeElapsed() const override;
|
2012-06-14 07:02:22 -05:00
|
|
|
|
2012-11-07 07:53:26 -06:00
|
|
|
/// Total time.
|
|
|
|
double totalTime() const;
|
2012-06-14 07:02:22 -05:00
|
|
|
|
2015-01-08 05:06:37 -06:00
|
|
|
/// Return start date of simulation
|
2021-06-08 08:20:15 -05:00
|
|
|
boost::posix_time::ptime startDateTime() const override;
|
2015-01-08 05:06:37 -06:00
|
|
|
|
2012-06-14 07:02:22 -05:00
|
|
|
/// Set total time.
|
|
|
|
/// This is primarily intended for multi-epoch schedules,
|
|
|
|
/// where a timer for a given epoch does not have
|
|
|
|
/// access to later timesteps.
|
2012-11-07 07:53:26 -06:00
|
|
|
void setTotalTime(double time);
|
2012-06-14 07:02:22 -05:00
|
|
|
|
2012-11-07 07:53:26 -06:00
|
|
|
/// Print a report with current and total time etc.
|
|
|
|
/// Note: if done(), it is an error to call report().
|
|
|
|
void report(std::ostream& os) const;
|
2012-06-14 07:02:22 -05:00
|
|
|
|
2015-01-28 08:46:11 -06:00
|
|
|
/// advance time by currentStepLength
|
2012-11-07 07:53:26 -06:00
|
|
|
SimulatorTimer& operator++();
|
2012-06-14 07:02:22 -05:00
|
|
|
|
2015-01-28 08:46:11 -06:00
|
|
|
/// advance time by currentStepLength
|
2021-06-08 08:20:15 -05:00
|
|
|
void advance() override { this->operator++(); }
|
2015-01-28 08:25:11 -06:00
|
|
|
|
2012-11-07 07:53:26 -06:00
|
|
|
/// Return true if op++() has been called numSteps() times.
|
2021-06-08 08:20:15 -05:00
|
|
|
bool done() const override;
|
2012-06-14 07:02:22 -05:00
|
|
|
|
2016-12-05 02:37:30 -06:00
|
|
|
/// Always return false. Timestep failures is handled in the
|
|
|
|
/// substepTimer
|
2021-06-08 08:20:15 -05:00
|
|
|
bool lastStepFailed() const override { return false; }
|
2016-12-05 02:37:30 -06:00
|
|
|
|
2016-03-21 04:53:54 -05:00
|
|
|
/// return copy of object
|
2023-02-13 10:59:35 -06:00
|
|
|
std::unique_ptr<SimulatorTimerInterface> clone() const override;
|
2016-03-21 04:53:54 -05:00
|
|
|
|
2023-01-31 05:09:20 -06:00
|
|
|
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;
|
|
|
|
|
2012-06-14 07:02:22 -05:00
|
|
|
private:
|
2012-11-07 07:53:26 -06:00
|
|
|
std::vector<double> timesteps_;
|
|
|
|
int current_step_;
|
|
|
|
double current_time_;
|
|
|
|
double total_time_;
|
2023-02-13 10:59:35 -06:00
|
|
|
boost::gregorian::date start_date_;
|
2012-06-14 07:02:22 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace Opm
|
|
|
|
|
|
|
|
#endif // OPM_SIMULATORTIMER_HEADER_INCLUDED
|