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