Finite Volume Solver  prototype
A framework to build finite volume solvers for the AG Klein at the Freie Universität Berlin.
IgniteDetonation.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_AMREX_IGNITE_DETONATION_HPP
22 #define FUB_AMREX_IGNITE_DETONATION_HPP
23 
25 #include "fub/TimeStepError.hpp"
27 #include "fub/ext/outcome.hpp"
28 
30 
31 #include <boost/log/trivial.hpp>
32 #include <boost/serialization/access.hpp>
33 
34 namespace fub::amrex {
35 
36 /// \ingroup LevelIntegrator
39 
41  const std::map<std::string, pybind11::object>& vm,
42  const std::string& prefix = "ignite");
43 
44  template <typename Logger> void Print(Logger& log) const {
45  // clang-format off
46  BOOST_LOG(log) << fmt::format("Ignite Detonation '{}' Options:", prefix);
47  BOOST_LOG(log) << fmt::format(" - measurement_position = {} [m]", measurement_position);
48  BOOST_LOG(log) << fmt::format(" - equivalence_ratio_criterium = {} [-]", equivalence_ratio_criterium);
49  BOOST_LOG(log) << fmt::format(" - temperature_low = {} [K]", temperature_low);
50  BOOST_LOG(log) << fmt::format(" - temperature_high = {} [K]", temperature_high);
51  BOOST_LOG(log) << fmt::format(" - ramp_width = {} [m]", ramp_width);
52  BOOST_LOG(log) << fmt::format(" - ignite_position = {} [m]", ignite_position);
53  BOOST_LOG(log) << fmt::format(" - ignite_interval = {} [s]", ignite_interval.count());
54  BOOST_LOG(log) << fmt::format(" - offset = {} [s]", offset.count());
55  // clang-format on
56  }
57 
58  std::string prefix{"ignite"};
59  double measurement_position{1.0};
61  double temperature_low{300.0};
62  double temperature_high{2000.0};
63  double ramp_width{0.05};
64  double ignite_position{0.0};
67 };
68 
69 } // namespace fub::amrex
70 
71 namespace boost::serialization {
72 
73 template <typename Archive>
74 void serialize(Archive& ar, ::fub::amrex::IgniteDetonationOptions& opts,
75  unsigned int version);
76 
77 } // namespace boost::serialization
78 
79 namespace fub::amrex {
80 
81 /// \ingroup LevelIntegrator
83 public:
84  static constexpr int Rank = 1;
85 
86  /// \brief Constructs the source term
87  ///
88  /// \param[in] eq The equation which knows the species
89  ///
90  /// \param[in] max_refinement_level This is needed to allocate storate for
91  /// ignition times at each refinement level.
92  ///
93  /// \param[in] opts Options which
94  /// manipulate the way of igniting the the gas mixture
95  IgniteDetonation(const IdealGasMix<1>& eq, int max_refinement_level,
96  const IgniteDetonationOptions& opts = {});
97 
98  /// \brief Resets internal configuration
99  ///
100  /// Resets the last ignition time points if the time point on grid is lower
101  /// than the last recorded ignition. This happens when the CFL condition gets
102  /// violated right after the ignition.
103  void ResetHierarchyConfiguration(std::shared_ptr<GriddingAlgorithm> grid);
104 
105  /// \brief Returns numeric_limits<double>::max()
106  ///
107  /// This operator artificially ignites a detonation and has no restriction on
108  /// the time step size.
109  [[nodiscard]] Duration ComputeStableDt(int) const noexcept;
110 
111  /// Uses the scratch space of simulation_data to evaluate the criterion on the
112  /// current equivalence ratio.
113  [[nodiscard]] Result<void, TimeStepTooLarge>
114  AdvanceLevel(IntegratorContext& simulation_data, int level, Duration dt,
115  const ::amrex::IntVect& ngrow = ::amrex::IntVect(0));
116 
117  /// \brief Returns the options for this operator
118  [[nodiscard]] const IgniteDetonationOptions& GetOptions() const noexcept {
119  return options_;
120  }
121 
122  /// \brief Returns the time points for the last ignition on refinement level
123  /// `level`.
124  [[nodiscard]] Duration GetNextIgnitionTimePoint(int level) const noexcept;
125 
126  /// \brief Set a time point for an ignition on refinement level `level`.
127  void SetNextIgnitionTimePoint(int level, Duration t) noexcept;
128 
129 private:
132  std::vector<Duration> next_ignition_time_backup_{};
133  std::vector<Duration> next_ignition_time_{};
134 
135  friend class boost::serialization::access;
136  template <typename Archive> void serialize(Archive& ar, unsigned int version);
137 };
138 
139 template <typename Archive>
140 void IgniteDetonation::serialize(Archive& ar, unsigned int /* version */) {
141  // clang-format off
142  ar & options_;
143  ar & next_ignition_time_;
145  // clang-format on
146 }
147 
148 } // namespace fub::amrex
149 
150 namespace boost::serialization {
151 
152 template <typename Archive>
153 void serialize(Archive& ar, ::fub::amrex::IgniteDetonationOptions& opts,
154  unsigned int /* version */) {
155  // clang-format off
156  ar & opts.equivalence_ratio_criterium;
157  ar & opts.measurement_position;
158  ar & opts.ramp_width;
159  ar & opts.temperature_high;
160  ar & opts.temperature_low;
161  ar & opts.ignite_interval;
162  ar & opts.ignite_position;
163  ar & opts.offset;
164  // clang-format on
165 }
166 
167 } // namespace boost::serialization
168 
169 #endif
Definition: IgniteDetonation.hpp:82
static constexpr int Rank
Definition: IgniteDetonation.hpp:84
void SetNextIgnitionTimePoint(int level, Duration t) noexcept
Set a time point for an ignition on refinement level level.
Duration GetNextIgnitionTimePoint(int level) const noexcept
Returns the time points for the last ignition on refinement level level.
IgniteDetonation(const IdealGasMix< 1 > &eq, int max_refinement_level, const IgniteDetonationOptions &opts={})
Constructs the source term.
void ResetHierarchyConfiguration(std::shared_ptr< GriddingAlgorithm > grid)
Resets internal configuration.
Duration ComputeStableDt(int) const noexcept
Returns numeric_limits<double>::max()
void serialize(Archive &ar, unsigned int version)
Definition: IgniteDetonation.hpp:140
const IgniteDetonationOptions & GetOptions() const noexcept
Returns the options for this operator.
Definition: IgniteDetonation.hpp:118
std::vector< Duration > next_ignition_time_
Definition: IgniteDetonation.hpp:133
std::vector< Duration > next_ignition_time_backup_
Definition: IgniteDetonation.hpp:132
IdealGasMix< 1 > equation_
Definition: IgniteDetonation.hpp:130
Result< void, TimeStepTooLarge > AdvanceLevel(IntegratorContext &simulation_data, int level, Duration dt, const ::amrex::IntVect &ngrow=::amrex::IntVect(0))
Uses the scratch space of simulation_data to evaluate the criterion on the current equivalence ratio.
IgniteDetonationOptions options_
Definition: IgniteDetonation.hpp:131
This class is used by the HypebrolicSplitLevelIntegrator and delegates AMR related tasks to the AMReX...
Definition: AMReX/IntegratorContext.hpp:49
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
Definition: IgniteDetonation.hpp:37
double ramp_width
Definition: IgniteDetonation.hpp:63
double temperature_low
Definition: IgniteDetonation.hpp:61
std::string prefix
Definition: IgniteDetonation.hpp:58
IgniteDetonationOptions(const std::map< std::string, pybind11::object > &vm, const std::string &prefix="ignite")
Duration offset
Definition: IgniteDetonation.hpp:65
double temperature_high
Definition: IgniteDetonation.hpp:62
double ignite_position
Definition: IgniteDetonation.hpp:64
void Print(Logger &log) const
Definition: IgniteDetonation.hpp:44
double equivalence_ratio_criterium
Definition: IgniteDetonation.hpp:60
Duration ignite_interval
Definition: IgniteDetonation.hpp:66
double measurement_position
Definition: IgniteDetonation.hpp:59