Blender V2.61 - r43446

elbeem.h

Go to the documentation of this file.
00001 
00004 /******************************************************************************
00005  *
00006  * El'Beem - Free Surface Fluid Simulation with the Lattice Boltzmann Method
00007  * All code distributed as part of El'Beem is covered by the version 2 of the 
00008  * GNU General Public License. See the file COPYING for details.
00009  * Copyright 2003-2006 Nils Thuerey
00010  *
00011  * API header
00012  */
00013 #ifndef ELBEEM_API_H
00014 #define ELBEEM_API_H
00015 
00016 
00017 // simulation run callback function type (elbeemSimulationSettings->runsimCallback)
00018 // best use with FLUIDSIM_CBxxx defines below.
00019 // >parameters
00020 // return values: 0=continue, 1=stop, 2=abort
00021 // data pointer: user data pointer from elbeemSimulationSettings->runsimUserData
00022 // status integer: 1=running simulation, 2=new frame saved
00023 // frame integer: if status is 1, contains current frame number
00024 typedef int (*elbeemRunSimulationCallback)(void *data, int status, int frame);
00025 #define FLUIDSIM_CBRET_CONTINUE    0
00026 #define FLUIDSIM_CBRET_STOP        1
00027 #define FLUIDSIM_CBRET_ABORT       2 
00028 #define FLUIDSIM_CBSTATUS_STEP     1 
00029 #define FLUIDSIM_CBSTATUS_NEWFRAME 2 
00030 
00031 
00032 // global settings for the simulation
00033 typedef struct elbeemSimulationSettings {
00034   /* version number */
00035   short version;
00036     /* id number of simulation domain, needed if more than a
00037      * single domain should be simulated */
00038     short domainId; // unused within blender
00039 
00040     /* geometrical extent */
00041     float geoStart[3], geoSize[3];
00042 
00043   /* resolutions */
00044   short resolutionxyz;
00045   short previewresxyz;
00046   /* size of the domain in real units (meters along largest resolution x,y,z extent) */
00047   float realsize;
00048 
00049   /* fluid properties */
00050   double viscosity;
00051   /* gravity strength */
00052   float gravity[3];
00053   /* anim start end time */
00054   float animStart, aniFrameTime;
00055     /* no. of frames to simulate & output */
00056     short noOfFrames;
00057   /* g star param (LBM compressibility) */
00058   float gstar;
00059   /* activate refinement? */
00060   short maxRefine;
00061   /* probability for surface particle generation (0.0=off) */
00062   float generateParticles;
00063   /* amount of tracer particles to generate (0=off) */
00064   int numTracerParticles;
00065 
00066   /* store output path, and file prefix for baked fluid surface */
00067   char outputPath[160+80];
00068 
00069     /* channel for frame time, visc & gravity animations */
00070     int channelSizeFrameTime;
00071     float *channelFrameTime;
00072     int channelSizeViscosity;
00073     float *channelViscosity;
00074     int channelSizeGravity;
00075     float *channelGravity;  // vector
00076 
00077     /* boundary types and settings for domain walls */
00078     short domainobsType;
00079     float domainobsPartslip;
00080 
00081     /* what surfaces to generate */
00082     int mFsSurfGenSetting;
00083 
00084     /* generate speed vectors for vertices (e.g. for image based motion blur)*/
00085     short generateVertexVectors;
00086     /* strength of surface smoothing */
00087     float surfaceSmoothing;
00088     /* no. of surface subdivisions */
00089     int   surfaceSubdivs;
00090 
00091     /* global transformation to apply to fluidsim mesh */
00092     float surfaceTrafo[4*4];
00093 
00094     /* development variables, testing for upcoming releases...*/
00095     float farFieldSize;
00096 
00097     /* callback function to notify calling program of performed simulation steps
00098      * or newly available frame data, if NULL it is ignored */
00099     elbeemRunSimulationCallback runsimCallback;
00100     /* pointer passed to runsimCallback for user data storage */
00101     void* runsimUserData;
00102 
00103 } elbeemSimulationSettings;
00104 
00105 
00106 // defines for elbeemMesh->type below
00107 /* please keep in sync with DNA_object_fluidsim.h */
00108 #define OB_FLUIDSIM_FLUID       4
00109 #define OB_FLUIDSIM_OBSTACLE    8
00110 #define OB_FLUIDSIM_INFLOW      16
00111 #define OB_FLUIDSIM_OUTFLOW     32
00112 #define OB_FLUIDSIM_PARTICLE    64
00113 #define OB_FLUIDSIM_CONTROL     128
00114 
00115 // defines for elbeemMesh->obstacleType below (low bits) high bits (>=64) are reserved for mFsSurfGenSetting flags which are defined in solver_class.h
00116 #define FLUIDSIM_OBSTACLE_NOSLIP     1
00117 #define FLUIDSIM_OBSTACLE_PARTSLIP   2
00118 #define FLUIDSIM_OBSTACLE_FREESLIP   3
00119 #define FLUIDSIM_FSSG_NOOBS          64
00120 
00121 
00122 #define OB_VOLUMEINIT_VOLUME 1
00123 #define OB_VOLUMEINIT_SHELL  2
00124 #define OB_VOLUMEINIT_BOTH   (OB_VOLUMEINIT_SHELL|OB_VOLUMEINIT_VOLUME)
00125 
00126 // a single mesh object
00127 typedef struct elbeemMesh {
00128   /* obstacle,fluid or inflow or control ... */
00129   short type;
00130     /* id of simulation domain it belongs to */
00131     short parentDomainId;
00132 
00133     /* vertices */
00134   int numVertices;
00135     float *vertices; // = float[n][3];
00136     /* animated vertices */
00137   int channelSizeVertices;
00138     float *channelVertices; // = float[channelSizeVertices* (n*3+1) ];
00139 
00140     /* triangles */
00141     int   numTriangles;
00142   int   *triangles; // = int[][3];
00143 
00144     /* animation channels */
00145     int channelSizeTranslation;
00146     float *channelTranslation;
00147     int channelSizeRotation;
00148     float *channelRotation;
00149     int channelSizeScale;
00150     float *channelScale;
00151     
00152     /* active channel */
00153     int channelSizeActive;
00154     float *channelActive;
00155     /* initial velocity channel (e.g. for inflow) */
00156     int channelSizeInitialVel;
00157     float *channelInitialVel; // vector
00158     /* use initial velocity in object coordinates? (e.g. for rotation) */
00159     short localInivelCoords;
00160     /* boundary types and settings */
00161     short obstacleType;
00162     float obstaclePartslip;
00163     /* amount of force transfer from fluid to obj, 0=off, 1=normal */
00164     float obstacleImpactFactor;
00165     /* init volume, shell or both? use OB_VOLUMEINIT_xxx defines above */
00166     short volumeInitType;
00167 
00168     /* name of the mesh, mostly for debugging */
00169     const char *name;
00170     
00171     /* fluid control settings */
00172     float cpsTimeStart;
00173     float cpsTimeEnd;
00174     float cpsQuality;
00175     
00176     int channelSizeAttractforceStrength;
00177     float *channelAttractforceStrength;
00178     int channelSizeAttractforceRadius;
00179     float *channelAttractforceRadius;
00180     int channelSizeVelocityforceStrength;
00181     float *channelVelocityforceStrength;
00182     int channelSizeVelocityforceRadius;
00183     float *channelVelocityforceRadius;
00184 } elbeemMesh;
00185 
00186 // API functions
00187 
00188 #ifdef __cplusplus
00189 extern "C"  {
00190 #endif // __cplusplus
00191  
00192 
00193 // reset elbeemSimulationSettings struct with defaults
00194 void elbeemResetSettings(struct elbeemSimulationSettings*);
00195  
00196 // start fluidsim init (returns !=0 upon failure)
00197 int elbeemInit(void);
00198 
00199 // frees fluidsim
00200 int elbeemFree(void);
00201 
00202 // start fluidsim init (returns !=0 upon failure)
00203 int elbeemAddDomain(struct elbeemSimulationSettings*);
00204 
00205 // get failure message during simulation or init
00206 // if an error occured (the string is copied into buffer,
00207 // max. length = 256 chars )
00208 void elbeemGetErrorString(char *buffer);
00209 
00210 // reset elbeemMesh struct with zeroes
00211 void elbeemResetMesh(struct elbeemMesh*);
00212 
00213 // add mesh as fluidsim object
00214 int elbeemAddMesh(struct elbeemMesh*);
00215 
00216 // do the actual simulation
00217 int elbeemSimulate(void);
00218 
00219 // continue a previously stopped simulation
00220 int elbeemContinueSimulation(void);
00221 
00222 
00223 // helper functions 
00224 
00225 // simplify animation channels
00226 // returns if the channel and its size changed
00227 int elbeemSimplifyChannelFloat(float *channel, int *size);
00228 int elbeemSimplifyChannelVec3(float *channel, int *size);
00229 
00230 // helper functions implemented in utilities.cpp
00231 
00232 /* set elbeem debug output level (0=off to 10=full on) */
00233 void elbeemSetDebugLevel(int level);
00234 /* elbeem debug output function, prints if debug level >0 */
00235 void elbeemDebugOut(char *msg);
00236 
00237 /* estimate how much memory a given setup will require */
00238 double elbeemEstimateMemreq(int res,
00239     float sx, float sy, float sz,
00240     int refine, char *retstr);
00241 
00242 
00243 
00244 #ifdef __cplusplus
00245 }
00246 #endif // __cplusplus
00247 
00248 
00249 
00250 /******************************************************************************/
00251 // internal defines, do not use for initializing elbeemMesh
00252 // structs, for these use OB_xxx defines above
00253 
00255 // type "int" used, so max is 8
00256 #define FGI_FLAGSTART   16
00257 #define FGI_FLUID             (1<<(FGI_FLAGSTART+ 0))
00258 #define FGI_NO_FLUID      (1<<(FGI_FLAGSTART+ 1))
00259 #define FGI_BNDNO             (1<<(FGI_FLAGSTART+ 2))
00260 #define FGI_BNDFREE       (1<<(FGI_FLAGSTART+ 3))
00261 #define FGI_BNDPART       (1<<(FGI_FLAGSTART+ 4))
00262 #define FGI_NO_BND        (1<<(FGI_FLAGSTART+ 5))
00263 #define FGI_MBNDINFLOW  (1<<(FGI_FLAGSTART+ 6))
00264 #define FGI_MBNDOUTFLOW (1<<(FGI_FLAGSTART+ 7))
00265 #define FGI_CONTROL (1<<(FGI_FLAGSTART+ 8))
00266 
00267 // all boundary types at once
00268 #define FGI_ALLBOUNDS ( FGI_BNDNO | FGI_BNDFREE | FGI_BNDPART | FGI_MBNDINFLOW | FGI_MBNDOUTFLOW )
00269 
00270 
00271 #endif // ELBEEM_API_H