Reference documentation for deal.II version 9.4.1
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
Loading...
Searching...
No Matches
time_dependent.h
Go to the documentation of this file.
1// ---------------------------------------------------------------------
2//
3// Copyright (C) 1999 - 2020 by the deal.II authors
4//
5// This file is part of the deal.II library.
6//
7// The deal.II library is free software; you can use it, redistribute
8// it, and/or modify it under the terms of the GNU Lesser General
9// Public License as published by the Free Software Foundation; either
10// version 2.1 of the License, or (at your option) any later version.
11// The full text of the license can be found in the file LICENSE.md at
12// the top level directory of deal.II.
13//
14// ---------------------------------------------------------------------
15
16#ifndef dealii_time_dependent_h
17# define dealii_time_dependent_h
18
19
20/*---------------------------- time-dependent.h ---------------------------*/
21
22
23# include <deal.II/base/config.h>
24
28
29# include <utility>
30# include <vector>
31
33
34// forward declarations
35# ifndef DOXYGEN
36class TimeStepBase;
37template <typename number>
38class Vector;
39template <int dim, int spacedim>
40class Triangulation;
41# endif
42
362{
363public:
371 {
376 TimeSteppingData(const unsigned int look_ahead,
377 const unsigned int look_back);
378
397 const unsigned int look_ahead;
398
411 const unsigned int look_back;
412 };
413
419 {
428 };
429
433 TimeDependent(const TimeSteppingData &data_primal,
434 const TimeSteppingData &data_dual,
435 const TimeSteppingData &data_postprocess);
436
437
443 virtual ~TimeDependent();
444
465 void
466 insert_timestep(const TimeStepBase *position, TimeStepBase *new_timestep);
467
477 void
478 add_timestep(TimeStepBase *new_timestep);
479
492 void
493 delete_timestep(const unsigned int position);
494
503 void
505
514 void
516
525 void
526 postprocess();
527
558 template <typename InitFunctionObject, typename LoopFunctionObject>
559 void
560 do_loop(InitFunctionObject init_function,
561 LoopFunctionObject loop_function,
562 const TimeSteppingData &timestepping_data,
563 const Direction direction);
564
565
583 virtual void
584 start_sweep(const unsigned int sweep_no);
585
599 virtual void
600 end_sweep();
601
606 std::size_t
607 memory_consumption() const;
608
613 "You cannot insert a time step at the specified position.");
614
615protected:
621 std::vector<SmartPointer<TimeStepBase, TimeDependent>> timesteps;
622
627 unsigned int sweep_no;
628
634
640
646
647private:
652 void
653 end_sweep(const unsigned int begin_timestep, const unsigned int end_timestep);
654};
655
656
657
666{
667public:
672 {
684 postprocess = 0x2
685 };
686
690 TimeStepBase(const double time);
691
695 virtual ~TimeStepBase() override = default;
696
701 TimeStepBase(const TimeStepBase &) = delete;
702
708 operator=(const TimeStepBase &) = delete;
709
725 virtual void
726 wake_up(const unsigned int);
727
737 virtual void
738 sleep(const unsigned int);
739
755 virtual void
756 start_sweep();
757
763 virtual void
764 end_sweep();
765
773 virtual void
775
779 virtual void
781
785 virtual void
787
795 virtual void
797
807 virtual void
809
819 virtual void
821
825 double
826 get_time() const;
827
832 unsigned int
833 get_timestep_no() const;
834
848 double
849 get_backward_timestep() const;
850
856 double
857 get_forward_timestep() const;
858
867 virtual std::size_t
868 memory_consumption() const;
869
870protected:
875
880
885 unsigned int sweep_no;
886
892 unsigned int timestep_no;
893
897 const double time;
898
904 unsigned int next_action;
905
906private:
914 void
915 set_previous_timestep(const TimeStepBase *previous);
916
924 void
925 set_next_timestep(const TimeStepBase *next);
926
933 void
934 set_timestep_no(const unsigned int step_no);
935
940 void
941 set_sweep_no(const unsigned int sweep_no);
942
943 // make the manager object a friend
944 friend class TimeDependent;
945};
946
947
948
956{
964 template <int dim>
965 struct Flags
966 {
970 Flags();
971
977 const unsigned int wakeup_level_to_build_grid,
978 const unsigned int sleep_level_to_delete_grid);
979
991
1000 const unsigned int wakeup_level_to_build_grid;
1001
1006 const unsigned int sleep_level_to_delete_grid;
1007 };
1008
1009
1010
1130 template <int dim>
1132 {
1139 std::vector<std::vector<std::pair<unsigned int, double>>>;
1140
1145
1150 RefinementFlags(const unsigned int max_refinement_level = 0,
1151 const unsigned int first_sweep_with_correction = 0,
1152 const unsigned int min_cells_for_correction = 0,
1153 const double cell_number_corridor_top = (1 << dim),
1154 const double cell_number_corridor_bottom = 1,
1157 const unsigned int cell_number_correction_steps = 0,
1158 const bool mirror_flags_to_previous_grid = false,
1159 const bool adapt_grids = false);
1160
1169 const unsigned int max_refinement_level;
1170
1177
1178
1183 const unsigned int min_cells_for_correction;
1184
1191
1196
1200 const std::vector<std::vector<std::pair<unsigned int, double>>>
1202
1209
1227
1231 const bool adapt_grids;
1232
1237 double,
1238 << "The value " << arg1
1239 << " for the cell number corridor does not fulfill "
1240 "its natural requirements.");
1241 };
1242
1243
1244
1251 template <int dim>
1253 {
1258 const double coarsening_threshold = 0);
1259
1267
1273
1278 double,
1279 << "The value " << arg1
1280 << " for the cell refinement thresholds does not fulfill "
1281 "its natural requirements.");
1282 };
1283} // namespace TimeStepBase_Tria_Flags
1284
1285
1286
1303template <int dim>
1305{
1306public:
1315
1316
1322 {
1326 grid_refinement = 0x1000
1328
1329
1339
1353 const double time,
1355 const Flags & flags,
1357
1362 virtual ~TimeStepBase_Tria() override;
1363
1384 virtual void
1385 wake_up(const unsigned int wakeup_level) override;
1386
1400 virtual void
1401 sleep(const unsigned int) override;
1402
1417 void
1418 refine_grid(const RefinementData data);
1419
1425 virtual void
1427
1435 virtual void
1437
1442 void
1444
1453 virtual std::size_t
1454 memory_consumption() const override;
1455
1460 "When calling restore_grid(), you must have previously "
1461 "deleted the triangulation.");
1462
1463protected:
1472
1480
1486
1492
1493private:
1499 std::vector<std::vector<bool>> refine_flags;
1500
1504 std::vector<std::vector<bool>> coarsen_flags;
1505
1510 void
1511 restore_grid();
1512};
1513
1514
1515
1516/*--------------------------- template functions ----------------------------*/
1517
1518template <typename InitFunctionObject, typename LoopFunctionObject>
1519void
1520TimeDependent::do_loop(InitFunctionObject init_function,
1521 LoopFunctionObject loop_function,
1522 const TimeSteppingData &timestepping_data,
1523 const Direction direction)
1524{
1525 // the following functions looks quite
1526 // disrupted due to the recurring switches
1527 // for forward and backward running loops.
1528 //
1529 // I chose to switch at every place where
1530 // it is needed, since it is so easy
1531 // to overlook something when you change
1532 // some code at one place when it needs
1533 // to be changed at a second place, here
1534 // for the other direction, also.
1535
1536 const unsigned int n_timesteps = timesteps.size();
1537
1538 // initialize the time steps for
1539 // a round of this loop
1540 for (unsigned int step = 0; step < n_timesteps; ++step)
1541 switch (direction)
1542 {
1543 case forward:
1544 init_function((&*timesteps[step]));
1545 break;
1546 case backward:
1547 init_function((&*timesteps[n_timesteps - step - 1]));
1548 break;
1549 };
1550
1551
1552 // wake up the first few time levels
1553 for (int step = -static_cast<int>(timestepping_data.look_ahead); step < 0;
1554 ++step)
1555 for (int look_ahead = 0;
1556 look_ahead <= static_cast<int>(timestepping_data.look_ahead);
1557 ++look_ahead)
1558 switch (direction)
1559 {
1560 case forward:
1561 if (step + look_ahead >= 0)
1562 timesteps[step + look_ahead]->wake_up(look_ahead);
1563 break;
1564 case backward:
1565 if (n_timesteps - (step + look_ahead) < n_timesteps)
1566 timesteps[n_timesteps - (step + look_ahead)]->wake_up(look_ahead);
1567 break;
1568 };
1569
1570
1571 for (unsigned int step = 0; step < n_timesteps; ++step)
1572 {
1573 // first thing: wake up the
1574 // timesteps ahead as necessary
1575 for (unsigned int look_ahead = 0;
1576 look_ahead <= timestepping_data.look_ahead;
1577 ++look_ahead)
1578 switch (direction)
1579 {
1580 case forward:
1581 if (step + look_ahead < n_timesteps)
1582 timesteps[step + look_ahead]->wake_up(look_ahead);
1583 break;
1584 case backward:
1585 if (n_timesteps > (step + look_ahead))
1586 timesteps[n_timesteps - (step + look_ahead) - 1]->wake_up(
1587 look_ahead);
1588 break;
1589 };
1590
1591
1592 // actually do the work
1593 switch (direction)
1594 {
1595 case forward:
1596 loop_function((&*timesteps[step]));
1597 break;
1598 case backward:
1599 loop_function((&*timesteps[n_timesteps - step - 1]));
1600 break;
1601 };
1602
1603 // let the timesteps behind sleep
1604 for (unsigned int look_back = 0; look_back <= timestepping_data.look_back;
1605 ++look_back)
1606 switch (direction)
1607 {
1608 case forward:
1609 if (step >= look_back)
1610 timesteps[step - look_back]->sleep(look_back);
1611 break;
1612 case backward:
1613 if (n_timesteps - (step - look_back) <= n_timesteps)
1614 timesteps[n_timesteps - (step - look_back) - 1]->sleep(
1615 look_back);
1616 break;
1617 }
1618 }
1619
1620 // make the last few timesteps sleep
1621 for (int step = n_timesteps;
1622 step < static_cast<int>(n_timesteps + timestepping_data.look_back);
1623 ++step)
1624 for (int look_back = 0;
1625 look_back <= static_cast<int>(timestepping_data.look_back);
1626 ++look_back)
1627 switch (direction)
1628 {
1629 case forward:
1630 if ((step - look_back >= 0) &&
1631 (step - look_back < static_cast<int>(n_timesteps)))
1632 timesteps[step - look_back]->sleep(look_back);
1633 break;
1634 case backward:
1635 if ((step - look_back >= 0) &&
1636 (step - look_back < static_cast<int>(n_timesteps)))
1637 timesteps[n_timesteps - (step - look_back) - 1]->sleep(look_back);
1638 break;
1639 };
1640}
1641
1643
1644/*---------------------------- time-dependent.h ---------------------------*/
1645#endif
1646/*---------------------------- time-dependent.h ---------------------------*/
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
virtual void end_sweep()
std::vector< SmartPointer< TimeStepBase, TimeDependent > > timesteps
void solve_dual_problem()
virtual ~TimeDependent()
void do_loop(InitFunctionObject init_function, LoopFunctionObject loop_function, const TimeSteppingData &timestepping_data, const Direction direction)
const TimeSteppingData timestepping_data_dual
void solve_primal_problem()
unsigned int sweep_no
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
typename TimeStepBase_Tria_Flags::Flags< dim > Flags
std::vector< std::vector< bool > > coarsen_flags
virtual void sleep(const unsigned int) override
TimeStepBase_Tria(const double time, const Triangulation< dim, dim > &coarse_grid, const Flags &flags, const RefinementFlags &refinement_flags=RefinementFlags())
virtual std::size_t memory_consumption() const override
void refine_grid(const RefinementData data)
virtual void init_for_refinement()
SmartPointer< const Triangulation< dim, dim >, TimeStepBase_Tria< dim > > coarse_grid
typename TimeStepBase_Tria_Flags::RefinementData< dim > RefinementData
virtual void get_tria_refinement_criteria(Vector< float > &criteria) const =0
const RefinementFlags refinement_flags
virtual ~TimeStepBase_Tria() override
SmartPointer< Triangulation< dim, dim >, TimeStepBase_Tria< dim > > tria
typename TimeStepBase_Tria_Flags::RefinementFlags< dim > RefinementFlags
std::vector< std::vector< bool > > refine_flags
virtual std::size_t memory_consumption() const
double get_forward_timestep() const
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
TimeStepBase(const TimeStepBase &)=delete
virtual ~TimeStepBase() override=default
virtual void postprocess_timestep()
virtual void sleep(const unsigned int)
unsigned int timestep_no
void set_next_timestep(const TimeStepBase *next)
unsigned int get_timestep_no() const
unsigned int next_action
double get_backward_timestep() const
void set_sweep_no(const unsigned int sweep_no)
const double time
unsigned int sweep_no
virtual void end_sweep()
TimeStepBase & operator=(const TimeStepBase &)=delete
virtual void solve_primal_problem()=0
virtual void init_for_postprocessing()
virtual void start_sweep()
virtual void init_for_primal_problem()
double get_time() const
virtual void solve_dual_problem()
virtual void init_for_dual_problem()
const TimeStepBase * next_timestep
Definition: vector.h:109
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:442
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:443
static ::ExceptionBase & ExcGridNotDeleted()
static ::ExceptionBase & ExcInvalidValue(double arg1)
#define DeclExceptionMsg(Exception, defaulttext)
Definition: exceptions.h:487
#define DeclException1(Exception1, type1, outsequence)
Definition: exceptions.h:509
static ::ExceptionBase & ExcInvalidValue(double arg1)
static ::ExceptionBase & ExcInvalidPosition()
const unsigned int wakeup_level_to_build_grid
const unsigned int sleep_level_to_delete_grid
std::vector< std::vector< std::pair< unsigned int, double > > > CorrectionRelaxations
const std::vector< std::vector< std::pair< unsigned int, double > > > correction_relaxations
static CorrectionRelaxations default_correction_relaxations