📄 gasbase.cpp
字号:
#include "..\\include\\GasBase.h"
namespace XZGas
{
//Members of class GasData:
/*=================================================================================================
Constructor
Parameters:
n[]: the name of the gas
l: the length of data array A
Action:
Allocate space the 1st dimension for array A used to precise Cp, initiate the name of the Gas.
-------------------------------------------------------------------------------------------------*/
GasData::GasData(char n[],unsigned int lA):
A(lA)
{
//if n is not a gas name, the allocation will not take any sense
if(strcmp(n,"NoNameGas")!=0)
{
Name=new char[strlen(n)+1];
strcpy(Name,n);
}
else
{
Name=NULL;
}
}
/*===================================================================================================
Copy constructor
Action:
If the name of source gas provided is not null, allocate memory for the name string of this and
copy the data for the source gas. If the name of source gas provided is null, make this name null.
Initiate the 2-d array A with the A in the source gas.
Copy other data from the source gas.
---------------------------------------------------------------------------------------------------*/
GasData::GasData(const GasData &scrGas):
A(scrGas.A)
{
if(scrGas.Name!=NULL)
{
Name=new char[strlen(scrGas.Name)+1];
strcpy(Name,scrGas.Name);
}
else
{
Name=NULL;
}
this->pc=scrGas.pc; //critical pressure Unit: Pa
this->Tc=scrGas.Tc; //critical temperature Unit: K
this->vc=scrGas.vc; //critical special volume Unit: m3/kg
this->M=scrGas.M; //mass per mole Unit: kg/mol
//the point on which h,u and s are zero
this->p0=scrGas.p0;
this->T0=scrGas.T0;
this->h0=scrGas.h0;
this->u0=scrGas.u0;
this->s0=scrGas.s0;
this->BBEquData=scrGas.BBEquData;
this->MHEquData=scrGas.MHEquData;
}
/*=============================================================================================
Destructor
Action:
If the name of this gas is not null, free the memory for it.
---------------------------------------------------------------------------------------------*/
GasData::~GasData()
{
if(Name!=NULL)
{
delete []this->Name;
}
}
/*==============================================================================================
The overload of the operator =
Parameters:
scrGas(const GasData &): providing the target gas which gives the data to copy
Action:
If this gas is the same as the source gas provided, return this.
If the name of this gas has already allocated space, free it. And then, allocate new memory
space for it and copy the data of the name of source gas.
Copy other data of the source gas.
----------------------------------------------------------------------------------------------*/
inline GasData &GasData::operator =(const GasData &scrGas)
{
if(this == &scrGas)
return *this;
if(Name!=NULL)
delete []Name;
Name=new char[strlen(scrGas.Name)+1];
strcpy(Name,scrGas.Name);
A=scrGas.A;
this->pc=scrGas.pc; //critical pressure Unit: Pa
this->Tc=scrGas.Tc; //critical temperature Unit: K
this->vc=scrGas.vc; //critical special volume Unit: m3/kg
this->M=scrGas.M; //mass per mole Unit: kg/mol
//the zero point
this->p0=scrGas.p0;
this->T0=scrGas.T0;
this->h0=scrGas.h0;
this->u0=scrGas.u0;
this->s0=scrGas.s0;
this->BBEquData=scrGas.BBEquData;
this->MHEquData=scrGas.MHEquData;
return *this;
}
//Members of class GasModel:
//heat capacity with constant pressure
inline double GasModel::_Cp(double TT)
{
unsigned int iA=FindA(TT);
unsigned int length1=A.SubLen(iA);
double cp=A[iA][length1-1];
//cp=((((A[n]*TT+A[n-1])*TT+A[n-2])+....)+A[0]
for(int i=length1-2; i>=0; --i)
cp=cp*TT+A[iA][i];
return cp;
}
//the integration of the above heat capacity function only with temperature
inline double GasModel::_ICp(double TT)
{
unsigned int iA=FindA(TT);
unsigned int length1=A.SubLen(iA);
double icp=A[iA][length1-1]/length1;
for(int i=length1-2; i>0; --i)
icp=icp*TT+A[iA][i-1]/i;
icp*=TT;
return icp;
}
//the integration of Cp/T with temperature T only
inline double GasModel::_ICpT(double TT)
{
unsigned int iA=FindA(TT);
unsigned int length1=A.SubLen(iA);
double icpt=A[iA][length1-1]/(length1-1);
for(int i=length1-2;i>0;--i)
icpt=icpt*TT+A[iA][i]/i;
icpt*=TT;
icpt+=A[iA][0]*log(TT);
return icpt;
}
//locate the temperature segment according to the temperature TT
inline unsigned int GasModel::FindA(double TT)
{
unsigned int index,len;
len=A.Len();
if(len==1)
return 0;
else
{
for(index=0;index<len;++index)
if(TT<A.Tl(index))
return index;
return len-1;
}
}
/*=======================================================================================
Constructor:
---------------------------------------------------------------------------------------*/
GasModel::GasModel(const GasData &gas):
A(gas.A)
{
GasName=new char[strlen(gas.Name)+1];
strcpy(GasName,gas.Name);
M=gas.M; //mass per mole Unit: kg/mol
Rg=R/M;
p0=gas.p0;
T0=gas.T0;
h0=gas.h0;
u0=gas.u0;
s0=gas.s0;
}
/*=======================================================================================
Destructor:
---------------------------------------------------------------------------------------*/
GasModel::~GasModel()
{
delete []GasName;
}
const char* GasModel::Name()const
{
return GasName;
}
inline double GasModel::Z(double TT,double pp)
{
double vv=v(TT,pp);
return pp*vv/Rg/TT;
}
inline void GasModel::ChangeGas(const GasData &newgas)
{
delete []GasName;
GasName=new char[strlen(newgas.Name)+1];
strcpy(GasName, newgas.Name);
A=newgas.A;
M=newgas.M; //mass per mole Unit: kg/mol
Rg=R/M;
p0=newgas.p0;
T0=newgas.T0;
h0=newgas.h0;
u0=newgas.u0;
s0=newgas.s0;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -