/[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 123 by jgs, Fri Jul 8 04:08:13 2005 UTC trunk/escript/src/escriptcpp.cpp revision 767 by gross, Fri Jun 30 07:29:08 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://www.esscc.uq.edu.au/~cochrane/esys_python_doc/html/index.html>Python module documentation (doxygen generated)</a>   * - <a href=http://iservo.edu.au/esys/epydoc/index.html>Python module documentation (epydoc generated)</a>
  *  
  * - <a href=http://www.esscc.uq.edu.au/~cochrane/esys_python_doc/index.html>Python module documentation (epydoc generated)</a>  
45   *   *
46   */   */
47    
# Line 70  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 78  BOOST_PYTHON_MODULE(escriptcpp) Line 77  BOOST_PYTHON_MODULE(escriptcpp)
77       .def("getX",&escript::AbstractDomain::getX)       .def("getX",&escript::AbstractDomain::getX)
78       .def("getNormal",&escript::AbstractDomain::getNormal)       .def("getNormal",&escript::AbstractDomain::getNormal)
79       .def("getSize",&escript::AbstractDomain::getSize)       .def("getSize",&escript::AbstractDomain::getSize)
80         .def("saveVTK",&escript::AbstractDomain::saveVTK)
81         .def("saveDX",&escript::AbstractDomain::saveDX)
82       .def(self == self)       .def(self == self)
83       .def(self != self);       .def(self != self);
84    
# Line 92  BOOST_PYTHON_MODULE(escriptcpp) Line 93  BOOST_PYTHON_MODULE(escriptcpp)
93    //    //
94    class_<escript::FunctionSpace>("FunctionSpace",init<>())    class_<escript::FunctionSpace>("FunctionSpace",init<>())
95       .def("getDim",&escript::FunctionSpace::getDim)       .def("getDim",&escript::FunctionSpace::getDim)
96         .def("getDomain",&escript::FunctionSpace::getDomain,return_internal_reference<>())
97       .def("getX",&escript::FunctionSpace::getX)       .def("getX",&escript::FunctionSpace::getX)
98       .def("getNormal",&escript::FunctionSpace::getNormal)       .def("getNormal",&escript::FunctionSpace::getNormal)
99       .def("getSize",&escript::FunctionSpace::getSize)       .def("getSize",&escript::FunctionSpace::getSize)
100       .def("toString",&escript::FunctionSpace::toString)       .def("setTags",&escript::FunctionSpace::setTags)
101         .def("getTagFromDataPointNo",&escript::FunctionSpace::getTagFromDataPointNo)
102         .def("__str__",&escript::FunctionSpace::toString)
103       .def(self == self)       .def(self == self)
104       .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);  
   
105    //    //
106    // Interface for Data    // Interface for Data
107    //    //
108    class_<escript::Data>("Data",init<>())    class_<escript::Data>("Data","TEST DOCUMENTATION",init<>())
109      // various constructors for Data objects      // various constructors for Data objects
110      .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")))
111      .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")))
# Line 120  BOOST_PYTHON_MODULE(escriptcpp) Line 114  BOOST_PYTHON_MODULE(escriptcpp)
114      .def(init<const escript::Data&>())      .def(init<const escript::Data&>())
115      // 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
116      // reference. In this case return_internal_reference.      // reference. In this case return_internal_reference.
117      .def("toString",&escript::Data::toString)      .def("__str__",&escript::Data::toString)
118      .def("getDomain",&escript::Data::getDomain,return_internal_reference<>())      .def("getDomain",&escript::Data::getDomain,return_internal_reference<>())
119      .def("getFunctionSpace",&escript::Data::getFunctionSpace,return_internal_reference<>())      .def("getFunctionSpace",&escript::Data::getFunctionSpace,return_internal_reference<>())
120      .def("isEmpty",&escript::Data::isEmpty)      .def("isEmpty",&escript::Data::isEmpty)
# Line 132  BOOST_PYTHON_MODULE(escriptcpp) Line 126  BOOST_PYTHON_MODULE(escriptcpp)
126      .def("getRefValue",&escript::Data::getRefValue)      .def("getRefValue",&escript::Data::getRefValue)
127      .def("expand",&escript::Data::expand)      .def("expand",&escript::Data::expand)
128      .def("tag",&escript::Data::tag)      .def("tag",&escript::Data::tag)
129      .def("saveDX",&escript::Data::saveDX)      .def("copy",&escript::Data::copy)
     .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)  
