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_INCOMPRESSIBLE_NAVIER_STOKES_SOLVER_PRECURSOR_H_
23#define INCLUDE_EXADG_INCOMPRESSIBLE_NAVIER_STOKES_SOLVER_PRECURSOR_H_
24
25// deal.II
26#include <deal.II/base/parameter_handler.h>
27
28// ExaDG
29#include <exadg/utilities/enum_patterns.h>
30
31// driver
32#include <exadg/incompressible_navier_stokes/precursor/driver.h>
33
34// utilities
35#include <exadg/utilities/general_parameters.h>
36
37// application
38#include <exadg/incompressible_navier_stokes/precursor/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 // we have to assume a default dimension and default Number type
51 // for the automatic generation of a default input file
52 unsigned int const Dim = 2;
53 typedef double Number;
54 IncNS::Precursor::get_application<Dim, Number>(input_file, MPI_COMM_WORLD)->add_parameters(prm);
55
56 prm.print_parameters(input_file,
57 dealii::ParameterHandler::Short |
58 dealii::ParameterHandler::KeepDeclarationOrder);
59}
60
61template<int dim, typename Number>
62void
63run(std::string const & input_file, MPI_Comm const & mpi_comm, bool const is_test)
64{
65 dealii::Timer timer;
66 timer.restart();
67
68 std::shared_ptr<IncNS::Precursor::ApplicationBase<dim, Number>> application =
69 IncNS::Precursor::get_application<dim, Number>(input_file, mpi_comm);
70
71 std::shared_ptr<IncNS::Precursor::Driver<dim, Number>> driver =
72 std::make_shared<IncNS::Precursor::Driver<dim, Number>>(mpi_comm, application, is_test);
73
74 driver->setup();
75
76 driver->solve();
77
78 if(not(is_test))
79 driver->print_performance_results(timer.wall_time());
80}
81} // namespace ExaDG
82
83int
84main(int argc, char ** argv)
85{
86 dealii::Utilities::MPI::MPI_InitFinalize mpi(argc, argv, 1);
87
88 MPI_Comm mpi_comm(MPI_COMM_WORLD);
89
90 std::string input_file;
91
92 if(argc == 1)
93 {
94 if(dealii::Utilities::MPI::this_mpi_process(mpi_comm) == 0)
95 {
96 // clang-format off
97 std::cout << "To run the program, use: ./solver_precursor input_file" << std::endl
98 << "To setup the input file, use: ./solver_precursor input_file --help" << std::endl;
99 // clang-format on
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);
118
119 // run the simulation
120 if(general.dim == 2 and general.precision == "float")
121 {
122 ExaDG::run<2, float>(input_file, mpi_comm, general.is_test);
123 }
124 else if(general.dim == 2 and general.precision == "double")
125 {
126 ExaDG::run<2, double>(input_file, mpi_comm, general.is_test);
127 }
128 else if(general.dim == 3 and general.precision == "float")
129 {
130 ExaDG::run<3, float>(input_file, mpi_comm, general.is_test);
131 }
132 else if(general.dim == 3 and general.precision == "double")
133 {
134 ExaDG::run<3, double>(input_file, mpi_comm, general.is_test);
135 }
136 else
137 {
138 AssertThrow(false,
139 dealii::ExcMessage("Only dim = 2|3 and precision = float|double implemented."));
140 }
141
142 return 0;
143}
144
145#endif /* INCLUDE_EXADG_INCOMPRESSIBLE_NAVIER_STOKES_SOLVER_PRECURSOR_H_ */
Definition driver.cpp:33
Definition general_parameters.h:32