openCARP
Doxygen code documentation for the open cardiac electrophysiology simulator openCARP
main.cc
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // openCARP is an open cardiac electrophysiology simulator.
3 //
4 // Copyright (C) 2020 openCARP project
5 //
6 // This program is licensed under the openCARP Academic Public License (APL)
7 // v1.0: You can use and redistribute it and/or modify it in non-commercial
8 // academic environments under the terms of APL as published by the openCARP
9 // project v1.0, or (at your option) any later version. Commercial use requires
10 // a commercial license (info@opencarp.org).
11 //
12 // This program is distributed without any warranty; see the openCARP APL for
13 // more details.
14 //
15 // You should have received a copy of the openCARP APL along with this program
16 // and can find it online: http://www.opencarp.org/license
17 // ----------------------------------------------------------------------------
18 
27 #include <cstdio>
28 #include <csignal>
29 
30 //#include <omp.h>
31 #include "simulator.h"
32 #include "async_io.h"
33 #include "numerics.h"
34 #include "fem.h"
35 
36 
37 #ifdef WITH_CALIPER
38 #include "caliper/cali.h"
39 #else
40 #include "caliper_hooks.h"
41 #endif
42 
43 // globals
44 namespace opencarp {
45 namespace user_globals {
49  std::map<mesh_t, sf_mesh> mesh_reg;
51  std::map<SF::quadruple<int>, SF::index_mapping<mesh_int_t> > map_reg;
53  std::map<physic_t, Basic_physic*> physics_reg;
57  std::map<datavec_t, sf_vec*> datavec_reg;
59  FILE* petsc_error_fd = NULL;
61  bool using_legacy_stimuli = false;
63  MPI_Comm IO_Intercomm;
64 #ifdef WITH_POWERCAPPING
66  powercapping_manager *pc_manager;
67 #endif
68 } // namespace user_globals
69 } // namespace opencarp
70 
71 using namespace opencarp;
72 
73 #undef __FUNCT__
74 #define __FUNCT__ "main"
75 int main(int argc, char** argv)
76 {
78 // #ifdef __osf__
79 // signal( SIGFPE, SIG_IGN );
80 // #endif
81 // signal( SIGHUP, savequit );
82 // signal( SIGINT, savequit );
83 // signal( SIGQUIT, savequit );
84 // signal( SIGIO, savequit );
85 
86  //omp_set_num_threads(20);
87 
88  parse_params_cpy(argc, argv);
89 
90  // This is called intentionally before MPI_Init(), which might be helpful
91  // in an HPC context, where a script might call this without mpirun on the master.
92  // Still, in a parallel run we dont want every rank to print the build info,
93  // as this is quite spammy. Therefore, // we call show_build_info() a second time
94  // after MPI_Init, but only on rank 0.
95  if(param_globals::buildinfo) {
97  exit(EXIT_SUCCESS);
98  }
99 
100  char *DBfile = NULL; // could be used to pass in ~/.petscrc
101  char *help_msg = NULL;
102  initialize_PETSc(&argc, argv, DBfile, help_msg);
103 
104  if(get_rank() == 0)
105  show_build_info();
106 
107  bool io_rank = setup_IO(argc, argv);
108 
109  if(!io_rank) {
111 
112  // accumulate check and conversions of param globals in here, so that
113  // the rest of the codebase can remain stateless
115 
116  // set up meshes
118  bool require_fibers = phys_defined(PHYSREG_INTRA_ELEC) || phys_defined(PHYSREG_LAPLACE);
119  setup_meshes(require_fibers);
120  output_meshes();
121 
122  // for experiment EXP_SETUP_MESH we quit after the mesh output step
123  if(param_globals::experiment == EXP_SETUP_MESH)
125 
126  // convert input to internal unit
128 
129  // register and initialize physics
132 
133  // for experiment EXP_OUTPUT_FEM we quit after the electrics initialization
134  if(param_globals::experiment == EXP_OUTPUT_FEM)
136 
137  // simulate
138  if(param_globals::experiment == EXP_NORMAL){
139 simulate();
140  }
141 
142  post_process();
143 
144  if(param_globals::num_io_nodes > 0)
146 
148  } else {
149  async::async_IO_queue queue;
151 
152  PetscFinalize();
153  exit(EXIT_SUCCESS);
154  }
155 }
Async IO functions.
#define CALI_CXX_MARK_FUNCTION
Definition: caliper_hooks.h:5
The scatterer registry class.
centralize time managment and output triggering
Definition: timer_utils.h:73
Top-level header of FEM module.
int main(int argc, char **argv)
Definition: main.cc:75
void COMPUTE_send_exit_flag()
this function sends the exit flag from a compute node to an io node.
Definition: async_io.cc:94
void IO_poll_for_output(async_IO_queue &io_queue)
Definition: async_io.cc:36
MPI_Comm IO_Intercomm
Communicator between IO and compute worlds.
Definition: main.cc:63
FILE * petsc_error_fd
file descriptor for petsc error output
Definition: main.cc:59
timer_manager * tm_manager
a manager for the various physics timers
Definition: main.cc:55
std::map< datavec_t, sf_vec * > datavec_reg
important solution vectors from different physics
Definition: main.cc:57
std::map< SF::quadruple< int >, SF::index_mapping< mesh_int_t > > map_reg
Registriy for the inter domain mappings.
Definition: main.cc:51
bool using_legacy_stimuli
flag storing whether legacy stimuli are used
Definition: main.cc:61
SF::scatter_registry scatter_reg
Registry for the different scatter objects.
Definition: main.cc:47
std::map< mesh_t, sf_mesh > mesh_reg
Registry for the different meshes used in a multi-physics simulation.
Definition: main.cc:49
std::map< physic_t, Basic_physic * > physics_reg
the physics
Definition: main.cc:53
void initialize_physics()
Initialize all physics in the registry.
Definition: sim_utils.cc:1203
bool setup_IO(int argc, char **argv)
Definition: sim_utils.cc:1525
void parse_params_cpy(int argc, char **argv)
Initialize input parameters on a copy of the real command line parameters.
Definition: sim_utils.cc:1134
void cleanup_and_exit()
Definition: sim_utils.cc:2617
void register_physics()
Register physics to the physics registry.
Definition: sim_utils.cc:1181
void post_process()
do postprocessing
Definition: sim_utils.cc:1992
void check_and_convert_params()
Here we want to put all parameter checks, conversions and modifications that have been littered throu...
Definition: sim_utils.cc:1330
int get_rank(MPI_Comm comm=PETSC_COMM_WORLD)
Definition: basics.h:284
bool phys_defined(int physreg)
function to check if certain physics are defined
void show_build_info()
show the build info, exit if -buildinfo was provided. This code runs before MPI_Init().
Definition: sim_utils.cc:1318
void basic_timer_setup()
Here we set up the timers that we always want to have, independent of physics.
Definition: sim_utils.cc:1595
void setup_meshes(bool require_fibers=true)
Read in the reference mesh and use its data to populate all meshes registered in the mesh registry.
Definition: sim_utils.cc:2202
void output_meshes()
Definition: sim_utils.cc:2520
void setup_petsc_err_log()
set up error logs for PETSc, so that it doesnt print errors to stderr.
Definition: sim_utils.cc:2644
void simulate()
Main simulate loop.
Definition: sim_utils.cc:1905
void parse_mesh_types()
Parse the phys_type CLI parameters and set up (empty) SF::meshdata meshes.
Definition: sim_utils.cc:2067
Top-level header file of numerics module.
#define PHYSREG_INTRA_ELEC
Definition: sf_interface.h:84
#define PHYSREG_LAPLACE
Definition: sf_interface.h:89
#define EXP_OUTPUT_FEM
Definition: sim_utils.h:204
#define EXP_SETUP_MESH
Definition: sim_utils.h:206
#define EXP_NORMAL
Definition: sim_utils.h:203
queue with the data required for performing async IO writes to IGB
Definition: async_io.h:55