Hi,
I see that a number of posts exists concerning this topic but I do not see anything that I can use. I can calculate the force on an object by integrating the pressure over a surface over time. I can not understand how to use the plot over time feature. Below is a script where I write out a csv file for each time step and plot this data outside of paraview. Very awkward.
How can I plot directly with paraview?
I have tried to access the individual cells in a spreadsheet in a script but it appears not readily done. Can you provide any guidance on this?
I can access the integrated values for a time step using this
x=integrateVariables1.CellData
y=x.GetArray(‘Result’)
in an attempt to get the desired data but this is awkward too.
Can one assign data to a cell in a spreadsheet manually?
Any thoughts regarding this is much appreciated.
#### import the simple module from the paraview
from paraview.simple import *
#### disable automatic camera reset on 'Show'
paraview.simple._DisableFirstRenderCameraReset()
# create a new OpenFOAMReader
pfoam = OpenFOAMReader(FileName=r'pv.foam')
pfoam.CaseType = 'Decomposed Case'
pfoam.Decomposepolyhedra = 0
# get active view
renderView1 = GetActiveViewOrCreate('RenderView')
renderView1.ResetActiveCameraToPositiveY()
# reset view to fit data
renderView1.ResetCamera()
# create a new 'Clean to Grid'
cleantoGrid1 = CleantoGrid(Input=pfoam)
# show data in view
cleantoGrid1Display = Show(cleantoGrid1, renderView1)
# hide data in view
Hide(pfoam, renderView1)
# get color transfer function/color map for 'U'
ULUT = GetColorTransferFunction('U')
# trace defaults for the display properties.
cleantoGrid1Display.ColorArrayName = ['POINTS', 'U']
cleantoGrid1Display.LookupTable = ULUT
cleantoGrid1Display.EdgeColor = [0.0, 0.0, 0.5]
cleantoGrid1Display.ScalarOpacityUnitDistance = 0.05
# get animation scene
animationScene1 = GetAnimationScene()
# update animation scene based on data timesteps
animationScene1.UpdateAnimationUsingDataTimeSteps()
# go to the final timestep of the simulation
timesteps = pfoam.TimestepValues
finalTime = timesteps[-1]
animationScene1.AnimationTime = finalTime
# rescale color and/or opacity maps used to exactly fit the current data range
cleantoGrid1Display.RescaleTransferFunctionToDataRange(False, True)
# update the view to ensure updated data information
renderView1.Update()
# reset view to fit data
renderView1.ResetCamera(False)
#### disable automatic camera reset on 'Show'
paraview.simple._DisableFirstRenderCameraReset()
spreadSheetView1 = GetActiveViewOrCreate('SpreadSheetView')
extractBlock1 = ExtractBlock(registrationName='ExtractBlock1', Input=cleantoGrid1)
extractBlock1.Selectors = ['/Root']
extractSurface1 = ExtractSurface(registrationName='ExtractSurface1', Input=extractBlock1)
generateSurfaceNormals1 = GenerateSurfaceNormals(registrationName='GenerateSurfaceNormals1', Input=extractSurface1)
generateSurfaceNormals1.ComputeCellNormals = 1
calculator1 = Calculator(registrationName='Calculator1', Input=generateSurfaceNormals1)
calculator1.AttributeType = 'Cell Data'
calculator1.Function = 'p*Normals_X'
integrateVariables1 = IntegrateVariables(registrationName='IntegrateVariables1', Input=calculator1)
integrateVariables1Display = Show(integrateVariables1, spreadSheetView1, 'SpreadSheetRepresentation')
spreadSheetView1.FieldAssociation = 'Cell Data'
spreadSheetView1.Update()
spreadSheetView1.HiddenColumnLabels = ['Cell ID', 'alphat', 'Area', 'Cell Type', 'k', 'Ma', 'Normals', 'Normals_Magnitude', 'nut', 'p', 'pseudoCoField', 'rho', 'T', 'U', 'U_Magnitude']
x=integrateVariables1.CellData
y=x.GetArray('Result')
print(y.GetRange(0)[0])
# get animation scene
animationScene1 = GetAnimationScene()
#for i in range(len(timesteps)):
for i in range(5):
animationScene1.AnimationTime = timesteps[i]
ExportView(str(timesteps[i])+'_f.csv', view=spreadSheetView1)