Line data Source code
1 0 : // Distributed under the MIT License.
2 : // See LICENSE.txt for details.
3 :
4 : #pragma once
5 :
6 : #include <array>
7 : #include <cstddef>
8 : #include <limits>
9 : #include <memory>
10 : #include <utility>
11 :
12 : #include "DataStructures/VariablesTag.hpp"
13 : #include "Domain/Structure/DirectionalIdMap.hpp"
14 : #include "Domain/Tags.hpp"
15 : #include "Evolution/DgSubcell/Tags/GhostDataForReconstruction.hpp"
16 : #include "Evolution/DgSubcell/Tags/Mesh.hpp"
17 : #include "Evolution/Systems/GrMhd/ValenciaDivClean/FiniteDifference/ReconstructWork.hpp"
18 : #include "Evolution/Systems/GrMhd/ValenciaDivClean/FiniteDifference/Reconstructor.hpp"
19 : #include "Evolution/VariableFixing/FixToAtmosphere.hpp"
20 : #include "Evolution/VariableFixing/Tags.hpp"
21 : #include "NumericalAlgorithms/FiniteDifference/FallbackReconstructorType.hpp"
22 : #include "Options/String.hpp"
23 : #include "PointwiseFunctions/Hydro/Tags.hpp"
24 : #include "Utilities/TMPL.hpp"
25 :
26 : /// \cond
27 : class DataVector;
28 : template <size_t Dim>
29 : class Direction;
30 : template <size_t Dim>
31 : class Element;
32 : template <size_t Dim>
33 : class ElementId;
34 : namespace EquationsOfState {
35 : template <bool IsRelativistic, size_t ThermodynamicDim>
36 : class EquationOfState;
37 : } // namespace EquationsOfState
38 : template <size_t Dim>
39 : class Mesh;
40 : namespace gsl {
41 : template <typename T>
42 : class not_null;
43 : } // namespace gsl
44 : namespace PUP {
45 : class er;
46 : } // namespace PUP
47 : template <typename TagsList>
48 : class Variables;
49 : namespace evolution::dg::subcell {
50 : class GhostData;
51 : } // namespace evolution::dg::subcell
52 : /// \endcond
53 :
54 : namespace grmhd::ValenciaDivClean::fd {
55 : /*!
56 : * \brief Fifth order weighted nonlinear compact scheme reconstruction using the
57 : * Z oscillation indicator. See ::fd::reconstruction::wcns5z() for details.
58 : *
59 : */
60 1 : class Wcns5zPrim : public Reconstructor {
61 : private:
62 0 : using prims_to_reconstruct_tags =
63 : tmpl::list<hydro::Tags::RestMassDensity<DataVector>,
64 : hydro::Tags::ElectronFraction<DataVector>,
65 : hydro::Tags::Temperature<DataVector>,
66 : hydro::Tags::LorentzFactorTimesSpatialVelocity<DataVector, 3>,
67 : hydro::Tags::MagneticField<DataVector, 3>,
68 : hydro::Tags::DivergenceCleaningField<DataVector>>;
69 :
70 0 : using FallbackReconstructorType =
71 : ::fd::reconstruction::FallbackReconstructorType;
72 :
73 : public:
74 0 : static constexpr size_t dim = 3;
75 :
76 0 : struct NonlinearWeightExponent {
77 0 : using type = size_t;
78 0 : static constexpr Options::String help = {
79 : "The exponent q to which the oscillation indicator term is raised"};
80 : };
81 0 : struct Epsilon {
82 0 : using type = double;
83 0 : static constexpr Options::String help = {
84 : "The parameter added to the oscillation indicators to avoid division "
85 : "by zero"};
86 : };
87 0 : struct FallbackReconstructor {
88 0 : using type = FallbackReconstructorType;
89 0 : static constexpr Options::String help = {
90 : "A reconstruction scheme to fallback to adaptively. Finite difference "
91 : "will switch to this reconstruction scheme if there are more extrema "
92 : "in a FD stencil than a specified number. See also the option "
93 : "'MaxNumberOfExtrema' below. Adaptive fallback is disabled if 'None'."};
94 : };
95 0 : struct MaxNumberOfExtrema {
96 0 : using type = size_t;
97 0 : static constexpr Options::String help = {
98 : "The maximum allowed number of extrema in FD stencil for using Wcns5z "
99 : "reconstruction before switching to a low-order reconstruction. If "
100 : "FallbackReconstructor=None, this option is ignored"};
101 : };
102 0 : struct ReconstructRhoTimesTemperature {
103 0 : using type = bool;
104 0 : static constexpr Options::String help = {
105 : "If 'true' then we reconstruct the rho*T, if 'false' we reconstruct "
106 : "T."};
107 : };
108 :
109 0 : using options =
110 : tmpl::list<NonlinearWeightExponent, Epsilon, FallbackReconstructor,
111 : MaxNumberOfExtrema, ReconstructRhoTimesTemperature>;
112 :
113 0 : static constexpr Options::String help{
114 : "WCNS 5Z reconstruction scheme using primitive variables."};
115 :
116 0 : Wcns5zPrim() = default;
117 0 : Wcns5zPrim(Wcns5zPrim&&) = default;
118 0 : Wcns5zPrim& operator=(Wcns5zPrim&&) = default;
119 0 : Wcns5zPrim(const Wcns5zPrim&) = default;
120 0 : Wcns5zPrim& operator=(const Wcns5zPrim&) = default;
121 0 : ~Wcns5zPrim() override = default;
122 :
123 0 : Wcns5zPrim(size_t nonlinear_weight_exponent, double epsilon,
124 : FallbackReconstructorType fallback_reconstructor,
125 : size_t max_number_of_extrema,
126 : bool reconstruct_rho_times_temperature);
127 :
128 0 : explicit Wcns5zPrim(CkMigrateMessage* msg);
129 :
130 0 : WRAPPED_PUPable_decl_base_template(Reconstructor, Wcns5zPrim);
131 :
132 0 : auto get_clone() const -> std::unique_ptr<Reconstructor> override;
133 :
134 0 : static constexpr bool use_adaptive_order = false;
135 :
136 0 : void pup(PUP::er& p) override;
137 :
138 0 : size_t ghost_zone_size() const override { return 3; }
139 :
140 0 : using reconstruction_argument_tags =
141 : tmpl::list<::Tags::Variables<hydro::grmhd_tags<DataVector>>,
142 : hydro::Tags::GrmhdEquationOfState, domain::Tags::Element<dim>,
143 : evolution::dg::subcell::Tags::GhostDataForReconstruction<dim>,
144 : evolution::dg::subcell::Tags::Mesh<dim>,
145 : ::Tags::VariableFixer<VariableFixing::FixToAtmosphere<dim>>>;
146 :
147 : template <size_t ThermodynamicDim>
148 0 : void reconstruct(
149 : gsl::not_null<std::array<Variables<tags_list_for_reconstruct>, dim>*>
150 : vars_on_lower_face,
151 : gsl::not_null<std::array<Variables<tags_list_for_reconstruct>, dim>*>
152 : vars_on_upper_face,
153 : const Variables<hydro::grmhd_tags<DataVector>>& volume_prims,
154 : const EquationsOfState::EquationOfState<true, ThermodynamicDim>& eos,
155 : const Element<dim>& element,
156 : const DirectionalIdMap<dim, evolution::dg::subcell::GhostData>&
157 : ghost_data,
158 : const Mesh<dim>& subcell_mesh,
159 : const VariableFixing::FixToAtmosphere<dim>& fix_to_atmosphere) const;
160 :
161 : template <size_t ThermodynamicDim>
162 0 : void reconstruct_fd_neighbor(
163 : gsl::not_null<Variables<tags_list_for_reconstruct>*> vars_on_face,
164 : const Variables<hydro::grmhd_tags<DataVector>>& subcell_volume_prims,
165 : const EquationsOfState::EquationOfState<true, ThermodynamicDim>& eos,
166 : const Element<dim>& element,
167 : const DirectionalIdMap<dim, evolution::dg::subcell::GhostData>&
168 : ghost_data,
169 : const Mesh<dim>& subcell_mesh,
170 : const VariableFixing::FixToAtmosphere<dim>& fix_to_atmosphere,
171 : Direction<dim> direction_to_reconstruct) const;
172 :
173 0 : bool reconstruct_rho_times_temperature() const override;
174 :
175 : private:
176 : // NOLINTNEXTLINE(readability-redundant-declaration)
177 0 : friend bool operator==(const Wcns5zPrim& lhs, const Wcns5zPrim& rhs);
178 0 : friend bool operator!=(const Wcns5zPrim& lhs, const Wcns5zPrim& rhs);
179 :
180 0 : size_t nonlinear_weight_exponent_ = 0;
181 0 : double epsilon_ = std::numeric_limits<double>::signaling_NaN();
182 0 : FallbackReconstructorType fallback_reconstructor_ =
183 : FallbackReconstructorType::None;
184 0 : size_t max_number_of_extrema_ = 0;
185 0 : bool reconstruct_rho_times_temperature_{false};
186 :
187 0 : void (*reconstruct_)(gsl::not_null<std::array<gsl::span<double>, dim>*>,
188 : gsl::not_null<std::array<gsl::span<double>, dim>*>,
189 : const gsl::span<const double>&,
190 : const DirectionMap<dim, gsl::span<const double>>&,
191 : const Index<dim>&, size_t, double, size_t) = nullptr;
192 0 : void (*reconstruct_lower_neighbor_)(gsl::not_null<DataVector*>,
193 : const DataVector&, const DataVector&,
194 : const Index<dim>&, const Index<dim>&,
195 : const Direction<dim>&, const double&,
196 : const size_t&) = nullptr;
197 0 : void (*reconstruct_upper_neighbor_)(gsl::not_null<DataVector*>,
198 : const DataVector&, const DataVector&,
199 : const Index<dim>&, const Index<dim>&,
200 : const Direction<dim>&, const double&,
201 : const size_t&) = nullptr;
202 : };
203 :
204 : } // namespace grmhd::ValenciaDivClean::fd
|