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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6651 - (hide 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 ksteube 1313
2 jfenwick 3981 /*****************************************************************************
3 ksteube 1811 *
4 jfenwick 6651 * Copyright (c) 2003-2018 by The University of Queensland
5 jfenwick 3981 * http://www.uq.edu.au
6 ksteube 1811 *
7     * Primary Business: Queensland, Australia
8 jfenwick 6112 * Licensed under the Apache License, version 2.0
9     * http://www.apache.org/licenses/LICENSE-2.0
10 ksteube 1811 *
11 jfenwick 3981 * Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12 jfenwick 4657 * Development 2012-2013 by School of Earth Sciences
13     * Development from 2014 by Centre for Geoscience Computing (GeoComp)
14 jfenwick 3981 *
15     *****************************************************************************/
16 ksteube 1313
17 caltinay 4492 /*
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 ksteube 1811
22 caltinay 4492 #ifndef __FINLEY_NODEMAPPING_H__
23     #define __FINLEY_NODEMAPPING_H__
24 ksteube 1313
25 caltinay 4492 #include "Util.h"
26 ksteube 1313
27 caltinay 4492 namespace finley {
28 ksteube 1313
29 caltinay 4492 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 caltinay 5692 void assign(const std::vector<index_t>& theTarget, index_t unused)
41 caltinay 4492 {
42 sshaw 5346 if (theTarget.empty())
43     return;
44    
45 caltinay 5692 std::pair<index_t,index_t> range(
46 sshaw 5346 util::getFlaggedMinMaxInt(theTarget.size(), &theTarget[0], unused));
47 caltinay 4492 if (range.first < 0) {
48 caltinay 5988 throw escript::ValueError("NodeMapping: target has negative entry.");
49 caltinay 4492 }
50     // now we assume min(target)=0!
51 caltinay 5692 const dim_t numTargets = range.first<=range.second ? range.second+1 : 0;
52 caltinay 4492 target.assign(theTarget.begin(), theTarget.end());
53 caltinay 5692 const index_t targetSize = target.size();
54 caltinay 4492 map.assign(numTargets, -1);
55    
56 caltinay 5988 bool err = false;
57 caltinay 4492 #pragma omp parallel
58     {
59     #pragma omp for
60 caltinay 5692 for (index_t i=0; i<targetSize; ++i) {
61 caltinay 4492 if (target[i] != unused)
62     map[target[i]]=i;
63     }
64     // sanity check
65     #pragma omp for
66 caltinay 5692 for (index_t i=0; i<numTargets; ++i) {
67 caltinay 4492 if (map[i]==-1) {
68 caltinay 5988 #pragma omp critical
69     err=true;
70 caltinay 4492 }
71     }
72     }
73 caltinay 5988 if (err)
74     throw escript::ValueError("NodeMapping: target does not define a continuous labeling.");
75 caltinay 4492 }
76    
77     /// returns the number of target nodes (number of items in the map array)
78 caltinay 5692 dim_t getNumTargets() const { return map.size(); }
79 caltinay 4492
80     /// target[i] defines the target of FEM node i=0,...,numNodes-1
81 caltinay 5692 std::vector<index_t> target;
82 caltinay 4492 /// maps the target nodes back to the FEM nodes: target[map[i]]=i
83 caltinay 5692 std::vector<index_t> map;
84 ksteube 1313 };
85    
86 caltinay 4492 } // namespace finley
87 ksteube 1313
88 caltinay 4492 #endif // __FINLEY_NODEMAPPING_H__
89    

  ViewVC Help
Powered by ViewVC 1.1.26