mirror of
https://github.com/CoolProp/CoolProp.git
synced 2026-04-01 03:00:13 -04:00
@@ -26,7 +26,7 @@ void SaturationSolvers::saturation_PHSU_pure(HelmholtzEOSMixtureBackend *HEOS, l
|
||||
|
||||
long double T, rhoL,rhoV;
|
||||
long double deltaL=0, deltaV=0, tau=0, error;
|
||||
int iter=0;
|
||||
int iter=0, specified_parameter;
|
||||
|
||||
// Use the density ancillary function as the starting point for the solver
|
||||
try
|
||||
@@ -148,6 +148,7 @@ void SaturationSolvers::saturation_PHSU_pure(HelmholtzEOSMixtureBackend *HEOS, l
|
||||
}
|
||||
// dr_3/ddelta'' (liquid pressure not a function of vapor density)
|
||||
J[2][2] = 0;
|
||||
specified_parameter = CoolProp::iP;
|
||||
break;
|
||||
case saturation_PHSU_pure_options::IMPOSED_PV:
|
||||
// dr_3/dtau
|
||||
@@ -162,6 +163,7 @@ void SaturationSolvers::saturation_PHSU_pure(HelmholtzEOSMixtureBackend *HEOS, l
|
||||
// dr_3/ddelta''
|
||||
J[2][2] = SatV->first_partial_deriv(iP,iDelta,iTau)/specified_value;
|
||||
}
|
||||
specified_parameter = CoolProp::iP;
|
||||
break;
|
||||
default:
|
||||
throw ValueError(format("options.specified_variable to saturation_PHSU_pure [%d] is invalid",options.specified_variable));
|
||||
@@ -191,7 +193,8 @@ void SaturationSolvers::saturation_PHSU_pure(HelmholtzEOSMixtureBackend *HEOS, l
|
||||
throw SolutionError(format("saturation_PHSU_pure solver T < 0"));
|
||||
}
|
||||
if (iter > 200){
|
||||
throw SolutionError(format("saturation_PHSU_pure solver did not converge after 100 iterations with specified value: %g with index %d",specified_value, options.specified_variable));
|
||||
std::string info = get_parameter_information(specified_parameter, "short");
|
||||
throw SolutionError(format("saturation_PHSU_pure solver did not converge after 200 iterations for %s=%Lg current error is %Lg", info.c_str(), specified_value, error));
|
||||
}
|
||||
}
|
||||
while (error > 1e-11);
|
||||
@@ -386,7 +389,7 @@ void SaturationSolvers::saturation_T_pure_Akasaka(HelmholtzEOSMixtureBackend *HE
|
||||
SatV = HEOS->SatV;
|
||||
|
||||
long double rhoL,rhoV,JL,JV,KL,KV,dJL,dJV,dKL,dKV;
|
||||
long double DELTA, deltaL=0, deltaV=0, tau=0, error, PL, PV, stepL, stepV;
|
||||
long double DELTA, deltaL=0, deltaV=0, tau, error, PL, PV, stepL, stepV;
|
||||
int iter=0;
|
||||
// Use the density ancillary function as the starting point for the solver
|
||||
try
|
||||
@@ -490,6 +493,12 @@ void SaturationSolvers::saturation_T_pure_Akasaka(HelmholtzEOSMixtureBackend *HE
|
||||
}
|
||||
}
|
||||
while (error > 1e-10 && fabs(stepL) > 10*DBL_EPSILON*fabs(stepL) && fabs(stepV) > 10*DBL_EPSILON*fabs(stepV));
|
||||
|
||||
double p_error_limit = 1e-3;
|
||||
double p_error = (PL - PV)/PL;
|
||||
if (fabs(p_error) > p_error_limit){
|
||||
throw SolutionError(format("saturation_T_pure_Akasaka solver abs error on p [%g] > limit [%g]", fabs(p_error), p_error_limit));
|
||||
}
|
||||
}
|
||||
|
||||
void SaturationSolvers::x_and_y_from_K(long double beta, const std::vector<long double> &K, const std::vector<long double> &z, std::vector<long double> &x, std::vector<long double> &y)
|
||||
|
||||
@@ -60,6 +60,8 @@ int main()
|
||||
{
|
||||
#if 1
|
||||
|
||||
double T = PropsSI("T","P",8.7257510472904255e+02,"Q",0.0000000000000000e+00,"Water");
|
||||
std::cout << get_global_param_string("errstring");
|
||||
double Tc = Props1SI("Water","Tcrit");
|
||||
double rhoc = Props1SI("Water","rhocrit");
|
||||
std::cout << Tc << rhoc << std::endl;
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#cython: embedsignature = True, c_string_type=str, c_string_encoding=ascii
|
||||
from __future__ import division
|
||||
|
||||
cdef class AbstractState:
|
||||
"""
|
||||
|
||||
@@ -4,7 +4,7 @@ cimport cython
|
||||
|
||||
from libcpp.vector cimport vector
|
||||
|
||||
cimport AbstractState
|
||||
include "AbstractState.pxd"
|
||||
|
||||
# Default string in Python 3.x is a unicode string (type str)
|
||||
# Default string in Python 2.x is a byte string(type bytes)
|
||||
@@ -29,25 +29,21 @@ cdef extern from "CoolProp.h" namespace "CoolProp":
|
||||
vector[double] _PropsSI "CoolProp::PropsSI"(string Output, string Name1, vector[double] Prop1, string Name2, vector[double] Prop2, string FluidName, vector[double] fractions)
|
||||
string _get_global_param_string "CoolProp::get_global_param_string"(string ParamName)
|
||||
|
||||
# double _Props1SI "Props1SI"(string Ref, string Output)
|
||||
# double _Props1SI "CoolProp::Props1SI"(string Ref, string Output)
|
||||
|
||||
# double _IProps "IProps"(long Output, long Name1, double Prop1, long Name2, double Prop2, long Ref)
|
||||
# double _IProps "CoolProp::IProps"(long Output, long Name1, double Prop1, long Name2, double Prop2, long Ref)
|
||||
|
||||
# double _Props "Props"(string Output, string Name1, double Prop1, string Name2, double Prop2, string Ref)
|
||||
# double _Props1 "Props1"(string Ref, string Output)
|
||||
# double _Props "CoolProp::Props"(string Output, string Name1, double Prop1, string Name2, double Prop2, string Ref)
|
||||
# double _Props1 "CoolProp::Props1"(string Ref, string Output)
|
||||
|
||||
# string _get_fluid_param_string "get_fluid_param_string"(string ParamName, string FluidName)
|
||||
# string _get_fluid_param_string "CoolProp::get_fluid_param_string"(string ParamName, string FluidName)
|
||||
|
||||
# long _set_phase "set_phase" (string phase)
|
||||
# long _get_Fluid_index "get_Fluid_index" (string Fluid)
|
||||
long _get_parameter_index "get_parameter_index" (string param)
|
||||
# long _get_Fluid_index "CoolProp::get_Fluid_index" (string Fluid)
|
||||
long _get_parameter_index "CoolProp::get_parameter_index" (string param)
|
||||
int _get_debug_level "CoolProp::get_debug_level"()
|
||||
void _set_debug_level "CoolProp::set_debug_level"(int level)
|
||||
#
|
||||
# string _add_REFPROP_fluid "add_REFPROP_fluid"(string FluidName) except +
|
||||
#
|
||||
# int _get_debug_level "get_debug_level"()
|
||||
# void _set_debug_level "set_debug_level"(int level)
|
||||
#
|
||||
# string _get_BibTeXKey "get_BibTeXKey"(string Ref, string key)
|
||||
# string _get_BibTeXKey "CoolProp::get_BibTeXKey"(string Ref, string key)
|
||||
|
||||
# Convenience functions
|
||||
# int _IsFluidType "IsFluidType"(char* Ref, char* Type)
|
||||
@@ -58,7 +54,7 @@ cdef extern from "CoolProp.h" namespace "CoolProp":
|
||||
# double _cair_sat "cair_sat"(double T)
|
||||
|
||||
cdef class State:
|
||||
cdef AbstractState.AbstractState pAS
|
||||
cdef AbstractState pAS
|
||||
cdef readonly string Fluid, phase
|
||||
cdef int iFluid,iParam1,iParam2,iOutput
|
||||
cdef double T_, rho_, p_
|
||||
|
||||
@@ -6,9 +6,15 @@ from __future__ import division
|
||||
# Each of the functions from the CoolProp header are renamed in cython code to
|
||||
# an underscored name so that the same name can be used in the exposed functions below
|
||||
|
||||
import cython
|
||||
cimport cython
|
||||
|
||||
import math
|
||||
import warnings
|
||||
|
||||
from libcpp.string cimport string
|
||||
from libcpp.vector cimport vector
|
||||
|
||||
from constants import *
|
||||
from constants_header cimport *
|
||||
|
||||
@@ -25,6 +31,7 @@ cpdef ndarray_or_iterable(object input):
|
||||
return input
|
||||
|
||||
include "HumidAirProp.pyx"
|
||||
include "AbstractState.pyx"
|
||||
|
||||
# def set_reference_state(string_like FluidName, *args):
|
||||
# """
|
||||
@@ -100,7 +107,7 @@ include "HumidAirProp.pyx"
|
||||
# if not len(err_string) == 0:
|
||||
# raise ValueError("{err:s} :: inputs were :{iin1:d},{in1:g},{iin2:d},{in2:g},{iFluid:d}".format(err= err_string,iin1=iInput1,in1=Input1,iin2=iInput2,in2=Input2,iFluid = iFluid))
|
||||
# else:
|
||||
# raise ValueError("IProps failed ungracefully with inputs:\"{in1:g}\",\"{in2:g}\"; please file a ticket at https://sourceforge.net/p/coolprop/tickets/".format(in1=Input1,in2=Input2))
|
||||
# raise ValueError("IProps failed ungracefully with inputs:\"{in1:g}\",\"{in2:g}\"; please file a ticket at https://github.com/CoolProp/CoolProp/issues".format(in1=Input1,in2=Input2))
|
||||
# else:
|
||||
# return val
|
||||
|
||||
@@ -114,14 +121,14 @@ cpdef get_fluid_param_string(string_like fluid, string_like param):
|
||||
# if not len(errstr) == 0:
|
||||
# raise ValueError("{err:s} :: inputs were :\"{in1:s}\",\"{in2:s}\"".format(err= errstr,in1=in1,in2=in2))
|
||||
# else:
|
||||
# raise ValueError("Props failed ungracefully with inputs:\"{in1:s}\",\"{in2:s}\"; please file a ticket at https://github.com/ibell/coolprop/issues".format(in1=in1,in2=in2))
|
||||
# raise ValueError("Props failed ungracefully with inputs:\"{in1:s}\",\"{in2:s}\"; please file a ticket at https://github.com/CoolProp/CoolProp/issues".format(in1=in1,in2=in2))
|
||||
#
|
||||
cpdef __Props_err2(in1, in2, in3, in4, in5, in6):
|
||||
errstr = get_global_param_string('errstring')
|
||||
errstr = _get_global_param_string('errstring')
|
||||
if not len(errstr) == 0:
|
||||
raise ValueError("{err:s} :: inputs were:\"{in1:s}\",\"{in2:s}\",{in3:0.16e},\"{in4:s}\",{in5:0.16e},\"{in6:s}\"".format(err=errstr,in1=in1,in2=in2,in3=in3,in4=in4,in5=in5,in6=in6))
|
||||
else:
|
||||
raise ValueError("Props failed ungracefully :: inputs were:\"{in1:s}\",\"{in2:s}\",{in3:0.16e},\"{in4:s}\",{in5:0.16e},\"{in6:s}\"; please file a ticket at https://github.com/ibell/coolprop/issues".format(in1=in1,in2=in2,in3=in3,in4=in4,in5=in5,in6=in6))
|
||||
raise ValueError("Props failed ungracefully :: inputs were:\"{in1:s}\",\"{in2:s}\",{in3:0.16e},\"{in4:s}\",{in5:0.16e},\"{in6:s}\"; please file a ticket at https://github.com/CoolProp/CoolProp/issues".format(in1=in1,in2=in2,in3=in3,in4=in4,in5=in5,in6=in6))
|
||||
|
||||
# cpdef Props(in1, in2, in3, in4, in5, in6, in7 = None):
|
||||
# """
|
||||
@@ -214,11 +221,12 @@ cpdef string get_REFPROPname(str Fluid):
|
||||
# empty string if Fluid not in CoolProp, "Bad key" if key is invalid
|
||||
# """
|
||||
# return _get_BibTeXKey(Fluid, key)
|
||||
# cpdef string get_errstr():
|
||||
# """
|
||||
# Return the current error string
|
||||
# """
|
||||
# return _get_global_param_string("errstring")
|
||||
cpdef string get_errstr():
|
||||
"""
|
||||
Return the current error string
|
||||
"""
|
||||
return _get_global_param_string("errstring")
|
||||
|
||||
cpdef set_debug_level(int level):
|
||||
"""
|
||||
Set the current debug level as integer in the range [0,10]
|
||||
@@ -351,7 +359,7 @@ cdef class State:
|
||||
# return rebuildState,(d,)
|
||||
|
||||
cpdef set_Fluid(self, string Fluid, string backend):
|
||||
self.pAS = AbstractState.AbstractState(backend, Fluid)
|
||||
self.pAS = AbstractState(backend, Fluid)
|
||||
|
||||
# cpdef update_ph(self, double p, double h):
|
||||
# """
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
from __future__ import absolute_import
|
||||
|
||||
from . import AbstractState
|
||||
from .CoolProp import AbstractState
|
||||
from . import CoolProp
|
||||
from . import HumidAirProp
|
||||
from . import State
|
||||
from .constants import *
|
||||
|
||||
__fluids__ = CoolProp.get_global_param_string(b'FluidList')
|
||||
__fluids__ = CoolProp.get_global_param_string(b'FluidsList').split(b',')
|
||||
__incompressibles__ = CoolProp.get_global_param_string(b'IncompressibleList')
|
||||
__version__ = CoolProp.get_global_param_string(b'version')
|
||||
__gitrevision__ = CoolProp.get_global_param_string(b'gitrevision')
|
||||
|
||||
@@ -2,6 +2,7 @@ from __future__ import print_function
|
||||
|
||||
def copy_files():
|
||||
import shutil
|
||||
shutil.rmtree(os.path.join('CoolProp5','include'), ignore_errors = True)
|
||||
shutil.copytree(os.path.join(CProot, 'include'), os.path.join('CoolProp5','include'))
|
||||
shutil.copy2(os.path.join(CProot, 'CoolPropBibTeXLibrary.bib'), os.path.join('CoolProp5', 'CoolPropBibTeXLibrary.bib'))
|
||||
|
||||
@@ -119,10 +120,7 @@ if __name__=='__main__':
|
||||
cython_directives = cython_directives
|
||||
)
|
||||
)
|
||||
|
||||
AbstractState_module = Extension('CoolProp5.AbstractState',
|
||||
[os.path.join('CoolProp5','AbstractState.' + cy_ext)] + sources,
|
||||
**common_args)
|
||||
|
||||
CoolProp_module = Extension('CoolProp5.CoolProp',
|
||||
[os.path.join('CoolProp5','CoolProp.' + cy_ext)] + sources,
|
||||
**common_args)
|
||||
@@ -134,7 +132,7 @@ if __name__=='__main__':
|
||||
if not pypi:
|
||||
copy_files()
|
||||
|
||||
ext_modules = [CoolProp_module, AbstractState_module, constants_module]
|
||||
ext_modules = [CoolProp_module, constants_module]
|
||||
|
||||
if USE_CYTHON:
|
||||
ext_modules = cythonize(ext_modules)
|
||||
|
||||
Reference in New Issue
Block a user