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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3682 - (show annotations)
Mon Nov 21 01:56:45 2011 UTC (9 years, 8 months ago) by jfenwick
File size: 17848 byte(s)
Fixed some cases which allowed domain objects to be created without wrappers

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26