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

revision 3163 by jfenwick, Tue Sep 7 05:30:39 2010 UTC revision 3247 by caltinay, Wed Oct 6 05:53:06 2010 UTC
# Line 10  Line 10 
10  *  *
11  *******************************************************/  *******************************************************/
12    
   
13  /**************************************************************/  /**************************************************************/
14    
15  /*   Dudley: Mesh */  /*   Dudley: Mesh */
# Line 24  Line 23 
23  /*   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, */
24  /*   the most appropriate order is selected indepently. */  /*   the most appropriate order is selected indepently. */
25    
26  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)
27  {  {
28    Dudley_Mesh *out;      Dudley_Mesh *out;
29      
30    /*  allocate the return value */      /*  allocate the return value */
31      
32    out=MEMALLOC(1,Dudley_Mesh);      out = MEMALLOC(1, Dudley_Mesh);
33    if (Dudley_checkPtr(out)) return NULL;      if (Dudley_checkPtr(out))
34    out->Name=NULL;        return NULL;
35    out->Nodes=NULL;      out->Name = NULL;
36    out->Elements=NULL;        out->Nodes = NULL;
37    out->FaceElements=NULL;      out->Elements = NULL;
38    out->Points=NULL;            out->FaceElements = NULL;
39    out->TagMap=NULL;            out->Points = NULL;
40    out->reference_counter=0;      out->TagMap = NULL;
41        out->reference_counter = 0;
42    out->FullFullPattern=NULL;  
43    out->FullReducedPattern=NULL;      out->FullFullPattern = NULL;
44    out->ReducedFullPattern=NULL;      out->FullReducedPattern = NULL;
45    out->ReducedReducedPattern=NULL;      out->ReducedFullPattern = NULL;
46    out->MPIInfo = Paso_MPIInfo_getReference( mpi_info );      out->ReducedReducedPattern = NULL;
47    if (! Dudley_noError()) {      out->MPIInfo = Esys_MPIInfo_getReference(mpi_info);
48        Dudley_Mesh_free(out);      if (!Dudley_noError())
49        return NULL;      {
50    }      Dudley_Mesh_free(out);
51    /*   copy name: */      return NULL;
52          }
53    out->Name=MEMALLOC(strlen(name)+1,char);      /*   copy name: */
54    if (Dudley_checkPtr(out->Name)) {  
55        Dudley_Mesh_free(out);      out->Name = MEMALLOC(strlen(name) + 1, char);
56        return NULL;      if (Dudley_checkPtr(out->Name))
57    }      {
58    strcpy(out->Name,name);      Dudley_Mesh_free(out);
59          return NULL;
60    /*   allocate node table: */      }
61    out->Nodes=Dudley_NodeFile_alloc( numDim, mpi_info );      strcpy(out->Name, name);
62    if (! Dudley_noError()) {  
63        Dudley_Mesh_free(out);      /*   allocate node table: */
64        return NULL;      out->Nodes = Dudley_NodeFile_alloc(numDim, mpi_info);
65    }      if (!Dudley_noError())
66    out->approximationOrder=-1;      {
67    out->reducedApproximationOrder=-1;      Dudley_Mesh_free(out);
68    out->integrationOrder=-1;      return NULL;
69    out->reducedIntegrationOrder=-1;      }
70        out->approximationOrder = -1;
71    out->Elements=NULL;      out->reducedApproximationOrder = -1;
72    out->FaceElements=NULL;      out->integrationOrder = -1;
73    out->Points=NULL;      out->reducedIntegrationOrder = -1;
74    out->reference_counter++;  
75    return out;      out->Elements = NULL;
76        out->FaceElements = NULL;
77        out->Points = NULL;
78        out->reference_counter++;
79        return out;
80  }  }
81    
82  /* returns a reference to Dudley_Mesh in */  /* returns a reference to Dudley_Mesh in */
83    
84  Dudley_Mesh* Dudley_Mesh_reference(Dudley_Mesh* in) {  Dudley_Mesh *Dudley_Mesh_reference(Dudley_Mesh * in)
85       if (in!=NULL) ++(in->reference_counter);  {
86       return in;      if (in != NULL)
87  }      ++(in->reference_counter);
88        return in;
89  /*   freeates a mesh: */  }
90    
91  void Dudley_Mesh_free(Dudley_Mesh* in) {  /*   frees a mesh: */
92    if (in!=NULL) {  
93       in->reference_counter--;  void Dudley_Mesh_free(Dudley_Mesh * in)
94       if (in->reference_counter<1) {  {
95         MEMFREE(in->Name);      if (in != NULL)
96         Dudley_NodeFile_free(in->Nodes);      {
97         Dudley_ElementFile_free(in->FaceElements);      in->reference_counter--;
98         Dudley_ElementFile_free(in->Elements);        if (in->reference_counter < 1)
99         Dudley_ElementFile_free(in->Points);      {
100         Dudley_TagMap_free(in->TagMap);          MEMFREE(in->Name);
101         Paso_SystemMatrixPattern_free(in->FullFullPattern);          Dudley_NodeFile_free(in->Nodes);
102         Paso_SystemMatrixPattern_free(in->FullReducedPattern);          Dudley_ElementFile_free(in->FaceElements);
103         Paso_SystemMatrixPattern_free(in->ReducedFullPattern);          Dudley_ElementFile_free(in->Elements);
104         Paso_SystemMatrixPattern_free(in->ReducedReducedPattern);          Dudley_ElementFile_free(in->Points);
105         Paso_MPIInfo_free( in->MPIInfo );          Dudley_TagMap_free(in->TagMap);
106         MEMFREE(in);                Paso_SystemMatrixPattern_free(in->FullFullPattern);
107       }          Paso_SystemMatrixPattern_free(in->FullReducedPattern);
108    }          Paso_SystemMatrixPattern_free(in->ReducedFullPattern);
109            Paso_SystemMatrixPattern_free(in->ReducedReducedPattern);
110            Esys_MPIInfo_free(in->MPIInfo);
111            MEMFREE(in);
112        }
113        }
114  }  }
115    
116  /**************************************************************/  /**************************************************************/
117    
118  /*  returns the spatial dimension of the mesh: */  /*  returns the spatial dimension of the mesh: */
119    
120  dim_t Dudley_Mesh_getDim(Dudley_Mesh *in) {  dim_t Dudley_Mesh_getDim(Dudley_Mesh * in)
121    return in->Nodes->numDim;  {
122        return in->Nodes->numDim;
123  }  }
124    
125  void Dudley_Mesh_setElements(Dudley_Mesh* self,Dudley_ElementFile *elements) {  void Dudley_Mesh_setElements(Dudley_Mesh * self, Dudley_ElementFile * elements)
126    {
127      Dudley_ElementFile_free(self->Elements);      Dudley_ElementFile_free(self->Elements);
128      self->Elements=elements;      self->Elements = elements;
129  }  }
130  void Dudley_Mesh_setFaceElements(Dudley_Mesh* self,Dudley_ElementFile *elements) {  
131    void Dudley_Mesh_setFaceElements(Dudley_Mesh * self, Dudley_ElementFile * elements)
132    {
133      Dudley_ElementFile_free(self->FaceElements);      Dudley_ElementFile_free(self->FaceElements);
134      self->FaceElements=elements;      self->FaceElements = elements;
135  }  }
136  void Dudley_Mesh_setPoints(Dudley_Mesh* self,Dudley_ElementFile *elements) {  
137    void Dudley_Mesh_setPoints(Dudley_Mesh * self, Dudley_ElementFile * elements)
138    {
139      Dudley_ElementFile_free(self->Points);      Dudley_ElementFile_free(self->Points);
140      self->Points=elements;      self->Points = elements;
141  }  }
 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  
142    
143    int Dudley_Mesh_getStatus(Dudley_Mesh * in)
144    {
145        if (in == NULL)
146        {
147        return -1;
148        }
149        else if (in->Nodes == NULL)
150        {
151        return -1;
152        }
153        else
154        {
155        return in->Nodes->status;
156        }
157    }
158    
159    void Dudley_Mesh_setOrders(Dudley_Mesh * in)
160    {
161        in->approximationOrder = 1; // order of shapeFunctions is always 1 in Dudley
162        in->reducedApproximationOrder = 1;
163        in->integrationOrder = 2;
164        in->reducedIntegrationOrder = 0;
165    
166  }  }
     

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

  ViewVC Help
Powered by ViewVC 1.1.26