Engineering aspects of Realflow - Basic Questions

Discussions about the use of Realflow 2012
bmecohen
Posts: 28
Joined: Thu Sep 27, 2012 12:55 pm

Re: Engineering aspects of Realflow - Basic Questions

Post by bmecohen » Mon Oct 08, 2012 10:58 am

This is the main directory of the project : C:/Users/Gabor/scenes/test/
and I want to do a particle_version02 directory, to separate the bin files, what the simulation makes, from the txt files.

the Syntax check says, this is wrong:

position = particle.getPosition()

lukeiamyourfather
Posts: 2880
Joined: Mon Oct 15, 2007 4:09 pm
Contact:

Re: Engineering aspects of Realflow - Basic Questions

Post by lukeiamyourfather » Mon Oct 08, 2012 8:59 pm

bmecohen wrote:This is the main directory of the project : C:/Users/Gabor/scenes/test/
and I want to do a particle_version02 directory, to separate the bin files, what the simulation makes, from the txt files.

the Syntax check says, this is wrong:

position = particle.getPosition()
Please post the exact code you're using and do it in the code brackets so the tabs and spaces are preserved too.

Code: Select all

# Like this, see the spaces and tabs are preserved
def foo(bar):
    print bar

foo('This is a test')
WhenPicsFly | Debian GNU/Linux

bmecohen
Posts: 28
Joined: Thu Sep 27, 2012 12:55 pm

Re: Engineering aspects of Realflow - Basic Questions

Post by bmecohen » Mon Oct 08, 2012 10:50 pm

Code: Select all

# Creates a file object that Python can write to 
file = open("C:/Users/Gabor/scenes/test/particles_version02/001.txt", "w") 

# Gets the emitter and the first particle of the emitter 
emitter = scene.getEmitter("Circle01") 
particle = emitter.getFirstParticle() 

# Loop through all particles and write out their ID and position 
while particle: 
position = particle.getPosition() 
id = particle.getId() 
file.write("%s %s %s %s" % (id,position.getX(),position.getY(),position.getZ())) 
particle = particle.getNextParticle() 

# Close the file object when done, this is a good practice 
file.close()
I don't have a folder called particle_version02 maybe this is a problem /I would like to know how to create one, if there is no directory with the specified name. maybe with the import shutil -> shutil copytree python code/

I use this as a batch script, it should be an event script in every simulation frame?

After that, syntax check says a problem in this line: particle = emitter.getFirstParticle()

thanks in advance for the huge help!

fkfx
Posts: 309
Joined: Wed Apr 11, 2012 11:11 am
Location: Cologne, Germany
Contact:

Re: Engineering aspects of Realflow - Basic Questions

Post by fkfx » Tue Oct 09, 2012 9:48 am

I think the problem is incorrect indentation/ spacing. In Python spaces and tabs work just like parenthesis in other programming languages. Whitespace is not ignored, but part of the language. When I was new to Python, I hated that, too. In order to make position.getPosition() a part of your while- loop, do it like this.

Code: Select all

# Loop through all particles and write out their ID and position
while particle:
     position = particle.getPosition()
     id = particle.getId()
     file.write("%s %s %s %s" % (id,position.getX(),position.getY(),position.getZ()))
     particle = particle.getNextParticle() 
Some more detailesd info on that matter:

http://docs.python.org/release/2.5.1/re ... ation.html

bmecohen
Posts: 28
Joined: Thu Sep 27, 2012 12:55 pm

Re: Engineering aspects of Realflow - Basic Questions

Post by bmecohen » Tue Oct 09, 2012 1:47 pm

You were right, the code is now working! thank you!

I want to make a further development of the code, so I did a few improvments where I got error messages.

Code: Select all

current_frame = scene.getCurrentFrame()
root_path = scene.getRootPath()
This is the start because I want write out the particle data in every frame and I want to make a "file export directory chooser"

Code: Select all

form = GUIFormDialog.new()
form.setTitle("Export to TecPlot")
form.addStringField("Root Path", root_path+"/"+"export/")

Code: Select all

if ( form.show() == GUI_DIALOG_ACCEPTED ):
	emitter_export = scene.getEmitter(emitterNameList[form.getFieldValue("Choose emitter for export")])
	particle = emitter_export.getFirstParticle() 

	# Creates a file object that Python can write to 
	file = open( root_path + current_frame ".txt", "w")  
The syntax check says that it is an error in the line of file = open and I don't know how to get the root_path and current_frame correctly. I think it will be a integer to string problem or something.

Other "issue" is in the txt file

Code: Select all

