/[escript]/branches/trilinos_from_5897/dudley/src/Mesh_resolveNodeIds.cpp
ViewVC logotype

Diff of /branches/trilinos_from_5897/dudley/src/Mesh_resolveNodeIds.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

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    
 /****************************************************************************/  
 /*   Dudley: Mesh */  
 /*   at input the element nodes refers to the numbering defined the global Id assigned to the nodes in the */  
 /*   NodeFile. It is also not ensured that all nodes referred to by an element are actually available */  
 /*   on the process.  At the output, a local node labelling is used and all nodes are available */  
 /*   In particular the numbering of the element nodes is between 0 and in->NodeFile->numNodes */  
 /*   The function does not create a distribution of the degrees of freedom. */  
   
 /****************************************************************************/  
   
17  #include "Mesh.h"  #include "Mesh.h"
18  #include "Util.h"  #include "Util.h"
19    
20  namespace dudley {  namespace dudley {
21    
22  void Dudley_Mesh_resolveNodeIds(Dudley_Mesh* in)  void Mesh::resolveNodeIds()
23  {  {
24      index_t min_id, max_id, min_id2, max_id2, global_min_id, global_max_id,      // find the minimum and maximum id used by elements
25          *globalToNewLocalNodeLabels = NULL, *newLocalToGlobalNodeLabels = NULL;      index_t min_id = escript::DataTypes::index_t_max();
26      dim_t len, n, newNumNodes, numDim;      index_t max_id = -escript::DataTypes::index_t_max();
27      Dudley_NodeFile *newNodeFile = NULL;      std::pair<index_t,index_t> range(Elements->getNodeRange());
28      numDim = Dudley_Mesh_getDim(in);      max_id = std::max(max_id, range.second);
29      /*  find the minimum and maximum id used by elements: */      min_id = std::min(min_id, range.first);
30      min_id = escript::DataTypes::index_t_max();      range = FaceElements->getNodeRange();
31      max_id = -escript::DataTypes::index_t_max();      max_id = std::max(max_id, range.second);
32      Dudley_ElementFile_setNodeRange(&min_id2, &max_id2, in->Elements);      min_id = std::min(min_id, range.first);
33      max_id = std::max(max_id, max_id2);      range = Points->getNodeRange();
34      min_id = std::min(min_id, min_id2);      max_id = std::max(max_id, range.second);
35      Dudley_ElementFile_setNodeRange(&min_id2, &max_id2, in->FaceElements);      min_id = std::min(min_id, range.first);
36      max_id = std::max(max_id, max_id2);  #ifdef Dudley_TRACE
37      min_id = std::min(min_id, min_id2);      index_t global_min_id, global_max_id;
     Dudley_ElementFile_setNodeRange(&min_id2, &max_id2, in->Points);  
     max_id = std::max(max_id, max_id2);  
     min_id = std::min(min_id, min_id2);  
38  #ifdef ESYS_MPI  #ifdef ESYS_MPI
39      index_t id_range[2], global_id_range[2];      index_t id_range[2], global_id_range[2];
40      id_range[0] = -min_id;      id_range[0] = -min_id;
41      id_range[1] = max_id;      id_range[1] = max_id;
42      MPI_Allreduce(id_range, global_id_range, 2, MPI_INT, MPI_MAX, in->MPIInfo->comm);      MPI_Allreduce(id_range, global_id_range, 2, MPI_DIM_T, MPI_MAX, MPIInfo->comm);
43      global_min_id = -global_id_range[0];      global_min_id = -global_id_range[0];
44      global_max_id = global_id_range[1];      global_max_id = global_id_range[1];
45  #else  #else
46      global_min_id = min_id;      global_min_id = min_id;
47      global_max_id = max_id;      global_max_id = max_id;
48  #endif  #endif
 #ifdef Dudley_TRACE  
49      printf("Node id range used by elements is %d:%d\n", global_min_id, global_max_id);      printf("Node id range used by elements is %d:%d\n", global_min_id, global_max_id);
 #else  
     /* avoid unused var warning if Dudley_TRACE is not defined */  
     (void)global_min_id;  
     (void)global_max_id;  
50  #endif  #endif
51      if (min_id > max_id)      if (min_id > max_id) {
     {  
52          max_id = -1;          max_id = -1;
53          min_id = 0;          min_id = 0;
54      }      }
55    
56      /* allocate mappings for new local node labelling to global node labelling (newLocalToGlobalNodeLabels)      // allocate mappings for new local node labeling to global node labeling
57         and global node labelling to the new local node labelling (globalToNewLocalNodeLabels[i-min_id] is the      // (newLocalToGlobalNodeLabels) and global node labeling to the new local
58         new local id of global node i) */      // node labeling (globalToNewLocalNodeLabels[i-min_id] is the new local id
59      len = (max_id >= min_id) ? max_id - min_id + 1 : 0;      // of global node i)
60      globalToNewLocalNodeLabels = new index_t[len]; /* local mask for used nodes */      index_t len = (max_id >= min_id) ? max_id - min_id + 1 : 0;
61      newLocalToGlobalNodeLabels = new index_t[len];  
62        // mark the nodes referred by elements in usedMask
63  #pragma omp parallel      std::vector<short> usedMask(len, -1);
64      {      markNodes(usedMask, min_id);
65  #pragma omp for private(n) schedule(static)  
66          for (n = 0; n < len; n++)      // create a local labeling newLocalToGlobalNodeLabels of the local nodes
67              newLocalToGlobalNodeLabels[n] = -1;      // by packing the mask usedMask
68  #pragma omp for private(n) schedule(static)      std::vector<index_t> newLocalToGlobalNodeLabels =  util::packMask(usedMask);
69          for (n = 0; n < len; n++)      const dim_t newNumNodes = newLocalToGlobalNodeLabels.size();
70              globalToNewLocalNodeLabels[n] = -1;      usedMask.clear();
71      }  
72        // invert the new labeling and shift the index newLocalToGlobalNodeLabels
73      /*  mark the nodes referred by elements in globalToNewLocalNodeLabels which is currently used as a mask: */      // to global node IDs
74      Dudley_Mesh_markNodes(globalToNewLocalNodeLabels, min_id, in, false);      index_t* globalToNewLocalNodeLabels = new index_t[len];
   
     /* create a local labelling newLocalToGlobalNodeLabels of the local nodes by packing the mask globalToNewLocalNodeLabels */  
   
     newNumNodes = Dudley_Util_packMask(len, globalToNewLocalNodeLabels, newLocalToGlobalNodeLabels);  
75    
76      /* invert the new labelling and shift the index newLocalToGlobalNodeLabels to global node ids */  #pragma omp parallel for
77  #pragma omp parallel for private(n) schedule(static)      for (index_t n = 0; n < newNumNodes; n++) {
     for (n = 0; n < newNumNodes; n++)  
     {  
78  #ifdef BOUNDS_CHECK  #ifdef BOUNDS_CHECK
79          if (n >= len || n < 0)          if (newLocalToGlobalNodeLabels[n] >= len || newLocalToGlobalNodeLabels[n] < 0) {
         {  
             printf("BOUNDS_CHECK %s %d n=%d\n", __FILE__, __LINE__, n);  
             exit(1);  
         }  
         if (newLocalToGlobalNodeLabels[n] >= len || newLocalToGlobalNodeLabels[n] < 0)  
         {  
80              printf("BOUNDS_CHECK %s %d n=%d\n", __FILE__, __LINE__, n);              printf("BOUNDS_CHECK %s %d n=%d\n", __FILE__, __LINE__, n);
81              exit(1);              exit(1);
82          }          }
# Line 115  void Dudley_Mesh_resolveNodeIds(Dudley_M Line 84  void Dudley_Mesh_resolveNodeIds(Dudley_M
84          globalToNewLocalNodeLabels[newLocalToGlobalNodeLabels[n]] = n;          globalToNewLocalNodeLabels[newLocalToGlobalNodeLabels[n]] = n;
85          newLocalToGlobalNodeLabels[n] += min_id;          newLocalToGlobalNodeLabels[n] += min_id;
86      }      }
87      /* create a new table */      // create a new node file
88      newNodeFile = Dudley_NodeFile_alloc(numDim, in->MPIInfo);      NodeFile* newNodeFile = new NodeFile(getDim(), MPIInfo);
89      Dudley_NodeFile_allocTable(newNodeFile, newNumNodes);      newNodeFile->allocTable(newNumNodes);
90      Dudley_NodeFile_gather_global(newLocalToGlobalNodeLabels, in->Nodes, newNodeFile);      if (len)
91      Dudley_NodeFile_free(in->Nodes);          newNodeFile->gather_global(&newLocalToGlobalNodeLabels[0], Nodes);
92      in->Nodes = newNodeFile;      else
93      /*  relabel nodes of the elements: */          newNodeFile->gather_global(NULL, Nodes);
94      Dudley_Mesh_relableElementNodes(globalToNewLocalNodeLabels, min_id, in);  
95        delete Nodes;
96        Nodes = newNodeFile;
97        // relabel nodes of the elements
98        relabelElementNodes(globalToNewLocalNodeLabels, min_id);
99      delete[] globalToNewLocalNodeLabels;      delete[] globalToNewLocalNodeLabels;
     delete[] newLocalToGlobalNodeLabels;  
100  }  }
101    
102  } // namespace dudley  } // namespace dudley

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

  ViewVC Help
Powered by ViewVC 1.1.26