/[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 480 - (show annotations)
Wed Feb 1 05:15:12 2006 UTC (13 years, 7 months ago) by jgs
File size: 6655 byte(s)
rationalise #includes and forward declarations

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 char fName[fileName.size()+1];
35 strcpy(fName,fileName.c_str());
36 Finley_Mesh* fMesh=Finley_Mesh_read(fName,integrationOrder);
37 checkFinleyError();
38 AbstractContinuousDomain* temp=new MeshAdapter(fMesh);
39 return temp;
40 }
41
42 AbstractContinuousDomain* brick(int n0,int n1,int n2,int order,
43 double l0,double l1,double l2,
44 int periodic0,int periodic1,
45 int periodic2,
46 int integrationOrder,
47 int useElementsOnFace)
48 {
49 // cout << "n0=" << n0 << " n1=" << n1 << " n2=" << n2
50 // << " order=" << order
51 // << " l0=" << l0 << " l1=" << l1 << " l2=" << l2
52 // << " periodic0=" << periodic0
53 // << " periodic1=" << periodic1
54 // << " periodic2=" << periodic2
55 // << " integerationOrder=" << integrationOrder
56 // << " useElementsOnFace=" << useElementsOnFace << endl;
57
58 int numElements[]={n0,n1,n2};
59 double length[]={l0,l1,l2};
60 int periodic[]={periodic0, periodic1, periodic2};
61
62 //
63 // linearInterpolation
64 Finley_Mesh* fMesh;
65 if (order==1) {
66 fMesh=Finley_RectangularMesh_Hex8(numElements,length,periodic,integrationOrder,
67 useElementsOnFace) ;
68 } else if (order==2) {
69 fMesh=Finley_RectangularMesh_Hex20(numElements,length,periodic,integrationOrder,
70 useElementsOnFace) ;
71 } else {
72 stringstream temp;
73 temp << "Illegal interpolation order: " << order;
74 setFinleyError(VALUE_ERROR,temp.str().c_str());
75 }
76 //
77 // Convert any finley errors into a C++ exception
78 checkFinleyError();
79 AbstractContinuousDomain* temp=new MeshAdapter(fMesh);
80 return temp;
81 }
82 AbstractContinuousDomain* rectangle(int n0,int n1,int order,
83 double l0, double l1,
84 int periodic0,int periodic1,
85 int integrationOrder,
86 int useElementsOnFace)
87 {
88 int numElements[]={n0,n1};
89 double length[]={l0,l1};
90 int periodic[]={periodic0, periodic1};
91
92 Finley_Mesh* fMesh;
93 if (order==1) {
94 fMesh=Finley_RectangularMesh_Rec4(numElements, length,periodic,integrationOrder,
95 useElementsOnFace);
96 } else if (order==2) {
97 fMesh=Finley_RectangularMesh_Rec8(numElements,length,periodic,integrationOrder,
98 useElementsOnFace);
99 } else {
100 stringstream temp;
101 temp << "Illegal interpolation order: " << order;
102 setFinleyError(VALUE_ERROR,temp.str().c_str());
103 }
104 //
105 // Convert any finley errors into a C++ exception
106 checkFinleyError();
107 AbstractContinuousDomain* temp=new MeshAdapter(fMesh);
108 return temp;
109 }
110 AbstractContinuousDomain* interval(int n0,int order,double l0,int periodic0,
111 int integrationOrder,
112 int useElementsOnFace)
113 {
114 int numElements[]={n0};
115 double length[]={l0};
116 int periodic[]={periodic0};
117 Finley_Mesh* fMesh;
118 if (order==1) {
119 fMesh=Finley_RectangularMesh_Line2(numElements, length,periodic,integrationOrder,
120 useElementsOnFace);
121 } else if (order==2) {
122 fMesh=Finley_RectangularMesh_Line3(numElements,length,periodic,integrationOrder,
123 useElementsOnFace);
124 } else {
125 stringstream temp;
126 temp << "Illegal interpolation order: " << order;
127 setFinleyError(VALUE_ERROR,temp.str().c_str());
128 }
129 //
130 // Convert any finley errors into a C++ exception
131 checkFinleyError();
132 AbstractContinuousDomain* temp=new MeshAdapter(fMesh);
133 return temp;
134 }
135 AbstractContinuousDomain* meshMerge(const boost::python::list& meshList)
136 {
137 Finley_Mesh* fMesh=0;
138 //
139 // extract the meshes from meshList
140 int numMsh=boost::python::extract<int>(meshList.attr("__len__")());
141 Finley_Mesh* mshes[numMsh];
142 for (int i=0;i<numMsh;++i) {
143 AbstractContinuousDomain& meshListMember=boost::python::extract<AbstractContinuousDomain&>(meshList[i]);
144 const MeshAdapter* finley_meshListMember=static_cast<const MeshAdapter*>(&meshListMember);
145 mshes[i]=finley_meshListMember->getFinley_Mesh();
146 }
147 //
148 // merge the meshes:
149 fMesh=Finley_Mesh_merge(numMsh,mshes);
150 //
151 // Convert any finley errors into a C++ exception
152 checkFinleyError();
153 AbstractContinuousDomain* temp=new MeshAdapter(fMesh);
154 return temp;
155 }
156 AbstractContinuousDomain* glueFaces(const boost::python::list& meshList,
157 double safety_factor,
158 double tolerance)
159 {
160 Finley_Mesh* fMesh=0;
161 //
162 // merge the meshes:
163 AbstractContinuousDomain* merged_meshes=meshMerge(meshList);
164 //
165 // glue the faces:
166 const MeshAdapter* merged_finley_meshes=static_cast<const MeshAdapter*>(merged_meshes);
167 fMesh=merged_finley_meshes->getFinley_Mesh();
168 Finley_Mesh_glueFaces(fMesh,safety_factor,tolerance);
169 //
170 // Convert any finley errors into a C++ exception
171 checkFinleyError();
172 return merged_meshes;
173 }
174 AbstractContinuousDomain* joinFaces(const boost::python::list& meshList,
175 double safety_factor,
176 double tolerance)
177 {
178 Finley_Mesh* fMesh=0;
179 //
180 // merge the meshes:
181 AbstractContinuousDomain* merged_meshes=meshMerge(meshList);
182 //
183 // join the faces:
184 const MeshAdapter* merged_finley_meshes=static_cast<const MeshAdapter*>(merged_meshes);
185 fMesh=merged_finley_meshes->getFinley_Mesh();
186 Finley_Mesh_joinFaces(fMesh,safety_factor,tolerance);
187 //
188 // Convert any finley errors into a C++ exception
189 checkFinleyError();
190 return merged_meshes;
191 }
192
193 } // end of namespace

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26