Zoltan2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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 "TpetraExt_MatrixMatrix.hpp"
56 
57 namespace Zoltan2 {
58 
68 };
69 
76  POINT, // a 0D entity (e.g. a vertex)
77  LINE_SEGMENT, // a 1D entity (e.g. an edge)
78  POLYGON, // a general 2D entity
79  TRIANGLE, // a specific 2D entity bounded by 3 edge entities
80  QUADRILATERAL, // a specific 2D entity bounded by 4 edge entities
81  POLYHEDRON, // a general 3D entity
82  TETRAHEDRON, // a specific 3D entity bounded by 4 triangle entities
83  HEXAHEDRON, // a specific 3D entity bounded by 6 quadrilateral
84  // entities
85  PRISM, // a specific 3D entity bounded by a combination of 3
86  //quadrilateral entities and 2 triangle entities
87  PYRAMID // a specific 3D entity bounded by a combination of 1
88  // quadrilateral entity and 4 triangle entities
89 };
90 
123 template <typename User>
124 class MeshAdapter : public AdapterWithCoords<User> {
125 public:
126 
127 #ifndef DOXYGEN_SHOULD_SKIP_THIS
128  typedef typename InputTraits<User>::scalar_t scalar_t;
129  typedef typename InputTraits<User>::offset_t offset_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;
137 #endif
138 
139  enum BaseAdapterType adapterType() const override {return MeshAdapterType;}
140 
141  // Default MeshEntityType is MESH_REGION with MESH_FACE-based adjacencies and
142  // second adjacencies and coordinates
143  MeshAdapter() : primaryEntityType(MESH_REGION),
144  adjacencyEntityType(MESH_FACE),
145  secondAdjacencyEntityType(MESH_FACE) {};
146 
148  // Methods to be defined in derived classes.
149 
154  virtual bool areEntityIDsUnique(MeshEntityType etype) const
155  {
156  return etype==this->getPrimaryEntityType();
157  }
158 
161  //virtual size_t getGlobalNumOf(MeshEntityType etype) const = 0;
162 
165  virtual size_t getLocalNumOf(MeshEntityType etype) const = 0;
166 
167 
172  virtual void getIDsViewOf(MeshEntityType etype,
173  gno_t const *&Ids) const = 0;
174 
175 
180  virtual void getTopologyViewOf(MeshEntityType etype,
181  enum EntityTopologyType const *&Types) const
182  {
183  Types = NULL;
185  }
186 
192  virtual int getNumWeightsPerOf(MeshEntityType etype) const { return 0; }
193 
207  virtual void getWeightsViewOf(MeshEntityType etype,
208  const scalar_t *&weights, int &stride, int idx = 0) const
209  {
210  weights = NULL;
211  stride = 0;
213  }
214 
215 
224  virtual int getDimension() const { return 0; }
225 
237  const scalar_t *&coords, int &stride, int coordDim) const
238  {
239  coords = NULL;
240  stride = 0;
242  }
243 
244 
247  virtual bool availAdjs(MeshEntityType source, MeshEntityType target) const {
248  return false;
249  }
250 
251 
254  virtual size_t getLocalNumAdjs(MeshEntityType source,
255  MeshEntityType target) const { return 0;}
256 
257 
268  virtual void getAdjsView(MeshEntityType source, MeshEntityType target,
269  const offset_t *&offsets, const gno_t *& adjacencyIds) const
270  {
271  offsets = NULL;
272  adjacencyIds = NULL;
274  }
275 
276 
281  virtual bool avail2ndAdjs(MeshEntityType sourcetarget,
282  MeshEntityType through) const
283  {
284  return false;
285  }
286 
290  virtual size_t getLocalNum2ndAdjs(MeshEntityType sourcetarget,
291  MeshEntityType through) const
292  {
293  return 0;
294  }
295 
306  virtual void get2ndAdjsView(MeshEntityType sourcetarget,
307  MeshEntityType through,
308  const offset_t *&offsets,
309  const gno_t *&adjacencyIds) const
310  {
311  offsets = NULL;
312  adjacencyIds = NULL;
314  }
315 
319  virtual int getNumWeightsPer2ndAdj(MeshEntityType sourcetarget,
320  MeshEntityType through) const { return 0;}
321 
322 
332  virtual void get2ndAdjWeightsView(MeshEntityType sourcetarget,
333  MeshEntityType through,
334  const scalar_t *&weights,
335  int &stride,
336  int idx) const
337  {
338  weights = NULL;
339  stride = 0;
341  }
342 
344  // Implementations of base-class methods
345 
348  inline enum MeshEntityType getPrimaryEntityType() const {
349  return this->primaryEntityType;
350  }
351 
358  return this->adjacencyEntityType;
359  }
360 
367  return this->secondAdjacencyEntityType;
368  }
369 
376  void setEntityTypes(std::string ptypestr, std::string atypestr,
377  std::string satypestr) {
378 
379  if (ptypestr != atypestr && ptypestr != satypestr) {
380  if (ptypestr == "region")
381  this->primaryEntityType = MESH_REGION;
382  else if (ptypestr == "face")
383  this->primaryEntityType = MESH_FACE;
384  else if (ptypestr == "edge")
385  this->primaryEntityType = MESH_EDGE;
386  else if (ptypestr == "vertex")
387  this->primaryEntityType = MESH_VERTEX;
388  else {
389  std::ostringstream emsg;
390  emsg << __FILE__ << "," << __LINE__
391  << " error: Invalid MeshEntityType " << ptypestr << std::endl;
392  emsg << "Valid values: region face edge vertex" << std::endl;
393  throw std::runtime_error(emsg.str());
394  }
395 
396  if (atypestr == "region")
397  this->adjacencyEntityType = MESH_REGION;
398  else if (atypestr == "face")
399  this->adjacencyEntityType = MESH_FACE;
400  else if (atypestr == "edge")
401  this->adjacencyEntityType = MESH_EDGE;
402  else if (atypestr == "vertex")
403  this->adjacencyEntityType = MESH_VERTEX;
404  else {
405  std::ostringstream emsg;
406  emsg << __FILE__ << "," << __LINE__
407  << " error: Invalid MeshEntityType " << atypestr << std::endl;
408  emsg << "Valid values: region face edge vertex" << std::endl;
409  throw std::runtime_error(emsg.str());
410  }
411 
412  if (satypestr == "region")
413  this->secondAdjacencyEntityType = MESH_REGION;
414  else if (satypestr == "face")
415  this->secondAdjacencyEntityType = MESH_FACE;
416  else if (satypestr == "edge")
417  this->secondAdjacencyEntityType = MESH_EDGE;
418  else if (satypestr == "vertex")
419  this->secondAdjacencyEntityType = MESH_VERTEX;
420  else {
421  std::ostringstream emsg;
422  emsg << __FILE__ << "," << __LINE__
423  << " error: Invalid MeshEntityType " << satypestr << std::endl;
424  emsg << "Valid values: region face edge vertex" << std::endl;
425  throw std::runtime_error(emsg.str());
426  }
427  }
428  else {
429  std::ostringstream emsg;
430  emsg << __FILE__ << "," << __LINE__
431  << " error: PrimaryEntityType " << ptypestr
432  << " matches AdjacencyEntityType " << atypestr
433  << " or SecondAdjacencyEntityType " << satypestr << std::endl;
434  throw std::runtime_error(emsg.str());
435  }
436  }
437 
442  virtual bool useDegreeAsWeightOf(MeshEntityType etype, int idx) const
443  {
444  return false;
445  }
446 
448  // Functions from the BaseAdapter interface
449  size_t getLocalNumIDs() const override {
451  }
452 
453  void getIDsView(const gno_t *&Ids) const override {
455  }
456 
457  void getIDsKokkosView(Kokkos::View<const gno_t *,
458  typename node_t::device_type> &ids) const override
459  {
460  Kokkos::View<gno_t *, typename node_t::device_type>
461  kokkos_ids("gids", getLocalNumIDs());
462  auto host_kokkos_ids = Kokkos::create_mirror_view(kokkos_ids);
463 
464  const gno_t * gnos;
465  getIDsView(gnos);
466  for(size_t n = 0; n < getLocalNumIDs(); ++n) {
467  host_kokkos_ids(n) = gnos[n];
468  }
469  Kokkos::deep_copy(kokkos_ids, host_kokkos_ids);
470  ids = kokkos_ids;
471  }
472 
473  int getNumWeightsPerID() const override {
475  }
476 
477  void getWeightsView(const scalar_t *&wgt, int &stride, int idx = 0) const override {
478  getWeightsViewOf(getPrimaryEntityType(), wgt, stride, idx);
479  }
480 
481  void getCoordinatesView(const scalar_t *&coords, int &stride,
482  int coordDim) const override
483  {
484  getCoordinatesViewOf(getPrimaryEntityType(), coords, stride, coordDim);
485  }
486 
488  // coordinates in MJ are LayoutLeft since Tpetra Multivector gives LayoutLeft
489  Kokkos::View<scalar_t **, Kokkos::LayoutLeft, typename node_t::device_type> & elements) const override
490  {
491  // coordinates in MJ are LayoutLeft since Tpetra Multivector gives LayoutLeft
492  Kokkos::View<scalar_t **, Kokkos::LayoutLeft, typename node_t::device_type>
493  kokkos_coordinates("pamgen coords", getLocalNumIDs(), getDimension());
494  auto host_temp_values = Kokkos::create_mirror_view(kokkos_coordinates);
495  const scalar_t * coords;
496  for(int dim = 0; dim < getDimension(); ++dim) {
497  int stride = -1;
498  getCoordinatesView(coords, stride, dim);
499  for(size_t n = 0; n < getLocalNumIDs(); ++n) {
500  host_temp_values(n, dim) = coords[n*stride];
501  }
502  }
503  Kokkos::deep_copy(kokkos_coordinates, host_temp_values);
504  elements = kokkos_coordinates;
505  }
506 
507  bool useDegreeAsWeight(int idx) const
508  {
510  }
511 
512 private:
513  enum MeshEntityType primaryEntityType; // Entity type
514  // to be partitioned, ordered,
515  // colored, matched, etc.
516  enum MeshEntityType adjacencyEntityType; // Entity type defining first-order
517  // adjacencies; adjacencies are of
518  // this type.
519  enum MeshEntityType secondAdjacencyEntityType; // Bridge entity type
520  // defining second-order
521  // adjacencies.
522 };
523 
524 } //namespace Zoltan2
525 
526 #endif
virtual void getAdjsView(MeshEntityType source, MeshEntityType target, const offset_t *&offsets, const gno_t *&adjacencyIds) const
Sets pointers to this process&#39; mesh first adjacencies.
Zoltan2::BaseAdapter< userTypes_t > base_adapter_t
virtual bool areEntityIDsUnique(MeshEntityType etype) const
Provide a pointer to the entity topology types.
int getNumWeightsPerID() const override
Returns the number of weights per object. Number of weights per object should be zero or greater...
void getIDsView(const gno_t *&Ids) const override
Provide a pointer to this process&#39; identifiers.
virtual bool availAdjs(MeshEntityType source, MeshEntityType target) const
Returns whether a first adjacency combination is available.
typename InputTraits< User >::scalar_t scalar_t
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...
static ArrayRCP< ArrayRCP< zscalar_t > > weights
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.
default_offset_t offset_t
The data type to represent offsets.
map_t::global_ordinal_type gno_t
Definition: mapRemotes.cpp:18
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.
#define Z2_THROW_NOT_IMPLEMENTED
enum BaseAdapterType adapterType() const override
Returns the type of adapter.
virtual void get2ndAdjsView(MeshEntityType sourcetarget, MeshEntityType through, const offset_t *&offsets, const gno_t *&adjacencyIds) const
if avail2ndAdjs(), set pointers to this process&#39; second adjacencies
virtual int getDimension() const
Return dimension of the entity coordinates, if any.
typename InputTraits< User >::part_t part_t
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...
void getCoordinatesKokkosView(Kokkos::View< scalar_t **, Kokkos::LayoutLeft, typename node_t::device_type > &elements) const override
virtual size_t getLocalNum2ndAdjs(MeshEntityType sourcetarget, MeshEntityType through) const
if avail2ndAdjs(), returns the number of second adjacencies on this process.
typename InputTraits< User >::node_t node_t
virtual void getIDsViewOf(MeshEntityType etype, gno_t const *&Ids) const =0
Provide a pointer to this process&#39; identifiers.
size_t getLocalNumIDs() const override
Returns the number of objects on this process.
virtual void getCoordinatesViewOf(MeshEntityType etype, const scalar_t *&coords, int &stride, int coordDim) const
Provide a pointer to one dimension of entity coordinates.
typename InputTraits< User >::gno_t gno_t
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.
void getWeightsView(const scalar_t *&wgt, int &stride, int idx=0) const override
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...
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.
typename InputTraits< User >::offset_t offset_t
void getCoordinatesView(const scalar_t *&coords, int &stride, int coordDim) const override
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.
typename BaseAdapter< User >::scalar_t scalar_t
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.
typename InputTraits< User >::lno_t lno_t
void getIDsKokkosView(Kokkos::View< const gno_t *, typename node_t::device_type > &ids) const override
default_scalar_t scalar_t
The data type for weights and coordinates.
Zoltan2::BasicUserTypes< zscalar_t, zlno_t, zgno_t > user_t
Definition: Metric.cpp:74