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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6939 - (hide annotations)
Mon Jan 20 03:37:18 2020 UTC (15 months, 2 weeks ago) by uqaeller
File MIME type: text/plain
File size: 2833 byte(s)
Updated the copyright header.


1 ksteube 1313
2 jfenwick 3981 /*****************************************************************************
3 ksteube 1811 *
4 uqaeller 6939 * Copyright (c) 2003-2020 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 uqaeller 6939 * Development from 2014-2017 by Centre for Geoscience Computing (GeoComp)
14     * Development from 2019 by School of Earth and Environmental Sciences
15     **
16 jfenwick 3981 *****************************************************************************/
17 ksteube 1313
18 caltinay 4492 /*
19     NodeMapping provides a mapping from the local nodes typically to the
20     degrees of freedom, the reduced degrees of freedom or the reduced node set.
21     */
22 ksteube 1811
23 caltinay 4492 #ifndef __FINLEY_NODEMAPPING_H__
24     #define __FINLEY_NODEMAPPING_H__
25 ksteube 1313
26 caltinay 4492 #include "Util.h"
27 ksteube 1313
28 caltinay 4492 namespace finley {
29 ksteube 1313
30 caltinay 4492 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 caltinay 5692 void assign(const std::vector<index_t>& theTarget, index_t unused)
42 caltinay 4492 {
43 sshaw 5346 if (theTarget.empty())
44     return;
45    
46 caltinay 5692 std::pair<index_t,index_t> range(
47 sshaw 5346 util::getFlaggedMinMaxInt(theTarget.size(), &theTarget[0], unused));
48 caltinay 4492 if (range.first < 0) {
49 caltinay 5988 throw escript::ValueError("NodeMapping: target has negative entry.");
50 caltinay 4492 }
51     // now we assume min(target)=0!
52 caltinay 5692 const dim_t numTargets = range.first<=range.second ? range.second+1 : 0;
53 caltinay 4492 target.assign(theTarget.begin(), theTarget.end());
54 caltinay 5692 const index_t targetSize = target.size();
55 caltinay 4492 map.assign(numTargets, -1);
56    
57 caltinay 5988 bool err = false;
58 caltinay 4492 #pragma omp parallel
59     {
60     #pragma omp for
61 caltinay 5692 for (index_t i=0; i<targetSize; ++i) {
62 caltinay 4492 if (target[i] != unused)
63     map[target[i]]=i;
64     }
65     // sanity check
66     #pragma omp for
67 caltinay 5692 for (index_t i=0; i<numTargets; ++i) {
68 caltinay 4492 if (map[i]==-1) {
69 caltinay 5988 #pragma omp critical
70     err=true;
71 caltinay 4492 }
72     }
73     }
74 caltinay 5988 if (err)
75     throw escript::ValueError("NodeMapping: target does not define a continuous labeling.");
76 caltinay 4492 }
77    
78     /// returns the number of target nodes (number of items in the map array)
79 caltinay 5692 dim_t getNumTargets() const { return map.size(); }
80 caltinay 4492
81     /// target[i] defines the target of FEM node i=0,...,numNodes-1
82 caltinay 5692 std::vector<index_t> target;
83 caltinay 4492 /// maps the target nodes back to the FEM nodes: target[map[i]]=i
84 caltinay 5692 std::vector<index_t> map;
85 ksteube 1313 };
86    
87 caltinay 4492 } // namespace finley
88 ksteube 1313
89 caltinay 4492 #endif // __FINLEY_NODEMAPPING_H__
90    

  ViewVC Help
Powered by ViewVC 1.1.26