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

Contents of /branches/doubleplusgood/finley/src/Mesh.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4257 - (show annotations)
Wed Feb 27 03:42:40 2013 UTC (6 years, 9 months ago) by jfenwick
Original Path: branches/doubleplusgood/finley/src/Mesh.c
File MIME type: text/plain
File size: 7037 byte(s)
Some simple experiments for c++ Finley

1 /*****************************************************************************
2 *
3 * Copyright (c) 2003-2013 by University of Queensland
4 * http://www.uq.edu.au
5 *
6 * Primary Business: Queensland, Australia
7 * Licensed under the Open Software License version 3.0
8 * 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
18 /* Finley: Mesh */
19
20 /************************************************************************************/
21
22 #include "Mesh.h"
23
24 /************************************************************************************/
25
26 /* allocates a Mesh with name name for elements of type id using an integration order. If order is negative, */
27 /* the most appropriate order is selected independently. */
28
29 Finley_Mesh* Finley_Mesh_alloc(char* name,dim_t numDim, Esys_MPIInfo *mpi_info)
30 {
31 Finley_Mesh *out;
32
33 /* allocate the return value */
34
35 out=MEMALLOC(1,Finley_Mesh);
36 if (Finley_checkPtr(out)) return NULL;
37 out->Name=NULL;
38 out->Nodes=NULL;
39 out->Elements=NULL;
40 out->FaceElements=NULL;
41 out->Points=NULL;
42 out->ContactElements=NULL;
43 out->TagMap=NULL;
44 out->reference_counter=0;
45
46 out->FullFullPattern=NULL;
47 out->FullReducedPattern=NULL;
48 out->ReducedFullPattern=NULL;
49 out->ReducedReducedPattern=NULL;
50 out->MPIInfo = Esys_MPIInfo_getReference( mpi_info );
51 if (! Finley_noError()) {
52 Finley_Mesh_free(out);
53 return NULL;
54 }
55 /* copy name: */
56
57 out->Name=MEMALLOC(strlen(name)+1,char);
58 if (Finley_checkPtr(out->Name)) {
59 Finley_Mesh_free(out);
60 return NULL;
61 }
62 strcpy(out->Name,name);
63
64 /* allocate node table: */
65 out->Nodes=Finley_NodeFile_alloc( numDim, mpi_info );
66 if (! Finley_noError()) {
67 Finley_Mesh_free(out);
68 return NULL;
69 }
70 out->approximationOrder=-1;
71 out->reducedApproximationOrder=-1;
72 out->integrationOrder=-1;
73 out->reducedIntegrationOrder=-1;
74
75 out->Elements=NULL;
76 out->FaceElements=NULL;
77 out->Points=NULL;
78 out->ContactElements=NULL;
79 out->reference_counter++;
80 return out;
81 }
82
83 /* returns a reference to Finley_Mesh in */
84
85 Finley_Mesh* Finley_Mesh_reference(Finley_Mesh* in) {
86 if (in!=NULL) ++(in->reference_counter);
87 return in;
88 }
89
90 /* frees a mesh: */
91
92 void Finley_Mesh_free(Finley_Mesh* in) {
93 if (in!=NULL) {
94 in->reference_counter--;
95 if (in->reference_counter<1) {
96 MEMFREE(in->Name);
97 Finley_NodeFile_free(in->Nodes);
98 Finley_ElementFile_free(in->FaceElements);
99 Finley_ElementFile_free(in->Elements);
100 Finley_ElementFile_free(in->ContactElements);
101 Finley_ElementFile_free(in->Points);
102 Finley_TagMap_free(in->TagMap);
103 Paso_SystemMatrixPattern_free(in->FullFullPattern);
104 Paso_SystemMatrixPattern_free(in->FullReducedPattern);
105 Paso_SystemMatrixPattern_free(in->ReducedFullPattern);
106 Paso_SystemMatrixPattern_free(in->ReducedReducedPattern);
107 Esys_MPIInfo_free( in->MPIInfo );
108 MEMFREE(in);
109 }
110 }
111 }
112
113 /************************************************************************************/
114
115 /* returns the spatial dimension of the mesh: */
116
117 dim_t Finley_Mesh_getDim(Finley_Mesh *in) {
118 return in->Nodes->numDim;
119 }
120
121 void Finley_Mesh_setElements(Finley_Mesh* self,Finley_ElementFile *elements) {
122 Finley_ElementFile_free(self->Elements);
123 self->Elements=elements;
124 }
125 void Finley_Mesh_setFaceElements(Finley_Mesh* self,Finley_ElementFile *elements) {
126 Finley_ElementFile_free(self->FaceElements);
127 self->FaceElements=elements;
128 }
129 void Finley_Mesh_setContactElements(Finley_Mesh* self,Finley_ElementFile *elements) {
130 Finley_ElementFile_free(self->ContactElements);
131 self->ContactElements=elements;
132 }
133 void Finley_Mesh_setPoints(Finley_Mesh* self,Finley_ElementFile *elements) {
134 Finley_ElementFile_free(self->Points);
135 self->Points=elements;
136 }
137 int Finley_Mesh_getStatus(Finley_Mesh* in) {
138 if (in == NULL) {
139 return -1;
140 } else if (in->Nodes == NULL) {
141 return -1;
142 } else {
143 return in->Nodes->status;
144 }
145 }
146
147 void Finley_Mesh_setOrders(Finley_Mesh *in)
148 {
149 const dim_t order_max=9999999;
150 dim_t locals[4];
151 #ifdef ESYS_MPI
152 dim_t globals[4];
153 #endif
154 locals[0]=order_max; locals[1]=order_max; locals[2]=order_max; locals[3]=order_max;
155
156 if ( in->Elements!=NULL) {
157 if (in->Elements->numElements > 0) {
158 locals[0]=MIN(locals[0], in->Elements->referenceElementSet->referenceElement->BasisFunctions->Type->numOrder);
159 locals[1]=MIN(locals[1], in->Elements->referenceElementSet->referenceElement->LinearBasisFunctions->Type->numOrder);
160 locals[2]=MIN(locals[2], in->Elements->referenceElementSet->referenceElement->integrationOrder);
161 locals[3]=MIN(locals[3], in->Elements->referenceElementSet->referenceElementReducedQuadrature->integrationOrder);
162 }
163 }
164 if ( in->FaceElements!=NULL) {
165 if (in->FaceElements->numElements > 0) {
166 locals[0]=MIN(locals[0], in->FaceElements->referenceElementSet->referenceElement->BasisFunctions->Type->numOrder);
167 locals[1]=MIN(locals[1], in->FaceElements->referenceElementSet->referenceElement->LinearBasisFunctions->Type->numOrder);
168 locals[2]=MIN(locals[2], in->FaceElements->referenceElementSet->referenceElement->integrationOrder);
169 locals[3]=MIN(locals[3], in->FaceElements->referenceElementSet->referenceElementReducedQuadrature->integrationOrder);
170 }
171
172
173 }
174 if ( in->ContactElements!=NULL) {
175 if (in->ContactElements->numElements > 0) {
176 locals[0]=MIN(locals[0], in->ContactElements->referenceElementSet->referenceElement->BasisFunctions->Type->numOrder);
177 locals[1]=MIN(locals[1], in->ContactElements->referenceElementSet->referenceElement->LinearBasisFunctions->Type->numOrder);
178 locals[2]=MIN(locals[2], in->ContactElements->referenceElementSet->referenceElement->integrationOrder);
179 locals[3]=MIN(locals[3], in->ContactElements->referenceElementSet->referenceElementReducedQuadrature->integrationOrder);
180 }
181
182 }
183
184 #ifdef ESYS_MPI
185 MPI_Allreduce( locals, globals, 4, MPI_INT, MPI_MIN, in->MPIInfo->comm );
186 in->approximationOrder=(globals[0] < order_max ? globals[0] : -1 );
187 in->reducedApproximationOrder=(globals[1] < order_max ? globals[1] : -1 );
188 in->integrationOrder=(globals[2] < order_max ? globals[2] : -1 );
189 in->reducedIntegrationOrder=(globals[3] < order_max ? globals[3] : -1 );
190 #else
191 in->approximationOrder=(locals[0] < order_max ? locals[0] : -1 );
192 in->reducedApproximationOrder=(locals[1] < order_max ? locals[1] : -1 );
193 in->integrationOrder=(locals[2] < order_max ? locals[2] : -1 );
194 in->reducedIntegrationOrder=(locals[3] < order_max ? locals[3] : -1 );
195 #endif
196
197
198 }
199

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.26