-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdirector.cpp
98 lines (81 loc) · 3.79 KB
/
director.cpp
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
97
//WRITTEN BY: github.com/kgorze
#include "Headers/simulation/director.h"
// Handler for parsing INI file
static int handler(void* user, const char* section, const char* name, const char* value) {
std::unordered_map<std::string, std::string>* config =
reinterpret_cast<std::unordered_map<std::string, std::string>*>(user);
std::string key = std::string(section) + "." + std::string(name);
(*config)[key] = std::string(value);
return 1;
}
void Director::set_builder(std::shared_ptr<Builder> b) {
builder = b;
}
std::shared_ptr<Builder> Director::getBuilder() const {
return builder;
}
void Director::initializeSimulationWithConfig(const std::string& configFilePath) {
std::unordered_map<std::string, std::string> config;
if (ini_parse(configFilePath.c_str(), handler, &config) < 0) {
std::cout << "Can't load '" << configFilePath << "'\n";
return;
}
try {
double deltaT = std::stod(config["Parameters.deltaT"]);
double density = std::stod(config["Parameters.density"]);
int initUcellX = std::stoi(config["Parameters.initUcell"].substr(0, config["Parameters.initUcell"].find(' ')));
int initUcellY = std::stoi(config["Parameters.initUcell"].substr(config["Parameters.initUcell"].find(' ') + 1));
int stepAvg = std::stoi(config["Parameters.stepAvg"]);
int stepEquil = std::stoi(config["Parameters.stepEquil"]);
int stepLimit = std::stoi(config["Parameters.stepLimit"]);
double temperature = std::stod(config["Parameters.temperature"]);
int limitVel = std::stoi(config["Parameters.limitVel"]);
double rangeVel = std::stod(config["Parameters.rangeVel"]);
int sizeHistVel = std::stoi(config["Parameters.sizeHistVel"]);
int stepVel = std::stoi(config["Parameters.stepVel"]);
int randSeed = std::stoi(config["Parameters.randSeed"]);
int numberOfDimensions = std::stoi(config["Parameters.numberOfDimensions"]);
Eigen::VectorXd initUcell(2);
initUcell << initUcellX, initUcellY;
this->builder->setDeltaT(deltaT);
this->builder->setDensity(density);
this->builder->setInitUcell(initUcell);
this->builder->setStepAvg(stepAvg);
this->builder->setStepEquil(stepEquil);
this->builder->setStepLimit(stepLimit);
this->builder->setTemperature(temperature);
this->builder->setLimitVel(limitVel);
this->builder->setRangeVel(rangeVel);
this->builder->setSizeHistVel(sizeHistVel);
this->builder->setStepVel(stepVel);
this->builder->setRandSeed(randSeed);
this->builder->setNumberOfDimensions(numberOfDimensions);
} catch (const std::out_of_range& e) {
std::cerr << "Missing parameter in config: " << e.what() << std::endl;
// Optionally handle missing parameters
} catch (const std::invalid_argument& e) {
std::cerr << "Invalid argument in config: " << e.what() << std::endl;
// Optionally handle invalid arguments
} catch (const std::exception& e) {
std::cerr << "Unexpected error: " << e.what() << std::endl;
// Optionally handle unexpected errors
}
try {
this->builder->setConfig(config);
} catch (const std::exception& e) {
std::cerr << "Error setting configuration: " << e.what() << std::endl;
}
}
/* void Director::setRestOfParameters() {
}*/
void Director::buildMinimalSimulation() {
this->builder->setRestOfParameters();
this->builder->initializeVectors();
this->builder->setupStaticSimulation();
//this->builder->setAtomSize(this->builder->getinitUcellX(), this->builder->getinitUcellY());
//this->builder->initializeAtoms();
}
void Director::buildFullSimulation() {
//this->builder->setAtomSize(5,5);
//this->builder->initializeAtoms();
}