InitializeFields.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"
16 #include "Parallel/GlobalCache.hpp"
17 #include "ParallelAlgorithms/Initialization/MutateAssign.hpp"
19 #include "Utilities/TMPL.hpp"
20 
21 namespace elliptic::Actions {
22 
23 /*!
24  * \brief Initialize the dynamic fields of the elliptic system, i.e. those we
25  * solve for.
26  *
27  * Uses:
28  * - System:
29  * - `fields_tag`
30  * - DataBox:
31  * - `InitialGuessTag`
32  * - `Tags::Coordinates<Dim, Frame::Inertial>`
33  *
34  * DataBox:
35  * - Adds:
36  * - `fields_tag`
37  *
38  * \note This action relies on the `SetupDataBox` aggregated initialization
39  * mechanism, so `Actions::SetupDataBox` must be present in the `Initialization`
40  * phase action list prior to this action.
41  */
42 template <typename System, typename InitialGuessTag>
44  private:
45  using system = System;
46  using fields_tag = typename system::fields_tag;
47 
48  public:
49  using simple_tags = tmpl::list<
50  fields_tag,
52  using compute_tags = tmpl::list<>;
53 
54  template <typename DbTagsList, typename... InboxTags, typename Metavariables,
55  size_t Dim, typename ActionList, typename ParallelComponent>
56  static std::tuple<db::DataBox<DbTagsList>&&> apply(
57  db::DataBox<DbTagsList>& box,
58  const tuples::TaggedTuple<InboxTags...>& /*inboxes*/,
59  const Parallel::GlobalCache<Metavariables>& /*cache*/,
60  const ElementId<Dim>& /*array_index*/, const ActionList /*meta*/,
61  const ParallelComponent* const /*meta*/) noexcept {
62  const auto& inertial_coords =
63  get<domain::Tags::Coordinates<Dim, Frame::Inertial>>(box);
64  const auto& initial_guess = db::get<InitialGuessTag>(box);
65  auto initial_fields = variables_from_tagged_tuple(initial_guess.variables(
66  inertial_coords, typename fields_tag::tags_list{}));
67  ::Initialization::mutate_assign<tmpl::list<fields_tag>>(
68  make_not_null(&box), std::move(initial_fields));
69  // For now we assume the initial data is zero so we don't need to apply the
70  // DG operator but may just set it to zero as well. This will be replaced
71  // ASAP by applying the DG operator to the initial fields.
72  db::mutate<
74  make_not_null(&box),
75  [&inertial_coords](
76  const auto linear_operator_applied_to_fields) noexcept {
77  linear_operator_applied_to_fields->initialize(
78  inertial_coords.begin()->size(), 0.);
79  });
80  return {std::move(box)};
81  }
82 };
83 
84 } // namespace elliptic::Actions
variables_from_tagged_tuple
Variables< tmpl::list< Tags... > > variables_from_tagged_tuple(const tuples::TaggedTuple< Tags... > &tuple) noexcept
Definition: Variables.hpp:819
utility
Parallel::GlobalCache
Definition: ElementReceiveInterpPoints.hpp:15
GlobalCache.hpp
Tags.hpp
db::add_tag_prefix
typename detail::add_tag_prefix_impl< Prefix, Tag, Args... >::type add_tag_prefix
Definition: PrefixHelpers.hpp:51
std::tuple
Tags.hpp
ElementId< Dim >
db::mutate
decltype(auto) mutate(const gsl::not_null< DataBox< TagList > * > box, Invokable &&invokable, Args &&... args) noexcept
Allows changing the state of one or more non-computed elements in the DataBox.
Definition: DataBox.hpp:636
DataBox.hpp
cstddef
tuples::TaggedTuple
An associative container that is indexed by structs.
Definition: TaggedTuple.hpp:271
elliptic::Actions::InitializeFields
Initialize the dynamic fields of the elliptic system, i.e. those we solve for.
Definition: InitializeFields.hpp:43
Variables.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
Prefixes.hpp
TMPL.hpp
Mesh.hpp