10#include <deal.II/grid/grid_refinement.h>
14 template <
typename Description,
int dim,
typename Number>
16 const MPI_Comm &mpi_communicator,
20 const std::string &subsection )
21 : ParameterAcceptor(subsection)
22 , mpi_communicator_(mpi_communicator)
23 , offline_data_(&offline_data)
24 , hyperbolic_system_(&hyperbolic_system)
25 , parabolic_system_(¶bolic_system)
26 , need_mesh_adaptation_(false)
29 add_parameter(
"adaptation strategy",
31 "The chosen adaptation strategy. Possible values are: global "
32 "refinement, random adaptation");
38 "The chosen marking strategy. Possible values are: fixed number");
40 time_point_selection_strategy_ =
42 add_parameter(
"time point selection strategy",
43 time_point_selection_strategy_,
44 "The chosen time point selection strategy. Possible values "
45 "are: fixed adaptation time points");
48 enter_subsection(
"adaptation strategies");
49 random_adaptation_mersenne_twister_seed_ = 42u;
50 add_parameter(
"random adaptation: mersenne_twister_seed",
51 random_adaptation_mersenne_twister_seed_,
52 "Seed for 64bit Mersenne Twister used for random refinement");
57 enter_subsection(
"marking strategies");
58 fixed_number_refinement_fraction_ = 0.3;
60 "fixed number: refinement fraction",
61 fixed_number_refinement_fraction_,
62 "Fixed number strategy: fraction of cells selected for refinement.");
64 fixed_number_coarsening_fraction_ = 0.3;
66 "fixed number: coarsening fraction",
67 fixed_number_coarsening_fraction_,
68 "Fixed number strategy: fraction of cells selected for coarsening.");
73 enter_subsection(
"time point selection strategies");
74 adaptation_time_points_ = {};
75 add_parameter(
"adaptation timepoints",
76 adaptation_time_points_,
77 "List of time points in (simulation) time at which we will "
78 "perform a mesh adaptation cycle.");
81 const auto call_back = [
this] {
83 mersenne_twister_.seed(random_adaptation_mersenne_twister_seed_);
87 ParameterAcceptor::parse_parameters_call_back.connect(call_back);
91 template <
typename Description,
int dim,
typename Number>
95 std::cout <<
"MeshAdaptor<dim, Number>::prepare()" << std::endl;
98 switch (time_point_selection_strategy_) {
101 const auto new_end = std::remove_if(
102 adaptation_time_points_.begin(),
103 adaptation_time_points_.end(),
104 [&](
const Number &t_refinement) { return (t > t_refinement); });
105 adaptation_time_points_.erase(new_end, adaptation_time_points_.end());
114 need_mesh_adaptation_ =
false;
118 template <
typename Description,
int dim,
typename Number>
125 std::cout <<
"MeshAdaptor<dim, Number>::analyze()" << std::endl;
128 switch (time_point_selection_strategy_) {
131 const auto new_end = std::remove_if(
132 adaptation_time_points_.begin(),
133 adaptation_time_points_.end(),
134 [&](
const Number &t_refinement) {
135 if (t < t_refinement)
137 need_mesh_adaptation_ = true;
140 adaptation_time_points_.erase(new_end, adaptation_time_points_.end());
144 AssertThrow(
false, dealii::ExcInternalError());
150 template <
typename Description,
int dim,
typename Number>
153 dealii::Triangulation<dim> &triangulation)
const
155 auto &discretization [[maybe_unused]] = offline_data_->discretization();
156 Assert(&triangulation == &discretization.triangulation(),
157 dealii::ExcInternalError());
163 dealii::Vector<float> indicators;
165 switch (adaptation_strategy_) {
168 for (
auto &cell : triangulation.active_cell_iterators())
169 cell->set_refine_flag();
174 indicators.reinit(triangulation.n_active_cells());
175 std::generate(std::begin(indicators), std::end(indicators), [&]() {
176 static std::uniform_real_distribution<double> distribution(0.0, 10.0);
177 return distribution(mersenne_twister_);
182 AssertThrow(
false, dealii::ExcInternalError());
190 switch (marking_strategy_) {
192 dealii::GridRefinement::refine_and_coarsen_fixed_number(
195 fixed_number_refinement_fraction_,
196 fixed_number_coarsening_fraction_);
200 AssertThrow(
false, dealii::ExcInternalError());
typename View::StateVector StateVector
void analyze(const StateVector &state_vector, const Number t, unsigned int cycle)
typename Description::ParabolicSystem ParabolicSystem
typename Description::HyperbolicSystem HyperbolicSystem
void mark_cells_for_coarsening_and_refinement(dealii::Triangulation< dim > &triangulation) const
void prepare(const Number t)
MeshAdaptor(const MPI_Comm &mpi_communicator, const OfflineData< dim, Number > &offline_data, const HyperbolicSystem &hyperbolic_system, const ParabolicSystem ¶bolic_system, const std::string &subsection="/MeshAdaptor")
@ fixed_adaptation_time_points