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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 934 - (hide annotations)
Tue Jan 23 09:52:45 2007 UTC (13 years, 2 months ago) by gross
Original Path: trunk/finley/src/CPPAdapter/MeshAdapterFactory.cpp
File size: 8999 byte(s)
gmsh file reader for finley
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     int integrationOrder)
33     {
34     //
35     // create a copy of the filename to overcome the non-constness of call
36     // to Finley_Mesh_read
37 bcumming 751 Finley_Mesh* fMesh=0;
38 woo409 757 // Win32 refactor
39     char *fName = ((fileName.size()+1)>0) ? TMPMEMALLOC((fileName.size()+1),char) : (char*)NULL;
40 jgs 82 strcpy(fName,fileName.c_str());
41 bcumming 751
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 jgs 82 checkFinleyError();
52     AbstractContinuousDomain* temp=new MeshAdapter(fMesh);
53 woo409 757
54     /* win32 refactor */
55     TMPMEMFREE(fName);
56    
57 jgs 82 return temp;
58     }
59    
60 gross 934 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 jgs 82 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 bcumming 751 Finley_Mesh* fMesh=NULL;
115    
116 jgs 82 if (order==1) {
117 jgs 102 fMesh=Finley_RectangularMesh_Hex8(numElements,length,periodic,integrationOrder,
118 jgs 82 useElementsOnFace) ;
119 bcumming 751 }
120     else if (order==2) {
121 jgs 102 fMesh=Finley_RectangularMesh_Hex20(numElements,length,periodic,integrationOrder,
122 jgs 82 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 bcumming 751 Finley_Mesh* fMesh=0;
145 jgs 82 if (order==1) {
146 jgs 102 fMesh=Finley_RectangularMesh_Rec4(numElements, length,periodic,integrationOrder,
147 jgs 82 useElementsOnFace);
148 bcumming 751 }
149     else if (order==2) {
150 jgs 102 fMesh=Finley_RectangularMesh_Rec8(numElements,length,periodic,integrationOrder,
151 jgs 82 useElementsOnFace);
152 bcumming 751 }
153     else {
154 jgs 82 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 jgs 102 fMesh=Finley_RectangularMesh_Line2(numElements, length,periodic,integrationOrder,
174 jgs 82 useElementsOnFace);
175 bcumming 751 }
176     else if (order==2) {
177 jgs 102 fMesh=Finley_RectangularMesh_Line3(numElements,length,periodic,integrationOrder,
178 jgs 82 useElementsOnFace);
179 bcumming 751 }
180     else {
181 jgs 82 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 jgs 110 AbstractContinuousDomain* meshMerge(const boost::python::list& meshList)
192 jgs 82 {
193 jgs 110 Finley_Mesh* fMesh=0;
194     //
195     // extract the meshes from meshList
196 bcumming 751 #ifndef PASO_MPI
197 jgs 110 int numMsh=boost::python::extract<int>(meshList.attr("__len__")());
198 woo409 757 Finley_Mesh **mshes = (numMsh) ? TMPMEMALLOC(numMsh,Finley_Mesh*) : (Finley_Mesh**)NULL;
199 jgs 110 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 bcumming 759 TMPMEMFREE(mshes);
208 bcumming 751 #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 jgs 110 //
216     // Convert any finley errors into a C++ exception
217     checkFinleyError();
218     AbstractContinuousDomain* temp=new MeshAdapter(fMesh);
219 woo409 757
220 jgs 82 return temp;
221     }
222     AbstractContinuousDomain* glueFaces(const boost::python::list& meshList,
223 jgs 110 double safety_factor,
224 jgs 82 double tolerance)
225     {
226 jgs 110 Finley_Mesh* fMesh=0;
227 bcumming 751 #ifndef PASO_MPI
228 jgs 110 //
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 bcumming 751
237 jgs 110 //
238     // Convert any finley errors into a C++ exception
239     checkFinleyError();
240     return merged_meshes;
241 bcumming 751 #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 jgs 82 }
255     AbstractContinuousDomain* joinFaces(const boost::python::list& meshList,
256     double safety_factor,
257     double tolerance)
258     {
259 jgs 110 Finley_Mesh* fMesh=0;
260     //
261     // merge the meshes:
262 bcumming 751 #ifndef PASO_MPI
263 jgs 110 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 bcumming 751 #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 jgs 82 }
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