Example #1
0
def exportBeamInternalForces(nmbComb, elems, fName):
    '''Writes a comma separated values file with the element's internal forces.'''
    for e in elems:
        e.getResistingForce()
        N1= 0.0; Vy1= 0.0; Vz1= 0.0; T1= 0.0; My1= 0.0; Mz1= 0.0
        N2= 0.0; Vy2= 0.0; Vz2= 0.0; T2= 0.0; My2= 0.0; Mz2= 0.0; 
        axialForces= e.getValuesAtNodes('N')
        if(len(axialForces)>1): # 'N' found.
            N1= axialForces[0]
            N2= axialForces[1]
        shearY= e.getValuesAtNodes('Vy')
        if(len(shearY)>1): # 'Vy' found.
            Vy1= shearY[0]
            Vy2= shearY[1]
        shearZ= e.getValuesAtNodes('Vz')
        if(len(shearZ)>1): # 'Vz' found.
            Vz1= shearZ[0]
            Vz2= shearZ[1]
        torque= e.getValuesAtNodes('T')
        if(len(torque)>1): # 'T' found.
            T1= torque[0]
            T2= torque[1]
        bendingY= e.getValuesAtNodes('My')
        if(len(bendingY)>1): # 'My' found.
            My1= bendingY[0]
            My2= bendingY[1]
        bendingZ= e.getValuesAtNodes('Mz')
        if(len(bendingZ)>1): # 'Mz' found.
            Mz1= bendingZ[0]
            Mz2= bendingZ[1]
        internalForces= internal_forces.CrossSectionInternalForces(N1,Vy1,Vz1,T1,My1,Mz1) # Internal forces at the origin of the bar.
        fName.write(nmbComb+", "+str(e.tag*10+1)+","+internalForces.getCSVString())
        internalForces= internal_forces.CrossSectionInternalForces(N2,Vy2,Vz2,T2,My2,Mz2) # Internal forces at the end of the bar.
        fName.write(nmbComb+", "+str(e.tag*10+2)+","+internalForces.getCSVString())
Example #2
0
def exportBeamInternalForces(nmbComb, elems, fName):
  '''Writes a comma separated values file with the element's internal forces.'''
  for e in elems:
    e.getResistingForce()
    internalForces= internal_forces.CrossSectionInternalForces(e.getN1,e.getVy1,e.getVz1,e.getT1,e.getMy1,e.getMz1) # Internal forces at the origin of the bar.
    fName.write(nmbComb+", "+str(e.tag*10+1)+","+internalForces.getCSVString())
    internalForces= internal_forces.CrossSectionInternalForces(e.getN2,e.getVy2,e.getVz2,e.getT2,e.getMy2,e.getMz2) # Internal forces at the end of the bar.
    fName.write(nmbComb+", "+str(e.tag*10+2)+","+internalForces.getCSVString())
Example #3
0
def oldReadIntForcesFile(intForcCombFileName, setCalc=None):
    '''Extracts element and combination identifiers from the internal
    forces listing file. Return elementTags, idCombs and 
    internal-forces values
    
    :param   intForcCombFileName: name of the file containing the internal
                                  forces obtained for each element for 
                                  the combinations analyzed
    :param setCalc: set of elements to be analyzed (defaults to None which 
                    means that all the elements in the file of internal forces
                    results are analyzed) 
    '''
    errMsg = 'oldReadIntForcesFile will be deprecated soon.'
    #lmsg.error(errMsg)
    elementTags = set()
    idCombs = set()
    f = open(intForcCombFileName, "r")
    internalForcesValues = defaultdict(list)
    internalForcesListing = csv.reader(f)
    next(internalForcesListing)  #skip first line (head)
    if setCalc == None:
        for lst in internalForcesListing:  #lst: list of internal forces for each combination and element
            if (len(lst) > 0):
                idComb = lst[0]
                idCombs.add(idComb)
                tagElem = eval(lst[1])
                idSection = eval(lst[2])
                elementTags.add(tagElem)
                crossSectionInternalForces = internal_forces.CrossSectionInternalForces(
                )
                crossSectionInternalForces.setFromCSVString(lst, 3)
                crossSectionInternalForces.idComb = idComb
                crossSectionInternalForces.tagElem = tagElem
                crossSectionInternalForces.idSection = idSection
                internalForcesValues[tagElem].append(
                    crossSectionInternalForces)
    else:
        setElTags = setCalc.getElementTags()
        for lst in internalForcesListing:
            if (len(lst) > 0):
                tagElem = eval(lst[1])
                if tagElem in setElTags:
                    idComb = lst[0]
                    idCombs.add(idComb)
                    tagElem = eval(lst[1])
                    idSection = eval(lst[2])
                    elementTags.add(tagElem)
                    crossSectionInternalForces = internal_forces.CrossSectionInternalForces(
                    )
                    crossSectionInternalForces.setFromCSVString(lst, 3)
                    crossSectionInternalForces.idComb = idComb
                    crossSectionInternalForces.tagElem = tagElem
                    crossSectionInternalForces.idSection = idSection
                    internalForcesValues[tagElem].append(
                        crossSectionInternalForces)
    f.close()
    return (elementTags, idCombs, internalForcesValues)
