diff options
Diffstat (limited to 'intern/mantaflow')
-rw-r--r-- | intern/mantaflow/extern/manta_fluid_API.h | 17 | ||||
-rw-r--r-- | intern/mantaflow/intern/MANTA_main.cpp | 528 | ||||
-rw-r--r-- | intern/mantaflow/intern/MANTA_main.h | 170 | ||||
-rw-r--r-- | intern/mantaflow/intern/manta_fluid_API.cpp | 93 | ||||
-rw-r--r-- | intern/mantaflow/intern/strings/fluid_script.h | 13 |
5 files changed, 407 insertions, 414 deletions
diff --git a/intern/mantaflow/extern/manta_fluid_API.h b/intern/mantaflow/extern/manta_fluid_API.h index 3da1d8f53f0..124671467f7 100644 --- a/intern/mantaflow/extern/manta_fluid_API.h +++ b/intern/mantaflow/extern/manta_fluid_API.h @@ -33,10 +33,10 @@ struct MANTA; /* Fluid functions */ struct MANTA *manta_init(int *res, struct FluidModifierData *fmd); void manta_free(struct MANTA *fluid); -void manta_ensure_obstacle(struct MANTA *fluid, struct FluidModifierData *fmd); -void manta_ensure_guiding(struct MANTA *fluid, struct FluidModifierData *fmd); -void manta_ensure_invelocity(struct MANTA *fluid, struct FluidModifierData *fmd); -void manta_ensure_outflow(struct MANTA *fluid, struct FluidModifierData *fmd); +int manta_ensure_obstacle(struct MANTA *fluid, struct FluidModifierData *fmd); +int manta_ensure_guiding(struct MANTA *fluid, struct FluidModifierData *fmd); +int manta_ensure_invelocity(struct MANTA *fluid, struct FluidModifierData *fmd); +int manta_ensure_outflow(struct MANTA *fluid, struct FluidModifierData *fmd); int manta_write_config(struct MANTA *fluid, struct FluidModifierData *fmd, int framenr); int manta_write_data(struct MANTA *fluid, struct FluidModifierData *fmd, int framenr); int manta_write_noise(struct MANTA *fluid, struct FluidModifierData *fmd, int framenr); @@ -77,6 +77,7 @@ int manta_get_frame(struct MANTA *fluid); float manta_get_timestep(struct MANTA *fluid); void manta_adapt_timestep(struct MANTA *fluid); bool manta_needs_realloc(struct MANTA *fluid, struct FluidModifierData *fmd); +void manta_update_pointers(struct MANTA *fluid, struct FluidModifierData *fmd, bool flush); /* Fluid accessors */ size_t manta_get_index(int x, int max_x, int y, int max_y, int z /*, int max_z */); @@ -121,9 +122,9 @@ void manta_noise_get_rgba_fixed_color(struct MANTA *smoke, float color[3], float *data, int sequential); -void manta_smoke_ensure_heat(struct MANTA *smoke, struct FluidModifierData *fmd); -void manta_smoke_ensure_fire(struct MANTA *smoke, struct FluidModifierData *fmd); -void manta_smoke_ensure_colors(struct MANTA *smoke, struct FluidModifierData *fmd); +int manta_smoke_ensure_heat(struct MANTA *smoke, struct FluidModifierData *fmd); +int manta_smoke_ensure_fire(struct MANTA *smoke, struct FluidModifierData *fmd); +int manta_smoke_ensure_colors(struct MANTA *smoke, struct FluidModifierData *fmd); /* Smoke accessors */ float *manta_smoke_get_density(struct MANTA *smoke); @@ -167,7 +168,7 @@ int manta_noise_get_cells(struct MANTA *smoke); /* Liquid functions */ void manta_liquid_export_script(struct MANTA *smoke, struct FluidModifierData *fmd); -void manta_liquid_ensure_sndparts(struct MANTA *fluid, struct FluidModifierData *fmd); +int manta_liquid_ensure_sndparts(struct MANTA *fluid, struct FluidModifierData *fmd); /* Liquid accessors */ int manta_liquid_get_particle_res_x(struct MANTA *liquid); diff --git a/intern/mantaflow/intern/MANTA_main.cpp b/intern/mantaflow/intern/MANTA_main.cpp index 6e6451be725..5997e819ccf 100644 --- a/intern/mantaflow/intern/MANTA_main.cpp +++ b/intern/mantaflow/intern/MANTA_main.cpp @@ -27,10 +27,6 @@ #include <sstream> #include <zlib.h> -#if OPENVDB == 1 -# include "openvdb/openvdb.h" -#endif - #include "MANTA_main.h" #include "Python.h" #include "fluid_script.h" @@ -60,13 +56,6 @@ using std::to_string; atomic<int> MANTA::solverID(0); int MANTA::with_debug(0); -/* Number of particles that the cache reads at once (with zlib). */ -#define PARTICLE_CHUNK 20000 -/* Number of mesh nodes that the cache reads at once (with zlib). */ -#define NODE_CHUNK 20000 -/* Number of mesh triangles that the cache reads at once (with zlib). */ -#define TRIANGLE_CHUNK 20000 - MANTA::MANTA(int *res, FluidModifierData *fmd) : mCurrentID(++solverID) { if (with_debug) @@ -96,8 +85,7 @@ MANTA::MANTA(int *res, FluidModifierData *fmd) : mCurrentID(++solverID) mUsingInvel = (fds->active_fields & FLUID_DOMAIN_ACTIVE_INVEL); mUsingOutflow = (fds->active_fields & FLUID_DOMAIN_ACTIVE_OUTFLOW); - // Simulation constants - mTempAmb = 0; // TODO: Maybe use this later for buoyancy calculation + /* Simulation constants. */ mResX = res[0]; mResY = res[1]; mResZ = res[2]; @@ -105,7 +93,7 @@ MANTA::MANTA(int *res, FluidModifierData *fmd) : mCurrentID(++solverID) mTotalCells = mResX * mResY * mResZ; mResGuiding = fds->res; - // Smoke low res grids + /* Smoke low res grids. */ mDensity = nullptr; mShadow = nullptr; mHeat = nullptr; @@ -131,7 +119,7 @@ MANTA::MANTA(int *res, FluidModifierData *fmd) : mCurrentID(++solverID) mReactIn = nullptr; mEmissionIn = nullptr; - // Smoke high res grids + /* Smoke high res grids. */ mDensityHigh = nullptr; mFlameHigh = nullptr; mFuelHigh = nullptr; @@ -146,19 +134,19 @@ MANTA::MANTA(int *res, FluidModifierData *fmd) : mCurrentID(++solverID) mTextureV2 = nullptr; mTextureW2 = nullptr; - // Fluid low res grids + /* Fluid low res grids. */ mPhiIn = nullptr; mPhiStaticIn = nullptr; mPhiOutIn = nullptr; mPhiOutStaticIn = nullptr; mPhi = nullptr; - // Mesh + /* Mesh. */ mMeshNodes = nullptr; mMeshTriangles = nullptr; mMeshVelocities = nullptr; - // Fluid obstacle + /* Fluid obstacle. */ mPhiObsIn = nullptr; mPhiObsStaticIn = nullptr; mNumObstacle = nullptr; @@ -166,47 +154,48 @@ MANTA::MANTA(int *res, FluidModifierData *fmd) : mCurrentID(++solverID) mObVelocityY = nullptr; mObVelocityZ = nullptr; - // Fluid guiding + /* Fluid guiding. */ mPhiGuideIn = nullptr; mNumGuide = nullptr; mGuideVelocityX = nullptr; mGuideVelocityY = nullptr; mGuideVelocityZ = nullptr; - // Fluid initial velocity + /* Fluid initial velocity. */ mInVelocityX = nullptr; mInVelocityY = nullptr; mInVelocityZ = nullptr; - // Secondary particles + /* Secondary particles. */ mFlipParticleData = nullptr; mFlipParticleVelocity = nullptr; - mSndParticleData = nullptr; - mSndParticleVelocity = nullptr; - mSndParticleLife = nullptr; + mParticleData = nullptr; + mParticleVelocity = nullptr; + mParticleLife = nullptr; - // Cache read success indicators + /* Cache read success indicators. */ mFlipFromFile = false; mMeshFromFile = false; mParticlesFromFile = false; - // Setup Mantaflow in Python + /* Setup Mantaflow in Python. */ initializeMantaflow(); - // Initializa RNA map with values that Python will need + /* Initializa RNA map with values that Python will need. */ initializeRNAMap(fmd); - // Initialize Mantaflow variables in Python - // Liquid + bool initSuccess = true; + /* Initialize Mantaflow variables in Python. */ + /* Liquid. */ if (mUsingLiquid) { - initDomain(); - initLiquid(); + initSuccess &= initDomain(); + initSuccess &= initLiquid(); if (mUsingObstacle) - initObstacle(); + initSuccess &= initObstacle(); if (mUsingInvel) - initInVelocity(); + initSuccess &= initInVelocity(); if (mUsingOutflow) - initOutflow(); + initSuccess &= initOutflow(); if (mUsingDrops || mUsingBubbles || mUsingFloats || mUsingTracers) { mUpresParticle = fds->particle_scale; @@ -215,8 +204,8 @@ MANTA::MANTA(int *res, FluidModifierData *fmd) : mCurrentID(++solverID) mResZParticle = mUpresParticle * mResZ; mTotalCellsParticles = mResXParticle * mResYParticle * mResZParticle; - initSndParts(); - initLiquidSndParts(); + initSuccess &= initSndParts(); + initSuccess &= initLiquidSndParts(); } if (mUsingMesh) { @@ -226,44 +215,44 @@ MANTA::MANTA(int *res, FluidModifierData *fmd) : mCurrentID(++solverID) mResZMesh = mUpresMesh * mResZ; mTotalCellsMesh = mResXMesh * mResYMesh * mResZMesh; - // Initialize Mantaflow variables in Python - initMesh(); - initLiquidMesh(); + /* Initialize Mantaflow variables in Python. */ + initSuccess &= initMesh(); + initSuccess &= initLiquidMesh(); } if (mUsingDiffusion) { - initCurvature(); + initSuccess &= initCurvature(); } if (mUsingGuiding) { mResGuiding = (fds->guide_parent) ? fds->guide_res : fds->res; - initGuiding(); + initSuccess &= initGuiding(); } if (mUsingFractions) { - initFractions(); + initSuccess &= initFractions(); } } - // Smoke + /* Smoke. */ if (mUsingSmoke) { - initDomain(); - initSmoke(); + initSuccess &= initDomain(); + initSuccess &= initSmoke(); if (mUsingHeat) - initHeat(); + initSuccess &= initHeat(); if (mUsingFire) - initFire(); + initSuccess &= initFire(); if (mUsingColors) - initColors(); + initSuccess &= initColors(); if (mUsingObstacle) - initObstacle(); + initSuccess &= initObstacle(); if (mUsingInvel) - initInVelocity(); + initSuccess &= initInVelocity(); if (mUsingOutflow) - initOutflow(); + initSuccess &= initOutflow(); if (mUsingGuiding) { mResGuiding = (fds->guide_parent) ? fds->guide_res : fds->res; - initGuiding(); + initSuccess &= initGuiding(); } if (mUsingNoise) { @@ -273,31 +262,33 @@ MANTA::MANTA(int *res, FluidModifierData *fmd) : mCurrentID(++solverID) mResZNoise = amplify * mResZ; mTotalCellsHigh = mResXNoise * mResYNoise * mResZNoise; - // Initialize Mantaflow variables in Python - initNoise(); - initSmokeNoise(); + /* Initialize Mantaflow variables in Python. */ + initSuccess &= initNoise(); + initSuccess &= initSmokeNoise(); if (mUsingFire) - initFireHigh(); + initSuccess &= initFireHigh(); if (mUsingColors) - initColorsHigh(); + initSuccess &= initColorsHigh(); } } - updatePointers(); + /* All requested initializations must not fail in constructor. */ + BLI_assert(initSuccess); + updatePointers(fmd); } -void MANTA::initDomain(FluidModifierData *fmd) +bool MANTA::initDomain(FluidModifierData *fmd) { - // Vector will hold all python commands that are to be executed + /* Vector will hold all python commands that are to be executed. */ vector<string> pythonCommands; - // Set manta debug level first + /* Set manta debug level first. */ pythonCommands.push_back(manta_import + manta_debuglevel); ostringstream ss; ss << "set_manta_debuglevel(" << with_debug << ")"; pythonCommands.push_back(ss.str()); - // Now init basic fluid domain + /* Now init basic fluid domain. */ string tmpString = fluid_variables + fluid_solver + fluid_alloc + fluid_cache_helper + fluid_bake_multiprocessing + fluid_bake_data + fluid_bake_noise + fluid_bake_mesh + fluid_bake_particles + fluid_bake_guiding + @@ -305,20 +296,20 @@ void MANTA::initDomain(FluidModifierData *fmd) fluid_adapt_time_step + fluid_time_stepping; string finalString = parseScript(tmpString, fmd); pythonCommands.push_back(finalString); - runPythonString(pythonCommands); + return runPythonString(pythonCommands); } -void MANTA::initNoise(FluidModifierData *fmd) +bool MANTA::initNoise(FluidModifierData *fmd) { vector<string> pythonCommands; string tmpString = fluid_variables_noise + fluid_solver_noise; string finalString = parseScript(tmpString, fmd); pythonCommands.push_back(finalString); - runPythonString(pythonCommands); + return runPythonString(pythonCommands); } -void MANTA::initSmoke(FluidModifierData *fmd) +bool MANTA::initSmoke(FluidModifierData *fmd) { vector<string> pythonCommands; string tmpString = smoke_variables + smoke_alloc + smoke_adaptive_step + smoke_save_data + @@ -326,10 +317,10 @@ void MANTA::initSmoke(FluidModifierData *fmd) string finalString = parseScript(tmpString, fmd); pythonCommands.push_back(finalString); - runPythonString(pythonCommands); + return runPythonString(pythonCommands); } -void MANTA::initSmokeNoise(FluidModifierData *fmd) +bool MANTA::initSmokeNoise(FluidModifierData *fmd) { vector<string> pythonCommands; string tmpString = smoke_variables_noise + smoke_alloc_noise + smoke_wavelet_noise + @@ -337,11 +328,11 @@ void MANTA::initSmokeNoise(FluidModifierData *fmd) string finalString = parseScript(tmpString, fmd); pythonCommands.push_back(finalString); - runPythonString(pythonCommands); mUsingNoise = true; + return runPythonString(pythonCommands); } -void MANTA::initHeat(FluidModifierData *fmd) +bool MANTA::initHeat(FluidModifierData *fmd) { if (!mHeat) { vector<string> pythonCommands; @@ -349,12 +340,13 @@ void MANTA::initHeat(FluidModifierData *fmd) string finalString = parseScript(tmpString, fmd); pythonCommands.push_back(finalString); - runPythonString(pythonCommands); mUsingHeat = true; + return runPythonString(pythonCommands); } + return false; } -void MANTA::initFire(FluidModifierData *fmd) +bool MANTA::initFire(FluidModifierData *fmd) { if (!mFuel) { vector<string> pythonCommands; @@ -362,12 +354,13 @@ void MANTA::initFire(FluidModifierData *fmd) string finalString = parseScript(tmpString, fmd); pythonCommands.push_back(finalString); - runPythonString(pythonCommands); mUsingFire = true; + return runPythonString(pythonCommands); } + return false; } -void MANTA::initFireHigh(FluidModifierData *fmd) +bool MANTA::initFireHigh(FluidModifierData *fmd) { if (!mFuelHigh) { vector<string> pythonCommands; @@ -375,12 +368,13 @@ void MANTA::initFireHigh(FluidModifierData *fmd) string finalString = parseScript(tmpString, fmd); pythonCommands.push_back(finalString); - runPythonString(pythonCommands); mUsingFire = true; + return runPythonString(pythonCommands); } + return false; } -void MANTA::initColors(FluidModifierData *fmd) +bool MANTA::initColors(FluidModifierData *fmd) { if (!mColorR) { vector<string> pythonCommands; @@ -388,12 +382,13 @@ void MANTA::initColors(FluidModifierData *fmd) string finalString = parseScript(tmpString, fmd); pythonCommands.push_back(finalString); - runPythonString(pythonCommands); mUsingColors = true; + return runPythonString(pythonCommands); } + return false; } -void MANTA::initColorsHigh(FluidModifierData *fmd) +bool MANTA::initColorsHigh(FluidModifierData *fmd) { if (!mColorRHigh) { vector<string> pythonCommands; @@ -401,12 +396,13 @@ void MANTA::initColorsHigh(FluidModifierData *fmd) string finalString = parseScript(tmpString, fmd); pythonCommands.push_back(finalString); - runPythonString(pythonCommands); mUsingColors = true; + return runPythonString(pythonCommands); } + return false; } -void MANTA::initLiquid(FluidModifierData *fmd) +bool MANTA::initLiquid(FluidModifierData *fmd) { if (!mPhiIn) { vector<string> pythonCommands; @@ -415,44 +411,45 @@ void MANTA::initLiquid(FluidModifierData *fmd) string finalString = parseScript(tmpString, fmd); pythonCommands.push_back(finalString); - runPythonString(pythonCommands); mUsingLiquid = true; + return runPythonString(pythonCommands); } + return false; } -void MANTA::initMesh(FluidModifierData *fmd) +bool MANTA::initMesh(FluidModifierData *fmd) { vector<string> pythonCommands; string tmpString = fluid_variables_mesh + fluid_solver_mesh + liquid_load_mesh; string finalString = parseScript(tmpString, fmd); pythonCommands.push_back(finalString); - runPythonString(pythonCommands); mUsingMesh = true; + return runPythonString(pythonCommands); } -void MANTA::initLiquidMesh(FluidModifierData *fmd) +bool MANTA::initLiquidMesh(FluidModifierData *fmd) { vector<string> pythonCommands; string tmpString = liquid_alloc_mesh + liquid_step_mesh + liquid_save_mesh; string finalString = parseScript(tmpString, fmd); pythonCommands.push_back(finalString); - runPythonString(pythonCommands); mUsingMesh = true; + return runPythonString(pythonCommands); } -void MANTA::initCurvature(FluidModifierData *fmd) +bool MANTA::initCurvature(FluidModifierData *fmd) { std::vector<std::string> pythonCommands; std::string finalString = parseScript(liquid_alloc_curvature, fmd); pythonCommands.push_back(finalString); - runPythonString(pythonCommands); mUsingDiffusion = true; + return runPythonString(pythonCommands); } -void MANTA::initObstacle(FluidModifierData *fmd) +bool MANTA::initObstacle(FluidModifierData *fmd) { if (!mPhiObsIn) { vector<string> pythonCommands; @@ -460,12 +457,13 @@ void MANTA::initObstacle(FluidModifierData *fmd) string finalString = parseScript(tmpString, fmd); pythonCommands.push_back(finalString); - runPythonString(pythonCommands); mUsingObstacle = true; + return runPythonString(pythonCommands); } + return false; } -void MANTA::initGuiding(FluidModifierData *fmd) +bool MANTA::initGuiding(FluidModifierData *fmd) { if (!mPhiGuideIn) { vector<string> pythonCommands; @@ -474,23 +472,24 @@ void MANTA::initGuiding(FluidModifierData *fmd) string finalString = parseScript(tmpString, fmd); pythonCommands.push_back(finalString); - runPythonString(pythonCommands); mUsingGuiding = true; + return runPythonString(pythonCommands); } + return false; } -void MANTA::initFractions(FluidModifierData *fmd) +bool MANTA::initFractions(FluidModifierData *fmd) { vector<string> pythonCommands; string tmpString = fluid_alloc_fractions + fluid_with_fractions; string finalString = parseScript(tmpString, fmd); pythonCommands.push_back(finalString); - runPythonString(pythonCommands); mUsingFractions = true; + return runPythonString(pythonCommands); } -void MANTA::initInVelocity(FluidModifierData *fmd) +bool MANTA::initInVelocity(FluidModifierData *fmd) { if (!mInVelocityX) { vector<string> pythonCommands; @@ -498,12 +497,13 @@ void MANTA::initInVelocity(FluidModifierData *fmd) string finalString = parseScript(tmpString, fmd); pythonCommands.push_back(finalString); - runPythonString(pythonCommands); mUsingInvel = true; + return runPythonString(pythonCommands); } + return false; } -void MANTA::initOutflow(FluidModifierData *fmd) +bool MANTA::initOutflow(FluidModifierData *fmd) { if (!mPhiOutIn) { vector<string> pythonCommands; @@ -511,24 +511,25 @@ void MANTA::initOutflow(FluidModifierData *fmd) string finalString = parseScript(tmpString, fmd); pythonCommands.push_back(finalString); - runPythonString(pythonCommands); mUsingOutflow = true; + return runPythonString(pythonCommands); } + return false; } -void MANTA::initSndParts(FluidModifierData *fmd) +bool MANTA::initSndParts(FluidModifierData *fmd) { vector<string> pythonCommands; string tmpString = fluid_variables_particles + fluid_solver_particles; string finalString = parseScript(tmpString, fmd); pythonCommands.push_back(finalString); - runPythonString(pythonCommands); + return runPythonString(pythonCommands); } -void MANTA::initLiquidSndParts(FluidModifierData *fmd) +bool MANTA::initLiquidSndParts(FluidModifierData *fmd) { - if (!mSndParticleData) { + if (!mParticleData) { vector<string> pythonCommands; string tmpString = liquid_alloc_particles + liquid_variables_particles + liquid_step_particles + fluid_with_sndparts + liquid_load_particles + @@ -536,8 +537,9 @@ void MANTA::initLiquidSndParts(FluidModifierData *fmd) string finalString = parseScript(tmpString, fmd); pythonCommands.push_back(finalString); - runPythonString(pythonCommands); + return runPythonString(pythonCommands); } + return false; } MANTA::~MANTA() @@ -546,7 +548,7 @@ MANTA::~MANTA() cout << "~FLUID: " << mCurrentID << " with res(" << mResX << ", " << mResY << ", " << mResZ << ")" << endl; - // Destruction string for Python + /* Destruction string for Python. */ string tmpString = ""; vector<string> pythonCommands; bool result = false; @@ -554,10 +556,10 @@ MANTA::~MANTA() tmpString += manta_import; tmpString += fluid_delete_all; - // Initializa RNA map with values that Python will need + /* Initializa RNA map with values that Python will need. */ initializeRNAMap(); - // Leave out fmd argument in parseScript since only looking up IDs + /* Leave out fmd argument in parseScript since only looking up IDs. */ string finalString = parseScript(tmpString); pythonCommands.push_back(finalString); result = runPythonString(pythonCommands); @@ -619,10 +621,10 @@ void MANTA::initializeMantaflow() string filename = "manta_scene_" + to_string(mCurrentID) + ".py"; vector<string> fill = vector<string>(); - // Initialize extension classes and wrappers + /* Initialize extension classes and wrappers. */ srand(0); PyGILState_STATE gilstate = PyGILState_Ensure(); - Pb::setup(filename, fill); // Namespace from Mantaflow (registry) + Pb::setup(filename, fill); /* Namespace from Mantaflow (registry). */ PyGILState_Release(gilstate); } @@ -632,7 +634,7 @@ void MANTA::terminateMantaflow() cout << "Fluid: Releasing Mantaflow framework" << endl; PyGILState_STATE gilstate = PyGILState_Ensure(); - Pb::finalize(); // Namespace from Mantaflow (registry) + Pb::finalize(); /* Namespace from Mantaflow (registry). */ PyGILState_Release(gilstate); } @@ -1073,7 +1075,7 @@ string MANTA::parseScript(const string &setup_string, FluidModifierData *fmd) ostringstream res; string line = ""; - // Update RNA map if modifier data is handed over + /* Update RNA map if modifier data is handed over. */ if (fmd) { initializeRNAMap(fmd); } @@ -1111,7 +1113,8 @@ bool MANTA::writeConfiguration(FluidModifierData *fmd, int framenr) /* Create 'config' subdir if it does not exist already. */ BLI_dir_create_recursive(directory.c_str()); - gzFile gzf = (gzFile)BLI_gzopen(file.c_str(), "wb1"); // do some compression + /* Open new file with some compression. */ + gzFile gzf = (gzFile)BLI_gzopen(file.c_str(), "wb1"); if (!gzf) { cerr << "Fluid Error -- Cannot open file " << file << endl; return false; @@ -1616,10 +1619,10 @@ void MANTA::exportSmokeScript(FluidModifierData *fmd) string manta_script; - // Libraries + /* Libraries. */ manta_script += header_libraries + manta_import; - // Variables + /* Variables. */ manta_script += header_variables + fluid_variables + smoke_variables; if (noise) { manta_script += fluid_variables_noise + smoke_variables_noise; @@ -1627,14 +1630,14 @@ void MANTA::exportSmokeScript(FluidModifierData *fmd) if (guiding) manta_script += fluid_variables_guiding; - // Solvers + /* Solvers. */ manta_script += header_solvers + fluid_solver; if (noise) manta_script += fluid_solver_noise; if (guiding) manta_script += fluid_solver_guiding; - // Grids + /* Grids. */ manta_script += header_grids + fluid_alloc + smoke_alloc; if (noise) { manta_script += smoke_alloc_noise; @@ -1658,36 +1661,36 @@ void MANTA::exportSmokeScript(FluidModifierData *fmd) if (outflow) manta_script += fluid_alloc_outflow; - // Noise field + /* Noise field. */ if (noise) manta_script += smoke_wavelet_noise; - // Time + /* Time. */ manta_script += header_time + fluid_time_stepping + fluid_adapt_time_step; - // Import + /* Import. */ manta_script += header_import + fluid_file_import + fluid_cache_helper + smoke_load_data; if (noise) manta_script += smoke_load_noise; if (guiding) manta_script += fluid_load_guiding; - // Pre/Post Steps + /* Pre/Post Steps. */ manta_script += header_prepost + fluid_pre_step + fluid_post_step; - // Steps + /* Steps. */ manta_script += header_steps + smoke_adaptive_step + smoke_step; if (noise) { manta_script += smoke_step_noise; } - // Main + /* Main. */ manta_script += header_main + smoke_standalone + fluid_standalone; - // Fill in missing variables in script + /* Fill in missing variables in script. */ string final_script = MANTA::parseScript(manta_script, fmd); - // Write script + /* Write script. */ ofstream myfile; myfile.open(cacheDirScript); myfile << final_script; @@ -1726,10 +1729,10 @@ void MANTA::exportLiquidScript(FluidModifierData *fmd) string manta_script; - // Libraries + /* Libraries. */ manta_script += header_libraries + manta_import; - // Variables + /* Variables. */ manta_script += header_variables + fluid_variables + liquid_variables; if (mesh) manta_script += fluid_variables_mesh; @@ -1738,7 +1741,7 @@ void MANTA::exportLiquidScript(FluidModifierData *fmd) if (guiding) manta_script += fluid_variables_guiding; - // Solvers + /* Solvers. */ manta_script += header_solvers + fluid_solver; if (mesh) manta_script += fluid_solver_mesh; @@ -1747,7 +1750,7 @@ void MANTA::exportLiquidScript(FluidModifierData *fmd) if (guiding) manta_script += fluid_solver_guiding; - // Grids + /* Grids. */ manta_script += header_grids + fluid_alloc + liquid_alloc; if (mesh) manta_script += liquid_alloc_mesh; @@ -1764,13 +1767,13 @@ void MANTA::exportLiquidScript(FluidModifierData *fmd) if (outflow) manta_script += fluid_alloc_outflow; - // Domain init + /* Domain init. */ manta_script += header_gridinit + liquid_init_phi; - // Time + /* Time. */ manta_script += header_time + fluid_time_stepping + fluid_adapt_time_step; - // Import + /* Import. */ manta_script += header_import + fluid_file_import + fluid_cache_helper + liquid_load_data; if (mesh) manta_script += liquid_load_mesh; @@ -1779,23 +1782,23 @@ void MANTA::exportLiquidScript(FluidModifierData *fmd) if (guiding) manta_script += fluid_load_guiding; - // Pre/Post Steps + /* Pre/Post Steps. */ manta_script += header_prepost + fluid_pre_step + fluid_post_step; - // Steps + /* Steps. */ manta_script += header_steps + liquid_adaptive_step + liquid_step; if (mesh) manta_script += liquid_step_mesh; if (drops || bubble || floater || tracer) manta_script += liquid_step_particles; - // Main + /* Main. */ manta_script += header_main + liquid_standalone + fluid_standalone; - // Fill in missing variables in script + /* Fill in missing variables in script. */ string final_script = MANTA::parseScript(manta_script, fmd); - // Write script + /* Write script. */ ofstream myfile; myfile.open(cacheDirScript); myfile << final_script; @@ -1824,12 +1827,18 @@ static PyObject *callPythonFunction(string varName, string functionName, bool is /* Be sure to initialize Python before using it. */ Py_Initialize(); - // Get pyobject that holds result value + /* Get pyobject that holds result value. */ if (!manta_main_module) { PyGILState_Release(gilstate); return nullptr; } + /* Ensure that requested variable is present in module - avoid attribute errors later on. */ + if (!PyObject_HasAttrString(manta_main_module, varName.c_str())) { + PyGILState_Release(gilstate); + return nullptr; + } + var = PyObject_GetAttrString(manta_main_module, varName.c_str()); if (!var) { PyGILState_Release(gilstate); @@ -1912,6 +1921,11 @@ static long pyObjectToLong(PyObject *inputObject) return result; } +template<class T> static T *getPointer(string pyObjectName, string pyFunctionName) +{ + return static_cast<T *>(pyObjectToPointer(callPythonFunction(pyObjectName, pyFunctionName))); +} + int MANTA::getFrame() { if (with_debug) @@ -1956,137 +1970,137 @@ void MANTA::adaptTimestep() runPythonString(pythonCommands); } -void MANTA::updatePointers() +void MANTA::updatePointers(FluidModifierData *fmd, bool flush) { if (with_debug) cout << "MANTA::updatePointers()" << endl; + FluidDomainSettings *fds = fmd->domain; + + bool liquid = !flush && (fds->type == FLUID_DOMAIN_TYPE_LIQUID); + bool smoke = !flush && (fds->type == FLUID_DOMAIN_TYPE_GAS); + bool noise = !flush && smoke && fds->flags & FLUID_DOMAIN_USE_NOISE; + bool heat = !flush && smoke && fds->active_fields & FLUID_DOMAIN_ACTIVE_HEAT; + bool colors = !flush && smoke && fds->active_fields & FLUID_DOMAIN_ACTIVE_COLORS; + bool fire = !flush && smoke && fds->active_fields & FLUID_DOMAIN_ACTIVE_FIRE; + bool obstacle = !flush && fds->active_fields & FLUID_DOMAIN_ACTIVE_OBSTACLE; + bool guiding = !flush && fds->active_fields & FLUID_DOMAIN_ACTIVE_GUIDE; + bool invel = !flush && fds->active_fields & FLUID_DOMAIN_ACTIVE_INVEL; + bool outflow = !flush && fds->active_fields & FLUID_DOMAIN_ACTIVE_OUTFLOW; + bool drops = !flush && liquid && fds->particle_type & FLUID_DOMAIN_PARTICLE_SPRAY; + bool bubble = !flush && liquid && fds->particle_type & FLUID_DOMAIN_PARTICLE_BUBBLE; + bool floater = !flush && liquid && fds->particle_type & FLUID_DOMAIN_PARTICLE_FOAM; + bool tracer = !flush && liquid && fds->particle_type & FLUID_DOMAIN_PARTICLE_TRACER; + bool parts = !flush && liquid && (drops | bubble | floater | tracer); + bool mesh = !flush && liquid && fds->flags & FLUID_DOMAIN_USE_MESH; + bool meshvel = !flush && liquid && mesh && fds->flags & FLUID_DOMAIN_USE_SPEED_VECTORS; + string func = "getDataPointer"; string funcNodes = "getNodesDataPointer"; string funcTris = "getTrisDataPointer"; string id = to_string(mCurrentID); - string solver = "s" + id; - string parts = "pp" + id; - string snd = "sp" + id; - string mesh = "sm" + id; - string mesh2 = "mesh" + id; - string noise = "sn" + id; - string solver_ext = "_" + solver; - string parts_ext = "_" + parts; - string snd_ext = "_" + snd; - string mesh_ext = "_" + mesh; - string mesh_ext2 = "_" + mesh2; - string noise_ext = "_" + noise; - - mFlags = (int *)pyObjectToPointer(callPythonFunction("flags" + solver_ext, func)); - mPhiIn = (float *)pyObjectToPointer(callPythonFunction("phiIn" + solver_ext, func)); - mPhiStaticIn = (float *)pyObjectToPointer(callPythonFunction("phiSIn" + solver_ext, func)); - mVelocityX = (float *)pyObjectToPointer(callPythonFunction("x_vel" + solver_ext, func)); - mVelocityY = (float *)pyObjectToPointer(callPythonFunction("y_vel" + solver_ext, func)); - mVelocityZ = (float *)pyObjectToPointer(callPythonFunction("z_vel" + solver_ext, func)); - mForceX = (float *)pyObjectToPointer(callPythonFunction("x_force" + solver_ext, func)); - mForceY = (float *)pyObjectToPointer(callPythonFunction("y_force" + solver_ext, func)); - mForceZ = (float *)pyObjectToPointer(callPythonFunction("z_force" + solver_ext, func)); - - if (mUsingOutflow) { - mPhiOutIn = (float *)pyObjectToPointer(callPythonFunction("phiOutIn" + solver_ext, func)); - mPhiOutStaticIn = (float *)pyObjectToPointer( - callPythonFunction("phiOutSIn" + solver_ext, func)); - } - if (mUsingObstacle) { - mPhiObsIn = (float *)pyObjectToPointer(callPythonFunction("phiObsIn" + solver_ext, func)); - mPhiObsStaticIn = (float *)pyObjectToPointer( - callPythonFunction("phiObsSIn" + solver_ext, func)); - mObVelocityX = (float *)pyObjectToPointer(callPythonFunction("x_obvel" + solver_ext, func)); - mObVelocityY = (float *)pyObjectToPointer(callPythonFunction("y_obvel" + solver_ext, func)); - mObVelocityZ = (float *)pyObjectToPointer(callPythonFunction("z_obvel" + solver_ext, func)); - mNumObstacle = (float *)pyObjectToPointer(callPythonFunction("numObs" + solver_ext, func)); - } - if (mUsingGuiding) { - mPhiGuideIn = (float *)pyObjectToPointer(callPythonFunction("phiGuideIn" + solver_ext, func)); - mGuideVelocityX = (float *)pyObjectToPointer( - callPythonFunction("x_guidevel" + solver_ext, func)); - mGuideVelocityY = (float *)pyObjectToPointer( - callPythonFunction("y_guidevel" + solver_ext, func)); - mGuideVelocityZ = (float *)pyObjectToPointer( - callPythonFunction("z_guidevel" + solver_ext, func)); - mNumGuide = (float *)pyObjectToPointer(callPythonFunction("numGuides" + solver_ext, func)); - } - if (mUsingInvel) { - mInVelocityX = (float *)pyObjectToPointer(callPythonFunction("x_invel" + solver_ext, func)); - mInVelocityY = (float *)pyObjectToPointer(callPythonFunction("y_invel" + solver_ext, func)); - mInVelocityZ = (float *)pyObjectToPointer(callPythonFunction("z_invel" + solver_ext, func)); - } - if (mUsingSmoke) { - mDensity = (float *)pyObjectToPointer(callPythonFunction("density" + solver_ext, func)); - mDensityIn = (float *)pyObjectToPointer(callPythonFunction("densityIn" + solver_ext, func)); - mShadow = (float *)pyObjectToPointer(callPythonFunction("shadow" + solver_ext, func)); - mEmissionIn = (float *)pyObjectToPointer(callPythonFunction("emissionIn" + solver_ext, func)); - } - if (mUsingSmoke && mUsingHeat) { - mHeat = (float *)pyObjectToPointer(callPythonFunction("heat" + solver_ext, func)); - mHeatIn = (float *)pyObjectToPointer(callPythonFunction("heatIn" + solver_ext, func)); - } - if (mUsingSmoke && mUsingFire) { - mFlame = (float *)pyObjectToPointer(callPythonFunction("flame" + solver_ext, func)); - mFuel = (float *)pyObjectToPointer(callPythonFunction("fuel" + solver_ext, func)); - mReact = (float *)pyObjectToPointer(callPythonFunction("react" + solver_ext, func)); - mFuelIn = (float *)pyObjectToPointer(callPythonFunction("fuelIn" + solver_ext, func)); - mReactIn = (float *)pyObjectToPointer(callPythonFunction("reactIn" + solver_ext, func)); - } - if (mUsingSmoke && mUsingColors) { - mColorR = (float *)pyObjectToPointer(callPythonFunction("color_r" + solver_ext, func)); - mColorG = (float *)pyObjectToPointer(callPythonFunction("color_g" + solver_ext, func)); - mColorB = (float *)pyObjectToPointer(callPythonFunction("color_b" + solver_ext, func)); - mColorRIn = (float *)pyObjectToPointer(callPythonFunction("color_r_in" + solver_ext, func)); - mColorGIn = (float *)pyObjectToPointer(callPythonFunction("color_g_in" + solver_ext, func)); - mColorBIn = (float *)pyObjectToPointer(callPythonFunction("color_b_in" + solver_ext, func)); - } - if (mUsingSmoke && mUsingNoise) { - mDensityHigh = (float *)pyObjectToPointer(callPythonFunction("density" + noise_ext, func)); - mTextureU = (float *)pyObjectToPointer(callPythonFunction("texture_u" + solver_ext, func)); - mTextureV = (float *)pyObjectToPointer(callPythonFunction("texture_v" + solver_ext, func)); - mTextureW = (float *)pyObjectToPointer(callPythonFunction("texture_w" + solver_ext, func)); - mTextureU2 = (float *)pyObjectToPointer(callPythonFunction("texture_u2" + solver_ext, func)); - mTextureV2 = (float *)pyObjectToPointer(callPythonFunction("texture_v2" + solver_ext, func)); - mTextureW2 = (float *)pyObjectToPointer(callPythonFunction("texture_w2" + solver_ext, func)); - } - if (mUsingSmoke && mUsingNoise && mUsingFire) { - mFlameHigh = (float *)pyObjectToPointer(callPythonFunction("flame" + noise_ext, func)); - mFuelHigh = (float *)pyObjectToPointer(callPythonFunction("fuel" + noise_ext, func)); - mReactHigh = (float *)pyObjectToPointer(callPythonFunction("react" + noise_ext, func)); - } - if (mUsingSmoke && mUsingNoise && mUsingColors) { - mColorRHigh = (float *)pyObjectToPointer(callPythonFunction("color_r" + noise_ext, func)); - mColorGHigh = (float *)pyObjectToPointer(callPythonFunction("color_g" + noise_ext, func)); - mColorBHigh = (float *)pyObjectToPointer(callPythonFunction("color_b" + noise_ext, func)); - } - if (mUsingLiquid) { - mPhi = (float *)pyObjectToPointer(callPythonFunction("phi" + solver_ext, func)); - mFlipParticleData = (vector<pData> *)pyObjectToPointer( - callPythonFunction("pp" + solver_ext, func)); - mFlipParticleVelocity = (vector<pVel> *)pyObjectToPointer( - callPythonFunction("pVel" + parts_ext, func)); - } - if (mUsingLiquid && mUsingMesh) { - mMeshNodes = (vector<Node> *)pyObjectToPointer( - callPythonFunction("mesh" + mesh_ext, funcNodes)); - mMeshTriangles = (vector<Triangle> *)pyObjectToPointer( - callPythonFunction("mesh" + mesh_ext, funcTris)); - } - if (mUsingLiquid && mUsingMVel) { - mMeshVelocities = (vector<pVel> *)pyObjectToPointer( - callPythonFunction("mVel" + mesh_ext2, func)); - } - if (mUsingLiquid && (mUsingDrops | mUsingBubbles | mUsingFloats | mUsingTracers)) { - mSndParticleData = (vector<pData> *)pyObjectToPointer( - callPythonFunction("ppSnd" + snd_ext, func)); - mSndParticleVelocity = (vector<pVel> *)pyObjectToPointer( - callPythonFunction("pVelSnd" + parts_ext, func)); - mSndParticleLife = (vector<float> *)pyObjectToPointer( - callPythonFunction("pLifeSnd" + parts_ext, func)); - } + string s_ext = "_s" + id; + string pp_ext = "_pp" + id; + string snd_ext = "_sp" + id; + string sm_ext = "_sm" + id; + string mesh_ext = "_mesh" + id; + string sn_ext = "_sn" + id; + + mFlags = (smoke || liquid) ? getPointer<int>("flags" + s_ext, func) : nullptr; + mPhiIn = (smoke || liquid) ? getPointer<float>("phiIn" + s_ext, func) : nullptr; + mPhiStaticIn = (smoke || liquid) ? getPointer<float>("phiSIn" + s_ext, func) : nullptr; + mVelocityX = (smoke || liquid) ? getPointer<float>("x_vel" + s_ext, func) : nullptr; + mVelocityY = (smoke || liquid) ? getPointer<float>("y_vel" + s_ext, func) : nullptr; + mVelocityZ = (smoke || liquid) ? getPointer<float>("z_vel" + s_ext, func) : nullptr; + mForceX = (smoke || liquid) ? getPointer<float>("x_force" + s_ext, func) : nullptr; + mForceY = (smoke || liquid) ? getPointer<float>("y_force" + s_ext, func) : nullptr; + mForceZ = (smoke || liquid) ? getPointer<float>("z_force" + s_ext, func) : nullptr; + + /* Outflow. */ + mPhiOutIn = (outflow) ? getPointer<float>("phiOutIn" + s_ext, func) : nullptr; + mPhiOutStaticIn = (outflow) ? getPointer<float>("phiOutSIn" + s_ext, func) : nullptr; + + /* Obstacles. */ + mPhiObsIn = (obstacle) ? getPointer<float>("phiObsIn" + s_ext, func) : nullptr; + mPhiObsStaticIn = (obstacle) ? getPointer<float>("phiObsSIn" + s_ext, func) : nullptr; + mObVelocityX = (obstacle) ? getPointer<float>("x_obvel" + s_ext, func) : nullptr; + mObVelocityY = (obstacle) ? getPointer<float>("y_obvel" + s_ext, func) : nullptr; + mObVelocityZ = (obstacle) ? getPointer<float>("z_obvel" + s_ext, func) : nullptr; + mNumObstacle = (obstacle) ? getPointer<float>("numObs" + s_ext, func) : nullptr; + + /* Guiding. */ + mPhiGuideIn = (guiding) ? getPointer<float>("phiGuideIn" + s_ext, func) : nullptr; + mGuideVelocityX = (guiding) ? getPointer<float>("x_guidevel" + s_ext, func) : nullptr; + mGuideVelocityY = (guiding) ? getPointer<float>("y_guidevel" + s_ext, func) : nullptr; + mGuideVelocityZ = (guiding) ? getPointer<float>("z_guidevel" + s_ext, func) : nullptr; + mNumGuide = (guiding) ? getPointer<float>("numGuides" + s_ext, func) : nullptr; + + /* Initial velocities. */ + mInVelocityX = (invel) ? getPointer<float>("x_invel" + s_ext, func) : nullptr; + mInVelocityY = (invel) ? getPointer<float>("y_invel" + s_ext, func) : nullptr; + mInVelocityZ = (invel) ? getPointer<float>("z_invel" + s_ext, func) : nullptr; + + /* Smoke. */ + mDensity = (smoke) ? getPointer<float>("density" + s_ext, func) : nullptr; + mDensityIn = (smoke) ? getPointer<float>("densityIn" + s_ext, func) : nullptr; + mShadow = (smoke) ? getPointer<float>("shadow" + s_ext, func) : nullptr; + mEmissionIn = (smoke) ? getPointer<float>("emissionIn" + s_ext, func) : nullptr; + + /* Heat. */ + mHeat = (heat) ? getPointer<float>("heat" + s_ext, func) : nullptr; + mHeatIn = (heat) ? getPointer<float>("heatIn" + s_ext, func) : nullptr; + + /* Fire. */ + mFlame = (fire) ? getPointer<float>("flame" + s_ext, func) : nullptr; + mFuel = (fire) ? getPointer<float>("fuel" + s_ext, func) : nullptr; + mReact = (fire) ? getPointer<float>("react" + s_ext, func) : nullptr; + mFuelIn = (fire) ? getPointer<float>("fuelIn" + s_ext, func) : nullptr; + mReactIn = (fire) ? getPointer<float>("reactIn" + s_ext, func) : nullptr; + + /* Colors. */ + mColorR = (colors) ? getPointer<float>("color_r" + s_ext, func) : nullptr; + mColorG = (colors) ? getPointer<float>("color_g" + s_ext, func) : nullptr; + mColorB = (colors) ? getPointer<float>("color_b" + s_ext, func) : nullptr; + mColorRIn = (colors) ? getPointer<float>("color_r_in" + s_ext, func) : nullptr; + mColorGIn = (colors) ? getPointer<float>("color_g_in" + s_ext, func) : nullptr; + mColorBIn = (colors) ? getPointer<float>("color_b_in" + s_ext, func) : nullptr; + + /* Noise. */ + mDensityHigh = (noise) ? getPointer<float>("density" + sn_ext, func) : nullptr; + mTextureU = (noise) ? getPointer<float>("texture_u" + s_ext, func) : nullptr; + mTextureV = (noise) ? getPointer<float>("texture_v" + s_ext, func) : nullptr; + mTextureW = (noise) ? getPointer<float>("texture_w" + s_ext, func) : nullptr; + mTextureU2 = (noise) ? getPointer<float>("texture_u2" + s_ext, func) : nullptr; + mTextureV2 = (noise) ? getPointer<float>("texture_v2" + s_ext, func) : nullptr; + mTextureW2 = (noise) ? getPointer<float>("texture_w2" + s_ext, func) : nullptr; + + /* Fire with noise. */ + mFlameHigh = (noise && fire) ? getPointer<float>("flame" + sn_ext, func) : nullptr; + mFuelHigh = (noise && fire) ? getPointer<float>("fuel" + sn_ext, func) : nullptr; + mReactHigh = (noise && fire) ? getPointer<float>("react" + sn_ext, func) : nullptr; + + /* Colors with noise. */ + mColorRHigh = (noise && colors) ? getPointer<float>("color_r" + sn_ext, func) : nullptr; + mColorGHigh = (noise && colors) ? getPointer<float>("color_g" + sn_ext, func) : nullptr; + mColorBHigh = (noise && colors) ? getPointer<float>("color_b" + sn_ext, func) : nullptr; + + /* Liquid. */ + mPhi = (liquid) ? getPointer<float>("phi" + s_ext, func) : nullptr; + mFlipParticleData = (liquid) ? getPointer<vector<pData>>("pp" + s_ext, func) : nullptr; + mFlipParticleVelocity = (liquid) ? getPointer<vector<pVel>>("pVel" + pp_ext, func) : nullptr; + + /* Mesh. */ + mMeshNodes = (mesh) ? getPointer<vector<Node>>("mesh" + sm_ext, funcNodes) : nullptr; + mMeshTriangles = (mesh) ? getPointer<vector<Triangle>>("mesh" + sm_ext, funcTris) : nullptr; + + /* Mesh velocities. */ + mMeshVelocities = (meshvel) ? getPointer<vector<pVel>>("mVel" + mesh_ext, func) : nullptr; + + /* Secondary particles. */ + mParticleData = (parts) ? getPointer<vector<pData>>("ppSnd" + snd_ext, func) : nullptr; + mParticleVelocity = (parts) ? getPointer<vector<pVel>>("pVelSnd" + pp_ext, func) : nullptr; + mParticleLife = (parts) ? getPointer<vector<float>>("pLifeSnd" + pp_ext, func) : nullptr; mFlipFromFile = false; mMeshFromFile = false; diff --git a/intern/mantaflow/intern/MANTA_main.h b/intern/mantaflow/intern/MANTA_main.h index dae2aea4e08..5fd94ca01bc 100644 --- a/intern/mantaflow/intern/MANTA_main.h +++ b/intern/mantaflow/intern/MANTA_main.h @@ -41,7 +41,7 @@ struct MANTA { MANTA(){}; virtual ~MANTA(); - // Mirroring Mantaflow structures for particle data (pVel also used for mesh vert vels) + /* Mirroring Mantaflow structures for particle data (pVel also used for mesh vert vels). */ typedef struct PData { float pos[3]; int flag; @@ -50,7 +50,7 @@ struct MANTA { float pos[3]; } pVel; - // Mirroring Mantaflow structures for meshes + /* Mirroring Mantaflow structures for meshes. */ typedef struct Node { int flags; float pos[3], normal[3]; @@ -60,36 +60,33 @@ struct MANTA { int flags; } Triangle; - // Manta step, handling everything - void step(struct FluidModifierData *fmd, int startFrame); - - // Grid initialization functions - void initHeat(struct FluidModifierData *fmd = NULL); - void initFire(struct FluidModifierData *fmd = NULL); - void initColors(struct FluidModifierData *fmd = NULL); - void initFireHigh(struct FluidModifierData *fmd = NULL); - void initColorsHigh(struct FluidModifierData *fmd = NULL); - void initLiquid(FluidModifierData *fmd = NULL); - void initLiquidMesh(FluidModifierData *fmd = NULL); - void initObstacle(FluidModifierData *fmd = NULL); - void initCurvature(FluidModifierData *fmd = NULL); - void initGuiding(FluidModifierData *fmd = NULL); - void initFractions(FluidModifierData *fmd = NULL); - void initInVelocity(FluidModifierData *fmd = NULL); - void initOutflow(FluidModifierData *fmd = NULL); - void initSndParts(FluidModifierData *fmd = NULL); - void initLiquidSndParts(FluidModifierData *fmd = NULL); - - // Pointer transfer: Mantaflow -> Blender - void updatePointers(); - - // Write cache + /* Grid initialization functions. */ + bool initHeat(struct FluidModifierData *fmd = nullptr); + bool initFire(struct FluidModifierData *fmd = nullptr); + bool initColors(struct FluidModifierData *fmd = nullptr); + bool initFireHigh(struct FluidModifierData *fmd = nullptr); + bool initColorsHigh(struct FluidModifierData *fmd = nullptr); + bool initLiquid(FluidModifierData *fmd = nullptr); + bool initLiquidMesh(FluidModifierData *fmd = nullptr); + bool initObstacle(FluidModifierData *fmd = nullptr); + bool initCurvature(FluidModifierData *fmd = nullptr); + bool initGuiding(FluidModifierData *fmd = nullptr); + bool initFractions(FluidModifierData *fmd = nullptr); + bool initInVelocity(FluidModifierData *fmd = nullptr); + bool initOutflow(FluidModifierData *fmd = nullptr); + bool initSndParts(FluidModifierData *fmd = nullptr); + bool initLiquidSndParts(FluidModifierData *fmd = nullptr); + + /* Pointer transfer: Mantaflow -> Blender. Use flush to reset all pointers to nullptr. */ + void updatePointers(FluidModifierData *fmd, bool flush = false); + + /* Write cache. */ bool writeConfiguration(FluidModifierData *fmd, int framenr); bool writeData(FluidModifierData *fmd, int framenr); bool writeNoise(FluidModifierData *fmd, int framenr); - // write calls for mesh and particles were left in bake calls for now + /* Write calls for mesh and particles were left in bake calls for now. */ - // Read cache (via Manta save/load) + /* Read cache (via Python). */ bool readConfiguration(FluidModifierData *fmd, int framenr); bool readData(FluidModifierData *fmd, int framenr, bool resumable); bool readNoise(FluidModifierData *fmd, int framenr, bool resumable); @@ -97,26 +94,21 @@ struct MANTA { bool readParticles(FluidModifierData *fmd, int framenr, bool resumable); bool readGuiding(FluidModifierData *fmd, int framenr, bool sourceDomain); - // Read cache (via file read functions in MANTA - e.g. read .bobj.gz meshes, .uni particles) - bool updateMeshStructures(FluidModifierData *fmd, int framenr); - bool updateFlipStructures(FluidModifierData *fmd, int framenr); - bool updateParticleStructures(FluidModifierData *fmd, int framenr); - bool updateSmokeStructures(FluidModifierData *fmd, int framenr); - bool updateNoiseStructures(FluidModifierData *fmd, int framenr); + /* Propagate variable changes from RNA to Python. */ bool updateVariables(FluidModifierData *fmd); - // Bake cache + /* Bake cache. */ bool bakeData(FluidModifierData *fmd, int framenr); bool bakeNoise(FluidModifierData *fmd, int framenr); bool bakeMesh(FluidModifierData *fmd, int framenr); bool bakeParticles(FluidModifierData *fmd, int framenr); bool bakeGuiding(FluidModifierData *fmd, int framenr); - // IO for Mantaflow scene script + /* IO for Mantaflow scene script. */ void exportSmokeScript(struct FluidModifierData *fmd); void exportLiquidScript(struct FluidModifierData *fmd); - // Check cache status by frame + /* Check cache status by frame. */ bool hasConfig(FluidModifierData *fmd, int framenr); bool hasData(FluidModifierData *fmd, int framenr); bool hasNoise(FluidModifierData *fmd, int framenr); @@ -193,7 +185,7 @@ struct MANTA { return mUpresParticle; } - // Smoke getters + /* Smoke getters. */ inline float *getDensity() { return mDensity; @@ -422,9 +414,9 @@ struct MANTA { } static atomic<int> solverID; - static int with_debug; // on or off (1 or 0), also sets manta debug level + static int with_debug; /* On or off (1 or 0), also sets manta debug level. */ - // Mesh getters + /* Mesh getters. */ inline int getNumVertices() { return (mMeshNodes && !mMeshNodes->empty()) ? mMeshNodes->size() : 0; @@ -563,9 +555,9 @@ struct MANTA { inline int getSndParticleFlagAt(int i) { assert(i >= 0); - if (mSndParticleData && !mSndParticleData->empty()) { - assert(i < mSndParticleData->size()); - return (*mSndParticleData)[i].flag; + if (mParticleData && !mParticleData->empty()) { + assert(i < mParticleData->size()); + return (*mParticleData)[i].flag; } return 0; } @@ -601,27 +593,27 @@ struct MANTA { inline float getSndParticlePositionXAt(int i) { assert(i >= 0); - if (mSndParticleData && !mSndParticleData->empty()) { - assert(i < mSndParticleData->size()); - return (*mSndParticleData)[i].pos[0]; + if (mParticleData && !mParticleData->empty()) { + assert(i < mParticleData->size()); + return (*mParticleData)[i].pos[0]; } return 0.0f; } inline float getSndParticlePositionYAt(int i) { assert(i >= 0); - if (mSndParticleData && !mSndParticleData->empty()) { - assert(i < mSndParticleData->size()); - return (*mSndParticleData)[i].pos[1]; + if (mParticleData && !mParticleData->empty()) { + assert(i < mParticleData->size()); + return (*mParticleData)[i].pos[1]; } return 0.0f; } inline float getSndParticlePositionZAt(int i) { assert(i >= 0); - if (mSndParticleData && !mSndParticleData->empty()) { - assert(i < mSndParticleData->size()); - return (*mSndParticleData)[i].pos[2]; + if (mParticleData && !mParticleData->empty()) { + assert(i < mParticleData->size()); + return (*mParticleData)[i].pos[2]; } return 0.0f; } @@ -657,27 +649,27 @@ struct MANTA { inline float getSndParticleVelocityXAt(int i) { assert(i >= 0); - if (mSndParticleVelocity && !mSndParticleVelocity->empty()) { - assert(i < mSndParticleVelocity->size()); - return (*mSndParticleVelocity)[i].pos[0]; + if (mParticleVelocity && !mParticleVelocity->empty()) { + assert(i < mParticleVelocity->size()); + return (*mParticleVelocity)[i].pos[0]; } return 0.0f; } inline float getSndParticleVelocityYAt(int i) { assert(i >= 0); - if (mSndParticleVelocity && !mSndParticleVelocity->empty()) { - assert(i < mSndParticleVelocity->size()); - return (*mSndParticleVelocity)[i].pos[1]; + if (mParticleVelocity && !mParticleVelocity->empty()) { + assert(i < mParticleVelocity->size()); + return (*mParticleVelocity)[i].pos[1]; } return 0.0f; } inline float getSndParticleVelocityZAt(int i) { assert(i >= 0); - if (mSndParticleVelocity && !mSndParticleVelocity->empty()) { - assert(i < mSndParticleVelocity->size()); - return (*mSndParticleVelocity)[i].pos[2]; + if (mParticleVelocity && !mParticleVelocity->empty()) { + assert(i < mParticleVelocity->size()); + return (*mParticleVelocity)[i].pos[2]; } return 0.0f; } @@ -686,30 +678,28 @@ struct MANTA { { return (mFlipParticleData && !mFlipParticleData->empty()) ? (float *)&mFlipParticleData->front() : - NULL; + nullptr; } inline float *getSndParticleData() { - return (mSndParticleData && !mSndParticleData->empty()) ? (float *)&mSndParticleData->front() : - NULL; + return (mParticleData && !mParticleData->empty()) ? (float *)&mParticleData->front() : nullptr; } inline float *getFlipParticleVelocity() { return (mFlipParticleVelocity && !mFlipParticleVelocity->empty()) ? (float *)&mFlipParticleVelocity->front() : - NULL; + nullptr; } inline float *getSndParticleVelocity() { - return (mSndParticleVelocity && !mSndParticleVelocity->empty()) ? - (float *)&mSndParticleVelocity->front() : - NULL; + return (mParticleVelocity && !mParticleVelocity->empty()) ? + (float *)&mParticleVelocity->front() : + nullptr; } inline float *getSndParticleLife() { - return (mSndParticleLife && !mSndParticleLife->empty()) ? (float *)&mSndParticleLife->front() : - NULL; + return (mParticleLife && !mParticleLife->empty()) ? (float *)&mParticleLife->front() : nullptr; } inline int getNumFlipParticles() @@ -718,7 +708,7 @@ struct MANTA { } inline int getNumSndParticles() { - return (mSndParticleData && !mSndParticleData->empty()) ? mSndParticleData->size() : 0; + return (mParticleData && !mParticleData->empty()) ? mParticleData->size() : 0; } inline bool usingFlipFromFile() @@ -734,7 +724,7 @@ struct MANTA { return mParticlesFromFile; } - // Direct access to solver time attributes + /* Direct access to solver time attributes. */ int getFrame(); float getTimestep(); void adaptTimestep(); @@ -742,7 +732,7 @@ struct MANTA { bool needsRealloc(FluidModifierData *fmd); private: - // simulation constants + /* Simulation constants. */ size_t mTotalCells; size_t mTotalCellsHigh; size_t mTotalCellsMesh; @@ -750,6 +740,7 @@ struct MANTA { unordered_map<string, string> mRNAMap; + /* The ID of the solver objects will be incremented for every new object. */ int mCurrentID; bool mUsingHeat; @@ -796,10 +787,7 @@ struct MANTA { int mUpresMesh; int mUpresParticle; - float mTempAmb; /* ambient temperature */ - float mConstantScaling; - - // Fluid grids + /* Fluid grids. */ float *mVelocityX; float *mVelocityY; float *mVelocityZ; @@ -819,7 +807,7 @@ struct MANTA { float *mNumObstacle; float *mNumGuide; - // Smoke grids + /* Smoke grids. */ float *mDensity; float *mHeat; float *mFlame; @@ -851,7 +839,7 @@ struct MANTA { float *mTextureV2; float *mTextureW2; - // Liquid grids + /* Liquid grids. */ float *mPhiIn; float *mPhiStaticIn; float *mPhiObsIn; @@ -861,31 +849,31 @@ struct MANTA { float *mPhiOutStaticIn; float *mPhi; - // Mesh fields + /* Mesh fields. */ vector<Node> *mMeshNodes; vector<Triangle> *mMeshTriangles; vector<pVel> *mMeshVelocities; - // Particle fields + /* Particle fields. */ vector<pData> *mFlipParticleData; vector<pVel> *mFlipParticleVelocity; - vector<pData> *mSndParticleData; - vector<pVel> *mSndParticleVelocity; - vector<float> *mSndParticleLife; + vector<pData> *mParticleData; + vector<pVel> *mParticleVelocity; + vector<float> *mParticleLife; - void initializeRNAMap(struct FluidModifierData *fmd = NULL); - void initDomain(struct FluidModifierData *fmd = NULL); - void initNoise(struct FluidModifierData *fmd = NULL); - void initMesh(struct FluidModifierData *fmd = NULL); - void initSmoke(struct FluidModifierData *fmd = NULL); - void initSmokeNoise(struct FluidModifierData *fmd = NULL); + void initializeRNAMap(struct FluidModifierData *doRnaRefresh = nullptr); + bool initDomain(struct FluidModifierData *doRnaRefresh = nullptr); + bool initNoise(struct FluidModifierData *doRnaRefresh = nullptr); + bool initMesh(struct FluidModifierData *doRnaRefresh = nullptr); + bool initSmoke(struct FluidModifierData *doRnaRefresh = nullptr); + bool initSmokeNoise(struct FluidModifierData *doRnaRefresh = nullptr); void initializeMantaflow(); void terminateMantaflow(); bool runPythonString(vector<string> commands); string getRealValue(const string &varName); string parseLine(const string &line); - string parseScript(const string &setup_string, FluidModifierData *fmd = NULL); + string parseScript(const string &setup_string, FluidModifierData *fmd = nullptr); string getDirectory(struct FluidModifierData *fmd, string subdirectory); string getFile(struct FluidModifierData *fmd, string subdirectory, diff --git a/intern/mantaflow/intern/manta_fluid_API.cpp b/intern/mantaflow/intern/manta_fluid_API.cpp index 60546bc1183..530dbd49b7c 100644 --- a/intern/mantaflow/intern/manta_fluid_API.cpp +++ b/intern/mantaflow/intern/manta_fluid_API.cpp @@ -37,33 +37,29 @@ void manta_free(MANTA *fluid) fluid = nullptr; } -void manta_ensure_obstacle(MANTA *fluid, struct FluidModifierData *fmd) +int manta_ensure_obstacle(MANTA *fluid, struct FluidModifierData *fmd) { - if (!fluid) - return; - fluid->initObstacle(fmd); - fluid->updatePointers(); + if (!fluid || !fmd) + return 0; + return fluid->initObstacle(fmd); } -void manta_ensure_guiding(MANTA *fluid, struct FluidModifierData *fmd) +int manta_ensure_guiding(MANTA *fluid, struct FluidModifierData *fmd) { - if (!fluid) - return; - fluid->initGuiding(fmd); - fluid->updatePointers(); + if (!fluid || !fmd) + return 0; + return fluid->initGuiding(fmd); } -void manta_ensure_invelocity(MANTA *fluid, struct FluidModifierData *fmd) +int manta_ensure_invelocity(MANTA *fluid, struct FluidModifierData *fmd) { - if (!fluid) - return; - fluid->initInVelocity(fmd); - fluid->updatePointers(); + if (!fluid || !fmd) + return 0; + return fluid->initInVelocity(fmd); } -void manta_ensure_outflow(MANTA *fluid, struct FluidModifierData *fmd) +int manta_ensure_outflow(MANTA *fluid, struct FluidModifierData *fmd) { - if (!fluid) - return; - fluid->initOutflow(fmd); - fluid->updatePointers(); + if (!fluid || !fmd) + return 0; + return fluid->initOutflow(fmd); } int manta_write_config(MANTA *fluid, FluidModifierData *fmd, int framenr) @@ -229,11 +225,18 @@ void manta_adapt_timestep(MANTA *fluid) bool manta_needs_realloc(MANTA *fluid, FluidModifierData *fmd) { - if (!fluid) + if (!fluid || !fmd) return false; return fluid->needsRealloc(fmd); } +void manta_update_pointers(struct MANTA *fluid, struct FluidModifierData *fmd, bool flush) +{ + if (!fluid || !fmd) + return; + fluid->updatePointers(fmd, flush); +} + /* Fluid accessors */ size_t manta_get_index(int x, int max_x, int y, int max_y, int z /*, int max_z */) { @@ -441,34 +444,35 @@ void manta_noise_get_rgba_fixed_color(MANTA *smoke, float color[3], float *data, get_rgba_fixed_color(color, smoke->getTotalCellsHigh(), data, sequential); } -void manta_smoke_ensure_heat(MANTA *smoke, struct FluidModifierData *fmd) +int manta_smoke_ensure_heat(MANTA *smoke, struct FluidModifierData *fmd) { - if (smoke) { - smoke->initHeat(fmd); - smoke->updatePointers(); - } + if (!smoke || !fmd) + return 0; + return smoke->initHeat(fmd); } -void manta_smoke_ensure_fire(MANTA *smoke, struct FluidModifierData *fmd) +int manta_smoke_ensure_fire(MANTA *smoke, struct FluidModifierData *fmd) { - if (smoke) { - smoke->initFire(fmd); - if (smoke->usingNoise()) { - smoke->initFireHigh(fmd); - } - smoke->updatePointers(); + if (!smoke || !fmd) + return 0; + + int result = smoke->initFire(fmd); + if (smoke->usingNoise()) { + result &= smoke->initFireHigh(fmd); } + return result; } -void manta_smoke_ensure_colors(MANTA *smoke, struct FluidModifierData *fmd) +int manta_smoke_ensure_colors(MANTA *smoke, struct FluidModifierData *fmd) { - if (smoke) { - smoke->initColors(fmd); - if (smoke->usingNoise()) { - smoke->initColorsHigh(fmd); - } - smoke->updatePointers(); + if (!smoke || !fmd) + return 0; + + int result = smoke->initColors(fmd); + if (smoke->usingNoise()) { + result &= smoke->initColorsHigh(fmd); } + return result; } /* Smoke accessors */ @@ -645,12 +649,11 @@ void manta_liquid_export_script(MANTA *liquid, FluidModifierData *fmd) liquid->exportLiquidScript(fmd); } -void manta_liquid_ensure_sndparts(MANTA *liquid, struct FluidModifierData *fmd) +int manta_liquid_ensure_sndparts(MANTA *liquid, struct FluidModifierData *fmd) { - if (liquid) { - liquid->initLiquidSndParts(fmd); - liquid->updatePointers(); - } + if (!liquid || !fmd) + return 0; + return liquid->initLiquidSndParts(fmd); } /* Liquid accessors */ diff --git a/intern/mantaflow/intern/strings/fluid_script.h b/intern/mantaflow/intern/strings/fluid_script.h index 83ad201fcbd..d669e8cf3b4 100644 --- a/intern/mantaflow/intern/strings/fluid_script.h +++ b/intern/mantaflow/intern/strings/fluid_script.h @@ -418,19 +418,6 @@ const std::string fluid_post_step = "\n\ def fluid_post_step_$ID$():\n\ mantaMsg('Fluid post step')\n\ - forces_s$ID$.clear()\n\ - x_force_s$ID$.clear()\n\ - y_force_s$ID$.clear()\n\ - z_force_s$ID$.clear()\n\ - \n\ - if using_guiding_s$ID$:\n\ - weightGuide_s$ID$.clear()\n\ - if using_invel_s$ID$:\n\ - x_invel_s$ID$.clear()\n\ - y_invel_s$ID$.clear()\n\ - z_invel_s$ID$.clear()\n\ - invel_s$ID$.clear()\n\ - invelC_s$ID$.clear()\n\ \n\ # Copy vel grid to reals grids (which Blender internal will in turn use for vel access)\n\ copyVec3ToReal(source=vel_s$ID$, targetX=x_vel_s$ID$, targetY=y_vel_s$ID$, targetZ=z_vel_s$ID$)\n"; |