msvc: Use source folder structure for project file.
[blender.git] / intern / elbeem / intern / solver_init.cpp
index ce54adb48ee4b913a8fe9a0aeabffb560d5c4914..8b962d604cf8532dcce9057273805b96f4377928 100644 (file)
@@ -1,3 +1,6 @@
+/** \file elbeem/intern/solver_init.cpp
+ *  \ingroup elbeem
+ */
 /******************************************************************************
  *
  * El'Beem - Free Surface Fluid Simulation with the Lattice Boltzmann Method
@@ -12,6 +15,8 @@
 #include "solver_relax.h"
 // for geo init FGI_ defines
 #include "elbeem.h"
+#include "globals.h"
+
 
 // helper for 2d init
 #define SWAPYZ(vec) { \
 #endif  // LBMDIM==2
 
 
-// required globals
-extern bool glob_mpactive;
-extern int glob_mpnum, glob_mpindex;
 
 
 /******************************************************************************
@@ -535,6 +537,15 @@ void LbmFsgrSolver::parseAttrList()
 }
 
 
+/******************************************************************************
+ * (part of enabling chapter 6 of "Free Surface Flows with Moving and Deforming Objects for LBM")
+ *****************************************************************************/
+void LbmFsgrSolver::setSurfGenSettings(short value)
+{
+       mFsSurfGenSetting = value;
+}
+
+
 /******************************************************************************
  * Initialize omegas and forces on all levels (for init/timestep change)
  *****************************************************************************/
@@ -674,13 +685,16 @@ bool LbmFsgrSolver::initializeSolverMemory()
                if(firstMInit) {
                        mrSetup();
                }
+#else
+               (void)firstMInit;
 #endif // LBM_INCLUDE_TESTSOLVERS==1
                firstMInit=false;
 
                calculateMemreqEstimate( mSizex, mSizey, mSizez, 
                                mMaxRefine, mFarFieldSize, &memEstFromFunc, &memEstFine, &memreqStr );
                
-               double memLimit;
+               bool noLimit = false;
+               double memLimit = 0.;
                string memLimStr("-");
                if(sizeof(void*)==4) {
                        // 32bit system, limit to 2GB
@@ -688,8 +702,9 @@ bool LbmFsgrSolver::initializeSolverMemory()
                        memLimStr = string("2GB");
                } else {
                        // 64bit, just take 16GB as limit for now...
-                       memLimit = 16.0* 1024.0*1024.0*1024.0;
-                       memLimStr = string("16GB");
+                       // memLimit = 16.0* 1024.0*1024.0*1024.0;
+                       // memLimStr = string("16GB");
+                       noLimit = true;
                }
 
                // restrict max. chunk of 1 mem block to 1GB for windos
@@ -713,7 +728,7 @@ bool LbmFsgrSolver::initializeSolverMemory()
                        memBlockAllocProblem = true;
                }
 
