1 #ifndef COSMO_UTILS_RK4REGISTER_H 2 #define COSMO_UTILS_RK4REGISTER_H 18 template<
typename IT,
typename RT>
37 _array_p(), _array_a(), _array_c(), _array_f()
42 RK4Register(IT nx_in, IT ny_in, IT nz_in, RT sim_dt_in):
50 points = nx_in*ny_in*nz_in;
64 void init(IT nx_in, IT ny_in, IT nz_in, RT sim_dt_in)
68 points = nx_in*ny_in*nz_in;
70 _array_p.init(nx_in, ny_in, nz_in);
71 _array_a.init(nx_in, ny_in, nz_in);
72 _array_c.init(nx_in, ny_in, nz_in);
73 _array_f.init(nx_in, ny_in, nz_in);
94 _array_p.setName(name_in +
"_p");
95 _array_a.setName(name_in +
"_a");
96 _array_c.setName(name_in +
"_c");
97 _array_f.setName(name_in +
"_f");
105 std::swap(_array_a.name, _array_c.name);
106 std::swap(_array_a._array, _array_c._array);
114 std::swap(_array_p.name, _array_f.name);
115 std::swap(_array_p._array, _array_f._array);
121 #pragma omp parallel for default(shared) private(i) 122 for(i=0; i<points; ++i)
124 _array_a[i] = _array_p[i];
131 #pragma omp parallel for 132 for(IT i=0; i<points; ++i)
134 _array_f[i] += sim_dt*_array_c[i]/6.0;
135 _array_c[i] = _array_p[i] + sim_dt*_array_c[i]/2.0;
143 #pragma omp parallel for 144 for(IT i=0; i<points; ++i)
146 _array_f[i] += sim_dt*_array_c[i]/3.0;
147 _array_c[i] = _array_p[i] + sim_dt*_array_c[i]/2.0;
155 #pragma omp parallel for 156 for(IT i=0; i<points; ++i)
158 _array_f[i] += sim_dt*_array_c[i]/3.0;
159 _array_c[i] = _array_p[i] + sim_dt*_array_c[i];
167 #pragma omp parallel for 168 for(IT i=0; i<points; ++i)
170 _array_f[i] += sim_dt*_array_c[i]/6.0 + _array_p[i];
171 _array_c[i] = _array_f[i];
172 _array_p[i] = _array_f[i];
178 RT& _p(
const IT & i,
const IT & j,
const IT & k) {
return _array_p(i, j, k); }
179 RT& _a(
const IT & i,
const IT & j,
const IT & k) {
return _array_a(i, j, k); }
180 RT& _c(
const IT & i,
const IT & j,
const IT & k) {
return _array_c(i, j, k); }
181 RT& _f(
const IT & i,
const IT & j,
const IT & k) {
return _array_f(i, j, k); }
183 RT& operator()(
const IT & i,
const IT & j,
const IT & k)
186 return _array_a[_array_a.idx(i, j, k)];
189 RT& operator[](IT idx)
191 return _array_a[idx];
CosmoArray< IT, RT > _array_a
"_a" register: containes _a_ctive data needed for _c_omputations
Definition: RK4Register.h:28
void swap_a_c()
Swap data in and names of _a and _c registers.
Definition: RK4Register.h:103
RK4 Class for integration.
Definition: RK4Register.h:19
void init(IT nx_in, IT ny_in, IT nz_in, RT sim_dt_in)
Initialize class variables; call CosmoArray::init for array members.
Definition: RK4Register.h:64
void setName(std::string name_in)
Set "name" property of instance, CosmoArray member instances.
Definition: RK4Register.h:91
void setDt(RT sim_dt_in)
Set "dt" for RK4Register instance.
Definition: RK4Register.h:79
RK4Register()
Constructor calls CosmoArray constructors; call RK4Register::init to initialize class.
Definition: RK4Register.h:36
CosmoArray< IT, RT > _array_p
"_p" register: contains data from _p_revious step
Definition: RK4Register.h:27
void swap_p_f()
Swap data in and names of _p and _f registers.
Definition: RK4Register.h:112
CosmoArray< IT, RT > _array_c
"_c" register: contains _c_omputed values
Definition: RK4Register.h:29
CosmoArray< IT, RT > _array_f
"_f" register: containes final value of RK4 step
Definition: RK4Register.h:30