7 #ifndef FLAT_MESH_WRAPPER_H_ 8 #define FLAT_MESH_WRAPPER_H_ 35 template <
class T=
double>
48 template<
class Mesh_Wrapper>
52 dim_ = input.space_dimension();
54 numOwnedCells_ = input.num_owned_cells();
55 int numCells = numOwnedCells_ + input.num_ghost_cells();
57 numOwnedNodes_ = input.num_owned_nodes();
58 int numNodes = numOwnedNodes_ + input.num_ghost_nodes();
63 numOwnedFaces_ = input.num_owned_faces();
64 numFaces = numOwnedFaces_ + input.num_ghost_faces();
68 reset_and_reserve(numCells, numFaces, numNodes);
76 for (
int c = 0; c < numCells; c++)
80 std::vector<int> cellNodes;
81 input.cell_get_nodes(c, &cellNodes);
82 cellNodeCounts_.push_back(cellNodes.size());
83 cellToNodeList_.insert(cellToNodeList_.end(),
84 cellNodes.begin(), cellNodes.end());
88 for (
int n = 0; n < numNodes; ++n) {
101 for (
int n=0; n<numNodes; ++n) {
103 input.node_get_coordinates(n, &nodeCoord);
104 for (
int j=0; j<2; ++j)
105 nodeCoords_.push_back(nodeCoord[j]);
118 for (
int c=0; c<numCells; ++c)
120 std::vector<int> cellFaces, cfDirs;
121 input.cell_get_faces_and_dirs(c, &cellFaces, &cfDirs);
122 cellFaceCounts_.push_back(cellFaces.size());
123 cellToFaceList_.insert(cellToFaceList_.end(),
124 cellFaces.begin(), cellFaces.end());
125 int const nb_cell_faces = cellFaces.size();
126 for (
int j = 0; j < nb_cell_faces; ++j)
127 cellToFaceDirs_.push_back(cfDirs[j] >= 0);
131 for (
int f=0; f<numFaces; ++f)
134 std::vector<int> faceNodes;
135 input.face_get_nodes(f, &faceNodes);
136 faceNodeCounts_.push_back(faceNodes.size());
137 faceToNodeList_.insert(faceToNodeList_.end(),
138 faceNodes.begin(), faceNodes.end());
142 for (
int n=0; n<numNodes; ++n) {
144 input.node_get_coordinates(n, &nodeCoord);
145 for (
int j=0; j<3; ++j)
146 nodeCoords_.push_back(nodeCoord[j]);
197 cellToFaceList_.clear();
198 cellToFaceList_.reserve(cellNodeCounts_.size());
200 cellToFaceDirs_.clear();
201 cellToFaceDirs_.reserve(cellNodeCounts_.size());
203 faceToNodeList_.clear();
204 faceToNodeList_.reserve(cellToNodeList_.size());
213 std::map<std::pair<int, int>,
int> nodePairToFaceTmp;
217 int const nb_cell_node_counts = cellNodeCounts_.size();
219 for (
int c = 0; c < nb_cell_node_counts; ++c) {
220 int offset = cellNodeOffsets_[c];
221 int count = cellNodeCounts_[c];
222 for (
int i=0; i<count; ++i) {
223 int n0 = cellToNodeList_[offset+i];
224 int n1 = cellToNodeList_[offset+((i+1)%count)];
226 int p0 = std::min(n0, n1);
227 int p1 = std::max(n0, n1);
228 auto npair = std::make_pair(p0, p1);
229 auto it = nodePairToFaceTmp.find(npair);
231 if (it == nodePairToFaceTmp.end()) {
234 nodePairToFaceTmp.insert(std::make_pair(npair, face));
235 faceToNodeList_.emplace_back(p0);
236 faceToNodeList_.emplace_back(p1);
243 cellToFaceList_.emplace_back(face);
244 cellToFaceDirs_.push_back(n0 == p0);
247 if (c == numOwnedCells_ - 1) numOwnedFaces_ = facecount;
260 cellNodeCounts_.clear();
261 cellNodeCounts_.reserve(cellFaceCounts_.size());
263 cellToNodeList_.clear();
264 cellToNodeList_.reserve(cellFaceCounts_.size() * 4);
265 int const nb_cell_face_counts = cellFaceCounts_.size();
267 for (
int c = 0; c < nb_cell_face_counts; ++c) {
268 std::vector<int> cellfaces, dummy;
270 std::set<int> cellnodes;
272 for (
auto const& f : cellfaces) {
273 std::vector<int> facenodes;
275 cellnodes.insert(facenodes.begin(), facenodes.end());
278 cellNodeCounts_.emplace_back(cellnodes.size());
279 cellToNodeList_.insert(cellToNodeList_.end(),
280 cellnodes.begin(), cellnodes.end());
286 int numNodes = nodeCoords_.size()/dim_;
287 std::vector<std::set<int>> nodeToCellTmp(numNodes);
288 int const nb_cell_node_counts = cellNodeCounts_.size();
290 for (
int c = 0; c < nb_cell_node_counts; ++c) {
291 int offset = cellNodeOffsets_[c];
292 int count = cellNodeCounts_[c];
293 for (
int i=0; i<count; ++i) {
294 int n = cellToNodeList_[offset+i];
295 nodeToCellTmp[n].insert(c);
299 nodeCellCounts_.clear();
300 nodeCellCounts_.reserve(numNodes);
302 nodeToCellList_.clear();
303 nodeToCellList_.reserve(cellToNodeList_.size());
305 for (
int n=0; n<numNodes; ++n) {
306 const std::set<int>& nodes = nodeToCellTmp[n];
307 nodeCellCounts_.emplace_back(nodes.size());
308 nodeToCellList_.insert(nodeToCellList_.end(), nodes.begin(), nodes.end());
317 std::vector<int>* offsets) {
318 offsets->resize(counts.size());
319 if (not counts.empty()) {
321 std::partial_sum(counts.begin(), counts.end()-1, offsets->begin()+1);
327 return numOwnedCells_;
332 return (cellNodeCounts_.size() - numOwnedCells_);
337 return numOwnedNodes_;
342 return (nodeCoords_.size()/dim_ - numOwnedNodes_);
347 return numOwnedFaces_;
353 return (faceToNodeList_.size() / 2 - numOwnedFaces_);
356 return (faceNodeCounts_.size() - numOwnedFaces_);
364 for (
int j=0; j<dim_; j++)
365 (*pp)[j] = nodeCoords_[nodeid*dim_+j];
387 std::vector<int> *cfdirs)
const {
391 offset = cellNodeOffsets_[cellid];
392 count = cellNodeCounts_[cellid];
396 offset = cellFaceOffsets_[cellid];
397 count = cellFaceCounts_[cellid];
399 cfaces->assign(&cellToFaceList_[offset],
400 &cellToFaceList_[offset+count]);
402 for (
int j=0; j<count; ++j)
403 cfdirs->push_back(cellToFaceDirs_[offset + j] ? 1 : -1);
408 int offset = cellNodeOffsets_[cellid];
409 int count = cellNodeCounts_[cellid];
410 nodes->assign(&cellToNodeList_[offset],
411 &cellToNodeList_[offset+count]);
424 offset = faceNodeOffsets_[faceid];
425 count = faceNodeCounts_[faceid];
427 fnodes->assign(&faceToNodeList_[offset],
428 &faceToNodeList_[offset+count]);
433 std::vector<int> *cells)
const {
434 int offset = nodeCellOffsets_[nodeid];
435 int count = nodeCellCounts_[nodeid];
437 cells->assign(&nodeToCellList_[offset],
438 &nodeToCellList_[offset+count]);
441 cells->reserve(count);
442 for (
int i = 0; i < count; i++) {
443 int c = nodeToCellList_[offset+i];
456 std::vector<int> nodes;
458 int cellNumNodes = nodes.size();
459 pplist->resize(cellNumNodes);
460 for (
int i=0; i<cellNumNodes; ++i)
473 { cellToNodeList_ = cellToNodeList; }
479 { cellNodeCounts_ = cellNodeCounts; }
489 { cellToFaceList_ = cellToFaceList; }
495 { cellToFaceDirs_ = cellToFaceDirs; }
501 { cellFaceCounts_ = cellFaceCounts; }
511 { faceToNodeList_ = faceToNodeList; }
517 { faceNodeCounts_ = faceNodeCounts; }
543 { nodeGlobalIds_ = nodeGlobalIds; }
547 { numOwnedCells_ = numOwnedCells; }
551 { numOwnedFaces_ = numOwnedFaces; }
555 { numOwnedNodes_ = numOwnedNodes; }
577 std::vector<T> nodeCoords_;
578 std::vector<int> cellToNodeList_;
579 std::vector<int> cellNodeCounts_;
580 std::vector<int> cellNodeOffsets_;
581 std::vector<int> cellToFaceList_;
582 std::vector<bool> cellToFaceDirs_;
584 std::vector<int> cellFaceCounts_;
586 std::vector<int> cellFaceOffsets_;
587 std::vector<int> faceToNodeList_;
588 std::vector<int> faceNodeCounts_;
589 std::vector<int> faceNodeOffsets_;
590 std::vector<int> nodeToCellList_;
591 std::vector<int> nodeCellCounts_;
592 std::vector<int> nodeCellOffsets_;
594 std::vector<GID_t> cellGlobalIds_;
595 std::vector<GID_t> faceGlobalIds_;
596 std::vector<GID_t> nodeGlobalIds_;
599 void reset_and_reserve(
int numCells,
int numFaces,
int numNodes){
602 nodeCoords_.reserve(numNodes*dim_);
604 cellNodeCounts_.clear();
605 cellNodeCounts_.reserve(numCells);
607 cellToNodeList_.clear();
608 cellToNodeList_.reserve(numCells*(dim_+1));
610 cellGlobalIds_.clear();
611 cellGlobalIds_.reserve(numCells);
613 nodeGlobalIds_.clear();
614 nodeGlobalIds_.reserve(numNodes);
616 faceNodeCounts_.clear();
617 faceToNodeList_.clear();
618 faceGlobalIds_.clear();
620 cellFaceCounts_.clear();
621 cellToFaceList_.clear();
622 cellToFaceDirs_.clear();
628 faceGlobalIds_.reserve(numFaces);
629 faceNodeCounts_.reserve(numFaces);
630 cellFaceCounts_.reserve(numCells);
633 faceToNodeList_.reserve(numFaces*dim_);
634 cellToFaceList_.reserve(numCells*(dim_+1));
635 cellToFaceDirs_.reserve(numCells*(dim_+1));
643 #endif // FLAT_MESH_WRAPPER_H_ void set_num_owned_nodes(int numOwnedNodes)
set the number of owned nodes
Definition: flat_mesh_wrapper.h:554
std::vector< GID_t > & get_global_cell_ids()
get global cell ids
Definition: flat_mesh_wrapper.h:534
GID_t get_global_id(int ent, Entity_kind onwhat) const
Get global ID of entities.
Definition: flat_mesh_wrapper.h:561
void cell_get_faces_and_dirs(int const cellid, std::vector< int > *cfaces, std::vector< int > *cfdirs) const
Get cell faces and the directions in which they are used.
Definition: flat_mesh_wrapper.h:386
int num_owned_cells() const
Number of owned cells in the mesh.
Definition: flat_mesh_wrapper.h:326
void set_node_global_ids(std::vector< GID_t > &nodeGlobalIds)
Definition: flat_mesh_wrapper.h:542
std::vector< int > & get_cell_node_counts()
get/set cell node counts
Definition: flat_mesh_wrapper.h:476
void cell_get_nodes(int const cellid, std::vector< int > *nodes) const
Get list of nodes for a cell.
Definition: flat_mesh_wrapper.h:407
void set_cell_node_counts(std::vector< int > &cellNodeCounts)
Definition: flat_mesh_wrapper.h:478
std::vector< int > & get_node_cell_counts()
get node cell counts
Definition: flat_mesh_wrapper.h:527
void finish_init()
Finish mesh initialization, after initialize or MPI distribute.
Definition: flat_mesh_wrapper.h:162
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
Flat_Mesh_Wrapper & operator=(Flat_Mesh_Wrapper const &)=delete
Assignment operator (disabled) - don't know how to implement (RVG)
void make_index_maps()
Definition: flat_mesh_wrapper.h:182
Entity_type
The parallel type of a given entity.
Definition: wonton.h:124
void set_face_to_node_list(std::vector< int > &faceToNodeList)
Definition: flat_mesh_wrapper.h:510
std::vector< bool > & get_cell_to_face_dirs()
get/set cell to face dirs
Definition: flat_mesh_wrapper.h:492
Wonton::Element_type cell_get_element_type(int const cellid) const
Definition: flat_mesh_wrapper.h:380
~Flat_Mesh_Wrapper()=default
Empty destructor.
int num_ghost_nodes() const
Number of ghost nodes in the mesh.
Definition: flat_mesh_wrapper.h:341
std::vector< int > & get_node_cell_offsets()
get node cell offsets
Definition: flat_mesh_wrapper.h:530
void set_cell_to_face_dirs(std::vector< bool > &cellToFaceDirs)
Definition: flat_mesh_wrapper.h:494
std::vector< int > & get_face_to_node_list()
Definition: flat_mesh_wrapper.h:508
int num_ghost_faces() const
Number of ghost faces in the mesh.
Definition: flat_mesh_wrapper.h:351
int num_owned_faces() const
Number of owned faces in the mesh.
Definition: flat_mesh_wrapper.h:346
void set_cell_to_node_list(std::vector< int > &cellToNodeList)
Definition: flat_mesh_wrapper.h:472
std::vector< int > & get_cell_to_node_list()
Definition: flat_mesh_wrapper.h:470
void node_get_cells(int const nodeid, Entity_type const ptype, std::vector< int > *cells) const
Get list of cells for a node.
Definition: flat_mesh_wrapper.h:432
void set_num_owned_cells(int numOwnedCells)
set the number of owned cells
Definition: flat_mesh_wrapper.h:546
std::vector< int > & get_cell_node_offsets()
get cell node offsets
Definition: flat_mesh_wrapper.h:482
int num_owned_nodes() const
Number of owned nodes in the mesh.
Definition: flat_mesh_wrapper.h:336
Represents a point in an N-dimensional space.
Definition: Point.h:50
void node_get_coordinates(int const nodeid, Point< D > *pp) const
Coords of a node.
Definition: flat_mesh_wrapper.h:362
Wonton::Entity_type node_get_type(int const nodeid) const
Get the type of the node - PARALLEL_OWNED or PARALLEL_GHOST.
Definition: flat_mesh_wrapper.h:374
std::vector< int > & get_cell_face_offsets()
get cell face offsets
Definition: flat_mesh_wrapper.h:504
Wonton::Entity_type cell_get_type(int const cellid) const
Get the type of the cell - PARALLEL_OWNED or PARALLEL_GHOST.
Definition: flat_mesh_wrapper.h:369
Flat_Mesh_Wrapper()=default
Constructor.
std::vector< int > & get_node_to_cell_list()
Definition: flat_mesh_wrapper.h:524
Flat_Mesh_Wrapper implements mesh methods.
Definition: flat_mesh_wrapper.h:36
Entity_kind
The type of mesh entity.
Definition: wonton.h:81
void compute_offsets(const std::vector< int > &counts, std::vector< int > *offsets)
Compute offsets from counts.
Definition: flat_mesh_wrapper.h:316
void build_aux_entities()
Definition: AuxMeshTopology.h:1331
int64_t GID_t
Definition: wonton.h:76
void cell_get_coordinates(int const cellid, std::vector< Wonton::Point< D >> *pplist) const
Coords of nodes of a cell.
Definition: flat_mesh_wrapper.h:452
int num_ghost_cells() const
Number of ghost cells in the mesh.
Definition: flat_mesh_wrapper.h:331
int space_dimension() const
get spatial dimension
Definition: flat_mesh_wrapper.h:558
std::vector< int > & get_face_node_offsets()
get face node offsets
Definition: flat_mesh_wrapper.h:520
void initialize(Mesh_Wrapper &input)
Definition: flat_mesh_wrapper.h:49
Element_type
Element (cell topology) type.
Definition: wonton.h:153
void set_num_owned_faces(int numOwnedFaces)
set the number of owned cells
Definition: flat_mesh_wrapper.h:550
std::vector< GID_t > & get_global_face_ids()
get global face ids
Definition: flat_mesh_wrapper.h:540
std::vector< T > & get_coords()
get coordinates
Definition: flat_mesh_wrapper.h:466
void set_cell_face_counts(std::vector< int > &cellFaceCounts)
Definition: flat_mesh_wrapper.h:500
void set_face_node_counts(std::vector< int > &faceNodeCounts)
Definition: flat_mesh_wrapper.h:516
void face_get_nodes(int const faceid, std::vector< int > *fnodes) const
Get nodes of a face.
Definition: flat_mesh_wrapper.h:415
std::vector< GID_t > & get_global_node_ids()
get global node ids
Definition: flat_mesh_wrapper.h:537
std::vector< int > & get_cell_face_counts()
get/set cell face counts
Definition: flat_mesh_wrapper.h:498
std::vector< int > & get_face_node_counts()
get/set face node counts
Definition: flat_mesh_wrapper.h:514
void set_cell_to_face_list(std::vector< int > &cellToFaceList)
Definition: flat_mesh_wrapper.h:488
std::vector< int > & get_cell_to_face_list()
Definition: flat_mesh_wrapper.h:486