Example #4
0
 def setupForElementsAndCombinations(self,
                                     intForcCombFileName,
                                     setCalc=None):
     '''Extracts element and combination identifiers from the internal
    forces listing file.
 
 :param   intForcCombFileName: name of the file containing the internal
                               forces obtained for each element for 
                               the combinations analyzed
 :param setCalc: set of elements to be analyzed (defaults to None which 
                 means that all the elements in the file of internal forces
                 results are analyzed) 
 '''
     self.elementTags = set()
     self.idCombs = set()
     f = open(intForcCombFileName, "r")
     self.internalForcesValues = defaultdict(list)
     internalForcesListing = csv.reader(f)
     internalForcesListing.next()  #skip first line (head)
     if setCalc == None:
         for lst in internalForcesListing:  #lst: list of internal forces for each combination and element
             if (len(lst) > 0):
                 idComb = lst[0]
                 self.idCombs.add(idComb)
                 tagElem = eval(lst[1])
                 idSection = eval(lst[2])
                 self.elementTags.add(tagElem)
                 crossSectionInternalForces = internal_forces.CrossSectionInternalForces(
                 )
                 crossSectionInternalForces.setFromCSVString(lst, 3)
                 crossSectionInternalForces.idComb = idComb
                 crossSectionInternalForces.tagElem = tagElem
                 crossSectionInternalForces.idSection = idSection
                 self.internalForcesValues[tagElem].append(
                     crossSectionInternalForces)
     else:
         setElTags = setCalc.getElementTags()
         for lst in internalForcesListing:
             if (len(lst) > 0):
                 tagElem = eval(lst[1])
                 if tagElem in setElTags:
                     idComb = lst[0]
                     self.idCombs.add(idComb)
                     tagElem = eval(lst[1])
                     idSection = eval(lst[2])
                     self.elementTags.add(tagElem)
                     crossSectionInternalForces = internal_forces.CrossSectionInternalForces(
                     )
                     crossSectionInternalForces.setFromCSVString(lst, 3)
                     crossSectionInternalForces.idComb = idComb
                     crossSectionInternalForces.tagElem = tagElem
                     crossSectionInternalForces.idSection = idSection
                     self.internalForcesValues[tagElem].append(
                         crossSectionInternalForces)
     f.close()
