Repository navigation
Expand file tree
/
Copy pathSandDunesConfig.lua
More file actions
executable file
·2735 lines (2176 loc) · 86.2 KB
/
Copy pathSandDunesConfig.lua
File metadata and controls
executable file
·2735 lines (2176 loc) · 86.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
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
--------------------------------------------------------------------------------
-- Initial Parameters
--------------------------------------------------------------------------------
local myProblem = {}
myProblem.Init = function(self, o)
-- Numerical parameters of the discretization
self.problem = o.problem
self.simCase = o.simCase
self.simCaseBnd = o.simCaseBnd
self.dim = o.dim
self.dir_name = o.dir_name
self.file_name = o.file_name
self.folder_name = o.folder_name
self.elem_type = o.elem_type
self.numRefs = o.numRefs
self.numPreRefs = o.numPreRefs
self.algebraBlockSize = o.algebraBlockSize
self.timeMethod = o.timeMethod
self.DT = o.DT
self.DTmax = o.DTmax
self.DTmin = o.DTmin
self.DTLimex = o.DTLimex
self.numTimeSteps = o.numTimeSteps
self.startTime = o.startTime
self.endTime = o.endTime
self.modifyDT = o.modifyDT
--Output Data
self.boolData = o.boolData
self.data_name = o.data_name
self.outputFactor = o.outputFactor
self.writeIntegral = o.writeIntegral
self.boolLoadCheckPoint = o.boolLoadCheckPoint
self.boolSaveCheckPoint = o.boolSaveCheckPoint
self.incr_factor = o.incr_factor
self.red_factor_fail = o.red_factor_fail
self.red_factor_success = o.red_factor_success
self.optimal_newton_steps = o.optimal_newton_steps
self.maxConvRate = o.maxConvRate
self.minConvRate = o.minConvRate
self.NewtonDebug = o.NewtonDebug
self.NewtonSteadyDebug = o.NewtonSteadyDebug
self.NewtonUpdaterSteady = o.NewtonUpdaterSteady
self.NewtonUpdater = o.NewtonUpdater
self.StepDebug = o.StepDebug
self.debug_dir = o.debug_dir
self.tol = o.tol
self.nstages = o.nstages
self.limex_partial_mask = o.limex_partial_mask
self.limex_debug_level = o.limex_debug_level
self.VelErrorNorm = o.VelErrorNorm
self.PressErrorNorm = o.PressErrorNorm
self.VolErrorNorm = o.VolErrorNorm
self.alphaVel = o.alphaVel
self.alphaPress = o.alphaPress
self.alphaVol = o.alphaVol
self.max_newton_steps_steady_state = o.max_newton_steps_steady_state
self.max_newton_steps_transient = o.max_newton_steps_transient
self.SteadyAbsDefect = o.SteadyAbsDefect
self.SteadyRedDefect = o.SteadyRedDefect
self.AbsDefect = o.AbsDefect
self.RedDefect = o.RedDefect
self.baseSolverLim = o.baseSolverLim
self.baseSolverImp = o.baseSolverImp
self.LinAbsDefectImp = o.LinAbsDefectImp
self.LinRedDefectImp = o.LinRedDefectImp
self.LinAbsDefectLim = o.LinAbsDefectLim
self.LinRedDefectLim = o.LinRedDefectLim
self.max_linear_steps_Lim = o.max_linear_steps_Lim
self.max_linear_steps_Imp = o.max_linear_steps_Imp
self.rap = o.rap
self.rim = o.rim
self.damping_gmg = o.damping_gmg
self.damping_ilu = o.damping_ilu
self.value_beta = o.value_beta
self.linear_solver_Lim = o.linear_solver_Lim
self.precondLim = o.precondLim
self.smootherLim = o.smootherLim
self.orderingLim = o.orderingLim
self.pre_smoothLim = o.pre_smoothLim
self.post_smoothLim = o.post_smoothLim
self.gmgBaseLevelLim = o.gmgBaseLevelLim
self.linear_solver_Imp = o.linear_solver_Imp
self.precondImp = o.precondImp
self.smootherImp = o.smootherImp
self.orderingImp = o.orderingImp
self.pre_smoothImp = o.pre_smoothImp
self.post_smoothImp = o.post_smoothImp
self.gmgBaseLevelImp = o.gmgBaseLevelImp
self.eps_ilut = o.eps_ilut
self.lambdamaxSteps = o.lambdamaxSteps
self.lambdaStart = o.lambdaStart
-- Physical phenomenon of simulation
self.doSteadyState = o.doSteadyState
self.steadyStateOnly = o.steadyStateOnly
self.boolSource = o.boolSource
self.consistentRho_in_source = o.consistentRho_in_source
self.boolRelativeVel = o.boolRelativeVel
self.boolGradientPsSource = o.boolGradientPsSource
self.boolViscPs = o.boolViscPs
self.boolAveDiff = o.boolAveDiff
self.boolSaltationFlux = o.boolSaltationFlux
self.boolSlipDiff = o.boolSlipDiff
self.boolSlipVel = o.boolSlipVel
self.boolpress_jump = o.boolpress_jump
self.boolAveNormal = o.boolAveNormal
self.boolFixVel = o.boolFixVel
self.boolFixVol = o.boolFixVol
self.boolMassTerm = o.boolMassTerm
self.boolDensityMean = o.boolDensityMean
self.inflow = o.inflow
self.SlipVelValue = o.SlipVelValue
self.H_0 = o.H_0
self.ReferencePressure = o.ReferencePressure
self.bStokes = o.bStokes or false
self.bNoLaplace = o.bNoLaplace or false
self.exactJac = o.exactJac or false
self.bPecletBlend = o.bPecletBlend or false
self.upwind_m = o.upwind_m or "full"
self.upwind_t = o.upwind_t or "full"
self.upwind_r = o.upwind_r or "full"
self.bPac = o.bPac
self.diffLength = o.diffLength
self.stab = o.stab
self.div_correction = o.div_correction
self.boolIPVelocity = o.boolIPVelocity
self.turbViscMethod = o.turbViscMethod
self.modellconstant = o.modellconstant
self.beta1 = o.beta1
self.kIn = o.kIn
self.omegaIn = o.omegaIn
self.dWall = o.dWall
self.omegaWall = o.omegaWall
--Material Properties
self.nu_a = o.nu_a
self.rho_a = o.rho_a
self.rho_s = o.rho_s
self.dp = o.dp
self.nu_s = o.nu_s
self.c_init = o.c_init
self.alpha_max = o.alpha_max
self.alpha_min = o.alpha_min
self.packing_factor = o.packing_factor
self.grad_limit = o.grad_limit
self.slope_limit = o.slope_limit
self.granular_model = o.granular_model
self.density_model = o.density_model
self.interface_value = o.interface_value
self.drag_mod = o.drag_mod
self.riemman = o.riemman
self.FR = o.FR
self.B_phi = o.B_phi
self.deltaGamma = o.deltaGamma
self.Visc_limit = o.Visc_limit
self.deltaPs = o.deltaPs
self.deltaI = o.deltaI
self.FricMu_1 = o.FricMu_1
self.FricMu_2 = o.FricMu_2
self.I_0 = o.I_0
self.gravity = o.gravity
self.roughness_length = o.roughness_length
self.boolSolverDesc = false
self.NewtonSolverDescSteady = {}
self.NewtonSolverDesc = {}
self.gridName = o.gridName
end
--------------------------------------------------------------------------------
-- DEFAULT Parameters
--------------------------------------------------------------------------------
myProblem.GetCaseDefaults = function(self, problem)
if problem == "flow" then
return {
Name = "Dune",
numRefs = 6,
numPreRefs = 3,
alphaVel = 1.0,
alphaPress = 1e-11,
boolSaltationFlux = false,
boolAveDiff = false,
boolSlipDiff = false,
boolSlipVel = false,
boolFixVel = false,
rap = true,
rim = false,
value_beta = 0.0,
linear_solver_Imp = "bicgStab",
smootherImp = "ilu",
orderingImp = "none",
pre_smoothImp = 1,
post_smoothImp = 0,
baseSolverImp = "SuperLu",
LinAbsDefectImp = 1e-08,
LinRedDefectImp = 1e-3,
gmgBaseLevelImp = 5,
linear_solver_Lim = "gmres",
smootherLim = "ilu",
orderingLim = "none",
pre_smoothLim = 1,
post_smoothLim = 0,
baseSolverLim = "SuperLu",
LinAbsDefectLim = 1e-8,
LinRedDefectLim = 1e-7,
gmgBaseLevelLim = 5,
DTLimex=1000,
}
elseif problem == "avalanche" then
return {
Name = "Solution",
numRefs = 4,
numPreRefs = 3,
alphaVel = 1e-15,
alphaPress = 0.5e-15,
boolSaltationFlux = false,
boolAveDiff = false,
boolSlipDiff = false,
boolSlipVel = true,
boolFixVel = true,
rap = true,
rim = false,
value_beta = 0.0,
linear_solver_Imp = "bicgStab",
smootherImp = "ilu",
orderingImp = "none",
pre_smoothImp = 1,
post_smoothImp = 2,
baseSolverImp = "SuperLu",
LinAbsDefectImp = 1e-08,
LinRedDefectImp = 1e-5,
gmgBaseLevelImp = 5,
linear_solver_Lim = "bicgStab",
smootherLim = "ilu",
orderingLim = "none",
pre_smoothLim = 1,
post_smoothLim = 2,
baseSolverLim = "SuperLu",
LinAbsDefectLim = 1e-12,
LinRedDefectLim = 1e-12,
gmgBaseLevelLim = 5,
DTLimex=1e-03,
}
end
error("Unknown problem: " .. tostring(problem))
end
--------------------------------------------------------------------------------
-- GEOMETRY
--------------------------------------------------------------------------------
myProblem.GetGeometry = function(self, params)
if params.dim ~= 2 and params.dim ~= 3 then error("Only dimensions 2 and 3 are supported") end
if params.elem_type ~= "tri" and params.elem_type ~= "quad" then error("Unknown element type: " .. tostring(params.elem_type)) end
local geometry = {}
if params.problem == "flow" then
geometry.gridName = "Dune" .. params.dim .. "D_" .. params.elem_type .. "_double.ugx"
geometry.innerSubsets = {"Inner", "Inner2"}
geometry.allSubsets = "Inner,Inner2,Left,Right,Top,Bottom"
geometry.boundaries = "Left,Right,Top,Bottom"
if params.dim == 3 then
geometry.allSubsets = geometry.allSubsets .. ",Back,Front"
end
elseif params.problem == "avalanche" then
geometry.gridName = "Avalanche" .. params.dim .. "D_" .. params.elem_type .. ".ugx"
geometry.innerSubsets = {"Inner"}
if params.dim == 2 then
geometry.allSubsets = "Inner,Left,Right,Top,Bottom"
geometry.boundaries = "Left,Right,Top,Bottom"
else
geometry.allSubsets = "Inner,Left1,Left2,Right,Top,Bottom,Front1,Front2,Back1,Back2,Back3"
geometry.boundaries = "Left1,Left2,Right,Top,Bottom,Front1,Front2,Back1,Back2,Back3"
end
else
error("Unknown problem: " .. tostring(params.problem))
end
self.geometry = geometry
return geometry
end
--------------------------------------------------------------------------------
-- File Names
--------------------------------------------------------------------------------
myProblem.FileNames = function (self,rank,SpaceSize)
local riemman_name = nil
if self.riemman == 0 then
riemman_name = "Godunov"
elseif self.riemman == 1 then
riemman_name = "Rusanov"
elseif self.riemman == 2 then
riemman_name = "Roe"
elseif self.riemman == 3 then
riemman_name = "Engquist-Osher"
else
print ("Numerical Flux Scheme for NonLinear Scalar conservation Law not defined"); exit();
end
local folder_name = nil
if self.dir_name == "" then
folder_name = self.folder_name
else
folder_name = self.dir_name .. "/" .. self.folder_name
end
---------------------
-- FolderName
---------------------
folder_name = folder_name .. "_" .. self.dim.. "D"
folder_name = folder_name .. "-" .. self.timeMethod
if self.turbViscMethod ~= "no" and not(self.bStokes) then
folder_name = folder_name .. "-" .. self.turbViscMethod
end
if self.bStokes then
folder_name = folder_name .. "-Stokes"
end
folder_name = folder_name .. "-" ..riemman_name
if self.boolSaltationFlux then
folder_name =folder_name .. "-SaltFlux"
else
folder_name =folder_name .. "-NoSaltFlux"
end
if self.boolRelativeVel then
folder_name =folder_name .. "-RelVel"
else
folder_name =folder_name .. "-NoRelVel"
end
if self.boolGradientPsSource or self.boolSource then
if self.boolSource then
if self.consistentRho_in_source then
folder_name =folder_name .. "-Consistent"
end
folder_name = folder_name .. "-MG_Force"
end
if self.boolGradientPsSource then
folder_name = folder_name .. "-DPs"
else
folder_name = folder_name .. "-DPh"
end
else
folder_name = folder_name .. "-NoForce"
end
if self.boolAveDiff then
folder_name = folder_name .. "-AveDiff"
else
folder_name = folder_name .. "-NoAveDiff"
end
if (self.boolSlipDiff and self.boolSlipVel) then print ("SlipVel and SlipDiff activated at the same time."); exit(); end
if self.boolSlipDiff then
folder_name = folder_name .. "-SlipDiff"
else if self.boolSlipVel then
folder_name = folder_name .. "-SlipVel"
else
folder_name = folder_name .. "-NoSlip"
end
end
if (rank==0) then
if not DirectoryExists (folder_name) then
CreateDirectory (folder_name)
end
print(folder_name)
end
---------------------
-- VTK folder
---------------------
local file_name = self.file_name
vtk_file_name = file_name .. "-" .. self.elem_type
vtk_file_name = vtk_file_name .. "-lev" .. self.numRefs
local fixedSpaceSize = string.format("%04d", SpaceSize)
vtk_file_name = vtk_file_name .. "_Parallel_" .. fixedSpaceSize
folder_vtk = folder_name .. "/" .. vtk_file_name
if (rank== 0) then
if not DirectoryExists (folder_vtk) then
CreateDirectory (folder_vtk)
else
if(self.NewtonDebug or self.NewtonSteadyDebug) then
local cmd = "rm -rf " .. folder_vtk
os.execute(cmd)
print(" Directory reseted")
CreateDirectory (folder_vtk)
end
end
end
vtk_file_name = folder_vtk .. "/" .. self.file_name -- VTK output file name base
self.debug_dir = folder_vtk
self.riemman_name = riemman_name
print("Files Setting DONE")
print("File Adress: ".. vtk_file_name)
-- vtk_file_name: Name of the vtk files
-- folder_vtk: Directory where vtk files are saved
-- folder_name: Directory where the different simulations are saved, e.g. folder2dLimex, folder3dEuler
return vtk_file_name,folder_vtk,folder_name
end
--------------------------------------------------------------------------------
-- LOG Files
--------------------------------------------------------------------------------
myProblem.LogFiles = function (self,rank_t,Name)
local counter = 0
local filename = Name .. "_" .. counter
while io.open(filename, "r") do
counter = counter + 1
filename = Name .. "_" .. counter
end
GetLogAssistant():enable_file_output(true, filename)
if rank_t > 0 then
GetLogAssistant():enable_terminal_output(false)
end
end
--------------------------------------------------------------------------------
-- Printing Simulation Settings
--------------------------------------------------------------------------------
myProblem.PrintingSettings = function (self)
-----------------------------------------------------------------------
print (" Sand Dune Dynamics " .. os.date("%A, %B %d, %Y at %I:%M %p"))
print (" Geometry: " .. self.gridName ..", dim = " .. self.dim)
print("Algebra Block Size = " .. tostring(self.algebraBlockSize))
print (" Physical parameter:")
print (" Table case = " .. self.simCase + 1)
print (" inflow = " .. self.inflow)
print (" SlipVel = " .. self.SlipVelValue)
print (" Stokes = " .. tostring (self.bStokes))
print (" Steady state = " .. tostring (self.doSteadyState))
print (" BodyForce = " .. tostring (self.boolSource))
print (" Consisten Gravity = " .. tostring (self.consistentRho_in_source))
print (" Saltation FLux = " .. tostring (self.boolSaltationFlux))
print (" Relative Vel = " .. tostring (self.boolRelativeVel))
print (" Ps gradient = " .. tostring (self.boolGradientPsSource))
print (" Ps in visc = " .. tostring (self.boolViscPs))
print (" Diffusion = " .. tostring (self.boolAveDiff))
print (" SlipDiff = " .. tostring (self.boolSlipDiff))
print (" SlipVel = " .. tostring (self.boolSlipVel))
print (" MassMean = " .. tostring (self.boolDensityMean))
-----------------------------------------------------------------------
print (" Numerical parameter:")
print (" elem_type = " .. self.elem_type)
print (" numRefs = " .. self.numRefs)
print (" numPreRefs = " .. self.numPreRefs)
print (" timeMethod = " .. self.timeMethod)
print (" DT = " .. self.DT)
print (" numTimeSteps = " .. self.numTimeSteps)
print (" noLaplace = " .. tostring (self.bNoLaplace))
print (" exactJac = " .. tostring (self.exactJac))
print (" PecletBlend = " .. tostring (self.bPecletBlend))
print (" upwind_m = " .. self.upwind_m)
print (" upwind_t = " .. self.upwind_t)
print (" Num Flux Scheme = " .. self.riemman_name)
print (" pac = " .. tostring (self.bPac))
print (" stab = " .. self.stab)
print (" difflength = " .. self.diffLength)
print (" Turbulence = " .. self.turbViscMethod)
-----------------------------------------------------------------------
print (" Linear Solver parameters:")
print (" damping_gmg = " .. self.damping_gmg)
print (" damping_ilu = " .. self.damping_ilu)
print (" RAP = " .. tostring (self.rap))
print (" RIM = " .. tostring (self.rim))
print (" beta = " .. self.value_beta)
print (" AbsDefImp = " .. self.LinAbsDefectImp)
print (" RedDefImp = " .. self.LinRedDefectImp)
print (" AbsDefLim = " .. self.LinAbsDefectLim)
print (" RedDefLim = " .. self.LinRedDefectLim)
print (" MaxStepsLim = " .. tostring (self.max_linear_steps_Lim))
print (" MaxStepsImp = " .. tostring (self.max_linear_steps_Imp))
print (" PreconditionerLim = " .. tostring (self.precondLim))
print (" Smoother Lim = " .. tostring (self.smootherLim))
print (" Ordering Lim = " .. tostring (self.orderingLim))
print (" Pre Smooth Lim = " .. tostring (self.pre_smoothLim))
print (" Post Smooth Lim = " .. tostring (self.post_smoothLim))
print (" PreconditionerImp = " .. tostring (self.precondImp))
print (" Smoother Imp = " .. tostring (self.smootherImp))
print (" Ordering Imp = " .. tostring (self.orderingImp))
print (" Pre Smooth Imp = " .. tostring (self.pre_smoothImp))
print (" Post Smooth Imp = " .. tostring (self.post_smoothImp))
print (" Eps ILUT = " .. self.eps_ilut)
-----------------------------------------------------------------------
if self.timeMethod == "limex" then
print (" Limex Numerical parameter:")
print (" Vel norm = " .. self.VelErrorNorm)
print (" Press norm = " .. self.PressErrorNorm)
print (" Vol norm = " .. self.VolErrorNorm)
print (" Vel norm scale = " .. self.alphaVel)
print (" Press norm scale = " .. self.alphaPress)
print (" Vol norm scale = " .. self.alphaVol)
end
end
--------------------------------------------------------------------------------
-- Approximation Space
--------------------------------------------------------------------------------
myProblem.ApproximationSpace = function (self)
local allSubsets = self.geometry.allSubsets
print("Approximation Space Setting")
local fct_cmp_tbl = nil
local nv_cmp_tbl = nil
local vel_cmp_tbl = nil
if self.turbViscMethod == "komegaSST" then
if self.dim == 3 then
fct_cmp_tbl = {"u", "v", "w", "p", "c", "k", "omega"}
nv_cmp_tbl = {"u", "v", "w", "p", "c"}
vel_cmp_tbl = {"u", "v", "w"}
else
fct_cmp_tbl = {"u", "v", "p", "c", "k", "omega"}
nv_cmp_tbl = {"u", "v", "p", "c"}
vel_cmp_tbl = {"u", "v"}
end
else
if self.dim == 3 then
fct_cmp_tbl = {"u", "v", "w", "p", "c"}
nv_cmp_tbl = fct_cmp_tbl
vel_cmp_tbl = {"u", "v", "w"}
else
fct_cmp_tbl = {"u", "v", "p", "c"}
nv_cmp_tbl = fct_cmp_tbl
vel_cmp_tbl = {"u", "v"}
end
end
-- Create the domain, load the grid and refine it
local dom = util.CreateDomain (self.gridName, self.numPreRefs)
balancer.RefineAndRebalanceDomain (dom, self.numRefs - self.numPreRefs)
--util.refinement.CreateRegularHierarchy(dom, self.numRefs, true)
print ("Domain-info:")
print (dom:domain_info():to_string())
-- Create the vertex-centered approximation space
local approxSpace = ApproximationSpace (dom)
approxSpace:add_fct("u", "Lagrange",1,allSubsets)
approxSpace:add_fct("v", "Lagrange",1,allSubsets)
if self.dim == 3 then
approxSpace:add_fct("w", "Lagrange",1,allSubsets)
end
approxSpace:add_fct("p", "Lagrange",1,allSubsets)
approxSpace:add_fct("c", "Lagrange",1,allSubsets)
if self.turbViscMethod == "komegaSST" then
approxSpace:add_fct("k", "Lagrange",1,allSubsets)
approxSpace:add_fct("omega", "Lagrange",1,allSubsets)
end
approxSpace:init_levels()
approxSpace:init_top_surface()
approxSpace:print_statistic()
OrderLex (approxSpace, "x")
--OrderCuthillMcKee(approxSpace,true)
util.solver.defaults.approxSpace = approxSpace
-- grid function for the solution
local u = GridFunction (approxSpace)
u:set(0)
self.fct_cmp_tbl = fct_cmp_tbl
self.nv_cmp_tbl = nv_cmp_tbl
self.vel_cmp_tbl = vel_cmp_tbl
self.u = u
self.approxSpace = approxSpace
print("Approximation Space DONE")
return approxSpace,u
end
--------------------------------------------------------------------------------
-- Interface Parameters List
--------------------------------------------------------------------------------
myProblem.InterfaceParameters = function (self)
local InterfaceValues = Interface()
InterfaceValues:set_particle_diameter(self.dp)
InterfaceValues:set_particle_density(self.rho_s)
InterfaceValues:set_air_density(self.rho_a)
InterfaceValues:set_fluid_Visc(self.nu_a*self.rho_a)
InterfaceValues:set_particle_kinVisc(self.nu_s)
InterfaceValues:set_alpha_max(self.alpha_max)
InterfaceValues:set_alpha_min(self.alpha_min)
InterfaceValues:set_packing_factor(self.packing_factor)
InterfaceValues:set_FrictionMu_1(self.FricMu_1)
InterfaceValues:set_FrictionMu_2(self.FricMu_2)
InterfaceValues:set_I_0(self.I_0)
InterfaceValues:set_deltaI(self.deltaI)
InterfaceValues:set_deltaPs(self.deltaPs)
InterfaceValues:set_FR(self.FR)
InterfaceValues:set_B_phi(self.B_phi)
InterfaceValues:set_deltaGamma(self.deltaGamma)
InterfaceValues:set_limit(self.Visc_limit)
InterfaceValues:set_bool_particle_pressure_force(self.boolGradientPsSource)
InterfaceValues:set_bool_consistent_gravity(false)
InterfaceValues:set_reference_pressure(self.ReferencePressure)
InterfaceValues:set_time_step_factor(self.DT)
InterfaceValues:set_interface_volume_fraction(self.interface_value)
InterfaceValues:set_drag_model(self.drag_mod)
InterfaceValues:set_relative_vel_error(1)
InterfaceValues:set_bool_initialized(true)
self.InterfaceValues = InterfaceValues
print("Interfce Parameters list: DONE")
return InterfaceValues
end
--------------------------------------------------------------------------------
-- LUA Functions
--------------------------------------------------------------------------------
myProblem.RegisterCallbacks = function(self)
if self.problem == "avalanche" then
if self.simCaseBnd ~= 1 and self.simCaseBnd ~= 2 then error("Unknown avalanche boundary case") end
if self.dim == 3 and self.simCaseBnd == 2 then error("The supplied Avalanche.lua has no initial concentration function for 3D case 2") end
end
local function inletSpeed(height)
local hh=20.0
if self.problem == "avalanche" then return 0.0 end
if height <= 0.0 then return 0.0 end
--return self.inflow
return self.inflow * math.log(1 + height / self.roughness_length) / math.log(1 + hh / self.roughness_length)
--return self.inflow* (2*hh - height) * (height ) / (hh * hh)
end
local function InflowVel2d(x, y, t) return inletSpeed(y), 0.0 end
local function InflowVel3d(x, y, z, t) return inletSpeed(z), 0.0, 0.0 end
local function initialC2d(x, y)
local sigma = 5
if self.problem == "flow" then
local dx = math.abs((x - 20.0) / sigma)
local height = self.H_0 * math.exp(-0.5*(dx^4)) - 0.01
if y > height then return 0.0 end
return self.c_init
end
if (x > 0.2 and x < 0.4) or x > 0.8 then return 1.5e-3 end
return 0.0
end
local function initialC3d(x, y, z)
local sigma = 5
if self.problem == "avalanche" then return 0.0 end
local dx = math.abs((x - 20.0) / sigma)^2
local dy = math.abs(y / sigma)^2
local height = self.H_0 * math.exp(-0.5*(dx + dy)^2) - 0.01
if z > height then return 0.0 end
return self.c_init
end
local function topFlux2d(x, y)
if self.simCaseBnd == 1 then
if x > 0.3 and x < 2.0 then return -1e-5 end
else
if (x > 0.2 and x < 0.4) or x > 0.8 then return -1e-5 end
end
return 0.0
end
local function topFlux3d(x, y, z)
if x > -1.0 and x < 2.0 then return -1e-5 end
return 0.0
end
local turbulenceIntensity = 0.05
local turbulenceLength = 0.05
local Cmu = 0.09
local function InletK2d(x, y, t)
local ux, uy = InflowVel2d(x, y, t)
local U = math.sqrt(ux * ux + uy * uy)
return 1.5 * (turbulenceIntensity * U)^2
end
local function InletK3d(x, y, z, t)
local ux, uy, uz = InflowVel3d(x, y, z, t)
local U = math.sqrt(ux * ux + uy * uy + uz * uz)
return 1.5 * (turbulenceIntensity * U)^2
end
local function InletOmega2d(x, y, t)
local k = InletK2d(x, y, t)
return math.sqrt(k) / (Cmu^0.25 * turbulenceLength)
end
local function InletOmega3d(x, y, z, t)
local k = InletK3d(x, y, z, t)
return math.sqrt(k) / (Cmu^0.25 * turbulenceLength)
end
local function WallDistance2d(x, y, t)
local lowerWallY = 0.0
local dLower = y - lowerWallY
return math.max( dLower, 0.0)
end
local function WallDistance3d(x, y, z, t)
local lowerWallZ = 0.0
local dLower = z - lowerWallZ
return math.max( dLower, 0.0)
end
if self.dim == 2 then
_G.SandInflow = InflowVel2d
_G.SandInitialC = initialC2d
_G.SandInitialK = InletK2d
_G.SandInitialOmega = InletOmega2d
_G.SandTopFlux = topFlux2d
_G.InletK = InletK2d
_G.InletOmega = InletOmega2d
_G.WallDistance = WallDistance2d
else
_G.SandInflow = InflowVel3d
_G.SandInitialC = initialC3d
_G.SandInitialK = InletK3d
_G.SandInitialOmega = InletOmega3d
_G.SandTopFlux = topFlux3d
_G.InletK = InletK3d
_G.InletOmega = InletOmega3d
_G.WallDistance = WallDistance3d
end
end
--------------------------------------------------------------------------------
-- Variables
--------------------------------------------------------------------------------
myProblem.Clousures = function (self,u,Inner_total)
local InterfaceValues = self.InterfaceValues
-------------------------------------------------------------- VelocityGradMag
--local gamma = ShearStressFV1(self.approxSpace,u)
--self.gamma = gamma
---------------------------------------------------------------------- Density
local Density = nil
if self.bStokes or self.boolSaltationFlux then
Density = ConstUserNumber(self.rho_a)
else
Density = GranularDensityLinker();
Density:set_model(self.density_model)
Density:set_phase_parameters(self.InterfaceValues)
end
self.Density = Density
---------------------------------------------------------------------- Viscosity
local Inverse_RHO = InverseLinker();
Inverse_RHO:divide(1.0,Density);
local AirDensity = ConstUserNumber(self.rho_a)
local Scale_RHO = ScaleLinker();
Scale_RHO:set_import_1(Inverse_RHO)
Scale_RHO:set_import_2(AirDensity)
local KinMixViscosity = ScaleLinker();
KinMixViscosity:set_import_1(Inverse_RHO)
local EfectiveKinViscosity = nil
local KinTurbulentViscosity = nil
local TurbulenceDisc = nil
if self.turbViscMethod=="no" then
KinTurbulentViscosity = 0.0
elseif self.turbViscMethod=="dyn" or self.turbViscMethod=="sma" then
if self.turbViscMethod == "dyn" then
KinTurbulentViscosity = FV1DynamicTurbViscData(self.approxSpace,u)
else
KinTurbulentViscosity = FV1SmagorinskyTurbViscData(self.approxSpace,u,self.modellconstant)
end
KinTurbulentViscosity:set_turbulence_zero_bnd(self.geometry.boundaries)
KinTurbulentViscosity:set_kinematic_viscosity(0.0)
elseif self.turbViscMethod=="komegaSST" then
TurbulenceDisc = RANSTurbulenceFV1({"k", "omega"}, Inner_total)
KinTurbulentViscosity = TurbulenceDisc:turbulent_kinematic_viscosity()
end
if self.turbViscMethod=="no" then
EfectiveKinViscosity = KinMixViscosity
else
EfectiveKinViscosity = ScaleAddLinkerNumber()
EfectiveKinViscosity:add(1.0,KinMixViscosity)
EfectiveKinViscosity:add(Scale_RHO,KinTurbulentViscosity)
end
local MixViscosity = ScaleLinker();
MixViscosity:set_import_1(Density)
MixViscosity:set_import_2(EfectiveKinViscosity)
local DiffusionViscosity = nil
if self.turbViscMethod=="no" then
DiffusionViscosity = ConstUserNumber(self.rho_a * self.nu_a)
else
DiffusionViscosity = ConstUserNumber(self.rho_a * self.nu_a)
end
local TurbulentViscosity = ScaleLinker();
TurbulentViscosity:set_import_1(AirDensity)
TurbulentViscosity:set_import_2(KinTurbulentViscosity)
self.TurbulenceDisc = TurbulenceDisc
self.TurbulentViscosity = TurbulentViscosity
self.KinTurbulentViscosity = KinTurbulentViscosity
self.MixViscosity = MixViscosity
self.KinMixViscosity = KinMixViscosity
self.EfectiveKinViscosity = EfectiveKinViscosity
---------------------------------------------------------------------- Normal
local ss_value = math.atan(self.FricMu_2)*180/3.1415926
local Normal = nil
if self.boolAveNormal then
Normal = DuneNormal(self.approxSpace,u)
Normal:set_theta(ss_value)
Normal:set_gradient_limit(self.grad_limit)
Normal:set_phase_parameters(InterfaceValues)
else
Normal = InterfaceNormalLinker()
end
self.Normal = Normal
---------------------------------------------------------------------- Sediment Velocity
local iter = 0
local Vs = InterfaceValues:RelVel_ext(0.0,self.rho_a,self.dp,self.rho_s,self.gravity)
local re = InterfaceValues:RE(self.nu_a*self.rho_a,self.rho_a,self.dp,Vs)
local Cd = InterfaceValues:CD(re,self.drag_mod)
--RelVel = ScaleAddLinkerVector()
--RelVel:add(-Vs, self.Normal)
local RelVel = RelativeVelocity(self.approxSpace,u)
RelVel:set_phase_parameters(InterfaceValues)
self.RelVel = RelVel
---------------------------------------------------------------------- Diffusion (Erotion)
local Diff_beta = 0.217
local d1= 250e-06
local A1= 1.673
local k0 = 1.0 + A1 * (1-self.dp/d1)
local Diff_factor = Diff_beta*k0*k0*Vs/(2*self.rho_a*(math.abs(self.gravity)))
local Diffusion = GranularDiffusionLinker();
Diffusion:set_mix_viscosity(DiffusionViscosity)
Diffusion:set_diff_factor(Diff_factor)
Diffusion:set_phase_parameters(InterfaceValues)
--local Dreg = ConstUserMatrix(0.2*Vs)
self.Diffusion = Diffusion
--self.Dreg = Dreg
---------------------------------------------------------------------- SaltationFlux
local SaltFlux = SaltationFluxLinker()
SaltFlux:set_phase_parameters(InterfaceValues)
SaltFlux:set_saltation_coefficient(5.5)
SaltFlux:set_threshold_friction_velocity(0.22)
SaltFlux:set_normal_epsilon(1e-8)
SaltFlux:set_delta_epsilon(1e-8)
SaltFlux:set_velocity_epsilon(1e-8)
SaltFlux:set_direction_mode(2)
SaltFlux:set_turbulent_kinematic_viscosity(self.KinTurbulentViscosity)
SaltFlux:set_normal(self.Normal)
self.SaltFlux = SaltFlux
---------------------------------------------------------------------- AvalancheFlux
local AvalancheFlux = AvalancheFluxLinker()
AvalancheFlux:set_phase_parameters(InterfaceValues)
AvalancheFlux:set_avalanche_coefficient(1.0)
AvalancheFlux:set_angle_of_repose_degrees(34.0)
AvalancheFlux:set_normal_epsilon(1.0e-8)
AvalancheFlux:set_delta_epsilon(1.0e-8)
AvalancheFlux:set_vertical_epsilon(1.0e-8)
self.AvalancheFlux = AvalancheFlux
---------------------------------------------------------------------- Vel-Diffusion (Avalanching)
local SlipDiff = nil
local SlipVel = nil
if self.boolSlipDiff then
SlipDiff = SlipDiffusion(self.approxSpace,u)
SlipDiff:set_theta(ss_value)
SlipDiff:set_diff(self.SlipVelValue)
SlipDiff:set_slope_limit(self.slope_limit)
SlipDiff:set_normal(Normal)
SlipDiff:set_phase_parameters(InterfaceValues)
if self.boolAveDiff then
SlipDiff:set_diffusion(Diffusion)
end
else if self.boolSlipVel then
SlipVel = SlipVelocity(self.approxSpace,u)
SlipVel:set_theta(ss_value)
SlipVel:set_vel(self.SlipVelValue)
SlipVel:set_slope_limit(self.slope_limit)
SlipVel:set_normal(Normal)
SlipVel:set_phase_parameters(InterfaceValues)
end