| 239 | } |
| 240 | |
| 241 | void _PropsSI_initialize(const std::string& backend, const std::vector<std::string>& fluid_names, const std::vector<double>& z, |
| 242 | shared_ptr<AbstractState>& State) { |
| 243 | |
| 244 | if (fluid_names.empty()) { |
| 245 | throw ValueError("fluid_names cannot be empty"); |
| 246 | } |
| 247 | |
| 248 | std::vector<double> fractions(1, 1.0); // Default to one component, unity fraction |
| 249 | const std::vector<double>* fractions_ptr = nullptr; // Pointer to the array to be used; |
| 250 | |
| 251 | if (fluid_names.size() > 1) { |
| 252 | // Set the pointer - we are going to use the supplied fractions; they must be provided |
| 253 | fractions_ptr = &z; |
| 254 | // Reset the state |
| 255 | State.reset(AbstractState::factory(backend, fluid_names)); |
| 256 | } else if (fluid_names.size() == 1) { |
| 257 | if (has_fractions_in_string(fluid_names[0]) || has_solution_concentration(fluid_names[0])) { |
| 258 | // Extract fractions from the string |
| 259 | const std::string fluid_string = extract_fractions(fluid_names[0], fractions); |
| 260 | // Set the pointer - we are going to use the extracted fractions |
| 261 | fractions_ptr = &fractions; |
| 262 | // Reset the state |
| 263 | State.reset(AbstractState::factory(backend, fluid_string)); |
| 264 | } else { |
| 265 | if (z.empty()) { |
| 266 | // Set the pointer - we are going to use the default fractions |
| 267 | fractions_ptr = &fractions; |
| 268 | } else { |
| 269 | // Set the pointer - we are going to use the provided fractions |
| 270 | fractions_ptr = &z; |
| 271 | } |
| 272 | // Reset the state |
| 273 | State.reset(AbstractState::factory(backend, fluid_names)); |
| 274 | } |
| 275 | } else { // The only path where fractions_ptr stays nullptr |
| 276 | throw ValueError("fractions_ptr is nullptr"); |
| 277 | } |
| 278 | if (!State->available_in_high_level()) { |
| 279 | throw ValueError( |
| 280 | "This AbstractState derived class cannot be used in the high-level interface; see www.coolprop.org/dev/coolprop/LowLevelAPI.html"); |
| 281 | } |
| 282 | |
| 283 | // Set the fraction for the state |
| 284 | if (State->using_mole_fractions()) { |
| 285 | // If a predefined mixture or a pure fluid, the fractions will already be set |
| 286 | if (State->get_mole_fractions().empty()) { |
| 287 | State->set_mole_fractions(*fractions_ptr); |
| 288 | } |
| 289 | } else if (State->using_mass_fractions()) { |
| 290 | State->set_mass_fractions(*fractions_ptr); |
| 291 | } else if (State->using_volu_fractions()) { |
| 292 | State->set_volu_fractions(*fractions_ptr); |
| 293 | } else { |
| 294 | if (get_debug_level() > 50) |
| 295 | std::cout << format("%s:%d: _PropsSI, could not set composition to %s, defaulting to mole fraction.\n", __FILE__, __LINE__, |
| 296 | vec_to_string(z).c_str()) |
| 297 | .c_str(); |
| 298 | } |
no test coverage detected