The file “COM/EX99_LANGS/testClaCom.py” contains the Python code for automating CLA calculations. Some explanation of how the program works is given below.
First, some standard Python packages must be imported to enable OLE automation in the program. The following statements are therefore added at the beginning of the program:
import sys import gc from win32com.client import Dispatch, constants
The program then defines several methods that are used in the main program:
The method “id2str” converts an identifier returned by a CLA method into a string that can be used when printing results. Recall that a CLA identifier is either an integer, a String, or an Array containing one integer and one String. The method “id2str” checks the type of the “id” argument and performs the operations needed to convert it to a String.
The method “printLamProperties” writes a laminate definition and several of its properties (ABBD matrix, G matrix, CTE vectors, etc.). The method takes three arguments:
“db”: a ClaDb object (composite database) from which the laminate is retrieved.
“os”: the output stream to which results are written.
“lamID”: the identifier of the ClaLam object whose properties are written.
The lamID argument is used to obtain a copy of the laminate from the database. The laminate definition and its properties are then written to the output stream. The corresponding lines of code are straightforward and require no further explanation.
The method “printLoadResponse” calculates the laminate’s load response for a selected loading. It takes six arguments:
“db”: a ClaDb object (composite database) from which the laminate and the load used in the calculation are retrieved.
“os”: the output stream to which results are written.
“lamID”: the identifier of the ClaLam object for which the load response is calculated.
“loadID”: the identifier of the ClaLoad object for which the load response is calculated.
“theta”: a real number giving the angle of the applied load with respect to the laminate axes.
“criteria”: an Array of Strings listing the criteria for which reserve factors are calculated.
At the beginning of the method, the ClaLam and ClaLoad objects are retrieved from the database, and the laminate load response is calculated as follows:
lam=db.getLaminateCopy(lamID)
load=db.getLoadCopy(loadID)
lam.calcResponse(db,theta,load,True,True,True)
(Note that ply results are requested at the bottom, mid, and top of each ply.) Several results are then extracted from the ClaLam object and printed to the output stream:
The laminate normal forces, bending moments, normal strains, and curvatures, expressed in laminate axes.
The ply stresses in ply axes.
The ply strains in ply axes.
The reserve factors for the selected criteria, calculated with a unit safety factor.
Note that other results, such as failure indices, could also be calculated; this is left as an exercise. Also note that interpreting ply results requires some understanding of the structure of the results returned by methods such as “getPliesStresses”, “getPliesStrains”, and “getReserveFactors”. The information provided in Part II of this manual and in Chapter VI.0 should be sufficient, even though it will take some time to analyze the example.
No “main” function is defined in the program; instead, the last lines of the file contain the instructions that perform the main analysis.
First, the component must be accessed and a ClaDb object created and initialized, as follows:
frpApp = Dispatch("FeResPost_3_4_0.Application")
db=frpApp.newObject("ClaDb")
db.readNeutral("test.ndf")
Note that accessing the application requires its full name, which includes the version identifier. This means that the name must be changed if a different version of the component is used. Initializing the ClaDb object involves reading the “test.ndf” neutral data file.
The results are written to a disk file:
os=file("testClaCom_py.txt","w")
Note that iterators are easy to use in Python. Readers familiar with Python should have no trouble understanding the following lines:
for lamId in db.iter_laminateId: printLamProperties(db,os,lamId) for loadId in db.iter_loadId: printLoadResponse(db,os,lamId,loadId,0.0,criteria)
The outer loop iterates over the laminates and prints their properties. Inside this loop, an inner loop iterates over the loads stored in the database, calculating and printing the laminate load response for each one. The criteria calculated are: “TsaiHill”, “Ilss” and “YamadaSun”.
When the program is run, the FeResPost component application window displays the number of referenced component objects and the number of references to each. You can stop the program at various points to check this information, for example by adding Windows message boxes.