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;
739 Vector<float> criteria;
740 get_tria_refinement_criteria(criteria);
745 double refinement_threshold = refinement_data.refinement_threshold,
746 coarsening_threshold = refinement_data.coarsening_threshold;
755 Vector<float> sorted_criteria;
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>(
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;
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"