Fluid structure interaction suite
runner.h
Go to the documentation of this file.
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2022 by Luca Heltai
4 //
5 // This file is part of the FSI-suite platform, based on the deal.II library.
6 //
7 // The FSI-suite platform is free software; you can use it, redistribute it,
8 // and/or modify it under the terms of the GNU Lesser General Public License as
9 // published by the Free Software Foundation; either version 3.0 of the License,
10 // or (at your option) any later version. The full text of the license can be
11 // found in the file LICENSE at the top level of the FSI-suite platform
12 // distribution.
13 //
14 // ---------------------------------------------------------------------
15 
16 #ifndef fsi_runner_h
17 #define fsi_runner_h
18 
19 #include <deal.II/base/utilities.h>
20 
25 namespace Runner
26 {
102  std::tuple<int, int, std::string, std::string>
104 
204  int
205  setup_parameters_from_cli(char **argv,
206  const std::string &input_parameter_file,
207  const std::string &output_parameter_file);
208 
217  template <typename Class>
218  void
219  run(char **argv,
220  const std::string &input_parameter_file,
221  const std::string &output_parameter_file)
222  {
223  Class class_name;
224  if (setup_parameters_from_cli(argv,
225  input_parameter_file,
226  output_parameter_file) == -1)
227  return;
228  class_name.run();
229  }
230 } // namespace Runner
231 
232 #ifndef DOXYGEN
233 
234 # define RUN_CODIM_NO_ONE(Class, dim, spacedim, in_file, out_file) \
235  if (dim == 2 && spacedim == 3) \
236  Runner::run<Class<2, 3>>(argv, in_file, out_file);
237 
238 # define RUN_CODIM(Class, dim, spacedim, in_file, out_file) \
239  if (dim == 1 && spacedim == 2) \
240  Runner::run<Class<1, 2>>(argv, in_file, out_file); \
241  else \
242  RUN_CODIM_NO_ONE(Class, dim, spacedim, in_file, out_file)
243 
244 # define RUN_DIM_NO_ONE(Class, dim, spacedim, in_file, out_file) \
245  if (dim == 2 && spacedim == 2) \
246  Runner::run<Class<2>>(argv, in_file, out_file); \
247  else if (dim == 3 && spacedim == 3) \
248  Runner::run<Class<3>>(argv, in_file, out_file);
249 
250 # define RUN_DIM(Class, dim, spacedim, in_file, out_file) \
251  if (dim == 1 && spacedim == 1) \
252  Runner::run<Class<1>>(argv, in_file, out_file); \
253  else \
254  RUN_DIM_NO_ONE(Class, dim, spacedim, in_file, out_file)
255 
256 // Standard catch block for all snippets
257 # define STANDARD_CATCH() \
258  catch (std::exception & exc) \
259  { \
260  std::cerr << std::endl \
261  << std::endl \
262  << "----------------------------------------------------" \
263  << std::endl; \
264  std::cerr << "Exception on processing: " << std::endl \
265  << exc.what() << std::endl \
266  << "Aborting!" << std::endl \
267  << "----------------------------------------------------" \
268  << std::endl; \
269  return 1; \
270  } \
271  catch (...) \
272  { \
273  std::cerr << std::endl \
274  << std::endl \
275  << "----------------------------------------------------" \
276  << std::endl; \
277  std::cerr << "Unknown exception!" << std::endl \
278  << "Aborting!" << std::endl \
279  << "----------------------------------------------------" \
280  << std::endl; \
281  return 1; \
282  }
283 
284 #endif
285 
286 
291 #define RUNNER_DIM(Class, argc, argv) \
292  try \
293  { \
294  dealii::Utilities::MPI::MPI_InitFinalize mpi_initialization(argc, \
295  argv, \
296  1); \
297  const auto [dim, spacedim, in_file, out_file] = \
298  Runner::get_dimensions_and_parameter_files(argv); \
299  RUN_DIM(Class, dim, spacedim, in_file, out_file) \
300  else AssertThrow(false, \
301  dealii::ExcImpossibleInDimSpacedim(dim, spacedim)); \
302  } \
303  STANDARD_CATCH()
304 
309 #define RUNNER_DIM_NO_ONE(Class, argc, argv) \
310  try \
311  { \
312  dealii::Utilities::MPI::MPI_InitFinalize mpi_initialization(argc, \
313  argv, \
314  1); \
315  const auto [dim, spacedim, in_file, out_file] = \
316  Runner::get_dimensions_and_parameter_files(argv); \
317  RUN_DIM_NO_ONE(Class, dim, spacedim, in_file, out_file) \
318  else AssertThrow(false, \
319  dealii::ExcImpossibleInDimSpacedim(dim, spacedim)); \
320  } \
321  STANDARD_CATCH()
322 
323 
328 #define RUNNER(Class, argc, argv) \
329  try \
330  { \
331  dealii::Utilities::MPI::MPI_InitFinalize mpi_initialization(argc, \
332  argv, \
333  1); \
334  const auto [dim, spacedim, in_file, out_file] = \
335  Runner::get_dimensions_and_parameter_files(argv); \
336  RUN_DIM(Class, dim, spacedim, in_file, out_file) \
337  else RUN_CODIM( \
338  Class, \
339  dim, \
340  spacedim, \
341  in_file, \
342  out_file) else AssertThrow(false, \
343  dealii::ExcImpossibleInDimSpacedim( \
344  dim, spacedim)); \
345  } \
346  STANDARD_CATCH()
347 
348 
354 #define RUNNER_NO_ONE(Class, argc, argv) \
355  try \
356  { \
357  dealii::Utilities::MPI::MPI_InitFinalize mpi_initialization(argc, \
358  argv, \
359  1); \
360  const auto [dim, spacedim, in_file, out_file] = \
361  Runner::get_dimensions_and_parameter_files(argv); \
362  RUN_DIM_NO_ONE(Class, dim, spacedim, in_file, out_file) \
363  else RUN_CODIM_NO_ONE( \
364  Class, \
365  dim, \
366  spacedim, \
367  in_file, \
368  out_file) else AssertThrow(false, \
369  dealii::ExcImpossibleInDimSpacedim( \
370  dim, spacedim)); \
371  } \
372  STANDARD_CATCH()
373 
374 
375 
381 #define RUNNER_CODIM(Class, argc, argv) \
382  try \
383  { \
384  dealii::Utilities::MPI::MPI_InitFinalize mpi_initialization(argc, \
385  argv, \
386  1); \
387  const auto [dim, spacedim, in_file, out_file] = \
388  Runner::get_dimensions_and_parameter_files(argv); \
389  RUN_DIM_NO_ONE(Class, dim, spacedim, in_file, out_file) \
390  else RUN_CODIM( \
391  Class, \
392  dim, \
393  spacedim, \
394  in_file, \
395  out_file) else AssertThrow(false, \
396  dealii::ExcImpossibleInDimSpacedim( \
397  dim, spacedim)); \
398  } \
399  STANDARD_CATCH()
400 #endif
Gather some functions and classes typically used in the main() of the FSI-suite applications.
Definition: runner.h:26
int setup_parameters_from_cli(char **argv, const std::string &input_parameter_file, const std::string &output_parameter_file)
Setup the ParameterAcceptor::prm according to the parameters specified in the parameter file,...
Definition: runner.cc:183
void run(char **argv, const std::string &input_parameter_file, const std::string &output_parameter_file)
Setup parameters from the command line, and call the Class::run() method.
Definition: runner.h:219
std::tuple< int, int, std::string, std::string > get_dimensions_and_parameter_files(char **argv)
Parse from the command line the parameter file names (both input and output) and the running dimensio...
Definition: runner.cc:89