DiFfRG
Loading...
Searching...
No Matches
abstract_timestepper.hh
Go to the documentation of this file.
1#pragma once
2
3// DiFfRG
11
12namespace DiFfRG
13{
45 template <typename VectorType_, typename SparseMatrixType_, uint dim_> class AbstractTimestepper
46 {
47 protected:
48 static constexpr uint dim = dim_;
49 using VectorType = VectorType_;
51 using SparseMatrixType = SparseMatrixType_;
53 static_assert(std::is_same_v<VectorType, Vector<NumberType>>, "VectorType must not be Vector<double>!");
54 using BlockVectorType = dealii::BlockVector<NumberType>;
55
56 public:
68 start_time(std::chrono::high_resolution_clock::now())
69 {
70 verbosity = json.get_int("/output/verbosity");
71 output_dt = json.get_double("/timestepping/output_dt");
72
73 impl.dt = json.get_double("/timestepping/implicit/dt");
74 impl.minimal_dt = json.get_double("/timestepping/implicit/minimal_dt");
75 impl.maximal_dt = json.get_double("/timestepping/implicit/maximal_dt");
76 impl.abs_tol = json.get_double("/timestepping/implicit/abs_tol");
77 impl.rel_tol = json.get_double("/timestepping/implicit/rel_tol");
78
79 expl.dt = json.get_double("/timestepping/explicit/dt");
80 expl.minimal_dt = json.get_double("/timestepping/explicit/minimal_dt");
81 expl.maximal_dt = json.get_double("/timestepping/explicit/maximal_dt");
82 expl.abs_tol = json.get_double("/timestepping/explicit/abs_tol");
83 expl.rel_tol = json.get_double("/timestepping/explicit/rel_tol");
84
85 try {
86 Lambda = json.get_double("/physical/Lambda");
87 } catch (std::exception &e) {
88 Lambda = -1.0;
89 }
90 }
91
99 {
100 if (data_out == nullptr) {
101 data_out_default = std::make_shared<DataOutput<dim, VectorType>>(json);
102 return data_out_default.get();
103 }
104 return data_out;
105 }
106
114 {
115 if (adaptor == nullptr) {
116 adaptor_default = std::make_shared<NoAdaptivity<VectorType>>();
117 return adaptor_default.get();
118 }
119 return adaptor;
120 }
121
129 virtual void run(AbstractFlowingVariables<NumberType> *initial_condition, const double t_start,
130 const double t_stop) = 0;
131
132 protected:
137
138 const std::chrono::time_point<std::chrono::high_resolution_clock> start_time;
139
140 std::shared_ptr<NoAdaptivity<VectorType>> adaptor_default;
141 std::shared_ptr<DataOutput<dim, VectorType>> data_out_default;
142
143 double Lambda;
145 double output_dt;
147 double dt;
150 double abs_tol;
151 double rel_tol;
153
155 double dt;
158 double abs_tol;
159 double rel_tol;
161
170 void console_out(const double t, const std::string name, const int verbosity_level,
171 const double calc_dt_ms = -1.0) const
172 {
173 if (verbosity >= verbosity_level) {
174 std::ios_base::fmtflags oldflags = std::cout.flags();
175 std::cout << "[" << name << "]";
176 std::cout << " t: " << std::setw(10) << std::left << std::setprecision(4) << std::scientific << t;
177 if (Lambda > 0.0) {
178 std::cout << " | k: " << std::setw(10) << std::left << std::setprecision(4) << std::scientific
179 << exp(-t) * Lambda;
180 }
181 if (calc_dt_ms >= 0.0) {
182 std::cout << " | calc_dt: " << time_format_ms(size_t(calc_dt_ms));
183 }
184 size_t milliseconds = std::chrono::duration_cast<std::chrono::milliseconds>(
185 std::chrono::high_resolution_clock::now() - start_time)
186 .count();
187 std::cout << " | calc_t: " << time_format_ms(milliseconds);
188 std::cout << std::endl;
189 std::cout.flags(oldflags);
190 }
191 }
192 };
193} // namespace DiFfRG
Implement a simple interface to do all adaptivity tasks, i.e. solution transfer, reinit of dofHandler...
Definition abstract_adaptor.hh:11
This is the general assembler interface for any kind of discretization. An assembler is responsible f...
Definition abstract_assembler.hh:39
A class to set up initial data for whatever discretization we have chosen. Also used to switch/manage...
Definition abstract_data.hh:18
The abstract base class for all timestepping algorithms. It provides a standard constructor which pop...
Definition abstract_timestepper.hh:46
VectorType_ VectorType
Definition abstract_timestepper.hh:49
dealii::BlockVector< NumberType > BlockVectorType
Definition abstract_timestepper.hh:54
int verbosity
Definition abstract_timestepper.hh:144
AbstractAssembler< VectorType, SparseMatrixType, dim > * assembler
Definition abstract_timestepper.hh:134
std::shared_ptr< DataOutput< dim, VectorType > > data_out_default
Definition abstract_timestepper.hh:141
double Lambda
Definition abstract_timestepper.hh:143
void console_out(const double t, const std::string name, const int verbosity_level, const double calc_dt_ms=-1.0) const
Pretty-print the status of the timestepping algorithm to the console.
Definition abstract_timestepper.hh:170
SparseMatrixType_ SparseMatrixType
Definition abstract_timestepper.hh:51
DataOutput< dim, VectorType > * data_out
Definition abstract_timestepper.hh:135
const std::chrono::time_point< std::chrono::high_resolution_clock > start_time
Definition abstract_timestepper.hh:138
AbstractTimestepper(const JSONValue &json, AbstractAssembler< VectorType, SparseMatrixType, dim > *assembler, DataOutput< dim, VectorType > *data_out=nullptr, AbstractAdaptor< VectorType > *adaptor=nullptr)
Construct a new Abstract Timestepper object.
Definition abstract_timestepper.hh:65
AbstractAdaptor< VectorType > * adaptor
Definition abstract_timestepper.hh:136
std::shared_ptr< NoAdaptivity< VectorType > > adaptor_default
Definition abstract_timestepper.hh:140
virtual void run(AbstractFlowingVariables< NumberType > *initial_condition, const double t_start, const double t_stop)=0
Any derived class must implement this method to run the timestepping algorithm.
typename get_type::NumberType< VectorType > NumberType
Definition abstract_timestepper.hh:50
DataOutput< dim, VectorType > * get_data_out()
Utility function to obtain a DataOutput object. If no DataOutput object is provided,...
Definition abstract_timestepper.hh:98
typename get_type::InverseSparseMatrixType< SparseMatrixType > InverseSparseMatrixType
Definition abstract_timestepper.hh:52
struct DiFfRG::AbstractTimestepper::implicitParameters impl
AbstractAdaptor< VectorType > * get_adaptor()
Utility function to obtain an Adaptor object. If no Adaptor object is provided, a default one is crea...
Definition abstract_timestepper.hh:113
const JSONValue json
Definition abstract_timestepper.hh:133
static constexpr uint dim
Definition abstract_timestepper.hh:48
struct DiFfRG::AbstractTimestepper::explicitParameters expl
double output_dt
Definition abstract_timestepper.hh:145
Class to manage writing to files. FEM functions are written to vtk files and other data is written to...
Definition data_output.hh:20
A wrapper around the boost json value class.
Definition json.hh:19
double get_double(const std::string &key) const
Get the value of a key in the json object.
int get_int(const std::string &key) const
Get the value of a key in the json object.
typename internal::_NumberType< VectorType >::value NumberType
Definition types.hh:61
typename internal::_InverseSparseMatrixType< SparseMatrixType >::value InverseSparseMatrixType
Definition types.hh:67
Definition complex_math.hh:14
std::string time_format_ms(size_t time_in_miliseconds)
Nice output from seconds to h/min/s style string.
unsigned int uint
Definition utils.hh:22
Definition tuples.hh:117
Definition abstract_timestepper.hh:154
double rel_tol
Definition abstract_timestepper.hh:159
double maximal_dt
Definition abstract_timestepper.hh:157
double abs_tol
Definition abstract_timestepper.hh:158
double dt
Definition abstract_timestepper.hh:155
double minimal_dt
Definition abstract_timestepper.hh:156
Definition abstract_timestepper.hh:146
double maximal_dt
Definition abstract_timestepper.hh:149
double abs_tol
Definition abstract_timestepper.hh:150
double minimal_dt
Definition abstract_timestepper.hh:148
double dt
Definition abstract_timestepper.hh:147
double rel_tol
Definition abstract_timestepper.hh:151