-               if(memEstFromFunc>memLimit || memBlockAllocProblem) {
+               if(!noLimit && (memEstFromFunc>memLimit || memBlockAllocProblem)) {
                        sizeReduction *= 0.9;
                        mSizex = (int)(orgSx * sizeReduction);
                        mSizey = (int)(orgSy * sizeReduction);
@@ -786,6 +801,17 @@ bool LbmFsgrSolver::initializeSolverMemory()
                mLevel[i].avgOmegaCnt = 0.0;
        }
 
+#if PARALLEL == 1
+       /*
+       // DG: this would be the correct sanity check, not the "hack below" */
+       // if(( mSizey / mNumOMPThreads) * mNumOMPThreads != mSizey) {
+               // setNumOMPThreads();
+       //}
+       if( mSizey < mNumOMPThreads ) {
+               setNumOMPThreads(mSizey);
+       }
+#endif
+
        // init sizes
        mLevel[mMaxRefine].lSizex = mSizex;
        mLevel[mMaxRefine].lSizey = mSizey;
@@ -806,16 +832,16 @@ bool LbmFsgrSolver::initializeSolverMemory()
        mLevel[ mMaxRefine ].nodeSize = ((mvGeoEnd[0]-mvGeoStart[0]) / (LbmFloat)(mSizex));
        mLevel[ mMaxRefine ].simCellSize = mpParam->getCellSize();
        mLevel[ mMaxRefine ].lcellfactor = 1.0;
-       LONGINT rcellSize = ((mLevel[mMaxRefine].lSizex*mLevel[mMaxRefine].lSizey*mLevel[mMaxRefine].lSizez) *dTotalNum);
+       LONGINT rcellSize = (LONGINT)((LONGINT)((LONGINT)mLevel[mMaxRefine].lSizex*(LONGINT)mLevel[mMaxRefine].lSizey*(LONGINT)mLevel[mMaxRefine].lSizez) * (LONGINT)dTotalNum);
 
 #if COMPRESSGRIDS==0
        mLevel[ mMaxRefine ].mprsCells[0] = new LbmFloat[ rcellSize +4 ];
        mLevel[ mMaxRefine ].mprsCells[1] = new LbmFloat[ rcellSize +4 ];
        ownMemCheck += 2 * sizeof(LbmFloat) * (rcellSize+4);
 #else // COMPRESSGRIDS==0
-       LONGINT compressOffset = (mLevel[mMaxRefine].lSizex*mLevel[mMaxRefine].lSizey*dTotalNum*2);
-       // D int tmp = ( (rcellSize +compressOffset +4)/(1024*1024) )*4;
-       // D printf("Debug MEMMMM excee: %d\n", tmp);
+       LONGINT compressOffset = (LONGINT)((LONGINT)mLevel[mMaxRefine].lSizex * (LONGINT)mLevel[mMaxRefine].lSizey * (LONGINT)dTotalNum * 2);
+       // LONGINT tmp = ( (rcellSize +compressOffset +4)/(1024*1024) )*sizeof(LbmFloat);
+       // printf("Debug MEMMMM excee: %I64d, %I64d, %I64d, %d, %d\n", tmp, compressOffset, rcellSize, mLevel[mMaxRefine].lSizex, mLevel[mMaxRefine].lSizey );
        mLevel[ mMaxRefine ].mprsCells[1] = new LbmFloat[ rcellSize +compressOffset +4 ];
        mLevel[ mMaxRefine ].mprsCells[0] = mLevel[ mMaxRefine ].mprsCells[1]+compressOffset;
        ownMemCheck += sizeof(LbmFloat) * (rcellSize +compressOffset +4);
@@ -1001,7 +1027,7 @@ bool LbmFsgrSolver::initializeSolverMemory()
        preinitGrids();
        for(int lev=0; lev<=mMaxRefine; lev++) {
                FSGR_FORIJK_BOUNDS(lev) {
-                       RFLAG(lev,i,j,k,0) = RFLAG(lev,i,j,k,0) = 0; // reset for changeFlag usage
+                       RFLAG(lev,i,j,k,0) = 0, RFLAG(lev,i,j,k,0) = 0; // reset for changeFlag usage
                        if(!mAllfluid) {
                                initEmptyCell(lev, i,j,k, CFEmpty, -1.0, -1.0); 
                        } else {
@@ -1327,13 +1353,13 @@ bool LbmFsgrSolver::initializeSolverPostinit() {
                                } } \
                                if(ntype&(CFBndFreeslip)) { \
                                        const LbmFloat dp=dot(objvel, vec2L((*pNormals)[n]) ); \
-                                       const LbmVec oldov=objvel; /*DEBUG*/ \
+                                       /* const LbmVec oldov=objvel; */ /*DEBUG*/ \
                                        objvel = vec2L((*pNormals)[n]) *dp; \
                                        /* if((j==24)&&(n%5==2)) errMsg("FSBT","n"<<n<<" v"<<objvel<<" nn"<<(*pNormals)[n]<<" dp"<<dp<<" oldov"<<oldov ); */ \
                                } \
                                else if(ntype&(CFBndPartslip)) { \
                                        const LbmFloat dp=dot(objvel, vec2L((*pNormals)[n]) ); \
-                                       const LbmVec oldov=objvel; /*DEBUG*/ \
+                                       /* const LbmVec oldov=objvel; */ /*DEBUG*/ \
                                        /* if((j==24)&&(n%5==2)) errMsg("FSBT","n"<<n<<" v"<<objvel<<" nn"<<(*pNormals)[n]<<" dp"<<dp<<" oldov"<<oldov ); */ \
                                        const LbmFloat partv = mObjectPartslips[OId]; \
                                        /*errMsg("PARTSLIP_DEBUG","l="<<l<<" ccel="<<RAC(ccel, dfInv[l] )<<" partv="<<partv<<",id="<<(int)(mnbf>>24)<<" newval="<<newval ); / part slip debug */ \
@@ -1464,7 +1490,7 @@ void LbmFsgrSolver::initMovingObstacles(bool staticInit) {
                                obj->applyTransformation(targetTime, &mMOIVertices,NULL /* no old normals needed */, 0, mMOIVertices.size(), false );
                        } else {
                                // only do transform update
-                               obj->getMovingPoints(mMOIVertices,pNormals);
+                               obj->getMovingPoints(mMOIVertices,pNormals); // mMOIVertices = mCachedMovPoints
                                mMOIVerticesOld = mMOIVertices;
                                // WARNING - assumes mSimulationTime is global!?
                                obj->applyTransformation(targetTime, &mMOIVertices,pNormals, 0, mMOIVertices.size(), false );