def __init__(self, tag, ref, weight=0, color=0): super().__init__(tag) self.myRef = ref self.myWeight = weight self.myColor = color self.myDegree = 0 # degree of node i is number of edges meeting at node i or number of vertices adjacent to it self.myTmp = 0 self.myAdjacency = ID(size=0, arraySize=8) # two nodes are said to be adjacent if they are connected by an edge
def __init__(self, tag, dim, Nd1, Nd2, theMaterial, A, r=0.0, damp=0, cm=0): super().__init__(tag, Truss.ELE_TAG_Truss) self.theMaterial = theMaterial self.connectedExternalNodes = ID(2) # 存储节点号 self.connectedExternalNodes[0] = Nd1 self.connectedExternalNodes[1] = Nd2 self.dimension = dim # truss in 2 or 3d domain self.numDOF = 0 # number of dof for truss ?? self.theLoad = None # pointer to the load vector P self.theMatrix = None # pointer to objects matrix (a class wide Matrix) ?? self.theVector = None # pointer to objects vector (a class wide Vector) ?? self.L = 0.0 # length of truss based on undeformed configuration self.A = A # area of truss self.rho = r # rho: mass density per unit length self.doRayleighDamping = damp # flag to include Rayleigh damping self.cMass = cm # consistent mass flag self.cosX = [0, 0, 0] # direction cosines self.theNodes = [None, None] # 存储节点本身 self.initialDisp = None # narray
def __init__(self, tag, theDomain, theSP, alpha=1.0e8): self.theTag = tag self.myDOF_Groups = ID(1) self.numDOF = 1 self.alpha = alpha self.theSP = theSP self.theNode = theDomain.getNode(theSP.getNodeTag()) if self.theNode == None: print('FATAL PenaltySP_FE::PenaltySP_FE() - no Node: ' + str(theSP.getNodeTag) + ' in domain.\n') dofGrp = self.theNode.getDOF_Group() if dofGrp != None: self.myDOF_Groups[0] = dofGrp.getTag()
class Vertex(TaggedObject): def __init__(self, tag, ref, weight=0, color=0): super().__init__(tag) self.myRef = ref self.myWeight = weight self.myColor = color self.myDegree = 0 # degree of node i is number of edges meeting at node i or number of vertices adjacent to it self.myTmp = 0 self.myAdjacency = ID(size=0, arraySize=8) # two nodes are said to be adjacent if they are connected by an edge # set method def setWeight(self, newWeight): self.myWeight = newWeight def setColor(self, newColor): self.myColor = newColor def setTmp(self, newTmp): self.myTmp = newTmp # get method def getRef(self): return self.myRef def getWeight(self): return self.myWeight def getColor(self): return self.myColor def getTmp(self): return self.myTmp def getDegree(self): return self.myDegree def getAdjacency(self): return self.myAdjacency # add method def addEdge(self, otherTag): # don't allow itself to be added if(otherTag==self.getTag()): return 0 # check the otherVertex has not already been added??? 在 ID::insert 内部自动check return self.myAdjacency.insert(otherTag)
import numpy as np from SRC.matrix.ID import ID id1 = ID() a = np.array([1]) # test getitem id1.setData(a) print(id1[0]) # test setitem id1[0] = 2 print(id1[0])
def number(self, theGraph, startVertex=-1): # 有重载 # first check our size, if not same make new if self.numVertex != theGraph.getNumVertex(): # delete the old self.theRefResult = None self.numVertex = theGraph.getNumVertex() self.theRefResult = ID(self.numVertex) # see if we can do quick return if self.numVertex == 0: return self.theRefResult # we first set the Tmp of all vertices to -1, indicating they have not yet been added. vertexs = theGraph.getVertices().getComponents() for key, vertex in vertexs.items(): vertex.setTmp(-1) # we now set up; setting our markers and getting first vertex startVertexTag = startVertex if startVertexTag != -1: vertex = theGraph.getVertex(startVertexTag) if vertex == None: print('WARNING: RCM::number - No vertex with tag ' + str(startVertexTag) + 'Exists - using first come from iter.\n') startVertexTag = -1 # if no starting vertex use the first one we get from the VertexIter vertexIter2 = iter(theGraph.getVertices().getComponents()) if startVertexTag == -1: vertex = next(vertexIter2) start = vertex # if GPS true use gibbs-poole-stodlmyer determine the last level set # assuming a starting vertex and then use one of the nodes in this set to base the numbering on if self.GPS == True: currentMark = self.numVertex - 1 # marks current vertex visiting nextMark = currentMark - 1 # marks where to put next Tag startLastLevelSet = nextMark self.theRefResult[currentMark] = vertex.getTag() vertex.setTmp(currentMark) # we continue till the ID is full while nextMark >= 0: # get the current vertex and its adjacency vertex = theGraph.getVertex(self.theRefResult[currentMark]) adjacency = vertex.getAdjacency() # go through the vertices adjacency and add vertices which have not yet been Tmp'ed to the (*theRefResult) size = adjacency.Size() for i in range(0, size): vertexTag = adjacency[i] vertex = theGraph.getVertex(vertexTag) if vertex.getTmp() == -1: vertex.setTmp(nextMark) self.theRefResult[nextMark] = vertexTag nextMark -= 1 # go to the next vertex # we decrement because we are doing reverse Cuthill-McKee currentMark -= 1 if startLastLevelSet == currentMark: startLastLevelSet = nextMark # check to see if graph is disconneted if currentMark == nextMark and currentMark >= 0: # loop over iter till we get a vertex not yet Tmped vertex = next(vertexIter2) while vertex != None and vertex.getTmp() != -1: nextMark -= 1 startLastLevelSet = nextMark vertex.setTmp(currentMark) self.theRefResult[currentMark] = vertex.getTag() # create an id of the last level set if startLastLevelSet > 0: lastLeverSet = ID(startLastLevelSet) for i in range(0, startLastLevelSet): lastLeverSet[i] = self.theRefResult[i] return self.number(theGraph, lastLeverSet) # 用到了重载的函数 else: vertex = start vertexIter3 = theGraph.getVertices().getComponents() # set to -1 all the vertices for key, other in vertexIter3: other.setTmp(-1) vertexIter4 = theGraph.getVertices().getComponents() currentMark = self.numVertex - 1 # marks current vertex visiting nextMark = currentMark - 1 # indiactes where to put next Tag in ID self.theRefResult[currentMark] = vertex.getTag() vertex.setTmp(currentMark) # we continue till the ID is full while nextMark >= 0: # get the current vertex and its adjacency vertex = theGraph.getVertex(self.theRefResult[currentMark]) adjacency = vertex.getAdjacency() # go through the vertices adjacency and add vertices which have not yet been Tmp'ed to the (*theRefResult) size = adjacency.Size() for i in range(0, size): vertexTag = adjacency[i] vertex = theGraph.getVertex(vertexTag) if vertex.getTmp() == -1: vertex.setTmp(nextMark) self.theRefResult[nextMark] = vertexTag nextMark -= 1 # go to the next vertex, we decrement because we are doing reverse Cuthill-McKee currentMark -= 1 # check to see if graph is disconneted if currentMark == nextMark and currentMark >= 0: # 有一段不知所措 nextMark -= 1 vertex.setTmp(currentMark) self.theRefResult[currentMark] = vertex.getTag() # now set the vertex references instead of the vertex tags # in the result, we change the Tmp to indicate number and return for i in range(0, self.numVertex): vertexTag = self.theRefResult[i] vertex = theGraph.getVertex(vertexTag) vertex.setTmp(i + 1) # 1 through numVertex self.theRefResult[i] = vertex.getTag() return self.theRefResult