Finite Volume Solver  prototype
A framework to build finite volume solvers for the AG Klein at the Freie Universität Berlin.
NoSubcycleSolver.hpp
Go to the documentation of this file.
1 // Copyright (c) 2019 Maikel Nadolski
2 //
3 // Permission is hereby granted, free of charge, to any person obtaining a copy
4 // of this software and associated documentation files (the "Software"), to deal
5 // in the Software without restriction, including without limitation the rights
6 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 // copies of the Software, and to permit persons to whom the Software is
8 // furnished to do so, subject to the following conditions:
9 //
10 // The above copyright notice and this permission notice shall be included in
11 // all copies or substantial portions of the Software.
12 //
13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19 // SOFTWARE.
20 
21 #ifndef FUB_NO_SUBCYCLE_SOLVER_HPP
22 #define FUB_NO_SUBCYCLE_SOLVER_HPP
23 
24 #include "fub/Meta.hpp"
25 #include "fub/TimeStepError.hpp"
26 #include "fub/ext/outcome.hpp"
28 
29 namespace fub {
30 
31 /// \ingroup SubcycleSolver
32 ///
33 /// \brief This is a solver class which does a AMR integration scheme without
34 /// subcycling on finer levels. Which means, that this uses one time step size
35 /// for each refinement level on the patch hierarchy.
36 template <typename LevelIntegrator>
37 class NoSubcycleSolver : public SolverFacade<LevelIntegrator> {
38 private:
40 
41 public:
42  explicit NoSubcycleSolver(LevelIntegrator&& integrator)
43  : Base(std::move(integrator)) {}
44 
45  explicit NoSubcycleSolver(const LevelIntegrator& integrator)
46  : Base(integrator) {}
47 
48  [[nodiscard]] Duration ComputeStableDt();
49 
50  [[nodiscard]] Result<void, TimeStepTooLarge>
51  AdvanceLevel(int level, Duration time_step_size);
52 
53  [[nodiscard]] Result<void, TimeStepTooLarge>
54  AdvanceHierarchy(Duration time_step_size);
55 };
56 
57 template <typename LevelIntegrator>
59  Duration min_dt(std::numeric_limits<double>::max());
60  for (int level_num = 0; Base::LevelExists(level_num); ++level_num) {
61  min_dt = std::min(min_dt, Base::ComputeStableDt(level_num));
62  }
63  MPI_Comm comm = Base::GetMpiCommunicator();
64  const Duration global_min_dt = MinAll(comm, min_dt);
65  return global_min_dt;
66 }
67 
68 template <typename LevelIntegrator>
71  return AdvanceLevel(0, time_step_size);
72 }
73 
74 template <typename LevelIntegrator>
77  Duration time_step_size) {
78  Base::PreAdvanceLevel(level, time_step_size, {0, 1});
79  const int next_level = level + 1;
80  if (Base::LevelExists(next_level)) {
81  Base::ResetCoarseFineFluxes(next_level, level);
83  AdvanceLevel(next_level, time_step_size);
84  if (!result) {
85  return result;
86  }
87  }
89  Base::AdvanceLevelNonRecursively(level, time_step_size, {0, 1});
90  if (!result) {
91  return result;
92  }
93  if (Base::LevelExists(next_level)) {
94  Base::ApplyFluxCorrection(next_level, level, time_step_size);
95  Base::CoarsenConservatively(next_level, level);
96  Base::CompleteFromCons(level, time_step_size);
97  }
98  Base::CopyScratchToData(level);
99  return Base::PostAdvanceLevel(level, time_step_size, {0, 1});
100 }
101 
102 } // namespace fub
103 
104 #endif
This is a solver class which does a AMR integration scheme without subcycling on finer levels.
Definition: NoSubcycleSolver.hpp:37
Duration ComputeStableDt()
Definition: NoSubcycleSolver.hpp:58
NoSubcycleSolver(const LevelIntegrator &integrator)
Definition: NoSubcycleSolver.hpp:45
NoSubcycleSolver(LevelIntegrator &&integrator)
Definition: NoSubcycleSolver.hpp:42
Result< void, TimeStepTooLarge > AdvanceHierarchy(Duration time_step_size)
Definition: NoSubcycleSolver.hpp:70
Result< void, TimeStepTooLarge > AdvanceLevel(int level, Duration time_step_size)
Definition: NoSubcycleSolver.hpp:76
Definition: SolverFacade.hpp:29
void CompleteFromCons(Equation &&equation, Complete< std::decay_t< Equation >> &complete, const Conservative< std::decay_t< Equation >> &cons)
Definition: CompleteFromCons.hpp:42
decltype(std::declval< Context >().PreAdvanceLevel(std::declval< Args >()...)) PreAdvanceLevel
A template typedef to detect the member function.
Definition: Meta.hpp:44
decltype(std::declval< Context >().PostAdvanceLevel(std::declval< Args >()...)) PostAdvanceLevel
A template typedef to detect the member function.
Definition: Meta.hpp:48
The fub namespace.
Definition: AnyBoundaryCondition.hpp:31
Duration MinAll(MPI_Comm comm, Duration local_duration)
std::chrono::duration< double > Duration
Definition: Duration.hpp:31
boost::outcome_v2::result< T, E > Result
Definition: outcome.hpp:32