/[escript]/trunk/finley/src/Mesh_prepare.cpp
ViewVC logotype

Diff of /trunk/finley/src/Mesh_prepare.cpp

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

trunk/finley/src/finley/Mesh_prepare.c revision 201 by jgs, Wed Nov 23 04:10:21 2005 UTC trunk/finley/src/Mesh_prepare.c revision 2856 by gross, Mon Jan 18 04:14:37 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    * Copyright (c) 2003-2009 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    
 /*   Finley: Mesh: prepares the mesh for further calculations  */  
14    
15  /**************************************************************/  /**************************************************************/
16    
17  /*   Author: gross@access.edu.au */  /*   Finley: Mesh: prepares the mesh for further calculations  */
 /*   Version: $Id$ */  
18    
19  /**************************************************************/  /**************************************************************/
20    
# Line 27  Line 22 
22    
23  /**************************************************************/  /**************************************************************/
24    
25  void Finley_Mesh_prepare(Finley_Mesh* in) {  void Finley_Mesh_prepare(Finley_Mesh* in, bool_t optimize) {
26         dim_t newGlobalNumDOFs=0, numReducedNodes=0,i;
27         index_t* distribution=NULL, *maskReducedNodes=NULL, *indexReducedNodes=NULL, *node_distribution=NULL;
28         if (in==NULL) return;
29         if (in->Nodes == NULL) return;
30    
31         Mesh_setOrders(in);
32    
33         /* first step is to distribute the elements according to a global distribution of DOF */
34    
35         distribution=TMPMEMALLOC(in->MPIInfo->size+1,index_t);
36         node_distribution=TMPMEMALLOC(in->MPIInfo->size+1,index_t);
37         if (! (Finley_checkPtr(distribution) || Finley_checkPtr(node_distribution))) {
38            /* first we create dense labeling for the DOFs */
39    
40            newGlobalNumDOFs=Finley_NodeFile_createDenseDOFLabeling(in->Nodes);
41    
42            /* create a distribution of the global DOFs and determine
43               the MPI_rank controling the DOFs on this processor      */
44            Paso_MPIInfo_setDistribution(in->MPIInfo,0,newGlobalNumDOFs-1,distribution);
45    
46            /* now the mesh is re-distributed according to the mpiRankOfDOF vector */
47            /* this will redistribute the Nodes and Elements including overlap and will create an element coloring
48               but will not create any mappings (see later in this function)                                   */
49            if (Finley_noError()) Finley_Mesh_distributeByRankOfDOF(in,distribution);
50         }
51    
52         /* at this stage we are able to start an optimization of the DOF distribution using ParaMetis */
53         /* on return distribution is altered and new DOF ids have been assigned */
54         if (Finley_noError() && optimize && in->MPIInfo->size>1) {
55             Finley_Mesh_optimizeDOFDistribution(in,distribution);
56             if (Finley_noError()) Finley_Mesh_distributeByRankOfDOF(in,distribution);
57         }
58         /* the local labeling of the degrees of free is optimized */
59         if (Finley_noError() && optimize) {
60           Finley_Mesh_optimizeDOFLabeling(in,distribution);
61         }
62         /* rearrange elements with the attempt to bring elements closer to memory locations of the nodes (distributed shared memory!): */
63         if (Finley_noError()) Finley_Mesh_optimizeElementOrdering(in);
64    
65    
66         /* create the global indices */
67         if (Finley_noError()) {
68    
69    
70            maskReducedNodes=TMPMEMALLOC(in->Nodes->numNodes,index_t);
71            indexReducedNodes=TMPMEMALLOC(in->Nodes->numNodes,index_t);
72            if (! ( Finley_checkPtr(maskReducedNodes) ||  Finley_checkPtr(indexReducedNodes) ) ) {
73    
74    /* useful DEBUG:
75    {index_t MIN_id,MAX_id;
76    printf("Mesh_prepare: global DOF : %d\n",newGlobalNumDOFs);
77    Finley_NodeFile_setGlobalIdRange(&MIN_id,&MAX_id,in->Nodes);
78    printf("Mesh_prepare: global node id range = %d :%d\n", MIN_id,MAX_id);
79    Finley_NodeFile_setIdRange(&MIN_id,&MAX_id,in->Nodes);
80    printf("Mesh_prepare: local node id range = %d :%d\n", MIN_id,MAX_id);
81    }
82    */
83              #pragma omp parallel for private(i) schedule(static)
84              for (i=0;i<in->Nodes->numNodes;++i) maskReducedNodes[i]=-1;
85    
86         /* set the labeling vectors in node files: */            Finley_Mesh_markNodes(maskReducedNodes,0,in,TRUE);
87         Finley_Mesh_prepareNodes(in);    
88              numReducedNodes=Finley_Util_packMask(in->Nodes->numNodes,maskReducedNodes,indexReducedNodes);
89    
90              Finley_NodeFile_createDenseNodeLabeling(in->Nodes, node_distribution, distribution);
91              Finley_NodeFile_createDenseReducedDOFLabeling(in->Nodes,maskReducedNodes);
92              Finley_NodeFile_createDenseReducedNodeLabeling(in->Nodes,maskReducedNodes);
93              /* create the missing mappings */
94    
95              if (Finley_noError()) Finley_Mesh_createNodeFileMappings(in,numReducedNodes,indexReducedNodes,distribution, node_distribution);
96            }
97    
98            TMPMEMFREE(maskReducedNodes);
99            TMPMEMFREE(indexReducedNodes);
100         }
101    
102         /* rearrange elements: */       TMPMEMFREE(distribution);
103         Finley_Mesh_optimizeElementDistribution(in);       TMPMEMFREE(node_distribution);
104    
105         /* improve coloring */       Finley_Mesh_setTagsInUse(in);
106         Finley_Mesh_improveColoring(in);       return;
107  }  }
108    
109  /*                                                      */  /*                                                      */
110  /*  tries to reduce the coloring for all element files: */  /*  tries to reduce the coloring for all element files: */
111  /*                                                      */  /*                                                      */
112  void Finley_Mesh_improveColoring(Finley_Mesh* in) {  void Finley_Mesh_createColoring(Finley_Mesh* in, index_t *node_localDOF_map) {
113    Finley_ElementFile_improveColoring(in->Elements,in->Nodes->numNodes,in->Nodes->degreeOfFreedom);    if (Finley_noError()) Finley_ElementFile_createColoring(in->Elements,in->Nodes->numNodes,node_localDOF_map);
114    Finley_ElementFile_improveColoring(in->FaceElements,in->Nodes->numNodes,in->Nodes->degreeOfFreedom);    if (Finley_noError()) Finley_ElementFile_createColoring(in->FaceElements,in->Nodes->numNodes,node_localDOF_map);
115    Finley_ElementFile_improveColoring(in->Points,in->Nodes->numNodes,in->Nodes->degreeOfFreedom);    if (Finley_noError()) Finley_ElementFile_createColoring(in->Points,in->Nodes->numNodes,node_localDOF_map);
116    Finley_ElementFile_improveColoring(in->ContactElements,in->Nodes->numNodes,in->Nodes->degreeOfFreedom);    if (Finley_noError()) Finley_ElementFile_createColoring(in->ContactElements,in->Nodes->numNodes,node_localDOF_map);
117  }  }
118  /*                                                                    */  /*                                                                    */
119  /*  redistribute elements to minimize communication during assemblage */  /*  redistribute elements to minimize communication during assemblage */
120  /*                                                                    */  /*                                                                    */
121  void Finley_Mesh_optimizeElementDistribution(Finley_Mesh* in) {  void Finley_Mesh_optimizeElementOrdering(Finley_Mesh* in) {
122    Finley_ElementFile_optimizeDistribution(&(in->Elements));    if (Finley_noError()) Finley_ElementFile_optimizeOrdering(&(in->Elements));
123    Finley_ElementFile_optimizeDistribution(&(in->FaceElements));    if (Finley_noError()) Finley_ElementFile_optimizeOrdering(&(in->FaceElements));
124    Finley_ElementFile_optimizeDistribution(&(in->Points));    if (Finley_noError()) Finley_ElementFile_optimizeOrdering(&(in->Points));
125    Finley_ElementFile_optimizeDistribution(&(in->ContactElements));    if (Finley_noError()) Finley_ElementFile_optimizeOrdering(&(in->ContactElements));
126  }  }
127    
128  /*  /*                                                                    */
129  * $Log$  /*  redistribute elements to minimize communication during assemblage */
130  * Revision 1.2  2005/09/15 03:44:22  jgs  void Finley_Mesh_setTagsInUse(Finley_Mesh* in)
131  * Merge of development branch dev-02 back to main trunk on 2005-09-15  {
132  *      if (Finley_noError()) Finley_NodeFile_setTagsInUse(in->Nodes);
133  * Revision 1.1.1.1.6.1  2005/09/07 06:26:19  gross      if (Finley_noError()) Finley_ElementFile_setTagsInUse(in->Elements);
134  * the solver from finley are put into the standalone package paso now      if (Finley_noError()) Finley_ElementFile_setTagsInUse(in->FaceElements);
135  *      if (Finley_noError()) Finley_ElementFile_setTagsInUse(in->Points);
136  * Revision 1.1.1.1  2004/10/26 06:53:57  jgs      if (Finley_noError()) Finley_ElementFile_setTagsInUse(in->ContactElements);
137  * initial import of project esys2  }
 *  
 * Revision 1.1.1.1  2004/06/24 04:00:40  johng  
 * Initial version of eys using boost-python.  
 *  
 *  
 */  
   

Legend:
Removed from v.201  
changed lines
  Added in v.2856

  ViewVC Help
Powered by ViewVC 1.1.26