forked from AMReX-Codes/amrex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathboxarray_f.f90
893 lines (787 loc) · 23.8 KB
/
boxarray_f.f90
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
!!
!! A _BoxArray_ is an array of boxes.
!!
module boxarray_module
use bl_types
use box_module
use list_box_module
use bl_mem_stat_module
implicit none
type boxarray
private
integer :: dim = 0
integer :: nboxes = 0
type(box), pointer :: bxs(:) => Null()
end type boxarray
interface dataptr
module procedure boxarray_dataptr
end interface
interface get_dim
module procedure boxarray_dim
end interface
interface empty
module procedure boxarray_empty
end interface
interface built_q
module procedure boxarray_built_q
end interface
interface copy
module procedure boxarray_build_copy
module procedure boxarray_build_copy_l
end interface
interface build
module procedure boxarray_build_v
module procedure boxarray_build_l
module procedure boxarray_build_bx
end interface
interface destroy
module procedure boxarray_destroy
end interface
interface nboxes
module procedure boxarray_nboxes
module procedure boxlist_nboxes
end interface
interface volume
module procedure boxarray_volume
end interface
interface dvolume
module procedure boxarray_dvolume
end interface
interface set_box
module procedure boxarray_set_box
end interface
interface get_box
module procedure boxarray_get_box
end interface
interface boxarray_maxsize
module procedure boxarray_maxsize_i
module procedure boxarray_maxsize_v
end interface
interface boxarray_coarsen
module procedure boxarray_coarsen_v
module procedure boxarray_coarsen_i
end interface
interface boxarray_refine
module procedure boxarray_refine_v
module procedure boxarray_refine_i
end interface
interface boxarray_shift
module procedure boxarray_shift_v
module procedure boxarray_shift_i
end interface
interface boxarray_intersection
module procedure boxarray_intersection_bx
end interface
interface boxarray_grow
module procedure boxarray_grow_n
module procedure boxarray_grow_n_f
module procedure boxarray_grow_n_d_f
module procedure boxarray_grow_v
module procedure boxarray_grow_v_f
end interface
interface bbox
module procedure boxarray_bbox
end interface
interface print
module procedure boxarray_print
end interface
interface contains
module procedure boxarray_box_contains
module procedure boxarray_boxarray_contains
end interface
interface equal
module procedure boxarray_equal
end interface
interface operator( .eq. )
module procedure boxarray_equal
end interface
interface not_equal
module procedure boxarray_not_equal
end interface
interface operator( .ne. )
module procedure boxarray_not_equal
end interface
private :: boxarray_maxsize_l
private :: boxlist_nboxes
type(mem_stats), private, save :: boxarray_ms
contains
function boxarray_dataptr(ba) result(r)
type(boxarray), intent(in) :: ba
type(box), pointer :: r(:)
r => ba%bxs
end function boxarray_dataptr
pure function boxarray_equal(ba1, ba2) result(r)
type(boxarray), intent(in) :: ba1, ba2
logical :: r
r = associated(ba1%bxs, ba2%bxs)
end function boxarray_equal
pure function boxarray_not_equal(ba1, ba2) result(r)
type(boxarray), intent(in) :: ba1, ba2
logical :: r
r = .not. associated(ba1%bxs, ba2%bxs)
end function boxarray_not_equal
pure function boxarray_same_q(ba1, ba2) result(r)
type(boxarray), intent(in) :: ba1, ba2
logical :: r
integer :: i
if ( ba1 == ba2 ) then
r = .true.
else if ( ba1%dim /= ba2%dim .or. ba1%nboxes /= ba2%nboxes ) then
r = .false.
else
do i = 1, ba1%nboxes
if ( ba1%bxs(i) /= ba2%bxs(i) ) then
r = .false.
return
end if
end do
r = .true.
end if
end function boxarray_same_q
subroutine boxarray_set_mem_stats(ms)
type(mem_stats), intent(in) :: ms
boxarray_ms = ms
end subroutine boxarray_set_mem_stats
function boxarray_mem_stats() result(r)
type(mem_stats) :: r
r = boxarray_ms
end function boxarray_mem_stats
pure function boxarray_empty(ba) result(r)
logical :: r
type(boxarray), intent(in) :: ba
r = ba%nboxes == 0
end function boxarray_empty
pure function boxarray_built_q(ba) result(r)
logical :: r
type(boxarray), intent(in) :: ba
r = ba%dim /= 0
end function boxarray_built_q
pure function boxarray_dim(ba) result(r)
type(boxarray), intent(in) :: ba
integer :: r
r = ba%dim
end function boxarray_dim
subroutine boxarray_set_box(ba, i, bx)
type(boxarray), intent(inout) :: ba
integer, intent(in) :: i
type(box), intent(in) :: bx
ba%bxs(i) = bx
end subroutine boxarray_set_box
pure function boxarray_get_box(ba, i) result(r)
type(boxarray), intent(in) :: ba
integer, intent(in) :: i
type(box) :: r
r = ba%bxs(i)
end function boxarray_get_box
subroutine boxarray_build_copy(ba, ba1)
use bl_error_module
type(boxarray), intent(inout) :: ba
type(boxarray), intent(in) :: ba1
if ( built_q(ba) ) call bl_error("BOXARRAY_BUILD_COPY: already built")
if ( .not. built_q(ba1) ) return
ba%nboxes = size(ba1%bxs)
allocate(ba%bxs(size(ba1%bxs)))
ba%bxs = ba1%bxs
ba%dim = ba1%dim
call boxarray_verify_dim(ba)
call mem_stats_alloc(boxarray_ms, ba%nboxes)
end subroutine boxarray_build_copy
subroutine boxarray_build_copy_l(ba, bl)
type(boxarray), intent(inout) :: ba
type(list_box), intent(in) :: bl
if ( built_q(ba) ) call destroy(ba)
call boxarray_build_l(ba, bl)
end subroutine boxarray_build_copy_l
subroutine boxarray_build_v(ba, bxs, sort)
use bl_error_module
type(boxarray), intent(inout) :: ba
type(box), intent(in), dimension(:) :: bxs
logical, intent(in), optional :: sort
logical :: lsort
lsort = .false. ; if (present(sort)) lsort = sort
if ( built_q(ba) ) call bl_error("BOXARRAY_BUILD_V: already built")
ba%nboxes = size(bxs)
allocate(ba%bxs(size(bxs)))
ba%bxs = bxs
if ( ba%nboxes > 0 ) then
ba%dim = ba%bxs(1)%dim
end if
call boxarray_verify_dim(ba)
if (lsort) call boxarray_sort(ba) !! make sure all grids are sorted
call mem_stats_alloc(boxarray_ms, ba%nboxes)
end subroutine boxarray_build_v
subroutine boxarray_build_bx(ba, bx)
use bl_error_module
type(boxarray), intent(inout) :: ba
type(box), intent(in) :: bx
if ( built_q(ba) ) call bl_error("BOXARRAY_BUILD_BX: already built")
ba%nboxes = 1
allocate(ba%bxs(1))
ba%bxs(1) = bx
ba%dim = bx%dim
call boxarray_verify_dim(ba)
call mem_stats_alloc(boxarray_ms, ba%nboxes)
end subroutine boxarray_build_bx
subroutine boxarray_build_l(ba, bl, sort)
use bl_error_module
type(boxarray), intent(inout) :: ba
type(list_box), intent(in) :: bl
logical, intent(in), optional :: sort
type(list_box_node), pointer :: bln
logical :: lsort
integer :: i
!
! Default is to sort.
!
lsort = .true. ; if ( present(sort) ) lsort = sort
if ( built_q(ba) ) call bl_error("BOXARRAY_BUILD_L: already built")
ba%nboxes = size(bl)
allocate(ba%bxs(ba%nboxes))
bln => begin(bl)
i = 1
do while (associated(bln))
ba%bxs(i) = value(bln)
i = i + 1
bln=>next(bln)
end do
if ( ba%nboxes > 0 ) then
ba%dim = ba%bxs(1)%dim
end if
call boxarray_verify_dim(ba)
if ( lsort ) call boxarray_sort(ba)
call mem_stats_alloc(boxarray_ms, ba%nboxes)
end subroutine boxarray_build_l
subroutine boxarray_destroy(ba)
type(boxarray), intent(inout) :: ba
if ( associated(ba%bxs) ) then
call mem_stats_dealloc(boxarray_ms, ba%nboxes)
deallocate(ba%bxs)
ba%bxs => Null()
end if
ba%dim = 0
ba%nboxes = 0
end subroutine boxarray_destroy
subroutine boxarray_sort(ba)
use sort_box_module
type(boxarray), intent(inout) :: ba
call box_sort(ba%bxs)
end subroutine boxarray_sort
subroutine boxarray_verify_dim(ba, stat)
use bl_error_module
type(boxarray), intent(in) :: ba
integer, intent(out), optional :: stat
integer :: i, dm
if ( present(stat) ) stat = 0
if ( ba%nboxes < 1 ) return
dm = ba%dim
if ( dm == 0 ) then
dm = ba%bxs(1)%dim
end if
if ( dm == 0 ) then
call bl_error("BOXARRAY_VERIFY_DIM: dim is zero!")
end if
do i = 1, ba%nboxes
if ( ba%dim /= ba%bxs(i)%dim ) then
if ( present(stat) ) then
stat = 1
return
else
call bl_error("BOXARRAY_VERIFY_DIM: " // &
"ba%dim not equal to some boxes dim: ", ba%dim)
end if
end if
end do
end subroutine boxarray_verify_dim
subroutine boxarray_grow_v(ba, rv)
type(boxarray), intent(inout) :: ba
integer, intent(in) :: rv(:)
integer :: i
!$OMP PARALLEL DO
do i = 1, ba%nboxes
ba%bxs(i) = grow(ba%bxs(i), rv)
end do
!$OMP END PARALLEL DO
end subroutine boxarray_grow_v
subroutine boxarray_grow_v_f(ba, rv, face)
type(boxarray), intent(inout) :: ba
integer, intent(in) :: rv(:), face
integer :: i
!$OMP PARALLEL DO
do i = 1, ba%nboxes
ba%bxs(i) = grow(ba%bxs(i), rv, face)
end do
!$OMP END PARALLEL DO
end subroutine boxarray_grow_v_f
subroutine boxarray_grow_n(ba, n)
type(boxarray), intent(inout) :: ba
integer, intent(in) :: n
integer :: i
!$OMP PARALLEL DO
do i = 1, ba%nboxes
ba%bxs(i) = grow(ba%bxs(i), n)
end do
!$OMP END PARALLEL DO
end subroutine boxarray_grow_n
subroutine boxarray_grow_n_f(ba, n, face)
type(boxarray), intent(inout) :: ba
integer, intent(in) :: n, face
integer :: i
!$OMP PARALLEL DO
do i = 1, ba%nboxes
ba%bxs(i) = grow(ba%bxs(i), n, face)
end do
!$OMP END PARALLEL DO
end subroutine boxarray_grow_n_f
subroutine boxarray_grow_n_d_f(ba, n, dim, face)
type(boxarray), intent(inout) :: ba
integer, intent(in) :: n, face, dim
integer :: i
!$OMP PARALLEL DO
do i = 1, ba%nboxes
ba%bxs(i) = grow(ba%bxs(i), n, dim, face)
end do
!$OMP END PARALLEL DO
end subroutine boxarray_grow_n_d_f
subroutine boxarray_nodalize(ba, nodal)
type(boxarray), intent(inout) :: ba
logical, intent(in), optional :: nodal(:)
integer :: i
!$OMP PARALLEL DO
do i = 1, ba%nboxes
ba%bxs(i) = box_nodalize(ba%bxs(i), nodal)
end do
!$OMP END PARALLEL DO
end subroutine boxarray_nodalize
pure function boxarray_projectable(ba, rr) result(r)
logical :: r
type(boxarray), intent(in) :: ba
integer, intent(in) :: rr(:)
integer :: i
r = .true.
do i = 1, nboxes(ba)
if ( .not. box_projectable(ba%bxs(i), rr) ) then
r = .false.
exit
end if
end do
end function boxarray_projectable
subroutine boxarray_coarsen_v_m(ba, cv, mask)
type(boxarray), intent(inout) :: ba
integer, intent(in) :: cv(:)
logical, intent(in) :: mask(:)
integer :: i
!$OMP PARALLEL DO
do i = 1, ba%nboxes
ba%bxs(i) = coarsen(ba%bxs(i), cv, mask)
end do
!$OMP END PARALLEL DO
end subroutine boxarray_coarsen_v_m
subroutine boxarray_coarsen_v(ba, cv)
type(boxarray), intent(inout) :: ba
integer, intent(in) :: cv(:)
integer :: i
!$OMP PARALLEL DO
do i = 1, ba%nboxes
ba%bxs(i) = coarsen(ba%bxs(i), cv)
end do
!$OMP END PARALLEL DO
end subroutine boxarray_coarsen_v
subroutine boxarray_coarsen_i_m(ba, ci, mask)
type(boxarray), intent(inout) :: ba
integer, intent(in) :: ci
logical, intent(in) :: mask(:)
integer :: i
!$OMP PARALLEL DO
do i = 1, ba%nboxes
ba%bxs(i) = coarsen(ba%bxs(i), ci, mask)
end do
!$OMP END PARALLEL DO
end subroutine boxarray_coarsen_i_m
subroutine boxarray_coarsen_i(ba, ci)
type(boxarray), intent(inout) :: ba
integer, intent(in) :: ci
integer :: i
!$OMP PARALLEL DO
do i = 1, ba%nboxes
ba%bxs(i) = coarsen(ba%bxs(i), ci)
end do
!$OMP END PARALLEL DO
end subroutine boxarray_coarsen_i
subroutine boxarray_shift_v(ba, rv)
type(boxarray), intent(inout) :: ba
integer, intent(in) :: rv(:)
integer :: i
!$OMP PARALLEL DO
do i = 1, ba%nboxes
ba%bxs(i) = shift(ba%bxs(i), rv)
end do
!$OMP END PARALLEL DO
end subroutine boxarray_shift_v
subroutine boxarray_shift_i(ba, ri)
type(boxarray), intent(inout) :: ba
integer, intent(in) :: ri
integer :: i
!$OMP PARALLEL DO
do i = 1, ba%nboxes
ba%bxs(i) = shift(ba%bxs(i), ri)
end do
!$OMP END PARALLEL DO
end subroutine boxarray_shift_i
subroutine boxarray_refine_v(ba, rv)
type(boxarray), intent(inout) :: ba
integer, intent(in) :: rv(:)
integer :: i
!$OMP PARALLEL DO
do i = 1, ba%nboxes
ba%bxs(i) = refine(ba%bxs(i), rv)
end do
!$OMP END PARALLEL DO
end subroutine boxarray_refine_v
subroutine boxarray_refine_i(ba, ri)
type(boxarray), intent(inout) :: ba
integer, intent(in) :: ri
integer :: i
!$OMP PARALLEL DO
do i = 1, ba%nboxes
ba%bxs(i) = refine(ba%bxs(i), ri)
end do
!$OMP END PARALLEL DO
end subroutine boxarray_refine_i
!
! This is a very naive implementation.
!
subroutine boxarray_intersection_bx(ba, bx)
type(boxarray), intent(inout) :: ba
type(box), intent(in) :: bx
integer :: i
!$OMP PARALLEL DO
do i = 1, ba%nboxes
ba%bxs(i) = intersection(ba%bxs(i), bx)
end do
!$OMP END PARALLEL DO
call boxarray_simplify(ba)
end subroutine boxarray_intersection_bx
subroutine boxarray_box_boundary_n(bao, bx, n)
type(boxarray), intent(out) :: bao
type(box), intent(in) :: bx
integer, intent(in) :: n
type(boxarray) :: baa
call boxarray_build_bx(baa, bx)
call boxarray_boundary_n(bao, baa, n)
call boxarray_destroy(baa)
end subroutine boxarray_box_boundary_n
subroutine boxarray_boundary_n_d_f(bao, ba, n, dim, face)
type(boxarray), intent(out) :: bao
type(boxarray), intent(in) :: ba
integer, intent(in) :: n, face, dim
call boxarray_build_copy(bao, ba)
call boxarray_grow(bao, n, dim, face)
call boxarray_diff(bao, ba)
end subroutine boxarray_boundary_n_d_f
subroutine boxarray_boundary_n(bao, ba, n)
type(boxarray), intent(out) :: bao
type(boxarray), intent(in) :: ba
integer, intent(in) :: n
call boxarray_build_copy(bao, ba)
call boxarray_grow(bao, n)
call boxarray_diff(bao, ba)
end subroutine boxarray_boundary_n
pure function boxarray_nboxes(ba) result(r)
type(boxarray), intent(in) :: ba
integer :: r
r = ba%nboxes
end function boxarray_nboxes
pure function boxlist_nboxes(bl) result(r)
type(list_box), intent(in) :: bl
integer :: r
r = size(bl)
end function boxlist_nboxes
function boxarray_volume(ba) result(r)
type(boxarray), intent(in) :: ba
integer(kind=ll_t) :: r
integer :: i
r = 0_ll_t
!$OMP PARALLEL DO REDUCTION(+:r)
do i = 1, ba%nboxes
r = r + box_volume(ba%bxs(i))
end do
!$OMP END PARALLEL DO
end function boxarray_volume
function boxarray_dvolume(ba) result(r)
type(boxarray), intent(in) :: ba
real(dp_t) :: r
integer :: i
r = 0_dp_t
!$OMP PARALLEL DO REDUCTION(+:r)
do i = 1, ba%nboxes
r = r + box_dvolume(ba%bxs(i))
end do
!$OMP END PARALLEL DO
end function boxarray_dvolume
pure function boxarray_bbox(ba) result(r)
type(boxarray), intent(in) :: ba
type(box) :: r
integer :: i
r = nobox(ba%dim)
do i = 1, ba%nboxes
r = bbox(r, ba%bxs(i))
end do
end function boxarray_bbox
subroutine boxarray_box_diff(ba, b1, b2)
type(boxarray), intent(out) :: ba
type(box), intent(in) :: b1, b2
type(list_box) :: bl
bl = boxlist_box_diff(b1, b2)
call boxarray_build_l(ba, bl)
call destroy(bl)
end subroutine boxarray_box_diff
subroutine boxarray_diff(bao, ba)
type(boxarray), intent(inout) :: bao
type(boxarray), intent(in) :: ba
type(list_box) :: bl, bl1, bl2
integer :: i
call build(bl1, ba%bxs)
do i = 1, bao%nboxes
bl2 = boxlist_boxlist_diff(bao%bxs(i), bl1)
call splice(bl, bl2)
end do
call boxarray_destroy(bao)
call boxarray_build_l(bao, bl)
call destroy(bl)
call destroy(bl1)
end subroutine boxarray_diff
subroutine boxarray_maxsize_i(bxa, chunk)
type(boxarray), intent(inout) :: bxa
integer, intent(in) :: chunk
integer :: vchunk(bxa%dim)
vchunk = chunk
call boxarray_maxsize_v(bxa, vchunk)
end subroutine boxarray_maxsize_i
subroutine boxarray_maxsize_v(bxa, chunk)
type(boxarray), intent(inout) :: bxa
integer, intent(in), dimension(:) :: chunk
type(list_box) :: bl
bl = boxarray_maxsize_l(bxa, chunk)
call boxarray_destroy(bxa)
call boxarray_build_l(bxa, bl)
call destroy(bl)
end subroutine boxarray_maxsize_v
function boxarray_maxsize_l(bxa, chunk) result(r)
type(list_box) :: r
type(boxarray), intent(in) :: bxa
integer, intent(in), dimension(:) :: chunk
integer :: i,k
type(list_box_node), pointer :: li
integer :: len(bxa%dim)
integer :: nl, bs, rt, nblk, sz, ex, ks, ps
type(box) :: bxr, bxl
do i = 1, bxa%nboxes
call push_back(r, bxa%bxs(i))
end do
li => begin(r)
do while ( associated(li) )
len = extent(value(li))
do i = 1, bxa%dim
if ( len(i) > chunk(i) ) then
rt = 1
bs = chunk(i)
nl = len(i)
do while ( mod(bs,2) == 0 .AND. mod(nl,2) == 0)
rt = rt * 2
bs = bs/2
nl = nl/2
end do
nblk = nl/bs
if ( mod(nl,bs) /= 0 ) nblk = nblk + 1
sz = nl/nblk
ex = mod(nl,nblk)
do k = 0, nblk-2
if ( k < ex ) then
ks = (sz+1)*rt
else
ks = sz*rt
end if
ps = upb(value(li), i) - ks + 1
call box_chop(value(li), bxr, bxl, i, ps)
call set(li, bxr)
call push_back(r, bxl)
end do
end if
end do
li => next(li)
end do
end function boxarray_maxsize_l
subroutine boxarray_simplify(bxa)
type(boxarray), intent(inout) :: bxa
type(list_box) :: bxl
call build(bxl, bxa%bxs)
call boxlist_simplify(bxl)
call boxarray_destroy(bxa)
call boxarray_build_l(bxa, bxl)
call destroy(bxl)
end subroutine boxarray_simplify
subroutine boxarray_print(ba, str, unit, legacy, skip)
use bl_IO_module
type(boxarray), intent(in) :: ba
character (len=*), intent(in), optional :: str
integer, intent(in), optional :: unit
logical, intent(in), optional :: legacy
integer, intent(in), optional :: skip
integer :: i
integer :: un
un = unit_stdout(unit)
call unit_skip(un, skip)
write(unit=un, fmt = '("BOXARRAY[(*")', advance = 'no')
if ( present(str) ) then
write(unit=un, fmt='(" ",A)') str
else
write(unit=un, fmt='()')
end if
call unit_skip(un, skip)
write(unit=un, fmt='(" DIM = ",i5)') ba%dim
call unit_skip(un, skip)
write(unit=un, fmt='(" NBOXES = ",i5)') ba%nboxes
call unit_skip(un, skip)
write(unit=un, fmt='(" *) {")')
do i = 1, ba%nboxes
call print(ba%bxs(i), unit=unit, advance = 'NO', &
legacy = legacy, skip = unit_get_skip(skip)+ 1)
if ( i == ba%nboxes ) then
write(unit=un, fmt='("}]")')
else
write(unit=un, fmt='(",")')
end if
end do
end subroutine boxarray_print
function boxarray_clean(boxes) result(r)
logical :: r
type(box), intent(in), dimension(:) :: boxes
integer :: i, j
do i = 1, size(boxes)-1
do j = i+1, size(boxes)
if ( intersects(boxes(i),boxes(j)) ) then
r = .FALSE.
return
end if
end do
end do
r = .TRUE.
end function boxarray_clean
subroutine boxarray_add_clean(ba, bx)
use bl_prof_module
type(boxarray), intent(inout) :: ba
type(box), intent(in) :: bx
type(list_box) :: check, tmp, tmpbl, bl
type(list_box_node), pointer :: cp, lp
type(bl_prof_timer), save :: bpt
if ( empty(ba) ) then
call boxarray_build_bx(ba, bx)
return
end if
call build(bpt, "ba_add_clean")
call list_build_v_box(bl, ba%bxs)
call push_back(check, bx)
lp => begin(bl)
do while ( associated(lp) )
cp => begin(check)
do while ( associated(cp) )
if ( intersects(value(cp), value(lp)) ) then
tmpbl = boxlist_box_diff(value(cp), value(lp))
call splice(tmp, tmpbl)
cp => erase(check, cp)
else
cp => next(cp)
end if
end do
call splice(check, tmp)
lp => next(lp)
end do
call splice(bl, check)
call boxlist_simplify(bl)
call boxarray_build_copy_l(ba, bl)
call list_destroy_box(bl)
call destroy(bpt)
end subroutine boxarray_add_clean
subroutine boxarray_add_clean_boxes(ba, bxs, simplify)
use bl_prof_module
type(boxarray), intent(inout) :: ba
type(box), intent(in) :: bxs(:)
logical, intent(in), optional :: simplify
logical :: lsimplify
type(list_box) :: check, tmp, tmpbl, bl
type(list_box_node), pointer :: cp, lp
integer :: i
type(bl_prof_timer), save :: bpt
call build(bpt, "ba_add_clean_boxes")
lsimplify = .true.; if ( present(simplify) ) lsimplify = simplify
if ( size(bxs) .eq. 0 ) return
if ( empty(ba) ) call boxarray_build_bx(ba, bxs(1))
call list_build_v_box(bl, ba%bxs)
do i = 1, size(bxs)
call list_build_v_box(check, bxs(i:i))
lp => begin(bl)
do while ( associated(lp) )
cp => begin(check)
do while ( associated(cp) )
if ( intersects(value(cp), value(lp)) ) then
tmpbl = boxlist_box_diff(value(cp), value(lp))
call splice(tmp, tmpbl)
cp => erase(check, cp)
else
cp => next(cp)
end if
end do
call splice(check, tmp)
lp => next(lp)
end do
call splice(bl, check)
end do
if ( lsimplify ) call boxlist_simplify(bl)
call boxarray_build_copy_l(ba, bl)
call list_destroy_box(bl)
call destroy(bpt)
end subroutine boxarray_add_clean_boxes
subroutine boxarray_to_domain(ba)
type(boxarray), intent(inout) :: ba
type(boxarray) :: ba1
call boxarray_add_clean_boxes(ba1, ba%bxs)
call boxarray_destroy(ba)
ba = ba1
end subroutine boxarray_to_domain
function boxarray_box_contains(ba, bx) result(r)
use bl_error_module
logical :: r
type(boxarray), intent(in) :: ba
type(box), intent(in) :: bx
type(list_box) :: bl1, bl
type(box) :: bx1
integer :: i
if ( nboxes(ba) .eq. 0 ) &
call bl_error('Empty boxarray in boxarray_box_contains')
call build(bl1)
do i = 1, nboxes(ba)
bx1 = intersection(bx, get_box(ba,i))
if ( empty(bx1) ) cycle
call push_back(bl1, bx1)
end do
bl = boxlist_boxlist_diff(bx, bl1)
r = empty(bl)
call destroy(bl)
call destroy(bl1)
end function boxarray_box_contains
function boxarray_boxarray_contains(ba1, ba2) result(r)
use bl_error_module
logical :: r
type(boxarray), intent(in) :: ba1, ba2
integer :: i
if ( nboxes(ba1) .eq. 0 ) &
call bl_error('Empty boxarray ba1 in boxarray_boxarray_contains')
if ( nboxes(ba2) .eq. 0 ) &
call bl_error('Empty boxarray ba2 in boxarray_boxarray_contains')
do i = 1, nboxes(ba2)
r = boxarray_box_contains(ba1, get_box(ba2,i))
if ( .not. r ) return
end do
r = .true.
end function boxarray_boxarray_contains
end module boxarray_module