7 #ifndef WONTON_DIRECT_PRODUCT_MESH_WRAPPER_H_ 8 #define WONTON_DIRECT_PRODUCT_MESH_WRAPPER_H_ 42 template<
int D,
class CoordSys=DefaultCoordSys>
192 std::vector<int> *adjcells)
const;
203 std::vector<int> *adjnodes)
const;
231 int const dim, std::array<int,D> lowindices,
bool lowval,
244 void build_index_combinations(
int dim,
245 std::array<int,D> indices,
246 std::array<std::array<int,2>,D> index_ranges,
247 std::vector<std::array<int,D>> *indices_list)
const;
257 template<
int D,
class CoordSys>
265 template<
int D,
class CoordSys>
275 template<
int D,
class CoordSys>
283 template<
int D,
class CoordSys>
285 return mesh_.space_dimension();
290 template<
int D,
class CoordSys>
292 return mesh_.distributed();
297 template<
int D,
class CoordSys>
299 return mesh_.num_ghost_layers();
304 template<
int D,
class CoordSys>
307 assert(D == mesh_.space_dimension());
310 for (
int d = 0; d < D; ++d) {
311 mesh_.get_global_coord_bounds(d, &(lo[d]), &(hi[d]));
317 template<
int D,
class CoordSys>
321 assert(dim < mesh_.space_dimension());
322 return mesh_.num_axis_points(dim, ptype);
327 template<
int D,
class CoordSys>
329 const int dim)
const {
331 assert(dim < mesh_.space_dimension());
332 int start_index = -mesh_.num_ghost_layers();
338 template<
int D,
class CoordSys>
340 const int dim)
const {
342 assert(dim < mesh_.space_dimension());
344 mesh_.num_axis_points(dim,
ALL));
349 template<
int D,
class CoordSys>
351 const int dim,
const int pointid)
const {
353 assert(dim < mesh_.space_dimension());
354 return mesh_.get_axis_point(dim, pointid);
359 template<
int D,
class CoordSys>
361 const int pointid)
const {
363 std::array<int,D> indices;
364 pointid_to_indices(pointid, &indices);
365 for (
int d = 0; d < D; d++) pnt[d] = mesh_.get_axis_point(d, indices[d]);
370 template<
int D,
class CoordSys>
374 assert(dim < mesh_.space_dimension());
375 return mesh_.num_axis_cells(dim, ptype);
380 template<
int D,
class CoordSys>
383 for (
int dim = 0; dim < mesh_.space_dimension(); ++dim) {
391 template<
int D,
class CoordSys>
393 if (mesh_.distributed()) {
394 int num_all_cells = 1;
395 for (
int dim = 0; dim < mesh_.space_dimension(); ++dim)
396 num_all_cells *= mesh_.num_axis_cells(dim,
ALL);
404 template<
int D,
class CoordSys>
409 for (
int d = 0; d < D; ++d) {
410 (*plo)[d] = mesh_.get_axis_point(d, indices[d]);
411 (*phi)[d] = mesh_.get_axis_point(d, indices[d]+1);
417 template<
int D,
class CoordSys>
420 for (
int dim = 0; dim < mesh_.space_dimension(); ++dim)
427 template<
int D,
class CoordSys>
429 if (mesh_.distributed()) {
430 int num_all_nodes = 1;
431 for (
int dim = 0; dim < mesh_.space_dimension(); ++dim)
432 num_all_nodes *= mesh_.num_axis_points(dim,
ALL);
440 template<
int D,
class CoordSys>
450 for (
int d = 0; d < D; d++) {
451 Entity_type dtype = mesh_.axis_point_type(d, indices[d]);
464 template<
int D,
class CoordSys>
474 for (
int d = 0; d < D; d++) {
476 int hi = indices[d]+1;
490 template<
int D,
class CoordSys>
496 for (
int d = 0; d < D; d++)
497 if (mesh_.point_on_external_boundary(d, indices[d]))
return true;
498 for (
int d = 0; d < D; d++)
499 if (mesh_.point_on_external_boundary(d, indices[d]+1))
return true;
504 for (
int d = 0; d < D; d++)
505 if (mesh_.point_on_external_boundary(d, indices[d]))
return true;
516 template<
int D,
class CoordSys>
518 int const dim, std::array<int,D> indices,
bool lowval,
521 int idx = lowval ? indices[dim] : indices[dim]+1;
522 double val = mesh_.get_axis_point(dim, idx);
523 for (
auto it = coords_begin; it != coords_end; it++) {
530 int ncoords = coords_end - coords_begin;
532 fill_dth_coord(dim-1, indices,
true,
533 coords_begin, coords_begin + ncoords/2);
535 fill_dth_coord(dim-1, indices,
false,
536 coords_begin + ncoords/2, coords_end);
542 template<
int D,
class CoordSys>
547 for (
int d = 0; d < D; d++) ncoords *= 2;
549 ccoords->resize(ncoords);
554 fill_dth_coord(D-1, indices,
true,
555 ccoords->begin(), ccoords->begin() + ncoords/2);
556 fill_dth_coord(D-1, indices,
false,
557 ccoords->begin() + ncoords/2, ccoords->end());
563 template<
int D,
class CoordSys>
565 const int cellid)
const {
569 double moment0 = 1.0;
570 for (
int d = 0; d < D; d++)
571 moment0 *= (hi[d]-lo[d]);
573 CoordSys::modify_volume(moment0, lo, hi);
579 template<
int D,
class CoordSys>
581 const int cellid,
Point<D> *ccen)
const {
585 double moment0 = 1.0;
586 for (
int d = 0; d < D; d++)
587 moment0 *= (hi[d]-lo[d]);
589 Point<D> moment1 = 0.5*(lo+hi)*moment0;
591 CoordSys::modify_volume(moment0, lo, hi);
592 CoordSys::modify_first_moments(moment1, lo, hi);
593 *ccen = moment1/moment0;
598 template<
int D,
class CoordSys>
601 assert(entity ==
CELL || entity ==
NODE);
602 if (mesh_.distributed())
603 assert(etype ==
ALL);
609 template<
int D,
class CoordSys>
613 assert(entity ==
CELL || entity ==
NODE);
614 if (mesh_.distributed())
615 assert(etype ==
ALL);
621 else if (entity ==
NODE)
625 return begin(entity, etype);
636 template<
int D,
class CoordSys>
638 const std::array<int,D>& indices)
const {
639 assert(D == mesh_.space_dimension());
642 for (
int d = D-1; d > 0; --d) {
643 int idx = indices[d]+mesh_.num_ghost_layers();
649 id += indices[0]+mesh_.num_ghost_layers();
656 template<
int D,
class CoordSys>
658 const int id)
const {
659 assert(D == mesh_.space_dimension());
660 std::array<int,D> indices;
663 std::array<int,D> denom;
665 for (
int d = 1; d < D; ++d) {
669 for (
int d = D-1; d > 0; --d) {
670 int index = residual / denom[d];
671 residual -= index * denom[d];
672 indices[d] = (int) index;
675 indices[0] = (int) residual;
677 for (
int d = 0; d < D; ++d)
678 indices[d] -= mesh_.num_ghost_layers();
688 template<
int D,
class CoordSys>
690 const std::array<int,D>& indices)
const {
691 assert(D == mesh_.space_dimension());
694 for (
int d = D-1; d > 0; --d) {
695 int idx = indices[d]+mesh_.num_ghost_layers();
696 int mult = mesh_.num_axis_points(d-1);
701 id += indices[0]+mesh_.num_ghost_layers();
708 template<
int D,
class CoordSys>
710 const int id)
const {
711 assert(D == mesh_.space_dimension());
712 std::array<int,D> indices;
715 std::array<int,D> denom;
717 for (
int d = 1; d < D; ++d) {
718 denom[d] = denom[d-1] * mesh_.num_axis_points(d-1);
721 for (
int d = D-1; d > 0; --d) {
722 int index = residual / denom[d];
723 residual -= index * denom[d];
724 indices[d] = (int) index;
727 indices[0] = (int) residual;
729 for (
int d = 0; d < D; ++d)
730 indices[d] -= mesh_.num_ghost_layers();
736 template<
int D,
class CoordSys>
739 std::array<int,D> indices,
740 std::array<std::array<int,2>,D> index_ranges,
741 std::vector<std::array<int,D>> *indices_list)
const {
742 for (
int i = index_ranges[dim][0]; i <= index_ranges[dim][1]; i++) {
745 indices_list->push_back(indices);
747 build_index_combinations(dim-1, indices, index_ranges, indices_list);
753 template<
int D,
class CoordSys>
755 const int cellid,
const Entity_type ptype, std::vector<int> *adjcells)
const {
758 std::array<std::array<int, 2>, D> index_ranges;
760 for (
int d = 0; d < D; d++) {
761 int num_points_all = mesh_.num_axis_points(d,
Wonton::ALL);
763 indices[d]-1 : indices[d];
764 index_ranges[d][1] = (indices[d]+1 < num_points_all-num_ghost_layers-1) ?
765 indices[d]+1 : indices[d];
769 for (
int d = 0; d < D; d++) nmax *= 3;
771 std::vector<std::array<int,D>> cell_indices;
772 cell_indices.reserve(nmax);
773 std::array<int, D> tmpindices {};
774 build_index_combinations(D-1, tmpindices, index_ranges, &cell_indices);
776 for (
auto const& inds : cell_indices) {
779 adjcells->push_back(
id);
785 template<
int D,
class CoordSys>
787 const int nodeid,
const Entity_type ptype, std::vector<int> *adjnodes)
const {
790 std::array<std::array<int, 2>, D> index_ranges;
792 for (
int d = 0; d < D; d++) {
793 int num_points_all = mesh_.num_axis_points(d,
Wonton::ALL);
795 indices[d]-1 : indices[d];
797 indices[d]+1 : indices[d];
801 for (
int d = 0; d < D; d++) nmax *= 3;
803 std::vector<std::array<int,D>> node_indices;
804 node_indices.reserve(nmax);
805 std::array<int, D> tmpindices {};
806 build_index_combinations(D-1, tmpindices, index_ranges, &node_indices);
808 for (
auto const& inds : node_indices) {
811 adjnodes->push_back(
id);
817 #endif // WONTON_DIRECT_PRODUCT_MESH_WRAPPER_H_
Direct_Product_Mesh< D, CoordSys > const & mesh() const
Definition: direct_product_mesh_wrapper.h:277
A wrapper that implements the prescribed interface for direct product meshes in Portage using the Dir...
Definition: direct_product_mesh_wrapper.h:43
int num_ghost_cells() const
Get number of ghost cells on this processing element.
Definition: direct_product_mesh_wrapper.h:392
double get_axis_point(const int dim, const int pointid) const
Get axis point value.
Definition: direct_product_mesh_wrapper.h:350
counting_iterator axis_point_end(const int dim) const
Get iterator for axis point (end of array).
Definition: direct_product_mesh_wrapper.h:339
int num_axis_cells(const int dim, const Entity_type ptype=ALL) const
Get number of cells along axis.
Definition: direct_product_mesh_wrapper.h:371
Factorize a number N into D equal (or nearly equal) factors.
Definition: adaptive_refinement_mesh.h:31
std::vector< T > vector
Definition: wonton.h:285
int num_ghost_layers() const
Number of ghost layers in each direction at each end.
Definition: direct_product_mesh_wrapper.h:298
double cell_volume(const int id) const
Get cell volume.
Definition: direct_product_mesh_wrapper.h:564
Definition of the Direct_Product_Mesh class.
Entity_type
The parallel type of a given entity.
Definition: wonton.h:124
int num_ghost_nodes() const
Get number of ghost nodes on this processing element.
Definition: direct_product_mesh_wrapper.h:428
Entity_type cell_get_type(const int id) const
Cell type (PARALLEL_OWNED, PARALLEL_GHOST or BOUNDARY_GHOST)
Definition: direct_product_mesh_wrapper.h:466
std::array< int, D > cellid_to_indices(const int id) const
Convert from ID to indices of lo corner of cell.
Definition: direct_product_mesh_wrapper.h:657
boost::counting_iterator< int > counting_iterator
Definition: wonton.h:290
std::array< int, D > nodeid_to_indices(const int id) const
Convert from node ID to indices of node.
Definition: direct_product_mesh_wrapper.h:709
bool distributed() const
Is mesh distributed?
Definition: direct_product_mesh_wrapper.h:291
A basic, axis-aligned, logically-rectangular mesh.
Definition: direct_product_mesh.h:112
counting_iterator axis_point_begin(const int dim) const
Get iterator for axis point (beginning of array).
Definition: direct_product_mesh_wrapper.h:328
Represents a point in an N-dimensional space.
Definition: Point.h:50
int indices_to_nodeid(const std::array< int, D > &indices) const
Convert from indices of node to node ID.
Definition: direct_product_mesh_wrapper.h:689
void cell_get_node_adj_cells(const int cellid, const Entity_type ptype, std::vector< int > *adjcells) const
Get the list of cell IDs for all cells attached to a specific cell through its faces.
Definition: direct_product_mesh_wrapper.h:754
bool on_exterior_boundary(const Entity_kind entity, const int id) const
If entity is on exterior (global not partition) boundary.
Definition: direct_product_mesh_wrapper.h:491
counting_iterator make_counting_iterator(int const i)
Definition: wonton.h:291
counting_iterator begin(Entity_kind const entity, Entity_type const etype=ALL) const
Iterators on mesh entity - begin.
Definition: direct_product_mesh_wrapper.h:599
void cell_get_bounds(const int id, Point< D > *plo, Point< D > *phi) const
Get lower and upper corners of cell bounding box.
Definition: direct_product_mesh_wrapper.h:405
Entity_kind
The type of mesh entity.
Definition: wonton.h:81
void cell_centroid(const int id, Point< D > *ccen) const
Get cell centroid.
Definition: direct_product_mesh_wrapper.h:580
void cell_get_coordinates(const int id, std::vector< Point< D >> *ccoords) const
Get coordinates of cell points.
Definition: direct_product_mesh_wrapper.h:543
Direct_Product_Mesh_Wrapper()=delete
Default constructor (disabled)
void get_global_bounds(Point< D > *plo, Point< D > *phi) const
Get global mesh bounds.
Definition: direct_product_mesh_wrapper.h:305
~Direct_Product_Mesh_Wrapper()
Destructor.
Definition: direct_product_mesh_wrapper.h:266
int indices_to_cellid(const std::array< int, D > &indices) const
Convert from indices of lo corner of cell to cell ID.
Definition: direct_product_mesh_wrapper.h:637
Point< D > get_node_coordinates(const int pointid) const
Get coordinates of node.
Definition: direct_product_mesh_wrapper.h:360
Entity_type node_get_type(const int id) const
Node type (PARALLEL_OWNED, PARALLEL_GHOST or BOUNDARY_GHOST)
Definition: direct_product_mesh_wrapper.h:442
int space_dimension() const
Get dimensionality of the mesh.
Definition: direct_product_mesh_wrapper.h:284
int num_owned_nodes() const
Get number of nodes owned by this processing element.
Definition: direct_product_mesh_wrapper.h:418
int num_owned_cells() const
Get number of cells owned by this processing element.
Definition: direct_product_mesh_wrapper.h:381
void node_get_cell_adj_nodes(const int nodeid, const Entity_type ptype, std::vector< int > *adjnodes) const
Get the list of node IDs for all nodes attached to all cells attached to a specific node...
Definition: direct_product_mesh_wrapper.h:786
Direct_Product_Mesh_Wrapper & operator=(Direct_Product_Mesh_Wrapper< D, CoordSys > const &)=delete
Assignment operator (disabled).
int num_axis_points(const int dim, const Entity_type ptype=ALL) const
Get number of points along axis.
Definition: direct_product_mesh_wrapper.h:318
counting_iterator end(Entity_kind const entity, Entity_type const etype=ALL) const
Iterator on mesh entity - end.
Definition: direct_product_mesh_wrapper.h:610