/[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 110 - (show annotations)
Mon Feb 14 04:14:42 2005 UTC (14 years, 7 months ago) by jgs
Original Path: trunk/esys2/finley/src/CPPAdapter/MeshAdapterFactory.cpp
File size: 6837 byte(s)
*** empty log message ***

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26