CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > OpenFOAM Post-Processing

Exporting screenshots from paraview with pvbatch

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

Reply
 
LinkBack Thread Tools Display Modes
Old   September 23, 2017, 06:22
Default Exporting screenshots from paraview with pvbatch
  #1
New Member
 
Lennart Steffen
Join Date: Mar 2017
Location: Braunschweig, Germany
Posts: 7
Rep Power: 2
RL-S is on a distinguished road
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')
Now, this works well enough for me, which is why I wanted to share the code. Keep in mind that you still need to feed it with arguments for the number of frames to export (= number of VTK files to read from) and the time step between them (has to be consistent). This bash script is how I call the pvbatch script:

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
However, there are still two issues with it:

  1. At the end of the code's execution, I get the error message
    Code:
    Inconsistency detected by ld.so: dl-close.c: 811: _dl_close: Assertion `map->l_init_called' failed!
    Why is that and how can I get rid of it? The code still executes, but I'd like to know where the error is from.
  2. This is the more important issue: At a writeInterval of 0.5, the screenshots for a time period of 2s (four screenshots) always look completely the same. For example, the first four screenshots, at 0s, 0.5s, 1.0s and 1.5s all show the same result. Then there's a change between 1.5 and 2s, but then no change until and including 3.5s.
    Any ideas why that is? And maybe even how to fix it?

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
RL-S is offline   Reply With Quote

Reply

Tags
openfoam, paraview, pvbatch, pvpython

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
Installing OpenFOAM and ParaView in VirtualBox(Ubuntu on Win8) chrisb2244 OpenFOAM Installation 2 August 21, 2013 13:24
Exporting exact data on paraview solalito ParaView 1 August 21, 2013 11:50
paraFoam / paraview crashes when exporting images/animation griztown OpenFOAM Paraview & paraFoam 5 March 28, 2012 18: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


All times are GMT -4. The time now is 16:53.