-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSandDunesConfig.lua
More file actions
executable file
·1428 lines (1114 loc) · 46.5 KB
/
Copy pathSandDunesConfig.lua
File metadata and controls
executable file
·1428 lines (1114 loc) · 46.5 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.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.simCase = o.simCase
self.startTime = o.startTime
self.endTime = o.endTime
self.numTimeSteps = o.numTimeSteps
self.DT = o.DT
self.DTmax = o.DTmax
self.DTmin = o.DTmin
self.DTLimex = o.DTLimex
self.outputFactor = o.outputFactor
self.boolCheckPoint = o.boolCheckPoint
self.timeMethod = o.timeMethod
self.modifyDT = o.modifyDT
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.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.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.damping_mg = o.damping_mg
self.value_beta = o.value_beta
self.lambdamaxSteps = o.lambdamaxSteps
self.lambdaStart = o.lambdaStart
-- Physical phenomenon of simulation
self.doSteadyState = o.doSteadyState
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.boolSlipDiff = o.boolSlipDiff
self.boolSlipVel = o.boolSlipVel
self.boolpress_jump = o.boolpress_jump
self.boolNormal = o.boolNormal
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.bExactJac = o.bExactJac 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.boolTransportJac = o.boolTransportJac
self.turbViscMethod = o.turbViscMethod
self.modellconstant = o.modellconstant
self.update_turb = o.update_turb
--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.boolSolverDesc = false
self.NewtonSolverDescSteady = {}
self.NewtonSolverDesc = {}
self.gridName = o.gridName
end
--------------------------------------------------------------------------------
-- File Names
--------------------------------------------------------------------------------
myProblem.FileNames = function (self,rank,SpaceSize)
riemman_name = nil
if self.riemman == 0 then
riemman_name = "Upwind"
elseif self.riemman == 1 then
riemman_name = "Godunov"
elseif self.riemman == 2 then
riemman_name = "Rusanov"
elseif self.riemman == 3 then
riemman_name = "Roe"
else
print ("Numerical Flux Scheme for NonLinear Scalar conservation Law not defined"); exit();
end
local file_name = self.file_name
if self.dir_name == "" then
folder_name = self.folder_name
else
folder_name = self.dir_name .. "/" .. self.folder_name
end
if(SpaceSize>1) then
folder_name = folder_name .. "Parallel" .. SpaceSize .."_"
else
folder_name = folder_name .. "Serial"
end
folder_name = folder_name .. self.dim.. "D"
if self.bStokes then
folder_name = folder_name .. "-Stokes"
end
folder_name = folder_name .. "_" .. self.timeMethod
if self.timeMethod == "limex" then
folder_name = folder_name .. "_" ..self.VelErrorNorm .. self.PressErrorNorm .. self.VolErrorNorm
end
---------------------
-- Folder and files
---------------------
if (rank==0) then
if not DirectoryExists (folder_name) then
CreateDirectory (folder_name)
end
print(folder_name)
end
vtk_file_name = file_name .. "-" .. self.elem_type
vtk_file_name = vtk_file_name .. "-lev" .. self.numRefs
print(vtk_file_name)
if self.bStokes then
vtk_file_name = vtk_file_name .. "-Stokes"
end
vtk_file_name = vtk_file_name .. "-" ..riemman_name
if self.boolRelativeVel then
vtk_file_name =vtk_file_name .. "-RelVel"
else
vtk_file_name =vtk_file_name .. "-NoRelVel"
end
if self.boolGradientPsSource or self.boolSource then
if self.boolSource then
if self.consistentRho_in_source then vtk_file_name =vtk_file_name .. "-Consistent" end
vtk_file_name = vtk_file_name .. "-MG_Force"
end
if self.boolGradientPsSource then
vtk_file_name = vtk_file_name .. "-DPs"
else
vtk_file_name = vtk_file_name .. "-DPh"
end
else
vtk_file_name = vtk_file_name .. "-NoForce"
end
if self.boolAveDiff then
vtk_file_name = vtk_file_name .. "-AveDiff"
else
vtk_file_name = vtk_file_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
vtk_file_name = vtk_file_name .. "-SlipDiff"
else if self.boolSlipVel then
vtk_file_name = vtk_file_name .. "-SlipVel"
else
vtk_file_name = vtk_file_name .. "-NoSlip"
end
end
folder = folder_name .. "/" .. vtk_file_name
if (rank== 0) then
if not DirectoryExists (folder) then
print("Hola hola2"..folder)
CreateDirectory (folder)
else
if(self.NewtonDebug or self.NewtonSteadyDebug) then
local cmd = "rm -rf " .. folder
os.execute(cmd)
print(" Directory reseted")
CreateDirectory (folder)
end
end
end
vtk_file_name = folder .. "/" .. vtk_file_name -- VTK output file name base
self.debug_dir = folder
self.riemman_name = riemman_name
print("Files Setting DONE")
print("File Adress: ".. vtk_file_name)
return vtk_file_name,folder,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 (" 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 (" 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.bExactJac))
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_mg = " .. self.damping_mg)
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))
-----------------------------------------------------------------------
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,allSubsets)
print("Approximation Space Setting")
local fct_cmp_tbl = nil
local vel_cmp_tbl = nil
if self.dim == 3 then
fct_cmp_tbl = {"u", "v", "w", "p", "c"}
vel_cmp_tbl = {"u", "v", "w"}
else
fct_cmp_tbl = {"u", "v", "p", "c"}
vel_cmp_tbl = {"u", "v"}
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)
approxSpace:init_levels()
approxSpace:init_top_surface()
approxSpace:print_statistic()
OrderLex (approxSpace, "y")
--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.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
--------------------------------------------------------------------------------
-- Variables
--------------------------------------------------------------------------------
myProblem.Clousures = function (self,approxSpace,u,walls)
local InterfaceValues = self.InterfaceValues
-------------------------------------------------------------- VelocityGradMag
local gamma = ShearStressFV1(approxSpace,u)
self.gamma = gamma
---------------------------------------------------------------------- Density
local Density = nil
if self.bStokes 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);
Scale_RHO = ScaleLinker();
Scale_RHO:set_import_1(Inverse_RHO)
Scale_RHO:set_import_2(self.rho_a)
local KinMixViscosity = nil
KinMixViscosity = ScaleLinker();
KinMixViscosity:set_import_1(Inverse_RHO)
if self.turbViscMethod=="dyn" then
KinTurbulentViscosity = FV1DynamicTurbViscData(approxSpace,u)
else
KinTurbulentViscosity = FV1SmagorinskyTurbViscData(approxSpace,u,self.modellconstant)
end
KinTurbulentViscosity:set_turbulence_zero_bnd(walls)
KinTurbulentViscosity:set_kinematic_viscosity(0.0)
local EfectiveKinViscosity = nil
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 = self.rho_a * self.nu_a
else
DiffusionViscosity = self.rho_a * self.nu_a
end
local TurbulentViscosity = ScaleLinker();
TurbulentViscosity:set_import_1(self.rho_a)
TurbulentViscosity:set_import_2(KinTurbulentViscosity)
self.TurbulentViscosity = TurbulentViscosity
self.KinTurbulentViscosity = KinTurbulentViscosity
self.MixViscosity = MixViscosity
self.KinMixViscosity = KinMixViscosity
self.EfectiveKinViscosity = EfectiveKinViscosity
---------------------------------------------------------------------- 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)
local RelVel = RelativeVelocity(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)
self.Diffusion = Diffusion
---------------------------------------------------------------------- Normal
local ss_value = math.atan(self.FricMu_2)*180/3.1415926
local Normal = DuneNormal(approxSpace,u)
Normal:set_theta(ss_value)
Normal:set_gradient_limit(self.grad_limit)
Normal:set_phase_parameters(InterfaceValues)
self.Normal = Normal
---------------------------------------------------------------------- Vel-Diffusion (Avalanching)
local SlipDiff = nil
local SlipVel = nil
if self.boolSlipDiff then
SlipDiff = SlipDiffusion(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(approxSpace,u)
SlipVel:set_theta(ss_value)
SlipVel:set_vel(self.SlipVelValue)
SlipVel:set_slope_limit(self.slope_limit)
SlipVel:set_phase_parameters(InterfaceValues)
SlipVel:set_normal(Normal)
end
end
self.SlipDiff = SlipDiff
self.SlipVel = SlipVel
print("Clousures Discretization DONE")
end
--------------------------------------------------------------------------------
-- Discretization
--------------------------------------------------------------------------------
myProblem.Discretization = function (self,Inner_total)
local NavierStokesDisc = NavierStokesFV1M (self.fct_cmp_tbl, Inner_total)
NavierStokesDisc:set_exact_jacobian (self.bExactJac)
NavierStokesDisc:set_stokes (self.bStokes)
NavierStokesDisc:set_laplace (self.bNoLaplace)
NavierStokesDisc:set_upwind (self.upwind_m)
NavierStokesDisc:set_upwind_vol(self.upwind_t)
NavierStokesDisc:set_peclet_blend (self.bPecletBlend)
NavierStokesDisc:set_stabilization (self.stab, self.diffLength)
NavierStokesDisc:set_div_correction (self.div_correction)
NavierStokesDisc:set_transport_ip_velocity(self.boolIPVelocity)
NavierStokesDisc:set_transport_jac(self.boolTransportJac)
NavierStokesDisc:set_mass_term(self.boolMassTerm)
NavierStokesDisc:set_mass_mean(self.boolDensityMean)
NavierStokesDisc:set_density(self.Density,true)
if self.timeMethod == "limex" and self.boolMassTerm and not(self.bStokes) then
NavierStokesDisc:set_limex_correction(true)
end
if self.boolRelativeVel then
NavierStokesDisc:set_relative_velocity(self.RelVel,self.riemman)
NavierStokesDisc:set_upwind_rel(self.upwind_r)
end
if self.boolSlipDiff then
NavierStokesDisc:set_diffusion(self.SlipDiff)
else
if self.boolAveDiff then
NavierStokesDisc:set_diffusion(self.Diffusion)
end
if self.boolSlipVel then
NavierStokesDisc:set_slip_velocity(self.SlipVel)
end
end
if(self.boolpress_jump) then
NavierStokesDisc:set_pressure_jump ( self.diffLength)
end
NavierStokesDisc:set_kinematic_viscosity (self.EfectiveKinViscosity)
NavierStokesDisc:set_average_gamma(self.gamma)
NavierStokesDisc:set_phase_parameters(self.InterfaceValues)
print("Space Discretization DONE")
self.NavierStokesDisc = NavierStokesDisc
return NavierStokesDisc
end
--------------------------------------------------------------------------------
-- Time Discretization
--------------------------------------------------------------------------------
myProblem.TimeDiscretization = function (self,domainDisc)
print("Time Discretization")
-- create the assembled operator for the solver
local timeDisc = nil
-- create time discretization
if self.timeMethod=="cn" then
timeDisc = ThetaTimeStep(domainDisc)
timeDisc:set_theta(0.5) -- Crank-Nicolson method
end
if self.timeMethod=="euler" then
timeDisc = ThetaTimeStep(domainDisc)
timeDisc:set_theta(1) -- implicit Euler
end
if self.timeMethod=="fracstep" then
timeDisc = ThetaTimeStep(domainDisc,"FracStep")
end
if self.timeMethod=="alex" then
timeDisc = ThetaTimeStep(domainDisc, "Alexander")
end
print("Time Discretization DONE")
self.timeDisc = timeDisc
return timeDisc
end
--------------------------------------------------------------------------------
-- SOLVER
--------------------------------------------------------------------------------
myProblem.CreateSolver = function (self, domainDisc, approxSpace)
--------------
-- LineSearch
--------------
local NewtonLineSearch = nil
if true then
NewtonLineSearch = StandardLineSearch()
NewtonLineSearch:set_maximum_steps(self.lambdamaxSteps)
NewtonLineSearch:set_lambda_start(self.lambdaStart)
NewtonLineSearch:set_reduce_factor(0.5)
NewtonLineSearch:set_accept_best(true)
NewtonLineSearch:set_check_all(false)
NewtonLineSearch:set_suff_descent_factor(0.2)
NewtonLineSearch:set_maximum_defect(2e20)
else
NewtonLineSearch = TrustRegionMethod()
NewtonLineSearch:set_maximum_steps(3)
NewtonLineSearch:set_lambda_start(self.lambdaStart)
NewtonLineSearch:set_reduce_factor(0.5)
NewtonLineSearch:set_accept_best(true)
NewtonLineSearch:set_check_all(false)
NewtonLineSearch:set_suff_descent_factor(0.25)
NewtonLineSearch:set_maximum_defect(2e20)
end
----------------------
-- NoLinear COnvCheck
----------------------
local NewtonSteadyConvCheck=ConvCheck(self.max_newton_steps_steady_state, self.SteadyAbsDefect, self.SteadyRedDefect, true)
local NewtonConvCheck=ConvCheck(self.max_newton_steps_transient, self.AbsDefect, self.RedDefect, true)
local LinearConvCheckImp=ConvCheck(self.max_linear_steps_Imp, self.LinAbsDefectImp, self.LinRedDefectImp, true)
local LinearConvCheckLim=ConvCheck(self.max_linear_steps_Lim, self.LinAbsDefectLim, self.LinRedDefectLim, true)
local LimexConvCheck=ConvCheck(1, 1e-12, 1e-12, true)
LimexConvCheck:set_supress_unsuccessful(true)
--------------
-- Smoothers
--------------
-- base solver
baseSolver = LU()
baseSolver = AgglomeratingSolver(SuperLU());
ilu = ILU()
ilu:set_beta(self.value_beta)
ilu:set_damp(self.damping_mg)
ilu:set_ordering_algorithm(TopologicalOrdering())
ilu:set_sort(true)
--ilu:set_sort_eps(1.e-50)
ilu:set_inversion_eps(1.e-8)
ilu:enable_consistent_interfaces(true)
ilu:enable_overlap(false)
jac = Jacobi (0.7);
bgs = BlockGaussSeidel ();
gs = GaussSeidel()
gs:enable_consistent_interfaces(false)
gs:enable_overlap(false)
sgs = SymmetricGaussSeidel ()
sgs:enable_consistent_interfaces(true)
sgs:enable_overlap(false)
egs = ElementGaussSeidel();
cgs = ComponentGaussSeidel(0.1, {"p"}, {1,2}, {1})
------------------
-- preconditioners
-------------------
gmg = GeometricMultiGrid(approxSpace)
gmg:set_discretization(domainDisc)
gmg:set_base_level(self.numPreRefs)
gmg:set_base_solver(baseSolver)
gmg:set_smoother(ilu)
gmg:set_cycle_type(1)
gmg:set_num_presmooth(3)
gmg:set_num_postsmooth(3)
gmg:set_rap( true)
gmg:set_smooth_on_surface_rim(false)
-- gmg:set_damp(MinimalResiduumDamping())
-- gmg:set_damp(0.8)
-- gmg:set_damp(MinimalEnergyDamping())
-----------------
-- Linear Solver
-----------------
-- create Linear Solver
--GMresSolver = GMRES(20)
--GMresSolver:set_preconditioner(gmg)
--GMresSolver:set_convergence_check(LinearConvCheck)
-- create Linear Solver
BiCGStabSolverImp = BiCGStab()
BiCGStabSolverImp:set_preconditioner(gmg)
BiCGStabSolverImp:set_convergence_check(LinearConvCheckImp)
BiCGStabSolverLim = BiCGStab()
BiCGStabSolverLim:set_preconditioner(gmg)
BiCGStabSolverLim:set_convergence_check(LinearConvCheckLim)
--gmgSolver = LinearSolver()
--gmgSolver:set_preconditioner(gmg)
--gmgSolver:set_convergence_check(LinearConvCheck)
--ilutSolver = LinearSolver()
--ilutSolver:set_preconditioner(ilu)
--ilutSolver:set_convergence_check(LinearConvCheck)
-- choose a solver
LinearSolverLim = BiCGStabSolverLim
LinearSolverImp = BiCGStabSolverImp
--LinearSolver = GMresSolver
--LinearSolver = gmgSolver
--LinearSolver = ilutSolver
local NewtonSolverSteady = nil
if self.doSteadyState then
NewtonSolverSteady = NewtonSolver()
NewtonSolverSteady:set_linear_solver(LinearSolverImp)
NewtonSolverSteady:set_convergence_check(NewtonSteadyConvCheck)
NewtonSolverSteady:set_line_search(NewtonLineSearch)
if self.NewtonSteadyDebug then
local dbgWriter_steady = GridFunctionDebugWriter(approxSpace)
dbgWriter_steady:set_vtk_output(true)
dbgWriter_steady:set_conn_viewer_output(false)
dbgWriter_steady:set_base_dir(self.debug_dir)
NewtonSolverSteady:set_debug(dbgWriter_steady)
end
end
local limex = nil
local NLSolver = NewtonSolver()
if self.timeMethod == "limex" then
NLSolver:set_linear_solver(LinearSolverLim)
NLSolver:set_convergence_check(LimexConvCheck)
NLSolver:auto_update(false)
limex = myProblem:LimexObject( domainDisc, NLSolver)
else
NLSolver:set_linear_solver(LinearSolverImp)
NLSolver:set_convergence_check(NewtonConvCheck)
NLSolver:set_line_search(NewtonLineSearch)
NLSolver:set_reassemble_J_freq(0)
NLSolver:auto_update(true)
op = AssembledOperator(self.timeDisc)
op:init()
NLSolver:init(op)
if NLSolver:prepare(u) == false then
print ("Newton solver prepare failed.") return op, NLSolver, NewtonSolverSteady, limex, 0
end
end
if self.NewtonDebug then
local dbgWriter = GridFunctionDebugWriter(approxSpace)
dbgWriter:set_vtk_output(true)
dbgWriter:set_conn_viewer_output(false)
dbgWriter:set_base_dir(self.debug_dir)
NLSolver:set_debug(dbgWriter)
end
TransientNewtonUpdater = nil
if (self.NewtonUpdater and self.timeMethod == "euler")then
TransientNewtonUpdater = NewtonUpdaterProjection()
TransientNewtonUpdater:set_projection_fct(self.dim+1)
TransientNewtonUpdater:set_max_threshold(1.1)
TransientNewtonUpdater:set_min_threshold(-1.1)
NLSolver:setNewtonUpdater(TransientNewtonUpdater)
end
self.NewtonSolverDescSteady = NewtonSolverDescSteady
self.NewtonSolverDesc = NewtonSolverDesc
self.boolSolverDesc = true
print("Solver Setting DONE")
return op, NLSolver, NewtonSolverSteady, limex
end
--------------------------------------------------------------------------------
-- OutputParameters
--------------------------------------------------------------------------------
myProblem.OutputParameters = function (self)
local out = VTKOutput()
out:clear_selection()
out:select_all(false)
if self.dim == 2 then
out:select_nodal ("u,v", "velocity")
else
out:select_nodal ("u,v,w", "velocity")
end
out:select_nodal ("u", "u")
out:select_nodal ("v", "v")
if self.dim == 3 then
out:select_nodal ("w", "w")
end
out:select_nodal ("p", "p")
out:select_nodal ("c", "c")
out:select(self.Density, "Rho")
out:select(self.NavierStokesDisc:einstein_viscosity(), "Mu_eins")
out:select(self.NavierStokesDisc:mix_viscosity(), "Mu_I")
out:select(self.MixViscosity, "MixViscosity")
out:select(self.TurbulentViscosity, "Mu_turb")
out:select(self.RelVel, "RelVel")
out:select(self.NavierStokesDisc:particle_pressure(), "Ps")
out:select(self.NavierStokesDisc:particle_pressure_grad(), "DPs")
out:select(self.NavierStokesDisc:velocity_grad(), "Gamma")
out:select(self.gamma, "MeanGamma")
if (self.boolSlipDiff) then
out:select_element(self.SlipDiff, "SDiff")
else
if self.boolSlipVel then
out:select_element(self.SlipVel, "SVel")
end
end
out:select_element(self.Diffusion, "D")
out:select_element(self.Normal, "n")
print("Output file setting DONE")
return out
end
--------------------------------------------------------------------------------
-- CheckPoint
--------------------------------------------------------------------------------
myProblem.SaveCheckPoint = function (self,u,folder)
SaveToFile(u, folder .. "/CheckPoint" .. ".vec")
print("Saving CheckPoint: DONE")
end
myProblem.LoadCheckPoint = function (self,u,folder)
local boolInterpolate = false
local filename = folder .. "/Integral.txt"
local step = nil
local file = io.open(filename, "r")
if file then
print("Loading CheckPoint")
for line in file:lines() do
-- Skip the header
if not line:match("^Step") and not line:match("^%-") then
local columns = {}
for value in line:gmatch("%S+") do
table.insert(columns, value)
end