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

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

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

revision 1311 by gross, Tue Feb 13 05:10:26 2007 UTC revision 1312 by ksteube, Mon Sep 24 06:18:44 2007 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  /**************************************************************/  /* $Id$ */
3    
4  /*   Finley: Mesh: prepares the mesh for further calculations  */  /*******************************************************
5     *
6     *           Copyright 2003-2007 by ACceSS MNRF
7     *       Copyright 2007 by University of Queensland
8     *
9     *                http://esscc.uq.edu.au
10     *        Primary Business: Queensland, Australia
11     *  Licensed under the Open Software License version 3.0
12     *     http://www.opensource.org/licenses/osl-3.0.php
13     *
14     *******************************************************/
15    
16  /**************************************************************/  /**************************************************************/
17    
18  /*   Author: gross@access.edu.au */  /*   Finley: Mesh: prepares the mesh for further calculations  */
 /*   Version: $Id$ */  
19    
20  /**************************************************************/  /**************************************************************/
21    
# Line 25  Line 23 
23    
24  /**************************************************************/  /**************************************************************/
25    
26  void Finley_Mesh_prepare(Finley_Mesh* in) {  void Finley_Mesh_prepare(Finley_Mesh* in, bool_t optimize) {
27         dim_t newGlobalNumDOFs=0, numReducedNodes=0,i;
28         index_t* distribution=NULL, *maskReducedNodes=NULL, *indexReducedNodes=NULL;
29         if (in==NULL) return;
30         if (in->Nodes == NULL) return;
31    
32         /* first step is to distribute the elements according to a global distribution of DOF */
33    
34         distribution=TMPMEMALLOC(in->MPIInfo->size+1,index_t);
35         if (! Finley_checkPtr(distribution)) {
36            /* first we create dense labeling for the DOFs */
37            newGlobalNumDOFs=Finley_NodeFile_createDenseDOFLabeling(in->Nodes);
38    
39            /* create a distribution of the global DOFs and determine
40               the MPI_rank controling the DOFs on this processor      */
41            Paso_MPIInfo_setDistribution(in->MPIInfo,0,newGlobalNumDOFs-1,distribution);
42    
43            /* now the mesh is re-distributed according to the mpiRankOfDOF vector */
44            /* this will redistribute the Nodes and Elements including overlap and will create an element coloring
45               but will not create any mappings (see later in this function)                                   */
46            if (Finley_noError()) Finley_Mesh_distributeByRankOfDOF(in,distribution);
47         }
48    
49         /* at this stage we are able to start an optimization of the DOF distribution using ParaMetis */
50         /* on return distribution is altered and new DOF ids have been assigned */
51         if (Finley_noError() && optimize && in->MPIInfo->size>1) {
52    
53             Finley_Mesh_optimizeDOFDistribution(in,distribution);
54    
55             if (Finley_noError()) Finley_Mesh_distributeByRankOfDOF(in,distribution);
56    
57         }
58         /* now a local labeling of the DOF is introduced */
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            maskReducedNodes=TMPMEMALLOC(in->Nodes->numNodes,index_t);
69            indexReducedNodes=TMPMEMALLOC(in->Nodes->numNodes,index_t);
70            if (! ( Finley_checkPtr(maskReducedNodes) ||  Finley_checkPtr(indexReducedNodes) ) ) {
71    
72              #pragma omp parallel for private(i) schedule(static)
73              for (i=0;i<in->Nodes->numNodes;++i) maskReducedNodes[i]=-1;
74    
75              Finley_Mesh_markNodes(maskReducedNodes,0,in,1);
76      
77              numReducedNodes=Finley_Util_packMask(in->Nodes->numNodes,maskReducedNodes,indexReducedNodes);
78    
79              Finley_NodeFile_createDenseNodeLabeling(in->Nodes);
80              Finley_NodeFile_createDenseReducedNodeLabeling(in->Nodes,maskReducedNodes);
81              Finley_NodeFile_createDenseReducedDOFLabeling(in->Nodes,maskReducedNodes);
82              /* create the missing mappings */
83              if (Finley_noError()) Finley_Mesh_createNodeFileMappings(in,numReducedNodes,indexReducedNodes,distribution);
84            }
85    
86            TMPMEMFREE(maskReducedNodes);
87            TMPMEMFREE(indexReducedNodes);
88         }
89    
90         /* set the labeling vectors in node files: */       TMPMEMFREE(distribution);
        Finley_Mesh_prepareNodes(in);  
91    
92  #ifndef PASO_MPI       return;
        /* rearrange elements: */  
        Finley_Mesh_optimizeElementDistribution(in);  
   
        /* improve coloring */  
        Finley_Mesh_improveColoring(in);  
 #endif  
93  }  }
94    
 bool_t Finley_Mesh_isPrepared(Finley_Mesh* in) {  
      /* returns true if nodes and elements have been prepared for calculation */  
      index_t out = TRUE;  
      if ( in->Nodes != NULL) out = MIN(out , in->Nodes->isPrepared);  
      if ( in->Elements != NULL) out = MIN(out ,  in->Elements->isPrepared);  
      if ( in->FaceElements != NULL) out = MIN(out ,  in->FaceElements->isPrepared);  
      if ( in->ContactElements != NULL) out = MIN(out ,  in->ContactElements->isPrepared);  
      if ( in->Points != NULL) out = MIN(out ,  in->Points->isPrepared);  
   
      return out == FINLEY_PREPARED;  
 }  
95  /*                                                      */  /*                                                      */
96  /*  tries to reduce the coloring for all element files: */  /*  tries to reduce the coloring for all element files: */
97  /*                                                      */  /*                                                      */
98  void Finley_Mesh_improveColoring(Finley_Mesh* in) {  void Finley_Mesh_createColoring(Finley_Mesh* in, index_t *node_localDOF_map) {
99    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);
100    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);
101    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);
102    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);
103  }  }
104  /*                                                                    */  /*                                                                    */
105  /*  redistribute elements to minimize communication during assemblage */  /*  redistribute elements to minimize communication during assemblage */
106  /*                                                                    */  /*                                                                    */
107  void Finley_Mesh_optimizeElementDistribution(Finley_Mesh* in) {  void Finley_Mesh_optimizeElementOrdering(Finley_Mesh* in) {
108    Finley_ElementFile_optimizeDistribution(&(in->Elements));    if (Finley_noError()) Finley_ElementFile_optimizeOrdering(&(in->Elements));
109    Finley_ElementFile_optimizeDistribution(&(in->FaceElements));    if (Finley_noError()) Finley_ElementFile_optimizeOrdering(&(in->FaceElements));
110    Finley_ElementFile_optimizeDistribution(&(in->Points));    if (Finley_noError()) Finley_ElementFile_optimizeOrdering(&(in->Points));
111    Finley_ElementFile_optimizeDistribution(&(in->ContactElements));    if (Finley_noError()) Finley_ElementFile_optimizeOrdering(&(in->ContactElements));
112  }  }
   
 /*  
 * $Log$  
 * Revision 1.2  2005/09/15 03:44:22  jgs  
 * Merge of development branch dev-02 back to main trunk on 2005-09-15  
 *  
 * Revision 1.1.1.1.6.1  2005/09/07 06:26:19  gross  
 * the solver from finley are put into the standalone package paso now  
 *  
 * Revision 1.1.1.1  2004/10/26 06:53:57  jgs  
 * 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.1311  
changed lines
  Added in v.1312

  ViewVC Help
Powered by ViewVC 1.1.26