Example #5
0
def exportInternalForces(nmbComb, elems, fDesc):
    '''Writes a comma separated values file with the element's internal forces.

  :param nmbComb: combination name.
  :param elems: element set.
  :param fDesc: file descriptor to write internal forces on.'''
    for e in elems:
        elementType = e.type()
        if ('Shell' in elementType):
            internalForces = internal_forces.ShellMaterialInternalForces()
            internalForces.setFromAverageInShellElement(e)
            strEsf = internalForces.getCSVString()
            forcesOnNodes = internalForces.getWoodArmer()
            sz = len(forcesOnNodes)
            for i in range(0, sz):
                force = forcesOnNodes[i]
                outStr = nmbComb + ", " + str(
                    e.tag) + ", " + str(i) + ", " + force.getCSVString() + '\n'
                fDesc.write(outStr)
        elif ('Beam2d' in elementType):
            e.getResistingForce()
            # Internal forces at the origin of the bar.
            internalForces = internal_forces.CrossSectionInternalForces(
                e.getN1, e.getV1, 0.0, 0.0, 0.0, e.getM1)
            fDesc.write(nmbComb + ", " + str(e.tag) + ", 0, " +
                        internalForces.getCSVString() + '\n')
            internalForces = internal_forces.CrossSectionInternalForces(
                e.getN2, e.getV2, 0.0, 0.0, 0.0,
                e.getM2)  # Internal forces at the end of the bar.
            fDesc.write(nmbComb + ", " + str(e.tag) + ", 1, " +
                        internalForces.getCSVString() + '\n')
        elif ('Beam' in elementType):
            e.getResistingForce()
            internalForces = internal_forces.CrossSectionInternalForces(
                e.getN1, e.getVy1, e.getVz1, e.getT1, e.getMy1,
                e.getMz1)  # Internal forces at the origin of the bar.
            fDesc.write(nmbComb + ", " + str(e.tag) + ", 0, " +
                        internalForces.getCSVString() + '\n')
            internalForces = internal_forces.CrossSectionInternalForces(
                e.getN2, e.getVy2, e.getVz2, e.getT2, e.getMy2,
                e.getMz2)  # Internal forces at the end of the bar.
            fDesc.write(nmbComb + ", " + str(e.tag) + ", 1, " +
                        internalForces.getCSVString() + '\n')
        elif ('ZeroLength' in elementType):
            lmsg.warning("exportInternalForces for element type: '" +
                         elementType + "' not implemented.")
        else:
            lmsg.error("exportInternalForces error; element type: '" +
                       elementType + "' unknown.")
Example #6
0

# Solution procedure
analysis= predefined_solutions.simple_static_linear(feProblem)
analOk= analysis.analyze(1)

f1= preprocessor.getSets.getSet("f1")

from postprocess.reports import export_internal_forces
setTotal= preprocessor.getSets["total"]
fName= "/tmp/test_export_shell_internal_forces.txt"
internalForcesDict=  export_internal_forces.getInternalForcesDict("test",setTotal.getElements)
with open(fName, 'w') as outfile:
    json.dump(internalForcesDict, outfile)

average= [internal_forces.CrossSectionInternalForces(),internal_forces.CrossSectionInternalForces()]
nCols= len(average)

with open(fName) as json_file:
    combInternalForcesDict= json.load(json_file)
json_file.close()

nRows= 0
for key in combInternalForcesDict.keys():
    elements= combInternalForcesDict[key]
    for elemId in elements.keys():
        elementData= elements[elemId]
        internalForces= elementData['internalForces']
        for k in internalForces.keys():
            nRows+= 1
            sectionIndex= eval(k)
# Solution procedure
analisis = predefined_solutions.simple_static_linear(feProblem)
analOk = analisis.analyze(1)

f1 = preprocessor.getSets.getSet("f1")

from postprocess.reports import export_internal_forces
setTotal = preprocessor.getSets["total"]
fName = "/tmp/test_export_shell_internal_forces.txt"
f = open(fName, "w")
export_internal_forces.exportInternalForces("test", setTotal.getElements, f)
f.close()

mean = [
    internal_forces.CrossSectionInternalForces(),
    internal_forces.CrossSectionInternalForces()
]
nCols = len(mean)
nRows = 0
import csv
cr = csv.reader(open(fName, "rb"))
for row in cr:
    nRows += 1
    sectionIndex = eval(row[2])
    mean[sectionIndex] += internal_forces.CrossSectionInternalForces(
        eval(row[3]), eval(row[4]), eval(row[5]), eval(row[6]), eval(row[7]),
        eval(row[8]))

for m in mean:
    m *= 1.0 / nRows
