1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
4 #pragma once
11 #include "Parallel/Info.hpp"
12 #include "Parallel/Invoke.hpp"
13 #include "Parallel/Reduction.hpp"
16 /// \cond
17 namespace tuples {
18 template <typename...>
19 class TaggedTuple;
20 } // namespace tuples
21 namespace LinearSolver {
22 namespace cg_detail {
23 template <typename Metavariables>
24 struct ResidualMonitor;
25 template <typename BroadcastTarget>
26 struct InitializeResidual;
27 } // namespace cg_detail
28 } // namespace LinearSolver
29 /// \endcond
31 namespace LinearSolver {
32 namespace cg_detail {
34 template <typename Metavariables>
35 struct InitializeElement {
36  private:
37  using fields_tag = typename Metavariables::system::fields_tag;
38  using operand_tag =
40  using residual_tag =
43  public:
44  using simple_tags =
47  residual_tag, LinearSolver::Tags::HasConverged>;
48  using compute_tags = db::AddComputeTags<>;
50  template <typename TagsList, typename ArrayIndex, typename ParallelComponent>
51  static auto initialize(
54  const ArrayIndex& array_index, const ParallelComponent* const /*meta*/,
57  LinearSolver::Tags::OperatorAppliedTo, fields_tag>>& Ax) noexcept {
58  LinearSolver::IterationId iteration_id{0};
59  LinearSolver::IterationId next_iteration_id{1};
61  db::mutate<operand_tag>(make_not_null(&box), [
62  &b, &Ax
63  ](const gsl::not_null<db::item_type<operand_tag>*> p) noexcept {
64  *p = b - Ax;
65  });
66  auto r = db::item_type<residual_tag>(get<operand_tag>(box));
68  // Perform global reduction to compute initial residual magnitude square for
69  // residual monitor
71  cg_detail::InitializeResidual<ParallelComponent>>(
72  Parallel::ReductionData<
74  inner_product(r, r)},
75  Parallel::get_parallel_component<ParallelComponent>(cache)[array_index],
76  Parallel::get_parallel_component<ResidualMonitor<Metavariables>>(
77  cache));
79  return db::create_from<db::RemoveTags<>, simple_tags, compute_tags>(
80  std::move(box), iteration_id, next_iteration_id, std::move(r),
82  }
83 };
85 } // namespace cg_detail
86 } // namespace LinearSolver
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:533
Definition: Variables.hpp:46
Defines functions for interfacing with the parallelization framework.
Defines DataBox tags for the linear solver.
Functionality for solving linear systems of equations.
Definition: TerminateIfConverged.hpp:22
Definition: TaggedTuple.hpp:25
Define prefixes for DataBox tags.
Holds a LinearSolver::HasConverged flag that signals the linear solver has converged, along with the reason for convergence.
Definition: Tags.hpp:204
void contribute_to_reduction(ReductionData< Ts... > reduction_data, const SenderProxy &sender_component, const TargetProxy &target_component) noexcept
Perform a reduction from the sender_component (typically your own parallel component) to the target_c...
Definition: Reduction.hpp:243
Holds an IterationId that identifies a step in the linear solver algorithm.
Definition: Tags.hpp:66
Defines classes and functions used for manipulating DataBox&#39;s.
tmpl::flatten< tmpl::list< Tags... > > AddSimpleTags
List of Tags to add to the DataBox.
Definition: DataBox.hpp:1227
Definition: InterpolationTargetWedgeSectionTorus.hpp:24
double inner_product(const Lhs &lhs, const Rhs &rhs) noexcept
The local part of the Euclidean inner product on the vector space w.r.t. which the addition and scala...
Definition: InnerProduct.hpp:71
A Charm++ chare that caches constant data once per Charm++ node.
Definition: ConstGlobalCache.hpp:76
auto get_parallel_component(ConstGlobalCache< Metavariables > &cache) noexcept -> Parallel::proxy_from_parallel_component< ConstGlobalCache_detail::get_component_if_mocked< typename Metavariables::component_list, ParallelComponentTag >> &
Access the Charm++ proxy associated with a ParallelComponent.
Definition: ConstGlobalCache.hpp:163
Prefix indicating the value a quantity will take on the next iteration of the algorithm.
Definition: Prefixes.hpp:98
typename DataBox_detail::item_type_impl< TagList, Tag >::type item_type
Get the type that is returned by the Tag. If it is a base tag then a TagList must be passed as a seco...
Definition: DataBoxTag.hpp:410
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, but it may be necessary to perform the conversion explicitly when type deduction is desired.
Definition: Gsl.hpp:863
The linear operator applied to the data in Tag
Definition: Tags.hpp:53
Identifies a step in the linear solver algorithm.
Definition: IterationId.hpp:25
Defines class template ConstGlobalCache.
The data to be reduced, and invokables to be called whenever two reduction messages are combined and ...
Definition: Reduction.hpp:64
Require a pointer to not be a nullptr
Definition: ConservativeFromPrimitive.hpp:12
Defines make_with_value.
Defines class IterationId.
tmpl::flatten< tmpl::list< Tags... > > AddComputeTags
List of Compute Item Tags to add to the DataBox.
Definition: DataBox.hpp:1234