35 const unsigned int look_back)
36 : look_ahead(look_ahead)
37 , look_back(look_back)
69 (position ==
nullptr),
74 if (position ==
nullptr)
80 timesteps.back()->set_next_timestep(new_timestep);
92 timesteps[0]->set_previous_timestep(new_timestep);
101 const std::vector<SmartPointer<TimeStepBase, TimeDependent>>::iterator
110 (*(insert_position - 1))->set_next_timestep(new_timestep);
113 (*insert_position)->set_previous_timestep(new_timestep);
153 timesteps[position - 1]->set_next_timestep(
161 timesteps[position]->set_previous_timestep(
162 (position != 0) ?
timesteps[position - 1] :
213 for (
unsigned int step = 0; step <
timesteps.size(); ++step)
220 timestep->start_sweep();
231 [
this](
const unsigned int begin,
const unsigned int end) {
232 this->end_sweep(begin, end);
242 for (
unsigned int step = begin; step < end; ++step)
268 : previous_timestep(nullptr)
269 , next_timestep(nullptr)
270 , sweep_no(
numbers::invalid_unsigned_int)
271 , timestep_no(
numbers::invalid_unsigned_int)
273 , next_action(
numbers::invalid_unsigned_int)
362 ExcMessage(
"The backward time step cannot be computed because "
363 "there is no previous time step."));
373 ExcMessage(
"The forward time step cannot be computed because "
374 "there is no next time step."));
416 return sizeof(*this);
424 , tria(nullptr, typeid(*this).name())
425 , coarse_grid(nullptr, typeid(*this).name())
427 , refinement_flags(0)
440 const RefinementFlags &refinement_flags)
442 , tria(nullptr, typeid(*this).name())
443 , coarse_grid(&coarse_grid, typeid(*this).name())
445 , refinement_flags(refinement_flags)
454 if (!flags.delete_and_rebuild_tria)
463 coarse_grid =
nullptr;
474 if (wakeup_level == flags.wakeup_level_to_build_grid)
475 if (flags.delete_and_rebuild_tria || !tria)
485 if (sleep_level == flags.sleep_level_to_delete_grid)
489 if (flags.delete_and_rebuild_tria)
508 refine_flags.emplace_back();
509 coarsen_flags.emplace_back();
510 tria->save_refine_flags(refine_flags.back());
511 tria->save_coarsen_flags(coarsen_flags.back());
520 Assert(tria ==
nullptr, ExcGridNotDeleted());
526 tria->copy_triangulation(*coarse_grid);
530 for (
unsigned int previous_sweep = 0; previous_sweep < refine_flags.size();
534 tria->load_refine_flags(refine_flags[previous_sweep]);
535 tria->load_coarsen_flags(coarsen_flags[previous_sweep]);
548 tria->execute_coarsening_and_refinement();
559 mirror_refinement_flags(
585 if (new_cell->is_active())
587 if (new_cell->refine_flag_set() && old_cell->is_active())
589 if (old_cell->coarsen_flag_set())
590 old_cell->clear_coarsen_flag();
592 old_cell->set_refine_flag();
598 if (old_cell->has_children() && new_cell->has_children())
600 Assert(old_cell->n_children() == new_cell->n_children(),
602 for (
unsigned int c = 0; c < new_cell->n_children(); ++c)
603 ::mirror_refinement_flags<dim>(new_cell->child(c),
615 if (cell2->has_children() && cell1->has_children())
617 bool grids_changed =
false;
620 for (
unsigned int c = 0; c < cell1->n_children(); ++c)
622 ::adapt_grid_cells<dim>(cell1->child(c), cell2->child(c));
623 return grids_changed;
627 if (!cell1->has_children() && !cell2->has_children())
633 if (cell1->refine_flag_set() && cell2->coarsen_flag_set())
635 cell2->clear_coarsen_flag();
638 else if (cell1->coarsen_flag_set() && cell2->refine_flag_set())
640 cell1->clear_coarsen_flag();
648 if (cell1->has_children() && !cell2->has_children())
667 bool changed_grid =
false;
668 if (cell2->coarsen_flag_set())
670 cell2->clear_coarsen_flag();
674 if (!cell2->refine_flag_set())
675 for (
unsigned int c = 0; c < cell1->n_children(); ++c)
676 if (cell1->child(c)->refine_flag_set() ||
677 cell1->child(c)->has_children())
679 cell2->set_refine_flag();
686 if (!cell1->has_children() && cell2->has_children())
689 bool changed_grid =
false;
690 if (cell1->coarsen_flag_set())
692 cell1->clear_coarsen_flag();
696 if (!cell1->refine_flag_set())
697 for (
unsigned int c = 0; c < cell2->n_children(); ++c)
698 if (cell2->child(c)->refine_flag_set() ||
699 cell2->child(c)->has_children())
701 cell1->set_refine_flag();
718 bool grids_changed =
false;
721 cell2 = tria2.
begin();
726 for (; cell1 != endc; ++cell1, ++cell2)
727 grids_changed |= ::adapt_grid_cells<dim>(cell1, cell2);
729 return grids_changed;
739 get_tria_refinement_criteria(criteria);
744 double refinement_threshold = refinement_data.refinement_threshold,
745 coarsening_threshold = refinement_data.coarsening_threshold;
759 p_coarsening_threshold =
nullptr;
776 if ((timestep_no != 0) &&
777 (sweep_no >= refinement_flags.first_sweep_with_correction) &&
778 (refinement_flags.cell_number_correction_steps > 0))
780 sorted_criteria = criteria;
781 std::sort(sorted_criteria.
begin(), sorted_criteria.
end());
782 p_refinement_threshold =
784 sorted_criteria.
end(),
785 static_cast<float>(refinement_threshold));
786 p_coarsening_threshold =
787 std::upper_bound(sorted_criteria.
begin(),
788 sorted_criteria.
end(),
789 static_cast<float>(coarsening_threshold));
800 const unsigned int n_active_cells = tria->n_active_cells();
841 if ((timestep_no != 0) &&
842 (sweep_no >= refinement_flags.first_sweep_with_correction))
843 for (
unsigned int loop = 0;
844 loop < refinement_flags.cell_number_correction_steps;
853 if (refinement_flags.adapt_grids)
854 ::adapt_grids<dim>(*previous_tria, *tria);
859 tria->prepare_coarsening_and_refinement();
884 endc = previous_tria->
end();
885 for (; cell != endc; ++cell)
886 if (cell->refine_flag_set())
888 else if (cell->coarsen_flag_set())
889 previous_cells -=
static_cast<double>(
909 double estimated_cells = n_active_cells;
910 cell = tria->begin_active();
912 for (; cell != endc; ++cell)
913 if (cell->refine_flag_set())
915 else if (cell->coarsen_flag_set())
916 estimated_cells -=
static_cast<double>(
923 double delta_up = refinement_flags.cell_number_corridor_top,
924 delta_down = refinement_flags.cell_number_corridor_bottom;
926 const std::vector<std::pair<unsigned int, double>> &relaxations =
927 (sweep_no >= refinement_flags.correction_relaxations.size() ?
928 refinement_flags.correction_relaxations.back() :
929 refinement_flags.correction_relaxations[sweep_no]);
930 for (
const auto &relaxation : relaxations)
931 if (n_active_cells < relaxation.first)
933 delta_up *= relaxation.second;
934 delta_down *= relaxation.second;
947 if (estimated_cells > previous_cells * (1. + delta_up))
965 if (estimated_cells > refinement_flags.min_cells_for_correction)
970 estimated_cells - previous_cells * (1. + delta_up);
981 for (
unsigned int i = 0; i < delta_cells;
983 if (p_refinement_threshold != sorted_criteria.
end())
984 ++p_refinement_threshold;
1003 if (estimated_cells < previous_cells * (1. - delta_down))
1007 double delta_cells =
1008 previous_cells * (1. - delta_down) - estimated_cells;
1034 if (loop != refinement_flags.cell_number_correction_steps - 1)
1043 for (
unsigned int i = 0; i < delta_cells;
1045 if (p_refinement_threshold != p_coarsening_threshold)
1046 --refinement_threshold;
1047 else if (p_coarsening_threshold != sorted_criteria.
begin())
1048 --p_coarsening_threshold, --p_refinement_threshold;
1057 if (p_refinement_threshold == sorted_criteria.
end())
1059 Assert(p_coarsening_threshold != p_refinement_threshold,
1061 --p_refinement_threshold;
1064 coarsening_threshold = *p_coarsening_threshold;
1065 refinement_threshold = *p_refinement_threshold;
1067 if (coarsening_threshold >= refinement_threshold)
1068 coarsening_threshold = 0.999 * refinement_threshold;
1074 cell = tria->begin_active();
1076 for (; cell != endc; ++cell)
1078 cell->clear_refine_flag();
1079 cell->clear_coarsen_flag();
1095 if ((timestep_no >= 1) && (refinement_flags.adapt_grids))
1112 if (refinement_flags.mirror_flags_to_previous_grid)
1114 ::adapt_grids<dim>(*previous_tria, *tria);
1117 old_cell = previous_tria->
begin(0);
1118 new_cell = tria->begin(0);
1119 endc = tria->end(0);
1120 for (; new_cell != endc; ++new_cell, ++old_cell)
1121 ::mirror_refinement_flags<dim>(new_cell, old_cell);
1124 tria->prepare_coarsening_and_refinement();
1132 ::adapt_grids<dim>(*previous_tria, *tria);
1142 next_action = grid_refinement;
1153 sizeof(refinement_flags) +
1162 : delete_and_rebuild_tria(false)
1163 , wakeup_level_to_build_grid(0)
1164 , sleep_level_to_delete_grid(0)
1173 const bool delete_and_rebuild_tria,
1174 const unsigned int wakeup_level_to_build_grid,
1175 const unsigned int sleep_level_to_delete_grid)
1176 : delete_and_rebuild_tria(delete_and_rebuild_tria)
1177 , wakeup_level_to_build_grid(wakeup_level_to_build_grid)
1178 , sleep_level_to_delete_grid(sleep_level_to_delete_grid)
1191 std::vector<std::pair<unsigned int, double>>(1,
1194 std::make_pair(0U, 0.)));
1199 const unsigned int max_refinement_level,
1200 const unsigned int first_sweep_with_correction,
1201 const unsigned int min_cells_for_correction,
1202 const double cell_number_corridor_top,
1203 const double cell_number_corridor_bottom,
1205 const unsigned int cell_number_correction_steps,
1206 const bool mirror_flags_to_previous_grid,
1207 const bool adapt_grids)
1208 : max_refinement_level(max_refinement_level)
1209 , first_sweep_with_correction(first_sweep_with_correction)
1210 , min_cells_for_correction(min_cells_for_correction)
1211 , cell_number_corridor_top(cell_number_corridor_top)
1212 , cell_number_corridor_bottom(cell_number_corridor_bottom)
1213 , correction_relaxations(correction_relaxations.size() != 0 ?
1214 correction_relaxations :
1215 default_correction_relaxations)
1216 , cell_number_correction_steps(cell_number_correction_steps)
1217 , mirror_flags_to_previous_grid(mirror_flags_to_previous_grid)
1218 , adapt_grids(adapt_grids)
1231 const double _refinement_threshold,
1232 const double _coarsening_threshold)
1233 : refinement_threshold(_refinement_threshold)
1253 coarsening_threshold((_coarsening_threshold == _refinement_threshold ?
1254 _coarsening_threshold :
1255 0.999 * _coarsening_threshold))
1270#include "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
const TimeSteppingData timestepping_data_primal
std::vector< SmartPointer< TimeStepBase, TimeDependent > > timesteps
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
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
#define DEAL_II_ASSERT_UNREACHABLE()
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)
VectorType::value_type * begin(VectorType &V)
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)
std::vector< std::vector< std::pair< unsigned int, double > > > CorrectionRelaxations
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)
static CorrectionRelaxations default_correction_relaxations
const double cell_number_corridor_bottom