ExaDG
Loading...
Searching...
No Matches
solver.h
1/* ______________________________________________________________________
2 *
3 * ExaDG - High-Order Discontinuous Galerkin for the Exa-Scale
4 *
5 * Copyright (C) 2023 by the ExaDG authors
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 * ______________________________________________________________________
20 */
21
22#ifndef EXADG_ACOUSTIC_CONSERVATION_EQUATIONS_SOLVER_H_
23#define EXADG_ACOUSTIC_CONSERVATION_EQUATIONS_SOLVER_H_
24
25// driver
26#include <exadg/acoustic_conservation_equations/driver.h>
27
28// utilities
29#include <exadg/operators/resolution_parameters.h>
30#include <exadg/time_integration/resolution_parameters.h>
31#include <exadg/utilities/general_parameters.h>
32
33// application
34#include <exadg/acoustic_conservation_equations/user_interface/declare_get_application.h>
35
36namespace ExaDG
37{
38void
39create_input_file(std::string const & input_file)
40{
41 dealii::ParameterHandler prm;
42
43 GeneralParameters general;
44 general.add_parameters(prm);
45
46 SpatialResolutionParametersMinMax spatial;
47 spatial.add_parameters(prm);
48
49 TemporalResolutionParameters temporal;
50 temporal.add_parameters(prm);
51
52 // we have to assume a default dimension and default Number type
53 // for the automatic generation of a default input file
54 unsigned int const Dim = 2;
55 using Number = double;
56 Acoustics::get_application<Dim, Number>(input_file, MPI_COMM_WORLD)->add_parameters(prm);
57
58 prm.print_parameters(input_file,
59 dealii::ParameterHandler::Short |
60 dealii::ParameterHandler::KeepDeclarationOrder);
61}
62
63template<int dim, typename Number>
64void
65run(std::string const & input_file,
66 unsigned int const degree,
67 unsigned int const refine_space,
68 unsigned int const refine_time,
69 MPI_Comm const & mpi_comm,
70 bool const is_test)
71{
72 dealii::Timer timer;
73 timer.restart();
74
75 std::shared_ptr<Acoustics::ApplicationBase<dim, Number>> application =
76 Acoustics::get_application<dim, Number>(input_file, mpi_comm);
77
78 application->set_parameters_convergence_study(degree, refine_space, refine_time);
79
80 std::shared_ptr<Acoustics::Driver<dim, Number>> driver =
81 std::make_shared<Acoustics::Driver<dim, Number>>(mpi_comm, application, is_test, false);
82
83 driver->setup();
84
85 driver->solve();
86
87 if(not(is_test))
88 driver->print_performance_results(timer.wall_time());
89}
90
91} // namespace ExaDG
92
93//#define USE_SUB_COMMUNICATOR
94
95int
96main(int argc, char ** argv)
97{
98 dealii::Utilities::MPI::MPI_InitFinalize mpi(argc, argv, 1);
99
100 MPI_Comm mpi_comm(MPI_COMM_WORLD);
101
102 // new communicator
103 MPI_Comm sub_comm;
104
105#ifdef USE_SUB_COMMUNICATOR
106 // use stride of n cores
107 int const n = 48; // 24;
108
109 int const rank = dealii::Utilities::MPI::this_mpi_process(mpi_comm);
110 int const size = dealii::Utilities::MPI::n_mpi_processes(mpi_comm);
111 int const flag = 1;
112 int const new_rank = rank + (rank % n) * size;
113
114 // split default communicator into two groups
115 MPI_Comm_split(mpi_comm, flag, new_rank, &sub_comm);
116
117 if(rank == 0)
118 std::cout << std::endl << "Created sub communicator with stride of " << n << std::endl;
119#else
120 sub_comm = mpi_comm;
121#endif
122
123 std::string input_file;
124
125 if(argc == 1)
126 {
127 if(dealii::Utilities::MPI::this_mpi_process(mpi_comm) == 0)
128 {
129 // clang-format off
130 std::cout << "To run the program, use: ./solver input_file" << std::endl
131 << "To setup the input file, use: ./solver input_file --help" << std::endl;
132 // clang-format on
133 }
134
135 return 0;
136 }
137 else if(argc >= 2)
138 {
139 input_file = std::string(argv[1]);
140
141 if(argc == 3 and std::string(argv[2]) == "--help")
142 {
143 if(dealii::Utilities::MPI::this_mpi_process(mpi_comm) == 0)
144 ExaDG::create_input_file(input_file);
145
146 return 0;
147 }
148 }
149
150 ExaDG::GeneralParameters general(input_file);
152 ExaDG::TemporalResolutionParameters temporal(input_file);
153
154 // k-refinement
155 for(unsigned int degree = spatial.degree_min; degree <= spatial.degree_max; ++degree)
156 {
157 // h-refinement
158 for(unsigned int refine_space = spatial.refine_space_min;
159 refine_space <= spatial.refine_space_max;
160 ++refine_space)
161 {
162 // dt-refinement
163 for(unsigned int refine_time = temporal.refine_time_min;
164 refine_time <= temporal.refine_time_max;
165 ++refine_time)
166 {
167 // run the simulation
168 if(general.dim == 2 and general.precision == "float")
169 {
170 ExaDG::run<2, float>(
171 input_file, degree, refine_space, refine_time, sub_comm, general.is_test);
172 }
173 else if(general.dim == 2 and general.precision == "double")
174 {
175 ExaDG::run<2, double>(
176 input_file, degree, refine_space, refine_time, sub_comm, general.is_test);
177 }
178 else if(general.dim == 3 and general.precision == "float")
179 {
180 ExaDG::run<3, float>(
181 input_file, degree, refine_space, refine_time, sub_comm, general.is_test);
182 }
183 else if(general.dim == 3 and general.precision == "double")
184 {
185 ExaDG::run<3, double>(
186 input_file, degree, refine_space, refine_time, sub_comm, general.is_test);
187 }
188 else
189 {
190 AssertThrow(
191 false, dealii::ExcMessage("Only dim = 2|3 and precision = float|double implemented."));
192 }
193 }
194 }
195 }
196
197#ifdef USE_SUB_COMMUNICATOR
198 // free communicator
199 MPI_Comm_free(&sub_comm);
200#endif
201
202 return 0;
203}
204
205#endif /* EXADG_ACOUSTIC_CONSERVATION_EQUATIONS_SOLVER_H_ */
Definition driver.cpp:33
Definition general_parameters.h:32
Definition resolution_parameters.h:32
Definition resolution_parameters.h:32