15 template<
typename time>
18 vector<shared_ptr<Encapsulation<time>>> dst = { this->end_state };
19 dst[0]->copy(this->start_state);
20 dst[0]->mat_apply(dst, dt, this->quadrature->get_b_mat(), this->fs_expl,
false);
21 dst[0]->mat_apply(dst, dt, this->quadrature->get_b_mat(), this->fs_impl,
false);
24 template<
typename time>
29 auto const num_nodes = this->quadrature->get_num_nodes();
30 auto const num_s_integrals = this->quadrature->left_is_node() ? num_nodes - 1 : num_nodes;
32 for (
size_t m = 0; m < num_nodes; m++) {
36 for (
size_t m = 0; m < num_s_integrals; m++) {
40 if (! this->quadrature->left_is_node()) {
44 size_t nsteps = this->get_controller()->get_end_time() / this->get_controller()->get_step_size();
45 size_t digit_step = (this->get_controller()->get_step_size() > 0) ?
46 to_string(nsteps + 1).length() : 3;
47 size_t digit_iter = (this->get_controller()->get_max_iterations() > 0) ?
48 to_string(this->get_controller()->get_max_iterations() - 1).length() : 3;
49 this->FORMAT_STR =
"step: %|" + to_string(digit_step) +
"| iter: %|" + to_string(digit_iter) +
"|"
50 +
" n1: %|2| n2: %|3|"
51 +
" residual: %10.4e" +
" err: %10.4e";
54 template<
typename time>
57 if (this->quadrature->left_is_node()) {
58 this->predict_with_left(initial);
60 this->predict_without_left(initial);
63 if (this->quadrature->right_is_node()) {
64 this->end_state->copy(this->state.back());
66 this->integrate_end_state(this->get_controller()->get_step_size());
70 template<
typename time>
73 if (this->quadrature->left_is_node()) {
74 this->sweep_with_left();
76 this->sweep_without_left();
79 if (this->quadrature->right_is_node()) {
80 this->end_state->copy(this->state.back());
82 this->integrate_end_state(this->get_controller()->get_step_size());
86 template<
typename time>
89 this->start_state->copy(this->end_state);
90 if (this->quadrature->left_is_node() && this->quadrature->right_is_node()) {
91 this->state[0]->copy(this->start_state);
92 this->fs_expl.front()->copy(this->fs_expl.back());
93 this->fs_impl.front()->copy(this->fs_impl.back());
97 template<
typename time>
100 time t0 = this->get_controller()->get_time();
101 time
dt = this->get_controller()->get_step_size();
103 if (this->quadrature->left_is_node()) {
104 this->f_expl_eval(this->fs_expl[0], this->state[0], t0);
105 this->f_impl_eval(this->fs_impl[0], this->state[0], t0);
110 for (
size_t m = 0; m < this->quadrature->get_num_nodes(); m++) {
111 time
t = t0 + dt * this->quadrature->get_nodes()[m];
112 this->f_expl_eval(this->fs_expl[m], this->state[m], t);
113 this->f_impl_eval(this->fs_impl[m], this->state[m], t);
118 template<
typename time>
121 auto const q_mat = this->quadrature->get_q_mat();
122 dst[0]->mat_apply(dst, dt, q_mat, this->fs_expl,
true);
123 dst[0]->mat_apply(dst, dt, q_mat, this->fs_impl,
false);
126 template<
typename time>
129 for (
size_t m = 0; m < this->quadrature->get_num_nodes(); m++) {
130 dst[m]->copy(this->start_state);
131 dst[m]->saxpy(-1.0, this->state[m]);
133 if (this->fas_corrections.size() > 0) {
135 for (
size_t m = 0; m < this->quadrature->get_num_nodes(); m++) {
136 for (
size_t n = 0; n <= m; n++) {
137 dst[m]->saxpy(1.0, this->fas_corrections[n]);
141 dst[0]->mat_apply(dst, dt, this->quadrature->get_q_mat(), this->fs_expl,
false);
142 dst[0]->mat_apply(dst, dt, this->quadrature->get_q_mat(), this->fs_impl,
false);
145 template<
typename time>
154 template<
typename time>
163 template<
typename time>
173 template<
typename time>
176 time
dt = this->get_controller()->get_step_size();
177 time
t = this->get_controller()->get_time();
178 ML_CVLOG(1,
"Sweeper",
"predicting step " << this->get_controller()->get_step() + 1
179 <<
" (t=" << t <<
", dt=" << dt <<
")");
182 this->state[0]->copy(this->start_state);
183 this->f_expl_eval(this->fs_expl[0], this->state[0], t);
184 this->f_impl_eval(this->fs_impl[0], this->state[0], t);
189 auto const nodes = this->quadrature->get_nodes();
192 for (
size_t m = 0; m < nodes.size() - 1; ++m) {
193 time ds = dt * (nodes[m+1] - nodes[m]);
194 rhs->copy(this->state[m]);
195 rhs->saxpy(ds, this->fs_expl[m]);
196 this->impl_solve(this->fs_impl[m + 1], this->state[m + 1], t, ds, rhs);
197 this->f_expl_eval(this->fs_expl[m + 1], this->state[m + 1], t + ds);
202 template<
typename time>
206 time
dt = this->get_controller()->get_step_size();
207 time
t = this->get_controller()->get_time();
208 ML_CVLOG(1,
"Sweeper",
"predicting step " << this->get_controller()->get_step() + 1
209 <<
" (t=" << t <<
", dt=" << dt <<
")");
214 auto const nodes = this->quadrature->get_nodes();
218 this->f_expl_eval(this->fs_expl_start, this->start_state, t);
219 rhs->copy(this->start_state);
220 rhs->saxpy(ds, this->fs_expl_start);
221 this->impl_solve(this->fs_impl[0], this->state[0], t, ds, rhs);
222 this->f_expl_eval(this->fs_expl[0], this->state[0], t + ds);
225 for (
size_t m = 0; m < nodes.size() - 1; ++m) {
226 ds = dt * (nodes[m+1] - nodes[m]);
227 rhs->copy(this->state[m]);
228 rhs->saxpy(ds, this->fs_expl[m]);
229 this->impl_solve(this->fs_impl[m+1], this->state[m+1], t, ds, rhs);
230 this->f_expl_eval(this->fs_expl[m+1], this->state[m+1], t + ds);
235 template<
typename time>
238 auto const nodes = this->quadrature->
get_nodes();
239 auto const dt = this->get_controller()->get_step_size();
240 auto const s_mat = this->quadrature->get_s_mat().block(1, 0, nodes.size()-1, nodes.size());
241 ML_CVLOG(1,
"Sweeper",
"sweeping on step " << this->get_controller()->get_step() + 1
242 <<
" in iteration " << this->get_controller()->get_iteration()
243 <<
" (dt=" <<
dt <<
")");
246 this->s_integrals[0]->mat_apply(this->s_integrals,
dt, s_mat, this->fs_expl,
true);
247 this->s_integrals[0]->mat_apply(this->s_integrals,
dt, s_mat, this->fs_impl,
false);
248 for (
size_t m = 0; m < nodes.size() - 1; ++m) {
249 ds =
dt * (nodes[m+1] - nodes[m]);
250 this->s_integrals[m]->saxpy(-ds, this->fs_expl[m]);
251 this->s_integrals[m]->saxpy(-ds, this->fs_impl[m+1]);
253 if (this->fas_corrections.size() > 0) {
254 for (
size_t m = 0; m < this->s_integrals.size(); m++) {
255 this->s_integrals[m]->saxpy(1.0, this->fas_corrections[m+1]);
262 auto t = this->get_controller()->get_time();
263 for (
size_t m = 0; m < nodes.size() - 1; ++m) {
264 ds =
dt * (nodes[m+1] - nodes[m]);
265 rhs->copy(this->state[m]);
266 rhs->saxpy(ds, this->fs_expl[m]);
267 rhs->saxpy(1.0, this->s_integrals[m]);
268 this->impl_solve(this->fs_impl[m + 1], this->state[m + 1],
t, ds, rhs);
269 this->f_expl_eval(this->fs_expl[m + 1], this->state[m + 1],
t + ds);
274 template<
typename time>
277 auto const nodes = this->quadrature->
get_nodes();
278 auto const dt = this->get_controller()->get_step_size();
279 auto const s_mat = this->quadrature->get_s_mat();
280 ML_CVLOG(1,
"Sweeper",
"sweeping on step " << this->get_controller()->get_step() + 1
281 <<
" in iteration " << this->get_controller()->get_iteration()
282 <<
" (dt=" <<
dt <<
")");
285 this->s_integrals[0]->mat_apply(this->s_integrals,
dt, s_mat, this->fs_expl,
true);
286 this->s_integrals[0]->mat_apply(this->s_integrals,
dt, s_mat, this->fs_impl,
false);
288 this->s_integrals[0]->saxpy(-ds, this->fs_expl_start);
289 this->s_integrals[0]->saxpy(-ds, this->fs_impl[0]);
290 for (
size_t m = 0; m < nodes.size() - 1; ++m) {
291 ds =
dt * (nodes[m+1] - nodes[m]);
292 this->s_integrals[m+1]->saxpy(-ds, this->fs_expl[m]);
293 this->s_integrals[m+1]->saxpy(-ds, this->fs_impl[m+1]);
295 if (this->fas_corrections.size() > 0) {
296 for (
size_t m = 0; m < this->s_integrals.size(); m++) {
297 this->s_integrals[m]->saxpy(1.0, this->fas_corrections[m]);
304 auto t = this->get_controller()->get_time();
306 this->f_expl_eval(this->fs_expl_start, this->start_state,
t);
307 rhs->copy(this->start_state);
308 rhs->saxpy(ds, this->fs_expl_start);
309 rhs->saxpy(1.0, this->s_integrals[0]);
310 this->impl_solve(this->fs_impl[0], this->state[0],
t, ds, rhs);
311 this->f_expl_eval(this->fs_expl[0], this->state[0],
t + ds);
314 for (
size_t m = 0; m < nodes.size() - 1; ++m) {
315 ds =
dt * (nodes[m+1] - nodes[m]);
316 rhs->copy(this->state[m]);
317 rhs->saxpy(ds, this->fs_expl[m]);
318 rhs->saxpy(1.0, this->s_integrals[m+1]);
319 this->impl_solve(this->fs_impl[m+1], this->state[m+1],
t, ds, rhs);
320 this->f_expl_eval(this->fs_expl[m+1], this->state[m+1],
t + ds);
Semi-implicit IMEX sweeper.
void setup(shared_ptr< WrapperInterface< scalar, time >> wrapper)
Not implemented yet exception.
virtual void setup(bool coarse) override
Setup (allocate etc) the sweeper.
Data/solution encapsulation.
#define ML_CVLOG(verbose_level, logger_id, x)
same as CVLOG(verbosity, logger, x) from easylogging++
#define UNUSED(expr)
Denoting unused function parameters for omitting compiler warnings.
virtual const vector< time > get_nodes() const