/* Submodel PNL0001 skeleton created by AME Submodel editing utility mer. juin 20 14:20:39 2018 */ #include #include #include #include "ameutils.h" /* ******************************************************************************* TITLE : PNL0001 (C-R) ------------------------------------------------------------------------------ DESCRIPTION : PNL0001 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 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 . The submodels PNGD001 or PNGD002 should be included in your circuit to define the characteristics of the gas. ------------------------------------------------------------------------------ PARAMETER SETTINGS : ------------------------------------------------------------------------------ DATE OF CREATION / AUTHOR : 2002 FS from PNL01 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_ "PNL0001" /* >>>>>>>>>>>>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 AREAEX 6 #define SPL_FR 0 /* <<<<<<<<<<< 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 pnl0001in_(int *n, double rp[6], int ip[2], double c[7] , int ic[1], double *t2, double *p2) { int loop, error; /* >>>>>>>>>>>>Extra Initialization Function Declarations Here. */ /* <<<<<<<<<<<>>>>>>>>>>>Initialization Function Check Statements. */ pn2_valid_gas_(&gi, &error); 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"); } } /* <<<<<<<<<<< 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; /* Compute exchange area of pipe. */ c[AREAEX] = M_PI * diam * le; /* <<<<<<<<<<< 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 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 5 internal variables. 1 mgas mass of gas in pipe [g -> kg] basic variable 2 re Reynolds number [null] basic variable 3 cm mass flow parameter (cm) [(kg*K/J)**(1/2)] basic variable 4 v mean gas velocity [m/s] basic variable 5 ff friction factor [null] basic variable */ void pnl0001_(int *n, double *dh1, double *dm1, double *t1, double *p1 , double *t2, double *dt2, double *p2, double *dp2, double *dh2 , double *dm2, 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 sdh; double dh2i, dm2i; double dq; double pa1, pa2, dmgas; double r; int dummyreg; /* <<<<<<<<<<< SI units conversions. */ *dm2 *= 1.00000000000000e-003; /* Set all submodel outputs below: *dh1 = ??; *dm1 = ??; *dt2 = ??; *dp2 = ??; *mgas = ??; *re = ??; *cm = ??; *v = ??; *ff = ??; */ /* >>>>>>>>>>>>Calculation Function Executable Statements. */ /* set absolute pressures */ pa1 = *p1 + c[PATM]; pa2 = *p2 + c[PATM]; /* Compute flows through the pipe */ pn2pipefr_(&pa1, t1, &pa2, t2, &diam, &rr, &le, &c[AREA], re, v,ff, dh1, dm1, &dh2i, &dm2i, cm, &c[TABFR], &gi, &ic[SPL_FR], &dummyreg); /* Compute mass variation */ dmgas = (*dm2) + dm2i; /* sum of enthalpy flows */ sdh = (*dh2) + dh2i; /*** temperature & pressure variation ***/ if (mode == 1) /* Polytropic model. */ { r = pn2ri_(&gi); /* Compute initial mass of gas inside the pipe */ *mgas = (pa2) * c[VOL] / ((*t2) * r); pn2vol1_(dt2, dp2, t2, &pa2, &dmgas, mgas, &zero, &c[VOL], &k, &gi); } else /* Heat exchange. */ { dq = kth * c[AREAEX] * (extemp - *t2); pn2vol_(dt2, dp2, mgas, t2, &pa2, &dmgas, &sdh, &c[VOL], &zero, &dq, &gi); } /* <<<<<<<<<<< Common units conversions. */ *dm1 /= 1.00000000000000e-003; *dm2 /= 1.00000000000000e-003; *mgas /= 1.00000000000000e-003; }