/
FluidChannel.py
1320 lines (1046 loc) · 45.4 KB
/
FluidChannel.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
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#FluidChannel.py
"""
Class implementation file for the Python class FluidChannel
Depends on vtkHelper module for geometry visualization functionality
"""
import math
import numpy as np
from vtkHelper import saveStructuredPointsVTK_ascii as writeVTK
import scipy.io
class LatticeSubset(object):
"""
object that will represent a subset of lattice points.
A fluid channel may have lattice subsets. Each lattice
subset will be responsible for identifying its members
and providing facilities for them. These facilities
can be specialized in derived classes.
"""
def __init__(self):
"""
"""
def get_members(self,X,Y,Z):
"""
given X,Y, and Z coordinates of a lattice
return the indices of lattice points
that are a member of the subset.
"""
return []
class YZ_Slice(LatticeSubset):
"""
subset of a lattice comprising a 2D slice in the YZ plane
"""
def __init__(self,Xo,Ymin,Ymax,Zmin,Zmax):
"""
pass in X-position and YZ bounds for slice
"""
super(YZ_Slice,self).__init__();
self.Xo = Xo
self.Ymin = Ymin;
self.Ymax = Ymax;
self.Zmin = Zmin;
self.Zmax = Zmax;
def get_members(self,X,Y,Z):
"""
return indices of lattice points that are within dx/2 of specified YZ plane
"""
x = np.array(X);
y = np.array(Y);
z = np.array(Z);
# get lattice spacing.
xVals = np.unique(x); #sorted unique values
dx = xVals[1] - xVals[0]; #difference between two sorted unique values
obst = np.where(y >= self.Ymin);
obst = np.intersect1d(obst[:],np.where(y<=self.Ymax));
obst = np.intersect1d(obst[:],np.where(z>=self.Zmin));
obst = np.intersect1d(obst[:],np.where(z<=self.Zmax));
obst = np.intersect1d(obst[:],np.where(x>=(self.Xo - dx/2.)));
obst = np.intersect1d(obst[:],np.where(x<=(self.Xo+dx/2.)));
obst = obst.astype(np.int)
return obst[:]
class EmptyChannel:
"""
a channel with nothing in it
"""
def __init__(self,Lo):
"""
constructor
"""
self.Lo = Lo
def get_Lo(self):
"""
set Lo if need be ?
"""
return self.Lo
def get_obstList(self,X,Y,Z):
"""
for an empty channel - no obstacles
"""
return []
class ChannelCavity(EmptyChannel):
"""
a channel with a cavity part way down the length
- implicitly the channel begins at z = 0
- and the depth of the channel indicates the maximum value
- of Y that will be defined as "floor"
- the bottom of the cavity will be defined as Y = 0
- this version of the cavity will span the width (X-direction)
- of the channel.
"""
def __init__(self,depth,z_start,z_end):
self.depth = depth
self.z_start = z_start
self.z_end = z_end
def get_Lo(self):
return self.depth
def get_obstList(self,X,Y,Z):
""" return a list of indices within the boundary of the channel floor
"""
#x = np.array(X);
y = np.array(Y); z = np.array(Z);
cav1 = np.where(z >= self.z_start)
cav2 = np.where(z <= self.z_end)
ol = np.setxor1d(cav1[:],cav2[:])
cav3 = np.where(y <= self.depth)
ol = np.intersect1d(ol[:],cav3[:])
return ol[:]
class GridObst(EmptyChannel):
"""
a channel with a turbulence-inducing grid at the entrance
of the channel. The grid has a circular hole to accomodate
passage of a drive-shaft for a propeller
"""
def __init__(self,gridZ,xT,yT,zT,xPitch,yPitch,hX,hY,hD):
"""
gridZ - z-coordinate of center of grid
xT - thickness of grid webs in x-direction (vertical webs)
yT - thickness of grid webs in y-direction (horizontal webs)
zT - thickness of grid in z-direction
yPitch - pitch of horizontal grids in Y-direction
xPitch - pitch of vertical grids in the X-direction
hX - x-coordinate of grid hole
hY - y-coordinate of grid hole
hD - diameter of grid hole
"""
self.gridZ = gridZ;
self.xT = xT;
self.yT = yT;
self.zT = zT;
self.yPitch = yPitch;
self.xPitch = xPitch;
self.hX = hX;
self.hY = hY;
self.hD = hD;
def get_Lo(self,):
"""
to do: talk to Luksa about non-dimensionalization
and most appropriate choice for this
non-dimensionalization.
"""
return self.yPitch
def get_obstList(self,X,Y,Z):
"""
"""
x = np.array(X);
y = np.array(Y);
z = np.array(Z);
xMax = np.max(x);
xMin = np.min(x); # expect this to be zero
yMax = np.max(y);
yMin = np.min(y); # expect this to be zero
xPitch = self.xPitch
yPitch = self.yPitch
xT = self.xT
yT = self.yT
zT = self.zT
gridZ = self.gridZ
hX = self.hX
hY = self.hY
hD = self.hD
obst_list = [];
# get x-center of vertical grids
xC_vGrids = np.linspace(xMin+xT/2.,xMax-xT/2.,((xMax-xMin)/xPitch)+1);
for i in range(len(xC_vGrids)):
distX = np.abs(x - xC_vGrids[i]);
distZ = np.abs(z - gridZ);
gridObstA = np.where((distX < xT/2.))
gridObstB = np.where((distZ < zT/2.))
gridObst = np.intersect1d(gridObstA,gridObstB);
obst_list = np.union1d(obst_list[:],gridObst)
# get y-center of horizontal grids
yC_hGrids = np.linspace(yMin+yT/2.,yMax-yT/2.,((yMax - yMin)/yPitch)+1);
for i in range(len(yC_hGrids)):
distY = np.abs(y - yC_hGrids[i]);
distZ = np.abs(z - gridZ);
gridObstA = np.where((distY < yT/2.))
gridObstB = np.where((distZ < zT/2.))
gridObst = np.intersect1d(gridObstA,gridObstB);
obst_list = np.union1d(obst_list[:],gridObst)
# remove grids within the hole region
distH = np.sqrt((y - hY)**2. + (x - hX)**2.)
obstH = np.where(distH < hD/2.)
obst_list = np.setdiff1d(obst_list[:],obstH)
obst_list = obst_list.astype(np.int)
return obst_list[:]
class StraightPipe(EmptyChannel):
"""
a square channel where the non-solid nodes
constitute a circular pipe.
"""
def __init__(self,x_c,y_c,diameter):
self.x_c = x_c;
self.y_c = y_c;
self.diameter = diameter;
def get_Lo(self):
return self.diameter;
def get_obstList(self,X,Y,Z):
x = np.array(X); y = np.array(Y);
dist = (x - self.x_c)**2 + (y - self.y_c)**2
return list(np.where(dist >= (self.diameter/2.0)**2))
class SphereObstruction(EmptyChannel):
"""
a channel with a sphere obstruction
"""
def __init__(self,r,x_c,y_c,z_c):
"""
just need to define the radius and position of the center of the obstacle.
it is up to the caller to verify that the object will fit within the intended
channel. If it does not fit, the obstacle will effectively be
truncated at the channel boundaries
"""
self.r = r
self.x_c = x_c
self.y_c = y_c
self.z_c = z_c
def get_Lo(self):
return self.r*2.
def get_obstList(self,X,Y,Z):
"""
return a list of all indices all indices within boundary of sphere
"""
x = np.array(X); y = np.array(Y); z = np.array(Z);
dist = (x - self.x_c)**2 + (y - self.y_c)**2 + (z - self.z_c)**2
return list(np.where(dist < self.r**2))
class WallMountedBrick(EmptyChannel):
"""
a channel with a brick mounted to the wall (y = min)
"""
def __init__(self,x_c,z_c,L,W,H):
"""
x_c = x-coordinate of the brick centroid
z_c = z-coordinate of the brick centroid
L = length of the brick (in the Z-direction)
W = width of the brick (in the X-direction)
H = height of the brick (in the Y-direction)
"""
self.x_c = x_c
self.z_c = z_c
self.L = L
self.W = W
self.H = H
def get_Lo(self):
return self.H
def get_obstList(self,X,Y,Z):
"""
return a list of all indices within the boundary of the brick
"""
x = np.array(X); y = np.array(Y); z = np.array(Z);
inH = np.where(y<=self.H);
inZa = np.where(z>=(self.z_c - self.L/2.));
inZb = np.where(z<=(self.z_c + self.L/2.));
inZ = np.intersect1d(inZa,inZb);
inXa = np.where(x>=(self.x_c - self.W/2.));
inXb = np.where(x<=(self.x_c + self.W/2.));
inX = np.intersect1d(inXa,inXb);
obst = np.intersect1d(inH,inZ);
obst = np.intersect1d(obst[:],inX);
return obst[:]
class TwinJet(EmptyChannel):
"""
a channel with block obstructions allowing for simulation of
the twin-jet problem
"""
def __init__(self,y1,x1,W,a,S,L):
"""
y1 = height (m) of first channel in twin-jet
x1 = value of smallest magnitude x-coordinate (assume width
in x-direction
W = width (m) width of each jet channel
a = width (m) of the openings of both jets
S = pitch (m) distance between centroids of twin jets (should be
greater than a)
L = length (m) length of the channel for twin jets prior to openings
assumes the overall domain starts at z = 0.
assumes overall domain is wider (in x-direction) than x1+W
assumes overall domain is higher (in y-direction) than y1+S+a/2.
"""
self.y1 = y1
self.x1 = x1
self.W = W
self.a = a
self.S = S
self.L = L
def get_Lo(self):
"""
characteristic length is the hydraulic diameter. (flow area/wetted
perimeter)
"""
flow_area = self.a * self.W
wetted_perimeter = 2.*self.a+2.*self.W
return flow_area/wetted_perimeter
def get_obstList(self,X,Y,Z):
#x = np.array(X);
y = np.array(Y);
z = np.array(Z);
obst_l = np.where(z < self.L)
obst_h = np.where(z > 0.2)
obst = np.intersect1d(obst_l[:],obst_h[:])
y_dist1 = np.abs(y - (self.y1+self.a/2.))
ch1 = np.where(y_dist1<self.a/2.)
ch1 = np.intersect1d(obst[:],ch1[:])
obst = np.setxor1d(obst[:],ch1[:])
y_dist2 = np.abs(y - (self.y1+self.a/2.+self.S))
ch2 = np.where(y_dist2<self.a/2.)
ch2 = np.intersect1d(obst[:],ch2[:])
obst = np.setxor1d(obst[:],ch2[:])
return obst[:]
class GolfBall(EmptyChannel):
"""
a channel with a golf ball obstacle
"""
def __init__(self,SO,d_dimp,rd_dimp,N_e,N_a):
"""
SO - pass in a sphericle obstacle as one of the arguments
d_dimp = diameter of the dimples on the golf ball
rd_dimp = radial distance of the center of the dimple from the center
of the golf ball
N_e = number of dimples along all [0,pi] elevation angles
N_e = number of dimples along all [0,2pi] azimuthal angles
"""
self.sphere = SO;
self.d_dimp = d_dimp;
self.rd_dimp = rd_dimp;
self.N_e = N_e;
self.N_a = N_a;
def get_Lo(self):
return self.sphere.get_Lo()
def get_obstList(self,X,Y,Z):
"""
return the obst list for the golf ball
"""
obst_list1 = self.sphere.get_obstList(X,Y,Z)
el_angles = np.linspace(0.,np.pi,self.N_e)
x = np.array(X); y = np.array(Y); z = np.array(Z);
print "removing the dimples"
# start removing dimples
iel = 0;
for el in el_angles:
iel+=1
# for each elevation, we will get a different number of dimples
N_az_el = np.floor(self.N_a*np.sin(el))+1;
if N_az_el == 1:
N_az_el+=1
az_angles = np.linspace(0.,2.*np.pi, N_az_el, endpoint = False)
print "removing dimples in elevation %g of %g" % (iel, len(el_angles))
iaz = 0;
for az in az_angles:
iaz+=1
print "removing dimple %g of %g on this elevation" % (iaz,len(az_angles))
# get coordinates of the center of the spherical dimple
y_c_d = self.sphere.y_c + self.rd_dimp*np.cos(el);
z_c_d = self.sphere.z_c + self.rd_dimp*np.sin(az)*np.sin(el);
x_c_d = self.sphere.x_c + self.rd_dimp*np.cos(az)*np.sin(el);
dist = (x - x_c_d)**2 + (y - y_c_d)**2 + (z - z_c_d)**2
dimples = np.where(dist <= ((self.d_dimp/2.))**2)
obst_list1 = np.setxor1d(obst_list1[:],
np.intersect1d(obst_list1[:],dimples[:]))
return obst_list1[:]
class EllipticalScourPit(EmptyChannel):
"""
a channel with an elliptical scour pit with prescribed properties
corresponds to case 3 of Bryan's geometry_desc.m
"""
def __init__(self,x_c,z_c,cyl_rad):
"""
constructor giving the x and z coordinates of the scour pit along with
the radius of the cylindrical piling
"""
self.x_c = x_c
self.z_c = z_c
self.cyl_rad = cyl_rad
def get_Lo(self):
return self.cyl_rad*2.
def get_obstList(self,X,Y,Z):
"""
return a list of all indices of lattice points within the boundaries of the
scour pit obstacle
"""
ellip_a = 2.*2.*self.cyl_rad
ellip_b = 2.*self.cyl_rad
ellip_c = 8.*self.cyl_rad
ellip_x = self.x_c
ellip_z = self.z_c + self.cyl_rad
ellip_y = ellip_b
floor_part = np.array(np.where(Y < ellip_b)).flatten()
dist = (X - self.x_c)**2 + (Z - self.z_c)**2;
cyl_part = list(np.array(np.where( dist < self.cyl_rad**2)).flatten())
scour_pit = np.array(np.where( (X - ellip_x)**2/(ellip_a**2) +
(Y - ellip_y)**2/(ellip_b**2) +
(Z - ellip_z)**2/(ellip_c**2) <= 1.)).flatten()
# remove the scour pit from the floor
obst_list = np.setxor1d(floor_part[:],
np.intersect1d(floor_part[:],scour_pit[:]))
# then add the cylinder
obst_list = np.union1d(obst_list[:],cyl_part[:])
return list(obst_list[:])
class ConeScourPit(EmptyChannel):
"""
a channel with a conical scour pit determined by the angle of repose of the soil particles (assumed to be river sand, phi=30 deg).
"""
def __init__(self,x_c,z_c,cyl_rad):
"""
constructor giving the x and z coordinates of the scour pit along with the radius of the cylindrical piling
"""
self.x_c = x_c
self.z_c = z_c
self.cyl_rad = cyl_rad
def get_Lo(self):
return self.cyl_rad*2.
def get_obstList(self,X,Y,Z):
"""
return a list of all indices of lattice points within the boundaries of the conical scour pit obstacle. x_s is defined in 'Scour at marine structures' by Richard Whitehouse, 1998. Assumes river sand with phi (angle of repose) equal to 30 degrees. h_cone is equal to rad_cone*tan(30) = rad_cone*0.57735
"""
x_c_cone = self.x_c
z_c_cone = self.z_c
y_c_cone = 0
x_s = 2.25*2*self.cyl_rad
rad_cone = x_s + self.cyl_rad
h_cone = rad_cone*0.57735
floor_part = np.array(np.where(Y < h_cone)).flatten()
dist = (X - self.x_c)**2 + (Z - self.z_c)**2;
cyl_part = list(np.array(np.where( dist < self.cyl_rad**2)).flatten())
scour_pit = np.array(np.where( (X - x_c_cone)**2 + (Z - z_c_cone)**2 <= ((self.cyl_rad/cone)/(h_cone))**2*(Y - y_c_cone)**2))
# remove the scour pit from the floor
obst_list = np.setxor1d(floor_part[:],
np.intersect1d(floor_part[:],scour_pit[:]))
# then add the cylinder
obst_list = np.union1d(obst_list[:],cyl_part[:])
return list(obst_list[:])
class SinglePile(EmptyChannel):
"""
a channel with a single pile, no scour. Used for comparison to both elliptical and conical scour pits.
"""
def __init__(self,x_c,z_c,cyl_rad):
"""
constructor giving the x and z coordinates of the piling center along with the radius of the cylindrical piling
"""
self.x_c = x_c
self.z_c = z_c
self.cyl_rad = cyl_rad
def get_Lo(self):
return self.cyl_rad*2.
def get_obstList(self,X,Y,Z):
"""
return a list of all indices of lattice points within the boundaries of the bed Bed thickness is equal to the diameter of the piling (2x radius)
"""
#Bed
floor_part = np.array(np.where(Y < 2*self.cyl_rad)).flatten()
#Piling
dist = (X - self.x_c)**2 + (Z - self.z_c)**2;
cyl_part = list(np.array(np.where( dist < self.cyl_rad**2)).flatten())
# then add the cylinder
obst_list = np.union1d(floor_part[:],cyl_part[:])
return list(obst_list[:])
class WavyBed(EmptyChannel):
"""
a channel with a single pile, Sin-wave bottom.
"""
def __init__(self,x_c,z_c,cyl_rad):
"""
constructor giving the x and z coordinates of the piling center along with the radius of the cylindrical piling
"""
self.x_c = x_c
self.z_c = z_c
self.cyl_rad = cyl_rad
def get_Lo(self):
return self.cyl_rad*2.
def get_obstList(self,X,Y,Z):
"""
waveh and wavel are used to characterize the sine wave for the bed. shallower sin waves do better in remaining stable throughout the simulation at low Reynolds numbers.
"""
waveh = 0.125
wavel = 5
floor_part = np.array(np.where(Y < (waveh*np.sin(wavel*Z) + 2*self.cyl_rad))).flatten()
#Piling
dist = (X - self.x_c)**2 + (Z - self.z_c)**2;
cyl_part = list(np.array(np.where( dist < self.cyl_rad**2)).flatten())
# then add the cylinder
obst_list = np.union1d(floor_part[:],cyl_part[:])
return list(obst_list[:])
class PipeContract(EmptyChannel):
"""
a single smooth pipe with diameter in, diam_in, through a contraction and leaving at diameter out, diam_out. Contraction assumed to be 45 degrees. Channel assumed to be 2 x 2 x 8. Lo = diam_out (smaller diameter). Contraction begins at z = 4. For a clean pipe, diam_in = 1.8 and diam_out = 0.8.
"""
def __init__(self,diam_in,diam_out):
"""
constructor identifying diameters into and out of contraction. Recommend diam_in = 1.8 and diam_out = 0.8
"""
self.diam_in = diam_in
self.diam_out = diam_out
def get_Lo(self):
return self.diam_out
def get_obstList(self,X,Y,Z):
"""
Define areas external to pipe.
"""
#Pipe in - find all points exterior of large pipe
pipe_in = np.array(np.where((X - 1)**2 + (Y - 1)**2 > (self.diam_in/2)**2)).flatten()
pipe_in_stop = np.array(np.where(Z <= 4)).flatten()
pipe_in = np.intersect1d(pipe_in[:],pipe_in_stop[:])
#Contraction - find all points exterior of contraction
r_cone = self.diam_out
h_cone = self.diam_out
contraction = np.array(np.where((X - 1)**2 + (Y - 1)**2 > (r_cone/h_cone)**2*(Z - (4 + h_cone))**2)).flatten()
contraction_start = np.array(np.where(Z >= 4)).flatten()
contraction_stop = np.array(np.where(Z <= 4 + .5*self.diam_out)).flatten()
contraction = np.intersect1d(contraction[:],contraction_start[:])
contraction = np.intersect1d(contraction[:],contraction_stop[:])
#Pipe out - final all points exterior of smaller pipe
pipe_out = np.array(np.where((X - 1)**2 + (Y - 1)**2 > (self.diam_out/2)**2)).flatten()
pipe_out_start = np.array(np.where(Z >= 4 + .5*self.diam_out)).flatten()
pipe_out = np.intersect1d(pipe_out[:],pipe_out_start[:])
#Put the pieces together
#pipe = pipe_in[:]
pipe = np.union1d(contraction[:],pipe_in[:])
pipe = np.union1d(pipe[:],pipe_out[:])
obst_list = pipe[:]
return list(obst_list[:])
class PipeExpand(EmptyChannel):
"""
opposite of pipe contraction. a single smooth pipe with diameter in, diam_in, through an expansion and leaving at diameter out, diam_out. Expansion assumed to be 45 degrees. Channel assumed to be 2 x 2 x 8. Lo = diam_in (smaller diameter). Expansion begins at z = 4. Best works when diam_in = 0.8 and diam_out = 1.8
"""
def __init__(self,diam_in,diam_out):
"""
constructor identifying pipe diameters into and out of expansion. Recommend diam_in = 0.8 and diam_out = 1.8
"""
self.diam_in = diam_in
self.diam_out = diam_out
def get_Lo(self):
return self.diam_in
def get_obstList(self,X,Y,Z):
"""
Define areas external to pipe.
"""
#Pipe in - find all points exterior of small
pipe_in = np.array(np.where((X - 1)**2 + (Y - 1)**2 > (self.diam_in/2)**2)).flatten()
pipe_in_stop = np.array(np.where(Z <= 1.5 + 0.5*(self.diam_out - self.diam_in))).flatten()
pipe_in = np.intersect1d(pipe_in[:],pipe_in_stop[:])
#Expansion - find all points exterior of expansion
r_cone = self.diam_in
h_cone = self.diam_in
expansion = np.array(np.where((X - 1)**2 + (Y - 1)**2 > (r_cone/h_cone)**2*(Z - 1.5)**2)).flatten()
expansion_start = np.array(np.where(Z >= 1.5 + 0.5*(self.diam_out - self.diam_in)))
#expansion_stop = np.array(np.where(Z <= 4)).flatten()
expansion = np.intersect1d(expansion[:],expansion_start[:])
#expansion = np.intersect1d(expansion[:],expansion_stop[:])
#Pipe out - final all points exterior of smaller pipe
pipe_out = np.array(np.where((X - 1)**2 + (Y - 1)**2 > (self.diam_out/2)**2)).flatten()
pipe_out_start = np.array(np.where(Z >= 1.5 + 0.5*(self.diam_in - self.diam_out))).flatten()
pipe_out = np.intersect1d(pipe_out[:],pipe_out_start[:])
#Put the pieces together
pipe = expansion[:]
pipe = np.union1d(expansion[:],pipe_in[:])
pipe = np.union1d(pipe[:],pipe_out[:])
obst_list = pipe[:]
return list(obst_list[:])
class PipeTurn(EmptyChannel):
"""
Provides an s-shaped pipe of constant radius with two 180-degree turns constructed out of constant-radius tori. Diameter needs to be 0.5 for
"""
def __init__(self,diam_in):
"""
constructor providing pipe diameter for use in Lo. Use 0.5.
"""
self.diam_in = diam_in
def get_Lo(self):
return self.diam_in
def get_obstList(self,X,Y,Z):
"""
Define areas external to pipe.
"""
#Pipe_1
pipe_1 = np.array(np.where((X - 1)**2 + (Y - 4)**2 >= 0.5**2)).flatten()
pipe_1_stop_z = np.array(np.where(Z <= 3.0)).flatten()
pipe_1_stop_y = np.array(np.where(Y >= 3.25)).flatten()
pipe_1_stop = np.intersect1d(pipe_1_stop_z[:],pipe_1_stop_y[:])
pipe_1 = np.intersect1d(pipe_1[:],pipe_1_stop[:])
#Turn_1
turn_1 = np.array(np.where((0.75 - np.sqrt((Y - 3.25)**2 + (Z -3)**2))**2 + (X - 1)**2 >= 0.5**2)).flatten()
turn_1_stop_z = np.array(np.where(Z >= 3.0)).flatten()
turn_1_stop_y = np.array(np.where(Y>= 1.75)).flatten()
turn_1_stop = np.intersect1d(turn_1_stop_z[:],turn_1_stop_y[:])
turn_1 = np.intersect1d(turn_1[:],turn_1_stop[:])
#Pipe_2
pipe_2 = np.array(np.where((X - 1)**2 + (Y - 2.5)**2 >= 0.5**2)).flatten()
pipe_2_start_z = np.array(np.where(Z >= 1.5)).flatten()
pipe_2_start_y_up = np.array(np.where(Y <= 3.25)).flatten()
pipe_2_start_y_down = np.array(np.where(Y >= 1.75)).flatten()
pipe_2_start_y = np.intersect1d(pipe_2_start_y_up[:],pipe_2_start_y_down[:])
pipe_2_start = np.intersect1d(pipe_2_start_z[:],pipe_2_start_y[:])
pipe_2 = np.intersect1d(pipe_2[:],pipe_2_start[:])
pipe_2_stop_z = np.array(np.where(Z <= 3.0)).flatten()
pipe_2_stop_y = np.array(np.where(Y <= 3.25)).flatten()
pipe_2_stop = np.intersect1d(pipe_2_stop_z[:],pipe_2_stop_y[:])
pipe_2 = np.intersect1d(pipe_2[:],pipe_2_stop[:])
#Turn_2
turn_2 = np.array(np.where((0.75 - np.sqrt((Y - 1.75)**2 + (Z -1.5)**2))**2 + (X - 1)**2 >= 0.5**2)).flatten()
turn_2_stop_z = np.array(np.where(Z <= 1.5)).flatten()
turn_2_stop_y = np.array(np.where(Y <= 3.25)).flatten()
turn_2_stop = np.intersect1d(turn_2_stop_z[:],turn_2_stop_y[:])
turn_2 = np.intersect1d(turn_2[:],turn_2_stop[:])
#Pipe_3
pipe_3 = np.array(np.where((X - 1)**2 + (Y - 1.0)**2 >= 0.5**2)).flatten()
pipe_3_start_z = np.array(np.where(Z >= 1.5)).flatten()
pipe_3_start_y = np.array(np.where(Y <= 1.75)).flatten()
pipe_3_start = np.intersect1d(pipe_3_start_z[:],pipe_3_start_y[:])
pipe_3 = np.intersect1d(pipe_3[:],pipe_3_start[:])
#Put the pieces together
pipe = np.union1d(pipe_1[:],turn_1[:])
pipe = np.union1d(pipe[:],pipe_2[:])
pipe = np.union1d(pipe[:],turn_2[:])
pipe = np.union1d(pipe[:],pipe_3[:])
obst_list = pipe[:]
return list(obst_list[:])
class PipeOut(EmptyChannel):
"""
Class consisting of a single pipe of diam_in and length length_in exiting a wall into an open space.
"""
def __init__(self,diam_in,length_in):
"""
defines the diameter and length (z axis) of pipe leading to open area
"""
self.diam_in = diam_in
self.length_in = length_in
def get_Lo(self):
return self.diam_in
def get_obstList(self,X,Y,Z):
"""
Define solid areas around pipe. Everything else will be open. Ensure coordinates for center of circle match center of Lx-Ly.
"""
#Pipe In
pipe_in = np.array(np.where((X - 0.5*(4))**2 + (Y - 0.5*(4))**2 >= (0.5*self.diam_in)**2)).flatten()
pipe_in_stop = np.array(np.where(Z <= self.length_in)).flatten()
pipe_in = np.intersect1d(pipe_in[:],pipe_in_stop[:])
obst_list = pipe_in[:]
return list(obst_list[:])
class Butterfly(EmptyChannel):
"""
A geometry class that defines a fully open butterfly valve within a pipe of diam=1.0.
"""
def __init__(self,diam):
"""
constructor identifying pipe diameter. Must be a 1 diam pipe inside a 1.2 x 1.2 x 8 channel. Valve center at z = 3.
"""
self.diam = diam
def get_Lo(self):
return self.diam
def get_obstList(self,X,Y,Z):
"""
Define solid areas
"""
#Pipe
pipe = np.array(np.where((X - 0.6)**2 + (Y - 0.6)**2 >= 0.5**2)).flatten()
#Seat
seat = np.array(np.where((X - 0.6)**2 + (Y - 0.6)**2 >= 0.42**2)).flatten()
seat_start = np.array(np.where(Z >= 2.975)).flatten()
seat_stop = np.array(np.where(Z <= 3.025)).flatten()
seat = np.intersect1d(seat[:],seat_start[:])
seat = np.intersect1d(seat[:],seat_stop[:])
#Pivot
pivot = np.array(np.where((X - 0.6)**2 + (Z - 3)**2 <= 0.075**2)).flatten()
#Front Disc
front_disc = np.array(np.where((Y - 0.6)**2 + (Z - 3)**2 <= 0.5**2)).flatten()
front_disc_stop = np.array(np.where(Z <= 3.0)).flatten()
front_disc_x_min = np.array(np.where(X >= 0.525)).flatten()
front_disc_x_max = np.array(np.where(X <= 0.575)).flatten()
front_disc = np.intersect1d(front_disc[:],front_disc_stop[:])
front_disc = np.intersect1d(front_disc[:],front_disc_x_min[:])
front_disc = np.intersect1d(front_disc[:],front_disc_x_max[:])
#Back Disc
back_disc = np.array(np.where((Y - 0.6)**2 + (Z - 3)**2 <= 0.5**2)).flatten()
back_disc_start = np.array(np.where(Z >= 3.0)).flatten()
back_disc_x_min = np.array(np.where(X >= 0.625)).flatten()
back_disc_x_max = np.array(np.where(X <= 0.675)).flatten()
back_disc = np.intersect1d(back_disc[:],back_disc_start[:])
back_disc = np.intersect1d(back_disc[:],back_disc_x_min[:])
back_disc = np.intersect1d(back_disc[:],back_disc_x_max[:])
#Put the pieces together
valve = np.union1d(pipe[:],seat[:])
valve = np.union1d(valve[:],pivot[:])
valve = np.union1d(valve[:],front_disc[:])
valve = np.union1d(valve[:],back_disc[:])
obst_list = valve[:]
return list(obst_list[:])
class Tee(EmptyChannel):
"""
establishes a single large pipe with a "tee" into a smaller pipe that loops up and around before rejoining the main line. The Main line undergoes a contraction after the tee but before the rejoining secondary line. diam_2 should be smaller than diam_1.
"""
def __init__(self,diam_1,diam_2):
"""
Constructor identifying the diameters of the two pipes. Pipe 1 runs straight through from Z_min to Z_max. Pipe 2 tees off and runs parallel to Pipe 1. Pipe 1 enters/exits z planes at y = 1. Pipe 2 runs at y = 3. Assumes dimensions of space (X,Y,Z) is (2,4,8).
"""
self.diam_1 = diam_1
self.diam_2 = diam_2
def get_Lo(self):
return self.diam_1
def get_obstList(self,X,Y,Z):
"""
Define solid areas
"""
#Pipe 1
pipe_1a = np.array(np.where((X - 1)**2 + (Y - 1)**2 <= (self.diam_1/2)**2)).flatten()
pipe_1a_stop = np.array(np.where(Z<=4.)).flatten()
pipe_1a = np.intersect1d(pipe_1a[:],pipe_1a_stop[:])
pipe_1b = np.array(np.where((X - 1)**2 + (Y - 1)**2 <= (self.diam_1/4)**2)).flatten()
pipe_1 = np.union1d(pipe_1a[:],pipe_1b[:])
#Pipe 2 Tee Off
tee_1 = np.array(np.where((X - 1)**2 + (Z - 1.5)**2 <= (self.diam_2/2)**2)).flatten()
tee_1_start = np.array(np.where(Y >= 1)).flatten()
tee_1_end = np.array(np.where(Y <= 3 - 0.5*self.diam_2)).flatten()
tee_1 = np.intersect1d(tee_1[:],tee_1_start[:])
tee_1 = np.intersect1d(tee_1[:],tee_1_end[:])
#Pipe 2 Elbow 1
elbow_1 = np.array(np.where((self.diam_2/2 - np.sqrt((Y - (3 - self.diam_2/2))**2 + (Z -(1.5 + self.diam_2/2))**2))**2 + (X - 1)**2 <= (self.diam_2/2)**2)).flatten()
elbow_1_start = np.array(np.where(Y >= 3- 0.5*self.diam_2)).flatten()
elbow_1_stop = np.array(np.where(Z <= 1.5 + self.diam_2/2)).flatten()
elbow_1 = np.intersect1d(elbow_1[:],elbow_1_start[:])
elbow_1 = np.intersect1d(elbow_1[:],elbow_1_stop[:])
#Pipe 2
pipe_2 = np.array(np.where((X - 1)**2 + (Y - 3)**2 <= (self.diam_2/2)**2)).flatten()
pipe_2_start = np.array(np.where(Z >= 1.5 + self.diam_2/2)).flatten()
pipe_2_stop = np.array(np.where(Z <= 5 - self.diam_2/2)).flatten()
pipe_2 = np.intersect1d(pipe_2[:],pipe_2_start[:])
pipe_2 = np.intersect1d(pipe_2[:],pipe_2_stop[:])
#Pipe 2 Elbow 2
elbow_2 = np.array(np.where((self.diam_2/2 - np.sqrt((Y - (3 - self.diam_2/2))**2 + (Z -(5- self.diam_2/2))**2))**2 + (X - 1)**2 <= (self.diam_2/2)**2)).flatten()
elbow_2_start = np.array(np.where(Y >= 3- 0.5*self.diam_2)).flatten()
elbow_2_stop = np.array(np.where(Z >= 5- self.diam_2/2)).flatten()
elbow_2 = np.intersect1d(elbow_2[:],elbow_2_start[:])
elbow_2 = np.intersect1d(elbow_2[:],elbow_2_stop[:])
#Pipe 2 Tee In
tee_2 = np.array(np.where((X - 1)**2 + (Z - 5)**2 <= (self.diam_2/2)**2)).flatten()
tee_2_start = np.array(np.where(Y >= 1)).flatten()
tee_2_end = np.array(np.where(Y <= 3 - 0.5*self.diam_2)).flatten()
tee_2 = np.intersect1d(tee_2[:],tee_2_start[:])
tee_2 = np.intersect1d(tee_2[:],tee_2_end[:])
empty = np.array(np.where(Y>=0.)).flatten()
#Put the pieces together
pipe = np.union1d(pipe_1[:],tee_1[:])
pipe = np.union1d(pipe[:],elbow_1[:])
pipe = np.union1d(pipe[:],pipe_2[:])
pipe = np.union1d(pipe[:],elbow_2[:])
pipe = np.union1d(pipe[:],tee_2[:])
pipe = np.setxor1d(pipe[:], empty[:])
obst_list = pipe[:]
return list(obst_list[:])
def fluid_properties(fluid_str):
"""
Return the physical density and kinematic viscosity for the prescribed
fluid.
"""
fluid_lib = {'water':(1000., 1.0e-6),
'glycol':(965.3,6.216e-4),
'glycerin':(1260,1.18e-3)}
if fluid_str in fluid_lib.keys():
return fluid_lib[fluid_str]
else:
print 'valid fluids are:'
for keys in fluid_lib:
print " '%s' " % keys
raise KeyError('invalid fluid specified')
class LidDrivenCavity:
def __init__(self,Lx_p = 1.,
Ly_p = 1., Lz_p = 1.,
fluid='water',
N_divs=11) :
"""
class constructor - lid driven cavity.
All surfaces xm,xp,ym,zm,zp are solid except
the "lid" (yp) which is a moving surface
(node type 5)
"""
self.Lx_p = Lx_p
self.Ly_p = Ly_p
self.Lz_p = Lz_p
self.N_divs = N_divs
self.fluid = fluid
# generate the geometry
Lo = Ly_p # by convention (for now)
self.Lo = Lo
self.Ny = math.ceil((N_divs-1)*(Ly_p/Lo))+1
self.Nx = math.ceil((N_divs-1)*(Lx_p/Lo))+1
self.Nz = math.ceil((N_divs-1)*(Lz_p/Lo))+1
self.nnodes = self.Nx*self.Ny*self.Nz
print "Creating channel with %g lattice points." % self.nnodes
x = np.linspace(0.,Lx_p,self.Nx).astype(np.float32);
y = np.linspace(0.,Ly_p,self.Ny).astype(np.float32);
z = np.linspace(0.,Lz_p,self.Nz).astype(np.float32);
Y,Z,X = np.meshgrid(y,z,x);
self.x = np.reshape(X,int(self.nnodes))
self.y = np.reshape(Y,int(self.nnodes))
self.z = np.reshape(Z,int(self.nnodes))
self.dx = x[1]-x[0]
# get fluid properties from the included fluid library