dudley/src/NodeMapping.h
Go to the documentation of this file.
/*****************************************************************************
*
* Copyright (c) 2003-2017 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 by Centre for Geoscience Computing (GeoComp)
*
*****************************************************************************/
#ifndef __DUDLEY_NODEMAPPING_H__
#define __DUDLEY_NODEMAPPING_H__
#include "Util.h"
namespace dudley {
struct NodeMapping
{
NodeMapping() : numNodes(0), target(NULL), numTargets(0), map(NULL) {}
void clear()
{
delete[] map;
delete[] target;
target = NULL;
map = NULL;
numNodes = 0;
numTargets = 0;
}
void assign(const index_t* theTarget, dim_t nNodes, index_t unused)
{
clear();
if (nNodes == 0)
return;
numNodes = nNodes;
std::pair<index_t,index_t> range(
util::getFlaggedMinMaxInt(numNodes, theTarget, unused));
if (range.first < 0) {
throw escript::ValueError("NodeMapping: target has negative entry.");
}
numTargets = range.first<=range.second ? range.second+1 : 0;
target = new index_t[numNodes];
map = new index_t[numTargets];
bool err = false;
#pragma omp parallel
{
#pragma omp for
for (index_t i=0; i<numNodes; ++i) {
target[i] = theTarget[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.");
}
inline dim_t getNumTargets() const { return numTargets; }
dim_t numNodes;
index_t* target;
dim_t numTargets;
index_t* map;
};
} // namespace dudley
#endif // __DUDLEY_NODEMAPPING_H__
dudley::NodeMapping::getNumTargets
dim_t getNumTargets() const
returns the number of target nodes (number of items in the map array)
Definition: dudley/src/NodeMapping.h:86
dudley::NodeMapping::assign
void assign(const index_t *theTarget, dim_t nNodes, index_t unused)
Definition: dudley/src/NodeMapping.h:44
escript::DataTypes::index_t
int index_t
type for array/matrix indices used both globally and on each rank
Definition: DataTypes.h:59
dudley::NodeMapping::target
index_t * target
target[i] defines the target of FEM node i=0,...,numNodes
Definition: dudley/src/NodeMapping.h:92
dudley::NodeMapping::numNodes
dim_t numNodes
size of target (number of FEM nodes)
Definition: dudley/src/NodeMapping.h:89
dudley
A suite of factory methods for creating 2D and 3D dudley domains.
Definition: dudley/src/Assemble.h:31
dudley::NodeMapping::NodeMapping
NodeMapping()
Definition: dudley/src/NodeMapping.h:28
dudley::NodeMapping::map
index_t * map
maps the target nodes back to the FEM nodes: target[map[i]]=i
Definition: dudley/src/NodeMapping.h:98
dudley::util::getFlaggedMinMaxInt
IndexPair getFlaggedMinMaxInt(dim_t N, const index_t *values, index_t ignore)
Definition: dudley/src/Util.cpp:185
dudley::NodeMapping
Definition: dudley/src/NodeMapping.h:26
escript::ValueError
An exception class that signals an invalid argument value.
Definition: EsysException.h:88
dudley::NodeMapping::clear
void clear()
resets both map and target
Definition: dudley/src/NodeMapping.h:31
dudley::NodeMapping::numTargets
dim_t numTargets
size of map (number of target nodes, e.g. DOF, reduced DOF, etc.)
Definition: dudley/src/NodeMapping.h:95
Util.h
escript::DataTypes::dim_t
index_t dim_t
Definition: DataTypes.h:64