Post.Probe: Probe extraction

Specific probe extraction module.

This page describes how the object-oriented Probe module operates. The various methods presented below should be used after instantiating a Probe object of the same-named class.

All of these methods and functions can be executed in both sequential and parallel contexts.

List of functions

– Probe creation

Post.Probe.Probe

Create Probe object to extract and save data during simulations.

– Probe methods

Probe.printInfo

Print information about a new probe.

Probe.prepare

Prepare the interpolation data for probe extraction in mode 3.

Probe.extract

Extract probe information.

Probe.flush

Flush buffered data to probe file.

Probe.read

Read data from existing probe file.

Contents

Probe creation

Post.Probe.Probe(fileName, t=None, X=None, ind=None, blockName=None, tPermeable=None, fields=None, append=False, bufferSize=100)

Create a Python object from the Probe class. Five modes are possible:

  • mode 0: if t and X are provided, the probe will extract the fields from t at the absolute position X=(x,y,z).

  • mode 1: if t and (ind, blockName) are provided, the probe will extract the fields from t at the given index of the specified block.

  • mode 2: if t is provided without a specific location (index or position), the probe will store all zones of t with both coordinates and fields. t must be 1D or 2D.

  • mode 3: if t and tPermeable are provided, the probe will interpolate the fields on tPermeable using t as the donor tree. tPermeable must be 1D or 2D.

  • mode 4: if t is not provided, the probe will simply store specified values over time.

Data are periodically flushed to probe file when the buffer size exceeds the user input bufferSize.

For Probe objects in modes 0, 1, or 4, all data are stored in 1D numpy arrays of size bufferSize.

For Probe objects in modes 2 or 3, the data are stored in 2D/3D numpy arrays of size (bufferSize,ni,nj) where (ni,nj) are the original dimensions of the receiver tree zones (t for mode 2 or tPermeable for mode 3).

Note

Modes 2 and 3 only operates with structured meshes.

Parameters:
  • fileName (string) – name of the probe file

  • t (pyTree) – pyTree containing the flow solution

  • X (tuple of 3 floats (x,y,z)) – absolute position of a single probe (mode 0 only)

  • ind (integer or tuple of 3 integers (i,j,k)) – index of a single probe located in blockName (mode 1 only)

  • blockName (string) – name of the block containing the probe index (mode 1 only)

  • tPermeable (pyTree, zone or list of zones) – interpolated tree (mode 3 only)

  • fields (list of strings) – list of fields to extract (located at the mesh nodes OR the mesh centers)

  • append (Boolean) – if True, append result to existing file

  • bufferSize (int) – size of internal buffer

Return type:

probe instance

Example of use:

# - Probe mode 0 (pyTree) -
import Post.Probe as Probe
import Converter.PyTree as C
import Generator.PyTree as G

# test case
a = G.cartRx((0,0,0), (1,1,1), (30,30,30), (5,5,5))
t = C.newPyTree(['Base', a])
C._initVars(t, '{centers:Fx} = {centers:CoordinateX}')
C._initVars(t, '{centers:Fy} = {centers:CoordinateY}')

# create a probe using mode 0
fields = ['centers:Fx', 'centers:Fy']
p0 = Probe.Probe('probe0.cgns', t, X=(10.,10.,10.), fields=fields, append=False, bufferSize=100)
p0.printInfo()

# extract probe information over time
for i in range(110):
    time = 0.1*i
    C._initVars(t, '{centers:Fx} = {centers:Fx} + cos(%f)'%time, isVectorized=True)
    C._initVars(t, '{centers:Fy} = {centers:Fx} + sin(%f)'%time, isVectorized=True)
    p0.extract(t, time=time)

# force probe flush
p0.flush()
# - Probe mode 1 (pyTree) -
import Post.Probe as Probe
import Converter.PyTree as C
import Generator.PyTree as G

# test case
a = G.cartRx((0,0,0), (1,1,1), (30,30,30), (5,5,5))
t = C.newPyTree(['Base', a])
C._initVars(t, '{centers:Fx} = {centers:CoordinateX}')
C._initVars(t, '{centers:Fy} = {centers:CoordinateY}')

