/[escript]/branches/domexper/dudley/src/Mesh_resolveNodeIds.c
ViewVC logotype

Diff of /branches/domexper/dudley/src/Mesh_resolveNodeIds.c

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

trunk/finley/src/finleyC/Mesh_resolveNodeIds.c revision 155 by jgs, Wed Nov 9 02:02:19 2005 UTC branches/domexper/dudley/src/Mesh_resolveNodeIds.c revision 3080 by jfenwick, Tue Aug 3 04:28:03 2010 UTC
# Line 1  Line 1 
 /*  
  ******************************************************************************  
  *                                                                            *  
  *       COPYRIGHT  ACcESS 2003,2004,2005 -  All Rights Reserved              *  
  *                                                                            *  
  * This software is the property of ACcESS. No part of this code              *  
  * may be copied in any form or by any means without the expressed written    *  
  * consent of ACcESS.  Copying, use or modification of this software          *  
  * by any unauthorised person is illegal unless that person has a software    *  
  * license agreement with ACcESS.                                             *  
  *                                                                            *  
  ******************************************************************************  
 */  
1    
2  /**************************************************************/  /*******************************************************
3    *
4  /*   Finley: Mesh */  * Copyright (c) 2003-2010 by University of Queensland
5    * Earth Systems Science Computational Center (ESSCC)
6    * http://www.uq.edu.au/esscc
7    *
8    * Primary Business: Queensland, Australia
9    * Licensed under the Open Software License version 3.0
10    * http://www.opensource.org/licenses/osl-3.0.php
11    *
12    *******************************************************/
13    
 /*   at input the element nodes refers to the numbering defined the Id assigned to the nodes in the */  
 /*   NodeFile. At the output, the numbering of the element nodes is between 0 and numNodes */  
 /*   degreesOfFreedom are not neccessarily referening to a dense numbering */  
