Update the updating of the TPD state class

This commit is contained in:
Ian Bell
2016-02-15 17:59:15 -07:00
parent 42e674c32a
commit 1701db312c
3 changed files with 18 additions and 5 deletions

View File

@@ -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()));
};
};
/**

View File

@@ -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<CoolPropDbl>(w.begin(), w.end()));
if (rhomolar_guess < 0){
TPD_state->update(PT_INPUTS, p, T);

View File

@@ -23,6 +23,13 @@ protected:
void pre_update(CoolProp::input_pairs &input_pair, CoolPropDbl &value1, CoolPropDbl &value2 );
void post_update();
shared_ptr<HelmholtzEOSMixtureBackend> 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<CoolPropFluid> 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<CoolPropFluid> &components, bool generate_SatL_and_SatV = true);