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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1062 - (hide annotations)
Mon Mar 26 06:17:53 2007 UTC (12 years, 5 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 jgs 102 /* $Id$ */
2 jgs 82 /*
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 ksteube 817 #ifdef PASO_MPI
17     #include <mpi.h>
18     #endif
19 jgs 203 #include "MeshAdapterFactory.h"
20 jgs 480 #include "FinleyError.h"
21 jgs 82
22 jgs 480 #include <boost/python/extract.hpp>
23    
24     #include <sstream>
25    
26 jgs 82 using namespace std;
27     using namespace escript;
28    
29     namespace finley {
30    
31     AbstractContinuousDomain* readMesh(const std::string& fileName,
32 gross 1059 int integrationOrder,
33     int reducedIntegrationOrder,
34     bool optimizeLabeling)
35 jgs 82 {
36     //
37     // create a copy of the filename to overcome the non-constness of call
38     // to Finley_Mesh_read
39 bcumming 751 Finley_Mesh* fMesh=0;
40 woo409 757 // Win32 refactor
41     char *fName = ((fileName.size()+1)>0) ? TMPMEMALLOC((fileName.size()+1),char) : (char*)NULL;
42 jgs 82 strcpy(fName,fileName.c_str());
43 bcumming 751
44     #ifndef PASO_MPI
45 gross 1062 fMesh=Finley_Mesh_read(fName,integrationOrder, reducedIntegrationOrder, (optimizeLabeling ? TRUE : FALSE));
46 bcumming 751 #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 jgs 82 checkFinleyError();
54     AbstractContinuousDomain* temp=new MeshAdapter(fMesh);
55 woo409 757
56     /* win32 refactor */
57     TMPMEMFREE(fName);
58    
59 jgs 82 return temp;
60     }
61    
62 gross 934 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 gross 1062 fMesh=Finley_Mesh_readGmsh(fName, numDim, integrationOrder, reducedIntegrationOrder, (optimizeLabeling ? TRUE : FALSE));
78 gross 934 #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 jgs 82 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 gross 1059 int reducedIntegrationOrder,
100 jgs 82 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 bcumming 751 Finley_Mesh* fMesh=NULL;
118    
119 jgs 82 if (order==1) {
120 gross 1062 fMesh=Finley_RectangularMesh_Hex8(numElements,length,periodic,integrationOrder,reducedIntegrationOrder,
121 jgs 82 useElementsOnFace) ;
122 bcumming 751 }
123     else if (order==2) {
124 gross 1062 fMesh=Finley_RectangularMesh_Hex20(numElements,length,periodic,integrationOrder,reducedIntegrationOrder,
125 jgs 82 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 gross 1059 int reducedIntegrationOrder,
142 jgs 82 int useElementsOnFace)
143     {
144     int numElements[]={n0,n1};
145     double length[]={l0,l1};
146     int periodic[]={periodic0, periodic1};
147    
148 bcumming 751 Finley_Mesh* fMesh=0;
149 jgs 82 if (order==1) {
150 gross 1062 fMesh=Finley_RectangularMesh_Rec4(numElements, length,periodic,integrationOrder,reducedIntegrationOrder,
151 jgs 82 useElementsOnFace);
152 bcumming 751 }
153     else if (order==2) {
154 gross 1062 fMesh=Finley_RectangularMesh_Rec8(numElements,length,periodic,integrationOrder,reducedIntegrationOrder,
155 jgs 82 useElementsOnFace);
156 bcumming 751 }
157     else {
158 jgs 82 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 gross 1059 int reducedIntegrationOrder,
171 jgs 82 int useElementsOnFace)
172     {
173     int numElements[]={n0};
174     double length[]={l0};
175     int periodic[]={periodic0};
176     Finley_Mesh* fMesh;
177     if (order==1) {
178 gross 1062 fMesh=Finley_RectangularMesh_Line2(numElements, length,periodic,integrationOrder,reducedIntegrationOrder,
179 jgs 82 useElementsOnFace);
180 bcumming 751 }
181     else if (order==2) {
182 gross 1062 fMesh=Finley_RectangularMesh_Line3(numElements,length,periodic,integrationOrder,reducedIntegrationOrder,
183 jgs 82 useElementsOnFace);
184 bcumming 751 }
185     else {
186 jgs 82 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 gross 1062
197 jgs 110 AbstractContinuousDomain* meshMerge(const boost::python::list& meshList)
198 jgs 82 {
199 jgs 110 Finley_Mesh* fMesh=0;
200     //
201     // extract the meshes from meshList
202 bcumming 751 #ifndef PASO_MPI
203 jgs 110 int numMsh=boost::python::extract<int>(meshList.attr("__len__")());
204 woo409 757 Finley_Mesh **mshes = (numMsh) ? TMPMEMALLOC(numMsh,Finley_Mesh*) : (Finley_Mesh**)NULL;
205 jgs 110 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 bcumming 759 TMPMEMFREE(mshes);
214 bcumming 751 #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 jgs 110 //
222     // Convert any finley errors into a C++ exception
223     checkFinleyError();
224     AbstractContinuousDomain* temp=new MeshAdapter(fMesh);
225 woo409 757
226 jgs 82 return temp;
227     }
228     AbstractContinuousDomain* glueFaces(const boost::python::list& meshList,
229 gross 1062 double safety_factor,
230 gross 1059 double tolerance,
231     bool optimizeLabeling)
232 jgs 82 {
233 jgs 110 Finley_Mesh* fMesh=0;
234 bcumming 751 #ifndef PASO_MPI
235 jgs 110 //
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 gross 1062 Finley_Mesh_glueFaces(fMesh,safety_factor,tolerance,(optimizeLabeling ? TRUE : FALSE));
243 bcumming 751
244 jgs 110 //
245     // Convert any finley errors into a C++ exception
246     checkFinleyError();
247     return merged_meshes;
248 bcumming 751 #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 jgs 82 }
262     AbstractContinuousDomain* joinFaces(const boost::python::list& meshList,
263     double safety_factor,
264 gross 1059 double tolerance,
265     bool optimizeLabeling)
266 jgs 82 {
267 jgs 110 Finley_Mesh* fMesh=0;
268     //
269     // merge the meshes:
270 bcumming 751 #ifndef PASO_MPI
271 jgs 110 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 gross 1062 Finley_Mesh_joinFaces(fMesh,safety_factor,tolerance, (optimizeLabeling ? TRUE : FALSE));
277 jgs 110 //
278     // Convert any finley errors into a C++ exception
279     checkFinleyError();
280     return merged_meshes;
281 bcumming 751 #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 jgs 82 }
294    
295 gross 1062 // 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