|
[Sponsors] |
[OpenFOAM] Exporting screenshots from paraview with pvbatch |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
September 23, 2017, 07:22 |
Exporting screenshots from paraview with pvbatch
|
#1 |
New Member
Lennart Steffen
Join Date: Mar 2017
Location: Braunschweig, Germany
Posts: 17
Rep Power: 9 |
Hello there,
I'm running simulations via VPN+ssh on a remote computer. Therefore, viewing results with the ParaView-GUI isn't really an option. That's why I wrote a pvbatch (python) script to load VTK files, take screenshots of the results of the quantity alpha (particle volume fraction) and export them as .png files. This is my code: Code:
import sys import os print("Running batchExport.py ...") # set current path as case path casePath = os.getcwd() # extract caseName from path caseName = casePath.replace('/', 'X', casePath.count('/') - 1) caseName = caseName[(caseName.find('/') + 1):] # add trailing slash casePath = casePath + '/' # first argument contains number of frames frames = int(sys.argv[1]) # second argument contains time step step = float(sys.argv[2]) try: paraview.simple except: from paraview.simple import * paraview.simple._DisableFirstRenderCameraReset() AnimationScene1 = GetAnimationScene() AnimationScene1.EndTime = (frames-1)*step AnimationScene1.PlayMode = 'Snap To TimeSteps' RenderView1 = GetRenderView() # declare list for filenames files = [] for i in range(frames): # define file names file = casePath + 'VTK/' + caseName + '_' + str(int(i*step)) + ".vtk" # append file name to list for VTKReader files.append(file) #read files reader = LegacyVTKReader( FileNames=files ) DataRepresentation1 = Show() DataRepresentation1.EdgeColor = [0.0, 0.0, 0.5] DataRepresentation1.SelectionPointFieldDataArrayName = 'alpha' DataRepresentation1.SelectionCellFieldDataArrayName = 'alpha' DataRepresentation1.ScalarOpacityUnitDistance = 0.004 DataRepresentation1.ExtractedBlockIndex = 2 DataRepresentation1.ScaleFactor = 0.02 RenderView1.CenterOfRotation = [0.04, 0.05, 0.025] RenderView1.CameraPosition = [0.04, 0.05, 0.4522] RenderView1.CameraFocalPoint = [0.04, 0.05, 0.025] RenderView1.CameraClippingRange = [0.373175, 0.5] RenderView1.CameraParallelScale = 0.110567 a1_alpha_PVLookupTable = GetLookupTableForArray( "alpha", 1, RGBPoints=[0.0, 0.0, 0.0, 1.0, 0.635, 1.0, 0.0, 0.0], VectorMode='Magnitude', NanColor=[0.498039, 0.498039, 0.498039], ColorSpace='HSV', ScalarRangeInitialized=1.0, LockScalarRange=1 ) a1_alpha_PiecewiseFunction = CreatePiecewiseFunction( Points=[0.0, 0.0, 0.5, 0.0, 0.635, 1.0, 0.5, 0.0] ) DataRepresentation1.ScalarOpacityFunction = a1_alpha_PiecewiseFunction DataRepresentation1.ColorArrayName = ('CELL_DATA', 'alpha') DataRepresentation1.LookupTable = a1_alpha_PVLookupTable DataRepresentation1.ColorAttributeType = 'CELL_DATA' ScalarBarWidgetRepresentation1 = CreateScalarBar( Title='alpha', LabelFontSize=12, Enabled=1, LookupTable=a1_alpha_PVLookupTable, TitleFontSize=12 ) GetRenderView().Representations.append(ScalarBarWidgetRepresentation1) a1_alpha_PVLookupTable.ScalarOpacityFunction = a1_alpha_PiecewiseFunction AnimationScene1 = GetAnimationScene() print('Exporting...') for i in range(frames): print('Current frame: ' + str(i) + '/' + str(frames - 1)) AnimationScene1.AnimationTime = float(i*step) Render() WriteImage(casePath + 'Animation/' + str(i*step) + '.png') Code:
#!/bin/bash # for VTK conversion, reconstruct data reconstructPar # convert binaries to VTK (I excluded all patches to only get internalField) foamToVTK -fields '(alpha)' -excludePatches '(inandouthalf11 inandouthalf12 inandouthalf21 inandouthalf22 top walls frontAndBackPlanes)' -useTimeName # remove reconstructed data foamListTimes -rm -noZero -time 0: # get number of time steps written timeSteps=$(foamListTimes -withZero -processor | wc -l) # get latest time latestTime=$(foamListTimes -processor | tail -n 1) # get write interval from controlDict sS="writeInterval" wI=$(grep -i $sS system/controlDict) # trim wI=${wI//;/} wI=${wI// /} wI=${wI#$sS} writeInterval=$wI # create the directory for the script mkdir Animation # first argument is number of time steps, second argument is time step pvbatch --use-offscreen-rendering batchExport.py $timeSteps $writeInterval
I searched online for both issues, but to no avail. Any feedback would be greatly appreciated. The OpenFOAM version on the remote server is 2.4.0, so the ParaView version should be 4.1.0. Lennart |
|
Tags |
openfoam, paraview, pvbatch, pvpython |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
[General] Paraview parallel processing with pvbatch | wouterremmerie | ParaView | 2 | February 26, 2020 11:41 |
[General] Exporting exact data on paraview | solalito | ParaView | 1 | August 21, 2013 12:50 |
[OpenFOAM] paraFoam / paraview crashes when exporting images/animation | griztown | ParaView | 5 | March 28, 2012 19:14 |
paraFoam reader for OpenFOAM 1.6 | smart | OpenFOAM Installation | 13 | November 16, 2009 22:41 |
Exporting Fluent vector data into Paraview | JT | FLUENT | 2 | December 29, 2008 19:09 |