MCPcopy Create free account
hub / github.com/CoolProp/CoolProp / add_many

Method add_many

src/Backends/PCSAFT/PCSAFTLibrary.cpp:101–203  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

99}
100
101int PCSAFTLibraryClass::add_many(const nlohmann::json& listing) {
102 int counter = 0;
103 std::string fluid_name;
104 for (const auto& fluid_json : listing) {
105 try {
106 PCSAFTFluid fluid = cpjson::make_pcsaft_fluid(fluid_json);
107 fluid_name = fluid.getName();
108
109 // If the fluid is ok...
110
111 // First check that none of the identifiers are already present
112 bool already_present = false;
113
114 if (string_to_index_map.find(fluid.getCAS()) != string_to_index_map.end()
115 || string_to_index_map.find(fluid_name) != string_to_index_map.end()
116 || string_to_index_map.find(upper(fluid_name)) != string_to_index_map.end()) {
117 already_present = true;
118 } else {
119 // Check the aliases
120 for (std::size_t i = 0; i < fluid.getAliases().size(); ++i) {
121 if (string_to_index_map.find(fluid.getAliases()[i]) != string_to_index_map.end()) {
122 already_present = true;
123 break;
124 }
125 if (string_to_index_map.find(upper(fluid.getAliases()[i])) != string_to_index_map.end()) {
126 already_present = true;
127 break;
128 }
129 }
130 }
131
132 if (already_present) {
133 if (!get_config_bool(OVERWRITE_FLUIDS)) {
134 throw ValueError(format(
135 "Cannot load fluid [%s:%s] because it is already in library; consider enabling the config boolean variable OVERWRITE_FLUIDS",
136 fluid.getName().c_str(), fluid.getCAS().c_str()));
137 } else {
138 // Remove the one(s) that are already there
139
140 // Remove the actual fluid instance
141 std::size_t index = string_to_index_map.find(fluid_name)->second;
142
143 if (fluid_map.find(index) != fluid_map.end()) {
144 fluid_map.erase(fluid_map.find(index));
145 }
146
147 if (string_to_index_map.find(fluid_name) != string_to_index_map.end()) {
148 fluid_map.erase(fluid_map.find(index));
149 }
150
151 // Remove the identifiers pointing to that instance
152 if (string_to_index_map.find(fluid.getCAS()) != string_to_index_map.end()) {
153 string_to_index_map.erase(string_to_index_map.find(fluid.getCAS()));
154 }
155 if (string_to_index_map.find(fluid_name) != string_to_index_map.end()) {
156 string_to_index_map.erase(string_to_index_map.find(fluid_name));
157 }
158 // Check the aliases

Callers 1

Calls 10

make_pcsaft_fluidFunction · 0.85
upperFunction · 0.85
get_config_boolFunction · 0.85
getCASMethod · 0.80
getAliasesMethod · 0.80
whatMethod · 0.80
formatFunction · 0.50
get_debug_levelFunction · 0.50
getNameMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected