finley/src/NodeMapping.h
Go to the documentation of this file.
/*****************************************************************************
*
* Copyright (c) 2003-2020 by The University of Queensland
* http://www.uq.edu.au
*
* Primary Business: Queensland, Australia
* Licensed under the Apache License, version 2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Development until 2012 by Earth Systems Science Computational Center (ESSCC)
* Development 2012-2013 by School of Earth Sciences
* Development from 2014-2017 by Centre for Geoscience Computing (GeoComp)
* Development from 2019 by School of Earth and Environmental Sciences
**
*****************************************************************************/
/*
NodeMapping provides a mapping from the local nodes typically to the
degrees of freedom, the reduced degrees of freedom or the reduced node set.
*/
#ifndef __FINLEY_NODEMAPPING_H__
#define __FINLEY_NODEMAPPING_H__
#include "Util.h"
namespace finley {
struct NodeMapping {
void clear()
{
target.clear();
map.clear();
}
void assign(const std::vector<index_t>& theTarget, index_t unused)
{
if (theTarget.empty())
return;
std::pair<index_t,index_t> range(
util::getFlaggedMinMaxInt(theTarget.size(), &theTarget[0], unused));
if (range.first < 0) {
throw escript::ValueError("NodeMapping: target has negative entry.");
}
// now we assume min(target)=0!
const dim_t numTargets = range.first<=range.second ? range.second+1 : 0;
target.assign(theTarget.begin(), theTarget.end());
const index_t targetSize = target.size();
map.assign(numTargets, -1);
bool err = false;
#pragma omp parallel
{
#pragma omp for
for (index_t i=0; i<targetSize; ++i) {
if (target[i] != unused)
map[target[i]]=i;
}
// sanity check
#pragma omp for
for (index_t i=0; i<numTargets; ++i) {
if (map[i]==-1) {
#pragma omp critical
err=true;
}
}
}
if (err)
throw escript::ValueError("NodeMapping: target does not define a continuous labeling.");
}
dim_t getNumTargets() const { return map.size(); }
std::vector<index_t> target;
std::vector<index_t> map;
};
} // namespace finley
#endif // __FINLEY_NODEMAPPING_H__
escript::ValueError
An exception class that signals an invalid argument value.
Definition: EsysException.h:100
Util.h
escript::DataTypes::dim_t
index_t dim_t
Definition: DataTypes.h:66
escript::DataTypes::index_t
int index_t
type for array/matrix indices used both globally and on each rank
Definition: DataTypes.h:61
finley::util::getFlaggedMinMaxInt
IndexPair getFlaggedMinMaxInt(dim_t N, const index_t *values, index_t ignore)
Definition: finley/src/Util.cpp:305
finley
A suite of factory methods for creating various finley domains.
Definition: finley/src/Assemble.h:32
finley::NodeMapping
Definition: finley/src/NodeMapping.h:30
finley::NodeMapping::target
std::vector< index_t > target
target[i] defines the target of FEM node i=0,...,numNodes-1
Definition: finley/src/NodeMapping.h:82
finley::NodeMapping::map
std::vector< index_t > map
maps the target nodes back to the FEM nodes: target[map[i]]=i
Definition: finley/src/NodeMapping.h:84
finley::NodeMapping::assign
void assign(const std::vector< index_t > &theTarget, index_t unused)
Definition: finley/src/NodeMapping.h:41
finley::NodeMapping::getNumTargets
dim_t getNumTargets() const
returns the number of target nodes (number of items in the map array)
Definition: finley/src/NodeMapping.h:79
finley::NodeMapping::clear
void clear()
resets both map and target.
Definition: finley/src/NodeMapping.h:32