ExaDG
Loading...
Searching...
No Matches
time_int_abm_base.h
1/* ______________________________________________________________________
2 *
3 * ExaDG - High-Order Discontinuous Galerkin for the Exa-Scale
4 *
5 * Copyright (C) 2023 by the ExaDG authors
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 * ______________________________________________________________________
20 */
21
22#ifndef INCLUDE_EXADG_TIME_INTEGRATION_TIME_INT_ABM_BASE_H_
23#define INCLUDE_EXADG_TIME_INTEGRATION_TIME_INT_ABM_BASE_H_
24
25
26#include <exadg/time_integration/ab_constants.h>
27#include <exadg/time_integration/am_constants.h>
28#include <exadg/time_integration/push_back_vectors.h>
29#include <exadg/time_integration/time_int_multistep_base.h>
30#include <exadg/utilities/print_solver_results.h>
31
32namespace ExaDG
33{
37template<typename Operator, typename VectorType>
39{
40 using Number = typename VectorType::value_type;
41
42public:
43 TimeIntAdamsBashforthMoultonBase(std::shared_ptr<Operator> pde_operator_in,
44 double const start_time_,
45 double const end_time_,
46 unsigned int const max_number_of_time_steps_,
47 unsigned int const order_,
48 bool const start_with_low_order_,
49 bool const adaptive_time_stepping_,
50 RestartData const & restart_data_,
51 MPI_Comm const & mpi_comm_,
52 bool const is_test_)
53 : TimeIntMultistepBase(start_time_,
54 end_time_,
55 max_number_of_time_steps_,
56 order_,
57 start_with_low_order_,
58 adaptive_time_stepping_,
59 restart_data_,
60 mpi_comm_,
61 is_test_),
62 pde_operator(pde_operator_in),
63 // order of predictor can be chosen one below order of corrector
64 ab(order_ - 1, start_with_low_order_),
65 am(order_, start_with_low_order_),
66 vec_evaluated_operators(order_ - 1)
67 {
68 AssertThrow(order_ >= 1,
69 dealii::ExcMessage("Oder of ABM time integrator has to be at least 1."));
70 }
71
72 void
73 print_iterations() const
74 {
75 // explicit time integration -> no iterations
76 print_list_of_iterations(pcout, {"Adams-Bashforth-Moulton"}, {0});
77 }
78
79 void
80 ale_update()
81 {
82 AssertThrow(false, dealii::ExcMessage("not yet implemented"));
83 }
84
85 VectorType const &
86 get_solution() const
87 {
88 return solution;
89 }
90
91protected:
92 Operator const &
93 get_underlying_operator() const
94 {
95 return *pde_operator;
96 }
97
98private:
99 void
100 update_time_integrator_constants() final
101 {
102 ab.update(time_step_number, adaptive_time_stepping, time_steps);
103 am.update(time_step_number, adaptive_time_stepping, time_steps);
104 }
105
106 void
107 allocate_vectors() final
108 {
109 pde_operator->initialize_dof_vector(solution);
110 pde_operator->initialize_dof_vector(prediction);
111
112 pde_operator->initialize_dof_vector(evaluated_operator_np);
113 for(auto & evaluated_operator : vec_evaluated_operators)
114 pde_operator->initialize_dof_vector(evaluated_operator);
115 }
116
117 void
118 initialize_current_solution() final
119 {
120 pde_operator->prescribe_initial_conditions(solution, get_time());
121 }
122
123 void
124 initialize_former_multistep_dof_vectors() final
125 {
126 if(start_with_low_order)
127 {
128 if(vec_evaluated_operators.size() > 0)
129 pde_operator->evaluate(vec_evaluated_operators[0], solution, get_time());
130 }
131 else // start with high order
132 {
133 // fill evaluated operators
134 VectorType temp_sol;
135 pde_operator->initialize_dof_vector(temp_sol);
136 for(unsigned int i = 0; i < vec_evaluated_operators.size(); ++i)
137 {
138 pde_operator->prescribe_initial_conditions(temp_sol, get_previous_time(i));
139 pde_operator->evaluate(vec_evaluated_operators[i], temp_sol, get_previous_time(i));
140 }
141 }
142 }
143
144 void
145 setup_derived() final
146 {
147 }
148
149 void
150 do_timestep_predict()
151 {
152 dealii::Timer timer;
153 timer.restart();
154
155 predrict_solution(prediction, solution, vec_evaluated_operators);
156
157 timer_tree->insert({"Timeloop", "Adams-Bashforth-Moulton"}, timer.wall_time());
158 }
159
160 void
161 do_timestep_correct()
162 {
163 dealii::Timer timer;
164 timer.restart();
165
166 // evaluate operator given the predicted solution
167 pde_operator->evaluate(evaluated_operator_np, prediction, get_next_time());
168 // correct solution
169 correct_solution(solution, evaluated_operator_np, vec_evaluated_operators);
170 // correct operator by evaluating operator with correct solution
171 pde_operator->evaluate(evaluated_operator_np, solution, get_next_time());
172
173 // write output
174 if(this->print_solver_info() and not(this->is_test))
175 {
176 pcout << std::endl << "Adams-Bashforth-Moulton:";
177 print_wall_time(pcout, timer.wall_time());
178 }
179
180 timer_tree->insert({"Timeloop", "Adams-Bashforth-Moulton"}, timer.wall_time());
181 }
182
183 void
184 do_timestep_solve() final
185 {
186 do_timestep_predict();
187 do_timestep_correct();
188 }
189
190 void
191 correct_solution(VectorType & dst,
192 VectorType const & op_np,
193 std::vector<VectorType> const & ops) const
194 {
195 dst.add(static_cast<Number>(get_time_step_size() * am.get_gamma0()), op_np);
196 for(unsigned int i = 0; i < this->am.get_order() - 1; ++i)
197 dst.add(static_cast<Number>(get_time_step_size() * am.get_alpha(i)), ops[i]);
198 }
199
200 void
201 predrict_solution(VectorType & dst,
202 VectorType const & src,
203 std::vector<VectorType> const & ops) const
204 {
205 dst = src;
206 for(unsigned int i = 0; i < this->ab.get_order(); ++i)
207 dst.add(static_cast<Number>(get_time_step_size() * ab.get_alpha(i)), ops[i]);
208 }
209
210 void
211 prepare_vectors_for_next_timestep() final
212 {
213 if(vec_evaluated_operators.size() > 0)
214 {
215 push_back(vec_evaluated_operators);
216 std::swap(vec_evaluated_operators[0], evaluated_operator_np);
217 }
218 }
219
220 void
221 read_restart_vectors(boost::archive::binary_iarchive & ia) final
222 {
223 ia >> solution;
224 ia >> prediction;
225 }
226
227 void
228 write_restart_vectors(boost::archive::binary_oarchive & oa) const final
229 {
230 oa << solution;
231 oa << prediction;
232 }
233
234 void
235 solve_steady_problem() final
236 {
237 AssertThrow(false, dealii::ExcMessage("Steady not implemented."));
238 }
239
240 // spatial pde operator
241 std::shared_ptr<Operator> pde_operator;
242
243 // Time integration constants
246
247 // solution vector
248 VectorType solution;
249 // temporary vector to store prediction
250 VectorType prediction;
251
252 // store evaluated operators from previous time steps
253 VectorType evaluated_operator_np;
254 std::vector<VectorType> vec_evaluated_operators;
255};
256
257} // namespace ExaDG
258
259#endif /* INCLUDE_EXADG_TIME_INTEGRATION_TIME_INT_ABM_BASE_H_*/
Definition ab_constants.h:40
Definition am_constants.h:40
Definition time_int_abm_base.h:39
Definition time_int_multistep_base.h:31
Definition driver.cpp:33
Definition restart_data.h:38