CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   ParaView (https://www.cfd-online.com/Forums/paraview/)
-   -   [OpenFOAM] Python script for Integrate Variable (https://www.cfd-online.com/Forums/paraview/118628-python-script-integrate-variable.html)

Dadou May 31, 2013 05:09

Python script for Integrate Variable
 
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

Eloise July 4, 2013 10:25

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

Dadou July 5, 2013 03:37

Hi Eloise,

Nop any progress unfortunately, do you have any idea ?

Regards

Mehdi

Eloise July 5, 2013 04:02

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

Dadou July 5, 2013 05:38

I'll look it up.

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

Regards :)
Mehdi


All times are GMT -4. The time now is 03:41.