Lethe Open-Source Library version 1.2.0
Developer Guide
Loading...
Searching...
No Matches
mesh_controller.cc
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) 2023 The Lethe Authors
2// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
3
5
6double
8 unsigned int current_number_of_elements)
9{
10 // Parameters of the controller
11 double P = 0.5;
12 double I = 0.3;
13 double D = 0.1;
14
15 // Evaluation of the error used to control the mesh refinement.
16 double error = static_cast<signed>(target_number_of_elements -
17 current_number_of_elements) /
18 static_cast<double>(target_number_of_elements);
19 double previous_error = static_cast<signed>(target_number_of_elements -
21 static_cast<double>(target_number_of_elements);
22
23 previous_number_of_elements = current_number_of_elements;
25
26 // Calculate the coarsening factor
27 double coarsening_fraction_controlled =
28 -error * P - previous_mesh_control_error * I - (error - previous_error) * D;
29
30 // Saturate the coarsening parameter.
31 if (coarsening_fraction_controlled < 0.0)
32 {
33 // Stop the integration if we are at the saturation point.
34 coarsening_fraction_controlled = 0;
35 if (error > 0.0)
37 }
38 if (coarsening_fraction_controlled > 1.0)
39 {
40 coarsening_fraction_controlled = 1;
41 // Stop the integration if we are at the saturation point.
42 if (error < 1.0)
44 }
45
46 return coarsening_fraction_controlled;
47}
const unsigned int target_number_of_elements
unsigned int previous_number_of_elements
double calculate_coarsening_factor(unsigned int current_number_of_elements)
Returns the coarsening factor.
double previous_mesh_control_error