/[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

trunk/esys2/escript/src/Data/escriptcpp.cpp revision 153 by jgs, Tue Oct 25 01:51:20 2005 UTC trunk/escript/src/escriptcpp.cpp revision 699 by gross, Fri Mar 31 06:27:56 2006 UTC
# Line 1  Line 1 
1  //$Id$  //$Id$
2  /*=============================================================================  /*
3     ************************************************************
4   ******************************************************************************   *          Copyright 2006 by ACcESS MNRF                   *
5   *                                                                            *   *                                                          *
6   *       COPYRIGHT ACcESS 2004 -  All Rights Reserved                         *   *              http://www.access.edu.au                    *
7   *                                                                            *   *       Primary Business: Queensland, Australia            *
8   * This software is the property of ACcESS.  No part of this code             *   *  Licensed under the Open Software License version 3.0    *
9   * may be copied in any form or by any means without the expressed written    *   *     http://www.opensource.org/licenses/osl-3.0.php       *
10   * consent of ACcESS.  Copying, use or modification of this software          *   *                                                          *
11   * by any unauthorised person is illegal unless that                          *   ************************************************************
12   * person has a software license agreement with ACcESS.                       *  */
13   *                                                                            *  
14   ******************************************************************************  #include "Data.h"
15    #include "FunctionSpace.h"
16  ******************************************************************************/  #include "FunctionSpaceFactory.h"
17    #include "DataFactory.h"
18  #include "escript/Data/Data.h"  #include "AbstractContinuousDomain.h"
19  #include "escript/Data/DataVariable.h"  #include "AbstractDomain.h"
20  #include "escript/Data/FunctionSpace.h"  #include "Utils.h"
21  #include "escript/Data/FunctionSpaceFactory.h"  #include "AbstractSystemMatrix.h"
22  #include "escript/Data/DataFactory.h"  
 #include "escript/Data/AbstractContinuousDomain.h"  
 #include "escript/Data/AbstractDomain.h"  
23  #include "esysUtils/esysExceptionTranslator.h"  #include "esysUtils/esysExceptionTranslator.h"
24    
25  #include <boost/python.hpp>  #include <boost/python.hpp>
# Line 29  Line 27 
27  #include <boost/python/def.hpp>  #include <boost/python/def.hpp>
28  #include <boost/python/object.hpp>  #include <boost/python/object.hpp>
29  #include <boost/python/tuple.hpp>  #include <boost/python/tuple.hpp>
30                                                                                                                                              #include <boost/python/numeric.hpp>
31    
32  using namespace boost::python;  using namespace boost::python;
33    
34  /*! \mainpage Esys Documentation  /*! \mainpage Esys Documentation
# Line 42  using namespace boost::python; Line 41  using namespace boost::python;
41   *   *
42   * - \ref finley   * - \ref finley
43   *   *
44   * - <a href=http://iservo.edu.au/esys/esys_python_doc/index.html>Python module documentation (epydoc generated)</a>   * - <a href=http://iservo.edu.au/esys/epydoc/index.html>Python module documentation (epydoc generated)</a>
45   *   *
46   */   */
47    
# Line 68  using namespace boost::python; Line 67  using namespace boost::python;
67    
68  BOOST_PYTHON_MODULE(escriptcpp)  BOOST_PYTHON_MODULE(escriptcpp)
69  {  {
70      def("setNumberOfThreads",escript::setNumberOfThreads);
71      def("getNumberOfThreads",escript::getNumberOfThreads);
72    
73    //    //
74    // Interface for AbstractDomain    // Interface for AbstractDomain
# Line 100  BOOST_PYTHON_MODULE(escriptcpp) Line 101  BOOST_PYTHON_MODULE(escriptcpp)
101       .def("__str__",&escript::FunctionSpace::toString)       .def("__str__",&escript::FunctionSpace::toString)
102       .def(self == self)       .def(self == self)
103       .def(self != self);       .def(self != self);
   
   //  
   // Interface for DataVariable  
   //  
   class_<escript::DataVariable>("DataVariable",init<>())  
     .def(init<escript::Data*>())  
     .def("evaluate",&escript::DataVariable::evaluate)  
     .def("sum",&escript::DataVariable::sum)  
     .def("diff",&escript::DataVariable::diff);  
   
104    //    //
105    // Interface for Data    // Interface for Data
106    //    //
# Line 122  BOOST_PYTHON_MODULE(escriptcpp) Line 113  BOOST_PYTHON_MODULE(escriptcpp)
113      .def(init<const escript::Data&>())      .def(init<const escript::Data&>())
114      // 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
115      // reference. In this case return_internal_reference.      // reference. In this case return_internal_reference.
116      .def("toString",&escript::Data::toString)      .def("__str__",&escript::Data::toString)
117      .def("getDomain",&escript::Data::getDomain,return_internal_reference<>())      .def("getDomain",&escript::Data::getDomain,return_internal_reference<>())
118      .def("getFunctionSpace",&escript::Data::getFunctionSpace,return_internal_reference<>())      .def("getFunctionSpace",&escript::Data::getFunctionSpace,return_internal_reference<>())
119      .def("isEmpty",&escript::Data::isEmpty)      .def("isEmpty",&escript::Data::isEmpty)
# Line 135  BOOST_PYTHON_MODULE(escriptcpp) Line 126  BOOST_PYTHON_MODULE(escriptcpp)
126      .def("expand",&escript::Data::expand)      .def("expand",&escript::Data::expand)
127      .def("tag",&escript::Data::tag)      .def("tag",&escript::Data::tag)
128      .def("copy",&escript::Data::copy)      .def("copy",&escript::Data::copy)
     .def("saveDX",&escript::Data::saveDX)  
     .def("saveVTK",&escript::Data::saveVTK)  
     .def("wherePositive",&escript::Data::wherePositive)  
     .def("whereNegative",&escript::Data::whereNegative)  
     .def("whereNonNegative",&escript::Data::whereNonNegative)  
     .def("whereNonPositive",&escript::Data::whereNonPositive)  
     .def("whereZero",&escript::Data::whereZero)  
     .def("whereNonZero",&escript::Data::whereNonZero)  
     // Unary functions for Data  
     .def("interpolate",&escript::Data::interpolate)  
     .def("grad",&escript::Data::gradOn)  
     .def("grad",&escript::Data::grad)  
129      .def("convertToNumArray",&escript::Data::convertToNumArray)      .def("convertToNumArray",&escript::Data::convertToNumArray)
130      .def("convertToNumArrayFromSampleNo",&escript::Data::convertToNumArrayFromSampleNo)      .def("convertToNumArrayFromSampleNo",&escript::Data::convertToNumArrayFromSampleNo)
131      .def("convertToNumArrayFromDPNo",&escript::Data::convertToNumArrayFromDPNo)      .def("convertToNumArrayFromDPNo",&escript::Data::convertToNumArrayFromDPNo)
132      .def("fillFromNumArray",&escript::Data::fillFromNumArray)      .def("fillFromNumArray",&escript::Data::fillFromNumArray)
133        .def("interpolate",&escript::Data::interpolate)
134        .def("mindp",&escript::Data::mindp)
135        .def("saveDX",&escript::Data::saveDX)
136        .def("saveVTK",&escript::Data::saveVTK)
137      .def("getTagNumber",&escript::Data::getTagNumber)      .def("getTagNumber",&escript::Data::getTagNumber)
138      .def("archiveData",&escript::Data::archiveData)      .def("archiveData",&escript::Data::archiveData)
139      .def("extractData",&escript::Data::extractData)      .def("extractData",&escript::Data::extractData)
140      .def("integrate",&escript::Data::integrate)      // Unary functions for Data
141      .def("transpose",&escript::Data::transpose)      .def("_interpolate",&escript::Data::interpolate)
142      .def("trace",&escript::Data::trace)      .def("_grad",&escript::Data::gradOn)
143      .def("sin",&escript::Data::sin)      .def("_grad",&escript::Data::grad)
144      .def("cos",&escript::Data::cos)      .def("_transpose",&escript::Data::transpose)
145      .def("tan",&escript::Data::tan)      .def("_trace",&escript::Data::trace)
146      .def("asin",&escript::Data::asin)      .def("_maxval",&escript::Data::maxval)
147      .def("acos",&escript::Data::acos)      .def("_minval",&escript::Data::minval)
148      .def("atan",&escript::Data::atan)      .def("_wherePositive",&escript::Data::wherePositive)
149      .def("sinh",&escript::Data::sinh)      .def("_whereNegative",&escript::Data::whereNegative)
150      .def("cosh",&escript::Data::cosh)      .def("_whereNonNegative",&escript::Data::whereNonNegative)
151      .def("tanh",&escript::Data::tanh)      .def("_whereNonPositive",&escript::Data::whereNonPositive)
152      .def("asinh",&escript::Data::asinh)      .def("_whereZero",&escript::Data::whereZero,(arg("tol")=0.0))
153      .def("acosh",&escript::Data::acosh)      .def("_whereNonZero",&escript::Data::whereNonZero,(arg("tol")=0.0))
154      .def("atanh",&escript::Data::atanh)      .def("_sin",&escript::Data::sin)
155      .def("log",&escript::Data::log)      .def("_cos",&escript::Data::cos)
156      .def("ln",&escript::Data::ln)      .def("_tan",&escript::Data::tan)
157      .def("Lsup",&escript::Data::Lsup)      .def("_asin",&escript::Data::asin)
158      .def("Linf",&escript::Data::Lsup)      .def("_acos",&escript::Data::acos)
159      .def("sup",&escript::Data::sup)      .def("_atan",&escript::Data::atan)
160      .def("inf",&escript::Data::inf)      .def("_sinh",&escript::Data::sinh)
161        .def("_cosh",&escript::Data::cosh)
162        .def("_tanh",&escript::Data::tanh)
163        .def("_asinh",&escript::Data::asinh)
164        .def("_acosh",&escript::Data::acosh)
165        .def("_atanh",&escript::Data::atanh)
166        .def("_exp",&escript::Data::exp)
167        .def("_sqrt",&escript::Data::sqrt)
168        .def("_log10",&escript::Data::log10)
169        .def("_log",&escript::Data::log)
170        .def("_sign",&escript::Data::sign)
171        .def("_eigenvalues",&escript::Data::eigenvalues)
172        .def("_eigenvalues_and_eigenvectors",&escript::Data::eigenvalues_and_eigenvectors,(arg("tol")=1.e-13))
173        // functions returning a single real number:
174        .def("_Lsup",&escript::Data::Lsup)
175        .def("_sup",&escript::Data::sup)
176        .def("_inf",&escript::Data::inf)
177        .def("_integrate",&escript::Data::integrate)
178    
179        // following implements the python abs operator
180      .def("__abs__",&escript::Data::abs)      .def("__abs__",&escript::Data::abs)
     .def("abs",&escript::Data::abs)  
     .def("exp",&escript::Data::exp)  
     .def("sqrt",&escript::Data::sqrt)  
     .def("maxval",&escript::Data::maxval)  
     .def("minval",&escript::Data::minval)  
     .def("mindp",&escript::Data::mindp)  
     .def("length",&escript::Data::length)  
     .def("sign",&escript::Data::sign)  
181      // following implements the python "-" negation operator      // following implements the python "-" negation operator
182      .def("__neg__",&escript::Data::neg)      .def("__neg__",&escript::Data::neg)
     .def("neg",&escript::Data::neg)  
183      // following implements the python "+" identity operator      // following implements the python "+" identity operator
184      .def("__pos__",&escript::Data::pos)      .def("__pos__",&escript::Data::pos)
     .def("pos",&escript::Data::pos)  
185      // following two functions implement the python [] operator      // following two functions implement the python [] operator
186      .def("__getitem__",&escript::Data::getItem)      .def("__getitem__",&escript::Data::getItem)
187      .def("__setitem__",&escript::Data::setItemO)      .def("__setitem__",&escript::Data::setItemO)
# Line 197  BOOST_PYTHON_MODULE(escriptcpp) Line 189  BOOST_PYTHON_MODULE(escriptcpp)
189      // following two functions implement the python ** operator      // following two functions implement the python ** operator
190      .def("__pow__",&escript::Data::powO)      .def("__pow__",&escript::Data::powO)
191      .def("__pow__",&escript::Data::powD)      .def("__pow__",&escript::Data::powD)
192        .def("__rpow__",&escript::Data::rpowO)
193      // NOTE:: The order of these declarations is important. Anything      // NOTE:: The order of these declarations is important. Anything
194      // declared before the generic declaration isn't found so the generic      // declared before the generic declaration isn't found so the generic
195      // version will be called.      // version will be called.
     .def(self += other<object>())  
     .def(self += self)  
196      .def(self + other<object>())      .def(self + other<object>())
197      .def(other<object>() + self)      .def(other<object>() + self)
198      .def(self + self)      .def(self + self)
199      .def(self -= other<object>())      .def(self += other<object>())
200      .def(self -= self)      .def(self += self)
201    
202      .def(self - other<object>())      .def(self - other<object>())
203      .def(other<object>() - self)      .def(other<object>() - self)
204      .def(self - self)      .def(self - self)
205      .def(self *= other<object>())      .def(self -= other<object>())
206      .def(self *= self)      .def(self -= self)
207    
208      .def(self * other<object>())      .def(self * other<object>())
209      .def(other<object>() * self)      .def(other<object>() * self)
210      .def(self * self)      .def(self * self)
211      .def(self /= other<object>())      .def(self *= other<object>())
212      .def(self /= self)      .def(self *= self)
213    
214      .def(self / other<object>())      .def(self / other<object>())
215      .def(other<object>() / self)      .def(other<object>() / self)
216      .def(self / self)      .def(self / self)
217        .def(self /= other<object>())
218        .def(self /= self)
219      // Need scope resolution due to a bug either in the compiler or      // Need scope resolution due to a bug either in the compiler or
220      // the boost code. This calls operator << for Data.      // the boost code. This calls operator << for Data.
221      .def(self_ns::str(self));      .def(self_ns::str(self));

Legend:
Removed from v.153  
changed lines
  Added in v.699

  ViewVC Help
Powered by ViewVC 1.1.26