369 lines
10 KiB
C
369 lines
10 KiB
C
/* Submodel PNL0002 skeleton created by AME Submodel editing utility
|
|
mer. juin 20 14:35:13 2018 */
|
|
|
|
|
|
|
|
#include <math.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include "ameutils.h"
|
|
/* *******************************************************************************
|
|
TITLE : PNL0002 (R-C-R)
|
|
------------------------------------------------------------------------------
|
|
DESCRIPTION :
|
|
PNL0002 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 the middle volume 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 .
|
|
|
|
PNL0002 is basically similar to PNL0001 and PNL0003 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 PNL02 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 coeffitient 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_ "PNL0002"
|
|
|
|
/* >>>>>>>>>>>>Insert Private Code Here. */
|
|
#define TABFR 0 /* real store 0, 1 & 2 are used by pn2pipefr */
|
|
#define PATM 3
|
|
#define AREA 4
|
|
#define VOL 5
|
|
#define HALFLE 6
|
|
#define AREAEX 7
|
|
|
|
|
|
#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 pnl0002in_(int *n, double rp[6], int ip[2], double c[8]
|
|
, int ic[1], double *tctr, double *pctr)
|
|
|
|
{
|
|
int loop, error;
|
|
/* >>>>>>>>>>>>Extra Initialization Function Declarations Here. */
|
|
/* <<<<<<<<<<<<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]
|
|
*tctr
|
|
*pctr
|
|
*/
|
|
|
|
|
|
/* >>>>>>>>>>>>Initialization Function Check Statements. */
|
|
|
|
pn2_valid_gas_(&gi, &error);
|
|
|
|
if (*pctr < -GPATMOS)
|
|
{
|
|
error = 2;
|
|
amefprintf(stderr, "\nInitial pressure at center of pipe should be > 0 [barA].\n");
|
|
}
|
|
|
|
if (*tctr <= 0.0)
|
|
{
|
|
error = 2;
|
|
amefprintf(stderr, "\nInitial temperature at center of pipe 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. */
|
|
|
|
/* get atmospheric pressure */
|
|
c[PATM] = pn2getatp_();
|
|
|
|
/* Compute the cross-sectional area of pipe. */
|
|
c[AREA] = M_PI * (diam) * (diam) / 4.0;
|
|
|
|
/* Compute volume of pipe. */
|
|
c[VOL] = c[AREA] * le;
|
|
|
|
/* Divide the restriction in 2 identical restrictions */
|
|
c[HALFLE] = 0.5 * le;
|
|
|
|
/* Compute exchange area of pipe. */
|
|
c[AREAEX] = M_PI * diam * le;
|
|
|
|
/* <<<<<<<<<<<<End of Initialization Executable Statements. */
|
|
}
|
|
|
|
/* There are 2 ports.
|
|
|
|
Port 1 has 4 variables:
|
|
|
|
1 dh1 enthalpy flow rate at port 1 [J/s -> W] basic variable output
|
|
2 dm1 mass flow rate at port 1 [g/s -> kg/s] basic variable output
|
|
3 t1 temperature at port 1 [K] basic variable input
|
|
4 p1 pressure at port 1 [Pa] basic variable input
|
|
|
|
Port 2 has 4 variables:
|
|
|
|
1 dh2 enthalpy flow rate at port 2 [J/s -> W] basic variable output
|
|
2 dm2 mass flow rate at port 2 [g/s -> kg/s] basic variable output
|
|
3 t2 temperature at port 2 [K] basic variable input
|
|
4 p2 pressure at port 2 [Pa] basic variable input
|
|
*/
|
|
|
|
/* There are 7 internal variables.
|
|
|
|
1 tctr temperature at center of pipe [K] explicit state (derivative `dtctr')
|
|
2 pctr pressure at center of pipe [Pa] explicit state (derivative `dpctr')
|
|
3 mgas mass of gas in pipe [g -> kg] basic variable
|
|
4 re mean Reynolds number [null] basic variable
|
|
5 cm mean mass flow parameter [(kg*K/J)**(1/2)] basic variable
|
|
6 v mean gas velocity [m/s] basic variable
|
|
7 ff mean friction factor [null] basic variable
|
|
*/
|
|
|
|
void pnl0002_(int *n, double *dh1, double *dm1, double *t1, double *p1
|
|
, double *dh2, double *dm2, double *t2, double *p2, double *tctr
|
|
, double *dtctr, double *pctr, double *dpctr, double *mgas
|
|
, double *re, double *cm, double *v, double *ff, double rp[6]
|
|
, int ip[2], double c[8], int ic[1])
|
|
|
|
{
|
|
int loop;
|
|
/* >>>>>>>>>>>>Extra Calculation Function Declarations Here. */
|
|
static double zero = 0.0;
|
|
double sdh;
|
|
double dh1i, dm1i;
|
|
double dh2i, dm2i;
|
|
double ff1, ff2, re1, re2, cm1, cm2;
|
|
double dq;
|
|
double pa1, pa2, pactr;
|
|
double v1, v2;
|
|
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;
|
|
|
|
/*
|
|
Set all submodel outputs below:
|
|
|
|
*dh1 = ??;
|
|
*dm1 = ??;
|
|
*dh2 = ??;
|
|
*dm2 = ??;
|
|
*dtctr = ??;
|
|
*dpctr = ??;
|
|
*mgas = ??;
|
|
*re = ??;
|
|
*cm = ??;
|
|
*v = ??;
|
|
*ff = ??;
|
|
*/
|
|
|
|
|
|
|
|
/* >>>>>>>>>>>>Calculation Function Executable Statements. */
|
|
|
|
/* set absolute pressure */
|
|
pa1 = *p1 + c[PATM];
|
|
pa2 = *p2 + c[PATM];
|
|
pactr = *pctr + c[PATM];
|
|
|
|
/* Compute flows through the pipe */
|
|
pn2pipefr_(&pa1, t1, &pactr, tctr, &diam, &rr, &c[HALFLE], &c[AREA], &re1, &v1, &ff1,
|
|
dh1, dm1, &dh1i, &dm1i, &cm1, &c[TABFR], &gi, &ic[SPL_FR], &dummyreg);
|
|
|
|
pn2pipefr_(&pactr, tctr, &pa2, t2, &diam, &rr, &c[HALFLE], &c[AREA], &re2, &v2, &ff2,
|
|
&dh2i, &dm2i, dh2, dm2, &cm2, &c[TABFR], &gi, &ic[SPL_FR], &dummyreg);
|
|
|
|
/* Mean variables */
|
|
*ff = 0.5 * (ff1 + ff2);
|
|
*re = 0.5 * (re1 + re2);
|
|
*cm = 0.5 * (cm1 + cm2);
|
|
*v = 0.5 * (fabs(v1) + fabs(v2));
|
|
|
|
/* Compute mass variation */
|
|
dmgas = dm1i + dm2i;
|
|
|
|
/* sum of enthalpy flows */
|
|
sdh = dh1i + dh2i;
|
|
|
|
/*** temperature & pressure variation ***/
|
|
if (mode == 1) /* Polytropic model. */
|
|
{
|
|
r = pn2ri_(&gi);
|
|
*mgas = (pactr) * c[VOL] / ((*tctr) * r);
|
|
|
|
pn2vol1_(dtctr, dpctr, tctr, &pactr,
|
|
&dmgas, mgas, &zero, &c[VOL], &k, &gi);
|
|
}
|
|
else /* Heat exchange. */
|
|
{
|
|
dq = kth * c[AREAEX] * (extemp-*tctr);
|
|
|
|
pn2vol_(dtctr, dpctr, mgas, tctr, &pactr,
|
|
&dmgas, &sdh, &c[VOL], &zero, &dq, &gi);
|
|
}
|
|
|
|
/* <<<<<<<<<<<<End of Calculation Executable Statements. */
|
|
|
|
/* SI -> Common units conversions. */
|
|
|
|
*dm1 /= 1.00000000000000e-003;
|
|
*dm2 /= 1.00000000000000e-003;
|
|
*mgas /= 1.00000000000000e-003;
|
|
}
|
|
|