InitializeSystem.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 
13 #include "Domain/Mesh.hpp"
14 #include "Elliptic/FirstOrderComputeTags.hpp"
15 #include "Elliptic/Tags.hpp"
18 #include "ParallelAlgorithms/Initialization/MergeIntoDataBox.hpp"
20 #include "Utilities/TMPL.hpp"
21 
22 namespace elliptic {
23 namespace Actions {
24 
25 /*!
26  * \brief Initializes the DataBox tags related to the elliptic system
27  *
28  * The system fields are initially set to zero. The linear solver operand and
29  * the linear operator applied to it are also added, but initialized to
30  * undefined values.
31  *
32  * \note Currently the sources are always retrieved from an analytic solution.
33  *
34  * With:
35  * - `linear_operand_tag` = `db::add_tag_prefix<LinearSolver::Tags::Operand,
36  * fields_tag>`
37  * - `fluxes_tag` = `db::add_tag_prefix<Tags::Flux, linear_operand_tag,
38  * tmpl::size_t<Dim>, Frame::Inertial>`
39  * - `sources_tag` = `db::add_tag_prefix<Tags::Source, linear_operand_tag>`
40  *
41  * Uses:
42  * - Metavariables:
43  * - `analytic_solution_tag`
44  * - System:
45  * - `fields_tag`
46  * - `primal_fields`
47  * - `primal_variables`
48  * - `auxiliary_variables`
49  * - `fluxes`
50  * - `sources`
51  * - DataBox:
52  * - `Tags::Mesh<Dim>`
53  * - `Tags::Coordinates<Dim, Frame::Inertial>`
54  * - All items required by the added compute tags
55  *
56  * DataBox:
57  * - Uses:
58  * - `elliptic::Tags::FluxesComputer<fluxes>`
59  * - Adds:
60  * - `fields_tag`
61  * - `db::add_tag_prefix<LinearSolver::Tags::OperatorAppliedTo, fields_tag>`
62  * - `db::add_tag_prefix<::Tags::FixedSource, fields_tag>`
63  * - `linear_operand_tag`
64  * - `db::add_tag_prefix<LinearSolver::Tags::OperatorAppliedTo,
65  * linear_operand_tag>`
66  * - `fluxes_tag`
67  * - `sources_tag`
68  * - `Tags::div<fluxes_tag>`
69  */
71  template <typename DbTagsList, typename... InboxTags, typename Metavariables,
72  size_t Dim, typename ActionList, typename ParallelComponent>
73  static auto apply(db::DataBox<DbTagsList>& box,
74  const tuples::TaggedTuple<InboxTags...>& /*inboxes*/,
76  const ElementIndex<Dim>& /*array_index*/,
77  const ActionList /*meta*/,
78  const ParallelComponent* const /*meta*/) noexcept {
79  using system = typename Metavariables::system;
80  using fields_tag = typename system::fields_tag;
81  using linear_operator_applied_to_fields_tag =
83  using fixed_sources_tag =
85  using linear_operand_tag =
87  using linear_operator_applied_to_operand_tag =
89  linear_operand_tag>;
90  using fluxes_tag = db::add_tag_prefix<::Tags::Flux, linear_operand_tag,
91  tmpl::size_t<Dim>, Frame::Inertial>;
92  using inv_jacobian_tag =
95 
96  using fluxes_compute_tag =
98  using sources_compute_tag =
100 
101  using simple_tags =
102  db::AddSimpleTags<fields_tag, linear_operator_applied_to_fields_tag,
103  fixed_sources_tag, linear_operand_tag,
104  linear_operator_applied_to_operand_tag>;
105  using compute_tags =
106  db::AddComputeTags<fluxes_compute_tag, sources_compute_tag,
108 
109  const auto& mesh = db::get<::Tags::Mesh<Dim>>(box);
110  const size_t num_grid_points = mesh.number_of_grid_points();
111  const auto& inertial_coords =
112  get<::Tags::Coordinates<Dim, Frame::Inertial>>(box);
113 
114  // Set initial data to zero. Non-zero initial data would require us to also
115  // compute the linear operator applied to the the initial data.
116  db::item_type<fields_tag> fields{num_grid_points, 0.};
118  linear_operator_applied_to_fields{num_grid_points, 0.};
119 
120  // Retrieve the sources of the elliptic system from the analytic solution,
121  // which defines the problem we want to solve.
122  // We need only retrieve sources for the primal fields, since the auxiliary
123  // fields will never be sourced.
124  db::item_type<fixed_sources_tag> fixed_sources{num_grid_points, 0.};
125  fixed_sources.assign_subset(
126  Parallel::get<typename Metavariables::analytic_solution_tag>(cache)
127  .variables(inertial_coords,
129  typename system::primal_fields>{}));
130 
131  // Initialize the variables for the elliptic solve. Their initial value is
132  // determined by the linear solver. The value is also updated by the linear
133  // solver in every step.
134  db::item_type<linear_operand_tag> linear_operand{num_grid_points};
135 
136  // Initialize the linear operator applied to the variables. It needs no
137  // initial value, but is computed in every step of the elliptic solve.
139  linear_operator_applied_to_operand{num_grid_points};
140 
141  return std::make_tuple(
143  compute_tags>(
144  std::move(box), std::move(fields),
145  std::move(linear_operator_applied_to_fields),
146  std::move(fixed_sources), std::move(linear_operand),
147  std::move(linear_operator_applied_to_operand)));
148  }
149 };
150 
151 } // namespace Actions
152 } // namespace elliptic
Prefix< DataBox_detail::dispatch_add_tag_prefix_impl< Prefix, Tag, Args... >, Args... > add_tag_prefix
Wrap Tag in Prefix<_, Args...>, also wrapping variables tags if Tag is a Tags::Variables.
Definition: DataBoxTag.hpp:616
Initializes the DataBox tags related to the elliptic system.
Definition: InitializeSystem.hpp:70
Definition: InitializeAnalyticSolution.hpp:27
Define prefixes for DataBox tags.
tmpl::transform< TagList, tmpl::bind< Wrapper, tmpl::_1, tmpl::pin< Args >... > > wrap_tags_in
Create a new list of Tags by wrapping each tag in TagList using the Wrapper.
Definition: DataBoxTag.hpp:501
Definition: FirstOrderComputeTags.hpp:68
auto merge_into_databox(db::DataBox< DbTagsList > &&box, Args &&... args) noexcept
Add tags that are not yet in the DataBox.
Definition: MergeIntoDataBox.hpp:132
Computes the inverse Jacobian of the map held by MapTag at the coordinates held by SourceCoordsTag...
Definition: Tags.hpp:168
An associative container that is indexed by structs.
Definition: TaggedTuple.hpp:273
Defines classes and functions used for manipulating DataBox&#39;s.
Definition: FirstOrderComputeTags.hpp:24
tmpl::flatten< tmpl::list< Tags... > > AddSimpleTags
List of Tags to add to the DataBox.
Definition: DataBox.hpp:1227
Prefix indicating a flux.
Definition: Prefixes.hpp:54
Definition: InterpolationTargetWedgeSectionTorus.hpp:24
Defines class Variables.
A Charm++ chare that caches constant data once per Charm++ node.
Definition: ConstGlobalCache.hpp:135
Defines the class template Mesh.
The coordinates in a given frame.
Definition: Tags.hpp:138
Wraps the template metaprogramming library used (brigand)
typename DataBox_detail::item_type_impl< TagList, Tag >::type item_type
Get the type that can be written to the Tag. If it is a base tag then a TagList must be passed as a s...
Definition: DataBoxTag.hpp:461
Definition: IndexType.hpp:44
The linear operator applied to the data in Tag
Definition: Tags.hpp:63
A class for indexing a Charm array by Element.
Definition: ElementIndex.hpp:53
Defines classes SimpleTag, PrefixTag, ComputeTag and several functions for retrieving tag info...
Defines class template ConstGlobalCache.
Compute the divergence of a Variables.
Definition: Divergence.hpp:81
Defines DataBox tags for the linear solver.
Prefix indicating a source term that is independent of dynamic variables.
Definition: Prefixes.hpp:98
Defines functions and tags for taking a divergence.
Definition: ComputeTimeDerivative.hpp:28
tmpl::flatten< tmpl::list< Tags... > > AddComputeTags
List of Compute Item Tags to add to the DataBox.
Definition: DataBox.hpp:1248