Zoltan2
Zoltan2_MeshAdapter.hpp
Go to the documentation of this file.
1 // @HEADER
2 //
3 // ***********************************************************************
4 //
5 // Zoltan2: A package of combinatorial algorithms for scientific computing
6 // Copyright 2012 Sandia Corporation
7 //
8 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact Karen Devine (kddevin@sandia.gov)
39 // Erik Boman (egboman@sandia.gov)
40 // Siva Rajamanickam (srajama@sandia.gov)
41 //
42 // ***********************************************************************
43 //
44 // @HEADER
45 
51 #ifndef _ZOLTAN2_MESHADAPTER_HPP_
52 #define _ZOLTAN2_MESHADAPTER_HPP_
53 
54 #include <Zoltan2_Adapter.hpp>
55 #include "Tpetra_DefaultPlatform.hpp"
56 #include "TpetraExt_MatrixMatrix.hpp"
57 
58 namespace Zoltan2 {
59 
69 };
70 
77  POINT, // a 0D entity (e.g. a vertex)
78  LINE_SEGMENT, // a 1D entity (e.g. an edge)
79  POLYGON, // a general 2D entity
80  TRIANGLE, // a specific 2D entity bounded by 3 edge entities
81  QUADRILATERAL, // a specific 2D entity bounded by 4 edge entities
82  POLYHEDRON, // a general 3D entity
83  TETRAHEDRON, // a specific 3D entity bounded by 4 triangle entities
84  HEXAHEDRON, // a specific 3D entity bounded by 6 quadrilateral
85  // entities
86  PRISM, // a specific 3D entity bounded by a combination of 3
87  //quadrilateral entities and 2 triangle entities
88  PYRAMID // a specific 3D entity bounded by a combination of 1
89  // quadrilateral entity and 4 triangle entities
90 };
91 
124 template <typename User>
125 class MeshAdapter : public BaseAdapter<User> {
126 public:
127 
128 #ifndef DOXYGEN_SHOULD_SKIP_THIS
129  typedef typename InputTraits<User>::scalar_t scalar_t;
130  typedef typename InputTraits<User>::lno_t lno_t;
131  typedef typename InputTraits<User>::gno_t gno_t;
132  typedef typename InputTraits<User>::part_t part_t;
133  typedef typename InputTraits<User>::node_t node_t;
134  typedef User user_t;
135  typedef User userCoord_t;
136 #endif
137 
139 
142  virtual ~MeshAdapter() {};
143 
144  // Default MeshEntityType is MESH_REGION with MESH_FACE-based adjacencies and
145  // second adjacencies and coordinates
146  MeshAdapter() : primaryEntityType(MESH_REGION),
147  adjacencyEntityType(MESH_FACE),
148  secondAdjacencyEntityType(MESH_FACE) {};
149 
151  // Methods to be defined in derived classes.
152 
157  virtual bool areEntityIDsUnique(MeshEntityType etype) const
158  {
159  return etype==this->getPrimaryEntityType();
160  }
161 
164  //virtual size_t getGlobalNumOf(MeshEntityType etype) const = 0;
165 
168  virtual size_t getLocalNumOf(MeshEntityType etype) const = 0;
169 
170 
175  virtual void getIDsViewOf(MeshEntityType etype,
176  gno_t const *&Ids) const = 0;
177 
178 
183  virtual void getTopologyViewOf(MeshEntityType etype,
184  enum EntityTopologyType const *&Types) const
185  {
186  Types = NULL;
188  }
189 
195  virtual int getNumWeightsPerOf(MeshEntityType etype) const { return 0; }
196 
210  virtual void getWeightsViewOf(MeshEntityType etype,
211  const scalar_t *&weights, int &stride, int idx = 0) const
212  {
213  weights = NULL;
214  stride = 0;
216  }
217 
218 
227  virtual int getDimension() const { return 0; }
228 
240  const scalar_t *&coords, int &stride, int coordDim) const
241  {
242  coords = NULL;
243  stride = 0;
245  }
246 
247 
250  virtual bool availAdjs(MeshEntityType source, MeshEntityType target) const {
251  return false;
252  }
253 
254 
257  virtual size_t getLocalNumAdjs(MeshEntityType source,
258  MeshEntityType target) const { return 0;}
259 
260 
271  virtual void getAdjsView(MeshEntityType source, MeshEntityType target,
272  const lno_t *&offsets, const gno_t *& adjacencyIds) const
273  {
274  offsets = NULL;
275  adjacencyIds = NULL;
277  }
278 
279 
284  virtual bool avail2ndAdjs(MeshEntityType sourcetarget,
285  MeshEntityType through) const
286  {
287  return false;
288  }
289 
293  virtual size_t getLocalNum2ndAdjs(MeshEntityType sourcetarget,
294  MeshEntityType through) const
295  {
296  return 0;
297  }
298 
309  virtual void get2ndAdjsView(MeshEntityType sourcetarget,
310  MeshEntityType through,
311  const lno_t *&offsets,
312  const gno_t *&adjacencyIds) const
313  {
314  offsets = NULL;
315  adjacencyIds = NULL;
317  }
318 
322  virtual int getNumWeightsPer2ndAdj(MeshEntityType sourcetarget,
323  MeshEntityType through) const { return 0;}
324 
325 
335  virtual void get2ndAdjWeightsView(MeshEntityType sourcetarget,
336  MeshEntityType through,
337  const scalar_t *&weights,
338  int &stride,
339  int idx) const
340  {
341  weights = NULL;
342  stride = 0;
344  }
345 
347  // Implementations of base-class methods
348 
351  inline enum MeshEntityType getPrimaryEntityType() const {
352  return this->primaryEntityType;
353  }
354 
361  return this->adjacencyEntityType;
362  }
363 
370  return this->secondAdjacencyEntityType;
371  }
372 
379  void setEntityTypes(std::string ptypestr, std::string atypestr,
380  std::string satypestr) {
381 
382  if (ptypestr != atypestr && ptypestr != satypestr) {
383  if (ptypestr == "region")
384  this->primaryEntityType = MESH_REGION;
385  else if (ptypestr == "face")
386  this->primaryEntityType = MESH_FACE;
387  else if (ptypestr == "edge")
388  this->primaryEntityType = MESH_EDGE;
389  else if (ptypestr == "vertex")
390  this->primaryEntityType = MESH_VERTEX;
391  else {
392  std::ostringstream emsg;
393  emsg << __FILE__ << "," << __LINE__
394  << " error: Invalid MeshEntityType " << ptypestr << std::endl;
395  emsg << "Valid values: region face edge vertex" << std::endl;
396  throw std::runtime_error(emsg.str());
397  }
398 
399  if (atypestr == "region")
400  this->adjacencyEntityType = MESH_REGION;
401  else if (atypestr == "face")
402  this->adjacencyEntityType = MESH_FACE;
403  else if (atypestr == "edge")
404  this->adjacencyEntityType = MESH_EDGE;
405  else if (atypestr == "vertex")
406  this->adjacencyEntityType = MESH_VERTEX;
407  else {
408  std::ostringstream emsg;
409  emsg << __FILE__ << "," << __LINE__
410  << " error: Invalid MeshEntityType " << atypestr << std::endl;
411  emsg << "Valid values: region face edge vertex" << std::endl;
412  throw std::runtime_error(emsg.str());
413  }
414 
415  if (satypestr == "region")
416  this->secondAdjacencyEntityType = MESH_REGION;
417  else if (satypestr == "face")
418  this->secondAdjacencyEntityType = MESH_FACE;
419  else if (satypestr == "edge")
420  this->secondAdjacencyEntityType = MESH_EDGE;
421  else if (satypestr == "vertex")
422  this->secondAdjacencyEntityType = MESH_VERTEX;
423  else {
424  std::ostringstream emsg;
425  emsg << __FILE__ << "," << __LINE__
426  << " error: Invalid MeshEntityType " << satypestr << std::endl;
427  emsg << "Valid values: region face edge vertex" << std::endl;
428  throw std::runtime_error(emsg.str());
429  }
430  }
431  else {
432  std::ostringstream emsg;
433  emsg << __FILE__ << "," << __LINE__
434  << " error: PrimaryEntityType " << ptypestr
435  << " matches AdjacencyEntityType " << atypestr
436  << " or SecondAdjacencyEntityType " << satypestr << std::endl;
437  throw std::runtime_error(emsg.str());
438  }
439  }
440 
445  virtual bool useDegreeAsWeightOf(MeshEntityType etype, int idx) const
446  {
447  return false;
448  }
449 
451  // Functions from the BaseAdapter interface
452  size_t getLocalNumIDs() const {
454  }
455 
456  void getIDsView(const gno_t *&Ids) const {
458  }
459 
460  int getNumWeightsPerID() const {
462  }
463 
464  void getWeightsView(const scalar_t *&wgt, int &stride, int idx = 0) const {
465  getWeightsViewOf(getPrimaryEntityType(), wgt, stride, idx);
466  }
467 
468  void getCoordinatesView(const scalar_t *&coords, int &stride,
469  int coordDim) const
470  {
471  getCoordinatesViewOf(getPrimaryEntityType(), coords, stride, coordDim);
472  }
473 
474  bool useDegreeAsWeight(int idx) const
475  {
477  }
478 
479 private:
480  enum MeshEntityType primaryEntityType; // Entity type
481  // to be partitioned, ordered,
482  // colored, matched, etc.
483  enum MeshEntityType adjacencyEntityType; // Entity type defining first-order
484  // adjacencies; adjacencies are of
485  // this type.
486  enum MeshEntityType secondAdjacencyEntityType; // Bridge entity type
487  // defining second-order
488  // adjacencies.
489 };
490 
491 } //namespace Zoltan2
492 
493 #endif
InputTraits< User >::scalar_t scalar_t
virtual bool areEntityIDsUnique(MeshEntityType etype) const
Provide a pointer to the entity topology types.
virtual bool availAdjs(MeshEntityType source, MeshEntityType target) const
Returns whether a first adjacency combination is available.
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...
InputTraits< User >::gno_t gno_t
int getNumWeightsPerID() const
Returns the number of weights per object. Number of weights per object should be zero or greater...
MeshAdapter defines the interface for mesh input.
virtual size_t getLocalNumOf(MeshEntityType etype) const =0
Returns the global number of mesh entities of MeshEntityType.
default_part_t part_t
The data type to represent part numbers.
virtual ~MeshAdapter()
Destructor.
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&#39; optional entity weights.
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 getAdjacencyEntityType() const
Returns the entity that describes adjacencies between the entities to be partitioned, ordered, colored, etc. That is, a primaryEntityType that contains an adjacencyEntityType are adjacent.
static ArrayRCP< ArrayRCP< zscalar_t > > weights
virtual int getDimension() const
Return dimension of the entity coordinates, if any.
void getCoordinatesView(const scalar_t *&coords, int &stride, int coordDim) const
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 size_t getLocalNum2ndAdjs(MeshEntityType sourcetarget, MeshEntityType through) const
if avail2ndAdjs(), returns the number of second adjacencies on this process.
virtual void getIDsViewOf(MeshEntityType etype, gno_t const *&Ids) const =0
Provide a pointer to this process&#39; identifiers.
virtual void getCoordinatesViewOf(MeshEntityType etype, const scalar_t *&coords, int &stride, int coordDim) const
Provide a pointer to one dimension of entity coordinates.
enum MeshEntityType getSecondAdjacencyEntityType() const
Returns the entity that describes second adjacencies between the entities to be partitioned, ordered, colored, etc. That is, two primaryEntityType that share a secondAdjacencyEntityType are adjacent.
default_lno_t lno_t
The ordinal type (e.g., int, long, int64_t) that represents local counts and local indices...
BaseAdapterType
An enum to identify general types of adapters.
virtual size_t getLocalNumAdjs(MeshEntityType source, MeshEntityType target) const
Returns the number of first adjacencies on this process.
virtual void get2ndAdjsView(MeshEntityType sourcetarget, MeshEntityType through, const lno_t *&offsets, const gno_t *&adjacencyIds) const
if avail2ndAdjs(), set pointers to this process&#39; second adjacencies
void getWeightsView(const scalar_t *&wgt, int &stride, int idx=0) const
Provide pointer to a weight array with stride.
virtual int getNumWeightsPer2ndAdj(MeshEntityType sourcetarget, MeshEntityType through) const
Returns the number (0 or greater) of weights per second adjacency. Note: second-adjacency weights may...
virtual void getAdjsView(MeshEntityType source, MeshEntityType target, const lno_t *&offsets, const gno_t *&adjacencyIds) const
Sets pointers to this process&#39; mesh first adjacencies.
InputTraits< User >::part_t part_t
EntityTopologyType
Enumerate entity topology types for meshes: points,lines,polygons,triangles,quadrilaterals, polyhedrons, tetrahedrons, hexhedrons, prisms, or pyramids.
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.
#define Z2_THROW_NOT_IMPLEMENTED_IN_ADAPTER
BaseAdapter defines methods required by all Adapters.
MeshEntityType
Enumerate entity types for meshes: Regions, Faces, Edges, or Vertices.
bool useDegreeAsWeight(int idx) const
virtual int getNumWeightsPerOf(MeshEntityType etype) const
Return the number of weights per entity.
virtual void getTopologyViewOf(MeshEntityType etype, enum EntityTopologyType const *&Types) const
Provide a pointer to the entity topology types.
size_t getLocalNumIDs() const
Returns the number of objects on this process.
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 ...
enum MeshEntityType getPrimaryEntityType() const
Returns the entity to be partitioned, ordered, colored, etc.
default_scalar_t scalar_t
The data type for weights and coordinates.
enum BaseAdapterType adapterType() const
Returns the type of adapter.
void getIDsView(const gno_t *&Ids) const
Provide a pointer to this process&#39; identifiers.