/[escript]/trunk/escript/src/escriptcpp.cpp
ViewVC logotype

Diff of /trunk/escript/src/escriptcpp.cpp

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

revision 2005 by jfenwick, Mon Nov 10 01:21:39 2008 UTC revision 2459 by jfenwick, Thu Jun 4 06:17:54 2009 UTC
# Line 27  Line 27 
27    
28    
29  extern "C" {  extern "C" {
30  #include "escript/blocktimer.h"  #include "esysUtils/blocktimer.h"
31  }  }
32    
33  #include "esysUtils/esysExceptionTranslator.h"  #include "esysUtils/esysExceptionTranslator.h"
34    
35    #include <boost/version.hpp>
36  #include <boost/python.hpp>  #include <boost/python.hpp>
37  #include <boost/python/module.hpp>  #include <boost/python/module.hpp>
38  #include <boost/python/def.hpp>  #include <boost/python/def.hpp>
# Line 39  extern "C" { Line 40  extern "C" {
40  #include <boost/python/tuple.hpp>  #include <boost/python/tuple.hpp>
41  #include <boost/python/numeric.hpp>  #include <boost/python/numeric.hpp>
42  #include <boost/smart_ptr.hpp>  #include <boost/smart_ptr.hpp>
43    #include <boost/version.hpp>
44    
45  using namespace boost::python;  using namespace boost::python;
46    
47  /*! \mainpage Esys Documentation  /*! \mainpage Esys Documentation
48   *   *
49   * \version 1.0.0   * \version 2.9.0
50   *   *
51   * - \ref escript   * - \ref escript
52   *   *
# Line 52  using namespace boost::python; Line 54  using namespace boost::python;
54   *   *
55   * - \ref finley   * - \ref finley
56   *   *
57   * - <a href=http://iservo.edu.au/esys/epydoc/index.html>Python module documentation (epydoc generated)</a>   * - <a href="../../epydoc/index.html">Python module documentation (epydoc generated)</a>
58   *   *
59   */   */
60    
# Line 60  using namespace boost::python; Line 62  using namespace boost::python;
62   * Escript is the python module that contains the interfaces   * Escript is the python module that contains the interfaces
63   * to the C++ side of escript.   * to the C++ side of escript.
64   *   *
65   * \version 1.0.0   *
66   *   *
67   * \section class_desc Class Description:   * \section class_desc Class Description:
68   * Data   * Data
# Line 78  using namespace boost::python; Line 80  using namespace boost::python;
80    
81  BOOST_PYTHON_MODULE(escriptcpp)  BOOST_PYTHON_MODULE(escriptcpp)
82  {  {
83    // This feature was added in boost v1.34
84    #if ((BOOST_VERSION/100)%1000 > 34) || (BOOST_VERSION/100000 >1)
85    //#if ((BOOST_VERSION/100)%1000) > 34
86      // params are: bool show_user_defined, bool show_py_signatures, bool show_cpp_signatures
87      #if BOOST_VERSION > 103399
88      docstring_options docopt(true, true, false);
89      #endif
90    #endif
91    
92    def("setNumberOfThreads",escript::setNumberOfThreads);    def("setNumberOfThreads",escript::setNumberOfThreads);
93    def("getNumberOfThreads",escript::getNumberOfThreads);    def("getNumberOfThreads",escript::getNumberOfThreads);
94    def("releaseUnusedMemory",escript::releaseUnusedMemory);    def("releaseUnusedMemory",escript::releaseUnusedMemory);
# Line 90  BOOST_PYTHON_MODULE(escriptcpp) Line 101  BOOST_PYTHON_MODULE(escriptcpp)
101    def("printParallelThreadCounts",escript::printParallelThreadCnt);    def("printParallelThreadCounts",escript::printParallelThreadCnt);
102    def("getMPISizeWorld",escript::getMPISizeWorld);    def("getMPISizeWorld",escript::getMPISizeWorld);
103    def("getMPIRankWorld",escript::getMPIRankWorld);    def("getMPIRankWorld",escript::getMPIRankWorld);
104      def("MPIBarrierWorld",escript::MPIBarrierWorld);
105      def("getMPIWorldMax",escript::getMPIWorldMax);
106      def("getMachinePrecision",escript::getMachinePrecision);
107      def("getMaxFloat",escript::getMaxFloat);
108    //    //
109    // Interface for AbstractDomain    // Interface for AbstractDomain
110    //    //
111    class_<escript::AbstractDomain, escript::Domain_ptr>("Domain",no_init)    class_<escript::AbstractDomain, escript::Domain_ptr>("Domain","Base class for all domains.",no_init)
112       .def("setTagMap",&escript::AbstractDomain::setTagMap)       .def("setTagMap",&escript::AbstractDomain::setTagMap)
113       .def("getTag",&escript::AbstractDomain::getTag)       .def("getTag",&escript::AbstractDomain::getTag)
114       .def("isValidTagName",&escript::AbstractDomain::isValidTagName)       .def("isValidTagName",&escript::AbstractDomain::isValidTagName)
# Line 105  BOOST_PYTHON_MODULE(escriptcpp) Line 118  BOOST_PYTHON_MODULE(escriptcpp)
118       .def("getNormal",&escript::AbstractDomain::getNormal)       .def("getNormal",&escript::AbstractDomain::getNormal)
119       .def("getSize",&escript::AbstractDomain::getSize)       .def("getSize",&escript::AbstractDomain::getSize)
120       .def("saveVTK",&escript::AbstractDomain::saveVTK)       .def("saveVTK",&escript::AbstractDomain::saveVTK)
121         .def("dump",&escript::AbstractDomain::dump)
122       .def("saveDX",&escript::AbstractDomain::saveDX)       .def("saveDX",&escript::AbstractDomain::saveDX)
123       .def("getMPISize",&escript::AbstractDomain::getMPISize)       .def("getMPISize",&escript::AbstractDomain::getMPISize)
124       .def("getMPIRank",&escript::AbstractDomain::getMPIRank)       .def("getMPIRank",&escript::AbstractDomain::getMPIRank)
# Line 117  BOOST_PYTHON_MODULE(escriptcpp) Line 131  BOOST_PYTHON_MODULE(escriptcpp)
131    //    //
132    // Interface for AbstractContinuousDomain    // Interface for AbstractContinuousDomain
133    //    //
134    class_<escript::AbstractContinuousDomain, bases<escript::AbstractDomain> >("ContinuousDomain",no_init)    class_<escript::AbstractContinuousDomain, bases<escript::AbstractDomain> >("ContinuousDomain","Class representing continuous domains",no_init)
135         .def("getSystemMatrixTypeId",&escript::AbstractContinuousDomain::getSystemMatrixTypeId)         .def("getSystemMatrixTypeId",&escript::AbstractContinuousDomain::getSystemMatrixTypeId)
136         .def("getTransportTypeId",&escript::AbstractContinuousDomain::getTransportTypeId);         .def("getTransportTypeId",&escript::AbstractContinuousDomain::getTransportTypeId);
137    
138    //    //
139    // Interface for FunctionSpace    // Interface for FunctionSpace
140    //    //
141    class_<escript::FunctionSpace> fs_definer("FunctionSpace",init<>());    class_<escript::FunctionSpace> fs_definer("FunctionSpace","",init<>());   // Doco goes in the empty string param
142    fs_definer.def("getDim",&escript::FunctionSpace::getDim);    fs_definer.def("getDim",&escript::FunctionSpace::getDim);
143  //   fs_definer.def("getDomain",&escript::FunctionSpace::getDomain,  //   fs_definer.def("getDomain",&escript::FunctionSpace::getDomain,
144  //                  return_internal_reference<>());  //                  return_internal_reference<>());
# Line 143  BOOST_PYTHON_MODULE(escriptcpp) Line 157  BOOST_PYTHON_MODULE(escriptcpp)
157    //    //
158    // Interface for Data    // Interface for Data
159    //    //
160    class_<escript::Data>("Data","TEST DOCUMENTATION",init<>() )    class_<escript::Data>("Data","Represents a collection of datapoints. It is used to store the values of a function. For more details please consult the c++ class documentation.",init<>() )
161      // various constructors for Data objects      // various constructors for Data objects
     .def(init<const numeric::array&, optional<const escript::FunctionSpace&, bool> >(args("value","what","expand")))  
162      .def(init<const object&, optional<const escript::FunctionSpace&, bool> >(args("value","what","expand")))      .def(init<const object&, optional<const escript::FunctionSpace&, bool> >(args("value","what","expand")))
163      .def(init<const double, const tuple&, optional<const escript::FunctionSpace&, bool> >(args("value","shape","what","expand")))      .def(init<const double, const tuple&, optional<const escript::FunctionSpace&, bool> >(args("value","shape","what","expand")))
164      .def(init<const escript::Data&, const escript::FunctionSpace&>(args("value","what")))      .def(init<const escript::Data&, const escript::FunctionSpace&>(args("value","what")))
# Line 153  BOOST_PYTHON_MODULE(escriptcpp) Line 166  BOOST_PYTHON_MODULE(escriptcpp)
166      // Note for Lutz, Need to specify the call policy in order to return a      // Note for Lutz, Need to specify the call policy in order to return a
167      // reference. In this case return_internal_reference.      // reference. In this case return_internal_reference.
168      .def("__str__",&escript::Data::toString)      .def("__str__",&escript::Data::toString)
 //     .def("getDomain",&escript::Data::getDomain,return_internal_reference<>())  
169      .def("getDomain",&escript::Data::getDomainPython)      .def("getDomain",&escript::Data::getDomainPython)
170      .def("getFunctionSpace",&escript::Data::getFunctionSpace,return_value_policy<copy_const_reference>())      .def("getFunctionSpace",&escript::Data::getFunctionSpace,return_value_policy<copy_const_reference>())
171      .def("isEmpty",&escript::Data::isEmpty)      .def("isEmpty",&escript::Data::isEmpty)
# Line 162  BOOST_PYTHON_MODULE(escriptcpp) Line 174  BOOST_PYTHON_MODULE(escriptcpp)
174      .def("getShape",&escript::Data::getShapeTuple)      .def("getShape",&escript::Data::getShapeTuple)
175      .def("getRank",&escript::Data::getDataPointRank)      .def("getRank",&escript::Data::getDataPointRank)
176      .def("dump",&escript::Data::dump)      .def("dump",&escript::Data::dump)
177        .def("toListOfTuples",&escript::Data::toListOfTuples, (arg("scalarastuple")=false))
178      .def("copyWithMask",&escript::Data::copyWithMask)      .def("copyWithMask",&escript::Data::copyWithMask)
179      .def("setTaggedValue",&escript::Data::setTaggedValue)      .def("setTaggedValue",&escript::Data::setTaggedValue)
180      .def("setTaggedValue",&escript::Data::setTaggedValueByName)      .def("setTaggedValue",&escript::Data::setTaggedValueByName)
# Line 175  BOOST_PYTHON_MODULE(escriptcpp) Line 188  BOOST_PYTHON_MODULE(escriptcpp)
188      .def("tag",&escript::Data::tag)      .def("tag",&escript::Data::tag)
189      .def("resolve",&escript::Data::resolve)      .def("resolve",&escript::Data::resolve)
190      .def("copy",&escript::Data::copy)      .def("copy",&escript::Data::copy)
191      .def("copy",&escript::Data::copySelf,return_value_policy<manage_new_object>())      .def("copy",&escript::Data::copySelf)
192      .def("delay",&escript::Data::delay)      .def("delay",&escript::Data::delay)
193      .def("setValueOfDataPoint",&escript::Data::setValueOfDataPointToPyObject)      .def("setValueOfDataPoint",&escript::Data::setValueOfDataPointToPyObject)
194      .def("setValueOfDataPoint",&escript::Data::setValueOfDataPointToArray)      .def("setValueOfDataPoint",&escript::Data::setValueOfDataPointToArray)
195      .def("setValueOfDataPoint",&escript::Data::setValueOfDataPoint)      .def("setValueOfDataPoint",&escript::Data::setValueOfDataPoint)
196      .def("getValueOfDataPoint",&escript::Data::getValueOfDataPoint)      .def("getTupleForDataPoint",&escript::Data::getValueOfDataPointAsTuple)
197      .def("getValueOfGlobalDataPoint",&escript::Data::getValueOfGlobalDataPoint)      .def("getTupleForGlobalDataPoint",&escript::Data::getValueOfGlobalDataPointAsTuple)
198      .def("setToZero",&escript::Data::setToZero)      .def("setToZero",&escript::Data::setToZero)
199      .def("interpolate",&escript::Data::interpolate)      .def("interpolate",&escript::Data::interpolate)
200      .def("minGlobalDataPoint",&escript::Data::minGlobalDataPoint)      .def("minGlobalDataPoint",&escript::Data::minGlobalDataPoint)
# Line 230  BOOST_PYTHON_MODULE(escriptcpp) Line 243  BOOST_PYTHON_MODULE(escriptcpp)
243      .def("_Lsup",&escript::Data::Lsup)      .def("_Lsup",&escript::Data::Lsup)
244      .def("_sup",&escript::Data::sup)      .def("_sup",&escript::Data::sup)
245      .def("_inf",&escript::Data::inf)      .def("_inf",&escript::Data::inf)
246      .def("_integrate",&escript::Data::integrate)      .def("_integrateToTuple",&escript::Data::integrateToTuple)
247    
248      // following implements the python abs operator      // following implements the python abs operator
249      .def("__abs__",&escript::Data::abs)      .def("__abs__",&escript::Data::abs)
# Line 331  BOOST_PYTHON_MODULE(escriptcpp) Line 344  BOOST_PYTHON_MODULE(escriptcpp)
344    //    //
345    // Interface for AbstractSystemMatrix    // Interface for AbstractSystemMatrix
346    //    //
347    class_<escript::AbstractSystemMatrix>("Operator",init<>())    class_<escript::AbstractSystemMatrix>("Operator","",init<>())    // Doco goes in the empty string param
348       .def("isEmpty",&escript::AbstractSystemMatrix::isEmpty)       .def("isEmpty",&escript::AbstractSystemMatrix::isEmpty)
349       .def("solve",&escript::AbstractSystemMatrix::solve)       .def("solve",&escript::AbstractSystemMatrix::solve)
350       .def("of",&escript::AbstractSystemMatrix::vectorMultiply)       .def("of",&escript::AbstractSystemMatrix::vectorMultiply)
# Line 342  BOOST_PYTHON_MODULE(escriptcpp) Line 355  BOOST_PYTHON_MODULE(escriptcpp)
355    //    //
356    // Interface for AbstractTransportProblem    // Interface for AbstractTransportProblem
357    //    //
358    class_<escript::AbstractTransportProblem>("TransportProblem",init<>())    class_<escript::AbstractTransportProblem>("TransportProblem","",init<>())    // Doco goes in the empty string param
359       .def("isEmpty",&escript::AbstractTransportProblem::isEmpty)       .def("isEmpty",&escript::AbstractTransportProblem::isEmpty)
360       .def("solve",&escript::AbstractTransportProblem::solve)       .def("solve",&escript::AbstractTransportProblem::solve)
361       .def("setInitialValue",&escript::AbstractTransportProblem::setInitialValue)       .def("setInitialValue",&escript::AbstractTransportProblem::setInitialValue)
# Line 357  BOOST_PYTHON_MODULE(escriptcpp) Line 370  BOOST_PYTHON_MODULE(escriptcpp)
370        (arg("value")=0));        (arg("value")=0));
371    def("getEscriptParamInt",escript::getEscriptParamInt,    def("getEscriptParamInt",escript::getEscriptParamInt,
372        (arg("sentinel")=0));        (arg("sentinel")=0));
373      def("listEscriptParams",escript::listEscriptParams);
374    
375    //    //
376    // Register esysExceptionTranslator    // Register esysExceptionTranslator

Legend:
Removed from v.2005  
changed lines
  Added in v.2459

  ViewVC Help
Powered by ViewVC 1.1.26