| 310 | } |
| 311 | |
| 312 | bool is_valid_second_derivative(const std::string& name, parameters& iOf1, parameters& iWrt1, parameters& iConstant1, parameters& iWrt2, |
| 313 | parameters& iConstant2) { |
| 314 | if (get_debug_level() > 5) { |
| 315 | std::cout << format("is_valid_second_derivative(%s)", name.c_str()); |
| 316 | } |
| 317 | |
| 318 | // Suppose we start with "d(d(P)/d(Dmolar)|T)/d(Dmolar)|T" |
| 319 | std::size_t i = name.rfind('|'); |
| 320 | if ((i == 0) || (i == std::string::npos)) { |
| 321 | return false; |
| 322 | } |
| 323 | std::string constant2 = name.substr(i + 1); // "T" |
| 324 | if (!is_valid_parameter(constant2, iConstant2)) { |
| 325 | return false; |
| 326 | }; |
| 327 | std::string left_of_bar = name.substr(0, i); // "d(d(P)/d(Dmolar)|T)/d(Dmolar)" |
| 328 | |
| 329 | i = left_of_bar.rfind('/'); |
| 330 | if ((i == 0) || (i == std::string::npos)) { |
| 331 | return false; |
| 332 | } |
| 333 | std::string left_of_slash = left_of_bar.substr(0, i); // "d(d(P)/d(Dmolar)|T)" |
| 334 | std::string right_of_slash = left_of_bar.substr(i + 1); // "d(Dmolar)" |
| 335 | |
| 336 | i = left_of_slash.find('('); |
| 337 | std::size_t i1 = left_of_slash.rfind(')'); |
| 338 | if (!((i > 0) && (i != std::string::npos) && (i1 > (i + 1)) && (i1 != std::string::npos))) { |
| 339 | return false; |
| 340 | } |
| 341 | std::string num = left_of_slash.substr(i + 1, i1 - i - 1); // "d(P)/d(Dmolar)|T" |
| 342 | if (!is_valid_first_derivative(num, iOf1, iWrt1, iConstant1)) { |
| 343 | return false; |
| 344 | } |
| 345 | |
| 346 | i = right_of_slash.find('('); |
| 347 | i1 = right_of_slash.rfind(')'); |
| 348 | if (!((i > 0) && (i != std::string::npos) && (i1 > (i + 1)) && (i1 != std::string::npos))) { |
| 349 | return false; |
| 350 | } |
| 351 | std::string den = right_of_slash.substr(i + 1, i1 - i - 1); // "Dmolar" |
| 352 | if (!is_valid_parameter(den, iWrt2)) { |
| 353 | return false; |
| 354 | } |
| 355 | |
| 356 | // If we haven't quit yet, all is well |
| 357 | return true; |
| 358 | } |
| 359 | |
| 360 | struct phase_info |
| 361 | { |
no test coverage detected