ExaDG
Loading...
Searching...
No Matches
solver.h
1/* ______________________________________________________________________
2 *
3 * ExaDG - High-Order Discontinuous Galerkin for the Exa-Scale
4 *
5 * Copyright (C) 2022 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_FLUID_STRUCTURE_INTERACTION_PRECICE_SOLVER_H_
23#define INCLUDE_EXADG_FLUID_STRUCTURE_INTERACTION_PRECICE_SOLVER_H_
24
25// deal.II
26#include <deal.II/base/parameter_handler.h>
27
28// ExaDG
29#include <exadg/fluid_structure_interaction/precice/driver.h>
30#include <exadg/fluid_structure_interaction/precice/driver_fluid.h>
31#include <exadg/fluid_structure_interaction/precice/driver_solid.h>
32#include <exadg/fluid_structure_interaction/user_interface/declare_get_application.h>
33#include <exadg/utilities/enum_patterns.h>
34#include <exadg/utilities/general_parameters.h>
35
36namespace ExaDG
37{
38void
39create_input_file(std::string const & input_file)
40{
41 dealii::ParameterHandler prm;
42
43 GeneralParameters general;
44 general.add_parameters(prm);
45
46 preCICE::ConfigurationParameters precice_parameters;
47 precice_parameters.add_parameters(prm);
48
49 // we have to assume a default dimension and default Number type
50 // for the automatic generation of a default input file
51 constexpr int Dim = 2;
52 using Number = double;
53
54 FSI::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
61
62template<int dim, typename Number>
63void
64run(std::string const & input_file, MPI_Comm const & mpi_comm, bool const is_test)
65{
66 dealii::Timer timer;
67 timer.restart();
68
69 std::shared_ptr<FSI::ApplicationBase<dim, Number>> application =
70 FSI::get_application<dim, Number>(input_file, mpi_comm);
71
72
73 preCICE::ConfigurationParameters precice_param(input_file);
74 std::shared_ptr<FSI::preCICE::Driver<dim, Number>> driver;
75
76 // We have different drivers for Fluid and Solid since the data exchange and underlying
77 // configuration are different. However, both solver share a common base class. One could also
78 // compile different executables for both solvers or try to create a common Driver class for both
79 // parts.
80 if(precice_param.physics == "Structure")
81 {
82 driver = std::make_shared<FSI::preCICE::DriverSolid<dim, Number>>(input_file,
83 mpi_comm,
84 application,
85 is_test);
86 }
87 else if(precice_param.physics == "Fluid")
88 {
89 driver = std::make_shared<FSI::preCICE::DriverFluid<dim, Number>>(input_file,
90 mpi_comm,
91 application,
92 is_test);
93 }
94 else
95 {
96 AssertThrow(false,
97 dealii::ExcMessage("precice_param.physics has to be \"Structure\" or \"Fluid\""));
98 }
99
100 driver->setup();
101 driver->solve();
102
103 if(not is_test)
104 driver->print_performance_results(timer.wall_time());
105}
106} // namespace ExaDG
107
108
109// The preCICE coupled executable is called solver_precice and we compile the Solid and the Fluid
110// Driver into the same executable. Configuration can be done via individual parameter files.
111int
112main(int argc, char ** argv)
113{
114 dealii::Utilities::MPI::MPI_InitFinalize mpi(argc, argv, 1);
115
116 MPI_Comm mpi_comm(MPI_COMM_WORLD);
117
118 std::string input_file;
119
120 if(argc == 1)
121 {
122 if(dealii::Utilities::MPI::this_mpi_process(mpi_comm) == 0)
123 {
124 // clang-format off
125 std::cout << "To run the program, use: ./solver input_file" << std::endl
126 << "To setup the input file, use: ./solver input_file --help" << std::endl;
127 // clang-format on
128 }
129
130 return EXIT_SUCCESS;
131 }
132 else if(argc >= 2)
133 {
134 input_file = std::string(argv[1]);
135
136 if(argc == 3 and std::string(argv[2]) == "--help")
137 {
138 if(dealii::Utilities::MPI::this_mpi_process(mpi_comm) == 0)
139 ExaDG::create_input_file(input_file);
140
141 return EXIT_SUCCESS;
142 }
143 }
144
145 ExaDG::GeneralParameters general(input_file);
146
147 // run the simulation
148 if(general.dim == 2 and general.precision == "double")
149 ExaDG::run<2, double>(input_file, mpi_comm, general.is_test);
150 else if(general.dim == 3 and general.precision == "double")
151 ExaDG::run<3, double>(input_file, mpi_comm, general.is_test);
152 else
153 AssertThrow(false, dealii::ExcMessage("Only dim = 2|3 and precision=double implemented."));
154
155 return EXIT_SUCCESS;
156}
157
158#endif /* INCLUDE_EXADG_FLUID_STRUCTURE_INTERACTION_SOLVER_H_ */
Definition driver.cpp:33
Definition general_parameters.h:32