-
Notifications
You must be signed in to change notification settings - Fork 89
Expand file tree
/
Copy pathRefineSchedule.cpp
More file actions
5490 lines (4659 loc) · 195 KB
/
Copy pathRefineSchedule.cpp
File metadata and controls
5490 lines (4659 loc) · 195 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
/*************************************************************************
*
* This file is part of the SAMRAI distribution. For full copyright
* information, see COPYRIGHT and LICENSE.
*
* Copyright: (c) 1997-2025 Lawrence Livermore National Security, LLC
* Description: Refine schedule for data transfer between AMR levels
*
************************************************************************/
#include "SAMRAI/xfer/RefineSchedule.h"
#include "SAMRAI/xfer/BoxGeometryVariableFillPattern.h"
#include "SAMRAI/xfer/PatchLevelFullFillPattern.h"
#include "SAMRAI/xfer/PatchLevelInteriorFillPattern.h"
#include "SAMRAI/xfer/RefineCopyTransaction.h"
#include "SAMRAI/xfer/RefineScheduleConnectorWidthRequestor.h"
#include "SAMRAI/xfer/RefineTimeTransaction.h"
#include "SAMRAI/hier/BoxContainer.h"
#include "SAMRAI/hier/BoxGeometry.h"
#include "SAMRAI/hier/BoxOverlap.h"
#include "SAMRAI/hier/BoxUtilities.h"
#include "SAMRAI/hier/BoxLevelConnectorUtils.h"
#include "SAMRAI/hier/MappingConnectorAlgorithm.h"
#include "SAMRAI/hier/OverlapConnectorAlgorithm.h"
#include "SAMRAI/hier/PeriodicShiftCatalog.h"
#include "SAMRAI/hier/Patch.h"
#include "SAMRAI/hier/PatchData.h"
#include "SAMRAI/hier/PatchGeometry.h"
#include "SAMRAI/tbox/AsyncCommPeer.h"
#include "SAMRAI/tbox/MathUtilities.h"
#include "SAMRAI/tbox/InputManager.h"
#include "SAMRAI/tbox/OpenMPUtilities.h"
#include "SAMRAI/tbox/StagedKernelFusers.h"
#include "SAMRAI/tbox/StartupShutdownManager.h"
#include "SAMRAI/tbox/TimerManager.h"
#include "SAMRAI/tbox/Utilities.h"
#include "SAMRAI/tbox/NVTXUtilities.h"
#include "SAMRAI/tbox/Collectives.h"
#if !defined(__BGL_FAMILY__) && defined(__xlC__)
/*
* Suppress XLC warnings
*/
#pragma report(disable, CPPC5334)
#pragma report(disable, CPPC5328)
#endif
namespace SAMRAI {
namespace xfer {
bool RefineSchedule::s_extra_debug = false;
bool RefineSchedule::s_barrier_and_time = false;
bool RefineSchedule::s_read_static_input = false;
std::shared_ptr<tbox::Timer> RefineSchedule::t_refine_schedule;
std::shared_ptr<tbox::Timer> RefineSchedule::t_fill_data;
std::shared_ptr<tbox::Timer> RefineSchedule::t_fill_data_nonrecursive;
std::shared_ptr<tbox::Timer> RefineSchedule::t_fill_data_recursive;
std::shared_ptr<tbox::Timer> RefineSchedule::t_fill_physical_boundaries;
std::shared_ptr<tbox::Timer> RefineSchedule::t_fill_singularity_boundaries;
std::shared_ptr<tbox::Timer> RefineSchedule::t_refine_scratch_data;
std::shared_ptr<tbox::Timer> RefineSchedule::t_finish_sched_const;
std::shared_ptr<tbox::Timer> RefineSchedule::t_finish_sched_const_recurse;
std::shared_ptr<tbox::Timer> RefineSchedule::t_gen_comm_sched;
std::shared_ptr<tbox::Timer> RefineSchedule::t_shear;
std::shared_ptr<tbox::Timer> RefineSchedule::t_get_global_box_count;
std::shared_ptr<tbox::Timer> RefineSchedule::t_coarse_shear;
std::shared_ptr<tbox::Timer> RefineSchedule::t_setup_coarse_interp_box_level;
std::shared_ptr<tbox::Timer> RefineSchedule::t_bridge_coarse_interp_hiercoarse;
std::shared_ptr<tbox::Timer> RefineSchedule::t_bridge_dst_hiercoarse;
std::shared_ptr<tbox::Timer> RefineSchedule::t_invert_edges;
std::shared_ptr<tbox::Timer> RefineSchedule::t_construct_send_trans;
std::shared_ptr<tbox::Timer> RefineSchedule::t_construct_recv_trans;
tbox::StartupShutdownManager::Handler
RefineSchedule::s_initialize_finalize_handler(
RefineSchedule::initializeCallback,
0,
0,
RefineSchedule::finalizeCallback,
tbox::StartupShutdownManager::priorityTimers);
/*
**************************************************************************
*
* Create a refine schedule that copies data from the source level into
* the destination level on the components represented by the refine
* classes. Ony data on the intersection of the two levels will be
* copied. It is assumed that the index spaces of the source and
* destination levels are "consistent"; i.e., they represent the same
* grid resolution. The levels do not have to be part of the same
* AMR patch hierarchy, however.
*
**************************************************************************
*/
RefineSchedule::RefineSchedule(
const std::shared_ptr<PatchLevelFillPattern>& dst_level_fill_pattern,
const std::shared_ptr<hier::PatchLevel>& dst_level,
const std::shared_ptr<hier::PatchLevel>& src_level,
const std::shared_ptr<RefineClasses>& refine_classes,
const std::shared_ptr<RefineTransactionFactory>& transaction_factory,
RefinePatchStrategy* patch_strategy,
bool use_time_refinement):
d_number_refine_items(0),
d_refine_items(0),
d_dst_level(dst_level),
d_src_level(src_level),
d_refine_patch_strategy(patch_strategy),
d_singularity_patch_strategy(dynamic_cast<SingularityPatchStrategy *>(patch_strategy)),
d_transaction_factory(transaction_factory),
d_max_stencil_width(dst_level->getDim()),
d_max_scratch_gcw(dst_level->getDim()),
d_boundary_fill_ghost_width(dst_level->getDim()),
d_force_boundary_fill(false),
d_num_periodic_directions(0),
d_periodic_shift(dst_level->getDim()),
d_coarse_priority_level_schedule(std::make_shared<tbox::Schedule>()),
d_fine_priority_level_schedule(std::make_shared<tbox::Schedule>()),
d_encon_level(std::make_shared<hier::PatchLevel>(dst_level->getDim())),
d_dst_to_src(0),
d_max_fill_boxes(0),
d_dst_level_fill_pattern(dst_level_fill_pattern),
d_top_refine_schedule(this),
d_internal_allocated(false)
{
TBOX_ASSERT(dst_level);
TBOX_ASSERT(src_level);
TBOX_ASSERT(refine_classes);
TBOX_ASSERT(transaction_factory);
#ifdef DEBUG_CHECK_DIM_ASSERTIONS
TBOX_ASSERT_OBJDIM_EQUALITY2(*dst_level, *src_level);
#endif
getFromInput();
if (s_barrier_and_time) {
t_refine_schedule->barrierAndStart();
}
if (d_dst_level->getGridGeometry()->getNumberOfBlockSingularities() > 0 &&
!d_singularity_patch_strategy && d_refine_patch_strategy) {
TBOX_ERROR("RefineSchedule: Schedules for meshes with singularities\n"
<< "requires a SingularityPatchStrategy implementation along\n"
<< "with the RefinePatchStrategy. To do this,\n"
<< "inherit SinglarityPatchStrategy with the user class\n"
<< "that inherited RefinePatchStrategy and implement\n"
<< "the SingularityPatchStrategy pure virtual methods.");
}
setRefineItems(refine_classes);
initialCheckRefineClassItems();
d_domain_is_one_box.resize(
d_dst_level->getGridGeometry()->getNumberBlocks(), false);
d_coarse_priority_level_schedule->setTimerPrefix("xfer::RefineSchedule_fill");
d_fine_priority_level_schedule->setTimerPrefix("xfer::RefineSchedule_fill");
/*
* Initialize destination level, ghost cell widths,
* and domain information data members.
*/
initializeDomainAndGhostInformation();
hier::IntVector min_connector_width(getMinConnectorWidth());
if (!d_dst_level_fill_pattern->fillingCoarseFineGhosts()) {
min_connector_width = hier::IntVector::getZero(dst_level->getDim());
}
d_dst_to_src = &d_dst_level->findConnectorWithTranspose(*d_src_level,
min_connector_width,
hier::Connector::convertHeadWidthToBase(
d_src_level->getBoxLevel()->getRefinementRatio(),
d_dst_level->getBoxLevel()->getRefinementRatio(),
min_connector_width),
hier::CONNECTOR_IMPLICIT_CREATION_RULE,
true);
hier::Connector& src_to_dst = d_dst_to_src->getTranspose();
TBOX_ASSERT(d_dst_to_src->getBase() == *d_dst_level->getBoxLevel());
TBOX_ASSERT(src_to_dst.getHead() == *d_dst_level->getBoxLevel());
#ifdef DEBUG_CHECK_ASSERTIONS
if (d_dst_level_fill_pattern->fillingCoarseFineGhosts()) {
TBOX_ASSERT(d_dst_to_src->getConnectorWidth() >= d_max_scratch_gcw);
TBOX_ASSERT(d_dst_to_src->getConnectorWidth() >= d_boundary_fill_ghost_width);
}
#endif
if (s_extra_debug) {
/*
* This check may be redundant because
* PersistentOverlapConnectors should already guarantee
* completeness.
*/
d_dst_to_src->assertOverlapCorrectness();
src_to_dst.assertOverlapCorrectness();
}
/*
* Create fill_box_level, representing all parts of the
* destination level, including ghost regions if desired, that this
* schedule will attempt to fill.
*/
std::shared_ptr<hier::BoxLevel> fill_box_level;
std::shared_ptr<hier::Connector> dst_to_fill;
hier::BoxNeighborhoodCollection dst_to_fill_on_src_proc;
setDefaultFillBoxLevel(
fill_box_level,
dst_to_fill,
dst_to_fill_on_src_proc);
/*
* Generation the communication transactions that will move data from
* the source to the destination. generateCommunicationSchedule will
* initialize the "unused" objects with information about the parts of
* fill_box_level that cannot be filled from the source level.
* They are unused because this RefineSchedule constructor creates
* schedules that do not do anything to fill the parts of the
* destination that can't be filled directly from the source.
*/
std::shared_ptr<hier::BoxLevel> unused_unfilled_box_level;
std::shared_ptr<hier::Connector> unused_dst_to_unfilled;
std::shared_ptr<hier::BoxLevel> unused_unfilled_encon_box_level;
std::shared_ptr<hier::Connector> unused_encon_to_unfilled_encon;
bool create_transactions = true;
generateCommunicationSchedule(
unused_unfilled_box_level,
unused_dst_to_unfilled,
unused_unfilled_encon_box_level,
unused_encon_to_unfilled_encon,
*dst_to_fill,
dst_to_fill_on_src_proc,
use_time_refinement,
create_transactions);
if (d_coarse_interp_level) {
computeRefineOverlaps(d_refine_overlaps,
d_dst_level,
d_coarse_interp_level,
d_dst_to_coarse_interp->getTranspose(),
*d_coarse_interp_to_unfilled);
}
if (d_coarse_interp_encon_level) {
computeRefineOverlaps(d_encon_refine_overlaps,
d_encon_level,
d_coarse_interp_encon_level,
d_encon_to_coarse_interp_encon->getTranspose(),
*d_coarse_interp_encon_to_unfilled_encon);
}
if (s_barrier_and_time) {
t_refine_schedule->barrierAndStop();
}
}
/*
**************************************************************************
*
* Create a refine schedule that copies data from the source level into
* the destination level on the components represented by the refine
* classes. If portions of the destination level remain unfilled, then
* the algorithm recursively fills those unfilled portions from coarser
* levels in the AMR hierarchy. It is assumed that the index spaces of
* the source and destination levels are "consistent"; i.e., they
* represent the same grid resolution. Also, the next coarser level
* integer argument must be the number of level in the specified
* hierarchy representing the next coarser level of mesh resolution to
* the destination level.
*
* IMPORTANT NOTES: The source level may be NULL, in which case the
* destination level will be filled only using data interpolated from
* coarser levels in the AMR hierarchy. The hierarchy may be NULL only
* if the next coarser level is -1 (that is, there is no coarser level).
*
**************************************************************************
*/
RefineSchedule::RefineSchedule(
const std::shared_ptr<PatchLevelFillPattern>& dst_level_fill_pattern,
const std::shared_ptr<hier::PatchLevel>& dst_level,
const std::shared_ptr<hier::PatchLevel>& src_level,
int next_coarser_ln,
const std::shared_ptr<hier::PatchHierarchy>& hierarchy,
const std::shared_ptr<RefineClasses>& refine_classes,
const std::shared_ptr<RefineTransactionFactory>& transaction_factory,
RefinePatchStrategy* patch_strategy,
bool use_time_refinement):
d_number_refine_items(0),
d_refine_items(0),
d_dst_level(dst_level),
d_src_level(src_level),
d_refine_patch_strategy(patch_strategy),
d_singularity_patch_strategy(dynamic_cast<SingularityPatchStrategy *>(patch_strategy)),
d_transaction_factory(transaction_factory),
d_max_stencil_width(dst_level->getDim()),
d_max_scratch_gcw(dst_level->getDim()),
d_boundary_fill_ghost_width(dst_level->getDim()),
d_force_boundary_fill(false),
d_num_periodic_directions(0),
d_periodic_shift(dst_level->getDim()),
d_encon_level(std::make_shared<hier::PatchLevel>(dst_level->getDim())),
d_dst_to_src(0),
d_max_fill_boxes(0),
d_dst_level_fill_pattern(dst_level_fill_pattern),
d_top_refine_schedule(this),
d_internal_allocated(false)
{
TBOX_ASSERT(dst_level);
TBOX_ASSERT((next_coarser_ln == -1) || hierarchy);
TBOX_ASSERT(refine_classes);
TBOX_ASSERT(transaction_factory);
#ifdef DEBUG_CHECK_DIM_ASSERTIONS
if (src_level) {
TBOX_ASSERT_OBJDIM_EQUALITY2(*dst_level, *src_level);
}
if (hierarchy) {
TBOX_ASSERT_OBJDIM_EQUALITY2(*dst_level, *hierarchy);
}
#endif
getFromInput();
if (s_barrier_and_time) {
t_refine_schedule->barrierAndStart();
}
const tbox::Dimension& dim(dst_level->getDim());
if (dst_level->getGridGeometry()->getNumberOfBlockSingularities() > 0 &&
!d_singularity_patch_strategy && d_refine_patch_strategy) {
TBOX_ERROR("RefineSchedule: Schedules for meshes with singularities\n"
<< "requires a SingularityPatchStrategy implementation along\n"
<< "with the RefinePatchStrategy. To do this,\n"
<< "inherit SinglarityPatchStrategy with the user class\n"
<< "that inherited RefinePatchStrategy and implement\n"
<< "the SingularityPatchStrategy pure virtual methods.");
}
setRefineItems(refine_classes);
initialCheckRefineClassItems();
d_domain_is_one_box.resize(
dst_level->getGridGeometry()->getNumberBlocks(), false);
/*
* Initialize destination level, ghost cell widths,
* and domain information data members.
*/
initializeDomainAndGhostInformation();
hier::IntVector min_connector_width(getMinConnectorWidth());
if (d_src_level &&
d_src_level->getRatioToLevelZero() != d_dst_level->getRatioToLevelZero()) {
if (d_src_level->getRatioToLevelZero() >= d_dst_level->getRatioToLevelZero()) {
const hier::IntVector src_dst_ratio =
d_src_level->getRatioToLevelZero() / d_dst_level->getRatioToLevelZero();
if (d_dst_level->getRatioToLevelZero() * src_dst_ratio !=
d_src_level->getRatioToLevelZero()) {
TBOX_ERROR("RefineSchedule::RefineSchedule error: source and destination\n"
<< "levels must be a simple refinement of one another.\n"
<< "src resolution: " << d_src_level->getRatioToLevelZero() << "\n"
<< "dst resolution: " << d_dst_level->getRatioToLevelZero());
}
min_connector_width *= src_dst_ratio;
} else if (d_src_level->getRatioToLevelZero() <= d_dst_level->getRatioToLevelZero()) {
TBOX_ERROR("RefineSchedule:RefineSchedule error: We are not currently\n"
<< "supporting RefineSchedules with the source level finer\n"
<< "than the destination level.");
} else {
TBOX_ERROR("RefineSchedule::RefineSchedule error: src level may not be\n"
<< "coarser than dst level in one direction and finer in another.\n"
<< "src resolution: " << d_src_level->getRatioToLevelZero() << "\n"
<< "dst resolution: " << d_dst_level->getRatioToLevelZero());
}
}
if (next_coarser_ln >= 0) {
RefineScheduleConnectorWidthRequestor rscwr;
if (hierarchy->getNumberOfLevels() > next_coarser_ln + 1) {
if (d_dst_level->getRatioToLevelZero() !=
hierarchy->getPatchLevel(next_coarser_ln + 1)->getRatioToLevelZero()) {
hier::IntVector expansion_ratio =
hierarchy->getPatchLevel(next_coarser_ln+1)->getRatioToLevelZero() / d_dst_level->getRatioToLevelZero();
#ifdef DEBUG_CHECK_ASSERTIONS
TBOX_ASSERT( expansion_ratio * d_dst_level->getRatioToLevelZero() == hierarchy->getPatchLevel(next_coarser_ln+1)->getRatioToLevelZero() );
// All values in expansion_ratio must be identical.
TBOX_ASSERT( hier::IntVector(dim,expansion_ratio(0,0),expansion_ratio.getNumBlocks()) == expansion_ratio );
#endif
rscwr.setGhostCellWidthFactor(expansion_ratio(0,0));
}
}
rscwr.computeRequiredFineConnectorWidthsForRecursiveRefinement(
d_fine_connector_widths,
min_connector_width,
d_max_stencil_width,
*hierarchy,
next_coarser_ln + 1);
}
std::shared_ptr<hier::Connector> dummy_connector(
std::make_shared<hier::Connector>(dim));
if (d_src_level) {
hier::IntVector transpose_min_connector_width =
hier::Connector::convertHeadWidthToBase(
d_src_level->getBoxLevel()->getRefinementRatio(),
dst_level->getBoxLevel()->getRefinementRatio(),
min_connector_width);
d_dst_to_src = &dst_level->findConnectorWithTranspose(*d_src_level,
min_connector_width,
transpose_min_connector_width,
hier::CONNECTOR_IMPLICIT_CREATION_RULE,
true);
TBOX_ASSERT(d_dst_to_src->getBase() == *dst_level->getBoxLevel());
TBOX_ASSERT(d_dst_to_src->getTranspose().getHead() == *dst_level->getBoxLevel());
TBOX_ASSERT(d_dst_to_src->getConnectorWidth() >= d_max_scratch_gcw);
TBOX_ASSERT(d_dst_to_src->getConnectorWidth() >= d_boundary_fill_ghost_width);
} else {
dummy_connector->setTranspose(dummy_connector.get(), false);
d_dst_to_src = dummy_connector.get();
}
/*
* Create fill_box_level, representing all parts of the
* destination level, including ghost regions if desired, that this
* schedule will fill.
*/
std::shared_ptr<hier::BoxLevel> fill_box_level;
std::shared_ptr<hier::Connector> dst_to_fill;
hier::BoxNeighborhoodCollection dst_to_fill_on_src_proc;
setDefaultFillBoxLevel(
fill_box_level,
dst_to_fill,
dst_to_fill_on_src_proc);
const bool skip_first_generate_schedule =
!d_dst_level_fill_pattern->doesSourceLevelCommunicateToDestination();
const hier::IntVector dummy_intvector(dim, -1);
/*
* finishScheduleConstruction sets up all transactions to communicate
* data from source to destination, and sets up recursive schedules to
* fill whatever cannot be filled by the source.
*/
int errf = finishScheduleConstruction(
next_coarser_ln,
hierarchy,
dummy_intvector,
*dst_to_fill,
dst_to_fill_on_src_proc,
use_time_refinement,
skip_first_generate_schedule);
if (errf) {
tbox::perr
<< "Internal error in RefineSchedule constructor..."
<< "\n dst_to_fill:\n" << dst_to_fill->format("\tDF->", 2)
<< "\n dst:\n" << d_dst_level->getBoxLevel()->format("\tD->", 2)
<< std::endl;
TBOX_ERROR("Top RefineSchedule constructor aborting due to above error.");
return;
}
/*
* Compute the BoxOverlap objects that will be used to refine the
* data from coarser levels onto the destination.
*/
if (d_coarse_interp_schedule) {
computeRefineOverlaps(d_refine_overlaps,
d_dst_level,
d_coarse_interp_level,
d_dst_to_coarse_interp->getTranspose(),
*d_coarse_interp_to_unfilled);
}
if (d_coarse_interp_encon_schedule) {
computeRefineOverlaps(d_encon_refine_overlaps,
d_encon_level,
d_coarse_interp_encon_level,
d_encon_to_coarse_interp_encon->getTranspose(),
*d_coarse_interp_encon_to_unfilled_encon);
}
if (s_barrier_and_time) {
t_refine_schedule->barrierAndStop();
}
}
/*
**************************************************************************
*
* This private constructor is used to create internal schedules that
* fill internal levels that are used as coarse levels in refinement
* operations.
*
**************************************************************************
*/
RefineSchedule::RefineSchedule(
int& errf,
const std::shared_ptr<hier::PatchLevel>& dst_level,
const std::shared_ptr<hier::PatchLevel>& src_level,
int next_coarser_ln,
const std::shared_ptr<hier::PatchHierarchy>& hierarchy,
const hier::Connector& dst_to_src,
const hier::IntVector& src_growth_to_nest_dst,
const std::shared_ptr<RefineClasses>& refine_classes,
const std::shared_ptr<RefineTransactionFactory>& transaction_factory,
RefinePatchStrategy* patch_strategy,
const RefineSchedule* top_refine_schedule):
d_number_refine_items(0),
d_refine_items(0),
d_dst_level(dst_level),
d_src_level(src_level),
d_refine_patch_strategy(patch_strategy),
d_singularity_patch_strategy(dynamic_cast<SingularityPatchStrategy *>(patch_strategy)),
d_transaction_factory(transaction_factory),
d_max_stencil_width(dst_level->getDim()),
d_max_scratch_gcw(dst_level->getDim()),
d_boundary_fill_ghost_width(dst_level->getDim()),
d_force_boundary_fill(false),
d_domain_is_one_box(dst_level->getGridGeometry()->getNumberBlocks(), false),
d_num_periodic_directions(0),
d_periodic_shift(dst_level->getDim()),
d_encon_level(std::make_shared<hier::PatchLevel>(dst_level->getDim())),
d_dst_to_src(&dst_to_src),
d_max_fill_boxes(0),
d_dst_level_fill_pattern(std::make_shared<PatchLevelFullFillPattern>()),
d_top_refine_schedule(top_refine_schedule),
d_internal_allocated(false)
{
TBOX_ASSERT(dst_level);
TBOX_ASSERT(src_level);
TBOX_ASSERT((next_coarser_ln == -1) || hierarchy);
TBOX_ASSERT(dst_to_src.hasTranspose());
TBOX_ASSERT(refine_classes);
#ifdef DEBUG_CHECK_DIM_ASSERTIONS
TBOX_ASSERT_OBJDIM_EQUALITY2(*dst_level, *src_level);
if (hierarchy) {
TBOX_ASSERT_OBJDIM_EQUALITY2(*dst_level, *hierarchy);
}
#endif
// Don't time this constructor because it's recursive.
getFromInput();
/*
* Initial values; some will change in setup operations.
* Note that we do not check refine items here, since this
* constructor is private and called recursively (i.e., the
* items have been checked already).
*/
setRefineItems(refine_classes);
/*
* Initialize destination level, ghost cell widths,
* and domain information data members.
*/
initializeDomainAndGhostInformation();
hier::Connector& src_to_dst = d_dst_to_src->getTranspose();
TBOX_ASSERT(d_dst_to_src->getBase() == *d_dst_level->getBoxLevel());
TBOX_ASSERT(src_to_dst.getHead() == *d_dst_level->getBoxLevel());
if (s_extra_debug) {
src_to_dst.assertOverlapCorrectness(false, true, true);
d_dst_to_src->assertOverlapCorrectness(false, true, true);
}
/*
* Create fill_box_level, representing all parts of the
* destination level, including ghost regions if desired, that this
* schedule will fill. Here, the destination is always a coarse interpolation
* level constructed by coarsening another RefineSchedule's unfilled
* boxes. As the destination will be used as a coarse level in a
* refinement operation, the fill_box_level will be the boxes
* of the destination level grown by the maximum interplation stencil
* width.
*/
std::shared_ptr<hier::BoxLevel> fill_box_level;
std::shared_ptr<hier::Connector> dst_to_fill;
hier::BoxNeighborhoodCollection dst_to_fill_on_src_proc;
setDefaultFillBoxLevel(
fill_box_level,
dst_to_fill,
dst_to_fill_on_src_proc);
bool use_time_refinement = true;
/*
* finishScheduleConstruction sets up all transactions to communicate
* data from source to destination, and sets up recursive schedules to
* fill whatever cannot be filled by the source.
*/
errf = finishScheduleConstruction(
next_coarser_ln,
hierarchy,
src_growth_to_nest_dst,
*dst_to_fill,
dst_to_fill_on_src_proc,
use_time_refinement);
if (errf) {
tbox::perr
<< "Internal error in private RefineSchedule constructor..."
<< "\n next_coarser_ln: " << next_coarser_ln
<< "\n dst_to_fill:\n" << dst_to_fill->format("\tDF->", 2)
<< std::endl;
return;
}
/*
* Compute the BoxOverlap objects that will be used to refine the
* data from coarser levels onto the destination.
*/
if (d_coarse_interp_schedule) {
computeRefineOverlaps(d_refine_overlaps,
d_dst_level,
d_coarse_interp_level,
d_dst_to_coarse_interp->getTranspose(),
*d_coarse_interp_to_unfilled);
}
if (d_coarse_interp_encon_schedule) {
computeRefineOverlaps(d_encon_refine_overlaps,
d_encon_level,
d_coarse_interp_encon_level,
d_encon_to_coarse_interp_encon->getTranspose(),
*d_coarse_interp_encon_to_unfilled_encon);
}
}
/*
**************************************************************************
*
* The destructor for the refine schedule class implicitly deallocates
* all of the data associated with the communication schedule.
*
**************************************************************************
*/
RefineSchedule::~RefineSchedule()
{
clearRefineItems();
delete[] d_refine_items;
if (d_internal_allocated) {
deallocateInternalData();
}
}
/*
*************************************************************************
*
* Read static member data from input database once.
*
************************************************************************
*/
void
RefineSchedule::getFromInput()
{
if (!s_read_static_input) {
s_read_static_input = true;
std::shared_ptr<tbox::Database> idb(
tbox::InputManager::getInputDatabase());
if (idb && idb->isDatabase("RefineSchedule")) {
std::shared_ptr<tbox::Database> rsdb(
idb->getDatabase("RefineSchedule"));
s_extra_debug = rsdb->getBoolWithDefault("DEV_extra_debug", false);
s_barrier_and_time =
rsdb->getBoolWithDefault("DEV_barrier_and_time", false);
}
}
}
/*
*************************************************************************
*
* Reset schedule with new set of refine items.
*
************************************************************************
*/
void
RefineSchedule::reset(
const std::shared_ptr<RefineClasses>& refine_classes)
{
TBOX_ASSERT(refine_classes);
if (d_internal_allocated) {
deallocateInternalData();
}
setRefineItems(refine_classes);
if (d_coarse_interp_schedule) {
d_coarse_interp_schedule->reset(refine_classes);
}
if (d_coarse_interp_encon_schedule) {
d_coarse_interp_encon_schedule->reset(refine_classes);
}
}
/*
************************************************************************
* Construct transactions for schedule and set up recursive schedules if
* needed.
*
* Generate communication schedules to transfer data from src to
* fillboxes associated with dst boxes. What parts cannot be filled
* from the src becomes the "unfilled" boxes. If no source, all fill
* boxes become "unfilled" boxes. We also construct unfilled boxes at
* enhanced connectivity block boundaries.
*
* If there are any unfilled boxes, we coarsen them to create a
* coarse interpolation level and set up a recursive schedule for filling the
* coarse interpolation level. The idea is to interpolate data from the
* coarse interpolation level to fill the unfilled boxes.
************************************************************************
*/
int
RefineSchedule::finishScheduleConstruction(
int next_coarser_ln,
const std::shared_ptr<hier::PatchHierarchy>& hierarchy,
const hier::IntVector& src_growth_to_nest_dst,
const hier::Connector& dst_to_fill,
const hier::BoxNeighborhoodCollection& dst_to_fill_on_src_proc,
bool use_time_interpolation,
bool skip_generate_schedule)
{
if (s_barrier_and_time) {
t_finish_sched_const->barrierAndStart();
}
TBOX_ASSERT(d_dst_to_src);
TBOX_ASSERT(d_dst_to_src->hasTranspose());
TBOX_ASSERT((next_coarser_ln == -1) || hierarchy);
// Get data that will be used below.
const tbox::Dimension& dim(hierarchy->getDim());
hier::BoxLevelConnectorUtils edge_utils;
hier::OverlapConnectorAlgorithm oca;
oca.setTimerPrefix("xfer::RefineSchedule_build");
if (d_src_level) {
// Should never have a source without connection from destination.
TBOX_ASSERT(d_dst_to_src->isFinalized());
}
d_coarse_priority_level_schedule.reset(new tbox::Schedule());
d_fine_priority_level_schedule.reset(new tbox::Schedule());
d_coarse_priority_level_schedule->setTimerPrefix("xfer::RefineSchedule_fill");
d_fine_priority_level_schedule->setTimerPrefix("xfer::RefineSchedule_fill");
/*
* Generate the schedule for filling the boxes in dst_to_fill.
* Any portions of the fill boxes that cannot be filled from
* the source is placed in d_unfilled_box_level.
*
* If the source is not given or skip_generate_schedule==true,
* the schedule generation degenates to turning all the fill boxes
* into unfilled boxes.
*/
std::shared_ptr<hier::Connector> dst_to_unfilled;
const std::shared_ptr<hier::BaseGridGeometry>& grid_geometry(
d_dst_level->getGridGeometry());
std::shared_ptr<hier::Connector> encon_to_unfilled_encon;
bool create_transactions = true;
if (!d_src_level || skip_generate_schedule) {
create_transactions = false;
}
generateCommunicationSchedule(
d_unfilled_box_level,
dst_to_unfilled,
d_unfilled_encon_box_level,
encon_to_unfilled_encon,
dst_to_fill,
dst_to_fill_on_src_proc,
use_time_interpolation,
create_transactions);
/*
* d_unfilled_box_level may include ghost cells that lie
* outside the physical domain. These parts must be removed if
* they are not at periodic boundaries. They will be filled
* through a user call-back method.
*/
shearUnfilledBoxesOutsideNonperiodicBoundaries(
*d_unfilled_box_level,
*dst_to_unfilled,
hierarchy);
t_get_global_box_count->barrierAndStart();
const bool need_to_fill =
(d_unfilled_box_level->getGlobalNumberOfBoxes() > 0);
const bool need_to_fill_encon =
grid_geometry->hasEnhancedConnectivity() &&
(d_unfilled_encon_box_level->getGlobalNumberOfBoxes() > 0);
t_get_global_box_count->stop();
/*
* If there remain boxes to be filled from coarser levels, then set
* up data for recursive schedule generation:
*
* 1. Generate a coarse interpolation BoxLevel
* (coarse_interp_box_level) by coarsening the unfilled boxes.
*
* 2. Connect coarse_interp_box_level to the next coarser level on
* the hierarchy.
*
* 3: Construct the coarse interpolation PatchLevel (d_coarse_interp_level)
* and construct d_coarse_interp_schedule to fill d_coarse_interp_level.
* The coarser level on the hierarchy will be the source for filling
* d_coarse_interp_level, which is why we need step 2..
*
* The idea is that once d_coarse_interp_level is filled, we can refine its
* data to fill the current unfilled boxes.
*/
if (need_to_fill) {
t_finish_sched_const_recurse->start();
makeNodeCenteredUnfilledBoxLevel(*d_unfilled_box_level,
*dst_to_unfilled);
/*
* If there are no coarser levels in the hierarchy or the
* hierarchy is null, then throw an error. Something is messed
* up someplace and code execution cannot proceed.
*/
if (next_coarser_ln < 0) {
tbox::perr
<< "Internal error in RefineSchedule::finishScheduleConstruction..."
<< "\n In finishScheduleConstruction() -- "
<< "\n No coarser levels...will not fill from coarser."
<< "\n next_coarser_ln: " << next_coarser_ln
<< "\n src_growth_to_nest_dst: " << src_growth_to_nest_dst
<< "\n dst_to_unfilled:\n" << dst_to_unfilled->format("\tDU->", 2)
<< "\n d_unfilled_box_level:\n" << d_unfilled_box_level->format("\tUF->", 2)
<< std::endl;
return 1;
} else {
if (!hierarchy) {
tbox::perr
<< "Internal RefineSchedule error..."
<< "\n In finishScheduleConstruction() -- "
<< "\n Need to fill from coarser hierarchy level and \n"
<< "hierarchy is unavailable." << std::endl;
return 2;
}
}
/*
* hiercoarse is the coarse level on the hierarchy. It is to be
* differentiated from the coarse interpolation (coarse_interp) level,
* which is at the same resolution and level number but is not on the
* hierarchy.
*/
const std::shared_ptr<hier::PatchLevel> hiercoarse_level(
hierarchy->getPatchLevel(next_coarser_ln));
const hier::BoxLevel& hiercoarse_box_level(
*hiercoarse_level->getBoxLevel());
/*
* Ratio to the next coarser level in the hierarchy.
*/
const hier::IntVector dst_hiercoarse_ratio(
d_dst_level->getRatioToLevelZero()
/ hiercoarse_level->getRatioToLevelZero());
/*
* Set up the coarse interpolation BoxLevel and also set up
* d_dst_to_coarse_interp, its transpose and
* d_coarse_interp_to_unfilled. These
* Connectors are easily generated using dst_to_unfilled.
*/
std::shared_ptr<hier::BoxLevel> coarse_interp_box_level;
setupCoarseInterpBoxLevel(
coarse_interp_box_level,
d_dst_to_coarse_interp,
d_coarse_interp_to_unfilled,
hiercoarse_box_level,
*dst_to_unfilled);
/*
* Create the coarse interpolation PatchLevel and connect its
* BoxLevel (the next recursion's dst) to the hiercoarse
* BoxLevel (the next recursion's src).
*/
std::shared_ptr<hier::Connector> coarse_interp_to_hiercoarse;
createCoarseInterpPatchLevel(
d_coarse_interp_level,
coarse_interp_box_level,
coarse_interp_to_hiercoarse,
next_coarser_ln,
hierarchy,
*d_dst_to_src,
*d_dst_to_coarse_interp,
d_dst_level);
/*
* Compute how much hiercoarse would have to grow to nest coarse_interp, a
* required parameter in the private constructor.
*
* If dst is a coarse interpolation level (generated by RefineSchedule),
* we have the info to compute the growth. If not, we make some
* assumptions about where dst came from in order to determine
* how its fill boxes nest in hiercoarse.
*/
hier::IntVector hiercoarse_growth_to_nest_coarse_interp(
hier::IntVector::getZero(dim));
const bool dst_is_coarse_interp_level = this != d_top_refine_schedule;
if (dst_is_coarse_interp_level) {
/*
* Assume that src barely nests in hiercoarse. (In most
* places, it nests by a margin equal to the nesting buffer,
* but we don't count on that because the nesting buffer is
* zero at physical boundaries.) To nest dst, hiercoarse
* has to grow as much as the src does, plus the ghost width
* of the fill.
*
* REMARK: We may in fact be able to count on the nesting
* buffer because extending boxes to physical boundaries do
* not create any extra relationships. However, we don't
* currently have access to the size of the nesting buffer.
*/
hiercoarse_growth_to_nest_coarse_interp =
src_growth_to_nest_dst + dst_to_fill.getConnectorWidth();
} else {
/*
* dst may be:
* 1. The hierarchy level just finer than level number next_coarser_ln.
* 2. A level that nests in level number next_coarser_ln:
* a. A new level generated by GriddingAlgorithm.
* b. The hierarchy level just finer than level number next_coarser_ln,
* coarsened for Richardson extrapolation.
* In any case, dst should nest in hiercoarse. Furthermore, it does
* not grow when coarsened into the hiercoarse index space.
* To nest dst and its fill boxes, hiercoarse just has to grow by
* the ghost width of the fill.
*/
hiercoarse_growth_to_nest_coarse_interp =
dst_to_fill.getConnectorWidth();
}
hiercoarse_growth_to_nest_coarse_interp.ceilingDivide(
dst_hiercoarse_ratio);
t_finish_sched_const_recurse->stop();
/*
* We now have all the data for building the coarse interpolation
* schedule using the private constructor.
*
* We need to make sure that the coarse schedule uses
* BoxGeometryVariableFillPattern, so that it fills all needed
* parts of d_coarse_interp_level
*/
std::shared_ptr<BoxGeometryVariableFillPattern> bg_fill_pattern(
std::make_shared<BoxGeometryVariableFillPattern>());
std::shared_ptr<RefineClasses> coarse_schedule_refine_classes(
std::make_shared<RefineClasses>());
const int num_refine_items =
d_refine_classes->getNumberOfRefineItems();
for (int nd = 0; nd < num_refine_items; ++nd) {
RefineClasses::Data item = d_refine_classes->getRefineItem(nd);
item.d_var_fill_pattern = bg_fill_pattern;
coarse_schedule_refine_classes->insertEquivalenceClassItem(item);
}
if (t_finish_sched_const->isRunning()) {