Example #8
0
def exportInternalForces(nmbComb, elems, fDesc):
    '''Writes a comma separated values file with the element's internal forces.

    :param nmbComb: combination name.
    :param elems: element set.
    :param fDesc: file descriptor to write internal forces on.
    '''
    errMsg= 'exportInternalForces deprecated use getInternalForcesDict'
    errMsg+= 'with apropriate arguments'
    for e in elems:
        elementType= e.type()
        if('Shell' in elementType):
          internalForces= internal_forces.ShellMaterialInternalForces()
          internalForces.setFromAverageInShellElement(e)
          forcesOnNodes= internalForces.getWoodArmer()
          sz= len(forcesOnNodes)
          for i in range(0,sz):
            force= forcesOnNodes[i]
            outStr= nmbComb+", "+str(e.tag)+", "+str(i)+", "+force.getCSVString()+'\n'
            fDesc.write(outStr)
        elif('Beam2d' in elementType):
            e.getResistingForce()
            # Internal forces at the origin of the bar. 
            N1= 0.0; M1= 0.0; V1= 0.0
            N2= 0.0; M2= 0.0; V2= 0.0
            axialForces= e.getValuesAtNodes('N', False)
            if(len(axialForces)>1): # 'N' found.
                N1= axialForces[0]
                N2= axialForces[1]
            bending= e.getValuesAtNodes('M', False)
            if(len(bending)>1): # 'M' found.
                M1= bending[0]
                M2= bending[1]
            shear= e.getValuesAtNodes('V', False)
            if(len(shear)>1): # 'V' found.
                V1= shear[0]
                V2= shear[1]
            internalForces= internal_forces.CrossSectionInternalForces(N1,V1,0.0,0.0,0.0,M1) 
            fDesc.write(nmbComb+", "+str(e.tag)+", 0, "+internalForces.getCSVString()+'\n')
            internalForces= internal_forces.CrossSectionInternalForces(N2,V2,0.0,0.0,0.0,M2) # Internal forces at the end of the bar.
            fDesc.write(nmbComb+", "+str(e.tag)+", 1, "+internalForces.getCSVString()+'\n')
        elif('Beam' in elementType):
            e.getResistingForce()
            N1= 0.0; Vy1= 0.0; Vz1= 0.0; T1= 0.0; My1= 0.0; Mz1= 0.0
            N2= 0.0; Vy2= 0.0; Vz2= 0.0; T2= 0.0; My2= 0.0; Mz2= 0.0 
            axialForces= e.getValuesAtNodes('N', False)
            if(len(axialForces)>1): # 'N' found.
                N1= axialForces[0]
                N2= axialForces[1]
            shearY= e.getValuesAtNodes('Vy', False)
            if(len(shearY)>1): # 'Vy' found.
                Vy1= shearY[0]
                Vy2= shearY[1]
            shearZ= e.getValuesAtNodes('Vz', False)
            if(len(shearZ)>1): # 'Vz' found.
                Vz1= shearZ[0]
                Vz2= shearZ[1]
            torque= e.getValuesAtNodes('T', False)
            if(len(torque)>1): # 'T' found.
                T1= torque[0]
                T2= torque[1]
            bendingY= e.getValuesAtNodes('My', False)
            if(len(bendingY)>1): # 'My' found.
                My1= bendingY[0]
                My2= bendingY[1]
            bendingZ= e.getValuesAtNodes('Mz', False)
            if(len(bendingZ)>1): # 'Mz' found.
                Mz1= bendingZ[0]
                Mz2= bendingZ[1]
            internalForces= internal_forces.CrossSectionInternalForces(N1,Vy1,Vz1,T1,My1,Mz1) # Internal forces at the origin of the bar.
            if e.hasProp('chiLT'):   #steel beam
                fDesc.write(nmbComb+", "+str(e.tag)+", 0, "+internalForces.getCSVString()+" , "+str(e.getProp('chiLT'))+'\n')
            else:
                fDesc.write(nmbComb+", "+str(e.tag)+", 0, "+internalForces.getCSVString()+'\n')
            internalForces= internal_forces.CrossSectionInternalForces(N2,Vy2,Vz2,T2,My2,Mz2) # Internal forces at the end of the bar.
            if e.hasProp('chiLT'):
                fDesc.write(nmbComb+", "+str(e.tag)+", 1, "+internalForces.getCSVString()+" , " + str(e.getProp('chiLT'))+'\n')
            else:
                fDesc.write(nmbComb+", "+str(e.tag)+", 1, "+internalForces.getCSVString()+'\n')
        elif('Truss' in elementType):
            e.getResistingForce()
            N1= 0.0
            N2= 0.0
            axialForces= e.getValuesAtNodes('N', False)
            if(len(axialForces)>1): # 'N' found.
                N1= axialForces[0]
                N2= axialForces[1]
            internalForces= internal_forces.CrossSectionInternalForces(N1) # Internal forces at the origin of the bar.
            if e.hasProp('chiLT'):   #steel beam
                fDesc.write(nmbComb+", "+str(e.tag)+", 0, "+internalForces.getCSVString()+" , "+str(e.getProp('chiLT'))+'\n')
            else:
                fDesc.write(nmbComb+", "+str(e.tag)+", 0, "+internalForces.getCSVString()+'\n')
            internalForces= internal_forces.CrossSectionInternalForces(N2) # Internal forces at the end of the bar.
            if e.hasProp('chiLT'):
                fDesc.write(nmbComb+", "+str(e.tag)+", 1, "+internalForces.getCSVString()+" , " + str(e.getProp('chiLT'))+'\n')
            else:
                fDesc.write(nmbComb+", "+str(e.tag)+", 1, "+internalForces.getCSVString()+'\n')
        elif('ZeroLength' in elementType):
            lmsg.warning("exportInternalForces for element type: '"+elementType+"' not implemented.")
        else:
            lmsg.error("exportInternalForces error; element type: '"+elementType+"' unknown.")
