[Bf-blender-cvs] [756eedd] fluid-mantaflow: added new liquid script functions (mostly nb flip)
Sebastián Barschkis
noreply at git.blender.org
Mon May 23 23:45:40 CEST 2016
Commit: 756eedd2ab80251bde97af4b113e8576c327f20a
Author: Sebastián Barschkis
Date: Thu May 5 10:33:23 2016 +0200
Branches: fluid-mantaflow
https://developer.blender.org/rB756eedd2ab80251bde97af4b113e8576c327f20a
added new liquid script functions (mostly nb flip)
===================================================================
D intern/mantaflow/intern/strings/liquid.h
A intern/mantaflow/intern/strings/liquid_script.h
===================================================================
diff --git a/intern/mantaflow/intern/strings/liquid.h b/intern/mantaflow/intern/strings/liquid.h
deleted file mode 100644
index 054d38a..0000000
--- a/intern/mantaflow/intern/strings/liquid.h
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * ***** BEGIN GPL LICENSE BLOCK *****
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2016 Blender Foundation.
- * All rights reserved.
- *
- * Contributor(s): Sebastian Barschkis (sebbas)
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file mantaflow/intern/strings/liquid.h
- * \ingroup mantaflow
- */
-
-#include <string>
-
-//////////////////////////////////////////////////////////////////////
-// GENERAL SETUP
-//////////////////////////////////////////////////////////////////////
-
-// DEPRECATED! BUT KEEPING HERE FOR REFERENCE FOR LATER USE
-const std::endl liquid_flags = "\n\
-low_flags_updated = False\n";
-
-//////////////////////////////////////////////////////////////////////
-// STEP FUNCTIONS LOW
-//////////////////////////////////////////////////////////////////////
-
-// DEPRECATED! BUT KEEPING HERE FOR REFERENCE FOR LATER USE
-const std::endl liquid_step_low = "\n\
-def sim_step_low(t):\n\
-#update flags from density on first step\n\
- setWallBcs(flags=flags, vel=vel)\n\
- density.multConst(-1.)\n\
- mantaMsg(using_colors)\n\
- global low_flags_updated\n\
- if not low_flags_updated:\n\
- mantaMsg('Updating Flags from Levelset on startup!')\n\
- flags.updateFromLevelset(density)\n\
- low_flags_updated = True \n\
- setWallBcs(flags=flags, vel=vel)\n\
- density.reinitMarching(flags=flags, velTransport=vel)\n\
- advectSemiLagrange(flags=flags, vel=vel, grid=density, order=2)\n\
- flags.updateFromLevelset(density)\n\
- \n\
- advectSemiLagrange(flags=flags, vel=vel, grid=vel, order=2)\n\
- addGravity(flags=flags, vel=vel, gravity=vec3(0,0,-0.981))\n\
- \n\
- # mantaMsg current maximal velocity\n\
- maxvel = vel.getMaxValue()\n\
- mantaMsg('Current max velocity %f ' % maxvel)\n\
- \n\
- # pressure solve\n\
- setWallBcs(flags=flags, vel=vel)\n\
- solvePressure(flags=flags, vel=vel, pressure=pressure, cgMaxIterFac=0.5, useResNorm=True) \n\
- setWallBcs(flags=flags, vel=vel)\n\
- s.step()\n\
- density.multConst(-1.)\n";
-
diff --git a/intern/mantaflow/intern/strings/liquid_script.h b/intern/mantaflow/intern/strings/liquid_script.h
new file mode 100644
index 0000000..ec5dd74
--- /dev/null
+++ b/intern/mantaflow/intern/strings/liquid_script.h
@@ -0,0 +1,204 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2016 Blender Foundation.
+ * All rights reserved.
+ *
+ * Contributor(s): Sebastian Barschkis (sebbas)
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file mantaflow/intern/strings/liquid.h
+ * \ingroup mantaflow
+ */
+
+#include <string>
+
+//////////////////////////////////////////////////////////////////////
+// GENERAL SETUP
+//////////////////////////////////////////////////////////////////////
+
+const std::string manta_import = "\
+from manta import *\n\
+import os, shutil, math, sys, gc\n";
+
+const std::string liquid_flags = "\n\
+narrowBand = False\n";
+
+const std::string liquid_solver_setup = "\n\
+dim = 3\n\
+particleNumber = 2\n\
+res = 64\n\
+gs = vec3(res,res,res)\n\
+if (dim==2):\n\
+ gs.z=1\n\
+s = Solver(name='main', gridSize = gs, dim=dim)\n\
+dt_default = 0.1\n\
+dt_factor = 1.0\n\
+fps = 24\n\
+dt0 = dt_default * (25.0 / fps) * dt_factor\n\
+s.frameLength = dt0\n\
+s.timestepMin = dt0 / 10\n\
+s.timestepMax = dt0\n\
+s.cfl = 4.0\n\
+s.timestep = dt0\n\
+#s.frameLength = 1.0\n\
+#s.timestep = 1.0\n\
+#s.timestepMin = 0.5\n\
+#s.timestepMax = 1.0\n\
+#s.cfl = 5.0\n\
+narrowBandWidth = 3\n\
+combineBandWidth = narrowBandWidth - 1\n\
+# using special gravity for blender\n\
+gravity = (0,0,-1)\n\
+minParticles = pow(2,dim)\n\
+step = -1\n\
+maxVel = 0\n";
+
+//////////////////////////////////////////////////////////////////////
+// GRIDS & MESHES
+//////////////////////////////////////////////////////////////////////
+
+const std::string alloc_liquid = "\n\
+flags = s.create(FlagGrid)\n\
+\n\
+phiParts = s.create(LevelsetGrid)\n\
+phi = s.create(LevelsetGrid)\n\
+pressure = s.create(RealGrid)\n\
+\n\
+vel = s.create(MACGrid)\n\
+velOld = s.create(MACGrid)\n\
+velParts = s.create(MACGrid)\n\
+mapWeights = s.create(MACGrid)\n\
+\n\
+pp = s.create(BasicParticleSystem)\n\
+pVel = pp.create(PdataVec3)\n\
+mesh = s.create(Mesh)\n\
+\n\
+# Acceleration data for particle nbs\n\
+pindex = s.create(ParticleIndexSystem)\n\
+gpi = s.create(IntGrid)\n";
+
+const std::string prep_domain = "\n\
+flags.initDomain(boundaryWidth=0)\n\
+phi.initFromFlags(flags)\n";
+
+//////////////////////////////////////////////////////////////////////
+// MESH LOADING
+//////////////////////////////////////////////////////////////////////
+
+const std::string mesh_loading = "\n\
+mesh.load('manta_flow.obj')\n\
+mesh.scale( vec3(res/2.0) )\n\
+mesh.offset( gs*0.5 )\n\
+mesh.computeLevelset(phi, 4., -1.)\n\
+\n\
+flags.updateFromLevelset(phi)\n\
+sampleLevelsetWithParticles( phi=phi, flags=flags, parts=pp, discretization=2, randomness=0.4 )\n\
+mapGridToPartsVec3(source=vel, parts=pp, target=pVel )\n";
+
+//////////////////////////////////////////////////////////////////////
+// ADAPTIVE STEP
+//////////////////////////////////////////////////////////////////////
+
+const std::string manta_step = "\n\
+def manta_step(start_frame):\n\
+ s.frame = start_frame\n\
+ s.timeTotal = s.frame * dt0\n\
+ last_frame = s.frame\n\
+ while s.frame == last_frame:\n\
+ global step\n\
+ step = step + 1\n\
+ mantaMsg('Adapt timestep')\n\
+ maxvel = vel.getMaxValue()\n\
+ s.adaptTimestep(maxvel)\n\
+ \n\
+ mantaMsg('Liquid step / s.frame: ' + str(s.frame))\n\
+ liquid_step()\n\
+ s.step()\n";
+
+//////////////////////////////////////////////////////////////////////
+// STEP FUNCTIONS
+//////////////////////////////////////////////////////////////////////
+
+const std::string liquid_step = "\n\
+def liquid_step():\n\
+ # Advect particles and grid phi\n\
+ # Note: Grid velocities are extrapolated at the end of each step\n\
+ pp.advectInGrid(flags=flags, vel=vel, integrationMode=IntRK4, deleteInObstacle=False )\n\
+ advectSemiLagrange(flags=flags, vel=vel, grid=phi, order=1)\n\
+ flags.updateFromLevelset(phi)\n\
+ \n\
+ # Advect grid velocity\n\
+ if narrowBand:\n\
+ advectSemiLagrange(flags=flags, vel=vel, grid=vel, order=2)\n\
+ \n\
+ # Create level set of particles\n\
+ gridParticleIndex( parts=pp , flags=flags, indexSys=pindex, index=gpi )\n\
+ unionParticleLevelset( pp, pindex, flags, gpi, phiParts )\n\
+ \n\
+ if narrowBand:\n\
+ # Combine level set of particles with grid level set\n\
+ phi.addConst(1.); # shrink slightly\n\
+ phi.join( phiParts );\n\
+ extrapolateLsSimple(phi=phi, distance=narrowBandWidth+2, inside=True )\n\
+ else:\n\
+ # Overwrite grid level set with level set of particles\n\
+ phi.copyFrom( phiParts );\n\
+ extrapolateLsSimple(phi=phi, distance=4, inside=True )\n\
+ \n\
+ extrapolateLsSimple(phi=phi, distance=3 )\n\
+ flags.updateFromLevelset(phi)\n\
+ \n\
+ # Make sure we have velocities throught liquid region\n\
+ if narrowBand:\n\
+ # Combine particles velocities with advected grid velocities\n\
+ mapPartsToMAC(vel=velParts, flags=flags, velOld=velOld, parts=pp, partVel=pVel, weight=mapWeights)\n\
+ extrapolateMACFromWeight( vel=velParts , distance=2, weight=mapWeights )\n\
+ combineGridVel(vel=velParts, weight=mapWeights , combineVel=vel, phi=phi, narrowBand=combineBandWidth, thresh=0)\n\
+ velOld.copyFrom(vel)\n\
+ else:\n\
+ # Map particle velocities to grid\n\
+ mapPartsToMAC(vel=vel, flags=flags, velOld=velOld, parts=pp, partVel=pVel, weight=mapWeights)\n\
+ extrapolateMACFromWeight( vel=vel , distance=2, weight=mapWeights )\n\
+ \n\
+ # Forces & pressure solve\n\
+ addGravity(flags=flags, vel=vel, gravity=gravity)\n\
+ setWallBcs(flags=flags, vel=vel)\n\
+ solvePressure(flags=flags, vel=vel, pressure=pressure, phi=phi)\n\
+ setWallBcs(flags=flags, vel=vel)\n\
+ \n\
+ # Extrapolate velocities\n\
+ extrapolateMACSimple( flags=flags, vel=vel, distance=(int(maxVel*1.25 + 2.)) )\n\
+ \n\
+ # Update particle velocities\n\
+ flipVelocityUpdate(vel=vel, velOld=velOld, flags=flags, parts=pp, partVel=pVel, flipRatio=0.95 )\n\
+ \n\
+ if dim==3:\n\
+ phi.createMesh(mesh)\n\
+ mesh.save('/Users/sbarschkis/Desktop/surface/fluidsurface_final_%04d.bobj.gz' %
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list