16 #include <deal.II/numerics/time_dependent.h> 17 #include <deal.II/base/memory_consumption.h> 18 #include <deal.II/base/thread_management.h> 19 #include <deal.II/base/utilities.h> 20 #include <deal.II/base/parallel.h> 21 #include <deal.II/grid/tria.h> 22 #include <deal.II/grid/tria_accessor.h> 23 #include <deal.II/grid/tria_iterator.h> 24 #include <deal.II/grid/grid_refinement.h> 25 #include <deal.II/lac/vector.h> 31 DEAL_II_NAMESPACE_OPEN
34 const unsigned int look_back)
36 look_ahead (look_ahead),
64 ExcInvalidPosition());
74 timesteps.back()->set_next_timestep (new_timestep);
86 timesteps[0]->set_previous_timestep (new_timestep);
95 std::vector<SmartPointer<TimeStepBase,TimeDependent> >::iterator insert_position
98 (*(insert_position-1))->set_next_timestep (new_timestep);
101 (*insert_position)->set_previous_timestep (new_timestep);
123 ExcInvalidPosition());
148 timesteps[position]->set_previous_timestep ((position!=0) ?
196 for (
unsigned int step=0; step<
timesteps.size(); ++step)
202 for (
unsigned int step=0; step<
timesteps.size(); ++step)
210 void (
TimeDependent::*p) (
const unsigned int,
const unsigned int)
213 std_cxx11::bind (p,
this, std_cxx11::_1, std_cxx11::_2),
220 const unsigned int end)
222 for (
unsigned int step=begin; step<end; ++step)
236 for (
unsigned int i=0; i<
timesteps.size(); ++i)
248 previous_timestep(0),
251 timestep_no (
numbers::invalid_unsigned_int),
313 Assert (
false, ExcPureFunctionCalled());
321 Assert (
false, ExcPureFunctionCalled());
346 ExcMessage(
"The backward time step cannot be computed because " 347 "there is no previous time step."));
357 ExcMessage(
"The forward time step cannot be computed because " 358 "there is no next time step."));
400 return sizeof(*this);
408 tria (0, typeid(*this).name()),
409 coarse_grid (0, typeid(*this).name()),
413 Assert (
false, ExcPureFunctionCalled());
424 tria(0,
typeid(*this).name()),
425 coarse_grid (&coarse_grid,
typeid(*this).name()),
510 for (
unsigned int previous_sweep=0; previous_sweep<
refine_flags.size();
530 tria->execute_coarsening_and_refinement ();
566 if (new_cell->active())
568 if (new_cell->refine_flag_set() && old_cell->active())
570 if (old_cell->coarsen_flag_set())
571 old_cell->clear_coarsen_flag();
573 old_cell->set_refine_flag();
579 if (old_cell->has_children() && new_cell->has_children())
581 Assert(old_cell->n_children()==new_cell->n_children(), ExcNotImplemented());
582 for (
unsigned int c=0; c<new_cell->n_children(); ++c)
583 ::mirror_refinement_flags<dim> (new_cell->child(c), old_cell->child(c));
595 if (cell2->has_children() && cell1->has_children())
597 bool grids_changed =
false;
599 Assert(cell2->n_children()==cell1->n_children(), ExcNotImplemented());
600 for (
unsigned int c=0; c<cell1->n_children(); ++c)
601 grids_changed |= ::adapt_grid_cells<dim> (cell1->child(c),
603 return grids_changed;
607 if (!cell1->has_children() && !cell2->has_children())
613 if (cell1->refine_flag_set() && cell2->coarsen_flag_set())
615 cell2->clear_coarsen_flag();
618 else if (cell1->coarsen_flag_set() && cell2->refine_flag_set())
620 cell1->clear_coarsen_flag();
628 if (cell1->has_children() && !cell2->has_children())
647 bool changed_grid =
false;
648 if (cell2->coarsen_flag_set())
650 cell2->clear_coarsen_flag();
654 if (!cell2->refine_flag_set())
655 for (
unsigned int c=0; c<cell1->n_children(); ++c)
656 if (cell1->child(c)->refine_flag_set() ||
657 cell1->child(c)->has_children())
659 cell2->set_refine_flag();
666 if (!cell1->has_children() && cell2->has_children())
669 bool changed_grid =
false;
670 if (cell1->coarsen_flag_set())
672 cell1->clear_coarsen_flag();
676 if (!cell1->refine_flag_set())
677 for (
unsigned int c=0; c<cell2->n_children(); ++c)
678 if (cell2->child(c)->refine_flag_set() ||
679 cell2->child(c)->has_children())
681 cell1->set_refine_flag();
688 Assert (
false, ExcInternalError());
699 bool grids_changed =
false;
702 cell2 = tria2.
begin();
707 for (; cell1!=endc; ++cell1, ++cell2)
708 grids_changed |= ::adapt_grid_cells<dim> (cell1, cell2);
710 return grids_changed;
738 Vector<float>::const_iterator p_refinement_threshold=0,
739 p_coarsening_threshold=0;
760 sorted_criteria = criteria;
761 std::sort (sorted_criteria.
begin(),
762 sorted_criteria.
end());
764 sorted_criteria.
end(),
765 static_cast<float>(refinement_threshold));
766 p_coarsening_threshold = std::upper_bound (sorted_criteria.
begin(),
767 sorted_criteria.
end(),
768 static_cast<float>(coarsening_threshold));
821 for (
unsigned int loop=0;
831 ::adapt_grids<dim> (*previous_tria, *
tria);
837 previous_tria->prepare_coarsening_and_refinement ();
856 Assert(!previous_tria->get_anisotropic_refinement_flag(), ExcNotImplemented());
857 double previous_cells = previous_tria->n_active_cells();
860 endc = previous_tria->
end();
861 for (; cell!=endc; ++cell)
862 if (cell->refine_flag_set())
864 else if (cell->coarsen_flag_set())
884 double estimated_cells = n_active_cells;
887 for (; cell!=endc; ++cell)
888 if (cell->refine_flag_set())
890 else if (cell->coarsen_flag_set())
900 const std::vector<std::pair<unsigned int,double> > &relaxations
904 for (
unsigned int r=0; r!=relaxations.size(); ++r)
905 if (n_active_cells < relaxations[r].first)
907 delta_up *= relaxations[r].second;
908 delta_down *= relaxations[r].second;
921 if (estimated_cells > previous_cells*(1.+delta_up))
943 double delta_cells = estimated_cells -
944 previous_cells*(1.+delta_up);
955 for (
unsigned int i=0; i<delta_cells;
957 if (p_refinement_threshold != sorted_criteria.
end())
958 ++p_refinement_threshold;
977 if (estimated_cells < previous_cells*(1.-delta_down))
981 double delta_cells = previous_cells*(1.-delta_down)-estimated_cells;
1016 for (
unsigned int i=0; i<delta_cells;
1018 if (p_refinement_threshold != p_coarsening_threshold)
1019 --refinement_threshold;
1020 else if (p_coarsening_threshold != sorted_criteria.
begin())
1021 --p_coarsening_threshold, --p_refinement_threshold;
1030 if (p_refinement_threshold == sorted_criteria.
end())
1032 Assert (p_coarsening_threshold != p_refinement_threshold,
1033 ExcInternalError());
1034 --p_refinement_threshold;
1037 coarsening_threshold = *p_coarsening_threshold;
1038 refinement_threshold = *p_refinement_threshold;
1040 if (coarsening_threshold>=refinement_threshold)
1041 coarsening_threshold = 0.999*refinement_threshold;
1049 for (; cell!=endc; ++cell)
1051 cell->clear_refine_flag ();
1052 cell->clear_coarsen_flag ();
1087 ::adapt_grids<dim> (*previous_tria, *
tria);
1090 old_cell = previous_tria->
begin(0);
1093 for (; new_cell!=endc; ++new_cell, ++old_cell)
1094 ::mirror_refinement_flags<dim> (new_cell, old_cell);
1105 ::adapt_grids<dim> (*previous_tria, *
tria);
1126 sizeof(flags) +
sizeof(refinement_flags) +
1136 delete_and_rebuild_tria (false),
1137 wakeup_level_to_build_grid (0),
1138 sleep_level_to_delete_grid (0)
1140 Assert (
false, ExcInternalError());
1149 delete_and_rebuild_tria (delete_and_rebuild_tria),
1150 wakeup_level_to_build_grid (wakeup_level_to_build_grid),
1151 sleep_level_to_delete_grid (sleep_level_to_delete_grid)
1164 std::vector<std::pair<unsigned int,double> >(1,
1167 std::make_pair (0U, 0.)));
1173 const unsigned int first_sweep_with_correction,
1174 const unsigned int min_cells_for_correction,
1175 const double cell_number_corridor_top,
1176 const double cell_number_corridor_bottom,
1178 const unsigned int cell_number_correction_steps,
1179 const bool mirror_flags_to_previous_grid,
1180 const bool adapt_grids) :
1181 max_refinement_level(max_refinement_level),
1182 first_sweep_with_correction (first_sweep_with_correction),
1183 min_cells_for_correction(min_cells_for_correction),
1184 cell_number_corridor_top(cell_number_corridor_top),
1185 cell_number_corridor_bottom(cell_number_corridor_bottom),
1186 correction_relaxations (correction_relaxations.size() != 0 ?
1187 correction_relaxations :
1188 default_correction_relaxations),
1189 cell_number_correction_steps(cell_number_correction_steps),
1190 mirror_flags_to_previous_grid(mirror_flags_to_previous_grid),
1191 adapt_grids(adapt_grids)
1193 Assert (cell_number_corridor_top>=0, ExcInvalidValue (cell_number_corridor_top));
1194 Assert (cell_number_corridor_bottom>=0, ExcInvalidValue (cell_number_corridor_bottom));
1195 Assert (cell_number_corridor_bottom<=1, ExcInvalidValue (cell_number_corridor_bottom));
1202 const double _coarsening_threshold) :
1203 refinement_threshold(_refinement_threshold),
1222 coarsening_threshold((_coarsening_threshold == _refinement_threshold ?
1223 _coarsening_threshold :
1224 0.999*_coarsening_threshold))
1239 #include "time_dependent.inst" 1242 DEAL_II_NAMESPACE_CLOSE
void set_sweep_no(const unsigned int sweep_no)
virtual std::size_t memory_consumption() const
virtual void solve_primal_problem()=0
Iterator lower_bound(Iterator first, Iterator last, const T &val)
virtual void sleep(const unsigned int)
virtual void start_sweep()
unsigned int n_active_cells() const
void refine_grid(const RefinementData data)
TimeDependent(const TimeSteppingData &data_primal, const TimeSteppingData &data_dual, const TimeSteppingData &data_postprocess)
virtual void solve_dual_problem()
void set_timestep_no(const unsigned int step_no)
void solve_primal_problem()
void add_timestep(TimeStepBase *new_timestep)
void solve_dual_problem()
const TimeStepBase * next_timestep
const TimeSteppingData timestepping_data_postprocess
const unsigned int wakeup_level_to_build_grid
::ExceptionBase & ExcMessage(std::string arg1)
double get_forward_timestep() const
void set_next_timestep(const TimeStepBase *next)
virtual void copy_triangulation(const Triangulation< dim, spacedim > &old_tria)
const TimeStepBase * previous_timestep
active_cell_iterator begin_active(const unsigned int level=0) const
const TimeSteppingData timestepping_data_dual
const unsigned int cell_number_correction_steps
cell_iterator begin(const unsigned int level=0) const
void apply_to_subranges(const RangeType &begin, const typename identity< RangeType >::type &end, const Function &f, const unsigned int grainsize)
unsigned int n_levels() const
const double cell_number_corridor_top
void set_previous_timestep(const TimeStepBase *previous)
cell_iterator end() const
unsigned int get_timestep_no() const
void do_loop(InitFunctionObject init_function, LoopFunctionObject loop_function, const TimeSteppingData ×tepping_data, const Direction direction)
const RefinementFlags refinement_flags
virtual bool prepare_coarsening_and_refinement()
const std::vector< std::vector< std::pair< unsigned int, double > > > correction_relaxations
TriaIterator< CellAccessor< dim, spacedim > > cell_iterator
SmartPointer< const Triangulation< dim, dim >, TimeStepBase_Tria< dim > > coarse_grid
std::size_t memory_consumption() const
virtual void init_for_refinement()
RefinementData(const double refinement_threshold, const double coarsening_threshold=0)
#define Assert(cond, exc)
bool get_anisotropic_refinement_flag() const
virtual void get_tria_refinement_criteria(Vector< float > &criteria) const =0
const TimeSteppingData timestepping_data_primal
void loop(ITERATOR begin, typename identity< ITERATOR >::type end, DOFINFO &dinfo, INFOBOX &info, const std_cxx11::function< void(DOFINFO &, typename INFOBOX::CellInfo &)> &cell_worker, const std_cxx11::function< void(DOFINFO &, typename INFOBOX::CellInfo &)> &boundary_worker, const std_cxx11::function< void(DOFINFO &, DOFINFO &, typename INFOBOX::CellInfo &, typename INFOBOX::CellInfo &)> &face_worker, ASSEMBLER &assembler, const LoopControl &lctrl=LoopControl())
virtual void start_sweep(const unsigned int sweep_no)
void save_coarsen_flags(std::ostream &out) const
void save_refine_flags(std::ostream &out) const
virtual void init_for_postprocessing()
virtual ~TimeStepBase_Tria()
static CorrectionRelaxations default_correction_relaxations
void coarsen(Triangulation< dim, spacedim > &tria, const VectorType &criteria, const double threshold)
const unsigned int first_sweep_with_correction
double get_backward_timestep() const
const unsigned int sleep_level_to_delete_grid
const double coarsening_threshold
void delete_timestep(const unsigned int position)
virtual std::size_t memory_consumption() const
std_cxx11::enable_if< std_cxx11::is_fundamental< T >::value, std::size_t >::type memory_consumption(const T &t)
virtual void wake_up(const unsigned int)
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)
virtual void sleep(const unsigned int)
std::vector< SmartPointer< TimeStepBase, TimeDependent > > timesteps
virtual void init_for_dual_problem()
const double cell_number_corridor_bottom
virtual void init_for_primal_problem()
const bool mirror_flags_to_previous_grid
const unsigned int min_cells_for_correction
void insert_timestep(const TimeStepBase *position, TimeStepBase *new_timestep)
std::vector< std::vector< bool > > refine_flags
const double refinement_threshold
std::vector< std::vector< bool > > coarsen_flags
virtual void postprocess_timestep()
void refine(Triangulation< dim, spacedim > &tria, const VectorType &criteria, const double threshold, const unsigned int max_to_mark=numbers::invalid_unsigned_int)
std::vector< std::vector< std::pair< unsigned int, double > > > CorrectionRelaxations
const bool delete_and_rebuild_tria
virtual void wake_up(const unsigned int wakeup_level)
TimeStepBase(const double time)
TimeSteppingData(const unsigned int look_ahead, const unsigned int look_back)
SmartPointer< Triangulation< dim, dim >, TimeStepBase_Tria< dim > > tria