The script first calls the function runDADemo. This loops over each result and, based on the type and subtype it calls an appropriate sub function to perform the calculation.
In the case of fragmentation results, it first calls a function, IdentifyFragments, to create a dictionary of fragments. The fragment dictionary created is a data collection that contains the fragment number for each Element Id. This dictionary is passed to each function so it can be used for the fragment result calculation.
An example of this fragment result calculation is VolumeOfFragment:
def VolumeOfFragment(SortedDict, DAResult, FragmentDict, NodalMass):
print " "
print "Volume of Fragment"
print " ________________________________"
print "|Fragment | Volume(m^3) |"
print "+------------+-------------------+"
UpstrResDensity = UpstreamSolution.CreateSolutionResult("","DENSITY","No Units")
UpstrResDensity.IntegrationMethod = "unAveraged" # unaveraged because summing indiviual values
# and taking an average afterwards.
Density = 0
NodeCounter = 0
FragmentDataDict = {} #key = elementid, data = mass
FragmentDataDict2 = {}
NodesProcessed = {}
for ElementID in FragmentDict.keys():
NodeList = DA.MeshData.ElementById(ElementID).NodeIds()
for NodeID in NodeList:
if NodesProcessed.has_key(NodeID):
continue
else:
Fragment = FragmentDict[ElementID]
Mass = NodalMass[NodeID] # uses NodalMass dictionary from NodalMassFunc
if FragmentDataDict.has_key(Fragment):
FragmentDataDict[Fragment] += Mass
else:
FragmentDataDict[Fragment] = Mass
NodesProcessed[NodeID] = 0
Density += UpstrResDensity.ElementNodalValues(ElementID, NodeID)[0] # sum all of the
# densities
NodeCounter += 1 # Count the number of nodes which have been processed
Index = 1
Total = 0
for Key in FragmentDataDict.keys():
TVol = (FragmentDataDict[Key])/(Density/NodeCounter) # divide total density by the number
# of nodes
Text = "Fragment :" + str(Index) + " has a Volume of " + str(TVol) + " m^3"
FragmentDataDict2[Key] = TVol
Index += 1
Total += TVol
NewResultData = DAResult.CreateDAResultSet("Scalar","Elemental")
for ElementId in FragmentDict:
NewResultData.SetElementalValue(ElementId, 1, FragmentDataDict2[FragmentDict[ElementId]])
FragmentDataDict2 = Sort(SortedDict, FragmentDataDict2)
for Fragment in FragmentDataDict2:
print "| " + str(Fragment) + " | " + str('%.3e'%FragmentDataDict2[Fragment]) +\
" |"
print "+------------+-------------------+"
print "| Total | " + str('%.3e'%Total) +" |"
print "|____________|___________________|"
print " "
print " "
print " "The result can then be displayed:
