ccm commited on
Commit
3c4eca6
·
1 Parent(s): 254dcfa

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -1414
app.py CHANGED
@@ -1,1424 +1,24 @@
1
- import keras
2
  import numpy
3
  import gradio
4
- import pandas
5
- import glob
6
- import os
7
- import shutil
8
- import stat
9
- import math
10
- import platform
11
- import scipy.spatial
12
- import plotly.graph_objects as go
13
- import random
14
  from huggingface_hub import from_pretrained_keras
15
 
16
- def load_data():
 
 
 
 
17
 
18
- from datasets import load_dataset
19
-
20
- data = load_dataset("cmudrc/wave-energy", data_files="data.csv", split='train').to_pandas()
21
-
22
- # Open all the files we downloaded at the beginning and take out hte good bits
23
- curves = data.iloc[:, [i for i in range(1, 3*64+1)]]
24
- geometry = data.iloc[:, [i for i in range(1 + 3*64, 1 + 3*64 + 32**3)]]
25
- S = 5
26
- N = 1000
27
- D = 3
28
- F = 64
29
- G = 32
30
-
31
- flattened_curves = curves.values / 1000000
32
- curvey_curves = [c.reshape([3, 64]) for c in flattened_curves]
33
-
34
- flattened_geometry = geometry.values
35
- round_geometry = [g.reshape([32, 32, 32]) for g in flattened_geometry]
36
-
37
- # Return good bits to user
38
- return curvey_curves, round_geometry, S, N, D, F, G, flattened_curves, flattened_geometry
39
-
40
- # Disable eager execution because its bad
41
- from tensorflow.python.framework.ops import disable_eager_execution
42
- disable_eager_execution()
43
-
44
- class Mesh:
45
- def __init__(self):
46
- # Define blank values
47
- self.np = 0
48
- self.nf = 0
49
- self.X = []
50
- self.Y = []
51
- self.Z = []
52
- self.P = []
53
-
54
- def combine_meshes(self, ob1, ob2):
55
- # Check for largest mesh
56
- if ob1.nf < ob2.nf:
57
- coin_test = ob1.make_coin()
58
- coin_target = ob2.make_coin()
59
- else:
60
- coin_test = ob2.make_coin()
61
- coin_target = ob1.make_coin()
62
- # Check for duplicate panels
63
- deletion_list = []
64
- for iF in range(numpy.size(coin_test[1, 1, :])):
65
- panel_test = coin_test[:, :, iF]
66
- for iFF in range(numpy.size(coin_target[1, 1, :])):
67
- panel_target = coin_target[:, :, iFF]
68
- if numpy.sum(panel_test == panel_target) == 12:
69
- coin_target = numpy.delete(coin_target, iFF, 2)
70
- deletion_list.append(iF)
71
- coin_test = numpy.delete(coin_test, deletion_list, 2)
72
-
73
- # Concatenate unique meshes
74
- coin = numpy.concatenate((coin_test, coin_target), axis=2)
75
- self.np = numpy.size(coin[1, 1, :]) * 4
76
- self.nf = numpy.size(coin[1, 1, :])
77
- self.X = numpy.zeros(numpy.size(coin[1, 1, :]) * 4)
78
- self.Y = numpy.zeros(numpy.size(coin[1, 1, :]) * 4)
79
- self.Z = numpy.zeros(numpy.size(coin[1, 1, :]) * 4)
80
- self.P = numpy.zeros((numpy.size(coin[1, 1, :]), 4), dtype=int)
81
-
82
- iP = 0
83
- for iF in range(numpy.size(coin[1, 1, :])):
84
- for iC in range(4):
85
- self.X[iP] = coin[0, iC, iF]
86
- self.Y[iP] = coin[1, iC, iF]
87
- self.Z[iP] = coin[2, iC, iF]
88
- iP += 1
89
- self.P[iF, 0] = 1 + iF * 4
90
- self.P[iF, 1] = 2 + iF * 4
91
- self.P[iF, 2] = 3 + iF * 4
92
- self.P[iF, 3] = 4 + iF * 4
93
-
94
- def make_coin(self):
95
- coin = numpy.zeros((3, 4, self.nf))
96
- for iF in range(self.nf):
97
- for iC in range(4):
98
- coin[0, iC, iF] = self.X[self.P[iF, iC] - 1]
99
- coin[1, iC, iF] = self.Y[self.P[iF, iC] - 1]
100
- coin[2, iC, iF] = self.Z[self.P[iF, iC] - 1]
101
- return coin
102
-
103
- def delete_horizontal_panels(self):
104
- coin = self.make_coin()
105
- apex = numpy.min(self.Z)
106
- zLoc = numpy.zeros(4)
107
- deletion_list = []
108
-
109
- # Check every panel for horizontality and higher position than lowest point
110
- for iP in range(self.nf):
111
- for iC in range(4):
112
- zLoc[iC] = coin[2, iC, iP]
113
- if numpy.abs(numpy.mean(zLoc) - zLoc[0]) < 0.001 and numpy.mean(zLoc) > apex:
114
- deletion_list.append(iP)
115
-
116
- # Delete selected panels
117
- coin = numpy.delete(coin, deletion_list, 2)
118
-
119
- # Remake mesh
120
- self.np = numpy.size(coin[1, 1, :]) * 4
121
- self.nf = numpy.size(coin[1, 1, :])
122
- self.X = numpy.zeros(numpy.size(coin[1, 1, :]) * 4)
123
- self.Y = numpy.zeros(numpy.size(coin[1, 1, :]) * 4)
124
- self.Z = numpy.zeros(numpy.size(coin[1, 1, :]) * 4)
125
- self.P = numpy.zeros((numpy.size(coin[1, 1, :]), 4), dtype=int)
126
-
127
- iP = 0
128
- for iF in range(numpy.size(coin[1, 1, :])):
129
- for iC in range(4):
130
- self.X[iP] = coin[0, iC, iF]
131
- self.Y[iP] = coin[1, iC, iF]
132
- self.Z[iP] = coin[2, iC, iF]
133
- iP += 1
134
- self.P[iF, 0] = 1 + (iF) * 4
135
- self.P[iF, 1] = 2 + (iF) * 4
136
- self.P[iF, 2] = 3 + (iF) * 4
137
- self.P[iF, 3] = 4 + (iF) * 4
138
-
139
-
140
-
141
-
142
- def writeMesh(msh, filename):
143
- with open(filename, 'w') as f:
144
- f.write('{:d}\n'.format(msh.np))
145
- f.write('{:d}\n'.format(msh.nf))
146
- for iP in range(msh.np):
147
- f.write(' {:.7f} {:.7f} {:.7f}\n'.format(msh.X[iP], msh.Y[iP], msh.Z[iP]))
148
- for iF in range(msh.nf):
149
- f.write(' {:d} {:d} {:d} {:d}\n'.format(msh.P[iF, 0], msh.P[iF, 1], msh.P[iF, 2], msh.P[iF, 3]))
150
- return None
151
-
152
-
153
-
154
- class box:
155
- def __init__(self, length, width, height, cCor):
156
- self.length = length
157
- self.width = width
158
- self.height = height
159
- self.xC = cCor[0]
160
- self.yC = cCor[1]
161
- self.zC = cCor[2]
162
- self.name = 'box'
163
- self.panelize()
164
- self.translate(self.xC, self.yC, self.zC)
165
-
166
- def panelize(self):
167
- self.nf = 6
168
- self.np = 8
169
- self.X = numpy.array(
170
- [-self.length / 2.0, self.length / 2.0, -self.length / 2.0, self.length / 2.0, -self.length / 2.0,
171
- self.length / 2.0, -self.length / 2.0, self.length / 2.0])
172
- self.Y = numpy.array([self.width / 2.0, self.width / 2.0, self.width / 2.0, self.width / 2.0, -self.width / 2.0,
173
- -self.width / 2.0, -self.width / 2.0, -self.width / 2.0])
174
- self.Z = numpy.array(
175
- [-self.height / 2.0, -self.height / 2.0, self.height / 2.0, self.height / 2.0, -self.height / 2.0,
176
- -self.height / 2.0, self.height / 2.0, self.height / 2.0])
177
- self.P = numpy.zeros([6, 4], dtype=int)
178
- self.P[0, :] = numpy.array([3, 4, 2, 1])
179
- self.P[1, :] = numpy.array([4, 8, 6, 2])
180
- self.P[2, :] = numpy.array([8, 7, 5, 6])
181
- self.P[3, :] = numpy.array([7, 3, 1, 5])
182
- self.P[4, :] = numpy.array([2, 6, 5, 1])
183
- self.P[5, :] = numpy.array([8, 4, 3, 7])
184
- # Define triangles for plotting
185
- self.trii = numpy.zeros([2 * self.nf, 3], dtype=int)
186
- iT = 0
187
- for iTr in range(self.nf):
188
- self.trii[iT, :] = [self.P[iTr, 0] - 1, self.P[iTr, 1] - 1, self.P[iTr, 2] - 1]
189
- self.trii[iT + 1, :] = [self.P[iTr, 0] - 1, self.P[iTr, 2] - 1, self.P[iTr, 3] - 1]
190
- iT += 2
191
-
192
- def translate(self, xT, yT, zT):
193
- self.X += xT
194
- self.Y += yT
195
- self.Z += zT
196
-
197
- def rotate(self, a1, a2, theta):
198
- R = numpy.zeros([3, 3])
199
- # Normal vector through origin
200
- u = a2[0] - a1[0]
201
- v = a2[1] - a1[1]
202
- w = a2[2] - a1[2]
203
- u = u / numpy.sqrt(u ** 2 + v ** 2 + w ** 2)
204
- v = v / numpy.sqrt(u ** 2 + v ** 2 + w ** 2)
205
- w = w / numpy.sqrt(u ** 2 + v ** 2 + w ** 2)
206
- # Translate mesh so that rotation axis starts from the origin
207
- self.X -= a1[0]
208
- self.Y -= a1[1]
209
- self.Z -= a1[2]
210
-
211
- # Rotation matrix
212
- R[0, 0] = u ** 2 + numpy.cos(theta) * (1 - u ** 2)
213
- R[0, 1] = u * v * (1 - numpy.cos(theta)) - w * numpy.sin(theta)
214
- R[0, 2] = u * w * (1 - numpy.cos(theta)) + v * numpy.sin(theta)
215
- R[1, 0] = u * v * (1 - numpy.cos(theta)) + w * numpy.sin(theta)
216
- R[1, 1] = v ** 2 + numpy.cos(theta) * (1 - v ** 2)
217
- R[1, 2] = v * w * (1 - numpy.cos(theta)) - u * numpy.sin(theta)
218
- R[2, 0] = w * u * (1 - numpy.cos(theta)) - v * numpy.sin(theta)
219
- R[2, 1] = w * v * (1 - numpy.cos(theta)) + u * numpy.sin(theta)
220
- R[2, 2] = w ** 2 + numpy.cos(theta) * (1 - w ** 2)
221
-
222
- for iP in range(self.np):
223
- p1 = numpy.array([self.X[iP], self.Y[iP], self.Z[iP]])
224
- p2 = numpy.dot(R, p1)
225
- self.X[iP] = p2[0]
226
- self.Y[iP] = p2[1]
227
- self.Z[iP] = p2[2]
228
-
229
- # Translate back to original position
230
-
231
- self.X += a1[0]
232
- self.Y += a1[1]
233
- self.Z += a1[2]
234
-
235
- def makeCoin(self):
236
- coin = numpy.zeros((3, 4, self.nf))
237
- for iF in range(self.nf):
238
- for iC in range(4):
239
- coin[0, iC, iF] = self.X[self.P[iF, iC] - 1]
240
- coin[1, iC, iF] = self.Y[self.P[iF, iC] - 1]
241
- coin[2, iC, iF] = self.Z[self.P[iF, iC] - 1]
242
- return coin
243
-
244
-
245
-
246
-
247
- class cone:
248
- def __init__(self, diameter, height, cCor):
249
- self.diameter = diameter
250
- self.height = height
251
- self.xC = cCor[0]
252
- self.yC = cCor[1]
253
- self.zC = cCor[2]
254
- self.name = 'cone'
255
- self.panelize()
256
- self.translate(self.xC, self.yC, self.zC)
257
-
258
- def panelize(self):
259
- Ntheta = 18
260
- Nz = 3
261
- theta = [xx * 2 * numpy.pi / (Ntheta - 1) for xx in range(Ntheta)]
262
- self.nf = 0
263
- self.np = 0
264
- r = [0, self.diameter / 2.0, 0]
265
- z = [0, 0, -self.height]
266
- self.X = []
267
- self.Y = []
268
- self.Z = []
269
- self.P = numpy.zeros([(len(r) - 1) * (Ntheta - 1), 4], dtype=int)
270
- n = len(r)
271
-
272
- for iT in range(Ntheta):
273
- for iN in range(n):
274
- self.X.append(r[iN] * numpy.cos(theta[iT]))
275
- self.Y.append(r[iN] * numpy.sin(theta[iT]))
276
- self.Z.append(z[iN])
277
- self.np += 1
278
-
279
- iP = 0
280
- for iN in range(1, n):
281
- for iT in range(1, Ntheta):
282
- self.P[iP, 0] = iN + n * (iT - 1)
283
- self.P[iP, 1] = iN + 1 + n * (iT - 1)
284
- self.P[iP, 2] = iN + 1 + n * iT
285
- self.P[iP, 3] = iN + n * iT
286
- self.nf += 1
287
- iP += 1
288
-
289
- self.X = numpy.array(self.X)
290
- self.Y = numpy.array(self.Y)
291
- self.Z = numpy.array(self.Z)
292
- # Define triangles for plotting
293
- self.trii = numpy.zeros([2 * self.nf, 3], dtype=int)
294
- iT = 0
295
- for iTr in range(self.nf):
296
- self.trii[iT, :] = [self.P[iTr, 0] - 1, self.P[iTr, 1] - 1, self.P[iTr, 2] - 1]
297
- self.trii[iT + 1, :] = [self.P[iTr, 0] - 1, self.P[iTr, 2] - 1, self.P[iTr, 3] - 1]
298
- iT += 2
299
-
300
- def translate(self, xT, yT, zT):
301
- self.X += xT
302
- self.Y += yT
303
- self.Z += zT
304
-
305
- def rotate(self, a1, a2, theta):
306
- R = numpy.zeros([3, 3])
307
- # Normal vector through origin
308
- u = a2[0] - a1[0]
309
- v = a2[1] - a1[1]
310
- w = a2[2] - a1[2]
311
- u = u / numpy.sqrt(u ** 2 + v ** 2 + w ** 2)
312
- v = v / numpy.sqrt(u ** 2 + v ** 2 + w ** 2)
313
- w = w / numpy.sqrt(u ** 2 + v ** 2 + w ** 2)
314
- # Translate mesh so that rotation axis starts from the origin
315
- self.X -= a1[0]
316
- self.Y -= a1[1]
317
- self.Z -= a1[2]
318
-
319
- # Rotation matrix
320
- R[0, 0] = u ** 2 + numpy.cos(theta) * (1 - u ** 2)
321
- R[0, 1] = u * v * (1 - numpy.cos(theta)) - w * numpy.sin(theta)
322
- R[0, 2] = u * w * (1 - numpy.cos(theta)) + v * numpy.sin(theta)
323
- R[1, 0] = u * v * (1 - numpy.cos(theta)) + w * numpy.sin(theta)
324
- R[1, 1] = v ** 2 + numpy.cos(theta) * (1 - v ** 2)
325
- R[1, 2] = v * w * (1 - numpy.cos(theta)) - u * numpy.sin(theta)
326
- R[2, 0] = w * u * (1 - numpy.cos(theta)) - v * numpy.sin(theta)
327
- R[2, 1] = w * v * (1 - numpy.cos(theta)) + u * numpy.sin(theta)
328
- R[2, 2] = w ** 2 + numpy.cos(theta) * (1 - w ** 2)
329
-
330
- for iP in range(self.np):
331
- p1 = numpy.array([self.X[iP], self.Y[iP], self.Z[iP]])
332
- p2 = numpy.dot(R, p1)
333
- self.X[iP] = p2[0]
334
- self.Y[iP] = p2[1]
335
- self.Z[iP] = p2[2]
336
-
337
- # Translate back to original position
338
-
339
- self.X += a1[0]
340
- self.Y += a1[1]
341
- self.Z += a1[2]
342
-
343
- def makeCoin(self):
344
- coin = numpy.zeros((3, 4, self.nf))
345
- for iF in range(self.nf):
346
- for iC in range(4):
347
- coin[0, iC, iF] = self.X[self.P[iF, iC] - 1]
348
- coin[1, iC, iF] = self.Y[self.P[iF, iC] - 1]
349
- coin[2, iC, iF] = self.Z[self.P[iF, iC] - 1]
350
- return coin
351
-
352
-
353
-
354
- class cylinder:
355
- def __init__(self, diameter, height, cCor):
356
- self.diameter = diameter
357
- self.height = height
358
- self.xC = cCor[0]
359
- self.yC = cCor[1]
360
- self.zC = cCor[2]
361
- self.name = 'cylinder'
362
- self.panelize()
363
- self.translate(self.xC, self.yC, self.zC)
364
-
365
- def panelize(self):
366
- Ntheta = 18
367
- Nz = 3
368
- theta = [xx * 2 * numpy.pi / (Ntheta - 1) for xx in range(Ntheta)]
369
- self.nf = 0
370
- self.np = 0
371
- r = [0, self.diameter / 2.0, self.diameter / 2.0, 0]
372
- z = [0, 0, -self.height, -self.height]
373
- self.X = []
374
- self.Y = []
375
- self.Z = []
376
- self.P = numpy.zeros([(len(r) - 1) * (Ntheta - 1), 4], dtype=int)
377
- n = len(r)
378
-
379
- for iT in range(Ntheta):
380
- for iN in range(n):
381
- self.X.append(r[iN] * numpy.cos(theta[iT]))
382
- self.Y.append(r[iN] * numpy.sin(theta[iT]))
383
- self.Z.append(z[iN])
384
- self.np += 1
385
-
386
- iP = 0
387
- for iN in range(1, n):
388
- for iT in range(1, Ntheta):
389
- self.P[iP, 0] = iN + n * (iT - 1)
390
- self.P[iP, 1] = iN + 1 + n * (iT - 1)
391
- self.P[iP, 2] = iN + 1 + n * iT
392
- self.P[iP, 3] = iN + n * iT
393
- self.nf += 1
394
- iP += 1
395
-
396
- self.X = numpy.array(self.X)
397
- self.Y = numpy.array(self.Y)
398
- self.Z = numpy.array(self.Z)
399
- # Define triangles for plotting
400
- self.trii = numpy.zeros([2 * self.nf, 3], dtype=int)
401
- iT = 0
402
- for iTr in range(self.nf):
403
- self.trii[iT, :] = [self.P[iTr, 0] - 1, self.P[iTr, 1] - 1, self.P[iTr, 2] - 1]
404
- self.trii[iT + 1, :] = [self.P[iTr, 0] - 1, self.P[iTr, 2] - 1, self.P[iTr, 3] - 1]
405
- iT += 2
406
-
407
- def translate(self, xT, yT, zT):
408
- self.X += xT
409
- self.Y += yT
410
- self.Z += zT
411
-
412
- def rotate(self, a1, a2, theta):
413
- R = numpy.zeros([3, 3])
414
- # Normal vector through origin
415
- u = a2[0] - a1[0]
416
- v = a2[1] - a1[1]
417
- w = a2[2] - a1[2]
418
- u = u / numpy.sqrt(u ** 2 + v ** 2 + w ** 2)
419
- v = v / numpy.sqrt(u ** 2 + v ** 2 + w ** 2)
420
- w = w / numpy.sqrt(u ** 2 + v ** 2 + w ** 2)
421
- # Translate mesh so that rotation axis starts from the origin
422
- self.X -= a1[0]
423
- self.Y -= a1[1]
424
- self.Z -= a1[2]
425
-
426
- # Rotation matrix
427
- R[0, 0] = u ** 2 + numpy.cos(theta) * (1 - u ** 2)
428
- R[0, 1] = u * v * (1 - numpy.cos(theta)) - w * numpy.sin(theta)
429
- R[0, 2] = u * w * (1 - numpy.cos(theta)) + v * numpy.sin(theta)
430
- R[1, 0] = u * v * (1 - numpy.cos(theta)) + w * numpy.sin(theta)
431
- R[1, 1] = v ** 2 + numpy.cos(theta) * (1 - v ** 2)
432
- R[1, 2] = v * w * (1 - numpy.cos(theta)) - u * numpy.sin(theta)
433
- R[2, 0] = w * u * (1 - numpy.cos(theta)) - v * numpy.sin(theta)
434
- R[2, 1] = w * v * (1 - numpy.cos(theta)) + u * numpy.sin(theta)
435
- R[2, 2] = w ** 2 + numpy.cos(theta) * (1 - w ** 2)
436
-
437
- for iP in range(self.np):
438
- p1 = numpy.array([self.X[iP], self.Y[iP], self.Z[iP]])
439
- p2 = numpy.dot(R, p1)
440
- self.X[iP] = p2[0]
441
- self.Y[iP] = p2[1]
442
- self.Z[iP] = p2[2]
443
-
444
- # Translate back to original position
445
-
446
- self.X += a1[0]
447
- self.Y += a1[1]
448
- self.Z += a1[2]
449
-
450
- def makeCoin(self):
451
- coin = numpy.zeros((3, 4, self.nf))
452
- for iF in range(self.nf):
453
- for iC in range(4):
454
- coin[0, iC, iF] = self.X[self.P[iF, iC] - 1]
455
- coin[1, iC, iF] = self.Y[self.P[iF, iC] - 1]
456
- coin[2, iC, iF] = self.Z[self.P[iF, iC] - 1]
457
- return coin
458
-
459
-
460
-
461
-
462
- class hemicylinder:
463
- def __init__(self, diameter, height, cCor):
464
- self.diameter = diameter
465
- self.height = height
466
- self.xC = cCor[0]
467
- self.yC = cCor[1]
468
- self.zC = cCor[2]
469
- self.name = 'hemicylinder'
470
- self.panelize()
471
- self.translate(self.xC, self.yC, self.zC)
472
-
473
- def panelize(self):
474
- Ntheta = 18
475
- Nz = 3
476
- theta = [xx * numpy.pi / (Ntheta - 1) - numpy.pi / 2.0 for xx in range(Ntheta)]
477
- self.nf = 0
478
- self.np = 0
479
- r = [0, self.diameter / 2.0, self.diameter / 2.0, 0]
480
- z = [self.height / 2.0, self.height / 2.0, -self.height / 2.0, -self.height / 2.0]
481
- self.X = []
482
- self.Y = []
483
- self.Z = []
484
- self.P = numpy.zeros([(len(r) - 1) * (Ntheta - 1), 4], dtype=int)
485
- n = len(r)
486
-
487
- for iT in range(Ntheta):
488
- for iN in range(n):
489
- self.Z.append(-r[iN] * numpy.cos(theta[iT]))
490
- self.X.append(r[iN] * numpy.sin(theta[iT]))
491
- self.Y.append(z[iN])
492
- self.np += 1
493
-
494
- iP = 0
495
- for iN in range(1, n):
496
- for iT in range(1, Ntheta):
497
- self.P[iP, 3] = iN + n * (iT - 1)
498
- self.P[iP, 2] = iN + 1 + n * (iT - 1)
499
- self.P[iP, 1] = iN + 1 + n * iT
500
- self.P[iP, 0] = iN + n * iT
501
- self.nf += 1
502
- iP += 1
503
-
504
- self.X = numpy.array(self.X)
505
- self.Y = numpy.array(self.Y)
506
- self.Z = numpy.array(self.Z)
507
- # Define triangles for plotting
508
- self.trii = numpy.zeros([2 * self.nf, 3], dtype=int)
509
- iT = 0
510
- for iTr in range(self.nf):
511
- self.trii[iT, :] = [self.P[iTr, 0] - 1, self.P[iTr, 1] - 1, self.P[iTr, 2] - 1]
512
- self.trii[iT + 1, :] = [self.P[iTr, 0] - 1, self.P[iTr, 2] - 1, self.P[iTr, 3] - 1]
513
- iT += 2
514
-
515
- def translate(self, xT, yT, zT):
516
- self.X += xT
517
- self.Y += yT
518
- self.Z += zT
519
-
520
- def rotate(self, a1, a2, theta):
521
- R = numpy.zeros([3, 3])
522
- # Normal vector through origin
523
- u = a2[0] - a1[0]
524
- v = a2[1] - a1[1]
525
- w = a2[2] - a1[2]
526
- u = u / numpy.sqrt(u ** 2 + v ** 2 + w ** 2)
527
- v = v / numpy.sqrt(u ** 2 + v ** 2 + w ** 2)
528
- w = w / numpy.sqrt(u ** 2 + v ** 2 + w ** 2)
529
- # Translate mesh so that rotation axis starts from the origin
530
- self.X -= a1[0]
531
- self.Y -= a1[1]
532
- self.Z -= a1[2]
533
-
534
- # Rotation matrix
535
- R[0, 0] = u ** 2 + numpy.cos(theta) * (1 - u ** 2)
536
- R[0, 1] = u * v * (1 - numpy.cos(theta)) - w * numpy.sin(theta)
537
- R[0, 2] = u * w * (1 - numpy.cos(theta)) + v * numpy.sin(theta)
538
- R[1, 0] = u * v * (1 - numpy.cos(theta)) + w * numpy.sin(theta)
539
- R[1, 1] = v ** 2 + numpy.cos(theta) * (1 - v ** 2)
540
- R[1, 2] = v * w * (1 - numpy.cos(theta)) - u * numpy.sin(theta)
541
- R[2, 0] = w * u * (1 - numpy.cos(theta)) - v * numpy.sin(theta)
542
- R[2, 1] = w * v * (1 - numpy.cos(theta)) + u * numpy.sin(theta)
543
- R[2, 2] = w ** 2 + numpy.cos(theta) * (1 - w ** 2)
544
-
545
- for iP in range(self.np):
546
- p1 = numpy.array([self.X[iP], self.Y[iP], self.Z[iP]])
547
- p2 = numpy.dot(R, p1)
548
- self.X[iP] = p2[0]
549
- self.Y[iP] = p2[1]
550
- self.Z[iP] = p2[2]
551
-
552
- # Translate back to original position
553
-
554
- self.X += a1[0]
555
- self.Y += a1[1]
556
- self.Z += a1[2]
557
-
558
- def makeCoin(self):
559
- coin = numpy.zeros((3, 4, self.nf))
560
- for iF in range(self.nf):
561
- for iC in range(4):
562
- coin[0, iC, iF] = self.X[self.P[iF, iC] - 1]
563
- coin[1, iC, iF] = self.Y[self.P[iF, iC] - 1]
564
- coin[2, iC, iF] = self.Z[self.P[iF, iC] - 1]
565
- return coin
566
-
567
-
568
- class sphere:
569
- def __init__(self, diameter, cCor):
570
- self.diameter = diameter
571
- self.xC = cCor[0]
572
- self.yC = cCor[1]
573
- self.zC = cCor[2]
574
- self.name = 'sphere'
575
- self.panelize()
576
- self.translate(self.xC, self.yC, self.zC)
577
-
578
- def panelize(self):
579
- Ntheta = 18
580
- Nthetad2 = int(Ntheta / 2)
581
- Nz = 3
582
- theta = [xx * 2 * numpy.pi / (Ntheta - 1) for xx in range(Ntheta)]
583
- phi = [xx * numpy.pi / (Ntheta / 2 - 1) for xx in range(Nthetad2)]
584
- self.nf = 0
585
- self.np = 0
586
- r = self.diameter / 2.0
587
- self.X = []
588
- self.Y = []
589
- self.Z = []
590
- self.P = numpy.zeros([(Ntheta - 1) * (Nthetad2 - 1), 4], dtype=int)
591
-
592
- for iT in range(Nthetad2):
593
- for iTT in range(Ntheta):
594
- self.X.append(r * numpy.cos(theta[iTT]) * numpy.sin(phi[iT]))
595
- self.Y.append(r * numpy.sin(theta[iTT]) * numpy.sin(phi[iT]))
596
- self.Z.append(r * numpy.cos(phi[iT]))
597
- self.np += 1
598
-
599
- iP = 0
600
- for iN in range(1, Ntheta):
601
- for iT in range(1, Nthetad2):
602
- self.P[iP, 3] = iN + Ntheta * (iT - 1)
603
- self.P[iP, 2] = iN + 1 + Ntheta * (iT - 1)
604
- self.P[iP, 1] = iN + 1 + Ntheta * iT
605
- self.P[iP, 0] = iN + Ntheta * iT
606
- self.nf += 1
607
- iP += 1
608
- self.X = numpy.array(self.X)
609
- self.Y = numpy.array(self.Y)
610
- self.Z = numpy.array(self.Z)
611
- # Define triangles for plotting
612
- self.trii = numpy.zeros([2 * self.nf, 3], dtype=int)
613
- iT = 0
614
- for iTr in range(self.nf):
615
- self.trii[iT, :] = [self.P[iTr, 0] - 1, self.P[iTr, 1] - 1, self.P[iTr, 2] - 1]
616
- self.trii[iT + 1, :] = [self.P[iTr, 0] - 1, self.P[iTr, 2] - 1, self.P[iTr, 3] - 1]
617
- iT += 2
618
-
619
- def translate(self, xT, yT, zT):
620
- self.X += xT
621
- self.Y += yT
622
- self.Z += zT
623
-
624
- def rotate(self, a1, a2, theta):
625
- R = numpy.zeros([3, 3])
626
- # Normal vector through origin
627
- u = a2[0] - a1[0]
628
- v = a2[1] - a1[1]
629
- w = a2[2] - a1[2]
630
- u = u / numpy.sqrt(u ** 2 + v ** 2 + w ** 2)
631
- v = v / numpy.sqrt(u ** 2 + v ** 2 + w ** 2)
632
- w = w / numpy.sqrt(u ** 2 + v ** 2 + w ** 2)
633
- # Translate mesh so that rotation axis starts from the origin
634
- self.X -= a1[0]
635
- self.Y -= a1[1]
636
- self.Z -= a1[2]
637
-
638
- # Rotation matrix
639
- R[0, 0] = u ** 2 + numpy.cos(theta) * (1 - u ** 2)
640
- R[0, 1] = u * v * (1 - numpy.cos(theta)) - w * numpy.sin(theta)
641
- R[0, 2] = u * w * (1 - numpy.cos(theta)) + v * numpy.sin(theta)
642
- R[1, 0] = u * v * (1 - numpy.cos(theta)) + w * numpy.sin(theta)
643
- R[1, 1] = v ** 2 + numpy.cos(theta) * (1 - v ** 2)
644
- R[1, 2] = v * w * (1 - numpy.cos(theta)) - u * numpy.sin(theta)
645
- R[2, 0] = w * u * (1 - numpy.cos(theta)) - v * numpy.sin(theta)
646
- R[2, 1] = w * v * (1 - numpy.cos(theta)) + u * numpy.sin(theta)
647
- R[2, 2] = w ** 2 + numpy.cos(theta) * (1 - w ** 2)
648
-
649
- for iP in range(self.np):
650
- p1 = numpy.array([self.X[iP], self.Y[iP], self.Z[iP]])
651
- p2 = numpy.dot(R, p1)
652
- self.X[iP] = p2[0]
653
- self.Y[iP] = p2[1]
654
- self.Z[iP] = p2[2]
655
-
656
- # Translate back to original position
657
-
658
- self.X += a1[0]
659
- self.Y += a1[1]
660
- self.Z += a1[2]
661
-
662
- def makeCoin(self):
663
- coin = numpy.zeros((3, 4, self.nf))
664
- for iF in range(self.nf):
665
- for iC in range(4):
666
- coin[0, iC, iF] = self.X[self.P[iF, iC] - 1]
667
- coin[1, iC, iF] = self.Y[self.P[iF, iC] - 1]
668
- coin[2, iC, iF] = self.Z[self.P[iF, iC] - 1]
669
- return coin
670
-
671
-
672
-
673
-
674
-
675
- class hemisphere:
676
- def __init__(self, diameter, cCor):
677
- self.diameter = diameter
678
- self.xC = cCor[0]
679
- self.yC = cCor[1]
680
- self.zC = cCor[2]
681
- self.name = 'hemisphere'
682
- self.panelize()
683
- self.translate(self.xC, self.yC, self.zC)
684
-
685
- def panelize(self):
686
- Ntheta = 18
687
- theta = [xx * 2 * numpy.pi / (Ntheta - 1) for xx in range(Ntheta)]
688
- phi = [xx * numpy.pi / 2.0 / (Ntheta / 2 - 1) for xx in range(Ntheta / 2)]
689
- self.nf = 0
690
- self.np = 0
691
- r = self.diameter / 2.0
692
- self.X = []
693
- self.Y = []
694
- self.Z = []
695
- self.P = numpy.zeros([(Ntheta - 1) * (Ntheta / 2 - 1), 4], dtype=int)
696
-
697
- for iT in range(Ntheta / 2):
698
- for iTT in range(Ntheta):
699
- self.X.append(r * numpy.cos(theta[iTT]) * numpy.sin(phi[iT]))
700
- self.Y.append(r * numpy.sin(theta[iTT]) * numpy.sin(phi[iT]))
701
- self.Z.append(-r * numpy.cos(phi[iT]))
702
- self.np += 1
703
-
704
- iP = 0
705
- for iN in range(1, Ntheta):
706
- for iT in range(1, Ntheta / 2):
707
- self.P[iP, 0] = iN + Ntheta * (iT - 1)
708
- self.P[iP, 1] = iN + 1 + Ntheta * (iT - 1)
709
- self.P[iP, 2] = iN + 1 + Ntheta * iT
710
- self.P[iP, 3] = iN + Ntheta * iT
711
- self.nf += 1
712
- iP += 1
713
-
714
- self.X = numpy.array(self.X)
715
- self.Y = numpy.array(self.Y)
716
- self.Z = numpy.array(self.Z)
717
- # Define triangles for plotting
718
- self.trii = numpy.zeros([2 * self.nf, 3], dtype=int)
719
- iT = 0
720
- for iTr in range(self.nf):
721
- self.trii[iT, :] = [self.P[iTr, 0] - 1, self.P[iTr, 1] - 1, self.P[iTr, 2] - 1]
722
- self.trii[iT + 1, :] = [self.P[iTr, 0] - 1, self.P[iTr, 2] - 1, self.P[iTr, 3] - 1]
723
- iT += 2
724
-
725
- def translate(self, xT, yT, zT):
726
- self.X += xT
727
- self.Y += yT
728
- self.Z += zT
729
-
730
- def rotate(self, a1, a2, theta):
731
- R = numpy.zeros([3, 3])
732
- # Normal vector through origin
733
- u = a2[0] - a1[0]
734
- v = a2[1] - a1[1]
735
- w = a2[2] - a1[2]
736
- u = u / numpy.sqrt(u ** 2 + v ** 2 + w ** 2)
737
- v = v / numpy.sqrt(u ** 2 + v ** 2 + w ** 2)
738
- w = w / numpy.sqrt(u ** 2 + v ** 2 + w ** 2)
739
- # Translate mesh so that rotation axis starts from the origin
740
- self.X -= a1[0]
741
- self.Y -= a1[1]
742
- self.Z -= a1[2]
743
-
744
- # Rotation matrix
745
- R[0, 0] = u ** 2 + numpy.cos(theta) * (1 - u ** 2)
746
- R[0, 1] = u * v * (1 - numpy.cos(theta)) - w * numpy.sin(theta)
747
- R[0, 2] = u * w * (1 - numpy.cos(theta)) + v * numpy.sin(theta)
748
- R[1, 0] = u * v * (1 - numpy.cos(theta)) + w * numpy.sin(theta)
749
- R[1, 1] = v ** 2 + numpy.cos(theta) * (1 - v ** 2)
750
- R[1, 2] = v * w * (1 - numpy.cos(theta)) - u * numpy.sin(theta)
751
- R[2, 0] = w * u * (1 - numpy.cos(theta)) - v * numpy.sin(theta)
752
- R[2, 1] = w * v * (1 - numpy.cos(theta)) + u * numpy.sin(theta)
753
- R[2, 2] = w ** 2 + numpy.cos(theta) * (1 - w ** 2)
754
-
755
- for iP in range(self.np):
756
- p1 = numpy.array([self.X[iP], self.Y[iP], self.Z[iP]])
757
- p2 = numpy.dot(R, p1)
758
- self.X[iP] = p2[0]
759
- self.Y[iP] = p2[1]
760
- self.Z[iP] = p2[2]
761
-
762
- # Translate back to original position
763
-
764
- self.X += a1[0]
765
- self.Y += a1[1]
766
- self.Z += a1[2]
767
-
768
- def makeCoin(self):
769
- coin = numpy.zeros((3, 4, self.nf))
770
- for iF in range(self.nf):
771
- for iC in range(4):
772
- coin[0, iC, iF] = self.X[self.P[iF, iC] - 1]
773
- coin[1, iC, iF] = self.Y[self.P[iF, iC] - 1]
774
- coin[2, iC, iF] = self.Z[self.P[iF, iC] - 1]
775
- return coin
776
-
777
-
778
-
779
-
780
- class pyramid:
781
- def __init__(self, length, width, height, cCor):
782
- self.length = length
783
- self.width = width
784
- self.height = height
785
- self.xC = cCor[0]
786
- self.yC = cCor[1]
787
- self.zC = cCor[2]
788
- self.name = 'pyramid'
789
- self.panelize()
790
- self.translate(self.xC, self.yC, self.zC)
791
-
792
- def panelize(self):
793
- self.nf = 6
794
- self.np = 8
795
- self.X = numpy.array(
796
- [0.0, 0.0, -self.length / 2.0, self.length / 2.0, 0.0, 0.0, -self.length / 2.0, self.length / 2.0])
797
- self.Y = numpy.array(
798
- [0.0, 0.0, self.width / 2.0, self.width / 2.0, 0.0, 0.0, -self.width / 2.0, -self.width / 2.0])
799
- self.Z = numpy.array([-self.height, -self.height, 0.0, 0.0, -self.height, -self.height, 0.0, 0.0])
800
- self.P = numpy.zeros([6, 4], dtype=int)
801
- self.P[0, :] = numpy.array([3, 4, 2, 1])
802
- self.P[1, :] = numpy.array([4, 8, 6, 2])
803
- self.P[2, :] = numpy.array([8, 7, 5, 6])
804
- self.P[3, :] = numpy.array([7, 3, 1, 5])
805
- self.P[4, :] = numpy.array([5, 6, 5, 1])
806
- self.P[5, :] = numpy.array([8, 4, 3, 7])
807
- # Define triangles for plotting
808
- self.trii = numpy.zeros([2 * self.nf, 3], dtype=int)
809
- iT = 0
810
- for iTr in range(self.nf):
811
- self.trii[iT, :] = [self.P[iTr, 0] - 1, self.P[iTr, 1] - 1, self.P[iTr, 2] - 1]
812
- self.trii[iT + 1, :] = [self.P[iTr, 0] - 1, self.P[iTr, 2] - 1, self.P[iTr, 3] - 1]
813
- iT += 2
814
-
815
- def translate(self, xT, yT, zT):
816
- self.X += xT
817
- self.Y += yT
818
- self.Z += zT
819
-
820
- def rotate(self, a1, a2, theta):
821
- R = numpy.zeros([3, 3])
822
- # Normal vector through origin
823
- u = a2[0] - a1[0]
824
- v = a2[1] - a1[1]
825
- w = a2[2] - a1[2]
826
- u = u / numpy.sqrt(u ** 2 + v ** 2 + w ** 2)
827
- v = v / numpy.sqrt(u ** 2 + v ** 2 + w ** 2)
828
- w = w / numpy.sqrt(u ** 2 + v ** 2 + w ** 2)
829
- # Translate mesh so that rotation axis starts from the origin
830
- self.X -= a1[0]
831
- self.Y -= a1[1]
832
- self.Z -= a1[2]
833
-
834
- # Rotation matrix
835
- R[0, 0] = u ** 2 + numpy.cos(theta) * (1 - u ** 2)
836
- R[0, 1] = u * v * (1 - numpy.cos(theta)) - w * numpy.sin(theta)
837
- R[0, 2] = u * w * (1 - numpy.cos(theta)) + v * numpy.sin(theta)
838
- R[1, 0] = u * v * (1 - numpy.cos(theta)) + w * numpy.sin(theta)
839
- R[1, 1] = v ** 2 + numpy.cos(theta) * (1 - v ** 2)
840
- R[1, 2] = v * w * (1 - numpy.cos(theta)) - u * numpy.sin(theta)
841
- R[2, 0] = w * u * (1 - numpy.cos(theta)) - v * numpy.sin(theta)
842
- R[2, 1] = w * v * (1 - numpy.cos(theta)) + u * numpy.sin(theta)
843
- R[2, 2] = w ** 2 + numpy.cos(theta) * (1 - w ** 2)
844
-
845
- for iP in range(self.np):
846
- p1 = numpy.array([self.X[iP], self.Y[iP], self.Z[iP]])
847
- p2 = numpy.dot(R, p1)
848
- self.X[iP] = p2[0]
849
- self.Y[iP] = p2[1]
850
- self.Z[iP] = p2[2]
851
-
852
- # Translate back to original position
853
-
854
- self.X += a1[0]
855
- self.Y += a1[1]
856
- self.Z += a1[2]
857
-
858
- def makeCoin(self):
859
- coin = numpy.zeros((3, 4, self.nf))
860
- for iF in range(self.nf):
861
- for iC in range(4):
862
- coin[0, iC, iF] = self.X[self.P[iF, iC] - 1]
863
- coin[1, iC, iF] = self.Y[self.P[iF, iC] - 1]
864
- coin[2, iC, iF] = self.Z[self.P[iF, iC] - 1]
865
- return coin
866
-
867
-
868
-
869
-
870
-
871
- class wedge:
872
- def __init__(self, length, width, height, cCor):
873
- self.length = length
874
- self.width = width
875
- self.height = height
876
- self.xC = cCor[0]
877
- self.yC = cCor[1]
878
- self.zC = cCor[2]
879
- self.name = 'wedge'
880
- self.panelize()
881
- self.translate(self.xC, self.yC, self.zC)
882
-
883
- def panelize(self):
884
- self.nf = 6
885
- self.np = 8
886
- self.X = numpy.array(
887
- [0.0, 0.0, -self.length / 2.0, self.length / 2.0, 0.0, 0.0, -self.length / 2.0, self.length / 2.0])
888
- self.Y = numpy.array([self.width / 2.0, self.width / 2.0, self.width / 2.0, self.width / 2.0, -self.width / 2.0,
889
- -self.width / 2.0, -self.width / 2.0, -self.width / 2.0])
890
- self.Z = numpy.array([-self.height, -self.height, 0.0, 0.0, -self.height, -self.height, 0.0, 0.0])
891
- self.P = numpy.zeros([6, 4], dtype=int)
892
- self.P[0, :] = numpy.array([3, 4, 2, 1])
893
- self.P[1, :] = numpy.array([4, 8, 6, 2])
894
- self.P[2, :] = numpy.array([8, 7, 5, 6])
895
- self.P[3, :] = numpy.array([7, 3, 1, 5])
896
- self.P[4, :] = numpy.array([2, 6, 5, 1])
897
- self.P[5, :] = numpy.array([8, 4, 3, 7])
898
- # Define triangles for plotting
899
- self.trii = numpy.zeros([2 * self.nf, 3], dtype=int)
900
- iT = 0
901
- for iTr in range(self.nf):
902
- self.trii[iT, :] = [self.P[iTr, 0] - 1, self.P[iTr, 1] - 1, self.P[iTr, 2] - 1]
903
- self.trii[iT + 1, :] = [self.P[iTr, 0] - 1, self.P[iTr, 2] - 1, self.P[iTr, 3] - 1]
904
- iT += 2
905
-
906
- def translate(self, xT, yT, zT):
907
- self.X += xT
908
- self.Y += yT
909
- self.Z += zT
910
-
911
- def rotate(self, a1, a2, theta):
912
- R = numpy.zeros([3, 3])
913
- # Normal vector through origin
914
- u = a2[0] - a1[0]
915
- v = a2[1] - a1[1]
916
- w = a2[2] - a1[2]
917
- u = u / numpy.sqrt(u ** 2 + v ** 2 + w ** 2)
918
- v = v / numpy.sqrt(u ** 2 + v ** 2 + w ** 2)
919
- w = w / numpy.sqrt(u ** 2 + v ** 2 + w ** 2)
920
- # Translate mesh so that rotation axis starts from the origin
921
- self.X -= a1[0]
922
- self.Y -= a1[1]
923
- self.Z -= a1[2]
924
-
925
- # Rotation matrix
926
- R[0, 0] = u ** 2 + numpy.cos(theta) * (1 - u ** 2)
927
- R[0, 1] = u * v * (1 - numpy.cos(theta)) - w * numpy.sin(theta)
928
- R[0, 2] = u * w * (1 - numpy.cos(theta)) + v * numpy.sin(theta)
929
- R[1, 0] = u * v * (1 - numpy.cos(theta)) + w * numpy.sin(theta)
930
- R[1, 1] = v ** 2 + numpy.cos(theta) * (1 - v ** 2)
931
- R[1, 2] = v * w * (1 - numpy.cos(theta)) - u * numpy.sin(theta)
932
- R[2, 0] = w * u * (1 - numpy.cos(theta)) - v * numpy.sin(theta)
933
- R[2, 1] = w * v * (1 - numpy.cos(theta)) + u * numpy.sin(theta)
934
- R[2, 2] = w ** 2 + numpy.cos(theta) * (1 - w ** 2)
935
-
936
- for iP in range(self.np):
937
- p1 = numpy.array([self.X[iP], self.Y[iP], self.Z[iP]])
938
- p2 = numpy.dot(R, p1)
939
- self.X[iP] = p2[0]
940
- self.Y[iP] = p2[1]
941
- self.Z[iP] = p2[2]
942
-
943
- # Translate back to original position
944
-
945
- self.X += a1[0]
946
- self.Y += a1[1]
947
- self.Z += a1[2]
948
-
949
- def makeCoin(self):
950
- coin = numpy.zeros((3, 4, self.nf))
951
- for iF in range(self.nf):
952
- for iC in range(4):
953
- coin[0, iC, iF] = self.X[self.P[iF, iC] - 1]
954
- coin[1, iC, iF] = self.Y[self.P[iF, iC] - 1]
955
- coin[2, iC, iF] = self.Z[self.P[iF, iC] - 1]
956
- return coin
957
-
958
-
959
-
960
-
961
-
962
- class torus:
963
- def __init__(self, diamOut, diamIn, cCor):
964
- self.diamOut = diamOut
965
- self.diamIn = diamIn
966
- self.xC = cCor[0]
967
- self.yC = cCor[1]
968
- self.zC = cCor[2]
969
- self.name = 'torus'
970
- self.panelize()
971
- self.translate(self.xC, self.yC, self.zC)
972
-
973
- def panelize(self):
974
- Ntheta = 18
975
- Nphi = 18
976
- theta = [xx * 2 * numpy.pi / (Ntheta - 1) for xx in range(Ntheta)]
977
- phi = [xx * 2 * numpy.pi / (Nphi - 1) for xx in range(Nphi)]
978
- self.nf = 0
979
- self.np = 0
980
- self.X = []
981
- self.Y = []
982
- self.Z = []
983
- R = self.diamOut / 2.0
984
- r = self.diamIn / 2.0
985
-
986
- for iT in range(Ntheta):
987
- for iP in range(Nphi):
988
- self.X.append((R + r * numpy.cos(theta[iT])) * numpy.cos(phi[iP]))
989
- self.Y.append((R + r * numpy.cos(theta[iT])) * numpy.sin(phi[iP]))
990
- self.Z.append(r * numpy.sin(theta[iT]))
991
- self.np += 1
992
-
993
- self.nf = (Ntheta - 1) * (Nphi - 1)
994
- self.P = numpy.zeros([self.nf, 4], dtype=int)
995
- iPan = 0
996
- for iT in range(Ntheta - 1):
997
- for iP in range(Nphi - 1):
998
- self.P[iPan, 0] = iP + iT * Nphi + 1
999
- self.P[iPan, 1] = iP + 1 + iT * Nphi + 1
1000
- self.P[iPan, 2] = iP + 1 + Ntheta + iT * Nphi + 1
1001
- self.P[iPan, 3] = iP + Ntheta + iT * Nphi + 1
1002
- iPan += 1
1003
-
1004
- self.X = numpy.array(self.X)
1005
- self.Y = numpy.array(self.Y)
1006
- self.Z = numpy.array(self.Z)
1007
- # Define triangles for plotting
1008
- self.trii = numpy.zeros([2 * self.nf, 3], dtype=int)
1009
- iT = 0
1010
- for iTr in range(self.nf):
1011
- self.trii[iT, :] = [self.P[iTr, 0] - 1, self.P[iTr, 1] - 1, self.P[iTr, 2] - 1]
1012
- self.trii[iT + 1, :] = [self.P[iTr, 0] - 1, self.P[iTr, 2] - 1, self.P[iTr, 3] - 1]
1013
- iT += 2
1014
-
1015
- def translate(self, xT, yT, zT):
1016
- self.X += xT
1017
- self.Y += yT
1018
- self.Z += zT
1019
-
1020
- def rotate(self, a1, a2, theta):
1021
- R = numpy.zeros([3, 3])
1022
- # Normal vector through origin
1023
- u = a2[0] - a1[0]
1024
- v = a2[1] - a1[1]
1025
- w = a2[2] - a1[2]
1026
- u = u / numpy.sqrt(u ** 2 + v ** 2 + w ** 2)
1027
- v = v / numpy.sqrt(u ** 2 + v ** 2 + w ** 2)
1028
- w = w / numpy.sqrt(u ** 2 + v ** 2 + w ** 2)
1029
- # Translate mesh so that rotation axis starts from the origin
1030
- self.X -= a1[0]
1031
- self.Y -= a1[1]
1032
- self.Z -= a1[2]
1033
-
1034
- # Rotation matrix
1035
- R[0, 0] = u ** 2 + numpy.cos(theta) * (1 - u ** 2)
1036
- R[0, 1] = u * v * (1 - numpy.cos(theta)) - w * numpy.sin(theta)
1037
- R[0, 2] = u * w * (1 - numpy.cos(theta)) + v * numpy.sin(theta)
1038
- R[1, 0] = u * v * (1 - numpy.cos(theta)) + w * numpy.sin(theta)
1039
- R[1, 1] = v ** 2 + numpy.cos(theta) * (1 - v ** 2)
1040
- R[1, 2] = v * w * (1 - numpy.cos(theta)) - u * numpy.sin(theta)
1041
- R[2, 0] = w * u * (1 - numpy.cos(theta)) - v * numpy.sin(theta)
1042
- R[2, 1] = w * v * (1 - numpy.cos(theta)) + u * numpy.sin(theta)
1043
- R[2, 2] = w ** 2 + numpy.cos(theta) * (1 - w ** 2)
1044
-
1045
- for iP in range(self.np):
1046
- p1 = numpy.array([self.X[iP], self.Y[iP], self.Z[iP]])
1047
- p2 = numpy.dot(R, p1)
1048
- self.X[iP] = p2[0]
1049
- self.Y[iP] = p2[1]
1050
- self.Z[iP] = p2[2]
1051
-
1052
- # Translate back to original position
1053
-
1054
- self.X += a1[0]
1055
- self.Y += a1[1]
1056
- self.Z += a1[2]
1057
-
1058
- def makeCoin(self):
1059
- coin = numpy.zeros((3, 4, self.nf))
1060
- for iF in range(self.nf):
1061
- for iC in range(4):
1062
- coin[0, iC, iF] = self.X[self.P[iF, iC] - 1]
1063
- coin[1, iC, iF] = self.Y[self.P[iF, iC] - 1]
1064
- coin[2, iC, iF] = self.Z[self.P[iF, iC] - 1]
1065
- return coin
1066
-
1067
- def make_voxels_without_figure(shape, length, height, width, diameter):
1068
- pos = [0, 0, 0]
1069
- if shape == "box":
1070
- mesh = box(length, width, height, pos)
1071
- elif shape == "cone":
1072
- mesh = cone(diameter, height, pos)
1073
- elif shape == "cylinder":
1074
- mesh = cylinder(diameter, height, pos)
1075
- elif shape == "sphere":
1076
- mesh = sphere(diameter, pos)
1077
- elif shape == "wedge":
1078
- mesh = wedge(length, width, height, pos)
1079
-
1080
- hull_points = numpy.array([mesh.X.tolist(), mesh.Y.tolist(), mesh.Z.tolist()]).T
1081
-
1082
- # Set up test points
1083
- G = 32
1084
- ex = 5 - 5 / G
1085
- x, y, z = numpy.meshgrid(numpy.linspace(-ex, ex, G),
1086
- numpy.linspace(-ex, ex, G),
1087
- numpy.linspace(-(9.5 - 5 / G), 0.5 - 5 / G, G))
1088
- test_points = numpy.vstack((x.ravel(), y.ravel(), z.ravel())).T
1089
-
1090
- hull = scipy.spatial.Delaunay(hull_points)
1091
- within = hull.find_simplex(test_points) >= 0
1092
-
1093
- return within*1.0
1094
-
1095
-
1096
- def make_voxels(shape, length, height, width, diameter):
1097
- return plotly_fig(make_voxels_without_figure(shape, length, height, width, diameter))
1098
-
1099
- # This function loads a fuckton of data
1100
- # def load_data():
1101
- # # Open all the files we downloaded at the beginning and take out hte good bits
1102
- # curves = numpy.load('data_curves.npz')['curves']
1103
- # geometry = numpy.load('data_geometry.npz')['geometry']
1104
- # constants = numpy.load('constants.npz')
1105
- # S = constants['S']
1106
- # N = constants['N']
1107
- # D = constants['D']
1108
- # F = constants['F']
1109
- # G = constants['G']
1110
-
1111
- # # Some of the good bits need additional processining
1112
- # new_curves = numpy.zeros((S*N, D * F))
1113
- # for i, curveset in enumerate(curves):
1114
- # new_curves[i, :] = curveset.T.flatten() / 1000000
1115
-
1116
- # new_geometry = numpy.zeros((S*N, G * G * G))
1117
- # for i, geometryset in enumerate(geometry):
1118
- # new_geometry[i, :] = geometryset.T.flatten()
1119
-
1120
- # # Return good bits to user
1121
- # return curves, geometry, S, N, D, F, G, new_curves, new_geometry
1122
-
1123
- curves, geometry, S, N, D, F, G, new_curves, new_geometry = load_data()
1124
-
1125
- class Network(object):
1126
-
1127
- def __init__(self, type):
1128
- # Instantiate variables
1129
- # self.curves = curves
1130
- # self.new_curves = new_curves
1131
- # self.geometry = geometry
1132
- # self.new_geometry = new_geometry
1133
- # self.S = S
1134
- # self.N = N
1135
- # self.D = D
1136
- # self.F = F
1137
- # self.G = G
1138
-
1139
- # Load network
1140
- # with open(structure, 'r') as file:
1141
- # self.network = keras.models.model_from_json(file.read())
1142
- # self.network.load_weights(weights)
1143
- self.network = from_pretrained_keras("cmudrc/wave-energy-analysis") if type == "forward" else from_pretrained_keras("cmudrc/wave-energy-synthesis")
1144
-
1145
- def analysis(self, idx=None):
1146
- print(idx)
1147
-
1148
- if idx is None:
1149
- idx = numpy.random.randint(1, S * N)
1150
- else:
1151
- idx = int(idx)
1152
-
1153
- # Get the input
1154
- data_input = new_geometry[idx:(idx+1), :]
1155
- other_data_input = data_input.reshape((G, G, G), order='F')
1156
-
1157
- # Get the outputs
1158
- print(data_input.shape)
1159
- predicted_output = self.network.predict(data_input)
1160
- true_output = new_curves[idx].reshape((3, F))
1161
- predicted_output = predicted_output.reshape((3, F))
1162
-
1163
- f = numpy.linspace(0.05, 2.0, 64)
1164
- fd = pandas.DataFrame(f).rename(columns={0: "Frequency"})
1165
- df_pred = pandas.DataFrame(predicted_output.transpose()).rename(columns={0: "Surge", 1: "Heave", 2: "Pitch"})
1166
- df_true = pandas.DataFrame(true_output.transpose()).rename(columns={0: "Surge", 1: "Heave", 2: "Pitch"})
1167
-
1168
- # return idx, other_data_input, true_output, predicted_output
1169
- return pandas.concat([fd, df_pred], axis=1), pandas.concat([fd, df_true], axis=1)
1170
-
1171
-
1172
- def analysis_from_geometry(self, geometry):
1173
- # Get the outputs
1174
- predicted_output = self.network.predict(numpy.array([geometry.flatten().tolist()]))
1175
- predicted_output = predicted_output.reshape((3, F))
1176
-
1177
- f = numpy.linspace(0.05, 2.0, 64)
1178
- fd = pandas.DataFrame(f).rename(columns={0: "Frequency"})
1179
- df_pred = pandas.DataFrame(predicted_output.transpose()).rename(columns={0: "Surge", 1: "Heave", 2: "Pitch"})
1180
- good_frame = pandas.concat([fd, df_pred], axis=1)
1181
-
1182
- return good_frame, good_frame
1183
-
1184
- def synthesis(self, idx=None):
1185
- print(idx)
1186
-
1187
- if idx is None:
1188
- idx = numpy.random.randint(1, S * N)
1189
- else:
1190
- idx = int(idx)
1191
-
1192
- # Get the input
1193
- data_input = new_curves[idx:(idx+1), :]
1194
- other_data_input = data_input.reshape((3, F))
1195
-
1196
- # Get the outputs
1197
- predicted_output = self.network.predict(data_input)
1198
- true_output = new_geometry[idx].reshape((G, G, G), order='F')
1199
- predicted_output = predicted_output.reshape((G, G, G), order='F')
1200
-
1201
- # return idx, other_data_input, true_output, predicted_output
1202
- return predicted_output, true_output
1203
-
1204
-
1205
- def synthesis_from_spectrum(self, other_data_input):
1206
- # Get the input
1207
- data_input = other_data_input.reshape((1, 3*F))
1208
-
1209
- # Get the outputs
1210
- predicted_output = self.network.predict(data_input)
1211
- predicted_output = predicted_output.reshape((G, G, G), order='F')
1212
-
1213
- # return idx, other_data_input, true_output, predicted_output
1214
- return predicted_output
1215
-
1216
- def get_geometry(self, idx=None):
1217
-
1218
- if idx is None:
1219
- idx = numpy.random.randint(1, S * N)
1220
- else:
1221
- idx = int(idx)
1222
-
1223
- idx = int(idx)
1224
-
1225
- # Get the input
1226
- data_input = new_geometry[idx:(idx+1), :]
1227
- other_data_input = data_input.reshape((G, G, G), order='F')
1228
-
1229
- # return idx, other_data_input, true_output, predicted_output
1230
- return other_data_input
1231
-
1232
-
1233
- def get_performance(self, idx=None):
1234
-
1235
- if idx is None:
1236
- idx = numpy.random.randint(1, S *N)
1237
- else:
1238
- idx = int(idx)
1239
-
1240
- idx = int(idx)
1241
-
1242
- # Get the input
1243
- data_input = new_curves[idx:(idx+1), :]
1244
- other_data_input = data_input.reshape((3, F))
1245
-
1246
- f = numpy.linspace(0.05, 2.0, 64)
1247
- fd = pandas.DataFrame(f).rename(columns={0: "Frequency"})
1248
- df_pred = pandas.DataFrame(other_data_input.transpose()).rename(columns={0: "Surge", 1: "Heave", 2: "Pitch"})
1249
- table = pandas.concat([fd, df_pred], axis=1)
1250
-
1251
- return table
1252
-
1253
-
1254
- def plotly_fig(values):
1255
- X, Y, Z = numpy.mgrid[0:1:32j, 0:1:32j, 0:1:32j]
1256
- fig = go.Figure(data=go.Volume(
1257
- x=X.flatten(),
1258
- y=Y.flatten(),
1259
- z=Z.flatten(),
1260
- value=values.flatten(),
1261
- isomin=0.0,
1262
- isomax=1.0,
1263
- opacity=0.1, # needs to be small to see through all surfaces
1264
- surface_count=21, # needs to be a large number for good volume rendering
1265
- colorscale='haline'
1266
- ))
1267
- return fig
1268
-
1269
-
1270
- value_net = Network("forward")
1271
-
1272
- def performance(index):
1273
- return value_net.get_performance(index)
1274
-
1275
- def geometry(index):
1276
- values = value_net.get_geometry(index)
1277
- return plotly_fig(values)
1278
-
1279
- def simple_analysis(index, choice, shape, length, width, height, diameter):
1280
- forward_net = Network("forward")
1281
- # forward_net = Network("16forward_structure.json", "16forward_weights.h5")
1282
- if choice == "Construct Shape from Parameters":
1283
- return forward_net.analysis_from_geometry(make_voxels_without_figure(shape, length, height, width, diameter))
1284
- elif choice == "Pick Shape from Dataset":
1285
- return forward_net.analysis(index)
1286
-
1287
-
1288
- def simple_synthesis(index):
1289
- inverse_net = Network("inverse")
1290
- # inverse_net = Network("16inverse_structure.json", "16inverse_weights.h5")
1291
- pred, true = inverse_net.synthesis(index)
1292
- return plotly_fig(pred), plotly_fig(true)
1293
-
1294
- def synthesis_from_spectrum(df):
1295
- inverse_net = Network("inverse")
1296
- # inverse_net = Network("16inverse_structure.json", "16inverse_weights.h5")
1297
- pred = inverse_net.synthesis_from_spectrum(df.to_numpy()[:, 1:])
1298
- return plotly_fig(pred)
1299
-
1300
-
1301
-
1302
- def change_textbox(choice, length, height, width, diameter):
1303
- fig = make_voxels(choice, length, height, width, diameter)
1304
- if choice == "cylinder":
1305
- return [gradio.Slider.update(visible=True), gradio.Slider.update(visible=False), gradio.Slider.update(visible=True), gradio.Slider.update(visible=False), gradio.Plot.update(fig)]
1306
- elif choice == "sphere":
1307
- return [gradio.Slider.update(visible=False), gradio.Slider.update(visible=False), gradio.Slider.update(visible=True), gradio.Slider.update(visible=False), gradio.Plot.update(fig)]
1308
- elif choice == "box":
1309
- return [gradio.Slider.update(visible=True), gradio.Slider.update(visible=True), gradio.Slider.update(visible=False), gradio.Slider.update(visible=True), gradio.Plot.update(fig)]
1310
- elif choice == "wedge":
1311
- return [gradio.Slider.update(visible=True), gradio.Slider.update(visible=True), gradio.Slider.update(visible=False), gradio.Slider.update(visible=True), gradio.Plot.update(fig)]
1312
- elif choice == "cone":
1313
- return [gradio.Slider.update(visible=True), gradio.Slider.update(visible=False), gradio.Slider.update(visible=True), gradio.Slider.update(visible=False), gradio.Plot.update(fig)]
1314
-
1315
-
1316
-
1317
- def randomize_analysis(choice):
1318
- if choice == "Construct Shape from Parameters":
1319
- length = random.uniform(3.0, 10.0)
1320
- height = random.uniform(3.0, 10.0)
1321
- width = random.uniform(3.0, 10.0)
1322
- diameter = random.uniform(3.0, 10.0)
1323
- choice2 = random.choice(["box", "cone", "sphere", "wedge", "cone"])
1324
- if choice2 == "box" or choice2 == "wedge":
1325
- return [gradio.Radio.update(choice2), gradio.Slider.update(length), gradio.Slider.update(height), gradio.Slider.update(width), gradio.Slider.update(), gradio.Number.update(), gradio.Plot.update(make_voxels(choice2, length, height, width, diameter))]
1326
- elif choice2 == "cone" or choice2 == "cylinder":
1327
- return [gradio.Radio.update(choice2), gradio.Slider.update(), gradio.Slider.update(height), gradio.Slider.update(), gradio.Slider.update(diameter), gradio.Number.update(), gradio.Plot.update(make_voxels(choice2, length, height, width, diameter))]
1328
- elif choice2 == "sphere":
1329
- return [gradio.Radio.update(choice2), gradio.Slider.update(), gradio.Slider.update(), gradio.Slider.update(), gradio.Slider.update(diameter), gradio.Number.update(), gradio.Plot.update(make_voxels(choice2, length, height, width, diameter))]
1330
- elif choice == "Pick Shape from Dataset":
1331
- num = random.randint(1, 4999)
1332
- return [gradio.Radio.update(), gradio.Slider.update(), gradio.Slider.update(), gradio.Slider.update(), gradio.Slider.update(), gradio.Number.update(num), gradio.Plot.update(geometry(num))]
1333
-
1334
-
1335
-
1336
- def geometry_change(choice, choice2, num, length, width, height, diameter):
1337
- if choice == "Construct Shape from Parameters":
1338
- [slider1, slider2, slider3, slider4, plot] = change_textbox(choice2, length, height, width, diameter)
1339
- return [gradio.Radio.update(visible=True), slider1, slider2, slider3, slider4, gradio.Number.update(visible=False), gradio.Timeseries.update(visible=False), gradio.Plot.update(make_voxels(choice2, length, height, width, diameter))]
1340
- elif choice == "Pick Shape from Dataset":
1341
- return [gradio.Radio.update(visible=False), gradio.Slider.update(visible=False), gradio.Slider.update(visible=False), gradio.Slider.update(visible=False), gradio.Slider.update(visible=False), gradio.Number.update(visible=True), gradio.Timeseries.update(visible=True), gradio.Plot.update(geometry(num))]
1342
 
