-
Notifications
You must be signed in to change notification settings - Fork 479
Expand file tree
/
Copy pathAMReX_AmrLevel.cpp
More file actions
2305 lines (1993 loc) · 72.3 KB
/
Copy pathAMReX_AmrLevel.cpp
File metadata and controls
2305 lines (1993 loc) · 72.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <AMReX_AmrLevel.H>
#include <AMReX_Derive.H>
#include <AMReX_ParallelDescriptor.H>
#include <AMReX_Utility.H>
#include <AMReX_FillPatchUtil.H>
#include <AMReX_ParmParse.H>
#include <AMReX_BLProfiler.H>
#include <AMReX_Print.H>
#include <AMReX_VisMF.H>
#ifdef AMREX_USE_EB
#include <AMReX_EBFabFactory.H>
#include <AMReX_EBMultiFabUtil.H>
#include <AMReX_EB2.H>
#endif
#include <sstream>
#include <iterator>
#include <memory>
#include <limits>
namespace amrex {
#ifdef AMREX_USE_EB
int AmrLevel::m_eb_basic_grow_cells = 5;
int AmrLevel::m_eb_volume_grow_cells = 4;
int AmrLevel::m_eb_full_grow_cells = 2;
EBSupport AmrLevel::m_eb_support_level = EBSupport::volume;
#endif
DescriptorList AmrLevel::desc_lst;
DeriveList AmrLevel::derive_lst;
void
AmrLevel::post_timestep (int /*iteration*/)
{
if (level < parent->finestLevel()) {
parent->getLevel(level+1).resetFillPatcher();
}
}
void
AmrLevel::postCoarseTimeStep (Real /*time*/)
{
}
void
AmrLevel::set_preferred_boundary_values (MultiFab& /*S*/,
int /*state_index*/,
int /*scomp*/,
int /*dcomp*/,
int /*ncomp*/,
Real /*time*/) const
{}
DeriveList&
AmrLevel::get_derive_lst () noexcept
{
return derive_lst;
}
void
AmrLevel::manual_tags_placement (TagBoxArray& /*tags*/,
const Vector<IntVect>& /*bf_lev*/)
{}
AmrLevel::AmrLevel (Amr& papa,
int lev,
const Geometry& level_geom,
const BoxArray& ba, // NOLINT(modernize-pass-by-value)
const DistributionMapping& dm,
Real time)
:
level(lev),
geom(level_geom),
grids(ba),
dmap(dm),
parent(&papa)
{
BL_PROFILE("AmrLevel::AmrLevel(dm)");
fine_ratio = IntVect::TheUnitVector(); fine_ratio.scale(-1);
crse_ratio = IntVect::TheUnitVector(); crse_ratio.scale(-1);
if (level > 0)
{
crse_ratio = parent->refRatio(level-1);
}
if (level < parent->maxLevel())
{
fine_ratio = parent->refRatio(level);
}
state.resize(desc_lst.size());
m_fillpatcher.resize(desc_lst.size());
#ifdef AMREX_USE_EB
if (EB2::TopIndexSpaceIfPresent()) {
m_factory = makeEBFabFactory(geom, ba, dm,
{m_eb_basic_grow_cells,
m_eb_volume_grow_cells,
m_eb_full_grow_cells},
m_eb_support_level);
} else
#endif
{
m_factory = std::make_unique<FArrayBoxFactory>();
}
// Note that this creates a distribution map associated with grids.
for (int i = 0; i < std::ssize(state); i++)
{
MultiFab::RegionTag statedata_tag("StateData_Level_" + std::to_string(lev));
MultiFab::RegionTag statedata_index_tag("StateData_" + std::to_string(i) + "_Level_" + std::to_string(lev));
MultiFab::RegionTag statedata_index_new_tag("StateData_" + std::to_string(i) + "_New_Level_" + std::to_string(lev));
MultiFab::RegionTag level_tag("AmrLevel_Level_" + std::to_string(lev));
state[i].define(geom.Domain(),
grids,
dm,
desc_lst[i],
time,
parent->dtLevel(lev),
*m_factory);
}
if (parent->useFixedCoarseGrids()) { constructAreaNotToTag(); }
post_step_regrid = 0;
finishConstructor();
}
void
AmrLevel::writePlotFile (const std::string& dir,
std::ostream& os,
VisMF::How how)
{
BL_PROFILE("AmrLevel::writePlotFile()");
int i, n;
//
// The list of indices of State to write to plotfile.
// first component of pair is state_type,
// second component of pair is component # within the state_type
//
std::vector<std::pair<int,int> > plot_var_map;
for (int typ = 0; typ < std::ssize(desc_lst); typ++)
{
for (int comp = 0; comp < desc_lst[typ].nComp();comp++)
{
if (amrex::Amr::isStatePlotVar(desc_lst[typ].name(comp)) &&
desc_lst[typ].getType() == IndexType::TheCellType())
{
plot_var_map.emplace_back(typ,comp);
}
}
}
int num_derive = 0;
std::vector<std::string> derive_names;
const std::list<DeriveRec>& dlist = derive_lst.dlist();
for (auto const& d : dlist)
{
if (amrex::Amr::isDerivePlotVar(d.name()))
{
derive_names.push_back(d.name());
num_derive += d.numDerive();
}
}
int n_data_items = static_cast<int>(plot_var_map.size()) + num_derive;
#ifdef AMREX_USE_EB
if (EB2::TopIndexSpaceIfPresent()) {
n_data_items += 1;
}
#endif
// get the time from the first State_Type
// if the State_Type is ::Interval, this will get t^{n+1/2} instead of t^n
Real cur_time = state[0].curTime();
int f_lev = std::min(parent->plotMaxLevel(), parent->finestLevel());
if (level == 0 && ParallelDescriptor::IOProcessor())
{
//
// The first thing we write out is the plotfile type.
//
os << thePlotFileType() << '\n';
if (n_data_items == 0) {
amrex::Error("Must specify at least one valid data item to plot");
}
os << n_data_items << '\n';
//
// Names of variables
//
for (i =0; i < std::ssize(plot_var_map); i++)
{
int typ = plot_var_map[i].first;
int comp = plot_var_map[i].second;
os << desc_lst[typ].name(comp) << '\n';
}
// derived
for (auto const& dname : derive_names) {
const DeriveRec* rec = derive_lst.get(dname);
for (i = 0; i < rec->numDerive(); ++i) {
os << rec->variableName(i) << '\n';
}
}
#ifdef AMREX_USE_EB
if (EB2::TopIndexSpaceIfPresent()) {
os << "vfrac\n";
}
#endif
os << AMREX_SPACEDIM << '\n';
os << parent->cumTime() << '\n';
os << f_lev << '\n';
for (i = 0; i < AMREX_SPACEDIM; i++) {
os << Geom().ProbLo(i) << ' ';
}
os << '\n';
for (i = 0; i < AMREX_SPACEDIM; i++) {
os << Geom().ProbHi(i) << ' ';
}
os << '\n';
for (i = 0; i < f_lev; i++) {
os << parent->refRatio(i)[0] << ' ';
}
os << '\n';
for (i = 0; i <= f_lev; i++) {
os << parent->Geom(i).Domain() << ' ';
}
os << '\n';
for (i = 0; i <= f_lev; i++) {
os << parent->levelSteps(i) << ' ';
}
os << '\n';
for (i = 0; i <= f_lev; i++)
{
for (int k = 0; k < AMREX_SPACEDIM; k++) {
os << parent->Geom(i).CellSize()[k] << ' ';
}
os << '\n';
}
os << (int) Geom().Coord() << '\n';
os << "0\n"; // Write bndry data.
}
// Build the directory to hold the MultiFab at this level.
// The name is relative to the directory containing the Header file.
//
static const std::string BaseName = "/Cell";
char buf[64];
snprintf(buf, sizeof buf, "Level_%d", level);
std::string sLevel = buf;
//
// Now for the full pathname of that directory.
//
std::string FullPath = dir;
if ( ! FullPath.empty() && FullPath[FullPath.size()-1] != '/')
{
FullPath += '/';
}
FullPath += sLevel;
//
// Only the I/O processor makes the directory if it doesn't already exist.
//
if ( ! levelDirectoryCreated) {
if (ParallelDescriptor::IOProcessor()) {
if ( ! amrex::UtilCreateDirectory(FullPath, 0755)) {
amrex::CreateDirectoryFailed(FullPath);
}
}
// Force other processors to wait until directory is built.
ParallelDescriptor::Barrier();
}
if (ParallelDescriptor::IOProcessor())
{
os << level << ' ' << grids.size() << ' ' << cur_time << '\n';
os << parent->levelSteps(level) << '\n';
for (i = 0; i < std::ssize(grids); ++i)
{
RealBox gridloc = RealBox(grids[i],geom.CellSize(),geom.ProbLo());
for (n = 0; n < AMREX_SPACEDIM; n++) {
os << gridloc.lo(n) << ' ' << gridloc.hi(n) << '\n';
}
}
//
// The full relative pathname of the MultiFabs at this level.
// The name is relative to the Header file containing this name.
// It's the name that gets written into the Header.
//
if (n_data_items > 0)
{
std::string PathNameInHeader = sLevel;
PathNameInHeader += BaseName;
os << PathNameInHeader << '\n';
}
#ifdef AMREX_USE_EB
if (EB2::TopIndexSpaceIfPresent()) {
// volfrac threshold for amrvis
if (level == f_lev) {
for (int lev = 0; lev <= f_lev; ++lev) {
os << "1.0e-6\n";
}
}
}
#endif
}
//
// We combine all of the multifabs -- state, derived, etc -- into one
// multifab -- plotMF.
int cnt = 0;
const int nGrow = 0;
MultiFab plotMF(grids,dmap,n_data_items,nGrow,MFInfo(),Factory());
MultiFab* this_dat = nullptr;
//
// Cull data from state variables -- use no ghost cells.
//
for (i = 0; i < std::ssize(plot_var_map); i++)
{
int typ = plot_var_map[i].first;
int comp = plot_var_map[i].second;
this_dat = &state[typ].newData();
MultiFab::Copy(plotMF,*this_dat,comp,cnt,1,nGrow);
cnt++;
}
// derived
if (!derive_names.empty())
{
for (auto const& dname : derive_names)
{
derive(dname, cur_time, plotMF, cnt);
cnt += derive_lst.get(dname)->numDerive();
}
}
#ifdef AMREX_USE_EB
if (EB2::TopIndexSpaceIfPresent()) {
plotMF.setVal(0.0, cnt, 1, nGrow);
auto *factory = static_cast<EBFArrayBoxFactory*>(m_factory.get());
MultiFab::Copy(plotMF,factory->getVolFrac(),0,cnt,1,nGrow);
}
#endif
//
// Use the Full pathname when naming the MultiFab.
//
std::string TheFullPath = FullPath;
TheFullPath += BaseName;
if (AsyncOut::UseAsyncOut()) {
VisMF::AsyncWrite(plotMF,TheFullPath);
} else {
VisMF::Write(plotMF,TheFullPath,how,true);
}
levelDirectoryCreated = false; // ---- now that the plotfile is finished
}
void
AmrLevel::writePlotFilePre (const std::string& /*dir*/,
std::ostream& /*os*/)
{
}
void
AmrLevel::writePlotFilePost (const std::string& /*dir*/,
std::ostream& /*os*/)
{
}
void
AmrLevel::restart (Amr& papa,
std::istream& is,
bool bReadSpecial)
{
BL_PROFILE("AmrLevel::restart()");
parent = &papa;
is >> level;
is >> geom;
fine_ratio = IntVect::TheUnitVector(); fine_ratio.scale(-1);
crse_ratio = IntVect::TheUnitVector(); crse_ratio.scale(-1);
AMREX_ASSERT(level >= 0 && level <= parent->maxLevel());
if (level > 0)
{
crse_ratio = parent->refRatio(level-1);
}
if (level < parent->maxLevel())
{
fine_ratio = parent->refRatio(level);
}
if (bReadSpecial)
{
amrex::readBoxArray(grids, is, bReadSpecial);
}
else
{
grids.readFrom(is);
}
int nstate;
is >> nstate;
int ndesc = desc_lst.size();
Vector<int> state_in_checkpoint(ndesc, 1);
if (ndesc > nstate) {
set_state_in_checkpoint(state_in_checkpoint);
} else {
BL_ASSERT(nstate == ndesc);
}
dmap.define(grids);
parent->SetBoxArray(level, grids);
parent->SetDistributionMap(level, dmap);
#ifdef AMREX_USE_EB
if (EB2::TopIndexSpaceIfPresent()) {
m_factory = makeEBFabFactory(geom, grids, dmap,
{m_eb_basic_grow_cells,
m_eb_volume_grow_cells,
m_eb_full_grow_cells},
m_eb_support_level);
} else
#endif
{
m_factory = std::make_unique<FArrayBoxFactory>();
}
state.resize(ndesc);
for (int i = 0; i < ndesc; ++i)
{
if (state_in_checkpoint[i]) {
state[i].restart(is, geom.Domain(), grids, dmap, *m_factory,
desc_lst[i], papa.theRestartFile());
}
}
m_fillpatcher.resize(ndesc);
if (parent->useFixedCoarseGrids()) { constructAreaNotToTag(); }
post_step_regrid = 0;
finishConstructor();
}
void
AmrLevel::set_state_in_checkpoint (Vector<int>& /*state_in_checkpoint*/)
{
amrex::Error("Class derived AmrLevel has to handle this!");
}
void
AmrLevel::finishConstructor () {}
void
AmrLevel::setTimeLevel (Real time,
Real dt_old,
Real dt_new)
{
for (int k = 0; k < std::ssize(desc_lst); k++)
{
state[k].setTimeLevel(time,dt_old,dt_new);
}
}
bool
AmrLevel::isStateVariable (const std::string& name, int& state_indx, int& n)
{
for (state_indx = 0; state_indx < std::ssize(desc_lst); state_indx++)
{
const StateDescriptor& desc = desc_lst[state_indx];
for (n = 0; n < desc.nComp(); n++)
{
if (desc.name(n) == name) {
return true;
}
}
}
return false;
}
Long
AmrLevel::countCells () const noexcept
{
return grids.numPts();
}
void
AmrLevel::checkPoint (const std::string& dir,
std::ostream& os,
VisMF::How how,
bool dump_old)
{
BL_PROFILE("AmrLevel::checkPoint()");
int ndesc = desc_lst.size(), i;
//
// Build directory to hold the MultiFabs in the StateData at this level.
// The directory is relative the the directory containing the Header file.
//
std::string LevelDir, FullPath;
LevelDirectoryNames(dir, LevelDir, FullPath);
if( ! levelDirectoryCreated) {
CreateLevelDirectory(dir);
// ---- Force other processors to wait until directory is built.
ParallelDescriptor::Barrier("AmrLevel::checkPoint::dir");
}
if (ParallelDescriptor::IOProcessor())
{
os << level << '\n' << geom << '\n';
grids.writeOn(os);
os << ndesc << '\n';
}
//
// Output state data.
//
for (i = 0; i < ndesc; i++)
{
//
// Now build the full relative pathname of the StateData.
// The name is relative to the Header file containing this name.
// It's the name that gets written into the Header.
//
std::string PathNameInHdr = amrex::Concatenate(LevelDir + "/SD_", i, 1);
std::string FullPathName = amrex::Concatenate(FullPath + "/SD_", i, 1);
state[i].checkPoint(PathNameInHdr, FullPathName, os, how, dump_old);
}
levelDirectoryCreated = false; // ---- now that the checkpoint is finished
}
void
AmrLevel::checkPointPre (const std::string& /*dir*/,
std::ostream& /*os*/)
{
BL_PROFILE("AmrLevel::checkPointPre()");
}
void
AmrLevel::checkPointPost (const std::string& /*dir*/,
std::ostream& /*os*/)
{
BL_PROFILE("AmrLevel::checkPointPost()");
}
AmrLevel::~AmrLevel ()
{
parent = nullptr;
}
void
AmrLevel::allocOldData ()
{
for (int i = 0; i < std::ssize(desc_lst); i++)
{
state[i].allocOldData();
}
}
void
AmrLevel::removeOldData ()
{
for (int i = 0; i < std::ssize(desc_lst); i++)
{
state[i].removeOldData();
}
}
void
AmrLevel::reset ()
{
for (int i = 0; i < std::ssize(desc_lst); i++)
{
state[i].reset();
}
}
MultiFab&
AmrLevel::get_data (int state_indx, Real time)
{
const Real old_time = state[state_indx].prevTime();
const Real new_time = state[state_indx].curTime();
const Real eps = Real(0.001)*(new_time - old_time);
if (time >= old_time-eps && time <= old_time+eps)
{
return get_old_data(state_indx);
}
else if (time >= new_time-eps && time <= new_time+eps)
{
return get_new_data(state_indx);
}
amrex::Error("get_data: invalid time");
static MultiFab bogus;
return bogus;
}
const BoxArray&
AmrLevel::getEdgeBoxArray (int dir) const noexcept
{
BL_ASSERT(dir >=0 && dir < AMREX_SPACEDIM);
// NOLINTBEGIN(clang-analyzer-security.ArrayBound)
if (edge_grids[dir].empty()) {
edge_grids[dir] = grids;
edge_grids[dir].surroundingNodes(dir);
}
return edge_grids[dir];
// NOLINTEND(clang-analyzer-security.ArrayBound)
}
const BoxArray&
AmrLevel::getNodalBoxArray () const noexcept
{
if (nodal_grids.empty()) {
nodal_grids = grids;
nodal_grids.surroundingNodes();
}
return nodal_grids;
}
void
AmrLevel::setPhysBoundaryValues (FArrayBox& dest,
int state_indx,
Real time,
int dest_comp,
int src_comp,
int num_comp)
{
// Call the Fab interface if available.
if (state[state_indx].descriptor()->hasBndryFuncFab()) {
state[state_indx].FillBoundary(dest.box(), dest, time, geom, dest_comp, src_comp, num_comp);
}
else {
state[state_indx].FillBoundary(dest,time,geom.CellSize(),
geom.ProbDomain(),dest_comp,src_comp,num_comp);
}
}
FillPatchIteratorHelper::FillPatchIteratorHelper (AmrLevel& amrlevel,
MultiFab& leveldata)
:
m_amrlevel(&amrlevel),
m_leveldata(&leveldata),
m_mfid(m_amrlevel->level+1)
{}
FillPatchIterator::FillPatchIterator (AmrLevel& amrlevel,
MultiFab& leveldata)
:
MFIter(leveldata),
m_amrlevel(&amrlevel),
m_leveldata(&leveldata),
m_ncomp(0)
{
MFIter::depth = 0;
}
FillPatchIteratorHelper::FillPatchIteratorHelper (AmrLevel& amrlevel,
MultiFab& leveldata,
int boxGrow,
Real time,
int index,
int scomp,
int ncomp,
InterpBase* mapper)
:
m_amrlevel(&amrlevel),
m_leveldata(&leveldata),
m_mfid(m_amrlevel->level+1),
m_time(time),
m_growsize(boxGrow),
m_index(index),
m_scomp(scomp),
m_ncomp(ncomp)
{
Initialize(boxGrow,time,index,scomp,ncomp,mapper);
}
FillPatchIterator::FillPatchIterator (AmrLevel& amrlevel,
MultiFab& leveldata,
int boxGrow,
Real time,
int idx,
int scomp,
int ncomp)
:
MFIter(leveldata),
m_amrlevel(&amrlevel),
m_leveldata(&leveldata),
m_ncomp(ncomp)
{
BL_ASSERT(scomp >= 0);
BL_ASSERT(ncomp >= 1);
BL_ASSERT(AmrLevel::desc_lst[idx].inRange(scomp,ncomp));
BL_ASSERT(0 <= idx && idx < AmrLevel::desc_lst.size());
MFIter::depth = 0;
Initialize(boxGrow,time,idx,scomp,ncomp);
#ifdef BL_USE_TEAM
ParallelDescriptor::MyTeam().MemoryBarrier();
#endif
}
namespace {
bool
NeedToTouchUpPhysCorners (const Geometry& geom)
{
return geom.isAnyPeriodic() && !geom.isAllPeriodic();
}
}
void
FillPatchIteratorHelper::Initialize (int boxGrow,
Real time,
int idx,
int scomp,
int ncomp,
InterpBase* mapper)
{
BL_PROFILE("FillPatchIteratorHelper::Initialize()");
BL_ASSERT(mapper);
BL_ASSERT(scomp >= 0);
BL_ASSERT(ncomp >= 1);
BL_ASSERT(AmrLevel::desc_lst[idx].inRange(scomp,ncomp));
BL_ASSERT(0 <= idx && idx < AmrLevel::desc_lst.size());
m_map = dynamic_cast<Interpolater*>(mapper);
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(m_map, "Cannot use MFInterpolater without proper nesting");
m_time = time;
m_growsize = boxGrow;
m_index = idx;
m_scomp = scomp;
m_ncomp = ncomp;
m_FixUpCorners = NeedToTouchUpPhysCorners(m_amrlevel->geom);
const int MyProc = ParallelDescriptor::MyProc();
auto& amrLevels = m_amrlevel->parent->getAmrLevels();
const AmrLevel& topLevel = *amrLevels[m_amrlevel->level];
const Box& topPDomain = topLevel.state[m_index].getDomain();
const IndexType& boxType = m_leveldata->boxArray().ixType();
const bool extrap = AmrLevel::desc_lst[m_index].extrap();
//
// Check that the interpolaters are identical.
//
BL_ASSERT(AmrLevel::desc_lst[m_index].identicalInterps(scomp,ncomp));
for (int l = 0; l <= m_amrlevel->level; ++l)
{
amrLevels[l]->state[m_index].RegisterData(m_mfcd, m_mfid[l]);
}
for (int i = 0, N = static_cast<int>(m_leveldata->boxArray().size()); i < N; ++i)
{
//
// A couple typedefs we'll use in the next code segment.
//
using IntAABoxMapValType = std::map<int,Vector<Vector<Box> > >::value_type;
using IntAAAFBIDMapValType = std::map<int,Vector<Vector<Vector<FillBoxId> > > >::value_type;
if (m_leveldata->DistributionMap()[i] != MyProc) { continue; }
//
// Insert with a hint since the indices are ordered lowest to highest.
//
IntAAAFBIDMapValType v1(i,Vector<Vector<Vector<FillBoxId> > >());
m_fbid.insert(m_fbid.end(),v1)->second.resize(m_amrlevel->level+1);
IntAABoxMapValType v2(i,Vector<Vector<Box> >());
m_fbox.insert(m_fbox.end(),v2)->second.resize(m_amrlevel->level+1);
m_cbox.insert(m_cbox.end(),v2)->second.resize(m_amrlevel->level+1);
m_ba.insert(m_ba.end(),std::map<int,Box>::value_type(i,amrex::grow(m_leveldata->boxArray()[i],m_growsize)));
}
BoxList tempUnfillable(boxType);
BoxList unfillableThisLevel(boxType);
Vector<Box> unfilledThisLevel;
Vector<Box> crse_boxes;
Vector<IntVect> pshifts(27);
for (auto const& it : m_ba)
{
const int bxidx = it.first;
const Box& box = it.second;
unfilledThisLevel.clear();
unfilledThisLevel.push_back(box);
if (!topPDomain.contains(box))
{
unfilledThisLevel.back() &= topPDomain;
if (topLevel.geom.isAnyPeriodic())
{
//
// May need to add additional unique pieces of valid region
// in order to do periodic copies into ghost cells.
//
topLevel.geom.periodicShift(topPDomain,box,pshifts);
for (const auto& iv : pshifts)
{
Box shbox = box + iv;
shbox &= topPDomain;
if (boxType.nodeCentered())
{
for (int dir = 0; dir < AMREX_SPACEDIM; dir++)
{
if (iv[dir] > 0)
{
shbox.growHi(dir,-1);
}
else if (iv[dir] < 0)
{
shbox.growLo(dir,-1);
}
}
}
if (shbox.ok())
{
BoxList bl = amrex::boxDiff(shbox,box);
unfilledThisLevel.insert(unfilledThisLevel.end(), bl.begin(), bl.end());
}
}
}
}
// cells outside physical boundaries are not included in unfilledThisLevel
bool Done = false;
Vector< Vector<Box> >& TheCrseBoxes = m_cbox[bxidx];
Vector< Vector<Box> >& TheFineBoxes = m_fbox[bxidx];
Vector< Vector< Vector<FillBoxId> > >& TheFBIDs = m_fbid[bxidx];
for (int l = m_amrlevel->level; l >= 0 && !Done; --l)
{
unfillableThisLevel.clear();
AmrLevel& theAmrLevel = *amrLevels[l];
StateData& theState = theAmrLevel.state[m_index];
const Box& thePDomain = theState.getDomain();
const Geometry& theGeom = theAmrLevel.geom;
const bool is_periodic = theGeom.isAnyPeriodic();
const IntVect& fine_ratio = theAmrLevel.fine_ratio;
Vector<Box>& FineBoxes = TheFineBoxes[l];
//
// These are the boxes on this level contained in thePDomain
// that need to be filled in order to directly fill at the
// highest level or to interpolate up to the next higher level.
//
FineBoxes = unfilledThisLevel;
//
// Now build coarse boxes needed to interpolate to fine.
//
// If we're periodic and we're not at the finest level, we may
// need to get some additional data at this level in order to
// properly fill the CoarseBox()d versions of the fineboxes.
//
crse_boxes.clear();
for (const auto& fbx : FineBoxes)
{
crse_boxes.push_back(fbx);
if (l != m_amrlevel->level)
{
const Box& cbox = m_map->CoarseBox(fbx,fine_ratio);
crse_boxes.back() = cbox;
if (is_periodic && !thePDomain.contains(cbox))
{
theGeom.periodicShift(thePDomain,cbox,pshifts);
for (const auto& iv : pshifts)
{
Box shbox = cbox + iv;
shbox &= thePDomain;
if (boxType.nodeCentered())
{
for (int dir = 0; dir < AMREX_SPACEDIM; dir++)
{
if (iv[dir] > 0)
{
shbox.growHi(dir,-1);
}
else if (iv[dir] < 0)
{
shbox.growLo(dir,-1);
}
}
}
if (shbox.ok())
{
crse_boxes.push_back(shbox);
}
}
}
}
}
Vector< Vector<FillBoxId> >& FBIDs = TheFBIDs[l];
Vector<Box>& CrseBoxes = TheCrseBoxes[l];
FBIDs.resize(crse_boxes.size());
CrseBoxes.resize(crse_boxes.size());
//
// Now attempt to get as much coarse data as possible.
//
for (int i = 0, M = static_cast<int>(CrseBoxes.size()); i < M; i++)
{
BL_ASSERT(tempUnfillable.isEmpty());
CrseBoxes[i] = crse_boxes[i];
BL_ASSERT(CrseBoxes[i].intersects(thePDomain));
theState.InterpAddBox(m_mfcd,
m_mfid[l],
&tempUnfillable,
FBIDs[i],
CrseBoxes[i],
m_time,
m_scomp,
0,
m_ncomp,
extrap);
unfillableThisLevel.catenate(tempUnfillable);
}
unfillableThisLevel.intersect(thePDomain);
if (unfillableThisLevel.isEmpty())
{
Done = true;
}
else
{
unfilledThisLevel.clear();
unfilledThisLevel.insert(unfilledThisLevel.end(),
unfillableThisLevel.begin(),
unfillableThisLevel.end());
}
}
}
m_mfcd.CollectData();
}
void
FillPatchIterator::Initialize (int boxGrow,
Real time,
int idx,
int scomp,
int ncomp)
{
BL_PROFILE("FillPatchIterator::Initialize");
BL_ASSERT(scomp >= 0);
BL_ASSERT(ncomp >= 1);
BL_ASSERT(0 <= idx && idx < AmrLevel::desc_lst.size());