# create a probe using mode 1
fields = ['centers:Fx', 'centers:Fy']
p1 = Probe.Probe('probe1.cgns', t, ind=(10,10,10), blockName='cart1-1-1', fields=fields, append=False, bufferSize=100)
p1.printInfo()

# extract probe information over time
for i in range(110):
    time = 0.1*i
    C._initVars(t, '{centers:Fx} = {centers:Fx} + cos(%f)'%time, isVectorized=True)
    C._initVars(t, '{centers:Fy} = {centers:Fx} + sin(%f)'%time, isVectorized=True)
    p1.extract(t, time=time)

# force probe flush
p1.flush()
# - Probe mode 2 (pyTree) -
import Post.Probe as Probe
import Converter.PyTree as C
import Transform.PyTree as T
import Geom.PyTree as D

# test case
b = D.cylinder((50,50,50), 10., 40., N=50, ntype='STRUCT')
tR = C.newPyTree(['Base', b])
C._initVars(tR, '{centers:Fx} = {centers:CoordinateX}')
C._initVars(tR, '{centers:Fy} = {centers:CoordinateY}')

# create a probe using mode 2
fields = ['centers:Fx', 'centers:Fy']
p2 = Probe.Probe('probe2.cgns', tR, fields=fields, append=False, bufferSize=100)
p2.printInfo()

# extract probe information over time
for i in range(110):
    time = 0.1*i
    T._rotate(tR, (50.,50.,50.), (0.,0.,1.), 0.1)
    C._initVars(tR, '{centers:Fx} = {centers:CoordinateX}')
    C._initVars(tR, '{centers:Fy} = {centers:CoordinateY}')
    p2.extract(tR, time=time)

# force probe flush
p2.flush()
# - Probe mode 3 (pyTree) -
import Post.Probe as Probe
import Converter.Internal as Internal
import Converter.PyTree as C
import Generator.PyTree as G
import Geom.PyTree as D

# test case
a = G.cartRx((0,0,0), (1,1,1), (30,30,30), (5,5,5))
t = C.newPyTree(['Base', a])
C._initVars(t, '{centers:Fx} = {centers:CoordinateX}')
C._initVars(t, '{centers:Fy} = {centers:CoordinateY}')

b = D.cylinder((50,50,50), 10., 40., N=50, ntype='STRUCT')
tR = C.newPyTree(['Base', b]) # receiver surface tree storing the interpolated flow variable data

tD = Internal.copyRef(t) # donor tree storing the interpolation data (interpolation coefficients)

# create a probe using mode 3
fields = ['centers:Fx', 'centers:Fy']
p3 = Probe.Probe('probe3.cgns', tPermeable=tR, fields=fields, append=False, bufferSize=100)

# compute the interpolation data for probe extraction (mode 3 only)
tD = p3.prepare(tD, loc='centers')

# extract probe information over time
for i in range(110):
    time = 0.1*i
    C._initVars(t, '{centers:Fx} = {centers:Fx} + cos(%f)'%time, isVectorized=True)
    C._initVars(t, '{centers:Fy} = {centers:Fx} + sin(%f)'%time, isVectorized=True)
    for varname in fields: C._cpVars(t, varname, tD, varname)
    tD = C.center2Node(tD, fields) # donor solution is located at the nodes
    p3.extract(tD, time=time)

# force probe flush
p3.flush()
# - Probe mode 4 (pyTree) -
import Post.Probe as Probe
import Converter.PyTree as C
import Converter.Internal as Internal
import Generator.PyTree as G

import numpy

# test case
a = G.cartRx((0,0,0), (1,1,1), (30,30,30), (5,5,5))
t = C.newPyTree(['Base', a])
C._initVars(t, '{centers:Fx} = {centers:CoordinateX}')
C._initVars(t, '{centers:Fy} = {centers:CoordinateY}')

# create a probe using mode 4
p4 = Probe.Probe('probe4.cgns', fields=['minFx', 'maxFx', 'minFy', 'maxFy'], append=False, bufferSize=100)
p4.printInfo()