1343
  with gradio.Blocks() as demo:
1344
- with gradio.Accordion("✨ Read about the underlying ML model here! ✨", open=False):
1345
- with gradio.Row():
1346
- with gradio.Column():
1347
- gradio.Markdown("# Toward the Rapid Design of Engineered Systems Through Deep Neural Networks")
1348
- gradio.HTML("Christopher McComb, Carnegie Mellon University")
1349
- gradio.Markdown("__Abstract__: The design of a system commits a significant portion of the final cost of that system. Many computational approaches have been developed to assist designers in the analysis (e.g., computational fluid dynamics) and synthesis (e.g., topology optimization) of engineered systems. However, many of these approaches are computationally intensive, taking significant time to complete an analysis and even longer to iteratively synthesize a solution. The current work proposes a methodology for rapidly evaluating and synthesizing engineered systems through the use of deep neural networks. The proposed methodology is applied to the analysis and synthesis of offshore structures such as oil platforms. These structures are constructed in a marine environment and are typically designed to achieve specific dynamics in response to a known spectrum of ocean waves. Results show that deep learning can be used to accurately and rapidly synthesize and analyze offshore structure.")
1350
- with gradio.Column():
1351
- download = gradio.HTML("<a href=\"https://huggingface.co/spaces/cmudrc/wecnet/resolve/main/McComb2019_Chapter_TowardTheRapidDesignOfEngineer.pdf\" style=\"width: 60%; display: block; margin: auto;\"><img src=\"https://huggingface.co/spaces/cmudrc/wecnet/resolve/main/coverpage.png\"></a>")
1352
-
1353
- gradio.Markdown("When designing offshore structure, like [wave energy converters](https://www.nrel.gov/news/program/2021/how-wave-energy-could-go-big-by-getting-smaller.html), it's important to know what forces will be placed on the structure as waves come at different speeds. Likewise, if we have some idea of how we want the structure to respond to different waves, we can use that to guide the design of the shape of the structure. We call the first process _Analysis_, and the second process _Synthesis_. This demo has ML models that do both, very quickly.")
1354
-
1355
- with gradio.Tab("Analysis"):
1356
-
1357
- with gradio.Row():
1358
- with gradio.Column():
1359
- whence_commeth_geometry = gradio.Radio(
1360
- ["Construct Shape from Parameters", "Pick Shape from Dataset"], label="How would you like to generate the shape of the offshore structure for analysis?", value="Construct Shape from Parameters"
1361
- )
1362
- radio = gradio.Radio(
1363
- ["box", "cone", "cylinder", "sphere", "wedge"], label="What kind of shape would you like to generate?", value="sphere"
1364
- )
1365
- height = gradio.Slider(label="Height", interactive=True, minimum=3.0, maximum=10.0, value=6.5, visible=False)
1366
- width = gradio.Slider(label="Width", interactive=True, minimum=3.0, maximum=10.0, value=6.5, visible=False)
1367
- diameter = gradio.Slider(label="Diameter", interactive=True, minimum=3.0, maximum=10.0, value=6.5, visible=True)
1368
- length = gradio.Slider(label="Length", interactive=True, minimum=3.0, maximum=10.0, value=6.5, visible=False)
1369
-
1370
-
1371
- num = gradio.Number(42, label="Type the index of the spectrum you would like to use or randomly select it.", visible=False)
1372
-
1373
- btn1 = gradio.Button("Randomize")
1374
- with gradio.Column():
1375
- geo = gradio.Plot(make_voxels("sphere", 6.5, 6.5, 6.5, 6.5), label="Geometry")
1376
-
1377
-
1378
- with gradio.Row():
1379
- btn2 = gradio.Button("Estimate Spectrum")
1380
-
1381
- with gradio.Row():
1382
- with gradio.Column():
1383
- pred = gradio.Timeseries(x="Frequency", y=['Surge', 'Heave', 'Pitch'], label="Predicted")
1384
-
1385
- with gradio.Column():
1386
- true = gradio.Timeseries(x="Frequency", y=['Surge', 'Heave', 'Pitch'], label="True", visible=False)
1387
-
1388
- radio.change(fn=change_textbox, inputs=[radio, length, height, width, diameter], outputs=[height, width, diameter, length, geo])
1389
- height.change(fn=make_voxels, inputs = [radio, length, height, width, diameter], outputs=[geo])
1390
- width.change(fn=make_voxels, inputs = [radio, length, height, width, diameter], outputs=[geo])
1391
- diameter.change(fn=make_voxels, inputs = [radio, length, height, width, diameter], outputs=[geo])
1392
- length.change(fn=make_voxels, inputs = [radio, length, height, width, diameter], outputs=[geo])
1393
- whence_commeth_geometry.change(fn=geometry_change, inputs=[whence_commeth_geometry, radio, num, length, width, height, diameter], outputs=[radio, height, width, diameter, length, num, true, geo])
1394
- num.change(fn=geometry, inputs=[num], outputs=[geo])
1395
-
1396
- btn1.click(fn=randomize_analysis, inputs=[whence_commeth_geometry], outputs=[radio, length, height, width, diameter, num, geo])
1397
- btn2.click(fn=simple_analysis, inputs=[num, whence_commeth_geometry, radio, length, width, height, diameter], outputs=[pred, true], api_name="analyze")
1398
- with gradio.Tab("Synthesis"):
1399
- with gradio.Row():
1400
- with gradio.Column():
1401
- whence_commeth_performance = gradio.Radio(
1402
- ["Pick Spectrum from Dataset"], label="How would you like to generate the desired response spectrum to synthesize from?", value="Construct Spectrum from Table"
1403
- )
1404
- num = gradio.Number(42, label="Type the index of the shape you would like to use or randomly select it.")
1405
- btn1 = gradio.Button("Randomize")
1406
- with gradio.Column():
1407
- perf = gradio.Timeseries(x="Frequency", y=['Surge', 'Heave', 'Pitch'], label="Performance")
1408
-
1409
- with gradio.Row():
1410
- btn2 = gradio.Button("Synthesize Geometry")
1411
-
1412
- with gradio.Row():
1413
- with gradio.Column():
1414
- pred = gradio.Plot(label="Predicted")
1415
-
1416
- with gradio.Column():
1417
- true = gradio.Plot(label="True")
1418
-
1419
 
