/[escript]/trunk/finley/src/Mesh_prepareNodes.c
ViewVC logotype

Diff of /trunk/finley/src/Mesh_prepareNodes.c

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

revision 750 by elspeth, Wed Mar 22 02:46:56 2006 UTC revision 751 by bcumming, Mon Jun 26 01:46:34 2006 UTC
# Line 34  Line 34 
34  void Finley_Mesh_prepareNodes(Finley_Mesh* in) {  void Finley_Mesh_prepareNodes(Finley_Mesh* in) {
35    dim_t n,len;    dim_t n,len;
36    index_t id,max_id,min_id,*maskReducedDOF=NULL,*maskDOF=NULL,*reducedNodesMask=NULL,*index=NULL;    index_t id,max_id,min_id,*maskReducedDOF=NULL,*maskDOF=NULL,*reducedNodesMask=NULL,*index=NULL;
37    #ifdef PASO_MPI
38      index_t *indexLocal=NULL, *maskReducedDOFLocation=NULL;
39      index_t thisDom = in->MPIInfo->rank, i;
40      dim_t bufferLength=0, numReducedLocal, numReducedInternal, numReducedBoundary, numReducedExternal, numForward, numBackward, totalDOF;
41    
42    #endif
43    
44    /* TODO */
45    /* this is ok for the automatically generated rectangular meshes, but for arbitrary meshes it
46       may be neccesary to make sure that
47          -  the [internal][boundary][external] ordering is respected
48          -  the distribution data in Nodes->degreeOfFreedomDistribution reflects any changes in the
49             DOF ordering. */
50    
51    max_id=Finley_Util_getMaxInt(1,in->Nodes->numNodes,in->Nodes->degreeOfFreedom);    max_id=Finley_Util_getMaxInt(1,in->Nodes->numNodes,in->Nodes->degreeOfFreedom);
52    min_id=Finley_Util_getMinInt(1,in->Nodes->numNodes,in->Nodes->degreeOfFreedom);    min_id=Finley_Util_getMinInt(1,in->Nodes->numNodes,in->Nodes->degreeOfFreedom);
# Line 43  void Finley_Mesh_prepareNodes(Finley_Mes Line 56  void Finley_Mesh_prepareNodes(Finley_Mes
56    maskDOF=TMPMEMALLOC(len,index_t);    maskDOF=TMPMEMALLOC(len,index_t);
57    maskReducedDOF=TMPMEMALLOC(len,index_t);    maskReducedDOF=TMPMEMALLOC(len,index_t);
58    index=TMPMEMALLOC(MAX(in->Nodes->numNodes,len),index_t);    index=TMPMEMALLOC(MAX(in->Nodes->numNodes,len),index_t);
   
59    if  (! (Finley_checkPtr(maskDOF) || Finley_checkPtr(maskReducedDOF)    if  (! (Finley_checkPtr(maskDOF) || Finley_checkPtr(maskReducedDOF)
60                                          || Finley_checkPtr(reducedNodesMask) || Finley_checkPtr(index) ) ) {                                          || Finley_checkPtr(reducedNodesMask) || Finley_checkPtr(index) ) ) {
61        /* initialize everything */        /* initialize everything */
# Line 73  void Finley_Mesh_prepareNodes(Finley_Mes Line 85  void Finley_Mesh_prepareNodes(Finley_Mes
85        }        }
86        /* get a list of all nodes used in the reduced mesh and convert into in->Nodes->toReduced: */        /* get a list of all nodes used in the reduced mesh and convert into in->Nodes->toReduced: */
87        in->Nodes->reducedNumNodes=Finley_Util_packMask(in->Nodes->numNodes,reducedNodesMask,index);        in->Nodes->reducedNumNodes=Finley_Util_packMask(in->Nodes->numNodes,reducedNodesMask,index);
88    
89        #pragma omp parallel for private(n) schedule(static)        #pragma omp parallel for private(n) schedule(static)
90        for (n=0;n<in->Nodes->reducedNumNodes;n++) in->Nodes->toReduced[index[n]]=n;        for (n=0;n<in->Nodes->reducedNumNodes;n++)
91            in->Nodes->toReduced[index[n]]=n;
92    
93        /* get a list of the DOFs in the reduced mesh and convert it into reducedDegreeOfFreedom */        /* get a list of the DOFs in the reduced mesh and convert it into reducedDegreeOfFreedom */
94        in->Nodes->reducedNumDegreesOfFreedom=Finley_Util_packMask(len,maskReducedDOF,index);        in->Nodes->reducedNumDegreesOfFreedom=Finley_Util_packMask(len,maskReducedDOF,index);
95        #pragma omp parallel for private(n) schedule(static)        #pragma omp parallel for private(n) schedule(static)
96        for (n=0;n<in->Nodes->reducedNumDegreesOfFreedom;n++) maskReducedDOF[index[n]]=n;        for (n=0;n<in->Nodes->reducedNumDegreesOfFreedom;n++)
97            maskReducedDOF[index[n]]=n;
98    
99        /* get a list of the DOFs and convert it into degreeOfFreedom */        /* get a list of the DOFs and convert it into degreeOfFreedom */
100        in->Nodes->numDegreesOfFreedom=Finley_Util_packMask(len,maskDOF,index);        in->Nodes->numDegreesOfFreedom=Finley_Util_packMask(len,maskDOF,index);
101    
102        #pragma omp parallel        #pragma omp parallel
103        {        {
104            #pragma omp for private(n) schedule(static)            #pragma omp for private(n) schedule(static)
105            for (n=0;n<in->Nodes->numDegreesOfFreedom;n++) maskDOF[index[n]]=n;            for (n=0;n<in->Nodes->numDegreesOfFreedom;n++)
106                maskDOF[index[n]]=n;
107            #pragma omp for private(n,id) schedule(static)            #pragma omp for private(n,id) schedule(static)
108            for (n=0;n<in->Nodes->numNodes;n++) {            for (n=0;n<in->Nodes->numNodes;n++) {
109                  id=in->Nodes->degreeOfFreedom[n]-min_id;                  id=in->Nodes->degreeOfFreedom[n]-min_id;
# Line 93  void Finley_Mesh_prepareNodes(Finley_Mes Line 112  void Finley_Mesh_prepareNodes(Finley_Mes
112            }            }
113        }        }
114     }     }
115     TMPMEMFREE(reducedNodesMask);  
116     TMPMEMFREE(maskDOF);  #ifdef PASO_MPI
117     TMPMEMFREE(maskReducedDOF);  
118     TMPMEMFREE(index);    /***********************************************************
119        update the distribution data
120       ***********************************************************/
121    
122      totalDOF = in->Nodes->degreeOfFreedomDistribution->numLocal + in->Nodes->degreeOfFreedomDistribution->numExternal;
123    
124      /* update the forward and backward indices for each neighbour */
125      for( n=0; n<in->Nodes->degreeOfFreedomDistribution->numNeighbours; n++ ){
126        for( i=0; i<in->Nodes->degreeOfFreedomDistribution->edges[n]->numForward; i++ )
127          in->Nodes->degreeOfFreedomDistribution->edges[n]->indexForward[i] = maskDOF[in->Nodes->degreeOfFreedomDistribution->edges[n]->indexForward[i]];
128        for( i=0; i<in->Nodes->degreeOfFreedomDistribution->edges[n]->numBackward; i++ )
129          in->Nodes->degreeOfFreedomDistribution->edges[n]->indexBackward[i] = maskDOF[in->Nodes->degreeOfFreedomDistribution->edges[n]->indexBackward[i]];
130      }
131    
132      /* update the global indices for the external DOF on this subdomain */
133      Finley_NodeDistribution_calculateIndexExternal( in->Nodes->degreeOfFreedomDistribution, in->Nodes->CommBuffer );
134    
135      /***********************************************************
136        compile distribution data for the reduced degrees of freedom
137       ***********************************************************/
138      
139      /* determnine the number of internal, boundary and external DOF in the reduced distribution */
140      totalDOF = in->Nodes->degreeOfFreedomDistribution->numLocal + in->Nodes->degreeOfFreedomDistribution->numExternal;
141    
142      maskReducedDOFLocation = MEMALLOC( in->Nodes->numDegreesOfFreedom, index_t );
143      for( n=0; n<in->Nodes->numDegreesOfFreedom; n++ )
144        maskReducedDOFLocation[n] = -1;
145      Finley_Mesh_markOrderedDegreesOfFreedomLocation( maskReducedDOFLocation, 0, in, TRUE);
146    
147      numReducedInternal = numReducedBoundary = numReducedLocal = numReducedExternal = 0;
148      for( n=0; n<in->Nodes->degreeOfFreedomDistribution->numLocal + in->Nodes->degreeOfFreedomDistribution->numExternal; n++ ) {
149        switch( maskReducedDOFLocation[n] ) {
150          case 1 :
151            numReducedInternal++;
152            break;
153          case 2 :
154            numReducedBoundary++;
155            break;
156          case 3 :        
157            numReducedExternal++;
158            break;
159          }
160      }
161      numReducedLocal = numReducedInternal + numReducedBoundary;
162      MEMFREE( maskReducedDOFLocation );
163    
164      if( Finley_MPI_noError( in->MPIInfo ) )  
165      {
166        Finley_NodeDistribution_allocTable( in->Nodes->reducedDegreeOfFreedomDistribution, numReducedLocal, numReducedExternal, 0 );
167        in->Nodes->reducedDegreeOfFreedomDistribution->numInternal = numReducedInternal;  
168        in->Nodes->reducedDegreeOfFreedomDistribution->numBoundary = numReducedBoundary;
169    
170        /* determine the forward and backward distributions for each neighbour */
171        bufferLength = 0;  
172        for( n=0; n<in->Nodes->degreeOfFreedomDistribution->numNeighbours; n++ ){
173          if( in->Nodes->degreeOfFreedomDistribution->edges[n]->numForward>bufferLength )
174            bufferLength = in->Nodes->degreeOfFreedomDistribution->edges[n]->numForward;
175          else if( in->Nodes->degreeOfFreedomDistribution->edges[n]->numBackward>bufferLength )    
176            bufferLength = in->Nodes->degreeOfFreedomDistribution->edges[n]->numBackward;
177        }
178        indexLocal = TMPMEMALLOC( bufferLength, index_t );
179    
180        for( n=0; n<in->Nodes->degreeOfFreedomDistribution->numNeighbours; n++ ){
181          numForward = numBackward = 0;
182          for( i=0; i<in->Nodes->degreeOfFreedomDistribution->edges[n]->numForward; i++  )
183            if( maskReducedDOF[in->Nodes->degreeOfFreedomDistribution->edges[n]->indexForward[i]]>=0 )
184              indexLocal[numForward++] = maskReducedDOF[in->Nodes->degreeOfFreedomDistribution->edges[n]->indexForward[i]];      
185          Finley_NodeDistribution_addForward(  in->Nodes->reducedDegreeOfFreedomDistribution, in->Nodes->degreeOfFreedomDistribution->neighbours[n], numForward,  indexLocal  );
186          for( i=0; i<in->Nodes->degreeOfFreedomDistribution->edges[n]->numBackward; i++  )
187            if( maskReducedDOF[in->Nodes->degreeOfFreedomDistribution->edges[n]->indexBackward[i]]>=0 )
188              indexLocal[numBackward++] = maskReducedDOF[in->Nodes->degreeOfFreedomDistribution->edges[n]->indexBackward[i]];
189          Finley_NodeDistribution_addBackward( in->Nodes->reducedDegreeOfFreedomDistribution, in->Nodes->degreeOfFreedomDistribution->neighbours[n], numBackward, indexLocal  );
190        }
191    
192        /* update the global indices for the reduced external DOF on this subdomain */
193    
194        Finley_NodeDistribution_calculateIndexExternal( in->Nodes->degreeOfFreedomDistribution, in->Nodes->CommBuffer );
195        Finley_NodeDistribution_formCommBuffer( in->Nodes->reducedDegreeOfFreedomDistribution, in->Nodes->reducedCommBuffer );
196        Finley_NodeDistribution_calculateIndexExternal( in->Nodes->reducedDegreeOfFreedomDistribution, in->Nodes->reducedCommBuffer );
197      }
198    
199      TMPMEMFREE( indexLocal );
200    #endif
201      TMPMEMFREE(reducedNodesMask);
202      TMPMEMFREE(maskDOF);
203      TMPMEMFREE(maskReducedDOF);
204      TMPMEMFREE(index);
205  }  }
206    
207  /*  /*
# Line 122  void Finley_Mesh_prepareNodes(Finley_Mes Line 227  void Finley_Mesh_prepareNodes(Finley_Mes
227  *  *
228  */  */
229    
230    

Legend:
Removed from v.750  
changed lines
  Added in v.751

  ViewVC Help
Powered by ViewVC 1.1.26