escript  Revision_
finley/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 /*
18  NodeMapping provides a mapping from the local nodes typically to the
19  degrees of freedom, the reduced degrees of freedom or the reduced node set.
20 */
21 
22 #ifndef __FINLEY_NODEMAPPING_H__
23 #define __FINLEY_NODEMAPPING_H__
24 
25 #include "Util.h"
26 
27 namespace finley {
28 
29 struct NodeMapping {
31  void clear()
32  {
33  target.clear();
34  map.clear();
35  }
36 
40  void assign(const std::vector<index_t>& theTarget, index_t unused)
41  {
42  if (theTarget.empty())
43  return;
44 
45  std::pair<index_t,index_t> range(
46  util::getFlaggedMinMaxInt(theTarget.size(), &theTarget[0], unused));
47  if (range.first < 0) {
48  throw escript::ValueError("NodeMapping: target has negative entry.");
49  }
50  // now we assume min(target)=0!
51  const dim_t numTargets = range.first<=range.second ? range.second+1 : 0;
52  target.assign(theTarget.begin(), theTarget.end());
53  const index_t targetSize = target.size();
54  map.assign(numTargets, -1);
55 
56  bool err = false;
57 #pragma omp parallel
58  {
59 #pragma omp for
60  for (index_t i=0; i<targetSize; ++i) {
61  if (target[i] != unused)
62  map[target[i]]=i;
63  }
64  // sanity check
65 #pragma omp for
66  for (index_t i=0; i<numTargets; ++i) {
67  if (map[i]==-1) {
68 #pragma omp critical
69  err=true;
70  }
71  }
72  }
73  if (err)
74  throw escript::ValueError("NodeMapping: target does not define a continuous labeling.");
75  }
76 
78  dim_t getNumTargets() const { return map.size(); }
79 
81  std::vector<index_t> target;
83  std::vector<index_t> map;
84 };
85 
86 } // namespace finley
87 
88 #endif // __FINLEY_NODEMAPPING_H__
89 
void clear()
resets both map and target.
Definition: finley/src/NodeMapping.h:31
IndexPair getFlaggedMinMaxInt(dim_t N, const index_t *values, index_t ignore)
Definition: finley/src/Util.cpp:294
void assign(const std::vector< index_t > &theTarget, index_t unused)
Definition: finley/src/NodeMapping.h:40
A suite of factory methods for creating various finley domains.
Definition: finley/src/Assemble.h:31
int index_t
type for array/matrix indices used both globally and on each rank
Definition: DataTypes.h:59
Definition: finley/src/NodeMapping.h:29
std::vector< index_t > target
target[i] defines the target of FEM node i=0,...,numNodes-1
Definition: finley/src/NodeMapping.h:81
std::vector< index_t > map
maps the target nodes back to the FEM nodes: target[map[i]]=i
Definition: finley/src/NodeMapping.h:83
dim_t getNumTargets() const
returns the number of target nodes (number of items in the map array)
Definition: finley/src/NodeMapping.h:78
An exception class that signals an invalid argument value.
Definition: EsysException.h:88
index_t dim_t
Definition: DataTypes.h:64