EvolveValencia.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
6 #include <cstddef>
7 #include <cstdint>
8 #include <vector>
9 
10 #include "Domain/Creators/RegisterDerivedWithCharm.hpp"
11 #include "Domain/Creators/TimeDependence/RegisterDerivedWithCharm.hpp"
12 #include "Domain/FunctionsOfTime/RegisterDerivedWithCharm.hpp"
13 #include "Domain/Tags.hpp"
14 #include "Evolution/ComputeTags.hpp"
15 #include "Evolution/Conservative/UpdateConservatives.hpp"
16 #include "Evolution/DiscontinuousGalerkin/Actions/ApplyBoundaryCorrections.hpp"
17 #include "Evolution/DiscontinuousGalerkin/Actions/ComputeTimeDerivative.hpp"
18 #include "Evolution/DiscontinuousGalerkin/DgElementArray.hpp"
19 #include "Evolution/DiscontinuousGalerkin/Initialization/Mortars.hpp"
20 #include "Evolution/DiscontinuousGalerkin/Initialization/QuadratureTag.hpp"
22 #include "Evolution/DiscontinuousGalerkin/Limiters/Minmod.hpp"
23 #include "Evolution/DiscontinuousGalerkin/Limiters/Tags.hpp"
24 #include "Evolution/Initialization/ConservativeSystem.hpp"
25 #include "Evolution/Initialization/DgDomain.hpp"
26 #include "Evolution/Initialization/DiscontinuousGalerkin.hpp"
27 #include "Evolution/Initialization/Evolution.hpp"
28 #include "Evolution/Initialization/GrTagsForHydro.hpp"
29 #include "Evolution/Initialization/Limiter.hpp"
30 #include "Evolution/Initialization/SetVariables.hpp"
31 #include "Evolution/Systems/RelativisticEuler/Valencia/BoundaryConditions/Factory.hpp"
32 #include "Evolution/Systems/RelativisticEuler/Valencia/BoundaryConditions/RegisterDerivedWithCharm.hpp"
33 #include "Evolution/Systems/RelativisticEuler/Valencia/BoundaryCorrections/Factory.hpp"
34 #include "Evolution/Systems/RelativisticEuler/Valencia/BoundaryCorrections/RegisterDerived.hpp"
35 #include "Evolution/Systems/RelativisticEuler/Valencia/FixConservatives.hpp"
36 #include "Evolution/Systems/RelativisticEuler/Valencia/System.hpp"
37 #include "Evolution/Systems/RelativisticEuler/Valencia/Tags.hpp"
38 #include "Evolution/VariableFixing/Actions.hpp"
39 #include "Evolution/VariableFixing/FixToAtmosphere.hpp"
40 #include "Evolution/VariableFixing/Tags.hpp"
41 #include "IO/Observer/Actions/RegisterEvents.hpp"
42 #include "IO/Observer/Helpers.hpp"
43 #include "IO/Observer/ObserverComponent.hpp"
44 #include "NumericalAlgorithms/DiscontinuousGalerkin/Formulation.hpp"
45 #include "NumericalAlgorithms/DiscontinuousGalerkin/Tags.hpp"
46 #include "Options/Options.hpp"
47 #include "Options/Protocols/FactoryCreation.hpp"
48 #include "Parallel/Actions/SetupDataBox.hpp"
49 #include "Parallel/Actions/TerminatePhase.hpp"
50 #include "Parallel/InitializationFunctions.hpp"
51 #include "Parallel/PhaseControl/ExecutePhaseChange.hpp"
52 #include "Parallel/PhaseControl/PhaseControlTags.hpp"
53 #include "Parallel/PhaseControl/VisitAndReturn.hpp"
54 #include "Parallel/PhaseDependentActionList.hpp"
56 #include "ParallelAlgorithms/Actions/MutateApply.hpp"
57 #include "ParallelAlgorithms/DiscontinuousGalerkin/InitializeDomain.hpp"
58 #include "ParallelAlgorithms/Events/ObserveErrorNorms.hpp"
59 #include "ParallelAlgorithms/Events/ObserveFields.hpp"
60 #include "ParallelAlgorithms/Events/ObserveTimeStep.hpp"
61 #include "ParallelAlgorithms/EventsAndTriggers/Actions/RunEventsAndTriggers.hpp"
62 #include "ParallelAlgorithms/EventsAndTriggers/Event.hpp"
63 #include "ParallelAlgorithms/EventsAndTriggers/EventsAndTriggers.hpp"
65 #include "ParallelAlgorithms/Initialization/Actions/AddComputeTags.hpp"
66 #include "ParallelAlgorithms/Initialization/Actions/RemoveOptionsAndTerminatePhase.hpp"
67 #include "PointwiseFunctions/AnalyticSolutions/RelativisticEuler/SmoothFlow.hpp"
68 #include "PointwiseFunctions/AnalyticSolutions/Tags.hpp"
69 #include "PointwiseFunctions/Hydro/SoundSpeedSquared.hpp"
70 #include "PointwiseFunctions/Hydro/Tags.hpp"
72 #include "Time/Actions/ChangeSlabSize.hpp"
73 #include "Time/Actions/ChangeStepSize.hpp"
74 #include "Time/Actions/RecordTimeStepperData.hpp"
75 #include "Time/Actions/SelfStartActions.hpp"
76 #include "Time/Actions/UpdateU.hpp"
77 #include "Time/StepChoosers/Cfl.hpp"
78 #include "Time/StepChoosers/Constant.hpp"
79 #include "Time/StepChoosers/Increase.hpp"
80 #include "Time/StepChoosers/PreventRapidIncrease.hpp"
81 #include "Time/StepChoosers/StepChooser.hpp"
82 #include "Time/StepChoosers/StepToTimes.hpp"
83 #include "Time/StepControllers/Factory.hpp"
85 #include "Time/Tags.hpp"
86 #include "Time/TimeSequence.hpp"
87 #include "Time/TimeSteppers/TimeStepper.hpp"
88 #include "Time/Triggers/TimeTriggers.hpp"
89 #include "Utilities/Blas.hpp"
91 #include "Utilities/Functional.hpp"
92 #include "Utilities/ProtocolHelpers.hpp"
93 #include "Utilities/TMPL.hpp"
94 
95 /// \cond
96 namespace Frame {
97 struct Inertial;
98 } // namespace Frame
99 namespace PUP {
100 class er;
101 } // namespace PUP
102 namespace Parallel {
103 template <typename Metavariables>
104 class CProxy_GlobalCache;
105 } // namespace Parallel
106 /// \endcond
107 
108 template <size_t Dim, typename InitialData>
109 struct EvolutionMetavars {
110  static constexpr size_t volume_dim = Dim;
111  static constexpr dg::Formulation dg_formulation =
112  dg::Formulation::StrongInertial;
113 
114  using initial_data = InitialData;
115  static_assert(
116  evolution::is_analytic_data_v<initial_data> xor
117  evolution::is_analytic_solution_v<initial_data>,
118  "initial_data must be either an analytic_data or an analytic_solution");
119 
120  using equation_of_state_type = typename initial_data::equation_of_state_type;
121 
122  using system =
124 
125  static constexpr size_t thermodynamic_dim = system::thermodynamic_dim;
126 
127  using temporal_id = Tags::TimeStepId;
128  static constexpr bool local_time_stepping = false;
129 
130  using initial_data_tag =
131  tmpl::conditional_t<evolution::is_analytic_solution_v<initial_data>,
134 
135  using boundary_condition_tag = initial_data_tag;
136  using analytic_variables_tags =
137  typename system::primitive_variables_tag::tags_list;
138 
139  using equation_of_state_tag =
141 
142  using limiter = Tags::Limiter<Limiters::Minmod<
146 
147  using step_choosers_common = tmpl::list<
148  // StepChoosers::Registrars::Cfl<volume_dim, Frame::Inertial, system>,
150  using step_choosers_for_step_only =
151  tmpl::list<StepChoosers::Registrars::PreventRapidIncrease>;
152  using step_choosers_for_slab_only =
153  tmpl::list<StepChoosers::Registrars::StepToTimes>;
154  using step_choosers = tmpl::conditional_t<
155  local_time_stepping,
156  tmpl::append<step_choosers_common, step_choosers_for_step_only>,
157  tmpl::list<>>;
158  using slab_choosers = tmpl::conditional_t<
159  local_time_stepping,
160  tmpl::append<step_choosers_common, step_choosers_for_slab_only>,
161  tmpl::append<step_choosers_common, step_choosers_for_step_only,
162  step_choosers_for_slab_only>>;
163 
164  using time_stepper_tag = Tags::TimeStepper<
165  tmpl::conditional_t<local_time_stepping, LtsTimeStepper, TimeStepper>>;
166 
167  using events = tmpl::list<
168  tmpl::conditional_t<evolution::is_analytic_solution_v<initial_data>,
170  Tags::Time, analytic_variables_tags>,
171  tmpl::list<>>,
173  Dim, Tags::Time,
174  tmpl::append<typename system::variables_tag::tags_list,
175  typename system::primitive_variables_tag::tags_list>,
176  tmpl::conditional_t<evolution::is_analytic_solution_v<initial_data>,
177  analytic_variables_tags, tmpl::list<>>>,
180  using triggers = Triggers::time_triggers;
181 
182  using observed_reduction_data_tags = observers::collect_reduction_data_tags<
183  typename Event<events>::creatable_classes>;
184 
185  struct factory_creation
186  : tt::ConformsTo<Options::protocols::FactoryCreation> {
187  using factory_classes = tmpl::map<
188  tmpl::pair<StepController, StepControllers::standard_step_controllers>>;
189  };
190 
191  using step_actions = tmpl::flatten<tmpl::list<
194  tmpl::conditional_t<
195  local_time_stepping, tmpl::list<>,
196  tmpl::list<Actions::RecordTimeStepperData<>, Actions::UpdateU<>>>,
201  // Conservative `UpdatePrimitives` expects system to possess
202  // list of recovery schemes so we use `MutateApply` instead.
204 
205  enum class Phase {
206  Initialization,
207  InitializeTimeStepperHistory,
208  RegisterWithObserver,
209  LoadBalancing,
210  Evolve,
211  Exit
212  };
213 
214  static std::string phase_name(Phase phase) noexcept {
215  if (phase == Phase::LoadBalancing) {
216  return "LoadBalancing";
217  }
218  ERROR(
219  "Passed phase that should not be used in input file. Integer "
220  "corresponding to phase is: "
221  << static_cast<int>(phase));
222  }
223 
224  using phase_changes = tmpl::list<PhaseControl::Registrars::VisitAndReturn<
225  EvolutionMetavars, Phase::LoadBalancing>>;
226 
227  using initialize_phase_change_decision_data =
229 
230  using phase_change_tags_and_combines_list =
232 
233  using dg_registration_list =
234  tmpl::list<observers::Actions::RegisterEventsWithObservers>;
235 
236  using initialization_actions = tmpl::list<
242  equation_of_state_tag>,
249  tmpl::list<hydro::Tags::SoundSpeedSquaredCompute<DataVector>>>,
251  tmpl::conditional_t<
252  evolution::is_analytic_solution_v<initial_data>,
255  Dim, initial_data_tag, analytic_variables_tags>>>,
256  tmpl::list<>>,
258  StepChoosers::step_chooser_compute_tags<EvolutionMetavars>>,
262 
263  using dg_element_array = DgElementArray<
265  tmpl::list<
266  Parallel::PhaseActions<Phase, Phase::Initialization,
267  initialization_actions>,
268 
270  Phase, Phase::InitializeTimeStepperHistory,
272 
273  Parallel::PhaseActions<Phase, Phase::RegisterWithObserver,
274  tmpl::list<dg_registration_list,
276 
278  Phase, Phase::Evolve,
279  tmpl::list<
282  thermodynamic_dim>>,
286  triggers>>>>>;
287 
288  template <typename ParallelComponent>
289  struct registration_list {
290  using type =
292  dg_registration_list, tmpl::list<>>;
293  };
294 
295  using component_list =
296  tmpl::list<observers::Observer<EvolutionMetavars>,
298  dg_element_array>;
299 
300  using const_global_cache_tags = tmpl::list<
301  initial_data_tag, time_stepper_tag,
304 
305  static constexpr Options::String help{
306  "Evolve the Valencia formulation of RelativisticEuler system.\n\n"};
307 
308  template <typename... Tags>
309  static Phase determine_next_phase(
311  phase_change_decision_data,
312  const Phase& current_phase,
313  const Parallel::CProxy_GlobalCache<EvolutionMetavars>&
314  cache_proxy) noexcept {
315  const auto next_phase =
316  PhaseControl::arbitrate_phase_change<phase_changes, triggers>(
317  phase_change_decision_data, current_phase,
318  *(cache_proxy.ckLocalBranch()));
319  if (next_phase.has_value()) {
320  return next_phase.value();
321  }
322  switch (current_phase) {
323  case Phase::Initialization:
324  return Phase::InitializeTimeStepperHistory;
325  case Phase::InitializeTimeStepperHistory:
326  return Phase::RegisterWithObserver;
327  case Phase::RegisterWithObserver:
328  return Phase::Evolve;
329  case Phase::Evolve:
330  return Phase::Exit;
331  case Phase::Exit:
332  ERROR(
333  "Should never call determine_next_phase with the current phase "
334  "being 'Exit'");
335  default:
336  ERROR(
337  "Unknown type of phase. Did you static_cast<Phase> to an integral "
338  "value?");
339  }
340  }
341 
342  // NOLINTNEXTLINE(google-runtime-references)
343  void pup(PUP::er& /*p*/) noexcept {}
344 };
345 
346 static const std::vector<void (*)()> charm_init_node_funcs{
347  &setup_error_handling,
349  &domain::creators::register_derived_with_charm,
350  &domain::creators::time_dependence::register_derived_with_charm,
351  &domain::FunctionsOfTime::register_derived_with_charm,
352  &RelativisticEuler::Valencia::BoundaryConditions::
353  register_derived_with_charm,
354  &RelativisticEuler::Valencia::BoundaryCorrections::
355  register_derived_with_charm,
362  &Parallel::register_derived_classes_with_charm<TimeSequence<double>>,
363  &Parallel::register_derived_classes_with_charm<TimeSequence<std::uint64_t>>,
364  &Parallel::register_derived_classes_with_charm<TimeStepper>,
369  &Parallel::register_factory_classes_with_charm<metavariables>};
370 
371 static const std::vector<void (*)()> charm_init_proc_funcs{
FloatingPointExceptions.hpp
hydro::Tags::EquationOfState
The equation of state.
Definition: Tags.hpp:57
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
std::string
PhaseControl::InitializePhaseChangeDecisionData
Initialize the Main chare's phase_change_decision_data for the option-selected PhaseChanges.
Definition: ExecutePhaseChange.hpp:181
Tags::Limiter
The global cache tag for the limiter.
Definition: Tags.hpp:42
Tags::TimeStepId
Tag for TimeStepId for the algorithm state.
Definition: Tags.hpp:33
Limiters::Actions::SendData
Send local data needed for limiting.
Definition: LimiterActions.hpp:142
domain::Tags::Coordinates
Definition: Tags.hpp:130
Tags.hpp
LimiterActions.hpp
Options.hpp
VariableFixing::Actions::FixVariables
Adjust variables with a variable fixer.
Definition: Actions.hpp:42
Initialization::Actions::AddComputeTags
Initialize the list of compute tags in ComputeTagsList
Definition: AddComputeTags.hpp:42
Tags.hpp
vector
evolution::Tags::AnalyticCompute
Use the AnalyticSolutionTag to compute the analytic solution of the tags in AnalyticFieldsTagList.
Definition: ComputeTags.hpp:24
Initialization::Actions::RemoveOptionsAndTerminatePhase
Definition: RemoveOptionsAndTerminatePhase.hpp:27
SelfStart::self_start_procedure
tmpl::flatten< tmpl::list< SelfStart::Actions::Initialize< System >, ::Actions::Label< detail::PhaseStart >, SelfStart::Actions::CheckForCompletion< detail::PhaseEnd >, ::Actions::AdvanceTime, SelfStart::Actions::CheckForOrderIncrease, StepActions, ::Actions::Goto< detail::PhaseStart >, ::Actions::Label< detail::PhaseEnd >, SelfStart::Actions::Cleanup, ::Actions::AdvanceTime, Parallel::Actions::TerminatePhase > > self_start_procedure
Definition: SelfStartActions.hpp:455
Initialization::Actions::Minmod
Allocate items for minmod limiter.
Definition: Limiter.hpp:38
Actions::AdvanceTime
Advance time one substep.
Definition: AdvanceTime.hpp:50
Parallel::Actions::TerminatePhase
Terminate the algorithm to proceed to the next phase.
Definition: TerminatePhase.hpp:26
PhaseControl::Tags::PhaseChangeAndTriggers
Tag for the collection of triggers that indicate synchronization points at which phase changes should...
Definition: PhaseControlTags.hpp:139
disable_openblas_multithreading
void disable_openblas_multithreading() noexcept
Disable OpenBLAS multithreading since it conflicts with Charm++ parallelism.
DgElementArray
The parallel component responsible for managing the DG elements that compose the computational domain...
Definition: DgElementArray.hpp:43
Registration::Registrar
A template for defining a registrar.
Definition: Registration.hpp:42
EvolutionMetavars
Definition: EvolveBurgers.hpp:106
Initialization::Actions::ConservativeSystem
Allocate variables needed for evolution of conservative systems.
Definition: ConservativeSystem.hpp:72
enable_floating_point_exceptions
void enable_floating_point_exceptions()
PhaseControl::Actions::ExecutePhaseChange
Check if any triggers are activated, and perform phase changes as needed.
Definition: ExecutePhaseChange.hpp:52
ERROR
#define ERROR(m)
prints an error message to the standard error stream and aborts the program.
Definition: Error.hpp:37
Actions::UpdateConservatives
Compute the conservative variables from the primitive variables.
Definition: UpdateConservatives.hpp:32
Actions::ChangeSlabSize
Definition: ChangeSlabSize.hpp:108
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
RelativisticEuler::Valencia::Tags::TildeTau
The densitized energy density .
Definition: Tags.hpp:33
Event
Definition: Event.hpp:30
Initialization::Actions::GrTagsForHydro
Allocate and set general relativity quantities needed for evolution of some hydro systems.
Definition: GrTagsForHydro.hpp:65
evolution::dg::Actions::ComputeTimeDerivative
Computes the time derivative for a DG time step.
Definition: ComputeTimeDerivative.hpp:280
RelativisticEuler::Valencia::System
Definition: System.hpp:31
evolution::dg::Initialization::Mortars
Initialize mortars between elements for exchanging boundary correction terms.
Definition: Mortars.hpp:90
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
evolution::dg::Initialization::Domain
Initialize items related to the basic structure of the element.
Definition: DgDomain.hpp:85
Initialization::Actions::TimeStepperHistory
Initialize time-stepper items.
Definition: Evolution.hpp:194
PhaseControl::get_phase_change_tags
tmpl::push_back< tmpl::flatten< tmpl::transform< Registration::registrants< PhaseChangeRegistrars >, detail::get_phase_change_tags_and_combines< tmpl::_1 > >>, TagsAndCombines::UsePhaseChangeArbitration > get_phase_change_tags
Metafunction for determining the merged collection of tags in phase_change_tags_and_combines_lists fr...
Definition: PhaseControlTags.hpp:189
Tags::AnalyticSolution
Definition: Tags.hpp:58
cstdint
tuples::TaggedTuple< Tags... >
Limiters::Actions::Limit
Receive limiter data from neighbors, then apply limiter.
Definition: LimiterActions.hpp:71
Trigger
Definition: Trigger.hpp:34
StepController.hpp
Tags::Time
Tag for the current time as a double.
Definition: Tags.hpp:73
dg::Events::Registrars::ObserveFields
Definition: ObserveFields.hpp:68
RelativisticEuler::Valencia::Tags::TildeS
The densitized momentum density .
Definition: Tags.hpp:39
AdvanceTime.hpp
Tags::AnalyticData
The analytic data, with the type of the analytic data set as the template parameter.
Definition: Tags.hpp:43
Tags::EventsAndTriggers
Definition: Tags.hpp:57
PhaseChange
PhaseChange objects determine the storage types and logic for moving between phases based on runtime ...
Definition: PhaseChange.hpp:141
evolution::Initialization::Actions::SetVariables
Sets variables needed for evolution of hyperbolic systems.
Definition: SetVariables.hpp:54
Tags::TimeStepper
Tag for a TimeStepper of type StepperType.
Definition: Tags.hpp:206
Options::String
const char *const String
The string used in option structs.
Definition: Options.hpp:32
Frame
Definition: IndexType.hpp:36
Actions::UpdateU
Perform variable updates for one substep.
Definition: UpdateU.hpp:72
evolution::dg::Actions::ApplyBoundaryCorrections
Computes the boundary corrections and lifts them to the volume.
Definition: ApplyBoundaryCorrections.hpp:82
RelativisticEuler::Valencia::Tags::TildeD
The densitized rest-mass density .
Definition: Tags.hpp:28
Initialization::Actions::TimeAndTimeStep
Initialize items related to time, such as the time step.
Definition: Evolution.hpp:80
UpdateU.hpp
std::conditional_t
Parallel::register_derived_classes_with_charm
void register_derived_classes_with_charm() noexcept
Register derived classes of the Base class.
Definition: RegisterDerivedClassesWithCharm.hpp:35
Blas.hpp
Triggers::time_triggers
tmpl::list< Registrars::NearTimes, Registrars::SlabCompares, Registrars::Slabs, Registrars::TimeCompares, Registrars::Times > time_triggers
Definition: TimeTriggers.hpp:19
dg::Formulation
Formulation
The DG formulation to use.
Definition: Formulation.hpp:34
StepChooser
Definition: StepChooser.hpp:98
tt::ConformsTo
Indicate a class conforms to the Protocol.
Definition: ProtocolHelpers.hpp:22
Parallel
Functionality for parallelization.
Definition: ElementReceiveInterpPoints.hpp:13
VariableFixing::FixToAtmosphere
Fix the primitive variables to an atmosphere in low density regions.
Definition: FixToAtmosphere.hpp:47
RelativisticEuler::Valencia::FixConservatives
Fix conservative variables using the method proposed in F. Foucart's PhD thesis (Cornell)
Definition: FixConservatives.hpp:53
TMPL.hpp
gsl::not_null
Require a pointer to not be a nullptr
Definition: ReadSpecThirdOrderPiecewisePolynomial.hpp:13