# extract probe information over time
for i in range(110):
    time = 0.1*i
    maxFx, minFx = 0., 1.e6
    maxFy, minFy = 0., 1.e6
    C._initVars(t, '{centers:Fx} = {centers:Fx} + cos(%f)'%time, isVectorized=True)
    C._initVars(t, '{centers:Fy} = {centers:Fx} + sin(%f)'%time, isVectorized=True)
    for z in Internal.getZones(t):
        Fx = Internal.getNodeFromName(z, 'Fx')[1]
        Fy = Internal.getNodeFromName(z, 'Fy')[1]

        minFx = min(minFx, numpy.min(Fx))
        maxFx = max(maxFx, numpy.max(Fx))

        minFy = min(minFy, numpy.min(Fy))
        maxFy = max(maxFy, numpy.max(Fy))

    p4.extract(t, time=time, value=[minFx, maxFx, minFy, maxFy])

# force probe flush
p4.flush()

Probe methods

Probe.printInfo()[source]

printInfo is a method of the Probe class.

Print all the information about a probe object.

Example of use:

# - Probe printInfo (pyTree) -
import Post.Probe as Probe

# create a probe using mode 4
p4 = Probe.Probe('probe4.cgns', fields=['Density', 'Mach'], append=False, bufferSize=100)

# print all relevant information about the p4 probe object
p4.printInfo()

Probe.prepare(t, loc='nodes', extrap=1, nature=1, penalty=1, verbose=2)[source]

prepare is a method of the Probe class.

Only for mode 3. Prepare the interpolation data for probe extraction from a donor computational tree to a 1D or 2D receiver mesh.

The arguments are mostly the same as those for Connector.setInterpData2(). Donor tree flow fields must be located at the nodes. Receiver tree flow fields can be located at the nodes (loc=’nodes’) or at the centers (loc=’centers’).

If the cellN field (cell nature field) is not found in the donor tree, the function assumes that all cells are computed cells (cellN = 1). Similarly, if the cellN field is not found in the receiver tree, the function assumes that all cells are interpolated cells (cellN = 2).

extrap options:

  • 0: extrapolation is disabled. Extrapolated cells are flagged as orphans.

  • 1: extrapolation is enabled.

nature options:

  • 0: candidate donors can be everything but blanked cells (cellN = 0).

  • 1: candidate donors can only be computed cells (cellN = 1).

penalty options:

  • 0: all candidates have the same weight.

  • 1: donor cell candidates located at a zone border are penalized against interior cells.

verbose options:

  • 0: no information is printed.

  • 1: print only the summary of the interpolation data search.

  • 2: print the summary and indices of the orphan points (if any).

Parameters:
  • t (pyTree) – pyTree containing the flow solution

  • loc (string ('centers' or 'nodes')) – extraction location

  • extrap (integer (0 or 1)) – extrapolation parameter

  • nature (integer (0 or 1)) – donor cell nature parameter

  • penalty (integer (0 or 1)) – penalization parameter

  • verbose (integer (0, 1, or 2)) – print parameter

Example of use:

# - Probe prepare - centers (pyTree) -
import Post.Probe as Probe
import Converter.Internal as Internal
import Converter.PyTree as C
import Generator.PyTree as G
import Geom.PyTree as D

# test case
a = G.cart((0,0,0), (0.1,0.1,0.1), (11,11,11))
t = C.newPyTree(['Base', a])
C._initVars(t, '{centers:F} = {centers:CoordinateX}')

b = D.box((0.2,0.2,0.2), (0.7,0.7,0.7), 6, ntype='STRUCT')
tR = C.newPyTree(['Base', b]) # receiver surface tree storing the interpolated flow variable data

tD = Internal.copyRef(t) # donor tree storing the interpolation data (interpolation coefficients)

# create a probe using mode 3
p3 = Probe.Probe('probe3.cgns', tPermeable=tR, fields=['centers:F'], append=False, bufferSize=100)

# compute the interpolation data for probe extraction (mode 3 only)
C._initVars(tD, '{cellN} = 1') # donor solution is located at the nodes
C._initVars(tR, '{centers:cellN} = 2')
tD = p3.prepare(tD, loc='centers')
# - Probe prepare - nodes (pyTree) -
import Post.Probe as Probe
import Converter.Internal as Internal
import Converter.PyTree as C
import Generator.PyTree as G
import Geom.PyTree as D

