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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3991 - (hide annotations)
Tue Sep 25 23:52:22 2012 UTC (7 years, 1 month ago) by caltinay
File size: 17530 byte(s)
Updated doxygen cfg file and made a few first changes to doco.

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26