[Bf-blender-cvs] [d3c6768daab] fluid-mantaflow: added id member variable and cleaned up manta init function
Sebastián Barschkis
noreply at git.blender.org
Sun Mar 26 20:41:23 CEST 2017
Commit: d3c6768daaba19e585e7a309323887bcfaae506f
Author: Sebastián Barschkis
Date: Fri Mar 17 13:25:41 2017 +0200
Branches: fluid-mantaflow
https://developer.blender.org/rBd3c6768daaba19e585e7a309323887bcfaae506f
added id member variable and cleaned up manta init function
===================================================================
M intern/mantaflow/intern/FLUID.cpp
M intern/mantaflow/intern/FLUID.h
===================================================================
diff --git a/intern/mantaflow/intern/FLUID.cpp b/intern/mantaflow/intern/FLUID.cpp
index 4deca56cc2f..8a5c0dfe201 100644
--- a/intern/mantaflow/intern/FLUID.cpp
+++ b/intern/mantaflow/intern/FLUID.cpp
@@ -47,11 +47,12 @@
#include "DNA_modifier_types.h"
#include "DNA_smoke_types.h"
-bool FLUID::mantaInitialized = false;
+std::atomic<bool> FLUID::mantaInitialized(false);
+std::atomic<int> FLUID::solverID(0);
-FLUID::FLUID(int *res, SmokeModifierData *smd)
+FLUID::FLUID(int *res, SmokeModifierData *smd) : mCurrentID(++solverID)
{
- std::cout << "FLUID" << std::endl;
+ std::cout << "FLUID: " << mCurrentID << std::endl;
smd->domain->fluid = this;
smd->domain->manta_solver_res = 3; // Why do we need to set this explicitly? When not set, fluidsolver throws exception (occurs when loading a new .blend file)
@@ -123,8 +124,8 @@ FLUID::FLUID(int *res, SmokeModifierData *smd)
// Only start Mantaflow once. No need to start whenever new FLUID objected is allocated
if (!mantaInitialized)
- startMantaflow();
-
+ initializeMantaflow();
+
// Initialize Mantaflow variables in Python
// Liquid
if (mUsingLiquid) {
@@ -368,7 +369,7 @@ void FLUID::step(int startFrame)
// Run manta step and handover current frame number
mCommands.clear();
std::ostringstream manta_step;
- manta_step << "manta_step(" << startFrame << ")";
+ manta_step << "manta_step_" << mCurrentID << "(" << startFrame << ")";
mCommands.push_back(manta_step.str());
runPythonString(mCommands);
@@ -376,7 +377,7 @@ void FLUID::step(int startFrame)
FLUID::~FLUID()
{
- std::cout << "~FLUID()" << std::endl;
+ std::cout << "FLUID: " << mCurrentID << std::endl;
// Destruction in Python
std::string tmpString = "";
@@ -489,10 +490,10 @@ void FLUID::runPythonString(std::vector<std::string> commands)
PyGILState_Release(gilstate);
}
-void FLUID::startMantaflow()
+void FLUID::initializeMantaflow()
{
- std::cout << "Starting mantaflow" << std::endl;
- std::string filename = "manta_scene.py";
+ std::cout << "Initializing Mantaflow" << std::endl;
+ std::string filename = "manta_scene_" + std::to_string(mCurrentID) + ".py";
std::vector<std::string> fill = std::vector<std::string>();
// Initialize extension classes and wrappers
@@ -503,6 +504,16 @@ void FLUID::startMantaflow()
mantaInitialized = true;
}
+void FLUID::terminateMantaflow()
+{
+ std::cout << "Terminating Mantaflow" << std::endl;
+
+ PyGILState_STATE gilstate = PyGILState_Ensure();
+ Pb::finalize(); // Namespace from Mantaflow (registry)
+ PyGILState_Release(gilstate);
+ mantaInitialized = false;
+}
+
std::string FLUID::getRealValue(const std::string& varName, SmokeModifierData *smd)
{
std::ostringstream ss;
@@ -615,8 +626,10 @@ std::string FLUID::getRealValue(const std::string& varName, SmokeModifierData *
else if (smd->domain->preconditioner == MOD_SMOKE_PC_MIC) ss << "PcMIC";
else if (smd->domain->preconditioner == MOD_SMOKE_PC_MG_DYNAMIC) ss << "PcMGDynamic";
else if (smd->domain->preconditioner == MOD_SMOKE_PC_MG_STATIC) ss << "PcMGStatic";
- } else
- std::cout << "ERROR: Unknown option:" << varName << std::endl;
+ } else if (varName == "ID")
+ ss << mCurrentID;
+ else
+ std::cout << "ERROR: Unknown option: " << varName << std::endl;
return ss.str();
}
diff --git a/intern/mantaflow/intern/FLUID.h b/intern/mantaflow/intern/FLUID.h
index a8f6304478a..76452fa11c2 100644
--- a/intern/mantaflow/intern/FLUID.h
+++ b/intern/mantaflow/intern/FLUID.h
@@ -32,6 +32,7 @@
#include <string>
#include <vector>
+#include <atomic>
struct FLUID {
public:
@@ -124,7 +125,8 @@ public:
inline float* getPhiObs() { return mPhiObs; }
inline float* getPhiOut() { return mPhiOut; }
- static bool mantaInitialized;
+ static std::atomic<bool> mantaInitialized;
+ static std::atomic<int> solverID;
// Liquid getters
inline int getNumVertices() { return mNumVertices; }
@@ -145,10 +147,15 @@ public:
void updateMeshData(const char* filename);
+ // Helper for standalone Mantaflow
+ float* getInflow() { return mInflow; }
+
private:
// simulation constants
size_t mTotalCells;
size_t mTotalCellsHigh;
+
+ int mCurrentID;
bool mUsingHeat;
bool mUsingColors;
@@ -231,7 +238,8 @@ private:
void initDomainHigh(struct SmokeModifierData *smd);
void initSmoke(struct SmokeModifierData *smd);
void initSmokeHigh(struct SmokeModifierData *smd);
- void startMantaflow();
+ void initializeMantaflow();
+ void terminateMantaflow();
void runPythonString(std::vector<std::string> commands);
std::string getRealValue(const std::string& varName, SmokeModifierData *smd);
std::string parseLine(const std::string& line, SmokeModifierData *smd);
More information about the Bf-blender-cvs
mailing list