Need help with script - transferring between domains

Discussion about scripting with Python
dmeyer
Posts: 19
Joined: Thu Jun 03, 2010 7:26 pm

Need help with script - transferring between domains

Postby dmeyer » Wed Apr 05, 2017 4:47 am

Goal: Since RF does't detect particle-particle collision, fake it by looking at a particle's neighbors to see if it is a from a different domain, if so, then transfer it to a 3rd domain.

So water + sand = third domain.

Anyway I'm getting a syntax error and don't know why.

Code: Select all


# Get the domain "water_domain" and its particles
dyversoWaterDomain   = scene.get_DY_Domain("water_domain")
dyversoSandDomain   = scene.get_DY_Domain("sand_domain")
dyversoGelDomain   = scene.get_DY_Domain("gel_domain")
dyversoWaterEmitter   = scene.get_DY_Emitter("water_emitter")
dyversoSandEmitter   = scene.get_DY_Emitter("sand_emitter")
domainWaterParticles = dyversoWaterDomain.getParticles()
domainSandParticles = dyversoSandDomain.getParticles()
searchRadius    = 0.2
 
#create voxelization
dyversoWaterDomain.createVoxelization()

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

    # Search for neighbors at the particle's position and within the given radius
    neighbors = domainWaterParticles.getNeighbors(particlePos, searchRadius)
      
      #loop through the neighbors to see if they are sand
      for particle in neighbors:
         whichEmitter = particle.getEmitterId()
      if (whichEmitter == dyversoSandEmitter.getId()):
           
           #transfer the sand particle to the gel domain if it is close enough to water
            dyversoGelDomain.addParticle(particle.getPosition(), particle.getVelocity())
                  dyversoSandDomain.removeParticle(particle.getId())


I tried to attach a scene file but the website says the board attachment quota has been reached.


User avatar
tsn
Posts: 861
Joined: Fri Oct 27, 2006 10:36 am

Re: Need help with script - transferring between domains

Postby tsn » Wed Apr 05, 2017 6:31 am

It'd be nice if you could provide the scene anyway, e.g. via a PM or a file hoster. At least it's helpful to tell where the error occurs (line number, error message). For more verbose error messages go to Preferences > Scripts > Redirect Output to Messages Panel.

Anyway, from a quick look I can say that your indents are wrong and that you're trying to get an Id from an emitter:

Code: Select all

if (whichEmitter == dyversoSandEmitter.getId()):

The getId() statement is only available for particles.

More when I have the scene.

Cheers,
Thomas

dmeyer
Posts: 19
Joined: Thu Jun 03, 2010 7:26 pm

Re: Need help with script - transferring between domains

Postby dmeyer » Wed Apr 05, 2017 10:39 am


User avatar
tsn
Posts: 861
Joined: Fri Oct 27, 2006 10:36 am

Re: Need help with script - transferring between domains

Postby tsn » Wed Apr 05, 2017 3:02 pm

Ok, I've corrected the script, but I get crashes here when I use the createVoxelization() statement. This might be a bug in RF10 and I have to investigate a little on that.

And just to get it right: your aim was to look for granular particles around a PBD particle. and if there are neighbours the appropriate sand particles should be added to the third domain (gel)? did i understand that correctly?

dmeyer
Posts: 19
Joined: Thu Jun 03, 2010 7:26 pm

Re: Need help with script - transferring between domains

Postby dmeyer » Wed Apr 05, 2017 6:46 pm

tsn wrote:Ok, I've corrected the script, but I get crashes here when I use the createVoxelization() statement. This might be a bug in RF10 and I have to investigate a little on that.

And just to get it right: your aim was to look for granular particles around a PBD particle. and if there are neighbours the appropriate sand particles should be added to the third domain (gel)? did i understand that correctly?


Thanks for your help.

I did get the syntax error sorted out after turning on the verbose error messages. I've done some scripting before, and I've done some realflow before, but I've never scripted in realflow, so a bit of a learning curve.

Is it possible to run a getNeighbors lookup against a DY Domain, and find nearby particles of a different DY Domain?

To answer your question / clarify intent...the ideal would be:

(all using Dyverso)

When the PBD particles (or SPH) come in 'contact' with the granular particles, both of those are transferred into a third "gel" domain, which will be an SPH domain with higher viscosity.

The effect I'm trying to achieve is that the granular is an absorbant material that expands when water hits it, and turns to gel.

User avatar
tsn
Posts: 861
Joined: Fri Oct 27, 2006 10:36 am

Re: Need help with script - transferring between domains

Postby tsn » Thu Apr 06, 2017 7:43 am

Thanks for the clarification. I got it right and the only thing I didn't consider was to transfer the PBD particles to the gel domain as well. But the process is he same as with sand, so it shouldn't be a problem for you to extend the script accordingly.

With regards voxelization: it's indeed crashing, but only when the command is executed for the 2nd time and when there are no particles. It's a memory buffer issue and should be fixed with the next patch (at least I do hope so). In the meantime you have to live without this command. It's slower, but it works.

And, yes, it's possible to take a particle from domain A as a source to look for neighbours in domain B. That's exactly what I did when I fixed your script and here's the code I've been using:

Code: Select all

dyversoWaterDomain = scene.get_DY_Domain("water_domain")
dyversoSandDomain = scene.get_DY_Domain("sand_domain")
dyversoGelDomain = scene.get_DY_Domain("gel_domain")
domainWaterParticles = dyversoWaterDomain.getParticles()
searchRadius = 0.2

#dyversoSandDomain.createVoxelization()
#dyversoGelDomain.createVoxelization()

for particle in domainWaterParticles:
   particlePos = particle.getPosition()
   neighbors   = dyversoSandDomain.getNeighbors(particlePos, searchRadius)

   for particle in neighbors:
      dyversoGelDomain.addParticle(particle.getPosition(), particle.getVelocity())
      dyversoSandDomain.removeParticle(particle.getId())


The lines with createVoxelization are inactive because of the crash. If you want to take the water domain into consideration you have to create the voxelization for this domain as well (once it's working again).

Cheers,
Thomas

dmeyer
Posts: 19
Joined: Thu Jun 03, 2010 7:26 pm

Re: Need help with script - transferring between domains

Postby dmeyer » Thu Apr 06, 2017 12:55 pm

Thanks a bunch, tsn!


Return to “Python-Scripting”

Who is online

Users browsing this forum: No registered users and 2 guests