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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.26