📄 backvalve_.c
字号:
}
fclose(fp);
}
#endif
else
{
/* By defaults, the values of all variables are to be *
* written to the results file. */
for(i = 0; i < NUMVARS; i++)
{
SaveFlags[i] = 1;
}
n = NUMVARS;
}
if(n < NUMVARS)
{
HeaderSize = (2 + n) * sizeof(int);
}
else
{
HeaderSize = 2 * sizeof(int);
}
NumToSave = n;
return n;
#else
return NUMVARS;
#endif
}
/*****************************************************************
* *
* AmeReadFile opens the binary results file *
backvalve_.results
* If runtype&1=0, it is a new run and the first records are *
* written to indicate the number of variables and that there *
* are zero points produced so far. *
* *
* If runtype&1=1, a request has been made for a continuation run*
* An attempt is made to read the old file the state variables, *
* points and position. *
* *
* If runtype&2=2,a request has been made to use the final values*
* of an old simulation as the starting values for a new. An *
* attempt is made to read the old file *
backvalve_.results
* and reset the state variables. *
* *
* If runtype&4, it is some sort of stabilizing run and the file *
* is initialized as with runtype=0. *
* *
*****************************************************************/
static void AmeReadFile
#ifdef _NO_PROTO
(t, y)
double *t, *y;
#else
(double *t, double *y)
#endif
{
#ifndef NORESULTFILE
/* Local variables */
int successful;
int isize = sizeof(int);
int i1, i2, i, nv;
char line[PATH_MAX+128];
char *resultsname;
resultsname = GetResultsFileName();
/* Initialise the output value flags */
nv = InitSaveFlags();
if(isconrun_())
{
/* Its a continuation run */
GetOldValues(t, y, &successful);
if(!successful)
{
/* Cannot do a continuation run. */
ClearConRun();
}
else
{
return;
}
}
else if (isusefinval_())
{
/* New run with old final values as starting values */
GetOldValues(t, y, &successful);
if(!successful)
{
/* Cannot do run with old final values. */
ClearUseFinalVal();
}
}
if(ASOPT.outoff)
{
return;
}
remove(resultsname);
#ifdef WIN32
fd_results = open(resultsname , O_CREAT|O_RDWR|O_BINARY,S_IREAD|S_IWRITE);
#else
fd_results = creat(resultsname,0666);
#endif
if(fd_results == -1)
{
sprintf(line,"Cannot open results file `%s'",resultsname);
DisplayMessage(line);
}
i1 = 0;
if(write(fd_results, (char *)&i1, isize) != isize)
{
sprintf(line,"Cannot write to file `%s'",resultsname);
DisplayMessage(line);
}
/* The value of the no. of variables must be negative */
(nv < NUMVARS) ? (i2 = -nv) : (i2 = NUMVARS);
if(write(fd_results, (char *)&i2, isize) != isize)
{
sprintf(line,"Cannot write to file `%s'",resultsname);
DisplayMessage(line);
}
if(nv < NUMVARS)
{
for(i = 0; i < NUMVARS; i++)
{
if(SaveFlags[i])
{
if(write(fd_results, (char *)&i, isize) != isize)
{
sprintf(line,"Cannot write to file `%s'",resultsname);
DisplayMessage(line);
}
}
}
}
#else
fd_results=-1;
#endif
}
/**************************************************************
* *
* Function load_subdata_tables reads data for lookuptables *
* mostly/only used for realtime *
* *
**************************************************************/
#ifdef NOEXTERNALFILES
static void load_subdata_tables(void)
{
#include "backvalve_.subdata.h"
}
#endif
/*************************************************************
* *
* Function Input reads submodel and simulation data. *
* *
*************************************************************/
static void Input
#ifdef _NO_PROTO
(y)
double *y;
#else
(double *y)
#endif
{
/* Local variables */
int idummy[9];
double rdummy[8];
FILE *fptr;
char text1[PATH_MAX+128], text2[PATH_MAX+128];
#ifdef NOEXTERNALFILES
/* Include a formatted version of backvalve_.data to pick up submodel parameters */
#include "backvalve_.data.h"
#include "backvalve_.sim.h"
int lineptr=0;
/* Redefine the functions for accessing the parameters */
#define GetAndInterpretValues(a,b,c,d,e,f) ameGetAndInterpretValuesFromCharArray(allparams, &lineptr, b,c,d,e,f)
#define GetAndInterpretTextValues(a,b,c,d) ameGetAndInterpretTextValuesFromCharArray(allparams, &lineptr, b,c,d)
load_subdata_tables();
sprintf(text2, "Unable to load data from char array");
#else
/* Read backvalve_.data to pick up submodel parameters */
fptr = fopen(GetDataFileName(), "r");
if(fptr == NULL)
{
sprintf(text1, "Unable to open file %s\n", GetDataFileName());
DisplayMessage(text1);
}
sprintf(text2, "Unable to read file %s", GetDataFileName());
#endif
/* y is a double array holding state variables.
The following statement covers the case where there are
no state variables y. */
y[0] = 0.;
GetAndInterpretValues(fptr, r0, 3, I0, 2, text2);
GetAndInterpretValues(fptr, &y[0], 1, idummy, 0, text2);
GetAndInterpretValues(fptr, r1, 2, idummy, 0, text2);
GetAndInterpretValues(fptr, &v[13], 1, idummy, 0, text2);
GetAndInterpretValues(fptr, &v[6], 1, idummy, 0, text2);
GetAndInterpretValues(fptr, r4, 13, I4, 5, text2);
GetAndInterpretTextValues(fptr, t4, 2, text2);
GetAndInterpretValues(fptr, r6, 4, idummy, 0, text2);
GetAndInterpretTextValues(fptr, t6, 1, text2);
GetAndInterpretValues(fptr, &v[18], 1, idummy, 0, text2);
GetAndInterpretValues(fptr, r9, 2, I9, 1, text2);
GetAndInterpretValues(fptr, r10, 2, idummy, 0, text2);
GetAndInterpretValues(fptr, &v[27], 1, idummy, 0, text2);
GetAndInterpretValues(fptr, r13, 7, I13, 2, text2);
GetAndInterpretValues(fptr, &y[2], 1, idummy, 0, text2);
GetAndInterpretValues(fptr, &y[5], 1, idummy, 0, text2);
GetAndInterpretValues(fptr, r18, 7, I18, 2, text2);
GetAndInterpretValues(fptr, &y[1], 1, idummy, 0, text2);
GetAndInterpretValues(fptr, &y[3], 1, idummy, 0, text2);
GetAndInterpretValues(fptr, r19, 7, I19, 2, text2);
GetAndInterpretValues(fptr, &y[6], 1, idummy, 0, text2);
GetAndInterpretValues(fptr, &y[4], 1, idummy, 0, text2);
#ifdef NOEXTERNALFILES
#undef GetAndInterpretValues
#undef GetAndInterpretTextValues
#else
fclose(fptr);
#endif
ValidateRuntype(8); /* Dynamic run - no extra options */
}
/******************************************************
* *
* This function calls the submodel initialiation *
* functions/subroutines to check resp, iesp and *
* state variable values and set the the con and icon *
* arrays *
* *
******************************************************/
static void Initialize
#ifdef _NO_PROTO
(y)
double *y;
#else
(double *y)
#endif
{
int n;
n = 1;
fp04in_(&n, r4, I4, t4);
n = 1;
tk000in_(&n, &v[13]);
n = 2;
tk000in_(&n, &v[6]);
n = 1;
pmv00in_(&n);
n = 1;
vor01in_(&n, r6, t6, J6);
n = 3;
tk000in_(&n, &v[18]);
n = 1;
pu001in_(&n, r9, I9, c9);
n = 1;
h4node2in_(&n, &v[30], &v[33], &v[28]);
n = 1;
hl04in_(&n, r13, I13, c13, J13, &y[2], &y[5]);
n = 2;
hl04in_(&n, r18, I18, c18, J18, &y[1], &y[3]);
n = 1;
ha001in_(&n, r0, I0, c0, J0, &y[0]);
n = 1;
rv00in_(&n, r1, J1);
n = 1;
pt001in_(&n, r10, &v[27]);
n = 1;
h3node3in_(&n, &v[36], &v[10]);
n = 3;
hl04in_(&n, r19, I19, c19, J19, &y[6], &y[4]);
}
/***********************************************************************
* *
* funcval calls the submodels in an order that ensures that the *
* inputs of each are known when it is called. When submodels flag *
* discontinuities, conflicts are resolved. *
* *
***********************************************************************/
static void funcval(double *x, double *y, const double *input, double *dot,
double *output, int *flag)
{
int sflag, oflag, n, panic;
static double zero = 0.0e0;
static int *oldflag, *newflag;
double t;
#if defined (LABCAR) || defined (RTLAB)
int i;
for (i=0; i< NUMSTATES; i++)
{
if(fabs(y[i]) < 1.0e-200)
{
y[i] = 0.0;
}
}
#endif
t = *x;
/* Record old value of flag (oflag) and set
flag value for use in submodels (sflag). */
oflag = *flag;
sflag = *flag;
if(first_call)
{
GetFlagAddresses(&oldflag, &newflag);
}
/* Initialize everything ready for potential calls to stepdn
in submodels. */
panic = 0;
(void *)getredstep();
/* Assign the state variables y() calculated by the integrator
to the appropriate variables v(). */
v[2] = y[0];
v[24] = y[2];
v[35] = y[5];
v[20] = y[1];
v[29] = y[3];
v[38] = y[6];
v[32] = y[4];
/* Assign the interface input variables to the appropriate variable v(). */
v[16] = input[0];
v[17] = input[1];
/* Call submodel calculation subroutine in the order
that ensures the input requirements of each submodel
are satisfied. */
n = 1;
*oldflag = *newflag = sflag;
pmv00_(&n, &v[15], &v[16]);
if(sflag < 3)sflag = getnfg_();
resdis(flag, &sflag, &oflag, "PMV00", 1, &panic);
n = 1;
*oldflag = *newflag = sflag;
vor01_(&n, &v[17], &v[18], &v[21], &v[20], &v[22], r6, t6, J6
);
if(sflag < 3)sflag = getnfg_();
resdis(flag, &sflag, &oflag, "VOR01", 1, &panic);
v[19] = -v[21] /* Duplicate variable. */;
n = 1;
*oldflag = *newflag = sflag;
pu001_(&n, &v[13], &v[25], &v[24], &v[15], r9, I9, c9);
if(sflag < 3)sflag = getnfg_();
resdis(flag, &sflag, &oflag, "PU001", 1, &panic);
v[12] = -v[25] /* Duplicate variable. */;
v[14] = (v[24]-v[13])*c9[0];
v[31] = v[2] /* Duplicate variable. */;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -