7 #ifndef WONTON_ADAPTIVE_REFINEMENT_MESH_H_ 8 #define WONTON_ADAPTIVE_REFINEMENT_MESH_H_ 50 template<
int D,
class CoordSys=DefaultCoordSys>
56 using mesh_data_t = std::vector<BoundingBox<D>>;
78 std::function<
int(
const Point<D>)> func,
108 bool check_for_refinement(
const BoundingBox<D> &cell,
const int level);
114 std::pair<mesh_data_t, std::vector<int>> refine_cell(
115 const mesh_data_t &cells,
const std::vector<int> &level,
const int n);
129 std::function<int(const Point<D>)> refinement_level_;
143 template<
int D,
class CoordSys>
145 std::function<
int(
const Point<D>)> func,
150 refinement_level_ = func;
152 for (
int d = 0; d < D; ++d) {
153 mesh_corners_[d][
LO] = plo[d];
154 mesh_corners_[d][
HI] = phi[d];
166 template<
int D,
class CoordSys>
176 for (
int d = 0; d < D; ++d) {
177 center[d] = 0.5 * (cell[d][
LO] + cell[d][
HI]);
179 int value = refinement_level_(center);
185 return(value > level);
191 template<
int D,
class CoordSys>
192 typename Adaptive_Refinement_Mesh<D,CoordSys>::mesh_data_t
196 double midpoint = 0.5 * (cell[d][
LO] + cell[d][
HI]);
199 for (
int d2 = 0; d2 < D; ++d2) {
200 cell_lo[d2][
LO] = cell[d2][
LO];
201 cell_lo[d2][
HI] = cell[d2][
HI];
203 cell_lo[d][
HI] = midpoint;
206 for (
int d2 = 0; d2 < D; ++d2) {
207 cell_hi[d2][
LO] = cell[d2][
LO];
208 cell_hi[d2][
HI] = cell[d2][
HI];
210 cell_hi[d][
LO] = midpoint;
212 mesh_data_t newcells;
213 const int N = 1<<(d+1);
217 auto tempcells = split_cell(d-1, cell_lo);
218 for (
int n = 0; n < N/2; ++n) {
219 newcells[n] = tempcells[n];
222 tempcells = split_cell(d-1, cell_hi);
223 for (
int n = 0; n < N/2; ++n) {
224 newcells[n+N/2] = tempcells[n];
228 newcells[0] = cell_lo;
229 newcells[1] = cell_hi;
239 template<
int D,
class CoordSys>
241 typename Adaptive_Refinement_Mesh<D,CoordSys>::mesh_data_t,
244 const Adaptive_Refinement_Mesh<D,CoordSys>::mesh_data_t &cells,
245 const std::vector<int> &level,
const int n) {
247 assert(
unsigned(n) < cells.size());
250 const int num_new_cells = (1<<D) - 1;
251 const int newsize = cells.size() + num_new_cells;
252 mesh_data_t newcells;
253 std::vector<int> newlevel;
254 newcells.resize(newsize);
255 newlevel.resize(newsize);
257 for (
int i = 0; i < n; ++i) {
258 newcells[i] = cells[i];
259 newlevel[i] = level[i];
262 mesh_data_t tempcells = split_cell(D-1,cells[n]);
263 for (
unsigned i = 0; i < tempcells.size(); ++i) {
264 newcells[n+i] = tempcells[i];
265 newlevel[n+i] = level[n] + 1;
268 for (
unsigned i = n+1; i < level.size(); ++i) {
269 newcells[i+num_new_cells] = cells[i];
270 newlevel[i+num_new_cells] = level[i];
273 return std::make_pair(newcells, newlevel);
278 template<
int D,
class CoordSys>
282 cells_[0] = mesh_corners_;
283 std::vector<int> level = {0};
285 for (
unsigned n = 0; n < level.size(); ++n) {
286 if (check_for_refinement(cells_[n], level[n])) {
287 std::tie(cells_, level) = refine_cell(cells_, level, n);
299 template<
int D,
class CoordSys>
306 template<
int D,
class CoordSys>
308 return cells_.size();
313 template<
int D,
class CoordSys>
315 const int id)
const {
322 #endif // WONTON_ADAPTIVE_REFINEMENT_MESH_H_ Adaptive_Refinement_Mesh()=delete
Default constructor (disabled)
Factorize a number N into D equal (or nearly equal) factors.
Definition: adaptive_refinement_mesh.h:31
Adaptive_Refinement_Mesh & operator=(const Adaptive_Refinement_Mesh< D, CoordSys > &)=delete
Assignment operator (disabled).
int num_cells() const
Get the total number of cells in the mesh.
Definition: adaptive_refinement_mesh.h:307
A simple mesh that mimics a cell-by-cell AMR mesh.
Definition: adaptive_refinement_mesh.h:51
Represents a point in an N-dimensional space.
Definition: Point.h:50
std::array< std::array< double, 2 >, D > BoundingBox
Bounding Box type.
Definition: BoundingBox.h:21
int space_dimension() const
Get the dimensionality of the mesh.
Definition: adaptive_refinement_mesh.h:300
const int HI
Definition: BoundingBox.h:24
BoundingBox< D > cell_get_bounds(const int id) const
Get the lower and upper bounds of the specified cell.
Definition: adaptive_refinement_mesh.h:314
const int LO
Definition: BoundingBox.h:23