[Bf-blender-cvs] [1c57b84] fluid-mantaflow: preparations for liquid high resolution
Sebastián Barschkis
noreply at git.blender.org
Fri Aug 12 12:46:52 CEST 2016
Commit: 1c57b841270c9a57b9e3cbc7f178165ca49272d3
Author: Sebastián Barschkis
Date: Fri Aug 12 12:35:02 2016 +0200
Branches: fluid-mantaflow
https://developer.blender.org/rB1c57b841270c9a57b9e3cbc7f178165ca49272d3
preparations for liquid high resolution
===================================================================
M intern/mantaflow/intern/SMOKE.cpp
M intern/mantaflow/intern/SMOKE.h
M intern/mantaflow/intern/strings/liquid_script.h
M intern/mantaflow/intern/strings/shared_script.h
M intern/mantaflow/intern/strings/smoke_script.h
===================================================================
diff --git a/intern/mantaflow/intern/SMOKE.cpp b/intern/mantaflow/intern/SMOKE.cpp
index 88b3ab6..e49b34f 100644
--- a/intern/mantaflow/intern/SMOKE.cpp
+++ b/intern/mantaflow/intern/SMOKE.cpp
@@ -74,7 +74,7 @@ SMOKE::SMOKE(int *res, SmokeModifierData *smd)
mConstantScaling = (mConstantScaling < 1.0f) ? 1.0f : mConstantScaling;
mTotalCells = mResX * mResY * mResZ;
- // Low res grids
+ // Smoke low res grids
mDensity = NULL;
mFlags = NULL;
mHeat = NULL;
@@ -97,7 +97,7 @@ SMOKE::SMOKE(int *res, SmokeModifierData *smd)
mFuelInflow = NULL;
mObstacles = NULL;
- // High res grids
+ // Smoke high res grids
mDensityHigh = NULL;
mFlameHigh = NULL;
mFuelHigh = NULL;
@@ -112,9 +112,11 @@ SMOKE::SMOKE(int *res, SmokeModifierData *smd)
mTextureV2 = NULL;
mTextureW2 = NULL;
- // Liquids
+ // Liquid low res grids
mPhi = NULL;
mPhiInit = NULL;
+
+ // Liquid high res grids
mPhiHigh = NULL;
mNumVertices = 0;
@@ -130,7 +132,27 @@ SMOKE::SMOKE(int *res, SmokeModifierData *smd)
if (mUsingLiquid) {
initDomain(smd);
initLiquid(smd);
+
updatePointers(smd);
+
+ if (mUsingHighRes) {
+ // Make sure that string vector does not contain any previous commands
+ mCommands.clear();
+
+ // simulation constants
+ int amplify = smd->domain->amplify + 1;
+ mResXHigh = amplify * mResX;
+ mResYHigh = amplify * mResY;
+ mResZHigh = amplify * mResZ;
+ mTotalCellsHigh = mResXHigh * mResYHigh * mResZHigh;
+
+ // Initialize Mantaflow variables in Python
+ initDomainHigh(smd);
+ initLiquidHigh(smd);
+
+ updatePointersHigh(smd);
+ }
+
return;
}
@@ -194,7 +216,7 @@ void SMOKE::initSmoke(SmokeModifierData *smd)
std::string tmpString = alloc_base_grids_low
+ fluid_variables
+ smoke_variables_low
- + prep_domain_low
+ + smoke_prep_domain_low
+ manta_step
+ smoke_step_low;
std::string finalString = parseScript(tmpString, smd);
@@ -209,7 +231,7 @@ void SMOKE::initSmokeHigh(SmokeModifierData *smd)
std::string tmpString = alloc_base_grids_high
+ smoke_variables_high
+ uv_setup
- + prep_domain_high
+ + smoke_prep_domain_high
+ wavelet_turbulence_noise
+ smoke_step_high;
std::string finalString = parseScript(tmpString, smd);
@@ -292,7 +314,7 @@ void SMOKE::initLiquid(SmokeModifierData *smd)
std::string tmpString = alloc_liquid
+ fluid_variables
+ liquid_variables
- + prep_domain_low
+ + liquid_prep_domain_low
+ init_phi
+ save_mesh
+ save_liquid_data
@@ -308,6 +330,20 @@ void SMOKE::initLiquid(SmokeModifierData *smd)
}
}
+void SMOKE::initLiquidHigh(SmokeModifierData *smd)
+{
+ std::string tmpString = alloc_liquid_high
+ + liquid_variables_high
+ + liquid_prep_domain_high
+ + liquid_step_high;
+ std::string finalString = parseScript(tmpString, smd);
+ mCommands.clear();
+ mCommands.push_back(finalString);
+
+ runPythonString(mCommands);
+ mUsingHighRes = true;
+}
+
void SMOKE::step(SmokeModifierData *smd)
{
// manta_write_effectors(this); // TODO in Mantaflow
@@ -336,6 +372,9 @@ SMOKE::~SMOKE()
if (mUsingLiquid) {
mCommands.push_back(del_liquid_grids);
mCommands.push_back(del_liquid_vars);
+
+ if (mUsingHighRes) mCommands.push_back(del_liquid_grids_high);
+ if (mUsingHighRes) mCommands.push_back(del_liquid_vars_high);
}
// Smoke
@@ -499,7 +538,7 @@ std::string SMOKE::getRealValue(const std::string& varName, SmokeModifierData *
else if (varName == "VORTICITY")
ss << smd->domain->vorticity / mConstantScaling;
else if (varName == "UPRES")
- ss << smd->domain->amplify;
+ ss << smd->domain->amplify + 1;
else if (varName == "HRESX")
ss << mResXHigh;
else if (varName == "HRESY") {
@@ -612,7 +651,7 @@ void SMOKE::exportScript(SmokeModifierData *smd)
}
// Rest of low res setup
- manta_script += prep_domain_low + smoke_variables_low;
+ manta_script += smoke_prep_domain_low + smoke_variables_low;
// Setup high
if (smd->domain->flags & MOD_SMOKE_HIGHRES) {
@@ -634,7 +673,7 @@ void SMOKE::exportScript(SmokeModifierData *smd)
// Rest of high res setup
if (smd->domain->flags & MOD_SMOKE_HIGHRES) {
- manta_script += prep_domain_high + wavelet_turbulence_noise;
+ manta_script += smoke_prep_domain_high + wavelet_turbulence_noise;
}
// Import low
@@ -844,7 +883,7 @@ void SMOKE::updatePointersHigh(SmokeModifierData *smd)
// Liquid
if (mUsingLiquid) {
// TODO (sebbas) phiInitHigh does not exist yet
- mPhiHigh = (float*) getGridPointer("phiInitHigh", "xl");
+ // mPhiHigh = (float*) getGridPointer("phiInitHigh", "xl");
}
if (mUsingSmoke) {
diff --git a/intern/mantaflow/intern/SMOKE.h b/intern/mantaflow/intern/SMOKE.h
index 39b4560..579830a 100644
--- a/intern/mantaflow/intern/SMOKE.h
+++ b/intern/mantaflow/intern/SMOKE.h
@@ -51,6 +51,7 @@ public:
void initFireHigh(struct SmokeModifierData *smd);
void initColorsHigh(struct SmokeModifierData *smd);
void initLiquid(SmokeModifierData *smd);
+ void initLiquidHigh(SmokeModifierData *smd);
// Pointer transfer Mantaflow -> Blender
void updatePointers(struct SmokeModifierData *smd);
diff --git a/intern/mantaflow/intern/strings/liquid_script.h b/intern/mantaflow/intern/strings/liquid_script.h
index e55fc15..e263dc2 100644
--- a/intern/mantaflow/intern/strings/liquid_script.h
+++ b/intern/mantaflow/intern/strings/liquid_script.h
@@ -45,7 +45,27 @@ randomness = $RANDOMNESS$\n\
\n\
gravity = (0,0,-1)\n\
step = -1\n\
-maxVel = 0\n";
+maxVel = 0\n\
+\n\
+using_highres = $USE_WAVELETS$\n";
+
+const std::string liquid_variables_high = "\n\
+scale = 0.5\n\
+xl_radiusFactor = 2.5\n";
+
+const std::string liquid_prep_domain_low = "\n\
+# prepare domain low\n\
+mantaMsg('Liquid domain low')\n\
+flags.initDomain(boundaryWidth=boundaryWidth)\n\
+if doOpen:\n\
+ setOpenBound(flags=flags, bWidth=boundaryWidth, openBound=boundConditions, type=FlagOutflow|FlagEmpty)\n";
+
+const std::string liquid_prep_domain_high = "\n\
+# prepare domain high\n\
+mantaMsg('Liquid domain high')\n\
+xl_flags.initDomain(boundaryWidth=boundaryWidth)\n\
+if doOpen:\n\
+ setOpenBound(flags=xl_flags, bWidth=boundaryWidth, openBound=boundConditions, type=FlagOutflow|FlagEmpty)\n";
//////////////////////////////////////////////////////////////////////
// GRIDS & MESH & PARTICLESYSTEM
@@ -78,6 +98,16 @@ const std::string init_phi = "\n\
phi.initFromFlags(flags)\n\
phiInit.initFromFlags(flags)\n";
+const std::string alloc_liquid_high = "\n\
+xl_flags = xl.create(FlagGrid)\n\
+xl_phi = xl.create(LevelsetGrid)\n\
+xl_pp = xl.create(BasicParticleSystem)\n\
+xl_mesh = xl.create(Mesh)\n\
+\n\
+# Acceleration data for particle nbs\n\
+xl_pindex = xl.create(ParticleIndexSystem)\n\
+xl_gpi = xl.create(IntGrid)\n";
+
//////////////////////////////////////////////////////////////////////
// ADAPTIVE STEP
//////////////////////////////////////////////////////////////////////
@@ -98,8 +128,15 @@ def manta_step(start_frame):\n\
maxvel = vel.getMaxValue()\n\
s.adaptTimestep(maxvel)\n\
\n\
- mantaMsg('Liquid step / s.frame: ' + str(s.frame))\n\
+ mantaMsg('Low step / s.frame: ' + str(s.frame))\n\
liquid_step()\n\
+ \n\
+ # TODO (sebbas)\n\
+ if using_highres:\n\
+ xl.timestep = s.timestep\n\
+ mantaMsg('High step / s.frame: ' + str(s.frame))\n\
+ liquid_step_high()\n\
+ \n\
s.step()\n";
//////////////////////////////////////////////////////////////////////
@@ -174,16 +211,43 @@ def liquid_step():\n\
else:\n\
adjustNumber(parts=pp, vel=vel, flags=flags, minParticles=1*minParticles, maxParticles=2*minParticles, phi=phi, radiusFactor=radiusFactor)\n\
\n\
+ # TODO (sebbas): HACK - saving particle system for highres step\n\
+ #if using_highres:\n\
+ #pp.save('/tmp/partfile.uni')\n\
+ \n\
# reset inflow grid\n\
phiInit.setConst(0.5)\n";
+const std::string liquid_step_high = "\n\
+def liquid_step_high():\n\
+ xl_phi.setBound(value=0., boundaryWidth=1)\n\
+ xl_pp.load('/tmp/partfile.uni')\n\
+ \n\
+ # create surface\n\
+ gridParticleIndex( parts=xl_pp , flags=xl_flags, indexSys=xl_pindex, index=xl_gpi )\n\
+ unionParticleLevelset( xl_pp, xl_pindex, xl_flags, xl_gpi, xl_phi , xl_radiusFactor )\n\
+ #averagedParticleLevelset( xl_pp, xl_pindex, xl_flags, xl_gpi, xl_phi , xl_radiusFactor , 1, 1 )\n\
+ \n\
+ xl_phi.setBound(value=0., boundaryWidth=1)\n\
+ xl_phi.createMesh(xl_mesh)\n\
+ \n\
+ # beautify mesh, too slow right now!\n\
+ #subdivideMesh(mesh=xl_mesh, minAngle=0.01, minLength=scale, maxLength=3*scale, cutTubes=False)\n\
+ # perform smoothing\n\
+ #for iters in range(10):\n\
+ #smoothMesh(mesh=xl_mesh, strength=1e-3, steps=10)\n\
+ #subdivideMesh(mesh=xl_mesh, minAngle=0.01, minLength=scale, maxLength=3*scale, cutTubes=True)\n";
+
//////////////////////////////////////////////////////////////////////
// IMPORT EXPORT GRIDS, MESHES, PARTICLESYSTEM
//////////////////////////////////////////////////////////////////////
const std::string save_mesh = "\n\
def save_mesh(path):\n\
- mesh.save(path)\n";
+ mesh.save(path)\n\
+ # TODO (sebbas)\n\
+ #if using_highres:\n\
+ #xl_mesh.save(path)\n";
const std::string save_liquid_data = "\n\
def save_liquid_data(path):\n\
@@ -228,7 +292,7 @@ def load_liquid_data(path):\n\
//////////////////////////////////////////////////////////////////////
const std::string del_liquid_grids = "\n\
-mantaMsg('Deleting grids, mesh, particlesystem')\n\
+mantaMsg('Deleting lowres grids, mesh, particlesystem')\n\
if 'flags' in globals() : del flags\n\
if 'phiParts' in globals() : del phiParts\n\
if 'phi' in globals() : del phi\n\
@@ -245,8 +309,17 @@ if 'mesh' in globals() : del mesh\n\
if 'pindex' in globals() : del pindex\n\
if 'gpi' in globals() : del gpi\n";
+const std::string del_liquid_grids_high = "\n\
+mantaMsg('Deleting highres grids, mesh, particlesystem')\n\
+if 'xl_flags
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list