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 | |
---|
11 | import Rappture |
---|
12 | import sys |
---|
13 | import numpy as np |
---|
14 | |
---|
15 | # uncomment these for debugging |
---|
16 | # sys.stderr = open('tool.err', 'w') |
---|
17 | # sys.stdout = open('tool.out', 'w') |
---|
18 | |
---|
19 | rx = Rappture.PyXml(sys.argv[1]) |
---|
20 | |
---|
21 | vsweep = rx['input.(vsweep).current'].value |
---|
22 | vsweep = float(Rappture.Units.convert(vsweep, to='V', units='off')) |
---|
23 | |
---|
24 | # get 200 values between 0 and 10 |
---|
25 | xvals = np.linspace(0, 10, 200) |
---|
26 | |
---|
27 | |
---|
28 | # our function for the curve |
---|
29 | def f(x, v): |
---|
30 | return .1*x*x - (5 - v)**2 |
---|
31 | |
---|
32 | # evaluate our equation at the xvals |
---|
33 | yvals = f(xvals, vsweep) |
---|
34 | |
---|
35 | # save output as a curve |
---|
36 | #rx['output.curve(f).about.label'] = 'Plot of f(x)' |
---|
37 | rx['output.curve(f).component.xy'] = (xvals, yvals) |
---|
38 | |
---|
39 | |
---|
40 | rx.close() |
---|