| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202 |
- #ifndef DYMTABLE_H
- #define DYMTABLE_H
- #include "dymutil.h"
- /*
- * Copyright (C) 1997-2001 DLR and Dynasim AB.
- * All rights reserved.
- *
- */
- /* Functions to define tables and interpolate in these tables.
- It is assumed that these functions are called from the
- model function generated by Dymola.
- dymTableClear: Clear the table datastructure.
- dymTableInit : Initialize a new one- or two-dimensional table.
- dymTableIpo1 : Interpolate in a 1D-table defined via "dymTableInit12".
- dymTableIpo2 : Interpolate in a 2D-table defined via "dymTableInit12".
- Within Dymola, class "CombiTableTime/CombiTable1/CombiTable2" is used to
- carry out the actual interpolation by calling the appropriate "dymTable"
- functions.
- A table can be defined in the following ways when initializing the table:
- (1) Explicitly supplied in the argument list
- (= table is "NoName" or has only blanks AND
- fileName is "NoName" or has only blanks).
- (2) Statically stored in function "usertab" in file "usertab.c"
- (tableName has to be supplied; fileName = "NoName"
- or has only blanks).
- (3) Read from a file (tableName, fileName have to be supplied).
- The grid values have to be strict monotonically increasing. Outside of the
- defined table interval, functions are EXTRAPOLATED by linear interpolation
- through the last two points. If only ONE table value is supplied, no
- interpolation takes place and always the same value ís returned.
- Table definition methods (1) and (2) do NOT allocate dynamic memory,
- and do not access files, whereas method (3) does. Therefore (1) and (2)
- are suited for hardware-in-the-loop simulation (e.g. with dSpace hardware).
- When the constant "NO_FILE" is defined, all parts of the
- source code of method (3) are removed by the C-preprocessor, such that
- no dynamic memory allocation and no access to files takes place.
- */
- #include "libdssetup.h"
- DYMOLA_STATIC LIBDS_API_AFTER int usertab(char *tableName, int nipo, int dim[], int *colWise,
- double **table);
- /* Define tables by statically storing them in function usertab.
- This function can be adapted by the user to his/her needs.
- -> tableName: Name of table.
- -> nipo : = 0: time-table required (time interpolation).
- = 1: 1D-table required.
- = 2: 2D-table required.
- <- dim : Actual values of dimensions.
- <- colWise : = 0: table stored row-wise (row_1, row_2, ..., row_n).
- : = 1: table stored column-wise (column_1, column_2, ...).
- <- table : Pointer to vector containing a matrix with dimensions "dim".
- <- RETURN : = 0: No error.
- = 1: An error occured. An error message is printed
- from "usertab" with function "DymosimMessage".
- */
- DYMOLA_STATIC LIBDS_API_AFTER void dymTableClear(void);
- /* Clear the complete table datastructure and remove all
- allocated memory
- */
- DYMOLA_STATIC LIBDS_API_AFTER double dymTableInit(double nipo, double ipoType, const char *tableName,
- const char *fileName, double const *table, long ntable1,
- long ntable2, double colWise);
- /* Initialize a new one- or two-dimensional table
- A 1D-table is defined as a matrix where
- - the first column is the abszissa data
- - the other columns are the ordinate data to
- be interpolated with respect to the first column.
- A 2D-table is defined as a matrix where
- - the first column (without first element), i.e., table(2:,1),
- is the first abscissa (u(1)),
- - the first row (without first element), i.e., table(1,2:),
- is the second abscissa (u(2)),
- - the other elements, i.e., table(i,j) with i>=2,j>=2,
- are the corresponding ordinate values.
- The table data is stored for fast access and it is checked whether
- the first column contains only strict monotonically increasing values.
- -> nipo : = 0: Time-table (= 1D-table where first column is time).
- = 1: 1D-table.
- = 2: 2D-table.
- -> ipoType : Presently dummy argument (type of interpolation).
- -> tableName: Name of table.
- If not provided, table "table" is used. If "tableName"
- is given and no "fileName", table is inquired from
- function "usertab".
- -> fileName : Name of file where table is stored.
- -> table : Values of table, if tableName="" or "NoName" and
- fileName="" or "NoName".
- -> ntable1 : Row dimension of table "table".
- -> ntable2 : Column dimension of table "table".
- -> colWise : = 0: "table" stored row-wise (row_1, row_2, ..., row_n).
- : = 1: "table" stored column-wise (column_1, column_2, ...).
- <- return : ID of table which is needed for interpolation.
- In case of error, ID < -1 is returned.
- */
- DYMOLA_STATIC LIBDS_API_AFTER double dymTableIpo1DerDer(double tableID, double icol, double u,double ud,double udd);
- DYMOLA_STATIC LIBDS_API_AFTER double dymTableIpo1Der(double tableID, double icol, double u,double ud);
- DYMOLA_STATIC LIBDS_API_AFTER double dymTableIpo1(double tableID, double icol, double u);
- /* Interpolation in table "tableID" defined via "dymTableInit12"
- -> tableID: ID of table provided by function dymTableInit12.
- -> icol : Column of table to be interpolated (icol > 1).
- -> u : Abscissa value of table.
- <- return : Interpolated value, y=f(u).
- */
- DYMOLA_STATIC LIBDS_API_AFTER double dymTableIpo2DerDer(double tableID, double u1, double u2,double ud1,double ud2,double udd1,double udd2);
- DYMOLA_STATIC LIBDS_API_AFTER double dymTableIpo2Der(double tableID, double u1, double u2, double ud1,double ud2);
- DYMOLA_STATIC LIBDS_API_AFTER double dymTableIpo2(double tableID, double u1, double u2);
- /* Interpolation in table "tableID" defined via "dymTableInit12"
- -> tableID: ID of table provided by function dymTableInit12.
- -> u1 : First abscissa value of table.
- -> u2 : Second abscissa value of table.
- <- return : Interpolated value, y=f(u1,u2).
- */
- DYMOLA_STATIC LIBDS_API_AFTER double dymTableTimeIni(double time, double ipoType,
- const char *tableName, const char *fileName,
- double const *tableIn, long nt1In, long nt2In,
- double colWiseIn);
- DYMOLA_STATIC LIBDS_API_AFTER int dymTableTimeIni2(double time, double startTime, int ipoType,
- int expoType, const char *tableName, const char *fileName,
- double const *table, int nt1, int nt2, int colWise);
- /* Initialize table for time interpolation
- -> time : initialization time instant
- -> startTime : output = 0 for time < startTime.
- (Table data is defined relatively to startTime).
- -> ipoType : Presently dummy argument (type of interpolation).
- -> expoTypeIn: Extrapolation outside of table
- = 0: hold last/first table point
- = 1: extrapolate through last/first two table points
- = 2: repeat table periodically.
- -> tableName : Name of table.
- If not provided, table "table" is used. If "tableName"
- is given and no "fileName", table is inquired from
- function "usertab".
- -> fileName : Name of file where table is stored.
- -> tableIn : Values of table, if tableName="" or "NoName" and
- fileName="" or "NoName".
- -> nt1In : Row dimension of table "table".
- -> nt2In : Column dimension of table "table".
- -> colWiseIn : = 0: "table" stored row-wise (row_1, row_2, ..., row_n).
- : = 1: "table" stored column-wise (column_1, column_2, ...).
- <- return : ID of table which is needed for interpolation.
- In case of error, ID < -1 is returned.
- */
- DYMOLA_STATIC LIBDS_API_AFTER double dymTableTimeTmin(int tableID);
- /* Return minimum time value in table */
- DYMOLA_STATIC LIBDS_API_AFTER double dymTableTimeTmax(int tableID);
- /* Return maximum time value in table */
- #define dymTableTimeIpo(tableID, icol, Time) \
- (dymTableTimeIpol(tableID, icol, Time, DYNEvent))
- DYMOLA_STATIC LIBDS_API_AFTER double dymTableTimeIpol(double tableID, double icol, double time, int event);
- DYMOLA_STATIC LIBDS_API_AFTER double dymTableTimeIpo2(int tableID, int icol, double time);
- /* Time interpolation in table "tableID" defined via "dymTableTimeIni"
- -> tableID: ID of table provided by function dymTableTimeIni.
- -> icol : Column of table to be interpolated (icol > 1).
- -> time : Abscissa value of table (= time).
- -> event : = 0: Called during continuous integration.
- = 1: Called at an event instant.
- <- return : Interpolated value, y=f(time).
- */
- DYMOLA_STATIC LIBDS_API_AFTER void dymTablePrint(void);
- /* Print actual definition of tables to log-file */
- #endif
|