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

Diff of /branches/diaplayground/dudley/src/CPPAdapter/dudleycpp.cpp

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

trunk/finley/src/CPPAdapter/finleycpp.cpp revision 1388 by trankine, Fri Jan 11 07:45:58 2008 UTC trunk/dudley/src/CPPAdapter/dudleycpp.cpp revision 4154 by jfenwick, Tue Jan 22 09:30:23 2013 UTC
# Line 1  Line 1 
1    
2  /* $Id$ */  /*****************************************************************************
3    *
4    * Copyright (c) 2003-2013 by 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 since 2012 by School of Earth Sciences
13    *
14    *****************************************************************************/
15    
 /*******************************************************  
  *  
  *           Copyright 2003-2007 by ACceSS MNRF  
  *       Copyright 2007 by University of Queensland  
  *  
  *                http://esscc.uq.edu.au  
  *        Primary Business: Queensland, Australia  
  *  Licensed under the Open Software License version 3.0  
  *     http://www.opensource.org/licenses/osl-3.0.php  
  *  
  *******************************************************/  
16    
17  #ifdef PASO_MPI  #ifdef ESYS_MPI
18  #include <mpi.h>  #include "esysUtils/Esys_MPI.h"
19  #endif  #endif
20  extern "C" {  extern "C" {
21  #include "../Finley.h"  #include "../Dudley.h"
22  }  }
23    
24    #include <pasowrap/SystemMatrixAdapter.h>
25    #include <pasowrap/TransportProblemAdapter.h>
26    
27  #include "MeshAdapter.h"  #include "MeshAdapter.h"
28  #include "MeshAdapterFactory.h"  #include "MeshAdapterFactory.h"
 #include "SystemMatrixAdapter.h"  
 #include "TransportProblemAdapter.h"  
29    
30  #include "FinleyAdapterException.h"  #include "DudleyAdapterException.h"
31  // #include "esysUtils/EsysException.h"  // #include "esysUtils/EsysException.h"
32  #include "esysUtils/esysExceptionTranslator.h"  #include "esysUtils/esysExceptionTranslator.h"
33    
# Line 35  extern "C" { Line 37  extern "C" {
37  #include <boost/python/module.hpp>  #include <boost/python/module.hpp>
38  #include <boost/python/def.hpp>  #include <boost/python/def.hpp>
39  #include <boost/python/detail/defaults_gen.hpp>  #include <boost/python/detail/defaults_gen.hpp>
40    #include <boost/version.hpp>
41    
42  using namespace boost::python;  using namespace boost::python;
43    
44  /**  BOOST_PYTHON_MODULE(dudleycpp)
    \page finley Finley  
    Finley is the python module name that contains the interfaces  
    to the C++ wrapper to finley.  
   
    \version 1.0.0  
   
    \section class_desc Class Description:  
    Data  
   
    \section class_limits Class Limitations:  
    None  
   
    \section class_conds Class Conditions of Use:  
    None  
   
    \section throws Throws:  
    None  
   
 */  
   
 //  
 // The BOOST_PYTHON_FUNCTION_OVERLOADS macro generates function overloads for optional  
 // arguments to the respective finley functions.  
 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!  
 //  
 // NOTE: If the number of arguments to the finley functions change  
 // the magic numbers in the BOOST_PYTHON_FUNCTION_OVERLOADS call  
 // must change.  
 //  
 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!  
 // BOOST_PYTHON_FUNCTION_OVERLOADS(readMesh_overloads,finley::readMesh,1,2)  
 // BOOST_PYTHON_FUNCTION_OVERLOADS(brick_overloads,finley::brick,0,12)  
 // BOOST_PYTHON_FUNCTION_OVERLOADS(rectangle_overloads,finley::rectangle,0,9)  
 // BOOST_PYTHON_FUNCTION_OVERLOADS(interval_overloads,finley::interval,0,6)  
 // BOOST_PYTHON_FUNCTION_OVERLOADS(glueFaces_overloads,finley::glueFaces,1,3)  
 // BOOST_PYTHON_FUNCTION_OVERLOADS(joinFaces_overloads,finley::joinFaces,1,3)  
   
 BOOST_PYTHON_MODULE(finleycpp)  
