deal.II version GIT relicensing-2169-gec1b43f35b 2024-11-22 07:10:00+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: 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// Part of the source code is dual licensed under Apache-2.0 WITH
9// LLVM-exception OR LGPL-2.1-or-later. Detailed license information
10// governing the source code and code contributions can be found in
11// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II.
12//
13// ------------------------------------------------------------------------
14
15#ifndef dealii_time_dependent_h
16#define dealii_time_dependent_h
17
18
19#include <deal.II/base/config.h>
20
25
26#include <utility>
27#include <vector>
28
30
31// forward declarations
32#ifndef DOXYGEN
33class TimeStepBase;
34template <typename number>
35class Vector;
36template <int dim, int spacedim>
38class Triangulation;
39#endif
40
360{
361public:
369 {
374 TimeSteppingData(const unsigned int look_ahead,
375 const unsigned int look_back);
376
395 const unsigned int look_ahead;
396
409 const unsigned int look_back;
410 };
411
427
431 TimeDependent(const TimeSteppingData &data_primal,
432 const TimeSteppingData &data_dual,
433 const TimeSteppingData &data_postprocess);
434
435
441 virtual ~TimeDependent();
442
463 void
464 insert_timestep(const TimeStepBase *position, TimeStepBase *new_timestep);
465
475 void
476 add_timestep(TimeStepBase *new_timestep);
477
490 void
491 delete_timestep(const unsigned int position);
492
501 void
503
512 void
514
523 void
524 postprocess();
525
556 template <typename InitFunctionObject, typename LoopFunctionObject>
557 void
558 do_loop(InitFunctionObject init_function,
559 LoopFunctionObject loop_function,
560 const TimeSteppingData &timestepping_data,
561 const Direction direction);
562
563
581 virtual void
582 start_sweep(const unsigned int sweep_no);
583
597 virtual void
598 end_sweep();
599
604 std::size_t
605 memory_consumption() const;
606
611 "You cannot insert a time step at the specified position.");
612
613protected:
619 std::vector<ObserverPointer<TimeStepBase, TimeDependent>> timesteps;
620
625 unsigned int sweep_no;
626
632
638
644
645private:
650 void
651 end_sweep(const unsigned int begin_timestep, const unsigned int end_timestep);
652};
653
654
655
664{
665public:
684
688 TimeStepBase(const double time);
689
693 virtual ~TimeStepBase() override = default;
694
699 TimeStepBase(const TimeStepBase &) = delete;
700
706 operator=(const TimeStepBase &) = delete;
707
723 virtual void
724 wake_up(const unsigned int);
725
735 virtual void
736 sleep(const unsigned int);
737
753 virtual void
754 start_sweep();
755
761 virtual void
762 end_sweep();
763
771 virtual void
773
777 virtual void
779
783 virtual void
785
793 virtual void
795
805 virtual void
807
817 virtual void
819
823 double
824 get_time() const;
825
830 unsigned int
831 get_timestep_no() const;
832
846 double
847 get_backward_timestep() const;
848
854 double
855 get_forward_timestep() const;
856
865 virtual std::size_t
866 memory_consumption() const;
867
868protected:
873
878
883 unsigned int sweep_no;
884
890 unsigned int timestep_no;
891
895 const double time;
896
902 unsigned int next_action;
903
904private:
912 void
913 set_previous_timestep(const TimeStepBase *previous);
914
922 void
923 set_next_timestep(const TimeStepBase *next);
924
931 void
932 set_timestep_no(const unsigned int step_no);
933
938 void
939 set_sweep_no(const unsigned int sweep_no);
940
941 // make the manager object a friend
942 friend class TimeDependent;
943};
944
945
946
954{
962 template <int dim>
963 struct Flags
964 {
968 Flags();
969
975 const unsigned int wakeup_level_to_build_grid,
976 const unsigned int sleep_level_to_delete_grid);
977
989
998 const unsigned int wakeup_level_to_build_grid;
999
1004 const unsigned int sleep_level_to_delete_grid;
1005 };
1006
1007
1008
1128 template <int dim>
1130 {
1137 std::vector<std::vector<std::pair<unsigned int, double>>>;
1138
1143
1148 RefinementFlags(const unsigned int max_refinement_level = 0,
1149 const unsigned int first_sweep_with_correction = 0,
1150 const unsigned int min_cells_for_correction = 0,
1151 const double cell_number_corridor_top = (1 << dim),
1152 const double cell_number_corridor_bottom = 1,
1155 const unsigned int cell_number_correction_steps = 0,
1156 const bool mirror_flags_to_previous_grid = false,
1157 const bool adapt_grids = false);
1158
1167 const unsigned int max_refinement_level;
1168
1175
1176
1181 const unsigned int min_cells_for_correction;
1182
1189
1194
1198 const std::vector<std::vector<std::pair<unsigned int, double>>>
1200
1207
1225
1229 const bool adapt_grids;
1230
1235 double,
1236 << "The value " << arg1
1237 << " for the cell number corridor does not fulfill "
1238 "its natural requirements.");
1239 };
1240
1241
1242
1249 template <int dim>
1251 {
1256 const double coarsening_threshold = 0);
1257
1265
1271
1276 double,
1277 << "The value " << arg1
1278 << " for the cell refinement thresholds does not fulfill "
1279 "its natural requirements.");
1280 };
1281} // namespace TimeStepBase_Tria_Flags
1282
1283
1284
1301template <int dim>
1303{
1304public:
1313
1314
1320 {
1324 grid_refinement = 0x1000
1326
1327
1337
1351 const double time,
1353 const Flags &flags,
1355
1360 virtual ~TimeStepBase_Tria() override;
1361
1382 virtual void
1383 wake_up(const unsigned int wakeup_level) override;
1384
1398 virtual void
1399 sleep(const unsigned int) override;
1400
1415 void
1417
1423 virtual void
1425
1433 virtual void
1435
1440 void
1442
1451 virtual std::size_t
1452 memory_consumption() const override;
1453
1458 "When calling restore_grid(), you must have previously "
1459 "deleted the triangulation.");
1460
1461protected:
1470
1478
1484
1490
1491private:
1497 std::vector<std::vector<bool>> refine_flags;
1498
1502 std::vector<std::vector<bool>> coarsen_flags;
1503
1508 void
1509 restore_grid();
1510};
1511
1512
1513
1514/*--------------------------- template functions ----------------------------*/
1515
1516template <typename InitFunctionObject, typename LoopFunctionObject>
1517void
1518TimeDependent::do_loop(InitFunctionObject init_function,
1519 LoopFunctionObject loop_function,
1520 const TimeSteppingData &timestepping_data,
1521 const Direction direction)
1522{
1523 // the following functions looks quite
1524 // disrupted due to the recurring switches
1525 // for forward and backward running loops.
1526 //
1527 // I chose to switch at every place where
1528 // it is needed, since it is so easy
1529 // to overlook something when you change
1530 // some code at one place when it needs
1531 // to be changed at a second place, here
1532 // for the other direction, also.
1533
1534 const unsigned int n_timesteps = timesteps.size();
1535
1536 // initialize the time steps for
1537 // a round of this loop
1538 for (unsigned int step = 0; step < n_timesteps; ++step)
1539 switch (direction)
1540 {
1541 case forward:
1542 init_function((&*timesteps[step]));
1543 break;
1544 case backward:
1545 init_function((&*timesteps[n_timesteps - step - 1]));
1546 break;
1547 };
1548
1549
1550 // wake up the first few time levels
1551 for (int step = -static_cast<int>(timestepping_data.look_ahead); step < 0;
1552 ++step)
1553 for (int look_ahead = 0;
1554 look_ahead <= static_cast<int>(timestepping_data.look_ahead);
1555 ++look_ahead)
1556 switch (direction)
1557 {
1558 case forward:
1559 if (step + look_ahead >= 0)
1560 timesteps[step + look_ahead]->wake_up(look_ahead);
1561 break;
1562 case backward:
1563 if (n_timesteps - (step + look_ahead) < n_timesteps)
1564 timesteps[n_timesteps - (step + look_ahead)]->wake_up(look_ahead);
1565 break;
1566 };
1567
1568
1569 for (unsigned int step = 0; step < n_timesteps; ++step)
1570 {
1571 // first thing: wake up the
1572 // timesteps ahead as necessary
1573 for (unsigned int look_ahead = 0;
1574 look_ahead <= timestepping_data.look_ahead;
1575 ++look_ahead)
1576 switch (direction)
1577 {
1578 case forward:
1579 if (step + look_ahead < n_timesteps)
1580 timesteps[step + look_ahead]->wake_up(look_ahead);
1581 break;
1582 case backward:
1583 if (n_timesteps > (step + look_ahead))
1584 timesteps[n_timesteps - (step + look_ahead) - 1]->wake_up(
1585 look_ahead);
1586 break;
1587 };
1588
1589
1590 // actually do the work
1591 switch (direction)
1592 {
1593 case forward:
1594 loop_function((&*timesteps[step]));
1595 break;
1596 case backward:
1597 loop_function((&*timesteps[n_timesteps - step - 1]));
1598 break;
1599 };
1600
1601 // let the timesteps behind sleep
1602 for (unsigned int look_back = 0; look_back <= timestepping_data.look_back;
1603 ++look_back)
1604 switch (direction)
1605 {
1606 case forward:
1607 if (step >= look_back)
1608 timesteps[step - look_back]->sleep(look_back);
1609 break;
1610 case backward:
1611 if (n_timesteps - (step - look_back) <= n_timesteps)
1612 timesteps[n_timesteps - (step - look_back) - 1]->sleep(
1613 look_back);
1614 break;
1615 }
1616 }
1617
1618 // make the last few timesteps sleep
1619 for (int step = n_timesteps;
1620 step < static_cast<int>(n_timesteps + timestepping_data.look_back);
1621 ++step)
1622 for (int look_back = 0;
1623 look_back <= static_cast<int>(timestepping_data.look_back);
1624 ++look_back)
1625 switch (direction)
1626 {
1627 case forward:
1628 if ((step - look_back >= 0) &&
1629 (step - look_back < static_cast<int>(n_timesteps)))
1630 timesteps[step - look_back]->sleep(look_back);
1631 break;
1632 case backward:
1633 if ((step - look_back >= 0) &&
1634 (step - look_back < static_cast<int>(n_timesteps)))
1635 timesteps[n_timesteps - (step - look_back) - 1]->sleep(look_back);
1636 break;
1637 };
1638}
1639
1641
1642#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:498
#define DEAL_II_CXX20_REQUIRES(condition)
Definition config.h:175
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:499
static ::ExceptionBase & ExcGridNotDeleted()
static ::ExceptionBase & ExcInvalidValue(double arg1)
#define DeclExceptionMsg(Exception, defaulttext)
Definition exceptions.h:489
#define DeclException1(Exception1, type1, outsequence)
Definition exceptions.h:511
static ::ExceptionBase & ExcInvalidValue(double arg1)
static ::ExceptionBase & ExcInvalidPosition()
std::vector< index_type > data
Definition mpi.cc:735
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