/[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/Mesh_prepare.c revision 616 by elspeth, Wed Mar 22 02:46:56 2006 UTC trunk/finley/src/Mesh_prepare.cpp revision 4346 by jfenwick, Tue Apr 2 04:46:45 2013 UTC
# Line 1  Line 1 
 /*  
  ************************************************************  
  *          Copyright 2006 by ACcESS MNRF                   *  
  *                                                          *  
  *              http://www.access.edu.au                    *  
  *       Primary Business: Queensland, Australia            *  
  *  Licensed under the Open Software License version 3.0    *  
  *     http://www.opensource.org/licenses/osl-3.0.php       *  
  *                                                          *  
  ************************************************************  
 */  
1    
2  /**************************************************************/  /*****************************************************************************
3    *
4    * Copyright (c) 2003-2013 by University of Queensland
5    * http://www.uq.edu.au
6    *
7    * Primary Business: Queensland, Australia
8    * Licensed under the Open Software License version 3.0
9    * http://www.opensource.org/licenses/osl-3.0.php
10    *
11    * Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12    * Development since 2012 by School of Earth Sciences
13    *
14    *****************************************************************************/
15    
 /*   Finley: Mesh: prepares the mesh for further calculations  */  
16    
17  /**************************************************************/  /************************************************************************************/
18    
19  /*   Author: gross@access.edu.au */  /*   Finley: Mesh: prepares the mesh for further calculations  */
 /*   Version: $Id$ */  
20    
21  /**************************************************************/  /************************************************************************************/
22    
23  #include "Mesh.h"  #include "Mesh.h"
24    
25  /**************************************************************/  /************************************************************************************/
26    
27  void Finley_Mesh_prepare(Finley_Mesh* in) {  void Finley_Mesh_prepare(Finley_Mesh* in, bool_t optimize) {
28         dim_t newGlobalNumDOFs=0, numReducedNodes=0,i;
29         index_t* distribution=NULL, *maskReducedNodes=NULL, *indexReducedNodes=NULL, *node_distribution=NULL;
30         if (in==NULL) return;
31         if (in->Nodes == NULL) return;
32    
33         Finley_Mesh_setOrders(in);
34    
35         /* first step is to distribute the elements according to a global distribution of DOF */
36    
37         distribution=new index_t[in->MPIInfo->size+1];
38         node_distribution=new index_t[in->MPIInfo->size+1];
39         if (! (Finley_checkPtr(distribution) || Finley_checkPtr(node_distribution))) {
40            /* first we create dense labeling for the DOFs */
41    
42            newGlobalNumDOFs=Finley_NodeFile_createDenseDOFLabeling(in->Nodes);
43    
44            /* create a distribution of the global DOFs and determine
45               the MPI_rank controlling the DOFs on this processor      */
46            Esys_MPIInfo_setDistribution(in->MPIInfo,0,newGlobalNumDOFs-1,distribution);
47    
48            /* now the mesh is re-distributed according to the mpiRankOfDOF vector */
49            /* this will redistribute the Nodes and Elements including overlap and will create an element coloring
50               but will not create any mappings (see later in this function) */
51            if (Finley_noError()) Finley_Mesh_distributeByRankOfDOF(in,distribution);
52         }
53    
54         /* at this stage we are able to start an optimization of the DOF distribution using ParMetis */
55         /* on return distribution is altered and new DOF ids have been assigned */
56         if (Finley_noError() && optimize && in->MPIInfo->size>1) {
57             Finley_Mesh_optimizeDOFDistribution(in,distribution);
58             if (Finley_noError()) Finley_Mesh_distributeByRankOfDOF(in,distribution);
59         }
60         /* the local labelling of the degrees of freedom is optimized */
61         if (Finley_noError() && optimize) {
62           Finley_Mesh_optimizeDOFLabeling(in,distribution);
63         }
64         /* rearrange elements with the attempt to bring elements closer to memory locations of the nodes (distributed shared memory!): */
65         if (Finley_noError()) Finley_Mesh_optimizeElementOrdering(in);
66    
67    
68         /* create the global indices */
69         if (Finley_noError()) {
70    
71    
72            maskReducedNodes=new index_t[in->Nodes->numNodes];
73            indexReducedNodes=new index_t[in->Nodes->numNodes];
74            if (! ( Finley_checkPtr(maskReducedNodes) ||  Finley_checkPtr(indexReducedNodes) ) ) {
75    
76    /* useful DEBUG:
77    {index_t MIN_id,MAX_id;
78    printf("Mesh_prepare: global DOF : %d\n",newGlobalNumDOFs);
79    Finley_NodeFile_setGlobalIdRange(&MIN_id,&MAX_id,in->Nodes);
80    printf("Mesh_prepare: global node id range = %d :%d\n", MIN_id,MAX_id);
81    Finley_NodeFile_setIdRange(&MIN_id,&MAX_id,in->Nodes);
82    printf("Mesh_prepare: local node id range = %d :%d\n", MIN_id,MAX_id);
83    }
84    */
85              #pragma omp parallel for private(i) schedule(static)
86              for (i=0;i<in->Nodes->numNodes;++i) maskReducedNodes[i]=-1;
87    
88         /* set the labeling vectors in node files: */            Finley_Mesh_markNodes(maskReducedNodes,0,in,TRUE);
89         Finley_Mesh_prepareNodes(in);    
90              numReducedNodes=Finley_Util_packMask(in->Nodes->numNodes,maskReducedNodes,indexReducedNodes);
91    
92              Finley_NodeFile_createDenseNodeLabeling(in->Nodes, node_distribution, distribution);
93              Finley_NodeFile_createDenseReducedDOFLabeling(in->Nodes,maskReducedNodes);
94              Finley_NodeFile_createDenseReducedNodeLabeling(in->Nodes,maskReducedNodes);
95              /* create the missing mappings */
96    
97              if (Finley_noError()) Finley_Mesh_createNodeFileMappings(in,numReducedNodes,indexReducedNodes,distribution, node_distribution);
98            }
99    
100            delete[] maskReducedNodes;
101            delete[] indexReducedNodes;
102         }
103    
104         /* rearrange elements: */       delete[] distribution;
105         Finley_Mesh_optimizeElementDistribution(in);       delete[] node_distribution;
106    
107         /* improve coloring */       Finley_Mesh_setTagsInUse(in);
108         Finley_Mesh_improveColoring(in);       return;
109  }  }
110    
111  /*                                                      */  /*                                                      */
112  /*  tries to reduce the coloring for all element files: */  /*  tries to reduce the coloring for all element files: */
113  /*                                                      */  /*                                                      */
114  void Finley_Mesh_improveColoring(Finley_Mesh* in) {  void Finley_Mesh_createColoring(Finley_Mesh* in, index_t *node_localDOF_map) {
115    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);
116    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);
117    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);
118    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);
119  }  }
120  /*                                                                    */  /*                                                                    */
121  /*  redistribute elements to minimize communication during assemblage */  /*  redistribute elements to minimize communication during assemblage */
122  /*                                                                    */  /*                                                                    */
123  void Finley_Mesh_optimizeElementDistribution(Finley_Mesh* in) {  void Finley_Mesh_optimizeElementOrdering(Finley_Mesh* in) {
124    Finley_ElementFile_optimizeDistribution(&(in->Elements));    if (Finley_noError()) Finley_ElementFile_optimizeOrdering(&(in->Elements));
125    Finley_ElementFile_optimizeDistribution(&(in->FaceElements));    if (Finley_noError()) Finley_ElementFile_optimizeOrdering(&(in->FaceElements));
126    Finley_ElementFile_optimizeDistribution(&(in->Points));    if (Finley_noError()) Finley_ElementFile_optimizeOrdering(&(in->Points));
127    Finley_ElementFile_optimizeDistribution(&(in->ContactElements));    if (Finley_noError()) Finley_ElementFile_optimizeOrdering(&(in->ContactElements));
128  }  }
129    
130  /*  /*                                                                    */
131  * $Log$  /*  redistribute elements to minimize communication during assemblage */
132  * Revision 1.2  2005/09/15 03:44:22  jgs  void Finley_Mesh_setTagsInUse(Finley_Mesh* in)
133  * Merge of development branch dev-02 back to main trunk on 2005-09-15  {
134  *      if (Finley_noError()) Finley_NodeFile_setTagsInUse(in->Nodes);
135  * Revision 1.1.1.1.6.1  2005/09/07 06:26:19  gross      if (Finley_noError()) Finley_ElementFile_setTagsInUse(in->Elements);
136  * the solver from finley are put into the standalone package paso now      if (Finley_noError()) Finley_ElementFile_setTagsInUse(in->FaceElements);
137  *      if (Finley_noError()) Finley_ElementFile_setTagsInUse(in->Points);
138  * Revision 1.1.1.1  2004/10/26 06:53:57  jgs      if (Finley_noError()) Finley_ElementFile_setTagsInUse(in->ContactElements);
139  * 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.616  
changed lines
  Added in v.4346

  ViewVC Help
Powered by ViewVC 1.1.26