130      .def("convertToNumArray",&escript::Data::convertToNumArray)      .def("convertToNumArray",&escript::Data::convertToNumArray)
131      .def("convertToNumArrayFromSampleNo",&escript::Data::convertToNumArrayFromSampleNo)      .def("convertToNumArrayFromSampleNo",&escript::Data::convertToNumArrayFromSampleNo)
132      .def("convertToNumArrayFromDPNo",&escript::Data::convertToNumArrayFromDPNo)      .def("convertToNumArrayFromDPNo",&escript::Data::convertToNumArrayFromDPNo)
133        .def("fillFromNumArray",&escript::Data::fillFromNumArray)
134        .def("interpolate",&escript::Data::interpolate)
135        .def("mindp",&escript::Data::mindp)
136        .def("saveDX",&escript::Data::saveDX)
137        .def("saveVTK",&escript::Data::saveVTK)
138        .def("getTagNumber",&escript::Data::getTagNumber)
139      .def("archiveData",&escript::Data::archiveData)      .def("archiveData",&escript::Data::archiveData)
140      .def("extractData",&escript::Data::extractData)      .def("extractData",&escript::Data::extractData)
141      .def("integrate",&escript::Data::integrate)      // Unary functions for Data
142      .def("transpose",&escript::Data::transpose)      .def("_interpolate",&escript::Data::interpolate)
143      .def("trace",&escript::Data::trace)      .def("_grad",&escript::Data::gradOn)
144      .def("sin",&escript::Data::sin)      .def("_grad",&escript::Data::grad)
145      .def("cos",&escript::Data::cos)      .def("_transpose",&escript::Data::transpose)
146      .def("tan",&escript::Data::tan)      .def("_trace",&escript::Data::trace)
147      .def("log",&escript::Data::log)      .def("_maxval",&escript::Data::maxval)
148      .def("ln",&escript::Data::ln)      .def("_minval",&escript::Data::minval)
149      .def("Lsup",&escript::Data::Lsup)      .def("_wherePositive",&escript::Data::wherePositive)
150      .def("Linf",&escript::Data::Lsup)      .def("_whereNegative",&escript::Data::whereNegative)
151      .def("sup",&escript::Data::sup)      .def("_whereNonNegative",&escript::Data::whereNonNegative)
152      .def("inf",&escript::Data::inf)      .def("_whereNonPositive",&escript::Data::whereNonPositive)
153        .def("_whereZero",&escript::Data::whereZero,(arg("tol")=0.0))
154        .def("_whereNonZero",&escript::Data::whereNonZero,(arg("tol")=0.0))
155        .def("_sin",&escript::Data::sin)
156        .def("_cos",&escript::Data::cos)
157        .def("_tan",&escript::Data::tan)
158        .def("_asin",&escript::Data::asin)
159        .def("_acos",&escript::Data::acos)
160        .def("_atan",&escript::Data::atan)
161        .def("_sinh",&escript::Data::sinh)
162        .def("_cosh",&escript::Data::cosh)
163        .def("_tanh",&escript::Data::tanh)
164        .def("_asinh",&escript::Data::asinh)
165        .def("_acosh",&escript::Data::acosh)
166        .def("_atanh",&escript::Data::atanh)
167        .def("_exp",&escript::Data::exp)
168        .def("_sqrt",&escript::Data::sqrt)
169        .def("_log10",&escript::Data::log10)
170        .def("_log",&escript::Data::log)
171        .def("_sign",&escript::Data::sign)
172        .def("_eigenvalues",&escript::Data::eigenvalues)
173        .def("_eigenvalues_and_eigenvectors",&escript::Data::eigenvalues_and_eigenvectors,(arg("tol")=1.e-13))
174        // functions returning a single real number:
175        .def("_Lsup",&escript::Data::Lsup)
176        .def("_sup",&escript::Data::sup)
177        .def("_inf",&escript::Data::inf)
178        .def("_integrate",&escript::Data::integrate)
179    
180        // following implements the python abs operator
181      .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)  
182      // following implements the python "-" negation operator      // following implements the python "-" negation operator
183      .def("__neg__",&escript::Data::neg)      .def("__neg__",&escript::Data::neg)
     .def("neg",&escript::Data::neg)  
