ExaDG
Loading...
Searching...
No Matches
mesh_movement_functions.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 INCLUDE_MESH_MOVEMENT_FUNCTIONS_H_
23#define INCLUDE_MESH_MOVEMENT_FUNCTIONS_H_
24
25namespace ExaDG
26{
27enum class MeshMovementAdvanceInTime
28{
29 Undefined,
30 SinSquared,
31 Sin
32};
33
34enum class MeshMovementShape
35{
36 Undefined,
37 Sin,
38 SineZeroAtBoundary,
39 SineAligned
40};
41
42template<int dim>
44{
46 : temporal(MeshMovementAdvanceInTime::Undefined),
47 shape(MeshMovementShape::Undefined),
48 amplitude(0.0),
49 period(1.0),
50 t_start(0.0),
51 t_end(1.0),
52 spatial_number_of_oscillations(1)
53 {
54 }
55
56 MeshMovementAdvanceInTime temporal;
57 MeshMovementShape shape;
58 dealii::Tensor<1, dim> dimensions;
59 double amplitude;
60 double period;
61 double t_start;
62 double t_end;
63 double spatial_number_of_oscillations;
64};
65
66template<int dim>
67class CubeMeshMovementFunctions : public dealii::Function<dim>
68{
69public:
71 : dealii::Function<dim>(dim),
72 data(data_in),
73 width(data_in.dimensions[0]),
74 left(-1.0 / 2.0 * width),
75 right(-left),
76 runtime(data_in.t_end - data_in.t_start),
77 time_period(data_in.period)
78 {
79 }
80
81 double
82 value(dealii::Point<dim> const & x, unsigned int const coordinate_direction = 0) const override
83 {
84 double displacement = 0.0;
85
86 displacement = compute_displacement_share(x, coordinate_direction) * compute_time_share();
87
88 return displacement;
89 }
90
91private:
92 double
93 compute_displacement_share(dealii::Point<dim> const & x,
94 unsigned int const coordinate_direction = 0) const
95 {
96 double solution = 0.0;
97
98 switch(data.shape)
99 {
100 case MeshMovementShape::Undefined:
101 AssertThrow(false, dealii::ExcMessage("Undefined parameter MeshMovementShape."));
102 break;
103
104 case MeshMovementShape::Sin:
105 if(coordinate_direction == 0)
106 solution =
107 std::sin(2.0 * pi * (x(1) - left) * data.spatial_number_of_oscillations / width) *
108 data.amplitude *
109 (dim == 3 ?
110 std::sin(2.0 * pi * (x(2) - left) * data.spatial_number_of_oscillations / width) :
111 1.0);
112 else if(coordinate_direction == 1)
113 solution =
114 std::sin(2.0 * pi * (x(0) - left) * data.spatial_number_of_oscillations / width) *
115 data.amplitude *
116 (dim == 3 ?
117 std::sin(2.0 * pi * (x(2) - left) * data.spatial_number_of_oscillations / width) :
118 1.0);
119 else if(coordinate_direction == 2)
120 solution =
121 std::sin(2.0 * pi * (x(0) - left) * data.spatial_number_of_oscillations / width) *
122 data.amplitude *
123 std::sin(2.0 * pi * (x(1) - left) * data.spatial_number_of_oscillations / width);
124 break;
125
126 case MeshMovementShape::SineZeroAtBoundary:
127 if(coordinate_direction == 0)
128 solution =
129 std::sin(pi * (x(0) - left) * data.spatial_number_of_oscillations / width) *
130 std::sin(2.0 * pi * (x(1) - left) * data.spatial_number_of_oscillations / width) *
131 data.amplitude *
132 (dim == 3 ?
133 std::sin(2.0 * pi * (x(2) - left) * data.spatial_number_of_oscillations / width) :
134 1.0);
135 else if(coordinate_direction == 1)
136 solution =
137 std::sin(pi * (x(1) - left) * data.spatial_number_of_oscillations / width) *
138 std::sin(2.0 * pi * (x(0) - left) * data.spatial_number_of_oscillations / width) *
139 data.amplitude *
140 (dim == 3 ?
141 std::sin(2.0 * pi * (x(2) - left) * data.spatial_number_of_oscillations / width) :
142 1.0);
143 else if(coordinate_direction == 2)
144 solution =
145 std::sin(pi * (x(2) - left) * data.spatial_number_of_oscillations / width) *
146 std::sin(2.0 * pi * (x(0) - left) * data.spatial_number_of_oscillations / width) *
147 data.amplitude *
148 std::sin(2.0 * pi * (x(1) - left) * data.spatial_number_of_oscillations / width);
149 break;
150
151 case MeshMovementShape::SineAligned:
152 solution = std::sin(2.0 * pi * (x(coordinate_direction) - left) *
153 data.spatial_number_of_oscillations / width) *
154 data.amplitude;
155 break;
156
157 default:
158 AssertThrow(false, dealii::ExcMessage("Not implemented."));
159 break;
160 }
161
162 return solution;
163 }
164
165 double
166 compute_time_share() const
167 {
168 double solution = 0.0;
169
170 switch(data.temporal)
171 {
172 case MeshMovementAdvanceInTime::Undefined:
173 AssertThrow(false, dealii::ExcMessage("Undefined parameter MeshMovementAdvanceInTime."));
174 break;
175
176 case MeshMovementAdvanceInTime::SinSquared:
177 solution = std::pow(std::sin(2.0 * pi * this->get_time() / time_period), 2);
178 break;
179
180 case MeshMovementAdvanceInTime::Sin:
181 solution = std::sin(2.0 * pi * this->get_time() / time_period);
182 break;
183
184 default:
185 AssertThrow(false, dealii::ExcMessage("Not implemented."));
186 break;
187 }
188 return solution;
189 }
190
191protected:
192 double const pi = dealii::numbers::PI;
193 MeshMovementData<dim> const data;
194 double const width;
195 double const left;
196 double const right;
197 double const runtime;
198 double const time_period;
199};
200
201template<int dim>
202class RectangleMeshMovementFunctions : public dealii::Function<dim>
203{
204public:
206 : dealii::Function<dim>(dim),
207 data(data_in),
208 length(data_in.dimensions[0]),
209 height(data_in.dimensions[1]),
210 depth(dim == 3 ? data_in.dimensions[2] : 1.0),
211 runtime(data_in.t_end - data_in.t_start),
212 time_period(data_in.period)
213 {
214 }
215
216 double
217 value(dealii::Point<dim> const & x_in, unsigned int const coordinate_direction = 0) const override
218 {
219 // For 2D and 3D the coordinate system is set differently
220 dealii::Point<dim> x = x_in;
221 if(dim == 2)
222 x[0] -= length / 2.0;
223
224 double displacement = 0.0;
225
226 displacement = compute_displacement_share(x, coordinate_direction) * compute_time_share();
227
228 return displacement;
229 }
230
231private:
232 double
233 compute_displacement_share(dealii::Point<dim> const & x,
234 unsigned int const coordinate_direction = 0) const
235 {
236 double solution = 0.0;
237
238 switch(data.shape)
239 {
240 case MeshMovementShape::Undefined:
241 AssertThrow(false, dealii::ExcMessage("Undefined parameter MeshMovementShape."));
242 break;
243
244 case MeshMovementShape::Sin:
245 if(coordinate_direction == 0)
246 solution = std::sin(2.0 * pi * (x(1) - (height / 2.0)) / height) * data.amplitude *
247 (dim == 3 ? std::sin(2 * pi * (x(2.0) - (depth / 2)) / depth) : 1.0);
248 else if(coordinate_direction == 1)
249 solution = std::sin(2.0 * pi * (x(0) - (length / 2.0)) / length) * data.amplitude *
250 (dim == 3 ? std::sin(2 * pi * (x(2) - (depth / 2.0)) / depth) : 1.0);
251 else if(coordinate_direction == 2)
252 solution = std::sin(2.0 * pi * (x(1) - (height / 2.0)) / height) * data.amplitude *
253 std::sin(2.0 * pi * (x(0) - (length / 2.0)) / length);
254 break;
255
256 default:
257 AssertThrow(false, dealii::ExcMessage("Not implemented."));
258 break;
259 }
260
261 return solution;
262 }
263
264 double
265 compute_time_share() const
266 {
267 double solution = 0.0;
268
269 switch(data.temporal)
270 {
271 case MeshMovementAdvanceInTime::Undefined:
272 AssertThrow(false, dealii::ExcMessage("Undefined parameter MeshMovementAdvanceInTime."));
273 break;
274
275 case MeshMovementAdvanceInTime::SinSquared:
276 solution = std::pow(std::sin(2.0 * pi * this->get_time() / time_period), 2);
277 break;
278
279 case MeshMovementAdvanceInTime::Sin:
280 solution = std::sin(2.0 * pi * this->get_time() / time_period);
281 break;
282
283 default:
284 AssertThrow(false, dealii::ExcMessage("Not implemented."));
285 break;
286 }
287 return solution;
288 }
289
290protected:
291 double const pi = dealii::numbers::PI;
292 MeshMovementData<dim> const data;
293 double const length;
294 double const height;
295 double const depth;
296 double const runtime;
297 double const time_period;
298};
299
300} // namespace ExaDG
301
302#endif /*INCLUDE_MESH_MOVEMENT_FUNCTIONS_H_*/
Definition mesh_movement_functions.h:68
Definition mesh_movement_functions.h:203
Definition driver.cpp:33
Definition mesh_movement_functions.h:44