dymtable.h 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. #ifndef DYMTABLE_H
  2. #define DYMTABLE_H
  3. #include "dymutil.h"
  4. /*
  5. * Copyright (C) 1997-2001 DLR and Dynasim AB.
  6. * All rights reserved.
  7. *
  8. */
  9. /* Functions to define tables and interpolate in these tables.
  10. It is assumed that these functions are called from the
  11. model function generated by Dymola.
  12. dymTableClear: Clear the table datastructure.
  13. dymTableInit : Initialize a new one- or two-dimensional table.
  14. dymTableIpo1 : Interpolate in a 1D-table defined via "dymTableInit12".
  15. dymTableIpo2 : Interpolate in a 2D-table defined via "dymTableInit12".
  16. Within Dymola, class "CombiTableTime/CombiTable1/CombiTable2" is used to
  17. carry out the actual interpolation by calling the appropriate "dymTable"
  18. functions.
  19. A table can be defined in the following ways when initializing the table:
  20. (1) Explicitly supplied in the argument list
  21. (= table is "NoName" or has only blanks AND
  22. fileName is "NoName" or has only blanks).
  23. (2) Statically stored in function "usertab" in file "usertab.c"
  24. (tableName has to be supplied; fileName = "NoName"
  25. or has only blanks).
  26. (3) Read from a file (tableName, fileName have to be supplied).
  27. The grid values have to be strict monotonically increasing. Outside of the
  28. defined table interval, functions are EXTRAPOLATED by linear interpolation
  29. through the last two points. If only ONE table value is supplied, no
  30. interpolation takes place and always the same value ís returned.
  31. Table definition methods (1) and (2) do NOT allocate dynamic memory,
  32. and do not access files, whereas method (3) does. Therefore (1) and (2)
  33. are suited for hardware-in-the-loop simulation (e.g. with dSpace hardware).
  34. When the constant "NO_FILE" is defined, all parts of the
  35. source code of method (3) are removed by the C-preprocessor, such that
  36. no dynamic memory allocation and no access to files takes place.
  37. */
  38. #include "libdssetup.h"
  39. DYMOLA_STATIC LIBDS_API_AFTER int usertab(char *tableName, int nipo, int dim[], int *colWise,
  40. double **table);
  41. /* Define tables by statically storing them in function usertab.
  42. This function can be adapted by the user to his/her needs.
  43. -> tableName: Name of table.
  44. -> nipo : = 0: time-table required (time interpolation).
  45. = 1: 1D-table required.
  46. = 2: 2D-table required.
  47. <- dim : Actual values of dimensions.
  48. <- colWise : = 0: table stored row-wise (row_1, row_2, ..., row_n).
  49. : = 1: table stored column-wise (column_1, column_2, ...).
  50. <- table : Pointer to vector containing a matrix with dimensions "dim".
  51. <- RETURN : = 0: No error.
  52. = 1: An error occured. An error message is printed
  53. from "usertab" with function "DymosimMessage".
  54. */
  55. DYMOLA_STATIC LIBDS_API_AFTER void dymTableClear(void);
  56. /* Clear the complete table datastructure and remove all
  57. allocated memory
  58. */
  59. DYMOLA_STATIC LIBDS_API_AFTER double dymTableInit(double nipo, double ipoType, const char *tableName,
  60. const char *fileName, double const *table, long ntable1,
  61. long ntable2, double colWise);
  62. /* Initialize a new one- or two-dimensional table
  63. A 1D-table is defined as a matrix where
  64. - the first column is the abszissa data
  65. - the other columns are the ordinate data to
  66. be interpolated with respect to the first column.
  67. A 2D-table is defined as a matrix where
  68. - the first column (without first element), i.e., table(2:,1),
  69. is the first abscissa (u(1)),
  70. - the first row (without first element), i.e., table(1,2:),
  71. is the second abscissa (u(2)),
  72. - the other elements, i.e., table(i,j) with i>=2,j>=2,
  73. are the corresponding ordinate values.
  74. The table data is stored for fast access and it is checked whether
  75. the first column contains only strict monotonically increasing values.
  76. -> nipo : = 0: Time-table (= 1D-table where first column is time).
  77. = 1: 1D-table.
  78. = 2: 2D-table.
  79. -> ipoType : Presently dummy argument (type of interpolation).
  80. -> tableName: Name of table.
  81. If not provided, table "table" is used. If "tableName"
  82. is given and no "fileName", table is inquired from
  83. function "usertab".
  84. -> fileName : Name of file where table is stored.
  85. -> table : Values of table, if tableName="" or "NoName" and
  86. fileName="" or "NoName".
  87. -> ntable1 : Row dimension of table "table".
  88. -> ntable2 : Column dimension of table "table".
  89. -> colWise : = 0: "table" stored row-wise (row_1, row_2, ..., row_n).
  90. : = 1: "table" stored column-wise (column_1, column_2, ...).
  91. <- return : ID of table which is needed for interpolation.
  92. In case of error, ID < -1 is returned.
  93. */
  94. DYMOLA_STATIC LIBDS_API_AFTER double dymTableIpo1DerDer(double tableID, double icol, double u,double ud,double udd);
  95. DYMOLA_STATIC LIBDS_API_AFTER double dymTableIpo1Der(double tableID, double icol, double u,double ud);
  96. DYMOLA_STATIC LIBDS_API_AFTER double dymTableIpo1(double tableID, double icol, double u);
  97. /* Interpolation in table "tableID" defined via "dymTableInit12"
  98. -> tableID: ID of table provided by function dymTableInit12.
  99. -> icol : Column of table to be interpolated (icol > 1).
  100. -> u : Abscissa value of table.
  101. <- return : Interpolated value, y=f(u).
  102. */
  103. DYMOLA_STATIC LIBDS_API_AFTER double dymTableIpo2DerDer(double tableID, double u1, double u2,double ud1,double ud2,double udd1,double udd2);
  104. DYMOLA_STATIC LIBDS_API_AFTER double dymTableIpo2Der(double tableID, double u1, double u2, double ud1,double ud2);
  105. DYMOLA_STATIC LIBDS_API_AFTER double dymTableIpo2(double tableID, double u1, double u2);
  106. /* Interpolation in table "tableID" defined via "dymTableInit12"
  107. -> tableID: ID of table provided by function dymTableInit12.
  108. -> u1 : First abscissa value of table.
  109. -> u2 : Second abscissa value of table.
  110. <- return : Interpolated value, y=f(u1,u2).
  111. */
  112. DYMOLA_STATIC LIBDS_API_AFTER double dymTableTimeIni(double time, double ipoType,
  113. const char *tableName, const char *fileName,
  114. double const *tableIn, long nt1In, long nt2In,
  115. double colWiseIn);
  116. DYMOLA_STATIC LIBDS_API_AFTER int dymTableTimeIni2(double time, double startTime, int ipoType,
  117. int expoType, const char *tableName, const char *fileName,
  118. double const *table, int nt1, int nt2, int colWise);
  119. /* Initialize table for time interpolation
  120. -> time : initialization time instant
  121. -> startTime : output = 0 for time < startTime.
  122. (Table data is defined relatively to startTime).
  123. -> ipoType : Presently dummy argument (type of interpolation).
  124. -> expoTypeIn: Extrapolation outside of table
  125. = 0: hold last/first table point
  126. = 1: extrapolate through last/first two table points
  127. = 2: repeat table periodically.
  128. -> tableName : Name of table.
  129. If not provided, table "table" is used. If "tableName"
  130. is given and no "fileName", table is inquired from
  131. function "usertab".
  132. -> fileName : Name of file where table is stored.
  133. -> tableIn : Values of table, if tableName="" or "NoName" and
  134. fileName="" or "NoName".
  135. -> nt1In : Row dimension of table "table".
  136. -> nt2In : Column dimension of table "table".
  137. -> colWiseIn : = 0: "table" stored row-wise (row_1, row_2, ..., row_n).
  138. : = 1: "table" stored column-wise (column_1, column_2, ...).
  139. <- return : ID of table which is needed for interpolation.
  140. In case of error, ID < -1 is returned.
  141. */
  142. DYMOLA_STATIC LIBDS_API_AFTER double dymTableTimeTmin(int tableID);
  143. /* Return minimum time value in table */
  144. DYMOLA_STATIC LIBDS_API_AFTER double dymTableTimeTmax(int tableID);
  145. /* Return maximum time value in table */
  146. #define dymTableTimeIpo(tableID, icol, Time) \
  147. (dymTableTimeIpol(tableID, icol, Time, DYNEvent))
  148. DYMOLA_STATIC LIBDS_API_AFTER double dymTableTimeIpol(double tableID, double icol, double time, int event);
  149. DYMOLA_STATIC LIBDS_API_AFTER double dymTableTimeIpo2(int tableID, int icol, double time);
  150. /* Time interpolation in table "tableID" defined via "dymTableTimeIni"
  151. -> tableID: ID of table provided by function dymTableTimeIni.
  152. -> icol : Column of table to be interpolated (icol > 1).
  153. -> time : Abscissa value of table (= time).
  154. -> event : = 0: Called during continuous integration.
  155. = 1: Called at an event instant.
  156. <- return : Interpolated value, y=f(time).
  157. */
  158. DYMOLA_STATIC LIBDS_API_AFTER void dymTablePrint(void);
  159. /* Print actual definition of tables to log-file */
  160. #endif