escript  Revision_
dudley/src/NodeMapping.h
Go to the documentation of this file.
1 
2 /*****************************************************************************
3 *
4 * Copyright (c) 2003-2018 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 by Centre for Geoscience Computing (GeoComp)
14 *
15 *****************************************************************************/
16 
17 #ifndef __DUDLEY_NODEMAPPING_H__
18 #define __DUDLEY_NODEMAPPING_H__
19 
20 #include "Util.h"
21 
22 namespace dudley {
23 
26 struct NodeMapping
27 {
28  NodeMapping() : numNodes(0), target(NULL), numTargets(0), map(NULL) {}
29 
31  void clear()
32  {
33  delete[] map;
34  delete[] target;
35  target = NULL;
36  map = NULL;
37  numNodes = 0;
38  numTargets = 0;
39  }
40 
44  void assign(const index_t* theTarget, dim_t nNodes, index_t unused)
45  {
46  clear();
47 
48  if (nNodes == 0)
49  return;
50 
51  numNodes = nNodes;
52 
53  std::pair<index_t,index_t> range(
54  util::getFlaggedMinMaxInt(numNodes, theTarget, unused));
55  if (range.first < 0) {
56  throw escript::ValueError("NodeMapping: target has negative entry.");
57  }
58  numTargets = range.first<=range.second ? range.second+1 : 0;
59 
60  target = new index_t[numNodes];
61  map = new index_t[numTargets];
62 
63  bool err = false;
64 #pragma omp parallel
65  {
66 #pragma omp for
67  for (index_t i=0; i<numNodes; ++i) {
68  target[i] = theTarget[i];
69  if (target[i] != unused)
70  map[target[i]] = i;
71  }
72  // sanity check
73 #pragma omp for
74  for (index_t i=0; i<numTargets; ++i) {
75  if (map[i] == -1) {
76 #pragma omp critical
77  err = true;
78  }
79  }
80  }
81  if (err)
82  throw escript::ValueError("NodeMapping: target does not define a continuous labeling.");
83  }
84 
86  inline dim_t getNumTargets() const { return numTargets; }
87 
90 
92  index_t* target;
93 
96 
98  index_t* map;
99 };
100 
101 } // namespace dudley
102 
103 #endif // __DUDLEY_NODEMAPPING_H__
104 
dudley::NodeFile::globalDegreesOfFreedom
index_t * globalDegreesOfFreedom
Definition: dudley/src/NodeFile.h:155
MPI_Status
int MPI_Status
Definition: EsysMPI.h:43
dudley::NodeFile::gather
void gather(const index_t *index, const NodeFile *in)
Definition: NodeFile_gather.cpp:75
escript::DataTypes::real_t
double real_t
type of all real-valued scalars in escript
Definition: DataTypes.h:73
dudley::NodeMapping::numTargets
dim_t numTargets
size of map (number of target nodes, e.g. DOF, reduced DOF, etc.)
Definition: dudley/src/NodeMapping.h:118
dudley::NodeFile::nodesDistribution
escript::Distribution_ptr nodesDistribution
MPI distribution of nodes.
Definition: dudley/src/NodeFile.h:162
dudley::NodeFile::numDim
int numDim
number of spatial dimensions
Definition: dudley/src/NodeFile.h:144
dudley::NodeMapping::assign
void assign(const index_t *theTarget, dim_t nNodes, index_t unused)
Definition: dudley/src/NodeMapping.h:67
dudley::NodeFile
Definition: dudley/src/NodeFile.h:37
DudleyDomain.h
dudley::NodeFile::createNodeMappings
void createNodeMappings(const IndexVector &dofDistribution, const IndexVector &nodeDistribution)
Definition: NodeFile_createMappings.cpp:234
dudley::NodeFile::createDOFMappingAndCoupling
void createDOFMappingAndCoupling()
Definition: NodeFile_createMappings.cpp:39
escript::DataTypes::index_t_min
index_t index_t_min()
Returns the minimum finite value for the index_t type.
Definition: DataTypes.h:93
INDEX2
#define INDEX2(_X1_, _X2_, _N1_)
Definition: index.h:21
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:25
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:109
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:50
MPI_SUM
#define MPI_SUM
Definition: EsysMPI.h:50
dudley::NodeFile::createDenseDOFLabeling
dim_t createDenseDOFLabeling()
Definition: NodeFile_createDenseLabelings.cpp:32
paso::SharedComponents
Definition: SharedComponents.h:51
dudley::NodeFile::MPIInfo
escript::JMPI MPIInfo
MPI information.
Definition: dudley/src/NodeFile.h:142
dudley::NodeFile::getGlobalIdRange
std::pair< index_t, index_t > getGlobalIdRange() const
Definition: dudley/src/NodeFile.cpp:167
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:120
dudley::NodeFile::nodesMapping
NodeMapping nodesMapping
Definition: dudley/src/NodeFile.h:129
dudley::NodeFile::getGlobalDOFRange
std::pair< index_t, index_t > getGlobalDOFRange() const
Definition: dudley/src/NodeFile.cpp:172
paso::Connector
Definition: Coupler.h:57
dudley::NodeFile::status
int status
Definition: dudley/src/NodeFile.h:175
escript::Distribution
Definition: Distribution.h:42
MPI_INT
#define MPI_INT
Definition: EsysMPI.h:44
escript::DataTypes::index_t_max
index_t index_t_max()
Returns the maximum finite value for the index_t type.
Definition: DataTypes.h:102
MPI_MAX
#define MPI_MAX
Definition: EsysMPI.h:52
dudley
A suite of factory methods for creating 2D and 3D dudley domains.
Definition: dudley/src/Assemble.h:31
dudley::util::getFlaggedMinMaxInt
IndexPair getFlaggedMinMaxInt(dim_t N, const index_t *values, index_t ignore)
Definition: dudley/src/Util.cpp:208
dudley::NodeMapping::numNodes
dim_t numNodes
size of target (number of FEM nodes)
Definition: dudley/src/NodeMapping.h:112
escript::DataTypes::dim_t
index_t dim_t
Definition: DataTypes.h:87
dudley::NodeFile::degreesOfFreedomMapping
NodeMapping degreesOfFreedomMapping
Definition: dudley/src/NodeFile.h:130
dudley::NodeFile::gather_global
void gather_global(const index_t *index, const NodeFile *in)
Definition: NodeFile_gather.cpp:83
dudley::NodeFile::createDenseNodeLabeling
dim_t createDenseNodeLabeling(IndexVector &nodeDistribution, const IndexVector &dofDistribution)
escript::AssertException
An exception class for assertions within escript.
Definition: EsysException.h:69
dudley::NodeMapping::target
index_t * target
target[i] defines the target of FEM node i=0,...,numNodes
Definition: dudley/src/NodeMapping.h:115
NodeFile.h
paso::SharedComponents_ptr
boost::shared_ptr< SharedComponents > SharedComponents_ptr
Definition: SharedComponents.h:46
MPI_DOUBLE
#define MPI_DOUBLE
Definition: EsysMPI.h:45
dudley::NodeMapping::map
index_t * map
maps the target nodes back to the FEM nodes: target[map[i]]=i
Definition: dudley/src/NodeMapping.h:121
escript::DataTypes::index_t
int index_t
type for array/matrix indices used both globally and on each rank
Definition: DataTypes.h:82
dudley::NodeMapping::NodeMapping
NodeMapping()
Definition: dudley/src/NodeMapping.h:51
dudley::NodeFile::dofDistribution
escript::Distribution_ptr dofDistribution
MPI distribution of degrees of freedom.
Definition: dudley/src/NodeFile.h:165
Util.h
dudley::NodeFile::Id
index_t * Id
Id[i] is the unique ID number of FEM node i.
Definition: dudley/src/NodeFile.h:146
dudley::NodeFile::Tag
int * Tag
Tag[i] is the tag of node i.
Definition: dudley/src/NodeFile.h:148
dudley::NodeFile::numNodes
dim_t numNodes
number of nodes
Definition: dudley/src/NodeFile.h:133
escript::shipString
bool shipString(const char *src, char **dest, MPI_Comm &comm)
Definition: EsysMPI.cpp:174
dudley::NodeFile::degreesOfFreedomId
index_t * degreesOfFreedomId
Definition: dudley/src/NodeFile.h:171
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:77
dudley::NodeFile::Coordinates
double * Coordinates
Coordinates[INDEX2(k,i,numDim)] is the k-th coordinate of node i.
Definition: dudley/src/NodeFile.h:157
escript::ValueError
An exception class that signals an invalid argument value.
Definition: EsysException.h:99
dudley::NodeMapping::clear
void clear()
resets both map and target
Definition: dudley/src/NodeMapping.h:54
dudley::NodeFile::globalNodesIndex
index_t * globalNodesIndex
assigns each local node a global unique ID in a dense labeling
Definition: dudley/src/NodeFile.h:159
escript::DataTypes::IndexVector
std::vector< index_t > IndexVector
Definition: DataTypes.h:85