version 3.8
python/common/timeloop.hh
Go to the documentation of this file.
1// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2// vi: set et ts=4 sw=4 sts=4:
3//
4// SPDX-FileCopyrightInfo: Copyright © DuMux Project contributors, see AUTHORS.md in root folder
5// SPDX-License-Identifier: GPL-3.0-or-later
6//
12#ifndef DUMUX_PYTHON_COMMON_TIMELOOP_HH
13#define DUMUX_PYTHON_COMMON_TIMELOOP_HH
14
16
17#include <dune/python/pybind11/pybind11.h>
18#include <dune/python/pybind11/stl.h>
19
20namespace Dumux::Python {
21
22template <class Scalar, class... options>
23void registerTimeLoop(pybind11::handle scope,
24 pybind11::class_<CheckPointTimeLoop<Scalar>, options...> cls)
25{
26 using pybind11::operator""_a;
27
29 cls.def(pybind11::init([](Scalar startTime, Scalar dt, Scalar endTime, bool verbose){
30 return new TimeLoop(startTime, dt, endTime, verbose);
31 }), "startTime"_a, "dt"_a, "endTime"_a, "verbose"_a=true);
32
33 cls.def_property_readonly("time", &TimeLoop::time);
34 cls.def_property_readonly("timeStepSize", &TimeLoop::timeStepSize);
35 cls.def_property_readonly("finished", &TimeLoop::finished);
36 cls.def_property_readonly("isCheckPoint", &TimeLoop::isCheckPoint);
37 cls.def("start", &TimeLoop::start);
38 cls.def(
39 "reset",
40 static_cast<void(TimeLoop::*)(Scalar, Scalar, Scalar, bool)>(&TimeLoop::reset),
41 "startTime"_a, "dt"_a, "endTime"_a, "verbose"_a=true
42 );
43 cls.def("advanceTimeStep", &TimeLoop::advanceTimeStep);
44 cls.def("setTimeStepSize", static_cast<void(TimeLoop::*)(Scalar)>(&TimeLoop::setTimeStepSize), "dt"_a);
45 cls.def("setMaxTimeStepSize", &TimeLoop::template setMaxTimeStepSize<Scalar>, "dt"_a);
46 cls.def("reportTimeStep", &TimeLoop::reportTimeStep);
47 cls.def("finalize", [](TimeLoop& self){ self.finalize(); });
48 cls.def(
49 "setPeriodicCheckPoint",
50 &TimeLoop::template setPeriodicCheckPoint<Scalar, Scalar>,
51 "interval"_a, "offset"_a=0.0
52 );
53 cls.def("setCheckPoints", [](TimeLoop& self, const std::vector<Scalar>& checkPoints) {
54 self.setCheckPoint(checkPoints.begin(), checkPoints.end());
55 });
56}
57
58template<class Scalar>
59void registerTimeLoop(pybind11::handle scope, const char *clsName = "TimeLoop")
60{
61 pybind11::class_<CheckPointTimeLoop<Scalar>> cls(scope, clsName);
62 registerTimeLoop(scope, cls);
63}
64
65} // namespace Dumux::Python
66
67#endif
A time loop with a check point mechanism.
Definition: common/timeloop.hh:496
The default time loop for instationary simulations.
Definition: common/timeloop.hh:139
void advanceTimeStep() override
Advance time step.
Definition: common/timeloop.hh:239
void start()
Tells the time loop to start tracking the time.
Definition: common/timeloop.hh:169
void finalize(const Communicator &comm=Dune::MPIHelper::getCommunication())
Print final status and stops tracking the time.
Definition: common/timeloop.hh:434
void setTimeStepSize(Scalar dt) final
Set the current time step size to a given value.
Definition: common/timeloop.hh:320
bool finished() const override
Returns true if the simulation is finished.
Definition: common/timeloop.hh:385
void reportTimeStep() const
State info on cpu time.
Definition: common/timeloop.hh:417
Scalar timeStepSize() const final
Returns the suggested time step length so that we don't miss the beginning of the next episode or cr...
Definition: common/timeloop.hh:353
void reset(std::chrono::duration< Rep1, Period1 > startTime, std::chrono::duration< Rep2, Period2 > dt, std::chrono::duration< Rep3, Period3 > tEnd, bool verbose=true)
Reset the time loop.
Definition: common/timeloop.hh:197
Scalar time() const final
Return the time before the time integration. To get the time after the time integration you have to ...
Definition: common/timeloop.hh:282
Manages the handling of time dependent problems.
Definition: python/assembly/fvassembler.hh:18
void registerTimeLoop(pybind11::handle scope, pybind11::class_< CheckPointTimeLoop< Scalar >, options... > cls)
Definition: python/common/timeloop.hh:23
TimeLoop(std::chrono::duration< Rep1, Period1 >, std::chrono::duration< Rep2, Period2 >, std::chrono::duration< Rep3, Period3 >, bool verbose=true) -> TimeLoop< std::conditional_t< std::is_floating_point_v< std::common_type_t< Rep1, Rep2, Rep3 > >, std::common_type_t< Rep1, Rep2, Rep3 >, double > >