# test case
a = G.cart((0,0,0), (0.1,0.1,0.1), (11,11,11))
t = C.newPyTree(['Base', a])
C._initVars(t, '{F} = {CoordinateX}')

b = D.box((0.2,0.2,0.2), (0.7,0.7,0.7), 6, ntype='QUAD')
tR = C.newPyTree(['Base', b]) # receiver surface tree storing the interpolated flow variable data

tD = Internal.copyRef(t) # donor tree storing the interpolation data (interpolation coefficients)

# create a probe using mode 3
p3 = Probe.Probe('probe3.cgns', tPermeable=tR, fields=['F'], append=False, bufferSize=100)

# compute the interpolation data for probe extraction (mode 3 only)
C._initVars(tD, '{cellN} = 1') # donor solution is located at the nodes
C._initVars(tR, '{cellN} = 2')
tD = p3.prepare(tD, loc='nodes')

Probe.extract(t=None, time=-1., value=[], onlyTransfer=False)[source]

extract is a method of the Probe class.

Extract the probe information (coordinates and field) at a given time from t.

Flow solution and grid coordinate extractions from the donor tree t are based on the information located in the Internal.__FlowSolutionNodes__, Internal.__FlowSolutionCenters, and Internal.__FlowSolutionCenters__ containers. Users can modify these container names by editing the constant names in the Internal module. New containers are created each time the local buffer size exceeds the bufferSize limits specified by the user.

Probe information data is then stored in the following fixed container names: GridCoordinates#i, FlowSolution#i, and FlowSolution#Centers#i, where i is an iterator that is automatically set and handled by the Probe class.

To extract the receiver tree interpolated data at a given time without stacking the information (coordinates and field) in the probe, set onlyTransfer to True for mode 3. This option is useful when users only want to monitor integral quantities instead of monitoring all solution fields over time.

Parameters:
  • t (pyTree) – pyTree containing the flow solution

  • time (float) – extraction time

  • value (list of floats) – list of values to be stored in probe (only for mode 4)

  • onlyTransfer (boolean) – deactivate information stacking in the probe object (only for mode 3)

Example of use:

Note

for simpler examples of each mode, see the Post.Probe.Probe function definition.

# - Probe extract (pyTree) -
import Post.Probe as Probe
import Converter.Internal as Internal
import Converter.PyTree as C
import Generator.PyTree as G
import Post.PyTree as P

# test case
a = G.cart((0,0,0), (0.1,0.1,0.1), (51,11,11))
t = C.newPyTree(['Base', a])
C._initVars(t, '{Density} = 1.')
C._initVars(t, '{VelocityX} = {CoordinateX}-1')
C._initVars(t, '{VelocityY} = {CoordinateY}-1')
C._initVars(t, '{VelocityZ} = {CoordinateZ}-1')

b1 = G.cart((0,0,0), (0.,0.1,0.1), (1,11,11)); b1[0] = 'upstream'
b2 = G.cart((5,0,0), (0.,0.1,0.1), (1,11,11)); b2[0] = 'downstream'
tR = C.newPyTree(['Base', [b1,b2]])
G._getSmoothNormalMap(tR)

tD = Internal.copyRef(t)

# create a first probe using mode 3
fields = ['Density', 'VelocityX', 'VelocityY', 'VelocityZ']
p3 = Probe.Probe('probe3.cgns', tPermeable=tR, fields=fields, append=False, bufferSize=100)
tD = p3.prepare(tD, loc='nodes')

# create a second probe using mode 4
p4 = Probe.Probe('probe4.cgns', fields=['massflow_upstream', 'massflow_downstream'], bufferSize=100, append=False)

# extract flow information on the receiver surface tree
for varname in fields: C._cpVars(t, varname , tD, varname)
p3.extract(tD, onlyTransfer=True)

# tR interpolated data are now updated: integral quantities can be computed on each surface
C._initVars(tR, '{massflow}={Density}*({sx}*{VelocityX}+{sy}*{VelocityY}+{sz}*{VelocityZ})')

