escript  Revision_
NodeMapping.h
Go to the documentation of this file.
00001 
00002 /*****************************************************************************
00003 *
00004 * Copyright (c) 2003-2014 by University of Queensland
00005 * http://www.uq.edu.au
00006 *
00007 * Primary Business: Queensland, Australia
00008 * Licensed under the Open Software License version 3.0
00009 * http://www.opensource.org/licenses/osl-3.0.php
00010 *
00011 * Development until 2012 by Earth Systems Science Computational Center (ESSCC)
00012 * Development 2012-2013 by School of Earth Sciences
00013 * Development from 2014 by Centre for Geoscience Computing (GeoComp)
00014 *
00015 *****************************************************************************/
00016 
00017 /*
00018   NodeMapping provides a mapping from the local nodes typically to the
00019   degrees of freedom, the reduced degrees of freedom or the reduced node set.
00020 */
00021 
00022 #ifndef __FINLEY_NODEMAPPING_H__
00023 #define __FINLEY_NODEMAPPING_H__
00024 
00025 #include "Util.h"
00026 
00027 namespace finley {
00028 
00029 struct NodeMapping {
00031     void clear()
00032     {
00033         target.clear();
00034         map.clear();
00035     }
00036 
00040     void assign(const std::vector<int>& theTarget, int unused)
00041     {
00042         std::pair<int,int> range(
00043             util::getFlaggedMinMaxInt(theTarget.size(), &theTarget[0], unused));
00044         if (range.first < 0) {
00045             setError(VALUE_ERROR, "NodeMapping: target has negative entry.");
00046             return;
00047         }
00048         // now we assume min(target)=0!
00049         const int numTargets = range.first<=range.second ? range.second+1 : 0;
00050         target.assign(theTarget.begin(), theTarget.end());
00051         map.assign(numTargets, -1);
00052 
00053 #pragma omp parallel
00054         {
00055 #pragma omp for
00056             for (int i=0; i<target.size(); ++i) {
00057                 if (target[i] != unused)
00058                     map[target[i]]=i;
00059             }
00060             // sanity check
00061 #pragma omp for
00062             for (int i=0; i<numTargets; ++i) {
00063                 if (map[i]==-1) {
00064                     setError(VALUE_ERROR, "NodeMapping: target does not define a continuous labeling.");
00065                 }
00066             }
00067         }
00068     }
00069 
00071     int getNumTargets() const { return map.size(); }
00072 
00074     std::vector<int> target;
00076     std::vector<int> map;
00077 };
00078 
00079 } // namespace finley
00080 
00081 #endif // __FINLEY_NODEMAPPING_H__
00082