/[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 1796 by jfenwick, Wed Sep 17 01:45:46 2008 UTC revision 2271 by jfenwick, Mon Feb 16 05:08:29 2009 UTC
# Line 1  Line 1 
1    
 /* $Id$ */  
   
2  /*******************************************************  /*******************************************************
3   *  *
4   *           Copyright 2003-2007 by ACceSS MNRF  * Copyright (c) 2003-2008 by University of Queensland
5   *       Copyright 2007 by University of Queensland  * Earth Systems Science Computational Center (ESSCC)
6   *  * http://www.uq.edu.au/esscc
7   *                http://esscc.uq.edu.au  *
8   *        Primary Business: Queensland, Australia  * Primary Business: Queensland, Australia
9   *  Licensed under the Open Software License version 3.0  * Licensed under the Open Software License version 3.0
10   *     http://www.opensource.org/licenses/osl-3.0.php  * http://www.opensource.org/licenses/osl-3.0.php
11   *  *
12   *******************************************************/  *******************************************************/
13    
14    
15  #include "Data.h"  #include "Data.h"
16  #include "FunctionSpace.h"  #include "FunctionSpace.h"
# Line 23  Line 22 
22  #include "AbstractSystemMatrix.h"  #include "AbstractSystemMatrix.h"
23  #include "AbstractTransportProblem.h"  #include "AbstractTransportProblem.h"
24  #include "DataVector.h"  #include "DataVector.h"
25    #include "paso/Paso_MPI.h"
26    #include "EscriptParams.h"
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>
39  #include <boost/python/object.hpp>  #include <boost/python/object.hpp>
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>
43    #include <boost/version.hpp>
44    
45  using namespace boost::python;  using namespace boost::python;
46    
# Line 49  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="http://shake200.esscc.uq.edu.au/esys/esys13/release/epydoc/index.html">Python module documentation (epydoc generated)</a>
58   *   *
59   */   */
60    
# Line 75  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 85  BOOST_PYTHON_MODULE(escriptcpp) Line 99  BOOST_PYTHON_MODULE(escriptcpp)
99    def("blocktimer_time",blocktimer_time);    def("blocktimer_time",blocktimer_time);
100    def("getVersion",escript::getSvnVersion);    def("getVersion",escript::getSvnVersion);
101    def("printParallelThreadCounts",escript::printParallelThreadCnt);    def("printParallelThreadCounts",escript::printParallelThreadCnt);
102      def("getMPISizeWorld",escript::getMPISizeWorld);
103      def("getMPIRankWorld",escript::getMPIRankWorld);
104      def("getMachinePrecision",escript::getMachinePrecision);
105      def("getMaxFloat",escript::getMaxFloat);
106    //    //
107    // Interface for AbstractDomain    // Interface for AbstractDomain
108    //    //
109    class_<escript::AbstractDomain>("Domain",no_init)    class_<escript::AbstractDomain, escript::Domain_ptr>("Domain","Base class for all domains.",no_init)
110       .def("setTagMap",&escript::AbstractDomain::setTagMap)       .def("setTagMap",&escript::AbstractDomain::setTagMap)
111       .def("getTag",&escript::AbstractDomain::getTag)       .def("getTag",&escript::AbstractDomain::getTag)
112       .def("isValidTagName",&escript::AbstractDomain::isValidTagName)       .def("isValidTagName",&escript::AbstractDomain::isValidTagName)
113       .def("showTagNames",&escript::AbstractDomain::showTagNames)       .def("showTagNames",&escript::AbstractDomain::showTagNames)
114       .def("getX",&escript::AbstractDomain::getX)       .def("getX",&escript::AbstractDomain::getX)
115         .def("getDim",&escript::AbstractDomain::getDim)
116       .def("getNormal",&escript::AbstractDomain::getNormal)       .def("getNormal",&escript::AbstractDomain::getNormal)
117       .def("getSize",&escript::AbstractDomain::getSize)       .def("getSize",&escript::AbstractDomain::getSize)
118       .def("saveVTK",&escript::AbstractDomain::saveVTK)       .def("saveVTK",&escript::AbstractDomain::saveVTK)
119       .def("saveDX",&escript::AbstractDomain::saveDX)       .def("saveDX",&escript::AbstractDomain::saveDX)
120       .def("getMPISize",&escript::AbstractDomain::getMPISize)       .def("getMPISize",&escript::AbstractDomain::getMPISize)
121       .def("getMPIRank",&escript::AbstractDomain::getMPIRank)       .def("getMPIRank",&escript::AbstractDomain::getMPIRank)
122         .def("MPIBarrier",&escript::AbstractDomain::MPIBarrier)
123         .def("onMasterProcessor",&escript::AbstractDomain::onMasterProcessor)
124    
125       .def(self == self)       .def(self == self)
126       .def(self != self);       .def(self != self);
# Line 109  BOOST_PYTHON_MODULE(escriptcpp) Line 128  BOOST_PYTHON_MODULE(escriptcpp)
128    //    //
129    // Interface for AbstractContinuousDomain    // Interface for AbstractContinuousDomain
130    //    //
131    class_<escript::AbstractContinuousDomain, bases<escript::AbstractDomain> >("ContinuousDomain",no_init)    class_<escript::AbstractContinuousDomain, bases<escript::AbstractDomain> >("ContinuousDomain","Class representing continuous domains",no_init)
132         .def("getSystemMatrixTypeId",&escript::AbstractContinuousDomain::getSystemMatrixTypeId);         .def("getSystemMatrixTypeId",&escript::AbstractContinuousDomain::getSystemMatrixTypeId)
133           .def("getTransportTypeId",&escript::AbstractContinuousDomain::getTransportTypeId);
134    
135    //    //
136    // Interface for FunctionSpace    // Interface for FunctionSpace
137    //    //
138    class_<escript::FunctionSpace> fs_definer("FunctionSpace",init<>());    class_<escript::FunctionSpace> fs_definer("FunctionSpace","",init<>());   // Doco goes in the empty string param
139    fs_definer.def("getDim",&escript::FunctionSpace::getDim);    fs_definer.def("getDim",&escript::FunctionSpace::getDim);
140    fs_definer.def("getDomain",&escript::FunctionSpace::getDomain,  //   fs_definer.def("getDomain",&escript::FunctionSpace::getDomain,
141                   return_internal_reference<>());  //                  return_internal_reference<>());
142      fs_definer.def("getDomain",&escript::FunctionSpace::getDomainPython);
143    fs_definer.def("getX",&escript::FunctionSpace::getX);    fs_definer.def("getX",&escript::FunctionSpace::getX);
144    fs_definer.def("getNormal",&escript::FunctionSpace::getNormal);    fs_definer.def("getNormal",&escript::FunctionSpace::getNormal);
145    fs_definer.def("getSize",&escript::FunctionSpace::getSize);    fs_definer.def("getSize",&escript::FunctionSpace::getSize);
# Line 133  BOOST_PYTHON_MODULE(escriptcpp) Line 154  BOOST_PYTHON_MODULE(escriptcpp)
154    //    //
155    // Interface for Data    // Interface for Data
156    //    //
157    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<>() )
158      // various constructors for Data objects      // various constructors for Data objects
159      .def(init<const numeric::array&, optional<const escript::FunctionSpace&, bool> >(args("value","what","expand")))  //    .def(init<const numeric::array&, optional<const escript::FunctionSpace&, bool> >(args("value","what","expand")))
160      .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")))
161      .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")))
162      .def(init<const escript::Data&, const escript::FunctionSpace&>(args("value","what")))      .def(init<const escript::Data&, const escript::FunctionSpace&>(args("value","what")))
# Line 143  BOOST_PYTHON_MODULE(escriptcpp) Line 164  BOOST_PYTHON_MODULE(escriptcpp)
164      // 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
165      // reference. In this case return_internal_reference.      // reference. In this case return_internal_reference.
166      .def("__str__",&escript::Data::toString)      .def("__str__",&escript::Data::toString)
167      .def("getDomain",&escript::Data::getDomain,return_internal_reference<>())  //     .def("getDomain",&escript::Data::getDomain,return_internal_reference<>())
168      .def("getFunctionSpace",&escript::Data::getFunctionSpace,return_internal_reference<>())      .def("getDomain",&escript::Data::getDomainPython)
169        .def("getFunctionSpace",&escript::Data::getFunctionSpace,return_value_policy<copy_const_reference>())
170      .def("isEmpty",&escript::Data::isEmpty)      .def("isEmpty",&escript::Data::isEmpty)
171      .def("isProtected",&escript::Data::isProtected)      .def("isProtected",&escript::Data::isProtected)
172      .def("setProtection",&escript::Data::setProtection)      .def("setProtection",&escript::Data::setProtection)
# Line 157  BOOST_PYTHON_MODULE(escriptcpp) Line 179  BOOST_PYTHON_MODULE(escriptcpp)
179      .def("getNumberOfDataPoints",&escript::Data::getNumDataPoints)      .def("getNumberOfDataPoints",&escript::Data::getNumDataPoints)
180      .def("isExpanded",&escript::Data::isExpanded)      .def("isExpanded",&escript::Data::isExpanded)
181      .def("isTagged",&escript::Data::isTagged)      .def("isTagged",&escript::Data::isTagged)
182        .def("isConstant",&escript::Data::isConstant)
183        .def("isLazy",&escript::Data::isLazy)
184        .def("isReady",&escript::Data::isReady)
185      .def("expand",&escript::Data::expand)      .def("expand",&escript::Data::expand)
186      .def("tag",&escript::Data::tag)      .def("tag",&escript::Data::tag)
187        .def("resolve",&escript::Data::resolve)
188      .def("copy",&escript::Data::copy)      .def("copy",&escript::Data::copy)
189        .def("copy",&escript::Data::copySelf)
190        .def("delay",&escript::Data::delay)
191      .def("setValueOfDataPoint",&escript::Data::setValueOfDataPointToPyObject)      .def("setValueOfDataPoint",&escript::Data::setValueOfDataPointToPyObject)
192      .def("setValueOfDataPoint",&escript::Data::setValueOfDataPointToArray)      .def("setValueOfDataPoint",&escript::Data::setValueOfDataPointToArray)
193      .def("setValueOfDataPoint",&escript::Data::setValueOfDataPoint)      .def("setValueOfDataPoint",&escript::Data::setValueOfDataPoint)
194      .def("getValueOfDataPoint",&escript::Data::getValueOfDataPoint)      .def("getValueOfDataPoint",&escript::Data::getValueOfDataPoint)
195        .def("getTupleForDataPoint",&escript::Data::getValueOfDataPointAsTuple)
196      .def("getValueOfGlobalDataPoint",&escript::Data::getValueOfGlobalDataPoint)      .def("getValueOfGlobalDataPoint",&escript::Data::getValueOfGlobalDataPoint)
197        .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 214  BOOST_PYTHON_MODULE(escriptcpp) Line 244  BOOST_PYTHON_MODULE(escriptcpp)
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("_integrate",&escript::Data::integrate)
247        .def("_integrateToTuple",&escript::Data::integrateToTuple)
248    
249      // following implements the python abs operator      // following implements the python abs operator
250      .def("__abs__",&escript::Data::abs)      .def("__abs__",&escript::Data::abs)
# Line 314  BOOST_PYTHON_MODULE(escriptcpp) Line 345  BOOST_PYTHON_MODULE(escriptcpp)
345    //    //
346    // Interface for AbstractSystemMatrix    // Interface for AbstractSystemMatrix
347    //    //
348    class_<escript::AbstractSystemMatrix>("Operator",init<>())    class_<escript::AbstractSystemMatrix>("Operator","",init<>())    // Doco goes in the empty string param
349       .def("isEmpty",&escript::AbstractSystemMatrix::isEmpty)       .def("isEmpty",&escript::AbstractSystemMatrix::isEmpty)
350       .def("solve",&escript::AbstractSystemMatrix::solve)       .def("solve",&escript::AbstractSystemMatrix::solve)
351       .def("of",&escript::AbstractSystemMatrix::vectorMultiply)       .def("of",&escript::AbstractSystemMatrix::vectorMultiply)
# Line 325  BOOST_PYTHON_MODULE(escriptcpp) Line 356  BOOST_PYTHON_MODULE(escriptcpp)
356    //    //
357    // Interface for AbstractTransportProblem    // Interface for AbstractTransportProblem
358    //    //
359    class_<escript::AbstractTransportProblem>("TransportProblem",init<>())    class_<escript::AbstractTransportProblem>("TransportProblem","",init<>())    // Doco goes in the empty string param
360       .def("isEmpty",&escript::AbstractTransportProblem::isEmpty)       .def("isEmpty",&escript::AbstractTransportProblem::isEmpty)
361       .def("solve",&escript::AbstractTransportProblem::solve)       .def("solve",&escript::AbstractTransportProblem::solve)
362       .def("setInitialValue",&escript::AbstractTransportProblem::setInitialValue)       .def("setInitialValue",&escript::AbstractTransportProblem::setInitialValue)
363       .def("insertConstraint",&escript::AbstractTransportProblem::insertConstraint)       .def("insertConstraint",&escript::AbstractTransportProblem::insertConstraint)
364       .def("reset",&escript::AbstractTransportProblem::resetTransport)       .def("reset",&escript::AbstractTransportProblem::resetTransport)
365       .def("getSafeTimeStepSize",&escript::AbstractTransportProblem::getSafeTimeStepSize);       .def("resetValues",&escript::AbstractTransportProblem::resetTransport)
366         .def("getSafeTimeStepSize",&escript::AbstractTransportProblem::getSafeTimeStepSize)
367         .def("getUnlimitedTimeStepSize",&escript::AbstractTransportProblem::getUnlimitedTimeStepSize);
368    
369      // Functions to modify global parameters
370      def("setEscriptParamInt",escript::setEscriptParamInt,
371          (arg("value")=0));
372      def("getEscriptParamInt",escript::getEscriptParamInt,
373          (arg("sentinel")=0));
374      def("listEscriptParams",escript::listEscriptParams);
375    
376    //    //
377    // Register esysExceptionTranslator    // Register esysExceptionTranslator

Legend:
Removed from v.1796  
changed lines
  Added in v.2271

  ViewVC Help
Powered by ViewVC 1.1.26