6 #include <configure.hpp>
9 #include <athena/athena.hpp>
10 #include <athena/parameter_input.hpp>
13 #include <application/application.hpp>
14 #include <application/exceptions.hpp>
25 Application::Logger app(
"canoe");
26 app->Log(
"Destroy IndexMap");
42 throw RuntimeError(
"IndexMap",
"IndexMap has been initialized");
45 Application::Logger app(
"canoe");
46 app->Log(
"Initialize IndexMap");
57 std::string str = pin->GetOrAddString(
"species",
"vapor",
"");
58 std::vector<std::string> names = Vectorize<std::string>(str.c_str(),
" ,");
60 if (names.size() > NVAPOR) {
61 throw ValueError(
"IndexMap",
"Number of vapors", NVAPOR, names.size());
64 for (
size_t i = 0; i < names.size(); ++i) {
65 vapor_index_map[names[i]] = 1 + i;
69 str = pin->GetOrAddString(
"species",
"cloud",
"");
70 names = Vectorize<std::string>(str.c_str(),
" ,");
72 if (names.size() > NCLOUD) {
73 throw ValueError(
"IndexMap",
"Number of clouds", NCLOUD, names.size());
76 for (
size_t i = 0; i < names.size(); ++i) {
77 cloud_index_map[names[i]] = i;
81 str = pin->GetOrAddString(
"species",
"chemistry",
"");
82 names = Vectorize<std::string>(str.c_str(),
" ,");
84 if (names.size() > NCHEMISTRY) {
85 throw ValueError(
"IndexMap",
"Number of chemistry", NCHEMISTRY,
89 for (
size_t i = 0; i < names.size(); ++i) {
90 chemistry_index_map[names[i]] = i;
94 str = pin->GetOrAddString(
"species",
"tracer",
"");
95 names = Vectorize<std::string>(str.c_str(),
" ,");
97 if (names.size() > NTRACER) {
98 throw ValueError(
"IndexMap",
"Number of tracers", NTRACER, names.size());
101 for (
size_t i = 0; i < names.size(); ++i) {
102 tracer_index_map[names[i]] = i;
106 str = pin->GetOrAddString(
"species",
"particle",
"");
107 names = Vectorize<std::string>(str.c_str(),
" ,");
109 for (
size_t i = 0; i < names.size(); ++i) {
110 particle_index_map[names[i]] = i;
117 std::string delimiter =
".";
120 size_t delimiter_pos = category_name.find(delimiter);
122 if (delimiter_pos == std::string::npos) {
123 throw NotFoundError(
"GetSpeciesId",
124 "Delimiter '" + delimiter +
"' in " + category_name);
128 std::string category = category_name.substr(0, delimiter_pos);
129 std::string name = category_name.substr(delimiter_pos + delimiter.length());
131 if (category ==
"vapor") {
133 }
else if (category ==
"cloud") {
135 }
else if (category ==
"chemistry") {
137 }
else if (category ==
"tracer") {
138 return NHYDRO + NCLOUD + NCHEMISTRY +
GetTracerId(name);
140 throw NotFoundError(
"GetSpeciesId",
"Category " + category);
145 std::unique_lock<std::mutex> lock(
imap_mutex);
155 if (
id == i)
return name;
157 throw NotFoundError(
"GetVaporName",
"Vapor id " + std::to_string(i));
162 if (
id == i)
return name;
164 throw NotFoundError(
"GetCloudName",
"Cloud id " + std::to_string(i));
169 if (
id == i)
return name;
171 throw NotFoundError(
"GetTracerName",
"Tracer id " + std::to_string(i));
size_t GetTracerId(std::string const &name) const
std::map< std::string, size_t > chemistry_index_map_
size_t GetVaporId(std::string const &name) const
size_t GetSpeciesId(std::string category_name) const
std::string GetCloudName(size_t i) const
std::map< std::string, size_t > tracer_index_map_
std::string GetTracerName(size_t i) const
static IndexMap const * InitFromAthenaInput(ParameterInput *pin)
std::map< std::string, size_t > vapor_index_map_
static IndexMap * myindex_map_
Pointer to the single IndexMap instance.
IndexMap()
Protected ctor access thru static member function Instance.
size_t GetCloudId(std::string const &name) const
std::map< std::string, size_t > cloud_index_map_
std::string GetVaporName(size_t i) const
static IndexMap const * GetInstance()
size_t GetChemistryId(std::string const &name) const
std::map< std::string, size_t > particle_index_map_
static std::mutex imap_mutex