From c0157c0814ae06c867793208781859bf284b16bb Mon Sep 17 00:00:00 2001 From: Ian Bell Date: Mon, 15 Sep 2014 16:17:01 +0200 Subject: [PATCH] Added the ability to set/unset the phase for the abstract state class Signed-off-by: Ian Bell --- include/AbstractState.h | 10 ++++++++++ src/Backends/Helmholtz/HelmholtzEOSMixtureBackend.h | 2 ++ wrappers/Python/CoolProp/AbstractState.pxd | 3 +++ wrappers/Python/CoolProp/AbstractState.pyx | 7 +++++++ wrappers/Python/CoolProp/cAbstractState.pxd | 4 ++++ 5 files changed, 26 insertions(+) diff --git a/include/AbstractState.h b/include/AbstractState.h index dbee8024..d4e4f8af 100644 --- a/include/AbstractState.h +++ b/include/AbstractState.h @@ -251,7 +251,12 @@ protected: /// @param value The value for the parameter that is given virtual long double calc_saturation_ancillary(parameters param, int Q, parameters given, double value){throw NotImplementedError("This backend does not implement calc_saturation_ancillary");}; + /// Using this backend, calculate the phase virtual phases calc_phase(void){throw NotImplementedError("This backend does not implement calc_phase function");}; + /// Using this backend, specify the phase to be used for all further calculations + virtual void calc_specify_phase(phases phase){throw NotImplementedError("This backend does not implement calc_specify_phase function");}; + /// Using this backend, unspecify the phase + virtual void calc_unspecify_phase(void){throw NotImplementedError("This backend does not implement calc_unspecify_phase function");}; /// Using this backend, calculate a phase given by the state string /// @param state A string that describes the state desired, one of "hs_anchor", "critical"/"crit", "reducing" @@ -314,7 +319,12 @@ public: double pmax(void); double Ttriple(void); + /// Get the phase of the state phases phase(void){return calc_phase();}; + /// Specify the phase for all further calculations with this state class + void specify_phase(phases phase){calc_specify_phase(phase);}; + /// Unspecify the phase and go back to calculating it based on the inputs + void unspecify_phase(void){calc_unspecify_phase();}; /// Return the critical temperature in K /** diff --git a/src/Backends/Helmholtz/HelmholtzEOSMixtureBackend.h b/src/Backends/Helmholtz/HelmholtzEOSMixtureBackend.h index 8a168895..87247287 100644 --- a/src/Backends/Helmholtz/HelmholtzEOSMixtureBackend.h +++ b/src/Backends/Helmholtz/HelmholtzEOSMixtureBackend.h @@ -56,6 +56,8 @@ public: bool has_melting_line(){ return is_pure_or_pseudopure && components[0]->ancillaries.melting_line.enabled();}; long double calc_melting_line(int param, int given, long double value); phases calc_phase(void){return _phase;}; + void calc_specify_phase(phases phase){ specify_phase(phase); } + void calc_unspecify_phase(){ unspecify_phase(); } long double calc_saturation_ancillary(parameters param, int Q, parameters given, double value); const CoolProp::SimpleState &calc_state(const std::string &state); diff --git a/wrappers/Python/CoolProp/AbstractState.pxd b/wrappers/Python/CoolProp/AbstractState.pxd index 2068b02e..60ac161f 100644 --- a/wrappers/Python/CoolProp/AbstractState.pxd +++ b/wrappers/Python/CoolProp/AbstractState.pxd @@ -18,6 +18,9 @@ cdef class AbstractState: cpdef set_mass_fractions(self, vector[double] z) cpdef set_volu_fractions(self, vector[double] z) + cpdef specify_phase(self, constants_header.phases phase) + cpdef unspecify_phase(self) + ## ---------------------------------------- ## Fluid property accessors ## ---------------------------------------- diff --git a/wrappers/Python/CoolProp/AbstractState.pyx b/wrappers/Python/CoolProp/AbstractState.pyx index 4260d039..59fc2235 100644 --- a/wrappers/Python/CoolProp/AbstractState.pyx +++ b/wrappers/Python/CoolProp/AbstractState.pyx @@ -15,6 +15,13 @@ cdef class AbstractState: def __dealloc__(self): del self.thisptr + + cpdef specify_phase(self, constants_header.phases phase): + """ Specify the phase - wrapper of c++ function :cpapi:`CoolProp::AbstractState::specify_phase` """ + self.thisptr.specify_phase(phase) + cpdef unspecify_phase(self): + """ Unspecify the phase - wrapper of c++ function :cpapi:`CoolProp::AbstractState::specify_phase` """ + self.thisptr.unspecify_phase() cpdef update(self, constants_header.input_pairs ipair, double Value1, double Value2): """ Update function - wrapper of c++ function :cpapi:`CoolProp::AbstractState::update` """ diff --git a/wrappers/Python/CoolProp/cAbstractState.pxd b/wrappers/Python/CoolProp/cAbstractState.pxd index b4caa48e..d9874f51 100644 --- a/wrappers/Python/CoolProp/cAbstractState.pxd +++ b/wrappers/Python/CoolProp/cAbstractState.pxd @@ -19,6 +19,10 @@ cdef extern from "AbstractState.h" namespace "CoolProp": ## Constructor with fluid name AbstractState(string FluidName) except +ValueError + void specify_phase(constants_header.phases phase) except +ValueError + + void unspecify_phase() except +ValueError + bool clear() ## Property updater