elbeem.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. /** \file
  2. * \ingroup elbeem
  3. */
  4. /******************************************************************************
  5. *
  6. * El'Beem - Free Surface Fluid Simulation with the Lattice Boltzmann Method
  7. * All code distributed as part of El'Beem is covered by the version 2 of the
  8. * GNU General Public License. See the file COPYING for details.
  9. * Copyright 2003-2006 Nils Thuerey
  10. *
  11. * API header
  12. */
  13. #ifndef ELBEEM_API_H
  14. #define ELBEEM_API_H
  15. // simulation run callback function type (elbeemSimulationSettings->runsimCallback)
  16. // best use with FLUIDSIM_CBxxx defines below.
  17. // >parameters
  18. // return values: 0=continue, 1=stop, 2=abort
  19. // data pointer: user data pointer from elbeemSimulationSettings->runsimUserData
  20. // status integer: 1=running simulation, 2=new frame saved
  21. // frame integer: if status is 1, contains current frame number
  22. typedef int (*elbeemRunSimulationCallback)(void *data, int status, int frame);
  23. #define FLUIDSIM_CBRET_CONTINUE 0
  24. #define FLUIDSIM_CBRET_STOP 1
  25. #define FLUIDSIM_CBRET_ABORT 2
  26. #define FLUIDSIM_CBSTATUS_STEP 1
  27. #define FLUIDSIM_CBSTATUS_NEWFRAME 2
  28. // global settings for the simulation
  29. typedef struct elbeemSimulationSettings {
  30. /* version number */
  31. short version;
  32. /* id number of simulation domain, needed if more than a
  33. * single domain should be simulated */
  34. short domainId; // unused within blender
  35. /* geometrical extent */
  36. float geoStart[3], geoSize[3];
  37. /* resolutions */
  38. short resolutionxyz;
  39. short previewresxyz;
  40. /* size of the domain in real units (meters along largest resolution x,y,z extent) */
  41. float realsize;
  42. /* fluid properties */
  43. double viscosity;
  44. /* gravity strength */
  45. float gravity[3];
  46. /* anim start end time */
  47. float animStart, aniFrameTime;
  48. /* no. of frames to simulate & output */
  49. short noOfFrames;
  50. /* g star param (LBM compressibility) */
  51. float gstar;
  52. /* activate refinement? */
  53. short maxRefine;
  54. /* probability for surface particle generation (0.0=off) */
  55. float generateParticles;
  56. /* amount of tracer particles to generate (0=off) */
  57. int numTracerParticles;
  58. /* store output path, and file prefix for baked fluid surface */
  59. char outputPath[160+80];
  60. /* channel for frame time, visc & gravity animations */
  61. int channelSizeFrameTime;
  62. float *channelFrameTime;
  63. int channelSizeViscosity;
  64. float *channelViscosity;
  65. int channelSizeGravity;
  66. float *channelGravity; // vector
  67. /* boundary types and settings for domain walls */
  68. short domainobsType;
  69. float domainobsPartslip;
  70. /* what surfaces to generate */
  71. int mFsSurfGenSetting;
  72. /* generate speed vectors for vertices (e.g. for image based motion blur)*/
  73. short generateVertexVectors;
  74. /* strength of surface smoothing */
  75. float surfaceSmoothing;
  76. /* no. of surface subdivisions */
  77. int surfaceSubdivs;
  78. /* global transformation to apply to fluidsim mesh */
  79. float surfaceTrafo[4*4];
  80. /* development variables, testing for upcoming releases...*/
  81. float farFieldSize;
  82. /* callback function to notify calling program of performed simulation steps
  83. * or newly available frame data, if NULL it is ignored */
  84. elbeemRunSimulationCallback runsimCallback;
  85. /* pointer passed to runsimCallback for user data storage */
  86. void* runsimUserData;
  87. /* simulation threads used by omp */
  88. int threads;
  89. } elbeemSimulationSettings;
  90. // defines for elbeemMesh->type below
  91. /* please keep in sync with DNA_object_fluidsim_types.h */
  92. #define OB_FLUIDSIM_FLUID 4
  93. #define OB_FLUIDSIM_OBSTACLE 8
  94. #define OB_FLUIDSIM_INFLOW 16
  95. #define OB_FLUIDSIM_OUTFLOW 32
  96. #define OB_FLUIDSIM_PARTICLE 64
  97. #define OB_FLUIDSIM_CONTROL 128
  98. // defines for elbeemMesh->obstacleType below (low bits) high bits (>=64) are reserved for mFsSurfGenSetting flags which are defined in solver_class.h
  99. #define FLUIDSIM_OBSTACLE_NOSLIP 1
  100. #define FLUIDSIM_OBSTACLE_PARTSLIP 2
  101. #define FLUIDSIM_OBSTACLE_FREESLIP 3
  102. #define FLUIDSIM_FSSG_NOOBS 64
  103. #define OB_VOLUMEINIT_VOLUME 1
  104. #define OB_VOLUMEINIT_SHELL 2
  105. #define OB_VOLUMEINIT_BOTH (OB_VOLUMEINIT_SHELL|OB_VOLUMEINIT_VOLUME)
  106. // a single mesh object
  107. typedef struct elbeemMesh {
  108. /* obstacle,fluid or inflow or control ... */
  109. short type;
  110. /* id of simulation domain it belongs to */
  111. short parentDomainId;
  112. /* vertices */
  113. int numVertices;
  114. float *vertices; // = float[n][3];
  115. /* animated vertices */
  116. int channelSizeVertices;
  117. float *channelVertices; // = float[channelSizeVertices* (n*3+1) ];
  118. /* triangles */
  119. int numTriangles;
  120. int *triangles; // = int[][3];
  121. /* animation channels */
  122. int channelSizeTranslation;
  123. float *channelTranslation;
  124. int channelSizeRotation;
  125. float *channelRotation;
  126. int channelSizeScale;
  127. float *channelScale;
  128. /* active channel */
  129. int channelSizeActive;
  130. float *channelActive;
  131. /* initial velocity channel (e.g. for inflow) */
  132. int channelSizeInitialVel;
  133. float *channelInitialVel; // vector
  134. /* use initial velocity in object coordinates? (e.g. for rotation) */
  135. short localInivelCoords;
  136. /* boundary types and settings */
  137. short obstacleType;
  138. float obstaclePartslip;
  139. /* amount of force transfer from fluid to obj, 0=off, 1=normal */
  140. float obstacleImpactFactor;
  141. /* init volume, shell or both? use OB_VOLUMEINIT_xxx defines above */
  142. short volumeInitType;
  143. /* name of the mesh, mostly for debugging */
  144. const char *name;
  145. /* fluid control settings */
  146. float cpsTimeStart;
  147. float cpsTimeEnd;
  148. float cpsQuality;
  149. int channelSizeAttractforceStrength;
  150. float *channelAttractforceStrength;
  151. int channelSizeAttractforceRadius;
  152. float *channelAttractforceRadius;
  153. int channelSizeVelocityforceStrength;
  154. float *channelVelocityforceStrength;
  155. int channelSizeVelocityforceRadius;
  156. float *channelVelocityforceRadius;
  157. } elbeemMesh;
  158. // API functions
  159. #ifdef __cplusplus
  160. extern "C" {
  161. #endif // __cplusplus
  162. // reset elbeemSimulationSettings struct with defaults
  163. void elbeemResetSettings(struct elbeemSimulationSettings*);
  164. // start fluidsim init (returns !=0 upon failure)
  165. int elbeemInit(void);
  166. // frees fluidsim
  167. int elbeemFree(void);
  168. // start fluidsim init (returns !=0 upon failure)
  169. int elbeemAddDomain(struct elbeemSimulationSettings*);
  170. // get failure message during simulation or init
  171. // if an error occured (the string is copied into buffer,
  172. // max. length = 256 chars )
  173. void elbeemGetErrorString(char *buffer);
  174. // reset elbeemMesh struct with zeroes
  175. void elbeemResetMesh(struct elbeemMesh*);
  176. // add mesh as fluidsim object
  177. int elbeemAddMesh(struct elbeemMesh*);
  178. // do the actual simulation
  179. int elbeemSimulate(void);
  180. // continue a previously stopped simulation
  181. int elbeemContinueSimulation(void);
  182. // helper functions
  183. // simplify animation channels
  184. // returns if the channel and its size changed
  185. int elbeemSimplifyChannelFloat(float *channel, int *size);
  186. int elbeemSimplifyChannelVec3(float *channel, int *size);
  187. // helper functions implemented in utilities.cpp
  188. /* set elbeem debug output level (0=off to 10=full on) */
  189. void elbeemSetDebugLevel(int level);
  190. /* elbeem debug output function, prints if debug level >0 */
  191. void elbeemDebugOut(char *msg);
  192. /* estimate how much memory a given setup will require */
  193. double elbeemEstimateMemreq(int res,
  194. float sx, float sy, float sz,
  195. int refine, char *retstr);
  196. #ifdef __cplusplus
  197. }
  198. #endif // __cplusplus
  199. /******************************************************************************/
  200. // internal defines, do not use for initializing elbeemMesh
  201. // structs, for these use OB_xxx defines above
  202. /*! fluid geometry init types */
  203. // type "int" used, so max is 8
  204. #define FGI_FLAGSTART 16
  205. #define FGI_FLUID (1<<(FGI_FLAGSTART+ 0))
  206. #define FGI_NO_FLUID (1<<(FGI_FLAGSTART+ 1))
  207. #define FGI_BNDNO (1<<(FGI_FLAGSTART+ 2))
  208. #define FGI_BNDFREE (1<<(FGI_FLAGSTART+ 3))
  209. #define FGI_BNDPART (1<<(FGI_FLAGSTART+ 4))
  210. #define FGI_NO_BND (1<<(FGI_FLAGSTART+ 5))
  211. #define FGI_MBNDINFLOW (1<<(FGI_FLAGSTART+ 6))
  212. #define FGI_MBNDOUTFLOW (1<<(FGI_FLAGSTART+ 7))
  213. #define FGI_CONTROL (1<<(FGI_FLAGSTART+ 8))
  214. // all boundary types at once
  215. #define FGI_ALLBOUNDS ( FGI_BNDNO | FGI_BNDFREE | FGI_BNDPART | FGI_MBNDINFLOW | FGI_MBNDOUTFLOW )
  216. #endif // ELBEEM_API_H