Mechanical APDL is run repeatedly for each DA Result object. In each case, the CSV file is read and the results displayed. In-line if statements are used to determine, among other things, if the value is to be inverted and what the value is if it is inverted.
def runStressEvaluate(DesignAssessment):
#Change to the result path as the local folder, to save passing in long file names to the MAPDL solve
originaldir = os.getcwd()
os.chdir(DesignAssessment.Helper.ResultPath)
# Make sure the mapdl macro is in this directory
shutil.copy2(DesignAssessment.Helper.UserFilesDirectory + "\\LayerMultiPly.mac", \
DesignAssessment.Helper.ResultPath)
# For now just assume one upstream but could make the code generic if required
if (DesignAssessment.SolutionSelections()[0].SolutionCount > 1):
print "only the first solution in the solution selection object will be used"
for DAResult in DesignAssessment.DAResults():
#Identify the type and subtype to be passed into MAPDL
MAPDLKeys = TypeSubTypeDict[str(DAResult.XmlType),str(DAResult.XmlSubType)]
print MAPDLKeys
#in-line if / else statements, format of N = ValueA if statement [is true] else [N =] ValueB.
Layer = 0 if (DAResult.Attribute("Layer") == None) else DAResult.Attribute("Layer").ValueAsInt
Display = "Elemental" if (DAResult.Attribute("Display") == None) else \
DAResult.Attribute("Display").ValueAsString
Inverse = False if (DAResult.Attribute("Inverse") == None) else \
DAResult.Attribute("Inverse").ValueAsString == "Yes"
#Create the results temp file by running a post script with MAPDL
if Display == "Elemental":
CreateMAPDLInputFile(MAPDLKeys,Layer,0)
elif Display == "Nodal":
CreateMAPDLInputFile(MAPDLKeys,Layer,1)
#Run MAPDL
DesignAssessment.Helper.RunMAPDL(TempMAPDLRunFilePath,"out.lis","/minimise")
DesignAssessment.Helper.ReplaceSolverOutputFile("out.lis")
#Read the results from the temp file to memory.
IDToDataDict = CSVToDictionary(DesignAssessment.Helper.ResultPath + "tempres.csv")
#Present the results
#Elemental
if Display == "Elemental":
DAResultSet = DAResult.CreateDAResultSet("Scalar","Elemental")
for Element in DesignAssessment.MeshData.Elements():
Value = 1/max(IDToDataDict[Element.Id][0],0.01) if Inverse else \
IDToDataDict[Element.Id][0]
DAResultSet.SetElementalValue(Element.Id,1,Value)
#Nodal
elif Display == "Nodal":
DAResultSet = DAResult.CreateDAResultSet("Scalar","Nodal")
for Node in DesignAssessment.MeshData.Nodes():
Value = 1/max(IDToDataDict[Node.Id][0],0.01) if Inverse else IDToDataDict[Node.Id][0]
DAResultSet.SetNodalValue(Node.Id,1,Value)
os.chdir(originaldir)