/[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 2881 - (hide annotations)
Thu Jan 28 02:03:15 2010 UTC (9 years, 4 months ago) by jfenwick
File size: 16784 byte(s)
Don't panic.
Updating copyright stamps

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26