ExaDG
Loading...
Searching...
No Matches
interface.h
1/* ______________________________________________________________________
2 *
3 * ExaDG - High-Order Discontinuous Galerkin for the Exa-Scale
4 *
5 * Copyright (C) 2021 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 EXADG_CONVECTION_DIFFUSION_SPATIAL_DISCRETIZATION_INTERFACE_H_
23#define EXADG_CONVECTION_DIFFUSION_SPATIAL_DISCRETIZATION_INTERFACE_H_
24
25// deal.II
26#include <deal.II/lac/la_parallel_vector.h>
27
28// ExaDG
29#include <exadg/time_integration/interpolate.h>
30
31namespace ExaDG
32{
33namespace ConvDiff
34{
35namespace Interface
36{
37template<typename Number>
38class Operator
39{
40public:
41 typedef dealii::LinearAlgebra::distributed::Vector<Number> VectorType;
42
43 Operator()
44 {
45 }
46
47 virtual ~Operator()
48 {
49 }
50
51 // explicit time integration: evaluate operator
52 virtual void
53 evaluate_explicit_time_int(VectorType & dst,
54 VectorType const & src,
55 double const evaluation_time,
56 VectorType const * velocity = nullptr) const = 0;
57
58 // implicit time integration: calculate right-hand side of linear system of equations
59 virtual void
60 rhs(VectorType & dst,
61 double const evaluation_time = 0.0,
62 VectorType const * velocity = nullptr) const = 0;
63
64 // implicit time integration: solve linear system of equations
65 virtual unsigned int
66 solve(VectorType & sol,
67 VectorType const & rhs,
68 bool const update_preconditioner,
69 double const scaling_factor = -1.0,
70 double const evaluation_time = -1.0,
71 VectorType const * velocity = nullptr) = 0;
72
73 // time integration: initialize dof vector
74 virtual void
75 initialize_dof_vector(VectorType & src) const = 0;
76
77 virtual void
78 initialize_dof_vector_velocity(VectorType & src) const = 0;
79
80 virtual void
81 project_velocity(VectorType & velocity, double const time) const = 0;
82
83 // required for restart functionality
84 virtual void
85 serialize_vectors(std::vector<VectorType const *> const & vectors) const = 0;
86
87 virtual void
88 deserialize_vectors(std::vector<VectorType *> const & vectors) = 0;
89
90 // time integration: prescribe initial conditions
91 virtual void
92 prescribe_initial_conditions(VectorType & src, double const evaluation_time) const = 0;
93
94 // time step calculation: max efficiency
95 virtual double
96 calculate_time_step_max_efficiency(unsigned int const order_time_integrator) const = 0;
97
98 // time step calculation: global CFL condition
99 virtual double
100 calculate_time_step_cfl_global(double const time) const = 0;
101
102 // time step calculation: local CFL condition
103 virtual double
104 calculate_time_step_cfl_analytical_velocity(double const time) const = 0;
105
106 virtual double
107 calculate_time_step_cfl_numerical_velocity(VectorType const & velocity) const = 0;
108
109 // needed for time step calculation
110 virtual double
111 calculate_time_step_diffusion() const = 0;
112
113 /*
114 * Prepare and interpolation in adaptive mesh refinement.
115 */
116 virtual void
117 prepare_coarsening_and_refinement(std::vector<VectorType *> & vectors) = 0;
118
119 virtual void
120 interpolate_after_coarsening_and_refinement(std::vector<VectorType *> & vectors) = 0;
121};
122} // namespace Interface
123
124template<typename Number>
125class OperatorExplRK
126{
127public:
128 typedef dealii::LinearAlgebra::distributed::Vector<Number> VectorType;
129
130 OperatorExplRK(std::shared_ptr<ConvDiff::Interface::Operator<Number>> operator_in,
131 bool const numerical_velocity_field_in)
132 : pde_operator(operator_in), numerical_velocity_field(numerical_velocity_field_in)
133 {
134 if(numerical_velocity_field)
135 initialize_dof_vector_velocity(velocity_interpolated);
136 }
137
138 void
139 set_velocities_and_times(std::vector<VectorType const *> const & velocities_in,
140 std::vector<double> const & times_in)
141 {
142 velocities = velocities_in;
143 times = times_in;
144 }
145
146 void
147 evaluate(VectorType & dst, VectorType const & src, double const evaluation_time) const
148 {
149 if(numerical_velocity_field)
150 {
151 interpolate(velocity_interpolated, evaluation_time, velocities, times);
152
153 pde_operator->evaluate_explicit_time_int(dst, src, evaluation_time, &velocity_interpolated);
154 }
155 else
156 {
157 pde_operator->evaluate_explicit_time_int(dst, src, evaluation_time);
158 }
159 }
160
161 void
162 initialize_dof_vector(VectorType & src) const
163 {
164 pde_operator->initialize_dof_vector(src);
165 }
166
167 void
168 initialize_dof_vector_velocity(VectorType & src) const
169 {
170 pde_operator->initialize_dof_vector_velocity(src);
171 }
172
173private:
174 std::shared_ptr<ConvDiff::Interface::Operator<Number>> pde_operator;
175
176 bool numerical_velocity_field;
177 std::vector<VectorType const *> velocities;
178 std::vector<double> times;
179 VectorType mutable velocity_interpolated;
180};
181
182} // namespace ConvDiff
183} // namespace ExaDG
184
185#endif /* EXADG_CONVECTION_DIFFUSION_SPATIAL_DISCRETIZATION_INTERFACE_H_ */
Definition interface.h:39
Definition driver.cpp:33