Zoltan2
Loading...
Searching...
No Matches
Zoltan2_MeshAdapter.hpp
Go to the documentation of this file.
1// @HEADER
2// *****************************************************************************
3// Zoltan2: A package of combinatorial algorithms for scientific computing
4//
5// Copyright 2012 NTESS and the Zoltan2 contributors.
6// SPDX-License-Identifier: BSD-3-Clause
7// *****************************************************************************
8// @HEADER
9
15#ifndef _ZOLTAN2_MESHADAPTER_HPP_
16#define _ZOLTAN2_MESHADAPTER_HPP_
17
18#include <Zoltan2_Adapter.hpp>
19#include "TpetraExt_MatrixMatrix.hpp"
20
21namespace Zoltan2 {
22
33
40 POINT, // a 0D entity (e.g. a vertex)
41 LINE_SEGMENT, // a 1D entity (e.g. an edge)
42 POLYGON, // a general 2D entity
43 TRIANGLE, // a specific 2D entity bounded by 3 edge entities
44 QUADRILATERAL, // a specific 2D entity bounded by 4 edge entities
45 POLYHEDRON, // a general 3D entity
46 TETRAHEDRON, // a specific 3D entity bounded by 4 triangle entities
47 HEXAHEDRON, // a specific 3D entity bounded by 6 quadrilateral
48 // entities
49 PRISM, // a specific 3D entity bounded by a combination of 3
50 //quadrilateral entities and 2 triangle entities
51 PYRAMID // a specific 3D entity bounded by a combination of 1
52 // quadrilateral entity and 4 triangle entities
53};
54
87template <typename User>
88class MeshAdapter : public AdapterWithCoords<User> {
89public:
90
91#ifndef DOXYGEN_SHOULD_SKIP_THIS
94 typedef typename InputTraits<User>::lno_t lno_t;
95 typedef typename InputTraits<User>::gno_t gno_t;
96 typedef typename InputTraits<User>::part_t part_t;
97 typedef typename InputTraits<User>::node_t node_t;
98 typedef User user_t;
99 typedef User userCoord_t;
100 typedef MeshAdapter<User> base_adapter_t;
101#endif
102
103 enum BaseAdapterType adapterType() const override {return MeshAdapterType;}
104
105 // Default MeshEntityType is MESH_REGION with MESH_FACE-based adjacencies and
106 // second adjacencies and coordinates
107 MeshAdapter() : primaryEntityType(MESH_REGION),
108 adjacencyEntityType(MESH_FACE),
109 secondAdjacencyEntityType(MESH_FACE) {};
110
112 // Methods to be defined in derived classes.
113
118 virtual bool areEntityIDsUnique(MeshEntityType etype) const
119 {
120 return etype==this->getPrimaryEntityType();
121 }
122
125 //virtual size_t getGlobalNumOf(MeshEntityType etype) const = 0;
126
129 virtual size_t getLocalNumOf(MeshEntityType etype) const = 0;
130
131
136 virtual void getIDsViewOf(MeshEntityType etype,
137 gno_t const *&Ids) const = 0;
138
139
145 enum EntityTopologyType const *&Types) const
146 {
147 Types = NULL;
149 }
150
156 virtual int getNumWeightsPerOf(MeshEntityType etype) const { return 0; }
157
172 const scalar_t *&weights, int &stride, int idx = 0) const
173 {
174 weights = NULL;
175 stride = 0;
177 }
178
179
188 virtual int getDimension() const { return 0; }
189
201 const scalar_t *&coords, int &stride, int coordDim) const
202 {
203 coords = NULL;
204 stride = 0;
206 }
207
208
211 virtual bool availAdjs(MeshEntityType source, MeshEntityType target) const {
212 return false;
213 }
214
215
218 virtual size_t getLocalNumAdjs(MeshEntityType source,
219 MeshEntityType target) const { return 0;}
220
221
232 virtual void getAdjsView(MeshEntityType source, MeshEntityType target,
233 const offset_t *&offsets, const gno_t *& adjacencyIds) const
234 {
235 offsets = NULL;
236 adjacencyIds = NULL;
238 }
239
240
245 virtual bool avail2ndAdjs(MeshEntityType sourcetarget,
246 MeshEntityType through) const
247 {
248 return false;
249 }
250
254 virtual size_t getLocalNum2ndAdjs(MeshEntityType sourcetarget,
255 MeshEntityType through) const
256 {
257 return 0;
258 }
259
270 virtual void get2ndAdjsView(MeshEntityType sourcetarget,
271 MeshEntityType through,
272 const offset_t *&offsets,
273 const gno_t *&adjacencyIds) const
274 {
275 offsets = NULL;
276 adjacencyIds = NULL;
278 }
279
283 virtual int getNumWeightsPer2ndAdj(MeshEntityType sourcetarget,
284 MeshEntityType through) const { return 0;}
285
286
296 virtual void get2ndAdjWeightsView(MeshEntityType sourcetarget,
297 MeshEntityType through,
298 const scalar_t *&weights,
299 int &stride,
300 int idx) const
301 {
302 weights = NULL;
303 stride = 0;
305 }
306
308 // Implementations of base-class methods
309
313 return this->primaryEntityType;
314 }
315
322 return this->adjacencyEntityType;
323 }
324
331 return this->secondAdjacencyEntityType;
332 }
333
340 void setEntityTypes(std::string ptypestr, std::string atypestr,
341 std::string satypestr) {
342
343 if (ptypestr != atypestr && ptypestr != satypestr) {
344 if (ptypestr == "region")
345 this->primaryEntityType = MESH_REGION;
346 else if (ptypestr == "face")
347 this->primaryEntityType = MESH_FACE;
348 else if (ptypestr == "edge")
349 this->primaryEntityType = MESH_EDGE;
350 else if (ptypestr == "vertex")
351 this->primaryEntityType = MESH_VERTEX;
352 else {
353 std::ostringstream emsg;
354 emsg << __FILE__ << "," << __LINE__
355 << " error: Invalid MeshEntityType " << ptypestr << std::endl;
356 emsg << "Valid values: region face edge vertex" << std::endl;
357 throw std::runtime_error(emsg.str());
358 }
359
360 if (atypestr == "region")
361 this->adjacencyEntityType = MESH_REGION;
362 else if (atypestr == "face")
363 this->adjacencyEntityType = MESH_FACE;
364 else if (atypestr == "edge")
365 this->adjacencyEntityType = MESH_EDGE;
366 else if (atypestr == "vertex")
367 this->adjacencyEntityType = MESH_VERTEX;
368 else {
369 std::ostringstream emsg;
370 emsg << __FILE__ << "," << __LINE__
371 << " error: Invalid MeshEntityType " << atypestr << std::endl;
372 emsg << "Valid values: region face edge vertex" << std::endl;
373 throw std::runtime_error(emsg.str());
374 }
375
376 if (satypestr == "region")
377 this->secondAdjacencyEntityType = MESH_REGION;
378 else if (satypestr == "face")
379 this->secondAdjacencyEntityType = MESH_FACE;
380 else if (satypestr == "edge")
381 this->secondAdjacencyEntityType = MESH_EDGE;
382 else if (satypestr == "vertex")
383 this->secondAdjacencyEntityType = MESH_VERTEX;
384 else {
385 std::ostringstream emsg;
386 emsg << __FILE__ << "," << __LINE__
387 << " error: Invalid MeshEntityType " << satypestr << std::endl;
388 emsg << "Valid values: region face edge vertex" << std::endl;
389 throw std::runtime_error(emsg.str());
390 }
391 }
392 else {
393 std::ostringstream emsg;
394 emsg << __FILE__ << "," << __LINE__
395 << " error: PrimaryEntityType " << ptypestr
396 << " matches AdjacencyEntityType " << atypestr
397 << " or SecondAdjacencyEntityType " << satypestr << std::endl;
398 throw std::runtime_error(emsg.str());
399 }
400 }
401
406 virtual bool useDegreeAsWeightOf(MeshEntityType etype, int idx) const
407 {
408 return false;
409 }
410
412 // Functions from the BaseAdapter interface
413 size_t getLocalNumIDs() const override {
415 }
416
417 void getIDsView(const gno_t *&Ids) const override {
419 }
420
421 void getIDsKokkosView(Kokkos::View<const gno_t *,
422 typename node_t::device_type> &ids) const override
423 {
424 Kokkos::View<gno_t *, typename node_t::device_type>
425 kokkos_ids("gids", getLocalNumIDs());
426 auto host_kokkos_ids = Kokkos::create_mirror_view(kokkos_ids);
427
428 const gno_t * gnos;
429 getIDsView(gnos);
430 for(size_t n = 0; n < getLocalNumIDs(); ++n) {
431 host_kokkos_ids(n) = gnos[n];
432 }
433 Kokkos::deep_copy(kokkos_ids, host_kokkos_ids);
434 ids = kokkos_ids;
435 }
436
437 int getNumWeightsPerID() const override {
439 }
440
441 void getWeightsView(const scalar_t *&wgt, int &stride, int idx = 0) const override {
442 getWeightsViewOf(getPrimaryEntityType(), wgt, stride, idx);
443 }
444
445 void getCoordinatesView(const scalar_t *&coords, int &stride,
446 int coordDim) const override
447 {
448 getCoordinatesViewOf(getPrimaryEntityType(), coords, stride, coordDim);
449 }
450
452 // coordinates in MJ are LayoutLeft since Tpetra Multivector gives LayoutLeft
453 Kokkos::View<scalar_t **, Kokkos::LayoutLeft, typename node_t::device_type> & elements) const override
454 {
455 // coordinates in MJ are LayoutLeft since Tpetra Multivector gives LayoutLeft
456 Kokkos::View<scalar_t **, Kokkos::LayoutLeft, typename node_t::device_type>
457 kokkos_coordinates("pamgen coords", getLocalNumIDs(), getDimension());
458 auto host_temp_values = Kokkos::create_mirror_view(kokkos_coordinates);
459 const scalar_t * coords;
460 for(int dim = 0; dim < getDimension(); ++dim) {
461 int stride = -1;
462 getCoordinatesView(coords, stride, dim);
463 for(size_t n = 0; n < getLocalNumIDs(); ++n) {
464 host_temp_values(n, dim) = coords[n*stride];
465 }
466 }
467 Kokkos::deep_copy(kokkos_coordinates, host_temp_values);
468 elements = kokkos_coordinates;
469 }
470
471 bool useDegreeAsWeight(int idx) const
472 {
474 }
475
476private:
477 enum MeshEntityType primaryEntityType; // Entity type
478 // to be partitioned, ordered,
479 // colored, matched, etc.
480 enum MeshEntityType adjacencyEntityType; // Entity type defining first-order
481 // adjacencies; adjacencies are of
482 // this type.
483 enum MeshEntityType secondAdjacencyEntityType; // Bridge entity type
484 // defining second-order
485 // adjacencies.
486};
487
488} //namespace Zoltan2
489
490#endif
Zoltan2::BasicUserTypes< zscalar_t, zlno_t, zgno_t > user_t
Definition Metric.cpp:39
#define Z2_THROW_NOT_IMPLEMENTED
typename BaseAdapter< User >::scalar_t scalar_t
typename InputTraits< User >::node_t node_t
typename InputTraits< User >::lno_t lno_t
typename InputTraits< User >::gno_t gno_t
typename InputTraits< User >::offset_t offset_t
typename InputTraits< User >::part_t part_t
MeshAdapter defines the interface for mesh input.
virtual void getWeightsViewOf(MeshEntityType etype, const scalar_t *&weights, int &stride, int idx=0) const
Provide a pointer to one of the number of this process' optional entity weights.
virtual void get2ndAdjWeightsView(MeshEntityType sourcetarget, MeshEntityType through, const scalar_t *&weights, int &stride, int idx) const
Provide a pointer to the second adjacency weights, if any. Note: second-adjacency weights may be used...
virtual int getNumWeightsPer2ndAdj(MeshEntityType sourcetarget, MeshEntityType through) const
Returns the number (0 or greater) of weights per second adjacency. Note: second-adjacency weights may...
void getCoordinatesKokkosView(Kokkos::View< scalar_t **, Kokkos::LayoutLeft, typename node_t::device_type > &elements) const override
size_t getLocalNumIDs() const override
Returns the number of objects on this process.
virtual bool availAdjs(MeshEntityType source, MeshEntityType target) const
Returns whether a first adjacency combination is available.
virtual int getNumWeightsPerOf(MeshEntityType etype) const
Return the number of weights per entity.
void getIDsKokkosView(Kokkos::View< const gno_t *, typename node_t::device_type > &ids) const override
virtual size_t getLocalNum2ndAdjs(MeshEntityType sourcetarget, MeshEntityType through) const
if avail2ndAdjs(), returns the number of second adjacencies on this process.
void getIDsView(const gno_t *&Ids) const override
Provide a pointer to this process' identifiers.
void getCoordinatesView(const scalar_t *&coords, int &stride, int coordDim) const override
virtual void getTopologyViewOf(MeshEntityType etype, enum EntityTopologyType const *&Types) const
Provide a pointer to the entity topology types.
enum MeshEntityType getAdjacencyEntityType() const
Returns the entity that describes adjacencies between the entities to be partitioned,...
enum BaseAdapterType adapterType() const override
Returns the type of adapter.
virtual int getDimension() const
Return dimension of the entity coordinates, if any.
virtual size_t getLocalNumOf(MeshEntityType etype) const =0
Returns the global number of mesh entities of MeshEntityType.
virtual size_t getLocalNumAdjs(MeshEntityType source, MeshEntityType target) const
Returns the number of first adjacencies on this process.
virtual void getIDsViewOf(MeshEntityType etype, gno_t const *&Ids) const =0
Provide a pointer to this process' identifiers.
virtual bool areEntityIDsUnique(MeshEntityType etype) const
Provide a pointer to the entity topology types.
virtual void getCoordinatesViewOf(MeshEntityType etype, const scalar_t *&coords, int &stride, int coordDim) const
Provide a pointer to one dimension of entity coordinates.
virtual void getAdjsView(MeshEntityType source, MeshEntityType target, const offset_t *&offsets, const gno_t *&adjacencyIds) const
Sets pointers to this process' mesh first adjacencies.
enum MeshEntityType getSecondAdjacencyEntityType() const
Returns the entity that describes second adjacencies between the entities to be partitioned,...
void getWeightsView(const scalar_t *&wgt, int &stride, int idx=0) const override
virtual bool useDegreeAsWeightOf(MeshEntityType etype, int idx) const
Optional method allowing the idx-th weight of entity type etype to be set as the number of neighbors ...
virtual bool avail2ndAdjs(MeshEntityType sourcetarget, MeshEntityType through) const
Returns whether a second adjacency combination is available. If combination is not available in the M...
enum MeshEntityType getPrimaryEntityType() const
Returns the entity to be partitioned, ordered, colored, etc.
int getNumWeightsPerID() const override
Returns the number of weights per object. Number of weights per object should be zero or greater....
void setEntityTypes(std::string ptypestr, std::string atypestr, std::string satypestr)
Sets the primary, adjacency, and second adjacency entity types. Called by algorithm based on paramete...
virtual void get2ndAdjsView(MeshEntityType sourcetarget, MeshEntityType through, const offset_t *&offsets, const gno_t *&adjacencyIds) const
if avail2ndAdjs(), set pointers to this process' second adjacencies
bool useDegreeAsWeight(int idx) const
Created by mbenlioglu on Aug 31, 2020.
EntityTopologyType
Enumerate entity topology types for meshes: points,lines,polygons,triangles,quadrilaterals,...
BaseAdapterType
An enum to identify general types of adapters.
@ MeshAdapterType
mesh data
MeshEntityType
Enumerate entity types for meshes: Regions, Faces, Edges, or Vertices.
static ArrayRCP< ArrayRCP< zscalar_t > > weights
default_offset_t offset_t
The data type to represent offsets.
default_gno_t gno_t
The ordinal type (e.g., int, long, int64_t) that can represent global counts and identifiers.
default_node_t node_t
The Kokkos node type. This is only meaningful for users of Tpetra objects.
default_lno_t lno_t
The ordinal type (e.g., int, long, int64_t) that represents local counts and local indices.
default_part_t part_t
The data type to represent part numbers.
default_scalar_t scalar_t
The data type for weights and coordinates.