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