-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathSpatialDiscretization.f90
More file actions
1877 lines (1676 loc) · 78.3 KB
/
SpatialDiscretization.f90
File metadata and controls
1877 lines (1676 loc) · 78.3 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
#include "Includes.h"
module SpatialDiscretization
use SMConstants
use HyperbolicDiscretizations
use EllipticDiscretizations
use DGIntegrals
use MeshTypes
use LESModels
use HexMeshClass
use ElementClass
use PhysicsStorage
use Physics
use MPI_Face_Class
use MPI_Process_Info
use DGSEMClass
use FluidData
use VariableConversion, only: mGradientVariables, GetmOneFluidViscosity,&
GetmTwoFluidsViscosity, chGradientVariables,&
GetCHViscosity
use BoundaryConditions, only: BCs, SetBoundaryConditionsEqn, NS_BC, C_BC, MU_BC
use ProblemFileFunctions, only: UserDefinedSourceTermNS_f
use ParticlesClass
#ifdef _HAS_MPI_
use mpi
#endif
private
public ComputeTimeDerivative, ComputeTimeDerivativeIsolated, viscousDiscretizationKey
public Initialize_SpaceAndTimeMethods, Finalize_SpaceAndTimeMethods
abstract interface
SUBROUTINE computeElementInterfaceFluxF(f)
use FaceClass
IMPLICIT NONE
TYPE(Face) , INTENT(inout) :: f
end subroutine computeElementInterfaceFluxF
SUBROUTINE computeMPIFaceFluxF(f)
use FaceClass
IMPLICIT NONE
TYPE(Face) , INTENT(inout) :: f
end subroutine computeMPIFaceFluxF
SUBROUTINE computeBoundaryFluxF(f, time)
use SMConstants
use FaceClass, only: Face
IMPLICIT NONE
type(Face), intent(inout) :: f
REAL(KIND=RP) :: time
end subroutine computeBoundaryFluxF
end interface
character(len=LINE_LENGTH), parameter :: viscousDiscretizationKey = "viscous discretization"
character(len=LINE_LENGTH), parameter :: CHDiscretizationKey = "cahn-hilliard discretization"
character(len=LINE_LENGTH), parameter :: FLUID1_COMPRESSIBILITY_KEY = "fluid 1 sound speed square (m/s)"
real(kind=RP), protected :: IMEX_S0 = 0.0_RP
real(kind=RP), protected :: IMEX_K0 = 1.0_RP
logical :: use_non_constant_speed_of_sound = .false.
!
! ========
CONTAINS
! ========
!
!////////////////////////////////////////////////////////////////////////////////////////
!
subroutine Initialize_SpaceAndTimeMethods(controlVariables, mesh)
use FTValueDictionaryClass
use Utilities, only: toLower
use mainKeywordsModule
use Headers
use MPI_Process_Info
implicit none
class(FTValueDictionary), intent(in) :: controlVariables
class(HexMesh) :: mesh
!
! ---------------
! Local variables
! ---------------
!
character(len=LINE_LENGTH) :: inviscidDiscretizationName
character(len=LINE_LENGTH) :: viscousDiscretizationName
character(len=LINE_LENGTH) :: CHDiscretizationName
if (.not. mesh % child) then ! If this is a child mesh, all these constructs were already initialized for the parent mesh
if ( MPI_Process % isRoot ) then
write(STD_OUT,'(/)')
call Section_Header("Spatial discretization scheme")
write(STD_OUT,'(/)')
end if
!
! Initialize inviscid discretization
! ----------------------------------
inviscidDiscretizationName = controlVariables % stringValueForKey(inviscidDiscretizationKey,requestedLength = LINE_LENGTH)
call toLower(inviscidDiscretizationName)
select case ( trim(inviscidDiscretizationName) )
case ( "standard" )
if (.not. allocated(HyperbolicDiscretization)) allocate( StandardDG_t :: HyperbolicDiscretization )
case ( "split-form")
print*, "There are no split-forms available for the Multiphase Solver"
errorMessage(STD_OUT)
error stop
case default
write(STD_OUT,'(A,A,A)') 'Requested inviscid discretization "',trim(inviscidDiscretizationName),'" is not implemented.'
write(STD_OUT,'(A)') "Implemented discretizations are:"
write(STD_OUT,'(A)') " * Standard"
errorMessage(STD_OUT)
error stop
end select
call HyperbolicDiscretization % Initialize(controlVariables)
!
! Initialize viscous discretization
! ---------------------------------
if ( .not. controlVariables % ContainsKey(viscousDiscretizationKey) ) then
print*, "Input file is missing entry for keyword: viscous discretization"
errorMessage(STD_OUT)
error stop
end if
viscousDiscretizationName = controlVariables % stringValueForKey(viscousDiscretizationKey, requestedLength = LINE_LENGTH)
call toLower(viscousDiscretizationName)
select case ( trim(viscousDiscretizationName) )
case("br1")
allocate(BassiRebay1_t :: ViscousDiscretization)
case("br2")
allocate(BassiRebay2_t :: ViscousDiscretization)
case("ip")
allocate(InteriorPenalty_t :: ViscousDiscretization)
case default
write(STD_OUT,'(A,A,A)') 'Requested viscous discretization "',trim(viscousDiscretizationName),'" is not implemented.'
write(STD_OUT,'(A)') "Implemented discretizations are:"
write(STD_OUT,'(A)') " * BR1"
write(STD_OUT,'(A)') " * BR2"
write(STD_OUT,'(A)') " * IP"
errorMessage(STD_OUT)
error stop
end select
call ViscousDiscretization % Construct(controlVariables, ELLIPTIC_MU)
call ViscousDiscretization % Describe
!
! Compute wall distances
! ----------------------
call mesh % ComputeWallDistances
! Initialize models
! -----------------
call InitializeLESModel(LESModel, controlVariables)
!
! Initialize Cahn--Hilliard discretization
! ----------------------------------------
if ( .not. controlVariables % ContainsKey(CHDiscretizationKey) ) then
print*, "Input file is missing entry for keyword: Cahn-Hilliard discretization"
errorMessage(STD_OUT)
error stop
end if
CHDiscretizationName = controlVariables % stringValueForKey(CHDiscretizationKey, requestedLength = LINE_LENGTH)
call toLower(CHDiscretizationName)
select case ( trim(CHDiscretizationName) )
case("br1")
allocate(BassiRebay1_t :: CHDiscretization)
case("br2")
allocate(BassiRebay2_t :: CHDiscretization)
case("ip")
allocate(InteriorPenalty_t :: CHDiscretization)
case default
write(STD_OUT,'(A,A,A)') 'Requested viscous discretization "',trim(CHDiscretizationName),'" is not implemented.'
write(STD_OUT,'(A)') "Implemented discretizations are:"
write(STD_OUT,'(A)') " * BR1"
write(STD_OUT,'(A)') " * BR2"
write(STD_OUT,'(A)') " * IP"
errorMessage(STD_OUT)
error stop
end select
use_non_constant_speed_of_sound = controlVariables % ContainsKey(FLUID1_COMPRESSIBILITY_KEY)
if(use_non_constant_speed_of_sound) then
write(STD_OUT,'(A)') " Implementing artificial compressibility with a non-constant speed of sound in each phase"
else
write(STD_OUT,'(A)') " Implementing artificial compressibility with a constant speed of sound in each phase"
endif
call CHDiscretization % Construct(controlVariables, ELLIPTIC_CH)
call CHDiscretization % Describe
end if
end subroutine Initialize_SpaceAndTimeMethods
!
!////////////////////////////////////////////////////////////////////////
!
subroutine Finalize_SpaceAndTimeMethods
implicit none
IF ( ALLOCATED(HyperbolicDiscretization) ) DEALLOCATE( HyperbolicDiscretization )
end subroutine Finalize_SpaceAndTimeMethods
!
!////////////////////////////////////////////////////////////////////////
!
SUBROUTINE ComputeTimeDerivative( mesh, particles, time, mode, HO_Elements, element_mask)
IMPLICIT NONE
!
! ---------
! Arguments
! ---------
!
TYPE(HexMesh), target :: mesh
type(Particles_t) :: particles
REAL(KIND=RP) :: time
integer, intent(in) :: mode
logical, intent(in), optional :: HO_Elements
logical, intent(in), optional :: element_mask(:)
logical, allocatable :: face_mask(:)
real(kind=RP) :: mu_smag, delta
!
! ---------------
! Local variables
! ---------------
!
INTEGER :: k, eID, fID, i, j
real(kind=RP) :: sqrtRho, invMa2
class(Element), pointer :: e
logical :: compute_element
if (present(element_mask)) then
call CreateFaceMask(mesh, element_mask, face_mask)
endif
!$omp parallel shared(mesh, time) private(compute_element)
!
!///////////////////////////////////////////////////
! 1st step: Get chemical potential
!///////////////////////////////////////////////////
!
! ------------------------------------------
! Update concentration with the state vector
! ------------------------------------------
!
select case (mode)
case (CTD_IGNORE_MODE,CTD_IMEX_EXPLICIT)
!$omp do schedule(runtime)
do eID = 1, size(mesh % elements)
compute_element = .true.
if (present(element_mask)) compute_element = element_mask(eID)
if (compute_element) then
mesh % elements(eID) % storage % c(1,:,:,:) = mesh % elements(eID) % storage % QNS(IMC,:,:,:)
endif
end do
!$omp end do
end select
!
! -------------------------------
! Set memory to Cahn-Hilliard (C)
! -------------------------------
!
!$omp single
call mesh % SetStorageToEqn(C_BC)
select case (mode)
case (CTD_IGNORE_MODE,CTD_IMEX_EXPLICIT)
call SetBoundaryConditionsEqn(C_BC)
case (CTD_IMEX_IMPLICIT,CTD_LAPLACIAN)
call SetBoundaryConditionsEqn(MU_BC)
end select
!$omp end single
!
! --------------------------------------------
! Prolong Cahn-Hilliard concentration to faces
! --------------------------------------------
!
call mesh % ProlongSolutionToFaces(NCOMP, .false., element_mask)
!
! ----------------
! Update MPI Faces
! ----------------
!
#ifdef _HAS_MPI_
!$omp single
call mesh % UpdateMPIFacesSolution(NCOMP)
!$omp end single
#endif
!
! ------------------------------------------------------------
! Get concentration (lifted) gradients (also prolong to faces)
! ------------------------------------------------------------
!
call CHDiscretization % ComputeGradient(NCOMP, NCOMP, mesh, time, chGradientVariables, .false., element_mask)
!
! --------------------
! Update MPI Gradients
! --------------------
!
#ifdef _HAS_MPI_
!$omp single
call mesh % UpdateMPIFacesGradients(NCOMP)
!$omp end single
#endif
!
! ----------------------
! Get chemical potential
! ----------------------
!
! Get the concentration Laplacian (into QDot => cDot)
call ComputeLaplacian(mesh, time, element_mask)
select case (mode)
case (CTD_IGNORE_MODE, CTD_IMEX_EXPLICIT)
!$omp do schedule(runtime)
do eID = 1, size(mesh % elements)
compute_element = .true.
if (present(element_mask)) compute_element = element_mask(eID)
if (compute_element) then
!
! + Linear part
!mesh % elements(eID) % storage % mu = - POW2(multiphase % eps)* mesh % elements(eID) % storage % QDot
mesh % elements(eID) % storage % mu = - 1.5_RP * multiphase % eps * multiphase % sigma * mesh % elements(eID) % storage % QDot
!
! + NonLinear part
!call AddQuarticDWPDerivative(mesh % elements(eID) % storage % c, mesh % elements(eID) % storage % mu)
call Multiphase_AddChemFEDerivative(mesh % elements(eID) % storage % c, mesh % elements(eID) % storage % mu)
endif
end do
!$omp end do
case (CTD_IMEX_IMPLICIT)
!$omp do schedule(runtime)
do eID = 1, size(mesh % elements)
compute_element = .true.
if (present(element_mask)) compute_element = element_mask(eID)
if (compute_element) then
!
! + Linear part
!mesh % elements(eID) % storage % mu = - IMEX_K0 * POW2(multiphase % eps) * mesh % elements(eID) % storage % QDot &
mesh % elements(eID) % storage % mu = - 1.5_RP * IMEX_K0 * multiphase % eps * multiphase % sigma * mesh % elements(eID) % storage % QDot &
+ IMEX_S0 * mesh % elements(eID) % storage % c
! + Multiply by mobility
mesh % elements(eID) % storage % mu = multiphase % M0 * mesh % elements(eID) % storage % mu
endif
end do
!$omp end do
end select
!
! -----------------------------------
! Prolong chemical potential to faces
! -----------------------------------
!
select case(mode)
case(CTD_LAPLACIAN)
case default
!$omp single
call mesh % SetStorageToEqn(MU_BC)
!$omp end single
call mesh % ProlongSolutionToFaces(NCOMP, .false., element_mask)
!
! ----------------
! Update MPI Faces
! ----------------
!
#ifdef _HAS_MPI_
!$omp single
call mesh % UpdateMPIFacesSolution(NCOMP)
call mesh % GatherMPIFacesSolution(NCOMP)
!$omp end single
#endif
end select
!
!/////////////////////////////////////////////////////////////////////////////////
! 2nd step: If IMEX_IMPLCIIT, get the chemical potential laplacian and exit
!/////////////////////////////////////////////////////////////////////////////////
!
select case (mode)
case (CTD_IMEX_IMPLICIT)
!
! ------------------------------------------------------------
! Get concentration (lifted) gradients (also prolong to faces)
! ------------------------------------------------------------
!
call CHDiscretization % ComputeGradient(NCOMP, NCOMP, mesh, time, chGradientVariables, .false., element_mask)
!
! --------------------
! Update MPI Gradients
! --------------------
!
#ifdef _HAS_MPI_
!$omp single
call mesh % UpdateMPIFacesGradients(NCOMP)
call mesh % GatherMPIFacesGradients(NCOMP)
!$omp end single
#endif
!
! ----------------------
! Get chemical potential
! ----------------------
!
! Get the concentration Laplacian (into QDot => cDot)
call ComputeLaplacian(mesh, time, element_mask)
!
! ------------------------------------------
! *** WARNING! The storage leaves set to CH!
! ------------------------------------------
!
!$omp single
call mesh % SetStorageToEqn(C_BC)
call SetBoundaryConditionsEqn(C_BC)
!$omp end single
end select
!
!///////////////////////////////////////////////
! 3rd step: Navier-Stokes time derivative
!///////////////////////////////////////////////
!
select case (mode)
case (CTD_IGNORE_MODE, CTD_IMEX_EXPLICIT)
!$omp single
call mesh % SetStorageToEqn(NS_BC)
call SetBoundaryConditionsEqn(NS_BC)
!$omp end single
!
! -------------------------
! Prolong solution to faces
! -------------------------
!
call mesh % ProlongSolutionToFaces(NCONS, .false., element_mask)
!
! ----------------
! Update MPI Faces
! ----------------
!
#ifdef _HAS_MPI_
!$omp single
call mesh % UpdateMPIFacesSolution(NCONS)
call mesh % GatherMPIFacesSolution(NCONS)
!$omp end single
#endif
!
! -------------------------------------
! Get the density and invMa2 in faces and elements
! -------------------------------------
!
!$omp do schedule(runtime)
do eID = 1, size(mesh % elements)
compute_element = .true.
if (present(element_mask)) compute_element = element_mask(eID)
if (compute_element) then
mesh % elements(eID) % storage % rho = dimensionless % rho(2) + (dimensionless % rho(1)-dimensionless % rho(2))*mesh % elements(eID) % storage % Q(IMC,:,:,:)
mesh % elements(eID) % storage % rho = min(max(mesh % elements(eID) % storage % rho, dimensionless % rho_min),dimensionless % rho_max)
if (use_non_constant_speed_of_sound ) then
mesh % elements(eID) % storage % invMa2 = (sqrt(dimensionless % invMa2(1)/dimensionless % rho(1)) * min(max(mesh % elements(eID) % storage % Q(IMC,:,:,:),0.0_RP),1.0_RP) + sqrt(dimensionless % invMa2(2)/dimensionless % rho(2)) * (1.0_RP - min(max(mesh % elements(eID) % storage % Q(IMC,:,:,:),0.0_RP),1.0_RP)))**2
mesh % elements(eID) % storage % invMa2 = mesh % elements(eID) % storage % invMa2*mesh % elements(eID) % storage % rho
else
mesh % elements(eID) % storage % invMa2 = dimensionless % invMa2(1)
endif
endif
end do
!$omp end do nowait
!$omp do schedule(runtime)
do fID = 1, size(mesh % faces)
compute_element = .true.
if (present(element_mask)) compute_element = face_mask(fID)
if (compute_element) then
mesh % faces(fID) % storage(1) % rho = dimensionless % rho(2) + (dimensionless % rho(1)-dimensionless % rho(2))*mesh % faces(fID) % storage(1) % Q(IMC,:,:)
mesh % faces(fID) % storage(2) % rho = dimensionless % rho(2) + (dimensionless % rho(1)-dimensionless % rho(2))*mesh % faces(fID) % storage(2) % Q(IMC,:,:)
mesh % faces(fID) % storage(1) % rho = min(max(mesh % faces(fID) % storage(1) % rho, dimensionless % rho_min),dimensionless % rho_max)
mesh % faces(fID) % storage(2) % rho = min(max(mesh % faces(fID) % storage(2) % rho, dimensionless % rho_min),dimensionless % rho_max)
if (use_non_constant_speed_of_sound ) then
mesh % faces(fID) % storage(1) % invMa2 = (sqrt(dimensionless % invMa2(1)/dimensionless % rho(1)) * min(max(mesh % faces(fID) % storage(1) % Q(IMC,:,:),0.0_RP),1.0_RP) + sqrt(dimensionless % invMa2(2)/dimensionless % rho(2)) * (1.0_RP - min(max(mesh % faces(fID) % storage(1) % Q(IMC,:,:),0.0_RP),1.0_RP)))**2
mesh % faces(fID) % storage(2) % invMa2 = (sqrt(dimensionless % invMa2(1)/dimensionless % rho(1)) * min(max(mesh % faces(fID) % storage(2) % Q(IMC,:,:),0.0_RP),1.0_RP) + sqrt(dimensionless % invMa2(2)/dimensionless % rho(2)) * (1.0_RP - min(max(mesh % faces(fID) % storage(2) % Q(IMC,:,:),0.0_RP),1.0_RP)))**2
mesh % faces(fID) % storage(1) % invMa2 = mesh % faces(fID) % storage(1) % invMa2*mesh % faces(fID) % storage(1) % rho
mesh % faces(fID) % storage(2) % invMa2 = mesh % faces(fID) % storage(2) % invMa2*mesh % faces(fID) % storage(2) % rho
else
mesh % faces(fID) % storage(1) % invMa2 = dimensionless % invMa2(1)
mesh % faces(fID) % storage(2) % invMa2 = dimensionless % invMa2(2)
endif
endif
end do
!$omp end do
!
! ----------------------------------------
! Compute local entropy variables gradient
! ----------------------------------------
!
call ViscousDiscretization % ComputeLocalGradients( NCONS, NCONS, mesh , time , mGradientVariables)
!
! --------------------
! Update MPI Gradients
! --------------------
!
#ifdef _HAS_MPI_
!$omp single
call mesh % UpdateMPIFacesGradients(NCONS)
!$omp end single
#endif
!
! -------------------------------------
! Add the Non-Conservative term to QDot
! -------------------------------------
!
!$omp do schedule(runtime) private(i,j,k,e,sqrtRho,invMa2)
do eID = 1, size(mesh % elements)
compute_element = .true.
if (present(element_mask)) compute_element = element_mask(eID)
if (compute_element) then
associate(e => mesh % elements(eID))
do k = 0, e % Nxyz(3) ; do j = 0, e % Nxyz(2) ; do i = 0, e % Nxyz(1)
sqrtRho = sqrt(e % storage % rho(i,j,k))
invMa2 = e % storage % invMa2(i,j,k)
e % storage % QDot(IMC,i,j,k) = 0.0_RP
e % storage % QDot(IMSQRHOU,i,j,k) = -0.5_RP*sqrtRho*( e % storage % Q(IMSQRHOU,i,j,k)*e % storage % U_x(IGU,i,j,k) &
+ e % storage % Q(IMSQRHOV,i,j,k)*e % storage % U_y(IGU,i,j,k) &
+ e % storage % Q(IMSQRHOW,i,j,k)*e % storage % U_z(IGU,i,j,k) ) &
- e % storage % Q(IMC,i,j,k)*e % storage % U_x(IGMU,i,j,k)
e % storage % QDot(IMSQRHOV,i,j,k) = -0.5_RP*sqrtRho*( e % storage % Q(IMSQRHOU,i,j,k)*e % storage % U_x(IGV,i,j,k) &
+ e % storage % Q(IMSQRHOV,i,j,k)*e % storage % U_y(IGV,i,j,k) &
+ e % storage % Q(IMSQRHOW,i,j,k)*e % storage % U_z(IGV,i,j,k) ) &
- e % storage % Q(IMC,i,j,k)*e % storage % U_y(IGMU,i,j,k)
e % storage % QDot(IMSQRHOW,i,j,k) = -0.5_RP*sqrtRho*( e % storage % Q(IMSQRHOU,i,j,k)*e % storage % U_x(IGW,i,j,k) &
+ e % storage % Q(IMSQRHOV,i,j,k)*e % storage % U_y(IGW,i,j,k) &
+ e % storage % Q(IMSQRHOW,i,j,k)*e % storage % U_z(IGW,i,j,k) ) &
- e % storage % Q(IMC,i,j,k)*e % storage % U_z(IGMU,i,j,k)
! e % storage % QDot(IMP,i,j,k) = -dimensionless % invMa2*( e % storage % U_x(IGU,i,j,k) + e % storage % U_y(IGV,i,j,k) &
! + e % storage % U_z(IGW,i,j,k))
e % storage % QDot(IMP,i,j,k) = - invMa2*( e % storage % U_x(IGU,i,j,k) + e % storage % U_y(IGV,i,j,k) &
+ e % storage % U_z(IGW,i,j,k))
e % storage % QDot(:,i,j,k) = e % storage % QDot(:,i,j,k) * e % geom % jacobian(i,j,k)
end do ; end do ; end do
end associate
endif
end do
!$omp end do
call ViscousDiscretization % LiftGradients( NCONS, NCONS, mesh , time , mGradientVariables)
#ifdef _HAS_MPI_
!$omp single
! Not sure about the position of this w.r.t the MPI directly above
call mesh % UpdateMPIFacesGradients(NCONS)
call mesh % GatherMPIFacesGradients(NCONS)
!$omp end single
#endif
!
! -----------------------
! Compute time derivative
! -----------------------
!
select case (mode)
case(CTD_IMEX_EXPLICIT)
call multiphase % SetStarMobility(0.0_RP)
case(CTD_IGNORE_MODE)
call multiphase % SetStarMobility(multiphase % M0)
end select
call ComputeNSTimeDerivative(mesh, time, element_mask)
call multiphase % SetStarMobility(multiphase % M0)
end select
!
! -------------------------------------------------------------------------------
! If IMEX_Explicit, compute cDot with the explicit part of the chemical potential
! -------------------------------------------------------------------------------
!
select case (mode)
case(CTD_IMEX_EXPLICIT)
!$omp do schedule(runtime)
do eID = 1, size(mesh % elements)
compute_element = .true.
if (present(element_mask)) compute_element = element_mask(eID)
if (compute_element) then
!
! + Linear part
mesh % elements(eID) % storage % mu = - IMEX_S0 * mesh % elements(eID) % storage % c &
- 1.5_RP*(1.0_RP - IMEX_K0)*multiphase % sigma*multiphase % eps*mesh % elements(eID) % storage % cDot
!mesh % elements(eID) % storage % mu = - IMEX_S0 * mesh % elements(eID) % storage % c &
! - (1.0_RP - IMEX_K0)* POW2(multiphase % eps)*mesh % elements(eID) % storage % cDot
!
! + NonLinear part
!call AddQuarticDWPDerivative(mesh % elements(eID) % storage % c, mesh % elements(eID) % storage % mu)
call Multiphase_AddChemFEDerivative(mesh % elements(eID) % storage % c, mesh % elements(eID) % storage % mu)
endif
end do
!$omp end do
!
! -----------------------------------
! Prolong chemical potential to faces
! -----------------------------------
!
!$omp single
call mesh % SetStorageToEqn(MU_BC)
call SetBoundaryConditionsEqn(MU_BC)
!$omp end single
call mesh % ProlongSolutionToFaces(NCOMP, .false., element_mask)
!
! ------------------------------------------------------------
! Get concentration (lifted) gradients (also prolong to faces)
! ------------------------------------------------------------
!
call CHDiscretization % ComputeGradient(NCOMP, NCOMP, mesh, time, chGradientVariables, .false., element_mask)
!
! --------------------------------
! Get chemical potential laplacian
! --------------------------------
!
! Get the concentration Laplacian (into QDot => cDot)
call ComputeLaplacian(mesh, time, element_mask)
!$omp single
call mesh % SetStorageToEqn(NS_BC)
call SetBoundaryConditionsEqn(NS_BC)
!$omp end single
!
! -----------------------------------------
! Add the Chemical potential to the NS QDot
! -----------------------------------------
!
!$omp do schedule(runtime)
do eID = 1, size(mesh % elements)
compute_element = .true.
if (present(element_mask)) compute_element = element_mask(eID)
if (compute_element) then
mesh % elements(eID) % storage % QDot(IMC,:,:,:) = mesh % elements(eID) % storage % QDot(IMC,:,:,:) &
+ multiphase % M0*mesh % elements(eID) % storage % cDot(1,:,:,:)
endif
end do
!$omp end do
end select
!$omp end parallel
if (present(element_mask)) deallocate(face_mask)
!
END SUBROUTINE ComputeTimeDerivative
!
!////////////////////////////////////////////////////////////////////////////////////
!
! Navier--Stokes procedures
! -------------------------
!
!////////////////////////////////////////////////////////////////////////////////////
!
subroutine ComputeNSTimeDerivative( mesh , t, element_mask )
use SpongeClass, only: sponge, addSourceSponge
use ActuatorLine, only: farm, ForcesFarm
implicit none
type(HexMesh) :: mesh
real(kind=RP) :: t
procedure(UserDefinedSourceTermNS_f) :: UserDefinedSourceTermNS
logical, intent(in), optional :: element_mask(:)
!
! ---------------
! Local variables
! ---------------
!
integer :: eID , i, j, k, ierr, fID
real(kind=RP) :: sqrtRho, invSqrtRho
real(kind=RP) :: mu_smag, delta
real(kind=RP), dimension(NCONS) :: Source
logical :: compute_element
logical, allocatable :: face_mask(:)
if (present(element_mask)) then
call CreateFaceMask(mesh, element_mask, face_mask)
endif
!
! ****************
! Volume integrals
! ****************
!
!$omp do schedule(runtime)
do eID = 1 , size(mesh % elements)
compute_element = .true.
if (present(element_mask)) compute_element = element_mask(eID)
if (compute_element) then
call TimeDerivative_VolumetricContribution( mesh % elements(eID) , t)
endif
end do
!$omp end do nowait
if ( LESModel % active) then
!!$omp do schedule(runtime) private(i,j,k,delta,mu_smag)
do eID = 1, size(mesh % elements)
compute_element = .true.
if (present(element_mask)) compute_element = element_mask(eID)
if (compute_element) then
associate(e => mesh % elements(eID))
delta = (e % geom % Volume / product(e % Nxyz + 1)) ** (1.0_RP / 3.0_RP)
do k = 0, e % Nxyz(3) ; do j = 0, e % Nxyz(2) ; do i = 0, e % Nxyz(1)
call LESModel % ComputeViscosity(delta, e % geom % dWall(i,j,k), e % storage % Q(:,i,j,k), &
e % storage % U_x(:,i,j,k), &
e % storage % U_y(:,i,j,k), &
e % storage % U_z(:,i,j,k), &
e % storage % mu_turb_NS(i,j,k) )
! mu_smag)
! ! e % storage % mu_NS(1,i,j,k) = e % storage % mu_NS(1,i,j,k) + mu_smag
! ! e % storage % mu_NS(2,i,j,k) = e % storage % mu_NS(2,i,j,k) + mu_smag * dimensionless % mu_to_kappa
e % storage % mu_NS(1,i,j,k) = e % storage % mu_NS(1,i,j,k) + e % storage % mu_turb_NS(i,j,k)
! e % storage % mu_NS(2,i,j,k) = e % storage % mu_NS(2,i,j,k) + e % storage % mu_turb_NS(i,j,k) * dimensionless % mu_to_kappa
end do ; end do ; end do
end associate
endif
end do
!!$omp end do
end if
!
! Compute viscosity at interior and boundary faces
! ------------------------------------------------
call compute_viscosity_at_faces(size(mesh % faces_interior), 2, mesh % faces_interior, mesh)
call compute_viscosity_at_faces(size(mesh % faces_boundary), 1, mesh % faces_boundary, mesh)
!
! ******************************************
! Compute Riemann solver of non-shared faces
! ******************************************
!
!$omp do schedule(runtime)
do fID = 1, size(mesh % faces)
compute_element = .true.
if (present(element_mask)) compute_element = face_mask(fID)
if (compute_element) then
associate( f => mesh % faces(fID))
select case (f % faceType)
case (HMESH_INTERIOR)
CALL computeElementInterfaceFlux_MU( f )
case (HMESH_BOUNDARY)
CALL computeBoundaryFlux_MU(f, t)
end select
end associate
endif
end do
!$omp end do
!
! *************************************************************************************
! Element without shared faces: Surface integrals, scaling of elements with Jacobian,
! sqrt(rho)
! *************************************************************************************
!
!$omp do schedule(runtime) private(i,j,k,sqrtRho,invSqrtRho)
do eID = 1, size(mesh % elements)
compute_element = .true.
if (present(element_mask)) compute_element = element_mask(eID)
if (compute_element) then
associate(e => mesh % elements(eID))
if ( e % hasSharedFaces ) cycle
call TimeDerivative_FacesContribution(e, t, mesh)
do k = 0, e % Nxyz(3) ; do j = 0, e % Nxyz(2) ; do i = 0, e % Nxyz(1)
sqrtRho = sqrt(e % storage % rho(i,j,k))
invSqrtRho = 1.0_RP / sqrtRho
!
! + Scale with Jacobian and sqrt(Rho)
e % storage % QDot(:,i,j,k) = e % storage % QDot(:,i,j,k) * e % geom % InvJacobian(i,j,k)
e % storage % QDot(IMSQRHOU:IMSQRHOW,i,j,k) = e % storage % QDot(IMSQRHOU:IMSQRHOW,i,j,k) * invSqrtRho
!
! + Add gravity
e % storage % QDot(IMSQRHOU:IMSQRHOW,i,j,k) = e % storage % QDot(IMSQRHOU:IMSQRHOW,i,j,k) &
+ sqrtRho * dimensionless % invFr2 * dimensionless % gravity_dir
end do ; end do ; end do
end associate
endif
end do
!$omp end do
!
! ******************************************
! Do the same for elements with shared faces
! ******************************************
!
#ifdef _HAS_MPI_
if ( MPI_Process % doMPIAction ) then
!$omp single
call mesh % GatherMPIFacesGradients(NCONS)
!$omp end single
!
! Compute viscosity at MPI faces
! ------------------------------
call compute_viscosity_at_faces(size(mesh % faces_mpi), 2, mesh % faces_mpi, mesh)
!
! **************************************
! Compute Riemann solver of shared faces
! **************************************
!
!$omp do schedule(runtime)
do fID = 1, size(mesh % faces)
compute_element = .true.
if (present(element_mask)) compute_element = face_mask(fID)
if (compute_element) then
associate( f => mesh % faces(fID))
select case (f % faceType)
case (HMESH_MPI)
CALL computeMPIFaceFlux_MU( f )
end select
end associate
endif
end do
!$omp end do
!
! ***********************************************************
! Surface integrals and scaling of elements with shared faces
! ***********************************************************
!
!$omp do schedule(runtime) private(i,j,k, sqrtRho, invSqrtRho)
do eID = 1, size(mesh % elements)
compute_element = .true.
if (present(element_mask)) compute_element = element_mask(eID)
if (compute_element) then
associate(e => mesh % elements(eID))
if ( .not. e % hasSharedFaces ) cycle
call TimeDerivative_FacesContribution(e, t, mesh)
do k = 0, e % Nxyz(3) ; do j = 0, e % Nxyz(2) ; do i = 0, e % Nxyz(1)
sqrtRho = sqrt(e % storage % rho(i,j,k))
invSqrtRho = 1.0_RP / sqrtRho
!
! + Scale with Jacobian and sqrt(Rho)
e % storage % QDot(:,i,j,k) = e % storage % QDot(:,i,j,k) * e % geom % InvJacobian(i,j,k)
e % storage % QDot(IMSQRHOU:IMSQRHOW,i,j,k) = e % storage % QDot(IMSQRHOU:IMSQRHOW,i,j,k) * invSqrtRho
!
! + Add gravity
e % storage % QDot(IMSQRHOU:IMSQRHOW,i,j,k) = e % storage % QDot(IMSQRHOU:IMSQRHOW,i,j,k) &
+ sqrtRho * dimensionless % invFr2 * dimensionless % gravity_dir
end do ; end do ; end do
! do k = 0, e % Nxyz(3) ; do j = 0, e % Nxyz(2) ; do i = 0, e % Nxyz(1)
! e % storage % QDot(:,i,j,k) = e % storage % QDot(:,i,j,k) / e % geom % jacobian(i,j,k)
! end do ; end do ; end do
end associate
endif
end do
!$omp end do
!
! Add an MPI Barrier
! ------------------
!$omp single
call mpi_barrier(MPI_COMM_WORLD, ierr)
!$omp end single
end if
#endif
! ***************
! Add source term
! ***************
!$omp do schedule(runtime) private(i,j,k, InvSqrtRho)
do eID = 1, mesh % no_of_elements
compute_element = .true.
if (present(element_mask)) compute_element = element_mask(eID)
if (compute_element) then
associate ( e => mesh % elements(eID) )
e % storage % S_NS = 0.0_RP
do k = 0, e % Nxyz(3) ; do j = 0, e % Nxyz(2) ; do i = 0, e % Nxyz(1)
InvSqrtRho = 1.0_RP / sqrt(e % storage % rho(i,j,k))
call UserDefinedSourceTermNS(e % geom % x(:,i,j,k), e % storage % Q(:,i,j,k), t, e % storage % S_NS(:,i,j,k), thermodynamics, dimensionless, refValues, multiphase)
! scale UserDefinedSourceTerm momentum with sqrtRho
e % storage % S_NS(:,i,j,k) = e % storage % S_NS(:,i,j,k) * [1.0_RP,InvSqrtRho,InvSqrtRho,InvSqrtRho,1.0_RP]
end do ; end do ; end do
end associate
endif
end do
!$omp end do
!for the sponge, loops are in the internal subroutine as values are precalculated
!The scale with sqrtRho is done in the subroutines, not done againg here
call addSourceSponge(sponge,mesh)
call ForcesFarm(farm, mesh, t)
! Add all the source terms
!$omp do schedule(runtime) private(i,j,k)
do eID = 1, mesh % no_of_elements
compute_element = .true.
if (present(element_mask)) compute_element = element_mask(eID)
if (compute_element) then
associate ( e => mesh % elements(eID) )
do k = 0, e % Nxyz(3) ; do j = 0, e % Nxyz(2) ; do i = 0, e % Nxyz(1)
e % storage % QDot(:,i,j,k) = e % storage % QDot(:,i,j,k) + e % storage % S_NS(:,i,j,k)
end do ; end do ; end do
end associate
endif
end do
!$omp end do
!
! *********************
! Add IBM source term
! *********************
! no wall function for MULTIPHASE
if( mesh% IBM% active ) then
if( .not. mesh% IBM% semiImplicit ) then
!$omp do schedule(runtime) private(i,j,k,Source)
do eID = 1, mesh % no_of_elements
compute_element = .true.
if (present(element_mask)) compute_element = element_mask(eID)
if (compute_element) then
associate ( e => mesh % elements(eID) )
do k = 0, e % Nxyz(3) ; do j = 0, e % Nxyz(2) ; do i = 0, e % Nxyz(1)
if( e% isInsideBody(i,j,k) ) then
! only without moving for now in MULTIPHASE
if( .not. mesh% IBM% stl(e% STL(i,j,k))% move ) then
call mesh% IBM% SourceTerm( eID = eID, Q = e % storage % Q(:,i,j,k), Source = Source, wallfunction = .false. )
end if
e % storage % QDot(:,i,j,k) = e % storage % QDot(:,i,j,k) + Source
end if
end do ; end do ; end do
end associate
endif
end do
!$omp end do
end if
end if
if (present(element_mask)) deallocate(face_mask)
end subroutine ComputeNSTimeDerivative
!
!///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
!
subroutine TimeDerivative_VolumetricContribution( e , t )
use HexMeshClass
use ElementClass
implicit none
type(Element) :: e
real(kind=RP) :: t
!
! ---------------
! Local variables
! ---------------
!
real(kind=RP) :: inviscidContravariantFlux ( 1:NCONS, 0:e%Nxyz(1) , 0:e%Nxyz(2) , 0:e%Nxyz(3), 1:NDIM )
real(kind=RP) :: fSharp(1:NCONS, 0:e%Nxyz(1), 0:e%Nxyz(1), 0:e%Nxyz(2), 0:e%Nxyz(3))
real(kind=RP) :: gSharp(1:NCONS, 0:e%Nxyz(2), 0:e%Nxyz(1), 0:e%Nxyz(2), 0:e%Nxyz(3))
real(kind=RP) :: hSharp(1:NCONS, 0:e%Nxyz(3), 0:e%Nxyz(1), 0:e%Nxyz(2), 0:e%Nxyz(3))
real(kind=RP) :: viscousContravariantFlux ( 1:NCONS, 0:e%Nxyz(1) , 0:e%Nxyz(2) , 0:e%Nxyz(3), 1:NDIM )
real(kind=RP) :: contravariantFlux ( 1:NCONS, 0:e%Nxyz(1) , 0:e%Nxyz(2) , 0:e%Nxyz(3), 1:NDIM )