Any Dyverso Particle Phython Scripts?

Discussions about the use of Realflow
Forester
Posts: 60
Joined: Mon Mar 15, 2010 4:36 am
Contact:

Any Dyverso Particle Phython Scripts?

Postby Forester » Sun Jul 03, 2016 9:39 pm

Has anyone had any experience writing python scripts for use with the Dyverso solver? That is code that handles particles - such as maybe a water-to-foam script or something like it.

I am going quietly bonkers trying to figure out how to do this. (Well, OK, ... my husband would not say "quietly." He would claim that I am making quite a lot of noise in the process of going crazy.)

There seem to be zero script examples anywhere, not in the Help File Scripting Refs for the DY_... sections, not in the official RF Resources pages (amazing antiquated Python stuff there - this Forum is the best source available now), not on anyone else's web pages that I can find. (Not on Luis M's pages, not on the pages for Thomas Schlick, not on Jorge's RF Wisdom site -- no where!)

From study of Thomas' "Realflow Graphs" publication, I can see that it must be possible to write Phython code to handle particles by calling individual particle IDs, but I am no Python master, and I am having a ton of trouble trying to find any syntax that works for something as simple as a water-to-foam process.

Anybody have an examples they might like to share??????
Thank you folks!


Forester
Posts: 60
Joined: Mon Mar 15, 2010 4:36 am
Contact:

Re: Any Dyverso Particle Phython Scripts?

Postby Forester » Sun Jul 03, 2016 11:10 pm

Ditto for "Expressions" for the Dyverso solver. It seems that I cannot write any expressions into something like the Filter Daemon if using the Dyverso solver. In fact, the Dyverso solver seems to lack most of the support tools and mechanisms used for the other solvers in Realflow. Kind of a shame to have incomplete tools for such a nice solver, but maybe it is still just "early days" yet.

Not really complaining about Realflow. I am reasonably competent in Houdini and Maya particles tools as well. Realflow is superior to these alternatives for almost every purpose.

desigpa
Posts: 2
Joined: Tue Jul 18, 2017 4:44 am

Re: Any Dyverso Particle Phython Scripts?

Postby desigpa » Thu Jul 27, 2017 1:10 am

A little over a year later, any love in the Pything scripts for Dyverso department?

On a side note, using RF 2015 at the moment; I wasn't able to use Filter Daemon with Dyverso, does it work in 2015, does it work in RF 10?

Thanks!

Forester
Posts: 60
Joined: Mon Mar 15, 2010 4:36 am
Contact:

Re: Any Dyverso Particle Phython Scripts?

Postby Forester » Sat Jul 29, 2017 5:42 pm

For RF 10, there are sample Dyverso Python scripts. I'm not sure if these will work well with RF 2015, but I'll give them a try and get back to you in a few days.

Forester
Posts: 60
Joined: Mon Mar 15, 2010 4:36 am
Contact:

Re: Any Dyverso Particle Phython Scripts?

Postby Forester » Tue Aug 15, 2017 2:41 pm

Here are the Sample Dyverso Particle Scripts that are part of the Help Documentation for RF10. As nearly as I can tell, all of these work with RF2015. :D

Looping Particles

# Get the domain "DY_Domain01" and its particles
dyversoDomain = scene.get_DY_Domain("DY_Domain01")
dyversoParticles = dyversoDomain.getParticles()

# Loop through every individual particle and delete it if its velocity is greater than 5.0 m/s
for particle in dyversoParticles:
if (particle.getVelocity().module() > 5.0):
dyversoDomain.removeParticle(particle.getId())


Find all Dyverso domains in a scene and synchronize their "Resolution" and "Soft Viscosity" parameters:

# Get all Dyverso domains in the scene
dyversoDomains = scene.get_DY_Domains()

# Loop through the every individual domain and change parameters
for entry in dyversoDomains:
entry.setParameter("Resolution", 10.0)
entry.setParameter("Soft Viscosity", 25.0)


Dyverso Domains
Add script to Simulation Flow (Ctrl/Cmd + F2) > FramesPre or StepsPre.

Find a particle's neighbours in domain "DY_Domain01" and the given search radius. The number of neighbours will be displayed for

every particle:

# Get the domain "DY_Domain01" and its particles
dyversoDomain = scene.get_DY_Domain("DY_Domain01")
domainParticles = dyversoDomain.getParticles()
searchRadius = 0.2

# Loop through every particle, read out its position
for particle in domainParticles:
particlePos = particle.getPosition()

