/[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

branches/domexper/dudley/src/Mesh.c revision 3163 by jfenwick, Tue Sep 7 05:30:39 2010 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 (c) 2003-2010 by University of Queensland  * Copyright (c) 2003-2012 by University of Queensland
4  * Earth Systems Science Computational Center (ESSCC)  * http://www.uq.edu.au
 * http://www.uq.edu.au/esscc  
5  *  *
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    *****************************************************************************/
14    
15  /**************************************************************/  /************************************************************************************/
16    
17  /*   Dudley: Mesh */  /*   Dudley: Mesh */
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  Dudley_Mesh* Dudley_Mesh_alloc(char* name,dim_t numDim, Paso_MPIInfo *mpi_info)  Dudley_Mesh *Dudley_Mesh_alloc(char *name, dim_t numDim, Esys_MPIInfo * mpi_info)
29  {  {
30    Dudley_Mesh *out;      Dudley_Mesh *out;
31      
32    /*  allocate the return value */      /*  allocate the return value */
33      
34    out=MEMALLOC(1,Dudley_Mesh);      out = MEMALLOC(1, Dudley_Mesh);
35    if (Dudley_checkPtr(out)) return NULL;      if (Dudley_checkPtr(out))
36    out->Name=NULL;        return NULL;
37    out->Nodes=NULL;      out->Name = NULL;
38    out->Elements=NULL;        out->Nodes = NULL;
39    out->FaceElements=NULL;      out->Elements = NULL;
40    out->Points=NULL;            out->FaceElements = NULL;
41    out->TagMap=NULL;            out->Points = NULL;
42    out->reference_counter=0;      out->TagMap = NULL;
43        out->reference_counter = 0;
44    out->FullFullPattern=NULL;  
45    out->FullReducedPattern=NULL;      out->FullFullPattern = NULL;
46    out->ReducedFullPattern=NULL;      out->FullReducedPattern = NULL;
47    out->ReducedReducedPattern=NULL;      out->ReducedFullPattern = NULL;
48    out->MPIInfo = Paso_MPIInfo_getReference( mpi_info );      out->ReducedReducedPattern = NULL;
49    if (! Dudley_noError()) {      out->MPIInfo = Esys_MPIInfo_getReference(mpi_info);
50        Dudley_Mesh_free(out);      if (!Dudley_noError())
51        return NULL;      {
52    }      Dudley_Mesh_free(out);
53    /*   copy name: */      return NULL;
54          }
55    out->Name=MEMALLOC(strlen(name)+1,char);      /*   copy name: */
56    if (Dudley_checkPtr(out->Name)) {  
57        Dudley_Mesh_free(out);      out->Name = MEMALLOC(strlen(name) + 1, char);
58        return NULL;      if (Dudley_checkPtr(out->Name))
59    }      {
60    strcpy(out->Name,name);      Dudley_Mesh_free(out);
61          return NULL;
62    /*   allocate node table: */      }
63    out->Nodes=Dudley_NodeFile_alloc( numDim, mpi_info );      strcpy(out->Name, name);
64    if (! Dudley_noError()) {  
65        Dudley_Mesh_free(out);      /*   allocate node table: */
66        return NULL;      out->Nodes = Dudley_NodeFile_alloc(numDim, mpi_info);
67    }      if (!Dudley_noError())
68    out->approximationOrder=-1;      {
69    out->reducedApproximationOrder=-1;      Dudley_Mesh_free(out);
70    out->integrationOrder=-1;      return NULL;
71    out->reducedIntegrationOrder=-1;      }
72        out->approximationOrder = -1;
73    out->Elements=NULL;      out->reducedApproximationOrder = -1;
74    out->FaceElements=NULL;      out->integrationOrder = -1;
75    out->Points=NULL;      out->reducedIntegrationOrder = -1;
76    out->reference_counter++;  
77    return out;      out->Elements = NULL;
78        out->FaceElements = NULL;
79        out->Points = NULL;
80        out->reference_counter++;
81        return out;
82  }  }
83    
84  /* returns a reference to Dudley_Mesh in */  /* returns a reference to Dudley_Mesh in */
85    
86  Dudley_Mesh* Dudley_Mesh_reference(Dudley_Mesh* in) {  Dudley_Mesh *Dudley_Mesh_reference(Dudley_Mesh * in)
87       if (in!=NULL) ++(in->reference_counter);  {
88       return in;      if (in != NULL)
89  }      ++(in->reference_counter);
90        return in;
91  /*   freeates a mesh: */  }
92    
93  void Dudley_Mesh_free(Dudley_Mesh* in) {  /*   frees a mesh: */
94    if (in!=NULL) {  
95       in->reference_counter--;  void Dudley_Mesh_free(Dudley_Mesh * in)
96       if (in->reference_counter<1) {  {
97         MEMFREE(in->Name);      if (in != NULL)
98         Dudley_NodeFile_free(in->Nodes);      {
99         Dudley_ElementFile_free(in->FaceElements);      in->reference_counter--;
100         Dudley_ElementFile_free(in->Elements);        if (in->reference_counter < 1)
101         Dudley_ElementFile_free(in->Points);      {
102         Dudley_TagMap_free(in->TagMap);          MEMFREE(in->Name);
103         Paso_SystemMatrixPattern_free(in->FullFullPattern);          Dudley_NodeFile_free(in->Nodes);
104         Paso_SystemMatrixPattern_free(in->FullReducedPattern);          Dudley_ElementFile_free(in->FaceElements);
105         Paso_SystemMatrixPattern_free(in->ReducedFullPattern);          Dudley_ElementFile_free(in->Elements);
106         Paso_SystemMatrixPattern_free(in->ReducedReducedPattern);          Dudley_ElementFile_free(in->Points);
107         Paso_MPIInfo_free( in->MPIInfo );          Dudley_TagMap_free(in->TagMap);
108         MEMFREE(in);                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 spatial dimension of the mesh: */  /*  returns the spatial dimension of the mesh: */
121    
122  dim_t Dudley_Mesh_getDim(Dudley_Mesh *in) {  dim_t Dudley_Mesh_getDim(Dudley_Mesh * in)
123    return in->Nodes->numDim;  {
124        return in->Nodes->numDim;
125  }  }
126    
127  void Dudley_Mesh_setElements(Dudley_Mesh* self,Dudley_ElementFile *elements) {  void Dudley_Mesh_setElements(Dudley_Mesh * self, Dudley_ElementFile * elements)
128    {
129      Dudley_ElementFile_free(self->Elements);      Dudley_ElementFile_free(self->Elements);
130      self->Elements=elements;      self->Elements = elements;
131  }  }
132  void Dudley_Mesh_setFaceElements(Dudley_Mesh* self,Dudley_ElementFile *elements) {  
133    void Dudley_Mesh_setFaceElements(Dudley_Mesh * self, Dudley_ElementFile * elements)
134    {
135      Dudley_ElementFile_free(self->FaceElements);      Dudley_ElementFile_free(self->FaceElements);
136      self->FaceElements=elements;      self->FaceElements = elements;
137  }  }
138  void Dudley_Mesh_setPoints(Dudley_Mesh* self,Dudley_ElementFile *elements) {  
139    void Dudley_Mesh_setPoints(Dudley_Mesh * self, Dudley_ElementFile * elements)
140    {
141      Dudley_ElementFile_free(self->Points);      Dudley_ElementFile_free(self->Points);
142      self->Points=elements;      self->Points = elements;
143  }  }
 int  Dudley_Mesh_getStatus(Dudley_Mesh* in) {  
    if  (in == NULL) {  
         return -1;  
    } else if (in->Nodes == NULL) {  
         return -1;  
    } else {  
         return in->Nodes->status;  
    }  
 }  
   
 void Mesh_setOrders(Dudley_Mesh *in)  
 {  
    const dim_t order_max=9999999;  
    dim_t locals[3];  
    #ifdef PASO_MPI  
        dim_t globals[3];  
    #endif  
    locals[0]=order_max; locals[1]=order_max; locals[2]=order_max;  
   
   if ( in->Elements!=NULL) {  
      if (in->Elements->numElements > 0) {  
          locals[0]=MIN(locals[0], in->Elements->referenceElementSet->referenceElement->BasisFunctions->Type->numOrder);  
          locals[1]=MIN(locals[1], in->Elements->referenceElementSet->referenceElement->integrationOrder);  
          locals[2]=MIN(locals[2], in->Elements->referenceElementSet->referenceElementReducedQuadrature->integrationOrder);  
      }  
   }  
   if ( in->FaceElements!=NULL) {  
      if (in->FaceElements->numElements > 0) {  
          locals[0]=MIN(locals[0], in->FaceElements->referenceElementSet->referenceElement->BasisFunctions->Type->numOrder);  
          locals[1]=MIN(locals[1], in->FaceElements->referenceElementSet->referenceElement->integrationOrder);  
          locals[2]=MIN(locals[2], in->FaceElements->referenceElementSet->referenceElementReducedQuadrature->integrationOrder);  
      }  
   
   
   }  
   
    #ifdef PASO_MPI  
        MPI_Allreduce( locals, globals, 3, MPI_INT, MPI_MIN, in->MPIInfo->comm );  
        in->approximationOrder=(globals[0] < order_max ? globals[0] : -1 );  
        in->reducedApproximationOrder=in->approximationOrder;  
        in->integrationOrder=(globals[1] < order_max ? globals[1] : -1 );  
        in->reducedIntegrationOrder=(globals[2] < order_max ? globals[2] : -1 );  
    #else  
        in->approximationOrder=(locals[0] < order_max ? locals[0] : -1 );  
        in->reducedApproximationOrder=(locals[0] < order_max ? locals[0] : -1 );  
        in->integrationOrder=(locals[1] < order_max ? locals[1] : -1 );  
        in->reducedIntegrationOrder=(locals[2] < order_max ? locals[2] : -1 );  
    #endif  
144    
145    int Dudley_Mesh_getStatus(Dudley_Mesh * in)
146    {
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    void Dudley_Mesh_setOrders(Dudley_Mesh * in)
162    {
163        in->approximationOrder = 1; /* order of shapeFunctions is always 1 in Dudley */
164        in->reducedApproximationOrder = 1;
165        in->integrationOrder = 2;
166        in->reducedIntegrationOrder = 0;
167    
168  }  }
     

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

  ViewVC Help
Powered by ViewVC 1.1.26