deal.II version GIT relicensing-6842-g793a97d2aa 2026-10-02 14:00:01+00:00
\(\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// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
4// Copyright (C) 1999 - 2024 by the deal.II authors
5//
6// This file is part of the deal.II library.
7//
8// Detailed license information governing the source code and contributions
9// can be found in LICENSE.md and CONTRIBUTING.md at the top level directory.
10//
11// -----------------------------------------------------------------------------
12
13#ifndef dealii_time_dependent_h
14#define dealii_time_dependent_h
15
16
17#include <deal.II/base/config.h>
18
23
24#include <utility>
25#include <vector>
26
28
29// forward declarations
30#ifndef DOXYGEN
31class TimeStepBase;
32template <typename number>
33class Vector;
34template <int dim, int spacedim>
36class Triangulation;
37#endif
38
358{
359public:
367 {
372 TimeSteppingData(const unsigned int look_ahead,
373 const unsigned int look_back);
374
393 const unsigned int look_ahead;
394
407 const unsigned int look_back;
408 };
409
425
429 TimeDependent(const TimeSteppingData &data_primal,
430 const TimeSteppingData &data_dual,
431 const TimeSteppingData &data_postprocess);
432
433
439 virtual ~TimeDependent();
440
461 void
462 insert_timestep(const TimeStepBase *position, TimeStepBase *new_timestep);
463
473 void
474 add_timestep(TimeStepBase *new_timestep);
475
488 void
489 delete_timestep(const unsigned int position);
490
499 void
501
510 void
512
521 void
522 postprocess();
523
554 template <typename InitFunctionObject, typename LoopFunctionObject>
555 void
556 do_loop(InitFunctionObject init_function,
557 LoopFunctionObject loop_function,
558 const TimeSteppingData &timestepping_data,
559 const Direction direction);
560
561
579 virtual void
580 start_sweep(const unsigned int sweep_no);
581
595 virtual void
596 end_sweep();
597
602 std::size_t
603 memory_consumption() const;
604
609 "You cannot insert a time step at the specified position.");
610
611protected:
617 std::vector<ObserverPointer<TimeStepBase, TimeDependent>> timesteps;
618
623 unsigned int sweep_no;
624
630
636
642
643private:
648 void
649 end_sweep(const unsigned int begin_timestep, const unsigned int end_timestep);
650};
651
652
653
662{
663public:
682
686 TimeStepBase(const double time);
687
691 virtual ~TimeStepBase() override = default;
692
697 TimeStepBase(const TimeStepBase &) = delete;
698
704 operator=(const TimeStepBase &) = delete;
705
721 virtual void
722 wake_up(const unsigned int);
723
733 virtual void
734 sleep(const unsigned int);
735
751 virtual void
752 start_sweep();
753
759 virtual void
760 end_sweep();
761
769 virtual void
771
775 virtual void
777
781 virtual void
783
791 virtual void
793
803 virtual void
805
815 virtual void
817
821 double
822 get_time() const;
823
828 unsigned int
829 get_timestep_no() const;
830
844 double
845 get_backward_timestep() const;
846
852 double
853 get_forward_timestep() const;
854
863 virtual std::size_t
864 memory_consumption() const;
865
866protected:
871
876
881 unsigned int sweep_no;
882
888 unsigned int timestep_no;
889
893 const double time;
894
900 unsigned int next_action;
901
902private:
910 void
911 set_previous_timestep(const TimeStepBase *previous);
912
920 void
921 set_next_timestep(const TimeStepBase *next);
922
929 void
930 set_timestep_no(const unsigned int step_no);
931
936 void
937 set_sweep_no(const unsigned int sweep_no);
938
939 // make the manager object a friend
940 friend class TimeDependent;
941};
942
943
944
952{
960 template <int dim>
961 struct Flags
962 {
966 Flags();
967
973 const unsigned int wakeup_level_to_build_grid,
974 const unsigned int sleep_level_to_delete_grid);
975
987
996 const unsigned int wakeup_level_to_build_grid;
997
1002 const unsigned int sleep_level_to_delete_grid;
1003 };
1004
1005
1006
1126 template <int dim>
1128 {
1135 std::vector<std::vector<std::pair<unsigned int, double>>>;
1136
1141
1146 RefinementFlags(const unsigned int max_refinement_level = 0,
1147 const unsigned int first_sweep_with_correction = 0,
1148 const unsigned int min_cells_for_correction = 0,
1149 const double cell_number_corridor_top = (1 << dim),
1150 const double cell_number_corridor_bottom = 1,
1153 const unsigned int cell_number_correction_steps = 0,
1154 const bool mirror_flags_to_previous_grid = false,
1155 const bool adapt_grids = false);
1156
1165 const unsigned int max_refinement_level;
1166
1173
1174
1179 const unsigned int min_cells_for_correction;
1180
1187
1192
1196 const std::vector<std::vector<std::pair<unsigned int, double>>>
1198
1205
1223
1227 const bool adapt_grids;
1228
1233 double,
1234 << "The value " << arg1
1235 << " for the cell number corridor does not fulfill "
1236 "its natural requirements.");
1237 };
1238
1239
1240
1247 template <int dim>
1249 {
1254 const double coarsening_threshold = 0);
1255
1263
1269
1274 double,
1275 << "The value " << arg1
1276 << " for the cell refinement thresholds does not fulfill "
1277 "its natural requirements.");
1278 };
1279} // namespace TimeStepBase_Tria_Flags
1280
1281
1282
1299template <int dim>
1301{
1302public:
1311
1312
1318 {
1322 grid_refinement = 0x1000
1324
1325
1335
1349 const double time,
1351 const Flags &flags,
1353
1358 virtual ~TimeStepBase_Tria() override;
1359
1380 virtual void
1381 wake_up(const unsigned int wakeup_level) override;
1382
1396 virtual void
1397 sleep(const unsigned int) override;
1398
1413 void
1415
1421 virtual void
1423
1431 virtual void
1433
1438 void
1440
1449 virtual std::size_t
1450 memory_consumption() const override;
1451
1456 "When calling restore_grid(), you must have previously "
1457 "deleted the triangulation.");
1458
1459protected:
1468
1476
1482
1488
1489private:
1495 std::vector<std::vector<bool>> refine_flags;
1496
1500 std::vector<std::vector<bool>> coarsen_flags;
1501
1506 void
1507 restore_grid();
1508};
1509
1510
1511
1512/*--------------------------- template functions ----------------------------*/
1513
1514template <typename InitFunctionObject, typename LoopFunctionObject>
1515void
1516TimeDependent::do_loop(InitFunctionObject init_function,
1517 LoopFunctionObject loop_function,
1518 const TimeSteppingData &timestepping_data,
1519 const Direction direction)
1520{
1521 // the following functions looks quite
1522 // disrupted due to the recurring switches
1523 // for forward and backward running loops.
1524 //
1525 // I chose to switch at every place where
1526 // it is needed, since it is so easy
1527 // to overlook something when you change
1528 // some code at one place when it needs
1529 // to be changed at a second place, here
1530 // for the other direction, also.
1531
1532 const unsigned int n_timesteps = timesteps.size();
1533
1534 // initialize the time steps for
1535 // a round of this loop
1536 for (unsigned int step = 0; step < n_timesteps; ++step)
1537 switch (direction)
1538 {
1539 case forward:
1540 init_function((&*timesteps[step]));
1541 break;
1542 case backward:
1543 init_function((&*timesteps[n_timesteps - step - 1]));
1544 break;
1545 };
1546
1547
1548 // wake up the first few time levels
1549 for (int step = -static_cast<int>(timestepping_data.look_ahead); step < 0;
1550 ++step)
1551 for (int look_ahead = 0;
1552 look_ahead <= static_cast<int>(timestepping_data.look_ahead);
1553 ++look_ahead)
1554 switch (direction)
1555 {
1556 case forward:
1557 if (step + look_ahead >= 0)
1558 timesteps[step + look_ahead]->wake_up(look_ahead);
1559 break;
1560 case backward:
1561 if (n_timesteps - (step + look_ahead) < n_timesteps)
1562 timesteps[n_timesteps - (step + look_ahead)]->wake_up(look_ahead);
1563 break;
1564 };
1565
1566
1567 for (unsigned int step = 0; step < n_timesteps; ++step)
1568 {
1569 // first thing: wake up the
1570 // timesteps ahead as necessary
1571 for (unsigned int look_ahead = 0;
1572 look_ahead <= timestepping_data.look_ahead;
1573 ++look_ahead)
1574 switch (direction)
1575 {
1576 case forward:
1577 if (step + look_ahead < n_timesteps)
1578 timesteps[step + look_ahead]->wake_up(look_ahead);
1579 break;
1580 case backward:
1581 if (n_timesteps > (step + look_ahead))
1582 timesteps[n_timesteps - (step + look_ahead) - 1]->wake_up(
1583 look_ahead);
1584 break;
1585 };
1586
1587
1588 // actually do the work
1589 switch (direction)
1590 {
1591 case forward:
1592 loop_function((&*timesteps[step]));
1593 break;
1594 case backward:
1595 loop_function((&*timesteps[n_timesteps - step - 1]));
1596 break;
1597 };
1598
1599 // let the timesteps behind sleep
1600 for (unsigned int look_back = 0; look_back <= timestepping_data.look_back;
1601 ++look_back)
1602 switch (direction)
1603 {
1604 case forward:
1605 if (step >= look_back)
1606 timesteps[step - look_back]->sleep(look_back);
1607 break;
1608 case backward:
1609 if (n_timesteps - (step - look_back) <= n_timesteps)
1610 timesteps[n_timesteps - (step - look_back) - 1]->sleep(
1611 look_back);
1612 break;
1613 }
1614 }
1615
1616 // make the last few timesteps sleep
1617 for (int step = n_timesteps;
1618 step < static_cast<int>(n_timesteps + timestepping_data.look_back);
1619 ++step)
1620 for (int look_back = 0;
1621 look_back <= static_cast<int>(timestepping_data.look_back);
1622 ++look_back)
1623 switch (direction)
1624 {
1625 case forward:
1626 if ((step - look_back >= 0) &&
1627 (step - look_back < static_cast<int>(n_timesteps)))
1628 timesteps[step - look_back]->sleep(look_back);
1629 break;
1630 case backward:
1631 if ((step - look_back >= 0) &&
1632 (step - look_back < static_cast<int>(n_timesteps)))
1633 timesteps[n_timesteps - (step - look_back) - 1]->sleep(look_back);
1634 break;
1635 };
1636}
1637
1639
1640#endif
void insert_timestep(const TimeStepBase *position, TimeStepBase *new_timestep)
virtual void start_sweep(const unsigned int sweep_no)
std::size_t memory_consumption() const
std::vector< ObserverPointer< TimeStepBase, TimeDependent > > timesteps
const TimeSteppingData timestepping_data_primal
virtual void end_sweep()
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)
ObserverPointer< const Triangulation< dim, dim >, TimeStepBase_Tria< dim > > coarse_grid
ObserverPointer< Triangulation< dim, dim >, TimeStepBase_Tria< dim > > tria
virtual void init_for_refinement()
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
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
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:38
#define DEAL_II_CXX20_REQUIRES(condition)
Definition config.h:249
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:39
static ::ExceptionBase & ExcGridNotDeleted()
static ::ExceptionBase & ExcInvalidValue(double arg1)
#define DeclExceptionMsg(Exception, defaulttext)
#define DeclException1(Exception1, type1, outsequence)
static ::ExceptionBase & ExcInvalidValue(double arg1)
static ::ExceptionBase & ExcInvalidPosition()
std::vector< index_type > data
Definition mpi.cc:734
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