EvolveM1Grey.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
6 #include <cstdint>
7 #include <vector>
8 
9 #include "Domain/Creators/Factory3D.hpp"
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/Actions/ComputeTimeDerivative.hpp" // IWYU pragma: keep
15 #include "Evolution/Actions/RunEventsAndDenseTriggers.hpp"
16 #include "Evolution/ComputeTags.hpp"
17 #include "Evolution/DiscontinuousGalerkin/Actions/ApplyBoundaryCorrections.hpp"
18 #include "Evolution/DiscontinuousGalerkin/Actions/ComputeTimeDerivative.hpp"
19 #include "Evolution/DiscontinuousGalerkin/Actions/VolumeTermsImpl.tpp"
20 #include "Evolution/DiscontinuousGalerkin/DgElementArray.hpp"
21 #include "Evolution/DiscontinuousGalerkin/Initialization/Mortars.hpp"
22 #include "Evolution/DiscontinuousGalerkin/Initialization/QuadratureTag.hpp"
24 #include "Evolution/DiscontinuousGalerkin/Limiters/Minmod.hpp"
25 #include "Evolution/DiscontinuousGalerkin/Limiters/Tags.hpp"
26 #include "Evolution/EventsAndDenseTriggers/DenseTrigger.hpp"
27 #include "Evolution/EventsAndDenseTriggers/DenseTriggers/Factory.hpp"
28 #include "Evolution/Initialization/ConservativeSystem.hpp"
29 #include "Evolution/Initialization/DgDomain.hpp"
30 #include "Evolution/Initialization/DiscontinuousGalerkin.hpp"
31 #include "Evolution/Initialization/Evolution.hpp"
32 #include "Evolution/Initialization/GrTagsForHydro.hpp"
33 #include "Evolution/Initialization/Limiter.hpp"
34 #include "Evolution/Initialization/SetVariables.hpp"
35 #include "Evolution/Systems/RadiationTransport/M1Grey/BoundaryConditions/Factory.hpp"
36 #include "Evolution/Systems/RadiationTransport/M1Grey/BoundaryCorrections/Factory.hpp"
37 #include "Evolution/Systems/RadiationTransport/M1Grey/Initialize.hpp"
40 #include "Evolution/Systems/RadiationTransport/M1Grey/System.hpp"
41 #include "Evolution/Systems/RadiationTransport/M1Grey/Tags.hpp"
42 #include "Evolution/Systems/RadiationTransport/Tags.hpp"
43 #include "Evolution/TypeTraits.hpp"
44 #include "IO/Observer/Actions/RegisterEvents.hpp"
45 #include "IO/Observer/Helpers.hpp"
46 #include "IO/Observer/ObserverComponent.hpp"
47 #include "NumericalAlgorithms/DiscontinuousGalerkin/Formulation.hpp"
48 #include "NumericalAlgorithms/DiscontinuousGalerkin/Tags.hpp"
49 #include "Options/Options.hpp"
50 #include "Options/Protocols/FactoryCreation.hpp"
51 #include "Parallel/Actions/SetupDataBox.hpp"
52 #include "Parallel/Actions/TerminatePhase.hpp"
53 #include "Parallel/InitializationFunctions.hpp"
54 #include "Parallel/PhaseControl/CheckpointAndExitAfterWallclock.hpp"
55 #include "Parallel/PhaseControl/ExecutePhaseChange.hpp"
56 #include "Parallel/PhaseControl/PhaseControlTags.hpp"
57 #include "Parallel/PhaseControl/VisitAndReturn.hpp"
58 #include "Parallel/PhaseDependentActionList.hpp"
60 #include "ParallelAlgorithms/Actions/MutateApply.hpp"
61 #include "ParallelAlgorithms/Events/Factory.hpp"
62 #include "ParallelAlgorithms/EventsAndTriggers/Actions/RunEventsAndTriggers.hpp" // IWYU pragma: keep
63 #include "ParallelAlgorithms/EventsAndTriggers/Completion.hpp"
64 #include "ParallelAlgorithms/EventsAndTriggers/Event.hpp"
65 #include "ParallelAlgorithms/EventsAndTriggers/EventsAndTriggers.hpp" // IWYU pragma: keep
66 #include "ParallelAlgorithms/EventsAndTriggers/LogicalTriggers.hpp"
68 #include "ParallelAlgorithms/EventsAndTriggers/Trigger.hpp"
69 #include "ParallelAlgorithms/Initialization/Actions/AddComputeTags.hpp"
70 #include "ParallelAlgorithms/Initialization/Actions/RemoveOptionsAndTerminatePhase.hpp"
71 #include "PointwiseFunctions/AnalyticData/Tags.hpp"
72 #include "PointwiseFunctions/AnalyticSolutions/RadiationTransport/M1Grey/ConstantM1.hpp"
73 #include "PointwiseFunctions/AnalyticSolutions/Tags.hpp"
74 #include "PointwiseFunctions/Hydro/Tags.hpp"
76 #include "Time/Actions/ChangeSlabSize.hpp"
77 #include "Time/Actions/ChangeStepSize.hpp"
78 #include "Time/Actions/RecordTimeStepperData.hpp"
79 #include "Time/Actions/SelfStartActions.hpp" // IWYU pragma: keep
80 #include "Time/Actions/UpdateU.hpp"
81 #include "Time/StepChoosers/Factory.hpp"
82 #include "Time/StepChoosers/StepChooser.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/MemoryHelpers.hpp"
93 #include "Utilities/ProtocolHelpers.hpp"
94 #include "Utilities/TMPL.hpp"
95 
96 /// \cond
97 namespace Frame {
98 struct Inertial;
99 } // namespace Frame
100 namespace PUP {
101 class er;
102 } // namespace PUP
103 namespace Parallel {
104 template <typename Metavariables>
105 class CProxy_GlobalCache;
106 } // namespace Parallel
107 /// \endcond
108 
109 struct EvolutionMetavars {
110  static constexpr size_t volume_dim = 3;
111  static constexpr dg::Formulation dg_formulation =
112  dg::Formulation::StrongInertial;
113 
114  // To switch which initial data is evolved you only need to change the
115  // line `using initial_data = ...;` and include the header file for the
116  // solution.
118  static_assert(
119  evolution::is_analytic_data_v<initial_data> xor
120  evolution::is_analytic_solution_v<initial_data>,
121  "initial_data must be either an analytic_data or an analytic_solution");
122 
123  // Set list of neutrino species to be used by M1 code
124  using neutrino_species = tmpl::list<neutrinos::ElectronNeutrinos<1>>;
125 
127  using temporal_id = Tags::TimeStepId;
128  static constexpr bool local_time_stepping = false;
129  using initial_data_tag =
130  tmpl::conditional_t<evolution::is_analytic_solution_v<initial_data>,
133  using boundary_condition_tag = initial_data_tag;
134  using analytic_variables_tags = typename system::variables_tag::tags_list;
135  using limiter = Tags::Limiter<
137 
138  using time_stepper_tag = Tags::TimeStepper<
139  tmpl::conditional_t<local_time_stepping, LtsTimeStepper, TimeStepper>>;
140 
141  struct factory_creation
142  : tt::ConformsTo<Options::protocols::FactoryCreation> {
143  using factory_classes = tmpl::map<
144  tmpl::pair<DenseTrigger, DenseTriggers::standard_dense_triggers>,
145  tmpl::pair<DomainCreator<volume_dim>, domain_creators<volume_dim>>,
146  tmpl::pair<
147  Event,
148  tmpl::flatten<tmpl::list<
150  dg::Events::field_observations<
151  volume_dim, Tags::Time,
152  tmpl::append<
153  typename system::variables_tag::tags_list,
154  typename system::primitive_variables_tag::tags_list>,
155  tmpl::conditional_t<
156  evolution::is_analytic_solution_v<initial_data>,
157  analytic_variables_tags, tmpl::list<>>>,
158  Events::time_events<system>>>>,
159  tmpl::pair<
161  StepChoosers::standard_step_choosers<system, false>>,
162  tmpl::pair<StepChooser<StepChooserUse::Slab>,
163  StepChoosers::standard_slab_choosers<
164  system, local_time_stepping, false>>,
165  tmpl::pair<StepController, StepControllers::standard_step_controllers>,
166  tmpl::pair<TimeSequence<double>,
167  TimeSequences::all_time_sequences<double>>,
168  tmpl::pair<TimeSequence<std::uint64_t>,
169  TimeSequences::all_time_sequences<std::uint64_t>>,
170  tmpl::pair<Trigger, tmpl::append<Triggers::logical_triggers,
172  };
173 
174  using observed_reduction_data_tags =
175  observers::collect_reduction_data_tags<tmpl::flatten<tmpl::list<
176  tmpl::at<typename factory_creation::factory_classes, Event>>>>;
177 
178  using step_actions = tmpl::flatten<tmpl::list<
181  tmpl::conditional_t<
182  local_time_stepping, tmpl::list<>,
183  tmpl::list<Actions::RecordTimeStepperData<>,
188  Actions::MutateApply<typename RadiationTransport::M1Grey::
189  ComputeM1Closure<neutrino_species>>,
190  Actions::MutateApply<typename RadiationTransport::M1Grey::
191  ComputeM1HydroCoupling<neutrino_species>>>>;
192 
193  enum class Phase {
194  Initialization,
195  InitializeTimeStepperHistory,
196  RegisterWithObserver,
197  LoadBalancing,
198  WriteCheckpoint,
199  Evolve,
200  Exit
201  };
202 
203  static std::string phase_name(Phase phase) noexcept {
204  if (phase == Phase::LoadBalancing) {
205  return "LoadBalancing";
206  }
207  ERROR(
208  "Passed phase that should not be used in input file. Integer "
209  "corresponding to phase is: "
210  << static_cast<int>(phase));
211  }
212 
213  using phase_changes =
214  tmpl::list<PhaseControl::Registrars::VisitAndReturn<EvolutionMetavars,
215  Phase::LoadBalancing>,
216  PhaseControl::Registrars::CheckpointAndExitAfterWallclock<
218 
219  using initialize_phase_change_decision_data =
221 
222  using phase_change_tags_and_combines_list =
224 
225  using dg_registration_list =
226  tmpl::list<observers::Actions::RegisterEventsWithObservers>;
227 
228  using initialization_actions = tmpl::list<
238  Actions::MutateApply<typename RadiationTransport::M1Grey::
239  ComputeM1Closure<neutrino_species>>,
240  Actions::MutateApply<typename RadiationTransport::M1Grey::
241  ComputeM1HydroCoupling<neutrino_species>>,
242  tmpl::conditional_t<
243  evolution::is_analytic_solution_v<initial_data>,
246  3, initial_data_tag, analytic_variables_tags>>>,
247  tmpl::list<>>,
249  StepChoosers::step_chooser_compute_tags<EvolutionMetavars>>,
254 
255  using dg_element_array = DgElementArray<
257  tmpl::list<
258  Parallel::PhaseActions<Phase, Phase::Initialization,
259  initialization_actions>,
260 
262  Phase, Phase::InitializeTimeStepperHistory,
264 
265  Parallel::PhaseActions<Phase, Phase::RegisterWithObserver,
266  tmpl::list<dg_registration_list,
268 
270  Phase, Phase::Evolve,
272  step_actions, Actions::AdvanceTime,
274  phase_changes>>>>>;
275 
276  template <typename ParallelComponent>
277  struct registration_list {
278  using type =
280  dg_registration_list, tmpl::list<>>;
281  };
282 
283  using component_list =
284  tmpl::list<observers::Observer<EvolutionMetavars>,
286  dg_element_array>;
287 
288  using const_global_cache_tags =
289  tmpl::list<initial_data_tag, Tags::EventsAndTriggers,
291 
292  static constexpr Options::String help{
293  "Evolve the M1Grey system (without coupling to hydro).\n\n"};
294 
295  template <typename... Tags>
296  static Phase determine_next_phase(
298  phase_change_decision_data,
299  const Phase& current_phase,
300  const Parallel::CProxy_GlobalCache<EvolutionMetavars>&
301  cache_proxy) noexcept {
302  const auto next_phase =
303  PhaseControl::arbitrate_phase_change<phase_changes>(
304  phase_change_decision_data, current_phase,
305  *(cache_proxy.ckLocalBranch()));
306  if (next_phase.has_value()) {
307  return next_phase.value();
308  }
309  switch (current_phase) {
310  case Phase::Initialization:
311  return Phase::InitializeTimeStepperHistory;
312  case Phase::InitializeTimeStepperHistory:
313  return Phase::RegisterWithObserver;
314  case Phase::RegisterWithObserver:
315  return Phase::Evolve;
316  case Phase::Evolve:
317  return Phase::Exit;
318  case Phase::Exit:
319  ERROR(
320  "Should never call determine_next_phase with the current phase "
321  "being 'Exit'");
322  default:
323  ERROR(
324  "Unknown type of phase. Did you static_cast<Phase> an integral "
325  "value?");
326  }
327  }
328 
329  // NOLINTNEXTLINE(google-runtime-references)
330  void pup(PUP::er& /*p*/) noexcept {}
331 };
332 
333 static const std::vector<void (*)()> charm_init_node_funcs{
334  &setup_error_handling, &setup_memory_allocation_failure_reporting,
336  &domain::creators::register_derived_with_charm,
337  &domain::creators::time_dependence::register_derived_with_charm,
338  &domain::FunctionsOfTime::register_derived_with_charm,
341  metavariables::neutrino_species>>,
344  metavariables::neutrino_species>>,
345  &Parallel::register_derived_classes_with_charm<TimeStepper>,
348  &Parallel::register_factory_classes_with_charm<metavariables>};
349 
350 static const std::vector<void (*)()> charm_init_proc_funcs{
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
StepChooser< StepChooserUse::LtsStep >
Definition: StepChooser.hpp:143
std::string
PhaseControl::InitializePhaseChangeDecisionData
Initialize the Main chare's phase_change_decision_data for the option-selected PhaseChanges.
Definition: ExecutePhaseChange.hpp:169
Tags::Limiter
The global cache tag for the limiter.
Definition: Tags.hpp:42
evolution::Actions::RunEventsAndDenseTriggers
Run the events and dense triggers.
Definition: RunEventsAndDenseTriggers.hpp:43
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
M1Closure.hpp
Options.hpp
Initialization::Actions::AddComputeTags
Initialize the list of compute tags in ComputeTagsList
Definition: AddComputeTags.hpp:42
Tags.hpp
vector
std::system
T system(T... args)
evolution::Tags::AnalyticCompute
Use the AnalyticSolutionTag to compute the analytic solution of the tags in AnalyticFieldsTagList.
Definition: ComputeTags.hpp:24
Limiters::Minmod
A minmod-based generalized slope limiter.
Definition: Minmod.hpp:148
Initialization::Actions::RemoveOptionsAndTerminatePhase
Definition: RemoveOptionsAndTerminatePhase.hpp:27
Initialization::Actions::Minmod
Allocate items for minmod limiter.
Definition: Limiter.hpp:38
Actions::AdvanceTime
Advance time one substep.
Definition: AdvanceTime.hpp:50
RadiationTransport::M1Grey::BoundaryConditions::BoundaryCondition
The base class off of which all boundary conditions must inherit.
Definition: BoundaryCondition.hpp:22
Parallel::Actions::TerminatePhase
Terminate the algorithm to proceed to the next phase.
Definition: TerminatePhase.hpp:26
M1HydroCoupling.hpp
PhaseControl::Tags::PhaseChangeAndTriggers
Tag for the collection of triggers that indicate synchronization points at which phase changes should...
Definition: PhaseControlTags.hpp:66
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
EvolutionMetavars
Definition: EvolveBurgers.hpp:103
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:41
Events::Completion
Definition: Completion.hpp:15
ERROR
#define ERROR(m)
prints an error message to the standard error stream and aborts the program.
Definition: Error.hpp:37
Actions::ChangeSlabSize
Definition: ChangeSlabSize.hpp:106
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
Event
Definition: Event.hpp:19
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:287
evolution::dg::Initialization::Mortars
Initialize mortars between elements for exchanging boundary correction terms.
Definition: Mortars.hpp:90
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:214
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:114
RadiationTransport::M1Grey::BoundaryCorrections::BoundaryCorrection
The base class used to create boundary corrections from input files and store them in the global cach...
Definition: BoundaryCorrection.hpp:24
Tags::AnalyticSolution
Definition: Tags.hpp:58
Triggers::time_triggers
tmpl::list< NearTimes, SlabCompares, Slabs, TimeCompares, Times > time_triggers
Definition: TimeTriggers.hpp:17
cstdint
evolution::Actions::InitializeRunEventsAndDenseTriggers
Definition: RunEventsAndDenseTriggers.hpp:132
tuples::TaggedTuple< Tags... >
Limiters::Actions::Limit
Receive limiter data from neighbors, then apply limiter.
Definition: LimiterActions.hpp:71
Trigger
Definition: Trigger.hpp:17
StepController.hpp
Tags::Time
Tag for the current time as a double.
Definition: Tags.hpp:73
AdvanceTime.hpp
SelfStart::self_start_procedure
tmpl::flatten< tmpl::list< SelfStart::Actions::Initialize< System >, ::Actions::Label< detail::PhaseStart >, SelfStart::Actions::CheckForCompletion< detail::PhaseEnd, System >, ::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:471
Tags::AnalyticData
The analytic data, with the type of the analytic data set as the template parameter.
Definition: Tags.hpp:43
RadiationTransport::M1Grey::Actions::InitializeM1Tags
Definition: Initialize.hpp:46
Tags::EventsAndTriggers
Definition: Tags.hpp:51
RadiationTransport::M1Grey::Solutions::ConstantM1
Constant solution to M1 equations in Minkowski spacetime.
Definition: ConstantM1.hpp:39
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:214
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:96
evolution::dg::Actions::ApplyBoundaryCorrections
Computes the boundary corrections and lifts them to the volume.
Definition: ApplyBoundaryCorrections.hpp:105
Initialization::Actions::TimeAndTimeStep
Initialize items related to time, such as the time step.
Definition: Evolution.hpp:82
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
dg::Formulation
Formulation
The DG formulation to use.
Definition: Formulation.hpp:34
RadiationTransport::M1Grey::System
Definition: System.hpp:31
tt::ConformsTo
Indicate a class conforms to the Protocol.
Definition: ProtocolHelpers.hpp:22
Parallel
Functionality for parallelization.
Definition: ElementReceiveInterpPoints.hpp:13
TMPL.hpp
gsl::not_null
Require a pointer to not be a nullptr
Definition: ReadSpecPiecewisePolynomial.hpp:13