# Diff of /branches/trilinos_from_5897/dudley/src/NodeMapping.h

revision 6078 by caltinay, Wed Mar 2 04:13:26 2016 UTC revision 6079 by caltinay, Mon Mar 21 12:22:38 2016 UTC
# Line 14  Line 14
14  *  *
15  *****************************************************************************/  *****************************************************************************/
16
/* NodeMapping provides a mapping from the local nodes typically to the degrees of freedom, */
/*    the reduced degrees of freedom or the reduced node set */

17  #ifndef __DUDLEY_NODEMAPPING_H__  #ifndef __DUDLEY_NODEMAPPING_H__
18  #define __DUDLEY_NODEMAPPING_H__  #define __DUDLEY_NODEMAPPING_H__
19
20  #include "Dudley.h"  #include "Util.h"
21
22  namespace dudley {  namespace dudley {
23
24  struct Dudley_NodeMapping {  /// NodeMapping provides a mapping from the local nodes typically to the
25      dim_t numNodes;             /* number of FEM nodes */  /// degrees of freedom, the reduced degrees of freedom or the reduced node set
26      index_t *target;            /* target[i] defines the target if FEM  node i =0,...,numNodes */  struct NodeMapping
27      index_t unused;             /* target[i]=unused defines that no target is defined for FEM  node i */  {
28      dim_t numTargets;           /* number of targets */      NodeMapping() : numNodes(0), target(NULL), numTargets(0), map(NULL) {}
29      index_t *map;               /* maps the target nodes back to the FEM nodes: target[map[i]]=i */
30      dim_t reference_counter;      /// resets both map and target
31  };      void clear()
32  typedef struct Dudley_NodeMapping Dudley_NodeMapping;      {
33            delete[] map;
34            delete[] target;
35            target = NULL;
36            map = NULL;
37            numNodes = 0;
38            numTargets = 0;
39        }
40
41        /// initializes a node mapping. The target array is copied and a reverse
42        /// map created.
43        /// theTarget[i]=unused means that no target is defined for FEM node i.
44        void assign(const index_t* theTarget, dim_t nNodes, index_t unused)
45        {
46            clear();
47
48            if (nNodes == 0)
49                return;
50
51            numNodes = nNodes;
52
53            std::pair<index_t,index_t> range(
54                util::getFlaggedMinMaxInt(numNodes, theTarget, unused));
55            if (range.first < 0) {
56                throw escript::ValueError("NodeMapping: target has negative entry.");
57            }
58            numTargets = range.first<=range.second ? range.second+1 : 0;
59
60            target = new index_t[numNodes];
61            map = new index_t[numTargets];
62
63            bool err = false;
64    #pragma omp parallel
65            {
66    #pragma omp for
67                for (index_t i=0; i<numNodes; ++i) {
68                    target[i] = theTarget[i];
69                    if (target[i] != unused)
70                        map[target[i]] = i;
71                }
72                // sanity check
73    #pragma omp for
74                for (index_t i=0; i<numTargets; ++i) {
75                    if (map[i] == -1) {
76    #pragma omp critical
77                        err = true;
78                    }
79                }
80            }
81            if (err)
82                throw escript::ValueError("NodeMapping: target does not define a continuous labeling.");
83        }
84
85        /// returns the number of target nodes (number of items in the map array)
86        inline dim_t getNumTargets() const { return numTargets; }
87
88        /// size of `target` (number of FEM nodes)
89        dim_t numNodes;
90
91        /// target[i] defines the target of FEM node i=0,...,numNodes
92        index_t* target;
93
94  Dudley_NodeMapping *Dudley_NodeMapping_alloc(dim_t numNodes, index_t *target, index_t unused);      /// size of `map` (number of target nodes, e.g. DOF, reduced DOF, etc.)
95  void Dudley_NodeMapping_free(Dudley_NodeMapping *);      dim_t numTargets;
96  Dudley_NodeMapping *Dudley_NodeMapping_getReference(Dudley_NodeMapping *in);
97        /// maps the target nodes back to the FEM nodes: target[map[i]]=i
98        index_t* map;
99    };
100
101  } // namespace dudley  } // namespace dudley
102

Legend:
 Removed from v.6078 changed lines Added in v.6079