| 2384 | } |
| 2385 | |
| 2386 | shared_ptr<REFPROPMixtureBackend> REFPROPMixtureBackend::build_saturation_shim(int Q) { |
| 2387 | this->check_loaded_fluid(); |
| 2388 | if (!(Q == 0 || Q == 1)) { |
| 2389 | throw ValueError(format("build_saturation_shim requires Q==0 or Q==1; got %d", Q)); |
| 2390 | } |
| 2391 | const std::vector<double>& x_phase = (Q == 0) ? mole_fractions_liq : mole_fractions_vap; |
| 2392 | // is_cached (operator bool) check first: operator double()/CoolPropDbl() throws if uncached. |
| 2393 | bool have = (Q == 0) ? static_cast<bool>(_rhoLmolar) : static_cast<bool>(_rhoVmolar); |
| 2394 | CoolPropDbl rho_phase = have ? ((Q == 0) ? static_cast<CoolPropDbl>(_rhoLmolar) : static_cast<CoolPropDbl>(_rhoVmolar)) : _HUGE; |
| 2395 | if (!have || !ValidNumber(rho_phase)) { |
| 2396 | throw ValueError("The saturated state has not been set (no two-phase density available)."); |
| 2397 | } |
| 2398 | shared_ptr<REFPROPMixtureBackend> shim(new REFPROPMixtureBackend()); |
| 2399 | shim->link_to_loaded_fluids(*this); |
| 2400 | // Copy only the first Ncomp entries of the per-phase composition. |
| 2401 | std::vector<CoolPropDbl> x(x_phase.begin(), x_phase.begin() + Ncomp); |
| 2402 | shim->set_mole_fractions(x); |
| 2403 | shim->specify_phase((Q == 0) ? iphase_liquid : iphase_gas); |
| 2404 | shim->update_DmolarT_direct(rho_phase, _T); |
| 2405 | shim->_Q = static_cast<CoolPropDbl>(Q); // mark the shim as sitting on the envelope |
| 2406 | return shim; |
| 2407 | } |
| 2408 | |
| 2409 | double REFPROPMixtureBackend::dpdT_along_saturation_pure(int kph) { |
| 2410 | if (Ncomp != 1) { // precondition: DPTSATKdll is a single-component saturation routine |
no test coverage detected