/[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 817 - (hide annotations)
Sat Aug 26 03:08:52 2006 UTC (13 years, 9 months ago) by ksteube
File size: 7941 byte(s)
Can now compile and run with MPI on shake71


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     AbstractContinuousDomain* brick(int n0,int n1,int n2,int order,
61     double l0,double l1,double l2,
62     int periodic0,int periodic1,
63     int periodic2,
64     int integrationOrder,
65     int useElementsOnFace)
66     {
67     // cout << "n0=" << n0 << " n1=" << n1 << " n2=" << n2
68     // << " order=" << order
69     // << " l0=" << l0 << " l1=" << l1 << " l2=" << l2
70     // << " periodic0=" << periodic0
71     // << " periodic1=" << periodic1
72     // << " periodic2=" << periodic2
73     // << " integerationOrder=" << integrationOrder
74     // << " useElementsOnFace=" << useElementsOnFace << endl;
75    
76     int numElements[]={n0,n1,n2};
77     double length[]={l0,l1,l2};
78     int periodic[]={periodic0, periodic1, periodic2};
79    
80     //
81     // linearInterpolation
82 bcumming 751 Finley_Mesh* fMesh=NULL;
83    
84 jgs 82 if (order==1) {
85 jgs 102 fMesh=Finley_RectangularMesh_Hex8(numElements,length,periodic,integrationOrder,
86 jgs 82 useElementsOnFace) ;
87 bcumming 751 }
88     else if (order==2) {
89 jgs 102 fMesh=Finley_RectangularMesh_Hex20(numElements,length,periodic,integrationOrder,
90 jgs 82 useElementsOnFace) ;
91     } else {
92     stringstream temp;
93     temp << "Illegal interpolation order: " << order;
94     setFinleyError(VALUE_ERROR,temp.str().c_str());
95     }
96     //
97     // Convert any finley errors into a C++ exception
98     checkFinleyError();
99     AbstractContinuousDomain* temp=new MeshAdapter(fMesh);
100     return temp;
101     }
102     AbstractContinuousDomain* rectangle(int n0,int n1,int order,
103     double l0, double l1,
104     int periodic0,int periodic1,
105     int integrationOrder,
106     int useElementsOnFace)
107     {
108     int numElements[]={n0,n1};
109     double length[]={l0,l1};
110     int periodic[]={periodic0, periodic1};
111    
112 bcumming 751 Finley_Mesh* fMesh=0;
113 jgs 82 if (order==1) {
114 jgs 102 fMesh=Finley_RectangularMesh_Rec4(numElements, length,periodic,integrationOrder,
115 jgs 82 useElementsOnFace);
116 bcumming 751 }
117     else if (order==2) {
118 jgs 102 fMesh=Finley_RectangularMesh_Rec8(numElements,length,periodic,integrationOrder,
119 jgs 82 useElementsOnFace);
120 bcumming 751 }
121     else {
122 jgs 82 stringstream temp;
123     temp << "Illegal interpolation order: " << order;
124     setFinleyError(VALUE_ERROR,temp.str().c_str());
125     }
126     //
127     // Convert any finley errors into a C++ exception
128     checkFinleyError();
129     AbstractContinuousDomain* temp=new MeshAdapter(fMesh);
130     return temp;
131     }
132     AbstractContinuousDomain* interval(int n0,int order,double l0,int periodic0,
133     int integrationOrder,
134     int useElementsOnFace)
135     {
136     int numElements[]={n0};
137     double length[]={l0};
138     int periodic[]={periodic0};
139     Finley_Mesh* fMesh;
140     if (order==1) {
141 jgs 102 fMesh=Finley_RectangularMesh_Line2(numElements, length,periodic,integrationOrder,
142 jgs 82 useElementsOnFace);
143 bcumming 751 }
144     else if (order==2) {
145 jgs 102 fMesh=Finley_RectangularMesh_Line3(numElements,length,periodic,integrationOrder,
146 jgs 82 useElementsOnFace);
147 bcumming 751 }
148     else {
149 jgs 82 stringstream temp;
150     temp << "Illegal interpolation order: " << order;
151     setFinleyError(VALUE_ERROR,temp.str().c_str());
152     }
153     //
154     // Convert any finley errors into a C++ exception
155     checkFinleyError();
156     AbstractContinuousDomain* temp=new MeshAdapter(fMesh);
157     return temp;
158     }
159 jgs 110 AbstractContinuousDomain* meshMerge(const boost::python::list& meshList)
160 jgs 82 {
161 jgs 110 Finley_Mesh* fMesh=0;
162     //
163     // extract the meshes from meshList
164 bcumming 751 #ifndef PASO_MPI
165 jgs 110 int numMsh=boost::python::extract<int>(meshList.attr("__len__")());
166 woo409 757 Finley_Mesh **mshes = (numMsh) ? TMPMEMALLOC(numMsh,Finley_Mesh*) : (Finley_Mesh**)NULL;
167 jgs 110 for (int i=0;i<numMsh;++i) {
168     AbstractContinuousDomain& meshListMember=boost::python::extract<AbstractContinuousDomain&>(meshList[i]);
169     const MeshAdapter* finley_meshListMember=static_cast<const MeshAdapter*>(&meshListMember);
170     mshes[i]=finley_meshListMember->getFinley_Mesh();
171     }
172     //
173     // merge the meshes:
174     fMesh=Finley_Mesh_merge(numMsh,mshes);
175 bcumming 759 TMPMEMFREE(mshes);
176 bcumming 751 #else
177     {
178     stringstream temp;
179     temp << "meshMerge() not available in MPI yet...";
180     setFinleyError(VALUE_ERROR,temp.str().c_str());
181     }
182     #endif
183 jgs 110 //
184     // Convert any finley errors into a C++ exception
185     checkFinleyError();
186     AbstractContinuousDomain* temp=new MeshAdapter(fMesh);
187 woo409 757
188 jgs 82 return temp;
189     }
190     AbstractContinuousDomain* glueFaces(const boost::python::list& meshList,
191 jgs 110 double safety_factor,
192 jgs 82 double tolerance)
193     {
194 jgs 110 Finley_Mesh* fMesh=0;
195 bcumming 751 #ifndef PASO_MPI
196 jgs 110 //
197     // merge the meshes:
198     AbstractContinuousDomain* merged_meshes=meshMerge(meshList);
199     //
200     // glue the faces:
201     const MeshAdapter* merged_finley_meshes=static_cast<const MeshAdapter*>(merged_meshes);
202     fMesh=merged_finley_meshes->getFinley_Mesh();
203     Finley_Mesh_glueFaces(fMesh,safety_factor,tolerance);
204 bcumming 751
205 jgs 110 //
206     // Convert any finley errors into a C++ exception
207     checkFinleyError();
208     return merged_meshes;
209 bcumming 751 #else
210     {
211     stringstream temp;
212     temp << "glueFaces() not available in MPI yet...";
213     setFinleyError(VALUE_ERROR,temp.str().c_str());
214     }
215    
216     //
217     // Convert any finley errors into a C++ exception
218     checkFinleyError();
219     return (AbstractContinuousDomain*)0;
220     #endif
221    
222 jgs 82 }
223     AbstractContinuousDomain* joinFaces(const boost::python::list& meshList,
224     double safety_factor,
225     double tolerance)
226     {
227 jgs 110 Finley_Mesh* fMesh=0;
228     //
229     // merge the meshes:
230 bcumming 751 #ifndef PASO_MPI
231 jgs 110 AbstractContinuousDomain* merged_meshes=meshMerge(meshList);
232     //
233     // join the faces:
234     const MeshAdapter* merged_finley_meshes=static_cast<const MeshAdapter*>(merged_meshes);
235     fMesh=merged_finley_meshes->getFinley_Mesh();
236     Finley_Mesh_joinFaces(fMesh,safety_factor,tolerance);
237     //
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 << "joinFaces() not available in MPI yet...";
245     setFinleyError(VALUE_ERROR,temp.str().c_str());
246     }
247     //
248     // Convert any finley errors into a C++ exception
249     checkFinleyError();
250     return (AbstractContinuousDomain*)0;
251    
252     #endif
253 jgs 82 }
254    
255     } // end of namespace

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26