escript  Revision_
dudley/src/NodeMapping.h
Go to the documentation of this file.
1 
2 /*****************************************************************************
3 *
4 * Copyright (c) 2003-2016 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 
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 
93 
96 
99 };
100 
101 } // namespace dudley
102 
103 #endif // __DUDLEY_NODEMAPPING_H__
104 
dim_t getNumTargets() const
returns the number of target nodes (number of items in the map array)
Definition: dudley/src/NodeMapping.h:86
void assign(const index_t *theTarget, dim_t nNodes, index_t unused)
Definition: dudley/src/NodeMapping.h:44
int index_t
type for array/matrix indices used both globally and on each rank
Definition: DataTypes.h:59
index_t * target
target[i] defines the target of FEM node i=0,...,numNodes
Definition: dudley/src/NodeMapping.h:92
dim_t numNodes
size of target (number of FEM nodes)
Definition: dudley/src/NodeMapping.h:89
A suite of factory methods for creating 2D and 3D dudley domains.
Definition: dudley/src/Assemble.h:31
NodeMapping()
Definition: dudley/src/NodeMapping.h:28
index_t * map
maps the target nodes back to the FEM nodes: target[map[i]]=i
Definition: dudley/src/NodeMapping.h:98
IndexPair getFlaggedMinMaxInt(dim_t N, const index_t *values, index_t ignore)
Definition: dudley/src/Util.cpp:177
Definition: dudley/src/NodeMapping.h:26
An exception class that signals an invalid argument value.
Definition: EsysException.h:88
void clear()
resets both map and target
Definition: dudley/src/NodeMapping.h:31
dim_t numTargets
size of map (number of target nodes, e.g. DOF, reduced DOF, etc.)
Definition: dudley/src/NodeMapping.h:95
index_t dim_t
Definition: DataTypes.h:64