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

Contents of /branches/more_shared_ptrs_from_1812/finley/src/CPPAdapter/MeshAdapterFactory.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1059 - (show annotations)
Fri Mar 23 11:01:53 2007 UTC (13 years ago) by gross
Original Path: trunk/finley/src/CPPAdapter/MeshAdapterFactory.cpp
File size: 9374 byte(s)
first steps toward reduced element integration order. The escript bit is done but the finley part still needs work.
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);
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);
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,
121 useElementsOnFace) ;
122 }
123 else if (order==2) {
124 fMesh=Finley_RectangularMesh_Hex20(numElements,length,periodic,integrationOrder,
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,
151 useElementsOnFace);
152 }
153 else if (order==2) {
154 fMesh=Finley_RectangularMesh_Rec8(numElements,length,periodic,integrationOrder,
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,
179 useElementsOnFace);
180 }
181 else if (order==2) {
182 fMesh=Finley_RectangularMesh_Line3(numElements,length,periodic,integrationOrder,
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 AbstractContinuousDomain* meshMerge(const boost::python::list& meshList)
197 {
198 Finley_Mesh* fMesh=0;
199 //
200 // extract the meshes from meshList
201 #ifndef PASO_MPI
202 int numMsh=boost::python::extract<int>(meshList.attr("__len__")());
203 Finley_Mesh **mshes = (numMsh) ? TMPMEMALLOC(numMsh,Finley_Mesh*) : (Finley_Mesh**)NULL;
204 for (int i=0;i<numMsh;++i) {
205 AbstractContinuousDomain& meshListMember=boost::python::extract<AbstractContinuousDomain&>(meshList[i]);
206 const MeshAdapter* finley_meshListMember=static_cast<const MeshAdapter*>(&meshListMember);
207 mshes[i]=finley_meshListMember->getFinley_Mesh();
208 }
209 //
210 // merge the meshes:
211 fMesh=Finley_Mesh_merge(numMsh,mshes);
212 TMPMEMFREE(mshes);
213 #else
214 {
215 stringstream temp;
216 temp << "meshMerge() not available in MPI yet...";
217 setFinleyError(VALUE_ERROR,temp.str().c_str());
218 }
219 #endif
220 //
221 // Convert any finley errors into a C++ exception
222 checkFinleyError();
223 AbstractContinuousDomain* temp=new MeshAdapter(fMesh);
224
225 return temp;
226 }
227 AbstractContinuousDomain* glueFaces(const boost::python::list& meshList,
228 double safety_factor,
229 double tolerance,
230 bool optimizeLabeling)
231 {
232 Finley_Mesh* fMesh=0;
233 #ifndef PASO_MPI
234 //
235 // merge the meshes:
236 AbstractContinuousDomain* merged_meshes=meshMerge(meshList);
237 //
238 // glue the faces:
239 const MeshAdapter* merged_finley_meshes=static_cast<const MeshAdapter*>(merged_meshes);
240 fMesh=merged_finley_meshes->getFinley_Mesh();
241 Finley_Mesh_glueFaces(fMesh,safety_factor,tolerance);
242
243 //
244 // Convert any finley errors into a C++ exception
245 checkFinleyError();
246 return merged_meshes;
247 #else
248 {
249 stringstream temp;
250 temp << "glueFaces() not available in MPI yet...";
251 setFinleyError(VALUE_ERROR,temp.str().c_str());
252 }
253
254 //
255 // Convert any finley errors into a C++ exception
256 checkFinleyError();
257 return (AbstractContinuousDomain*)0;
258 #endif
259
260 }
261 AbstractContinuousDomain* joinFaces(const boost::python::list& meshList,
262 double safety_factor,
263 double tolerance,
264 bool optimizeLabeling)
265 {
266 Finley_Mesh* fMesh=0;
267 //
268 // merge the meshes:
269 #ifndef PASO_MPI
270 AbstractContinuousDomain* merged_meshes=meshMerge(meshList);
271 //
272 // join the faces:
273 const MeshAdapter* merged_finley_meshes=static_cast<const MeshAdapter*>(merged_meshes);
274 fMesh=merged_finley_meshes->getFinley_Mesh();
275 Finley_Mesh_joinFaces(fMesh,safety_factor,tolerance);
276 //
277 // Convert any finley errors into a C++ exception
278 checkFinleyError();
279 return merged_meshes;
280 #else
281 {
282 stringstream temp;
283 temp << "joinFaces() not available in MPI yet...";
284 setFinleyError(VALUE_ERROR,temp.str().c_str());
285 }
286 //
287 // Convert any finley errors into a C++ exception
288 checkFinleyError();
289 return (AbstractContinuousDomain*)0;
290
291 #endif
292 }
293
294 } // end of namespace

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26