/[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 1062 by gross, Mon Mar 26 06:17:53 2007 UTC branches/domexper/dudley/src/Mesh.c revision 3126 by jfenwick, Wed Sep 1 00:37:53 2010 UTC
# Line 1  Line 1 
1  /*  /*******************************************************
2   ************************************************************  *
3   *          Copyright 2006 by ACcESS MNRF                   *  * Copyright (c) 2003-2010 by University of Queensland
4   *                                                          *  * Earth Systems Science Computational Center (ESSCC)
5   *              http://www.access.edu.au                    *  * http://www.uq.edu.au/esscc
6   *       Primary Business: Queensland, Australia            *  *
7   *  Licensed under the Open Software License version 3.0    *  * Primary Business: Queensland, Australia
8   *     http://www.opensource.org/licenses/osl-3.0.php       *  * Licensed under the Open Software License version 3.0
9   *                                                          *  * http://www.opensource.org/licenses/osl-3.0.php
10   ************************************************************  *
11  */  *******************************************************/
   
   
 /**************************************************************/  
12    
 /*   Finley: Mesh */  
13    
14  /**************************************************************/  /**************************************************************/
15    
16  /*  Author: gross@access.edu.au */  /*   Dudley: Mesh */
 /*  Version: $Id$ */  
17    
18  /**************************************************************/  /**************************************************************/
19    
# Line 29  Line 24 
24  /*   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, */
25  /*   the most appropriate order is selected indepently. */  /*   the most appropriate order is selected indepently. */
26    
27  extern Finley_RefElementInfo Finley_RefElement_InfoList[];  Dudley_Mesh* Dudley_Mesh_alloc(char* name,dim_t numDim, Paso_MPIInfo *mpi_info)
   
 #ifndef PASO_MPI  
 Finley_Mesh* Finley_Mesh_alloc(char* name,dim_t numDim, index_t order, index_t reduced_order)  
 #else  
 Finley_Mesh* Finley_Mesh_alloc(char* name,dim_t numDim, index_t order, index_t reduced_order, Paso_MPIInfo *mpi_info)  
 #endif  
28  {  {
29    Finley_Mesh *out;    Dudley_Mesh *out;
30        
31    /*  allocate the return value */    /*  allocate the return value */
32        
33    out=MEMALLOC(1,Finley_Mesh);    out=MEMALLOC(1,Dudley_Mesh);
34    if (Finley_checkPtr(out)) return NULL;    if (Dudley_checkPtr(out)) return NULL;
35    out->Name=NULL;      out->Name=NULL;  
36    out->Nodes=NULL;    out->Nodes=NULL;
37    out->Elements=NULL;      out->Elements=NULL;  
38    out->FaceElements=NULL;    out->FaceElements=NULL;
39    out->Points=NULL;          out->Points=NULL;      
   out->ContactElements=NULL;        
40    out->TagMap=NULL;          out->TagMap=NULL;      
41    out->reference_counter=0;    out->reference_counter=0;
42    
# Line 56  Finley_Mesh* Finley_Mesh_alloc(char* nam Line 44  Finley_Mesh* Finley_Mesh_alloc(char* nam
44    out->FullReducedPattern=NULL;    out->FullReducedPattern=NULL;
45    out->ReducedFullPattern=NULL;    out->ReducedFullPattern=NULL;
46    out->ReducedReducedPattern=NULL;    out->ReducedReducedPattern=NULL;
   
 #ifdef PASO_MPI  
   out->MPIInfo = NULL;  
   
   /* get MPI info */  
47    out->MPIInfo = Paso_MPIInfo_getReference( mpi_info );    out->MPIInfo = Paso_MPIInfo_getReference( mpi_info );
48    if (! Finley_noError()) {    if (! Dudley_noError()) {
49        Finley_Mesh_dealloc(out);        Dudley_Mesh_free(out);
50        return NULL;        return NULL;
51    }    }
 #endif  
52    /*   copy name: */    /*   copy name: */
53        
54    out->Name=MEMALLOC(strlen(name)+1,char);    out->Name=MEMALLOC(strlen(name)+1,char);
55    if (Finley_checkPtr(out->Name)) {    if (Dudley_checkPtr(out->Name)) {
56        Finley_Mesh_dealloc(out);        Dudley_Mesh_free(out);
57        return NULL;        return NULL;
58    }    }
59    strcpy(out->Name,name);    strcpy(out->Name,name);
60        
61    /*   allocate node table: */    /*   allocate node table: */
62  #ifdef PASO_MPI    out->Nodes=Dudley_NodeFile_alloc( numDim, mpi_info );
63    out->Nodes=Finley_NodeFile_alloc( numDim, mpi_info );    if (! Dudley_noError()) {
64  #else        Dudley_Mesh_free(out);
   out->Nodes=Finley_NodeFile_alloc(numDim);  
 #endif  
   if (! Finley_noError()) {  
       Finley_Mesh_dealloc(out);  
65        return NULL;        return NULL;
66    }    }
67    out->order=order;    out->approximationOrder=-1;
68    out->reduced_order=reduced_order;    out->reducedApproximationOrder=-1;
69      out->integrationOrder=-1;
70      out->reducedIntegrationOrder=-1;
71    
72    out->Elements=NULL;    out->Elements=NULL;
73    out->FaceElements=NULL;    out->FaceElements=NULL;
74    out->Points=NULL;    out->Points=NULL;
   out->ContactElements=NULL;  
75    out->reference_counter++;    out->reference_counter++;
76    return out;    return out;
77  }  }
78    
79  /* returns a reference to Finley_Mesh in */  /* returns a reference to Dudley_Mesh in */
80    
81  Finley_Mesh* Finley_Mesh_reference(Finley_Mesh* in) {  Dudley_Mesh* Dudley_Mesh_reference(Dudley_Mesh* in) {
82       if (in!=NULL) ++(in->reference_counter);       if (in!=NULL) ++(in->reference_counter);
83       return in;       return in;
84  }  }
85    
86  /*   deallocates a mesh: */  /*   freeates a mesh: */
87    
88  void Finley_Mesh_dealloc(Finley_Mesh* in) {  void Dudley_Mesh_free(Dudley_Mesh* in) {
89    if (in!=NULL) {    if (in!=NULL) {
90       in->reference_counter--;       in->reference_counter--;
91       if (in->reference_counter<1) {       if (in->reference_counter<1) {
        #ifdef Finley_TRACE  
        if (in->Name!=NULL) {  
            printf("Finley_Mesh_dealloc: mesh %s is deallocated.\n",in->Name);  
        } else {  
            printf("Finley_Mesh_dealloc\n");  
        }  
        #endif  
92         MEMFREE(in->Name);         MEMFREE(in->Name);
93         Finley_NodeFile_dealloc(in->Nodes);         Dudley_NodeFile_free(in->Nodes);
94         Finley_ElementFile_dealloc(in->Elements);           Dudley_ElementFile_free(in->FaceElements);
95         Finley_ElementFile_dealloc(in->FaceElements);         Dudley_ElementFile_free(in->Elements);  
96         Finley_ElementFile_dealloc(in->ContactElements);         Dudley_ElementFile_free(in->Points);
97         Finley_ElementFile_dealloc(in->Points);         Dudley_TagMap_free(in->TagMap);
98         Finley_TagMap_free(in->TagMap);         Paso_SystemMatrixPattern_free(in->FullFullPattern);
99         Paso_SystemMatrixPattern_dealloc(in->FullFullPattern);         Paso_SystemMatrixPattern_free(in->FullReducedPattern);
100         Paso_SystemMatrixPattern_dealloc(in->FullReducedPattern);         Paso_SystemMatrixPattern_free(in->ReducedFullPattern);
101         Paso_SystemMatrixPattern_dealloc(in->ReducedFullPattern);         Paso_SystemMatrixPattern_free(in->ReducedReducedPattern);
102         Paso_SystemMatrixPattern_dealloc(in->ReducedReducedPattern);         Paso_MPIInfo_free( in->MPIInfo );
 #ifdef PASO_MPI  
        Paso_MPIInfo_dealloc( in->MPIInfo );  
 #endif  
103         MEMFREE(in);               MEMFREE(in);      
104       }       }
105    }    }
# Line 139  void Finley_Mesh_dealloc(Finley_Mesh* in Line 109  void Finley_Mesh_dealloc(Finley_Mesh* in
109    
110  /*  returns the spatial dimension of the mesh: */  /*  returns the spatial dimension of the mesh: */
111    
112  dim_t Finley_Mesh_getDim(Finley_Mesh *in) {  dim_t Dudley_Mesh_getDim(Dudley_Mesh *in) {
113    return in->Nodes->numDim;    return in->Nodes->numDim;
114  }  }
115    
116  /**************************************************************/  void Dudley_Mesh_setElements(Dudley_Mesh* self,Dudley_ElementFile *elements) {
117        Dudley_ElementFile_free(self->Elements);
118  /*  returns the number of nodes in the mesh: */      self->Elements=elements;
119    }
120  dim_t Finley_Mesh_getNumNodes(Finley_Mesh *in) {  void Dudley_Mesh_setFaceElements(Dudley_Mesh* self,Dudley_ElementFile *elements) {
121    return in->Nodes->numNodes;      Dudley_ElementFile_free(self->FaceElements);
122        self->FaceElements=elements;
123    }
124    void Dudley_Mesh_setPoints(Dudley_Mesh* self,Dudley_ElementFile *elements) {
125        Dudley_ElementFile_free(self->Points);
126        self->Points=elements;
127    }
128    int  Dudley_Mesh_getStatus(Dudley_Mesh* in) {
129       if  (in == NULL) {
130            return -1;
131       } else if (in->Nodes == NULL) {
132            return -1;
133       } else {
134            return in->Nodes->status;
135       }
136  }  }
 /**************************************************************/  
137    
138  /*  returns the number of degrees of freedom in the mesh: */  void Mesh_setOrders(Dudley_Mesh *in)
139    {
140       const dim_t order_max=9999999;
141       dim_t locals[4];
142       #ifdef PASO_MPI
143           dim_t globals[4];
144       #endif
145       locals[0]=order_max; locals[1]=order_max; locals[2]=order_max; locals[3]=order_max;
146    
147      if ( in->Elements!=NULL) {
148         if (in->Elements->numElements > 0) {
149             locals[0]=MIN(locals[0], in->Elements->referenceElementSet->referenceElement->BasisFunctions->Type->numOrder);
150             locals[1]=MIN(locals[1], in->Elements->referenceElementSet->referenceElement->LinearBasisFunctions->Type->numOrder);
151             locals[2]=MIN(locals[2], in->Elements->referenceElementSet->referenceElement->integrationOrder);
152             locals[3]=MIN(locals[3], in->Elements->referenceElementSet->referenceElementReducedQuadrature->integrationOrder);
153         }
154      }
155      if ( in->FaceElements!=NULL) {
156         if (in->FaceElements->numElements > 0) {
157             locals[0]=MIN(locals[0], in->FaceElements->referenceElementSet->referenceElement->BasisFunctions->Type->numOrder);
158             locals[1]=MIN(locals[1], in->FaceElements->referenceElementSet->referenceElement->LinearBasisFunctions->Type->numOrder);
159             locals[2]=MIN(locals[2], in->FaceElements->referenceElementSet->referenceElement->integrationOrder);
160             locals[3]=MIN(locals[3], in->FaceElements->referenceElementSet->referenceElementReducedQuadrature->integrationOrder);
161         }
162    
 dim_t Finley_Mesh_getNumDegreesOfFreedom(Finley_Mesh *in) {  
   return in->Nodes->numDegreesOfFreedom;  
 }  
 /**************************************************************/  
163    
164  /*  returns the number of degrees of freedom in the mesh: */    }
165    
166       #ifdef PASO_MPI
167           MPI_Allreduce( locals, globals, 4, MPI_INT, MPI_MIN, in->MPIInfo->comm );
168           in->approximationOrder=(globals[0] < order_max ? globals[0] : -1 );
169           in->reducedApproximationOrder=(globals[1] < order_max ? globals[1] : -1 );
170           in->integrationOrder=(globals[2] < order_max ? globals[2] : -1 );
171           in->reducedIntegrationOrder=(globals[3] < order_max ? globals[3] : -1 );
172       #else
173           in->approximationOrder=(locals[0] < order_max ? locals[0] : -1 );
174           in->reducedApproximationOrder=(locals[1] < order_max ? locals[1] : -1 );
175           in->integrationOrder=(locals[2] < order_max ? locals[2] : -1 );
176           in->reducedIntegrationOrder=(locals[3] < order_max ? locals[3] : -1 );
177       #endif
178    
 dim_t Finley_Mesh_getReducedNumDegreesOfFreedom(Finley_Mesh *in) {  
   return in->Nodes->reducedNumDegreesOfFreedom;  
 }  
179    
 #ifdef PASO_MPI  
 void print_mesh_statistics( Finley_Mesh *out, bool_t reduced )  
 {  
   index_t i, r, j, N, M, dim;  
     int *ref;    
     dim = out->Nodes->numDim;  
   
     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" );    
         }  
   
         printf( "\nDistribution Data\n==================\n\n" );  
         Finley_NodeDistribution_print( out->Nodes->reducedDegreeOfFreedomDistribution, stdout );  
     }  
180  }  }
181  #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.1062  
changed lines
  Added in v.3126

  ViewVC Help
Powered by ViewVC 1.1.26