Created
September 17, 2015 16:10
-
-
Save cwsmith/72343a4038f9c0918607 to your computer and use it in GitHub Desktop.
paraview parallel surface extraction script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#### import the simple module from the paraview | |
from paraview.simple import * | |
import sys | |
import os | |
from mpi4py import MPI | |
""" | |
mpirun -n <#cores> pvpython ExtractSurfaceParallel.py </location/of/file.pvtu> </location/of/output/folder> | |
""" | |
#### disable automatic camera reset on 'Show' | |
paraview.simple._DisableFirstRenderCameraReset() | |
#### set up inputs | |
inputFile = os.path.basename(sys.argv[1]) | |
inputDir = os.path.dirname(sys.argv[1]) | |
if( inputDir == "" ): | |
inputDir="." | |
outputDir = sys.argv[2] | |
if( outputDir == "" ): | |
sys.exit("YOU Failed to specify an output directory\n") | |
f = open(inputDir+'/'+sys.argv[1],'r') | |
outputPVTP = outputDir+'/'+inputFile[:-4]+'pvtp' | |
def setUpPVTP(piece): | |
# check if piece file name is local or global | |
if(piece.startswith('/')): | |
inputFileName = piece | |
else: | |
inputFileName = inputDir+'/'+piece | |
# create a new 'XML Unstructured Grid Reader' | |
part = XMLUnstructuredGridReader(FileName=[inputFileName]) | |
# create a new 'Extract Surface' | |
surface = ExtractSurface(Input=part) | |
# create a temporary pvtp file, that contains the field info, but only one source | |
# go in later, and put all the piece info correctly in it | |
v = XMLPPolyDataWriter(FileName=outputPVTP, Input=surface,DataMode=0) | |
v.UpdatePipeline() | |
Delete(surface) | |
del surface | |
Delete(part) | |
del part | |
vtpFile=outputDir+'/'+os.path.basename(inputFile)[:-5]+'_0.vtp' | |
if( not os.path.isfile(vtpFile) ): | |
sys.exit("The file that we expect to exist does not... exiting\n") | |
os.system('rm '+vtpFile) | |
def extract(piece,id): | |
# check if piece file name is local or global | |
if(piece.startswith('/')): | |
inputFileName = piece | |
else: | |
inputFileName = inputDir+'/'+piece | |
part = XMLUnstructuredGridReader(FileName=[inputFileName]) | |
# create a new 'Extract Surface' | |
surface = ExtractSurface(Input=part) | |
# save data | |
fn = outputDir+'/'+str(int(id/1000))+'/'+piece[:-3]+'vtp' | |
1,1 Top |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment