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

Example use cases for pyCAPS.capsProblem.autoLinkValue() function.

1 # Use: Test autolinking of capsValue objects
2 
3 from __future__ import print_function
4 
5 # Import pyCAPS module (Linux and OSx = pyCAPS.so file; Windows = pyCAPS.pyd file)
6 import pyCAPS
7 
8 # Instantiate our CAPS problem "myProblem"
9 print("Initiating capsProblem")
10 myProblem = pyCAPS.capsProblem()
11 
12 # Load a *.csm file "./csmData/cfdMultiBody.csm" into our newly created problem.
13 myGeometry = myProblem.loadCAPS("./csmData/cfdMultiBody.csm", "basicTest")
14 
15 myAnalysis = myProblem.loadAIM(aim = "fun3dAIM",
16  analysisDir = "FUN3DAnalysisTest",
17  capsIntent = "CFD")
18 
19 # Create a value
20 myValue = myProblem.createValue("Alpha", -10.0, units="degree")
21 print("Alpha Value = ", myValue.value)
22 
23 # Create another value
24 myValue = myProblem.createValue("Mach", 0.25)
25 print("Mach Value = ", myValue.value)
26 
27 # Autolink all capsValues with all AIMs loaded into the problem
28 myProblem.autoLinkValue()
29 
30 # Values are updated in a lazy manner - the value shouldn't reflect the linked value yet
31 print("Mach = ", myAnalysis.getAnalysisVal("Mach"))
32 print("Alpha = ", myAnalysis.getAnalysisVal("Alpha"))
33 
34 # Create a new value
35 myValue = myProblem.createValue("Beta", 1.3, units="degree")
36 print("Beta Value = ", myValue.value)
37 
38 # Autolink just the new value with all AIMs loaded into the problem
39 myProblem.autoLinkValue(myValue) # or could have used - myProblem.autoLinkValue("Beta")
40 
41 # Run preAnalysis to force the value update
42 myAnalysis.preAnalysis()
43 
44 # Re-print the values - the values should reflect the linked values
45 print("Again... Mach = ", myAnalysis.getAnalysisVal("Mach"))
46 print("Again... Alpha = ", myAnalysis.getAnalysisVal("Alpha"))
47 print("Again... Beta = ", myAnalysis.getAnalysisVal("Beta"))
48 
49 # Close our problems
50 print("Closing our problem")
51 myProblem.closeCAPS()