SolveLinearEllipticProblem.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
6 #include <cstddef>
7 
8 #include "Domain/Creators/RegisterDerivedWithCharm.hpp"
9 #include "Domain/Tags.hpp"
10 #include "Elliptic/Actions/InitializeAnalyticSolution.hpp"
11 #include "Elliptic/Actions/InitializeSystem.hpp"
12 #include "Elliptic/DiscontinuousGalerkin/DgElementArray.hpp"
13 #include "Elliptic/DiscontinuousGalerkin/ImposeBoundaryConditions.hpp"
14 #include "Elliptic/DiscontinuousGalerkin/ImposeInhomogeneousBoundaryConditionsOnSource.hpp"
15 #include "Elliptic/DiscontinuousGalerkin/InitializeFluxes.hpp"
16 #include "Elliptic/DiscontinuousGalerkin/NumericalFluxes/FirstOrderInternalPenalty.hpp"
17 #include "Elliptic/FirstOrderOperator.hpp"
19 #include "Elliptic/Tags.hpp"
20 #include "Elliptic/Triggers/EveryNIterations.hpp"
22 #include "IO/Observer/Actions.hpp"
23 #include "IO/Observer/Helpers.hpp"
24 #include "IO/Observer/ObserverComponent.hpp"
25 #include "IO/Observer/RegisterObservers.hpp"
26 #include "NumericalAlgorithms/DiscontinuousGalerkin/Actions/ApplyFluxes.hpp"
27 #include "NumericalAlgorithms/DiscontinuousGalerkin/Actions/ComputeNonconservativeBoundaryFluxes.hpp"
29 #include "NumericalAlgorithms/DiscontinuousGalerkin/Tags.hpp"
30 #include "Options/Options.hpp"
31 #include "Parallel/Actions/TerminatePhase.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/InitializeDomain.hpp"
39 #include "ParallelAlgorithms/DiscontinuousGalerkin/InitializeInterfaces.hpp"
40 #include "ParallelAlgorithms/DiscontinuousGalerkin/InitializeMortars.hpp"
41 #include "ParallelAlgorithms/Events/ObserveErrorNorms.hpp"
42 #include "ParallelAlgorithms/Events/ObserveFields.hpp"
43 #include "ParallelAlgorithms/EventsAndTriggers/Actions/RunEventsAndTriggers.hpp"
44 #include "ParallelAlgorithms/Initialization/Actions/RemoveOptionsAndTerminatePhase.hpp"
45 #include "ParallelAlgorithms/LinearSolver/Actions/TerminateIfConverged.hpp"
46 #include "ParallelAlgorithms/LinearSolver/Gmres/Gmres.hpp"
48 #include "PointwiseFunctions/AnalyticSolutions/Poisson/Lorentzian.hpp"
49 #include "PointwiseFunctions/AnalyticSolutions/Poisson/Moustache.hpp"
50 #include "PointwiseFunctions/AnalyticSolutions/Poisson/ProductOfSinusoids.hpp"
51 #include "PointwiseFunctions/AnalyticSolutions/Tags.hpp"
52 #include "Utilities/Functional.hpp"
53 #include "Utilities/TMPL.hpp"
54 
55 /// \cond
56 template <typename System, typename InitialGuess, typename BoundaryConditions>
57 struct Metavariables {
58  using system = System;
59  static constexpr size_t volume_dim = system::volume_dim;
60  using initial_guess = InitialGuess;
61  using boundary_conditions = BoundaryConditions;
62 
63  static constexpr OptionString help{
64  "Find the solution to a linear elliptic problem.\n"
65  "Linear solver: GMRES\n"
66  "Numerical flux: FirstOrderInternalPenaltyFlux"};
67 
68  using fluxes_computer_tag =
70 
71  // Only Dirichlet boundary conditions are currently supported, and they are
72  // are all imposed by analytic solutions right now.
73  // This will be generalized ASAP. We will also support numeric initial guesses
74  // and analytic initial guesses that aren't solutions ("analytic data").
75  using analytic_solution_tag = Tags::AnalyticSolution<boundary_conditions>;
76 
77  // The linear solver algorithm. We must use GMRES since the operator is
78  // not positive-definite for the first-order system.
79  using linear_solver =
81  using temporal_id = LinearSolver::Tags::IterationId;
82 
83  // This is needed for InitializeMortars and will be removed ASAP.
84  static constexpr bool local_time_stepping = false;
85 
86  // Parse numerical flux parameters from the input file to store in the cache.
87  using normal_dot_numerical_flux = Tags::NumericalFlux<
89  volume_dim, fluxes_computer_tag, typename system::primal_variables,
90  typename system::auxiliary_variables>>;
91 
92  // Collect events and triggers
93  // (public for use by the Charm++ registration code)
94  using observe_fields =
95  db::get_variables_tags_list<typename system::fields_tag>;
96  using analytic_solution_fields = observe_fields;
97  using events = tmpl::list<
99  volume_dim, LinearSolver::Tags::IterationId, observe_fields,
100  analytic_solution_fields>,
101  dg::Events::Registrars::ObserveErrorNorms<LinearSolver::Tags::IterationId,
102  analytic_solution_fields>>;
103  using triggers = tmpl::list<elliptic::Triggers::Registrars::EveryNIterations<
104  LinearSolver::Tags::IterationId>>;
105 
106  // Collect all items to store in the cache.
107  using const_global_cache_tags =
108  tmpl::list<analytic_solution_tag, fluxes_computer_tag,
110 
111  // Collect all reduction tags for observers
112  struct element_observation_type {};
113  using observed_reduction_data_tags =
114  observers::collect_reduction_data_tags<tmpl::flatten<tmpl::list<
115  typename Event<events>::creatable_classes, linear_solver>>>;
116 
117  // Specify all global synchronization points.
118  enum class Phase { Initialization, RegisterWithObserver, Solve, Exit };
119 
120  using initialization_actions = tmpl::list<
123  elliptic::Actions::InitializeAnalyticSolution<analytic_solution_tag,
124  analytic_solution_fields>,
126  system,
128  typename system::variables_tag>,
131  Metavariables>,
132  typename linear_solver::initialize_element,
135  // Initialization is done. Avoid introducing an extra phase by
136  // advancing the linear solver to the first step here.
137  typename linear_solver::prepare_step,
139 
140  // Specify all parallel components that will execute actions at some point.
141  using component_list = tmpl::append<
142  tmpl::list<elliptic::DgElementArray<
143  Metavariables,
144  tmpl::list<
145  Parallel::PhaseActions<Phase, Phase::Initialization,
146  initialization_actions>,
147 
149  Phase, Phase::RegisterWithObserver,
152  LinearSolver::Tags::IterationId,
153  element_observation_type>>,
155 
157  Phase, Phase::Solve,
158  tmpl::list<
164  typename system::variables_tag>>,
165  elliptic::dg::Actions::
166  ImposeHomogeneousDirichletBoundaryConditions<
167  Metavariables>,
170  typename linear_solver::perform_step,
171  typename linear_solver::prepare_step>>>>>,
172  typename linear_solver::component_list,
173  tmpl::list<observers::Observer<Metavariables>,
175 
176  // Specify the transitions between phases.
177  static Phase determine_next_phase(
178  const Phase& current_phase,
179  const Parallel::CProxy_ConstGlobalCache<
180  Metavariables>& /*cache_proxy*/) noexcept {
181  switch (current_phase) {
182  case Phase::Initialization:
183  return Phase::RegisterWithObserver;
184  case Phase::RegisterWithObserver:
185  return Phase::Solve;
186  case Phase::Solve:
187  return Phase::Exit;
188  case Phase::Exit:
189  ERROR(
190  "Should never call determine_next_phase with the current phase "
191  "being 'Exit'");
192  default:
193  ERROR(
194  "Unknown type of phase. Did you static_cast<Phase> an integral "
195  "value?");
196  }
197  }
198 };
199 
200 static const std::vector<void (*)()> charm_init_node_funcs{
201  &setup_error_handling, &domain::creators::register_derived_with_charm,
202  &Parallel::register_derived_classes_with_charm<
204  &Parallel::register_derived_classes_with_charm<
206 static const std::vector<void (*)()> charm_init_proc_funcs{
208 /// \endcond
The global cache tag for the numerical flux.
Definition: Tags.hpp:85
A GMRES solver for nonsymmetric linear systems of equations .
Definition: Gmres.hpp:65
Functions for serializing factory-created classes.
Adds boundary contributions to the sources.
Definition: ImposeInhomogeneousBoundaryConditionsOnSource.hpp:72
#define ERROR(m)
prints an error message to the standard error stream and aborts the program.
Definition: Error.hpp:36
Definition: ConservativeSystem.hpp:41
Initializes the DataBox tags related to the elliptic system.
Definition: InitializeSystem.hpp:70
T system(T... args)
Contains the events and triggers.
Definition: Tags.hpp:49
Registers itself with the local observer parallel component so the observer knows to expect data from...
Definition: Actions.hpp:232
Initialize mortars between elements for exchanging fluxes.
Definition: InitializeMortars.hpp:79
Apply the function Mutator::apply to the DataBox.
Definition: MutateApply.hpp:40
Receive boundary data needed for fluxes from neighbors.
Definition: FluxCommunication.hpp:59
Defines classes and functions for making classes creatable from input files.
Defines actions SendDataForFluxes and ReceiveDataForFluxes.
The nodegroup parallel component that is responsible for writing data to disk.
Definition: ObserverComponent.hpp:48
Initialize items related to the basic structure of the element.
Definition: InitializeDomain.hpp:63
Place the analytic solution of the system fields in the DataBox.
Definition: InitializeAnalyticSolution.hpp:43
const char *const OptionString
The string used in option structs.
Definition: Options.hpp:29
Holds an IterationId that identifies a step in the linear solver algorithm.
Definition: Tags.hpp:76
void enable_floating_point_exceptions()
After a call to this function, the code will terminate with a floating point exception on overflow...
Definition: FloatingPointExceptions.cpp:27
tmpl::list< Tags... > slice_tags_to_exterior
Tags that are to be sliced to the exterior side of the faces of the element
Definition: InitializeInterfaces.hpp:37
Terminate the algorithm if the linear solver has converged.
Definition: TerminateIfConverged.hpp:32
Definition: RemoveOptionsAndTerminatePhase.hpp:27
Defines class Poisson::FirstOrderSystem.
A template for defining a registrar.
Definition: Registration.hpp:42
The parallel component responsible for managing the DG elements that compose the computational domain...
Definition: DgElementArray.hpp:36
Send local boundary data needed for fluxes to neighbors.
Definition: FluxCommunication.hpp:204
The internal penalty flux for first-order elliptic equations.
Definition: FirstOrderInternalPenalty.hpp:135
Functions to enable/disable termination on floating point exceptions.
Run the events and triggers.
Definition: RunEventsAndTriggers.hpp:27
Terminate the algorithm to proceed to the next phase.
Definition: TerminatePhase.hpp:26
Mutating DataBox invokable to compute the bulk contribution to the operator represented by the Operat...
Definition: FirstOrderOperator.hpp:201
Wraps the template metaprogramming library used (brigand)
Base class for something that can happen during a simulation (such as an observation).
Definition: Event.hpp:30
List of all the actions to be executed in the specified phase.
Definition: PhaseDependentActionList.hpp:16
Passed to RegisterWithObservers action to register observer event.
Definition: RegisterObservers.hpp:15
Defines tags related to domain quantities.
The analytic solution, with the type of the analytic solution set as the template parameter...
Definition: Tags.hpp:50
Holds an object that computes the principal part of the elliptic PDEs.
Definition: Tags.hpp:27
tmpl::list< Tags... > slice_tags_to_face
Tags that are to be sliced to the faces of the element
Definition: InitializeInterfaces.hpp:32
Compute element boundary contributions to the temporal step of the variables.
Definition: ApplyFluxes.hpp:67
Definition: ObserveFields.hpp:61
The linear operator applied to the data in Tag
Definition: Tags.hpp:63
Defines class template ConstGlobalCache.
Defines DataBox tags for the linear solver.
Base class for checking whether to run an Event.
Definition: Trigger.hpp:34
Initialize items related to the interfaces between Elements and on external boundaries.
Definition: InitializeInterfaces.hpp:140
Initialize DataBox tags related to discontinuous Galerkin fluxes.
Definition: InitializeFluxes.hpp:44