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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6939 - (hide annotations)
Mon Jan 20 03:37:18 2020 UTC (4 weeks, 5 days ago) by uqaeller
File MIME type: text/plain
File size: 3102 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 5996 #ifndef __DUDLEY_NODEMAPPING_H__
19     #define __DUDLEY_NODEMAPPING_H__
20 ksteube 1313
21 caltinay 6119 #include "Util.h"
22 caltinay 5948
23 caltinay 5996 namespace dudley {
24 ksteube 1313
25 caltinay 6119 /// 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 ksteube 1313 };
101    
102 caltinay 5996 } // namespace dudley
103    
104     #endif // __DUDLEY_NODEMAPPING_H__
105    

  ViewVC Help
Powered by ViewVC 1.1.26