SolvePoisson.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
6 #include <cstddef>
7 
8 #include "DataStructures/DataBox/PrefixHelpers.hpp"
9 #include "Domain/Creators/RegisterDerivedWithCharm.hpp"
10 #include "Domain/Tags.hpp"
11 #include "Elliptic/Actions/InitializeAnalyticSolution.hpp"
12 #include "Elliptic/Actions/InitializeFields.hpp"
13 #include "Elliptic/Actions/InitializeFixedSources.hpp"
14 #include "Elliptic/DiscontinuousGalerkin/DgElementArray.hpp"
15 #include "Elliptic/DiscontinuousGalerkin/ImposeBoundaryConditions.hpp"
16 #include "Elliptic/DiscontinuousGalerkin/ImposeInhomogeneousBoundaryConditionsOnSource.hpp"
17 #include "Elliptic/DiscontinuousGalerkin/InitializeFirstOrderOperator.hpp"
18 #include "Elliptic/DiscontinuousGalerkin/NumericalFluxes/FirstOrderInternalPenalty.hpp"
19 #include "Elliptic/FirstOrderOperator.hpp"
21 #include "Elliptic/Tags.hpp"
22 #include "Elliptic/Triggers/EveryNIterations.hpp"
23 #include "IO/Observer/Actions/RegisterEvents.hpp"
24 #include "IO/Observer/Helpers.hpp"
25 #include "IO/Observer/ObserverComponent.hpp"
26 #include "NumericalAlgorithms/Convergence/Tags.hpp"
27 #include "NumericalAlgorithms/DiscontinuousGalerkin/BoundarySchemes/FirstOrder/FirstOrderScheme.hpp"
28 #include "NumericalAlgorithms/DiscontinuousGalerkin/Tags.hpp"
29 #include "Options/Options.hpp"
30 #include "Parallel/Actions/SetupDataBox.hpp"
31 #include "Parallel/Actions/TerminatePhase.hpp"
32 #include "Parallel/GlobalCache.hpp"
33 #include "Parallel/InitializationFunctions.hpp"
34 #include "Parallel/PhaseDependentActionList.hpp"
35 #include "Parallel/Reduction.hpp"
37 #include "ParallelAlgorithms/Actions/MutateApply.hpp"
38 #include "ParallelAlgorithms/DiscontinuousGalerkin/CollectDataForFluxes.hpp"
39 #include "ParallelAlgorithms/DiscontinuousGalerkin/FluxCommunication.hpp"
40 #include "ParallelAlgorithms/DiscontinuousGalerkin/InitializeDomain.hpp"
41 #include "ParallelAlgorithms/DiscontinuousGalerkin/InitializeInterfaces.hpp"
42 #include "ParallelAlgorithms/DiscontinuousGalerkin/InitializeMortars.hpp"
43 #include "ParallelAlgorithms/Events/ObserveErrorNorms.hpp"
44 #include "ParallelAlgorithms/Events/ObserveFields.hpp"
45 #include "ParallelAlgorithms/EventsAndTriggers/Actions/RunEventsAndTriggers.hpp"
46 #include "ParallelAlgorithms/Initialization/Actions/RemoveOptionsAndTerminatePhase.hpp"
47 #include "ParallelAlgorithms/LinearSolver/Gmres/Gmres.hpp"
49 #include "PointwiseFunctions/AnalyticData/AnalyticData.hpp"
50 #include "PointwiseFunctions/AnalyticSolutions/Poisson/AnalyticSolution.hpp"
51 #include "PointwiseFunctions/AnalyticSolutions/Poisson/Lorentzian.hpp"
52 #include "PointwiseFunctions/AnalyticSolutions/Poisson/Moustache.hpp"
53 #include "PointwiseFunctions/AnalyticSolutions/Poisson/ProductOfSinusoids.hpp"
54 #include "PointwiseFunctions/AnalyticSolutions/Poisson/Zero.hpp"
55 #include "PointwiseFunctions/AnalyticSolutions/Tags.hpp"
56 #include "Utilities/Blas.hpp"
58 #include "Utilities/Functional.hpp"
59 #include "Utilities/TMPL.hpp"
60 
61 namespace SolvePoisson::OptionTags {
63  static std::string name() noexcept { return "LinearSolver"; }
64  static constexpr Options::String help =
65  "The iterative Krylov-subspace linear solver";
66 };
67 struct GmresGroup {
68  static std::string name() noexcept { return "GMRES"; }
69  static constexpr Options::String help = "Options for the GMRES linear solver";
70  using group = LinearSolverGroup;
71 };
72 } // namespace SolvePoisson::OptionTags
73 
74 /// \cond
75 template <size_t Dim>
76 struct Metavariables {
77  static constexpr size_t volume_dim = Dim;
78  using system =
80 
81  // List the possible backgrounds, i.e. the variable-independent part of the
82  // equations that define the problem to solve (along with the boundary
83  // conditions). We'll probably always have an analytic solution for Poisson
84  // problems, so we don't bother supporting non-solution backgrounds for now.
85  using analytic_solution_registrars = tmpl::flatten<tmpl::list<
86  Poisson::Solutions::Registrars::ProductOfSinusoids<Dim>,
87  tmpl::conditional_t<Dim == 1 or Dim == 2,
88  Poisson::Solutions::Registrars::Moustache<Dim>,
89  tmpl::list<>>,
90  tmpl::conditional_t<Dim == 3,
91  Poisson::Solutions::Registrars::Lorentzian<Dim>,
92  tmpl::list<>>>>;
93  using analytic_solution_tag = elliptic::Tags::Background<
95 
96  // List the possible initial guesses. We currently only support the trivial
97  // "zero" initial guess. This will be generalized ASAP.
98  using initial_guess_registrars =
99  tmpl::list<Poisson::Solutions::Registrars::Zero<Dim>>;
100  using initial_guess_tag = elliptic::Tags::InitialGuess<
102 
103  static constexpr Options::String help{
104  "Find the solution to a Poisson problem."};
105 
106  using fluxes_computer_tag =
108 
109  // The linear solver algorithm. We must use GMRES since the operator is
110  // not positive-definite for the first-order system.
111  using linear_solver =
112  LinearSolver::gmres::Gmres<Metavariables, typename system::fields_tag,
114  false>;
115  using linear_solver_iteration_id =
117  // For the GMRES linear solver we need to apply the DG operator to its
118  // internal "operand" in every iteration of the algorithm.
119  using linear_operand_tag = db::add_tag_prefix<LinearSolver::Tags::Operand,
120  typename system::fields_tag>;
121  using primal_variables = db::wrap_tags_in<LinearSolver::Tags::Operand,
122  typename system::primal_fields>;
123  using auxiliary_variables =
125  typename system::auxiliary_fields>;
126 
127  // Parse numerical flux parameters from the input file to store in the cache.
128  using normal_dot_numerical_flux = Tags::NumericalFlux<
130  volume_dim, fluxes_computer_tag, primal_variables,
131  auxiliary_variables>>;
132  // Specify the DG boundary scheme. We use the strong first-order scheme here
133  // that only requires us to compute normals dotted into the first-order
134  // fluxes.
135  using boundary_scheme = dg::FirstOrderScheme::FirstOrderScheme<
136  volume_dim, linear_operand_tag,
138  linear_operand_tag>,
139  normal_dot_numerical_flux, linear_solver_iteration_id>;
140 
141  // Collect events and triggers
142  // (public for use by the Charm++ registration code)
143  using observe_fields = typename system::fields_tag::tags_list;
144  using analytic_solution_fields = observe_fields;
145  using events =
147  volume_dim, linear_solver_iteration_id, observe_fields,
148  analytic_solution_fields>,
150  linear_solver_iteration_id, analytic_solution_fields>>;
151  using triggers = tmpl::list<elliptic::Triggers::Registrars::EveryNIterations<
152  linear_solver_iteration_id>>;
153 
154  // Collect all items to store in the cache.
155  using const_global_cache_tags =
156  tmpl::list<analytic_solution_tag, initial_guess_tag, fluxes_computer_tag,
157  normal_dot_numerical_flux,
159 
160  // Collect all reduction tags for observers
161  using observed_reduction_data_tags =
162  observers::collect_reduction_data_tags<tmpl::flatten<tmpl::list<
163  typename Event<events>::creatable_classes, linear_solver>>>;
164 
165  // Specify all global synchronization points.
166  enum class Phase { Initialization, RegisterWithObserver, Solve, Exit };
167 
168  using initialization_actions = tmpl::list<
175  typename linear_solver::initialize_element,
178  elliptic::Actions::InitializeAnalyticSolution<analytic_solution_tag,
179  analytic_solution_fields>,
181  Metavariables>,
184  volume_dim, typename system::fluxes_computer,
185  typename system::sources_computer, linear_operand_tag,
186  primal_variables, auxiliary_variables>,
188 
189  using build_linear_operator_actions = tmpl::list<
195  linear_operand_tag>>,
197  linear_operand_tag, primal_variables>,
199  boundary_scheme,
203 
204  using register_actions =
207 
208  using solve_actions = tmpl::list<
209  typename linear_solver::template solve<tmpl::list<
210  Actions::RunEventsAndTriggers, build_linear_operator_actions>>,
212 
213  using dg_element_array = elliptic::DgElementArray<
214  Metavariables,
215  tmpl::list<Parallel::PhaseActions<Phase, Phase::Initialization,
216  initialization_actions>,
217  Parallel::PhaseActions<Phase, Phase::RegisterWithObserver,
218  register_actions>,
220 
221  // Specify all parallel components that will execute actions at some point.
222  using component_list = tmpl::flatten<
223  tmpl::list<dg_element_array, typename linear_solver::component_list,
226 
227  // Specify the transitions between phases.
228  template <typename... Tags>
229  static Phase determine_next_phase(
230  const gsl::not_null<
231  tuples::TaggedTuple<Tags...>*> /*phase_change_decision_data*/,
232  const Phase& current_phase,
233  const Parallel::CProxy_GlobalCache<
234  Metavariables>& /*cache_proxy*/) noexcept {
235  switch (current_phase) {
236  case Phase::Initialization:
237  return Phase::RegisterWithObserver;
238  case Phase::RegisterWithObserver:
239  return Phase::Solve;
240  case Phase::Solve:
241  return Phase::Exit;
242  case Phase::Exit:
243  ERROR(
244  "Should never call determine_next_phase with the current phase "
245  "being 'Exit'");
246  default:
247  ERROR(
248  "Unknown type of phase. Did you static_cast<Phase> an integral "
249  "value?");
250  }
251  }
252 };
253 
254 static const std::vector<void (*)()> charm_init_node_funcs{
255  &setup_error_handling,
257  &domain::creators::register_derived_with_charm,
259  metavariables::analytic_solution_tag::type::element_type>,
261  metavariables::initial_guess_tag::type::element_type>,
263  metavariables::system::boundary_conditions_base>,
268 static const std::vector<void (*)()> charm_init_proc_funcs{
270 /// \endcond
FloatingPointExceptions.hpp
RegisterDerivedClassesWithCharm.hpp
Actions::SetupDataBox
Add into the DataBox default constructed items for the collection of tags requested by any of the act...
Definition: SetupDataBox.hpp:102
LinearSolver::gmres::Gmres
A GMRES solver for nonsymmetric linear systems of equations .
Definition: Gmres.hpp:87
std::string
SolvePoisson::OptionTags::GmresGroup
Definition: SolvePoisson.hpp:67
observers::Actions::RegisterEventsWithObservers
Registers this element of a parallel component with the local Observer parallel component for each tr...
Definition: RegisterEvents.hpp:97
elliptic::dg::Actions::ImposeInhomogeneousBoundaryConditionsOnSource
Adds boundary contributions to the sources.
Definition: ImposeInhomogeneousBoundaryConditionsOnSource.hpp:71
LinearSolver::Tags::OperatorAppliedTo
The linear operator applied to the data in Tag
Definition: Tags.hpp:54
GlobalCache.hpp
Options.hpp
LinearSolver::Tags::Operand
The operand that the local linear operator is applied to.
Definition: Tags.hpp:41
Tags.hpp
std::vector
std::system
T system(T... args)
elliptic::Actions::InitializeAnalyticSolution
Place the analytic solution of the system fields in the DataBox.
Definition: InitializeAnalyticSolution.hpp:58
db::add_tag_prefix
typename detail::add_tag_prefix_impl< Prefix, Tag, Args... >::type add_tag_prefix
Definition: PrefixHelpers.hpp:51
dg::Actions::SendDataForFluxes
Send local boundary data needed for fluxes to neighbors.
Definition: FluxCommunication.hpp:78
Initialization::Actions::RemoveOptionsAndTerminatePhase
Definition: RemoveOptionsAndTerminatePhase.hpp:27
dg::Initialization::face_compute_tags
tmpl::list< Tags... > face_compute_tags
Definition: InitializeInterfaces.hpp:41
Parallel::Actions::TerminatePhase
Terminate the algorithm to proceed to the next phase.
Definition: TerminatePhase.hpp:26
Tags::NumericalFlux
The global cache tag for the numerical flux.
Definition: Tags.hpp:84
elliptic::Tags::Background
The variable-independent part of the elliptic equations, e.g. the fixed-sources in a Poisson equatio...
Definition: Tags.hpp:69
SolvePoisson::OptionTags::LinearSolverGroup
Definition: SolvePoisson.hpp:62
dg::Initialization::slice_tags_to_face
tmpl::list< Tags... > slice_tags_to_face
Definition: InitializeInterfaces.hpp:31
disable_openblas_multithreading
void disable_openblas_multithreading() noexcept
Disable OpenBLAS multithreading since it conflicts with Charm++ parallelism.
Definition: Blas.cpp:15
domain::Tags::BoundaryDirectionsInterior
Definition: Tags.hpp:296
Tags.hpp
Registration::Registrar
A template for defining a registrar.
Definition: Registration.hpp:42
elliptic::FirstOrderOperator
Mutating DataBox invokable to compute the bulk contribution to the operator represented by the Operat...
Definition: FirstOrderOperator.hpp:224
enable_floating_point_exceptions
void enable_floating_point_exceptions()
Definition: FloatingPointExceptions.cpp:27
Poisson::FirstOrderSystem
The Poisson equation formulated as a set of coupled first-order PDEs.
Definition: FirstOrderSystem.hpp:78
ERROR
#define ERROR(m)
prints an error message to the standard error stream and aborts the program.
Definition: Error.hpp:36
Parallel::PhaseActions
List of all the actions to be executed in the specified phase.
Definition: PhaseDependentActionList.hpp:16
observers::ObserverWriter
The nodegroup parallel component that is responsible for writing data to disk.
Definition: ObserverComponent.hpp:51
FirstOrderSystem.hpp
dg::Actions::InitializeInterfaces
Initialize items related to the interfaces between Elements and on external boundaries.
Definition: InitializeInterfaces.hpp:120
Event
Definition: Event.hpp:30
elliptic::DgElementArray
The parallel component responsible for managing the DG elements that compose the computational domain...
Definition: DgElementArray.hpp:37
dg::Actions::InitializeDomain
Initialize items related to the basic structure of the element.
Definition: InitializeDomain.hpp:67
cstddef
Actions::RunEventsAndTriggers
Run the events and triggers.
Definition: RunEventsAndTriggers.hpp:27
Actions::MutateApply
Apply the function Mutator::apply to the DataBox.
Definition: MutateApply.hpp:40
elliptic::Tags::FluxesComputer
Holds an object that computes the principal part of the elliptic PDEs.
Definition: Tags.hpp:52
tuples::TaggedTuple< Tags... >
observers::Observer
The group parallel component that is responsible for reducing data to be observed.
Definition: ObserverComponent.hpp:29
Trigger
Definition: Trigger.hpp:34
Poisson::Solutions::AnalyticSolution
Base class for analytic solutions of the Poisson equation.
Definition: AnalyticSolution.hpp:32
dg::Actions::InitializeMortars
Initialize mortars between elements for exchanging fluxes.
Definition: InitializeMortars.hpp:78
dg::Actions::CollectDataForFluxes
Collect data that is needed to compute numerical fluxes and store it on mortars, projecting it if nec...
Definition: CollectDataForFluxes.hpp:68
dg::Events::Registrars::ObserveFields
Definition: ObserveFields.hpp:68
elliptic::dg::NumericalFluxes::FirstOrderInternalPenalty
The internal penalty flux for first-order elliptic equations.
Definition: FirstOrderInternalPenalty.hpp:147
AnalyticData
Provides analytic tensor data as a function of the spatial coordinates.
Definition: AnalyticData.hpp:30
elliptic::Actions::InitializeFields
Initialize the dynamic fields of the elliptic system, i.e. those we solve for.
Definition: InitializeFields.hpp:43
Convergence::Tags::IterationId
Identifies a step in an iterative algorithm.
Definition: Tags.hpp:74
Tags::EventsAndTriggers
Definition: Tags.hpp:57
dg::Initialization::exterior_compute_tags
tmpl::list< Tags... > exterior_compute_tags
Definition: InitializeInterfaces.hpp:46
Options::String
const char *const String
The string used in option structs.
Definition: Options.hpp:32
dg::FirstOrderScheme::FirstOrderScheme
Boundary contributions for a first-order DG scheme.
Definition: FirstOrderScheme.hpp:66
domain::Tags::InternalDirections
Definition: Tags.hpp:269
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
elliptic::Tags::InitialGuess
The initial guess for the elliptic solve.
Definition: Tags.hpp:81
Parallel::register_derived_classes_with_charm
void register_derived_classes_with_charm() noexcept
Register derived classes of the Base class.
Definition: RegisterDerivedClassesWithCharm.hpp:31
Blas.hpp
elliptic::dg::Actions::ImposeHomogeneousDirichletBoundaryConditions
Set field data on external boundaries so that they represent homogeneous (zero) Dirichlet boundary co...
Definition: ImposeBoundaryConditions.hpp:91
elliptic::dg::Actions::InitializeFirstOrderOperator
Initialize DataBox tags for building the first-order elliptic DG operator.
Definition: InitializeFirstOrderOperator.hpp:49
dg::Actions::ReceiveDataForFluxes
Receive boundary data needed for fluxes from neighbors.
Definition: FluxCommunication.hpp:175
elliptic::Actions::InitializeFixedSources
Initialize the "fixed sources" of the elliptic equations, i.e. their variable-independent source term...
Definition: InitializeFixedSources.hpp:53
TMPL.hpp
gsl::not_null
Require a pointer to not be a nullptr
Definition: ReadSpecThirdOrderPiecewisePolynomial.hpp:13
dg::Initialization::slice_tags_to_exterior
tmpl::list< Tags... > slice_tags_to_exterior
Definition: InitializeInterfaces.hpp:36