87 lines
2.1 KiB
C
87 lines
2.1 KiB
C
#include "NGCal.h"
|
|
#include "Therm.h"
|
|
#include "Detail.h"
|
|
static Therm *ptTherm;
|
|
static Detail *ptDetail;
|
|
int NGCal_Init(void)
|
|
{
|
|
ptDetail = (Detail *)malloc(sizeof(Detail));
|
|
if (NULL == ptDetail )
|
|
{
|
|
return MEMORY_ALLOCATION_ERROR;
|
|
}
|
|
ptTherm = (Therm *)malloc(sizeof(Therm));
|
|
if (NULL == ptTherm )
|
|
{
|
|
return MEMORY_ALLOCATION_ERROR;
|
|
}
|
|
return NGCal_NGCal;
|
|
}
|
|
int NGCal_UnInit(void)
|
|
{
|
|
if (ptDetail) free( ptDetail);
|
|
if (ptTherm) free (ptTherm);
|
|
return 0;
|
|
}
|
|
double SOS(NGParSTRUCT *ptNGPar)
|
|
{
|
|
if (NULL == ptDetail || NULL == ptTherm)
|
|
{
|
|
NGCal_UnInit();
|
|
NGCal_Init();
|
|
}
|
|
ptTherm->Run(ptTherm,ptNGPar, ptDetail);
|
|
ptNGPar->dCstar = 0.0;
|
|
return ptNGPar->dSOS;
|
|
}
|
|
double Crit(NGParSTRUCT *ptNGPar, double dPlenumVelocity)
|
|
{
|
|
double DH, DDH, S, H;
|
|
double tolerance = 1.0;
|
|
double R, P, T, Z;
|
|
int i;
|
|
if (NULL == ptDetail || NULL == ptTherm)
|
|
{
|
|
NGCal_UnInit();
|
|
if (NGCal_NGCal != NGCal_Init())
|
|
{
|
|
ptNGPar->lStatus = MEMORY_ALLOCATION_ERROR;
|
|
return 0.0;
|
|
}
|
|
}
|
|
ptTherm->Run(ptTherm,ptNGPar, ptDetail);
|
|
DH = (ptNGPar->dSOS * ptNGPar->dSOS - dPlenumVelocity * dPlenumVelocity) / 2.0;
|
|
S = ptNGPar->dS;
|
|
H = ptNGPar->dH;
|
|
R = ptNGPar->dRhof;
|
|
P = ptNGPar->dPf;
|
|
Z = ptNGPar->dZf;
|
|
T = ptNGPar->dTf;
|
|
DDH = 10.0;
|
|
for (i = 1; i < MAX_NUM_OF_ITERATIONS; i++)
|
|
{
|
|
ptTherm->HS_Mode(ptTherm,ptNGPar, ptDetail, H - DH, S, true);
|
|
ptTherm->Run(ptTherm,ptNGPar, ptDetail);
|
|
DDH = DH;
|
|
DH = (ptNGPar->dSOS * ptNGPar->dSOS - dPlenumVelocity * dPlenumVelocity) / 2.0;
|
|
if (fabs(DDH - DH) < tolerance) break;
|
|
}
|
|
ptNGPar->dCstar = (ptNGPar->dRhof * ptNGPar->dSOS) / sqrt(R * P * Z);
|
|
ptNGPar->dPf = P;
|
|
ptNGPar->dTf = T;
|
|
ptTherm->Run(ptTherm,ptNGPar, ptDetail);
|
|
return ptNGPar->dCstar;
|
|
}
|
|
double Cperf(NGParSTRUCT *ptNGPar)
|
|
{
|
|
double k, root, exponent;
|
|
k = ptNGPar->dKappa;
|
|
root = 2.0 / (k + 1.0);
|
|
exponent = (k + 1.0) / (k - 1.0);
|
|
return(sqrt(k * pow(root, exponent)));
|
|
}
|
|
double CRi(NGParSTRUCT *ptNGPar)
|
|
{
|
|
return (Cperf(ptNGPar) / sqrt(ptNGPar->dZf));
|
|
}
|