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_INCOMPRESSIBLE_NAVIER_STOKES_SOLVER_H_
23#define EXADG_INCOMPRESSIBLE_NAVIER_STOKES_SOLVER_H_
24
25// ExaDG
26#include <exadg/incompressible_navier_stokes/driver.h>
27#include <exadg/incompressible_navier_stokes/user_interface/declare_get_application.h>
28#include <exadg/operators/resolution_parameters.h>
29#include <exadg/time_integration/resolution_parameters.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
46 temporal.add_parameters(prm);
47
48 // we have to assume a default dimension and default Number type
49 // for the automatic generation of a default input file
50 unsigned int const Dim = 2;
51 typedef double Number;
52 IncNS::get_application<Dim, Number>(input_file, MPI_COMM_WORLD)->add_parameters(prm);
53
54 prm.print_parameters(input_file,
55 dealii::ParameterHandler::Short |
56 dealii::ParameterHandler::KeepDeclarationOrder);
57}
58
59template<int dim, typename Number>
60void
61run(std::string const & input_file,
62 unsigned int const degree,
63 unsigned int const refine_space,
64 unsigned int const refine_time,
65 MPI_Comm const & mpi_comm,
66 bool const is_test)
67{
68 dealii::Timer timer;
69 timer.restart();
70
71 std::shared_ptr<IncNS::ApplicationBase<dim, Number>> application =
72 IncNS::get_application<dim, Number>(input_file, mpi_comm);
73
74 application->set_parameters_convergence_study(degree, refine_space, refine_time);
75
76 std::shared_ptr<IncNS::Driver<dim, Number>> driver =
77 std::make_shared<IncNS::Driver<dim, Number>>(mpi_comm, application, is_test, false);
78
79 driver->setup();
80
81 driver->solve();
82
83 if(not(is_test))
84 driver->print_performance_results(timer.wall_time());
85}
86
87} // namespace ExaDG
88
89//#define USE_SUB_COMMUNICATOR
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 // new communicator
99 MPI_Comm sub_comm;
100
101#ifdef USE_SUB_COMMUNICATOR
102 // use stride of n cores
103 int const n = 48; // 24;
104
105 int const rank = dealii::Utilities::MPI::this_mpi_process(mpi_comm);
106 int const size = dealii::Utilities::MPI::n_mpi_processes(mpi_comm);
107 int const flag = 1;
108 int const new_rank = rank + (rank % n) * size;
109
110 // split default communicator into two groups
111 MPI_Comm_split(mpi_comm, flag, new_rank, &sub_comm);
112
113 if(rank == 0)
114 std::cout << std::endl << "Created sub communicator with stride of " << n << std::endl;
115#else
116 sub_comm = mpi_comm;
117#endif
118
119 std::string input_file;
120
121 if(argc == 1)
122 {
123 if(dealii::Utilities::MPI::this_mpi_process(mpi_comm) == 0)
124 {
125 // clang-format off
126 std::cout << "To run the program, use: ./solver input_file" << std::endl
127 << "To setup the input file, use: ./solver input_file --help" << std::endl;
128 // clang-format on
129 }
130
131 return 0;
132 }
133 else if(argc >= 2)
134 {
135 input_file = std::string(argv[1]);
136
137 if(argc == 3 and std::string(argv[2]) == "--help")
138 {
139 if(dealii::Utilities::MPI::this_mpi_process(mpi_comm) == 0)
140 ExaDG::create_input_file(input_file);
141
142 return 0;
143 }
144 }
145
146 ExaDG::GeneralParameters general(input_file);
148 ExaDG::TemporalResolutionParameters temporal(input_file);
149
150 // k-refinement
151 for(unsigned int degree = spatial.degree_min; degree <= spatial.degree_max; ++degree)
152 {
153 // h-refinement
154 for(unsigned int refine_space = spatial.refine_space_min;
155 refine_space <= spatial.refine_space_max;
156 ++refine_space)
157 {
158 // dt-refinement
159 for(unsigned int refine_time = temporal.refine_time_min;
160 refine_time <= temporal.refine_time_max;
161 ++refine_time)
162 {
163 // run the simulation
164 if(general.dim == 2 and general.precision == "float")
165 {
166 ExaDG::run<2, float>(
167 input_file, degree, refine_space, refine_time, sub_comm, general.is_test);
168 }
169 else if(general.dim == 2 and general.precision == "double")
170 {
171 ExaDG::run<2, double>(
172 input_file, degree, refine_space, refine_time, sub_comm, general.is_test);
173 }
174 else if(general.dim == 3 and general.precision == "float")
175 {
176 ExaDG::run<3, float>(
177 input_file, degree, refine_space, refine_time, sub_comm, general.is_test);
178 }
179 else if(general.dim == 3 and general.precision == "double")
180 {
181 ExaDG::run<3, double>(
182 input_file, degree, refine_space, refine_time, sub_comm, general.is_test);
183 }
184 else
185 {
186 AssertThrow(
187 false, dealii::ExcMessage("Only dim = 2|3 and precision = float|double implemented."));
188 }
189 }
190 }
191 }
192
193#ifdef USE_SUB_COMMUNICATOR
194 // free communicator
195 MPI_Comm_free(&sub_comm);
196#endif
197
198 return 0;
199}
200
201#endif /* EXADG_INCOMPRESSIBLE_NAVIER_STOKES_SOLVER_H_ */
Definition driver.cpp:33
Definition general_parameters.h:34
Definition resolution_parameters.h:34
Definition resolution_parameters.h:34