Example #9
0
def getInternalForcesDict(nmbComb, elems, vonMisesStressId= 'max_von_mises_stress'):
    '''Creates a dictionary with the element's internal forces.

    :param nmbComb: combination name.
    :param elems: element set.
    :param vonMisesStressId: identifier of the Von Mises stress to read
                            (see NDMaterial and MembranePlateFiberSection).
    '''
    combInternalForcesDict= dict()
    outDict= dict()
    combInternalForcesDict[nmbComb]= outDict
    for e in elems:
        elemDict= dict()
        outDict[e.tag]= elemDict
        elementType= e.type()
        elemDict['type']= elementType
        if('Shell' in elementType):
            internalForces= internal_forces.ShellMaterialInternalForces()
            internalForces.setFromAverageInShellElement(e)
            internalForces= internalForces.getWoodArmer()
            # Silently ask about maximum Von-Mises stress.
            maxVonMisesAtNodes= e.getValuesAtNodes(vonMisesStressId, True) 
            avgMaxVM= None
            if(len(maxVonMisesAtNodes)>1): # vonMisesStressId found.
                avgMaxVM= 0.0
                avgMaxVM+= maxVonMisesAtNodes[0][0] # at node 1
                avgMaxVM+= maxVonMisesAtNodes[1][0] # at node 2
                avgMaxVM+= maxVonMisesAtNodes[2][0] # at node 3
                avgMaxVM+= maxVonMisesAtNodes[3][0] # at node 4
                avgMaxVM/= 4.0 # average of the max. value at nodes.
            sz= len(internalForces)
            internalForcesDict= dict()
            for i in range(0,sz):
                nForceDict= dict()
                force= internalForces[i]
                internalForcesDict[i]= force.getDict()
                if(avgMaxVM):
                    internalForcesDict[i].update({vonMisesStressId:avgMaxVM})
            elemDict['internalForces']= internalForcesDict
        elif('Beam2d' in elementType):
            e.getResistingForce()
            internalForcesDict= dict()
            # Internal forces of the bar. 
            N1= 0.0; M1= 0.0; V1= 0.0
            N2= 0.0; M2= 0.0; V2= 0.0
            axialForces= e.getValuesAtNodes('N', False)
            if(len(axialForces)>1): # 'N' found.
                N1= axialForces[0]
                N2= axialForces[1]
            bending= e.getValuesAtNodes('M', False)
            if(len(bending)>1): # 'M' found.
                M1= bending[0]
                M2= bending[1]
            shear= e.getValuesAtNodes('V', False)
            if(len(shear)>1): # 'V' found.
                V1= shear[0]
                V2= shear[1]
            internalForces= internal_forces.CrossSectionInternalForces(N1,V1,0.0,0.0,0.0,M1) 
            internalForcesDict[0]= internalForces.getDict()
            internalForces= internal_forces.CrossSectionInternalForces(N2,V2,0.0,0.0,0.0,M2) # Internal forces at the end of the bar.
            internalForcesDict[1]= internalForces.getDict()
            elemDict['internalForces']= internalForcesDict
        elif('Beam' in elementType):
            e.getResistingForce()
            internalForcesDict= dict()
            N1= 0.0; My1= 0.0; Mz1= 0.0; Vy1= 0.0;
            N2= 0.0; My2= 0.0; Mz2= 0.0; Vy2= 0.0;
            axialForces= e.getValuesAtNodes('N', False)
            if(len(axialForces)>1): # 'N' found.
                N1= axialForces[0]
                N2= axialForces[1]
            shearY= e.getValuesAtNodes('Vy', False)
            if(len(shearY)>1): # 'Vy' found.
                Vy1= shearY[0]
                Vy2= shearY[1]
            shearZ= e.getValuesAtNodes('Vz', False)
            if(len(shearZ)>1): # 'Vz' found.
                Vz1= shearZ[0]
                Vz2= shearZ[1]
            torque= e.getValuesAtNodes('T', False)
            if(len(torque)>1): # 'T' found.
                T1= torque[0]
                T2= torque[1]
            bendingY= e.getValuesAtNodes('My', False)
            if(len(bendingY)>1): # 'My' found.
                My1= bendingY[0]
                My2= bendingY[1]
            bendingZ= e.getValuesAtNodes('Mz', False)
            if(len(bendingZ)>1): # 'Mz' found.
                Mz1= bendingZ[0]
                Mz2= bendingZ[1]
            internalForces= internal_forces.CrossSectionInternalForces(N1,Vy1,Vz1,T1,My1,Mz1) # Internal forces at the origin of the bar.
            internalForcesDict[0]= internalForces.getDict()
            if e.hasProp('chiLT'):   #steel beam
                internalForcesDict[0]['chiLT']= e.getProp('chiLT')
            if e.hasProp('chiN'):   #steel beam
                internalForcesDict[0]['chiN']= e.getProp('chiN')
            internalForces= internal_forces.CrossSectionInternalForces(N2,Vy2,Vz2,T2,My2,Mz2) # Internal forces at the end of the bar.
            internalForcesDict[1]= internalForces.getDict()
            if e.hasProp('chiLT'):
                internalForcesDict[1]['chiLT']= e.getProp('chiLT')
            if e.hasProp('chiN'):
                internalForcesDict[1]['chiN']= e.getProp('chiN')
            elemDict['internalForces']= internalForcesDict
        elif('Truss' in elementType):
            e.getResistingForce()
            internalForcesDict= dict()
            N1= 0.0
            N2= 0.0
            axialForces= e.getValuesAtNodes('N', False)
            if(len(axialForces)>1): # 'N' found.
                N1= axialForces[0]
                N2= axialForces[1]
            internalForces= internal_forces.CrossSectionInternalForces(N1) # Internal forces at the origin of the bar.
            internalForcesDict[0]= internalForces.getDict()
            if e.hasProp('chiLT'):   #steel beam
                internalForcesDict[0]['chiLT']= e.getProp('chiLT')
            if e.hasProp('chiN'):   #steel beam
                internalForcesDict[0]['chiN']= e.getProp('chiN')
            internalForces= internal_forces.CrossSectionInternalForces(N2) # Internal forces at the end of the bar.
            internalForcesDict[1]= internalForces.getDict()
            if e.hasProp('chiLT'):
                internalForcesDict[1]['chiLT']= e.getProp('chiLT')
            if e.hasProp('chiN'):
                internalForcesDict[1]['chiN']= e.getProp('chiN')
            elemDict['internalForces']= internalForcesDict
        elif('ZeroLength' in elementType):
            e.getResistingForce()
            F= e.getValuesAtNodes("stress", False)
            internalForcesDict= dict()
            nDOFs= len(F[0]) # Number of degrees of freedom.
            if(nDOFs!= 6):
                lmsg.warning('exportInternalForces for '+str(nDOFs)+ " DOFs in element type: '"+elementType+"' not implemented.")
            else:
                F0= F[0]
                internalForces= internal_forces.CrossSectionInternalForces(N= F0[0],Vy= F0[1], Vz= F0[2],T= F0[3],My= F0[4], Mz= F0[5]) # Internal forces at the origin node.
                internalForcesDict[0]= internalForces.getDict()
                F1= F[1]
                internalForces= internal_forces.CrossSectionInternalForces(N= F1[0],Vy= F1[1], Vz= F1[2],T= F1[3],My= F1[4], Mz= F1[5]) # Internal forces at the end node.
                internalForcesDict[1]= internalForces.getDict()
            elemDict['internalForces']= internalForcesDict
        else:
            lmsg.error("exportInternalForces error; element type: '"+elementType+"' unknown.")
    return combInternalForcesDict
