2D Flow Field Example
Location: examples/rappture2/flow2d/
Simulates 2D lid-driven cavity flow and visualizes the velocity field as colored arrows.
Inputs
Grid Size – N x N grid resolution
Kinematic Viscosity – fluid viscosity (affects Reynolds number)
Lid Velocity – speed of the moving lid
Key concepts
Vector field output (3-component per point):
# Interleaved vx, vy, vz values
vec_text = "\n".join(
f"{vx[k]} {vy[k]} 0.0" for k in range(npoints)
)
rx['output.field(velocity).component.mesh'] = 'output.mesh(grid)'
rx['output.field(velocity).component.values'] = vec_text
rx['output.field(velocity).component.extents'] = '3'
extents=3tells the renderer this is a 3-component vector field.rappture2web renders vector fields as colored arrows.
Use
about.groupto overlay vector and scalar fields on the same view.
tool.xml
<?xml version="1.0"?>
<run xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../rappture2web/contract.xsd">
<tool>
<title>2D Flow Visualizer</title>
<about>Simulates 2D lid-driven cavity flow using a simple iterative solver and visualises the resulting velocity field as arrows coloured by magnitude.</about>
<command>python3 @tool/flow2d.py @driver</command>
<contract>
<input>
<integer id="npts">
<about>
<label>Grid Size</label>
<description>Number of grid points along each axis (N×N grid).</description>
</about>
<min>8</min>
<max>40</max>
<default>20</default>
</integer>
<number id="viscosity">
<about>
<label>Kinematic Viscosity</label>
<description>Fluid viscosity (affects Reynolds number).</description>
</about>
<units>m2/s</units>
<min>0.001m2/s</min>
<max>1.0m2/s</max>
<default>0.1m2/s</default>
</number>
<number id="lid_vel">
<about>
<label>Lid Velocity</label>
<description>Velocity of the moving lid at the top of the cavity.</description>
</about>
<units>m/s</units>
<min>0.1m/s</min>
<max>2.0m/s</max>
<default>1.0m/s</default>
</number>
</input>
<output>
<mesh id="grid"><about><label>Cavity Grid</label><description>Hidden mesh used by the cavity flow fields.</description></about></mesh>
<field id="velocity"><about><label>Velocity Field</label><description>Vector velocity field for the cavity flow.</description></about></field>
<field id="magnitude"><about><label>Velocity Magnitude</label><description>Scalar velocity magnitude field.</description></about></field>
</output>
</contract>
</tool>
<input>
<integer id="npts">
<about>
<label>Grid Size</label>
<description>Number of grid points along each axis (N×N grid).</description>
</about>
<min>8</min>
<max>40</max>
<default>20</default>
</integer>
<number id="viscosity">
<about>
<label>Kinematic Viscosity</label>
<description>Fluid viscosity (affects Reynolds number).</description>
</about>
<units>m2/s</units>
<min>0.001m2/s</min>
<max>1.0m2/s</max>
<default>0.1m2/s</default>
<preset>
<value>0.01m2/s</value>
<label>Low (Re≈100)</label>
</preset>
<preset>
<value>0.1m2/s</value>
<label>Medium (Re≈10)</label>
</preset>
<preset>
<value>0.5m2/s</value>
<label>High viscosity</label>
</preset>
</number>
<number id="lid_vel">
<about>
<label>Lid Velocity</label>
<description>Velocity of the moving lid at the top of the cavity.</description>
</about>
<units>m/s</units>
<min>0.1m/s</min>
<max>2.0m/s</max>
<default>1.0m/s</default>
</number>
</input>
</run>
Running
rappture2web examples/rappture2/flow2d/