/[escript]/trunk/finley/src/NodeMapping.h
ViewVC logotype

Contents of /trunk/finley/src/NodeMapping.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4492 - (show annotations)
Tue Jul 2 01:44:11 2013 UTC (5 years, 9 months ago) by caltinay
File MIME type: text/plain
File size: 2519 byte(s)
Finley changes that were held back while in release mode - moved more stuff
into finley namespace.

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 #include <vector>
27
28 namespace finley {
29
30 struct NodeMapping {
31 /// resets both map and target.
32 void clear()
33 {
34 target.clear();
35 map.clear();
36 }
37
38 /// initializes a node mapping. The target array is copied and a reverse
39 /// map created.
40 /// theTarget[i]=unused means that no target is defined for FEM node i.
41 void assign(const std::vector<int>& theTarget, int unused)
42 {
43 std::pair<int,int> range(
44 util::getFlaggedMinMaxInt(theTarget.size(), &theTarget[0], unused));
45 if (range.first < 0) {
46 Finley_setError(VALUE_ERROR, "NodeMapping: target has negative entry.");
47 return;
48 }
49 // now we assume min(target)=0!
50 const int numTargets = range.first<=range.second ? range.second+1 : 0;
51 target.assign(theTarget.begin(), theTarget.end());
52 map.assign(numTargets, -1);
53
54 #pragma omp parallel
55 {
56 #pragma omp for
57 for (int i=0; i<target.size(); ++i) {
58 if (target[i] != unused)
59 map[target[i]]=i;
60 }
61 // sanity check
62 #pragma omp for
63 for (int i=0; i<numTargets; ++i) {
64 if (map[i]==-1) {
65 Finley_setError(VALUE_ERROR, "NodeMapping: target does not define a continuous labeling.");
66 }
67 }
68 }
69 }
70
71 /// returns the number of target nodes (number of items in the map array)
72 int getNumTargets() const { return map.size(); }
73
74 /// target[i] defines the target of FEM node i=0,...,numNodes-1
75 std::vector<int> target;
76 /// maps the target nodes back to the FEM nodes: target[map[i]]=i
77 std::vector<int> map;
78 };
79
80 } // namespace finley
81
82 #endif // __FINLEY_NODEMAPPING_H__
83

  ViewVC Help
Powered by ViewVC 1.1.26