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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6939 - (show annotations)
Mon Jan 20 03:37:18 2020 UTC (5 weeks, 1 day ago) by uqaeller
File MIME type: text/plain
File size: 3102 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 #ifndef __DUDLEY_NODEMAPPING_H__
19 #define __DUDLEY_NODEMAPPING_H__
20
21 #include "Util.h"
22
23 namespace dudley {
24
25 /// NodeMapping provides a mapping from the local nodes typically to the
26 /// degrees of freedom, the reduced degrees of freedom or the reduced node set
27 struct NodeMapping
28 {
29 NodeMapping() : numNodes(0), target(NULL), numTargets(0), map(NULL) {}
30
31 /// resets both map and target
32 void clear()
33 {
34 delete[] map;
35 delete[] target;
36 target = NULL;
37 map = NULL;
38 numNodes = 0;
39 numTargets = 0;
40 }
41
42 /// initializes a node mapping. The target array is copied and a reverse
43 /// map created.
44 /// theTarget[i]=unused means that no target is defined for FEM node i.
45 void assign(const index_t* theTarget, dim_t nNodes, index_t unused)
46 {
47 clear();
48
49 if (nNodes == 0)
50 return;
51
52 numNodes = nNodes;
53
54 std::pair<index_t,index_t> range(
55 util::getFlaggedMinMaxInt(numNodes, theTarget, unused));
56 if (range.first < 0) {
57 throw escript::ValueError("NodeMapping: target has negative entry.");
58 }
59 numTargets = range.first<=range.second ? range.second+1 : 0;
60
61 target = new index_t[numNodes];
62 map = new index_t[numTargets];
63
64 bool err = false;
65 #pragma omp parallel
66 {
67 #pragma omp for
68 for (index_t i=0; i<numNodes; ++i) {
69 target[i] = theTarget[i];
70 if (target[i] != unused)
71 map[target[i]] = i;
72 }
73 // sanity check
74 #pragma omp for
75 for (index_t i=0; i<numTargets; ++i) {
76 if (map[i] == -1) {
77 #pragma omp critical
78 err = true;
79 }
80 }
81 }
82 if (err)
83 throw escript::ValueError("NodeMapping: target does not define a continuous labeling.");
84 }
85
86 /// returns the number of target nodes (number of items in the map array)
87 inline dim_t getNumTargets() const { return numTargets; }
88
89 /// size of `target` (number of FEM nodes)
90 dim_t numNodes;
91
92 /// target[i] defines the target of FEM node i=0,...,numNodes
93 index_t* target;
94
95 /// size of `map` (number of target nodes, e.g. DOF, reduced DOF, etc.)
96 dim_t numTargets;
97
98 /// maps the target nodes back to the FEM nodes: target[map[i]]=i
99 index_t* map;
100 };
101
102 } // namespace dudley
103
104 #endif // __DUDLEY_NODEMAPPING_H__
105

  ViewVC Help
Powered by ViewVC 1.1.26