ModelicaStandardTables.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. /* ModelicaStandardTables.h - External table functions header
  2. Copyright (C) 2013-2016, Modelica Association, DLR, and ITI GmbH
  3. Copyright (C) 2008-2013, Modelica Association and DLR
  4. All rights reserved.
  5. Redistribution and use in source and binary forms, with or without
  6. modification, are permitted provided that the following conditions are met:
  7. 1. Redistributions of source code must retain the above copyright notice,
  8. this list of conditions and the following disclaimer.
  9. 2. Redistributions in binary form must reproduce the above copyright
  10. notice, this list of conditions and the following disclaimer in the
  11. documentation and/or other materials provided with the distribution.
  12. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  13. ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  14. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  15. DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  16. FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  17. DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  18. SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  19. CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  20. OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  21. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  22. */
  23. /* Definition of interface to external functions for table computation
  24. in the Modelica Standard Library:
  25. Modelica.Blocks.Sources.CombiTimeTable
  26. Modelica.Blocks.Tables.CombiTable1D
  27. Modelica.Blocks.Tables.CombiTable1Ds
  28. Modelica.Blocks.Tables.CombiTable2D
  29. Release Notes:
  30. Oct. 27, 2015: by Thomas Beutlich, ITI GmbH
  31. Added nonnull attribute/annotations (ticket #1436)
  32. Apr. 09, 2013: by Thomas Beutlich, ITI GmbH
  33. Revised the first version
  34. Jan. 27, 2008: by Martin Otter, DLR
  35. Implemented a first version
  36. */
  37. /* A table can be defined in the following ways when initializing the table:
  38. (1) Explicitly supplied in the argument list
  39. (= table is "NoName" or has only blanks AND
  40. fileName is "NoName" or has only blanks).
  41. (2) Read from a file (tableName, fileName have to be supplied).
  42. Tables may be linearly interpolated or the first derivative
  43. may be continuous. In the latter case, cubic Hermite splines with Akima slope
  44. approximation, Fritsch-Butland slope approximation (univariate only) or Steffen
  45. slope approximation (univariate only) are used.
  46. */
  47. #ifndef _MODELICASTANDARDTABLES_H_
  48. #define _MODELICASTANDARDTABLES_H_
  49. #include <stdlib.h>
  50. #if defined(__cplusplus)
  51. extern "C" {
  52. #endif
  53. /*
  54. * Non-null pointers and esp. null-terminated strings need to be passed to
  55. * external functions.
  56. *
  57. * The following macros handle nonnull attributes for GNU C and Microsoft SAL.
  58. */
  59. #if defined(__GNUC__)
  60. #define MODELICA_NONNULLATTR __attribute__((nonnull))
  61. #else
  62. #define MODELICA_NONNULLATTR
  63. #endif
  64. #if !defined(__ATTR_SAL)
  65. #define _In_
  66. #define _In_z_
  67. #define _Inout_
  68. #endif
  69. DYMOLA_STATIC void* ModelicaStandardTables_CombiTimeTable_init(_In_z_ const char* tableName,
  70. _In_z_ const char* fileName,
  71. _In_ const double* table, size_t nRow,
  72. size_t nColumn,
  73. double startTime,
  74. _In_ const int* columns,
  75. size_t nCols, int smoothness,
  76. int extrapolation) MODELICA_NONNULLATTR;
  77. /* Initialize 1-dim. table where first column is time
  78. -> tableName: Name of table
  79. -> fileName: Name of file
  80. -> table: If tableName="NoName" or has only blanks AND
  81. fileName ="NoName" or has only blanks, then
  82. this pointer points to a 2-dim. array (row-wise storage)
  83. in the Modelica environment that holds this matrix.
  84. -> nRow: Number of rows of table
  85. -> nColumn: Number of columns of table
  86. -> startTime: Output = offset for time < startTime
  87. -> columns: Columns of table to be interpolated
  88. -> nCols: Number of columns of table to be interpolated
  89. -> smoothness: Interpolation type
  90. = 1: constant
  91. = 2: linear
  92. = 3: continuous first derivative
  93. -> extrapolation: Extrapolation type
  94. = 1: no
  95. = 2: hold first/last value
  96. = 3: linear
  97. = 4: periodic
  98. <- RETURN: Pointer to internal memory of table structure
  99. */
  100. DYMOLA_STATIC void ModelicaStandardTables_CombiTimeTable_close(void* tableID);
  101. /* Close table and free allocated memory */
  102. DYMOLA_STATIC double ModelicaStandardTables_CombiTimeTable_read(void* tableID, int force,
  103. int verbose);
  104. /* Read table from file
  105. -> tableID: Pointer to table defined with ModelicaStandardTables_CombiTimeTable_init
  106. -> force: Read only if forced or not yet read
  107. -> verbose: Print message that file is loading
  108. <- RETURN: = 1, if table was successfully read from file
  109. */
  110. DYMOLA_STATIC double ModelicaStandardTables_CombiTimeTable_minimumTime(void* tableID);
  111. /* Return minimum time defined in table (= table[1,1]) */
  112. DYMOLA_STATIC double ModelicaStandardTables_CombiTimeTable_maximumTime(void* tableID);
  113. /* Return maximum time defined in table (= table[end,1]) */
  114. DYMOLA_STATIC double ModelicaStandardTables_CombiTimeTable_getValue(void* tableID,
  115. int icol, double t,
  116. double nextTimeEvent,
  117. double preNextTimeEvent);
  118. /* Interpolate in table
  119. -> tableID: Pointer to table defined with ModelicaStandardTables_CombiTimeTable_init
  120. -> icol: Index (1-based) of column to interpolate
  121. -> t: Abscissa value (time)
  122. -> nextTimeEvent: Next time event (found by ModelicaStandardTables_CombiTimeTable_nextTimeEvent)
  123. -> preNextTimeEvent: Pre value of next time event
  124. <- RETURN : Ordinate value
  125. */
  126. DYMOLA_STATIC double ModelicaStandardTables_CombiTimeTable_getDerValue(void* tableID,
  127. int icol,
  128. double t,
  129. double nextTimeEvent,
  130. double preNextTimeEvent,
  131. double der_t);
  132. /* Interpolated derivative in table
  133. -> tableID: Pointer to table defined with ModelicaStandardTables_CombiTimeTable_init
  134. -> icol: Index (1-based) of column to interpolate
  135. -> t: Abscissa value (time)
  136. -> nextTimeEvent: Next time event (found by ModelicaStandardTables_CombiTimeTable_nextTimeEvent)
  137. -> preNextTimeEvent: Pre value of next time event
  138. -> der_t: Derivative of abscissa value (time)
  139. <- RETURN: Derivative of ordinate value
  140. */
  141. DYMOLA_STATIC double ModelicaStandardTables_CombiTimeTable_nextTimeEvent(void* tableID, double t);
  142. /* Return next time event in table
  143. -> tableID: Pointer to table defined with ModelicaStandardTables_CombiTimeTable_init
  144. -> t: Abscissa value (time)
  145. <- RETURN: Next abscissa value > t that triggers a time event
  146. */
  147. DYMOLA_STATIC void* ModelicaStandardTables_CombiTable1D_init(_In_z_ const char* tableName,
  148. _In_z_ const char* fileName,
  149. _In_ const double* table, size_t nRow,
  150. size_t nColumn,
  151. _In_ const int* columns,
  152. size_t nCols, int smoothness) MODELICA_NONNULLATTR;
  153. /* Initialize 1-dim. table defined by matrix, where first column
  154. is x-axis and further columns of matrix are interpolated
  155. -> tableName: Name of table
  156. -> fileName: Name of file
  157. -> table: If tableName="NoName" or has only blanks AND
  158. fileName ="NoName" or has only blanks, then
  159. this pointer points to a 2-dim. array (row-wise storage)
  160. in the Modelica environment that holds this matrix.
  161. -> nRow: Number of rows of table
  162. -> nColumn: Number of columns of table
  163. -> startTime: Output = offset for time < startTime
  164. -> columns: Columns of table to be interpolated
  165. -> nCols: Number of columns of table to be interpolated
  166. -> smoothness: Interpolation type
  167. = 1: constant
  168. = 2: linear
  169. = 3: continuous first derivative
  170. <- RETURN: Pointer to internal memory of table structure
  171. */
  172. DYMOLA_STATIC void ModelicaStandardTables_CombiTable1D_close(void* tableID);
  173. /* Close table and free allocated memory */
  174. DYMOLA_STATIC double ModelicaStandardTables_CombiTable1D_read(void* tableID, int force,
  175. int verbose);
  176. /* Read table from file
  177. -> tableID: Pointer to table defined with ModelicaStandardTables_CombiTable1D_init
  178. -> force: Read only if forced or not yet read
  179. -> verbose: Print message that file is loading
  180. <- RETURN: = 1, if table was successfully read from file
  181. */
  182. DYMOLA_STATIC double ModelicaStandardTables_CombiTable1D_getValue(void* tableID, int icol,
  183. double u);
  184. /* Interpolate in table
  185. -> tableID: Pointer to table defined with ModelicaStandardTables_CombiTable1D_init
  186. -> icol: Index (1-based) of column to interpolate
  187. -> u: Abscissa value
  188. <- RETURN : Ordinate value
  189. */
  190. DYMOLA_STATIC double ModelicaStandardTables_CombiTable1D_getDerValue(void* tableID, int icol,
  191. double u, double der_u);
  192. /* Interpolated derivative in table
  193. -> tableID: Pointer to table defined with ModelicaStandardTables_CombiTable1D_init
  194. -> icol: Index (1-based) of column to interpolate
  195. -> u: Abscissa value
  196. -> der_u: Derivative of abscissa value
  197. <- RETURN: Derivative of ordinate value
  198. */
  199. DYMOLA_STATIC void* ModelicaStandardTables_CombiTable2D_init(_In_z_ const char* tableName,
  200. _In_z_ const char* fileName,
  201. _In_ const double* table, size_t nRow,
  202. size_t nColumn, int smoothness) MODELICA_NONNULLATTR;
  203. /* Initialize 2-dim. table defined by matrix, where first column
  204. is x-axis, first row is y-axis and the matrix elements are the
  205. z-values.
  206. table[2:end,1 ]: Values of x-axis
  207. [1 ,2:end]: Values of y-axis
  208. [2:end,2:end]: Values of z-axis
  209. -> tableName: Name of table
  210. -> fileName: Name of file
  211. -> table: If tableName="NoName" or has only blanks AND
  212. fileName ="NoName" or has only blanks, then
  213. this pointer points to a 2-dim. array (row-wise storage)
  214. in the Modelica environment that holds this matrix.
  215. -> nRow: Number of rows of table
  216. -> nColumn: Number of columns of table
  217. -> smoothness: Interpolation type
  218. = 1: constant
  219. = 2: linear
  220. = 3: continuous first derivative
  221. <- RETURN: Pointer to internal memory of table structure
  222. */
  223. DYMOLA_STATIC void ModelicaStandardTables_CombiTable2D_close(void* tableID);
  224. /* Close table and free allocated memory */
  225. DYMOLA_STATIC double ModelicaStandardTables_CombiTable2D_read(void* tableID, int force,
  226. int verbose);
  227. /* Read table from file
  228. -> tableID: Pointer to table defined with ModelicaStandardTables_CombiTable2D_init
  229. -> force: Read only if forced or not yet read
  230. -> verbose: Print message that file is loading
  231. <- RETURN: = 1, if table was successfully read from file
  232. */
  233. DYMOLA_STATIC double ModelicaStandardTables_CombiTable2D_getValue(void* tableID, double u1,
  234. double u2);
  235. /* Interpolate in table
  236. -> tableID: Pointer to table defined with ModelicaStandardTables_CombiTable2D_init
  237. -> u1: Value of first independent variable
  238. -> u2: Value of second independent variable
  239. <- RETURN : Interpolated value
  240. */
  241. DYMOLA_STATIC double ModelicaStandardTables_CombiTable2D_getDerValue(void* tableID, double u1,
  242. double u2, double der_u1,
  243. double der_u2);
  244. /* Interpolated derivative in table
  245. -> tableID: Pointer to table defined with ModelicaStandrdTables_CombiTable2D_init
  246. -> u1: Value of first independent variable
  247. -> u2: Value of second independent variable
  248. -> der_u1: Derivative value of first independent variable
  249. -> der_u2: Derivative value of second independent variable
  250. <- RETURN: Derivative of interpolated value
  251. */
  252. #if defined(__cplusplus)
  253. }
  254. #endif
  255. #endif /* _MODELICASTANDARDTABLES_H_ */