Copy and update states better; closes #1050

This commit is contained in:
Ian Bell
2016-06-05 17:29:10 -06:00
parent 6a5c17335e
commit a0c29bf35a
2 changed files with 17 additions and 8 deletions

View File

@@ -96,10 +96,12 @@ void HelmholtzEOSMixtureBackend::set_components(const std::vector<CoolPropFluid>
// saturation classes cannot hold copies of the saturation classes
if (generate_SatL_and_SatV)
{
SatL.reset(new HelmholtzEOSMixtureBackend(components, false));
SatL.reset(copy(false));
SatL->specify_phase(iphase_liquid);
SatV.reset(new HelmholtzEOSMixtureBackend(components, false));
linked_states.push_back(SatL);
SatV.reset(copy(false));
SatV->specify_phase(iphase_gas);
linked_states.push_back(SatV);
}
}
void HelmholtzEOSMixtureBackend::set_mole_fractions(const std::vector<CoolPropDbl> &mole_fractions)
@@ -247,9 +249,10 @@ void HelmholtzEOSMixtureBackend::set_binary_interaction_double(const std::size_t
else{
Reducing->set_binary_interaction_double(i,j,parameter,value);
}
/// Also set the parameters in the managed pointers for saturated liquid and vapor states
if (this->SatL){ this->SatL->set_binary_interaction_double(i, j, parameter, value); }
if (this->SatV) { this->SatV->set_binary_interaction_double(i, j, parameter, value); }
/// Also set the parameters in the managed pointers for other states
for (std::vector<shared_ptr<HelmholtzEOSMixtureBackend> >::iterator it = linked_states.begin(); it != linked_states.end(); ++it){
it->get()->set_binary_interaction_double(i, j, parameter, value);
}
};
/// Get binary mixture floating point parameter for this instance
double HelmholtzEOSMixtureBackend::get_binary_interaction_double(const std::size_t i, const std::size_t j, const std::string &parameter){

View File

@@ -22,14 +22,14 @@ class HelmholtzEOSMixtureBackend : public AbstractState {
protected:
void pre_update(CoolProp::input_pairs &input_pair, CoolPropDbl &value1, CoolPropDbl &value2 );
void post_update(bool optional_checks = true);
std::vector<shared_ptr<HelmholtzEOSMixtureBackend> > linked_states; ///< States that are linked to this one, and should be updated (BIP, reference state, etc.)
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));
if (TPD_state.get() == NULL){ bool sat_states = false; TPD_state.reset(copy(sat_states)); linked_states.push_back(TPD_state);
}
};
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)
@@ -44,6 +44,12 @@ public:
HelmholtzEOSMixtureBackend();
HelmholtzEOSMixtureBackend(const std::vector<CoolPropFluid> &components, bool generate_SatL_and_SatV = true);
HelmholtzEOSMixtureBackend(const std::vector<std::string> &component_names, bool generate_SatL_and_SatV = true);
virtual HelmholtzEOSMixtureBackend * copy(bool generate_SatL_and_SatV = true){
HelmholtzEOSMixtureBackend * ptr = new HelmholtzEOSMixtureBackend(components, generate_SatL_and_SatV);
ptr->Reducing = Reducing;
ptr->residual_helmholtz = residual_helmholtz;
return ptr;
};
virtual ~HelmholtzEOSMixtureBackend(){};
std::string backend_name(void){return "HelmholtzEOSMixtureBackend";}
shared_ptr<ReducingFunction> Reducing;