Example #10
0
def readIntForcesDict(intForcCombFileName,
                      setCalc=None,
                      vonMisesStressId='max_von_mises_stress'):
    '''Extracts element and combination identifiers from the internal
    forces JSON file. Return elementTags, idCombs and 
    internal-forces values
    
    :param   intForcCombFileName: name of the file containing the internal
                                  forces obtained for each element for 
                                  the combinations analyzed
    :param setCalc: set of elements to be analyzed (defaults to None which 
                    means that all the elements in the file of internal forces
                    results are analyzed)
    :param vonMisesStressId: identifier of the Von Mises stress to read
                            (see NDMaterial and MembranePlateFiberSection).
    '''
    elementTags = set()
    idCombs = set()
    with open(intForcCombFileName) as json_file:
        combInternalForcesDict = json.load(json_file)
    json_file.close()

    internalForcesValues = defaultdict(list)

    if (not setCalc):
        for comb in combInternalForcesDict.keys():
            idComb = str(comb)
            idCombs.add(idComb)
            elements = combInternalForcesDict[comb]
            for elemId in elements.keys():
                tagElem = eval(elemId)
                elementData = elements[elemId]
                elementType = elementData['type']
                internalForces = elementData['internalForces']
                for k in internalForces.keys():
                    idSection = eval(k)
                    elementTags.add(tagElem)
                    crossSectionInternalForces = internal_forces.CrossSectionInternalForces(
                    )
                    forces = internalForces[k]
                    crossSectionInternalForces.setFromDict(forces)
                    crossSectionInternalForces.idComb = idComb
                    crossSectionInternalForces.tagElem = tagElem
                    crossSectionInternalForces.idSection = idSection
                    if (vonMisesStressId in forces):
                        crossSectionInternalForces.vonMisesStress = forces[
                            vonMisesStressId]
                    internalForcesValues[tagElem].append(
                        crossSectionInternalForces)
    else:
        setElTags = setCalc.getElementTags()
        for idComb in combInternalForcesDict.keys():
            idCombs.add(idComb)
            elements = combInternalForcesDict[idComb]
            for elemId in elements.keys():
                tagElem = eval(elemId)
                if (tagElem in setElTags):
                    elementData = elements[elemId]
                    elementType = elementData['type']
                    internalForces = elementData['internalForces']
                    for k in internalForces.keys():
                        idSection = eval(k)
                        elementTags.add(tagElem)
                        crossSectionInternalForces = internal_forces.CrossSectionInternalForces(
                        )
                        forces = internalForces[k]
                        crossSectionInternalForces.setFromDict(forces)
                        crossSectionInternalForces.idComb = idComb
                        crossSectionInternalForces.tagElem = tagElem
                        crossSectionInternalForces.idSection = idSection
                        if (vonMisesStressId in forces):
                            crossSectionInternalForces.vonMisesStress = forces[
                                vonMisesStressId]
                        internalForcesValues[tagElem].append(
                            crossSectionInternalForces)
    return (elementTags, idCombs, internalForcesValues)