while particle: 
			id = particle.getId()
			position = particle.getPosition() 
			velocity = particle.getVelocity()  
			density = particle.getDensity() 
			pressure = particle.getPressure() 
						 
			file.write("%s %s %s %s %s %s %s %s %s" % (id,position.getX(),position.getY(),position.getZ(),velocity.getX(),velocity.getY(),velocity.getZ(),density,pressure)) 
			particle = particle.getNextParticle() 
and the output data is not what I wanted.

The txt should like this in order: ID PosX PosY PosZ VelX VelY VelZ Den Pres
but my txt is like this: ID PosX PosY PosZ VelX VelY VelZ ? ? ? /I don't see the density, and the pressure correctly, because the density should be greater than 0.4 or something if I use it basically as 1000/

Also afterwards I don't see any other particle ID just the first one. Maybe I misunderstand the code entirely, but I want a code like this:

Code: Select all

VARIABLES = "id" "x" "y" "z" "vx" "vy" "vz" "density" "pressure"
ZONE F=POINT, STRANDID=1, SOLUTIONTIME=0.03
109616 0.786 -0.185 0.063 0.033 0.006 0.032 1049.749 304.752
109615 0.786 -0.177 0.063 0.001 0.005 0.003 1035.493 176.532
109614 0.786 -0.158 0.061 -0.005 -0.006 -0.007 1013.543 -1.258

lukeiamyourfather
Posts: 2880
Joined: Mon Oct 15, 2007 4:09 pm
Contact:

Re: Engineering aspects of Realflow - Basic Questions

Post by lukeiamyourfather » Tue Oct 09, 2012 4:36 pm

Get the basics of what you want working before you start adding a GUI and things that require string manipulation like the root path. Then go back and work out those non-essential items. Doing things one step at a time like that will make the debugging much easier to do.
WhenPicsFly | Debian GNU/Linux

bmecohen
Posts: 28
Joined: Thu Sep 27, 2012 12:55 pm

Re: Engineering aspects of Realflow - Basic Questions

Post by bmecohen » Tue Oct 09, 2012 4:54 pm

You are right...the most important problem is to fix the output data: I see only one particle id, and after just values what is look like position and velocity

Code: Select all

while particle: 
         id = particle.getId()
         position = particle.getPosition() 
         velocity = particle.getVelocity()  
         density = particle.getDensity() 
         pressure = particle.getPressure() 
                   
         file.write("%s %s %s %s %s %s %s %s %s" % (id,position.getX(),position.getY(),position.getZ(),velocity.getX(),velocity.getY(),velocity.getZ(),density,pressure)) 
         particle = particle.getNextParticle()
The txt should like this in order: ID PosX PosY PosZ VelX VelY VelZ Den Pres
but my txt is like this: ID PosX PosY PosZ VelX VelY VelZ ? ? ? /I don't see the density, and the pressure correctly, because the density should be greater than 0.4 or something if I use it basically as 1000/

Also afterwards I don't see any other particle ID just the first one. Maybe I misunderstand the code entirely, but I want a code like this:

Code: Select all

VARIABLES = "id" "x" "y" "z" "vx" "vy" "vz" "density" "pressure"
ZONE F=POINT, STRANDID=1, SOLUTIONTIME=0.03
109616 0.786 -0.185 0.063 0.033 0.006 0.032 1049.749 304.752
109615 0.786 -0.177 0.063 0.001 0.005 0.003 1035.493 176.532
109614 0.786 -0.158 0.061 -0.005 -0.006 -0.007 1013.543 -1.258

bmecohen
Posts: 28
Joined: Thu Sep 27, 2012 12:55 pm

Re: Engineering aspects of Realflow - Basic Questions

Post by bmecohen » Tue Oct 09, 2012 6:08 pm

In my code, as I can see, the last particle data is overwrite eveything. So when a new particle created the datas from the old one is gone.
I would like to create a txt file, with all the particles, to write out just for the current frames position velocity etc. So for the frame 2 - frame 1 = change of distance in all particles etc.

I saw in the scripting reference an example:

Code: Select all

# Iterate the list of particles and write out their ids.
currentParticle = emitter.getFirstParticle()
while currentParticle:
  scene.message( str( currentParticle.id ) )
  currentParticle = currentParticle.getNextParticle()
in this, the code is working, all the particles id is visible in the messages box.

bmecohen
Posts: 28
Joined: Thu Sep 27, 2012 12:55 pm

Re: Engineering aspects of Realflow - Basic Questions

Post by bmecohen » Thu Oct 11, 2012 2:05 pm

I divided this topic to specific problems because it's to complex. Thanks for everyone the help!

Locked

Return to “Realflow 2012”