FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
nvs_bdf_q.hpp
1// FEAT3: Finite Element Analysis Toolbox, Version 3
2// Copyright (C) 2010 by Stefan Turek & the FEAT group
3// FEAT3 is released under the GNU General Public License version 3,
4// see the file 'copyright.txt' in the top level directory for details.
5
6#pragma once
8#include <control/time/base.hpp>
9
10#include "vector"
11
12namespace FEAT
13{
14 namespace Control
15 {
16 namespace Time
17 {
113 template<typename DT_>
115 {
116 public:
118 typedef DT_ DataType;
119
120 private:
139
140 public:
143 std::vector<DataType> coeff_lhs_v;
146 std::vector<DataType> coeff_rhs_v_1;
148 std::vector<DataType> coeff_rhs_v_phi;
150 std::vector<DataType> coeff_extrapolation_p;
151
162
169
185 NvsBdfQ(PropertyMap* config_section, const DataType reynolds, const bool use_deformation,
186 const bool startup):
187 _num_steps(~Index(0)),
191 _reynolds(reynolds),
192 _delta_t(0),
193 _use_deformation(use_deformation),
195 _startup(startup),
196 coeff_lhs_v(3),
197 coeff_rhs_v_1(3),
200 coeff_rhs_f(0),
202 coeff_rhs_phi(0),
203 coeff_rhs_v_2(0),
204 coeff_rhs_v_p(0),
208 {
209 XASSERT(config_section != nullptr);
210 // Get time discretization order
211 auto num_steps_p = config_section->query("num_steps");
212 XASSERTM(num_steps_p.second, "TimeDiscretization section is missing the mandatory num_steps entry!");
213 _num_steps = Index(std::stoul(num_steps_p.first));
214 XASSERTM(_num_steps == Index(1) || _num_steps == Index(2),"Only BDF1 and BDF2 are implemented!");
215
216 // Get the order for extrapolation of the pressure in time
217 auto p_extrapolation_p = config_section->query("p_extrapolation_steps");
218 XASSERTM(p_extrapolation_p.second,
219 "TimeDiscretization section is missing the mandatory p_extrapolation_steps entry!");
220 _p_extrapolation_steps = Index(std::stoul(p_extrapolation_p.first));
221 XASSERTM(_p_extrapolation_steps < Index(3),"p extrapolation is only implemented for order 0, 1, 2!");
223
224 // Use the rotational form?
225 auto use_rotational_form_p = config_section->query("use_rotational_form");
226 XASSERTM(use_rotational_form_p.second,
227 "TimeDiscretization section is missing the mandatory use_rotational_form entry!");
228 XASSERTM(std::stoi(use_rotational_form_p.first) == 0 || std::stoi(use_rotational_form_p.first) == 1,
229 "use_rotational has to be set to 0 or 1");
230 _use_rotational_form = std::stoi(use_rotational_form_p.first) == 1;
231
232 // Get timestep size
233 auto delta_t_p = config_section->query("delta_t");
234 XASSERTM(delta_t_p.second, "TimeDiscretization section is missing the mandatory delta_t entry!");
235 _delta_t = DataType(std::stod(delta_t_p.first));
237
238 // Use ale (meaning solve Navier-Stokes instead of plain Stokes)?
239 auto ale_p = config_section->query("ALE");
240 XASSERTM(ale_p.second,
241 "TimeDiscretization section is missing the mandatory ALE entry!");
242 ale_p.first.parse(ale_handling);
243
244 // Use convection (meaning solve Navier-Stokes instead of plain Stokes)?
245 auto convection_p = config_section->query("convection");
246 XASSERTM(convection_p.second,
247 "TimeDiscretization section is missing the mandatory convection entry!");
248 convection_p.first.parse(conv_handling);
249
250 // Use viscous (meaning solve Navier-Stokes instead of plain Stokes)?
251 auto viscous_p = config_section->query("viscous");
252 XASSERTM(viscous_p.second,
253 "TimeDiscretization section is missing the mandatory viscous entry!");
254 viscous_p.first.parse(visc_handling);
255
256 coeff_rhs_v_phi.clear();
257 coeff_rhs_v_phi = std::vector<DataType>(_num_steps, DataType(0));
258
259 coeff_extrapolation_p.clear();
260 coeff_extrapolation_p = std::vector<DataType>(_p_extrapolation_steps, DataType(0));
261
262 if(startup)
263 {
265 }
266 else
267 {
269 }
270 }
271
275 virtual ~NvsBdfQ()
276 {
277 }
278
285 {
286 return _delta_t;
287 }
288
295 {
297 }
298
307 {
309 }
310
319 {
321 }
322
331 {
333 }
334
343 {
345 }
346
353 {
354 _startup = false;
355
357 }
358
368 void set_coeffs(const Index num_steps, const Index p_extrapolation_steps)
369 {
370
371 if(num_steps == Index(1))
372 {
373 // Mass matrix
374 coeff_lhs_v.at(0) = DataType(1);
375 // Convection matrix
376 coeff_lhs_v.at(1) = (conv_handling == TermHandling::impl || ale_handling == TermHandling::impl)
377 ? _delta_t : DataType(0);
378 // Stiffness matrix
379 coeff_lhs_v.at(2) = (visc_handling == TermHandling::impl) ? _delta_t/_reynolds : DataType(0);
380
381 // Mass matrix
382 coeff_rhs_v_1.at(0) = DataType(1);
383 // Convection matrix
384 coeff_rhs_v_1.at(1) = (conv_handling == TermHandling::expl || ale_handling == TermHandling::expl)
385 ? -_delta_t : DataType(0);
386 // Stiffness matrix
387 coeff_rhs_v_1.at(2) = (visc_handling == TermHandling::expl) ? -_delta_t/_reynolds : DataType(0);
388
389 // Mass matrix coefficient for previous time step vector
391
393
394 // coefficient for -(p*[k], div phi) on the rhs for the velocity eq.
396 // coefficient for -(phi[k], div phi) on the rhs for the velocity eq.
397 coeff_rhs_v_phi.at(0) = -_delta_t;
398
400
401 }
402 else if(num_steps == Index(2))
403 {
404 // Mass matrix
405 coeff_lhs_v.at(0) = DataType(1);
406 // Convection matrix
407 coeff_lhs_v.at(1) = (conv_handling == TermHandling::impl) ? DataType(2)/DataType(3)*_delta_t : DataType(0);
408 // Stiffness matrix
409 coeff_lhs_v.at(2) = (visc_handling == TermHandling::impl || ale_handling == TermHandling::impl)
411
412 // Mass matrix
413 coeff_rhs_v_1.at(0) = DataType(4)/DataType(3);
414 // Convection matrix
415 coeff_rhs_v_1.at(1) = (conv_handling == TermHandling::expl || ale_handling == TermHandling::expl)
416 ? -DataType(2)/DataType(3)*_delta_t : DataType(0);
417 // Stiffness matrix
418 coeff_rhs_v_1.at(2) =
419 (visc_handling == TermHandling::expl) ? -DataType(2)/DataType(3)*_delta_t/_reynolds : DataType(0);
420
422
423 // Mass matrix coefficient for previous time step vector
425
426 // coefficient for -(p*[k], div phi) on the rhs for the velocity eq.
428
429 // coefficient for -(phi[k], div phi) on the rhs for the velocity eq.
431 // coefficient for -(phi[k-1], div phi) on the rhs for the velocity eq.
433
435
436 }
437 else
438 {
439 XABORTM("Invalid number of BDF steps: "+stringify(num_steps));
440 }
441
442 // Coefficient for the div v term for the projection step
444
446 {
448 }
449
450 // Coefficients for the extrapolation of the pressure
451 if(p_extrapolation_steps == Index(1))
452 {
454 }
455 else if(p_extrapolation_steps == Index(2))
456 {
459 }
460 else
461 {
462 XABORTM("Invalid number of pressure extrapolation steps: "+stringify(p_extrapolation_steps));
463 }
464
465 }
466 };
467 } // namespace Time
468 } // namespace Control
469} // name FEAT
#define XABORTM(msg)
Abortion macro definition with custom message.
Definition: assertion.hpp:192
#define XASSERT(expr)
Assertion macro definition.
Definition: assertion.hpp:262
#define XASSERTM(expr, msg)
Assertion macro definition with custom message.
Definition: assertion.hpp:263
FEAT Kernel base header.
Set of coefficients for operator splitting time discretizations based on BDF(q)
Definition: nvs_bdf_q.hpp:115
std::vector< DataType > coeff_rhs_v_phi
k coeffcients for the auxillary variable phi enforcing the weak-divergence free condition
Definition: nvs_bdf_q.hpp:148
DT_ DataType
The floating point precision.
Definition: nvs_bdf_q.hpp:118
DataType _delta_t
The time step size.
Definition: nvs_bdf_q.hpp:132
DataType coeff_rhs_v_2
Coefficient for the reaction term depending on u[k-2].
Definition: nvs_bdf_q.hpp:159
std::vector< DataType > coeff_rhs_v_1
Definition: nvs_bdf_q.hpp:146
Index get_p_extrapolation_steps()
Returns the current number of pressure extrapolation steps.
Definition: nvs_bdf_q.hpp:342
Index get_num_steps()
Returns the current number of steps.
Definition: nvs_bdf_q.hpp:306
virtual ~NvsBdfQ()
Virtual destructor.
Definition: nvs_bdf_q.hpp:275
Index _num_steps
The k in BDF(k), has to be 1 or 2.
Definition: nvs_bdf_q.hpp:122
DataType coeff_rhs_proj_D_v
Coefficient for the div(u) term for the projection step.
Definition: nvs_bdf_q.hpp:155
TermHandling visc_handling
How to handle the viscous term.
Definition: nvs_bdf_q.hpp:168
void set_coeffs(const Index num_steps, const Index p_extrapolation_steps)
Sets the coefficients.
Definition: nvs_bdf_q.hpp:368
std::vector< DataType > coeff_extrapolation_p
coefficients for extrapolating the pressure from previous time steps
Definition: nvs_bdf_q.hpp:150
Index _p_extrapolation_steps_startup
Same in the startup phase.
Definition: nvs_bdf_q.hpp:128
Index _num_steps_startup
If k > 1, the methods performs this many steps as BDF(1) before switching to BDF(k)
Definition: nvs_bdf_q.hpp:124
bool is_rotational()
Are we using the rotational form?
Definition: nvs_bdf_q.hpp:294
const DataType _reynolds
The Reynolds number.
Definition: nvs_bdf_q.hpp:130
Index _p_extrapolation_steps
How many backward steps should be taken for extrapolating the pressure.
Definition: nvs_bdf_q.hpp:126
void finish_startup()
Finishes the startup phase.
Definition: nvs_bdf_q.hpp:352
bool _use_rotational_form
Shall we use the rotational form of the operator splitting?
Definition: nvs_bdf_q.hpp:136
bool _startup
Are we still in the startup phase?
Definition: nvs_bdf_q.hpp:138
bool _use_deformation
Shall we use the deformation tensor based bilinear form for the momentum equation?
Definition: nvs_bdf_q.hpp:134
TermHandling conv_handling
How to handle the convection term.
Definition: nvs_bdf_q.hpp:166
TermHandling ale_handling
How to handle the ALE term.
Definition: nvs_bdf_q.hpp:164
DataType coeff_rhs_phi
Coefficient the auxillary Poisson problem.
Definition: nvs_bdf_q.hpp:157
DataType coeff_rhs_v_p
Coefficient for the pressure gradient for the rhs of the momentum equation.
Definition: nvs_bdf_q.hpp:161
DataType coeff_rhs_f
Coefficient for the rhs for the momentum equation.
Definition: nvs_bdf_q.hpp:153
std::vector< DataType > coeff_lhs_v
Definition: nvs_bdf_q.hpp:143
NvsBdfQ(PropertyMap *config_section, const DataType reynolds, const bool use_deformation, const bool startup)
Constructor using a PropertyMap.
Definition: nvs_bdf_q.hpp:185
Index get_max_num_steps()
Returns the maximum number of steps.
Definition: nvs_bdf_q.hpp:318
DataType delta_t()
Returns the time step size.
Definition: nvs_bdf_q.hpp:284
Index get_max_p_extrapolation_steps()
Returns the maximum number of pressure extrapolation steps.
Definition: nvs_bdf_q.hpp:330
A class organizing a tree of key-value pairs.
std::pair< String, bool > query(String key_path) const
Queries a value by its key path.
TermHandling
For determining if a term is handled explicitly or implicitly.
Definition: base.hpp:24
T_ min(T_ a, T_ b)
Returns the minimum of two values.
Definition: math.hpp:123
T_ max(T_ a, T_ b)
Returns the maximum of two values.
Definition: math.hpp:137
FEAT namespace.
Definition: adjactor.hpp:12
String stringify(const T_ &item)
Converts an item into a String.
Definition: string.hpp:944
std::uint64_t Index
Index data type.