UQ Simple Example

Location: examples/rappture2/uq_simple/

A minimal example demonstrating Uncertainty Quantification on a simple cosine wave.

Running

rappture2web examples/rappture2/uq_simple/

How to use

  1. Open the tool in the browser

  2. Next to Amplitude and Frequency, you’ll see a dropdown that says exact

  3. Change one or both to uniform or gaussian

  4. Fill in the distribution parameters (min/max for uniform; mean/std for gaussian)

  5. Click Simulate

The tool will run multiple times at Smolyak collocation points and produce UQ output:

  • PDF curves showing the probability distribution of scalar outputs

  • Probability bands on curve outputs

  • Sensitivity analysis showing which inputs matter most

tool.xml

<?xml version="1.0"?>
<run xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:noNamespaceSchemaLocation="../../../rappture2web/contract.xsd">
<tool>
  <title>UQ Simple Curve (rappture2web)</title>
  <about>Demonstrates Uncertainty Quantification on a simple curve.

When UQ is enabled, number inputs can be set to uniform or gaussian
distributions.  The tool runs multiple times at Smolyak collocation
points and PUQ fits a response surface, producing PDF and probability
band outputs.</about>
  <command>python3 @tool/uq_simple.py @driver</command>
  <uq>true</uq>
  <contract>
    <input>
      <number id="amplitude">
        <about>
          <label>Amplitude</label>
          <description>Amplitude scaling factor for the output curve.</description>
        </about>
        <min>0.1</min>
        <max>10</max>
        <default>2</default>
      </number>
      <number id="frequency">
        <about>
          <label>Frequency</label>
          <description>Frequency of the cosine wave in Hz.</description>
        </about>
        <units>Hz</units>
        <min>0.1Hz</min>
        <max>10Hz</max>
        <default>1Hz</default>
      </number>
      <integer id="points">
        <about>
          <label>Number of points</label>
          <description>Number of data points in the output curve.</description>
        </about>
        <min>10</min>
        <max>1000</max>
        <default>200</default>
      </integer>
    </input>
    <output>
      <curve id="wave">
        <about>
          <label>Output Wave</label>
          <description>A * cos(2*pi*f*x) plotted over [0, 10].</description>
        </about>
        <xaxis><label>Time</label><units>s</units></xaxis>
        <yaxis><label>Amplitude</label></yaxis>
      </curve>
      <number id="peak">
        <about>
          <label>Peak Value</label>
          <description>Maximum value of the output curve.</description>
        </about>
      </number>
    </output>
  </contract>
</tool>
<input>
  <number id="amplitude">
    <about>
      <label>Amplitude</label>
      <description>Amplitude scaling factor for the output curve.</description>
    </about>
    <min>0.1</min>
    <max>10</max>
    <default>2</default>
  </number>
  <number id="frequency">
    <about>
      <label>Frequency</label>
      <description>Frequency of the cosine wave in Hz.</description>
    </about>
    <units>Hz</units>
    <min>0.1Hz</min>
    <max>10Hz</max>
    <default>1Hz</default>
  </number>
  <integer id="points">
    <about>
      <label>Number of points</label>
      <description>Number of data points in the output curve.</description>
    </about>
    <uq>false</uq>
    <min>10</min>
    <max>1000</max>
    <default>200</default>
  </integer>
</input>
<output>
  <curve id="wave">
    <about>
      <label>Output Wave</label>
      <description>A * cos(2*pi*f*x) plotted over [0, 10].</description>
    </about>
    <xaxis><label>Time</label><units>s</units></xaxis>
    <yaxis><label>Amplitude</label></yaxis>
  </curve>
  <number id="peak">
    <about>
      <label>Peak Value</label>
      <description>Maximum value of the output curve.</description>
    </about>
  </number>
</output>
</run>

Script (unchanged for UQ)

import sys
import numpy as np
import rappture2web.rp_library as Rappture

rx = Rappture.PyXml(sys.argv[1])

amplitude = float(rx['input.(amplitude).current'].value)
freq_str = rx['input.(frequency).current'].value
frequency = float(Rappture.Units.convert(freq_str, units='off'))
npts = int(rx['input.(points).current'].value)

x = np.linspace(0, 10, npts)
y = amplitude * np.cos(2 * np.pi * frequency * x)

rx['output.curve(wave).component.xy'] = (x, y)
rx['output.number(peak).current'] = str(float(np.max(np.abs(y))))
rx.close()

Note that the script is identical for exact and UQ runs. rappture2web handles the UQ orchestration (multiple runs, analysis) automatically.