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 // we set PrMGLOBAL ONLY ONCE. this will initialize the global variables
32 // in only one compilation unit
33 #define PrMGLOBAL
34 #include "simulator.h"
35 #include "async_io.h"
36 #include "numerics.h"
37 #include "fem.h"
38 
39 
40 #ifdef WITH_CALIPER
41 #include "caliper/cali.h"
42 #else
43 #include "caliper_hooks.h"
44 #endif
45 
46 // globals
47 namespace opencarp {
48 namespace user_globals {
52  std::map<mesh_t, sf_mesh> mesh_reg;
54  std::map<SF::quadruple<int>, SF::index_mapping<int> > map_reg;
56  std::map<physic_t, Basic_physic*> physics_reg;
60  std::map<datavec_t, sf_vec*> datavec_reg;
62  FILE* petsc_error_fd = NULL;
64  bool using_legacy_stimuli = false;
66  MPI_Comm IO_Intercomm;
67 } // namespace user_globals
68 } // namespace opencarp
69 
70 using namespace opencarp;
71 
72 #undef __FUNCT__
73 #define __FUNCT__ "main"
74 int main(int argc, char** argv)
75 {
77 // #ifdef __osf__
78 // signal( SIGFPE, SIG_IGN );
79 // #endif
80 // signal( SIGHUP, savequit );
81 // signal( SIGINT, savequit );
82 // signal( SIGQUIT, savequit );
83 // signal( SIGIO, savequit );
84 
85  //omp_set_num_threads(20);
86 
87  parse_params_cpy(argc, argv);
88 
89  // This is called intentionally before MPI_Init(), which might be helpful
90  // in an HPC context, where a script might call this without mpirun on the master.
91  // Still, in a parallel run we dont want every rank to print the build info,
92  // as this is quite spammy. Therefore, // we call show_build_info() a second time
93  // after MPI_Init, but only on rank 0.
94  if(param_globals::buildinfo) {
96  exit(EXIT_SUCCESS);
97  }
98 
99  char *DBfile = NULL; // could be used to pass in ~/.petscrc
100  char *help_msg = NULL;
101  initialize_PETSc(&argc, argv, DBfile, help_msg);
102 
103  if(get_rank() == 0)
104  show_build_info();
105 
106  bool io_rank = setup_IO(argc, argv);
107 
108  if(!io_rank) {
110 
111  // accumulate check and conversions of param globals in here, so that
112  // the rest of the codebase can remain stateless
114 
115  // set up meshes
117  bool require_fibers = phys_defined(PHYSREG_INTRA_ELEC) || phys_defined(PHYSREG_LAPLACE);
118  setup_meshes(require_fibers);
119  output_meshes();
120 
121  // for experiment EXP_SETUP_MESH we quit after the mesh output step
122  if(param_globals::experiment == EXP_SETUP_MESH)
124 
125  // convert input to internal unit
127 
128  // register and initialize physics
131 
132  // for experiment EXP_OUTPUT_FEM we quit after the electrics initialization
133  if(param_globals::experiment == EXP_OUTPUT_FEM)
135 
136  // simulate
137  if(param_globals::experiment == EXP_NORMAL){
138 simulate();
139  }
140 
141  post_process();
142 
143  if(param_globals::num_io_nodes > 0)
145 
147  } else {
148  async::async_IO_queue queue;
150 
151  PetscFinalize();
152  exit(EXIT_SUCCESS);
153  }
154 }
155 
Async IO functions.
#define CALI_CXX_MARK_FUNCTION
Definition: caliper_hooks.h:6
Index mapping class. This is a bijective mapping.
Definition: SF_container.h:220
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:74
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:66
FILE * petsc_error_fd
file descriptor for petsc error output
Definition: main.cc:62
timer_manager * tm_manager
a manager for the various physics timers
Definition: main.cc:58
std::map< datavec_t, sf_vec * > datavec_reg
important solution vectors from different physics
Definition: main.cc:60
std::map< SF::quadruple< int >, SF::index_mapping< int > > map_reg
Registriy for the inter domain mappings.
Definition: main.cc:54
bool using_legacy_stimuli
flag storing whether legacy stimuli are used
Definition: main.cc:64
SF::scatter_registry scatter_reg
Registry for the different scatter objects.
Definition: main.cc:50
std::map< mesh_t, sf_mesh > mesh_reg
Registry for the different meshes used in a multi-physics simulation.
Definition: main.cc:52
std::map< physic_t, Basic_physic * > physics_reg
the physics
Definition: main.cc:56
void initialize_physics()
Initialize all physics in the registry.
Definition: sim_utils.cc:110
bool setup_IO(int argc, char **argv)
Definition: sim_utils.cc:432
void parse_params_cpy(int argc, char **argv)
Initialize input parameters on a copy of the real command line parameters.
Definition: sim_utils.cc:46
void cleanup_and_exit()
Definition: sim_utils.cc:1274
void register_physics()
Register physics to the physics registry.
Definition: sim_utils.cc:89
void post_process()
do postprocessing
Definition: sim_utils.cc:855
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:237
int get_rank(MPI_Comm comm=PETSC_COMM_WORLD)
Definition: basics.h:276
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:229
void basic_timer_setup()
Here we set up the timers that we always want to have, independent of physics.
Definition: sim_utils.cc:502
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:1042
void output_meshes()
Definition: sim_utils.cc:1222
void setup_petsc_err_log()
set up error logs for PETSc, so that it doesnt print errors to stderr.
Definition: sim_utils.cc:1298
void simulate()
Main simulate loop.
Definition: sim_utils.cc:798
void parse_mesh_types()
Parse the phys_type CLI parameters and set up (empty) SF::meshdata meshes.
Definition: sim_utils.cc:907
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:159
#define EXP_SETUP_MESH
Definition: sim_utils.h:161
#define EXP_NORMAL
Definition: sim_utils.h:158
queue with the data required for performing async IO writes to IGB
Definition: async_io.h:55