/[escript]/branches/doubleplusgood/dudley/src/Mesh.cpp
ViewVC logotype

Diff of /branches/doubleplusgood/dudley/src/Mesh.cpp

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

trunk/finley/src/Mesh.c revision 1044 by gross, Mon Mar 19 07:29:31 2007 UTC trunk/dudley/src/Mesh.c revision 3981 by jfenwick, Fri Sep 21 02:47:54 2012 UTC
# Line 1  Line 1 
1  /*  /*****************************************************************************
2   ************************************************************  *
3   *          Copyright 2006 by ACcESS MNRF                   *  * Copyright (c) 2003-2012 by University of Queensland
4   *                                                          *  * http://www.uq.edu.au
5   *              http://www.access.edu.au                    *  *
6   *       Primary Business: Queensland, Australia            *  * Primary Business: Queensland, Australia
7   *  Licensed under the Open Software License version 3.0    *  * Licensed under the Open Software License version 3.0
8   *     http://www.opensource.org/licenses/osl-3.0.php       *  * http://www.opensource.org/licenses/osl-3.0.php
9   *                                                          *  *
10   ************************************************************  * Development until 2012 by Earth Systems Science Computational Center (ESSCC)
11  */  * Development since 2012 by School of Earth Sciences
12    *
13    *****************************************************************************/
 /**************************************************************/  
   
 /*   Finley: Mesh */  
14    
15  /**************************************************************/  /************************************************************************************/
16    
17  /*  Author: gross@access.edu.au */  /*   Dudley: Mesh */
 /*  Version: $Id$ */  
18    
19  /**************************************************************/  /************************************************************************************/
20    
21  #include "Mesh.h"  #include "Mesh.h"
22    
23  /**************************************************************/  /************************************************************************************/
24    
25  /*   allocates a Mesh with name name for elements of type id using an integration order. If order is negative, */  /*   allocates a Mesh with name name for elements of type id using an integration order. If order is negative, */
26  /*   the most appropriate order is selected indepently. */  /*   the most appropriate order is selected indepently. */
27    
28  extern Finley_RefElementInfo Finley_RefElement_InfoList[];  Dudley_Mesh *Dudley_Mesh_alloc(char *name, dim_t numDim, Esys_MPIInfo * mpi_info)
   
 #ifndef PASO_MPI  
 Finley_Mesh* Finley_Mesh_alloc(char* name,dim_t numDim, index_t order)  
 #else  
 Finley_Mesh* Finley_Mesh_alloc(char* name,dim_t numDim, index_t order, Paso_MPIInfo *mpi_info)  
 #endif  
