/[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 934 - (show annotations)
Tue Jan 23 09:52:45 2007 UTC (12 years, 2 months ago) by gross
File size: 8999 byte(s)
gmsh file reader for finley
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 {
34 //
35 // create a copy of the filename to overcome the non-constness of call
36 // to Finley_Mesh_read
37 Finley_Mesh* fMesh=0;
38 // Win32 refactor
39 char *fName = ((fileName.size()+1)>0) ? TMPMEMALLOC((fileName.size()+1),char) : (char*)NULL;
40 strcpy(fName,fileName.c_str());
41
42 #ifndef PASO_MPI
43 fMesh=Finley_Mesh_read(fName,integrationOrder);
44 #else
45 {
46 stringstream temp;
47 temp << "Unable to read meshes from file under MPI yet...";
48 setFinleyError(VALUE_ERROR,temp.str().c_str());
49 }
50 #endif
51 checkFinleyError();
52 AbstractContinuousDomain* temp=new MeshAdapter(fMesh);
53
54 /* win32 refactor */
55 TMPMEMFREE(fName);
56
57 return temp;
58 }
59
60 AbstractContinuousDomain* readGmsh(const std::string& fileName,
61 int numDim,
62 int integrationOrder,
63 int reducedIntegrationOrder,
64 bool optimizeLabeling)
65 {
66 //
67 // create a copy of the filename to overcome the non-constness of call
68 // to Finley_Mesh_read
69 Finley_Mesh* fMesh=0;
70 // Win32 refactor
71 char *fName = ((fileName.size()+1)>0) ? TMPMEMALLOC((fileName.size()+1),char) : (char*)NULL;
72 strcpy(fName,fileName.c_str());
73
74 #ifndef PASO_MPI
75 fMesh=Finley_Mesh_readGmsh(fName, numDim, integrationOrder, reducedIntegrationOrder, optimizeLabeling);
76 #else
77 {
78 stringstream temp;
79 temp << "Unable to read gmsh meshes from file under MPI yet...";
80 setFinleyError(VALUE_ERROR,temp.str().c_str());
81 }
82 #endif
83 checkFinleyError();
84 AbstractContinuousDomain* temp=new MeshAdapter(fMesh);
85
86 /* win32 refactor */
87 TMPMEMFREE(fName);
88
89 return temp;
90 }
91
92 AbstractContinuousDomain* brick(int n0,int n1,int n2,int order,
93 double l0,double l1,double l2,
94 int periodic0,int periodic1,
95 int periodic2,
96 int integrationOrder,
97 int useElementsOnFace)
98 {
99 // cout << "n0=" << n0 << " n1=" << n1 << " n2=" << n2
100 // << " order=" << order
101 // << " l0=" << l0 << " l1=" << l1 << " l2=" << l2
102 // << " periodic0=" << periodic0
103 // << " periodic1=" << periodic1
104 // << " periodic2=" << periodic2
105 // << " integerationOrder=" << integrationOrder
106 // << " useElementsOnFace=" << useElementsOnFace << endl;
107
108 int numElements[]={n0,n1,n2};
109 double length[]={l0,l1,l2};
110 int periodic[]={periodic0, periodic1, periodic2};
111
112 //
113 // linearInterpolation
114 Finley_Mesh* fMesh=NULL;
115
116 if (order==1) {
117 fMesh=Finley_RectangularMesh_Hex8(numElements,length,periodic,integrationOrder,
118 useElementsOnFace) ;
119 }
120 else if (order==2) {
121 fMesh=Finley_RectangularMesh_Hex20(numElements,length,periodic,integrationOrder,
122 useElementsOnFace) ;
123 } else {
124 stringstream temp;
125 temp << "Illegal interpolation order: " << order;
126 setFinleyError(VALUE_ERROR,temp.str().c_str());
127 }
128 //
129 // Convert any finley errors into a C++ exception
130 checkFinleyError();
131 AbstractContinuousDomain* temp=new MeshAdapter(fMesh);
132 return temp;
133 }
134 AbstractContinuousDomain* rectangle(int n0,int n1,int order,
135 double l0, double l1,
136 int periodic0,int periodic1,
137 int integrationOrder,
138 int useElementsOnFace)
139 {
140 int numElements[]={n0,n1};
141 double length[]={l0,l1};
142 int periodic[]={periodic0, periodic1};
143
144 Finley_Mesh* fMesh=0;
145 if (order==1) {
146 fMesh=Finley_RectangularMesh_Rec4(numElements, length,periodic,integrationOrder,
147 useElementsOnFace);
148 }
149 else if (order==2) {
150 fMesh=Finley_RectangularMesh_Rec8(numElements,length,periodic,integrationOrder,
151 useElementsOnFace);
152 }
153 else {
154 stringstream temp;
155 temp << "Illegal interpolation order: " << order;
156 setFinleyError(VALUE_ERROR,temp.str().c_str());
157 }
158 //
159 // Convert any finley errors into a C++ exception
160 checkFinleyError();
161 AbstractContinuousDomain* temp=new MeshAdapter(fMesh);
162 return temp;
163 }
164 AbstractContinuousDomain* interval(int n0,int order,double l0,int periodic0,
165 int integrationOrder,
166 int useElementsOnFace)
167 {
168 int numElements[]={n0};
169 double length[]={l0};
170 int periodic[]={periodic0};
171 Finley_Mesh* fMesh;
172 if (order==1) {
173 fMesh=Finley_RectangularMesh_Line2(numElements, length,periodic,integrationOrder,
174 useElementsOnFace);
175 }
176 else if (order==2) {
177 fMesh=Finley_RectangularMesh_Line3(numElements,length,periodic,integrationOrder,
178 useElementsOnFace);
179 }
180 else {
181 stringstream temp;
182 temp << "Illegal interpolation order: " << order;
183 setFinleyError(VALUE_ERROR,temp.str().c_str());
184 }
185 //
186 // Convert any finley errors into a C++ exception
187 checkFinleyError();
188 AbstractContinuousDomain* temp=new MeshAdapter(fMesh);
189 return temp;
190 }
191 AbstractContinuousDomain* meshMerge(const boost::python::list& meshList)
192 {
193 Finley_Mesh* fMesh=0;
194 //
195 // extract the meshes from meshList
196 #ifndef PASO_MPI
197 int numMsh=boost::python::extract<int>(meshList.attr("__len__")());
198 Finley_Mesh **mshes = (numMsh) ? TMPMEMALLOC(numMsh,Finley_Mesh*) : (Finley_Mesh**)NULL;
199 for (int i=0;i<numMsh;++i) {
200 AbstractContinuousDomain& meshListMember=boost::python::extract<AbstractContinuousDomain&>(meshList[i]);
201 const MeshAdapter* finley_meshListMember=static_cast<const MeshAdapter*>(&meshListMember);
202 mshes[i]=finley_meshListMember->getFinley_Mesh();
203 }
204 //
205 // merge the meshes:
206 fMesh=Finley_Mesh_merge(numMsh,mshes);
207 TMPMEMFREE(mshes);
208 #else
209 {
210 stringstream temp;
211 temp << "meshMerge() not available in MPI yet...";
212 setFinleyError(VALUE_ERROR,temp.str().c_str());
213 }
214 #endif
215 //
216 // Convert any finley errors into a C++ exception
217 checkFinleyError();
218 AbstractContinuousDomain* temp=new MeshAdapter(fMesh);
219
220 return temp;
221 }
222 AbstractContinuousDomain* glueFaces(const boost::python::list& meshList,
223 double safety_factor,
224 double tolerance)
225 {
226 Finley_Mesh* fMesh=0;
227 #ifndef PASO_MPI
228 //
229 // merge the meshes:
230 AbstractContinuousDomain* merged_meshes=meshMerge(meshList);
231 //
232 // glue the faces:
233 const MeshAdapter* merged_finley_meshes=static_cast<const MeshAdapter*>(merged_meshes);
234 fMesh=merged_finley_meshes->getFinley_Mesh();
235 Finley_Mesh_glueFaces(fMesh,safety_factor,tolerance);
236
237 //
238 // Convert any finley errors into a C++ exception
239 checkFinleyError();
240 return merged_meshes;
241 #else
242 {
243 stringstream temp;
244 temp << "glueFaces() not available in MPI yet...";
245 setFinleyError(VALUE_ERROR,temp.str().c_str());
246 }
247
248 //
249 // Convert any finley errors into a C++ exception
250 checkFinleyError();
251 return (AbstractContinuousDomain*)0;
252 #endif
253
254 }
255 AbstractContinuousDomain* joinFaces(const boost::python::list& meshList,
256 double safety_factor,
257 double tolerance)
258 {
259 Finley_Mesh* fMesh=0;
260 //
261 // merge the meshes:
262 #ifndef PASO_MPI
263 AbstractContinuousDomain* merged_meshes=meshMerge(meshList);
264 //
265 // join the faces:
266 const MeshAdapter* merged_finley_meshes=static_cast<const MeshAdapter*>(merged_meshes);
267 fMesh=merged_finley_meshes->getFinley_Mesh();
268 Finley_Mesh_joinFaces(fMesh,safety_factor,tolerance);
269 //
270 // Convert any finley errors into a C++ exception
271 checkFinleyError();
272 return merged_meshes;
273 #else
274 {
275 stringstream temp;
276 temp << "joinFaces() not available in MPI yet...";
277 setFinleyError(VALUE_ERROR,temp.str().c_str());
278 }
279 //
280 // Convert any finley errors into a C++ exception
281 checkFinleyError();
282 return (AbstractContinuousDomain*)0;
283
284 #endif
285 }
286
287 } // end of namespace

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26