Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Add the script to Simulation Flow (Ctrl/Cmd + F2) > FramesPreFramesPost.

The script calculates the normals of particles of a Dyverso domain ("DY_Domain") based on their neighbours. A calculation like that can be used to detect border particles.

To get the normals it is necessary to calculate the particles' centre of gravity by adding up all position values and building an average value. This average is then compared against a threshold.

Border particle detection works best with thin sheets of fluid, e.g. a "Linear" emitter with a "Sheeter" daemon. The main problem is to find a suitable threshold.average velocities of a scene's active rigid bodies for each frame of a simulation and prints out the result:

Initializing the Objects

Code Block
objects       = scene.getObjects()
activeObjects = []

for entry in objects:
	dynamicsMode = entry.getParameter("Dynamics")
	activeObjects.append(entry)

# The global variable is necessary to transfer the active objects from "SimulationPre" to "FramesPost".
scene.setGlobalVariableValue("activeObjects", activeObjects)

 

Calculating the Velocity

The output is formatted ("%.2f" % averageVelocity) and clips the result to two digits, e.g. 3.67 instead of 3.671472813

Code Block
languagepy
activeObjects  = scene.getGlobalVariableValue("activeObjects")
numOfObjects   = len(activeObjects)
objectVelocity = 0.0
 
for entry in activeObjects:
	objectVelocity += entry.getVelocity().module()
 
averageVelocity = objectVelocity / numOfObjects
 
scene.message("The average velocity is "+str("%.2f" % averageVelocity)+"m/s")