184      // following implements the python "+" identity operator      // following implements the python "+" identity operator
185      .def("__pos__",&escript::Data::pos)      .def("__pos__",&escript::Data::pos)
     .def("pos",&escript::Data::pos)  
186      // following two functions implement the python [] operator      // following two functions implement the python [] operator
187      .def("__getitem__",&escript::Data::getItem)      .def("__getitem__",&escript::Data::getItem)
188      .def("__setitem__",&escript::Data::setItemO)      .def("__setitem__",&escript::Data::setItemO)
# Line 183  BOOST_PYTHON_MODULE(escriptcpp) Line 190  BOOST_PYTHON_MODULE(escriptcpp)
190      // following two functions implement the python ** operator      // following two functions implement the python ** operator
191      .def("__pow__",&escript::Data::powO)      .def("__pow__",&escript::Data::powO)
192      .def("__pow__",&escript::Data::powD)      .def("__pow__",&escript::Data::powD)
193        .def("__rpow__",&escript::Data::rpowO)
194      // NOTE:: The order of these declarations is important. Anything      // NOTE:: The order of these declarations is important. Anything
195      // declared before the generic declaration isn't found so the generic      // declared before the generic declaration isn't found so the generic
196      // version will be called.      // version will be called.
     .def(self += other<object>())  
     .def(self += self)  
197      .def(self + other<object>())      .def(self + other<object>())
198      .def(other<object>() + self)      .def(other<object>() + self)
199      .def(self + self)      .def(self + self)
200      .def(self -= other<object>())      .def(self += other<object>())
201      .def(self -= self)      .def(self += self)
202    
203      .def(self - other<object>())      .def(self - other<object>())
204      .def(other<object>() - self)      .def(other<object>() - self)
205      .def(self - self)      .def(self - self)
206      .def(self *= other<object>())      .def(self -= other<object>())
207      .def(self *= self)      .def(self -= self)
208    
209      .def(self * other<object>())      .def(self * other<object>())
210      .def(other<object>() * self)      .def(other<object>() * self)
211      .def(self * self)      .def(self * self)
212      .def(self /= other<object>())      .def(self *= other<object>())
213      .def(self /= self)      .def(self *= self)
214    
215      .def(self / other<object>())      .def(self / other<object>())
216      .def(other<object>() / self)      .def(other<object>() / self)
217      .def(self / self)      .def(self / self)
218        .def(self /= other<object>())
219        .def(self /= self)
220      // Need scope resolution due to a bug either in the compiler or      // Need scope resolution due to a bug either in the compiler or
221      // the boost code. This calls operator << for Data.      // the boost code. This calls operator << for Data.
222      .def(self_ns::str(self));      .def(self_ns::str(self));
# Line 255  BOOST_PYTHON_MODULE(escriptcpp) Line 266  BOOST_PYTHON_MODULE(escriptcpp)
266       .def("of",&escript::AbstractSystemMatrix::vectorMultiply)       .def("of",&escript::AbstractSystemMatrix::vectorMultiply)
267       .def("saveMM",&escript::AbstractSystemMatrix::saveMM)       .def("saveMM",&escript::AbstractSystemMatrix::saveMM)
268       .def("saveHB",&escript::AbstractSystemMatrix::saveHB)       .def("saveHB",&escript::AbstractSystemMatrix::saveHB)
269       .def("setValue",&escript::AbstractSystemMatrix::setValue)       .def("resetValues",&escript::AbstractSystemMatrix::resetValues)
      .def("resetSolver",&escript::AbstractSystemMatrix::resetSolver)  
270       .def(self*other<escript::Data>());       .def(self*other<escript::Data>());
271    
272    //    //

Legend:
Removed from v.123  
changed lines
  Added in v.767

  ViewVC Help
Powered by ViewVC 1.1.26