Zoltan2
Loading...
Searching...
No Matches
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
57namespace 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
123template <typename User>
124class MeshAdapter : public AdapterWithCoords<User> {
125public:
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;
136 typedef MeshAdapter<User> base_adapter_t;
137#endif
138
139 enum BaseAdapterType adapterType() const override {return MeshAdapterType;}
140
143 virtual ~MeshAdapter() {};
144
145 // Default MeshEntityType is MESH_REGION with MESH_FACE-based adjacencies and
146 // second adjacencies and coordinates
147 MeshAdapter() : primaryEntityType(MESH_REGION),
148 adjacencyEntityType(MESH_FACE),
149 secondAdjacencyEntityType(MESH_FACE) {};
150
152 // Methods to be defined in derived classes.
153
158 virtual bool areEntityIDsUnique(MeshEntityType etype) const
159 {
160 return etype==this->getPrimaryEntityType();
161 }
162
165 //virtual size_t getGlobalNumOf(MeshEntityType etype) const = 0;
166
169 virtual size_t getLocalNumOf(MeshEntityType etype) const = 0;
170
171
176 virtual void getIDsViewOf(MeshEntityType etype,
177 gno_t const *&Ids) const = 0;
178
179
185 enum EntityTopologyType const *&Types) const
186 {
187 Types = NULL;
189 }
190
196 virtual int getNumWeightsPerOf(MeshEntityType etype) const { return 0; }
197
212 const scalar_t *&weights, int &stride, int idx = 0) const
213 {
214 weights = NULL;
215 stride = 0;
217 }
218
219
228 virtual int getDimension() const { return 0; }
229
241 const scalar_t *&coords, int &stride, int coordDim) const
242 {
243 coords = NULL;
244 stride = 0;
246 }
247
248
251 virtual bool availAdjs(MeshEntityType source, MeshEntityType target) const {
252 return false;
253 }
254
255
258 virtual size_t getLocalNumAdjs(MeshEntityType source,
259 MeshEntityType target) const { return 0;}
260
261
272 virtual void getAdjsView(MeshEntityType source, MeshEntityType target,
273 const offset_t *&offsets, const gno_t *& adjacencyIds) const
274 {
275 offsets = NULL;
276 adjacencyIds = NULL;
278 }
279
280
285 virtual bool avail2ndAdjs(MeshEntityType sourcetarget,
286 MeshEntityType through) const
287 {
288 return false;
289 }
290
294 virtual size_t getLocalNum2ndAdjs(MeshEntityType sourcetarget,
295 MeshEntityType through) const
296 {
297 return 0;
298 }
299
310 virtual void get2ndAdjsView(MeshEntityType sourcetarget,
311 MeshEntityType through,
312 const offset_t *&offsets,
313 const gno_t *&adjacencyIds) const
314 {
315 offsets = NULL;
316 adjacencyIds = NULL;
318 }
319
323 virtual int getNumWeightsPer2ndAdj(MeshEntityType sourcetarget,
324 MeshEntityType through) const { return 0;}
325
326
336 virtual void get2ndAdjWeightsView(MeshEntityType sourcetarget,
337 MeshEntityType through,
338 const scalar_t *&weights,
339 int &stride,
340 int idx) const
341 {
342 weights = NULL;
343 stride = 0;
345 }
346
348 // Implementations of base-class methods
349
353 return this->primaryEntityType;
354 }
355
362 return this->adjacencyEntityType;
363 }
364
371 return this->secondAdjacencyEntityType;
372 }
373
380 void setEntityTypes(std::string ptypestr, std::string atypestr,
381 std::string satypestr) {
382
383 if (ptypestr != atypestr && ptypestr != satypestr) {
384 if (ptypestr == "region")
385 this->primaryEntityType = MESH_REGION;
386 else if (ptypestr == "face")
387 this->primaryEntityType = MESH_FACE;
388 else if (ptypestr == "edge")
389 this->primaryEntityType = MESH_EDGE;
390 else if (ptypestr == "vertex")
391 this->primaryEntityType = MESH_VERTEX;
392 else {
393 std::ostringstream emsg;
394 emsg << __FILE__ << "," << __LINE__
395 << " error: Invalid MeshEntityType " << ptypestr << std::endl;
396 emsg << "Valid values: region face edge vertex" << std::endl;
397 throw std::runtime_error(emsg.str());
398 }
399
400 if (atypestr == "region")
401 this->adjacencyEntityType = MESH_REGION;
402 else if (atypestr == "face")
403 this->adjacencyEntityType = MESH_FACE;
404 else if (atypestr == "edge")
405 this->adjacencyEntityType = MESH_EDGE;
406 else if (atypestr == "vertex")
407 this->adjacencyEntityType = MESH_VERTEX;
408 else {
409 std::ostringstream emsg;
410 emsg << __FILE__ << "," << __LINE__
411 << " error: Invalid MeshEntityType " << atypestr << std::endl;
412 emsg << "Valid values: region face edge vertex" << std::endl;
413 throw std::runtime_error(emsg.str());
414 }
415
416 if (satypestr == "region")
417 this->secondAdjacencyEntityType = MESH_REGION;
418 else if (satypestr == "face")
419 this->secondAdjacencyEntityType = MESH_FACE;
420 else if (satypestr == "edge")
421 this->secondAdjacencyEntityType = MESH_EDGE;
422 else if (satypestr == "vertex")
423 this->secondAdjacencyEntityType = MESH_VERTEX;
424 else {
425 std::ostringstream emsg;
426 emsg << __FILE__ << "," << __LINE__
427 << " error: Invalid MeshEntityType " << satypestr << std::endl;
428 emsg << "Valid values: region face edge vertex" << std::endl;
429 throw std::runtime_error(emsg.str());
430 }
431 }
432 else {
433 std::ostringstream emsg;
434 emsg << __FILE__ << "," << __LINE__
435 << " error: PrimaryEntityType " << ptypestr
436 << " matches AdjacencyEntityType " << atypestr
437 << " or SecondAdjacencyEntityType " << satypestr << std::endl;
438 throw std::runtime_error(emsg.str());
439 }
440 }
441
446 virtual bool useDegreeAsWeightOf(MeshEntityType etype, int idx) const
447 {
448 return false;
449 }
450
452 // Functions from the BaseAdapter interface
453 size_t getLocalNumIDs() const override {
455 }
456
457 void getIDsView(const gno_t *&Ids) const override {
459 }
460
461 void getIDsKokkosView(Kokkos::View<const gno_t *,
462 typename node_t::device_type> &ids) const override
463 {
464 Kokkos::View<gno_t *, typename node_t::device_type>
465 kokkos_ids("gids", getLocalNumIDs());
466 auto host_kokkos_ids = Kokkos::create_mirror_view(kokkos_ids);
467
468 const gno_t * gnos;
469 getIDsView(gnos);
470 for(size_t n = 0; n < getLocalNumIDs(); ++n) {
471 host_kokkos_ids(n) = gnos[n];
472 }
473 Kokkos::deep_copy(kokkos_ids, host_kokkos_ids);
474 ids = kokkos_ids;
475 }
476
477 int getNumWeightsPerID() const override {
479 }
480
481 void getWeightsView(const scalar_t *&wgt, int &stride, int idx = 0) const override {
482 getWeightsViewOf(getPrimaryEntityType(), wgt, stride, idx);
483 }
484
485 void getCoordinatesView(const scalar_t *&coords, int &stride,
486 int coordDim) const override
487 {
488 getCoordinatesViewOf(getPrimaryEntityType(), coords, stride, coordDim);
489 }
490
492 // coordinates in MJ are LayoutLeft since Tpetra Multivector gives LayoutLeft
493 Kokkos::View<scalar_t **, Kokkos::LayoutLeft, typename node_t::device_type> & elements) const override
494 {
495 // coordinates in MJ are LayoutLeft since Tpetra Multivector gives LayoutLeft
496 Kokkos::View<scalar_t **, Kokkos::LayoutLeft, typename node_t::device_type>
497 kokkos_coordinates("pamgen coords", getLocalNumIDs(), getDimension());
498 auto host_temp_values = Kokkos::create_mirror_view(kokkos_coordinates);
499 const scalar_t * coords;
500 for(int dim = 0; dim < getDimension(); ++dim) {
501 int stride = -1;
502 getCoordinatesView(coords, stride, dim);
503 for(size_t n = 0; n < getLocalNumIDs(); ++n) {
504 host_temp_values(n, dim) = coords[n*stride];
505 }
506 }
507 Kokkos::deep_copy(kokkos_coordinates, host_temp_values);
508 elements = kokkos_coordinates;
509 }
510
511 bool useDegreeAsWeight(int idx) const
512 {
514 }
515
516private:
517 enum MeshEntityType primaryEntityType; // Entity type
518 // to be partitioned, ordered,
519 // colored, matched, etc.
520 enum MeshEntityType adjacencyEntityType; // Entity type defining first-order
521 // adjacencies; adjacencies are of
522 // this type.
523 enum MeshEntityType secondAdjacencyEntityType; // Bridge entity type
524 // defining second-order
525 // adjacencies.
526};
527
528} //namespace Zoltan2
529
530#endif
Zoltan2::BasicUserTypes< zscalar_t, zlno_t, zgno_t > user_t
Definition: Metric.cpp:74
#define Z2_THROW_NOT_IMPLEMENTED
InputTraits< User >::node_t node_t
InputTraits< User >::offset_t offset_t
InputTraits< User >::part_t part_t
InputTraits< User >::scalar_t scalar_t
InputTraits< User >::lno_t lno_t
InputTraits< User >::gno_t gno_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
Provide a Kokkos view to this process' identifiers.
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 ~MeshAdapter()
Destructor.
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.