21 #ifndef FUB_AMREX_BOUNDARY_CONDITION_GENERIC_PRESSURE_VALVE_HPP
22 #define FUB_AMREX_BOUNDARY_CONDITION_GENERIC_PRESSURE_VALVE_HPP
34 std::string
prefix{
"GenericPressureValve"};
40 template <
typename EulerEquation>
41 [[nodiscard]] std::optional<Duration>
42 operator()(EulerEquation& equation, std::optional<Duration> t_opened,
43 double inner_pressure,
47 if (!t_opened && inner_pressure <= p_ref) {
48 t_opened = gridding.GetTimePoint();
49 }
else if (inner_pressure > 1.1 * p_ref) {
57 template <
typename EulerEquation>
58 [[nodiscard]] std::optional<Duration>
59 operator()(EulerEquation& equation, std::optional<Duration> t_opened,
60 double inner_pressure,
65 t_opened = gridding.GetTimePoint();
74 template <
typename EulerEquation>
76 operator()(EulerEquation& equation, std::optional<Duration> ,
77 double inner_pressure,
85 template <
typename EulerEquation,
typename InflowFunction,
86 typename ChangeTOpenedT,
87 typename IsBlocked = IsBlockedIfLargePressure>
91 const EulerEquation& equation,
105 const std::shared_ptr<KineticState<EulerEquation>>&
124 #if __has_cpp_attribute(no_unique_address)
135 template <
typename Equation,
typename InflowFunction>
138 ChangeTOpened_ReducedModelDemo> {
144 template <
typename Equation,
typename InflowFunction>
148 ->PressureValveBoundary_ReducedModelDemo<
Equation, InflowFunction>;
150 template <
typename Equation,
typename InflowFunction>
153 ->PressureValveBoundary_ReducedModelDemo<
Equation, InflowFunction>;
155 template <
typename Equation,
typename InflowFunction>
158 ChangeTOpened_Klein> {
164 template <
typename Equation,
typename InflowFunction>
168 ->PressureValveBoundary_Klein<
Equation, InflowFunction>;
170 template <
typename Equation,
typename InflowFunction>
173 ->PressureValveBoundary_Klein<
Equation, InflowFunction>;
175 template <
typename EulerEquation,
typename InflowFunction,
176 typename ChangeTOpened,
typename IsBlocked>
179 GenericPressureValveBoundary(
180 const EulerEquation& equation,
183 : equation_(equation),
184 options_(options), constant_boundary_{options_.dir, options_.side,
186 Complete<EulerEquation>(equation_)},
187 reflective_boundary_(equation_, options_.dir, options_.side),
188 compressor_state_(std::make_shared<
KineticState<EulerEquation>>(
189 std::move(initial_compressor_state))),
190 inflow_function_(std::move(fn)) {}
192 template <
typename EulerEquation,
typename InflowFunction,
193 typename ChangeTOpened,
typename IsBlocked>
195 EulerEquation, InflowFunction, ChangeTOpened,
196 IsBlocked>::FillBoundary(::amrex::MultiFab& mf,
199 if (dir == options_.dir) {
200 FillBoundary(mf, gridding, level);
203 template <
typename EulerEquation,
typename InflowFunction,
204 typename ChangeTOpenedT,
typename IsBlocked>
206 EulerEquation, InflowFunction, ChangeTOpenedT,
207 IsBlocked>::ChangeTOpened(
double inner_pressure,
209 std::optional<Duration> t_opened_new =
210 std::invoke(change_t_opened_, equation_, t_opened_, inner_pressure,
211 *compressor_state_, gridding, level);
214 if (!t_opened_ && t_opened_new) {
216 BOOST_LOG_SCOPED_LOGGER_TAG(log,
"Channel", options_.prefix);
217 BOOST_LOG_SCOPED_LOGGER_TAG(log,
"Time", t.count());
218 BOOST_LOG_SCOPED_LOGGER_TAG(log,
"Level", level);
219 BOOST_LOG(log) << fmt::format(
220 "Pressure valve has opened because inner pressure is {}.",
222 }
else if (t_opened_ && !t_opened_new) {
224 BOOST_LOG_SCOPED_LOGGER_TAG(log,
"Channel", options_.prefix);
225 BOOST_LOG_SCOPED_LOGGER_TAG(log,
"Time", t.count());
226 BOOST_LOG_SCOPED_LOGGER_TAG(log,
"Level", level);
227 BOOST_LOG(log) << fmt::format(
228 "Pressure valve has closed because inner pressure is {}.",
231 t_opened_ = t_opened_new;
234 template <
typename EulerEquation,
typename InflowFunction,
235 typename ChangeTOpenedT,
typename IsBlocked>
237 EulerEquation, InflowFunction, ChangeTOpenedT,
238 IsBlocked>::FillBoundary(::amrex::MultiFab& mf,
240 const ::amrex::Geometry& geom =
244 GetInnerBox(domain_box, options_.side, options_.dir, 1);
245 const double inner_pressure =
248 ChangeTOpened(inner_pressure, gridding, level);
251 std::invoke(is_blocked_, equation_, t_opened_, inner_pressure,
252 *compressor_state_, gridding, level);
254 reflective_boundary_.FillBoundary(mf, gridding, level);
258 const Duration t_diff = t - *t_opened_;
259 std::invoke(inflow_function_, equation_, constant_boundary_.state,
260 *compressor_state_, inner_pressure, t_diff, mf, gridding,
262 constant_boundary_.FillBoundary(mf, gridding, level);
#define FUB_ASSERT(x)
Definition: assert.hpp:39
Definition: GenericPressureValveBoundary.hpp:88
ReflectiveBoundary< execution::SequentialTag, EulerEquation > reflective_boundary_
Definition: GenericPressureValveBoundary.hpp:118
const std::shared_ptr< KineticState< EulerEquation > > & GetSharedCompressorState() const noexcept
Definition: GenericPressureValveBoundary.hpp:106
GenericPressureValveBoundary(const EulerEquation &equation, KineticState< EulerEquation > initial_compressor_state, InflowFunction fn, const GenericPressureValveBoundaryOptions &options={})
Definition: GenericPressureValveBoundary.hpp:179
ConstantBoundary< EulerEquation > constant_boundary_
Definition: GenericPressureValveBoundary.hpp:116
GenericPressureValveBoundaryOptions options_
Definition: GenericPressureValveBoundary.hpp:115
void FillBoundary(::amrex::MultiFab &mf, const GriddingAlgorithm &gridding, int level, Direction dir)
Definition: GenericPressureValveBoundary.hpp:196
std::optional< Duration > t_opened_
Definition: GenericPressureValveBoundary.hpp:122
void ChangeTOpened(double inner_pressure, const GriddingAlgorithm &gridding, int level)
Definition: GenericPressureValveBoundary.hpp:207
EulerEquation equation_
Definition: GenericPressureValveBoundary.hpp:114
IndexMapping< EulerEquation > comps_
Definition: GenericPressureValveBoundary.hpp:121
std::optional< Duration > GetTimePointWhenOpened() const noexcept
Definition: GenericPressureValveBoundary.hpp:101
ChangeTOpenedT change_t_opened_
Definition: GenericPressureValveBoundary.hpp:130
InflowFunction inflow_function_
Definition: GenericPressureValveBoundary.hpp:129
std::shared_ptr< KineticState< EulerEquation > > compressor_state_
Definition: GenericPressureValveBoundary.hpp:120
void FillBoundary(::amrex::MultiFab &mf, const GriddingAlgorithm &gridding, int level)
Definition: GenericPressureValveBoundary.hpp:238
IsBlocked is_blocked_
Definition: GenericPressureValveBoundary.hpp:131
This class modifies and initializes a PatchLevel in a PatchHierarchy.
Definition: AMReX/GriddingAlgorithm.hpp:60
Duration GetTimePoint() const noexcept
Returns the current time point on the coarsest refinement level.
Definition: AMReX/GriddingAlgorithm.hpp:133
PatchHierarchy & GetPatchHierarchy() noexcept
Definition: AMReX/GriddingAlgorithm.hpp:108
const ::amrex::Geometry & GetGeometry(int level) const
Returns a Geometry object for a specified level.
Definition: AMReX/boundary_condition/ReflectiveBoundary.hpp:34
The amrex namespace.
Definition: AverageState.hpp:33
::amrex::Box GetInnerBox(const ::amrex::Box &box, int side, Direction dir, int width)
PressureValveBoundary_Klein(const Equation &, KineticState< Equation >, InflowFunction, const GenericPressureValveBoundaryOptions &) -> PressureValveBoundary_Klein< Equation, InflowFunction >
PressureValveBoundary_ReducedModelDemo(const Equation &, KineticState< Equation >, InflowFunction, const GenericPressureValveBoundaryOptions &) -> PressureValveBoundary_ReducedModelDemo< Equation, InflowFunction >
double GetMeanValueInBox(const ::amrex::MultiFab &data, const ::amrex::Box &box, int component)
constexpr struct fub::euler::PressureFn Pressure
std::chrono::duration< double > Duration
Definition: Duration.hpp:31
boost::log::sources::severity_logger< boost::log::trivial::severity_level > SeverityLogger
Definition: Log.hpp:46
Direction
This is a type safe type to denote a dimensional split direction.
Definition: Direction.hpp:30
IndexBox< Rank > Box(const BasicView< State, Layout, Rank > &view)
Definition: State.hpp:486
SeverityLogger GetInfoLogger()
Definition: Log.hpp:48
This type has a constructor which takes an equation and might allocate any dynamically sized member v...
Definition: State.hpp:335
Definition: State.hpp:301
Definition: GenericPressureValveBoundary.hpp:56
std::optional< Duration > operator()(EulerEquation &equation, std::optional< Duration > t_opened, double inner_pressure, const KineticState< EulerEquation > &compressor_state, const GriddingAlgorithm &gridding, int) const noexcept
Definition: GenericPressureValveBoundary.hpp:59
Definition: GenericPressureValveBoundary.hpp:39
std::optional< Duration > operator()(EulerEquation &equation, std::optional< Duration > t_opened, double inner_pressure, const KineticState< EulerEquation > &compressor_state, const GriddingAlgorithm &gridding, int) const noexcept
Definition: GenericPressureValveBoundary.hpp:42
Definition: GenericPressureValveBoundary.hpp:33
Direction dir
Definition: GenericPressureValveBoundary.hpp:35
int side
Definition: GenericPressureValveBoundary.hpp:36
std::string prefix
Definition: GenericPressureValveBoundary.hpp:34
Definition: GenericPressureValveBoundary.hpp:73
bool operator()(EulerEquation &equation, std::optional< Duration >, double inner_pressure, const KineticState< EulerEquation > &compressor_state, const GriddingAlgorithm &, int) const noexcept
Definition: GenericPressureValveBoundary.hpp:76
Definition: GenericPressureValveBoundary.hpp:158
Definition: GenericPressureValveBoundary.hpp:138