-
Notifications
You must be signed in to change notification settings - Fork 144
Expand file tree
/
Copy pathm_icpp_patches.fpp
More file actions
1421 lines (1154 loc) · 61.9 KB
/
m_icpp_patches.fpp
File metadata and controls
1421 lines (1154 loc) · 61.9 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
!>
!! @file
!! @brief Contains module m_icpp_patches
#:include 'case.fpp'
#:include 'ExtrusionHardcodedIC.fpp'
#:include '1dHardcodedIC.fpp'
#:include '2dHardcodedIC.fpp'
#:include '3dHardcodedIC.fpp'
#:include 'macros.fpp'
!> @brief Constructs initial condition patch geometries (lines, circles, rectangles, spheres, etc.) on the grid
module m_icpp_patches
use m_model ! Subroutine(s) related to STL files
use m_derived_types ! Definitions of the derived types
use m_global_parameters
use m_constants, only: max_2d_fourier_modes, max_sph_harm_degree, small_radius
use m_helper_basic
use m_helper
use m_mpi_common
use m_assign_variables
use m_mpi_common
use m_variables_conversion
implicit none
private; public :: s_apply_icpp_patches
real(wp) :: x_centroid, y_centroid, z_centroid
real(wp) :: length_x, length_y, length_z
integer :: smooth_patch_id
real(wp) :: smooth_coeff !< Smoothing coefficient (mirrors ic_patch_parameters%smooth_coeff)
real(wp) :: eta !< Pseudo volume fraction for patch boundary smoothing
real(wp) :: cart_y, cart_z
type(bounds_info) :: x_boundary, y_boundary, z_boundary !< Patch boundary locations in x, y, z
character(len=5) :: istr !< string to store int to string result for error checking
contains
!> Dispatch each initial condition patch to its geometry-specific initialization routine.
impure subroutine s_apply_icpp_patches(patch_id_fp, q_prim_vf)
type(scalar_field), dimension(1:sys_size), intent(inout) :: q_prim_vf
#ifdef MFC_MIXED_PRECISION
integer(kind=1), dimension(0:m,0:n,0:p), intent(inout) :: patch_id_fp
#else
integer, dimension(0:m,0:n,0:p), intent(inout) :: patch_id_fp
#endif
integer :: i
! 3D Patch Geometries
if (p > 0) then
do i = 1, num_patches
if (proc_rank == 0) then
print *, 'Processing patch', i
end if
!> ICPP Patches
!> @{
! Spherical patch
if (patch_icpp(i)%geometry == 8) then
call s_icpp_sphere(i, patch_id_fp, q_prim_vf)
! Cuboidal patch
else if (patch_icpp(i)%geometry == 9) then
call s_icpp_cuboid(i, patch_id_fp, q_prim_vf)
! Cylindrical patch
else if (patch_icpp(i)%geometry == 10) then
call s_icpp_cylinder(i, patch_id_fp, q_prim_vf)
! Swept plane patch
else if (patch_icpp(i)%geometry == 11) then
call s_icpp_sweep_plane(i, patch_id_fp, q_prim_vf)
! Ellipsoidal patch
else if (patch_icpp(i)%geometry == 12) then
call s_icpp_ellipsoid(i, patch_id_fp, q_prim_vf)
! 3D spherical harmonic patch
else if (patch_icpp(i)%geometry == 14) then
call s_icpp_3d_spherical_harmonic(i, patch_id_fp, q_prim_vf)
! 3D Modified circular patch
else if (patch_icpp(i)%geometry == 19) then
call s_icpp_3dvarcircle(i, patch_id_fp, q_prim_vf)
! 3D STL patch
else if (patch_icpp(i)%geometry == 21) then
call s_icpp_model(i, patch_id_fp, q_prim_vf)
end if
end do
!> @}
! 2D Patch Geometries
else if (n > 0) then
do i = 1, num_patches
if (proc_rank == 0) then
print *, 'Processing patch', i
end if
!> ICPP Patches
!> @{
! Circular patch
if (patch_icpp(i)%geometry == 2) then
call s_icpp_circle(i, patch_id_fp, q_prim_vf)
! Rectangular patch
else if (patch_icpp(i)%geometry == 3) then
call s_icpp_rectangle(i, patch_id_fp, q_prim_vf)
! Swept line patch
else if (patch_icpp(i)%geometry == 4) then
call s_icpp_sweep_line(i, patch_id_fp, q_prim_vf)
! Elliptical patch
else if (patch_icpp(i)%geometry == 5) then
call s_icpp_ellipse(i, patch_id_fp, q_prim_vf)
! Unimplemented patch (formerly isentropic vortex)
else if (patch_icpp(i)%geometry == 6) then
call s_mpi_abort('This used to be the isentropic vortex patch, ' &
& // 'which no longer exists. See Examples. Exiting.')
! 2D modal (Fourier) patch
else if (patch_icpp(i)%geometry == 13) then
call s_icpp_2d_modal(i, patch_id_fp, q_prim_vf)
! Spiral patch
else if (patch_icpp(i)%geometry == 17) then
call s_icpp_spiral(i, patch_id_fp, q_prim_vf)
! Modified circular patch
else if (patch_icpp(i)%geometry == 18) then
call s_icpp_varcircle(i, patch_id_fp, q_prim_vf)
! TaylorGreen vortex patch
else if (patch_icpp(i)%geometry == 20) then
call s_icpp_2D_TaylorGreen_vortex(i, patch_id_fp, q_prim_vf)
! STL patch
else if (patch_icpp(i)%geometry == 21) then
call s_icpp_model(i, patch_id_fp, q_prim_vf)
end if
!> @}
end do
! 1D Patch Geometries
else
do i = 1, num_patches
if (proc_rank == 0) then
print *, 'Processing patch', i
end if
! Line segment patch
if (patch_icpp(i)%geometry == 1) then
call s_icpp_line_segment(i, patch_id_fp, q_prim_vf)
! 1d analytical
else if (patch_icpp(i)%geometry == 16) then
call s_icpp_1d_bubble_pulse(i, patch_id_fp, q_prim_vf)
end if
end do
end if
end subroutine s_apply_icpp_patches
!> The line segment patch is a 1D geometry that may be used, for example, in creating a Riemann problem. The geometry of the
!! patch is well-defined when its centroid and length in the x-coordinate direction are provided. Note that the line segment
!! patch DOES NOT allow for the smearing of its boundaries.
subroutine s_icpp_line_segment(patch_id, patch_id_fp, q_prim_vf)
integer, intent(in) :: patch_id
#ifdef MFC_MIXED_PRECISION
integer(kind=1), dimension(0:m,0:n,0:p), intent(inout) :: patch_id_fp
#else
integer, dimension(0:m,0:n,0:p), intent(inout) :: patch_id_fp
#endif
type(scalar_field), dimension(1:sys_size), intent(inout) :: q_prim_vf
! Generic loop iterators
integer :: i, j, k
! Placeholders for the cell boundary values
real(wp) :: pi_inf, gamma, lit_gamma
@:HardcodedDimensionsExtrusion()
@:Hardcoded1DVariables()
pi_inf = pi_infs(1)
gamma = gammas(1)
lit_gamma = gs_min(1)
j = 0
k = 0
! Transferring the line segment's centroid and length information
x_centroid = patch_icpp(patch_id)%x_centroid
length_x = patch_icpp(patch_id)%length_x
! Computing the beginning and end x-coordinates of the line segment based on its centroid and length
x_boundary%beg = x_centroid - 0.5_wp*length_x
x_boundary%end = x_centroid + 0.5_wp*length_x
! Set eta=1 (no smoothing for this patch type)
eta = 1._wp
! Assign patch vars if cell is covered and patch has write permission
do i = 0, m
if (x_boundary%beg <= x_cc(i) .and. x_boundary%end >= x_cc(i) .and. patch_icpp(patch_id)%alter_patch(patch_id_fp(i, &
& 0, 0))) then
call s_assign_patch_primitive_variables(patch_id, i, 0, 0, eta, q_prim_vf, patch_id_fp)
@:analytical()
! check if this should load a hardcoded patch
if (patch_icpp(patch_id)%hcid /= dflt_int) then
@:Hardcoded1D()
end if
! Updating the patch identities bookkeeping variable
if (1._wp - eta < sgm_eps) patch_id_fp(i, 0, 0) = patch_id
end if
end do
@:HardcodedDellacation()
end subroutine s_icpp_line_segment
!> The spiral patch is a 2D geometry that may be used, The geometry of the patch is well-defined when its centroid and radius
!! are provided. Note that the circular patch DOES allow for the smoothing of its boundary.
impure subroutine s_icpp_spiral(patch_id, patch_id_fp, q_prim_vf)
integer, intent(in) :: patch_id
#ifdef MFC_MIXED_PRECISION
integer(kind=1), dimension(0:m,0:n,0:p), intent(inout) :: patch_id_fp
#else
integer, dimension(0:m,0:n,0:p), intent(inout) :: patch_id_fp
#endif
type(scalar_field), dimension(1:sys_size), intent(inout) :: q_prim_vf
integer :: i, j, k !< Generic loop iterators
real(wp) :: th, thickness, nturns, mya
real(wp) :: spiral_x_min, spiral_x_max, spiral_y_min, spiral_y_max
@:HardcodedDimensionsExtrusion()
@:Hardcoded2DVariables()
! Transferring the circular patch's radius, centroid, smearing patch identity and smearing coefficient information
x_centroid = patch_icpp(patch_id)%x_centroid
y_centroid = patch_icpp(patch_id)%y_centroid
mya = patch_icpp(patch_id)%radius
thickness = patch_icpp(patch_id)%length_x
nturns = patch_icpp(patch_id)%length_y
!
logic_grid = 0
do k = 0, int(m*91*nturns)
th = k/real(int(m*91._wp*nturns))*nturns*2._wp*pi
spiral_x_min = minval((/f_r(th, 0.0_wp, mya)*cos(th), f_r(th, thickness, mya)*cos(th)/))
spiral_y_min = minval((/f_r(th, 0.0_wp, mya)*sin(th), f_r(th, thickness, mya)*sin(th)/))
spiral_x_max = maxval((/f_r(th, 0.0_wp, mya)*cos(th), f_r(th, thickness, mya)*cos(th)/))
spiral_y_max = maxval((/f_r(th, 0.0_wp, mya)*sin(th), f_r(th, thickness, mya)*sin(th)/))
do j = 0, n; do i = 0, m
if ((x_cc(i) > spiral_x_min) .and. (x_cc(i) < spiral_x_max) .and. (y_cc(j) > spiral_y_min) .and. (y_cc(j) &
& < spiral_y_max)) then
logic_grid(i, j, 0) = 1
end if
end do; end do
end do
do j = 0, n
do i = 0, m
if ((logic_grid(i, j, 0) == 1)) then
call s_assign_patch_primitive_variables(patch_id, i, j, 0, eta, q_prim_vf, patch_id_fp)
@:analytical()
if (patch_icpp(patch_id)%hcid /= dflt_int) then
@:Hardcoded2D()
end if
! Updating the patch identities bookkeeping variable
if (1._wp - eta < sgm_eps) patch_id_fp(i, j, 0) = patch_id
end if
end do
end do
@:HardcodedDellacation()
end subroutine s_icpp_spiral
!> The circular patch is a 2D geometry that may be used, for example, in creating a bubble or a droplet. The geometry of the
!! patch is well-defined when its centroid and radius are provided. Note that the circular patch DOES allow for the smoothing of
!! its boundary.
subroutine s_icpp_circle(patch_id, patch_id_fp, q_prim_vf)
integer, intent(in) :: patch_id
#ifdef MFC_MIXED_PRECISION
integer(kind=1), dimension(0:m,0:n,0:p), intent(inout) :: patch_id_fp
#else
integer, dimension(0:m,0:n,0:p), intent(inout) :: patch_id_fp
#endif
type(scalar_field), dimension(1:sys_size), intent(inout) :: q_prim_vf
real(wp) :: radius
integer :: i, j, k !< Generic loop iterators
@:HardcodedDimensionsExtrusion()
@:Hardcoded2DVariables()
! Transferring the circular patch's radius, centroid, smearing patch identity and smearing coefficient information
x_centroid = patch_icpp(patch_id)%x_centroid
y_centroid = patch_icpp(patch_id)%y_centroid
radius = patch_icpp(patch_id)%radius
smooth_patch_id = patch_icpp(patch_id)%smooth_patch_id
smooth_coeff = patch_icpp(patch_id)%smooth_coeff
! Initialize eta=1; modified if smoothing is enabled
eta = 1._wp
! Assign patch vars if cell is covered and patch has write permission
do j = 0, n
do i = 0, m
if (patch_icpp(patch_id)%smoothen) then
! Smooth Heaviside via hyperbolic tangent; smooth_coeff controls interface sharpness
eta = tanh(smooth_coeff/min(dx, &
& dy)*(sqrt((x_cc(i) - x_centroid)**2 + (y_cc(j) - y_centroid)**2) - radius))*(-0.5_wp) + 0.5_wp
end if
if (((x_cc(i) - x_centroid)**2 + (y_cc(j) - y_centroid)**2 <= radius**2 &
& .and. patch_icpp(patch_id)%alter_patch(patch_id_fp(i, j, 0))) .or. patch_id_fp(i, j, &
& 0) == smooth_patch_id) then
call s_assign_patch_primitive_variables(patch_id, i, j, 0, eta, q_prim_vf, patch_id_fp)
@:analytical()
if (patch_icpp(patch_id)%hcid /= dflt_int) then
@:Hardcoded2D()
end if
end if
end do
end do
@:HardcodedDellacation()
end subroutine s_icpp_circle
!> The varcircle patch is a 2D geometry that may be used . It generatres an annulus
subroutine s_icpp_varcircle(patch_id, patch_id_fp, q_prim_vf)
! Patch identifier
integer, intent(in) :: patch_id
#ifdef MFC_MIXED_PRECISION
integer(kind=1), dimension(0:m,0:n,0:p), intent(inout) :: patch_id_fp
#else
integer, dimension(0:m,0:n,0:p), intent(inout) :: patch_id_fp
#endif
type(scalar_field), dimension(1:sys_size), intent(inout) :: q_prim_vf
! Generic loop iterators
integer :: i, j, k
real(wp) :: radius, myr, thickness
@:HardcodedDimensionsExtrusion()
@:Hardcoded2DVariables()
! Transferring the circular patch's radius, centroid, smearing patch identity and smearing coefficient information
x_centroid = patch_icpp(patch_id)%x_centroid
y_centroid = patch_icpp(patch_id)%y_centroid
radius = patch_icpp(patch_id)%radius
smooth_patch_id = patch_icpp(patch_id)%smooth_patch_id
smooth_coeff = patch_icpp(patch_id)%smooth_coeff
thickness = patch_icpp(patch_id)%epsilon
! Initialize eta=1; modified if smoothing is enabled
eta = 1._wp
! Assign patch vars if cell is covered and patch has write permission
do j = 0, n
do i = 0, m
myr = sqrt((x_cc(i) - x_centroid)**2 + (y_cc(j) - y_centroid)**2)
if (myr <= radius + thickness/2._wp .and. myr >= radius - thickness/2._wp &
& .and. patch_icpp(patch_id)%alter_patch(patch_id_fp(i, j, 0))) then
call s_assign_patch_primitive_variables(patch_id, i, j, 0, eta, q_prim_vf, patch_id_fp)
@:analytical()
if (patch_icpp(patch_id)%hcid /= dflt_int) then
@:Hardcoded2D()
end if
! Updating the patch identities bookkeeping variable
if (1._wp - eta < sgm_eps) patch_id_fp(i, j, 0) = patch_id
q_prim_vf(eqn_idx%alf)%sf(i, j, &
& 0) = patch_icpp(patch_id)%alpha(1)*exp(-0.5_wp*((myr - radius)**2._wp)/(thickness/3._wp)**2._wp)
end if
end do
end do
@:HardcodedDellacation()
end subroutine s_icpp_varcircle
!> Initialize a 3D variable-thickness circular annulus patch extruded along the z-axis.
subroutine s_icpp_3dvarcircle(patch_id, patch_id_fp, q_prim_vf)
! Patch identifier
integer, intent(in) :: patch_id
#ifdef MFC_MIXED_PRECISION
integer(kind=1), dimension(0:m,0:n,0:p), intent(inout) :: patch_id_fp
#else
integer, dimension(0:m,0:n,0:p), intent(inout) :: patch_id_fp
#endif
type(scalar_field), dimension(1:sys_size), intent(inout) :: q_prim_vf
! Generic loop iterators
integer :: i, j, k
real(wp) :: radius, myr, thickness
@:HardcodedDimensionsExtrusion()
@:Hardcoded3DVariables()
! Transferring the circular patch's radius, centroid, smearing patch identity and smearing coefficient information
x_centroid = patch_icpp(patch_id)%x_centroid
y_centroid = patch_icpp(patch_id)%y_centroid
z_centroid = patch_icpp(patch_id)%z_centroid
length_z = patch_icpp(patch_id)%length_z
radius = patch_icpp(patch_id)%radius
smooth_patch_id = patch_icpp(patch_id)%smooth_patch_id
smooth_coeff = patch_icpp(patch_id)%smooth_coeff
thickness = patch_icpp(patch_id)%epsilon
! Initialize eta=1; modified if smoothing is enabled
eta = 1._wp
! write for all z
! Assign patch vars if cell is covered and patch has write permission
do k = 0, p
do j = 0, n
do i = 0, m
myr = sqrt((x_cc(i) - x_centroid)**2 + (y_cc(j) - y_centroid)**2)
if (myr <= radius + thickness/2._wp .and. myr >= radius - thickness/2._wp &
& .and. patch_icpp(patch_id)%alter_patch(patch_id_fp(i, j, k))) then
call s_assign_patch_primitive_variables(patch_id, i, j, k, eta, q_prim_vf, patch_id_fp)
@:analytical()
if (patch_icpp(patch_id)%hcid /= dflt_int) then
@:Hardcoded3D()
end if
! Updating the patch identities bookkeeping variable
if (1._wp - eta < sgm_eps) patch_id_fp(i, j, k) = patch_id
q_prim_vf(eqn_idx%alf)%sf(i, j, &
& k) = patch_icpp(patch_id)%alpha(1)*exp(-0.5_wp*((myr - radius)**2._wp)/(thickness/3._wp)**2._wp)
end if
end do
end do
end do
@:HardcodedDellacation()
end subroutine s_icpp_3dvarcircle
!> The elliptical patch is a 2D geometry. The geometry of the patch is well-defined when its centroid and radii are provided.
!! Note that the elliptical patch DOES allow for the smoothing of its boundary
subroutine s_icpp_ellipse(patch_id, patch_id_fp, q_prim_vf)
integer, intent(in) :: patch_id
#ifdef MFC_MIXED_PRECISION
integer(kind=1), dimension(0:m,0:n,0:p), intent(inout) :: patch_id_fp
#else
integer, dimension(0:m,0:n,0:p), intent(inout) :: patch_id_fp
#endif
type(scalar_field), dimension(1:sys_size), intent(inout) :: q_prim_vf
integer :: i, j, k !< Generic loop operators
real(wp) :: a, b
@:HardcodedDimensionsExtrusion()
@:Hardcoded2DVariables()
! Transferring the elliptical patch's radii, centroid, smearing patch identity, and smearing coefficient information
x_centroid = patch_icpp(patch_id)%x_centroid
y_centroid = patch_icpp(patch_id)%y_centroid
a = patch_icpp(patch_id)%radii(1)
b = patch_icpp(patch_id)%radii(2)
smooth_patch_id = patch_icpp(patch_id)%smooth_patch_id
smooth_coeff = patch_icpp(patch_id)%smooth_coeff
! Initialize eta=1; modified if smoothing is enabled
eta = 1._wp
! Assign patch vars if cell is covered and patch has write permission
do j = 0, n
do i = 0, m
if (patch_icpp(patch_id)%smoothen) then
eta = tanh(smooth_coeff/min(dx, &
& dy)*(sqrt(((x_cc(i) - x_centroid)/a)**2 + ((y_cc(j) - y_centroid)/b)**2) - 1._wp))*(-0.5_wp) &
& + 0.5_wp
end if
if ((((x_cc(i) - x_centroid)/a)**2 + ((y_cc(j) - y_centroid)/b)**2 <= 1._wp &
& .and. patch_icpp(patch_id)%alter_patch(patch_id_fp(i, j, 0))) .or. patch_id_fp(i, j, &
& 0) == smooth_patch_id) then
call s_assign_patch_primitive_variables(patch_id, i, j, 0, eta, q_prim_vf, patch_id_fp)
@:analytical()
if (patch_icpp(patch_id)%hcid /= dflt_int) then
@:Hardcoded2D()
end if
! Updating the patch identities bookkeeping variable
if (1._wp - eta < sgm_eps) patch_id_fp(i, j, 0) = patch_id
end if
end do
end do
@:HardcodedDellacation()
end subroutine s_icpp_ellipse
!> The ellipsoidal patch is a 3D geometry. The geometry of the patch is well-defined when its centroid and radii are provided.
!! Note that the ellipsoidal patch DOES allow for the smoothing of its boundary
subroutine s_icpp_ellipsoid(patch_id, patch_id_fp, q_prim_vf)
! Patch identifier
integer, intent(in) :: patch_id
#ifdef MFC_MIXED_PRECISION
integer(kind=1), dimension(0:m,0:n,0:p), intent(inout) :: patch_id_fp
#else
integer, dimension(0:m,0:n,0:p), intent(inout) :: patch_id_fp
#endif
type(scalar_field), dimension(1:sys_size), intent(inout) :: q_prim_vf
! Generic loop iterators
integer :: i, j, k
real(wp) :: a, b, c
@:HardcodedDimensionsExtrusion()
@:Hardcoded3DVariables()
! Transferring the ellipsoidal patch's radii, centroid, smearing patch identity, and smearing coefficient information
x_centroid = patch_icpp(patch_id)%x_centroid
y_centroid = patch_icpp(patch_id)%y_centroid
z_centroid = patch_icpp(patch_id)%z_centroid
a = patch_icpp(patch_id)%radii(1)
b = patch_icpp(patch_id)%radii(2)
c = patch_icpp(patch_id)%radii(3)
smooth_patch_id = patch_icpp(patch_id)%smooth_patch_id
smooth_coeff = patch_icpp(patch_id)%smooth_coeff
! Initialize eta=1; modified if smoothing is enabled
eta = 1._wp
! Assign patch vars if cell is covered and patch has write permission
do k = 0, p
do j = 0, n
do i = 0, m
if (grid_geometry == 3) then
call s_convert_cylindrical_to_cartesian_coord(y_cc(j), z_cc(k))
else
cart_y = y_cc(j)
cart_z = z_cc(k)
end if
if (patch_icpp(patch_id)%smoothen) then
eta = tanh(smooth_coeff/min(dx, dy, &
& dz)*(sqrt(((x_cc(i) - x_centroid)/a)**2 + ((cart_y - y_centroid)/b)**2 + ((cart_z &
& - z_centroid)/c)**2) - 1._wp))*(-0.5_wp) + 0.5_wp
end if
if ((((x_cc(i) - x_centroid)/a)**2 + ((cart_y - y_centroid)/b)**2 + ((cart_z - z_centroid)/c)**2 <= 1._wp &
& .and. patch_icpp(patch_id)%alter_patch(patch_id_fp(i, j, k))) .or. patch_id_fp(i, j, &
& k) == smooth_patch_id) then
call s_assign_patch_primitive_variables(patch_id, i, j, k, eta, q_prim_vf, patch_id_fp)
@:analytical()
if (patch_icpp(patch_id)%hcid /= dflt_int) then
@:Hardcoded3D()
end if
! Updating the patch identities bookkeeping variable
if (1._wp - eta < sgm_eps) patch_id_fp(i, j, k) = patch_id
end if
end do
end do
end do
@:HardcodedDellacation()
end subroutine s_icpp_ellipsoid
!> The rectangular patch is a 2D geometry that may be used, for example, in creating a solid boundary, or pre-/post- shock
!! region, in alignment with the axes of the Cartesian coordinate system. The geometry of such a patch is well- defined when its
!! centroid and lengths in the x- and y- coordinate directions are provided. Please note that the rectangular patch DOES NOT
!! allow for the smoothing of its boundaries.
subroutine s_icpp_rectangle(patch_id, patch_id_fp, q_prim_vf)
integer, intent(in) :: patch_id
#ifdef MFC_MIXED_PRECISION
integer(kind=1), dimension(0:m,0:n,0:p), intent(inout) :: patch_id_fp
#else
integer, dimension(0:m,0:n,0:p), intent(inout) :: patch_id_fp
#endif
type(scalar_field), dimension(1:sys_size), intent(inout) :: q_prim_vf
integer :: i, j, k !< generic loop iterators
real(wp) :: pi_inf, gamma, lit_gamma !< Equation of state parameters
@:HardcodedDimensionsExtrusion()
@:Hardcoded2DVariables()
pi_inf = pi_infs(1)
gamma = gammas(1)
lit_gamma = gs_min(1)
! Transferring the rectangle's centroid and length information
x_centroid = patch_icpp(patch_id)%x_centroid
y_centroid = patch_icpp(patch_id)%y_centroid
length_x = patch_icpp(patch_id)%length_x
length_y = patch_icpp(patch_id)%length_y
! Computing the beginning and the end x- and y-coordinates of the rectangle based on its centroid and lengths
x_boundary%beg = x_centroid - 0.5_wp*length_x
x_boundary%end = x_centroid + 0.5_wp*length_x
y_boundary%beg = y_centroid - 0.5_wp*length_y
y_boundary%end = y_centroid + 0.5_wp*length_y
! Set eta=1 (no smoothing for this patch type)
eta = 1._wp
! Assign patch vars if cell is covered and patch has write permission
do j = 0, n
do i = 0, m
if (x_boundary%beg <= x_cc(i) .and. x_boundary%end >= x_cc(i) .and. y_boundary%beg <= y_cc(j) &
& .and. y_boundary%end >= y_cc(j)) then
if (patch_icpp(patch_id)%alter_patch(patch_id_fp(i, j, 0))) then
call s_assign_patch_primitive_variables(patch_id, i, j, 0, eta, q_prim_vf, patch_id_fp)
@:analytical()
if (patch_icpp(patch_id)%hcid /= dflt_int) then
@:Hardcoded2D()
end if
if ((q_prim_vf(1)%sf(i, j, 0) < 1.e-10) .and. (model_eqns == 4)) then
! zero density, reassign according to Tait EOS
q_prim_vf(1)%sf(i, j, 0) = (((q_prim_vf(eqn_idx%E)%sf(i, j, &
& 0) + pi_inf)/(pref + pi_inf))**(1._wp/lit_gamma))*rhoref*(1._wp &
& - q_prim_vf(eqn_idx%alf)%sf(i, j, 0))
end if
! Updating the patch identities bookkeeping variable
if (1._wp - eta < sgm_eps) patch_id_fp(i, j, 0) = patch_id
end if
end if
end do
end do
@:HardcodedDellacation()
end subroutine s_icpp_rectangle
!> The swept line patch is a 2D geometry that may be used, for example, in creating a solid boundary, or pre-/post- shock
!! region, at an angle with respect to the axes of the Cartesian coordinate system. The geometry of the patch is well-defined
!! when its centroid and normal vector, aimed in the sweep direction, are provided. Note that the sweep line patch DOES allow
!! the smoothing of its boundary.
subroutine s_icpp_sweep_line(patch_id, patch_id_fp, q_prim_vf)
integer, intent(in) :: patch_id
#ifdef MFC_MIXED_PRECISION
integer(kind=1), dimension(0:m,0:n,0:p), intent(inout) :: patch_id_fp
#else
integer, dimension(0:m,0:n,0:p), intent(inout) :: patch_id_fp
#endif
type(scalar_field), dimension(1:sys_size), intent(inout) :: q_prim_vf
integer :: i, j, k !< Generic loop operators
real(wp) :: a, b, c
@:HardcodedDimensionsExtrusion()
@:Hardcoded3DVariables()
! Transferring the centroid information of the line to be swept
x_centroid = patch_icpp(patch_id)%x_centroid
y_centroid = patch_icpp(patch_id)%y_centroid
smooth_patch_id = patch_icpp(patch_id)%smooth_patch_id
smooth_coeff = patch_icpp(patch_id)%smooth_coeff
! Obtaining coefficients of the equation describing the sweep line
a = patch_icpp(patch_id)%normal(1)
b = patch_icpp(patch_id)%normal(2)
c = -a*x_centroid - b*y_centroid
! Initialize eta=1; modified if smoothing is enabled
eta = 1._wp
! Assign patch vars if cell is covered and patch has write permission
do j = 0, n
do i = 0, m
if (patch_icpp(patch_id)%smoothen) then
eta = 5.e-1_wp + 5.e-1_wp*tanh(smooth_coeff/min(dx, dy)*(a*x_cc(i) + b*y_cc(j) + c)/sqrt(a**2 + b**2))
end if
if ((a*x_cc(i) + b*y_cc(j) + c >= 0._wp .and. patch_icpp(patch_id)%alter_patch(patch_id_fp(i, j, &
& 0))) .or. patch_id_fp(i, j, 0) == smooth_patch_id) then
call s_assign_patch_primitive_variables(patch_id, i, j, 0, eta, q_prim_vf, patch_id_fp)
@:analytical()
if (patch_icpp(patch_id)%hcid /= dflt_int) then
@:Hardcoded3D()
end if
! Updating the patch identities bookkeeping variable
if (1._wp - eta < sgm_eps) patch_id_fp(i, j, 0) = patch_id
end if
end do
end do
@:HardcodedDellacation()
end subroutine s_icpp_sweep_line
!> The Taylor Green vortex is 2D decaying vortex that may be used, for example, to verify the effects of viscous attenuation.
!! Geometry of the patch is well-defined when its centroid are provided.
subroutine s_icpp_2D_TaylorGreen_Vortex(patch_id, patch_id_fp, q_prim_vf)
integer, intent(in) :: patch_id
#ifdef MFC_MIXED_PRECISION
integer(kind=1), dimension(0:m,0:n,0:p), intent(inout) :: patch_id_fp
#else
integer, dimension(0:m,0:n,0:p), intent(inout) :: patch_id_fp
#endif
type(scalar_field), dimension(1:sys_size), intent(inout) :: q_prim_vf
integer :: i, j, k !< generic loop iterators
real(wp) :: pi_inf, gamma, lit_gamma !< equation of state parameters
real(wp) :: L0, U0 !< Taylor Green Vortex parameters
@:HardcodedDimensionsExtrusion()
@:Hardcoded2DVariables()
pi_inf = pi_infs(1)
gamma = gammas(1)
lit_gamma = gs_min(1)
! Transferring the patch's centroid and length information
x_centroid = patch_icpp(patch_id)%x_centroid
y_centroid = patch_icpp(patch_id)%y_centroid
length_x = patch_icpp(patch_id)%length_x
length_y = patch_icpp(patch_id)%length_y
! Computing the beginning and the end x- and y-coordinates of the patch based on its centroid and lengths
x_boundary%beg = x_centroid - 0.5_wp*length_x
x_boundary%end = x_centroid + 0.5_wp*length_x
y_boundary%beg = y_centroid - 0.5_wp*length_y
y_boundary%end = y_centroid + 0.5_wp*length_y
! Set eta=1 (no smoothing for this patch type)
eta = 1._wp
! U0 is the characteristic velocity of the vortex
U0 = patch_icpp(patch_id)%vel(1)
! L0 is the characteristic length of the vortex
L0 = patch_icpp(patch_id)%vel(2)
! Assign patch vars if cell is covered and patch has write permission
do j = 0, n
do i = 0, m
if (x_boundary%beg <= x_cc(i) .and. x_boundary%end >= x_cc(i) .and. y_boundary%beg <= y_cc(j) &
& .and. y_boundary%end >= y_cc(j) .and. patch_icpp(patch_id)%alter_patch(patch_id_fp(i, j, 0))) then
call s_assign_patch_primitive_variables(patch_id, i, j, 0, eta, q_prim_vf, patch_id_fp)
@:analytical()
if (patch_icpp(patch_id)%hcid /= dflt_int) then
@:Hardcoded2D()
end if
! Updating the patch identities bookkeeping variable
if (1._wp - eta < sgm_eps) patch_id_fp(i, j, 0) = patch_id
! Assign Parameters
q_prim_vf(eqn_idx%mom%beg)%sf(i, j, 0) = U0*sin(x_cc(i)/L0)*cos(y_cc(j)/L0)
q_prim_vf(eqn_idx%mom%end)%sf(i, j, 0) = -U0*cos(x_cc(i)/L0)*sin(y_cc(j)/L0)
q_prim_vf(eqn_idx%E)%sf(i, j, &
& 0) = patch_icpp(patch_id)%pres + (cos(2*x_cc(i))/L0 + cos(2*y_cc(j))/L0)*(q_prim_vf(1)%sf(i, j, &
& 0)*U0*U0)/16
end if
end do
end do
@:HardcodedDellacation()
end subroutine s_icpp_2D_TaylorGreen_Vortex
!> Initialize a 1D bubble-pulse patch with analytical primitive variable profiles.
subroutine s_icpp_1d_bubble_pulse(patch_id, patch_id_fp, q_prim_vf)
! Description: This patch assigns the primitive variables as analytical functions such that the code can be verified.
! Patch identifier
integer, intent(in) :: patch_id
#ifdef MFC_MIXED_PRECISION
integer(kind=1), dimension(0:m,0:n,0:p), intent(inout) :: patch_id_fp
#else
integer, dimension(0:m,0:n,0:p), intent(inout) :: patch_id_fp
#endif
type(scalar_field), dimension(1:sys_size), intent(inout) :: q_prim_vf
! Generic loop iterators
integer :: i, j, k
! Placeholders for the cell boundary values
real(wp) :: pi_inf, gamma, lit_gamma
@:HardcodedDimensionsExtrusion()
@:Hardcoded1DVariables()
pi_inf = pi_infs(1)
gamma = gammas(1)
lit_gamma = gs_min(1)
! Transferring the patch's centroid and length information
x_centroid = patch_icpp(patch_id)%x_centroid
length_x = patch_icpp(patch_id)%length_x
! Computing the beginning and the end x- and y-coordinates of the patch based on its centroid and lengths
x_boundary%beg = x_centroid - 0.5_wp*length_x
x_boundary%end = x_centroid + 0.5_wp*length_x
! Set eta=1 (no smoothing for this patch type)
eta = 1._wp
! Assign patch vars if cell is covered and patch has write permission
do i = 0, m
if (x_boundary%beg <= x_cc(i) .and. x_boundary%end >= x_cc(i) .and. patch_icpp(patch_id)%alter_patch(patch_id_fp(i, &
& 0, 0))) then
call s_assign_patch_primitive_variables(patch_id, i, 0, 0, eta, q_prim_vf, patch_id_fp)
@:analytical()
if (patch_icpp(patch_id)%hcid /= dflt_int) then
@:Hardcoded1D()
end if
end if
end do
@:HardcodedDellacation()
end subroutine s_icpp_1D_bubble_pulse
!> 2D modal (Fourier) patch. theta = atan2(y - y_centroid, x - x_centroid). Additive (modal_use_exp_form false): R = radius +
!! sum_n [fourier_cos*cos(n*theta)+fourier_sin*sin(n*theta)]; coefficients are absolute (same units as radius). R is clipped to
!! max(R,0). If modal_clip_r_to_min, R = max(R, modal_r_min). Exponential (modal_use_exp_form true): R = radius*exp(sum);
!! coefficients are relative (dimensionless).
subroutine s_icpp_2d_modal(patch_id, patch_id_fp, q_prim_vf)
integer, intent(in) :: patch_id
#ifdef MFC_MIXED_PRECISION
integer(kind=1), dimension(0:m,0:n,0:p), intent(inout) :: patch_id_fp
#else
integer, dimension(0:m,0:n,0:p), intent(inout) :: patch_id_fp
#endif
type(scalar_field), dimension(1:sys_size), intent(inout) :: q_prim_vf
real(wp) :: r, theta, R_boundary, sum_series
integer :: i, j, nn
x_centroid = patch_icpp(patch_id)%x_centroid
y_centroid = patch_icpp(patch_id)%y_centroid
smooth_patch_id = patch_icpp(patch_id)%smooth_patch_id
smooth_coeff = patch_icpp(patch_id)%smooth_coeff
eta = 1._wp
do j = 0, n
do i = 0, m
r = sqrt((x_cc(i) - x_centroid)**2 + (y_cc(j) - y_centroid)**2)
if (r < small_radius) then
theta = 0._wp
else
theta = atan2(y_cc(j) - y_centroid, x_cc(i) - x_centroid)
end if
sum_series = 0._wp
do nn = 1, max_2d_fourier_modes
sum_series = sum_series + patch_icpp(patch_id)%fourier_cos(nn)*cos(real(nn, &
& wp)*theta) + patch_icpp(patch_id)%fourier_sin(nn)*sin(real(nn, wp)*theta)
end do
if (patch_icpp(patch_id)%modal_use_exp_form) then
R_boundary = patch_icpp(patch_id)%radius*exp(sum_series)
else
R_boundary = patch_icpp(patch_id)%radius + sum_series
R_boundary = max(R_boundary, 0._wp)
if (patch_icpp(patch_id)%modal_clip_r_to_min) then
R_boundary = max(R_boundary, patch_icpp(patch_id)%modal_r_min)
end if
end if
if (patch_icpp(patch_id)%smoothen) then
eta = 0.5_wp + 0.5_wp*tanh(smooth_coeff/min(dx, dy)*(R_boundary - r))
end if
if ((r <= R_boundary .and. patch_icpp(patch_id)%alter_patch(patch_id_fp(i, j, 0))) .or. patch_id_fp(i, j, &
& 0) == smooth_patch_id) then
call s_assign_patch_primitive_variables(patch_id, i, j, 0, eta, q_prim_vf, patch_id_fp)
end if
end do
end do
end subroutine s_icpp_2d_modal
!> 3D spherical harmonic patch. Surface r = radius + sum_lm sph_har_coeff(l,m)*Y_lm(theta,phi). theta = acos(z/r), phi =
!! atan2(y,x) relative to centroid.
subroutine s_icpp_3d_spherical_harmonic(patch_id, patch_id_fp, q_prim_vf)
integer, intent(in) :: patch_id
#ifdef MFC_MIXED_PRECISION
integer(kind=1), dimension(0:m,0:n,0:p), intent(inout) :: patch_id_fp
#else
integer, dimension(0:m,0:n,0:p), intent(inout) :: patch_id_fp
#endif
type(scalar_field), dimension(1:sys_size), intent(inout) :: q_prim_vf
real(wp) :: dx_loc, dy_loc, dz_loc, r, theta, phi, R_surface, eta_local
integer :: i, j, k, ll, mm
x_centroid = patch_icpp(patch_id)%x_centroid
y_centroid = patch_icpp(patch_id)%y_centroid
z_centroid = patch_icpp(patch_id)%z_centroid
smooth_patch_id = patch_icpp(patch_id)%smooth_patch_id
smooth_coeff = patch_icpp(patch_id)%smooth_coeff
eta_local = 1._wp
do k = 0, p
do j = 0, n
do i = 0, m
if (grid_geometry == 3) then
call s_convert_cylindrical_to_cartesian_coord(y_cc(j), z_cc(k))
dx_loc = x_cc(i) - x_centroid
dy_loc = cart_y - y_centroid
dz_loc = cart_z - z_centroid
else
dx_loc = x_cc(i) - x_centroid
dy_loc = y_cc(j) - y_centroid
dz_loc = z_cc(k) - z_centroid
end if
r = sqrt(dx_loc**2 + dy_loc**2 + dz_loc**2)
if (r < small_radius) then
theta = 0._wp
phi = 0._wp
else
theta = acos(min(1._wp, max(-1._wp, dz_loc/r)))
phi = atan2(dy_loc, dx_loc)
end if
R_surface = patch_icpp(patch_id)%radius
do ll = 0, max_sph_harm_degree
do mm = -ll, ll
if (patch_icpp(patch_id)%sph_har_coeff(ll, mm) == 0._wp) cycle
R_surface = R_surface + patch_icpp(patch_id)%sph_har_coeff(ll, mm)*real_ylm(theta, phi, ll, mm)
end do
end do
if (patch_icpp(patch_id)%smoothen) then
eta_local = 0.5_wp + 0.5_wp*tanh(smooth_coeff/min(dx, dy, dz)*(R_surface - r))
end if
if ((r <= R_surface .and. patch_icpp(patch_id)%alter_patch(patch_id_fp(i, j, k))) .or. patch_id_fp(i, j, &
& k) == smooth_patch_id) then
call s_assign_patch_primitive_variables(patch_id, i, j, k, eta_local, q_prim_vf, patch_id_fp)
end if
end do
end do
end do
end subroutine s_icpp_3d_spherical_harmonic
!> The spherical patch is a 3D geometry that may be used, for example, in creating a bubble or a droplet. The patch geometry is
!! well-defined when its centroid and radius are provided. Please note that the spherical patch DOES allow for the smoothing of
!! its boundary.
subroutine s_icpp_sphere(patch_id, patch_id_fp, q_prim_vf)
integer, intent(in) :: patch_id
#ifdef MFC_MIXED_PRECISION
integer(kind=1), dimension(0:m,0:n,0:p), intent(inout) :: patch_id_fp
#else
integer, dimension(0:m,0:n,0:p), intent(inout) :: patch_id_fp
#endif
type(scalar_field), dimension(1:sys_size), intent(inout) :: q_prim_vf
! Generic loop iterators
integer :: i, j, k
real(wp) :: radius
@:HardcodedDimensionsExtrusion()
@:Hardcoded3DVariables()
! Variables to initialize the pressure field that corresponds to the bubble-collapse test case found in Tiwari et al. (2013)
! Transferring spherical patch's radius, centroid, smoothing patch identity and smoothing coefficient information
x_centroid = patch_icpp(patch_id)%x_centroid
y_centroid = patch_icpp(patch_id)%y_centroid
z_centroid = patch_icpp(patch_id)%z_centroid
radius = patch_icpp(patch_id)%radius
smooth_patch_id = patch_icpp(patch_id)%smooth_patch_id
smooth_coeff = patch_icpp(patch_id)%smooth_coeff
! Initialize eta=1; modified if smoothing is enabled
eta = 1._wp
! Assign patch vars if cell is covered and patch has write permission
do k = 0, p
do j = 0, n
do i = 0, m
if (grid_geometry == 3) then
call s_convert_cylindrical_to_cartesian_coord(y_cc(j), z_cc(k))
else
cart_y = y_cc(j)
cart_z = z_cc(k)
end if
if (patch_icpp(patch_id)%smoothen) then