Finite Volume Solver  prototype
A framework to build finite volume solvers for the AG Klein at the Freie Universität Berlin.
MultiBlockSourceTerm.hpp
Go to the documentation of this file.
1 // Copyright (c) 2020 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_AMREX_MULTI_BLOCK_SOURCE_TERM_HPP
22 #define FUB_AMREX_MULTI_BLOCK_SOURCE_TERM_HPP
23 
25 
26 #include <vector>
27 
28 namespace fub::amrex {
29 
30 /// This class manages multiple kinetic source terms which are associated to
31 /// independend one-dimensional domains
32 template <typename SourceTerm> class MultiBlockSourceTerm {
33 public:
34  static constexpr int Rank = SourceTerm::Rank;
35 
36  explicit MultiBlockSourceTerm(const std::vector<SourceTerm>& src_terms)
37  : source_terms_(src_terms) {}
38 
39  explicit MultiBlockSourceTerm(std::vector<SourceTerm>&& src_terms)
40  : source_terms_(std::move(src_terms)) {}
41 
43  const std::shared_ptr<MultiBlockGriddingAlgorithm>& grid) {
44  auto&& tubes = grid->GetTubes();
45  int i = 0;
46  for (auto&& tube : tubes) {
47  source_terms_[i].ResetHierarchyConfiguration(tube);
48  i = i + 1;
49  }
50  }
51 
52  [[nodiscard]] Duration ComputeStableDt(int level) noexcept {
53  Duration stable_dt(std::numeric_limits<double>::max());
54  for (SourceTerm& source : source_terms_) {
55  stable_dt = std::min(stable_dt, source.ComputeStableDt(level));
56  }
57  return stable_dt;
58  }
59 
60  /// \brief Integrates the source term for each tube in the specified context
61  template <typename IntegratorContext>
62  [[nodiscard]] Result<void, TimeStepTooLarge>
63  AdvanceLevel(IntegratorContext& context, int level, Duration dt,
64  [[maybe_unused]] const ::amrex::IntVect& ngrow = ::amrex::IntVect(0)) {
65  auto&& tubes = context.Tubes();
66  Result<void, TimeStepTooLarge> result = boost::outcome_v2::success();
67  int i = 0;
68  FUB_ASSERT(static_cast<std::size_t>(tubes.size()) == source_terms_.size());
69  for (auto&& tube : tubes) {
70  result = source_terms_[i].AdvanceLevel(tube, level, dt, ngrow);
71  if (!result) {
72  return result;
73  }
74  i = i + 1;
75  }
76  return result;
77  }
78 
79 private:
80  std::vector<SourceTerm> source_terms_{};
81 };
82 
83 } // namespace fub::amrex
84 
85 #endif
#define FUB_ASSERT(x)
Definition: assert.hpp:39
This class is used by the HypebrolicSplitLevelIntegrator and delegates AMR related tasks to the AMReX...
Definition: AMReX/IntegratorContext.hpp:49
This class manages multiple kinetic source terms which are associated to independend one-dimensional ...
Definition: MultiBlockSourceTerm.hpp:32
static constexpr int Rank
Definition: MultiBlockSourceTerm.hpp:34
Duration ComputeStableDt(int level) noexcept
Definition: MultiBlockSourceTerm.hpp:52
MultiBlockSourceTerm(const std::vector< SourceTerm > &src_terms)
Definition: MultiBlockSourceTerm.hpp:36
std::vector< SourceTerm > source_terms_
Definition: MultiBlockSourceTerm.hpp:80
void ResetHierarchyConfiguration(const std::shared_ptr< MultiBlockGriddingAlgorithm > &grid)
Definition: MultiBlockSourceTerm.hpp:42
MultiBlockSourceTerm(std::vector< SourceTerm > &&src_terms)
Definition: MultiBlockSourceTerm.hpp:39
Result< void, TimeStepTooLarge > AdvanceLevel(IntegratorContext &context, int level, Duration dt, [[maybe_unused]] const ::amrex::IntVect &ngrow=::amrex::IntVect(0))
Integrates the source term for each tube in the specified context.
Definition: MultiBlockSourceTerm.hpp:63
The amrex namespace.
Definition: AverageState.hpp:33
std::chrono::duration< double > Duration
Definition: Duration.hpp:31
boost::outcome_v2::result< T, E > Result
Definition: outcome.hpp:32