Blender V2.61 - r43446
|
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 * Header for Combined 2D/3D Lattice Boltzmann Interface Class 00012 * 00013 *****************************************************************************/ 00014 #ifndef LBMINTERFACE_H 00015 #define LBMINTERFACE_H 00016 00018 #ifndef NOGUI 00019 #define LBM_USE_GUI 1 00020 #else 00021 #define LBM_USE_GUI 0 00022 #endif 00023 00024 #if LBM_USE_GUI==1 00025 #define USE_GLUTILITIES 00026 // for debug display 00027 //#include <GL/gl.h> 00028 #include "../gui/guifuncs.h" 00029 #endif 00030 00031 #include <sstream> 00032 #include "utilities.h" 00033 #include "ntl_bsptree.h" 00034 #include "ntl_geometryobject.h" 00035 #include "parametrizer.h" 00036 #include "attributes.h" 00037 #include "isosurface.h" 00038 class ParticleTracer; 00039 class ParticleObject; 00040 00041 // use which fp-precision for LBM? 1=float, 2=double 00042 #ifdef PRECISION_LBM_SINGLE 00043 #define LBM_PRECISION 1 00044 #else 00045 #ifdef PRECISION_LBM_DOUBLE 00046 #define LBM_PRECISION 2 00047 #else 00048 // default to floats 00049 #define LBM_PRECISION 1 00050 #endif 00051 #endif 00052 00053 #if LBM_PRECISION==1 00054 /* low precision for LBM solver */ 00055 typedef float LbmFloat; 00056 typedef ntlVec3f LbmVec; 00057 #define LBM_EPSILON (1e-5) 00058 #else 00059 /* standard precision for LBM solver */ 00060 typedef double LbmFloat; 00061 typedef ntlVec3d LbmVec; 00062 #define LBM_EPSILON (1e-10) 00063 #endif 00064 00065 // long integer, needed e.g. for memory calculations 00066 #ifndef USE_MSVC6FIXES 00067 #define LONGINT long long int 00068 #else 00069 #define LONGINT _int64 00070 #endif 00071 00072 00073 // default to 3dim 00074 #ifndef LBMDIM 00075 #define LBMDIM 3 00076 #endif // LBMDIM 00077 00078 #if LBMDIM==2 00079 #define LBM_DFNUM 9 00080 #else 00081 #define LBM_DFNUM 19 00082 #endif 00083 00084 // conversions (lbm and parametrizer) 00085 template<class T> inline LbmVec vec2L(T v) { return LbmVec(v[0],v[1],v[2]); } 00086 template<class T> inline ParamVec vec2P(T v) { return ParamVec(v[0],v[1],v[2]); } 00087 00088 template<class Scalar> class ntlMatrix4x4; 00089 00090 00091 // bubble id type 00092 typedef int BubbleId; 00093 00094 // basic cell type distinctions 00095 #define CFUnused (1<< 0) 00096 #define CFEmpty (1<< 1) 00097 #define CFBnd (1<< 2) 00098 #define CFMbndInflow (1<< 3) 00099 #define CFMbndOutflow (1<< 4) 00100 #define CFFluid (1<< 5) 00101 #define CFInter (1<< 6) 00102 // additional for fluid (needed separately for adaptive grids) 00103 #define CFNoBndFluid (1<< 7) 00104 #define CFNoDelete (1<< 8) 00105 00106 // additional bnd add flags 00107 #define CFBndNoslip (1<< 9) 00108 #define CFBndFreeslip (1<<10) 00109 #define CFBndPartslip (1<<11) 00110 #define CFBndMoving (1<<12) 00111 00112 // additional for fluid/interface 00113 // force symmetry for flag reinit 00114 #define CFNoInterpolSrc (1<<13) 00115 #define CFNoNbFluid (1<<14) 00116 #define CFNoNbEmpty (1<<15) 00117 00118 // cell treated normally on coarser grids 00119 #define CFGrNorm (1<<16) 00120 #define CFGrCoarseInited (1<<17) 00121 00122 // (the following values shouldnt overlap to ensure 00123 // proper coarsening) 00124 // border cells to be interpolated from finer grid 00125 #define CFGrFromFine (1<<18) 00126 // 32k aux border marker 00127 #define CFGrToFine (1<<19) 00128 // also needed on finest level 00129 #define CFGrFromCoarse (1<<20) 00130 // additional refinement tags (coarse grids only?) 00131 // */ 00132 00133 // above 24 is used to encode in/outflow object type 00134 #define CFPersistMask (0xFF000000 | CFMbndInflow | CFMbndOutflow) 00135 #define CFNoPersistMask (~CFPersistMask) 00136 00137 00138 // nk 00139 #define CFInvalid (CellFlagType)(1<<31) 00140 00141 // use 32bit flag types 00142 //#ifdef __x86_64__ 00143 //typedef int cfINT32; 00144 //#else 00145 //typedef long cfINT32; 00146 //#endif // defined (_IA64) 00147 //#define CellFlagType cfINT32 00148 #define CellFlagType int 00149 #define CellFlagTypeSize 4 00150 00151 00152 // aux. field indices (same for 2d) 00153 #define dFfrac 19 00154 #define dMass 20 00155 #define dFlux 21 00156 // max. no. of cell values for 3d 00157 #define dTotalNum 22 00158 00159 00160 /*****************************************************************************/ 00162 /* the template is only needed for 00163 * dimension dependend constants e.g. 00164 * number of df's in model */ 00165 class LbmCellContents { 00166 public: 00167 LbmFloat df[ 27 ]; // be on the safe side here... 00168 LbmFloat rho; 00169 LbmVec vel; 00170 LbmFloat mass; 00171 CellFlagType flag; 00172 BubbleId bubble; 00173 LbmFloat ffrac; 00174 }; 00175 00176 /* struct for the coordinates of a cell in the grid */ 00177 typedef struct { 00178 int x,y,z; 00179 int flag; // special handling? 00180 } LbmPoint; 00181 00182 /* struct for the coordinates of a cell in the grid */ 00183 typedef struct { 00184 char active; // bubble in use, oder may be overwritten? 00185 LbmFloat volume; // volume of this bubble (0 vor atmosphere) 00186 LbmFloat mass; // "mass" of bubble 00187 int i,j,k; // index of a cell in the bubble 00188 } LbmBubble; 00189 00190 00191 00192 00194 #define FLUIDDISPINVALID 0 00195 #define FLUIDDISPNothing 1 00196 #define FLUIDDISPCelltypes 2 00197 #define FLUIDDISPVelocities 3 00198 #define FLUIDDISPCellfills 4 00199 #define FLUIDDISPDensity 5 00200 #define FLUIDDISPGrid 6 00201 #define FLUIDDISPSurface 7 00202 00203 00204 00205 /*****************************************************************************/ 00207 class CellIdentifierInterface { 00208 public: 00210 CellIdentifierInterface():mEnd(false) { }; 00212 virtual ~CellIdentifierInterface() {}; 00213 00215 virtual string getAsString() = 0; 00216 00218 virtual bool equal(CellIdentifierInterface* other) = 0; 00219 00221 inline void setEnd(bool set){ mEnd = set; } 00222 inline bool getEnd( ) { return mEnd; } 00223 00225 bool mEnd; 00226 00227 }; 00228 00229 00230 00231 /*****************************************************************************/ 00233 /* has to provide iterating functionality */ 00234 class LbmSolverInterface 00235 { 00236 public: 00238 LbmSolverInterface(); 00240 virtual ~LbmSolverInterface(); 00242 virtual string getIdString() = 0; 00243 00244 // multi step solver init 00246 virtual bool initializeSolverMemory() =0; 00248 virtual bool initializeSolverGrids() =0; 00250 virtual bool initializeSolverPostinit() =0; 00251 00253 virtual void notifySolverOfDump(int dumptype, int frameNr,char *frameNrStr,string outfilename) = 0; 00254 00256 CellFlagType readBoundaryFlagInt(string name, int defaultValue, string source,string target, bool needed); 00258 void parseStdAttrList(); 00260 virtual void parseAttrList() = 0; 00261 00262 virtual void step() = 0; 00263 virtual void prepareVisualization() { /* by default off */ }; 00264 00266 virtual int initParticles() = 0; 00267 virtual void advanceParticles() = 0; 00269 IsoSurface* getSurfaceGeoObj() { return mpIso; } 00270 00272 virtual vector<ntlGeometryObject*> getDebugObjects() { vector<ntlGeometryObject*> empty(0); return empty; } 00273 00274 /* surface generation settings */ 00275 virtual void setSurfGenSettings(short value) = 0; 00276 00277 #if LBM_USE_GUI==1 00278 00279 virtual void debugDisplay(int) = 0; 00280 #endif 00281 00283 void initGeoTree(); 00285 void freeGeoTree(); 00287 bool geoInitCheckPointInside(ntlVec3Gfx org, int flags, int &OId, gfxReal &distance,int shootDir=0); 00288 bool geoInitCheckPointInside(ntlVec3Gfx org, ntlVec3Gfx dir, int flags, int &OId, gfxReal &distance, 00289 const gfxReal halfCellsize, bool &thinHit, bool recurse); 00291 void setRenderGlobals(ntlRenderGlobals *glob) { mpGlob = glob; }; 00293 ntlVec3Gfx getGeoMaxMovementVelocity(LbmFloat simtime, LbmFloat stepsize); 00294 00295 /* rt interface functions */ 00296 unsigned int getIsoVertexCount() { return mpIso->getIsoVertexCount(); } 00297 unsigned int getIsoIndexCount() { return mpIso->getIsoIndexCount(); } 00298 char* getIsoVertexArray() { return mpIso->getIsoVertexArray(); } 00299 unsigned int *getIsoIndexArray() { return mpIso->getIsoIndexArray(); } 00300 void triangulateSurface() { mpIso->triangulate(); } 00301 00302 /* access functions */ 00303 00305 int getSizeX( void ) { return mSizex; } 00306 int getSizeY( void ) { return mSizey; } 00307 int getSizeZ( void ) { return mSizez; } 00309 void setSizeX( int ns ) { mSizex = ns; } 00310 void setSizeY( int ns ) { mSizey = ns; } 00311 void setSizeZ( int ns ) { mSizez = ns; } 00313 void setAllfluid(bool set) { mAllfluid=set; } 00314 bool getAllfluid() { return mAllfluid; } 00315 00317 void setAttrList(AttributeList *set) { mpSifAttrs = set; } 00319 inline AttributeList *getAttributeList() { return mpSifAttrs; } 00321 void setSwsAttrList(AttributeList *set) { mpSifSwsAttrs = set; } 00322 inline AttributeList *getSwsAttributeList() { return mpSifSwsAttrs; } 00323 00325 inline void setParametrizer(Parametrizer *set) { mpParam = set; } 00327 inline Parametrizer *getParametrizer() { return mpParam; } 00329 inline void setParticleTracer(ParticleTracer *set) { mpParticles = set; } 00330 inline ParticleTracer *getParticleTracer() { return mpParticles; } 00331 00333 inline void setInitDensityGradient(bool set) { mInitDensityGradient = set; } 00334 00336 inline void setGeoStart(ntlVec3Gfx set) { mvGeoStart = set; } 00337 inline ntlVec3Gfx getGeoStart() const { return mvGeoStart; } 00338 00340 inline void setGeoEnd(ntlVec3Gfx set) { mvGeoEnd = set; } 00341 inline ntlVec3Gfx getGeoEnd() const { return mvGeoEnd; } 00342 00344 inline void setLbmInitId(int set) { mLbmInitId = set; } 00345 inline int getLbmInitId() const { return mLbmInitId; } 00346 00348 void initDomainTrafo(float *mat); 00350 inline ntlMatrix4x4<gfxReal> *getDomainTrafo() { return mpSimTrafo; } 00351 00353 inline void setName(string set) { mName = set; } 00354 inline string getName() const { return mName; } 00355 00357 inline string getNodeInfoString() const { return mNodeInfoString; } 00358 00360 inline bool getPanic() { return mPanic; } 00361 00363 inline void setSilent(bool set){ mSilent = set; } 00364 00366 inline void setSmoothing(float setss,float setns){ mSmoothSurface=setss; mSmoothNormals=setns; } 00368 inline void setIsoSubdivs(int s){ mIsoSubdivs=s; } 00370 inline void setPreviewSize(int set){ mOutputSurfacePreview = set; } 00372 inline void setRefinementDesired(int set){ mRefinementDesired = set; } 00373 00375 inline void setDumpVelocities(bool set) { mDumpVelocities = set; } 00376 inline bool getDumpVelocities() const { return mDumpVelocities; } 00377 00379 inline void setGenerateParticles(LbmFloat set) { mPartGenProb = set; } 00380 inline LbmFloat getGenerateParticles() const { return mPartGenProb; } 00381 00383 inline void setDomainBound(string set) { mDomainBound = set; } 00384 inline string getDomainBound() const { return mDomainBound; } 00386 inline void setDomainPartSlip(LbmFloat set) { mDomainPartSlipValue = set; } 00387 inline LbmFloat getDomainPartSlip() const { return mDomainPartSlipValue; } 00389 inline void setFarFieldSize(LbmFloat set) { mFarFieldSize = set; } 00390 inline LbmFloat getFarFieldSize() const { return mFarFieldSize; } 00392 inline void setCpStage(int set) { mCppfStage = set; } 00393 inline int getCpStage() const { return mCppfStage; } 00395 inline void setDumpRawText(bool set) { mDumpRawText = set; } 00396 inline bool getDumpRawText() const { return mDumpRawText; } 00397 inline void setDumpRawBinary(bool set) { mDumpRawBinary = set; } 00398 inline bool getDumpRawBinary() const { return mDumpRawBinary; } 00399 inline void setDumpRawBinaryZip(bool set) { mDumpRawBinaryZip = set; } 00400 inline bool getDumpRawBinaryZip() const { return mDumpRawBinaryZip; } 00402 inline void setDebugVelScale(LbmFloat set) { mDebugVelScale = set; } 00403 inline LbmFloat getDebugVelScale() const { return mDebugVelScale; } 00404 00405 // cell iterator interface 00406 00407 // cell id type 00408 typedef CellIdentifierInterface* CellIdentifier; 00409 00411 virtual CellIdentifierInterface* getFirstCell( ) = 0; 00412 virtual void advanceCell( CellIdentifierInterface* ) = 0; 00413 virtual bool noEndCell( CellIdentifierInterface* ) = 0; 00415 virtual void deleteCellIterator( CellIdentifierInterface** ) = 0; 00416 00418 virtual CellIdentifierInterface* getCellAt( ntlVec3Gfx pos ) = 0; 00419 00421 virtual int getCellSet ( CellIdentifierInterface* ) = 0; 00422 virtual ntlVec3Gfx getCellOrigin ( CellIdentifierInterface* ) = 0; 00423 virtual ntlVec3Gfx getCellSize ( CellIdentifierInterface* ) = 0; 00424 virtual int getCellLevel ( CellIdentifierInterface* ) = 0; 00425 virtual LbmFloat getCellDensity ( CellIdentifierInterface*,int ) = 0; 00426 virtual LbmVec getCellVelocity ( CellIdentifierInterface*,int ) = 0; 00428 virtual LbmFloat getEquilDf ( int ) = 0; 00430 virtual LbmFloat getCellDf ( CellIdentifierInterface* ,int set, int dir) = 0; 00431 virtual LbmFloat getCellMass ( CellIdentifierInterface* ,int set) = 0; 00432 virtual LbmFloat getCellFill ( CellIdentifierInterface* ,int set) = 0; 00433 virtual CellFlagType getCellFlag ( CellIdentifierInterface* ,int set) = 0; 00434 00436 virtual ntlVec3Gfx getVelocityAt(float x, float y, float z) = 0; 00437 00438 // gui/output debugging functions 00439 #if LBM_USE_GUI==1 00440 virtual void debugDisplayNode(int dispset, CellIdentifier cell ) = 0; 00441 virtual void lbmDebugDisplay(int dispset) = 0; 00442 virtual void lbmMarkedCellDisplay() = 0; 00443 #endif // LBM_USE_GUI==1 00444 virtual void debugPrintNodeInfo(CellIdentifier cell, int forceSet=-1) = 0; 00445 00446 // debugging cell marker functions 00447 00449 void addCellToMarkedList( CellIdentifierInterface *cid ); 00451 CellIdentifierInterface* markedGetFirstCell( ); 00452 CellIdentifierInterface* markedAdvanceCell(); 00453 void markedClearList(); 00454 00455 00456 protected: 00457 00459 bool mPanic; 00460 00461 00463 int mSizex, mSizey, mSizez; 00465 bool mAllfluid; 00466 00467 00469 int mStepCnt; 00470 00472 LbmFloat mFixMass; 00473 00474 // deprecated param vars 00476 LbmFloat mOmega; 00478 LbmVec mGravity; 00480 LbmFloat mSurfaceTension; 00481 00482 00483 /* boundary inits */ 00484 CellFlagType mBoundaryEast, mBoundaryWest, 00485 mBoundaryNorth, mBoundarySouth, 00486 mBoundaryTop, mBoundaryBottom; 00487 00489 int mInitDone; 00490 00492 bool mInitDensityGradient; 00493 00495 AttributeList *mpSifAttrs; 00496 AttributeList *mpSifSwsAttrs; 00497 00499 Parametrizer *mpParam; 00501 ParticleTracer *mpParticles; 00502 00504 int mNumParticlesLost; 00506 int mNumInvalidDfs; 00508 int mNumFilledCells, mNumEmptiedCells; 00510 int mNumUsedCells; 00512 LbmFloat mMLSUPS; 00514 LbmFloat mDebugVelScale; 00516 string mNodeInfoString; 00517 00518 // geo init vars 00519 // TODO deprecate SimulationObject vars 00520 00522 ntlVec3Gfx mvGeoStart, mvGeoEnd; 00524 ntlMatrix4x4<gfxReal> *mpSimTrafo; 00525 00527 bool mAccurateGeoinit; 00528 00530 string mName; 00531 00533 IsoSurface *mpIso; 00535 LbmFloat mIsoValue; 00536 00538 bool mSilent; 00539 00541 int mLbmInitId; 00543 ntlTree *mpGiTree; 00545 vector<ntlGeometryObject*> *mpGiObjects; 00547 vector<int> mGiObjInside; 00549 vector<gfxReal> mGiObjDistance; 00550 vector<gfxReal> mGiObjSecondDist; 00552 ntlRenderGlobals *mpGlob; 00553 00555 int mRefinementDesired; 00556 00558 int mOutputSurfacePreview; 00559 LbmFloat mPreviewFactor; 00560 00562 float mSmoothSurface; 00563 float mSmoothNormals; 00565 int mIsoSubdivs; 00566 00568 LbmFloat mPartGenProb; 00569 00571 bool mDumpVelocities; 00572 00573 // list for marked cells 00574 vector<CellIdentifierInterface *> mMarkedCells; 00575 int mMarkedCellIndex; 00576 00578 string mDomainBound; 00580 LbmFloat mDomainPartSlipValue; 00581 00582 // size of far field area 00583 LbmFloat mFarFieldSize; 00584 // amount of drop mass to subtract 00585 LbmFloat mPartDropMassSub; 00586 // use physical drop model for particles? 00587 bool mPartUsePhysModel; 00588 00590 // strength of applied force 00591 LbmFloat mTForceStrength; 00592 int mCppfStage; 00593 00595 bool mDumpRawText; 00596 bool mDumpRawBinary; 00597 bool mDumpRawBinaryZip; 00598 }; 00599 00600 00601 // helper function to create consistent grid resolutions 00602 void initGridSizes(int &mSizex, int &mSizey, int &mSizez, 00603 ntlVec3Gfx &mvGeoStart, ntlVec3Gfx &mvGeoEnd, 00604 int mMaxRefine, bool parallel); 00605 // return the amount of memory required in total (reqret) 00606 // and for the finest grid only (reqretFine, can be NULL) 00607 void calculateMemreqEstimate(int resx,int resy,int resz, int refine, 00608 float farfieldsize, double *reqret, double *reqretFine, string *reqstr); 00609 00611 string convertCellFlagType2String( CellFlagType flag ); 00612 string convertSingleFlag2String(CellFlagType cflag); 00613 00614 #endif // LBMINTERFACE_H