-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathDofMap.py
executable file
·88 lines (78 loc) · 3.24 KB
/
DofMap.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env python
## Program: PyNS
## Module: DofMap.py
## Language: Python
## Date: $Date: 2012/09/04 10:21:12 $
## Version: $Revision: 0.4.2 $
## Copyright (c) Simone Manini, Luca Antiga. All rights reserved.
## See LICENCE file for details.
## This software is distributed WITHOUT ANY WARRANTY; without even
## the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
## PURPOSE. See the above copyright notices for more information.
## Developed with support from the EC FP7/2007-2013: ARCH, Project n. 224390
class DofMap(object):
'''
This class maps local degrees of freedom (dof) into global dof.
Each element knows only its global nodeIds and its local dofs.
DofMap must consider also various connections between each element.
This class provides the following methods:
SetNetworkMesh: a method for setting NetworkMesh input.
GetDof: a method which returns global dof from (element.Id, localdof).
Build: a method for building DofMap.
DofMapOutput: a method for printing DofMap Output ordered by element's Id.
'''
def __init__(self):
'''
Constructor
'''
self.NetworkMesh = None
self.DofMap = {}
self.NumberOfGlobalDofs = 0
def SetNetworkMesh(self,networkMesh):
'''
Setting NetworkMesh
'''
self.NetworkMesh = networkMesh
def GetDof(self,elementId,localDof):
'''
This method calculates Global dof from (element.Id, localdof)
'''
return self.DofMap[(elementId,localDof)]
def Build(self):
'''
Building DofMap, mapping local dofs of each element into global network dofs
'''
nodesToElements = self.NetworkMesh.BuildNodesToElements()
newDofId = 0
for element in self.NetworkMesh.Elements:
dofNodes = element.GetDofNodes()
matchedLocalDofs = []
for dofNode in dofNodes:
nodeElementIds = nodesToElements[dofNode]
aNeighborElementId = None
for nodeElementId in nodeElementIds:
if element.Id == nodeElementId:
break
else:
aNeighborElementId = nodeElementId
for el in self.NetworkMesh.Elements:
if el.Id == aNeighborElementId:
neighborElement = el
localDof = element.GetLocalDof(dofNode)
matchedLocalDofs.append(localDof)
aNeighborLocalDof = neighborElement.GetLocalDof(dofNode)
self.DofMap[(element.Id,localDof)] = self.DofMap[aNeighborElementId,aNeighborLocalDof]
for localDof in element.dof:
if localDof in matchedLocalDofs:
continue
self.DofMap[(element.Id,localDof)] = newDofId
newDofId += 1
self.NumberOfGlobalDofs = newDofId
return DofMap
def DofMapOutput(self):
'''
This method returns DofMap Output ordered by element's IDs.
'''
for i in sorted(self.DofMap.items(),
key=lambda x:int(x[1])):
print "%-10s %3s" % i