14    
15  /**************************************************************/  /**************************************************************/
16    
17  /*   Author: gross@access.edu.au */  /*   Finley: Mesh */
18  /*   Version: $Id$ */  
19    /*   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 refered by an element is actually available */
21    /*   on the process.  At the output, a local node labeling is used and all nodes are available */
22    /*   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. */
24    
25  /**************************************************************/  /**************************************************************/
26    
# Line 33  Line 30 
30  /**************************************************************/  /**************************************************************/
31    
32  void  Finley_Mesh_resolveNodeIds(Finley_Mesh* in) {  void  Finley_Mesh_resolveNodeIds(Finley_Mesh* in) {
33    char error_msg[LenErrorMsg_MAX];  
34    dim_t k,len,numDim,newNumNodes,n;    index_t min_id, max_id,  min_id2, max_id2, global_min_id, global_max_id,
35    index_t min_id,max_id,min_id2,max_id2,*maskNodes=NULL,*maskElements=NULL,*index=NULL;            *globalToNewLocalNodeLabels=NULL, *newLocalToGlobalNodeLabels=NULL;
36      dim_t len, n, newNumNodes, numDim;
37    Finley_NodeFile *newNodeFile=NULL;    Finley_NodeFile *newNodeFile=NULL;
38    Finley_resetError();    #ifdef PASO_MPI
39      index_t id_range[2], global_id_range[2];
40      #endif
41    numDim=Finley_Mesh_getDim(in);    numDim=Finley_Mesh_getDim(in);
42        /*  find the minimum and maximum id used by elements: */
   /*   find the minimum and maximum id used: */  
     
43    min_id=INDEX_T_MAX;    min_id=INDEX_T_MAX;
44    max_id=-INDEX_T_MAX;    max_id=-INDEX_T_MAX;
   Finley_NodeFile_setIdRange(&min_id2,&max_id2,in->Nodes);  
   if (min_id2==INDEX_T_MAX || max_id2==-INDEX_T_MAX) {  
     Finley_setError(VALUE_ERROR,"__FILE__: Mesh has not been defined completely.");  
     goto clean;  
   }  
   
   max_id=MAX(max_id,max_id2);  
   min_id=MIN(min_id,min_id2);  
45    Finley_ElementFile_setNodeRange(&min_id2,&max_id2,in->Elements);    Finley_ElementFile_setNodeRange(&min_id2,&max_id2,in->Elements);
46    max_id=MAX(max_id,max_id2);    max_id=MAX(max_id,max_id2);
47    min_id=MIN(min_id,min_id2);    min_id=MIN(min_id,min_id2);
# Line 64  void  Finley_Mesh_resolveNodeIds(Finley_ Line 54  void  Finley_Mesh_resolveNodeIds(Finley_
54    Finley_ElementFile_setNodeRange(&min_id2,&max_id2,in->Points);    Finley_ElementFile_setNodeRange(&min_id2,&max_id2,in->Points);
55    max_id=MAX(max_id,max_id2);    max_id=MAX(max_id,max_id2);
56    min_id=MIN(min_id,min_id2);    min_id=MIN(min_id,min_id2);
57      #ifdef PASO_MPI
58         id_range[0]=-min_id;
59         id_range[1]=max_id;
60         MPI_Allreduce( id_range, global_id_range, 2, MPI_INT, MPI_MAX, in->MPIInfo->comm );
61         global_min_id=-global_id_range[0];
62         global_max_id=global_id_range[1];
63      #else
64         global_min_id=min_id;
65         global_max_id=max_id;
66      #endif
67    #ifdef Finley_TRACE    #ifdef Finley_TRACE
68    printf("Node id range is %d:%d\n",min_id,max_id);    printf("Node id range used by elements is %d:%d\n",global_min_id,global_max_id);
69    #endif    #endif
70        if (min_id>max_id) {
71    /*  allocate a new node file used to gather existing node file: */       max_id=-1;
72           min_id=0;
   len=max_id-min_id+1;  
   newNodeFile=Finley_NodeFile_alloc(numDim);  
   if (! Finley_noError()) goto clean;  
   
   maskNodes=TMPMEMALLOC(len,index_t);  
   if (Finley_checkPtr(maskNodes)) goto clean;  
   
   maskElements=TMPMEMALLOC(len,index_t);  
   if (Finley_checkPtr(maskElements)) goto clean;  
   
   index=TMPMEMALLOC(in->Nodes->numNodes,index_t);  
   if (Finley_checkPtr(maskElements)) goto clean;  
   
   Finley_NodeFile_allocTable(newNodeFile,len);  
   if (! Finley_noError()) goto clean;  
   
   #pragma omp parallel for private(n) schedule(static)  
   for (n=0;n<in->Nodes->numNodes;n++) index[n]=-1;  
   #pragma omp parallel for private(n) schedule(static)  
   for (n=0;n<len;n++) {  
          maskNodes[n]=-1;  
          maskElements[n]=-1;  
73    }    }
   /*  mark the nodes referred by elements in maskElements: */  
74        
75    Finley_Mesh_markNodes(maskElements,min_id,in,FALSE);    /* allocate mappings for new local node labeling to global node labeling (newLocalToGlobalNodeLabels)
76         and global node labeling to the new local node labeling (globalToNewLocalNodeLabels[i-min_id] is the
77    /*  mark defined nodes */       new local id of global node i) */
78      len=(max_id>=min_id) ? max_id-min_id+1 : 0 ;
79    #pragma omp parallel for private(k) schedule(static)    globalToNewLocalNodeLabels=TMPMEMALLOC(len,index_t); /* local mask for used nodes */
80    for (k=0;k<in->Nodes->numNodes;k++) maskNodes[in->Nodes->Id[k]-min_id]=1;    newLocalToGlobalNodeLabels=TMPMEMALLOC(len,index_t);
81      if (! ( (Finley_checkPtr(globalToNewLocalNodeLabels) && Finley_checkPtr(newLocalToGlobalNodeLabels) ) ) ) {
82    /*  check if all referenced nodes are actually defined: */  
83           #pragma omp parallel
84    #pragma omp parallel for private(k) schedule(static)         {
85    for (k=0;k<len;k++) {             #pragma omp for private(n) schedule(static)
86       /* if a node is refered by an element is there a node defined ?*/             for (n=0;n<len;n++) newLocalToGlobalNodeLabels[n]=-1;
87       if (maskElements[k]>=0 && maskNodes[k]<0) {             #pragma omp for private(n) schedule(static)
88         sprintf(error_msg,"__FILE__:Node id %d is referenced by element but is not defined.",k+min_id);             for (n=0;n<len;n++) globalToNewLocalNodeLabels[n]=-1;
89         Finley_setError(VALUE_ERROR,error_msg);         }
90       }  
91           /*  mark the nodes referred by elements in globalToNewLocalNodeLabels which is currently used as a mask: */
92           Finley_Mesh_markNodes(globalToNewLocalNodeLabels,min_id,in,FALSE);
93    
94           /* create a local labeling newLocalToGlobalNodeLabels of the local nodes by packing the mask globalToNewLocalNodeLabels*/
95    
96           newNumNodes=Finley_Util_packMask(len,globalToNewLocalNodeLabels,newLocalToGlobalNodeLabels);
97    
98           /* invert the new labeling and shift the index newLocalToGlobalNodeLabels to global node ids */
99           #pragma omp parallel for private(n) schedule(static)
100           for (n=0;n<newNumNodes;n++) {
101                  #ifdef BOUNDS_CHECK
102                         if (n >= len || n < 0) { printf("BOUNDS_CHECK %s %d n=%d\n", __FILE__, __LINE__, n); exit(1); }
103                         if (newLocalToGlobalNodeLabels[n] >= len || newLocalToGlobalNodeLabels[n] < 0) { printf("BOUNDS_CHECK %s %d n=%d\n", __FILE__, __LINE__, n); exit(1); }
104                  #endif
105                  globalToNewLocalNodeLabels[newLocalToGlobalNodeLabels[n]]=n;
106                  newLocalToGlobalNodeLabels[n]+=min_id;
107            }
108            /* create a new table */
109            newNodeFile=Finley_NodeFile_alloc(numDim,in->MPIInfo);
110            if (Finley_noError()) {
111               Finley_NodeFile_allocTable(newNodeFile,newNumNodes);
112            }
113            if (Finley_noError()) {
114                Finley_NodeFile_gather_global(newLocalToGlobalNodeLabels,in->Nodes, newNodeFile);
115            }
116            if (Finley_noError()) {
117               Finley_NodeFile_free(in->Nodes);
118               in->Nodes=newNodeFile;
119               /*  relable nodes of the elements: */
120               Finley_Mesh_relableElementNodes(globalToNewLocalNodeLabels,min_id,in);
121            }
122    }    }
123      TMPMEMFREE(globalToNewLocalNodeLabels);
124    if (Finley_noError()) {    TMPMEMFREE(newLocalToGlobalNodeLabels);
125        if (! Finley_noError()) {
126        /*  scatter the nodefile in->nodes into newNodeFile using index; */         Finley_NodeFile_free(newNodeFile);
       #pragma omp parallel for private(k) schedule(static)  
       for (k=0;k<in->Nodes->numNodes;k++) index[k]=in->Nodes->Id[k]-min_id;  
       Finley_NodeFile_scatter(index,in->Nodes,newNodeFile);  
     
       /*  relable used nodes: */  
       /* index maps the new node labeling onto the old one */  
       newNumNodes=Finley_Util_packMask(len,maskElements,index);  
       #pragma omp parallel for private(k) schedule(static)  
       for (k=0;k<newNumNodes;k++) maskElements[index[k]]=k;  
   
       /*  create a new table of nodes: */  
       Finley_NodeFile_deallocTable(in->Nodes);  
       Finley_NodeFile_allocTable(in->Nodes,newNumNodes);  
       if (! Finley_noError()) goto clean;  
   
       /* gather the new nodefile into in->Nodes */  
       Finley_NodeFile_gather(index,newNodeFile,in->Nodes);  
   
       /*  relable nodes of the elements: */  
       Finley_Mesh_relableElementNodes(maskElements,min_id,in);  
   
127    }    }
   
   /*  clean-up: */  
     
   clean: TMPMEMFREE(maskNodes);  
          TMPMEMFREE(maskElements);  
          TMPMEMFREE(index);  
          Finley_NodeFile_deallocTable(newNodeFile);  
          Finley_NodeFile_dealloc(newNodeFile);  
128  }  }
   
 /*  
 * $Log$  
 * Revision 1.6  2005/09/15 03:44:23  jgs  
 * Merge of development branch dev-02 back to main trunk on 2005-09-15  
 *  
 * Revision 1.5.2.1  2005/09/07 06:26:20  gross  
 * the solver from finley are put into the standalone package paso now  
 *  
 * Revision 1.5  2005/07/08 04:07:54  jgs  
 * Merge of development branch back to main trunk on 2005-07-08  
 *  
 * Revision 1.4  2004/12/15 07:08:33  jgs  
 * *** empty log message ***  
 * Revision 1.1.1.1.2.2  2005/06/29 02:34:53  gross  
 * some changes towards 64 integers in finley  
 *  
 * Revision 1.1.1.1.2.1  2004/11/24 01:37:14  gross  
 * some changes dealing with the integer overflow in memory allocation. Finley solves 4M unknowns now  
 *  
 *  
 *  
 */  
   

Legend:
Removed from v.155  
changed lines
  Added in v.3080

  ViewVC Help
Powered by ViewVC 1.1.26