forked from AMReX-Codes/amrex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAMReX_AmrCore.cpp
232 lines (204 loc) · 6.74 KB
/
AMReX_AmrCore.cpp
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
#include <AMReX_AmrCore.H>
#ifdef AMREX_PARTICLES
#include <AMReX_AmrParGDB.H>
#endif
#ifdef AMREX_USE_OMP
#include <omp.h>
#endif
#include <algorithm>
#include <utility>
#include <ostream>
namespace amrex {
AmrCore::AmrCore ()
{
InitAmrCore();
}
AmrCore::AmrCore (const RealBox* rb, int max_level_in,
const Vector<int>& n_cell_in, int coord,
Vector<IntVect> ref_ratios, const int* is_per)
: AmrMesh(rb, max_level_in, n_cell_in, coord, std::move(ref_ratios), is_per)
{
InitAmrCore();
}
AmrCore::AmrCore (const RealBox& rb, int max_level_in,
const Vector<int>& n_cell_in, int coord,
Vector<IntVect> const& ref_ratios,
Array<int,AMREX_SPACEDIM> const& is_per)
: AmrMesh(rb, max_level_in, n_cell_in, coord, ref_ratios, is_per)
{
InitAmrCore();
}
AmrCore::AmrCore (Geometry const& level_0_geom, AmrInfo const& amr_info)
: AmrMesh(level_0_geom,amr_info)
{
#ifdef AMREX_PARTICLES
m_gdb = std::make_unique<AmrParGDB>(this);
#endif
}
AmrCore::AmrCore (AmrCore&& rhs) noexcept
: AmrMesh(static_cast<AmrMesh&&>(rhs))
{
#ifdef AMREX_PARTICLES
m_gdb = std::move(rhs.m_gdb); // NOLINT(cppcoreguidelines-prefer-member-initializer)
m_gdb->m_amrcore = this;
#endif
}
AmrCore::~AmrCore () {} // NOLINT
AmrCore& AmrCore::operator= (AmrCore&& rhs) noexcept
{
AmrMesh::operator=(static_cast<AmrMesh&&>(rhs));
#ifdef AMREX_PARTICLES
m_gdb = std::move(rhs.m_gdb);
m_gdb->m_amrcore = this;
#endif
return *this;
}
void
AmrCore::InitAmrCore ()
{
#ifdef AMREX_PARTICLES
m_gdb = std::make_unique<AmrParGDB>(this);
#endif
}
void
AmrCore::InitFromScratch (Real time)
{
MakeNewGrids(time);
}
void
AmrCore::regrid (int lbase, Real time, bool)
{
if (lbase >= max_level) { return; }
int new_finest;
Vector<BoxArray> new_grids(finest_level+2);
MakeNewGrids(lbase, time, new_finest, new_grids);
BL_ASSERT(new_finest <= finest_level+1);
bool coarse_ba_changed = false;
for (int lev = lbase+1; lev <= new_finest; ++lev)
{
if (lev <= finest_level) // an old level
{
bool ba_changed = (new_grids[lev] != grids[lev]);
if (ba_changed || coarse_ba_changed) {
BoxArray level_grids = grids[lev];
DistributionMapping level_dmap = dmap[lev];
if (ba_changed) {
level_grids = new_grids[lev];
level_dmap = MakeDistributionMap(lev, level_grids);
}
const auto old_num_setdm = num_setdm;
RemakeLevel(lev, time, level_grids, level_dmap);
SetBoxArray(lev, level_grids);
if (old_num_setdm == num_setdm) {
SetDistributionMap(lev, level_dmap);
}
}
coarse_ba_changed = ba_changed;;
}
else // a new level
{
DistributionMapping new_dmap = MakeDistributionMap(lev, new_grids[lev]);
const auto old_num_setdm = num_setdm;
MakeNewLevelFromCoarse(lev, time, new_grids[lev], new_dmap);
SetBoxArray(lev, new_grids[lev]);
if (old_num_setdm == num_setdm) {
SetDistributionMap(lev, new_dmap);
}
}
}
for (int lev = new_finest+1; lev <= finest_level; ++lev) {
ClearLevel(lev);
ClearBoxArray(lev);
ClearDistributionMap(lev);
}
finest_level = new_finest;
}
void
AmrCore::printGridSummary (std::ostream& os, int min_lev, int max_lev) const noexcept
{
for (int lev = min_lev; lev <= max_lev; lev++)
{
const BoxArray& bs = boxArray(lev);
int numgrid = static_cast<int>(bs.size());
Long ncells = bs.numPts();
double ntot = Geom(lev).Domain().d_numPts();
Real frac = Real(100.0*double(ncells) / ntot);
os << " Level "
<< lev
<< " "
<< numgrid
<< " grids "
<< ncells
<< " cells "
<< frac
<< " % of domain"
<< '\n';
if (numgrid > 1) {
Long vmin = std::numeric_limits<Long>::max();
Long vmax = -1;
int lmax = -1;
int smin = std::numeric_limits<int>::max();
int imax = std::numeric_limits<int>::lowest();
int imin = std::numeric_limits<int>::lowest();
#ifdef AMREX_USE_OMP
#pragma omp parallel
#endif
{
Long vmin_this = std::numeric_limits<Long>::max();
Long vmax_this = -1;
int lmax_this = -1;
int smin_this = std::numeric_limits<int>::max();
int imax_this = std::numeric_limits<int>::lowest();
int imin_this = std::numeric_limits<int>::lowest();
#ifdef AMREX_USE_OMP
#pragma omp for
#endif
for (int k = 0; k < numgrid; k++) {
const Box& bx = bs[k];
Long v = bx.volume();
int ss = bx.shortside();
int ls = bx.longside();
if (v < vmin_this || (v == vmin_this && ss < smin_this)) {
vmin_this = v;
smin_this = ss;
imin_this = k;
}
if (v > vmax_this || (v == vmax_this && ls > lmax_this)) {
vmax_this = v;
lmax_this = ls;
imax_this = k;
}
}
#ifdef AMREX_USE_OMP
#pragma omp critical (amr_prtgs)
#endif
{
if (vmin_this < vmin || (vmin_this == vmin && smin_this < smin)) {
vmin = vmin_this; // NOLINT
smin = smin_this; // NOLINT
imin = imin_this;
}
if (vmax_this > vmax || (vmax_this == vmax && lmax_this > lmax)) {
vmax = vmax_this; // NOLINT
lmax = lmax_this; // NOLINT
imax = imax_this;
}
}
}
const Box& bmin = bs[imin];
const Box& bmax = bs[imax];
os << " "
<< " smallest grid: "
AMREX_D_TERM(<< bmin.length(0),
<< " x " << bmin.length(1),
<< " x " << bmin.length(2))
<< " biggest grid: "
AMREX_D_TERM(<< bmax.length(0),
<< " x " << bmax.length(1),
<< " x " << bmax.length(2))
<< '\n';
}
}
os << std::endl; // Make sure we flush!
}
}