-
Notifications
You must be signed in to change notification settings - Fork 2
/
cosmo.cc
executable file
·96 lines (85 loc) · 2.18 KB
/
cosmo.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include "cosmo_includes.h"
#include "cosmo_types.h"
#include "cosmo_globals.h"
#include "sims/sim.h"
#include "sims/dust.h"
#include "sims/static.h"
#include "sims/particles.h"
#include "sims/scalar.h"
#include "sims/vacuum.h"
#include "sims/sheets.h"
using namespace std;
using namespace cosmo;
/* global definitions */
TimerManager _timer;
ConfigParser _config;
#ifndef dt
real_t dt;
#endif
#ifndef dx
real_t dx;
#endif
int main(int argc, char **argv)
{
// read in config file
if(argc != 2)
{
std::cout << "Error: please supply exactly one config filename as an argument.\n";
return EXIT_FAILURE;
}
// TODO: eliminate global _config; feed directly into constructor.
_config.parse(argv[1]);
// If not compiled in, set dt, dx
// TODO: set other things (and check for performance hits)
// set these in config file?
// big performance hit setting N dynamically, should deal with BCs separately.
dx = stold(_config( "dx", stringify(H_LEN_FRAC/(1.0*COSMO_N)) ));
dt = stold(_config( "dt_frac", "0.1" ))*dx;
// Set number of threads - only if specified
// Otherwise, OMP_NUM_THREADS or openmp default should be used.
int num_threads = stoi(_config("omp_num_threads", "0"));
if(num_threads > 0)
omp_set_num_threads(num_threads);
// Create simulation according to simulation_type
CosmoSim * cosmoSim;
std::string simulation_type = _config["simulation_type"];
if( simulation_type == "dust" )
{
cosmoSim = new DustSim();
}
else if( simulation_type == "static" )
{
cosmoSim = new StaticSim();
}
else if( simulation_type == "particles" )
{
cosmoSim = new ParticleSim();
}
else if( simulation_type == "scalar" )
{
cosmoSim = new ScalarSim();
}
else if( simulation_type == "vacuum" )
{
cosmoSim = new VacuumSim();
}
else if( simulation_type == "sheets")
{
cosmoSim = new SheetSim();
}
else
{
std::cerr << "Invalid simulation type specified. ";
throw 2;
}
// Initialize simulation
cosmoSim->init();
// Generate initial conditions
_timer["ICs"].start();
cosmoSim->setICs();
_timer["ICs"].stop();
// Run simulation
cosmoSim->run();
delete cosmoSim;
return EXIT_SUCCESS;
}