msvc: Use source folder structure for project file.
[blender.git] / intern / elbeem / intern / solver_init.cpp
index 7e9f5e7f4202e0d085d925623ecb05e74ceaae3b..8b962d604cf8532dcce9057273805b96f4377928 100644 (file)
@@ -15,6 +15,8 @@
 #include "solver_relax.h"
 // for geo init FGI_ defines
 #include "elbeem.h"
 #include "solver_relax.h"
 // for geo init FGI_ defines
 #include "elbeem.h"
+#include "globals.h"
+
 
 // helper for 2d init
 #define SWAPYZ(vec) { \
 
 // helper for 2d init
 #define SWAPYZ(vec) { \
 #endif  // LBMDIM==2
 
 
 #endif  // LBMDIM==2
 
 
-// required globals
-extern bool glob_mpactive;
-extern int glob_mpnum, glob_mpindex;
 
 
 /******************************************************************************
 
 
 /******************************************************************************
@@ -686,13 +685,16 @@ bool LbmFsgrSolver::initializeSolverMemory()
                if(firstMInit) {
                        mrSetup();
                }
                if(firstMInit) {
                        mrSetup();
                }
+#else
+               (void)firstMInit;
 #endif // LBM_INCLUDE_TESTSOLVERS==1
                firstMInit=false;
 
                calculateMemreqEstimate( mSizex, mSizey, mSizez, 
                                mMaxRefine, mFarFieldSize, &memEstFromFunc, &memEstFine, &memreqStr );
                
 #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
                string memLimStr("-");
                if(sizeof(void*)==4) {
                        // 32bit system, limit to 2GB
@@ -700,8 +702,9 @@ bool LbmFsgrSolver::initializeSolverMemory()
                        memLimStr = string("2GB");
                } else {
                        // 64bit, just take 16GB as limit for now...
                        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
                }
 
                // restrict max. chunk of 1 mem block to 1GB for windos
@@ -725,7 +728,7 @@ bool LbmFsgrSolver::initializeSolverMemory()
                        memBlockAllocProblem = true;
                }
 
                        memBlockAllocProblem = true;
                }
 
-               if(memEstFromFunc>memLimit || memBlockAllocProblem) {
+               if(!noLimit && (memEstFromFunc>memLimit || memBlockAllocProblem)) {
                        sizeReduction *= 0.9;
                        mSizex = (int)(orgSx * sizeReduction);
                        mSizey = (int)(orgSy * sizeReduction);
                        sizeReduction *= 0.9;
                        mSizex = (int)(orgSx * sizeReduction);
                        mSizey = (int)(orgSy * sizeReduction);
@@ -798,6 +801,17 @@ bool LbmFsgrSolver::initializeSolverMemory()
                mLevel[i].avgOmegaCnt = 0.0;
        }
 
                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;
        // init sizes
        mLevel[mMaxRefine].lSizex = mSizex;
        mLevel[mMaxRefine].lSizey = mSizey;
@@ -818,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;
        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
 
 #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);
        mLevel[ mMaxRefine ].mprsCells[1] = new LbmFloat[ rcellSize +compressOffset +4 ];
        mLevel[ mMaxRefine ].mprsCells[0] = mLevel[ mMaxRefine ].mprsCells[1]+compressOffset;
        ownMemCheck += sizeof(LbmFloat) * (rcellSize +compressOffset +4);
@@ -1339,13 +1353,13 @@ bool LbmFsgrSolver::initializeSolverPostinit() {
                                } } \
                                if(ntype&(CFBndFreeslip)) { \
                                        const LbmFloat dp=dot(objvel, vec2L((*pNormals)[n]) ); \
                                } } \
                                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]) ); \
                                        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 */ \
                                        /* 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 */ \