36 const unsigned int look_back)
37 : look_ahead(look_ahead)
38 , look_back(look_back)
70 (position ==
nullptr),
75 if (position ==
nullptr)
81 timesteps.back()->set_next_timestep(new_timestep);
93 timesteps[0]->set_previous_timestep(new_timestep);
102 const std::vector<SmartPointer<TimeStepBase, TimeDependent>>::iterator
111 (*(insert_position - 1))->set_next_timestep(new_timestep);
114 (*insert_position)->set_previous_timestep(new_timestep);
154 timesteps[position - 1]->set_next_timestep(
162 timesteps[position]->set_previous_timestep(
163 (position != 0) ?
timesteps[position - 1] :
214 for (
unsigned int step = 0; step <
timesteps.size(); ++step)
221 timestep->start_sweep();
231 [
this](
const unsigned int begin,
232 const unsigned int end) {
233 this->end_sweep(begin, end);
243 for (
unsigned int step =
begin; step <
end; ++step)
269 : previous_timestep(nullptr)
270 , next_timestep(nullptr)
363 ExcMessage(
"The backward time step cannot be computed because "
364 "there is no previous time step."));
374 ExcMessage(
"The forward time step cannot be computed because "
375 "there is no next time step."));
417 return sizeof(*this);
425 , tria(nullptr, typeid(*this).name())
426 , coarse_grid(nullptr, typeid(*this).name())
428 , refinement_flags(0)
441 const RefinementFlags & refinement_flags)
443 , tria(nullptr, typeid(*this).name())
444 , coarse_grid(&coarse_grid, typeid(*this).name())
446 , refinement_flags(refinement_flags)
455 if (!flags.delete_and_rebuild_tria)
464 coarse_grid =
nullptr;
475 if (wakeup_level == flags.wakeup_level_to_build_grid)
476 if (flags.delete_and_rebuild_tria || !tria)
486 if (sleep_level == flags.sleep_level_to_delete_grid)
490 if (flags.delete_and_rebuild_tria)
509 refine_flags.emplace_back();
510 coarsen_flags.emplace_back();
511 tria->save_refine_flags(refine_flags.back());
512 tria->save_coarsen_flags(coarsen_flags.back());
521 Assert(tria ==
nullptr, ExcGridNotDeleted());
527 tria->copy_triangulation(*coarse_grid);
531 for (
unsigned int previous_sweep = 0; previous_sweep < refine_flags.size();
535 tria->load_refine_flags(refine_flags[previous_sweep]);
536 tria->load_coarsen_flags(coarsen_flags[previous_sweep]);
549 tria->execute_coarsening_and_refinement();
560 mirror_refinement_flags(
586 if (new_cell->is_active())
588 if (new_cell->refine_flag_set() && old_cell->is_active())
590 if (old_cell->coarsen_flag_set())
591 old_cell->clear_coarsen_flag();
593 old_cell->set_refine_flag();
599 if (old_cell->has_children() && new_cell->has_children())
601 Assert(old_cell->n_children() == new_cell->n_children(),
603 for (
unsigned int c = 0; c < new_cell->n_children(); ++c)
604 ::mirror_refinement_flags<dim>(new_cell->child(c),
616 if (cell2->has_children() && cell1->has_children())
618 bool grids_changed =
false;
621 for (
unsigned int c = 0; c < cell1->n_children(); ++c)
623 ::adapt_grid_cells<dim>(cell1->child(c), cell2->child(c));
624 return grids_changed;
628 if (!cell1->has_children() && !cell2->has_children())
634 if (cell1->refine_flag_set() && cell2->coarsen_flag_set())
636 cell2->clear_coarsen_flag();
639 else if (cell1->coarsen_flag_set() && cell2->refine_flag_set())
641 cell1->clear_coarsen_flag();
649 if (cell1->has_children() && !cell2->has_children())
668 bool changed_grid =
false;
669 if (cell2->coarsen_flag_set())
671 cell2->clear_coarsen_flag();
675 if (!cell2->refine_flag_set())
676 for (
unsigned int c = 0; c < cell1->n_children(); ++c)
677 if (cell1->child(c)->refine_flag_set() ||
678 cell1->child(c)->has_children())
680 cell2->set_refine_flag();
687 if (!cell1->has_children() && cell2->has_children())
690 bool changed_grid =
false;
691 if (cell1->coarsen_flag_set())
693 cell1->clear_coarsen_flag();
697 if (!cell1->refine_flag_set())
698 for (
unsigned int c = 0; c < cell2->n_children(); ++c)
699 if (cell2->child(c)->refine_flag_set() ||
700 cell2->child(c)->has_children())
702 cell1->set_refine_flag();
719 bool grids_changed =
false;
722 cell2 = tria2.
begin();
727 for (; cell1 != endc; ++cell1, ++cell2)
728 grids_changed |= ::adapt_grid_cells<dim>(cell1, cell2);
730 return grids_changed;
740 get_tria_refinement_criteria(criteria);
745 double refinement_threshold = refinement_data.refinement_threshold,
746 coarsening_threshold = refinement_data.coarsening_threshold;
760 p_coarsening_threshold =
nullptr;
777 if ((timestep_no != 0) &&
778 (sweep_no >= refinement_flags.first_sweep_with_correction) &&
779 (refinement_flags.cell_number_correction_steps > 0))
781 sorted_criteria = criteria;
782 std::sort(sorted_criteria.
begin(), sorted_criteria.
end());
783 p_refinement_threshold =
785 sorted_criteria.
end(),
786 static_cast<float>(refinement_threshold));
787 p_coarsening_threshold =
788 std::upper_bound(sorted_criteria.
begin(),
789 sorted_criteria.
end(),
790 static_cast<float>(coarsening_threshold));
842 if ((timestep_no != 0) &&
843 (sweep_no >= refinement_flags.first_sweep_with_correction))
844 for (
unsigned int loop = 0;
845 loop < refinement_flags.cell_number_correction_steps;
854 if (refinement_flags.adapt_grids)
855 ::adapt_grids<dim>(*previous_tria, *tria);
860 tria->prepare_coarsening_and_refinement();
885 endc = previous_tria->
end();
886 for (; cell != endc; ++cell)
887 if (cell->refine_flag_set())
889 else if (cell->coarsen_flag_set())
890 previous_cells -=
static_cast<double>(
911 cell = tria->begin_active();
913 for (; cell != endc; ++cell)
914 if (cell->refine_flag_set())
916 else if (cell->coarsen_flag_set())
917 estimated_cells -=
static_cast<double>(
924 double delta_up = refinement_flags.cell_number_corridor_top,
925 delta_down = refinement_flags.cell_number_corridor_bottom;
927 const std::vector<std::pair<unsigned int, double>> &relaxations =
928 (sweep_no >= refinement_flags.correction_relaxations.size() ?
929 refinement_flags.correction_relaxations.back() :
930 refinement_flags.correction_relaxations[sweep_no]);
931 for (
unsigned int r = 0; r != relaxations.size(); ++r)
934 delta_up *= relaxations[r].second;
935 delta_down *= relaxations[r].second;
948 if (estimated_cells > previous_cells * (1. + delta_up))
966 if (estimated_cells > refinement_flags.min_cells_for_correction)
971 estimated_cells - previous_cells * (1. + delta_up);
982 for (
unsigned int i = 0; i < delta_cells;
984 if (p_refinement_threshold != sorted_criteria.
end())
985 ++p_refinement_threshold;
1004 if (estimated_cells < previous_cells * (1. - delta_down))
1008 double delta_cells =
1009 previous_cells * (1. - delta_down) - estimated_cells;
1035 if (
loop != refinement_flags.cell_number_correction_steps - 1)
1044 for (
unsigned int i = 0; i < delta_cells;
1046 if (p_refinement_threshold != p_coarsening_threshold)
1047 --refinement_threshold;
1048 else if (p_coarsening_threshold != sorted_criteria.
begin())
1049 --p_coarsening_threshold, --p_refinement_threshold;
1058 if (p_refinement_threshold == sorted_criteria.
end())
1060 Assert(p_coarsening_threshold != p_refinement_threshold,
1062 --p_refinement_threshold;
1065 coarsening_threshold = *p_coarsening_threshold;
1066 refinement_threshold = *p_refinement_threshold;
1068 if (coarsening_threshold >= refinement_threshold)
1069 coarsening_threshold = 0.999 * refinement_threshold;
1075 cell = tria->begin_active();
1077 for (; cell != endc; ++cell)
1079 cell->clear_refine_flag();
1080 cell->clear_coarsen_flag();
1096 if ((timestep_no >= 1) && (refinement_flags.adapt_grids))
1113 if (refinement_flags.mirror_flags_to_previous_grid)
1115 ::adapt_grids<dim>(*previous_tria, *tria);
1118 old_cell = previous_tria->
begin(0);
1119 new_cell = tria->begin(0);
1120 endc = tria->end(0);
1121 for (; new_cell != endc; ++new_cell, ++old_cell)
1122 ::mirror_refinement_flags<dim>(new_cell, old_cell);
1125 tria->prepare_coarsening_and_refinement();
1133 ::adapt_grids<dim>(*previous_tria, *tria);
1143 next_action = grid_refinement;
1154 sizeof(refinement_flags) +
1163 : delete_and_rebuild_tria(false)
1164 , wakeup_level_to_build_grid(0)
1165 , sleep_level_to_delete_grid(0)
1174 const bool delete_and_rebuild_tria,
1175 const unsigned int wakeup_level_to_build_grid,
1176 const unsigned int sleep_level_to_delete_grid)
1177 : delete_and_rebuild_tria(delete_and_rebuild_tria)
1178 , wakeup_level_to_build_grid(wakeup_level_to_build_grid)
1179 , sleep_level_to_delete_grid(sleep_level_to_delete_grid)
1192 std::vector<std::pair<unsigned int, double>>(1,
1195 std::make_pair(0
U, 0.)));
1200 const unsigned int max_refinement_level,
1201 const unsigned int first_sweep_with_correction,
1202 const unsigned int min_cells_for_correction,
1203 const double cell_number_corridor_top,
1204 const double cell_number_corridor_bottom,
1206 const unsigned int cell_number_correction_steps,
1207 const bool mirror_flags_to_previous_grid,
1208 const bool adapt_grids)
1209 : max_refinement_level(max_refinement_level)
1210 , first_sweep_with_correction(first_sweep_with_correction)
1211 , min_cells_for_correction(min_cells_for_correction)
1212 , cell_number_corridor_top(cell_number_corridor_top)
1213 , cell_number_corridor_bottom(cell_number_corridor_bottom)
1214 , correction_relaxations(correction_relaxations.size() != 0 ?
1215 correction_relaxations :
1216 default_correction_relaxations)
1217 , cell_number_correction_steps(cell_number_correction_steps)
1218 , mirror_flags_to_previous_grid(mirror_flags_to_previous_grid)
1219 , adapt_grids(adapt_grids)
1232 const double _refinement_threshold,
1233 const double _coarsening_threshold)
1234 : refinement_threshold(_refinement_threshold)
1254 coarsening_threshold((_coarsening_threshold == _refinement_threshold ?
1255 _coarsening_threshold :
1256 0.999 * _coarsening_threshold))
1271#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
#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
void loop(ITERATOR begin, typename identity< ITERATOR >::type end, DOFINFO &dinfo, INFOBOX &info, const std::function< void(DOFINFO &, typename INFOBOX::CellInfo &)> &cell_worker, const std::function< void(DOFINFO &, typename INFOBOX::CellInfo &)> &boundary_worker, const std::function< void(DOFINFO &, DOFINFO &, typename INFOBOX::CellInfo &, typename INFOBOX::CellInfo &)> &face_worker, ASSEMBLER &assembler, const LoopControl &lctrl=LoopControl())
const value_type * const_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< std::is_fundamental< T >::value, std::size_t >::type memory_consumption(const T &t)
VectorType::value_type * end(VectorType &V)
VectorType::value_type * begin(VectorType &V)
Iterator lower_bound(Iterator first, Iterator last, const T &val)
unsigned int n_active_cells(const internal::TriangulationImplementation::NumberCache< 1 > &c)
static const unsigned int invalid_unsigned_int
void apply_to_subranges(const RangeType &begin, const typename identity< RangeType >::type &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