ryujin 2.5.0 revision 3a6c8d57210175dea14d8116e1fe878f349f8c1c
Loading...
Searching...
No Matches
equation.template.h
Go to the documentation of this file.
1//
2// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3// Copyright (C) 2023 - 2026 by the ryujin authors
4//
5
6#pragma once
7
11
12#include <deal.II/base/parameter_acceptor.h>
13#include <deal.II/base/utilities.h>
14
15#include <algorithm>
16#include <iostream>
17#include <string>
18
19namespace ryujin
20{
21 template <typename HyperbolicDescription,
22 typename ParabolicDescription,
23 typename Number>
25 int dim,
26 const std::string &parameter_file,
27 const MPI_Comm &mpi_comm) const
28 {
29 if (dealii::Utilities::MPI::this_mpi_process(mpi_comm) == 0) {
30 std::cout << "[INFO] dispatching to driver »" << this->name()
31 << "« with dim=" << dim << std::endl;
32 }
33
34 switch (dim) {
35 case 1:
36 run_simulation<1>(parameter_file, mpi_comm);
37 break;
38 case 2:
39 run_simulation<2>(parameter_file, mpi_comm);
40 break;
41 case 3:
42 run_simulation<3>(parameter_file, mpi_comm);
43 break;
44 default:
45 AssertThrow(false,
46 dealii::ExcMessage("The dimension needs to be either 1, 2, "
47 "or 3, but we encountered »" +
48 std::to_string(dim) + "«"));
49 }
50 }
51
52
53 template <typename HyperbolicDescription,
54 typename ParabolicDescription,
55 typename Number>
58 {
59 create_parameter_file<1>(false);
60 create_parameter_file<2>(true);
61 create_parameter_file<3>(false);
62 }
63
64
65 template <typename HyperbolicDescription,
66 typename ParabolicDescription,
67 typename Number>
68 template <int dim>
69 void
71 const std::string &parameter_file, const MPI_Comm &mpi_comm)
72 {
74 simulation(mpi_comm);
75 TimeLoop<dim, Number> time_loop(simulation);
76 dealii::ParameterAcceptor::initialize(parameter_file);
77 time_loop.run();
78 }
79
80
81 template <typename HyperbolicDescription,
82 typename ParabolicDescription,
83 typename Number>
84 template <int dim>
85 void Equation<HyperbolicDescription, ParabolicDescription, Number>::
86 create_parameter_file(bool write_detailed_description) const
87 {
88 {
89 auto &prm = dealii::ParameterAcceptor::prm;
90
91 /*
92 * Workaround: Add an entry to the "A - TimeLoop" section so that is
93 * shows up first.
94 */
95 prm.enter_subsection("A - TimeLoop");
96 prm.declare_entry("basename", "test");
97 prm.leave_subsection();
98
99 /*
100 * The parameters "dimension" and "equation" of the EquationDispatch,
101 * set to this equation:
102 */
103 prm.enter_subsection("B - Equation");
104 prm.declare_entry("dimension",
105 std::to_string(dim),
106 dealii::Patterns::Integer(),
107 "The spatial dimension");
108 prm.declare_entry("equation",
109 this->name(),
110 dealii::Patterns::Anything(),
111 "The PDE system");
112 prm.leave_subsection();
113
114 /*
115 * Create temporary objects for the sole purpose of populating the
116 * ParameterAcceptor::prm object.
117 */
118 Simulation<HyperbolicDescription, ParabolicDescription, dim, Number>
119 simulation(MPI_COMM_SELF);
120 TimeLoop<dim, Number> time_loop(simulation);
121
122 std::string base_name = this->name();
123 std::ranges::replace(base_name, ' ', '_');
124 base_name += "-" + std::to_string(dim) + "d";
125
126 if (dealii::Utilities::MPI::this_mpi_process(MPI_COMM_SELF) == 0) {
127 const auto full_name =
128 "default_parameters-" + base_name + "-description.prm";
129 if (write_detailed_description)
130 prm.print_parameters(
131 full_name,
132 dealii::ParameterHandler::OutputStyle::KeepDeclarationOrder);
133
134 const auto short_name = "default_parameters-" + base_name + ".prm";
135 prm.print_parameters(
136 short_name,
137 dealii::ParameterHandler::OutputStyle::Short |
138 dealii::ParameterHandler::OutputStyle::KeepDeclarationOrder);
139 }
140 // all objects have to go out of scope, see
141 // https://github.com/dealii/dealii/issues/15111
142 }
143
144 dealii::ParameterAcceptor::clear();
145 }
146} // namespace ryujin
void run(int dim, const std::string &parameter_file, const MPI_Comm &mpi_comm) const override
void create_parameter_files() const override