Example #11
0
def getInternalForcesDict(nmbComb, elems):
    '''Creates a dictionary with the element's internal forces.

    :param nmbComb: combination name.
    :param elems: element set.
    :param fDesc: file descriptor to write internal forces on.
    '''
    combInternalForcesDict= dict()
    outDict= dict()
    combInternalForcesDict[nmbComb]= outDict
    for e in elems:
        elemDict= dict()
        outDict[e.tag]= elemDict
        elementType= e.type()
        elemDict['type']= elementType
        if('Shell' in elementType):
            internalForces= internal_forces.ShellMaterialInternalForces()
            internalForces.setFromAverageInShellElement(e)
            internalForces= internalForces.getWoodArmer()
            sz= len(internalForces)
            internalForcesDict= dict()
            for i in range(0,sz):
                nForceDict= dict()
                force= internalForces[i]
                internalForcesDict[i]= force.getDict()
            elemDict['internalForces']= internalForcesDict
        elif('Beam2d' in elementType):
            e.getResistingForce()
            internalForcesDict= dict()
            # Internal forces of the bar. 
            N1= 0.0; M1= 0.0; V1= 0.0
            N2= 0.0; M2= 0.0; V2= 0.0
            axialForces= e.getValuesAtNodes('N')
            if(len(axialForces)>1): # 'N' found.
                N1= axialForces[0]
                N2= axialForces[1]
            bending= e.getValuesAtNodes('M')
            if(len(bending)>1): # 'M' found.
                M1= bending[0]
                M2= bending[1]
            shear= e.getValuesAtNodes('V')
            if(len(shear)>1): # 'V' found.
                V1= shear[0]
                V2= shear[1]
            internalForces= internal_forces.CrossSectionInternalForces(N1,V1,0.0,0.0,0.0,M1) 
            internalForcesDict[0]= internalForces.getDict()
            internalForces= internal_forces.CrossSectionInternalForces(N2,V2,0.0,0.0,0.0,M2) # Internal forces at the end of the bar.
            internalForcesDict[1]= internalForces.getDict()
            elemDict['internalForces']= internalForcesDict
        elif('Beam' in elementType):
            e.getResistingForce()
            internalForcesDict= dict()
            N1= 0.0; My1= 0.0; Mz1= 0.0; Vy1= 0.0;
            N2= 0.0; My2= 0.0; Mz2= 0.0; Vy2= 0.0;
            axialForces= e.getValuesAtNodes('N')
            if(len(axialForces)>1): # 'N' found.
                N1= axialForces[0]
                N2= axialForces[1]
            shearY= e.getValuesAtNodes('Vy')
            if(len(shearY)>1): # 'Vy' found.
                Vy1= shearY[0]
                Vy2= shearY[1]
            shearZ= e.getValuesAtNodes('Vz')
            if(len(shearZ)>1): # 'Vz' found.
                Vz1= shearZ[0]
                Vz2= shearZ[1]
            torque= e.getValuesAtNodes('T')
            if(len(torque)>1): # 'T' found.
                T1= torque[0]
                T2= torque[1]
            bendingY= e.getValuesAtNodes('My')
            if(len(bendingY)>1): # 'My' found.
                My1= bendingY[0]
                My2= bendingY[1]
            bendingZ= e.getValuesAtNodes('Mz')
            if(len(bendingZ)>1): # 'Mz' found.
                Mz1= bendingZ[0]
                Mz2= bendingZ[1]
            internalForces= internal_forces.CrossSectionInternalForces(N1,Vy1,Vz1,T1,My1,Mz1) # Internal forces at the origin of the bar.
            internalForcesDict[0]= internalForces.getDict()
            if e.hasProp('chiLT'):   #steel beam
                internalForcesDict[0]['chiLT']= e.getProp('chiLT')
            if e.hasProp('chiN'):   #steel beam
                internalForcesDict[0]['chiN']= e.getProp('chiN')
            internalForces= internal_forces.CrossSectionInternalForces(N2,Vy2,Vz2,T2,My2,Mz2) # Internal forces at the end of the bar.
            internalForcesDict[1]= internalForces.getDict()
            if e.hasProp('chiLT'):
                internalForcesDict[1]['chiLT']= e.getProp('chiLT')
            if e.hasProp('chiN'):
                internalForcesDict[1]['chiN']= e.getProp('chiN')
            elemDict['internalForces']= internalForcesDict
        elif('Truss' in elementType):
            e.getResistingForce()
            internalForcesDict= dict()
            N1= 0.0
            N2= 0.0
            axialForces= e.getValuesAtNodes('N')
            if(len(axialForces)>1): # 'N' found.
                N1= axialForces[0]
                N2= axialForces[1]
            internalForces= internal_forces.CrossSectionInternalForces(N1) # Internal forces at the origin of the bar.
            internalForcesDict[0]= internalForces.getDict()
            if e.hasProp('chiLT'):   #steel beam
                internalForcesDict[0]['chiLT']= e.getProp('chiLT')
            if e.hasProp('chiN'):   #steel beam
                internalForcesDict[0]['chiN']= e.getProp('chiN')
            internalForces= internal_forces.CrossSectionInternalForces(N2) # Internal forces at the end of the bar.
            internalForcesDict[1]= internalForces.getDict()
            if e.hasProp('chiLT'):
                internalForcesDict[1]['chiLT']= e.getProp('chiLT')
            if e.hasProp('chiN'):
                internalForcesDict[1]['chiN']= e.getProp('chiN')
            elemDict['internalForces']= internalForcesDict
        elif('ZeroLength' in elementType):
          lmsg.warning("exportInternalForces for element type: '"+elementType+"' not implemented.")
        else:
          lmsg.error("exportInternalForces error; element type: '"+elementType+"' unknown.")
    return combInternalForcesDict