Skip to content
Mikael Mortensen edited this page Aug 15, 2017 · 6 revisions

The StructuredGrid class can be used to set probes in a 2D slice of a 3D (or 2D) geometry - or it can be used to set probes in a 3D box for some interesting part of the simulated geometry. We consider first a simple UnitCubeMesh and extract information from a box in the center that extends 0.5 units in all three directions:

mesh = UnitCubeMesh(10, 10, 10)
V = FunctionSpace(mesh, 'CG', 2)

# Create a Function s0 that we will Probe
s0 = interpolate(Expression("exp(-(pow(x[0]-0.5, 2)+pow(x[1]-0.5, 2)+pow(x[2]-0.5, 2)))"), V)

# Set the parameters for a 3D structured grid
origin = [0.25, 0.25, 0.25]                    # origin of 3D box
vectors = [[1, 0, 0], [0, 1, 0], [0, 0, 1]]    # coordinate vectors
dL = [0.5, 0.5, 0.5]                           # extent of vectors in all directions
N  = [5, 4, 3]                                 # number of points in each direction
    
# Create an instance of the StructuredGrid class, probe and dump results
sl = StructuredGrid(V, N, origin, vectors, dL)
sl(s0)     # probe once
sl(s0)     # probe once more
sl.tovtk(0, filename="dump_scalar.vtk")   # dump first snapshot to vtk
sl.toh5(0, 1, 'dump_scalar.h5')           # dump first snapshot to HDF5 format

Opening the file "dump_scalar.vtk" in ParaView it can be plotted as shown here:

Cube from StructuredGrid

The HDF5 format can be used by Voluviz - a 3D volume visualization software developed at the Norwegian Defence Research Establishment. Voluviz is a direct volume rendering application based on SGI's OpenGL Volumizer 2 and OpenGL. A snapshot of the sphere represented by the Function s0 in "dump_scalar.h5" is shown here with a subset:

Cube from Voluviz

By default the StructuredGrid class uses the regular Probes. To set the class to use StatisticsProbes instead one has to supply the keyword

sl = StructuredGrid(V, N, origin, vectors, dL, statistics=True)
sl(u0, v0, w0)                            # eval velocities
sl.tovtk(0, "dump_averages.vtk")          # Dump all average velocities and Reynolds stresses
sl.tovtk(1, "dump_latest_snapshot.vtk")   # Only dump velocities

Clone this wiki locally