pvpython and postprocessing

Dear all,

I am trying to automatise my post-processing of an OpenFOAM case using pvpython.

I obtain the result that I need and I want, however, I want to improve the code. I am really new, and it is my first time with pvpython/python and paraview.

The problem is that when I execute my pvpython code, I have a paraview GUI that opens while the code is running. But I do not want it to appear, I just want to execute the script and obtain the results without any extra window opening.

The code is built using the trace tool of paraview. I tried to suppress the code lines that open the windows but if I do so, the date do not get updated when I change the time (timestep) in which. E.g. I want to make the time average of a slice averaged property, if I do not show the window, the data, even if I do change properly the time step, do not get updated.

The code is the following:

import sys
import numpy as np
import os
import signal
import vtk.util.numpy_support as nps
import matplotlib.pyplot as plt
from numpy import linalg as LA
import math

from paraview.simple import *

testingFunctionsfoam = OpenFOAMReader(FileName=’/home/saddik/Desktop/LongerSim/LongerSim.foam’)
testingFunctionsfoam.MeshRegions = [‘internalMesh’]
testingFunctionsfoam.CellArrays = [‘H2’]
testingFunctionsfoam.Decomposepolyhedra = 0

animationScene1 = GetAnimationScene()

timeKeeper1 = GetTimeKeeper()
timesteps = timeKeeper1.TimestepValues
numTimesteps = len(timesteps)

animationScene1.UpdateAnimationUsingDataTimeSteps()

testingFunctionsfoam.SkipZeroTime = 0

renderView1 = GetActiveViewOrCreate(‘RenderView’)

layout1 = GetLayout()

materialLibrary1 = GetMaterialLibrary()

renderView1.Update()

renderView1.Update()

cellSize1 = CellSize(Input=testingFunctionsfoam)

cellSize1.ComputeVertexCount = 0
cellSize1.ComputeLength = 0
cellSize1.ComputeArea = 0

renderView1.Update()

SetActiveSource(cellSize1)
Data = servermanager.Fetch(cellSize1)

Data0 = Data.GetBlock(0)
Volume_i = Data0.GetCellData().GetArray(‘Volume’)

Volume_i_np = nps.vtk_to_numpy(Volume_i)
Volume_TOT = np.sum(Volume_i_np)

delta = []
for i in range(0, numTimesteps):
SetActiveSource(cellSize1)
Data = servermanager.Fetch(cellSize1)

Data0 = Data.GetBlock(0)

H2_i = Data0.GetCellData().GetArray(‘H2’)

H2_i_np = nps.vtk_to_numpy(H2_i)

H2_i_Volume_i = np.multiply(H2_i_np, Volume_i_np)

sumH2_i_Volume_i = np.sum(H2_i_Volume_i)

H2_avg = sumH2_i_Volume_i / Volume_TOT

H2_i_H2_avg_Volume_i = np.multiply(np.absolute(H2_i_np - H2_avg), Volume_i_np)

sum_H2_i_H2_avg_Volume_i = np.sum(H2_i_H2_avg_Volume_i)

if sumH2_i_Volume_i < 1e-16:
sumH2_i_Volume_i = 1
sum_H2_i_H2_avg_Volume_i = 0
delta_i = 1 - 0.5*(sum_H2_i_H2_avg_Volume_i/sumH2_i_Volume_i)

delta.append(delta_i)

SetActiveSource(cellSize1)

cellSize1Display = Show(cellSize1, renderView1, ‘GeometryRepresentation’)

renderView1.Update()

animationScene1.GoToNext()
print(i)
print(delta[i])

Basically, If I suppress the line

cellSize1Display = Show(cellSize1, renderView1, ‘GeometryRepresentation’)

The timestep do change but the information do not get updated.

I want to execute the code without any window opening.

Do you have any advice?

Thank you.

Try using pvbatch instead of pvpython or use the command line argument --force-offscreen-rendering to pvpython e.g. pvpython --force-offscreen-rendering ....script.py.

Thank you for your answer, let me try.

Is pvbatch as powerful as pvpython?

Is pvbatch as powerful as pvpython?

Yes, they exactly the same. pvbatch is intended for non-interactive use-cases (and distributed runs) while pvpython is intended for interactive ones.

It works perfectly, I just run the same scripts with pvbatch. Thank you very much for the advice.