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