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 "ParallelAlgorithms/Initialization/MutateAssign.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 "fixed sources" of the elliptic equations, i.e. their
31  * variable-independent source term \f$f(x)\f$
32  *
33  * This action initializes \f$f(x)\f$ in an elliptic system of PDEs \f$-div(F) +
34  * S = f(x)\f$.
35  *
36  * Uses:
37  * - System:
38  * - `fields_tag`
39  * - `primal_fields`
40  * - DataBox:
41  * - `BackgroundTag`
42  * - `Tags::Coordinates<Dim, Frame::Inertial>`
43  *
44  * DataBox:
45  * - Adds:
46  * - `db::add_tag_prefix<::Tags::FixedSource, fields_tag>`
47  *
48  * \note This action relies on the `SetupDataBox` aggregated initialization
49  * mechanism, so `Actions::SetupDataBox` must be present in the `Initialization`
50  * phase action list prior to this action.
51  */
52 template <typename System, typename BackgroundTag>
54  private:
55  using fields_tag = typename System::fields_tag;
57 
58  public:
59  using simple_tags = tmpl::list<fixed_sources_tag>;
60  using compute_tags = tmpl::list<>;
61 
62  template <typename DbTagsList, typename... InboxTags, typename Metavariables,
63  size_t Dim, typename ActionList, typename ParallelComponent>
64  static std::tuple<db::DataBox<DbTagsList>&&> apply(
65  db::DataBox<DbTagsList>& box,
66  const tuples::TaggedTuple<InboxTags...>& /*inboxes*/,
67  const Parallel::GlobalCache<Metavariables>& /*cache*/,
68  const ElementId<Dim>& /*array_index*/, const ActionList /*meta*/,
69  const ParallelComponent* const /*meta*/) noexcept {
70  const auto& inertial_coords =
71  get<domain::Tags::Coordinates<Dim, Frame::Inertial>>(box);
72  const auto& background = db::get<BackgroundTag>(box);
73 
74  // Retrieve the fixed-sources of the elliptic system from the background,
75  // which (along with the boundary conditions) define the problem we want to
76  // solve. We need only retrieve sources for the primal fields, since the
77  // auxiliary fields will never be sourced.
78  auto fixed_sources =
79  make_with_value<typename fixed_sources_tag::type>(inertial_coords, 0.);
80  fixed_sources.assign_subset(background.variables(
81  inertial_coords, db::wrap_tags_in<::Tags::FixedSource,
82  typename System::primal_fields>{}));
83 
84  ::Initialization::mutate_assign<simple_tags>(make_not_null(&box),
85  std::move(fixed_sources));
86  return {std::move(box)};
87  }
88 };
89 
90 } // namespace elliptic::Actions
utility
Parallel::GlobalCache
Definition: ElementReceiveInterpPoints.hpp:15
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
ElementId< Dim >
ElementId.hpp
Tags::FixedSource
Prefix indicating a source term that is independent of dynamic variables.
Definition: Prefixes.hpp:75
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
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:53
TMPL.hpp