/[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 6008 by caltinay, Mon Feb 22 06:59:27 2016 UTC revision 6009 by caltinay, Wed Mar 2 04:13:26 2016 UTC
# Line 14  Line 14 
14  *  *
15  *****************************************************************************/  *****************************************************************************/
16    
17  /************************************************************************************/  /****************************************************************************/
   
18  /*   Dudley: Mesh */  /*   Dudley: Mesh */
   
19  /*   at input the element nodes refers to the numbering defined the global Id assigned to the nodes in the */  /*   at input the element nodes refers to the numbering defined the global Id assigned to the nodes in the */
20  /*   NodeFile. It is also not ensured that all nodes referred to by an element are actually available */  /*   NodeFile. It is also not ensured that all nodes referred to by an element are actually available */
21  /*   on the process.  At the output, a local node labelling is used and all nodes are available */  /*   on the process.  At the output, a local node labelling is used and all nodes are available */
22  /*   In particular the numbering of the element nodes is between 0 and in->NodeFile->numNodes */  /*   In particular the numbering of the element nodes is between 0 and in->NodeFile->numNodes */
23  /*   The function does not create a distribution of the degrees of freedom. */  /*   The function does not create a distribution of the degrees of freedom. */
24    
25  /************************************************************************************/  /****************************************************************************/
   
 #define ESNEEDPYTHON  
 #include "esysUtils/first.h"  
26    
27  #include "Mesh.h"  #include "Mesh.h"
28  #include "Util.h"  #include "Util.h"
29    
30  /************************************************************************************/  namespace dudley {
31    
32  void Dudley_Mesh_resolveNodeIds(Dudley_Mesh * in)  void Dudley_Mesh_resolveNodeIds(Dudley_Mesh* in)
33  {  {
   
34      index_t min_id, max_id, min_id2, max_id2, global_min_id, global_max_id,      index_t min_id, max_id, min_id2, max_id2, global_min_id, global_max_id,
35      *globalToNewLocalNodeLabels = NULL, *newLocalToGlobalNodeLabels = NULL;          *globalToNewLocalNodeLabels = NULL, *newLocalToGlobalNodeLabels = NULL;
36      dim_t len, n, newNumNodes, numDim;      dim_t len, n, newNumNodes, numDim;
37      Dudley_NodeFile *newNodeFile = NULL;      Dudley_NodeFile *newNodeFile = NULL;
 #ifdef ESYS_MPI  
     index_t id_range[2], global_id_range[2];  
 #endif  
38      numDim = Dudley_Mesh_getDim(in);      numDim = Dudley_Mesh_getDim(in);
39      /*  find the minimum and maximum id used by elements: */      /*  find the minimum and maximum id used by elements: */
40      min_id = escript::DataTypes::index_t_max();      min_id = escript::DataTypes::index_t_max();
41      max_id = -escript::DataTypes::index_t_max();      max_id = -escript::DataTypes::index_t_max();
42      Dudley_ElementFile_setNodeRange(&min_id2, &max_id2, in->Elements);      Dudley_ElementFile_setNodeRange(&min_id2, &max_id2, in->Elements);
43      max_id = MAX(max_id, max_id2);      max_id = std::max(max_id, max_id2);
44      min_id = MIN(min_id, min_id2);      min_id = std::min(min_id, min_id2);
45      Dudley_ElementFile_setNodeRange(&min_id2, &max_id2, in->FaceElements);      Dudley_ElementFile_setNodeRange(&min_id2, &max_id2, in->FaceElements);
46      max_id = MAX(max_id, max_id2);      max_id = std::max(max_id, max_id2);
47      min_id = MIN(min_id, min_id2);      min_id = std::min(min_id, min_id2);
48      Dudley_ElementFile_setNodeRange(&min_id2, &max_id2, in->Points);      Dudley_ElementFile_setNodeRange(&min_id2, &max_id2, in->Points);
49      max_id = MAX(max_id, max_id2);      max_id = std::max(max_id, max_id2);
50      min_id = MIN(min_id, min_id2);      min_id = std::min(min_id, min_id2);
51  #ifdef ESYS_MPI  #ifdef ESYS_MPI
52        index_t id_range[2], global_id_range[2];
53      id_range[0] = -min_id;      id_range[0] = -min_id;
54      id_range[1] = max_id;      id_range[1] = max_id;
55      MPI_Allreduce(id_range, global_id_range, 2, MPI_INT, MPI_MAX, in->MPIInfo->comm);      MPI_Allreduce(id_range, global_id_range, 2, MPI_INT, MPI_MAX, in->MPIInfo->comm);
# Line 76  void Dudley_Mesh_resolveNodeIds(Dudley_M Line 68  void Dudley_Mesh_resolveNodeIds(Dudley_M
68  #endif  #endif
69      if (min_id > max_id)      if (min_id > max_id)
70      {      {
71      max_id = -1;          max_id = -1;
72      min_id = 0;          min_id = 0;
73      }      }
74    
75      /* allocate mappings for new local node labelling to global node labelling (newLocalToGlobalNodeLabels)      /* allocate mappings for new local node labelling to global node labelling (newLocalToGlobalNodeLabels)
76         and global node labelling to the new local node labelling (globalToNewLocalNodeLabels[i-min_id] is the         and global node labelling to the new local node labelling (globalToNewLocalNodeLabels[i-min_id] is the
77         new local id of global node i) */         new local id of global node i) */
78      len = (max_id >= min_id) ? max_id - min_id + 1 : 0;      len = (max_id >= min_id) ? max_id - min_id + 1 : 0;
79      globalToNewLocalNodeLabels = new  index_t[len]; /* local mask for used nodes */      globalToNewLocalNodeLabels = new index_t[len]; /* local mask for used nodes */
80      newLocalToGlobalNodeLabels = new  index_t[len];      newLocalToGlobalNodeLabels = new index_t[len];
     if (!((Dudley_checkPtr(globalToNewLocalNodeLabels) && Dudley_checkPtr(newLocalToGlobalNodeLabels))))  
     {  
81    
82  #pragma omp parallel  #pragma omp parallel
83      {      {
84  #pragma omp for private(n) schedule(static)  #pragma omp for private(n) schedule(static)
85          for (n = 0; n < len; n++)          for (n = 0; n < len; n++)
86          newLocalToGlobalNodeLabels[n] = -1;              newLocalToGlobalNodeLabels[n] = -1;
87  #pragma omp for private(n) schedule(static)  #pragma omp for private(n) schedule(static)
88          for (n = 0; n < len; n++)          for (n = 0; n < len; n++)
89          globalToNewLocalNodeLabels[n] = -1;              globalToNewLocalNodeLabels[n] = -1;
90      }      }
91    
92      /*  mark the nodes referred by elements in globalToNewLocalNodeLabels which is currently used as a mask: */      /*  mark the nodes referred by elements in globalToNewLocalNodeLabels which is currently used as a mask: */
93      Dudley_Mesh_markNodes(globalToNewLocalNodeLabels, min_id, in, FALSE);      Dudley_Mesh_markNodes(globalToNewLocalNodeLabels, min_id, in, false);
94    
95      /* create a local labelling newLocalToGlobalNodeLabels of the local nodes by packing the mask globalToNewLocalNodeLabels */      /* create a local labelling newLocalToGlobalNodeLabels of the local nodes by packing the mask globalToNewLocalNodeLabels */
96    
97      newNumNodes = Dudley_Util_packMask(len, globalToNewLocalNodeLabels, newLocalToGlobalNodeLabels);      newNumNodes = Dudley_Util_packMask(len, globalToNewLocalNodeLabels, newLocalToGlobalNodeLabels);
98    
99      /* invert the new labelling and shift the index newLocalToGlobalNodeLabels to global node ids */      /* invert the new labelling and shift the index newLocalToGlobalNodeLabels to global node ids */
100  #pragma omp parallel for private(n) schedule(static)  #pragma omp parallel for private(n) schedule(static)
101      for (n = 0; n < newNumNodes; n++)      for (n = 0; n < newNumNodes; n++)
102      {      {
103  #ifdef BOUNDS_CHECK  #ifdef BOUNDS_CHECK
104          if (n >= len || n < 0)          if (n >= len || n < 0)
105          {          {
106          printf("BOUNDS_CHECK %s %d n=%d\n", __FILE__, __LINE__, n);              printf("BOUNDS_CHECK %s %d n=%d\n", __FILE__, __LINE__, n);
107          exit(1);              exit(1);
108          }          }
109          if (newLocalToGlobalNodeLabels[n] >= len || newLocalToGlobalNodeLabels[n] < 0)          if (newLocalToGlobalNodeLabels[n] >= len || newLocalToGlobalNodeLabels[n] < 0)
110          {          {
111          printf("BOUNDS_CHECK %s %d n=%d\n", __FILE__, __LINE__, n);              printf("BOUNDS_CHECK %s %d n=%d\n", __FILE__, __LINE__, n);
112          exit(1);              exit(1);
113          }          }
114  #endif  #endif
115          globalToNewLocalNodeLabels[newLocalToGlobalNodeLabels[n]] = n;          globalToNewLocalNodeLabels[newLocalToGlobalNodeLabels[n]] = n;
116          newLocalToGlobalNodeLabels[n] += min_id;          newLocalToGlobalNodeLabels[n] += min_id;
     }  
     /* create a new table */  
     newNodeFile = Dudley_NodeFile_alloc(numDim, in->MPIInfo);  
     if (Dudley_noError())  
     {  
         Dudley_NodeFile_allocTable(newNodeFile, newNumNodes);  
     }  
     if (Dudley_noError())  
     {  
         Dudley_NodeFile_gather_global(newLocalToGlobalNodeLabels, in->Nodes, newNodeFile);  
     }  
     if (Dudley_noError())  
     {  
         Dudley_NodeFile_free(in->Nodes);  
         in->Nodes = newNodeFile;  
         /*  relabel nodes of the elements: */  
         Dudley_Mesh_relableElementNodes(globalToNewLocalNodeLabels, min_id, in);  
     }  
117      }      }
118        /* create a new table */
119        newNodeFile = Dudley_NodeFile_alloc(numDim, in->MPIInfo);
120        Dudley_NodeFile_allocTable(newNodeFile, newNumNodes);
121        Dudley_NodeFile_gather_global(newLocalToGlobalNodeLabels, in->Nodes, newNodeFile);
122        Dudley_NodeFile_free(in->Nodes);
123        in->Nodes = newNodeFile;
124        /*  relabel nodes of the elements: */
125        Dudley_Mesh_relableElementNodes(globalToNewLocalNodeLabels, min_id, in);
126      delete[] globalToNewLocalNodeLabels;      delete[] globalToNewLocalNodeLabels;
127      delete[] newLocalToGlobalNodeLabels;      delete[] newLocalToGlobalNodeLabels;
     if (!Dudley_noError())  
     {  
     Dudley_NodeFile_free(newNodeFile);  
     }  
128  }  }
129    
130    } // namespace dudley
131    

Legend:
Removed from v.6008  
changed lines
  Added in v.6009

  ViewVC Help
Powered by ViewVC 1.1.26