ESScript  Revision_
finley/src/NodeMapping.h
Go to the documentation of this file.
1 
2 /*****************************************************************************
3 *
4 * Copyright (c) 2003-2013 by University of Queensland
5 * http://www.uq.edu.au
6 *
7 * Primary Business: Queensland, Australia
8 * Licensed under the Open Software License version 3.0
9 * http://www.opensource.org/licenses/osl-3.0.php
10 *
11 * Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12 * Development since 2012 by School of Earth Sciences
13 *
14 *****************************************************************************/
15 
16 /*
17  NodeMapping provides a mapping from the local nodes typically to the
18  degrees of freedom, the reduced degrees of freedom or the reduced node set.
19 */
20 
21 #ifndef __FINLEY_NODEMAPPING_H__
22 #define __FINLEY_NODEMAPPING_H__
23 
24 #include "Util.h"
25 
26 namespace finley {
27 
28 struct NodeMapping {
30  void clear()
31  {
32  target.clear();
33  map.clear();
34  }
35 
39  void assign(const std::vector<int>& theTarget, int unused)
40  {
41  std::pair<int,int> range(
42  util::getFlaggedMinMaxInt(theTarget.size(), &theTarget[0], unused));
43  if (range.first < 0) {
44  setError(VALUE_ERROR, "NodeMapping: target has negative entry.");
45  return;
46  }
47  // now we assume min(target)=0!
48  const int numTargets = range.first<=range.second ? range.second+1 : 0;
49  target.assign(theTarget.begin(), theTarget.end());
50  map.assign(numTargets, -1);
51 
52 #pragma omp parallel
53  {
54 #pragma omp for
55  for (int i=0; i<target.size(); ++i) {
56  if (target[i] != unused)
57  map[target[i]]=i;
58  }
59  // sanity check
60 #pragma omp for
61  for (int i=0; i<numTargets; ++i) {
62  if (map[i]==-1) {
63  setError(VALUE_ERROR, "NodeMapping: target does not define a continuous labeling.");
64  }
65  }
66  }
67  }
68 
70  int getNumTargets() const { return map.size(); }
71 
73  std::vector<int> target;
75  std::vector<int> map;
76 };
77 
78 } // namespace finley
79 
80 #endif // __FINLEY_NODEMAPPING_H__
81