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  typedef int nonzero_t; // adjacency matrix doesn't need scalar_t
137  typedef Tpetra::CrsMatrix<nonzero_t,lno_t,gno_t,node_t> sparse_matrix_type;
138  typedef Tpetra::Map<lno_t, gno_t, node_t> map_type;
139 #endif
140 
142 
145  virtual ~MeshAdapter() {};
146 
147  // Default MeshEntityType is MESH_REGION with MESH_FACE-based adjacencies and
148  // second adjacencies and coordinates
149  MeshAdapter() : primaryEntityType(MESH_REGION),
150  adjacencyEntityType(MESH_FACE),
151  secondAdjacencyEntityType(MESH_FACE) {};
152 
154  // Methods to be defined in derived classes.
155 
160  virtual bool areEntityIDsUnique(MeshEntityType etype) const
161  {
162  return etype==this->getPrimaryEntityType();
163  }
164 
167  //virtual size_t getGlobalNumOf(MeshEntityType etype) const = 0;
168 
171  virtual size_t getLocalNumOf(MeshEntityType etype) const = 0;
172 
173 
178  virtual void getIDsViewOf(MeshEntityType etype,
179  gno_t const *&Ids) const = 0;
180 
181 
186  virtual void getTopologyViewOf(MeshEntityType etype,
187  enum EntityTopologyType const *&Types) const
188  {
189  Types = NULL;
191  }
192 
198  virtual int getNumWeightsPerOf(MeshEntityType etype) const { return 0; }
199 
213  virtual void getWeightsViewOf(MeshEntityType etype,
214  const scalar_t *&weights, int &stride, int idx = 0) const
215  {
216  weights = NULL;
217  stride = 0;
219  }
220 
221 
230  virtual int getDimension() const { return 0; }
231 
243  const scalar_t *&coords, int &stride, int coordDim) const
244  {
245  coords = NULL;
246  stride = 0;
248  }
249 
250 
253  virtual bool availAdjs(MeshEntityType source, MeshEntityType target) const {
254  return false;
255  }
256 
257 
260  virtual size_t getLocalNumAdjs(MeshEntityType source,
261  MeshEntityType target) const { return 0;}
262 
263 
274  virtual void getAdjsView(MeshEntityType source, MeshEntityType target,
275  const lno_t *&offsets, const gno_t *& adjacencyIds) const
276  {
277  offsets = NULL;
278  adjacencyIds = NULL;
280  }
281 
282 
287  virtual bool avail2ndAdjs(MeshEntityType sourcetarget,
288  MeshEntityType through) const
289  {
290  return false;
291  }
292 
296  virtual size_t getLocalNum2ndAdjs(MeshEntityType sourcetarget,
297  MeshEntityType through) const
298  {
299  return 0;
300  }
301 
312  virtual void get2ndAdjsView(MeshEntityType sourcetarget,
313  MeshEntityType through,
314  const lno_t *&offsets,
315  const gno_t *&adjacencyIds) const
316  {
317  offsets = NULL;
318  adjacencyIds = NULL;
320  }
321 
325  virtual int getNumWeightsPer2ndAdj(MeshEntityType sourcetarget,
326  MeshEntityType through) const { return 0;}
327 
328 
338  virtual void get2ndAdjWeightsView(MeshEntityType sourcetarget,
339  MeshEntityType through,
340  const scalar_t *&weights,
341  int &stride,
342  int idx) const
343  {
344  weights = NULL;
345  stride = 0;
347  }
348 
350  // Implementations of base-class methods
351 
354  inline enum MeshEntityType getPrimaryEntityType() const {
355  return this->primaryEntityType;
356  }
357 
364  return this->adjacencyEntityType;
365  }
366 
373  return this->secondAdjacencyEntityType;
374  }
375 
382  void setEntityTypes(std::string ptypestr, std::string atypestr,
383  std::string satypestr) {
384 
385  if (ptypestr != atypestr && ptypestr != satypestr) {
386  if (ptypestr == "region")
387  this->primaryEntityType = MESH_REGION;
388  else if (ptypestr == "face")
389  this->primaryEntityType = MESH_FACE;
390  else if (ptypestr == "edge")
391  this->primaryEntityType = MESH_EDGE;
392  else if (ptypestr == "vertex")
393  this->primaryEntityType = MESH_VERTEX;
394  else {
395  std::ostringstream emsg;
396  emsg << __FILE__ << "," << __LINE__
397  << " error: Invalid MeshEntityType " << ptypestr << std::endl;
398  emsg << "Valid values: region face edge vertex" << std::endl;
399  throw std::runtime_error(emsg.str());
400  }
401 
402  if (atypestr == "region")
403  this->adjacencyEntityType = MESH_REGION;
404  else if (atypestr == "face")
405  this->adjacencyEntityType = MESH_FACE;
406  else if (atypestr == "edge")
407  this->adjacencyEntityType = MESH_EDGE;
408  else if (atypestr == "vertex")
409  this->adjacencyEntityType = MESH_VERTEX;
410  else {
411  std::ostringstream emsg;
412  emsg << __FILE__ << "," << __LINE__
413  << " error: Invalid MeshEntityType " << atypestr << std::endl;
414  emsg << "Valid values: region face edge vertex" << std::endl;
415  throw std::runtime_error(emsg.str());
416  }
417 
418  if (satypestr == "region")
419  this->secondAdjacencyEntityType = MESH_REGION;
420  else if (satypestr == "face")
421  this->secondAdjacencyEntityType = MESH_FACE;
422  else if (satypestr == "edge")
423  this->secondAdjacencyEntityType = MESH_EDGE;
424  else if (satypestr == "vertex")
425  this->secondAdjacencyEntityType = MESH_VERTEX;
426  else {
427  std::ostringstream emsg;
428  emsg << __FILE__ << "," << __LINE__
429  << " error: Invalid MeshEntityType " << satypestr << std::endl;
430  emsg << "Valid values: region face edge vertex" << std::endl;
431  throw std::runtime_error(emsg.str());
432  }
433  }
434  else {
435  std::ostringstream emsg;
436  emsg << __FILE__ << "," << __LINE__
437  << " error: PrimaryEntityType " << ptypestr
438  << " matches AdjacencyEntityType " << atypestr
439  << " or SecondAdjacencyEntityType " << satypestr << std::endl;
440  throw std::runtime_error(emsg.str());
441  }
442  }
443 
448  virtual bool useDegreeAsWeightOf(MeshEntityType etype, int idx) const
449  {
450  return false;
451  }
452 
454  // Functions from the BaseAdapter interface
455  size_t getLocalNumIDs() const {
457  }
458 
459  void getIDsView(const gno_t *&Ids) const {
461  }
462 
463  int getNumWeightsPerID() const {
465  }
466 
467  void getWeightsView(const scalar_t *&wgt, int &stride, int idx = 0) const {
468  getWeightsViewOf(getPrimaryEntityType(), wgt, stride, idx);
469  }
470 
471  void getCoordinatesView(const scalar_t *&coords, int &stride,
472  int coordDim) const
473  {
474  getCoordinatesViewOf(getPrimaryEntityType(), coords, stride, coordDim);
475  }
476 
477  bool useDegreeAsWeight(int idx) const
478  {
480  }
481 
482 private:
483  enum MeshEntityType primaryEntityType; // Entity type
484  // to be partitioned, ordered,
485  // colored, matched, etc.
486  enum MeshEntityType adjacencyEntityType; // Entity type defining first-order
487  // adjacencies; adjacencies are of
488  // this type.
489  enum MeshEntityType secondAdjacencyEntityType; // Bridge entity type
490  // defining second-order
491  // adjacencies.
492 };
493 
494 } //namespace Zoltan2
495 
496 #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.
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.