pyCAPS
pyCAPS: A Python Extension Module for CAPS
Getting Started

Table of Contents

The following provides an overview of pyCAPS's services, with the intention being to emphasis and focus on basic, core functionality. As such not at all functions will be discussed. Users are encouraged to individually explore each classes documentation for a complete list of options.

The capsProblem Class

The capsProblem class is the front end of pyCAPS. All other classes are intended to be initiated through the problem class. The following code details the primary function calls and uses when creating/setting up a new problem.

Initialization and termination

The first step to create a new capsProblem is to import the pyCAPS module; on Linux and OSx this is the pyCAPS.so file, while on Windows it is the pyCAPS.pyd file. For convenience, it is recommended that the path to this file is added to the environmental variable PYTHONPATH.

import pyCAPS

After the module is loaded, a new capsProblem class object should be instantiated (see pyCAPS.capsProblem.__init__). Note that multiple problems may be simultaneously loaded/exist in a single script.

myProblem = pyCAPS.capsProblem()

Once a problem has been created the public attributes of the capsProblem are accessible.

After all desired operations on the problem are finished, it is recommended to close the problem (see pyCAPS.capsProblem.closeCAPS).

myProblem.closeCAPS()

Putting it all together we get:

# Use: Initiate/close problem.
# Import pyCAPS module (Linux and OSx = pyCAPS.so file; Windows = pyCAPS.pyd file)
import pyCAPS
# Instantiate our CAPS problem "myProblem"
print("Initiating capsProblem")
myProblem = pyCAPS.capsProblem()
# Close our problem
print("Closing our problem")
myProblem.closeCAPS()

Loading the geometry

A geometry file is loaded into the problem using the loadCAPS() function for the problem (see pyCAPS.capsProblem.loadCAPS). In the example below a *.csm file, "./csmData/cfdMultiBody.csm", is loaded into our created problem from above. The project name "basicTest" may be optionally set here; if no argument is provided the CAPS file provided is used as the project name. A reference to the newly created geometry class (see pyCAPS._capsGeometry) is stored and accessed through the geometry attribute (pyCAPS.capsProblem.geometry)

myProblem.loadCAPS("./csmData/cfdMultiBody.csm", "basicTest")

Alternatively, a reference to the geometry class is also returned during a call to loadCAPS() and can be used to also access the geometry class. Both the above and below code snippets are equivalent.

myGeometry = myProblem.loadCAPS("./csmData/cfdMultiBody.csm", "basicTest")

Loading an AIM

Analysis interface modules (AIMs) are loaded in the problem using the loadAIM() function for the problem (see pyCAPS.capsProblem.loadAIM). In the code sample below, the "fun3dAIM" is loaded into the problem with a specified working directory and intention.

myProblem.loadAIM(aim = "fun3dAIM",
altName = "fun3d",
analysisDir = "FUN3DAnalysisTest",
capsIntent = "CFD")

Since the "altName" keyword is being specified in the above snippet this analysis instance will be referenced/bookkept in the problem's analysis dictionary (pyCAPS.capsProblem.analysis) as "fun3d". For example,

print(myProblem.analysis["fun3d"].analysisDir)

results in,

FUN3DAnalysisTest

Alternatively, a reference to the analysis class is also returned during a call to loadAIM() and can be used to also access the analysis class. Both the above and below code snippets are equivalent.

fun3d = myProblem.loadAIM(aim = "fun3dAIM",
altName = "fun3d",
analysisDir = "FUN3DAnalysisTest",
capsIntent = "CFD")
print(fun3d.analysisDir)

Working with Geometry

Once the geometry is loaded various functions are provided to interact with it (see pyCAPS._capsGeometry). The following sections highlight a few of the more common ones.

Setting and getting design parameters

Geometric design parameters may be set using the setGeometryVal() function (pyCAPS._capsGeometry.setGeometryVal), while the current value of the parameter may be retrieved using getGeometryVal() (pyCAPS._capsGeometry.getGeometryVal). In the following example (geometry from Loading the geometry) the current value for the parameter "lesweep" is first obtained. The value is then reset and increased by 20.0.

# Get current value of the leading edges sweep
value = myGeometry.getGeometryVal("lesweep")
print("Current sweep Value =", value)
# Set a new value for the leading edges sweep
myGeometry.setGeometryVal("lesweep", value + 20.0)
# Check to see if the value was set correctly
value = myGeometry.getGeometryVal("lesweep")
print("New Sweep Value =", value)

The results from this snippet look like:

Current sweep Value = 30.0
New Sweep Value = 50.0

Viewing geometry

Within Python a picture of the current geometry may be viewed and/or saved using the viewGeometry() function (pyCAPS._capsGeometry.viewGeometry). A representative example of the function is as follows,

myGeometry.viewGeometry(filename = "GeomViewDemo_NewSweep",
title="DESPMTR: lesweep = " + str(value),
showImage = True,
ignoreBndBox = True,
combineBodies = True,
showTess = False,
showAxes = False,
directory = "GeometryImages",
viewType = "fourview")

Upon execution of the above code an image of the current geometry is displayed on the screen (showImage = True). As seen below, all the bodies are combined (combineBodies = True) into a single image with four different view points (viewType = "fourview"). Since a filename is also provided, the imaged displayed on the screen is also saved.

GeomViewDemo_NewSweep.png
Demo of viewGeometry()

Working with an AIM

Once an AIM has been loaded, various functions are provided to interact with it (see pyCAPS._capsAnalysis). The following sections highlight a few of the more common ones.

Setting and getting AIM inputs and outputs

AIM inputs may be set using the setAnalysisVal() function (pyCAPS._capsAnalysis.setAnalysisVal), while the current value of the input may be retrieved using getAnalysisVal() (pyCAPS._capsAnalysis.getAnalysisVal). In the following example (AIM from Loading an AIM) the current value for the input "Proj_Name" is first obtained and is then reset.

# Get current value of the project name
value = fun3d.getAnalysisVal("Proj_Name")
print("Current project name =", value)
# Set a new value for the project name
fun3d.setAnalysisVal("Proj_Name", "pyCAPS_Demo")
# Check to see if the value was set correctly
value = fun3d.getAnalysisVal("Proj_Name")
print("New project name =", value)

The results from this snippet look like:

Current project name = fun3d_CAPS
New project name = pyCAPS_Demo

Similar to getAnalysisVal, the getAnalysisOutVal() function (pyCAPS._capsAnalysis.getAnalysisOutVal) returns AIM output variables.

AIM pre- and post- analysis

For a given AIM, the CAPS pre- and post- analysis functions are executed in pyCAPS using the preAnalysis() (pyCAPS._capsAnalysis.preAnalysis) and postAnalysis() (pyCAPS._capsAnalysis.postAnalysis) functions.

# Execute pre-Analysis
fun3d.preAnalysis()
# Run AIM - os.system call, python interface, etc.....
# Execute post-Analysis
fun3d.postAnalysis()