Field Output Example
Location: examples/rappture2/field/
Demonstrates 2D and 3D scalar fields. The 2D field renders as a heatmap; the 3D field renders as isosurfaces or a point cloud depending on the mesh type.
Inputs
Formula – a mathematical expression in x, y, z (e.g.
x*y*z)3D Rendering – uniform grid (isosurface) or unstructured mesh
How to create a 2D field
A field requires two parts: a mesh definition and field values.
Define the mesh:
m2d = rx['output.mesh(m2d)']
m2d['dim'] = 2
m2d['units'] = 'um'
m2d['hide'] = 'yes'
m2d['grid.xaxis.min'] = 0
m2d['grid.xaxis.max'] = 4
m2d['grid.xaxis.numpoints'] = 5
m2d['grid.yaxis.min'] = 0
m2d['grid.yaxis.max'] = 4
m2d['grid.yaxis.numpoints'] = 5
Write field values on the mesh:
f2d = rx['output.field(f2d)']
f2d['about.label'] = '2D Field'
f2d['component.mesh'] = 'output.mesh(m2d)'
f2d['component.values'] = numpy_2d_array
3D uniform grid mesh
m3d = rx['output.mesh(m3d)']
m3d['dim'] = 3
m3d['grid.xaxis.numpoints'] = 5
m3d['grid.yaxis.numpoints'] = 5
m3d['grid.zaxis.numpoints'] = 2
3D unstructured mesh (point cloud)
m3d['unstructured.points'] = "x1 y1 z1\nx2 y2 z2\n..."
The heatmap viewer supports colorscale selection, zoom/pan, heightmap view, and download as PNG/SVG.
tool.xml
<?xml version="1.0"?>
<run xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../rappture2web/contract.xsd">
<tool>
<title>field (rappture2web)</title>
<about>Example of a Rappture <field> object.
Fields are a set of values defined on a mesh. When you click Simulate, the inputs generate output fields.
</about>
<command>python3 @tool/field.py @driver</command>
<contract>
<input>
<string id="formula">
<about>
<label>Formula</label>
<description>Formula used to calculate the value of the field.</description>
</about>
<default>x*y*z</default>
</string>
<choice id="3D">
<about>
<label>3D Rendering</label>
<description>Determines the mesh type and method used for 3D rendering</description>
</about>
<option>
<about><label>Isosurface (Uniform Grid)</label><description>Renders a series of isosurfaces using a uniform 3D grid mesh.</description></about>
<value>grid</value>
</option>
<option>
<about><label>Isosurface (Unstructured Grid)</label><description>Renders a series of isosurfaces using an unstructured 3D grid mesh.</description></about>
<value>unstructured</value>
</option>
<default>grid</default>
</choice>
</input>
<output>
<mesh id="m2d"><about><label>2D Mesh</label><description>Hidden mesh used by the 2D field output.</description></about></mesh>
<field id="f2d"><about><label>2D Field</label><description>Two-dimensional field evaluated from the formula.</description></about></field>
<mesh id="m3d"><about><label>3D Mesh</label><description>Hidden mesh used by the 3D field output.</description></about></mesh>
<field id="f3d"><about><label>3D Field</label><description>Three-dimensional field evaluated from the formula.</description></about></field>
</output>
</contract>
</tool>
<input>
<string id="formula">
<about>
<label>Formula</label>
<description>Formula used to calculate the value of the field.</description>
<hints>Example: 2*x*y + z</hints>
</about>
<default>x*y*z</default>
</string>
<separator/>
<choice id="3D">
<about>
<label>3D Rendering</label>
<description>Determines the mesh type and method used for 3D rendering</description>
</about>
<option>
<about>
<label>Isosurface (Uniform Grid)</label>
<description>Renders a series of isosurfaces using a uniform 3D grid mesh.</description>
</about>
<value>grid</value>
</option>
<option>
<about>
<label>Isosurface (Unstructured Grid)</label>
<description>Renders a series of isosurfaces using an unstructured 3D grid mesh.</description>
</about>
<value>unstructured</value>
</option>
<default>grid</default>
</choice>
</input>
</run>
Running
rappture2web examples/rappture2/field/