/[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 1059 - (hide annotations)
Fri Mar 23 11:01:53 2007 UTC (13 years, 2 months ago) by gross
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 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     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 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     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 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 jgs 102 fMesh=Finley_RectangularMesh_Hex8(numElements,length,periodic,integrationOrder,
121 jgs 82 useElementsOnFace) ;
122 bcumming 751 }
123     else if (order==2) {
124 jgs 102 fMesh=Finley_RectangularMesh_Hex20(numElements,length,periodic,integrationOrder,
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 jgs 102 fMesh=Finley_RectangularMesh_Rec4(numElements, length,periodic,integrationOrder,
151 jgs 82 useElementsOnFace);
152 bcumming 751 }
153     else if (order==2) {
154 jgs 102 fMesh=Finley_RectangularMesh_Rec8(numElements,length,periodic,integrationOrder,
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 jgs 102 fMesh=Finley_RectangularMesh_Line2(numElements, length,periodic,integrationOrder,
179 jgs 82 useElementsOnFace);
180 bcumming 751 }
181     else if (order==2) {
182 jgs 102 fMesh=Finley_RectangularMesh_Line3(numElements,length,periodic,integrationOrder,
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 jgs 110 AbstractContinuousDomain* meshMerge(const boost::python::list& meshList)
197 jgs 82 {
198 jgs 110 Finley_Mesh* fMesh=0;
199     //
200     // extract the meshes from meshList
201 bcumming 751 #ifndef PASO_MPI
202 jgs 110 int numMsh=boost::python::extract<int>(meshList.attr("__len__")());
203 woo409 757 Finley_Mesh **mshes = (numMsh) ? TMPMEMALLOC(numMsh,Finley_Mesh*) : (Finley_Mesh**)NULL;
204 jgs 110 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 bcumming 759 TMPMEMFREE(mshes);
213 bcumming 751 #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 jgs 110 //
221     // Convert any finley errors into a C++ exception
222     checkFinleyError();
223     AbstractContinuousDomain* temp=new MeshAdapter(fMesh);
224 woo409 757
225 jgs 82 return temp;
226     }
227     AbstractContinuousDomain* glueFaces(const boost::python::list& meshList,
228 jgs 110 double safety_factor,
229 gross 1059 double tolerance,
230     bool optimizeLabeling)
231 jgs 82 {
232 jgs 110 Finley_Mesh* fMesh=0;
233 bcumming 751 #ifndef PASO_MPI
234 jgs 110 //
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 bcumming 751
243 jgs 110 //
244     // Convert any finley errors into a C++ exception
245     checkFinleyError();
246     return merged_meshes;
247 bcumming 751 #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 jgs 82 }
261     AbstractContinuousDomain* joinFaces(const boost::python::list& meshList,
262     double safety_factor,
263 gross 1059 double tolerance,
264     bool optimizeLabeling)
265 jgs 82 {
266 jgs 110 Finley_Mesh* fMesh=0;
267     //
268     // merge the meshes:
269 bcumming 751 #ifndef PASO_MPI
270 jgs 110 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 bcumming 751 #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 jgs 82 }
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