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 
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 
94 
97 
100 };
101 
102 } // namespace dudley
103 
104 #endif // __DUDLEY_NODEMAPPING_H__
105 
An exception class that signals an invalid argument value.
Definition: EsysException.h:100
IndexPair getFlaggedMinMaxInt(dim_t N, const index_t *values, index_t ignore)
Definition: dudley/src/Util.cpp:186
A suite of factory methods for creating 2D and 3D dudley domains.
Definition: dudley/src/Assemble.h:32
index_t dim_t
Definition: DataTypes.h:66
int index_t
type for array/matrix indices used both globally and on each rank
Definition: DataTypes.h:61
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:99
dim_t numTargets
size of map (number of target nodes, e.g. DOF, reduced DOF, etc.)
Definition: dudley/src/NodeMapping.h:96
dim_t numNodes
size of target (number of FEM nodes)
Definition: dudley/src/NodeMapping.h:90
dim_t getNumTargets() const
returns the number of target nodes (number of items in the map array)
Definition: dudley/src/NodeMapping.h:87
void clear()
resets both map and target
Definition: dudley/src/NodeMapping.h:32
index_t * target
target[i] defines the target of FEM node i=0,...,numNodes
Definition: dudley/src/NodeMapping.h:93
NodeMapping()
Definition: dudley/src/NodeMapping.h:29
void assign(const index_t *theTarget, dim_t nNodes, index_t unused)
Definition: dudley/src/NodeMapping.h:45