/[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 775 by ksteube, Mon Jul 10 04:00:08 2006 UTC revision 2308 by gross, Mon Mar 16 01:20:56 2009 UTC
# Line 1  Line 1 
1  //$Id$  
2  /*  /*******************************************************
3   ************************************************************  *
4   *          Copyright 2006 by ACcESS MNRF                   *  * Copyright (c) 2003-2008 by University of Queensland
5   *                                                          *  * Earth Systems Science Computational Center (ESSCC)
6   *              http://www.access.edu.au                    *  * http://www.uq.edu.au/esscc
7   *       Primary Business: Queensland, Australia            *  *
8   *  Licensed under the Open Software License version 3.0    *  * Primary Business: Queensland, Australia
9   *     http://www.opensource.org/licenses/osl-3.0.php       *  * Licensed under the Open Software License version 3.0
10   *                                                          *  * 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 19  Line 20 
20  #include "AbstractDomain.h"  #include "AbstractDomain.h"
21  #include "Utils.h"  #include "Utils.h"
22  #include "AbstractSystemMatrix.h"  #include "AbstractSystemMatrix.h"
23    #include "AbstractTransportProblem.h"
24    #include "DataVector.h"
25    #include "paso/Paso_MPI.h"
26    #include "EscriptParams.h"
27    
28    
29    extern "C" {
30    #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 41  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 67  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);
95      def("blocktimer_initialize",blocktimer_initialize);
96      def("blocktimer_reportSortByName",blocktimer_reportSortByName);
97      def("blocktimer_reportSortByTime",blocktimer_reportSortByTime);
98      def("blocktimer_increment",blocktimer_increment);
99      def("blocktimer_time",blocktimer_time);
100      def("getVersion",escript::getSvnVersion);
101      def("printParallelThreadCounts",escript::printParallelThreadCnt);
102      def("getMPISizeWorld",escript::getMPISizeWorld);
103      def("getMPIRankWorld",escript::getMPIRankWorld);
104      def("getMPIWorldMax",escript::getMPIWorldMax);
105      def("getMachinePrecision",escript::getMachinePrecision);
106      def("getMaxFloat",escript::getMaxFloat);
107    //    //
108    // Interface for AbstractDomain    // Interface for AbstractDomain
109    //    //
110    class_<escript::AbstractDomain>("Domain",no_init)    class_<escript::AbstractDomain, escript::Domain_ptr>("Domain","Base class for all domains.",no_init)
111         .def("setTagMap",&escript::AbstractDomain::setTagMap)
112         .def("getTag",&escript::AbstractDomain::getTag)
113         .def("isValidTagName",&escript::AbstractDomain::isValidTagName)
114         .def("showTagNames",&escript::AbstractDomain::showTagNames)
115       .def("getX",&escript::AbstractDomain::getX)       .def("getX",&escript::AbstractDomain::getX)
116         .def("getDim",&escript::AbstractDomain::getDim)
117       .def("getNormal",&escript::AbstractDomain::getNormal)       .def("getNormal",&escript::AbstractDomain::getNormal)
118       .def("getSize",&escript::AbstractDomain::getSize)       .def("getSize",&escript::AbstractDomain::getSize)
119       .def("saveVTK",&escript::AbstractDomain::saveVTK)       .def("saveVTK",&escript::AbstractDomain::saveVTK)
120       .def("saveDX",&escript::AbstractDomain::saveDX)       .def("saveDX",&escript::AbstractDomain::saveDX)
121         .def("getMPISize",&escript::AbstractDomain::getMPISize)
122         .def("getMPIRank",&escript::AbstractDomain::getMPIRank)
123         .def("MPIBarrier",&escript::AbstractDomain::MPIBarrier)
124         .def("onMasterProcessor",&escript::AbstractDomain::onMasterProcessor)
125    
126       .def(self == self)       .def(self == self)
127       .def(self != self);       .def(self != self);
128    
129    //    //
130    // Interface for AbstractContinuousDomain    // Interface for AbstractContinuousDomain
131    //    //
132    class_<escript::AbstractContinuousDomain, bases<escript::AbstractDomain> >("ContinuousDomain",no_init)    class_<escript::AbstractContinuousDomain, bases<escript::AbstractDomain> >("ContinuousDomain","Class representing continuous domains",no_init)
133         .def("getSystemMatrixTypeId",&escript::AbstractContinuousDomain::getSystemMatrixTypeId);         .def("getSystemMatrixTypeId",&escript::AbstractContinuousDomain::getSystemMatrixTypeId)
134           .def("getTransportTypeId",&escript::AbstractContinuousDomain::getTransportTypeId);
135    
136    //    //
137    // Interface for FunctionSpace    // Interface for FunctionSpace
138    //    //
139    class_<escript::FunctionSpace>("FunctionSpace",init<>())    class_<escript::FunctionSpace> fs_definer("FunctionSpace","",init<>());   // Doco goes in the empty string param
140       .def("getDim",&escript::FunctionSpace::getDim)    fs_definer.def("getDim",&escript::FunctionSpace::getDim);
141       .def("getDomain",&escript::FunctionSpace::getDomain,return_internal_reference<>())  //   fs_definer.def("getDomain",&escript::FunctionSpace::getDomain,
142       .def("getX",&escript::FunctionSpace::getX)  //                  return_internal_reference<>());
143       .def("getNormal",&escript::FunctionSpace::getNormal)    fs_definer.def("getDomain",&escript::FunctionSpace::getDomainPython);
144       .def("getSize",&escript::FunctionSpace::getSize)    fs_definer.def("getX",&escript::FunctionSpace::getX);
145       .def("setTags",&escript::FunctionSpace::setTags)    fs_definer.def("getNormal",&escript::FunctionSpace::getNormal);
146       .def("getTagFromDataPointNo",&escript::FunctionSpace::getTagFromDataPointNo)    fs_definer.def("getSize",&escript::FunctionSpace::getSize);
147       .def("__str__",&escript::FunctionSpace::toString)    fs_definer.def("setTags",&escript::FunctionSpace::setTags);
148       .def(self == self)    fs_definer.def("getTagFromDataPointNo",
149       .def(self != self);                   &escript::FunctionSpace::getTagFromDataPointNo);
150      fs_definer.def("getReferenceIDFromDataPointNo", &escript::FunctionSpace::getReferenceIDFromDataPointNo);
151      fs_definer.def("getListOfTags",&escript::FunctionSpace::getListOfTags);
152      fs_definer.def("__str__", &escript::FunctionSpace::toString);
153      fs_definer.def(self == self);
154      fs_definer.def(self != self);
155    //    //
156    // Interface for Data    // Interface for Data
157    //    //
158    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<>() )
159      // various constructors for Data objects      // various constructors for Data objects
160      .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")))
161      .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")))
162      .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")))
163      .def(init<const escript::Data&, const escript::FunctionSpace&>(args("value","what")))      .def(init<const escript::Data&, const escript::FunctionSpace&>(args("value","what")))
# Line 115  BOOST_PYTHON_MODULE(escriptcpp) Line 165  BOOST_PYTHON_MODULE(escriptcpp)
165      // 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
166      // reference. In this case return_internal_reference.      // reference. In this case return_internal_reference.
167      .def("__str__",&escript::Data::toString)      .def("__str__",&escript::Data::toString)
168      .def("getDomain",&escript::Data::getDomain,return_internal_reference<>())  //     .def("getDomain",&escript::Data::getDomain,return_internal_reference<>())
169      .def("getFunctionSpace",&escript::Data::getFunctionSpace,return_internal_reference<>())      .def("getDomain",&escript::Data::getDomainPython)
170        .def("getFunctionSpace",&escript::Data::getFunctionSpace,return_value_policy<copy_const_reference>())
171      .def("isEmpty",&escript::Data::isEmpty)      .def("isEmpty",&escript::Data::isEmpty)
172        .def("isProtected",&escript::Data::isProtected)
173        .def("setProtection",&escript::Data::setProtection)
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)
177      .def("copyWithMask",&escript::Data::copyWithMask)      .def("copyWithMask",&escript::Data::copyWithMask)
178      .def("setTaggedValue",&escript::Data::setTaggedValue)      .def("setTaggedValue",&escript::Data::setTaggedValue)
179      .def("setRefValue",&escript::Data::setRefValue)      .def("setTaggedValue",&escript::Data::setTaggedValueByName)
180      .def("getRefValue",&escript::Data::getRefValue)      .def("getNumberOfDataPoints",&escript::Data::getNumDataPoints)
181        .def("isExpanded",&escript::Data::isExpanded)
182        .def("isTagged",&escript::Data::isTagged)
183        .def("isConstant",&escript::Data::isConstant)
184        .def("isLazy",&escript::Data::isLazy)
185        .def("isReady",&escript::Data::isReady)
186      .def("expand",&escript::Data::expand)      .def("expand",&escript::Data::expand)
187      .def("tag",&escript::Data::tag)      .def("tag",&escript::Data::tag)
188        .def("resolve",&escript::Data::resolve)
189      .def("copy",&escript::Data::copy)      .def("copy",&escript::Data::copy)
190      .def("convertToNumArray",&escript::Data::convertToNumArray)      .def("copy",&escript::Data::copySelf)
191      .def("convertToNumArrayFromSampleNo",&escript::Data::convertToNumArrayFromSampleNo)      .def("delay",&escript::Data::delay)
192      .def("convertToNumArrayFromDPNo",&escript::Data::convertToNumArrayFromDPNo)      .def("setValueOfDataPoint",&escript::Data::setValueOfDataPointToPyObject)
193      .def("fillFromNumArray",&escript::Data::fillFromNumArray)      .def("setValueOfDataPoint",&escript::Data::setValueOfDataPointToArray)
194        .def("setValueOfDataPoint",&escript::Data::setValueOfDataPoint)
195        .def("getValueOfDataPoint",&escript::Data::getValueOfDataPoint)
196        .def("getTupleForDataPoint",&escript::Data::getValueOfDataPointAsTuple)
197        .def("getValueOfGlobalDataPoint",&escript::Data::getValueOfGlobalDataPoint)
198        .def("getTupleForGlobalDataPoint",&escript::Data::getValueOfGlobalDataPointAsTuple)
199        .def("setToZero",&escript::Data::setToZero)
200      .def("interpolate",&escript::Data::interpolate)      .def("interpolate",&escript::Data::interpolate)
201      .def("mindp",&escript::Data::mindp)      .def("minGlobalDataPoint",&escript::Data::minGlobalDataPoint)
202      .def("saveDX",&escript::Data::saveDX)      .def("saveDX",&escript::Data::saveDX)
203      .def("saveVTK",&escript::Data::saveVTK)      .def("saveVTK",&escript::Data::saveVTK)
204      .def("getTagNumber",&escript::Data::getTagNumber)      .def("getTagNumber",&escript::Data::getTagNumber)
     .def("archiveData",&escript::Data::archiveData)  
     .def("extractData",&escript::Data::extractData)  
205      // Unary functions for Data      // Unary functions for Data
206      .def("_interpolate",&escript::Data::interpolate)      .def("_interpolate",&escript::Data::interpolate)
207      .def("_grad",&escript::Data::gradOn)      .def("_grad",&escript::Data::gradOn)
# Line 152  BOOST_PYTHON_MODULE(escriptcpp) Line 216  BOOST_PYTHON_MODULE(escriptcpp)
216      .def("_whereNonPositive",&escript::Data::whereNonPositive)      .def("_whereNonPositive",&escript::Data::whereNonPositive)
217      .def("_whereZero",&escript::Data::whereZero,(arg("tol")=0.0))      .def("_whereZero",&escript::Data::whereZero,(arg("tol")=0.0))
218      .def("_whereNonZero",&escript::Data::whereNonZero,(arg("tol")=0.0))      .def("_whereNonZero",&escript::Data::whereNonZero,(arg("tol")=0.0))
219        .def("_erf",&escript::Data::erf)
220      .def("_sin",&escript::Data::sin)      .def("_sin",&escript::Data::sin)
221      .def("_cos",&escript::Data::cos)      .def("_cos",&escript::Data::cos)
222      .def("_tan",&escript::Data::tan)      .def("_tan",&escript::Data::tan)
# Line 171  BOOST_PYTHON_MODULE(escriptcpp) Line 236  BOOST_PYTHON_MODULE(escriptcpp)
236      .def("_sign",&escript::Data::sign)      .def("_sign",&escript::Data::sign)
237      .def("_symmetric",&escript::Data::symmetric)      .def("_symmetric",&escript::Data::symmetric)
238      .def("_nonsymmetric",&escript::Data::nonsymmetric)      .def("_nonsymmetric",&escript::Data::nonsymmetric)
239      .def("_matrixtrace",&escript::Data::matrixtrace)      .def("_trace",&escript::Data::trace)
240        .def("_swap_axes",&escript::Data::swapaxes)
241      .def("_eigenvalues",&escript::Data::eigenvalues)      .def("_eigenvalues",&escript::Data::eigenvalues)
242      .def("_eigenvalues_and_eigenvectors",&escript::Data::eigenvalues_and_eigenvectors,(arg("tol")=1.e-13))      .def("_eigenvalues_and_eigenvectors",&escript::Data::eigenvalues_and_eigenvectors,(arg("tol")=1.e-13))
243      // functions returning a single real number:      // functions returning a single real number:
# Line 179  BOOST_PYTHON_MODULE(escriptcpp) Line 245  BOOST_PYTHON_MODULE(escriptcpp)
245      .def("_sup",&escript::Data::sup)      .def("_sup",&escript::Data::sup)
246      .def("_inf",&escript::Data::inf)      .def("_inf",&escript::Data::inf)
247      .def("_integrate",&escript::Data::integrate)      .def("_integrate",&escript::Data::integrate)
248        .def("_integrateToTuple",&escript::Data::integrateToTuple)
249    
250      // following implements the python abs operator      // following implements the python abs operator
251      .def("__abs__",&escript::Data::abs)      .def("__abs__",&escript::Data::abs)
# Line 228  BOOST_PYTHON_MODULE(escriptcpp) Line 295  BOOST_PYTHON_MODULE(escriptcpp)
295    // Factory methods for function space    // Factory methods for function space
296    //    //
297    def("ContinuousFunction",escript::continuousFunction);    def("ContinuousFunction",escript::continuousFunction);
298      def("ReducedContinuousFunction",escript::reducedContinuousFunction);
299    def("Function",escript::function);    def("Function",escript::function);
300      def("ReducedFunction",escript::reducedFunction);
301    def("FunctionOnBoundary",escript::functionOnBoundary);    def("FunctionOnBoundary",escript::functionOnBoundary);
302      def("ReducedFunctionOnBoundary",escript::reducedFunctionOnBoundary);
303    def("FunctionOnContactZero",escript::functionOnContactZero);    def("FunctionOnContactZero",escript::functionOnContactZero);
304      def("ReducedFunctionOnContactZero",escript::reducedFunctionOnContactZero);
305    def("FunctionOnContactOne",escript::functionOnContactOne);    def("FunctionOnContactOne",escript::functionOnContactOne);
306      def("ReducedFunctionOnContactOne",escript::reducedFunctionOnContactOne);
307    def("Solution",escript::solution);    def("Solution",escript::solution);
308    def("ReducedSolution",escript::reducedSolution);    def("ReducedSolution",escript::reducedSolution);
309    def("DiracDeltaFunction",escript::diracDeltaFunction);    def("DiracDeltaFunction",escript::diracDeltaFunction);
# Line 239  BOOST_PYTHON_MODULE(escriptcpp) Line 311  BOOST_PYTHON_MODULE(escriptcpp)
311    //    //
312    // Factory methods for Data    // Factory methods for Data
313    //    //
314      def("load",escript::load);
315      def("loadIsConfigured",escript::loadConfigured);
316    def("Scalar",escript::Scalar,    def("Scalar",escript::Scalar,
317        (arg("value")=0.0,        (arg("value")=0.0,
318         arg("what")=escript::FunctionSpace(),         arg("what")=escript::FunctionSpace(),
# Line 261  BOOST_PYTHON_MODULE(escriptcpp) Line 335  BOOST_PYTHON_MODULE(escriptcpp)
335         arg("expanded")=false));         arg("expanded")=false));
336    
337    //    //
338      // Binary operators
339      //
340      def("C_GeneralTensorProduct",escript::C_GeneralTensorProduct,
341          (arg("arg0")=escript::Data(),
342           arg("arg1")=escript::Data(),
343           arg("axis_offset")=0,
344           arg("transpose")=0));
345    
346      //
347    // Interface for AbstractSystemMatrix    // Interface for AbstractSystemMatrix
348    //    //
349    class_<escript::AbstractSystemMatrix>("Operator",init<>())    class_<escript::AbstractSystemMatrix>("Operator","",init<>())    // Doco goes in the empty string param
350       .def("isEmpty",&escript::AbstractSystemMatrix::isEmpty)       .def("isEmpty",&escript::AbstractSystemMatrix::isEmpty)
351       .def("solve",&escript::AbstractSystemMatrix::solve)       .def("solve",&escript::AbstractSystemMatrix::solve)
352       .def("of",&escript::AbstractSystemMatrix::vectorMultiply)       .def("of",&escript::AbstractSystemMatrix::vectorMultiply)
# Line 271  BOOST_PYTHON_MODULE(escriptcpp) Line 354  BOOST_PYTHON_MODULE(escriptcpp)
354       .def("saveHB",&escript::AbstractSystemMatrix::saveHB)       .def("saveHB",&escript::AbstractSystemMatrix::saveHB)
355       .def("resetValues",&escript::AbstractSystemMatrix::resetValues)       .def("resetValues",&escript::AbstractSystemMatrix::resetValues)
356       .def(self*other<escript::Data>());       .def(self*other<escript::Data>());
357      //
358      // Interface for AbstractTransportProblem
359      //
360      class_<escript::AbstractTransportProblem>("TransportProblem","",init<>())    // Doco goes in the empty string param
361         .def("isEmpty",&escript::AbstractTransportProblem::isEmpty)
362         .def("solve",&escript::AbstractTransportProblem::solve)
363         .def("setInitialValue",&escript::AbstractTransportProblem::setInitialValue)
364         .def("insertConstraint",&escript::AbstractTransportProblem::insertConstraint)
365         .def("reset",&escript::AbstractTransportProblem::resetTransport)
366         .def("resetValues",&escript::AbstractTransportProblem::resetTransport)
367         .def("getSafeTimeStepSize",&escript::AbstractTransportProblem::getSafeTimeStepSize)
368         .def("getUnlimitedTimeStepSize",&escript::AbstractTransportProblem::getUnlimitedTimeStepSize);
369    
370      // Functions to modify global parameters
371      def("setEscriptParamInt",escript::setEscriptParamInt,
372          (arg("value")=0));
373      def("getEscriptParamInt",escript::getEscriptParamInt,
374          (arg("sentinel")=0));
375      def("listEscriptParams",escript::listEscriptParams);
376    
377    //    //
378    // Register esysExceptionTranslator    // Register esysExceptionTranslator

Legend:
Removed from v.775  
changed lines
  Added in v.2308

  ViewVC Help
Powered by ViewVC 1.1.26