ExaDG
Loading...
Searching...
No Matches
solver.h
1/* ______________________________________________________________________
2 *
3 * ExaDG - High-Order Discontinuous Galerkin for the Exa-Scale
4 *
5 * Copyright (C) 2021 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#ifndef INCLUDE_EXADG_STRUCTURE_SOLVER_H_
22#define INCLUDE_EXADG_STRUCTURE_SOLVER_H_
23
24// deal.II
25#include <deal.II/base/exceptions.h>
26#include <deal.II/base/parameter_handler.h>
27
28// driver
29#include <exadg/structure/driver.h>
30
31// utilities
32#include <exadg/operators/resolution_parameters.h>
33#include <exadg/time_integration/resolution_parameters.h>
34#include <exadg/utilities/enum_patterns.h>
35#include <exadg/utilities/general_parameters.h>
36
37// application
38#include <exadg/structure/user_interface/declare_get_application.h>
39
40namespace ExaDG
41{
42void
43create_input_file(std::string const & input_file)
44{
45 dealii::ParameterHandler prm;
46
47 GeneralParameters general;
48 general.add_parameters(prm);
49
50 SpatialResolutionParametersMinMax spatial;
51 spatial.add_parameters(prm);
52
53 TemporalResolutionParameters temporal;
54 temporal.add_parameters(prm);
55
56 // we have to assume a default dimension and default Number type
57 // for the automatic generation of a default input file
58 unsigned int const Dim = 2;
59 typedef double Number;
60 Structure::get_application<Dim, Number>(input_file, MPI_COMM_WORLD)->add_parameters(prm);
61
62 prm.print_parameters(input_file,
63 dealii::ParameterHandler::Short |
64 dealii::ParameterHandler::KeepDeclarationOrder);
65}
66
67template<int dim, typename Number>
68void
69run(std::string const & input_file,
70 unsigned int const degree,
71 unsigned int const refine_space,
72 unsigned int const refine_time,
73 MPI_Comm const & mpi_comm,
74 bool const is_test)
75{
76 dealii::Timer timer;
77 timer.restart();
78
79 std::shared_ptr<Structure::ApplicationBase<dim, Number>> application =
80 Structure::get_application<dim, Number>(input_file, mpi_comm);
81
82 application->set_parameters_convergence_study(degree, refine_space, refine_time);
83
84 std::shared_ptr<Structure::Driver<dim, Number>> driver =
85 std::make_shared<Structure::Driver<dim, Number>>(mpi_comm, application, is_test, false);
86
87 driver->setup();
88
89 driver->solve();
90
91 if(not(is_test))
92 driver->print_performance_results(timer.wall_time());
93}
94} // namespace ExaDG
95
96int
97main(int argc, char ** argv)
98{
99 dealii::Utilities::MPI::MPI_InitFinalize mpi(argc, argv, 1);
100
101 MPI_Comm mpi_comm(MPI_COMM_WORLD);
102
103 std::string input_file;
104
105 if(argc == 1)
106 {
107 if(dealii::Utilities::MPI::this_mpi_process(mpi_comm) == 0)
108 {
109 // clang-format off
110 std::cout << "To run the program, use: ./solver input_file" << std::endl
111 << "To setup the input file, use: ./solver input_file --help" << std::endl;
112 // clang-format on
113 }
114
115 return 0;
116 }
117 else if(argc >= 2)
118 {
119 input_file = std::string(argv[1]);
120
121 if(argc == 3 and std::string(argv[2]) == "--help")
122 {
123 if(dealii::Utilities::MPI::this_mpi_process(mpi_comm) == 0)
124 ExaDG::create_input_file(input_file);
125
126 return 0;
127 }
128 }
129
130 ExaDG::GeneralParameters general(input_file);
132 ExaDG::TemporalResolutionParameters temporal(input_file);
133
134 // k-refinement
135 for(unsigned int degree = spatial.degree_min; degree <= spatial.degree_max; ++degree)
136 {
137 // h-refinement
138 for(unsigned int refine_space = spatial.refine_space_min;
139 refine_space <= spatial.refine_space_max;
140 ++refine_space)
141 {
142 // dt-refinement
143 for(unsigned int refine_time = temporal.refine_time_min;
144 refine_time <= temporal.refine_time_max;
145 ++refine_time)
146 {
147 // run the simulation
148 if(general.dim == 2 and general.precision == "float")
149 {
150 ExaDG::run<2, float>(
151 input_file, degree, refine_space, refine_time, mpi_comm, general.is_test);
152 }
153 else if(general.dim == 2 and general.precision == "double")
154 {
155 ExaDG::run<2, double>(
156 input_file, degree, refine_space, refine_time, mpi_comm, general.is_test);
157 }
158 else if(general.dim == 3 and general.precision == "float")
159 {
160 ExaDG::run<3, float>(
161 input_file, degree, refine_space, refine_time, mpi_comm, general.is_test);
162 }
163 else if(general.dim == 3 and general.precision == "double")
164 {
165 ExaDG::run<3, double>(
166 input_file, degree, refine_space, refine_time, mpi_comm, general.is_test);
167 }
168 else
169 {
170 AssertThrow(false,
171 dealii::ExcMessage("Only dim = 2|3 and precision=float|double implemented."));
172 }
173 }
174 }
175 }
176
177 return 0;
178}
179
180#endif /* INCLUDE_EXADG_STRUCTURE_SOLVER_H_ */
Definition driver.cpp:33
Definition general_parameters.h:32
Definition resolution_parameters.h:32
Definition resolution_parameters.h:32