Line data Source code
1 0 : // Distributed under the MIT License.
2 : // See LICENSE.txt for details.
3 :
4 : #pragma once
5 :
6 : #include <cstddef>
7 : #include <limits>
8 : #include <optional>
9 : #include <tuple>
10 : #include <utility>
11 :
12 : #include "DataStructures/DataBox/DataBox.hpp"
13 : #include "DataStructures/DataBox/PrefixHelpers.hpp"
14 : #include "NumericalAlgorithms/Convergence/HasConverged.hpp"
15 : #include "NumericalAlgorithms/Convergence/Tags.hpp"
16 : #include "Parallel/AlgorithmExecution.hpp"
17 : #include "ParallelAlgorithms/Initialization/MutateAssign.hpp"
18 : #include "ParallelAlgorithms/LinearSolver/Tags.hpp"
19 :
20 : /// \cond
21 : namespace Parallel {
22 : template <typename Metavariables>
23 : struct GlobalCache;
24 : } // namespace Parallel
25 : namespace tuples {
26 : template <typename...>
27 : class TaggedTuple;
28 : } // namespace tuples
29 : /// \endcond
30 :
31 : namespace LinearSolver::cg::detail {
32 :
33 : template <typename FieldsTag, typename OptionsGroup>
34 : struct InitializeElement {
35 : private:
36 : using fields_tag = FieldsTag;
37 : using operator_applied_to_fields_tag =
38 : db::add_tag_prefix<LinearSolver::Tags::OperatorAppliedTo, fields_tag>;
39 : using operand_tag =
40 : db::add_tag_prefix<LinearSolver::Tags::Operand, fields_tag>;
41 : using operator_applied_to_operand_tag =
42 : db::add_tag_prefix<LinearSolver::Tags::OperatorAppliedTo, operand_tag>;
43 : using residual_tag =
44 : db::add_tag_prefix<LinearSolver::Tags::Residual, fields_tag>;
45 :
46 : public:
47 : using simple_tags =
48 : tmpl::list<Convergence::Tags::IterationId<OptionsGroup>,
49 : operator_applied_to_fields_tag, operand_tag,
50 : operator_applied_to_operand_tag, residual_tag,
51 : Convergence::Tags::HasConverged<OptionsGroup>>;
52 : using compute_tags = tmpl::list<>;
53 :
54 : template <typename DbTagsList, typename... InboxTags, typename Metavariables,
55 : typename ArrayIndex, typename ActionList,
56 : typename ParallelComponent>
57 : static Parallel::iterable_action_return_t apply(
58 : db::DataBox<DbTagsList>& box,
59 : const tuples::TaggedTuple<InboxTags...>& /*inboxes*/,
60 : const Parallel::GlobalCache<Metavariables>& /*cache*/,
61 : const ArrayIndex& /*array_index*/, const ActionList /*meta*/,
62 : const ParallelComponent* const /*meta*/) {
63 : // The `PrepareSolve` action populates these tags with initial
64 : // values, except for `operator_applied_to_fields_tag` which is
65 : // expected to be filled at that point and
66 : // `operator_applied_to_operand_tag` which is expected to be updated
67 : // in every iteration of the algorithm.
68 : Initialization::mutate_assign<
69 : tmpl::list<Convergence::Tags::IterationId<OptionsGroup>>>(
70 : make_not_null(&box), std::numeric_limits<size_t>::max());
71 : return {Parallel::AlgorithmExecution::Continue, std::nullopt};
72 : }
73 : };
74 :
75 : } // namespace LinearSolver::cg::detail
|