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 // globals
41 namespace opencarp {
42 namespace user_globals {
46  std::map<mesh_t, sf_mesh> mesh_reg;
48  std::map<SF::quadruple<int>, SF::index_mapping<int> > map_reg;
50  std::map<physic_t, Basic_physic*> physics_reg;
54  std::map<datavec_t, sf_vec*> datavec_reg;
56  FILE* petsc_error_fd = NULL;
58  bool using_legacy_stimuli = false;
60  MPI_Comm IO_Intercomm;
61 } // namespace user_globals
62 } // namespace opencarp
63 
64 using namespace opencarp;
65 
66 #undef __FUNCT__
67 #define __FUNCT__ "main"
68 int main(int argc, char** argv)
69 {
70 // #ifdef __osf__
71 // signal( SIGFPE, SIG_IGN );
72 // #endif
73 // signal( SIGHUP, savequit );
74 // signal( SIGINT, savequit );
75 // signal( SIGQUIT, savequit );
76 // signal( SIGIO, savequit );
77 
78  //omp_set_num_threads(20);
79 
80  parse_params_cpy(argc, argv);
81 
82  // This is called intentionally before MPI_Init(), which might be helpful
83  // in an HPC context, where a script might call this without mpirun on the master.
84  // Still, in a parallel run we dont want every rank to print the build info,
85  // as this is quite spammy. Therefore, // we call show_build_info() a second time
86  // after MPI_Init, but only on rank 0.
87  if(param_globals::buildinfo) {
89  exit(EXIT_SUCCESS);
90  }
91 
92  char *DBfile = NULL; // could be used to pass in ~/.petscrc
93  char *help_msg = NULL;
94  initialize_PETSc(&argc, argv, DBfile, help_msg);
95 
96  if(get_rank() == 0)
98 
99  bool io_rank = setup_IO(argc, argv);
100 
101  if(!io_rank) {
103 
104  // accumulate check and conversions of param globals in here, so that
105  // the rest of the codebase can remain stateless
107 
108  // set up meshes
110  setup_meshes();
111  output_meshes();
112 
113  // for experiment EXP_SETUP_MESH we quit after the mesh output step
114  if(param_globals::experiment == EXP_SETUP_MESH)
116 
117  // convert input to internal units
119 
120  // register and initialize physics
123 
124  // for experiment EXP_OUTPUT_FEM we quit after the electrics initialization
125  if(param_globals::experiment == EXP_OUTPUT_FEM)
127 
128  // simulate
129  if(param_globals::experiment == EXP_NORMAL)
130  simulate();
131 
132  post_process();
133 
134  if(param_globals::num_io_nodes > 0)
136 
138  } else {
139  async::async_IO_queue queue;
141 
142  PetscFinalize();
143  exit(EXIT_SUCCESS);
144  }
145 }
146 
void register_physics()
Register physics to the physics registry.
Definition: sim_utils.cc:89
std::map< physic_t, Basic_physic * > physics_reg
the physics
Definition: main.cc:50
#define EXP_SETUP_MESH
Definition: sim_utils.h:159
std::map< mesh_t, sf_mesh > mesh_reg
Registry for the different meshes used in a multi-physics simulation.
Definition: main.cc:46
void simulate()
Main simulate loop.
Definition: sim_utils.cc:754
void post_process()
do postprocessing
Definition: sim_utils.cc:802
#define EXP_NORMAL
Definition: sim_utils.h:156
timer_manager * tm_manager
a manager for the various physics timers
Definition: main.cc:52
void setup_petsc_err_log()
set up error logs for PETSc, so that it doesnt print errors to stderr.
Definition: sim_utils.cc:1240
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
void initialize_physics()
Initialize all physics in the registry.
Definition: sim_utils.cc:100
Top-level header file of numerics module.
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:227
bool setup_IO(int argc, char **argv)
Definition: sim_utils.cc:388
bool using_legacy_stimuli
flag storing whether legacy stimuli are used
Definition: main.cc:58
FILE * petsc_error_fd
file descriptor for petsc error output
Definition: main.cc:56
Async IO functions.
std::map< SF::quadruple< int >, SF::index_mapping< int > > map_reg
Registriy for the inter domain mappings.
Definition: main.cc:48
void cleanup_and_exit()
Definition: sim_utils.cc:1216
Top-level header of FEM module.
void parse_mesh_types()
Parse the phys_type CLI parameters and set up (empty) SF::meshdata meshes.
Definition: sim_utils.cc:854
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 basic_timer_setup()
Here we set up the timers that we always want to have, independent of physics.
Definition: sim_utils.cc:458
void setup_meshes()
Read in the reference mesh and use its data to populate all meshes registered in the mesh registry...
Definition: sim_utils.cc:986
void show_build_info()
show the build info, exit if -buildinfo was provided. This code runs before MPI_Init().
Definition: sim_utils.cc:219
int main(int argc, char **argv)
Definition: main.cc:68
void output_meshes()
Definition: sim_utils.cc:1164
MPI_Comm IO_Intercomm
Communicator between IO and compute worlds.
Definition: main.cc:60
Index mapping class. This is a bijective mapping.
Definition: SF_container.h:207
#define EXP_OUTPUT_FEM
Definition: sim_utils.h:157
std::map< datavec_t, sf_vec * > datavec_reg
important solution vectors from different physics
Definition: main.cc:54
centralize time managment and output triggering
Definition: timer_utils.h:73
int get_rank(MPI_Comm comm=PETSC_COMM_WORLD)
Definition: basics.h:276
SF::scatter_registry scatter_reg
Registry for the different scatter objects.
Definition: main.cc:44
The scatterer registry class.
queue with the data required for performing async IO writes to IGB
Definition: async_io.h:55