Finite Volume Solver  prototype
A framework to build finite volume solvers for the AG Klein at the Freie Universität Berlin.
BK19LevelIntegrator.hpp
Go to the documentation of this file.
1 // Copyright (c) 2019 Maikel Nadolski
2 // Copyright (c) 2019 Stefan Vater
3 //
4 // Permission is hereby granted, free of charge, to any person obtaining a copy
5 // of this software and associated documentation files (the "Software"), to deal
6 // in the Software without restriction, including without limitation the rights
7 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 // copies of the Software, and to permit persons to whom the Software is
9 // furnished to do so, subject to the following conditions:
10 //
11 // The above copyright notice and this permission notice shall be included in
12 // all copies or substantial portions of the Software.
13 //
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 // SOFTWARE.
21 
22 #ifndef FUB_BK19_LEVEL_INTEGRATOR_HPP
23 #define FUB_BK19_LEVEL_INTEGRATOR_HPP
24 
26 #include "fub/AMReX/MLMG/MLNodeHelmholtz.hpp"
28 #include "fub/ext/Eigen.hpp"
31 
32 #include <AMReX_MLMG.H>
33 
34 #include <AMReX_PlotFileUtil.H>
35 #include <AMReX_VisMF.H>
36 
37 namespace fub::amrex {
38 
41  std::array<::amrex::MultiFab, 2>& Pv_faces, ::amrex::MultiFab& Pv_cells,
42  const ::amrex::MultiFab& scratch, const ::amrex::Periodicity& periodicity);
43 
44 /// \ingroup LevelIntegrator
48 
49  template <typename Log> void Print(Log& log);
50 
51  bool do_initial_projection = true;
52  double mlmg_tolerance_rel = 1.0e-4;
53  double mlmg_tolerance_abs = -1.0;
54  int mlmg_max_iter = 100;
55  int mlmg_verbose = 0;
56  double bottom_tolerance_rel = 1.0e-4;
57  double bottom_tolerance_abs = -1.0;
58  int bottom_max_iter = 20;
59  int bottom_verbose = 0;
61  std::string prefix = "BK19LevelIntegrator";
62  bool output_between_steps = false;
63 };
64 
65 /// \ingroup LevelIntegrator
67 
68  /// Specific gas constant
69  double R_gas{287.4};
70 
71  /// Heat capacity ratio
72  double gamma{1.4};
73 
74  /// Heat capacity at constant pressure
75  double c_p{1006.0};
76 
77  /// Gravitational acceleration
78  double g{10.0}; // [m / s^2]
79 
80  /// Coriolis parameter in beta plane
81  double f{0.0};
82  std::array<double, 3> k_vect{0.0, 0.0, 1.0};
83 
84  double alpha_p{1.0};
85  double Msq{0.0};
86 };
87 
88 /// \ingroup LevelIntegrator
91  AMREX_SPACEDIM, CompressibleAdvectionIntegratorContext,
92  AnySplitMethod> {
93 public:
94  static constexpr int Rank = AMREX_SPACEDIM;
95 
96  using Coordinates = Eigen::Matrix<double, Rank, 1>;
100  using SplittingMethod = ::fub::AnySplitMethod;
101 
104 
105  using AdvectionSolver::ApplyFluxCorrection;
106  using AdvectionSolver::CoarsenConservatively;
109  using AdvectionSolver::CopyDataToScratch;
110  using AdvectionSolver::CopyScratchToData;
112  using AdvectionSolver::GetCounterRegistry;
113  using AdvectionSolver::GetCycles;
114  using AdvectionSolver::GetGriddingAlgorithm;
115  using AdvectionSolver::GetMpiCommunicator;
116  using AdvectionSolver::GetRatioToCoarserLevel;
117  using AdvectionSolver::GetTimePoint;
118  using AdvectionSolver::LevelExists;
123  using AdvectionSolver::ResetCoarseFineFluxes;
125 
126  AdvectionSolver& GetAdvection() { return *this; }
127  const AdvectionSolver& GetAdvection() const { return *this; }
128 
130  const CompressibleAdvection<Rank>& equation, AdvectionSolver advection,
131  std::shared_ptr<::amrex::MLNodeHelmholtz> linop,
132  const BK19PhysicalParameters& physical_parameters,
134 
135  void ResetPatchHierarchy(std::shared_ptr<GriddingAlgorithm> grid);
136 
139  std::pair<int, int> subcycle);
140 
141  void InitialProjection(int level);
142 
143 
144 private:
149  std::shared_ptr<::amrex::MLNodeHelmholtz> lin_op_;
150 };
151 
152 void WriteRawField(const std::string& path, const std::string& name,
153  const ::amrex::MultiFab& data, int level);
154 
156  std::string plotfilename{};
157 
159  void operator()(const GriddingAlgorithm& grid) const;
160 };
161 
162 template <typename Log> void BK19LevelIntegratorOptions::Print(Log& log) {
163  BOOST_LOG(log) << fmt::format(" - do_initial_projection = {}", do_initial_projection);
164  BOOST_LOG(log) << fmt::format(" - mlmg_tolerance_rel = {}",
166  BOOST_LOG(log) << fmt::format(" - mlmg_tolerance_abs = {}",
168  BOOST_LOG(log) << fmt::format(" - mlmg_max_iter = {}", mlmg_max_iter);
169  BOOST_LOG(log) << fmt::format(" - mlmg_verbose = {}", mlmg_verbose);
170  BOOST_LOG(log) << fmt::format(" - bottom_tolerance_rel = {}",
172  BOOST_LOG(log) << fmt::format(" - bottom_tolerance_abs = {}",
174  BOOST_LOG(log) << fmt::format(" - bottom_max_iter = {}", bottom_max_iter);
175  BOOST_LOG(log) << fmt::format(" - bottom_verbose = {}", bottom_verbose);
176  BOOST_LOG(log) << fmt::format(" - always_use_bnorm = {}", always_use_bnorm);
177  BOOST_LOG(log) << fmt::format(" - prefix = {}", prefix);
178  BOOST_LOG(log) << fmt::format(" - output_between_steps = {}",
180 }
181 
182 } // namespace fub::amrex
183 
184 #endif
This Level Integrator applies a very general AMR integration scheme in context of dimensional splitti...
Definition: DimensionalSplitLevelIntegrator.hpp:55
void PostAdvanceHierarchy([[maybe_unused]] Duration time_step_size)
Definition: DimensionalSplitLevelIntegrator.hpp:159
const IntegratorContext & GetContext() const noexcept
Definition: DimensionalSplitLevelIntegrator.hpp:89
void PreAdvanceLevel([[maybe_unused]] int level, [[maybe_unused]] Duration time_step_size, [[maybe_unused]] std::pair< int, int > subcycle)
Definition: DimensionalSplitLevelIntegrator.hpp:169
void PreAdvanceHierarchy()
Definition: DimensionalSplitLevelIntegrator.hpp:152
Result< void, TimeStepTooLarge > PostAdvanceLevel([[maybe_unused]] int level, [[maybe_unused]] Duration time_step_size, [[maybe_unused]] std::pair< int, int > subcycle)
Definition: DimensionalSplitLevelIntegrator.hpp:195
Duration ComputeStableDt(int level_number)
Returns a stable dt on a specified level across all spatial directions.
Definition: DimensionalSplitLevelIntegrator.hpp:206
Definition: BK19LevelIntegrator.hpp:92
const AdvectionSolver & GetAdvection() const
Definition: BK19LevelIntegrator.hpp:127
BK19PhysicalParameters phys_param_
Definition: BK19LevelIntegrator.hpp:145
BK19LevelIntegrator(const CompressibleAdvection< Rank > &equation, AdvectionSolver advection, std::shared_ptr<::amrex::MLNodeHelmholtz > linop, const BK19PhysicalParameters &physical_parameters, const BK19LevelIntegratorOptions &options=BK19LevelIntegratorOptions())
std::shared_ptr<::amrex::MLNodeHelmholtz > lin_op_
Definition: BK19LevelIntegrator.hpp:149
fub::IndexMapping< fub::CompressibleAdvection< 2 > > index_
Definition: BK19LevelIntegrator.hpp:148
void ResetPatchHierarchy(std::shared_ptr< GriddingAlgorithm > grid)
CompressibleAdvection< Rank > equation_
Definition: BK19LevelIntegrator.hpp:147
::fub::AnySplitMethod SplittingMethod
Definition: BK19LevelIntegrator.hpp:100
Result< void, TimeStepTooLarge > AdvanceLevelNonRecursively(int level, Duration dt, std::pair< int, int > subcycle)
static constexpr int Rank
Definition: BK19LevelIntegrator.hpp:94
AdvectionSolver & GetAdvection()
Definition: BK19LevelIntegrator.hpp:126
BK19LevelIntegratorOptions options_
Definition: BK19LevelIntegrator.hpp:146
Eigen::Matrix< double, Rank, 1 > Coordinates
Definition: BK19LevelIntegrator.hpp:96
Definition: CompressibleAdvectionIntegratorContext.hpp:34
This class modifies and initializes a PatchLevel in a PatchHierarchy.
Definition: AMReX/GriddingAlgorithm.hpp:60
void CompleteFromCons(Equation &&equation, Complete< std::decay_t< Equation >> &complete, const Conservative< std::decay_t< Equation >> &cons)
Definition: CompleteFromCons.hpp:42
The amrex namespace.
Definition: AverageState.hpp:33
void RecomputeAdvectiveFluxes(const IndexMapping< CompressibleAdvection< 2 >> &index, std::array<::amrex::MultiFab, 2 > &Pv_faces, ::amrex::MultiFab &Pv_cells, const ::amrex::MultiFab &scratch, const ::amrex::Periodicity &periodicity)
void WriteRawField(const std::string &path, const std::string &name, const ::amrex::MultiFab &data, int level)
decltype(std::declval< T >().ResetHierarchyConfiguration(std::declval< Args >()...)) ResetHierarchyConfiguration
A template typedef to detect the member function.
Definition: Meta.hpp:52
void Log(std::string message, Duration timepoint, boost::log::trivial::severity_level level=boost::log::trivial::severity_level::info)
std::chrono::duration< double > Duration
Definition: Duration.hpp:31
boost::outcome_v2::result< T, E > Result
Definition: outcome.hpp:32
std::ptrdiff_t index
Definition: type_traits.hpp:179
std::map< std::string, pybind11::object > ProgramOptions
Definition: ProgramOptions.hpp:40
Definition: CompressibleAdvection.hpp:97
Definition: State.hpp:859
Definition: BK19LevelIntegrator.hpp:45
int bottom_max_iter
Definition: BK19LevelIntegrator.hpp:58
bool output_between_steps
Definition: BK19LevelIntegrator.hpp:62
double mlmg_tolerance_rel
Definition: BK19LevelIntegrator.hpp:52
BK19LevelIntegratorOptions(const ProgramOptions &map)
std::string prefix
Definition: BK19LevelIntegrator.hpp:61
int mlmg_verbose
Definition: BK19LevelIntegrator.hpp:55
int always_use_bnorm
Definition: BK19LevelIntegrator.hpp:60
bool do_initial_projection
Definition: BK19LevelIntegrator.hpp:51
int mlmg_max_iter
Definition: BK19LevelIntegrator.hpp:54
int bottom_verbose
Definition: BK19LevelIntegrator.hpp:59
double mlmg_tolerance_abs
Definition: BK19LevelIntegrator.hpp:53
double bottom_tolerance_rel
Definition: BK19LevelIntegrator.hpp:56
double bottom_tolerance_abs
Definition: BK19LevelIntegrator.hpp:57
void Print(Log &log)
Definition: BK19LevelIntegrator.hpp:162
Definition: BK19LevelIntegrator.hpp:66
double f
Coriolis parameter in beta plane.
Definition: BK19LevelIntegrator.hpp:81
double g
Gravitational acceleration.
Definition: BK19LevelIntegrator.hpp:78
double alpha_p
Definition: BK19LevelIntegrator.hpp:84
double c_p
Heat capacity at constant pressure.
Definition: BK19LevelIntegrator.hpp:75
double R_gas
Specific gas constant.
Definition: BK19LevelIntegrator.hpp:69
double gamma
Heat capacity ratio.
Definition: BK19LevelIntegrator.hpp:72
std::array< double, 3 > k_vect
Definition: BK19LevelIntegrator.hpp:82
double Msq
Definition: BK19LevelIntegrator.hpp:85
Definition: BK19LevelIntegrator.hpp:155
void operator()(const GriddingAlgorithm &grid) const
std::string plotfilename
Definition: BK19LevelIntegrator.hpp:156
void operator()(const CompressibleAdvectionIntegratorContext &context) const