400 lines
11 KiB
C
400 lines
11 KiB
C
/* Submodel PNL0003 skeleton created by AME Submodel editing utility
|
|
mer. juin 20 14:17:28 2018 */
|
|
|
|
|
|
|
|
#include <math.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include "ameutils.h"
|
|
/* *******************************************************************************
|
|
TITLE : PNL0003 (C-R-C)
|
|
------------------------------------------------------------------------------
|
|
DESCRIPTION :
|
|
PNL0003 is a submodel of a pneumatic pipe with only compressibility
|
|
and friction effects taking into account heat exchange.
|
|
|
|
The compressibility of the gas is taken into account by using a
|
|
simple polytropic model or a more complex one taking into account
|
|
heat exchange.
|
|
|
|
The polytropic model is a simplified form of the general internal
|
|
energy model based on the first law of thermodynamics. The polytropic
|
|
approach is obtained by representing the thermal exchange phenomena
|
|
by a polytropic constant k. In that case, the temperature and
|
|
pressure are no more independent variables.
|
|
|
|
The reduction of the complexity of the model implies a lack of
|
|
accuracy. For general studies, you'd better use the heat exchange
|
|
approach.
|
|
|
|
Pipe friction is taken into account using a friction factor based on
|
|
the Reynolds number and the relative roughness.
|
|
|
|
The temperature and pressure in each two volumes are state variables.
|
|
------------------------------------------------------------------------------
|
|
USAGE :
|
|
Use this submodel to simulate a pneumatic pipe with compressibility
|
|
and friction effects, when the Mach number is low, ie gas velocity
|
|
< 0.3 * speed of sound .
|
|
|
|
PNL0003 is basically similar to PNL0001 and PNL0002 differing only in the
|
|
input and output requirements.
|
|
|
|
The submodels PNGD01 or PNGD02 should be included in your circuit to
|
|
define the characteristics of the gas.
|
|
------------------------------------------------------------------------------
|
|
PARAMETER SETTINGS :
|
|
------------------------------------------------------------------------------
|
|
DATE OF CREATION / AUTHOR :
|
|
2002 FS from PNL03 SN.
|
|
------------------------------------------------------------------------------
|
|
REVISIONS :
|
|
------------------------------------------------------------------------------
|
|
LIST OF FUNCTIONS USED :
|
|
pn2getatp_() : get atmospheric pressure
|
|
pn2ri_() : get perfect gas constant
|
|
pn2vol1_() : polytropic model for chambers
|
|
pn2vol_() : heat exchange model for chambers
|
|
pn2pipefr_() : frictional coefficient in pneumatic pipes
|
|
------------------------------------------------------------------------------
|
|
SOURCE :
|
|
|
|
This material contains trade secrets or otherwise confidential
|
|
information owned by Siemens Industry Software Inc. or its
|
|
affiliates (collectively, "Siemens"), or its licensors. Access to
|
|
and use of this information is strictly limited as set forth in the
|
|
Customer's applicable agreements with Siemens.
|
|
|
|
Unpublished work. Copyright 2023 Siemens
|
|
|
|
******************************************************************************* */
|
|
|
|
#define _SUBMODELNAME_ "PNL0003"
|
|
|
|
/* >>>>>>>>>>>>Insert Private Code Here. */
|
|
#define TABFR 0 /* real store 0, 1 & 2 are used by pn2pipefr */
|
|
#define PATM 3
|
|
#define AREA 4
|
|
#define HALFVOL 5
|
|
#define HALFAREAEX 6
|
|
|
|
|
|
#define SPL_FR 0
|
|
/* <<<<<<<<<<<<End of Private Code. */
|
|
|
|
|
|
/* There are 6 real parameters:
|
|
|
|
diam diameter of pipe [mm -> m]
|
|
le pipe length [m]
|
|
rr relative roughness [null]
|
|
k polytropic constant [null]
|
|
kth thermal exchange coefficient [J/m**2/K/s -> W/m**2/K]
|
|
extemp external temperature [K]
|
|
*/
|
|
|
|
|
|
/* There are 2 integer parameters:
|
|
|
|
gi gas type index
|
|
mode model
|
|
*/
|
|
|
|
void pnl0003in_(int *n, double rp[6], int ip[2], double c[7]
|
|
, int ic[1], double *t1, double *p1, double *t2, double *p2)
|
|
|
|
{
|
|
int loop, error;
|
|
/* >>>>>>>>>>>>Extra Initialization Function Declarations Here. */
|
|
double vol, areaex;
|
|
/* <<<<<<<<<<<<End of Extra Initialization declarations. */
|
|
int gi, mode;
|
|
double diam, le, rr, k, kth, extemp;
|
|
|
|
gi = ip[0];
|
|
mode = ip[1];
|
|
|
|
diam = rp[0];
|
|
le = rp[1];
|
|
rr = rp[2];
|
|
k = rp[3];
|
|
kth = rp[4];
|
|
extemp = rp[5];
|
|
loop = 0;
|
|
error = 0;
|
|
|
|
/*
|
|
If necessary, check values of the following:
|
|
|
|
rp[0..5]
|
|
*t1
|
|
*p1
|
|
*t2
|
|
*p2
|
|
*/
|
|
|
|
|
|
/* >>>>>>>>>>>>Initialization Function Check Statements. */
|
|
|
|
pn2_valid_gas_(&gi, &error);
|
|
|
|
if (*p1 < -GPATMOS)
|
|
{
|
|
error = 2;
|
|
amefprintf(stderr, "\nInitial pressure at port 1 should be > 0 [barA].\n");
|
|
}
|
|
|
|
if (*t1 <= 0.0)
|
|
{
|
|
error = 2;
|
|
amefprintf(stderr, "\nInitial temperature at port 1 should be > 0 [K].\n");
|
|
}
|
|
|
|
if (*p2 < -GPATMOS)
|
|
{
|
|
error = 2;
|
|
amefprintf(stderr, "\nInitial pressure at port 2 should be > 0 [barA].\n");
|
|
}
|
|
|
|
if (*t2 <= 0.0)
|
|
{
|
|
error = 2;
|
|
amefprintf(stderr, "\nInitial temperature at port 2 should be > 0 [K].\n");
|
|
}
|
|
|
|
if (diam <= 0.0)
|
|
{
|
|
error = 2;
|
|
amefprintf(stderr, "\nDiameter of pipe should be > 0 [mm].\n");
|
|
}
|
|
|
|
if (le <= 0.0)
|
|
{
|
|
error = 2;
|
|
amefprintf(stderr, "\nPipe length should be > 0 [m].\n");
|
|
}
|
|
|
|
if (rr < 0.0)
|
|
{
|
|
error = 2;
|
|
amefprintf(stderr, "\nRelative roughness should be >= 0.\n");
|
|
}
|
|
|
|
if (mode == 1)
|
|
{
|
|
if (k <= 0.)
|
|
{
|
|
error = 2;
|
|
amefprintf(stderr, "\nPolytropic constant should be > 0.\n");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (kth < 0.)
|
|
{
|
|
error = 2;
|
|
amefprintf(stderr, "\nThermal exchange coefficient should be >= 0 [J/m**2/K/s].\n");
|
|
}
|
|
|
|
if (extemp <= 0.)
|
|
{
|
|
error = 2;
|
|
amefprintf(stderr, "\nExternal temperature should be > 0 [K].\n");
|
|
}
|
|
}
|
|
|
|
/* <<<<<<<<<<<<End of Initialization Check Statements. */
|
|
|
|
/* Integer parameter checking: */
|
|
|
|
if (gi < 1 || gi > 99)
|
|
{
|
|
amefprintf(stderr, "\ngas type index must be in range [1..99].\n");
|
|
error = 2;
|
|
}
|
|
if (mode < 1 || mode > 2)
|
|
{
|
|
amefprintf(stderr, "\nmodel must be in range [1..2].\n");
|
|
error = 2;
|
|
}
|
|
|
|
SUBMODEL_HANDLE_AND_RESET_ERROR(_SUBMODELNAME_, n, error)
|
|
|
|
/* Common -> SI units conversions. */
|
|
|
|
rp[0] *= 1.00000000000000e-003;
|
|
diam = rp[0];
|
|
|
|
|
|
/* >>>>>>>>>>>>Initialization Function Executable Statements. */
|
|
/* set atmospheric pressure */
|
|
c[PATM] = pn2getatp_();
|
|
|
|
/* Compute the cross-sectional area of pipe. */
|
|
c[AREA] = M_PI * (diam) * (diam) / 4.0;
|
|
|
|
/* Compute volume of pipe. */
|
|
vol = c[AREA] * le;
|
|
|
|
/* Divide the volume in 2 identical volumes */
|
|
c[HALFVOL] = 0.5 * vol;
|
|
|
|
/* Compute exchange area of pipe. */
|
|
areaex = M_PI * diam * le;
|
|
|
|
/* Divide the exchange area of pipe in 2 identical areas */
|
|
c[HALFAREAEX] = 0.5 * areaex;
|
|
|
|
/* <<<<<<<<<<<<End of Initialization Executable Statements. */
|
|
}
|
|
|
|
/* There are 2 ports.
|
|
|
|
Port 1 has 4 variables:
|
|
|
|
1 t1 temperature at port 1 [K] explicit state (derivative `dt1')
|
|
2 p1 pressure at port 1 [Pa] explicit state (derivative `dp1')
|
|
3 dh1 enthalpy flow rate at port 1 [J/s -> W] basic variable input
|
|
4 dm1 mass flow rate at port 1 [g/s -> kg/s] basic variable input
|
|
|
|
Port 2 has 4 variables:
|
|
|
|
1 t2 temperature at port 2 [K] explicit state (derivative `dt2')
|
|
2 p2 pressure at port 2 [Pa] explicit state (derivative `dp2')
|
|
3 dh2 enthalpy flow rate at port 2 [J/s -> W] basic variable input
|
|
4 dm2 mass flow rate at port 2 [g/s -> kg/s] basic variable input
|
|
*/
|
|
|
|
/* There are 7 internal variables.
|
|
|
|
1 dhctr enthalpy flow at center of pipe [J/s -> W] basic variable
|
|
2 dmctr mass flow at center of pipe [g/s -> kg/s] basic variable
|
|
3 mgas mass of gas in pipe [g -> kg] basic variable
|
|
4 re Reynolds number [null] basic variable
|
|
5 cm mass flow parameter (cm) [(kg*K/J)**(1/2)] basic variable
|
|
6 v mean gas velocity [m/s] basic variable
|
|
7 ff friction factor [null] basic variable
|
|
*/
|
|
|
|
void pnl0003_(int *n, double *t1, double *dt1, double *p1, double *dp1
|
|
, double *dh1, double *dm1, double *t2, double *dt2, double *p2
|
|
, double *dp2, double *dh2, double *dm2, double *dhctr
|
|
, double *dmctr, double *mgas, double *re, double *cm, double *v
|
|
, double *ff, double rp[6], int ip[2], double c[7], int ic[1])
|
|
|
|
{
|
|
int loop;
|
|
/* >>>>>>>>>>>>Extra Calculation Function Declarations Here. */
|
|
static double zero = 0.0;
|
|
double dh1i, dm1i;
|
|
double dh2i, dm2i;
|
|
double sdh1, sdm1;
|
|
double sdh2, sdm2;
|
|
double m1, m2;
|
|
double dq1, dq2;
|
|
double pa1, pa2;
|
|
double dmgas;
|
|
double r;
|
|
int dummyreg;
|
|
/* <<<<<<<<<<<<End of Extra Calculation declarations. */
|
|
int gi, mode;
|
|
double diam, le, rr, k, kth, extemp;
|
|
|
|
gi = ip[0];
|
|
mode = ip[1];
|
|
|
|
diam = rp[0];
|
|
le = rp[1];
|
|
rr = rp[2];
|
|
k = rp[3];
|
|
kth = rp[4];
|
|
extemp = rp[5];
|
|
loop = 0;
|
|
|
|
/* Common -> SI units conversions. */
|
|
|
|
*dm1 *= 1.00000000000000e-003;
|
|
*dm2 *= 1.00000000000000e-003;
|
|
|
|
/*
|
|
Set all submodel outputs below:
|
|
|
|
*dt1 = ??;
|
|
*dp1 = ??;
|
|
*dt2 = ??;
|
|
*dp2 = ??;
|
|
*dhctr = ??;
|
|
*dmctr = ??;
|
|
*mgas = ??;
|
|
*re = ??;
|
|
*cm = ??;
|
|
*v = ??;
|
|
*ff = ??;
|
|
*/
|
|
|
|
|
|
|
|
/* >>>>>>>>>>>>Calculation Function Executable Statements. */
|
|
|
|
/* set absolute pressures */
|
|
pa1 = *p1 + c[PATM];
|
|
pa2 = *p2 + c[PATM];
|
|
|
|
/* Compute flow through the pipe */
|
|
pn2pipefr_(&pa1, t1, &pa2, t2, &diam, &rr, &le, &c[AREA], re, v, ff,
|
|
&dh1i, &dm1i, &dh2i, &dm2i, cm, &c[TABFR], &gi, &ic[SPL_FR], &dummyreg);
|
|
|
|
/* Enthalpy flow and mass flow at center of pipe */
|
|
*dhctr = dh1i; /* = -dh2i */
|
|
*dmctr = dm1i; /* = -dm2i */
|
|
|
|
/* Compute the sum of the flows inside each volume */
|
|
sdm1 = *dm1 + dm1i;
|
|
sdh1 = *dh1 + dh1i;
|
|
sdm2 = *dm2 + dm2i;
|
|
sdh2 = *dh2 + dh2i;
|
|
|
|
dmgas = sdm1 + sdm2;
|
|
|
|
/*** temperature & pressure variation ***/
|
|
if (mode == 1) /* Polytropic model. */
|
|
{
|
|
r = pn2ri_(&gi);
|
|
|
|
/* Current mass in each volume */
|
|
m1 = pa1 * c[HALFVOL] / (*t1 * r);
|
|
m2 = pa2 * c[HALFVOL] / (*t2 * r);
|
|
|
|
pn2vol1_(dt1, dp1, t1, &pa1,
|
|
&sdm1, &m1, &zero, &c[HALFVOL], &k,&gi);
|
|
|
|
pn2vol1_(dt2, dp2, t2, &pa2,
|
|
&sdm2, &m2, &zero, &c[HALFVOL], &k,&gi);
|
|
}
|
|
else /* Heat exchange. */
|
|
{
|
|
dq1 = kth * c[HALFAREAEX] * (extemp - *t1);
|
|
|
|
pn2vol_(dt1, dp1, &m1, t1, &pa1,
|
|
&sdm1, &sdh1, &c[HALFVOL], &zero, &dq1, &gi);
|
|
|
|
dq2 = kth * c[HALFAREAEX] * (extemp - *t2);
|
|
|
|
pn2vol_(dt2, dp2, &m2, t2, &pa2,
|
|
&sdm2, &sdh2, &c[HALFVOL], &zero, &dq2, &gi);
|
|
}
|
|
|
|
*mgas = m1 + m2;
|
|
|
|
/* <<<<<<<<<<<<End of Calculation Executable Statements. */
|
|
|
|
/* SI -> Common units conversions. */
|
|
|
|
*dm1 /= 1.00000000000000e-003;
|
|
*dm2 /= 1.00000000000000e-003;
|
|
*dmctr /= 1.00000000000000e-003;
|
|
*mgas /= 1.00000000000000e-003;
|
|
}
|
|
|