z_upstream = Internal.getNodeFromName(tR, 'upstream')
massflow_upstream = P.integ(z_upstream, 'massflow')[0]

z_downstream = Internal.getNodeFromName(tR, 'downstream')
massflow_downstream = P.integ(z_downstream, 'massflow')[0]

# store data information in the p4 probe using single integrated values
p4.extract(time=1, value=[massflow_upstream, massflow_downstream])

p4.flush()

Probe.flush()[source]

flush is a method of the Probe class.

Force buffered data to be written in the associated probe file before reaching the user input bufferSize limit.

Example of use:

# - Probe flush (pyTree) -
import Post.Probe as Probe

# create a probe using mode 4
p4 = Probe.Probe('probe4.cgns', fields=['Density', 'Mach'], append=False, bufferSize=100)

for i in range(110):
    p4.extract(time=i*0.1, value=[i, i*10])
    # p4 will automatically flushed itself when reaching the buffer size limit (100)

# flush current buffered data to disk to save last extractions
p4.flush()

Probe.read(cont=None, ind=None, probeName=None)[source]

Read the data stored in the probe file and return either a zone or a list of zones.

The Probe object must already be instantiated with the desired probe file name. Otherwise, use Post.Probe.Probe(fileName) to create a new probe object from an existing probe file for reading purposes only.

Can be used in two ways:

  • extract all points: if cont is provided, this function extracts all data from the given time container.

  • extract all times: if ind and probeName are provided, this function now extracts the given index value(s) of the given zone at all times.

If ind is provided but probeName is not, the function will automatically selects the first zone in the probe.

When extracting all points, the output is a list of zones. Each zone corresponds to a probe zone at a single time included in the loaded container.

When extracting all times, the output is a single zone. This zone contains numpy arrays of size (ntime,npoints) depending on the number of point indices provided.

Note

For modes 0, 1, and 4, probes consist of only one zone named ‘probe’. For modes 2 and 3, probes contain the same number of zones as the original tree (t for mode 2 or tPermeable for mode 3).

Parameters:
  • cont (integer) – time container number

  • ind (integer, tuple of 3 integers (i,j,k), list of integers, or list of tuples of 3 integers [(i1,j1,k1), (i2,j2,k2), ...]) – index (or indices) of probe point(s) located in probeName

  • probeName (string or int) – only used when ind is provided. Name or number of the probe zone to extract

Return type:

zone or list of zones

Example of use:

# - Probe read (pyTree) -
import Post.Probe as Probe
import Converter.PyTree as C
import Converter.Internal as Internal
import Generator.PyTree as G

# test case
a = G.cartRx((0,0,0), (1,1,1), (30,30,30), (5,5,5))
t = C.newPyTree(['Base', a])
C._initVars(t, '{centers:Fx} = {centers:CoordinateX}')
C._initVars(t, '{centers:Fy} = {centers:CoordinateY}')

# create a probe using mode 1
fields = ['centers:Fx', 'centers:Fy']
p1 = Probe.Probe('probe1.cgns', t, ind=(10,10,10), blockName='cart1-1-1', fields=fields, append=False, bufferSize=100)
p1.printInfo()

# extract probe information over time
for i in range(210):
    time = 0.1*i
    C._initVars(t, '{centers:Fx} = {centers:Fx} + cos(%f)'%time, isVectorized=True)
    C._initVars(t, '{centers:Fy} = {centers:Fx} + sin(%f)'%time, isVectorized=True)
    p1.extract(t, time=time)

# flush current buffered data to disk to save last extractions
p1.flush()

# reread probe from file (not necessary here as the probe object p1 is already loaded)
p1 = Probe.Probe('probe1.cgns')

# extract all points
out = p1.read(cont=0) # get all the information located in the first container
Internal.printTree(out) # list of 100 zones named 'probe@it' where 'it' goes from 0 to 99 (bufferSize-1)

# extract all times
out = p1.read(ind=0, probeName=0) # get all the information over time of the first point of the first probe zone
Internal.printTree(out) # mono zone with numpy arrays of size 210