Added post-Newtonian parameters to the config file
This commit is contained in:
parent
9b900eff6e
commit
d7332be188
4 changed files with 60 additions and 20 deletions
28
config.cpp
28
config.cpp
|
|
@ -2,6 +2,7 @@
|
|||
#include <stdexcept>
|
||||
#include <cstdio>
|
||||
#include <fstream>
|
||||
#include <algorithm>
|
||||
|
||||
using Dictionary = std::unordered_map<std::string,std::string>;
|
||||
|
||||
|
|
@ -54,7 +55,7 @@ template<> double Config::string_cast(const std::string str)
|
|||
template<> int Config::string_cast(const std::string str)
|
||||
{
|
||||
size_t idx;
|
||||
auto value = std::stoi(str, &idx);
|
||||
auto value = std::stoi(str, &idx); // WARNING stoi can throw
|
||||
if (idx == str.size()) return value;
|
||||
else throw std::runtime_error("Cannot convert \"" + str + "\" into an int");
|
||||
}
|
||||
|
|
@ -66,6 +67,24 @@ template<> bool Config::string_cast(const std::string str)
|
|||
throw std::runtime_error("Cannot convert \"" + str + "\" into a bool");
|
||||
}
|
||||
|
||||
#include <iostream>
|
||||
template<> std::vector<int> Config::string_cast(const std::string str)
|
||||
{
|
||||
auto error = std::runtime_error("Cannot convert \"" + str + "\" into an integer array");
|
||||
if (!( (str.front()=='{') && (str.back()=='}'))) throw error;
|
||||
std::string new_str = strip(str.substr(1, str.length()-2));
|
||||
std::replace(new_str.begin(), new_str.end(), ',', ' ');
|
||||
|
||||
std::vector<int> result;
|
||||
while (new_str.length() > 0) {
|
||||
size_t idx;
|
||||
auto value = std::stoi(new_str, &idx);
|
||||
result.push_back(value);
|
||||
new_str = new_str.substr(idx, new_str.length()-idx);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
// For mandatory parameters
|
||||
template<typename T>
|
||||
|
|
@ -98,6 +117,11 @@ void Config::error_checking()
|
|||
throw std::runtime_error("Black hole neighbour output (live_smbh_neighbor_output=true) requires at least one live black hole (live_smbh_count)");
|
||||
if (binary_smbh_influence_sphere_output && (live_smbh_count != 2))
|
||||
throw std::runtime_error("Binary black hole influence sphere output (binary_smbh_influence_sphere_output=true) requires exactly two live black holes (live_smbh_count=2)");
|
||||
if (pn_usage.size() != 7)
|
||||
throw std::runtime_error("PN usage array (pn_usage) must have exactly seven components");
|
||||
for (int i; i<7; i++)
|
||||
if (!((pn_usage[i] == 0) || (pn_usage[i] == 1)))
|
||||
throw std::runtime_error("PN usage array (pn_usage) must have ones and zeros only");
|
||||
}
|
||||
|
||||
Config::Config(std::string file_name)
|
||||
|
|
@ -121,6 +145,8 @@ Config::Config(std::string file_name)
|
|||
binary_smbh_pn = get_parameter<bool>(dictionary, "binary_smbh_pn", false);
|
||||
binary_smbh_influence_sphere_output = get_parameter<bool>(dictionary, "binary_smbh_influence_sphere_output", false);
|
||||
binary_smbh_influence_radius_factor = get_parameter<double>(dictionary, "binary_smbh_influence_radius_factor", 10.);
|
||||
pn_usage = get_parameter<std::vector<int>>(dictionary, "pn_usage", std::vector<int>({1,1,1,1,1,1,1}));
|
||||
pn_c = get_parameter<double>(dictionary, "pn_c", 500);
|
||||
|
||||
error_checking();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue