/[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 782 - (show annotations)
Tue Jul 18 00:47:47 2006 UTC (12 years, 11 months ago) by bcumming
File size: 7901 byte(s)
Large number of changes to Finley for meshing in MPI.

- optimisation and neatening up of rectcanglular mesh generation code
- first and second order 1D, 2D and 3D rectangular meshes are now
  available in finley and escript using MPI.
- reduced meshes now generated in MPI, and interpolation to and from 
  reduced data types now supported.  

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 #include "MeshAdapterFactory.h"
17 #include "FinleyError.h"
18
19 #include <boost/python/extract.hpp>
20
21 #include <sstream>
22
23 using namespace std;
24 using namespace escript;
25
26 namespace finley {
27
28 AbstractContinuousDomain* readMesh(const std::string& fileName,
29 int integrationOrder)
30 {
31 //
32 // create a copy of the filename to overcome the non-constness of call
33 // to Finley_Mesh_read
34 Finley_Mesh* fMesh=0;
35 // Win32 refactor
36 char *fName = ((fileName.size()+1)>0) ? TMPMEMALLOC((fileName.size()+1),char) : (char*)NULL;
37 strcpy(fName,fileName.c_str());
38
39 #ifndef PASO_MPI
40 fMesh=Finley_Mesh_read(fName,integrationOrder);
41 #else
42 {
43 stringstream temp;
44 temp << "Unable to read meshes from file under MPI yet...";
45 setFinleyError(VALUE_ERROR,temp.str().c_str());
46 }
47 #endif
48 checkFinleyError();
49 AbstractContinuousDomain* temp=new MeshAdapter(fMesh);
50
51 /* win32 refactor */
52 TMPMEMFREE(fName);
53
54 return temp;
55 }
56
57 AbstractContinuousDomain* brick(int n0,int n1,int n2,int order,
58 double l0,double l1,double l2,
59 int periodic0,int periodic1,
60 int periodic2,
61 int integrationOrder,
62 int useElementsOnFace)
63 {
64 // cout << "n0=" << n0 << " n1=" << n1 << " n2=" << n2
65 // << " order=" << order
66 // << " l0=" << l0 << " l1=" << l1 << " l2=" << l2
67 // << " periodic0=" << periodic0
68 // << " periodic1=" << periodic1
69 // << " periodic2=" << periodic2
70 // << " integerationOrder=" << integrationOrder
71 // << " useElementsOnFace=" << useElementsOnFace << endl;
72
73 int numElements[]={n0,n1,n2};
74 double length[]={l0,l1,l2};
75 int periodic[]={periodic0, periodic1, periodic2};
76
77 //
78 // linearInterpolation
79 Finley_Mesh* fMesh=NULL;
80
81 if (order==1) {
82 fMesh=Finley_RectangularMesh_Hex8(numElements,length,periodic,integrationOrder,
83 useElementsOnFace) ;
84 }
85 else if (order==2) {
86 fMesh=Finley_RectangularMesh_Hex20(numElements,length,periodic,integrationOrder,
87 useElementsOnFace) ;
88 } else {
89 stringstream temp;
90 temp << "Illegal interpolation order: " << order;
91 setFinleyError(VALUE_ERROR,temp.str().c_str());
92 }
93 //
94 // Convert any finley errors into a C++ exception
95 checkFinleyError();
96 AbstractContinuousDomain* temp=new MeshAdapter(fMesh);
97 return temp;
98 }
99 AbstractContinuousDomain* rectangle(int n0,int n1,int order,
100 double l0, double l1,
101 int periodic0,int periodic1,
102 int integrationOrder,
103 int useElementsOnFace)
104 {
105 int numElements[]={n0,n1};
106 double length[]={l0,l1};
107 int periodic[]={periodic0, periodic1};
108
109 Finley_Mesh* fMesh=0;
110 if (order==1) {
111 fMesh=Finley_RectangularMesh_Rec4(numElements, length,periodic,integrationOrder,
112 useElementsOnFace);
113 }
114 else if (order==2) {
115 fMesh=Finley_RectangularMesh_Rec8(numElements,length,periodic,integrationOrder,
116 useElementsOnFace);
117 }
118 else {
119 stringstream temp;
120 temp << "Illegal interpolation order: " << order;
121 setFinleyError(VALUE_ERROR,temp.str().c_str());
122 }
123 //
124 // Convert any finley errors into a C++ exception
125 checkFinleyError();
126 AbstractContinuousDomain* temp=new MeshAdapter(fMesh);
127 return temp;
128 }
129 AbstractContinuousDomain* interval(int n0,int order,double l0,int periodic0,
130 int integrationOrder,
131 int useElementsOnFace)
132 {
133 int numElements[]={n0};
134 double length[]={l0};
135 int periodic[]={periodic0};
136 Finley_Mesh* fMesh;
137 if (order==1) {
138 fMesh=Finley_RectangularMesh_Line2(numElements, length,periodic,integrationOrder,
139 useElementsOnFace);
140 }
141 else if (order==2) {
142 fMesh=Finley_RectangularMesh_Line3(numElements,length,periodic,integrationOrder,
143 useElementsOnFace);
144 }
145 else {
146 stringstream temp;
147 temp << "Illegal interpolation order: " << order;
148 setFinleyError(VALUE_ERROR,temp.str().c_str());
149 }
150 //
151 // Convert any finley errors into a C++ exception
152 checkFinleyError();
153 AbstractContinuousDomain* temp=new MeshAdapter(fMesh);
154 return temp;
155 }
156 AbstractContinuousDomain* meshMerge(const boost::python::list& meshList)
157 {
158 Finley_Mesh* fMesh=0;
159 //
160 // extract the meshes from meshList
161 #ifndef PASO_MPI
162 int numMsh=boost::python::extract<int>(meshList.attr("__len__")());
163 Finley_Mesh **mshes = (numMsh) ? TMPMEMALLOC(numMsh,Finley_Mesh*) : (Finley_Mesh**)NULL;
164 for (int i=0;i<numMsh;++i) {
165 AbstractContinuousDomain& meshListMember=boost::python::extract<AbstractContinuousDomain&>(meshList[i]);
166 const MeshAdapter* finley_meshListMember=static_cast<const MeshAdapter*>(&meshListMember);
167 mshes[i]=finley_meshListMember->getFinley_Mesh();
168 }
169 //
170 // merge the meshes:
171 fMesh=Finley_Mesh_merge(numMsh,mshes);
172 TMPMEMFREE(mshes);
173 #else
174 {
175 stringstream temp;
176 temp << "meshMerge() not available in MPI yet...";
177 setFinleyError(VALUE_ERROR,temp.str().c_str());
178 }
179 #endif
180 //
181 // Convert any finley errors into a C++ exception
182 checkFinleyError();
183 AbstractContinuousDomain* temp=new MeshAdapter(fMesh);
184
185 return temp;
186 }
187 AbstractContinuousDomain* glueFaces(const boost::python::list& meshList,
188 double safety_factor,
189 double tolerance)
190 {
191 Finley_Mesh* fMesh=0;
192 #ifndef PASO_MPI
193 //
194 // merge the meshes:
195 AbstractContinuousDomain* merged_meshes=meshMerge(meshList);
196 //
197 // glue the faces:
198 const MeshAdapter* merged_finley_meshes=static_cast<const MeshAdapter*>(merged_meshes);
199 fMesh=merged_finley_meshes->getFinley_Mesh();
200 Finley_Mesh_glueFaces(fMesh,safety_factor,tolerance);
201
202 //
203 // Convert any finley errors into a C++ exception
204 checkFinleyError();
205 return merged_meshes;
206 #else
207 {
208 stringstream temp;
209 temp << "glueFaces() not available in MPI yet...";
210 setFinleyError(VALUE_ERROR,temp.str().c_str());
211 }
212
213 //
214 // Convert any finley errors into a C++ exception
215 checkFinleyError();
216 return (AbstractContinuousDomain*)0;
217 #endif
218
219 }
220 AbstractContinuousDomain* joinFaces(const boost::python::list& meshList,
221 double safety_factor,
222 double tolerance)
223 {
224 Finley_Mesh* fMesh=0;
225 //
226 // merge the meshes:
227 #ifndef PASO_MPI
228 AbstractContinuousDomain* merged_meshes=meshMerge(meshList);
229 //
230 // join the faces:
231 const MeshAdapter* merged_finley_meshes=static_cast<const MeshAdapter*>(merged_meshes);
232 fMesh=merged_finley_meshes->getFinley_Mesh();
233 Finley_Mesh_joinFaces(fMesh,safety_factor,tolerance);
234 //
235 // Convert any finley errors into a C++ exception
236 checkFinleyError();
237 return merged_meshes;
238 #else
239 {
240 stringstream temp;
241 temp << "joinFaces() not available in MPI yet...";
242 setFinleyError(VALUE_ERROR,temp.str().c_str());
243 }
244 //
245 // Convert any finley errors into a C++ exception
246 checkFinleyError();
247 return (AbstractContinuousDomain*)0;
248
249 #endif
250 }
251
252 } // end of namespace

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26