Using a Dictionary to Avoid a Long if/elif/else Statement.

At the beginning of the script it sets up a dictionary matching the XML Type and XML SubType to the Type and SubType of result required in Mechanical APDL:

TypeSubTypeDict = {}

TypeSubTypeDict["Layer Dependant Failure","Maximum strain"] = "fail","emax"
TypeSubTypeDict["Layer Dependant Failure","Maximum stress"] = "fail","smax"
TypeSubTypeDict["Layer Dependant Failure","Tsai-Wu strength index"] = "fail","twsi"
TypeSubTypeDict["Layer Dependant Failure","Inverse of Tsai-Wu strength ratio index"] = "fail","twsr"
TypeSubTypeDict["Layer Dependant Failure","Hashin fiber failure"] = "fail","hfib"
TypeSubTypeDict["Layer Dependant Failure","Hashin matrix failure"] = "fail","hmat"
TypeSubTypeDict["Layer Dependant Failure","Puck fiber failure"] = "fail","pfib"
TypeSubTypeDict["Layer Dependant Failure","Puck inter-fiber (matrix) failure"] = "fail","pmat"
TypeSubTypeDict["Layer Dependant Failure","LaRc03 fiber failure"] = "fail","l3fb"
TypeSubTypeDict["Layer Dependant Failure","LaRc03 matrix failure"] = "fail","l3mt"
TypeSubTypeDict["Layer Dependant Failure","LaRc04 fiber failure"] = "fail","l4fb"
TypeSubTypeDict["Layer Dependant Failure","LaRc04 matrix failure"] = "fail","l4mt"

TypeSubTypeDict["Maximum Failure Criteria","Layer"] = "FCMX","lay"
TypeSubTypeDict["Maximum Failure Criteria","Failure Criteria"] = "FCMX","fc"
TypeSubTypeDict["Maximum Failure Criteria","Value"] = "FCMX","val"

These can then be easily looked up using:

MAPDLKeys = TypeSubTypeDict[str(DAResult.XmlType),str(DAResult.XmlSubType)]

MAPDLKeys can then be accessed like a regular array; i.e. MAPDLKeys[0] will return “fail” or “FCMX” appropriately.


Release 18.2 - © ANSYS, Inc. All rights reserved.