/[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 782 - (hide annotations)
Tue Jul 18 00:47:47 2006 UTC (13 years, 2 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 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 jgs 203 #include "MeshAdapterFactory.h"
17 jgs 480 #include "FinleyError.h"
18 jgs 82
19 jgs 480 #include <boost/python/extract.hpp>
20    
21     #include <sstream>
22    
23 jgs 82 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 bcumming 751 Finley_Mesh* fMesh=0;
35 woo409 757 // Win32 refactor
36     char *fName = ((fileName.size()+1)>0) ? TMPMEMALLOC((fileName.size()+1),char) : (char*)NULL;
37 jgs 82 strcpy(fName,fileName.c_str());
38 bcumming 751
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 jgs 82 checkFinleyError();
49     AbstractContinuousDomain* temp=new MeshAdapter(fMesh);
50 woo409 757
51     /* win32 refactor */
52     TMPMEMFREE(fName);
53    
54 jgs 82 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 bcumming 751 Finley_Mesh* fMesh=NULL;
80    
81 jgs 82 if (order==1) {
82 jgs 102 fMesh=Finley_RectangularMesh_Hex8(numElements,length,periodic,integrationOrder,
83 jgs 82 useElementsOnFace) ;
84 bcumming 751 }
85     else if (order==2) {
86 jgs 102 fMesh=Finley_RectangularMesh_Hex20(numElements,length,periodic,integrationOrder,
87 jgs 82 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 bcumming 751 Finley_Mesh* fMesh=0;
110 jgs 82 if (order==1) {
111 jgs 102 fMesh=Finley_RectangularMesh_Rec4(numElements, length,periodic,integrationOrder,
112 jgs 82 useElementsOnFace);
113 bcumming 751 }
114     else if (order==2) {
115 jgs 102 fMesh=Finley_RectangularMesh_Rec8(numElements,length,periodic,integrationOrder,
116 jgs 82 useElementsOnFace);
117 bcumming 751 }
118     else {
119 jgs 82 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 jgs 102 fMesh=Finley_RectangularMesh_Line2(numElements, length,periodic,integrationOrder,
139 jgs 82 useElementsOnFace);
140 bcumming 751 }
141     else if (order==2) {
142 jgs 102 fMesh=Finley_RectangularMesh_Line3(numElements,length,periodic,integrationOrder,
143 jgs 82 useElementsOnFace);
144 bcumming 751 }
145     else {
146 jgs 82 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 jgs 110 AbstractContinuousDomain* meshMerge(const boost::python::list& meshList)
157 jgs 82 {
158 jgs 110 Finley_Mesh* fMesh=0;
159     //
160     // extract the meshes from meshList
161 bcumming 751 #ifndef PASO_MPI
162 jgs 110 int numMsh=boost::python::extract<int>(meshList.attr("__len__")());
163 woo409 757 Finley_Mesh **mshes = (numMsh) ? TMPMEMALLOC(numMsh,Finley_Mesh*) : (Finley_Mesh**)NULL;
164 jgs 110 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 bcumming 759 TMPMEMFREE(mshes);
173 bcumming 751 #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 jgs 110 //
181     // Convert any finley errors into a C++ exception
182     checkFinleyError();
183     AbstractContinuousDomain* temp=new MeshAdapter(fMesh);
184 woo409 757
185 jgs 82 return temp;
186     }
187     AbstractContinuousDomain* glueFaces(const boost::python::list& meshList,
188 jgs 110 double safety_factor,
189 jgs 82 double tolerance)
190     {
191 jgs 110 Finley_Mesh* fMesh=0;
192 bcumming 751 #ifndef PASO_MPI
193 jgs 110 //
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 bcumming 751
202 jgs 110 //
203     // Convert any finley errors into a C++ exception
204     checkFinleyError();
205     return merged_meshes;
206 bcumming 751 #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 jgs 82 }
220     AbstractContinuousDomain* joinFaces(const boost::python::list& meshList,
221     double safety_factor,
222     double tolerance)
223     {
224 jgs 110 Finley_Mesh* fMesh=0;
225     //
226     // merge the meshes:
227 bcumming 751 #ifndef PASO_MPI
228 jgs 110 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 bcumming 751 #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 jgs 82 }
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