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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 817 - (show annotations)
Sat Aug 26 03:08:52 2006 UTC (13 years ago) by ksteube
File size: 7941 byte(s)
Can now compile and run with MPI on shake71


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 {
34 //
35 // create a copy of the filename to overcome the non-constness of call
36 // to Finley_Mesh_read
37 Finley_Mesh* fMesh=0;
38 // Win32 refactor
39 char *fName = ((fileName.size()+1)>0) ? TMPMEMALLOC((fileName.size()+1),char) : (char*)NULL;
40 strcpy(fName,fileName.c_str());
41
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 checkFinleyError();
52 AbstractContinuousDomain* temp=new MeshAdapter(fMesh);
53
54 /* win32 refactor */
55 TMPMEMFREE(fName);
56
57 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 Finley_Mesh* fMesh=NULL;
83
84 if (order==1) {
85 fMesh=Finley_RectangularMesh_Hex8(numElements,length,periodic,integrationOrder,
86 useElementsOnFace) ;
87 }
88 else if (order==2) {
89 fMesh=Finley_RectangularMesh_Hex20(numElements,length,periodic,integrationOrder,
90 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 Finley_Mesh* fMesh=0;
113 if (order==1) {
114 fMesh=Finley_RectangularMesh_Rec4(numElements, length,periodic,integrationOrder,
115 useElementsOnFace);
116 }
117 else if (order==2) {
118 fMesh=Finley_RectangularMesh_Rec8(numElements,length,periodic,integrationOrder,
119 useElementsOnFace);
120 }
121 else {
122 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 fMesh=Finley_RectangularMesh_Line2(numElements, length,periodic,integrationOrder,
142 useElementsOnFace);
143 }
144 else if (order==2) {
145 fMesh=Finley_RectangularMesh_Line3(numElements,length,periodic,integrationOrder,
146 useElementsOnFace);
147 }
148 else {
149 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 AbstractContinuousDomain* meshMerge(const boost::python::list& meshList)
160 {
161 Finley_Mesh* fMesh=0;
162 //
163 // extract the meshes from meshList
164 #ifndef PASO_MPI
165 int numMsh=boost::python::extract<int>(meshList.attr("__len__")());
166 Finley_Mesh **mshes = (numMsh) ? TMPMEMALLOC(numMsh,Finley_Mesh*) : (Finley_Mesh**)NULL;
167 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 TMPMEMFREE(mshes);
176 #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 //
184 // Convert any finley errors into a C++ exception
185 checkFinleyError();
186 AbstractContinuousDomain* temp=new MeshAdapter(fMesh);
187
188 return temp;
189 }
190 AbstractContinuousDomain* glueFaces(const boost::python::list& meshList,
191 double safety_factor,
192 double tolerance)
193 {
194 Finley_Mesh* fMesh=0;
195 #ifndef PASO_MPI
196 //
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
205 //
206 // Convert any finley errors into a C++ exception
207 checkFinleyError();
208 return merged_meshes;
209 #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 }
223 AbstractContinuousDomain* joinFaces(const boost::python::list& meshList,
224 double safety_factor,
225 double tolerance)
226 {
227 Finley_Mesh* fMesh=0;
228 //
229 // merge the meshes:
230 #ifndef PASO_MPI
231 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 #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 }
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