/__w/DiFfRG_current/DiFfRG_current/DiFfRG/include/DiFfRG/model/model.hh Source File#

DiFfRG: /__w/DiFfRG_current/DiFfRG_current/DiFfRG/include/DiFfRG/model/model.hh Source File
DiFfRG
Discretization Framework for functional Renormalization Group flows
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 {
32 template <typename Model, typename Components_> class AbstractModel
33 {
34 Model &asImp()
35 {
36 static_assert(
37 std::is_base_of_v<AbstractModel<Model, Components_>, Model>,
38 "AbstractModel<Model, Components>: Model must inherit from AbstractModel<Model, Components> (CRTP). "
39 "Check that your model class passes itself as the first template argument.");
40 return static_cast<Model &>(*this);
41 }
42 const Model &asImp() const
43 {
44 static_assert(
45 std::is_base_of_v<AbstractModel<Model, Components_>, Model>,
46 "AbstractModel<Model, Components>: Model must inherit from AbstractModel<Model, Components> (CRTP). "
47 "Check that your model class passes itself as the first template argument.");
48 return static_cast<const Model &>(*this);
49 }
50
51 protected:
52 Components_ m_components;
53 auto &components() { return m_components; }
54
55 public:
56 const auto &get_components() const { return m_components; }
57 using Components = Components_;
62
72 template <int dim, typename Vector> void initial_condition(const Point<dim> &x, Vector &u_i) const = delete;
73
91 template <int dim, typename NumberType, typename Vector, typename Vector_dot, size_t n_fe_functions>
92 void mass(std::array<NumberType, n_fe_functions> &m_i, const Point<dim> &x, const Vector &u_i,
93 const Vector_dot &dt_u_i) const
94 {
95 // Just to avoid warnings
96 (void)x;
97 (void)u_i;
98
99 for (uint i = 0; i < n_fe_functions; ++i)
100 m_i[i] = dt_u_i[i];
101 }
102
117 template <int dim, typename NumberType, size_t n_fe_functions>
118 void mass(std::array<std::array<NumberType, n_fe_functions>, n_fe_functions> &m_ij, const Point<dim> &x) const
119 {
120 // Just to avoid warnings
121 (void)x;
122
123 for (uint i = 0; i < n_fe_functions; ++i)
124 for (uint j = 0; j < n_fe_functions; ++j)
125 m_ij[i][j] = 0.;
126 for (uint i = 0; i < n_fe_functions; ++i)
127 m_ij[i][i] = 1.;
128 }
129
150 template <int dim, typename NumberType, typename Solutions, size_t n_fe_functions>
151 void flux(std::array<Tensor<1, dim, NumberType>, n_fe_functions> &F_i, const Point<dim> &x,
152 const Solutions &sol) const
153 {
154 // Just to avoid warnings
155 (void)F_i;
156 (void)x;
157 (void)sol;
158 }
159
180 template <int dim, typename NumberType, typename Solutions, size_t n_fe_functions>
181 void source(std::array<NumberType, n_fe_functions> &s_i, const Point<dim> &x, const Solutions &sol) const
182 {
183 // Just to avoid warnings
184 (void)s_i;
185 (void)x;
186 (void)sol;
187 }
188
198 template <uint dim> std::vector<bool> differential_components() const
199 {
200 std::vector<bool> differential_components(Model::Components::count_fe_functions(), false);
201
202 // First we need two reference solutions u_i and dt_u_i, which we then both fill with 1.s
203 std::array<double, Model::Components::count_fe_functions()> u_i{{}};
204 std::array<double, Model::Components::count_fe_functions()> dt_u_i{{}};
205 for (uint i = 0; i < Model::Components::count_fe_functions(); ++i) {
206 u_i[i] = 1.;
207 dt_u_i[i] = 1.;
208 }
209 // Set the point to be at 1. in all directions
210 Point<dim> x;
211 for (uint i = 0; i < dim; ++i)
212 x[i] = 1.;
213 // Get the mass function m_i
214 std::array<double, Model::Components::count_fe_functions()> m_i{{}};
215 asImp().mass(m_i, x, u_i, dt_u_i);
216
217 // Now we check which components are differential by changing dt_u_i slightly and checking whether the mass
218 // function changes.
219 for (uint i = 0; i < Model::Components::count_fe_functions(); ++i) {
220 dt_u_i[i] = 1. + 1e-1;
221 std::array<double, Model::Components::count_fe_functions()> m_i_new{{}};
222 asImp().mass(m_i_new, x, u_i, dt_u_i);
223 dt_u_i[i] = 1.;
224 for (uint j = 0; j < Model::Components::count_fe_functions(); ++j)
225 if (!is_close(m_i[j], m_i_new[j])) differential_components[j] = true;
226 }
227
229 }
230
232
236
237 template <typename Vector> void initial_condition_variables(Vector &v_a) const
238 {
239 // Just to avoid warnings
240 (void)v_a;
241 }
242
243 template <typename Vector, typename Solution> void dt_variables(Vector &r_a, const Solution &sol) const
244 {
245 // Just to avoid warnings
246 (void)r_a;
247 (void)sol;
248 }
249
251
255
256 template <int dim, typename Vector, typename Solutions>
257 void extract(Vector &, const Point<dim> &, const Solutions &) const
258 {
259 }
260
262
266
289 template <uint dependent, int dim, typename NumberType, typename Vector, size_t n_fe_functions_dep>
290 void ldg_flux(std::array<Tensor<1, dim, NumberType>, n_fe_functions_dep> &F, const Point<dim> &x,
291 const Vector &u) const
292 {
293 (void)F;
294 (void)x;
295 (void)u;
296 }
297
320 template <uint dependent, int dim, typename NumberType, typename Vector, size_t n_fe_functions_dep>
321 void ldg_source(std::array<NumberType, n_fe_functions_dep> &s, const Point<dim> &x, const Vector &u) const
322 {
323 (void)s;
324 (void)x;
325 (void)u;
326 }
327
329
333
334 template <int dim, typename NumberType, typename Solutions_s, typename Solutions_n>
335 void face_indicator(std::array<NumberType, 2> & /*indicator*/, const Tensor<1, dim> & /*normal*/,
336 const Point<dim> & /*p*/, const Solutions_s & /*sol_s*/, const Solutions_n & /*sol_n*/) const
337 {
338 }
339
340 template <int dim, typename NumberType, typename Solution>
341 void cell_indicator(NumberType & /*indicator*/, const Point<dim> & /*p*/, const Solution & /*sol*/) const
342 {
343 }
345
349
350 template <int dim, typename Vector> std::array<double, dim> EoM(const Point<dim> &x, const Vector &u) const
351 {
352 // Just to avoid warnings
353 (void)x;
354 return std::array<double, dim>{{u[0]}};
355 }
356
357 template <int dim, typename Vector> Point<dim> EoM_postprocess(const Point<dim> &EoM, const Vector &) const
358 {
359 return EoM;
360 }
361
362 template <typename FUN, typename DataOut> void readouts_multiple(FUN &helper, DataOut &) const
363 {
364 helper([&](const auto &x, const auto &u_i) { return asImp().EoM(x, u_i); }, // chiral EoM
365 [&](auto &output, const auto &x, const auto &sol) { asImp().readouts(output, x, sol); });
366 }
367
368 template <int dim, typename DataOut, typename Solutions>
369 void readouts(DataOut &output, const Point<dim> &x, const Solutions &sol) const
370 {
371 // Just to avoid warnings
372 (void)output;
373 (void)x;
374 (void)sol;
375 }
376
377 template <int dim, typename Constraints>
378 void affine_constraints(Constraints &constraints, const std::vector<IndexSet> &component_boundary_dofs,
379 const std::vector<std::vector<Point<dim>>> &component_boundary_points)
380 {
381 // Just to avoid warnings
382 (void)constraints;
383 (void)component_boundary_dofs;
384 (void)component_boundary_points;
385 }
386
388 };
389
390 class Time
391 {
392 public:
393 void set_time(double t);
394 const double &get_time() const;
395
396 protected:
397 double t;
398 };
399
403 class fRG
404 {
405 public:
411 fRG(double Lambda);
412
418 fRG(const JSONValue &json);
419
425 void set_time(double t);
426
432 const double &get_time() const;
433
434 protected:
435 const double Lambda;
436 double t = 0., k = 0., k2 = 0., k3 = 0., k4 = 0., k5 = 0., k6 = 0.;
437 bool time_initialized = false;
438 };
439 } // namespace def
440} // 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:33
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:198
void dt_variables(Vector &r_a, const Solution &sol) const
Definition model.hh:243
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:181
auto & components()
Definition model.hh:53
const Model & asImp() const
Definition model.hh:42
Components_ m_components
Definition model.hh:52
void cell_indicator(NumberType &, const Point< dim > &, const Solution &) const
Definition model.hh:341
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:118
Model & asImp()
Definition model.hh:34
const auto & get_components() const
Definition model.hh:56
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:151
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:290
void face_indicator(std::array< NumberType, 2 > &, const Tensor< 1, dim > &, const Point< dim > &, const Solutions_s &, const Solutions_n &) const
Definition model.hh:335
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:92
void extract(Vector &, const Point< dim > &, const Solutions &) const
Definition model.hh:257
void readouts_multiple(FUN &helper, DataOut &) const
Definition model.hh:362
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:378
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:321
std::array< double, dim > EoM(const Point< dim > &x, const Vector &u) const
Definition model.hh:350
void initial_condition_variables(Vector &v_a) const
Definition model.hh:237
void readouts(DataOut &output, const Point< dim > &x, const Solutions &sol) const
Definition model.hh:369
Point< dim > EoM_postprocess(const Point< dim > &EoM, const Vector &) const
Definition model.hh:357
Components_ Components
Definition model.hh:57
Definition model.hh:391
const double & get_time() const
void set_time(double t)
double t
Definition model.hh:397
The fRG class is used to keep track of the RG time and the cutoff scale.
Definition model.hh:404
double k3
Definition model.hh:436
double k
Definition model.hh:436
double k4
Definition model.hh:436
double k6
Definition model.hh:436
fRG(const JSONValue &json)
Construct a new fRG object from a given JSONValue object.
double t
Definition model.hh:436
fRG(double Lambda)
Construct a new fRG object from a given initial cutoff scale.
double k5
Definition model.hh:436
const double Lambda
Definition model.hh:435
bool time_initialized
Definition model.hh:437
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:436
Definition complex_math.hh:10
::value 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