29  {  {
30    Finley_Mesh *out;      Dudley_Mesh *out;
     
   /*  allocate the return value */  
     
   out=MEMALLOC(1,Finley_Mesh);  
   if (Finley_checkPtr(out)) return NULL;  
   out->Name=NULL;    
   out->Nodes=NULL;  
   out->Elements=NULL;    
   out->FaceElements=NULL;  
   out->Points=NULL;        
   out->ContactElements=NULL;        
   out->TagMap=NULL;        
   out->reference_counter=0;  
   
   out->FullFullPattern=NULL;  
   out->FullReducedPattern=NULL;  
   out->ReducedFullPattern=NULL;  
   out->ReducedReducedPattern=NULL;  
   
 #ifdef PASO_MPI  
   out->MPIInfo = NULL;  
   
   /* get MPI info */  
   out->MPIInfo = Paso_MPIInfo_getReference( mpi_info );  
   if (! Finley_noError()) {  
       Finley_Mesh_dealloc(out);  
       return NULL;  
   }  
 #endif  
   /*   copy name: */  
     
   out->Name=MEMALLOC(strlen(name)+1,char);  
   if (Finley_checkPtr(out->Name)) {  
       Finley_Mesh_dealloc(out);  
       return NULL;  
   }  
   strcpy(out->Name,name);  
     
   /*   allocate node table: */  
 #ifdef PASO_MPI  
   out->Nodes=Finley_NodeFile_alloc( numDim, mpi_info );  
 #else  
   out->Nodes=Finley_NodeFile_alloc(numDim);  
 #endif  
   if (! Finley_noError()) {  
       Finley_Mesh_dealloc(out);  
       return NULL;  
   }  
   out->order=order;  
   out->Elements=NULL;  
   out->FaceElements=NULL;  
   out->Points=NULL;  
   out->ContactElements=NULL;  
   out->reference_counter++;  
   return out;  
 }  
31    
32  /* returns a reference to Finley_Mesh in */      /*  allocate the return value */
33    
34  Finley_Mesh* Finley_Mesh_reference(Finley_Mesh* in) {      out = MEMALLOC(1, Dudley_Mesh);
35       if (in!=NULL) ++(in->reference_counter);      if (Dudley_checkPtr(out))
36       return in;      return NULL;
37        out->Name = NULL;
38        out->Nodes = NULL;
39        out->Elements = NULL;
40        out->FaceElements = NULL;
41        out->Points = NULL;
42        out->TagMap = NULL;
43        out->reference_counter = 0;
44    
45        out->FullFullPattern = NULL;
46        out->FullReducedPattern = NULL;
47        out->ReducedFullPattern = NULL;
48        out->ReducedReducedPattern = NULL;
49        out->MPIInfo = Esys_MPIInfo_getReference(mpi_info);
50        if (!Dudley_noError())
51        {
52        Dudley_Mesh_free(out);
53        return NULL;
54        }
55        /*   copy name: */
56    
57        out->Name = MEMALLOC(strlen(name) + 1, char);
58        if (Dudley_checkPtr(out->Name))
59        {
60        Dudley_Mesh_free(out);
61        return NULL;
62        }
63        strcpy(out->Name, name);
64    
65        /*   allocate node table: */
66        out->Nodes = Dudley_NodeFile_alloc(numDim, mpi_info);
67        if (!Dudley_noError())
68        {
69        Dudley_Mesh_free(out);
70        return NULL;
71        }
72        out->approximationOrder = -1;
73        out->reducedApproximationOrder = -1;
74        out->integrationOrder = -1;
75        out->reducedIntegrationOrder = -1;
76    
77        out->Elements = NULL;
78        out->FaceElements = NULL;
79        out->Points = NULL;
80        out->reference_counter++;
81        return out;
82  }  }
83    
84  /*   deallocates a mesh: */  /* returns a reference to Dudley_Mesh in */
85    
86  void Finley_Mesh_dealloc(Finley_Mesh* in) {  Dudley_Mesh *Dudley_Mesh_reference(Dudley_Mesh * in)
87    if (in!=NULL) {  {
88       in->reference_counter--;      if (in != NULL)
89       if (in->reference_counter<1) {      ++(in->reference_counter);
90         #ifdef Finley_TRACE      return in;
        if (in->Name!=NULL) {  
            printf("Finley_Mesh_dealloc: mesh %s is deallocated.\n",in->Name);  
        } else {  
            printf("Finley_Mesh_dealloc\n");  
        }  
        #endif  
        MEMFREE(in->Name);  
        Finley_NodeFile_dealloc(in->Nodes);  
        Finley_ElementFile_dealloc(in->Elements);    
        Finley_ElementFile_dealloc(in->FaceElements);  
        Finley_ElementFile_dealloc(in->ContactElements);  
        Finley_ElementFile_dealloc(in->Points);  
        Finley_TagMap_free(in->TagMap);  
        Paso_SystemMatrixPattern_dealloc(in->FullFullPattern);  
        Paso_SystemMatrixPattern_dealloc(in->FullReducedPattern);  
        Paso_SystemMatrixPattern_dealloc(in->ReducedFullPattern);  
        Paso_SystemMatrixPattern_dealloc(in->ReducedReducedPattern);  
 #ifdef PASO_MPI  
        Paso_MPIInfo_dealloc( in->MPIInfo );  
 #endif  
        MEMFREE(in);        
      }  
   }  
91  }  }
92    
93  /**************************************************************/  /*   frees a mesh: */
   
 /*  returns the spatial dimension of the mesh: */  
