/[escript]/trunk/finley/src/CPPAdapter/MeshAdapterFactory.cpp
ViewVC logotype

Contents of /trunk/finley/src/CPPAdapter/MeshAdapterFactory.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1062 - (show annotations)
Mon Mar 26 06:17:53 2007 UTC (12 years, 3 months ago) by gross
File size: 9683 byte(s)
reduced integration schemes are implemented now for grad, integrate, etc. Tests still to be added.
1 /* $Id$ */
2 /*
3 ******************************************************************************
4 * *
5 * COPYRIGHT ACcESS 2004 - All Rights Reserved *
6 * *
7 * This software is the property of ACcESS. No part of this code *
8 * may be copied in any form or by any means without the expressed written *
9 * consent of ACcESS. Copying, use or modification of this software *
10 * by any unauthorised person is illegal unless that person has a software *
11 * license agreement with ACcESS. *
12 * *
13 ******************************************************************************
14 */
15
16 #ifdef PASO_MPI
17 #include <mpi.h>
18 #endif
19 #include "MeshAdapterFactory.h"
20 #include "FinleyError.h"
21
22 #include <boost/python/extract.hpp>
23
24 #include <sstream>
25
26 using namespace std;
27 using namespace escript;
28
29 namespace finley {
30
31 AbstractContinuousDomain* readMesh(const std::string& fileName,
32 int integrationOrder,
33 int reducedIntegrationOrder,
34 bool optimizeLabeling)
35 {
36 //
37 // create a copy of the filename to overcome the non-constness of call
38 // to Finley_Mesh_read
39 Finley_Mesh* fMesh=0;
40 // Win32 refactor
41 char *fName = ((fileName.size()+1)>0) ? TMPMEMALLOC((fileName.size()+1),char) : (char*)NULL;
42 strcpy(fName,fileName.c_str());
43
44 #ifndef PASO_MPI
45 fMesh=Finley_Mesh_read(fName,integrationOrder, reducedIntegrationOrder, (optimizeLabeling ? TRUE : FALSE));
46 #else
47 {
48 stringstream temp;
49 temp << "Unable to read meshes from file under MPI yet...";
50 setFinleyError(VALUE_ERROR,temp.str().c_str());
51 }
52 #endif
53 checkFinleyError();
54 AbstractContinuousDomain* temp=new MeshAdapter(fMesh);
55
56 /* win32 refactor */
57 TMPMEMFREE(fName);
58
59 return temp;
60 }
61
62 AbstractContinuousDomain* readGmsh(const std::string& fileName,
63 int numDim,
64 int integrationOrder,
65 int reducedIntegrationOrder,
66 bool optimizeLabeling)
67 {
68 //
69 // create a copy of the filename to overcome the non-constness of call
70 // to Finley_Mesh_read
71 Finley_Mesh* fMesh=0;
72 // Win32 refactor
73 char *fName = ((fileName.size()+1)>0) ? TMPMEMALLOC((fileName.size()+1),char) : (char*)NULL;
74 strcpy(fName,fileName.c_str());
75
76 #ifndef PASO_MPI
77 fMesh=Finley_Mesh_readGmsh(fName, numDim, integrationOrder, reducedIntegrationOrder, (optimizeLabeling ? TRUE : FALSE));
78 #else
79 {
80 stringstream temp;
81 temp << "Unable to read gmsh meshes from file under MPI yet...";
82 setFinleyError(VALUE_ERROR,temp.str().c_str());
83 }
84 #endif
85 checkFinleyError();
86 AbstractContinuousDomain* temp=new MeshAdapter(fMesh);
87
88 /* win32 refactor */
89 TMPMEMFREE(fName);
90
91 return temp;
92 }
93
94 AbstractContinuousDomain* brick(int n0,int n1,int n2,int order,
95 double l0,double l1,double l2,
96 int periodic0,int periodic1,
97 int periodic2,
98 int integrationOrder,
99 int reducedIntegrationOrder,
100 int useElementsOnFace)
101 {
102 // cout << "n0=" << n0 << " n1=" << n1 << " n2=" << n2
103 // << " order=" << order
104 // << " l0=" << l0 << " l1=" << l1 << " l2=" << l2
105 // << " periodic0=" << periodic0
106 // << " periodic1=" << periodic1
107 // << " periodic2=" << periodic2
108 // << " integerationOrder=" << integrationOrder
109 // << " useElementsOnFace=" << useElementsOnFace << endl;
110
111 int numElements[]={n0,n1,n2};
112 double length[]={l0,l1,l2};
113 int periodic[]={periodic0, periodic1, periodic2};
114
115 //
116 // linearInterpolation
117 Finley_Mesh* fMesh=NULL;
118
119 if (order==1) {
120 fMesh=Finley_RectangularMesh_Hex8(numElements,length,periodic,integrationOrder,reducedIntegrationOrder,
121 useElementsOnFace) ;
122 }
123 else if (order==2) {
124 fMesh=Finley_RectangularMesh_Hex20(numElements,length,periodic,integrationOrder,reducedIntegrationOrder,
125 useElementsOnFace) ;
126 } else {
127 stringstream temp;
128 temp << "Illegal interpolation order: " << order;
129 setFinleyError(VALUE_ERROR,temp.str().c_str());
130 }
131 //
132 // Convert any finley errors into a C++ exception
133 checkFinleyError();
134 AbstractContinuousDomain* temp=new MeshAdapter(fMesh);
135 return temp;
136 }
137 AbstractContinuousDomain* rectangle(int n0,int n1,int order,
138 double l0, double l1,
139 int periodic0,int periodic1,
140 int integrationOrder,
141 int reducedIntegrationOrder,
142 int useElementsOnFace)
143 {
144 int numElements[]={n0,n1};
145 double length[]={l0,l1};
146 int periodic[]={periodic0, periodic1};
147
148 Finley_Mesh* fMesh=0;
149 if (order==1) {
150 fMesh=Finley_RectangularMesh_Rec4(numElements, length,periodic,integrationOrder,reducedIntegrationOrder,
151 useElementsOnFace);
152 }
153 else if (order==2) {
154 fMesh=Finley_RectangularMesh_Rec8(numElements,length,periodic,integrationOrder,reducedIntegrationOrder,
155 useElementsOnFace);
156 }
157 else {
158 stringstream temp;
159 temp << "Illegal interpolation order: " << order;
160 setFinleyError(VALUE_ERROR,temp.str().c_str());
161 }
162 //
163 // Convert any finley errors into a C++ exception
164 checkFinleyError();
165 AbstractContinuousDomain* temp=new MeshAdapter(fMesh);
166 return temp;
167 }
168 AbstractContinuousDomain* interval(int n0,int order,double l0,int periodic0,
169 int integrationOrder,
170 int reducedIntegrationOrder,
171 int useElementsOnFace)
172 {
173 int numElements[]={n0};
174 double length[]={l0};
175 int periodic[]={periodic0};
176 Finley_Mesh* fMesh;
177 if (order==1) {
178 fMesh=Finley_RectangularMesh_Line2(numElements, length,periodic,integrationOrder,reducedIntegrationOrder,
179 useElementsOnFace);
180 }
181 else if (order==2) {
182 fMesh=Finley_RectangularMesh_Line3(numElements,length,periodic,integrationOrder,reducedIntegrationOrder,
183 useElementsOnFace);
184 }
185 else {
186 stringstream temp;
187 temp << "Illegal interpolation order: " << order;
188 setFinleyError(VALUE_ERROR,temp.str().c_str());
189 }
190 //
191 // Convert any finley errors into a C++ exception
192 checkFinleyError();
193 AbstractContinuousDomain* temp=new MeshAdapter(fMesh);
194 return temp;
195 }
196
197 AbstractContinuousDomain* meshMerge(const boost::python::list& meshList)
198 {
199 Finley_Mesh* fMesh=0;
200 //
201 // extract the meshes from meshList
202 #ifndef PASO_MPI
203 int numMsh=boost::python::extract<int>(meshList.attr("__len__")());
204 Finley_Mesh **mshes = (numMsh) ? TMPMEMALLOC(numMsh,Finley_Mesh*) : (Finley_Mesh**)NULL;
205 for (int i=0;i<numMsh;++i) {
206 AbstractContinuousDomain& meshListMember=boost::python::extract<AbstractContinuousDomain&>(meshList[i]);
207 const MeshAdapter* finley_meshListMember=static_cast<const MeshAdapter*>(&meshListMember);
208 mshes[i]=finley_meshListMember->getFinley_Mesh();
209 }
210 //
211 // merge the meshes:
212 fMesh=Finley_Mesh_merge(numMsh,mshes);
213 TMPMEMFREE(mshes);
214 #else
215 {
216 stringstream temp;
217 temp << "meshMerge() not available in MPI yet...";
218 setFinleyError(VALUE_ERROR,temp.str().c_str());
219 }
220 #endif
221 //
222 // Convert any finley errors into a C++ exception
223 checkFinleyError();
224 AbstractContinuousDomain* temp=new MeshAdapter(fMesh);
225
226 return temp;
227 }
228 AbstractContinuousDomain* glueFaces(const boost::python::list& meshList,
229 double safety_factor,
230 double tolerance,
231 bool optimizeLabeling)
232 {
233 Finley_Mesh* fMesh=0;
234 #ifndef PASO_MPI
235 //
236 // merge the meshes:
237 AbstractContinuousDomain* merged_meshes=meshMerge(meshList);
238 //
239 // glue the faces:
240 const MeshAdapter* merged_finley_meshes=static_cast<const MeshAdapter*>(merged_meshes);
241 fMesh=merged_finley_meshes->getFinley_Mesh();
242 Finley_Mesh_glueFaces(fMesh,safety_factor,tolerance,(optimizeLabeling ? TRUE : FALSE));
243
244 //
245 // Convert any finley errors into a C++ exception
246 checkFinleyError();
247 return merged_meshes;
248 #else
249 {
250 stringstream temp;
251 temp << "glueFaces() not available in MPI yet...";
252 setFinleyError(VALUE_ERROR,temp.str().c_str());
253 }
254
255 //
256 // Convert any finley errors into a C++ exception
257 checkFinleyError();
258 return (AbstractContinuousDomain*)0;
259 #endif
260
261 }
262 AbstractContinuousDomain* joinFaces(const boost::python::list& meshList,
263 double safety_factor,
264 double tolerance,
265 bool optimizeLabeling)
266 {
267 Finley_Mesh* fMesh=0;
268 //
269 // merge the meshes:
270 #ifndef PASO_MPI
271 AbstractContinuousDomain* merged_meshes=meshMerge(meshList);
272 //
273 // join the faces:
274 const MeshAdapter* merged_finley_meshes=static_cast<const MeshAdapter*>(merged_meshes);
275 fMesh=merged_finley_meshes->getFinley_Mesh();
276 Finley_Mesh_joinFaces(fMesh,safety_factor,tolerance, (optimizeLabeling ? TRUE : FALSE));
277 //
278 // Convert any finley errors into a C++ exception
279 checkFinleyError();
280 return merged_meshes;
281 #else
282 {
283 stringstream temp;
284 temp << "joinFaces() not available in MPI yet...";
285 setFinleyError(VALUE_ERROR,temp.str().c_str());
286 }
287 //
288 // Convert any finley errors into a C++ exception
289 checkFinleyError();
290 return (AbstractContinuousDomain*)0;
291
292 #endif
293 }
294
295 // end of namespace
296
297 }

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26