33 const unsigned int look_back)
34 : look_ahead(look_ahead)
35 , look_back(look_back)
67 (position ==
nullptr),
72 if (position ==
nullptr)
78 timesteps.back()->set_next_timestep(new_timestep);
90 timesteps[0]->set_previous_timestep(new_timestep);
99 const std::vector<ObserverPointer<TimeStepBase, TimeDependent>>::iterator
108 (*(insert_position - 1))->set_next_timestep(new_timestep);
111 (*insert_position)->set_previous_timestep(new_timestep);
159 timesteps[position]->set_previous_timestep(
212 for (
unsigned int step = 0; step <
timesteps.size(); ++step)
219 timestep->start_sweep();
230 [
this](
const unsigned int begin,
const unsigned int end) {
231 this->end_sweep(begin, end);
241 for (
unsigned int step =
begin; step <
end; ++step)
267 : previous_timestep(nullptr)
268 , next_timestep(nullptr)
269 , sweep_no(
numbers::invalid_unsigned_int)
270 , timestep_no(
numbers::invalid_unsigned_int)
272 , next_action(
numbers::invalid_unsigned_int)
361 ExcMessage(
"The backward time step cannot be computed because "
362 "there is no previous time step."));
372 ExcMessage(
"The forward time step cannot be computed because "
373 "there is no next time step."));
415 return sizeof(*this);
423 , tria(nullptr, typeid(*this).name())
424 , coarse_grid(nullptr, typeid(*this).name())
426 , refinement_flags(0)
439 const RefinementFlags &refinement_flags)
441 , tria(nullptr, typeid(*this).name())
442 , coarse_grid(&coarse_grid, typeid(*this).name())
444 , refinement_flags(refinement_flags)
453 if (!flags.delete_and_rebuild_tria)
462 coarse_grid =
nullptr;
473 if (wakeup_level == flags.wakeup_level_to_build_grid)
474 if (flags.delete_and_rebuild_tria || !tria)
484 if (sleep_level == flags.sleep_level_to_delete_grid)
488 if (flags.delete_and_rebuild_tria)
507 refine_flags.emplace_back();
508 coarsen_flags.emplace_back();
509 tria->save_refine_flags(refine_flags.back());
510 tria->save_coarsen_flags(coarsen_flags.back());
519 Assert(tria ==
nullptr, ExcGridNotDeleted());
525 tria->copy_triangulation(*coarse_grid);
529 for (
unsigned int previous_sweep = 0; previous_sweep < refine_flags.size();
533 tria->load_refine_flags(refine_flags[previous_sweep]);
534 tria->load_coarsen_flags(coarsen_flags[previous_sweep]);
547 tria->execute_coarsening_and_refinement();
558 mirror_refinement_flags(
584 if (new_cell->is_active())
586 if (new_cell->refine_flag_set() && old_cell->is_active())
588 if (old_cell->coarsen_flag_set())
589 old_cell->clear_coarsen_flag();
591 old_cell->set_refine_flag();
597 if (old_cell->has_children() && new_cell->has_children())
599 Assert(old_cell->n_children() == new_cell->n_children(),
601 for (
unsigned int c = 0; c < new_cell->n_children(); ++c)
602 ::mirror_refinement_flags<dim>(new_cell->child(c),
614 if (cell2->has_children() && cell1->has_children())
616 bool grids_changed =
false;
619 for (
unsigned int c = 0; c < cell1->n_children(); ++c)
621 ::adapt_grid_cells<dim>(cell1->child(c), cell2->child(c));
622 return grids_changed;
626 if (!cell1->has_children() && !cell2->has_children())
632 if (cell1->refine_flag_set() && cell2->coarsen_flag_set())
634 cell2->clear_coarsen_flag();
637 else if (cell1->coarsen_flag_set() && cell2->refine_flag_set())
639 cell1->clear_coarsen_flag();
647 if (cell1->has_children() && !cell2->has_children())
666 bool changed_grid =
false;
667 if (cell2->coarsen_flag_set())
669 cell2->clear_coarsen_flag();
673 if (!cell2->refine_flag_set())
674 for (
unsigned int c = 0; c < cell1->n_children(); ++c)
675 if (cell1->child(c)->refine_flag_set() ||
676 cell1->child(c)->has_children())
678 cell2->set_refine_flag();
685 if (!cell1->has_children() && cell2->has_children())
688 bool changed_grid =
false;
689 if (cell1->coarsen_flag_set())
691 cell1->clear_coarsen_flag();
695 if (!cell1->refine_flag_set())
696 for (
unsigned int c = 0; c < cell2->n_children(); ++c)
697 if (cell2->child(c)->refine_flag_set() ||
698 cell2->child(c)->has_children())
700 cell1->set_refine_flag();
717 bool grids_changed =
false;
720 cell2 = tria2.
begin();
725 for (; cell1 != endc; ++cell1, ++cell2)
726 grids_changed |= ::adapt_grid_cells<dim>(cell1, cell2);
728 return grids_changed;
738 get_tria_refinement_criteria(criteria);
743 double refinement_threshold = refinement_data.refinement_threshold,
744 coarsening_threshold = refinement_data.coarsening_threshold;
758 p_coarsening_threshold =
nullptr;
775 if ((timestep_no != 0) &&
776 (sweep_no >= refinement_flags.first_sweep_with_correction) &&
777 (refinement_flags.cell_number_correction_steps > 0))
779 sorted_criteria = criteria;
780 std::sort(sorted_criteria.
begin(), sorted_criteria.
end());
781 p_refinement_threshold =
783 sorted_criteria.
end(),
784 static_cast<float>(refinement_threshold));
785 p_coarsening_threshold =
786 std::upper_bound(sorted_criteria.
begin(),
787 sorted_criteria.
end(),
788 static_cast<float>(coarsening_threshold));
799 const unsigned int n_active_cells = tria->n_active_cells();
840 if ((timestep_no != 0) &&
841 (sweep_no >= refinement_flags.first_sweep_with_correction))
842 for (
unsigned int loop = 0;
843 loop < refinement_flags.cell_number_correction_steps;
852 if (refinement_flags.adapt_grids)
853 ::adapt_grids<dim>(*previous_tria, *tria);
858 tria->prepare_coarsening_and_refinement();
883 endc = previous_tria->
end();
884 for (; cell != endc; ++cell)
885 if (cell->refine_flag_set())
887 else if (cell->coarsen_flag_set())
888 previous_cells -=
static_cast<double>(
908 double estimated_cells = n_active_cells;
909 cell = tria->begin_active();
911 for (; cell != endc; ++cell)
912 if (cell->refine_flag_set())
914 else if (cell->coarsen_flag_set())
915 estimated_cells -=
static_cast<double>(
922 double delta_up = refinement_flags.cell_number_corridor_top,
923 delta_down = refinement_flags.cell_number_corridor_bottom;
925 const std::vector<std::pair<unsigned int, double>> &relaxations =
926 (sweep_no >= refinement_flags.correction_relaxations.size() ?
927 refinement_flags.correction_relaxations.back() :
928 refinement_flags.correction_relaxations[sweep_no]);
929 for (
const auto &relaxation : relaxations)
930 if (n_active_cells < relaxation.first)
932 delta_up *= relaxation.second;
933 delta_down *= relaxation.second;
946 if (estimated_cells > previous_cells * (1. + delta_up))
964 if (estimated_cells > refinement_flags.min_cells_for_correction)
969 estimated_cells - previous_cells * (1. + delta_up);
980 for (
unsigned int i = 0; i < delta_cells;
982 if (p_refinement_threshold != sorted_criteria.
end())
983 ++p_refinement_threshold;
1002 if (estimated_cells < previous_cells * (1. - delta_down))
1006 double delta_cells =
1007 previous_cells * (1. - delta_down) - estimated_cells;
1033 if (loop != refinement_flags.cell_number_correction_steps - 1)
1042 for (
unsigned int i = 0; i < delta_cells;
1044 if (p_refinement_threshold != p_coarsening_threshold)
1045 --refinement_threshold;
1046 else if (p_coarsening_threshold != sorted_criteria.
begin())
1047 --p_coarsening_threshold, --p_refinement_threshold;
1056 if (p_refinement_threshold == sorted_criteria.
end())
1058 Assert(p_coarsening_threshold != p_refinement_threshold,
1060 --p_refinement_threshold;
1063 coarsening_threshold = *p_coarsening_threshold;
1064 refinement_threshold = *p_refinement_threshold;
1066 if (coarsening_threshold >= refinement_threshold)
1067 coarsening_threshold = 0.999 * refinement_threshold;
1073 cell = tria->begin_active();
1075 for (; cell != endc; ++cell)
1077 cell->clear_refine_flag();
1078 cell->clear_coarsen_flag();
1094 if ((timestep_no >= 1) && (refinement_flags.adapt_grids))
1111 if (refinement_flags.mirror_flags_to_previous_grid)
1113 ::adapt_grids<dim>(*previous_tria, *tria);
1116 old_cell = previous_tria->
begin(0);
1117 new_cell = tria->begin(0);
1118 endc = tria->end(0);
1119 for (; new_cell != endc; ++new_cell, ++old_cell)
1120 ::mirror_refinement_flags<dim>(new_cell, old_cell);
1123 tria->prepare_coarsening_and_refinement();
1131 ::adapt_grids<dim>(*previous_tria, *tria);
1141 next_action = grid_refinement;
1152 sizeof(refinement_flags) +
1161 : delete_and_rebuild_tria(false)
1162 , wakeup_level_to_build_grid(0)
1163 , sleep_level_to_delete_grid(0)
1172 const bool delete_and_rebuild_tria,
1173 const unsigned int wakeup_level_to_build_grid,
1174 const unsigned int sleep_level_to_delete_grid)
1175 : delete_and_rebuild_tria(delete_and_rebuild_tria)
1176 , wakeup_level_to_build_grid(wakeup_level_to_build_grid)
1177 , sleep_level_to_delete_grid(sleep_level_to_delete_grid)
1190 std::vector<std::pair<unsigned int, double>>(1,
1193 std::make_pair(0U, 0.)));
1198 const unsigned int max_refinement_level,
1199 const unsigned int first_sweep_with_correction,
1200 const unsigned int min_cells_for_correction,
1201 const double cell_number_corridor_top,
1202 const double cell_number_corridor_bottom,
1204 const unsigned int cell_number_correction_steps,
1205 const bool mirror_flags_to_previous_grid,
1206 const bool adapt_grids)
1207 : max_refinement_level(max_refinement_level)
1208 , first_sweep_with_correction(first_sweep_with_correction)
1209 , min_cells_for_correction(min_cells_for_correction)
1210 , cell_number_corridor_top(cell_number_corridor_top)
1211 , cell_number_corridor_bottom(cell_number_corridor_bottom)
1212 , correction_relaxations(correction_relaxations.
size() != 0 ?
1213 correction_relaxations :
1214 default_correction_relaxations)
1215 , cell_number_correction_steps(cell_number_correction_steps)
1216 , mirror_flags_to_previous_grid(mirror_flags_to_previous_grid)
1217 , adapt_grids(adapt_grids)
1230 const double _refinement_threshold,
1231 const double _coarsening_threshold)
1232 : refinement_threshold(_refinement_threshold)
1252 coarsening_threshold((_coarsening_threshold == _refinement_threshold ?
1253 _coarsening_threshold :
1254 0.999 * _coarsening_threshold))
1269#include "numerics/time_dependent.inst"
void insert_timestep(const TimeStepBase *position, TimeStepBase *new_timestep)
virtual void start_sweep(const unsigned int sweep_no)
std::size_t memory_consumption() const
std::vector< ObserverPointer< TimeStepBase, TimeDependent > > timesteps
const TimeSteppingData timestepping_data_primal
void solve_dual_problem()
void do_loop(InitFunctionObject init_function, LoopFunctionObject loop_function, const TimeSteppingData ×tepping_data, const Direction direction)
const TimeSteppingData timestepping_data_dual
void solve_primal_problem()
TimeDependent(const TimeSteppingData &data_primal, const TimeSteppingData &data_dual, const TimeSteppingData &data_postprocess)
void delete_timestep(const unsigned int position)
void add_timestep(TimeStepBase *new_timestep)
const TimeSteppingData timestepping_data_postprocess
virtual void wake_up(const unsigned int wakeup_level) override
virtual void sleep(const unsigned int) override
virtual std::size_t memory_consumption() const override
void refine_grid(const RefinementData data)
virtual void init_for_refinement()
typename TimeStepBase_Tria_Flags::RefinementData< dim > RefinementData
virtual ~TimeStepBase_Tria() override
virtual std::size_t memory_consumption() const
double get_forward_timestep() const
TimeStepBase(const double time)
virtual void wake_up(const unsigned int)
void set_timestep_no(const unsigned int step_no)
void set_previous_timestep(const TimeStepBase *previous)
const TimeStepBase * previous_timestep
virtual void postprocess_timestep()
virtual void sleep(const unsigned int)
void set_next_timestep(const TimeStepBase *next)
unsigned int get_timestep_no() const
double get_backward_timestep() const
void set_sweep_no(const unsigned int sweep_no)
virtual void solve_primal_problem()=0
virtual void init_for_postprocessing()
virtual void start_sweep()
virtual void init_for_primal_problem()
virtual void solve_dual_problem()
virtual void init_for_dual_problem()
const TimeStepBase * next_timestep
bool get_anisotropic_refinement_flag() const
cell_iterator begin(const unsigned int level=0) const
unsigned int n_active_cells() const
unsigned int n_levels() const
cell_iterator end() const
virtual bool prepare_coarsening_and_refinement()
active_cell_iterator begin_active(const unsigned int level=0) const
const value_type * const_iterator
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_CLOSE
#define DEAL_II_ASSERT_UNREACHABLE()
static ::ExceptionBase & ExcInvalidValue(double arg1)
static ::ExceptionBase & ExcNotImplemented()
#define Assert(cond, exc)
static ::ExceptionBase & ExcPureFunctionCalled()
#define AssertNothrow(cond, exc)
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcInvalidValue(double arg1)
static ::ExceptionBase & ExcMessage(std::string arg1)
static ::ExceptionBase & ExcInvalidPosition()
TriaIterator< CellAccessor< dim, spacedim > > cell_iterator
void refine(Triangulation< dim, spacedim > &tria, const Vector< Number > &criteria, const double threshold, const unsigned int max_to_mark=numbers::invalid_unsigned_int)
void coarsen(Triangulation< dim, spacedim > &tria, const Vector< Number > &criteria, const double threshold)
std::enable_if_t< std::is_fundamental_v< T >, std::size_t > memory_consumption(const T &t)
Iterator lower_bound(Iterator first, Iterator last, const T &val)
void apply_to_subranges(const Iterator &begin, const std_cxx20::type_identity_t< Iterator > &end, const Function &f, const unsigned int grainsize)
TimeSteppingData(const unsigned int look_ahead, const unsigned int look_back)
const double refinement_threshold
const double coarsening_threshold
RefinementData(const double refinement_threshold, const double coarsening_threshold=0)
const double cell_number_corridor_top
RefinementFlags(const unsigned int max_refinement_level=0, const unsigned int first_sweep_with_correction=0, const unsigned int min_cells_for_correction=0, const double cell_number_corridor_top=(1<< dim), const double cell_number_corridor_bottom=1, const CorrectionRelaxations &correction_relaxations=CorrectionRelaxations(), const unsigned int cell_number_correction_steps=0, const bool mirror_flags_to_previous_grid=false, const bool adapt_grids=false)
std::vector< std::vector< std::pair< unsigned int, double > > > CorrectionRelaxations
static CorrectionRelaxations default_correction_relaxations
const double cell_number_corridor_bottom