InitializeFixedSources.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
6 #include <cstddef>
7 #include <utility>
8 
10 #include "DataStructures/DataBox/PrefixHelpers.hpp"
14 #include "Domain/Tags.hpp"
15 #include "Elliptic/DiscontinuousGalerkin/Tags.hpp"
16 #include "NumericalAlgorithms/DiscontinuousGalerkin/ApplyMassMatrix.hpp"
17 #include "ParallelAlgorithms/Initialization/MutateAssign.hpp"
19 #include "Utilities/TMPL.hpp"
20 #include "Utilities/TaggedTuple.hpp"
21 
22 /// \cond
23 namespace Parallel {
24 template <typename Metavariables>
25 struct GlobalCache;
26 } // namespace Parallel
27 /// \endcond
28 
29 namespace elliptic::Actions {
30 
31 /*!
32  * \brief Initialize the "fixed sources" of the elliptic equations, i.e. their
33  * variable-independent source term \f$f(x)\f$
34  *
35  * This action initializes \f$f(x)\f$ in an elliptic system of PDEs \f$-div(F) +
36  * S = f(x)\f$.
37  *
38  * Uses:
39  * - System:
40  * - `primal_fields`
41  * - DataBox:
42  * - `BackgroundTag`
43  * - `Tags::Coordinates<Dim, Frame::Inertial>`
44  *
45  * DataBox:
46  * - Adds:
47  * - `db::wrap_tags_in<::Tags::FixedSource, primal_fields>`
48  *
49  * \note This action relies on the `SetupDataBox` aggregated initialization
50  * mechanism, so `Actions::SetupDataBox` must be present in the `Initialization`
51  * phase action list prior to this action.
52  */
53 template <typename System, typename BackgroundTag>
55  private:
58 
59  public:
60  using const_global_cache_tags = tmpl::list<elliptic::dg::Tags::Massive>;
61  using simple_tags = tmpl::list<fixed_sources_tag>;
62  using compute_tags = tmpl::list<>;
63 
64  template <typename DbTagsList, typename... InboxTags, typename Metavariables,
65  size_t Dim, typename ActionList, typename ParallelComponent>
66  static std::tuple<db::DataBox<DbTagsList>&&> apply(
67  db::DataBox<DbTagsList>& box,
68  const tuples::TaggedTuple<InboxTags...>& /*inboxes*/,
69  const Parallel::GlobalCache<Metavariables>& /*cache*/,
70  const ElementId<Dim>& /*array_index*/, const ActionList /*meta*/,
71  const ParallelComponent* const /*meta*/) noexcept {
72  const auto& inertial_coords =
73  get<domain::Tags::Coordinates<Dim, Frame::Inertial>>(box);
74  const auto& background = db::get<BackgroundTag>(box);
75 
76  // Retrieve the fixed-sources of the elliptic system from the background,
77  // which (along with the boundary conditions) define the problem we want to
78  // solve.
79  auto fixed_sources = variables_from_tagged_tuple(background.variables(
80  inertial_coords, typename fixed_sources_tag::type::tags_list{}));
81 
82  // Apply DG mass matrix to the fixed sources if the DG operator is massive
83  if (db::get<elliptic::dg::Tags::Massive>(box)) {
84  const auto& mesh = db::get<domain::Tags::Mesh<Dim>>(box);
85  const auto& det_inv_jacobian = db::get<
87  fixed_sources /= get(det_inv_jacobian);
88  ::dg::apply_mass_matrix(make_not_null(&fixed_sources), mesh);
89  }
90 
91  ::Initialization::mutate_assign<simple_tags>(make_not_null(&box),
92  std::move(fixed_sources));
93  return {std::move(box)};
94  }
95 };
96 
97 } // namespace elliptic::Actions
variables_from_tagged_tuple
Variables< tmpl::list< Tags... > > variables_from_tagged_tuple(const tuples::TaggedTuple< Tags... > &tuple) noexcept
Definition: Variables.hpp:842
utility
Parallel::GlobalCache
Definition: ElementReceiveInterpPoints.hpp:15
Tags.hpp
Tags::Variables
Definition: VariablesTag.hpp:21
std::tuple
db::get
const auto & get(const DataBox< TagList > &box) noexcept
Retrieve the item with tag Tag from the DataBox.
Definition: DataBox.hpp:791
ElementId< Dim >
ElementId.hpp
DataBox.hpp
cstddef
MakeWithValue.hpp
tuples::TaggedTuple
An associative container that is indexed by structs.
Definition: TaggedTuple.hpp:271
Variables.hpp
db::wrap_tags_in
tmpl::transform< TagList, tmpl::bind< Wrapper, tmpl::_1, tmpl::pin< Args >... > > wrap_tags_in
Create a new tmpl::list of tags by wrapping each tag in TagList in Wrapper<_, Args....
Definition: PrefixHelpers.hpp:30
make_not_null
gsl::not_null< T * > make_not_null(T *ptr) noexcept
Construct a not_null from a pointer. Often this will be done as an implicit conversion,...
Definition: Gsl.hpp:880
domain::Tags::DetInvJacobian
The determinant of the inverse Jacobian from the source frame to the target frame.
Definition: Tags.hpp:235
Prefixes.hpp
Parallel
Functionality for parallelization.
Definition: ElementReceiveInterpPoints.hpp:13
elliptic::Actions::InitializeFixedSources
Initialize the "fixed sources" of the elliptic equations, i.e. their variable-independent source term...
Definition: InitializeFixedSources.hpp:54
TMPL.hpp