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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6651 - (show annotations)
Wed Feb 7 02:12:08 2018 UTC (21 months, 1 week ago) by jfenwick
File MIME type: text/plain
File size: 2757 byte(s)
Make everyone sad by touching all the files

Copyright dates update

1
2 /*****************************************************************************
3 *
4 * Copyright (c) 2003-2018 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 {
30 /// resets both map and target.
31 void clear()
32 {
33 target.clear();
34 map.clear();
35 }
36
37 /// initializes a node mapping. The target array is copied and a reverse
38 /// map created.
39 /// theTarget[i]=unused means that no target is defined for FEM node i.
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
77 /// returns the number of target nodes (number of items in the map array)
78 dim_t getNumTargets() const { return map.size(); }
79
80 /// target[i] defines the target of FEM node i=0,...,numNodes-1
81 std::vector<index_t> target;
82 /// maps the target nodes back to the FEM nodes: target[map[i]]=i
83 std::vector<index_t> map;
84 };
85
86 } // namespace finley
87
88 #endif // __FINLEY_NODEMAPPING_H__
89

  ViewVC Help
Powered by ViewVC 1.1.26