| 66 | } |
| 67 | |
| 68 | std::shared_ptr<CoolProp::AbstractState> get_critical_point(const std::shared_ptr<CoolProp::AbstractState>& state) { |
| 69 | CoolProp::CriticalState crit_state; |
| 70 | crit_state.T = Detail::NaN; |
| 71 | crit_state.p = Detail::NaN; |
| 72 | crit_state.rhomolar = Detail::NaN; |
| 73 | crit_state.rhomolar = Detail::NaN; |
| 74 | crit_state.stable = false; |
| 75 | try { |
| 76 | crit_state.T = state->T_critical(); |
| 77 | crit_state.p = state->p_critical(); |
| 78 | crit_state.rhomolar = state->rhomolar_critical(); |
| 79 | crit_state.stable = true; |
| 80 | } catch (...) { |
| 81 | try { |
| 82 | for (CoolProp::CriticalState crit_state_tmp : state->all_critical_points()) { |
| 83 | if (crit_state_tmp.stable && (crit_state_tmp.T > crit_state.T || !std::isfinite(crit_state.T))) { |
| 84 | crit_state.T = crit_state_tmp.T; |
| 85 | crit_state.p = crit_state_tmp.p; |
| 86 | crit_state.rhomolar = crit_state_tmp.rhomolar; |
| 87 | crit_state.stable = crit_state_tmp.stable; |
| 88 | } |
| 89 | } |
| 90 | } catch (...) { |
| 91 | throw CoolProp::ValueError("Could not calculate the critical point data."); |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | std::shared_ptr<CoolProp::AbstractState> new_state(CoolProp::AbstractState::factory(state->backend_name(), state->fluid_names())); |
| 96 | std::vector<double> masses = state->get_mass_fractions(); |
| 97 | if (masses.size() > 1) new_state->set_mass_fractions(masses); |
| 98 | |
| 99 | // Try (p, T) first with the iphase_critical_point hint and then |
| 100 | // without; fall through to (rhomolar, T) with the same hint pair |
| 101 | // if neither works. Each catch is a deliberate "try the next |
| 102 | // strategy" without reporting. |
| 103 | if (std::isfinite(crit_state.p) && std::isfinite(crit_state.T)) { |
| 104 | try { |
| 105 | new_state->specify_phase(CoolProp::iphase_critical_point); |
| 106 | new_state->update(CoolProp::PT_INPUTS, crit_state.p, crit_state.T); |
| 107 | return new_state; |
| 108 | } catch (...) { // NOLINT(bugprone-empty-catch) |
| 109 | } |
| 110 | try { |
| 111 | new_state->update(CoolProp::PT_INPUTS, crit_state.p, crit_state.T); |
| 112 | return new_state; |
| 113 | } catch (...) { // NOLINT(bugprone-empty-catch) |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | if (std::isfinite(crit_state.rhomolar) && std::isfinite(crit_state.T)) { |
| 118 | try { |
| 119 | new_state->specify_phase(CoolProp::iphase_critical_point); |
| 120 | new_state->update(CoolProp::DmolarT_INPUTS, crit_state.rhomolar, crit_state.T); |
| 121 | return new_state; |
| 122 | } catch (...) { // NOLINT(bugprone-empty-catch) |
| 123 | } |
| 124 | try { |
| 125 | new_state->update(CoolProp::DmolarT_INPUTS, crit_state.rhomolar, crit_state.T); |
no test coverage detected