94    
95  dim_t Finley_Mesh_getDim(Finley_Mesh *in) {  void Dudley_Mesh_free(Dudley_Mesh * in)
96    return in->Nodes->numDim;  {
97        if (in != NULL)
98        {
99        in->reference_counter--;
100        if (in->reference_counter < 1)
101        {
102            MEMFREE(in->Name);
103            Dudley_NodeFile_free(in->Nodes);
104            Dudley_ElementFile_free(in->FaceElements);
105            Dudley_ElementFile_free(in->Elements);
106            Dudley_ElementFile_free(in->Points);
107            Dudley_TagMap_free(in->TagMap);
108            Paso_SystemMatrixPattern_free(in->FullFullPattern);
109            Paso_SystemMatrixPattern_free(in->FullReducedPattern);
110            Paso_SystemMatrixPattern_free(in->ReducedFullPattern);
111            Paso_SystemMatrixPattern_free(in->ReducedReducedPattern);
112            Esys_MPIInfo_free(in->MPIInfo);
113            MEMFREE(in);
114        }
115        }
116  }  }
117    
118  /**************************************************************/  /************************************************************************************/
119    
120  /*  returns the number of nodes in the mesh: */  /*  returns the spatial dimension of the mesh: */
121    
122  dim_t Finley_Mesh_getNumNodes(Finley_Mesh *in) {  dim_t Dudley_Mesh_getDim(Dudley_Mesh * in)
123    return in->Nodes->numNodes;  {
124        return in->Nodes->numDim;
125  }  }
 /**************************************************************/  
126    
127  /*  returns the number of degrees of freedom in the mesh: */  void Dudley_Mesh_setElements(Dudley_Mesh * self, Dudley_ElementFile * elements)
128    {
129        Dudley_ElementFile_free(self->Elements);
130        self->Elements = elements;
131    }
132    
133  dim_t Finley_Mesh_getNumDegreesOfFreedom(Finley_Mesh *in) {  void Dudley_Mesh_setFaceElements(Dudley_Mesh * self, Dudley_ElementFile * elements)
134    return in->Nodes->numDegreesOfFreedom;  {
135        Dudley_ElementFile_free(self->FaceElements);
136        self->FaceElements = elements;
137  }  }
 /**************************************************************/  
138    
139  /*  returns the number of degrees of freedom in the mesh: */  void Dudley_Mesh_setPoints(Dudley_Mesh * self, Dudley_ElementFile * elements)
140    {
141        Dudley_ElementFile_free(self->Points);
142        self->Points = elements;
143    }
144    
145  dim_t Finley_Mesh_getReducedNumDegreesOfFreedom(Finley_Mesh *in) {  int Dudley_Mesh_getStatus(Dudley_Mesh * in)
146    return in->Nodes->reducedNumDegreesOfFreedom;  {
147        if (in == NULL)
148        {
149        return -1;
150        }
151        else if (in->Nodes == NULL)
152        {
153        return -1;
154        }
155        else
156        {
157        return in->Nodes->status;
158        }
159  }  }
160    
161  #ifdef PASO_MPI  void Dudley_Mesh_setOrders(Dudley_Mesh * in)
 void print_mesh_statistics( Finley_Mesh *out, bool_t reduced )  