# Search for neighbours at the particle's position and within the given radius
neighbours = dyversoDomain.getNeighbors(particlePos, searchRadius)

# Print out how many particles were found
scene.message(str(len(neighbours))+" neighbour particles found for particle "+str(particle.getId()))


Shifting and Deleting Particles


Add the script to Simulation Flow (Ctrl/Cmd + F2) > FramesPost or StepsPost.

The script copies Dyverso particles from "DY_Doman01" to "DY_Domain02" when they are colliding with an object. In order to avoid

instabilities, the original particles will be deleted. Both domains must have exactly the same "Resolution" and "Type" settings.

Use different colors for domains' particles to see the separation, or apply different daemons to the individual domains.

# Get the domains "DY_Domain01" and its particles, as well as "DY_Domain02"
domainA = scene.get_DY_Domain("DY_Domain01")
domainB = scene.get_DY_Domain("DY_Domain02")
particles = domainA.getParticles()

# Loop through every particle and check it is colliding with an objects.
# If the particle is colliding it is shifted to "DY_Domain02" and removed at its original position
for particle in particles:
if (particle.isColliding() == True):
domainB.addParticle(particle.getPosition(), particle.getVelocity())
domainA.removeParticle(particle.getId())

Randomization - Delete Particles


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

The script deletes particles from a Dyverso domain ("DY_Domain01") when velocity is greater than a random value between 7.0 m/s and

9.0 m/s:

# Load Python's random number generator
import random

# Get domain "DY_Domain01" and its particles, define a speed range
dyversoDomain = scene.get_DY_Domain("DY_Domain01")
particles = dyversoDomain.getParticles()
velocityMin = 7.0
velocityMax = 9.0

# Loop through every particle
for particle in particles:

# Get the particle's velocity
particleVelocity = particle.getVelocity().module()

# Define a random threshold within the speed range
randomLimit = random.uniform(velocityMin, velocityMax)

# Delete the particle if its velocity is greater than or equal to the random threshold
if (particleVelocity >= randomLimit):
dyversoDomain.removeParticle(particle.getId())


Delete Particles Below RW Surface


Dyverso Domain
Add the script to Simulation Flow (Ctrl/Cmd + F2) > FramesPost or StepsPost.

The script deletes all particles from a Dyverso domain ("DY_Domain01") particles below a RealWave surface's waterline. Particles,

which flow over the surface's borders, cannot be detected and have to be removed with appropriate daemons:

# Get the domain "DY_Domain01" and its particles
dyversoDomain = scene.get_DY_Domain("DY_Domain01")
particles = dyversoDomain.getParticles()

# Loop through every particle and delete it when it is below a RealWave surface
for particle in particles:
if (particle.isBelowRealwave()):
dyversoDomain.removeParticle(particle.getId())

Filling Objects (Dyverso)


Add this script to a "Batch Script" editor (F10) and execute it with Script > Run.

The script automatically fills a selected object (select exactly one closed object, e.g. a cube, sphere, or torus) with Dyverso

particles:

A Dyverso domain and a "Fill" emitter are added and linked in the "Relationship Editor".
The object's "Volume" is set to "Solid inside" to make it fillable.
The object is attached to the Dyverso emitter and then unlinked from the "Relationship Editor", because it is only used to create the

particles.
The object is copied and its "Volume mode" is set to "Solid outside" – now the copied objects acts as a collision object.
The scene is reset to add the particles.
# Get the selected nodes
fillObjects = scene.getSelectedNodes()

# Check if there is just one node selected, otherwise print out a warning
if (len(fillObjects) != 1):
scene.message("Select one closed object!")

# If there is one node selected check if it is really an object
else:
for node in fillObjects:
if (node.getType() == TYPE_OBJECT):

# Add a domain and a fill emitter
dyversoDomain = scene.add_DY_Domain()
dyversoEmitter = scene.add_DY_Emitter("Fill")

# Change the object's volume mode
dyversoEmitter.setParameter("Object", node.getName())
node.setParameter("Volume mode", "Solid inside")

# Remove the object's link from the "Relationship Editor"
# Create an exclusive link between domain and emitter
scene.removeGlobalLink(node)
scene.addExclusiveLink(dyversoDomain, dyversoEmitter)

# Create a copy of the object and change its volume mode
nodeCopy = node.clone()
nodeCopy.setParameter("Volume mode", "Solid outside")

# If you did not select an object print out a warning
else:
scene.message("Select an object.")

# Reset the scene to fill the object
scene.reset()


Return to “Realflow”

Who is online

Users browsing this forum: No registered users and 1 guest