45  {  {
46    // This feature was added in boost v1.34
47    #if ((BOOST_VERSION/100)%1000 > 34) || (BOOST_VERSION/100000 >1)
48      // params are: bool show_user_defined, bool show_py_signatures, bool show_cpp_signatures
49      docstring_options docopt(true, true, false);
50    #endif
51    
52      scope().attr("__doc__") = "To use this module, please import esys.dudley";  
53      
54      
55    //    //
56    // NOTE: The return_value_policy is necessary for functions that    // NOTE: The return_value_policy is necessary for functions that
57    // return pointers.    // return pointers.
58    //    //
59    register_exception_translator<finley::FinleyAdapterException>(&(esysUtils::esysExceptionTranslator));    register_exception_translator<dudley::DudleyAdapterException>(&(esysUtils::esysExceptionTranslator));
60    
61    def("LoadMesh",finley::loadMesh,    def("LoadMesh",dudley::loadMesh,
62        (arg("fileName")="file.nc"),        (arg("fileName")="file.nc"),":rtype: `Domain`"
63        return_value_policy<manage_new_object>());  /*      ,return_value_policy<manage_new_object>());*/
64    def("ReadMesh",finley::readMesh,        );
65        (arg("fileName")="file.fly",arg("integrationOrder")=-1,  arg("reducedIntegrationOrder")=-1,  arg("optimize")=true),  
66        return_value_policy<manage_new_object>());    def("ReadMesh",dudley::readMesh,
67    def("ReadMeshMPI",finley::readMeshMPI,        (arg("fileName")="file.fly",arg("integrationOrder")=-1,  arg("reducedIntegrationOrder")=-1,  arg("optimize")=true)
68        (arg("fileName")="file.fly",arg("integrationOrder")=-1,  arg("reducedIntegrationOrder")=-1,  arg("optimize")=true),  /*      ,return_value_policy<manage_new_object>());*/
69        return_value_policy<manage_new_object>());      ,"Read a mesh from a file. For MPI parallel runs fan out the mesh to multiple processes.\n\n"
70    ":rtype: `Domain`\n:param fileName:\n:type fileName: ``string``\n"
71    def("ReadGmsh",finley::readGmsh,  ":param integrationOrder: order of the quadrature scheme. If *integrationOrder<0* the integration order is selected independently.\n"
72        (arg("fileName")="file.msh",arg("numDim"), arg("integrationOrder")=-1, arg("reducedIntegrationOrder")=-1, arg("optimize")=true),  ":type integrationOrder: ``int``\n"
73        return_value_policy<manage_new_object>());  ":param reducedIntegrationOrder: order of the quadrature scheme. If *reducedIntegrationOrder<0* the integration order is selected independently.\n"
74    ":param optimize: Enable optimisation of node labels\n:type optimize: ``bool``");
75    
76      def("ReadGmsh",dudley::readGmsh,
77          (arg("fileName")="file.msh",
78           arg("numDim"),
79           arg("integrationOrder")=-1,
80           arg("reducedIntegrationOrder")=-1,
81           arg("optimize")=true,  
82           arg("useMacroElements")=false)
83    //       ,return_value_policy<manage_new_object>());
84    ,"Read a gmsh mesh file\n\n"
85    ":rtype: `Domain`\n:param fileName:\n:type fileName: ``string``\n"
86    ":param integrationOrder: order of the quadrature scheme. If *integrationOrder<0* the integration order is selected independently.\n"
87    ":type integrationOrder: ``int``\n"
88    ":param reducedIntegrationOrder: order of the quadrature scheme. If *reducedIntegrationOrder<0* the integration order is selected independently.\n"
89    ":param optimize: Enable optimisation of node labels\n:type optimize: ``bool``\n"
90    ":param useMacroElements: Enable the usage of macro elements instead of second order elements.\n:type useMacroElements: ``bool``"
91    );
92    
93    def ("Brick",finley::brick,    def ("Brick",dudley::brick,
94        (arg("n0")=1,arg("n1")=1,arg("n2")=1,        (arg("n0")=1,arg("n1")=1,arg("n2")=1,
95        arg("order")=1,        arg("order")=1,
96        arg("l0")=1.0,arg("l1")=1.0,arg("l2")=1.0,        arg("l0")=1.0,arg("l1")=1.0,arg("l2")=1.0,
# Line 107  BOOST_PYTHON_MODULE(finleycpp) Line 98  BOOST_PYTHON_MODULE(finleycpp)
98        arg("integrationOrder")=-1,  arg("reducedIntegrationOrder")=-1,        arg("integrationOrder")=-1,  arg("reducedIntegrationOrder")=-1,
99        arg("useElementsOnFace")=false,        arg("useElementsOnFace")=false,
100        arg("useFullElementOrder")=false,        arg("useFullElementOrder")=false,
101        arg("optimize")=false),        arg("optimize")=false)
102        return_value_policy<manage_new_object>());  ,"Creates a tetrahedral mesh by subdividing n0 x n1 x n2 rectangular elements over the brick [0,l0] x [0,l1] x [0,l2]."
103    "We accept floating point values for n0, n1 only to ease transition of scripts to python3 when the time comes."
104    "\n\n:param n0:\n:type n0:\n:param n1:\n:type n1:\n:param n2:\n:type n2:\n"
105    ":param order: =1, =-1 or =2 gives the order of shape function. If -1 macro elements of order 1 are used.\n"
106    ":param l0: length of side 0\n:param l1:\n:param l2:\n"
107    ":param integrationOrder: order of the quadrature scheme. If integrationOrder<0 the integration order is selected independently.\n"
108    ":param reducedIntegrationOrder: order of the quadrature scheme. If reducedIntegrationOrder<0 the integration order is selected independently.\n"
109    ":param useElementsOnFace:  whether or not to use elements on face\n"
110    ":type useElementsOnFace: ``int``"
111    ":param periodic0:  whether or not boundary conditions are periodic\n"
112    ":param periodic1:\n:param periodic2:\n"
113    ":param useFullElementOrder:\n:param optimize:\n"
114    ":param optimize: Enable optimisation of node labels\n:type optimize: ``bool``"
115    );
116    
117    def ("Rectangle",finley::rectangle,    def ("Rectangle",dudley::rectangle,
118        (arg("n0")=1,arg("n1")=1,arg("order")=1,        (arg("n0")=1,arg("n1")=1,arg("order")=1,
119        arg("l0")=1.0,arg("l1")=1.0,        arg("l0")=1.0,arg("l1")=1.0,
120        arg("periodic0")=false,arg("periodic1")=false,        arg("periodic0")=false,arg("periodic1")=false,
121        arg("integrationOrder")=-1,  arg("reducedIntegrationOrder")=-1,        arg("integrationOrder")=-1,  arg("reducedIntegrationOrder")=-1,
122        arg("useElementsOnFace")=false,        arg("useElementsOnFace")=false,
123        arg("useFullElementOrder")=false,        arg("useFullElementOrder")=false,
124        arg("optimize")=false),        arg("optimize")=false)
125        return_value_policy<manage_new_object>());  ,"Creates a triangular mesh by subdividing n0 x n1 rectangular elements over the brick [0,l0] x [0,l1]."
126    "We accept floating point values for n0, n1 only to ease transition of scripts to python3 when the time comes."
127    def("Merge",finley::meshMerge,  "\n\n:param n0:\n:type n0:\n:param n1:\n:type n1:\n"
128        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"
129    ":param l0: length of side 0\n:param l1:\n"
130    def("GlueFaces",finley::glueFaces,  ":param integrationOrder: order of the quadrature scheme. If integrationOrder<0 the integration order is selected independently.\n"
131        (arg("safetyFactor")=0.2,  ":param reducedIntegrationOrder: order of the quadrature scheme. If reducedIntegrationOrder<0 the integration order is selected independently.\n"
132        arg("tolerance")=1.e-8,  ":param useElementsOnFace:  whether or not to use elements on face\n"
133        arg("optimize")=true),  ":type useElementsOnFace: ``int``"
134        return_value_policy<manage_new_object>());  ":param periodic0:  whether or not boundary conditions are periodic\n"
135    ":param periodic1:\n"
136    def("JoinFaces",finley::joinFaces,  ":param useFullElementOrder:\n:param optimize:\n"
137        (arg("safetyFactor")=0.2,  ":param useMacroElements: Enable the usage of first order macro elements.\n:type useMacroElements: ``bool``\n"
138        arg("tolerance")=1.e-8,  ":param optimize: Enable optimisation of node labels\n:type optimize: ``bool``"
139        arg("optimize")=true),  );
140        return_value_policy<manage_new_object>());  
141      class_<dudley::MeshAdapter, bases<escript::AbstractContinuousDomain> >
142          ("MeshAdapter","A concrete class representing a domain. For more details, please consult the c++ documentation.",init<optional <Dudley_Mesh*> >())
143          .def(init<const dudley::MeshAdapter&>())
144    class_<finley::MeshAdapter, bases<escript::AbstractContinuousDomain> >        .def("write",&dudley::MeshAdapter::write,args("filename"),
145        ("MeshAdapter",init<optional <Finley_Mesh*> >())  "Write the current mesh to a file with the given name.")
146        .def(init<const finley::MeshAdapter&>())        .def("print_mesh_info",&dudley::MeshAdapter::Print_Mesh_Info,(arg("full")=false),
147        .def("write",&finley::MeshAdapter::write)  ":param full:\n:type full: ``bool``")
148        .def("print_mesh_info",&finley::MeshAdapter::Print_Mesh_Info,(arg("full")=false))        .def("dump",&dudley::MeshAdapter::dump,args("fileName")
149        .def("dump",&finley::MeshAdapter::dump)  ,"dumps the mesh to a file with the given name.")
150        .def("getDescription",&finley::MeshAdapter::getDescription)        .def("getDescription",&dudley::MeshAdapter::getDescription,
151        .def("getDim",&finley::MeshAdapter::getDim)  ":return: a description for this domain\n:rtype: ``string``")
152        .def("getDataShape",&finley::MeshAdapter::getDataShape)        .def("getDim",&dudley::MeshAdapter::getDim,":rtype: ``int``")
153        .def("addPDEToSystem",&finley::MeshAdapter::addPDEToSystem)        .def("getDataShape",&dudley::MeshAdapter::getDataShape, args("functionSpaceCode"),
154        .def("addPDEToLumpedSystem",&finley::MeshAdapter::addPDEToLumpedSystem)  ":return: a pair (dps, ns) where dps=the number of data points per sample, and ns=the number of samples\n:rtype: ``tuple``")
155        .def("addPDEToRHS",&finley::MeshAdapter::addPDEToRHS)        .def("getNumDataPointsGlobal",&dudley::MeshAdapter::getNumDataPointsGlobal,
156        .def("addPDEToTransportProblem",&finley::MeshAdapter::addPDEToTransportProblem)  ":return: the number of data points summed across all MPI processes\n"
157        .def("newOperator",&finley::MeshAdapter::newSystemMatrix)  ":rtype: ``int``")
158        .def("newTransportProblem",&finley::MeshAdapter::newTransportProblem)        .def("addPDEToSystem",&dudley::MeshAdapter::addPDEToSystem,
159        .def("getSystemMatrixTypeId",&finley::MeshAdapter::getSystemMatrixTypeId)  args("mat", "rhs","A", "B", "C", "D", "X", "Y", "d", "y", "d_contact", "y_contact"),
160        .def("setX",&finley::MeshAdapter::setNewX)  "adds a PDE onto the stiffness matrix mat and a rhs\n\n"
161        .def("getX",&finley::MeshAdapter::getX)  ":param mat:\n:type mat: `OperatorAdapter`\n:param rhs:\n:type rhs: `Data`\n"
162        .def("getNormal",&finley::MeshAdapter::getNormal)  ":param A:\n:type A: `Data`\n"
163        .def("getSize",&finley::MeshAdapter::getSize)  ":param B:\n:type B: `Data`\n"
164        .def("saveDX",&finley::MeshAdapter::saveDX)  ":param C:\n:type C: `Data`\n"
165        .def("saveVTK",&finley::MeshAdapter::saveVTK)  ":param D:\n:type D: `Data`\n"
166        .def("setTagMap",&finley::MeshAdapter::setTagMap)  ":param X:\n:type X: `Data`\n"
167        .def("getTag",&finley::MeshAdapter::getTag)  ":param Y:\n:type Y: `Data`\n"
168        .def("isValidTagName",&finley::MeshAdapter::isValidTagName)  ":param d:\n:type d: `Data`\n"
169        .def("showTagNames",&finley::MeshAdapter::showTagNames)  ":param d_contact:\n:type d_contact: `Data`\n"
170        .def("getMPISize",&finley::MeshAdapter::getMPISize)  ":param y_contact:\n:type y_contact: `Data`\n"
171        .def("getMPIRank",&finley::MeshAdapter::getMPIRank);  )
172          .def("addPDEToLumpedSystem",&dudley::MeshAdapter::addPDEToLumpedSystem,
173    class_<finley::SystemMatrixAdapter, bases<escript::AbstractSystemMatrix> >  args("mat", "D", "d"),
174        ("OperatorAdapter",no_init)  "adds a PDE onto the lumped stiffness matrix\n\n"
175        .def("print_matrix_info",&finley::SystemMatrixAdapter::Print_Matrix_Info,(arg("full")=false))  ":param mat:\n:type mat: `Data`\n"
176        .def("nullifyRowsAndCols",&finley::SystemMatrixAdapter::nullifyRowsAndCols)  ":param D:\n:type D: `Data`\n"
177        .def("resetValues",&finley::SystemMatrixAdapter::resetValues)  ":param d:\n:type d: `Data`\n"
178        .def("saveMM",&finley::SystemMatrixAdapter::saveMM)  ":param useHRZ:\n:type useHRZ: bool\n"
179        .def("saveHB",&finley::SystemMatrixAdapter::saveHB);  )
180          .def("addPDEToRHS",&dudley::MeshAdapter::addPDEToRHS,
181    class_<finley::TransportProblemAdapter, bases<escript::AbstractTransportProblem> >  args("rhs", "X", "Y", "y", "y_contact"),
182        ("OperatorAdapter",no_init)  "adds a PDE onto the stiffness matrix mat and a rhs\n\n"
183        .def("resetTransport",&finley::TransportProblemAdapter::resetTransport);  ":param rhs:\n:type rhs: `Data`\n"
184    ":param X:\n:type X: `Data`\n"
185    ":param Y:\n:type Y: `Data`\n"
186    ":param y:\n:type y: `Data`\n"
187    ":param y_contact:\n:type y_contact: `Data`"
188    )
189          .def("addPDEToTransportProblem",&dudley::MeshAdapter::addPDEToTransportProblem,
190    args( "tp", "source", "M", "A", "B", "C", "D", "X", "Y", "d", "y", "d_contact", "y_contact"),
191    ":param tp:\n:type tp: `TransportProblemAdapter`\n"
192    ":param source:\n:type source: `Data`\n"
193    ":param M:\n:type M: `Data`\n"
194    ":param A:\n:type A: `Data`\n"
195    ":param B:\n:type B: `Data`\n"
196    ":param C:\n:type C: `Data`\n"
197    ":param D:\n:type D: `Data`\n"
198    ":param X:\n:type X: `Data`\n"
199    ":param Y:\n:type Y: `Data`\n"
200    ":param d:\n:type d: `Data`\n"
201    ":param y:\n:type y: `Data`\n"
202    ":param d_contact:\n:type d_contact: `Data`\n"
203    ":param y_contact:\n:type y_contact: `Data`\n"
204    )
205          .def("newOperator",&dudley::MeshAdapter::newSystemMatrix,
206    args("row_blocksize", "row_functionspace", "column_blocksize", "column_functionspace", "type"),
207    "creates a SystemMatrixAdapter stiffness matrix and initializes it with zeros\n\n"
208    ":param row_blocksize:\n:type row_blocksize: ``int``\n"
209    ":param row_functionspace:\n:type row_functionspace: `FunctionSpace`\n"
210    ":param column_blocksize:\n:type column_blocksize: ``int``\n"
211    ":param column_functionspace:\n:type column_functionspace: `FunctionSpace`\n"
212    ":param type:\n:type type: ``int``\n"
213    )
214          .def("newTransportProblem",&dudley::MeshAdapter::newTransportProblem,
215    args("theta", "blocksize", "functionspace", "type"),
216    "creates a TransportProblemAdapter\n\n"
217    ":param theta:\n:type theta: ``float``\n"
218    ":param blocksize:\n:type blocksize: ``int``\n"
219    ":param functionspace:\n:type functionspace: `FunctionSpace`\n"
220    ":param type:\n:type type: ``int``\n"
221    )
222          .def("getSystemMatrixTypeId",&dudley::MeshAdapter::getSystemMatrixTypeId,
223    args("solver", "preconditioner", "package", "symmetry"),
224    ":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"
225    ":rtype: ``int``\n"
226    ":param solver:\n:type solver: ``int``\n"
227    ":param preconditioner:\n:type preconditioner: ``int``\n"
228    ":param package:\n:type package: ``int``\n"
229    ":param symmetry:\n:type symmetry: ``int``\n"
230    )
231          .def("getTransportTypeId",&dudley::MeshAdapter::getTransportTypeId,
232    args("solver", "preconditioner", "package", "symmetry"),
233    ":return: the identifier of the transport problem type to be used when a particular solver, perconditioner, package and symmetric matrix is used.\n"
234    ":rtype: ``int``\n"
235    ":param solver:\n:type solver: ``int``\n"
236    ":param preconditioner:\n:type preconditioner: ``int``\n"
237    ":param package:\n:type package: ``int``\n"
238    ":param symmetry:\n:type symmetry: ``int``\n"
239    )
240          .def("setX",&dudley::MeshAdapter::setNewX,
241    args("arg"), "assigns new location to the domain\n\n:param arg:\n:type arg: `Data`")
242          .def("getX",&dudley::MeshAdapter::getX, ":return: locations in the FEM nodes\n\n"
243    ":rtype: `Data`")
244          .def("getNormal",&dudley::MeshAdapter::getNormal,
245    ":return: boundary normals at the quadrature point on the face elements\n"
246    ":rtype: `Data`")
247          .def("getSize",&dudley::MeshAdapter::getSize,":return: the element size\n"
248    ":rtype: `Data`")
249          .def("setTagMap",&dudley::MeshAdapter::setTagMap,args("name","tag"),
250    "Give a tag number a name.\n\n:param name: Name for the tag\n:type name: ``string``\n"
251    ":param tag: numeric id\n:type tag: ``int``\n:note: Tag names must be unique within a domain")
252          .def("getTag",&dudley::MeshAdapter::getTag,args("name"),":return: tag id for "
253    "``name``\n:rtype: ``string``")
254          .def("isValidTagName",&dudley::MeshAdapter::isValidTagName,args("name"),
255    ":return: True is ``name`` corresponds to a tag\n:rtype: ``bool``")
256          .def("showTagNames",&dudley::MeshAdapter::showTagNames,":return: A space separated list of tag names\n:rtype: ``string``")
257          .def("getMPISize",&dudley::MeshAdapter::getMPISize,":return: the number of processes used for this `Domain`\n:rtype: ``int``")
258          .def("getMPIRank",&dudley::MeshAdapter::getMPIRank,":return: the rank of this process\n:rtype: ``int``")
259          .def("MPIBarrier",&dudley::MeshAdapter::MPIBarrier,"Wait until all processes have reached this point")
260          .def("onMasterProcessor",&dudley::MeshAdapter::onMasterProcessor,":return: True if this code is executing on the master process\n:rtype: `bool`");
261    
262  }  }

Legend:
Removed from v.1388  
changed lines
  Added in v.4154

  ViewVC Help
Powered by ViewVC 1.1.26