162  {  {
163    index_t i, r, j, N, M, dim;      in->approximationOrder = 1; /* order of shapeFunctions is always 1 in Dudley */
164      int *ref;        in->reducedApproximationOrder = 1;
165      dim = out->Nodes->numDim;      in->integrationOrder = 2;
166        in->reducedIntegrationOrder = 0;
     if( !reduced ){  
         printf( "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\nMESH STATISTICS\n\nFULL MESH\n+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n\n" );  
         printf( "\nNodes\n========\n\n" );  
         printf( "\t%d internal DOF\n\t%d boundary DOF\n\t%d local DOF\n\t%d external DOF\n", out->Nodes->degreeOfFreedomDistribution->numInternal, out->Nodes->degreeOfFreedomDistribution->numBoundary, out->Nodes->degreeOfFreedomDistribution->numLocal, out->Nodes->degreeOfFreedomDistribution->numExternal);  
         for( i=0; i<out->Nodes->numNodes; i++ ){  
             printf( "node %d\t: id %d   \tDOF %d   \t: tag %d  \t: Dom %d  \t: coordinates [%3g", i, out->Nodes->Id[i], out->Nodes->degreeOfFreedom[i], out->Nodes->Tag[i], out->Nodes->Dom[i], out->Nodes->Coordinates[INDEX2(0,i,dim)] );  
             for( j=1; j<dim; j++ )  
                 printf( ", %3g",  out->Nodes->Coordinates[INDEX2(j,i,dim)]);  
             printf( " ]\n" );  
         }  
   
         printf( "Elements\n=========\n\n" );  
         printf( "\t%d internal\n\t%d boundary\n\t%d local\n", out->Elements->elementDistribution->numInternal, out->Elements->elementDistribution->numBoundary, out->Elements->elementDistribution->numLocal );  
         N = out->Elements->ReferenceElement->Type->numNodes;  
         for( i=0; i<out->Elements->numElements; i++ ){  
             printf( "element %d    \t: id %d  \t: dom %d  \t: nodes [ %2d", i, out->Elements->Id[i], out->Elements->Dom[i], out->Elements->Nodes[INDEX2(0,i,N)] );  
             for( j=1; j<N; j++ )  
                 printf( ", %2d", out->Elements->Nodes[INDEX2(j,i,N)]);    
             printf( " ] -> " );  
             if( N>8 )  
                 printf( "\n\t\t\t\t\t\t" );  
             printf( ": DOF   [ %2d", out->Nodes->degreeOfFreedom[out->Elements->Nodes[INDEX2(0,i,N)]] );      
             for( j=1; j<N; j++ )  
                 printf( ", %2d", out->Nodes->degreeOfFreedom[out->Elements->Nodes[INDEX2(j,i,N)]]);  
             printf( " ]\n" );    
         }  
   
         printf( "\nFace Elements\n==========\n\n" );  
         printf( "\t%d internal\n\t%d boundary\n\t%d local\n", out->FaceElements->elementDistribution->numInternal, out->FaceElements->elementDistribution->numBoundary, out->FaceElements->elementDistribution->numLocal );  
         N = out->FaceElements->ReferenceElement->Type->numNodes;  
         for( i=0; i<out->FaceElements->numElements; i++ ){  
             printf( "face element %d \t: id %d  \t: dom %d  \t: nodes [ %2d", i, out->FaceElements->Id[i], out->FaceElements->Dom[i], out->FaceElements->Nodes[INDEX2(0,i,N)] );  
             for( j=1; j<N; j++ )  
                 printf( ", %2d", out->FaceElements->Nodes[INDEX2(j,i,N)]  );      
             printf( " ] -> " );  
             if( N>8 )  
                 printf( "\n\t\t\t\t\t\t" );  
             printf( ": DOF   [ %2d", out->Nodes->degreeOfFreedom[out->FaceElements->Nodes[INDEX2(0,i,N)]]);  
             for( j=1; j<N; j++ )  
                 printf( ", %2d", out->Nodes->degreeOfFreedom[out->FaceElements->Nodes[INDEX2(j,i,N)]]);  
             printf( " ]\n" );    
         }  
         printf( "\nDistribution Data\n==========\n\n" );  
         Finley_NodeDistribution_print( out->Nodes->degreeOfFreedomDistribution, stdout );  
     }  
     else{  
         printf( "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\nMESH STATISTICS\n\nREDUCED MESH\n+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n\n" );  
         printf( "\nNodes\n========\n\n" );  
         printf( "\t%d internal DOF\n\t%d boundary DOF\n\t%d local DOF\n\t%d external DOF\n", out->Nodes->reducedDegreeOfFreedomDistribution->numInternal, out->Nodes->reducedDegreeOfFreedomDistribution->numBoundary, out->Nodes->reducedDegreeOfFreedomDistribution->numLocal, out->Nodes->reducedDegreeOfFreedomDistribution->numExternal);  
         for( i=0, r=0; i<out->Nodes->numNodes; i++ ){  
             if( out->Nodes->toReduced[i]>=0 ){  
                 printf( "node %d   \t: id %d   \tDOF %d   \t: tag %d  \t: Dom %d  \t: coordinates [%3g", r, out->Nodes->Id[i], out->Nodes->reducedDegreeOfFreedom[i], out->Nodes->Tag[i], out->Nodes->Dom[i], out->Nodes->Coordinates[INDEX2(0,i,dim)] );  
                 for( j=1; j<dim; j++ )  
                     printf( ", %3g",  out->Nodes->Coordinates[INDEX2(j,i,dim)]);  
                 printf( " ]\n" );  
                 r++;  
             }  
         }  
   
         printf( "Elements\n=========\n\n" );  
         printf( "\t%d internal\n\t%d boundary\n\t%d local\n", out->Elements->elementDistribution->numInternal, out->Elements->elementDistribution->numBoundary, out->Elements->elementDistribution->numLocal );  
         N = out->Elements->LinearReferenceElement->Type->numNodes;  
         M = out->Elements->ReferenceElement->Type->numNodes;  
         ref = out->Elements->ReferenceElement->Type->linearNodes;  
         for( i=0; i<out->Elements->numElements; i++ ){  
             printf( "element %d    \t: id %d  \t: dom %d  \t: nodes [ %3d", i, out->Elements->Id[i], out->Elements->Dom[i], out->Nodes->toReduced[out->Elements->Nodes[INDEX2(ref[0],i,M)]] );  
             for( j=1; j<N; j++ ){  
                 printf( ", %3d", out->Nodes->toReduced[out->Elements->Nodes[INDEX2(ref[j],i,M)]] );  
             }  
             printf( " ] DOF [ %3d", out->Nodes->reducedDegreeOfFreedom[out->Elements->Nodes[INDEX2(ref[0],i,M)]] );  
             for( j=1; j<N; j++ )  
                 printf( ", %3d", out->Nodes->reducedDegreeOfFreedom[out->Elements->Nodes[INDEX2(ref[j],i,M)]]);  
             printf( " ]\n" );    
         }  
   
         printf( "\nFace Elements\n=================================================\n\n" );  
         printf( "\t%d internal\n\t%d boundary\n\t%d local\n", out->FaceElements->elementDistribution->numInternal, out->FaceElements->elementDistribution->numBoundary, out->FaceElements->elementDistribution->numLocal );  
         N = out->FaceElements->LinearReferenceElement->Type->numNodes;  
         M = out->FaceElements->ReferenceElement->Type->numNodes;  
         ref = out->FaceElements->ReferenceElement->Type->linearNodes;  
         for( i=0; i<out->FaceElements->numElements; i++ ){  
             printf( "face element %d \t: id %d  \t: dom %d  \t: nodes [ %3d", i, out->FaceElements->Id[i], out->FaceElements->Dom[i], out->Nodes->toReduced[out->FaceElements->Nodes[INDEX2(ref[0],i,M)]] );  
             for( j=1; j<N; j++ )  
                 printf( ", %3d", out->Nodes->toReduced[out->FaceElements->Nodes[INDEX2(j,i,M)]]  );  
             printf( " ] DOF [ %3d", out->Nodes->reducedDegreeOfFreedom[out->FaceElements->Nodes[INDEX2(ref[0],i,M)]]);    
             for( j=1; j<N; j++ )  
                 printf( ", %3d", out->Nodes->reducedDegreeOfFreedom[out->FaceElements->Nodes[INDEX2(j,i,M)]]);    
             printf( " ]\n" );    
         }  
167    
         printf( "\nDistribution Data\n==================\n\n" );  
         Finley_NodeDistribution_print( out->Nodes->reducedDegreeOfFreedomDistribution, stdout );  
     }  
168  }  }
 #endif  
 /*  
 * $Log$  
 * Revision 1.6  2005/09/15 03:44:22  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:19  gross  
 * the solver from finley are put into the standalone package paso now  
 *  
 * Revision 1.5  2005/07/08 04:07:51  jgs  
 * Merge of development branch back to main trunk on 2005-07-08  
 *  
 * Revision 1.4  2004/12/15 07:08:32  jgs  
 * *** empty log message ***  
 * Revision 1.1.1.1.2.3  2005/06/29 02:34:51  gross  
 * some changes towards 64 integers in finley  
 *  
 * Revision 1.1.1.1.2.2  2004/11/24 01:37:13  gross  
 * some changes dealing with the integer overflow in memory allocation. Finley solves 4M unknowns now  
 *  
 *  
 *  
 */  

Legend:
Removed from v.1044  
changed lines
  Added in v.3981

  ViewVC Help
Powered by ViewVC 1.1.26