/[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 1312 - (show annotations)
Mon Sep 24 06:18:44 2007 UTC (12 years, 1 month ago) by ksteube
File size: 7588 byte(s)
The MPI branch is hereby closed. All future work should be in trunk.

Previously in revision 1295 I merged the latest changes to trunk into trunk-mpi-branch.
In this revision I copied all files from trunk-mpi-branch over the corresponding
trunk files. I did not use 'svn merge', it was a copy.

1
2 /* $Id$ */
3
4 /*******************************************************
5 *
6 * Copyright 2003-2007 by ACceSS MNRF
7 * Copyright 2007 by University of Queensland
8 *
9 * http://esscc.uq.edu.au
10 * Primary Business: Queensland, Australia
11 * Licensed under the Open Software License version 3.0
12 * http://www.opensource.org/licenses/osl-3.0.php
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* loadMesh(const std::string& fileName)
32 {
33 //
34 // create a copy of the filename to overcome the non-constness of call
35 // to Finley_Mesh_read
36 Finley_Mesh* fMesh=0;
37 // Win32 refactor
38 char *fName = ((fileName.size()+1)>0) ? TMPMEMALLOC((fileName.size()+1),char) : (char*)NULL;
39 strcpy(fName,fileName.c_str());
40
41 fMesh=Finley_Mesh_load(fName);
42 checkFinleyError();
43 AbstractContinuousDomain* temp=new MeshAdapter(fMesh);
44
45 /* win32 refactor */
46 TMPMEMFREE(fName);
47
48 return temp;
49 }
50
51 AbstractContinuousDomain* readMesh(const std::string& fileName,
52 int integrationOrder,
53 int reducedIntegrationOrder,
54 int optimize)
55 {
56 //
57 // create a copy of the filename to overcome the non-constness of call
58 // to Finley_Mesh_read
59 Finley_Mesh* fMesh=0;
60 // Win32 refactor
61 char *fName = ((fileName.size()+1)>0) ? TMPMEMALLOC((fileName.size()+1),char) : (char*)NULL;
62 strcpy(fName,fileName.c_str());
63
64 fMesh=Finley_Mesh_read(fName,integrationOrder, reducedIntegrationOrder, (optimize ? TRUE : FALSE));
65 checkFinleyError();
66 AbstractContinuousDomain* temp=new MeshAdapter(fMesh);
67
68 /* win32 refactor */
69 TMPMEMFREE(fName);
70
71 return temp;
72 }
73
74 AbstractContinuousDomain* readGmsh(const std::string& fileName,
75 int numDim,
76 int integrationOrder,
77 int reducedIntegrationOrder,
78 int optimize)
79 {
80 //
81 // create a copy of the filename to overcome the non-constness of call
82 // to Finley_Mesh_read
83 Finley_Mesh* fMesh=0;
84 // Win32 refactor
85 char *fName = ((fileName.size()+1)>0) ? TMPMEMALLOC((fileName.size()+1),char) : (char*)NULL;
86 strcpy(fName,fileName.c_str());
87
88 fMesh=Finley_Mesh_readGmsh(fName, numDim, integrationOrder, reducedIntegrationOrder, (optimize ? TRUE : FALSE));
89 checkFinleyError();
90 AbstractContinuousDomain* temp=new MeshAdapter(fMesh);
91
92 /* win32 refactor */
93 TMPMEMFREE(fName);
94
95 return temp;
96 }
97
98 AbstractContinuousDomain* brick(int n0,int n1,int n2,int order,
99 double l0,double l1,double l2,
100 int periodic0,int periodic1,
101 int periodic2,
102 int integrationOrder,
103 int reducedIntegrationOrder,
104 int useElementsOnFace,
105 int useFullElementOrder,
106 int optimize)
107 {
108 int numElements[]={n0,n1,n2};
109 double length[]={l0,l1,l2};
110 int periodic[]={periodic0, periodic1, periodic2};
111
112 //
113 // linearInterpolation
114 Finley_Mesh* fMesh=NULL;
115
116 if (order==1) {
117 fMesh=Finley_RectangularMesh_Hex8(numElements,length,periodic,integrationOrder,reducedIntegrationOrder,
118 useElementsOnFace,useFullElementOrder,(optimize ? TRUE : FALSE)) ;
119 }
120 else if (order==2) {
121 fMesh=Finley_RectangularMesh_Hex20(numElements,length,periodic,integrationOrder,reducedIntegrationOrder,
122 useElementsOnFace,useFullElementOrder,(optimize ? TRUE : FALSE)) ;
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 reducedIntegrationOrder,
139 int useElementsOnFace,
140 int useFullElementOrder,
141 int optimize)
142 {
143 int numElements[]={n0,n1};
144 double length[]={l0,l1};
145 int periodic[]={periodic0, periodic1};
146
147 Finley_Mesh* fMesh=0;
148 if (order==1) {
149 fMesh=Finley_RectangularMesh_Rec4(numElements, length,periodic,integrationOrder,reducedIntegrationOrder,
150 useElementsOnFace,useFullElementOrder,(optimize ? TRUE : FALSE));
151 }
152 else if (order==2) {
153 fMesh=Finley_RectangularMesh_Rec8(numElements,length,periodic,integrationOrder,reducedIntegrationOrder,
154 useElementsOnFace,useFullElementOrder,(optimize ? TRUE : FALSE));
155 }
156 else {
157 stringstream temp;
158 temp << "Illegal interpolation order: " << order;
159 setFinleyError(VALUE_ERROR,temp.str().c_str());
160 }
161 //
162 // Convert any finley errors into a C++ exception
163 checkFinleyError();
164 AbstractContinuousDomain* temp=new MeshAdapter(fMesh);
165 return temp;
166 }
167
168 AbstractContinuousDomain* meshMerge(const boost::python::list& meshList)
169 {
170 Finley_Mesh* fMesh=0;
171 //
172 // extract the meshes from meshList
173 int numMsh=boost::python::extract<int>(meshList.attr("__len__")());
174 Finley_Mesh **mshes = (numMsh) ? TMPMEMALLOC(numMsh,Finley_Mesh*) : (Finley_Mesh**)NULL;
175 for (int i=0;i<numMsh;++i) {
176 AbstractContinuousDomain& meshListMember=boost::python::extract<AbstractContinuousDomain&>(meshList[i]);
177 const MeshAdapter* finley_meshListMember=static_cast<const MeshAdapter*>(&meshListMember);
178 mshes[i]=finley_meshListMember->getFinley_Mesh();
179 }
180 //
181 // merge the meshes:
182 fMesh=Finley_Mesh_merge(numMsh,mshes);
183 TMPMEMFREE(mshes);
184 //
185 // Convert any finley errors into a C++ exception
186 checkFinleyError();
187 AbstractContinuousDomain* temp=new MeshAdapter(fMesh);
188
189 return temp;
190 }
191 AbstractContinuousDomain* glueFaces(const boost::python::list& meshList,
192 double safety_factor,
193 double tolerance,
194 int optimize)
195 {
196 Finley_Mesh* fMesh=0;
197 //
198 // merge the meshes:
199 AbstractContinuousDomain* merged_meshes=meshMerge(meshList);
200 //
201 // glue the faces:
202 const MeshAdapter* merged_finley_meshes=static_cast<const MeshAdapter*>(merged_meshes);
203 fMesh=merged_finley_meshes->getFinley_Mesh();
204 Finley_Mesh_glueFaces(fMesh,safety_factor,tolerance,(optimize ? TRUE : FALSE));
205
206 //
207 // Convert any finley errors into a C++ exception
208 checkFinleyError();
209 return merged_meshes;
210 }
211 AbstractContinuousDomain* joinFaces(const boost::python::list& meshList,
212 double safety_factor,
213 double tolerance,
214 int optimize)
215 {
216 Finley_Mesh* fMesh=0;
217 //
218 // merge the meshes:
219 AbstractContinuousDomain* merged_meshes=meshMerge(meshList);
220 //
221 // join the faces:
222 const MeshAdapter* merged_finley_meshes=static_cast<const MeshAdapter*>(merged_meshes);
223 fMesh=merged_finley_meshes->getFinley_Mesh();
224 Finley_Mesh_joinFaces(fMesh,safety_factor,tolerance, (optimize ? TRUE : FALSE));
225 //
226 // Convert any finley errors into a C++ exception
227 checkFinleyError();
228 return merged_meshes;
229 }
230
231 // end of namespace
232
233 }

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26