7 #ifndef WONTON_DIRECT_PRODUCT_MESH_H_ 8 #define WONTON_DIRECT_PRODUCT_MESH_H_ 111 template<
int D,
class CoordSys=Wonton::DefaultCoordSys>
135 const int dpart = D);
243 std::array<std::array<double,2>,D> coord_bounds_global_;
246 std::array<GID_t,D> num_axis_points_global_;
249 int num_ghost_layers_;
253 std::array<std::array<GID_t,2>,D> gid_bounds_local_;
256 std::array<std::vector<double>,D> axis_points_;
259 bool distributed_=
false;
261 #ifdef WONTON_ENABLE_MPI 276 template<
int D,
class CoordSys>
278 const std::array<std::vector<double>,D> &axis_points_in,
281 for (
int d = 0; d < D; d++) {
282 coord_bounds_global_[d][0] = axis_points_in[d][0];
283 coord_bounds_global_[d][1] = axis_points_in[d][axis_points_in[d].size()-1];
284 num_axis_points_global_[d] = axis_points_in[d].size();
287 #ifdef WONTON_ENABLE_MPI 289 mycomm_ = MPI_COMM_NULL;
290 auto mpiexec =
dynamic_cast<MPIExecutor_type
const *
>(executor);
291 if (mpiexec && mpiexec->mpicomm != MPI_COMM_NULL) {
292 mycomm_ = mpiexec->mpicomm;
293 MPI_Comm_size(mycomm_, &nprocs_);
294 MPI_Comm_rank(mycomm_, &rank_);
295 if (nprocs_ > 1) distributed_ =
true;
303 std::array<GID_t, D> ncells;
304 for (
int d = 0; d < D; d++) ncells[d] = axis_points_in[d].size()-1;
305 auto partition_bounds =
306 structured_partitioner<D>(nprocs_, ncells, dpart, seed);
313 for (
int d = 0; d < D; d++) {
314 gid_bounds_local_[d][0] = partition_bounds[rank_][0][d];
315 gid_bounds_local_[d][1] = partition_bounds[rank_][1][d];
321 int NG = num_ghost_layers_;
323 double inf = std::numeric_limits<double>::infinity();
324 for (
int d = 0; d < D; d++) {
325 GID_t lo = gid_bounds_local_[d][0];
326 GID_t hi = gid_bounds_local_[d][1];
329 int npall =
static_cast<int>(hi-lo+1+2*NG);
330 axis_points_[d].resize(npall);
333 for (
int k = 0; k < NG; k++)
334 axis_points_[d][k] = -inf;
336 for (
int k = 0; k < NG; k++)
337 axis_points_[d][k] = (lo-NG+k < 0) ? -inf :
338 axis_points_[d][k] = axis_points_in[d][lo-NG+k];
340 std::copy(axis_points_in[d].begin()+lo, axis_points_in[d].begin()+hi+1,
341 axis_points_[d].begin()+NG);
343 if (hi == num_axis_points_global_[d]-1)
344 for (
int k = 0; k < NG; k++)
345 axis_points_[d][npall-NG+k] = inf;
347 for (
int k = 0; k < NG; k++)
348 axis_points_[d][npall-NG+k] = (hi+1+k >= num_axis_points_global_[d]) ?
349 inf : axis_points_in[d][hi+1+k];
352 num_ghost_layers_ = 0;
353 for (
int d = 0; d < D; ++d)
354 axis_points_[d] = axis_points_in[d];
355 for (
int d = 0; d < D; ++d) {
356 gid_bounds_local_[d][0] = 0;
357 gid_bounds_local_[d][1] = num_axis_points_global_[d];
362 num_ghost_layers_ = 0;
363 for (
int d = 0; d < D; ++d)
364 axis_points_[d] = axis_points_in[d];
365 for (
int d = 0; d < D; ++d) {
366 gid_bounds_local_[d][0] = 0;
367 gid_bounds_local_[d][1] = num_axis_points_global_[d];
379 template<
int D,
class CoordSys>
386 template<
int D,
class CoordSys>
388 return(distributed_);
393 template<
int D,
class CoordSys>
410 int n = axis_points_[dim].size()-2*num_ghost_layers_;
418 if (gid_bounds_local_[dim][0] != 0)
423 int n = 2*num_ghost_layers_;
424 if (gid_bounds_local_[dim][0] != 0)
429 return axis_points_[dim].size();
438 template<
int D,
class CoordSys>
440 return num_ghost_layers_;
445 template<
int D,
class CoordSys>
447 const int dim,
const int pointid)
const {
452 int npall = axis_points_[dim].size();
453 assert(pointid >= -num_ghost_layers_);
454 assert(pointid <= npall);
458 return axis_points_[dim][pointid+num_ghost_layers_];
465 template<
int D,
class CoordSys>
467 const int dim,
const int pointid)
const {
472 if (global_point_index <= 0)
474 else return global_point_index >= num_axis_points_global_[dim] - 1;
480 template<
int D,
class CoordSys>
482 const int dim,
const int pointid)
const {
485 if (pointid < 0 || pointid > npall-2*num_ghost_layers_-1)
487 else if (pointid == 0)
489 else if (pointid == npall-2*num_ghost_layers_-1)
492 if (pointid < 0 || pointid >= npall-2*num_ghost_layers_-1)
505 template<
int D,
class CoordSys>
507 const int dim,
const int pointid)
const {
511 return gid_bounds_local_[dim][0] + pointid;
516 template<
int D,
class CoordSys>
527 return 2*num_ghost_layers_;
536 template<
int D,
class CoordSys>
540 *plo = coord_bounds_global_[dim][0];
541 *phi = coord_bounds_global_[dim][1];
546 template<
int D,
class CoordSys>
550 int npall = axis_points_[dim].size();
551 *plo = axis_points_[dim][num_ghost_layers_];
552 *phi = axis_points_[dim][npall-1-num_ghost_layers_];
558 #endif // WONTON_DIRECT_PRODUCT_MESH_H_ int num_axis_cells(const int dim, const Entity_type etype=Entity_type::ALL) const
Get the number of cell along a specified axis.
Definition: direct_product_mesh.h:517
void get_local_coord_bounds(const int dim, double *lo, double *hi) const
coordinate bounds of OWNED cells in local domain (ghost layers EXCLUDED)
Definition: direct_product_mesh.h:547
int num_ghost_layers() const
Number of ghost layers on any end.
Definition: direct_product_mesh.h:439
Direct_Product_Mesh()=delete
Default constructor (disabled)
void get_global_coord_bounds(const int dim, double *lo, double *hi) const
get global coordinate bounds along axis
Definition: direct_product_mesh.h:537
Factorize a number N into D equal (or nearly equal) factors.
Definition: adaptive_refinement_mesh.h:31
Entity_type
The parallel type of a given entity.
Definition: wonton.h:124
bool distributed() const
Is the mesh distributed.
Definition: direct_product_mesh.h:387
bool point_on_external_boundary(const int dim, const int pointid) const
is point on external (global) boundary along given axis
Definition: direct_product_mesh.h:466
A basic, axis-aligned, logically-rectangular mesh.
Definition: direct_product_mesh.h:112
Entity_type axis_point_type(const int dim, const int pointid) const
Entity type of axis point.
Definition: direct_product_mesh.h:481
GID_t point_global_index(const int dim, const int pointid) const
Global index of point along a specified axis.
Definition: direct_product_mesh.h:506
double get_axis_point(const int dim, const int pointid) const
Get the specified axis point (coordinate value of cell corner)
Definition: direct_product_mesh.h:446
int64_t GID_t
Definition: wonton.h:76
int num_axis_points(const int dim, const Entity_type etype=Entity_type::ALL) const
Get the number of axis points (cell boundary coordinates) along a specified axis. ...
Definition: direct_product_mesh.h:394
Direct_Product_Mesh & operator=(const Direct_Product_Mesh< D, CoordSys > &)=delete
Assignment operator (disabled).
int space_dimension() const
Get the dimensionality of the mesh.
Definition: direct_product_mesh.h:380