mirror of
https://github.com/CoolProp/CoolProp.git
synced 2026-01-23 12:58:03 -05:00
Merge pull request #493 from mikekaganski/master
Avoid copying of parameters; some fixes for _HAPropsSI_inputs
This commit is contained in:
@@ -141,8 +141,8 @@
|
||||
|
||||
void MatInv_2(double A[2][2] , double B[2][2]);
|
||||
|
||||
double root_sum_square(std::vector<double> x);
|
||||
double interp1d(std::vector<double> *x, std::vector<double> *y, double x0);
|
||||
double root_sum_square(const std::vector<double> &x);
|
||||
double interp1d(const std::vector<double> *x, const std::vector<double> *y, double x0);
|
||||
double powInt(double x, int y);
|
||||
|
||||
#define POW2(x) ((x)*(x))
|
||||
@@ -283,7 +283,7 @@
|
||||
{
|
||||
return get_double(s);
|
||||
};
|
||||
std::vector<double> get_double_vector(std::string s)
|
||||
const std::vector<double>& get_double_vector(std::string s)
|
||||
{
|
||||
if (double_vectors.find(s) != double_vectors.end()){
|
||||
return double_vectors[s];
|
||||
@@ -292,7 +292,7 @@
|
||||
throw CoolProp::ValueError(format("%s could not be matched in get_double_vector",s.c_str()));
|
||||
}
|
||||
};
|
||||
std::vector<std::string> get_string_vector(std::string s)
|
||||
const std::vector<std::string>& get_string_vector(std::string s)
|
||||
{
|
||||
if (string_vectors.find(s) != string_vectors.end()){
|
||||
return string_vectors[s];
|
||||
|
||||
@@ -16,9 +16,7 @@ namespace CoolProp {
|
||||
struct SimpleState
|
||||
{
|
||||
double rhomolar, T, p, hmolar, smolar, umolar, Q;
|
||||
SimpleState(){rhomolar = _HUGE; T = _HUGE; p = _HUGE;
|
||||
hmolar = _HUGE; smolar = _HUGE, umolar = _HUGE;
|
||||
Q = _HUGE;}
|
||||
SimpleState() : rhomolar(_HUGE), T(_HUGE), p(_HUGE), hmolar(_HUGE), smolar(_HUGE), umolar(_HUGE), Q(_HUGE) {}
|
||||
bool is_valid(){return ValidNumber(rhomolar) && ValidNumber(T) && ValidNumber(hmolar) && ValidNumber(p);}
|
||||
};
|
||||
|
||||
@@ -27,7 +25,7 @@ struct SsatSimpleState : public SimpleState
|
||||
{
|
||||
enum SsatSimpleStateEnum {SSAT_MAX_NOT_SET=0, SSAT_MAX_DOESNT_EXIST, SSAT_MAX_DOES_EXIST};
|
||||
SsatSimpleStateEnum exists;
|
||||
SsatSimpleState(){ SimpleState(); }
|
||||
SsatSimpleState() : SimpleState() {}
|
||||
};
|
||||
|
||||
|
||||
@@ -42,7 +40,7 @@ enum parameters{
|
||||
INVALID_PARAMETER = 0,
|
||||
|
||||
// General parameters
|
||||
igas_constant,
|
||||
igas_constant,
|
||||
imolar_mass,
|
||||
iacentric_factor,
|
||||
irhomolar_reducing,
|
||||
@@ -52,7 +50,7 @@ enum parameters{
|
||||
irhomass_reducing,
|
||||
irhomass_critical,
|
||||
iP_critical,
|
||||
iP_reducing,
|
||||
iP_reducing,
|
||||
iT_triple,
|
||||
iP_triple,
|
||||
iT_min,
|
||||
@@ -185,7 +183,7 @@ enum fluid_types{FLUID_TYPE_PURE, FLUID_TYPE_PSEUDOPURE, FLUID_TYPE_REFPROP, FLU
|
||||
// !! If you add a parameter, update the map in the corresponding CPP file !!
|
||||
/// These are input pairs that can be used (in each pair, input keys are sorted alphabetically)
|
||||
enum input_pairs{
|
||||
INPUT_PAIR_INVALID = 0, // Default (invalid) value
|
||||
INPUT_PAIR_INVALID = 0, // Default (invalid) value
|
||||
QT_INPUTS, ///< Molar quality, Temperature in K
|
||||
PQ_INPUTS, ///< Pressure in Pa, Molar quality
|
||||
QSmolar_INPUTS, ///< Molar quality, Entropy in J/mol/K
|
||||
|
||||
@@ -1169,7 +1169,7 @@ public:
|
||||
/**
|
||||
@param key Either a CAS number or the name (CAS number should be preferred)
|
||||
*/
|
||||
CoolPropFluid& get(std::string key)
|
||||
CoolPropFluid& get(const std::string &key)
|
||||
{
|
||||
std::map<std::string, std::size_t>::iterator it;
|
||||
// Try to find it
|
||||
|
||||
@@ -33,8 +33,8 @@ public:
|
||||
}
|
||||
}
|
||||
else{
|
||||
components = std::vector<CoolPropFluid*>(1,&(get_library().get(name)));
|
||||
mole_fractions = std::vector<double>(1,1);
|
||||
components.push_back(&(get_library().get(name))); // Until now it's empty
|
||||
mole_fractions.push_back(1.);
|
||||
}
|
||||
// Set the components
|
||||
set_components(components);
|
||||
|
||||
@@ -51,7 +51,7 @@ HelmholtzEOSMixtureBackend::HelmholtzEOSMixtureBackend(const std::vector<std::st
|
||||
// Set the phase to default unknown value
|
||||
_phase = iphase_unknown;
|
||||
}
|
||||
HelmholtzEOSMixtureBackend::HelmholtzEOSMixtureBackend(std::vector<CoolPropFluid*> components, bool generate_SatL_and_SatV) {
|
||||
HelmholtzEOSMixtureBackend::HelmholtzEOSMixtureBackend(const std::vector<CoolPropFluid*> &components, bool generate_SatL_and_SatV) {
|
||||
|
||||
// Set the components and associated flags
|
||||
set_components(components, generate_SatL_and_SatV);
|
||||
@@ -59,7 +59,7 @@ HelmholtzEOSMixtureBackend::HelmholtzEOSMixtureBackend(std::vector<CoolPropFluid
|
||||
// Set the phase to default unknown value
|
||||
_phase = iphase_unknown;
|
||||
}
|
||||
void HelmholtzEOSMixtureBackend::set_components(std::vector<CoolPropFluid*> components, bool generate_SatL_and_SatV) {
|
||||
void HelmholtzEOSMixtureBackend::set_components(const std::vector<CoolPropFluid*> &components, bool generate_SatL_and_SatV) {
|
||||
|
||||
// Copy the components
|
||||
this->components = components;
|
||||
@@ -99,8 +99,8 @@ void HelmholtzEOSMixtureBackend::set_mole_fractions(const std::vector<long doubl
|
||||
throw ValueError(format("size of mole fraction vector [%d] does not equal that of component vector [%d]",mole_fractions.size(), N));
|
||||
}
|
||||
// Copy values without reallocating memory
|
||||
this->resize(N);
|
||||
std::copy( mole_fractions.begin(), mole_fractions.end(), this->mole_fractions.begin() );
|
||||
this->mole_fractions = mole_fractions; // Most effective copy
|
||||
this->resize(N); // No reallocation of this->mole_fractions happens
|
||||
// Resize the vectors for the liquid and vapor, but only if they are in use
|
||||
if (this->SatL.get() != NULL){
|
||||
this->SatL->resize(N);
|
||||
|
||||
@@ -35,7 +35,7 @@ protected:
|
||||
public:
|
||||
HelmholtzEOSMixtureBackend(){
|
||||
imposed_phase_index = iphase_not_imposed; _phase = iphase_unknown;};
|
||||
HelmholtzEOSMixtureBackend(std::vector<CoolPropFluid*> components, bool generate_SatL_and_SatV = true);
|
||||
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(){};
|
||||
shared_ptr<ReducingFunction> Reducing;
|
||||
@@ -119,7 +119,7 @@ public:
|
||||
* @param components The components that are to be used in this mixture
|
||||
* @param generate_SatL_and_SatV true if SatL and SatV classes should be added, false otherwise. Added so that saturation classes can be added without infinite recursion of adding saturation classes
|
||||
*/
|
||||
void set_components(std::vector<CoolPropFluid*> components, bool generate_SatL_and_SatV = true);
|
||||
void set_components(const std::vector<CoolPropFluid*> &components, bool generate_SatL_and_SatV = true);
|
||||
|
||||
/** \brief Specify the phase - this phase will always be used in calculations
|
||||
*
|
||||
|
||||
@@ -47,7 +47,7 @@ std::string get_csv_predefined_mixtures()
|
||||
return strjoin(out, ",");
|
||||
}
|
||||
|
||||
bool is_predefined_mixture(const std::string name, Dictionary &dict){
|
||||
bool is_predefined_mixture(const std::string &name, Dictionary &dict){
|
||||
std::map<std::string, Dictionary>::iterator iter = predefined_mixtures_library.predefined_mixture_map.find(name);
|
||||
if (iter != predefined_mixtures_library.predefined_mixture_map.end()){
|
||||
dict = iter->second;
|
||||
|
||||
@@ -14,7 +14,7 @@ std::string get_csv_mixture_binary_pairs();
|
||||
/** \brief Get the parameters for a predefined mixture - R410A, R404A, etc.
|
||||
*
|
||||
*/
|
||||
bool is_predefined_mixture(const std::string name, Dictionary &dict);
|
||||
bool is_predefined_mixture(const std::string &name, Dictionary &dict);
|
||||
|
||||
/** \brief Get a comma-separated list of predefined mixtures in
|
||||
*
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
#include "MatrixMath.h"
|
||||
#include "Exceptions.h"
|
||||
|
||||
double root_sum_square(std::vector<double> x)
|
||||
double root_sum_square(const std::vector<double> &x)
|
||||
{
|
||||
double sum = 0;
|
||||
for (unsigned int i=0; i<x.size(); i++)
|
||||
@@ -67,7 +67,7 @@ std::vector<std::string> strsplit(std::string s, char del)
|
||||
return v;
|
||||
}
|
||||
|
||||
double interp1d(std::vector<double> *x, std::vector<double> *y, double x0)
|
||||
double interp1d(const std::vector<double> *x, const std::vector<double> *y, double x0)
|
||||
{
|
||||
std::size_t i,L,R,M;
|
||||
L=0;
|
||||
|
||||
@@ -1350,23 +1350,21 @@ bool match_input_key(std::vector<givens> input_keys, givens key)
|
||||
/// Calculate T (dry bulb temp) and psi_w (water mole fraction) given the pair of inputs
|
||||
double _HAPropsSI_inputs(double p, const std::vector<givens> &input_keys, const std::vector<double> &input_vals, double &T, double &psi_w)
|
||||
{
|
||||
if (match_input_key(input_keys, GIVEN_T)) // Found T (or alias) as an input
|
||||
long key = get_input_key(input_keys, GIVEN_T);
|
||||
if (key >= 0) // Found T (or alias) as an input
|
||||
{
|
||||
long key = get_input_key(input_keys, GIVEN_T);
|
||||
long other = 1 - key; // 2 element vector
|
||||
T = input_vals[key];
|
||||
switch(input_keys[other]){
|
||||
switch(givens othergiven = input_keys[other]){
|
||||
case GIVEN_RH:
|
||||
psi_w = MoleFractionWater(T, p, GIVEN_RH, input_vals[other]); break;
|
||||
case GIVEN_HUMRAT:
|
||||
psi_w = MoleFractionWater(T, p, GIVEN_HUMRAT, input_vals[other]); break;
|
||||
case GIVEN_TDP:
|
||||
psi_w = MoleFractionWater(T, p, GIVEN_TDP, input_vals[other]); break;
|
||||
psi_w = MoleFractionWater(T, p, othergiven, input_vals[other]); break;
|
||||
default:
|
||||
{
|
||||
// Find the value for W
|
||||
double W_guess = 0.0001;
|
||||
double W = Secant_HAProps_W(p,T,input_keys[other],input_vals[other],W_guess);
|
||||
double W = Secant_HAProps_W(p, T, othergiven, input_vals[other], W_guess);
|
||||
// Mole fraction of water
|
||||
psi_w = MoleFractionWater(T, p, GIVEN_HUMRAT, W);
|
||||
}
|
||||
@@ -1375,15 +1373,14 @@ double _HAPropsSI_inputs(double p, const std::vector<givens> &input_keys, const
|
||||
else
|
||||
{
|
||||
// Need to iterate to find dry bulb temperature since temperature is not provided
|
||||
long key, other;
|
||||
if ((key = get_input_key(input_keys, GIVEN_HUMRAT)) && key >= 0){} // Humidity ratio is given
|
||||
else if ((key = get_input_key(input_keys, GIVEN_RH)) && key >= 0){} // Relative humidity is given
|
||||
else if ((key = get_input_key(input_keys, GIVEN_TDP)) && key >= 0){} // Dewpoint temperature is given
|
||||
if ((key = get_input_key(input_keys, GIVEN_HUMRAT)) >= 0){} // Humidity ratio is given
|
||||
else if ((key = get_input_key(input_keys, GIVEN_RH)) >= 0){} // Relative humidity is given
|
||||
else if ((key = get_input_key(input_keys, GIVEN_TDP)) >= 0){} // Dewpoint temperature is given
|
||||
else{
|
||||
CoolProp::ValueError("Sorry, but currently at least one of the variables as an input to HAPropsSI() must be temperature, relative humidity, humidity ratio, or dewpoint\n Eventually will add a 2-D NR solver to find T and psi_w simultaneously, but not included now\n");
|
||||
throw CoolProp::ValueError("Sorry, but currently at least one of the variables as an input to HAPropsSI() must be temperature, relative humidity, humidity ratio, or dewpoint\n Eventually will add a 2-D NR solver to find T and psi_w simultaneously, but not included now\n");
|
||||
}
|
||||
// 2-element vector
|
||||
other = 1 - key;
|
||||
long other = 1 - key;
|
||||
|
||||
// Main input is the one that you are using in the call to HAPropsSI
|
||||
double MainInputValue = input_vals[key];
|
||||
|
||||
Reference in New Issue
Block a user