File indexing completed on 2025-02-22 10:31:21
0001
0002
0003
0004
0005
0006
0007
0008 #pragma once
0009
0010 #include "corecel/Macros.hh"
0011 #include "corecel/Types.hh"
0012 #include "corecel/math/Algorithms.hh"
0013
0014 #include "Types.hh"
0015
0016 namespace celeritas
0017 {
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063 template<class EquationT>
0064 class DormandPrinceStepper
0065 {
0066 public:
0067
0068
0069 using result_type = FieldStepperResult;
0070
0071
0072 public:
0073
0074 explicit CELER_FUNCTION DormandPrinceStepper(EquationT&& eq)
0075 : calc_rhs_(::celeritas::forward<EquationT>(eq))
0076 {
0077 }
0078
0079
0080 CELER_FUNCTION result_type operator()(real_type step,
0081 OdeState const& beg_state) const;
0082
0083 private:
0084
0085 EquationT calc_rhs_;
0086 };
0087
0088
0089
0090
0091 template<class EquationT>
0092 CELER_FUNCTION
0093 DormandPrinceStepper(EquationT&&) -> DormandPrinceStepper<EquationT>;
0094
0095
0096
0097
0098
0099
0100
0101 template<class E>
0102 CELER_FUNCTION auto DormandPrinceStepper<E>::operator()(
0103 real_type step, OdeState const& beg_state) const -> result_type
0104 {
0105 using celeritas::axpy;
0106 using R = real_type;
0107
0108
0109 constexpr R a11 = 0.2;
0110
0111 constexpr R a21 = 0.075;
0112 constexpr R a22 = 0.225;
0113
0114 constexpr R a31 = 44 / R(45);
0115 constexpr R a32 = -56 / R(15);
0116 constexpr R a33 = 32 / R(9);
0117
0118 constexpr R a41 = 19372 / R(6561);
0119 constexpr R a42 = -25360 / R(2187);
0120 constexpr R a43 = 64448 / R(6561);
0121 constexpr R a44 = -212 / R(729);
0122
0123 constexpr R a51 = 9017 / R(3168);
0124 constexpr R a52 = -355 / R(33);
0125 constexpr R a53 = 46732 / R(5247);
0126 constexpr R a54 = 49 / R(176);
0127 constexpr R a55 = -5103 / R(18656);
0128
0129 constexpr R a61 = 35 / R(384);
0130 constexpr R a63 = 500 / R(1113);
0131 constexpr R a64 = 125 / R(192);
0132 constexpr R a65 = -2187 / R(6784);
0133 constexpr R a66 = 11 / R(84);
0134
0135 constexpr R d71 = a61 - 5179 / R(57600);
0136 constexpr R d73 = a63 - 7571 / R(16695);
0137 constexpr R d74 = a64 - 393 / R(640);
0138 constexpr R d75 = a65 + 92097 / R(339200);
0139 constexpr R d76 = a66 - 187 / R(2100);
0140 constexpr R d77 = -1 / R(40);
0141
0142
0143 constexpr R c71 = R(6025192743.) / R(30085553152.);
0144 constexpr R c73 = R(51252292925.) / R(65400821598.);
0145 constexpr R c74 = R(-2691868925.) / R(45128329728.);
0146 constexpr R c75 = R(187940372067.) / R(1594534317056.);
0147 constexpr R c76 = R(-1776094331.) / R(19743644256.);
0148 constexpr R c77 = R(11237099.) / R(235043384.);
0149
0150 result_type result;
0151
0152
0153 OdeState k1 = calc_rhs_(beg_state);
0154 OdeState state = beg_state;
0155 axpy(a11 * step, k1, &state);
0156
0157
0158 OdeState k2 = calc_rhs_(state);
0159 state = beg_state;
0160 axpy(a21 * step, k1, &state);
0161 axpy(a22 * step, k2, &state);
0162
0163
0164 OdeState k3 = calc_rhs_(state);
0165 state = beg_state;
0166 axpy(a31 * step, k1, &state);
0167 axpy(a32 * step, k2, &state);
0168 axpy(a33 * step, k3, &state);
0169
0170
0171 OdeState k4 = calc_rhs_(state);
0172 state = beg_state;
0173 axpy(a41 * step, k1, &state);
0174 axpy(a42 * step, k2, &state);
0175 axpy(a43 * step, k3, &state);
0176 axpy(a44 * step, k4, &state);
0177
0178
0179 OdeState k5 = calc_rhs_(state);
0180 state = beg_state;
0181 axpy(a51 * step, k1, &state);
0182 axpy(a52 * step, k2, &state);
0183 axpy(a53 * step, k3, &state);
0184 axpy(a54 * step, k4, &state);
0185 axpy(a55 * step, k5, &state);
0186
0187
0188 OdeState k6 = calc_rhs_(state);
0189 result.end_state = beg_state;
0190 axpy(a61 * step, k1, &result.end_state);
0191 axpy(a63 * step, k3, &result.end_state);
0192 axpy(a64 * step, k4, &result.end_state);
0193 axpy(a65 * step, k5, &result.end_state);
0194 axpy(a66 * step, k6, &result.end_state);
0195
0196
0197 OdeState k7 = calc_rhs_(result.end_state);
0198
0199
0200 result.err_state = {{0, 0, 0}, {0, 0, 0}};
0201 axpy(d71 * step, k1, &result.err_state);
0202 axpy(d73 * step, k3, &result.err_state);
0203 axpy(d74 * step, k4, &result.err_state);
0204 axpy(d75 * step, k5, &result.err_state);
0205 axpy(d76 * step, k6, &result.err_state);
0206 axpy(d77 * step, k7, &result.err_state);
0207
0208
0209 real_type half_step = step / real_type(2);
0210 result.mid_state = beg_state;
0211 axpy(c71 * half_step, k1, &result.mid_state);
0212 axpy(c73 * half_step, k3, &result.mid_state);
0213 axpy(c74 * half_step, k4, &result.mid_state);
0214 axpy(c75 * half_step, k5, &result.mid_state);
0215 axpy(c76 * half_step, k6, &result.mid_state);
0216 axpy(c77 * half_step, k7, &result.mid_state);
0217
0218 return result;
0219 }
0220
0221
0222 }