escript  Revision_4925
finley/src/NodeMapping.h
Go to the documentation of this file.
1 
2 /*****************************************************************************
3 *
4 * Copyright (c) 2003-2014 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 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<int>& theTarget, int unused)
41  {
42  std::pair<int,int> range(
43  util::getFlaggedMinMaxInt(theTarget.size(), &theTarget[0], unused));
44  if (range.first < 0) {
45  setError(VALUE_ERROR, "NodeMapping: target has negative entry.");
46  return;
47  }
48  // now we assume min(target)=0!
49  const int numTargets = range.first<=range.second ? range.second+1 : 0;
50  target.assign(theTarget.begin(), theTarget.end());
51  map.assign(numTargets, -1);
52 
53 #pragma omp parallel
54  {
55 #pragma omp for
56  for (int i=0; i<target.size(); ++i) {
57  if (target[i] != unused)
58  map[target[i]]=i;
59  }
60  // sanity check
61 #pragma omp for
62  for (int i=0; i<numTargets; ++i) {
63  if (map[i]==-1) {
64  setError(VALUE_ERROR, "NodeMapping: target does not define a continuous labeling.");
65  }
66  }
67  }
68  }
69 
71  int getNumTargets() const { return map.size(); }
72 
74  std::vector<int> target;
76  std::vector<int> map;
77 };
78 
79 } // namespace finley
80 
81 #endif // __FINLEY_NODEMAPPING_H__
82 
void clear()
resets both map and target.
Definition: finley/src/NodeMapping.h:31
void assign(const std::vector< int > &theTarget, int unused)
Definition: finley/src/NodeMapping.h:40
void setError(ErrorCodeType err, const char *msg)
sets an error
Definition: Finley.cpp:43
std::vector< int > target
target[i] defines the target of FEM node i=0,...,numNodes-1
Definition: finley/src/NodeMapping.h:74
Definition: finley/src/NodeMapping.h:29
int getNumTargets() const
returns the number of target nodes (number of items in the map array)
Definition: finley/src/NodeMapping.h:71
std::pair< int, int > getFlaggedMinMaxInt(int N, const int *values, int ignore)
Definition: finley/src/Util.cpp:306
std::vector< int > map
maps the target nodes back to the FEM nodes: target[map[i]]=i
Definition: finley/src/NodeMapping.h:76
Definition: error.h:45