/[escript]/branches/domexper/dudley/src/CPPAdapter/dudleycpp.cpp
ViewVC logotype

Contents of /branches/domexper/dudley/src/CPPAdapter/dudleycpp.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3115 - (show annotations)
Sun Aug 29 23:14:35 2010 UTC (8 years, 9 months ago) by jfenwick
File size: 15610 byte(s)
Now have cubes facing the correct direction

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

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision
svn:mergeinfo /branches/lapack2681/finley/src/CPPAdapter/finleycpp.cpp:2682-2741 /branches/restext/finley/src/CPPAdapter/finleycpp.cpp:2610-2624 /branches/stage3.0/finley/src/CPPAdapter/finleycpp.cpp:2569-2590 /release/3.0/finley/src/CPPAdapter/finleycpp.cpp:2591-2601

  ViewVC Help
Powered by ViewVC 1.1.26