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

Diff of /branches/dirac/finley/src/CPPAdapter/finleycpp.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

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

Legend:
Removed from v.1811  
changed lines
  Added in v.3259

  ViewVC Help
Powered by ViewVC 1.1.26