forked from xzhang66/STAPpy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDomain.py
More file actions
284 lines (217 loc) · 6.95 KB
/
Domain.py
File metadata and controls
284 lines (217 loc) · 6.95 KB
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
/*****************************************************************************/
/* STAPpy : A python FEM code sharing the same input data file with STAP90 */
/* Computational Dynamics Laboratory */
/* School of Aerospace Engineering, Tsinghua University */
/* */
/* Created on Mon Jun 22, 2020 */
/* */
/* @author: thurcni@163.com, xzhang@tsinghua.edu.cn */
/* http://www.comdyn.cn/ */
/*****************************************************************************/
"""
from utils.Singleton import Singleton
from utils.Outputter import COutputter
from element.Node import CNode
from LoadCaseData import CLoadCaseData
from element.ElementGroup import CElementGroup
from utils.SkylineMatrix import CSkylineMatrix
import numpy as np
import sys
@Singleton
class Domain(object):
"""
Domain class : Define the problem domain
Only a single instance of Domain class can be created
"""
def __init__(self):
super().__init__()
# Input file stream for reading data from input data file
self.input_file = None
# Heading information for use in labeling the output
self.Title = '0'
# Solution MODEX
# 0 : Data check only
# 1 : Execution
self.MODEX = 0
# Total number of nodal points
self.NUMNP = 0
# List of all nodes in the domain
self.NodeList = []
# Total number of element groups
self.NUMEG = 0
# Element group list
self.EleGrpList = []
# Number of load cases
self.NLCASE = 0
# Number of concentrated loads applied in each load case
self.NLOAD = []
# List of all load cases
self.LoadCases = []
# Total number of equations in the system
self.NEQ = 0
# Global nodal force/displacement vector
self.Force = None
# Banded stiffness matrix
# A one-dimensional array storing only the elements below the
# skyline of the global stiffness matrix.
self.StiffnessMatrix = None
def GetMODEX(self):
return self.MODEX
def GetTitle(self):
return self.Title
def GetNEQ(self):
return self.NEQ
def GetNUMNP(self):
return self.NUMNP
def GetNodeList(self):
return self.NodeList
def GetNUMEG(self):
return self.NUMEG
def GetEleGrpList(self):
return self.EleGrpList
def GetForce(self):
return self.Force
def GetDisplacement(self):
return self.Force
def GetNLCASE(self):
return self.NLCASE
def GetNLOAD(self):
return self.NLOAD
def GetLoadCases(self):
return self.LoadCases
def GetStiffnessMatrix(self):
return self.StiffnessMatrix
def ReadData(self, input_filename, output_filename):
""" Read domain data from the input data file """
try:
self.input_file = open(input_filename)
except FileNotFoundError as e:
print(e)
sys.exit(3)
Output = COutputter(output_filename)
# Read the heading line
self.Title = self.input_file.readline()
Output.OutputHeading()
# Read the control line
line = self.input_file.readline().split()
self.NUMNP = int(line[0])
self.NUMEG = int(line[1])
self.NLCASE = int(line[2])
self.MODEX = int(line[3])
# Read nodal point data
if self.ReadNodalPoints():
Output.OutputNodeInfo()
else:
return False
# Update equation number
self.CalculateEquationNumber()
Output.OutputEquationNumber()
# Read load data
if self.ReadLoadCases():
Output.OutputLoadInfo()
else:
return False
# Read element data
if self.ReadElements():
Output.OutputElementInfo()
else:
return False
return True
def ReadNodalPoints(self):
""" Read nodal point data """
self.NodeList = [CNode() for _ in range(self.NUMNP)]
for np in range(self.NUMNP):
try:
self.NodeList[np].Read(self.input_file, np)
except ValueError as e:
print(e)
return False
return True
def CalculateEquationNumber(self):
"""
Calculate global equation numbers corresponding to every
degree of freedom of each node
"""
self.NEQ = 0
for np in range(self.NUMNP):
for dof in range(CNode.NDF):
if self.NodeList[np].bcode[dof]:
self.NodeList[np].bcode[dof] = 0
else:
self.NEQ += 1
self.NodeList[np].bcode[dof] = self.NEQ
def ReadLoadCases(self):
""" Read load case data """
self.LoadCases = [CLoadCaseData() for _ in range(self.NLCASE)]
for lcase in range(self.NLCASE):
try:
self.LoadCases[lcase].Read(self.input_file, lcase)
except ValueError as e:
print(e)
return False
return True
def ReadElements(self):
""" Read element data """
self.EleGrpList = [CElementGroup() for _ in range(self.NUMEG)]
for EleGrp in range(self.NUMEG):
if not self.EleGrpList[EleGrp].Read(self.input_file):
return False
return True
def CalculateColumnHeights(self):
""" Calculate column heights """
for EleGrp in range(self.NUMEG):
ElementGrp = self.EleGrpList[EleGrp]
NUME = ElementGrp.GetNUME()
for Ele in range(NUME):
Element = ElementGrp[Ele]
Element.GenerateLocationMatrix()
self.StiffnessMatrix.CalculateColumnHeight(
Element.GetLocationMatrix(), Element.GetND())
self.StiffnessMatrix.CalculateMaximumHalfBandwidth()
def AssembleStiffnessMatrix(self):
""" Assemble the banded gloabl stiffness matrix """
# Loop over for all element groups
for EleGrp in range(self.NUMEG):
ElementGrp = self.EleGrpList[EleGrp]
NUME = ElementGrp.GetNUME()
size = ElementGrp[0].SizeOfStiffnessMatrix()
Matrix = np.zeros(size, dtype=np.double)
# Loop over for all elements in group EleGrp
for Ele in range(NUME):
Element = ElementGrp[Ele]
Element.ElementStiffness(Matrix)
self.StiffnessMatrix.Assembly(Matrix,
Element.GetLocationMatrix(), Element.GetND())
del Matrix
def AssembleForce(self, LoadCase):
""" Assemble the global nodal force vector for load case LoadCase """
if LoadCase > self.NLCASE:
return False
LoadData = self.LoadCases[LoadCase - 1]
# Loop over for all concentrated loads in load case LoadCase
for lnum in range(LoadData.nloads):
dof = self.NodeList[LoadData.node[lnum]-1].bcode[LoadData.dof[lnum]-1]
if dof:
self.Force[dof - 1] += LoadData.load[lnum]
return True
def AllocateMatrices(self):
"""
Allocate storage for matrices Force, ColumnHeights, DiagonalAddress
and StiffnessMatrix and calculate the column heights and address
of diagonal elements
"""
# Allocate for global force/displacement vector
self.Force = np.zeros(self.NEQ, dtype=np.double)
# Create the banded stiffness matrix
self.StiffnessMatrix = CSkylineMatrix(self.NEQ)
# Calculate column heights
self.CalculateColumnHeights()
# Calculate address of diagonal elements in banded matrix
self.StiffnessMatrix.CalculateDiagnoalAddress()
# Allocate for banded global stiffness matrix
self.StiffnessMatrix.Allocate()
Output = COutputter()
Output.OutputTotalSystemData()