Mallard 0.8.0
Unstructured, GPU accelerated, high-order finite volume CFD solver
Mallard website
Loading...
Searching...
No Matches
time_integrator.h
Go to the documentation of this file.
1
12#ifndef TIME_INTEGRATOR_H
13#define TIME_INTEGRATOR_H
14
15#include <functional>
16#include <string>
17#include <unordered_map>
18#include <vector>
19
20#include <Kokkos_Core.hpp>
21
22#include "common.h"
23#include "state.h"
24
26 FE,
27 RK4,
28 SSPRK3,
29};
30
31static const std::unordered_map<std::string, TimeIntegratorType> TIME_INTEGRATOR_TYPES = {
35};
36
37static const std::unordered_map<TimeIntegratorType, std::string> TIME_INTEGRATOR_NAMES = {
41};
42
43using RHSFunction = std::function<void(State solution, State rhs, rtype t)>;
44
52void axpby(const rtype a, const State & x, const rtype b, const State & y, const rtype * a_device = nullptr);
53
55enum DtScale { DT = 0, DT_HALF = 1, DT_SIXTH = 2, DT_THIRD = 3, N_DT_SCALES = 4 };
56
59void dt_scales(const rtype dt, rtype * scales) {
60 scales[DT] = dt;
61 scales[DT_HALF] = 0.5_r * dt;
62 scales[DT_SIXTH] = dt / 6.0_r;
63 scales[DT_THIRD] = dt / 3.0_r;
64}
65
71void lerp(const rtype a, const State & x, const State & y);
72
74 public:
75 virtual ~TimeIntegrator() = default;
76
77 TimeIntegratorType get_type() const { return type; }
80
91 virtual void take_step(const rtype t, const rtype dt,
92 std::vector<State> & solution_vec,
93 std::vector<State> & rhs_vec,
94 const RHSFunction & calc_rhs, const rtype * dt_device = nullptr) = 0;
95
96 protected:
100};
101
102class FE : public TimeIntegrator {
103 public:
104 FE();
105 void take_step(const rtype t, const rtype dt,
106 std::vector<State> & solution_vec,
107 std::vector<State> & rhs_vec,
108 const RHSFunction & calc_rhs, const rtype * dt_device = nullptr) override;
109};
110
111class RK4 : public TimeIntegrator {
112 public:
113 RK4();
114 void take_step(const rtype t, const rtype dt,
115 std::vector<State> & solution_vec,
116 std::vector<State> & rhs_vec,
117 const RHSFunction & calc_rhs, const rtype * dt_device = nullptr) override;
118};
119
124class SSPRK3 : public TimeIntegrator {
125 public:
126 SSPRK3();
127 void take_step(const rtype t, const rtype dt,
128 std::vector<State> & solution_vec,
129 std::vector<State> & rhs_vec,
130 const RHSFunction & calc_rhs, const rtype * dt_device = nullptr) override;
131};
132
133#endif // TIME_INTEGRATOR_H
Definition time_integrator.h:102
FE()
Definition time_integrator.cpp:49
void take_step(const rtype t, const rtype dt, std::vector< State > &solution_vec, std::vector< State > &rhs_vec, const RHSFunction &calc_rhs, const rtype *dt_device=nullptr) override
Advance solution_vec[0] from time t by dt.
Definition time_integrator.cpp:55
Definition time_integrator.h:111
RK4()
Definition time_integrator.cpp:65
void take_step(const rtype t, const rtype dt, std::vector< State > &solution_vec, std::vector< State > &rhs_vec, const RHSFunction &calc_rhs, const rtype *dt_device=nullptr) override
Advance solution_vec[0] from time t by dt.
Definition time_integrator.cpp:71
Three-stage, third-order strong-stability-preserving Runge-Kutta (Shu & Osher 1988).
Definition time_integrator.h:124
SSPRK3()
Definition time_integrator.cpp:101
void take_step(const rtype t, const rtype dt, std::vector< State > &solution_vec, std::vector< State > &rhs_vec, const RHSFunction &calc_rhs, const rtype *dt_device=nullptr) override
Advance solution_vec[0] from time t by dt.
Definition time_integrator.cpp:107
Definition time_integrator.h:73
uint8_t n_solution_vectors
Definition time_integrator.h:98
TimeIntegratorType get_type() const
Definition time_integrator.h:77
virtual ~TimeIntegrator()=default
uint8_t get_n_solution_vectors() const
Definition time_integrator.h:78
uint8_t n_rhs_vectors
Definition time_integrator.h:99
virtual void take_step(const rtype t, const rtype dt, std::vector< State > &solution_vec, std::vector< State > &rhs_vec, const RHSFunction &calc_rhs, const rtype *dt_device=nullptr)=0
Advance solution_vec[0] from time t by dt.
uint8_t get_n_rhs_vectors() const
Definition time_integrator.h:79
TimeIntegratorType type
Definition time_integrator.h:97
Common header file.
KOKKOS_INLINE_FUNCTION rtype dot(const rtype *a, const rtype *b)
Compute the dot product of two arrays.
Definition common_math.h:32
float rtype
Definition common_typedef.h:39
Conservative state: the flow block and the species partial densities.
Conservative state of every cell: the flow block and the partial densities of a mixture's species....
Definition state.h:56
void axpby(const rtype a, const State &x, const rtype b, const State &y, const rtype *a_device=nullptr)
y = a * x + b * y, on both blocks of the state.
Definition time_integrator.cpp:15
std::function< void(State solution, State rhs, rtype t)> RHSFunction
Definition time_integrator.h:43
TimeIntegratorType
Definition time_integrator.h:25
KOKKOS_INLINE_FUNCTION void dt_scales(const rtype dt, rtype *scales)
The multiples of dt that the integrators use, as take_step's device dt_scales holds them.
Definition time_integrator.h:59
DtScale
Index of each multiple of dt in the device array of take_step's dt_scales.
Definition time_integrator.h:55
@ DT_THIRD
Definition time_integrator.h:55
@ DT
Definition time_integrator.h:55
@ DT_HALF
Definition time_integrator.h:55
@ N_DT_SCALES
Definition time_integrator.h:55
@ DT_SIXTH
Definition time_integrator.h:55
void lerp(const rtype a, const State &x, const State &y)
y = (1 - a) y + a x as y + a (x - y), on both blocks of the state: unlike axpby with rounded weights ...
Definition time_integrator.cpp:30