27 #ifndef MODEL_DG_T_HPP_
28 #define MODEL_DG_T_HPP_
30 #include <deal.II/base/parameter_handler.h>
32 #include <deal.II/fe/mapping_q1_eulerian.h>
34 #include <deal.II/lac/full_matrix.h>
45 #include "source/core_model.hpp"
46 #include "source/geometry/mesh_handler.hpp"
47 #include "source/init.hpp"
48 #include "source/io/data_writer.hpp"
49 #include "source/numerics/bc_handler.hpp"
50 #include "source/numerics/linear_solver_handler.hpp"
51 #include "source/numerics/preconditioner_handler.hpp"
52 #include "source/numerics/time_handler.hpp"
53 #include "source/numerics/tools.hpp"
60 template <
class basis>
105 const std::shared_ptr<dealii::Function<lifex::dim>> &
u_ex,
106 const char *solution_name = (
char *)
"u");
132 template <
class basis>
137 this->linear_solver.declare_parameters(params);
138 this->preconditioner.declare_parameters(params);
141 params.enter_subsection(
"Mesh and space discretization");
143 params.declare_entry(
144 "Number of refinements",
146 dealii::Patterns::Integer(0),
147 "Number of global mesh refinement steps applied to initial grid.");
148 params.declare_entry(
"FE space degree",
150 dealii::Patterns::Integer(1),
151 "Degree of the FE space.");
153 params.leave_subsection();
155 params.enter_subsection(
"Discontinuous Galerkin");
157 params.declare_entry(
158 "Penalty coefficient",
160 dealii::Patterns::Double(-1, 1),
161 "Penalty coefficient in the Discontinuous Galerkin formulation.");
162 params.declare_entry(
163 "Stability coefficient",
165 dealii::Patterns::Double(0),
166 "Stabilization term in the Discontinuous Galerkin formulation.");
168 params.leave_subsection();
170 params.enter_subsection(
"Time solver");
172 params.declare_entry(
"Initial time",
174 dealii::Patterns::Double(0),
176 params.declare_entry(
"Final time",
178 dealii::Patterns::Double(0),
180 params.declare_entry(
"Time step",
182 dealii::Patterns::Double(0),
184 params.declare_entry(
"BDF order",
186 dealii::Patterns::Integer(1, 3),
187 "BDF order: 1, 2, 3.");
189 params.leave_subsection();
192 template <
class basis>
199 this->linear_solver.parse_parameters(params);
200 this->preconditioner.parse_parameters(params);
203 params.enter_subsection(
"Mesh and space discretization");
204 this->prm_n_refinements = params.get_integer(
"Number of refinements");
205 this->prm_fe_degree = params.get_integer(
"FE space degree");
206 params.leave_subsection();
208 params.enter_subsection(
"Discontinuous Galerkin");
209 this->prm_penalty_coeff = params.get_double(
"Penalty coefficient");
210 AssertThrow(this->prm_penalty_coeff == 1. || this->prm_penalty_coeff == 0. ||
211 this->prm_penalty_coeff == -1.,
212 dealii::StandardExceptions::ExcMessage(
213 "Penalty coefficient must be 1 (SIP method) or 0 (IIP method) "
214 "or -1 (NIP method)."));
216 this->prm_stability_coeff = params.get_double(
"Stability coefficient");
217 params.leave_subsection();
219 params.enter_subsection(
"Time solver");
220 this->prm_time_init = params.get_double(
"Initial time");
221 this->prm_time_final = params.get_double(
"Final time");
222 AssertThrow(this->prm_time_final > this->prm_time_init,
223 dealii::StandardExceptions::ExcMessage(
224 "Final time must be greater than initial time."));
226 this->prm_time_step = params.get_double(
"Time step");
227 this->prm_bdf_order = params.get_integer(
"BDF order");
228 params.leave_subsection();
231 template <
class basis>
236 this->u_ex->set_time(prm_time_init);
240 this->discretize_analytical_solution(this->u_ex, this->solution_owned);
241 this->solution_ex_owned = this->solution_owned;
242 this->solution = this->solution_owned;
245 const std::vector<lifex::LinAlg::MPI::Vector> sol_init(this->prm_bdf_order,
246 this->solution_owned);
249 bdf_handler.initialize(this->prm_bdf_order, sol_init);
251 solution_bdf = bdf_handler.get_sol_bdf();
254 template <
class basis>
257 const lifex::LinAlg::MPI::Vector &solution_owned,
258 const lifex::LinAlg::MPI::Vector &solution_ex_owned,
259 const std::shared_ptr<dealii::Function<lifex::dim>> &u_ex,
260 const char *solution_name)
262 AssertThrow(u_ex !=
nullptr,
263 dealii::StandardExceptions::ExcMessage(
264 "Not valid pointer to the exact solution."));
266 AssertThrow(solution_owned.size() == solution_ex_owned.size(),
267 dealii::StandardExceptions::ExcMessage(
268 "The exact solution vector and the approximate solution vector "
269 "must have the same length."));
271 lifex::LinAlg::MPI::Vector error_owned =
272 this->conversion_to_fem(solution_owned);
273 error_owned -= this->conversion_to_fem(solution_ex_owned);
275 pcerr << solution_name <<
":"
276 <<
"\tL-inf error norm: " << error_owned.linfty_norm() << std::endl;
279 template <
class basis>
284 this->u_ex->set_time(this->time);
285 this->f_ex->set_time(this->time);
286 this->g_n->set_time(this->time);
287 this->grad_u_ex->set_time(this->time);
289 bdf_handler.time_advance(this->solution_owned,
true);
290 this->solution_bdf = bdf_handler.get_sol_bdf();
293 this->discretize_analytical_solution(this->u_ex, this->solution_ex_owned);
296 template <
class basis>
301 this->setup_system();
302 this->initialize_solution(this->solution_owned, this->solution);
303 this->initialize_solution(this->solution_ex_owned, this->solution_ex);
304 this->time_initialization();
306 while (this->time < this->prm_time_final)
308 time += prm_time_step;
311 pcout <<
"Time step " << std::setw(6) << timestep_number
312 <<
" at t = " << std::setw(8) << std::fixed << std::setprecision(6)
313 << time << std::endl;
316 this->solution_ext = bdf_handler.get_sol_extrapolation();
318 this->assemble_system();
321 this->solution_owned = this->solution_ext;
322 this->solve_system();
324 this->intermediate_error_print(this->solution_owned,
325 this->solution_ex_owned,
329 this->compute_errors(this->solution_owned,
330 this->solution_ex_owned,
336 this->solution_ex = this->solution_ex_owned;
337 this->conversion_to_fem(this->solution_ex);
338 this->solution = this->solution_owned;
339 this->conversion_to_fem(this->solution);
340 this->output_results();
Class representing the resolution of time-dependent problems using discontinuous Galerkin methods.
virtual void declare_parameters(lifex::ParamHandler ¶ms) const override
Override for declaration of additional parameters.
double prm_time_step
Time-step amplitude.
lifex::LinAlg::MPI::Vector solution_bdf
BDF solution, with ghost entries.
lifex::LinAlg::MPI::Vector solution_ext
BDF extrapolated solution, with ghost entries.
lifex::utils::BDFHandler< lifex::LinAlg::MPI::Vector > bdf_handler
BDF time advancing handler.
double prm_time_init
Initial time.
virtual void parse_parameters(lifex::ParamHandler ¶ms) override
Override to parse additional parameters.
void run() override
Override for the simulation run.
unsigned int prm_bdf_order
BDF order.
double prm_time_final
Final time.
virtual void intermediate_error_print(const lifex::LinAlg::MPI::Vector &solution_owned, const lifex::LinAlg::MPI::Vector &solution_ex_owned, const std::shared_ptr< dealii::Function< lifex::dim >> &u_ex, const char *solution_name=(char *)"u")
Computation of the error at an intermediate time-step.
unsigned int timestep_number
Current time-step number.
virtual void update_time()
To perform the time increment.
virtual void time_initialization()
Setup for the time-dependent problems at the initial time-step.
ModelDG_t(std::string model_name)
Constructor.
virtual ~ModelDG_t()=default
Destructor.
Class representing the resolution of problems using discontinuous Galerkin methods.
const std::string model_name
Name of the class/problem.
lifex::LinAlg::MPI::Vector solution_owned
Distributed solution vector, without ghost entries.
std::shared_ptr< lifex::utils::FunctionDirichlet > u_ex
Pointer to exact solution function.
lifex::LinAlg::MPI::Vector solution_ex_owned
Distributed exact solution vector, without ghost entries.