# To be run using "Tools -> Python Shell -> Run Script" inside of paraFoam # assumes that one OpenFOAM-case is opened from PyFoam.RunDictionary.ParsedParameterFile import ParsedParameterFile from PyFoam.Basics.DataStructures import DictProxy from PyFoam.Paraview import caseDirectory from PyFoam.Paraview.SimpleSources import Point,Line from PyFoam.Paraview.SimpleFilters import Group from os import path sol=caseDirectory() ctrl=ParsedParameterFile( path.join(sol.systemDir(),"controlDict"), doMacroExpansion=True ) probes=[] sets=[] probeNr=0 setsNr=0 groupNr=0 grps=[]
# Displays important features of the snappyHexMeshDict # To be run using "Tools -> Python Shell -> Run Script" inside of paraFoam # assumes that one OpenFOAM-case is opened from PyFoam.RunDictionary.ParsedParameterFile import ParsedParameterFile from PyFoam.Paraview import caseDirectory from PyFoam.Paraview.SimpleSources import Sphere, Cube, STL, Point from os import path sol = caseDirectory() snap = ParsedParameterFile(path.join(sol.systemDir(), "snappyHexMeshDict")) pointInMesh = tuple(snap["castellatedMeshControls"]["locationInMesh"]) print "PointInMesh:", pointInMesh pt = Point("PointInMesh", pointInMesh) pt.repr.DiffuseColor = (1, 0, 0) geometries = [] for name, spec in snap["geometry"].iteritems(): if spec["type"] == "triSurfaceMesh": fn = path.join(sol.constantDir(), "triSurface", name) nm = spec["name"] print "STL:", fn, "Name:", nm ob = STL(nm, fn) elif spec["type"] == "searchableBox":
# Draws a vector in the direction of gravity # To be run using "Tools -> Python Shell -> Run Script" inside of paraFoam # assumes that one OpenFOAM-case is opened from PyFoam.Paraview import readerObject, caseDirectory from PyFoam.Paraview.SimpleSources import Glyph, Arrow from PyFoam.RunDictionary.ParsedParameterFile import ParsedParameterFile from os import path ro = readerObject() try: env = ParsedParameterFile( path.join(caseDirectory().constantDir(), "environmentalProperties")) g = env["g"][2] except IOError: env = ParsedParameterFile(path.join(caseDirectory().constantDir(), "g")) g = env["value"] #gly=Glyph("Gravity2D",ro.getCenter(),ro.getCenter()+0.5*g*abs(ro.getExtent())/abs(g)) gly = Arrow("Gravity", ro.getCenter(), ro.getCenter() + 0.5 * g * abs(ro.getExtent()) / abs(g)) gly.repr.DiffuseColor = (0, 0, 0)
# draws a vector in the direction of the gravity using vtk-primitves # to be used as a "Programmable Source" from PyFoam.RunDictionary.ParsedParameterFile import ParsedParameterFile from PyFoam.Paraview import caseDirectory from os import path import paraview env=ParsedParameterFile(path.join(caseDirectory().constantDir(),"environmentalProperties")) g=env["g"][2] pdo=self.GetPolyDataOutput() pdo.Allocate(1,1) pts=paraview.vtk.vtkPoints() pts.InsertPoint(0,(0.0,0.0,0.0)) pts.InsertPoint(1,g) line=paraview.vtk.vtkPolyLine() line.GetPointIds().SetNumberOfIds(2) line.GetPointIds().SetId(0,0) line.GetPointIds().SetId(1,1) pdo.InsertNextCell(line.GetCellType(), line.GetPointIds()) pdo.SetPoints(pts)
# draws a vector in the direction of the gravity using vtk-primitves # to be used as a "Programmable Source" from PyFoam.RunDictionary.ParsedParameterFile import ParsedParameterFile from PyFoam.Paraview import caseDirectory from os import path import paraview env = ParsedParameterFile( path.join(caseDirectory().constantDir(), "environmentalProperties")) g = env["g"][2] pdo = self.GetPolyDataOutput() pdo.Allocate(1, 1) pts = paraview.vtk.vtkPoints() pts.InsertPoint(0, (0.0, 0.0, 0.0)) pts.InsertPoint(1, g) line = paraview.vtk.vtkPolyLine() line.GetPointIds().SetNumberOfIds(2) line.GetPointIds().SetId(0, 0) line.GetPointIds().SetId(1, 1) pdo.InsertNextCell(line.GetCellType(), line.GetPointIds()) pdo.SetPoints(pts)