source: branches/uq/examples/uq/simple/simple.py @ 5808

Last change on this file since 5808 was 5808, checked in by mmh, 9 years ago

add uq examples

File size: 1.1 KB
Line 
1# ----------------------------------------------------------------------
2#  EXAMPLE: Simple UQ Example of Curve Output
3# ======================================================================
4#  AUTHOR:  Martin Hunt, Purdue University
5#  Copyright (c) 2015  HUBzero Foundation, LLC
6#
7#  See the file "license.terms" for information on usage and
8#  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
9# ======================================================================
10
11import Rappture
12import sys
13import numpy as np
14
15# uncomment these for debugging
16# sys.stderr = open('tool.err', 'w')
17# sys.stdout = open('tool.out', 'w')
18
19rx = Rappture.PyXml(sys.argv[1])
20
21vsweep = rx['input.(vsweep).current'].value
22vsweep = float(Rappture.Units.convert(vsweep, to='V', units='off'))
23
24# get 200 values between 0 and 10
25xvals = np.linspace(0, 10, 200)
26
27
28# our function for the curve
29def f(x, v):
30    return .1*x*x - (5 - v)**2
31
32# evaluate our equation at the xvals
33yvals = f(xvals, vsweep)
34
35# save output as a curve
36#rx['output.curve(f).about.label'] = 'Plot of f(x)'
37rx['output.curve(f).component.xy'] = (xvals, yvals)
38
39
40rx.close()
Note: See TracBrowser for help on using the repository browser.