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