pyCAPS
pyCAPS: A Python Extension Module for CAPS
value4.py

Example use cases for interacting the with pyCAPS._capsValue.convertUnits() function.

1 from __future__ import print_function
2 
3 # Import pyCAPS module (Linux and OSx = pyCAPS.so file; Windows = pyCAPS.pyd file)
4 import pyCAPS
5 
6 # Instantiate our CAPS problem "myProblem"
7 print("Initiating capsProblem")
8 myProblem = pyCAPS.capsProblem()
9 
10 # Load a *.csm file "./csmData/cfdMultiBody.csm" into our newly created problem.
11 myGeometry = myProblem.loadCAPS("./csmData/cfdMultiBody.csm", "basicTest")
12 
13 # Create a value
14 myValue = myProblem.createValue("Altitude", [0.0, 30000.0, 60000.0], units="ft")
15 print("Name = ", myValue.name)
16 print("Value = ", myValue.value)
17 print("Units = ", myValue.units)
18 
19 # Convert the units from feet to meters
20 convertValue = myValue.convertUnits("m")
21 print("Converted Value = ", convertValue, "(m)")
22 
23 # Create a new value
24 myValue = myProblem.createValue("Freq", [[0.0, 1, 2], [.25, .5, .75]], units="Hz")
25 print("Name = ", myValue.name)
26 print("Value = ", myValue.value)
27 print("Units = ", myValue.units)
28 
29 # Convert the units from 1/s to 1/min
30 convertValue = myValue.convertUnits("1 per minute")
31 print("Converted Value = ", convertValue, "(1/min)")
32 
33 # Create a new value
34 myValue = myProblem.createValue("Energy", 1.0, units="Btu")
35 print("Name = ", myValue.name)
36 print("Value = ", myValue.value)
37 print("Units = ", myValue.units)
38 
39 # Convert the units from Btu to Joules
40 convertValue = myValue.convertUnits("J")
41 print("Converted Value = ", convertValue, "(J)")
42 
43 # Close our problems
44 print("Closing our problem")
45 myProblem.closeCAPS()