CFD Online URL
[Sponsors]
Home > Forums > OpenFOAM Paraview & paraFoam

Python script for Integrate Variable

Register Blogs Members List Search Today's Posts Mark Forums Read

Like Tree2Likes
  • 2 Post By Eloise

Reply
 
LinkBack Thread Tools Display Modes
Old   May 31, 2013, 06:09
Post Python script for Integrate Variable
  #1
Member
 
Mehdi GHOZALI
Join Date: May 2013
Location: Dubai, UAE
Posts: 64
Rep Power: 3
Dadou is on a distinguished road
Hello,

I am using paraview for visualize the velocity and the flow on a slice/clip that I did.

I have a lot of clips and I have to export data for every one and even the integrate variable data on this one. The first part is done now I don't know what is the sciprt of integrate variable on a clip so I can do it automaticly!!

hope some one will help

thank you in advance

dadou
Dadou is offline   Reply With Quote

Old   July 4, 2013, 11:25
Default
  #2
Member
 
Elo´se
Join Date: Jul 2012
Location: Trondheim, Norway
Posts: 98
Rep Power: 4
Eloise is on a distinguished road
Hello Mehdi,

I'd like to do a similar scripted post-processing: integrate a variable on different clips and then export the spreadsheet data to a file. Have you made any progress on your case?

Regards,
Elo´se
Eloise is offline   Reply With Quote

Old   July 5, 2013, 04:37
Default
  #3
Member
 
Mehdi GHOZALI
Join Date: May 2013
Location: Dubai, UAE
Posts: 64
Rep Power: 3
Dadou is on a distinguished road
Hi Eloise,

Nop any progress unfortunately, do you have any idea ?

Regards

Mehdi
Dadou is offline   Reply With Quote

Old   July 5, 2013, 05:02
Default
  #4
Member
 
Elo´se
Join Date: Jul 2012
Location: Trondheim, Norway
Posts: 98
Rep Power: 4
Eloise is on a distinguished road
Hi Mehdi,

I'm not sure it is the fastest way to deal with the csv files, but I did manage. Here is the interesting part of the script

Code:
try: paraview.simple
except: from paraview.simple import *
paraview.simple._DisableFirstRenderCameraReset()

import csv
surf = LegacyVTKReader( FileNames=['pathToImportFile.vtk'] )

RenderView1 = GetRenderView()
                                      
Clip1 = Clip( ClipType="Plane" )
Clip1.Scalars = ['POINTS', 'p']
Clip1.ClipType.Origin = [0.0, 0.0, 0.0] #can be a random origin point
Clip1.ClipType.Normal = [1.0, 0.0, 0.0]   #can be a random normal orientation
Clip1.ClipType = "Plane"              

Clip2 = Clip( ClipType="Plane" )
Clip2.Scalars = ['POINTS', 'p']  
Clip2.ClipType.Origin = [1.0, 0.0, 0.0]  #can be a random origin point
Clip2.ClipType.Normal = [-1.0, 0.0, 0.0]  #can be a random normal orientation
Clip2.ClipType = "Plane"
                                      
# we define the variable to be integrated on Clip2                  
Calculator1 = Calculator()       
Calculator1.AttributeMode = 'point_data'
Calculator1.Function = 'writeHereTheFunctionOfYourVariable'
Calculator1.ReplaceInvalidResults = 0
Calculator1.ResultArrayName = 'NameOfYourVariable'

IntegrateVariables1 = IntegrateVariables()   #this integrates the current variable over Clip2

finalFile = open('pathToCSVFile.csv','wb')
fd = csv.writer(finalFile)  
                                     
writer = CreateWriter('PathToATemporaryFile.csv', IntegrateVariables1) 
writer.FieldAssociation = "Points"  # or "Cells"

for x in range(-6, 6): #loop through the origin point of Clip1
    print "We integrate from %1.1f to %1.1f" % (x,x+1)
        
    Clip1.ClipType.Origin = [x,0.0,0.0] #moves the first clip
    Clip1.ClipType.Normal = [1.0,0.0,0.0]
      
    Clip2.ClipType.Origin = [x+1,0.0,0.0] # moves the second clip
    Clip2.ClipType.Normal = [-1.0,0.0,0.0]
                      
    writer.UpdatePipeline() # writes the integrated variable table to the tmp file
    
    # appends the integrated results of this Clip to the final csv file
    ftmp = open('PathToATemporaryFile.csv','rb')
    reader = csv.reader(ftmp, delimiter=',')
    row = reader.next()                                        
    row = reader.next()
    fd.writerow([str(row)]) 
    ftmp.close()           
    
finalFile.close()             
del(writer)                

Render()
If you know a way to make it faster, please share it I hope this will help you!

Elo´se
elvis and Bernhard like this.
Eloise is offline   Reply With Quote

Old   July 5, 2013, 06:38
Default
  #5
Member
 
Mehdi GHOZALI
Join Date: May 2013
Location: Dubai, UAE
Posts: 64
Rep Power: 3
Dadou is on a distinguished road
I'll look it up.

Thank you so much for this, I'll see what I can do

Regards
Mehdi
Dadou is offline   Reply With Quote

Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
CentFOAM Python Script Installation: Error socon009 OpenFOAM Installation 2 May 26, 2012 10:36
emag beta feature: charge density charlotte CFX 4 March 22, 2011 11:14
error in COMSOL:'ERROR:6164 Duplicate Variable' bhushas Main CFD Forum 1 May 30, 2008 05:35
Env variable not set gruber2 OpenFOAM Installation 5 December 30, 2005 05:27
Replace periodic by inlet-outlet pair lego CFX 3 November 5, 2002 21:09


All times are GMT -4. The time now is 20:39.