CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Visualization & Post-Processing Software > ParaView

[OpenFOAM] 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 Search this Thread 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: 65
Rep Power: 12
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
Senior Member
 
Eloïse
Join Date: Jul 2012
Location: Trondheim, Norway
Posts: 113
Rep Power: 13
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: 65
Rep Power: 12
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
Senior Member
 
Eloïse
Join Date: Jul 2012
Location: Trondheim, Norway
Posts: 113
Rep Power: 13
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: 65
Rep Power: 12
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 Search this Thread
Search this Thread:

Advanced Search
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 Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
[General] Python script to sum up a variable for all cells hconel ParaView 1 February 7, 2019 18:59
[General] python script to group/append datasets ufocfd ParaView 0 July 30, 2018 17:25
[OpenFOAM] Get cell center coordinates in a python script francois ParaView 2 June 3, 2017 09:20
[General] Using variables defined in a Python script on a Paraview/Python Calculator gafxian87 ParaView 0 June 8, 2015 14:18
[General] Using time in Python script lingdeer ParaView 0 August 11, 2014 02:57


All times are GMT -4. The time now is 04:32.