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

Legend:
Removed from v.682  
changed lines
  Added in v.4346

  ViewVC Help
Powered by ViewVC 1.1.26