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 #ifdef WITH_POWERCAPPING
69  powercapping_manager *pc_manager;
70 #endif
71 } // namespace user_globals
72 } // namespace opencarp
73 
74 using namespace opencarp;
75 
76 #undef __FUNCT__
77 #define __FUNCT__ "main"
78 int main(int argc, char** argv)
79 {
81 // #ifdef __osf__
82 // signal( SIGFPE, SIG_IGN );
83 // #endif
84 // signal( SIGHUP, savequit );
85 // signal( SIGINT, savequit );
86 // signal( SIGQUIT, savequit );
87 // signal( SIGIO, savequit );
88 
89  //omp_set_num_threads(20);
90 
91  parse_params_cpy(argc, argv);
92 
93  // This is called intentionally before MPI_Init(), which might be helpful
94  // in an HPC context, where a script might call this without mpirun on the master.
95  // Still, in a parallel run we dont want every rank to print the build info,
96  // as this is quite spammy. Therefore, // we call show_build_info() a second time
97  // after MPI_Init, but only on rank 0.
98  if(param_globals::buildinfo) {
100  exit(EXIT_SUCCESS);
101  }
102 
103  char *DBfile = NULL; // could be used to pass in ~/.petscrc
104  char *help_msg = NULL;
105  initialize_PETSc(&argc, argv, DBfile, help_msg);
106 
107  if(get_rank() == 0)
108  show_build_info();
109 
110  bool io_rank = setup_IO(argc, argv);
111 
112  if(!io_rank) {
114 
115  // accumulate check and conversions of param globals in here, so that
116  // the rest of the codebase can remain stateless
118 
119  // set up meshes
121  bool require_fibers = phys_defined(PHYSREG_INTRA_ELEC) || phys_defined(PHYSREG_LAPLACE);
122  setup_meshes(require_fibers);
123  output_meshes();
124 
125  // for experiment EXP_SETUP_MESH we quit after the mesh output step
126  if(param_globals::experiment == EXP_SETUP_MESH)
128 
129  // convert input to internal unit
131 
132  // register and initialize physics
135 
136  // for experiment EXP_OUTPUT_FEM we quit after the electrics initialization
137  if(param_globals::experiment == EXP_OUTPUT_FEM)
139 
140  // simulate
141  if(param_globals::experiment == EXP_NORMAL){
142 simulate();
143  }
144 
145  post_process();
146 
147  if(param_globals::num_io_nodes > 0)
149 
151  } else {
152  async::async_IO_queue queue;
154 
155  PetscFinalize();
156  exit(EXIT_SUCCESS);
157  }
158 }
159 
Async IO functions.
#define CALI_CXX_MARK_FUNCTION
Definition: caliper_hooks.h:5
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:78
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:114
bool setup_IO(int argc, char **argv)
Definition: sim_utils.cc:436
void parse_params_cpy(int argc, char **argv)
Initialize input parameters on a copy of the real command line parameters.
Definition: sim_utils.cc:50
void cleanup_and_exit()
Definition: sim_utils.cc:1304
void register_physics()
Register physics to the physics registry.
Definition: sim_utils.cc:93
void post_process()
do postprocessing
Definition: sim_utils.cc:885
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:241
int get_rank(MPI_Comm comm=PETSC_COMM_WORLD)
Definition: basics.h:292
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:233
void basic_timer_setup()
Here we set up the timers that we always want to have, independent of physics.
Definition: sim_utils.cc:506
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:1072
void output_meshes()
Definition: sim_utils.cc:1252
void setup_petsc_err_log()
set up error logs for PETSc, so that it doesnt print errors to stderr.
Definition: sim_utils.cc:1328
void simulate()
Main simulate loop.
Definition: sim_utils.cc:809
void parse_mesh_types()
Parse the phys_type CLI parameters and set up (empty) SF::meshdata meshes.
Definition: sim_utils.cc:937
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:169
#define EXP_SETUP_MESH
Definition: sim_utils.h:171
#define EXP_NORMAL
Definition: sim_utils.h:168
queue with the data required for performing async IO writes to IGB
Definition: async_io.h:55