Advecting Flow Paths

Vapor can advect and render flow paths through your data.

import example_utils
from vapor import session, renderer, dataset, camera

ses = session.Session()
data = example_utils.OpenExampleDataset(ses)
Warning: sysroot "/Applications/Xcode_12.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk" not found (ignoring for now).
Vapor 3.9.3
Python 3.9.19 (/opt/anaconda3/envs/vapor)
OpenGL 4.1 Metal - 83.1

Default advection

When you create a Flow renderer, the default advection will create a regularly dispersed grid of seed points and simulate a streamline advection in 2D or 3D, depending on the provided variables.

# Use first 2 2D variables as our U,V for the flow advection
dimension = 2
U,V = data.GetDataVarNames(dimension)[0:2]

ren:renderer.FlowRenderer = data.NewRenderer(renderer.FlowRenderer)
ren.SetFieldVariableNames([U, V])
ses.GetCamera().ViewAll()
ses.Show()
../_images/cb04e6e8c0107ebf850daa4f60bdee8db80d3935c8c2679de388641c9285bb38.png

Rendering techniques

The rendering of the flow paths can be configured. A few examples are shown below. Call help(renderer.FlowRenderer) to see additional options.

ren.SetRenderType(ren.RenderType.RenderTypeStream)
ren.SetRenderRadiusScalar(3)
ren.SetRenderGeom3D(True)
ren.SetColorMapVariableName(U)
ses.Show()
../_images/9d760d377c6aa9f5b91d7ff39bb2a60e80c3b3d85739b48d98c25d7edf274099.png

Rather than rendering the flow lines, you can also render the sample points that are taken along the flow path individually.

ren.SetRenderType(ren.RenderType.RenderTypeSamples)
ses.Show()
../_images/353ee41374e848f07005f58512441ab40b3133b4c9a893df0093390e3a6eeda0.png
ren.SetRenderGlyphType(ren.GlpyhType.GlpyhTypeArrow)
ren.SetRenderRadiusScalar(7)
ses.Show()
../_images/ad02b0ea0c8f591775277477ce84afa6ae238e7c52e97f43be5742efefa61cc1.png
# Reset the rendering style for the next section
ren.SetRenderRadiusScalar(3)
ren.SetRenderType(ren.RenderType.RenderTypeStream)

Seeding the advection

The seeds from which the advected particles start can be configured in a variety of manners. Call help(renderer.FlowRenderer) to see additional options.

Uniform Distribution

This is the default. It creates a uniformly distributed grid of seed points over the area/volume of the advected region.

ren.SetSeedGenMode(ren.FlowSeedMode.UNIFORM)
rake = ren.GetRakeRegion()
defaultRakeExtents = rake.GetExtents()
rake.SetExtents((20, 20), (40, 40))
print(f"Seeding a {ren.GetGridNumOfSeeds()} grid over {rake.GetExtents()}")
ses.Show()
rake.SetExtents(*defaultRakeExtents)
Seeding a [5, 5] grid over ([20.0, 20.0, 0.0], [40.0, 40.0, 0.0])
../_images/e15d70414c34cb747bca8894031ae0d28566c93f8fd9b4d18a26d2306405556a.png

Random Distribution

ren.SetSeedGenMode(ren.FlowSeedMode.RANDOM)
print(f"Seeding {ren.GetRandomNumOfSeeds()} random points over {rake.GetExtents()}")
ses.Show()
Seeding 50 random points over ([0.0, 0.0, 0.0], [63.0, 63.0, 63.0])
../_images/a3852ba6059e3a408eacfdc0089fb7c00ebf854af8d96a05b065d2737d047943.png

Biased Distribution

This generates a random list of seed points however they are biased by a given variable. The number of seed points can be higher or lower based on the value of the RakeBiasVariable. You can set the RakeBiasStrength to a negative value to invert the bias.

ren.SetSeedGenMode(ren.FlowSeedMode.RANDOM_BIAS)
ren.SetRakeBiasVariable(V)
ren.SetRakeBiasStrength(1)
print(f"Seeding {ren.GetRandomNumOfSeeds()} random points biased by {ren.GetRakeBiasVariable()} over {rake.GetExtents()}")
ses.Show()
Seeding 50 random points biased by V10 over ([0.0, 0.0, 0.0], [63.0, 63.0, 63.0])
../_images/7acbcb2fe42f09690a835211fb2e9077ced67f50e2ef0e538786c30d5ce6d7a4.png

Manual List

You can pass in a manually created list of seeds using a basic text file format. The code below generates an example seed file and passes it to Vapor. The full documentation for the seed file format can be found on Vapor’s website.

with open("flow_seeds.txt", "w") as f:
    print("# X, Y, Z, T (optional)", file=f)
    print("10, 10, 0", file=f)
    print("20, 20, 0", file=f)

ren.SetSeedGenMode(ren.FlowSeedMode.LIST)
ren.SetSeedInputFilename("flow_seeds.txt")
ses.Show()
../_images/7d1d98e82c86db5c7fcb1ae2064381fdac9754d995a88e2e255d136f0a52703f.png