1420
- btn1.click(fn=lambda: random.randint(1, 4999), inputs=[], outputs=num)
1421
- num.change(fn=performance, inputs=[num], outputs=[perf])
1422
- btn2.click(fn=simple_synthesis, inputs=[num], outputs=[pred, true], api_name="synthesize")
 
 
1423
 
1424
  demo.launch()
 
 
1
  import numpy
2
  import gradio
 
 
 
 
 
 
 
 
 
 
3
  from huggingface_hub import from_pretrained_keras
4
 
5
+ S = 5
6
+ N = 1000
7
+ D = 3
8
+ F = 64
9
+ G = 32
10
 
11
+ analysis_network = from_pretrained_keras("cmudrc/wave-energy-analysis")
12
+ synthesis_network = from_pretrained_keras("cmudrc/wave-energy-synthesis")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
 
14
  with gradio.Blocks() as demo:
15
+ geometry = gradio.Textbox(label="geometry")
16
+ spectrum = gradio.Textbox(label="spectrum")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
 
18
+ analyze_it = gradio.Button("Analyze")
19
+ synthesize_it = gradio.Button("Synthesize")
20
+
21
+ analyze_it.click(fn=lambda x: numpy.array2string(analysis_network.predict(numpy.array(x))), inputs=[geometry], outputs=[spectrum], api_name="analyze")
22
+ synthesize_it.click(fn=lambda x: numpy.array2string(synthesis_network.predict(numpy.array(x))), inputs=[spectrum], outputs=[geometry], api_name="synthesize")
23
 
24
  demo.launch()