/[escript]/branches/dirac/finley/src/CPPAdapter/finleycpp.cpp
ViewVC logotype

Contents of /branches/dirac/finley/src/CPPAdapter/finleycpp.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3555 - (show annotations)
Thu Aug 25 08:54:10 2011 UTC (7 years, 9 months ago) by jfenwick
File size: 17726 byte(s)
Committing for home transfer

1
2 /*******************************************************
3 *
4 * Copyright (c) 2003-2010 by University of Queensland
5 * Earth Systems Science Computational Center (ESSCC)
6 * http://www.uq.edu.au/esscc
7 *
8 * Primary Business: Queensland, Australia
9 * Licensed under the Open Software License version 3.0
10 * http://www.opensource.org/licenses/osl-3.0.php
11 *
12 *******************************************************/
13
14
15 #ifdef ESYS_MPI
16 #include "esysUtils/Esys_MPI.h"
17 #endif
18 extern "C" {
19 #include "../Finley.h"
20 }
21
22 #include "MeshAdapter.h"
23 #include "MeshAdapterFactory.h"
24 #include "SystemMatrixAdapter.h"
25 #include "TransportProblemAdapter.h"
26
27 #include "FinleyAdapterException.h"
28 // #include "esysUtils/EsysException.h"
29 #include "esysUtils/esysExceptionTranslator.h"
30
31 #include "escript/AbstractContinuousDomain.h"
32
33 #include <boost/python.hpp>
34 #include <boost/python/module.hpp>
35 #include <boost/python/def.hpp>
36 #include <boost/python/detail/defaults_gen.hpp>
37 #include <boost/version.hpp>
38
39 using namespace boost::python;
40
41 /**
42 \page finley Finley
43 Finley is the python module name that contains the interfaces
44 to the C++ wrapper to finley.
45
46 \version 1.0.0
47
48 \section class_desc Class Description:
49 Data
50
51 \section class_limits Class Limitations:
52 None
53
54 \section class_conds Class Conditions of Use:
55 None
56
57 \section throws Throws:
58 None
59
60 */
61
62 //
63 // The BOOST_PYTHON_FUNCTION_OVERLOADS macro generates function overloads for optional
64 // arguments to the respective finley functions.
65 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
66 //
67 // NOTE: If the number of arguments to the finley functions change
68 // the magic numbers in the BOOST_PYTHON_FUNCTION_OVERLOADS call
69 // must change.
70 //
71 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
72 // BOOST_PYTHON_FUNCTION_OVERLOADS(readMesh_overloads,finley::readMesh,1,2)
73 // BOOST_PYTHON_FUNCTION_OVERLOADS(brick_overloads,finley::brick,0,12)
74 // BOOST_PYTHON_FUNCTION_OVERLOADS(rectangle_overloads,finley::rectangle,0,9)
75 // BOOST_PYTHON_FUNCTION_OVERLOADS(interval_overloads,finley::interval,0,6)
76 // BOOST_PYTHON_FUNCTION_OVERLOADS(glueFaces_overloads,finley::glueFaces,1,3)
77 // BOOST_PYTHON_FUNCTION_OVERLOADS(joinFaces_overloads,finley::joinFaces,1,3)
78
79 BOOST_PYTHON_MODULE(finleycpp)
80 {
81 // This feature was added in boost v1.34
82 #if ((BOOST_VERSION/100)%1000 > 34) || (BOOST_VERSION/100000 >1)
83 // params are: bool show_user_defined, bool show_py_signatures, bool show_cpp_signatures
84 docstring_options docopt(true, true, false);
85 #endif
86
87 //
88 // NOTE: The return_value_policy is necessary for functions that
89 // return pointers.
90 //
91 register_exception_translator<finley::FinleyAdapterException>(&(esysUtils::esysExceptionTranslator));
92
93 def("LoadMesh",finley::loadMesh,
94 (arg("fileName")="file.nc"),":rtype: `Domain`"
95 /* ,return_value_policy<manage_new_object>());*/
96 );
97
98 def("ReadMesh",finley::readMesh,
99 (arg("fileName")="file.fly",arg("integrationOrder")=-1, arg("reducedIntegrationOrder")=-1, arg("optimize")=true)
100 /* ,return_value_policy<manage_new_object>());*/
101 ,"Read a mesh from a file. For MPI parallel runs fan out the mesh to multiple processes.\n\n"
102 ":rtype: `Domain`\n:param fileName:\n:type fileName: ``string``\n"
103 ":param integrationOrder: order of the quadrature scheme. If *integrationOrder<0* the integration order is selected independently.\n"
104 ":type integrationOrder: ``int``\n"
105 ":param reducedIntegrationOrder: order of the quadrature scheme. If *reducedIntegrationOrder<0* the integration order is selected independently.\n"
106 ":param optimize: Enable optimisation of node labels\n:type optimize: ``bool``");
107
108 def("ReadGmsh",finley::readGmsh,
109 (arg("fileName")="file.msh",
110 arg("numDim"),
111 arg("integrationOrder")=-1,
112 arg("reducedIntegrationOrder")=-1,
113 arg("optimize")=true,
114 arg("useMacroElements")=false)
115 // ,return_value_policy<manage_new_object>());
116 ,"Read a gmsh mesh file\n\n"
117 ":rtype: `Domain`\n:param fileName:\n:type fileName: ``string``\n"
118 ":param integrationOrder: order of the quadrature scheme. If *integrationOrder<0* the integration order is selected independently.\n"
119 ":type integrationOrder: ``int``\n"
120 ":param reducedIntegrationOrder: order of the quadrature scheme. If *reducedIntegrationOrder<0* the integration order is selected independently.\n"
121 ":param optimize: Enable optimisation of node labels\n:type optimize: ``bool``\n"
122 ":param useMacroElements: Enable the usage of macro elements instead of second order elements.\n:type useMacroElements: ``bool``"
123 );
124
125 def ("__Brick_driver",finley::brick_driver,
126 (arg("params"))
127 ,"Creates a rectangular mesh with n0 x n1 x n2 elements over the brick [0,l0] x [0,l1] x [0,l2]."
128 "\n\n:param n0:\n:type n0:\n:param n1:\n:type n1:\n:param n2:\n:type n2:\n"
129 ":param order: =1, =-1 or =2 gives the order of shape function. If -1 macro elements of order 1 are used.\n"
130 ":param l0: length of side 0\n:param l1:\n:param l2:\n"
131 ":param integrationOrder: order of the quadrature scheme. If integrationOrder<0 the integration order is selected independently.\n"
132 ":param reducedIntegrationOrder: order of the quadrature scheme. If reducedIntegrationOrder<0 the integration order is selected independently.\n"
133 ":param useElementsOnFace: whether or not to use elements on face\n"
134 ":type useElementsOnFace: ``int``"
135 ":param periodic0: whether or not boundary conditions are periodic\n"
136 ":param periodic1:\n:param periodic2:\n"
137 ":param useFullElementOrder:\n:param optimize:\n"
138 ":param optimize: Enable optimisation of node labels\n:type optimize: ``bool``"
139 );
140
141 def ("__Rectangle_driver",finley::rectangle_driver,
142 (arg("args"))
143 // ,return_value_policy<manage_new_object>());
144 ,"Creates a rectangular mesh with n0 x n1 elements over the brick [0,l0] x [0,l1]."
145 "\n\n:param n0:\n:type n0:\n:param n1:\n:type n1:\n"
146 ":param order: =1, =-1 or =2 gives the order of shape function. If -1 macro elements of order 1 are used.\n"
147 ":param l0: length of side 0\n:param l1:\n"
148 ":param integrationOrder: order of the quadrature scheme. If integrationOrder<0 the integration order is selected independently.\n"
149 ":param reducedIntegrationOrder: order of the quadrature scheme. If reducedIntegrationOrder<0 the integration order is selected independently.\n"
150 ":param useElementsOnFace: whether or not to use elements on face\n"
151 ":type useElementsOnFace: ``int``"
152 ":param periodic0: whether or not boundary conditions are periodic\n"
153 ":param periodic1:\n"
154 ":param useFullElementOrder:\n:param optimize:\n"
155 ":param useMacroElements: Enable the usage of first order macro elements.\n:type useMacroElements: ``bool``\n"
156 ":param optimize: Enable optimisation of node labels\n:type optimize: ``bool``"
157 );
158
159 def("Merge",finley::meshMerge,args("meshList")
160 // ,return_value_policy<manage_new_object>());
161 ,"Merges a list of meshes into one mesh.\n\n:rtype: `Domain`"
162 );
163
164 def("GlueFaces",finley::glueFaces,
165 (arg("meshList"),arg("safetyFactor")=0.2,
166 arg("tolerance")=1.e-8,
167 arg("optimize")=true)
168 // ,return_value_policy<manage_new_object>());
169 ,"Detects matching faces in the mesh, removes them from the mesh and joins the elements touched by the face elements."
170 );
171
172 def("JoinFaces",finley::joinFaces,
173 (arg("meshList"), arg("safetyFactor")=0.2,
174 arg("tolerance")=1.e-8,
175 arg("optimize")=true)
176 // ,return_value_policy<manage_new_object>());
177 ,"Detects matching faces in the mesh and replaces them by joint elements."
178 );
179
180
181 class_<finley::MeshAdapter, bases<escript::AbstractContinuousDomain> >
182 ("MeshAdapter","A concrete class representing a domain. For more details, please consult the c++ documentation.",init<optional <Finley_Mesh*> >())
183 .def(init<const finley::MeshAdapter&>())
184 .def("write",&finley::MeshAdapter::write,args("filename"),
185 "Write the current mesh to a file with the given name.")
186 .def("print_mesh_info",&finley::MeshAdapter::Print_Mesh_Info,(arg("full")=false),
187 ":param full:\n:type full: ``bool``")
188 .def("dump",&finley::MeshAdapter::dump,args("fileName")
189 ,"dumps the mesh to a file with the given name.")
190 .def("getDescription",&finley::MeshAdapter::getDescription,
191 ":return: a description for this domain\n:rtype: ``string``")
192 .def("getDim",&finley::MeshAdapter::getDim,":rtype: ``int``")
193 .def("getDataShape",&finley::MeshAdapter::getDataShape, args("functionSpaceCode"),
194 ":return: a pair (dps, ns) where dps=the number of data points per sample, and ns=the number of samples\n:rtype: ``tuple``")
195 .def("getNumDataPointsGlobal",&finley::MeshAdapter::getNumDataPointsGlobal,
196 ":return: the number of data points summed across all MPI processes\n"
197 ":rtype: ``int``")
198 .def("addPDEToSystem",&finley::MeshAdapter::addPDEToSystem,
199 args("mat", "rhs","A", "B", "C", "D", "X", "Y", "d", "y", "d_contact", "y_contact"),
200 "adds a PDE onto the stiffness matrix mat and a rhs\n\n"
201 ":param mat:\n:type mat: `OperatorAdapter`\n:param rhs:\n:type rhs: `Data`\n"
202 ":param A:\n:type A: `Data`\n"
203 ":param B:\n:type B: `Data`\n"
204 ":param C:\n:type C: `Data`\n"
205 ":param D:\n:type D: `Data`\n"
206 ":param X:\n:type X: `Data`\n"
207 ":param Y:\n:type Y: `Data`\n"
208 ":param d:\n:type d: `Data`\n"
209 ":param d_contact:\n:type d_contact: `Data`\n"
210 ":param y_contact:\n:type y_contact: `Data`\n"
211 )
212 .def("addPDEToLumpedSystem",&finley::MeshAdapter::addPDEToLumpedSystem,
213 args("mat", "D", "d"),
214 "adds a PDE onto the lumped stiffness matrix\n\n"
215 ":param mat:\n:type mat: `Data`\n"
216 ":param D:\n:type D: `Data`\n"
217 ":param d:\n:type d: `Data`\n"
218 ":param useHRZ:\n:type useHRZ: bool\n")
219 .def("addPDEToRHS",&finley::MeshAdapter::addPDEToRHS,
220 args("rhs", "X", "Y", "y", "y_contact"),
221 "adds a PDE onto the stiffness matrix mat and a rhs\n\n"
222 ":param rhs:\n:type rhs: `Data`\n"
223 ":param X:\n:type X: `Data`\n"
224 ":param Y:\n:type Y: `Data`\n"
225 ":param y:\n:type y: `Data`\n"
226 ":param y_contact:\n:type y_contact: `Data`"
227 )
228 .def("addPDEToTransportProblem",&finley::MeshAdapter::addPDEToTransportProblem,
229 args( "tp", "source", "M", "A", "B", "C", "D", "X", "Y", "d", "y", "d_contact", "y_contact"),
230 ":param tp:\n:type tp: `TransportProblemAdapter`\n"
231 ":param source:\n:type source: `Data`\n"
232 ":param M:\n:type M: `Data`\n"
233 ":param A:\n:type A: `Data`\n"
234 ":param B:\n:type B: `Data`\n"
235 ":param C:\n:type C: `Data`\n"
236 ":param D:\n:type D: `Data`\n"
237 ":param X:\n:type X: `Data`\n"
238 ":param Y:\n:type Y: `Data`\n"
239 ":param d:\n:type d: `Data`\n"
240 ":param y:\n:type y: `Data`\n"
241 ":param d_contact:\n:type d_contact: `Data`\n"
242 ":param y_contact:\n:type y_contact: `Data`\n"
243 )
244 .def("newOperator",&finley::MeshAdapter::newSystemMatrix,
245 args("row_blocksize", "row_functionspace", "column_blocksize", "column_functionspace", "type"),
246 "creates a SystemMatrixAdapter stiffness matrix and initializes it with zeros\n\n"
247 ":param row_blocksize:\n:type row_blocksize: ``int``\n"
248 ":param row_functionspace:\n:type row_functionspace: `FunctionSpace`\n"
249 ":param column_blocksize:\n:type column_blocksize: ``int``\n"
250 ":param column_functionspace:\n:type column_functionspace: `FunctionSpace`\n"
251 ":param type:\n:type type: ``int``\n"
252 )
253 .def("newTransportProblem",&finley::MeshAdapter::newTransportProblem,
254 args("theta", "blocksize", "functionspace", "type"),
255 "creates a TransportProblemAdapter\n\n"
256 ":param theta:\n:type theta: ``float``\n"
257 ":param blocksize:\n:type blocksize: ``int``\n"
258 ":param functionspace:\n:type functionspace: `FunctionSpace`\n"
259 ":param type:\n:type type: ``int``\n"
260 )
261 .def("getSystemMatrixTypeId",&finley::MeshAdapter::getSystemMatrixTypeId,
262 args("solver", "preconditioner", "package", "symmetry"),
263 ":return: the identifier of the matrix type to be used for the global stiffness matrix when a particular solver, package, perconditioner, and symmetric matrix is used.\n"
264 ":rtype: ``int``\n"
265 ":param solver:\n:type solver: ``int``\n"
266 ":param preconditioner:\n:type preconditioner: ``int``\n"
267 ":param package:\n:type package: ``int``\n"
268 ":param symmetry:\n:type symmetry: ``int``\n"
269 )
270 .def("getTransportTypeId",&finley::MeshAdapter::getTransportTypeId,
271 args("solver", "preconditioner", "package", "symmetry"),
272 ":return: the identifier of the transport problem type to be used when a particular solver, perconditioner, package and symmetric matrix is used.\n"
273 ":rtype: ``int``\n"
274 ":param solver:\n:type solver: ``int``\n"
275 ":param preconditioner:\n:type preconditioner: ``int``\n"
276 ":param package:\n:type package: ``int``\n"
277 ":param symmetry:\n:type symmetry: ``int``\n"
278 )
279 .def("setX",&finley::MeshAdapter::setNewX,
280 args("arg"), "assigns new location to the domain\n\n:param arg:\n:type arg: `Data`")
281 .def("getX",&finley::MeshAdapter::getX, ":return: locations in the FEM nodes\n\n"
282 ":rtype: `Data`")
283 .def("getNormal",&finley::MeshAdapter::getNormal,
284 ":return: boundary normals at the quadrature point on the face elements\n"
285 ":rtype: `Data`")
286 .def("getSize",&finley::MeshAdapter::getSize,":return: the element size\n"
287 ":rtype: `Data`")
288 .def("saveDX",&finley::MeshAdapter::saveDX,args("filename" ,"arg"),
289 "Saves a dictonary of Data objects to an OpenDX input file. The keywords are used as identifier"
290 "\n\n:param filename: \n:type filename: ``string``\n"
291 "\n:param arg: \n:type arg: ``dict``\n")
292 .def("saveVTK",&finley::MeshAdapter::saveVTK,
293 args("filename" ,"arg", "metadata", "metadata_schema"),
294 "Saves a dictonary of Data objects to an VTK XML input file. The keywords are used as identifier"
295 "\n\n:param filename:\n:type filename: ``string``\n"
296 ":param arg:\n:type arg: ``dict``\n"
297 ":param metadata:\n:type metadata: ``string``\n"
298 ":param metadata_schema:\n:type metadata_schema: ``string``\n"
299 )
300 .def("setTagMap",&finley::MeshAdapter::setTagMap,args("name","tag"),
301 "Give a tag number a name.\n\n:param name: Name for the tag\n:type name: ``string``\n"
302 ":param tag: numeric id\n:type tag: ``int``\n:note: Tag names must be unique within a domain")
303 .def("getTag",&finley::MeshAdapter::getTag,args("name"),":return: tag id for "
304 "``name``\n:rtype: ``string``")
305 .def("isValidTagName",&finley::MeshAdapter::isValidTagName,args("name"),
306 ":return: True is ``name`` corresponds to a tag\n:rtype: ``bool``")
307 .def("showTagNames",&finley::MeshAdapter::showTagNames,":return: A space separated list of tag names\n:rtype: ``string``")
308 .def("getMPISize",&finley::MeshAdapter::getMPISize,":return: the number of processes used for this `Domain`\n:rtype: ``int``")
309 .def("getMPIRank",&finley::MeshAdapter::getMPIRank,":return: the rank of this process\n:rtype: ``int``")
310 .def("MPIBarrier",&finley::MeshAdapter::MPIBarrier,"Wait until all processes have reached this point")
311 .def("onMasterProcessor",&finley::MeshAdapter::onMasterProcessor,":return: True if this code is executing on the master process\n:rtype: `bool`")
312 // .def("addDiracPoints", &finley::MeshAdapter::addDiracPoints,(arg("points"), arg("tags")=finley::EmptyPythonList),
313 // "adds points to support more Dirac delta function.\n\n"
314 // ":param points: list of points where Dirac delta function are to be defined. The location will be adjusted to\n"
315 // " to match the nearest node of the finite element mesh.\n:type points: ``list`` of ``list``s of ``floats``\n"
316 // ":param tags: list of tags to be assigned to the points.\n:type tags: ``list`` of ``int``s or ``strings``\n"
317 // )
318 // .def("addDiracPoint", &finley::MeshAdapter::addDiracPoint,(arg("point"), arg("tag")=-1),
319 // "adds a point to support more Dirac delta function.\n\n"
320 // ":param point: point where Dirac delta function are to be defined. The location will be adjusted to\n"
321 // " to match the nearest node of the finite element mesh.\n:type point: ``list`` of ``floats``\n"
322 // ":param tags: tag to be assigned to the point.\n:type tag: ``int``s or ``strings``\n"
323 // )
324 // .def("addDiracPoint", &finley::MeshAdapter::addDiracPointWithTagName,(arg("point"), arg("tag")),
325 // "adds a point to support more Dirac delta function.\n\n"
326 // ":param point: point where Dirac delta function are to be defined. The location will be adjusted to\n"
327 // " to match the nearest node of the finite element mesh.\n:type point: ``list`` of ``floats``\n"
328 // ":param tags: tag to be assigned to the point.\n:type tag: ``int``s or ``strings``\n"
329 // )
330 ;
331
332 class_<finley::SystemMatrixAdapter, bases<escript::AbstractSystemMatrix> >
333 ("OperatorAdapter","A concrete class representing an operator. For more details, please see the c++ documentation.", no_init)
334 .def("print_matrix_info",&finley::SystemMatrixAdapter::Print_Matrix_Info,(arg("full")=false),"prints information about a system matrix")
335 .def("nullifyRowsAndCols",&finley::SystemMatrixAdapter::nullifyRowsAndCols)
336 .def("resetValues",&finley::SystemMatrixAdapter::resetValues, "resets the matrix entries")
337 .def("saveMM",&finley::SystemMatrixAdapter::saveMM,args("fileName"),
338 "writes the matrix to a file using the Matrix Market file format")
339 .def("saveHB",&finley::SystemMatrixAdapter::saveHB, args("filename"),
340 "writes the matrix to a file using the Harwell-Boeing file format");
341
342 class_<finley::TransportProblemAdapter, bases<escript::AbstractTransportProblem> >
343 ("TransportProblemAdapter","",no_init)
344 .def("getSafeTimeStepSize",&finley::TransportProblemAdapter::getSafeTimeStepSize)
345 .def("getUnlimitedTimeStepSize",&finley::TransportProblemAdapter::getUnlimitedTimeStepSize)
346 .def("resetTransport",&finley::TransportProblemAdapter::resetTransport,
347 "resets the transport operator typically as they have been updated");
348 }

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26