2
/*******************************************************
4
* Copyright (c) 2003-2010 by University of Queensland
5
* Earth Systems Science Computational Center (ESSCC)
6
* http://www.uq.edu.au/esscc
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
12
*******************************************************/
16
#include "esysUtils/Esys_MPI.h"
19
#include "../Dudley.h"
22
#include "MeshAdapter.h"
23
#include "MeshAdapterFactory.h"
24
#include "SystemMatrixAdapter.h"
25
#include "TransportProblemAdapter.h"
27
#include "DudleyAdapterException.h"
28
// #include "esysUtils/EsysException.h"
29
#include "esysUtils/esysExceptionTranslator.h"
31
#include "escript/AbstractContinuousDomain.h"
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>
39
using namespace boost::python;
43
Dudley is the python module name that contains the interfaces
44
to the C++ wrapper to dudley.
48
\section class_desc Class Description:
51
\section class_limits Class Limitations:
54
\section class_conds Class Conditions of Use:
57
\section throws Throws:
62
BOOST_PYTHON_MODULE(dudleycpp)
64
// This feature was added in boost v1.34
65
#if ((BOOST_VERSION/100)%1000 > 34) || (BOOST_VERSION/100000 >1)
66
// params are: bool show_user_defined, bool show_py_signatures, bool show_cpp_signatures
67
docstring_options docopt(true, true, false);
71
// NOTE: The return_value_policy is necessary for functions that
74
register_exception_translator<dudley::DudleyAdapterException>(&(esysUtils::esysExceptionTranslator));
76
def("LoadMesh",dudley::loadMesh,
77
(arg("fileName")="file.nc"),":rtype: `Domain`"
78
/* ,return_value_policy<manage_new_object>());*/
81
def("ReadMesh",dudley::readMesh,
82
(arg("fileName")="file.fly",arg("integrationOrder")=-1, arg("reducedIntegrationOrder")=-1, arg("optimize")=true)
83
/* ,return_value_policy<manage_new_object>());*/
84
,"Read a mesh from a file. For MPI parallel runs fan out the mesh to multiple processes.\n\n"
85
":rtype: `Domain`\n:param fileName:\n:type fileName: ``string``\n"
86
":param integrationOrder: order of the quadrature scheme. If *integrationOrder<0* the integration order is selected independently.\n"
87
":type integrationOrder: ``int``\n"
88
":param reducedIntegrationOrder: order of the quadrature scheme. If *reducedIntegrationOrder<0* the integration order is selected independently.\n"
89
":param optimize: Enable optimisation of node labels\n:type optimize: ``bool``");
91
def("ReadGmsh",dudley::readGmsh,
92
(arg("fileName")="file.msh",
94
arg("integrationOrder")=-1,
95
arg("reducedIntegrationOrder")=-1,
97
arg("useMacroElements")=false)
98
// ,return_value_policy<manage_new_object>());
99
,"Read a gmsh mesh file\n\n"
100
":rtype: `Domain`\n:param fileName:\n:type fileName: ``string``\n"
101
":param integrationOrder: order of the quadrature scheme. If *integrationOrder<0* the integration order is selected independently.\n"
102
":type integrationOrder: ``int``\n"
103
":param reducedIntegrationOrder: order of the quadrature scheme. If *reducedIntegrationOrder<0* the integration order is selected independently.\n"
104
":param optimize: Enable optimisation of node labels\n:type optimize: ``bool``\n"
105
":param useMacroElements: Enable the usage of macro elements instead of second order elements.\n:type useMacroElements: ``bool``"
108
def ("Brick",dudley::brick,
109
(arg("n0")=1,arg("n1")=1,arg("n2")=1,
111
arg("l0")=1.0,arg("l1")=1.0,arg("l2")=1.0,
112
arg("periodic0")=false,arg("periodic1")=false,arg("periodic2")=false,
113
arg("integrationOrder")=-1, arg("reducedIntegrationOrder")=-1,
114
arg("useElementsOnFace")=false,
115
arg("useFullElementOrder")=false,
116
arg("optimize")=false)
117
,"Creates a rectangular mesh with n0 x n1 x n2 elements over the brick [0,l0] x [0,l1] x [0,l2]."
118
"\n\n:param n0:\n:type n0:\n:param n1:\n:type n1:\n:param n2:\n:type n2:\n"
119
":param order: =1, =-1 or =2 gives the order of shape function. If -1 macro elements of order 1 are used.\n"
120
":param l0: length of side 0\n:param l1:\n:param l2:\n"
121
":param integrationOrder: order of the quadrature scheme. If integrationOrder<0 the integration order is selected independently.\n"
122
":param reducedIntegrationOrder: order of the quadrature scheme. If reducedIntegrationOrder<0 the integration order is selected independently.\n"
123
":param useElementsOnFace: whether or not to use elements on face\n"
124
":type useElementsOnFace: ``int``"
125
":param periodic0: whether or not boundary conditions are periodic\n"
126
":param periodic1:\n:param periodic2:\n"
127
":param useFullElementOrder:\n:param optimize:\n"
128
":param optimize: Enable optimisation of node labels\n:type optimize: ``bool``"
131
def ("Rectangle",dudley::rectangle,
132
(arg("n0")=1,arg("n1")=1,arg("order")=1,
133
arg("l0")=1.0,arg("l1")=1.0,
134
arg("periodic0")=false,arg("periodic1")=false,
135
arg("integrationOrder")=-1, arg("reducedIntegrationOrder")=-1,
136
arg("useElementsOnFace")=false,
137
arg("useFullElementOrder")=false,
138
arg("optimize")=false)
139
,"Creates a rectangular mesh with n0 x n1 elements over the brick [0,l0] x [0,l1]."
140
"\n\n:param n0:\n:type n0:\n:param n1:\n:type n1:\n"
141
":param order: =1, =-1 or =2 gives the order of shape function. If -1 macro elements of order 1 are used.\n"
142
":param l0: length of side 0\n:param l1:\n"
143
":param integrationOrder: order of the quadrature scheme. If integrationOrder<0 the integration order is selected independently.\n"
144
":param reducedIntegrationOrder: order of the quadrature scheme. If reducedIntegrationOrder<0 the integration order is selected independently.\n"
145
":param useElementsOnFace: whether or not to use elements on face\n"
146
":type useElementsOnFace: ``int``"
147
":param periodic0: whether or not boundary conditions are periodic\n"
148
":param periodic1:\n"
149
":param useFullElementOrder:\n:param optimize:\n"
150
":param useMacroElements: Enable the usage of first order macro elements.\n:type useMacroElements: ``bool``\n"
151
":param optimize: Enable optimisation of node labels\n:type optimize: ``bool``"
154
class_<dudley::MeshAdapter, bases<escript::AbstractContinuousDomain> >
155
("MeshAdapter","A concrete class representing a domain. For more details, please consult the c++ documentation.",init<optional <Dudley_Mesh*> >())
156
.def(init<const dudley::MeshAdapter&>())
157
.def("write",&dudley::MeshAdapter::write,args("filename"),
158
"Write the current mesh to a file with the given name.")
159
.def("print_mesh_info",&dudley::MeshAdapter::Print_Mesh_Info,(arg("full")=false),
160
":param full:\n:type full: ``bool``")
161
.def("dump",&dudley::MeshAdapter::dump,args("fileName")
162
,"dumps the mesh to a file with the given name.")
163
.def("getDescription",&dudley::MeshAdapter::getDescription,
164
":return: a description for this domain\n:rtype: ``string``")
165
.def("getDim",&dudley::MeshAdapter::getDim,":rtype: ``int``")
166
.def("getDataShape",&dudley::MeshAdapter::getDataShape, args("functionSpaceCode"),
167
":return: a pair (dps, ns) where dps=the number of data points per sample, and ns=the number of samples\n:rtype: ``tuple``")
168
.def("getNumDataPointsGlobal",&dudley::MeshAdapter::getNumDataPointsGlobal,
169
":return: the number of data points summed across all MPI processes\n"
171
.def("addPDEToSystem",&dudley::MeshAdapter::addPDEToSystem,
172
args("mat", "rhs","A", "B", "C", "D", "X", "Y", "d", "y"),
173
"adds a PDE onto the stiffness matrix mat and a rhs\n\n"
174
":param mat:\n:type mat: `OperatorAdapter`\n:param rhs:\n:type rhs: `Data`\n"
175
":param A:\n:type A: `Data`\n"
176
":param B:\n:type B: `Data`\n"
177
":param C:\n:type C: `Data`\n"
178
":param D:\n:type D: `Data`\n"
179
":param X:\n:type X: `Data`\n"
180
":param Y:\n:type Y: `Data`\n"
181
":param d:\n:type d: `Data`\n"
183
.def("addPDEToLumpedSystem",&dudley::MeshAdapter::addPDEToLumpedSystem,
184
args("mat", "D", "d"),
185
"adds a PDE onto the lumped stiffness matrix\n\n"
186
":param mat:\n:type mat: `Data`\n"
187
":param D:\n:type D: `Data`\n"
188
":param d:\n:type d: `Data`\n")
189
.def("addPDEToRHS",&dudley::MeshAdapter::addPDEToRHS,
190
args("rhs", "X", "Y", "y", "y_contact"),
191
"adds a PDE onto the stiffness matrix mat and a rhs\n\n"
192
":param rhs:\n:type rhs: `Data`\n"
193
":param X:\n:type X: `Data`\n"
194
":param Y:\n:type Y: `Data`\n"
195
":param y:\n:type y: `Data`\n"
197
.def("addPDEToTransportProblem",&dudley::MeshAdapter::addPDEToTransportProblem,
198
args( "tp", "source", "M", "A", "B", "C", "D", "X", "Y", "d", "y", "d_contact", "y_contact"),
199
":param tp:\n:type tp: `TransportProblemAdapter`\n"
200
":param source:\n:type source: `Data`\n"
201
":param M:\n:type M: `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 y:\n:type y: `Data`\n"
210
":param d_contact:\n:type d_contact: `Data`\n"
211
":param y_contact:\n:type y_contact: `Data`\n"
213
.def("newOperator",&dudley::MeshAdapter::newSystemMatrix,
214
args("row_blocksize", "row_functionspace", "column_blocksize", "column_functionspace", "type"),
215
"creates a SystemMatrixAdapter stiffness matrix and initializes it with zeros\n\n"
216
":param row_blocksize:\n:type row_blocksize: ``int``\n"
217
":param row_functionspace:\n:type row_functionspace: `FunctionSpace`\n"
218
":param column_blocksize:\n:type column_blocksize: ``int``\n"
219
":param column_functionspace:\n:type column_functionspace: `FunctionSpace`\n"
220
":param type:\n:type type: ``int``\n"
222
.def("newTransportProblem",&dudley::MeshAdapter::newTransportProblem,
223
args("theta", "blocksize", "functionspace", "type"),
224
"creates a TransportProblemAdapter\n\n"
225
":param theta:\n:type theta: ``float``\n"
226
":param blocksize:\n:type blocksize: ``int``\n"
227
":param functionspace:\n:type functionspace: `FunctionSpace`\n"
228
":param type:\n:type type: ``int``\n"
230
.def("getSystemMatrixTypeId",&dudley::MeshAdapter::getSystemMatrixTypeId,
231
args("solver", "preconditioner", "package", "symmetry"),
232
":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"
234
":param solver:\n:type solver: ``int``\n"
235
":param preconditioner:\n:type preconditioner: ``int``\n"
236
":param package:\n:type package: ``int``\n"
237
":param symmetry:\n:type symmetry: ``int``\n"
239
.def("getTransportTypeId",&dudley::MeshAdapter::getTransportTypeId,
240
args("solver", "preconditioner", "package", "symmetry"),
241
":return: the identifier of the transport problem type to be used when a particular solver, perconditioner, package and symmetric matrix is used.\n"
243
":param solver:\n:type solver: ``int``\n"
244
":param preconditioner:\n:type preconditioner: ``int``\n"
245
":param package:\n:type package: ``int``\n"
246
":param symmetry:\n:type symmetry: ``int``\n"
248
.def("setX",&dudley::MeshAdapter::setNewX,
249
args("arg"), "assigns new location to the domain\n\n:param arg:\n:type arg: `Data`")
250
.def("getX",&dudley::MeshAdapter::getX, ":return: locations in the FEM nodes\n\n"
252
.def("getNormal",&dudley::MeshAdapter::getNormal,
253
":return: boundary normals at the quadrature point on the face elements\n"
255
.def("getSize",&dudley::MeshAdapter::getSize,":return: the element size\n"
257
.def("saveDX",&dudley::MeshAdapter::saveDX,args("filename" ,"arg"),
258
"Saves a dictonary of Data objects to an OpenDX input file. The keywords are used as identifier"
259
"\n\n:param filename: \n:type filename: ``string``\n"
260
"\n:param arg: \n:type arg: ``dict``\n")
261
.def("saveVTK",&dudley::MeshAdapter::saveVTK,
262
args("filename" ,"arg", "metadata", "metadata_schema"),
263
"Saves a dictonary of Data objects to an VTK XML input file. The keywords are used as identifier"
264
"\n\n:param filename:\n:type filename: ``string``\n"
265
":param arg:\n:type arg: ``dict``\n"
266
":param metadata:\n:type metadata: ``string``\n"
267
":param metadata_schema:\n:type metadata_schema: ``string``\n"
269
.def("setTagMap",&dudley::MeshAdapter::setTagMap,args("name","tag"),
270
"Give a tag number a name.\n\n:param name: Name for the tag\n:type name: ``string``\n"
271
":param tag: numeric id\n:type tag: ``int``\n:note: Tag names must be unique within a domain")
272
.def("getTag",&dudley::MeshAdapter::getTag,args("name"),":return: tag id for "
273
"``name``\n:rtype: ``string``")
274
.def("isValidTagName",&dudley::MeshAdapter::isValidTagName,args("name"),
275
":return: True is ``name`` corresponds to a tag\n:rtype: ``bool``")
276
.def("showTagNames",&dudley::MeshAdapter::showTagNames,":return: A space separated list of tag names\n:rtype: ``string``")
277
.def("getMPISize",&dudley::MeshAdapter::getMPISize,":return: the number of processes used for this `Domain`\n:rtype: ``int``")
278
.def("getMPIRank",&dudley::MeshAdapter::getMPIRank,":return: the rank of this process\n:rtype: ``int``")
279
.def("MPIBarrier",&dudley::MeshAdapter::MPIBarrier,"Wait until all processes have reached this point")
280
.def("onMasterProcessor",&dudley::MeshAdapter::onMasterProcessor,":return: True if this code is executing on the master process\n:rtype: `bool`");
282
class_<dudley::SystemMatrixAdapter, bases<escript::AbstractSystemMatrix> >
283
("OperatorAdapter","A concrete class representing an operator. For more details, please see the c++ documentation.", no_init)
284
.def("print_matrix_info",&dudley::SystemMatrixAdapter::Print_Matrix_Info,(arg("full")=false),"prints information about a system matrix")
285
.def("nullifyRowsAndCols",&dudley::SystemMatrixAdapter::nullifyRowsAndCols)
286
.def("resetValues",&dudley::SystemMatrixAdapter::resetValues, "resets the matrix entries")
287
.def("saveMM",&dudley::SystemMatrixAdapter::saveMM,args("fileName"),
288
"writes the matrix to a file using the Matrix Market file format")
289
.def("saveHB",&dudley::SystemMatrixAdapter::saveHB, args("filename"),
290
"writes the matrix to a file using the Harwell-Boeing file format");
292
class_<dudley::TransportProblemAdapter, bases<escript::AbstractTransportProblem> >
293
("TransportProblemAdapter","",no_init)
294
.def("getSafeTimeStepSize",&dudley::TransportProblemAdapter::getSafeTimeStepSize)
295
.def("getUnlimitedTimeStepSize",&dudley::TransportProblemAdapter::getUnlimitedTimeStepSize)
296
.def("resetTransport",&dudley::TransportProblemAdapter::resetTransport,
297
"resets the transport operator typically as they have been updated");