-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathfront2back.py
437 lines (305 loc) · 12.9 KB
/
front2back.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
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
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
import numpy as np
class BackendJob:
def __init__(self, name):
# Specify default job name
self.setName(name)
# Specify default model value
self.setModel(0)
# Specify default thickness and damage value
self.setThickness(0.1)
self.setDamage(0.1)
# Set default values for material properties (E, n, T)
self.setMaterial(np.array([[3e10, 0.3, 10]]))
# Set default values for boundary conditions (Kx, Ky, T)
self.setBoundaries(np.array([[1e15, 1e10, 20]]))
# Set default values for corrosion wastage (W, x/L)
self.setCorrosion(np.array([[0.0, 0.5]]))
# Set default values for environmental temperature (T, x/L)
self.setTemperature(np.array([[10, 0.5]]))
# Set default type of analysis
self.setAnalysis('Modal')
# Set default values for modal analysis (Modes, normalization)
self.setModalSettings(5, 'Mass')
# Set default values for time history analysis (a, b, period, step, load)
self.setTimeHistorySettings(0.002, 0.0001, 50, 0.005, 0)
def setName(self, name):
"""
Specify the name of the job.
Parameters
----------
name: str
The name of the job.
"""
self._name = name
def getName(self):
return self._name
def setModel(self, model):
"""
Specify the model to be analyzed.
Parameters
----------
model: {0, 1, 2, 3, 4, 5, 6}
The model index corresponding to the following cases:
0: Healhty state
1: Damage state 1
2: Damage state 2
3: Damage state 3
4: Damage state 4
5: Damage state 5
6: Damage state 6
"""
self._model = model
def getModel(self):
return self._model
def setThickness(self, thickness):
"""
Specify the model thickness.
Parameters
----------
thickness: float, positive
The thickness of the model.
"""
self._thickness = thickness
def getThickness(self):
return self._thickness
def setDamage(self, damage):
"""
Specify the degree of severity, i.e., stiffness reduction, at the
damaged areas.
Parameters
----------
damage: float
The percentage [0-1] of stiffness reduction at the damaged areas.
"""
self._damage = damage
def getDamage(self):
return self._damage
def setMaterial(self, material):
"""
Specify the material properties and their dependency on temperature.
Parameters
----------
material: ndarray
The 2-dimensional ndarray of shape n x 3 containing the
dependency of material properties on temperature, with n
representing the number of temperature values at which the
material properties are specified. The first two columns of the
array contain the values of elastic molulus and Poisson ratio and
the second one stores the corresponding temperatures of each
property value. If only one temperature value is specified, the
material properties are temperature independent.
Example
-------
job = Job('Job-1')
material = np.array([
[2.1e11, 0.3, 0],
[1.9e11, 0.3, 20],
[1.8e11, 0.1, 30]])
job.setMaterial(material)
"""
self._material = material
def getMaterial(self):
return self._material
def setBoundaries(self, boundary1, boundary2=None, boundary3=None):
"""
Specify the boundary conditions and their dependency on temperature.
Parameters
----------
boundary1: ndarray
The 2-dimensional ndarray of shape n x 3 containing the dependency
of boundary conditions at the left-most support point on
temperature, with n being the number of temperature values at
which the boundary stiffness is specified. The first two columns
of the array contain the values of stiffness in x and y directions
and the second one stores the corresponding temperature values.
If only one temperature value is specified, boundary conditions
are temperature independent.
boundary2: ndarray, optional
Similar to boundary1 but referring to the support point at the
middle of the system.
boundary3: ndarray, optional
Similar to boundary1 but referring to the rightmost support point.
"""
self._boundary1 = boundary1
self._boundary2 = boundary1 if boundary2 is None else boundary2
self._boundary3 = boundary1 if boundary3 is None else boundary3
return self._boundary1, self._boundary2, self._boundary3
def getBoundaries(self):
return self._boundary1, self._boundary2, self._boundary3
def setCorrosion(self, corrosion):
"""
Specify the distribution of corrosion wastage along the length of
the system.
Parameters
----------
corrosion: ndarray
The 2-dimensional ndarray of shape n x 2 containing the
distribution of corrosion wastage, with n representing the number
of points in space at which the temperature is specified. The
first column of the array contains the values of corrosion wastage
and the second one stores the corresponding position (x / L) of
each corrosion value. A uniform profile is assumed when only a
single point in space is specified.
"""
self._corrosion = corrosion
def getCorrosion(self):
return self._corrosion
def setTemperature(self, temperature):
"""
Specify the distribution of temperature along the length of the system.
Parameters
----------
temperature: ndarray
The 2-dimensional ndarray of shape n x 2 containing the
distibution of temperature, with n representing the number of
points in space at which the temperature is specified. The first
column of the array contains the temperature values and the second
one stores the corresponding position (x / L) of each temperature
value. A uniform profile is assumed when only a single point in
space is specified.
"""
self._temperature = temperature
def getTemperature(self):
return self._temperature
def setAnalysis(self, analysis):
"""
Specify the type of analysis to be performed.
Parameters
----------
analysis: {'Modal', 'Time history'}
The type of analysis to be executed.
"""
self._analysis = analysis
def getAnalysis(self):
return self._analysis
def setModalSettings(self, modes, normalization):
"""
Specify the settings for modal analysis.
Parameters
----------
modes: int, positive
The number of vibration modes to be extracted.
normalization: {'Mass', 'Displacement'}
The normalization method mode shapes.
"""
self._modalSettings = {}
self._modalSettings['Modes'] = modes
self._modalSettings['Normalization'] = normalization
def getModalSettings(self):
return self._modalSettings
def setTimeHistorySettings(self, alpha, beta, period, increment, lcase):
"""
Specify the settings for time history analysis.
Parameters
----------
alpha: float, positive
The alpha coefficient of Rayleigh damping.
beta: float, positive
The beta coefficient of Rayleigh damping.
period: float, positive
The total simulation period.
increment: float, positive
The time increment.
lcase: {0, 1, 2, 3}
The load case index.
"""
self._timeHistorySettings = {}
self._timeHistorySettings['Alpha'] = alpha
self._timeHistorySettings['Beta'] = beta
self._timeHistorySettings['Period'] = period
self._timeHistorySettings['Increment'] = increment
self._timeHistorySettings['lcase'] = lcase
def getTimeHistorySettings(self):
return self._timeHistorySettings
def convert(frontJob):
"""
Convert frontend job to backend job.
Parameters
----------
frontJob: gui.Job
The frontend job instance.
Returns
-------
backJob: Job
The backend job instance.
"""
backJob = BackendJob(frontJob.getName())
backJob.setModel(frontJob.getModel())
backJob.setThickness(frontJob.getThickness())
backJob.setDamage(frontJob.getDamage())
# Convert material properties data
frontMaterial = frontJob.getMaterial()
if frontMaterial['temperature'] == False:
backMaterial = np.zeros((1, 3))
for index in [(0, 0), (0, 1)]:
backMaterial[index] = float(frontMaterial['values'][index])
else:
rows = np.max([item[0] for item in frontMaterial['values'].keys()])+1
cols = np.max([item[1] for item in frontMaterial['values'].keys()])+1
backMaterial = np.zeros((rows, cols))
for index, value in frontMaterial['values'].items():
backMaterial[index] = float(value)
backJob.setMaterial(backMaterial)
print('backmaterial', backMaterial)
# Convert boundary conditions data
frontBoundaries = frontJob.getBoundaries()
if frontBoundaries['identical'] == True:
if frontBoundaries['temperature'] == False:
backBoundaries = np.zeros((1, 3))
for index in [(0, 0), (0, 1)]:
backBoundaries[index] = float(frontBoundaries['values1'][index])
else: # this case does not work
rows = np.max([item[0] for item in frontBoundaries['values1'].keys()])+1
cols = np.max([item[1] for item in frontBoundaries['values1'].keys()])+1
backBoundaries = np.zeros((rows, cols))
for index, value in frontBoundaries['values1'].items():
backBoundaries[index] = float(value)
backBoundary1 = backBoundary2 = backBoundary3 = backBoundaries
else:
if frontBoundaries['temperature'] == True:
backBoundaries = [np.zeros((1, 3)), np.zeros((1, 3)), np.zeros((1, 3))]
for j, key in zip(range(3), ['values1', 'values2', 'values3']):
for index in [(0, 0), (0, 1)]:
value = float(frontBoundaries[key][index])
backBoundaries[j][index] = value
else:
backBoundaries = []
for j, key in zip(range(3), ['values1', 'values2', 'values3']):
rows = np.max([item[0] for item in frontBoundaries[key].keys()])+1
cols = np.max([item[1] for item in frontBoundaries[key].keys()])+1
backBoundaries.append(np.zeros((rows, cols)))
for index, value in frontBoundaries[key].items():
backBoundaries[j][index] = float(value)
backBoundary1, backBoundary2, backBoundary3 = backBoundaries
backJob.setBoundaries(backBoundary1, backBoundary2, backBoundary3)
print('backBoundaries', backBoundary1, backBoundary2, backBoundary3)
# Convert corrosion wastage data
frontCorrosion = frontJob.getCorrosion()
if frontCorrosion['spatial'] == False:
backCorrosion = np.zeros((1, 2))
backCorrosion[0, 1] = float(frontCorrosion['values'][(0, 0)])
else:
rows = np.max([item[0] for item in frontCorrosion['values'].keys()])+1
cols = np.max([item[1] for item in frontCorrosion['values'].keys()])+1
backCorrosion = np.zeros((rows, cols))
for index, value in frontCorrosion.items():
backCorrosion[index] = float(value)
backJob.setCorrosion(backCorrosion)
print('backcorrosion', backCorrosion)
# Convert temperature data
frontTemperature = frontJob.getTemperature()
if frontTemperature['spatial'] == False:
backTemperature = np.zeros((1, 2))
backTemperature[0, 1] = float(frontTemperature['values'][(0, 0)])
else:
rows = np.max([item[0] for item in frontTemperature['values'].keys()])+1
cols = np.max([item[1] for item in frontTemperature['values'].keys()])+1
for index, value in frontTemperature.items():
backTemperature[index] = float(value)
backJob.setTemperature(backTemperature)
print('backtemperature', backTemperature)
# Convert analysis type and settings
backJob.setAnalysis(frontJob.getAnalysis())
backJob.setModalSettings(*frontJob.getModalSettings().values())
backJob.setTimeHistorySettings(*frontJob.getTimeHistorySettings().values())
return backJob