/home/runner/work/DiFfRG_current/DiFfRG_current/DiFfRG/include/DiFfRG/model/model.hh Source File#

DiFfRG: /home/runner/work/DiFfRG_current/DiFfRG_current/DiFfRG/include/DiFfRG/model/model.hh Source File
DiFfRG
model.hh
Go to the documentation of this file.
1#pragma once
2
3// external libraries
5#include <deal.II/base/point.h>
6#include <deal.II/base/tensor.h>
7
8// DiFfRG
9#include <DiFfRG/model/ad.hh>
12
13namespace DiFfRG
14{
15 using namespace dealii;
16
21 namespace def
22 {
31 template <typename Model, typename Components_> class AbstractModel
32 {
33 Model &asImp()
34 {
35 static_assert(
36 std::is_base_of_v<AbstractModel<Model, Components_>, Model>,
37 "AbstractModel<Model, Components>: Model must inherit from AbstractModel<Model, Components> (CRTP). "
38 "Check that your model class passes itself as the first template argument.");
39 return static_cast<Model &>(*this);
40 }
41 const Model &asImp() const
42 {
43 static_assert(
44 std::is_base_of_v<AbstractModel<Model, Components_>, Model>,
45 "AbstractModel<Model, Components>: Model must inherit from AbstractModel<Model, Components> (CRTP). "
46 "Check that your model class passes itself as the first template argument.");
47 return static_cast<const Model &>(*this);
48 }
49
50 protected:
51 Components_ m_components;
52 auto &components() { return m_components; }
53
54 public:
55 const auto &get_components() const { return m_components; }
56 using Components = Components_;
61
71 template <int dim, typename Vector> void initial_condition(const Point<dim> &x, Vector &u_i) const = delete;
72
90 template <int dim, typename NumberType, typename Vector, typename Vector_dot, size_t n_fe_functions>
91 void mass(std::array<NumberType, n_fe_functions> &m_i, const Point<dim> &x, const Vector &u_i,
92 const Vector_dot &dt_u_i) const
93 {
94 // Just to avoid warnings
95 (void)x;
96 (void)u_i;
97
98 for (uint i = 0; i < n_fe_functions; ++i)
99 m_i[i] = dt_u_i[i];
100 }
101
116 template <int dim, typename NumberType, size_t n_fe_functions>
117 void mass(std::array<std::array<NumberType, n_fe_functions>, n_fe_functions> &m_ij, const Point<dim> &x) const
118 {
119 // Just to avoid warnings
120 (void)x;
121
122 for (uint i = 0; i < n_fe_functions; ++i)
123 for (uint j = 0; j < n_fe_functions; ++j)
124 m_ij[i][j] = 0.;
125 for (uint i = 0; i < n_fe_functions; ++i)
126 m_ij[i][i] = 1.;
127 }
128
149 template <int dim, typename NumberType, typename Solutions, size_t n_fe_functions>
150 void flux(std::array<Tensor<1, dim, NumberType>, n_fe_functions> &F_i, const Point<dim> &x,
151 const Solutions &sol) const
152 {
153 // Just to avoid warnings
154 (void)F_i;
155 (void)x;
156 (void)sol;
157 }
158
179 template <int dim, typename NumberType, typename Solutions, size_t n_fe_functions>
180 void source(std::array<NumberType, n_fe_functions> &s_i, const Point<dim> &x, const Solutions &sol) const
181 {
182 // Just to avoid warnings
183 (void)s_i;
184 (void)x;
185 (void)sol;
186 }
187
197 template <uint dim> std::vector<bool> differential_components() const
198 {
199 std::vector<bool> differential_components(Model::Components::count_fe_functions(), false);
200
201 // First we need two reference solutions u_i and dt_u_i, which we then both fill with 1.s
202 std::array<double, Model::Components::count_fe_functions()> u_i{{}};
203 std::array<double, Model::Components::count_fe_functions()> dt_u_i{{}};
204 for (uint i = 0; i < Model::Components::count_fe_functions(); ++i) {
205 u_i[i] = 1.;
206 dt_u_i[i] = 1.;
207 }
208 // Set the point to be at 1. in all directions
209 Point<dim> x;
210 for (uint i = 0; i < dim; ++i)
211 x[i] = 1.;
212 // Get the mass function m_i
213 std::array<double, Model::Components::count_fe_functions()> m_i{{}};
214 asImp().mass(m_i, x, u_i, dt_u_i);
215
216 // Now we check which components are differential by changing dt_u_i slightly and checking whether the mass
217 // function changes.
218 for (uint i = 0; i < Model::Components::count_fe_functions(); ++i) {
219 dt_u_i[i] = 1. + 1e-1;
220 std::array<double, Model::Components::count_fe_functions()> m_i_new{{}};
221 asImp().mass(m_i_new, x, u_i, dt_u_i);
222 dt_u_i[i] = 1.;
223 for (uint j = 0; j < Model::Components::count_fe_functions(); ++j)
224 if (!is_close(m_i[j], m_i_new[j])) differential_components[j] = true;
225 }
226
228 }
229
231
235
236 template <typename Vector> void initial_condition_variables(Vector &v_a) const
237 {
238 // Just to avoid warnings
239 (void)v_a;
240 }
241
242 template <typename Vector, typename Solution> void dt_variables(Vector &r_a, const Solution &sol) const
243 {
244 // Just to avoid warnings
245 (void)r_a;
246 (void)sol;
247 }
248
250
254
255 template <int dim, typename Vector, typename Solutions>
256 void extract(Vector &, const Point<dim> &, const Solutions &) const
257 {
258 }
259
261
265
288 template <uint dependent, int dim, typename NumberType, typename Vector, size_t n_fe_functions_dep>
289 void ldg_flux(std::array<Tensor<1, dim, NumberType>, n_fe_functions_dep> &F, const Point<dim> &x,
290 const Vector &u) const
291 {
292 (void)F;
293 (void)x;
294 (void)u;
295 }
296
319 template <uint dependent, int dim, typename NumberType, typename Vector, size_t n_fe_functions_dep>
320 void ldg_source(std::array<NumberType, n_fe_functions_dep> &s, const Point<dim> &x, const Vector &u) const
321 {
322 (void)s;
323 (void)x;
324 (void)u;
325 }
326
328
332
333 template <int dim, typename NumberType, typename Solutions_s, typename Solutions_n>
334 void face_indicator(std::array<NumberType, 2> & /*indicator*/, const Tensor<1, dim> & /*normal*/,
335 const Point<dim> & /*p*/, const Solutions_s & /*sol_s*/, const Solutions_n & /*sol_n*/) const
336 {
337 }
338
339 template <int dim, typename NumberType, typename Solution>
340 void cell_indicator(NumberType & /*indicator*/, const Point<dim> & /*p*/, const Solution & /*sol*/) const
341 {
342 }
344
348
349 template <int dim, typename Vector> std::array<double, dim> EoM(const Point<dim> &x, const Vector &u) const
350 {
351 // Just to avoid warnings
352 (void)x;
353 return std::array<double, dim>{{u[0]}};
354 }
355
356 template <int dim, typename Vector> Point<dim> EoM_postprocess(const Point<dim> &EoM, const Vector &) const
357 {
358 return EoM;
359 }
360
361 template <typename FUN, typename DataOut> void readouts_multiple(FUN &helper, DataOut &) const
362 {
363 helper([&](const auto &x, const auto &u_i) { return asImp().EoM(x, u_i); }, // chiral EoM
364 [&](auto &output, const auto &x, const auto &sol) { asImp().readouts(output, x, sol); });
365 }
366
367 template <int dim, typename DataOut, typename Solutions>
368 void readouts(DataOut &output, const Point<dim> &x, const Solutions &sol) const
369 {
370 // Just to avoid warnings
371 (void)output;
372 (void)x;
373 (void)sol;
374 }
375
376 template <int dim, typename Constraints>
377 void affine_constraints(Constraints &constraints, const std::vector<IndexSet> &component_boundary_dofs,
378 const std::vector<std::vector<Point<dim>>> &component_boundary_points)
379 {
380 // Just to avoid warnings
381 (void)constraints;
382 (void)component_boundary_dofs;
383 (void)component_boundary_points;
384 }
385
387 };
388
389 class Time
390 {
391 public:
392 void set_time(double t);
393 const double &get_time() const;
394
395 protected:
396 double t;
397 };
398
402 class fRG
403 {
404 public:
410 fRG(double Lambda);
411
417 fRG(const JSONValue &json);
418
424 void set_time(double t);
425
431 const double &get_time() const;
432
433 protected:
434 const double Lambda;
435 double t = 0., k = 0., k2 = 0., k3 = 0., k4 = 0., k5 = 0., k6 = 0.;
436 bool time_initialized = false;
437 };
438 } // namespace def
439} // namespace DiFfRG
A wrapper around the boost json value class.
Definition json.hh:19
The abstract interface for any numerical model. Most methods have a standard implementation,...
Definition model.hh:32
std::vector< bool > differential_components() const
A method to find out which components of the mass function are differential when using a DAE.
Definition model.hh:197
void dt_variables(Vector &r_a, const Solution &sol) const
Definition model.hh:242
void source(std::array< NumberType, n_fe_functions > &s_i, const Point< dim > &x, const Solutions &sol) const
The source function is implemented by this method.
Definition model.hh:180
auto & components()
Definition model.hh:52
const Model & asImp() const
Definition model.hh:41
Components_ m_components
Definition model.hh:51
void cell_indicator(NumberType &, const Point< dim > &, const Solution &) const
Definition model.hh:340
void mass(std::array< std::array< NumberType, n_fe_functions >, n_fe_functions > &m_ij, const Point< dim > &x) const
If not using a DAE, the mass matrix is implemented in this method.
Definition model.hh:117
Model & asImp()
Definition model.hh:33
const auto & get_components() const
Definition model.hh:55
void flux(std::array< Tensor< 1, dim, NumberType >, n_fe_functions > &F_i, const Point< dim > &x, const Solutions &sol) const
The flux function is implemented by this method.
Definition model.hh:150
void ldg_flux(std::array< Tensor< 1, dim, NumberType >, n_fe_functions_dep > &F, const Point< dim > &x, const Vector &u) const
The LDG flux function is implemented by this method.
Definition model.hh:289
void face_indicator(std::array< NumberType, 2 > &, const Tensor< 1, dim > &, const Point< dim > &, const Solutions_s &, const Solutions_n &) const
Definition model.hh:334
void mass(std::array< NumberType, n_fe_functions > &m_i, const Point< dim > &x, const Vector &u_i, const Vector_dot &dt_u_i) const
The mass function is implemented in this method.
Definition model.hh:91
void extract(Vector &, const Point< dim > &, const Solutions &) const
Definition model.hh:256
void readouts_multiple(FUN &helper, DataOut &) const
Definition model.hh:361
void initial_condition(const Point< dim > &x, Vector &u_i) const =delete
This method implements the initial condition for the FE functions.
void affine_constraints(Constraints &constraints, const std::vector< IndexSet > &component_boundary_dofs, const std::vector< std::vector< Point< dim > > > &component_boundary_points)
Definition model.hh:377
void ldg_source(std::array< NumberType, n_fe_functions_dep > &s, const Point< dim > &x, const Vector &u) const
The LDG source function is implemented by this method.
Definition model.hh:320
std::array< double, dim > EoM(const Point< dim > &x, const Vector &u) const
Definition model.hh:349
void initial_condition_variables(Vector &v_a) const
Definition model.hh:236
void readouts(DataOut &output, const Point< dim > &x, const Solutions &sol) const
Definition model.hh:368
Point< dim > EoM_postprocess(const Point< dim > &EoM, const Vector &) const
Definition model.hh:356
Components_ Components
Definition model.hh:56
Definition model.hh:390
const double & get_time() const
void set_time(double t)
double t
Definition model.hh:396
The fRG class is used to keep track of the RG time and the cutoff scale.
Definition model.hh:403
double k3
Definition model.hh:435
double k
Definition model.hh:435
double k4
Definition model.hh:435
double k6
Definition model.hh:435
fRG(const JSONValue &json)
Construct a new fRG object from a given JSONValue object.
double t
Definition model.hh:435
fRG(double Lambda)
Construct a new fRG object from a given initial cutoff scale.
double k5
Definition model.hh:435
const double Lambda
Definition model.hh:434
bool time_initialized
Definition model.hh:436
void set_time(double t)
Set the time of the fRG object, updating the cutoff scale and its powers.
const double & get_time() const
Get the time of the fRG object.
double k2
Definition model.hh:435
Definition complex_math.hh:10
bool KOKKOS_INLINE_FUNCTION is_close(T1 a, T2 b, T3 eps_)
Function to evaluate whether two floats are equal to numerical precision. Tests for both relative and...
Definition math.hh:168
unsigned int uint
Definition utils.hh:24