escript  Revision_
dudley/src/NodeMapping.h
Go to the documentation of this file.
1 
2 /*****************************************************************************
3 *
4 * Copyright (c) 2003-2020 by The University of Queensland
5 * http://www.uq.edu.au
6 *
7 * Primary Business: Queensland, Australia
8 * Licensed under the Apache License, version 2.0
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12 * Development 2012-2013 by School of Earth Sciences
13 * Development from 2014-2017 by Centre for Geoscience Computing (GeoComp)
14 * Development from 2019 by School of Earth and Environmental Sciences
15 **
16 *****************************************************************************/
17 
18 #ifndef __DUDLEY_NODEMAPPING_H__
19 #define __DUDLEY_NODEMAPPING_H__
20 
21 #include "Util.h"
22 
23 namespace dudley {
24 
27 struct NodeMapping
28 {
29  NodeMapping() : numNodes(0), target(NULL), numTargets(0), map(NULL) {}
30 
32  void clear()
33  {
34  delete[] map;
35  delete[] target;
36  target = NULL;
37  map = NULL;
38  numNodes = 0;
39  numTargets = 0;
40  }
41 
45  void assign(const index_t* theTarget, dim_t nNodes, index_t unused)
46  {
47  clear();
48 
49  if (nNodes == 0)
50  return;
51 
52  numNodes = nNodes;
53 
54  std::pair<index_t,index_t> range(
55  util::getFlaggedMinMaxInt(numNodes, theTarget, unused));
56  if (range.first < 0) {
57  throw escript::ValueError("NodeMapping: target has negative entry.");
58  }
59  numTargets = range.first<=range.second ? range.second+1 : 0;
60 
61  target = new index_t[numNodes];
62  map = new index_t[numTargets];
63 
64  bool err = false;
65 #pragma omp parallel
66  {
67 #pragma omp for
68  for (index_t i=0; i<numNodes; ++i) {
69  target[i] = theTarget[i];
70  if (target[i] != unused)
71  map[target[i]] = i;
72  }
73  // sanity check
74 #pragma omp for
75  for (index_t i=0; i<numTargets; ++i) {
76  if (map[i] == -1) {
77 #pragma omp critical
78  err = true;
79  }
80  }
81  }
82  if (err)
83  throw escript::ValueError("NodeMapping: target does not define a continuous labeling.");
84  }
85 
87  inline dim_t getNumTargets() const { return numTargets; }
88 
91 
93  index_t* target;
94 
97 
99  index_t* map;
100 };
101 
102 } // namespace dudley
103 
104 #endif // __DUDLEY_NODEMAPPING_H__
105 
dudley::NodeFile::globalDegreesOfFreedom
index_t * globalDegreesOfFreedom
Definition: dudley/src/NodeFile.h:157
MPI_Status
int MPI_Status
Definition: EsysMPI.h:45
dudley::NodeFile::gather
void gather(const index_t *index, const NodeFile *in)
Definition: NodeFile_gather.cpp:77
escript::DataTypes::real_t
double real_t
type of all real-valued scalars in escript
Definition: DataTypes.h:79
dudley::NodeMapping::numTargets
dim_t numTargets
size of map (number of target nodes, e.g. DOF, reduced DOF, etc.)
Definition: dudley/src/NodeMapping.h:124
dudley::NodeFile::nodesDistribution
escript::Distribution_ptr nodesDistribution
MPI distribution of nodes.
Definition: dudley/src/NodeFile.h:164
dudley::NodeFile::numDim
int numDim
number of spatial dimensions
Definition: dudley/src/NodeFile.h:146
dudley::NodeMapping::assign
void assign(const index_t *theTarget, dim_t nNodes, index_t unused)
Definition: dudley/src/NodeMapping.h:73
dudley::NodeFile
Definition: dudley/src/NodeFile.h:39
DudleyDomain.h
dudley::NodeFile::createNodeMappings
void createNodeMappings(const IndexVector &dofDistribution, const IndexVector &nodeDistribution)
Definition: NodeFile_createMappings.cpp:238
dudley::NodeFile::createDOFMappingAndCoupling
void createDOFMappingAndCoupling()
Definition: NodeFile_createMappings.cpp:43
escript::DataTypes::index_t_min
index_t index_t_min()
Returns the minimum finite value for the index_t type.
Definition: DataTypes.h:99
INDEX2
#define INDEX2(_X1_, _X2_, _N1_)
Definition: index.h:23
dudley::gatherEntries
static void gatherEntries(dim_t n, const index_t *index, index_t min_index, index_t max_index, index_t *Id_out, const index_t *Id_in, int *Tag_out, const int *Tag_in, index_t *globalDegreesOfFreedom_out, const index_t *globalDegreesOfFreedom_in, int numDim, real_t *Coordinates_out, const real_t *Coordinates_in)
Definition: NodeFile_gather.cpp:27
dudley::NodeMapping::getNumTargets
dim_t getNumTargets() const
returns the number of target nodes (number of items in the map array)
Definition: dudley/src/NodeMapping.h:115
dudley::scatterEntries
static void scatterEntries(dim_t n, const index_t *index, index_t min_index, index_t max_index, index_t *Id_out, const index_t *Id_in, int *Tag_out, const int *Tag_in, index_t *globalDegreesOfFreedom_out, const index_t *globalDegreesOfFreedom_in, int numDim, real_t *Coordinates_out, const real_t *Coordinates_in)
Definition: NodeFile_gather.cpp:52
MPI_SUM
#define MPI_SUM
Definition: EsysMPI.h:52
dudley::NodeFile::createDenseDOFLabeling
dim_t createDenseDOFLabeling()
Definition: NodeFile_createDenseLabelings.cpp:36
paso::SharedComponents
Definition: SharedComponents.h:55
dudley::NodeFile::MPIInfo
escript::JMPI MPIInfo
MPI information.
Definition: dudley/src/NodeFile.h:144
dudley::NodeFile::getGlobalIdRange
std::pair< index_t, index_t > getGlobalIdRange() const
Definition: dudley/src/NodeFile.cpp:171
escript::checkResult
bool checkResult(int res, int &mres, const JMPI &info)
Everyone puts in their error code and everyone gets the largest one.
Definition: EsysMPI.cpp:124
dudley::NodeFile::nodesMapping
NodeMapping nodesMapping
Definition: dudley/src/NodeFile.h:131
dudley::NodeFile::getGlobalDOFRange
std::pair< index_t, index_t > getGlobalDOFRange() const
Definition: dudley/src/NodeFile.cpp:176
paso::Connector
Definition: Coupler.h:61
dudley::NodeFile::status
int status
Definition: dudley/src/NodeFile.h:177
escript::Distribution
Definition: Distribution.h:46
MPI_INT
#define MPI_INT
Definition: EsysMPI.h:46
escript::DataTypes::index_t_max
index_t index_t_max()
Returns the maximum finite value for the index_t type.
Definition: DataTypes.h:108
MPI_MAX
#define MPI_MAX
Definition: EsysMPI.h:54
dudley
A suite of factory methods for creating 2D and 3D dudley domains.
Definition: dudley/src/Assemble.h:32
dudley::util::getFlaggedMinMaxInt
IndexPair getFlaggedMinMaxInt(dim_t N, const index_t *values, index_t ignore)
Definition: dudley/src/Util.cpp:214
dudley::NodeMapping::numNodes
dim_t numNodes
size of target (number of FEM nodes)
Definition: dudley/src/NodeMapping.h:118
escript::DataTypes::dim_t
index_t dim_t
Definition: DataTypes.h:93
dudley::NodeFile::degreesOfFreedomMapping
NodeMapping degreesOfFreedomMapping
Definition: dudley/src/NodeFile.h:132
dudley::NodeFile::gather_global
void gather_global(const index_t *index, const NodeFile *in)
Definition: NodeFile_gather.cpp:85
dudley::NodeFile::createDenseNodeLabeling
dim_t createDenseNodeLabeling(IndexVector &nodeDistribution, const IndexVector &dofDistribution)
escript::AssertException
An exception class for assertions within escript.
Definition: EsysException.h:73
dudley::NodeMapping::target
index_t * target
target[i] defines the target of FEM node i=0,...,numNodes
Definition: dudley/src/NodeMapping.h:121
NodeFile.h
paso::SharedComponents_ptr
boost::shared_ptr< SharedComponents > SharedComponents_ptr
Definition: SharedComponents.h:50
MPI_DOUBLE
#define MPI_DOUBLE
Definition: EsysMPI.h:47
dudley::NodeMapping::map
index_t * map
maps the target nodes back to the FEM nodes: target[map[i]]=i
Definition: dudley/src/NodeMapping.h:127
escript::DataTypes::index_t
int index_t
type for array/matrix indices used both globally and on each rank
Definition: DataTypes.h:88
dudley::NodeMapping::NodeMapping
NodeMapping()
Definition: dudley/src/NodeMapping.h:57
dudley::NodeFile::dofDistribution
escript::Distribution_ptr dofDistribution
MPI distribution of degrees of freedom.
Definition: dudley/src/NodeFile.h:167
Util.h
dudley::NodeFile::Id
index_t * Id
Id[i] is the unique ID number of FEM node i.
Definition: dudley/src/NodeFile.h:148
dudley::NodeFile::Tag
int * Tag
Tag[i] is the tag of node i.
Definition: dudley/src/NodeFile.h:150
dudley::NodeFile::numNodes
dim_t numNodes
number of nodes
Definition: dudley/src/NodeFile.h:135
escript::shipString
bool shipString(const char *src, char **dest, MPI_Comm &comm)
Definition: EsysMPI.cpp:178
dudley::NodeFile::degreesOfFreedomId
index_t * degreesOfFreedomId
Definition: dudley/src/NodeFile.h:173
ESYS_ASSERT
#define ESYS_ASSERT(a, b)
EsysAssert is a MACRO that will throw an exception if the boolean condition specified is false.
Definition: Assert.h:79
dudley::NodeFile::Coordinates
double * Coordinates
Coordinates[INDEX2(k,i,numDim)] is the k-th coordinate of node i.
Definition: dudley/src/NodeFile.h:159
escript::ValueError
An exception class that signals an invalid argument value.
Definition: EsysException.h:103
dudley::NodeMapping::clear
void clear()
resets both map and target
Definition: dudley/src/NodeMapping.h:60
dudley::NodeFile::globalNodesIndex
index_t * globalNodesIndex
assigns each local node a global unique ID in a dense labeling
Definition: dudley/src/NodeFile.h:161
escript::DataTypes::IndexVector
std::vector< index_t > IndexVector
Definition: DataTypes.h:91