-
Notifications
You must be signed in to change notification settings - Fork 54
/
RANS2P_IB.py
1702 lines (1657 loc) · 91.3 KB
/
RANS2P_IB.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
from __future__ import print_function
from __future__ import absolute_import
from __future__ import division
from builtins import str
from builtins import range
from past.utils import old_div
import proteus
import proteus.mprans.RANS2P as RANS2P
from proteus.mprans.cRANS2P_IB import *
import numpy as np
from . import beamFEM
from .ArchiveBeams import *
from proteus.Comm import (globalMax,
globalSum)
class Coefficients(proteus.mprans.RANS2P.Coefficients):
def __init__(self,
epsFact=1.5,
sigma=72.8,
rho_0=998.2, nu_0=1.004e-6,
rho_1=1.205, nu_1=1.500e-5,
g=[0.0, 0.0, -9.8],
nd=3,
LS_model=None,
VF_model=None,
KN_model=None,
Closure_0_model=None, # Turbulence closure model
Closure_1_model=None, # Second possible Turbulence closure model
epsFact_density=None,
stokes=False,
sd=True,
movingDomain=False,
useVF=0.0,
useRBLES=0.0,
useMetrics=0.0,
useConstant_he=False,
dragAlpha=0.01,
dragBeta=0.0,
setParamsFunc=None, # uses setParamsFunc if given
dragAlphaTypes=None, # otherwise can use element constant values
dragBetaTypes=None, # otherwise can use element constant values
porosityTypes=None,
killNonlinearDrag=False,
epsFact_source=1.,
epsFact_solid=None,
eb_adjoint_sigma=1.0,
eb_penalty_constant=10.0,
forceStrongDirichlet=False,
turbulenceClosureModel=0, # 0=No Model, 1=Smagorinksy, 2=Dynamic Smagorinsky, 3=K-Epsilon, 4=K-Omega
smagorinskyConstant=0.1,
barycenters=None,
beamLocation=[],
beamLength=[],
beamRadius=[],
EI=[],
GJ=[],
nBeamElements=4,
beam_quadOrder=3,
beamFilename="Beams",
beam_useSparse=False,
beam_Cd=1.2,
beam_nlTol=1.0e-5,
beamRigid=True):
RANS2P.Coefficients.__init__(self,
epsFact=1.5,
sigma=72.8,
rho_0=998.2, nu_0=1.004e-6,
rho_1=1.205, nu_1=1.500e-5,
g=[0.0, 0.0, -9.8],
nd=3,
LS_model=None,
VF_model=None,
KN_model=None,
Closure_0_model=None, # Turbulence closure model
Closure_1_model=None, # Second possible Turbulence closure model
epsFact_density=None,
stokes=False,
sd=True,
movingDomain=False,
useVF=0.0,
useRBLES=0.0,
useMetrics=0.0,
useConstant_he=False,
dragAlpha=0.01,
dragBeta=0.0,
setParamsFunc=None, # uses setParamsFunc if given
dragAlphaTypes=None, # otherwise can use element constant values
dragBetaTypes=None, # otherwise can use element constant values
porosityTypes=None,
killNonlinearDrag=False,
epsFact_solid=None,
eb_adjoint_sigma=1.0,
eb_penalty_constant=10.0,
forceStrongDirichlet=False,
turbulenceClosureModel=0, # 0=No Model, 1=Smagorinksy, 2=Dynamic Smagorinsky, 3=K-Epsilon, 4=K-Omega
smagorinskyConstant=0.1,
barycenters=None)
self.beamFilename = beamFilename
self.beamLength = beamLength
self.beamRadius = np.array(beamRadius)
self.beamLocation = beamLocation
self.beamVolume = math.pi * self.beamRadius * self.beamRadius * self.beamLength
self.nBeamElements = nBeamElements
self.EI = EI
self.GJ = GJ
self.beam_quadOrder = beam_quadOrder
self.beam_nlTol = beam_nlTol
self.beam_useSparse = beam_useSparse
self.beam_Cd = beam_Cd
self.beam_nlTol = beam_nlTol
self.beamRigid = beamRigid
def attachModels(self, modelList):
RANS2P.Coefficients.attachModels(self, modelList)
self.initializeBeams()
self.netBeamDrag = np.array([0.0])
def initializeElementQuadrature(self, t, cq):
RANS2P.Coefficients.initializeElementQuadrature(self, t, cq)
self.q_dragBeam1 = numpy.zeros(cq[('u', 1)].shape, 'd')
self.q_dragBeam2 = numpy.zeros(cq[('u', 1)].shape, 'd')
self.q_dragBeam3 = numpy.zeros(cq[('u', 1)].shape, 'd')
def initializeGlobalExteriorElementBoundaryQuadrature(self, t, cebqe):
RANS2P.Coefficients.initializeGlobalExteriorElementBoundaryQuadrature(self, t, cebqe)
self.ebqe_dragBeam1 = numpy.zeros(cebqe[('u', 1)].shape, 'd')
self.ebqe_dragBeam2 = numpy.zeros(cebqe[('u', 1)].shape, 'd')
self.ebqe_dragBeam3 = numpy.zeros(cebqe[('u', 1)].shape, 'd')
def initializeMesh(self, mesh):
RANS2P.Coefficients.initializeMesh(self, mesh)
if self.comm.isMaster():
self.netForceHistory = open("netForceHistory.txt", "w")
self.forceHistory_drag = open("forceHistory_drag.txt", "w")
self.velocityAverage = open("velocityAverage.txt", "w")
self.dragCoefficientHistory = open("dragCoefficientHistory.txt", "w")
if self.beamRigid == False:
self.deflectionHistory = open("deflectionHistory.txt", "w")
def postStep(self, t, firstStep=False):
self.beamDrag = np.array([0.0, 0.0, 0.0])
if not self.beamRigid:
self.updateBeams(t)
else:
self.updateBeamLoad()
if self.comm.isMaster():
print("wettedAreas")
print(self.wettedAreas[:])
print("Forces_p")
print(self.netForces_p[:, :])
print("Forces_v")
print(self.netForces_v[:, :])
#self.wettedAreaHistory.write("%21.16e\n" % (self.wettedAreas[-1],))
#self.forceHistory_p.write("%21.16e %21.16e %21.16e\n" %tuple(self.netForces_p[-1,:]))
# self.forceHistory_p.flush()
#self.forceHistory_v.write("%21.16e %21.16e %21.16e\n" %tuple(self.netForces_v[-1,:]))
# self.forceHistory_v.flush()
#self.momentHistory.write("%21.15e %21.16e %21.16e\n" % tuple(self.netMoments[-1,:]))
# self.momentHistory.flush()
#self.forceHistory_drag.write("%21.16e %21.16e %21.16e %21.16e\n" %tuple([t,self.beamDrag[0], self.beamDrag[1], self.beamDrag[2]]))
# self.forceHistory_drag.flush()
#self.velocityAverage.write("%21.16e %21.16e %21.16e %21.16e\n" %tuple([t,self.vel_avg[0], self.vel_avg[1], self.vel_avg[2]]))
# self.velocityAverage.flush()
if self.beamRigid == False:
self.deflectionHistory.write("%21.16e %21.16e %21.16e %21.16e\n" % tuple([t, self.avgHeight, self.avgDeflection, self.avgAngle]))
self.deflectionHistory.flush()
def delta_h(self, r):
if r <= -2.0:
return 0.0
elif r <= -1.0:
return 1.0 / 8.0 * (5.0 + 2.0 * r - (-7.0 - 12.0 * r - 4 * r * r)**0.5)
elif r <= 0.0:
return 1.0 / 8.0 * (3.0 + 2.0 * r + (1.0 - 4.0 * r - 4.0 * r * r)**0.5)
elif r <= 1.0:
return 1.0 / 8.0 * (3.0 - 2.0 * r + (1.0 + 4.0 * r - 4.0 * r * r)**0.5)
elif r <= 2.0:
return 1.0 / 8.0 * (5.0 - 2.0 * r - (-7.0 + 12.0 * r - 4.0 * r * r)**0.5)
else:
return 0.0
def updateBeamLoad(self):
for I in range(self.nBeams):
if I % self.comm.size() == self.comm.rank():
if self.nd == 3:
self.Beam_Solver[I].updateLoads(self.q1[I, :], self.q2[I, :], self.q3[I, :])
elif self.nd == 2:
self.Beam_Solver[I].updateLoads(self.q3[I, :], self.q2[I, :], self.q1[I, :])
self.Beam_Solver[I].updateQs(endLoad=[0.0, 0.0, 0.0], scale=1.0)
if self.centerBox[I] == True:
if self.nd == 3:
self.beamDrag[0] += self.Beam_Solver[I].Q1[0]
self.beamDrag[1] += self.Beam_Solver[I].Q2[0]
self.beamDrag[2] += self.Beam_Solver[I].Q3[0]
elif self.nd == 2:
self.beamDrag[0] += self.Beam_Solver[I].Q3[0]
self.beamDrag[1] += self.Beam_Solver[I].Q2[0]
self.beamDrag[2] += self.Beam_Solver[I].Q1[0]
for i in range(3):
self.beamDrag.flat[i] = globalSum(self.beamDrag.flat[i])
def updateBeams(self, t):
self.beamDrag = np.array([0.0, 0.0, 0.0])
loadSteps = 20
xv_hold = np.copy(self.xv)
yv_hold = np.copy(self.yv)
zv_hold = np.copy(self.zv)
xq_hold = np.copy(self.xq)
yq_hold = np.copy(self.yq)
zq_hold = np.copy(self.zq)
for I in range(self.nBeams):
self.xv[I].flat = 0.0
self.yv[I].flat = 0.0
self.zv[I].flat = 0.0
self.xq[I].flat = 0.0
self.yq[I].flat = 0.0
self.zq[I].flat = 0.0
if I % self.comm.size() == self.comm.rank():
if self.nd == 3:
self.Beam_Solver[I].updateLoads(self.q1[I, :], self.q2[I, :], self.q3[I, :])
elif self.nd == 2:
self.Beam_Solver[I].updateLoads(self.q3[I, :], self.q2[I, :], self.q1[I, :])
for j in range(loadSteps):
self.Beam_Solver[I].Phi.flat[:] = 0.0
self.Beam_Solver[I].updateQs(endLoad=[0.0, 0.0, 0.0], scale=old_div(float(j), float(loadSteps)))
counter = 0
go = True
Phi = np.copy(self.Beam_Solver[I].Phi)
while go == True:
self.Beam_Solver[I].calculateGradient_Hessian()
self.Beam_Solver[I].setBCs()
self.Beam_Solver[I].reduceOrder()
error = self.Beam_Solver[I].calculateResidual()
self.Beam_Solver[I].updateSolution()
go = self.Beam_Solver[I].checkConvergence()
counter += 1
if counter >= 100:
go = False
self.Beam_Solver[I].Phi = np.copy(Phi)
if self.nd == 3:
xv, yv, zv = self.Beam_Solver[I].updateCoords()
if np.min(zv) > -1.0e-10:
self.xv[I, :] = xv
self.yv[I, :] = yv
self.zv[I, :] = zv
self.xq[I, :].flat[:], self.yq[I, :].flat[:], self.zq[I, :].flat[:] = self.Beam_Solver[I].getCoords_at_Quad()
else:
self.xv[I, :] = xv_hold[I, :]
self.yv[I, :] = yv_hold[I, :]
self.zv[I, :] = zv_hold[I, :]
self.xq[I, :] = xq_hold[I, :]
self.yq[I, :] = yq_hold[I, :]
self.zq[I, :] = zq_hold[I, :]
self.beamDrag[0] += self.Beam_Solver[I].Q1[0]
self.beamDrag[1] += self.Beam_Solver[I].Q2[0]
self.beamDrag[2] += self.Beam_Solver[I].Q3[0]
elif self.nd == 2:
self.zv[I, :], self.yv[I, :], self.xv[I, :] = self.Beam_Solver[I].updateCoords()
self.zq[I, :].flat[:], self.yq[I, :].flat[:], self.xq[I, :].flat[:] = self.Beam_Solver[I].getCoords_at_Quad()
self.xq[I, :] += 0.2
self.xv[I, :] += 0.2
self.beamDrag[0] += self.Beam_Solver[I].Q3[0]
self.beamDrag[1] += self.Beam_Solver[I].Q2[0]
self.beamDrag[2] += self.Beam_Solver[I].Q1[0]
self.beamDrag[0] = globalSum(self.beamDrag[0])
self.beamDrag[1] = globalSum(self.beamDrag[1])
self.beamDrag[2] = globalSum(self.beamDrag[2])
for i in range(self.nBeams * (self.nBeamElements + 1)):
self.xv.flat[i] = globalSum(self.xv.flat[i])
self.yv.flat[i] = globalSum(self.yv.flat[i])
self.zv.flat[i] = globalSum(self.zv.flat[i])
for i in range(self.nBeams * self.nBeamElements * self.beam_quadOrder):
self.xq.flat[i] = globalSum(self.xq.flat[i])
self.yq.flat[i] = globalSum(self.yq.flat[i])
self.zq.flat[i] = globalSum(self.zq.flat[i])
if self.nBeams > 0 and self.comm.isMaster():
Archive_time_step(Beam_x=self.xv,
Beam_y=self.yv,
Beam_z=self.zv,
nBeams=self.nBeams,
filename=self.beamFilename,
t=t,
tStep=self.tStep)
self.tStep += 1
# self.avgHeight=0.0
# self.avgDeflection=0.0
# self.avgAngle=0.0
# nBeamsLocal=0
# for I in range(self.nBeams):
# if self.centerBox[I]==True:
# nBeamsLocal+=1
# self.avgHeight+=self.zv[I,-1]
# self.avgDeflection += abs(self.xv[I,-1]-self.xv[I,0])
# self.avgAngle+= math.degrees(math.atan((self.zv[I,-1]-self.zv[I,-2])/(self.xv[I,-1]-self.xv[I,-2])))#self.Beam_Solver[I].Phi[-3]
self.avgHeight = old_div(np.sum(self.zv[:, -1]), float(self.nBeams))
self.avgDeflection = old_div(np.sum(np.abs(self.xv[:, -1] - self.xv[:, 0])), float(self.nBeams))
self.avgAngle = old_div(np.sum(np.rad2deg(np.arctan(old_div((self.zv[:, -1] - self.zv[:, -2]), (self.xv[:, -1] - self.xv[:, -2]))))), float(self.nBeams))
def initializeBeams(self):
comm = Comm.get()
self.comm = comm
bBox = [.25 * .69, .69 - .25 * .69]
self.centerBox = []
self.nBeams = len(self.beamLocation)
# eulerian coords for beam at mesh vertices
self.xv = np.zeros((self.nBeams, self.nBeamElements + 1))
self.yv = np.zeros((self.nBeams, self.nBeamElements + 1))
self.zv = np.zeros((self.nBeams, self.nBeamElements + 1))
# distributed loads for beam at quadrature points #mesh vertices
self.q1 = np.zeros((self.nBeams, self.nBeamElements, self.beam_quadOrder)) # np.zeros((self.nBeams, self.nBeamElements+1))
self.q2 = np.zeros((self.nBeams, self.nBeamElements, self.beam_quadOrder)) # np.zeros((self.nBeams, self.nBeamElements+1))
self.q3 = np.zeros((self.nBeams, self.nBeamElements, self.beam_quadOrder)) # np.zeros((self.nBeams, self.nBeamElements+1))
# element diameters
self.Beam_h = np.zeros((self.nBeams, self.nBeamElements))
# eulerian coords for beam at quadrataure points
self.xq = np.zeros((self.nBeams, self.nBeamElements, self.beam_quadOrder))
self.yq = np.zeros((self.nBeams, self.nBeamElements, self.beam_quadOrder))
self.zq = np.zeros((self.nBeams, self.nBeamElements, self.beam_quadOrder))
# integration constant for beams
self.dV_beam = np.zeros((self.nBeams, self.nBeamElements, self.beam_quadOrder))
self.Beam_mesh = np.zeros((self.nBeams, self.nBeamElements + 1))
self.Beam_Solver = []
boxCount = 0
for i in range(self.nBeams):
if self.beamLocation[i][1] >= bBox[0] and self.beamLocation[i][1] <= bBox[1]:
self.centerBox.append(True)
boxCount += 1
else:
self.centerBox.append(False)
self.Beam_Solver.append(beamFEM.FEMTools(L=self.beamLength[i],
nElements=self.nBeamElements,
quadOrder=self.beam_quadOrder,
EI=self.EI[i],
GJ=self.GJ[i],
nlTol=self.beam_nlTol,
useSparse=self.beam_useSparse,
beamLocation=self.beamLocation[i]))
self.Beam_mesh[i, :], self.Beam_h[i, :] = self.Beam_Solver[i].structuredMesh()
self.Beam_Solver[i].GaussQuad()
self.Beam_Solver[i].basisFunctions()
self.Beam_Solver[i].initializePhi()
self.Beam_Solver[i].initializeCoords()
if self.nd == 3:
self.xv[i, :], self.yv[i, :], self.zv[i, :] = self.Beam_Solver[i].updateCoords()
elif self.nd == 2:
self.zv[i, :], self.yv[i, :], self.xv[i, :] = self.Beam_Solver[i].updateCoords()
self.xv[i, :] += 0.2
#self.xv[i,:], self.yv[i,:], self.zv[i,:] = self.Beam_Solver[i].updateCoords()
for j in range(self.nBeamElements):
for k in range(self.beam_quadOrder):
self.dV_beam[i, j, k] = 0.5 * self.Beam_h[i, j] * self.Beam_Solver[i].w[k]
if self.nd == 3:
self.xq[i, :].flat[:], self.yq[i, :].flat[:], self.zq[i, :].flat[:] = self.Beam_Solver[i].getCoords_at_Quad()
elif self.nd == 2:
self.zq[i, :].flat[:], self.yq[i, :].flat[:], self.xq[i, :].flat[:] = self.Beam_Solver[i].getCoords_at_Quad()
self.xq[i, :] += 0.2
self.tStep = 0
if self.nBeams > 0 and self.comm.isMaster():
Archive_time_step(Beam_x=self.xv,
Beam_y=self.yv,
Beam_z=self.zv,
nBeams=self.nBeams,
filename=self.beamFilename,
t=0.0,
tStep=self.tStep)
self.tStep += 1
print(boxCount)
pass
class LevelModel(proteus.mprans.RANS2P.LevelModel):
# def __init__(self,
# uDict,
# phiDict,
# testSpaceDict,
# matType,
# dofBoundaryConditionsDict,
# dofBoundaryConditionsSetterDict,
# coefficients,
# elementQuadrature,
# elementBoundaryQuadrature,
# fluxBoundaryConditionsDict=None,
# advectiveFluxBoundaryConditionsSetterDict=None,
# diffusiveFluxBoundaryConditionsSetterDictDict=None,
# stressTraceBoundaryConditionsSetterDictDict=None,
# stabilization=None,
# shockCapturing=None,
# conservativeFluxDict=None,
# numericalFluxType=None,
# TimeIntegrationClass=None,
# massLumping=False,
# reactionLumping=False,
# options=None,
# name='RANS2P',
# reuse_trial_and_test_quadrature=True,
# sd = True,
# movingDomain=False):
# RANS2P.LevelModel.__init__(self,
# uDict,
# phiDict,
# testSpaceDict,
# matType,
# dofBoundaryConditionsDict,
# dofBoundaryConditionsSetterDict,
# coefficients,
# elementQuadrature,
# elementBoundaryQuadrature,
# fluxBoundaryConditionsDict=None,
# advectiveFluxBoundaryConditionsSetterDict=None,
# diffusiveFluxBoundaryConditionsSetterDictDict=None,
# stressTraceBoundaryConditionsSetterDictDict=None,
# stabilization=None,
# shockCapturing=None,
# conservativeFluxDict=None,
# numericalFluxType=None,
# TimeIntegrationClass=None,
# massLumping=False,
# reactionLumping=False,
# options=None,
# name='RANS2P',
# reuse_trial_and_test_quadrature=True,
# sd = True,
# movingDomain=False)
# self.rans2p_ib = cRANS2P_IB_base(self.nSpace_global,
# self.nQuadraturePoints_element,
# self.u[0].femSpace.elementMaps.localFunctionSpace.dim,
# self.u[0].femSpace.referenceFiniteElement.localFunctionSpace.dim,
# self.testSpace[0].referenceFiniteElement.localFunctionSpace.dim,
# self.nElementBoundaryQuadraturePoints_elementBoundary,
# compKernelFlag)
def __init__(self,
uDict,
phiDict,
testSpaceDict,
matType,
dofBoundaryConditionsDict,
dofBoundaryConditionsSetterDict,
coefficients,
elementQuadrature,
elementBoundaryQuadrature,
fluxBoundaryConditionsDict=None,
advectiveFluxBoundaryConditionsSetterDict=None,
diffusiveFluxBoundaryConditionsSetterDictDict=None,
stressTraceBoundaryConditionsSetterDictDict=None,
stabilization=None,
shockCapturing=None,
conservativeFluxDict=None,
numericalFluxType=None,
TimeIntegrationClass=None,
massLumping=False,
reactionLumping=False,
options=None,
name='RANS2P',
reuse_trial_and_test_quadrature=True,
sd=True,
movingDomain=False):
self.eb_adjoint_sigma = coefficients.eb_adjoint_sigma
useConstant_he = coefficients.useConstant_he # this is a hack to test the effect of using a constant smoothing width
self.postProcessing = True
#
# set the objects describing the method and boundary conditions
#
self.movingDomain = coefficients.movingDomain
self.tLast_mesh = None
#
# cek todo clean up these flags in the optimized version
self.bcsTimeDependent = options.bcsTimeDependent
self.bcsSet = False
self.name = name
self.sd = sd
self.lowmem = True
self.timeTerm = True # allow turning off the time derivative
self.testIsTrial = True
self.phiTrialIsTrial = True
self.u = uDict
self.Hess = False
if isinstance(self.u[0].femSpace, C0_AffineQuadraticOnSimplexWithNodalBasis):
self.Hess = True
self.ua = {} # analytical solutions
self.phi = phiDict
self.dphi = {}
self.matType = matType
# mwf try to reuse test and trial information across components if spaces are the same
self.reuse_test_trial_quadrature = reuse_trial_and_test_quadrature # True#False
if self.reuse_test_trial_quadrature:
for ci in range(1, coefficients.nc):
assert self.u[ci].femSpace.__class__.__name__ == self.u[0].femSpace.__class__.__name__, "to reuse_test_trial_quad all femSpaces must be the same!"
# Simplicial Mesh
self.mesh = self.u[0].femSpace.mesh # assume the same mesh for all components for now
self.testSpace = testSpaceDict
self.dirichletConditions = dofBoundaryConditionsDict
self.dirichletNodeSetList = None # explicit Dirichlet conditions for now, no Dirichlet BC constraints
self.coefficients = coefficients
self.coefficients.initializeMesh(self.mesh)
self.nc = self.coefficients.nc
self.stabilization = stabilization
self.shockCapturing = shockCapturing
self.conservativeFlux = conservativeFluxDict # no velocity post-processing for now
self.fluxBoundaryConditions = fluxBoundaryConditionsDict
self.advectiveFluxBoundaryConditionsSetterDict = advectiveFluxBoundaryConditionsSetterDict
self.diffusiveFluxBoundaryConditionsSetterDictDict = diffusiveFluxBoundaryConditionsSetterDictDict
# determine whether the stabilization term is nonlinear
self.stabilizationIsNonlinear = False
# cek come back
if self.stabilization is not None:
for ci in range(self.nc):
if ci in coefficients.mass:
for flag in list(coefficients.mass[ci].values()):
if flag == 'nonlinear':
self.stabilizationIsNonlinear = True
if ci in coefficients.advection:
for flag in list(coefficients.advection[ci].values()):
if flag == 'nonlinear':
self.stabilizationIsNonlinear = True
if ci in coefficients.diffusion:
for diffusionDict in list(coefficients.diffusion[ci].values()):
for flag in list(diffusionDict.values()):
if flag != 'constant':
self.stabilizationIsNonlinear = True
if ci in coefficients.potential:
for flag in list(coefficients.potential[ci].values()):
if flag == 'nonlinear':
self.stabilizationIsNonlinear = True
if ci in coefficients.reaction:
for flag in list(coefficients.reaction[ci].values()):
if flag == 'nonlinear':
self.stabilizationIsNonlinear = True
if ci in coefficients.hamiltonian:
for flag in list(coefficients.hamiltonian[ci].values()):
if flag == 'nonlinear':
self.stabilizationIsNonlinear = True
# determine if we need element boundary storage
self.elementBoundaryIntegrals = {}
for ci in range(self.nc):
self.elementBoundaryIntegrals[ci] = ((self.conservativeFlux is not None) or
(numericalFluxType is not None) or
(self.fluxBoundaryConditions[ci] == 'outFlow') or
(self.fluxBoundaryConditions[ci] == 'mixedFlow') or
(self.fluxBoundaryConditions[ci] == 'setFlow'))
#
# calculate some dimensions
#
self.nSpace_global = self.u[0].femSpace.nSpace_global # assume same space dim for all variables
self.nDOF_trial_element = [u_j.femSpace.max_nDOF_element for u_j in list(self.u.values())]
self.nDOF_phi_trial_element = [phi_k.femSpace.max_nDOF_element for phi_k in list(self.phi.values())]
self.n_phi_ip_element = [phi_k.femSpace.referenceFiniteElement.interpolationConditions.nQuadraturePoints for phi_k in list(self.phi.values())]
self.nDOF_test_element = [femSpace.max_nDOF_element for femSpace in list(self.testSpace.values())]
self.nFreeDOF_global = [dc.nFreeDOF_global for dc in list(self.dirichletConditions.values())]
self.nVDOF_element = sum(self.nDOF_trial_element)
self.nFreeVDOF_global = sum(self.nFreeDOF_global)
#
NonlinearEquation.__init__(self, self.nFreeVDOF_global)
#
# build the quadrature point dictionaries from the input (this
# is just for convenience so that the input doesn't have to be
# complete)
#
elementQuadratureDict = {}
elemQuadIsDict = isinstance(elementQuadrature, dict)
if elemQuadIsDict: # set terms manually
for I in self.coefficients.elementIntegralKeys:
if I in elementQuadrature:
elementQuadratureDict[I] = elementQuadrature[I]
else:
elementQuadratureDict[I] = elementQuadrature['default']
else:
for I in self.coefficients.elementIntegralKeys:
elementQuadratureDict[I] = elementQuadrature
if self.stabilization is not None:
for I in self.coefficients.elementIntegralKeys:
if elemQuadIsDict:
if I in elementQuadrature:
elementQuadratureDict[('stab',) + I[1:]] = elementQuadrature[I]
else:
elementQuadratureDict[('stab',) + I[1:]] = elementQuadrature['default']
else:
elementQuadratureDict[('stab',) + I[1:]] = elementQuadrature
if self.shockCapturing is not None:
for ci in self.shockCapturing.components:
if elemQuadIsDict:
if ('numDiff', ci, ci) in elementQuadrature:
elementQuadratureDict[('numDiff', ci, ci)] = elementQuadrature[('numDiff', ci, ci)]
else:
elementQuadratureDict[('numDiff', ci, ci)] = elementQuadrature['default']
else:
elementQuadratureDict[('numDiff', ci, ci)] = elementQuadrature
if massLumping:
for ci in list(self.coefficients.mass.keys()):
elementQuadratureDict[('m', ci)] = Quadrature.SimplexLobattoQuadrature(self.nSpace_global, 1)
for I in self.coefficients.elementIntegralKeys:
elementQuadratureDict[('stab',) + I[1:]] = Quadrature.SimplexLobattoQuadrature(self.nSpace_global, 1)
if reactionLumping:
for ci in list(self.coefficients.mass.keys()):
elementQuadratureDict[('r', ci)] = Quadrature.SimplexLobattoQuadrature(self.nSpace_global, 1)
for I in self.coefficients.elementIntegralKeys:
elementQuadratureDict[('stab',) + I[1:]] = Quadrature.SimplexLobattoQuadrature(self.nSpace_global, 1)
elementBoundaryQuadratureDict = {}
if isinstance(elementBoundaryQuadrature, dict): # set terms manually
for I in self.coefficients.elementBoundaryIntegralKeys:
if I in elementBoundaryQuadrature:
elementBoundaryQuadratureDict[I] = elementBoundaryQuadrature[I]
else:
elementBoundaryQuadratureDict[I] = elementBoundaryQuadrature['default']
else:
for I in self.coefficients.elementBoundaryIntegralKeys:
elementBoundaryQuadratureDict[I] = elementBoundaryQuadrature
#
# find the union of all element quadrature points and
# build a quadrature rule for each integral that has a
# weight at each point in the union
(self.elementQuadraturePoints, self.elementQuadratureWeights,
self.elementQuadratureRuleIndeces) = Quadrature.buildUnion(elementQuadratureDict)
self.nQuadraturePoints_element = self.elementQuadraturePoints.shape[0]
self.nQuadraturePoints_global = self.nQuadraturePoints_element * self.mesh.nElements_global
#
# Repeat the same thing for the element boundary quadrature
#
(self.elementBoundaryQuadraturePoints,
self.elementBoundaryQuadratureWeights,
self.elementBoundaryQuadratureRuleIndeces) = Quadrature.buildUnion(elementBoundaryQuadratureDict)
self.nElementBoundaryQuadraturePoints_elementBoundary = self.elementBoundaryQuadraturePoints.shape[0]
self.nElementBoundaryQuadraturePoints_global = (self.mesh.nElements_global *
self.mesh.nElementBoundaries_element *
self.nElementBoundaryQuadraturePoints_elementBoundary)
#
# simplified allocations for test==trial and also check if space is mixed or not
#
self.q = {}
self.ebq = {}
self.ebq_global = {}
self.ebqe = {}
self.phi_ip = {}
# mesh
self.ebqe['x'] = numpy.zeros((self.mesh.nExteriorElementBoundaries_global, self.nElementBoundaryQuadraturePoints_elementBoundary, 3), 'd')
self.ebq_global[('totalFlux', 0)] = numpy.zeros((self.mesh.nElementBoundaries_global, self.nElementBoundaryQuadraturePoints_elementBoundary), 'd')
self.ebq_global[('velocityAverage', 0)] = numpy.zeros((self.mesh.nElementBoundaries_global,
self.nElementBoundaryQuadraturePoints_elementBoundary, self.nSpace_global), 'd')
self.q[('u', 1)] = numpy.zeros((self.mesh.nElements_global, self.nQuadraturePoints_element), 'd')
self.q[('u', 2)] = numpy.zeros((self.mesh.nElements_global, self.nQuadraturePoints_element), 'd')
self.q[('u', 3)] = numpy.zeros((self.mesh.nElements_global, self.nQuadraturePoints_element), 'd')
self.q[('m', 1)] = self.q[('u', 1)]
self.q[('m', 2)] = self.q[('u', 2)]
self.q[('m', 3)] = self.q[('u', 3)]
self.q['KE'] = numpy.zeros((self.mesh.nElements_global, self.nQuadraturePoints_element), 'd')
self.q['PE'] = numpy.zeros((self.mesh.nElements_global, self.nQuadraturePoints_element), 'd')
self.q['speed'] = numpy.zeros((self.mesh.nElements_global, self.nQuadraturePoints_element), 'd')
self.q['rho'] = numpy.zeros((self.mesh.nElements_global, self.nQuadraturePoints_element), 'd')
self.q[('m_last', 1)] = numpy.zeros((self.mesh.nElements_global, self.nQuadraturePoints_element), 'd')
self.q[('m_last', 2)] = numpy.zeros((self.mesh.nElements_global, self.nQuadraturePoints_element), 'd')
self.q[('m_last', 3)] = numpy.zeros((self.mesh.nElements_global, self.nQuadraturePoints_element), 'd')
self.q[('m_tmp', 1)] = numpy.zeros((self.mesh.nElements_global, self.nQuadraturePoints_element), 'd')
self.q[('m_tmp', 2)] = numpy.zeros((self.mesh.nElements_global, self.nQuadraturePoints_element), 'd')
self.q[('m_tmp', 3)] = numpy.zeros((self.mesh.nElements_global, self.nQuadraturePoints_element), 'd')
self.q[('mt', 1)] = numpy.zeros((self.mesh.nElements_global, self.nQuadraturePoints_element), 'd')
self.q[('mt', 2)] = numpy.zeros((self.mesh.nElements_global, self.nQuadraturePoints_element), 'd')
self.q[('mt', 3)] = numpy.zeros((self.mesh.nElements_global, self.nQuadraturePoints_element), 'd')
self.q[('dV_u', 1)] = (old_div(1.0, self.mesh.nElements_global)) * numpy.ones((self.mesh.nElements_global, self.nQuadraturePoints_element), 'd')
self.q[('dV_u', 2)] = (old_div(1.0, self.mesh.nElements_global)) * numpy.ones((self.mesh.nElements_global, self.nQuadraturePoints_element), 'd')
self.q[('dV_u', 3)] = (old_div(1.0, self.mesh.nElements_global)) * numpy.ones((self.mesh.nElements_global, self.nQuadraturePoints_element), 'd')
self.q['dV'] = self.q[('dV_u', 1)]
self.q[('f', 0)] = numpy.zeros((self.mesh.nElements_global, self.nQuadraturePoints_element, self.nSpace_global), 'd')
self.q[('velocity', 0)] = numpy.zeros((self.mesh.nElements_global, self.nQuadraturePoints_element, self.nSpace_global), 'd')
self.q['velocity_solid'] = numpy.zeros((self.mesh.nElements_global, self.nQuadraturePoints_element, self.nSpace_global), 'd')
self.q['phi_solid'] = numpy.zeros((self.mesh.nElements_global, self.nQuadraturePoints_element), 'd')
self.q['x'] = numpy.zeros((self.mesh.nElements_global, self.nQuadraturePoints_element, 3), 'd')
self.q[('cfl', 0)] = numpy.zeros((self.mesh.nElements_global, self.nQuadraturePoints_element), 'd')
self.q[('numDiff', 1, 1)] = numpy.zeros((self.mesh.nElements_global, self.nQuadraturePoints_element), 'd')
self.q[('numDiff', 2, 2)] = numpy.zeros((self.mesh.nElements_global, self.nQuadraturePoints_element), 'd')
self.q[('numDiff', 3, 3)] = numpy.zeros((self.mesh.nElements_global, self.nQuadraturePoints_element), 'd')
self.ebqe[('u', 0)] = numpy.zeros((self.mesh.nExteriorElementBoundaries_global, self.nElementBoundaryQuadraturePoints_elementBoundary), 'd')
self.ebqe[('u', 1)] = numpy.zeros((self.mesh.nExteriorElementBoundaries_global, self.nElementBoundaryQuadraturePoints_elementBoundary), 'd')
self.ebqe[('u', 2)] = numpy.zeros((self.mesh.nExteriorElementBoundaries_global, self.nElementBoundaryQuadraturePoints_elementBoundary), 'd')
self.ebqe[('u', 3)] = numpy.zeros((self.mesh.nExteriorElementBoundaries_global, self.nElementBoundaryQuadraturePoints_elementBoundary), 'd')
self.ebqe[('advectiveFlux_bc_flag', 0)] = numpy.zeros(
(self.mesh.nExteriorElementBoundaries_global, self.nElementBoundaryQuadraturePoints_elementBoundary), 'i')
self.ebqe[('advectiveFlux_bc_flag', 1)] = numpy.zeros(
(self.mesh.nExteriorElementBoundaries_global, self.nElementBoundaryQuadraturePoints_elementBoundary), 'i')
self.ebqe[('advectiveFlux_bc_flag', 2)] = numpy.zeros(
(self.mesh.nExteriorElementBoundaries_global, self.nElementBoundaryQuadraturePoints_elementBoundary), 'i')
self.ebqe[('advectiveFlux_bc_flag', 3)] = numpy.zeros(
(self.mesh.nExteriorElementBoundaries_global, self.nElementBoundaryQuadraturePoints_elementBoundary), 'i')
self.ebqe[('diffusiveFlux_bc_flag', 1, 1)] = numpy.zeros(
(self.mesh.nExteriorElementBoundaries_global, self.nElementBoundaryQuadraturePoints_elementBoundary), 'i')
self.ebqe[('diffusiveFlux_bc_flag', 2, 2)] = numpy.zeros(
(self.mesh.nExteriorElementBoundaries_global, self.nElementBoundaryQuadraturePoints_elementBoundary), 'i')
self.ebqe[('diffusiveFlux_bc_flag', 3, 3)] = numpy.zeros(
(self.mesh.nExteriorElementBoundaries_global, self.nElementBoundaryQuadraturePoints_elementBoundary), 'i')
self.ebqe[('advectiveFlux_bc', 0)] = numpy.zeros((self.mesh.nExteriorElementBoundaries_global, self.nElementBoundaryQuadraturePoints_elementBoundary), 'd')
self.ebqe[('advectiveFlux_bc', 1)] = numpy.zeros((self.mesh.nExteriorElementBoundaries_global, self.nElementBoundaryQuadraturePoints_elementBoundary), 'd')
self.ebqe[('advectiveFlux_bc', 2)] = numpy.zeros((self.mesh.nExteriorElementBoundaries_global, self.nElementBoundaryQuadraturePoints_elementBoundary), 'd')
self.ebqe[('advectiveFlux_bc', 3)] = numpy.zeros((self.mesh.nExteriorElementBoundaries_global, self.nElementBoundaryQuadraturePoints_elementBoundary), 'd')
self.ebqe[('diffusiveFlux_bc', 1, 1)] = numpy.zeros(
(self.mesh.nExteriorElementBoundaries_global, self.nElementBoundaryQuadraturePoints_elementBoundary), 'd')
self.ebqe['penalty'] = numpy.zeros((self.mesh.nExteriorElementBoundaries_global, self.nElementBoundaryQuadraturePoints_elementBoundary), 'd')
self.ebqe[('diffusiveFlux_bc', 2, 2)] = numpy.zeros(
(self.mesh.nExteriorElementBoundaries_global, self.nElementBoundaryQuadraturePoints_elementBoundary), 'd')
self.ebqe[('diffusiveFlux_bc', 3, 3)] = numpy.zeros(
(self.mesh.nExteriorElementBoundaries_global, self.nElementBoundaryQuadraturePoints_elementBoundary), 'd')
self.ebqe[('velocity', 0)] = numpy.zeros((self.mesh.nExteriorElementBoundaries_global,
self.nElementBoundaryQuadraturePoints_elementBoundary, self.nSpace_global), 'd')
self.ebqe[('velocity', 1)] = numpy.zeros((self.mesh.nExteriorElementBoundaries_global,
self.nElementBoundaryQuadraturePoints_elementBoundary, self.nSpace_global), 'd')
self.ebqe[('velocity', 2)] = numpy.zeros((self.mesh.nExteriorElementBoundaries_global,
self.nElementBoundaryQuadraturePoints_elementBoundary, self.nSpace_global), 'd')
self.ebqe[('velocity', 3)] = numpy.zeros((self.mesh.nExteriorElementBoundaries_global,
self.nElementBoundaryQuadraturePoints_elementBoundary, self.nSpace_global), 'd')
# VRANS start, defaults to RANS
self.q[('r', 0)] = numpy.zeros((self.mesh.nElements_global, self.nQuadraturePoints_element), 'd')
self.q['eddy_viscosity'] = numpy.zeros((self.mesh.nElements_global, self.nQuadraturePoints_element), 'd')
# VRANS end
# RANS 2eq Models start
self.q[('grad(u)', 1)] = numpy.zeros((self.mesh.nElements_global, self.nQuadraturePoints_element, self.nSpace_global), 'd')
self.q[('grad(u)', 2)] = numpy.zeros((self.mesh.nElements_global, self.nQuadraturePoints_element, self.nSpace_global), 'd')
self.q[('grad(u)', 3)] = numpy.zeros((self.mesh.nElements_global, self.nQuadraturePoints_element, self.nSpace_global), 'd')
# probably don't need ebqe gradients
self.ebqe[('grad(u)', 1)] = numpy.zeros((self.mesh.nExteriorElementBoundaries_global,
self.nElementBoundaryQuadraturePoints_elementBoundary, self.nSpace_global), 'd')
self.ebqe[('grad(u)', 2)] = numpy.zeros((self.mesh.nExteriorElementBoundaries_global,
self.nElementBoundaryQuadraturePoints_elementBoundary, self.nSpace_global), 'd')
self.ebqe[('grad(u)', 3)] = numpy.zeros((self.mesh.nExteriorElementBoundaries_global,
self.nElementBoundaryQuadraturePoints_elementBoundary, self.nSpace_global), 'd')
# RANS 2eq Models end
self.points_elementBoundaryQuadrature = set()
self.scalars_elementBoundaryQuadrature = set([('u', ci) for ci in range(self.nc)])
self.vectors_elementBoundaryQuadrature = set()
self.tensors_elementBoundaryQuadrature = set()
# use post processing tools to get conservative fluxes, None by default
if self.postProcessing:
self.q[('v', 0)] = numpy.zeros(
(self.mesh.nElements_global,
self.nQuadraturePoints_element,
self.nDOF_trial_element[0]),
'd')
self.q['J'] = numpy.zeros(
(self.mesh.nElements_global,
self.nQuadraturePoints_element,
self.nSpace_global,
self.nSpace_global),
'd')
self.q['det(J)'] = numpy.zeros(
(self.mesh.nElements_global,
self.nQuadraturePoints_element),
'd')
self.q['inverse(J)'] = numpy.zeros(
(self.mesh.nElements_global,
self.nQuadraturePoints_element,
self.nSpace_global,
self.nSpace_global),
'd')
self.ebq[('v', 0)] = numpy.zeros(
(self.mesh.nElements_global,
self.mesh.nElementBoundaries_element,
self.nElementBoundaryQuadraturePoints_elementBoundary,
self.nDOF_trial_element[0]),
'd')
self.ebq[('w', 0)] = numpy.zeros(
(self.mesh.nElements_global,
self.mesh.nElementBoundaries_element,
self.nElementBoundaryQuadraturePoints_elementBoundary,
self.nDOF_trial_element[0]),
'd')
self.ebq['x'] = numpy.zeros(
(self.mesh.nElements_global,
self.mesh.nElementBoundaries_element,
self.nElementBoundaryQuadraturePoints_elementBoundary,
3),
'd')
self.ebq['hat(x)'] = numpy.zeros(
(self.mesh.nElements_global,
self.mesh.nElementBoundaries_element,
self.nElementBoundaryQuadraturePoints_elementBoundary,
3),
'd')
self.ebq['inverse(J)'] = numpy.zeros(
(self.mesh.nElements_global,
self.mesh.nElementBoundaries_element,
self.nElementBoundaryQuadraturePoints_elementBoundary,
self.nSpace_global,
self.nSpace_global),
'd')
self.ebq['g'] = numpy.zeros(
(self.mesh.nElements_global,
self.mesh.nElementBoundaries_element,
self.nElementBoundaryQuadraturePoints_elementBoundary,
self.nSpace_global - 1,
self.nSpace_global - 1),
'd')
self.ebq['sqrt(det(g))'] = numpy.zeros(
(self.mesh.nElements_global,
self.mesh.nElementBoundaries_element,
self.nElementBoundaryQuadraturePoints_elementBoundary),
'd')
self.ebq['n'] = numpy.zeros(
(self.mesh.nElements_global,
self.mesh.nElementBoundaries_element,
self.nElementBoundaryQuadraturePoints_elementBoundary,
self.nSpace_global),
'd')
self.ebq[('dS_u', 0)] = numpy.zeros(
(self.mesh.nElements_global,
self.mesh.nElementBoundaries_element,
self.nElementBoundaryQuadraturePoints_elementBoundary),
'd')
self.ebqe['dS'] = numpy.zeros(
(self.mesh.nExteriorElementBoundaries_global,
self.nElementBoundaryQuadraturePoints_elementBoundary),
'd')
self.ebqe[('dS_u', 0)] = self.ebqe['dS']
self.ebqe['n'] = numpy.zeros(
(self.mesh.nExteriorElementBoundaries_global,
self.nElementBoundaryQuadraturePoints_elementBoundary,
self.nSpace_global),
'd')
self.ebqe['inverse(J)'] = numpy.zeros(
(self.mesh.nExteriorElementBoundaries_global,
self.nElementBoundaryQuadraturePoints_elementBoundary,
self.nSpace_global,
self.nSpace_global),
'd')
self.ebqe['g'] = numpy.zeros(
(self.mesh.nExteriorElementBoundaries_global,
self.nElementBoundaryQuadraturePoints_elementBoundary,
self.nSpace_global - 1,
self.nSpace_global - 1),
'd')
self.ebqe['sqrt(det(g))'] = numpy.zeros(
(self.mesh.nExteriorElementBoundaries_global,
self.nElementBoundaryQuadraturePoints_elementBoundary),
'd')
self.ebq_global['n'] = numpy.zeros(
(self.mesh.nElementBoundaries_global,
self.nElementBoundaryQuadraturePoints_elementBoundary,
self.nSpace_global),
'd')
self.ebq_global['x'] = numpy.zeros(
(self.mesh.nElementBoundaries_global,
self.nElementBoundaryQuadraturePoints_elementBoundary,
3),
'd')
#
# show quadrature
#
logEvent("Dumping quadrature shapes for model %s" % self.name, level=9)
logEvent("Element quadrature array (q)", level=9)
for (k, v) in list(self.q.items()):
logEvent(str((k, v.shape)), level=9)
logEvent("Element boundary quadrature (ebq)", level=9)
for (k, v) in list(self.ebq.items()):
logEvent(str((k, v.shape)), level=9)
logEvent("Global element boundary quadrature (ebq_global)", level=9)
for (k, v) in list(self.ebq_global.items()):
logEvent(str((k, v.shape)), level=9)
logEvent("Exterior element boundary quadrature (ebqe)", level=9)
for (k, v) in list(self.ebqe.items()):
logEvent(str((k, v.shape)), level=9)
logEvent("Interpolation points for nonlinear diffusion potential (phi_ip)", level=9)
for (k, v) in list(self.phi_ip.items()):
logEvent(str((k, v.shape)), level=9)
#
# allocate residual and Jacobian storage
#
#
# allocate residual and Jacobian storage
#
self.elementResidual = [numpy.zeros(
(self.mesh.nElements_global,
self.nDOF_test_element[ci]),
'd')]
self.inflowBoundaryBC = {}
self.inflowBoundaryBC_values = {}
self.inflowFlux = {}
for cj in range(self.nc):
self.inflowBoundaryBC[cj] = numpy.zeros((self.mesh.nExteriorElementBoundaries_global,), 'i')
self.inflowBoundaryBC_values[cj] = numpy.zeros((self.mesh.nExteriorElementBoundaries_global, self.nDOF_trial_element[cj]), 'd')
self.inflowFlux[cj] = numpy.zeros((self.mesh.nExteriorElementBoundaries_global, self.nElementBoundaryQuadraturePoints_elementBoundary), 'd')
self.internalNodes = set(range(self.mesh.nNodes_global))
# identify the internal nodes this is ought to be in mesh
# \todo move this to mesh
for ebNE in range(self.mesh.nExteriorElementBoundaries_global):
ebN = self.mesh.exteriorElementBoundariesArray[ebNE]
eN_global = self.mesh.elementBoundaryElementsArray[ebN, 0]
ebN_element = self.mesh.elementBoundaryLocalElementBoundariesArray[ebN, 0]
for i in range(self.mesh.nNodes_element):
if i != ebN_element:
I = self.mesh.elementNodesArray[eN_global, i]
self.internalNodes -= set([I])
self.nNodes_internal = len(self.internalNodes)
self.internalNodesArray = numpy.zeros((self.nNodes_internal,), 'i')
for nI, n in enumerate(self.internalNodes):
self.internalNodesArray[nI] = n
#
del self.internalNodes
self.internalNodes = None
logEvent("Updating local to global mappings", 2)
self.updateLocal2Global()
logEvent("Building time integration object", 2)
logEvent(memory("inflowBC, internalNodes,updateLocal2Global", "OneLevelTransport"), level=4)
# mwf for interpolating subgrid error for gradients etc
if self.stabilization and self.stabilization.usesGradientStabilization:
self.timeIntegration = TimeIntegrationClass(self, integrateInterpolationPoints=True)
else:
self.timeIntegration = TimeIntegrationClass(self)
if options is not None:
self.timeIntegration.setFromOptions(options)
logEvent(memory("TimeIntegration", "OneLevelTransport"), level=4)
logEvent("Calculating numerical quadrature formulas", 2)
self.calculateQuadrature()
self.setupFieldStrides()
comm = Comm.get()
self.comm = comm
if comm.size() > 1:
assert numericalFluxType is not None and numericalFluxType.useWeakDirichletConditions, "You must use a numerical flux to apply weak boundary conditions for parallel runs"
logEvent("initalizing numerical flux")
logEvent(memory("stride+offset", "OneLevelTransport"), level=4)
if numericalFluxType is not None:
if options is None or options.periodicDirichletConditions is None:
self.numericalFlux = numericalFluxType(self,
dofBoundaryConditionsSetterDict,
advectiveFluxBoundaryConditionsSetterDict,
diffusiveFluxBoundaryConditionsSetterDictDict)
else:
self.numericalFlux = numericalFluxType(self,
dofBoundaryConditionsSetterDict,
advectiveFluxBoundaryConditionsSetterDict,
diffusiveFluxBoundaryConditionsSetterDictDict,
options.periodicDirichletConditions)
else:
self.numericalFlux = None
# set penalty terms
logEvent("initializing numerical flux penalty")
self.numericalFlux.penalty_constant = self.coefficients.eb_penalty_constant
# cek todo move into numerical flux initialization
if 'penalty' in self.ebq_global:
for ebN in range(self.mesh.nElementBoundaries_global):
for k in range(self.nElementBoundaryQuadraturePoints_elementBoundary):
self.ebq_global['penalty'][ebN, k] = old_div(self.numericalFlux.penalty_constant, \
(self.mesh.elementBoundaryDiametersArray[ebN]**self.numericalFlux.penalty_power))
# penalty term
# cek move to Numerical flux initialization
if 'penalty' in self.ebqe:
for ebNE in range(self.mesh.nExteriorElementBoundaries_global):
ebN = self.mesh.exteriorElementBoundariesArray[ebNE]
for k in range(self.nElementBoundaryQuadraturePoints_elementBoundary):
self.ebqe['penalty'][ebNE, k] = old_div(self.numericalFlux.penalty_constant, \
self.mesh.elementBoundaryDiametersArray[ebN]**self.numericalFlux.penalty_power)
logEvent(memory("numericalFlux", "OneLevelTransport"), level=4)
self.elementEffectiveDiametersArray = self.mesh.elementInnerDiametersArray
logEvent("setting up post-processing")
from proteus import PostProcessingTools
self.velocityPostProcessor = PostProcessingTools.VelocityPostProcessingChooser(self)
logEvent(memory("velocity postprocessor", "OneLevelTransport"), level=4)
# helper for writing out data storage
logEvent("initializing archiver")
from proteus import Archiver
self.elementQuadratureDictionaryWriter = Archiver.XdmfWriter()
self.elementBoundaryQuadratureDictionaryWriter = Archiver.XdmfWriter()
self.exteriorElementBoundaryQuadratureDictionaryWriter = Archiver.XdmfWriter()
logEvent("flux bc objects")
for ci, fbcObject in list(self.fluxBoundaryConditionsObjectsDict.items()):
self.ebqe[('advectiveFlux_bc_flag', ci)] = numpy.zeros(self.ebqe[('advectiveFlux_bc', ci)].shape, 'i')
for t, g in list(fbcObject.advectiveFluxBoundaryConditionsDict.items()):
if ci in self.coefficients.advection:
self.ebqe[('advectiveFlux_bc', ci)][t[0], t[1]] = g(self.ebqe[('x')][t[0], t[1]], self.timeIntegration.t)
self.ebqe[('advectiveFlux_bc_flag', ci)][t[0], t[1]] = 1
for ck, diffusiveFluxBoundaryConditionsDict in list(fbcObject.diffusiveFluxBoundaryConditionsDictDict.items()):
self.ebqe[('diffusiveFlux_bc_flag', ck, ci)] = numpy.zeros(self.ebqe[('diffusiveFlux_bc', ck, ci)].shape, 'i')
for t, g in list(diffusiveFluxBoundaryConditionsDict.items()):
self.ebqe[('diffusiveFlux_bc', ck, ci)][t[0], t[1]] = g(self.ebqe[('x')][t[0], t[1]], self.timeIntegration.t)
self.ebqe[('diffusiveFlux_bc_flag', ck, ci)][t[0], t[1]] = 1
self.numericalFlux.setDirichletValues(self.ebqe)
if self.movingDomain:
self.MOVING_DOMAIN = 1.0
else:
self.MOVING_DOMAIN = 0.0
if self.mesh.nodeVelocityArray is None:
self.mesh.nodeVelocityArray = numpy.zeros(self.mesh.nodeArray.shape, 'd')
# cek/ido todo replace python loops in modules with optimized code if possible/necessary
logEvent("dirichlet conditions")
self.forceStrongConditions = coefficients.forceStrongDirichlet