diff --git a/src/Backends/Cubics/CubicBackend.h b/src/Backends/Cubics/CubicBackend.h index 7144a158..3bc771eb 100644 --- a/src/Backends/Cubics/CubicBackend.h +++ b/src/Backends/Cubics/CubicBackend.h @@ -170,6 +170,11 @@ public: cubic.reset(new SRK(Tc, pc, acentric, R_u)); setup(); } + /// Update the state used to calculate the tangent-plane-distance + void update_TPD_state(){ + AbstractCubic *cubic = get_cubic().get(); + TPD_state.reset(new SRKBackend(cubic->get_Tc(),cubic->get_pc(),cubic->get_acentric(),cubic->get_R_u())); + }; }; class PengRobinsonBackend : public AbstractCubicBackend { @@ -200,6 +205,11 @@ public: cubic.reset(new PengRobinson(Tc, pc, acentric, R_u)); setup(); }; + /// Update the state used to calculate the tangent-plane-distance + void update_TPD_state(){ + AbstractCubic *cubic = get_cubic().get(); + TPD_state.reset(new PengRobinsonBackend(cubic->get_Tc(),cubic->get_pc(),cubic->get_acentric(),cubic->get_R_u())); + }; }; /** diff --git a/src/Backends/Helmholtz/HelmholtzEOSMixtureBackend.cpp b/src/Backends/Helmholtz/HelmholtzEOSMixtureBackend.cpp index fd62f42e..c1384564 100644 --- a/src/Backends/Helmholtz/HelmholtzEOSMixtureBackend.cpp +++ b/src/Backends/Helmholtz/HelmholtzEOSMixtureBackend.cpp @@ -3301,10 +3301,7 @@ double HelmholtzEOSMixtureBackend::calc_tangent_plane_distance(const double T, c if (w.size() != z.size()){ throw ValueError(format("Trial composition vector size [%d] is not the same as bulk composition [%d]", w.size(), z.size())); } - if (TPD_state.get() == NULL){ - bool sat_states = false; - TPD_state.reset(new HelmholtzEOSMixtureBackend(components, sat_states)); - } + update_TPD_state(); TPD_state->set_mole_fractions(std::vector(w.begin(), w.end())); if (rhomolar_guess < 0){ TPD_state->update(PT_INPUTS, p, T); diff --git a/src/Backends/Helmholtz/HelmholtzEOSMixtureBackend.h b/src/Backends/Helmholtz/HelmholtzEOSMixtureBackend.h index cd9379ec..cd355ba2 100644 --- a/src/Backends/Helmholtz/HelmholtzEOSMixtureBackend.h +++ b/src/Backends/Helmholtz/HelmholtzEOSMixtureBackend.h @@ -23,6 +23,13 @@ protected: void pre_update(CoolProp::input_pairs &input_pair, CoolPropDbl &value1, CoolPropDbl &value2 ); void post_update(); shared_ptr TPD_state; ///< A temporary state used for calculations of the tangent-plane-distance + /// Update the state class used to calculate the tangent-plane-distance + virtual void update_TPD_state(){ + if (TPD_state.get() == NULL){ + bool sat_states = false; + TPD_state.reset(new HelmholtzEOSMixtureBackend(components, sat_states)); + } + }; std::vector components; ///< The components that are in use phases imposed_phase_index; bool is_pure_or_pseudopure; ///< A flag for whether the substance is a pure or pseudo-pure fluid (true) or a mixture (false) @@ -33,7 +40,6 @@ protected: SimpleState _crit; std::size_t N; ///< Number of components - public: HelmholtzEOSMixtureBackend(); HelmholtzEOSMixtureBackend(const std::vector &components, bool generate_SatL_and_SatV = true);