InitializeBackgroundFields.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
6 #include <cstddef>
7 #include <tuple>
8 #include <type_traits>
9 #include <utility>
10 
14 #include "Domain/Tags.hpp"
15 #include "ParallelAlgorithms/Initialization/MutateAssign.hpp"
16 #include "Utilities/Gsl.hpp"
17 #include "Utilities/TMPL.hpp"
18 #include "Utilities/TaggedTuple.hpp"
19 
20 /// \cond
21 namespace Parallel {
22 template <typename Metavariables>
23 struct GlobalCache;
24 } // namespace Parallel
25 /// \endcond
26 
27 namespace elliptic::Actions {
28 
29 /*!
30  * \brief Initialize the variable-independent background fields for an elliptic
31  * solve.
32  *
33  * Examples for background fields would be a background metric, associated
34  * curvature quantities, or matter sources such as a mass-density in the XCTS
35  * equations.
36  *
37  * This action retrieves the `System::background_fields` from the
38  * `BackgroundTag`. It invokes the `variables` function with the inertial
39  * coordinates, the element's `Mesh` and the element's inverse Jacobian. These
40  * arguments allow computing numeric derivatives, if necessary.
41  *
42  * Uses:
43  * - System:
44  * - `background_fields`
45  * - DataBox:
46  * - `BackgroundTag`
47  * - `domain::Tags::Coordinates<Dim, Frame::Inertial>`
48  *
49  * DataBox:
50  * - Adds:
51  * - `::Tags::Variables<background_fields>`
52  */
53 template <typename System, typename BackgroundTag>
55  static_assert(
56  not std::is_same_v<typename System::background_fields, tmpl::list<>>,
57  "The system has no background fields. Don't add the "
58  "'InitializeBackgroundFields' action to the action list.");
59 
60  private:
61  using background_fields_tag =
63 
64  public:
65  using simple_tags = tmpl::list<background_fields_tag>;
66  using compute_tags = tmpl::list<>;
67 
68  template <typename DbTags, typename... InboxTags, typename Metavariables,
69  size_t Dim, typename ActionList, typename ParallelComponent>
70  static std::tuple<db::DataBox<DbTags>&&> apply(
71  db::DataBox<DbTags>& box,
72  const tuples::TaggedTuple<InboxTags...>& /*inboxes*/,
73  const Parallel::GlobalCache<Metavariables>& /*cache*/,
74  const ElementId<Dim>& /*array_index*/, const ActionList /*meta*/,
75  const ParallelComponent* const /*meta*/) noexcept {
76  const auto& background = db::get<BackgroundTag>(box);
77  const auto& inertial_coords =
78  get<domain::Tags::Coordinates<Dim, Frame::Inertial>>(box);
79  const auto& mesh = get<domain::Tags::Mesh<Dim>>(box);
80  const auto& inv_jacobian = get<
82  box);
83  auto background_fields = variables_from_tagged_tuple(
84  background.variables(inertial_coords, mesh, inv_jacobian,
85  typename background_fields_tag::tags_list{}));
86  ::Initialization::mutate_assign<simple_tags>(make_not_null(&box),
87  std::move(background_fields));
88  return {std::move(box)};
89  }
90 };
91 
92 } // 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
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 >
DataBox.hpp
cstddef
elliptic::Actions::InitializeBackgroundFields
Initialize the variable-independent background fields for an elliptic solve.
Definition: InitializeBackgroundFields.hpp:54
domain::Tags::InverseJacobian< Dim, Frame::Logical, Frame::Inertial >
tuples::TaggedTuple
An associative container that is indexed by structs.
Definition: TaggedTuple.hpp:271
Variables.hpp
Gsl.hpp
Tensor.hpp
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
Parallel
Functionality for parallelization.
Definition: ElementReceiveInterpPoints.hpp:13
type_traits
TMPL.hpp