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

Contents of /trunk/finley/src/CPPAdapter/finleycpp.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5677 - (show annotations)
Mon Jun 22 08:05:28 2015 UTC (3 years, 9 months ago) by jduplessis
File size: 16368 byte(s)
brick and rectangle documentations updates

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26