The following topic describes the Programming Reference by exploring the wall_results.py example script. (This script is included in the API Programming Reference.)
Each line (or block of lines) is described in detail and related back to the applicable section of the Programming Reference.
from CFD import Setup
from CFD import Results
from CFD import DSE
# Get current scenario & activate results
study = Setup.DesignStudy.Create()
scenario = study.getActiveScenario()
curr_results = scenario.results()
curr_results.activate()
# Create a WallResults object
wr = Results.WallResults(scenario)
# Set the id of surface of interest & ask it to calculate
wr.select(15)
wr.select(9)
wr.calculate()
# Get the results
area = wr.area(15)
pressure = wr.pressure(15)
temp = wr.temperature(15)
fx, fy, fz = 0.0, 0.0, 0.0 # force is a little complicated because it is 3 values
err, fx, fy, fz = wr.force(fx, fy, fz)
print("Area = ", area)
print("Press = ", pressure)
print("Temp = ", temp)
print("FX = ", fx)
print("FY = ", fy)
print("FZ = ", fz)
DSE.UI.ShowMessage( "Area = " + str(area) )
DSE.UI.ShowMessage( "Press = " + str(pressure) )
DSE.UI.ShowMessage( "Temp = " + str(temp) )
DSE.UI.ShowMessage( "FX = " + str(fx) )
DSE.UI.ShowMessage( "FY = " + str(fy) )
DSE.UI.ShowMessage( "FZ = " + str(fz) )
# Or you can write all wall results to a file
wr.writeToFile("C:/wr.csv")
print("Wall results are written to c:/wr.csv")
DSE.UI.ShowMessage( "Wall results are written to c:/wr.csv" )
from CFD import Setup
from CFD import Results
from CFD import DSE
>>> In the header section, each module to be referenced in the script must be declared. All are from the CFD project. Click Modules in the Programming Reference for the list of modules:
study = Setup.DesignStudy.Create()
>>>This line declares the variable called study as defined from the Setup module, the DesignStudy class, and the Create method. This is also how to get the handle on the design study. It is not necessary to specify the design study name because there is only one open during an Autodesk Simulation CFD session.
scenario = study.getActiveScenario()
>>> This line gets the active scenario in the study. Because there is only one active scenario at any given time, it is not necessary to specify the scenario name. The exception is if the intent is to reference a scenario other than the open one.
curr_results = scenario.results()
>>> This gets the results of the scenario.
curr_results.activate()
>>> This command activates the current results.
wr = Results.WallResults(scenario)
>>> Initialize the parameters needed for the wall results. Click Results on the Module page to access the WallResults class. The WallResults command is on the WallResults Class page:
wr.select(15)
wr.select(9)
wr.calculate()
>>> Use the Select function to select specific surfaces with the ID numbers (in this case surfaces 15 and 9). Use the Calculate function to trigger the calculation.
area = wr.area(15)
pressure = wr.pressure(15)
temp = wr.temperature(15)
fx, fy, fz = 0.0, 0.0, 0.0 # force is a little complicated because it is 3 values
err, fx, fy, fz = wr.force(fx, fy, fz)
>>> Compute the area, pressure, and temperature on the surface. Use the force function to compute the three force components:
print("Area = ", area)
print("Press = ", pressure)
print("Temp = ", temp)
print("FX = ", fx)
print("FY = ", fy)
print("FZ = ", fz)
>>> Use the print command to create the strings for outputting the results.
DSE.UI.ShowMessage( "Area = " + str(area) )
DSE.UI.ShowMessage( "Press = " + str(pressure) )
DSE.UI.ShowMessage( "Temp = " + str(temp) )
DSE.UI.ShowMessage( "FX = " + str(fx) )
DSE.UI.ShowMessage( "FY = " + str(fy) )
DSE.UI.ShowMessage( "FZ = " + str(fz) )
>>> Display the strings in the Output bar. These commands use the ShowMessage function of the UI class of the DSE module:
wr.writeToFile("C:/wr.csv")
print("Wall results are written to c:/wr.csv")
DSE.UI.ShowMessage( "Wall results are written to c:/wr.csv" )
>>> This command writes the results to a file. The function writeToFile is in the WallResults class. The last line displays a message confirming that the results are written to the file in the Output bar.
Related Topics