escript Revision_
finley/src/NodeMapping.h
Go to the documentation of this file.
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
28namespace finley {
29
32 void clear()
33 {
34 target.clear();
35 map.clear();
36 }
37
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
79 dim_t getNumTargets() const { return map.size(); }
80
82 std::vector<index_t> target;
84 std::vector<index_t> map;
85};
86
87} // namespace finley
88
89#endif // __FINLEY_NODEMAPPING_H__
90
An exception class that signals an invalid argument value.
Definition EsysException.h:100
index_t dim_t
Definition DataTypes.h:66
int index_t
type for array/matrix indices used both globally and on each rank
Definition DataTypes.h:61
IndexPair getFlaggedMinMaxInt(dim_t N, const index_t *values, index_t ignore)
Definition finley/src/Util.cpp:305
A suite of factory methods for creating various finley domains.
Definition finley/src/Assemble.h:32
Definition finley/src/NodeMapping.h:30
std::vector< index_t > target
target[i] defines the target of FEM node i=0,...,numNodes-1
Definition finley/src/NodeMapping.h:82
std::vector< index_t > map
maps the target nodes back to the FEM nodes: target[map[i]]=i
Definition finley/src/NodeMapping.h:84
void assign(const std::vector< index_t > &theTarget, index_t unused)
Definition finley/src/NodeMapping.h:41
dim_t getNumTargets() const
returns the number of target nodes (number of items in the map array)
Definition finley/src/NodeMapping.h:79
void clear()
resets both map and target.
Definition finley/src/NodeMapping.h:32