/[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/escript/src/Data/escriptcpp.cpp revision 155 by jgs, Wed Nov 9 02:02:19 2005 UTC trunk/escript/src/escriptcpp.cpp revision 1137 by gross, Thu May 10 08:11:31 2007 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 "DataVector.h"
23  #include "escript/Data/AbstractContinuousDomain.h"  
 #include "escript/Data/AbstractDomain.h"  
24  #include "esysUtils/esysExceptionTranslator.h"  #include "esysUtils/esysExceptionTranslator.h"
25    
26  #include <boost/python.hpp>  #include <boost/python.hpp>
# Line 29  Line 28 
28  #include <boost/python/def.hpp>  #include <boost/python/def.hpp>
29  #include <boost/python/object.hpp>  #include <boost/python/object.hpp>
30  #include <boost/python/tuple.hpp>  #include <boost/python/tuple.hpp>
31                                                                                                                                              #include <boost/python/numeric.hpp>
32    
33  using namespace boost::python;  using namespace boost::python;
34    
35  /*! \mainpage Esys Documentation  /*! \mainpage Esys Documentation
# Line 42  using namespace boost::python; Line 42  using namespace boost::python;
42   *   *
43   * - \ref finley   * - \ref finley
44   *   *
45   * - <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>
46   *   *
47   */   */
48    
# Line 68  using namespace boost::python; Line 68  using namespace boost::python;
68    
69  BOOST_PYTHON_MODULE(escriptcpp)  BOOST_PYTHON_MODULE(escriptcpp)
70  {  {
71      def("setNumberOfThreads",escript::setNumberOfThreads);
72      def("getNumberOfThreads",escript::getNumberOfThreads);
73      def("releaseUnusedMemory",escript::releaseUnusedMemory);
74    
75    
76    //    //
77    // Interface for AbstractDomain    // Interface for AbstractDomain
78    //    //
79    class_<escript::AbstractDomain>("Domain",no_init)    class_<escript::AbstractDomain>("Domain",no_init)
80         .def("__str__",&escript::AbstractDomain::str)
81         .def("setTagMap",&escript::AbstractDomain::setTagMap)
82         .def("getTag",&escript::AbstractDomain::getTag)
83         .def("isValidTagName",&escript::AbstractDomain::isValidTagName)
84         .def("showTagNames",&escript::AbstractDomain::showTagNames)
85       .def("getX",&escript::AbstractDomain::getX)       .def("getX",&escript::AbstractDomain::getX)
86       .def("getNormal",&escript::AbstractDomain::getNormal)       .def("getNormal",&escript::AbstractDomain::getNormal)
87       .def("getSize",&escript::AbstractDomain::getSize)       .def("getSize",&escript::AbstractDomain::getSize)
# Line 96  BOOST_PYTHON_MODULE(escriptcpp) Line 105  BOOST_PYTHON_MODULE(escriptcpp)
105       .def("getX",&escript::FunctionSpace::getX)       .def("getX",&escript::FunctionSpace::getX)
106       .def("getNormal",&escript::FunctionSpace::getNormal)       .def("getNormal",&escript::FunctionSpace::getNormal)
107       .def("getSize",&escript::FunctionSpace::getSize)       .def("getSize",&escript::FunctionSpace::getSize)
108         .def("setTags",&escript::FunctionSpace::setTags)
109       .def("getTagFromDataPointNo",&escript::FunctionSpace::getTagFromDataPointNo)       .def("getTagFromDataPointNo",&escript::FunctionSpace::getTagFromDataPointNo)
110       .def("__str__",&escript::FunctionSpace::toString)       .def("__str__",&escript::FunctionSpace::str)
111       .def(self == self)       .def(self == self)
112       .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);  
   
113    //    //
114    // Interface for Data    // Interface for Data
115    //    //
# Line 122  BOOST_PYTHON_MODULE(escriptcpp) Line 122  BOOST_PYTHON_MODULE(escriptcpp)
122      .def(init<const escript::Data&>())      .def(init<const escript::Data&>())
123      // 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
124      // reference. In this case return_internal_reference.      // reference. In this case return_internal_reference.
125      .def("toString",&escript::Data::toString)      .def("__str__",&escript::Data::str)
126      .def("getDomain",&escript::Data::getDomain,return_internal_reference<>())      .def("getDomain",&escript::Data::getDomain,return_internal_reference<>())
127      .def("getFunctionSpace",&escript::Data::getFunctionSpace,return_internal_reference<>())      .def("getFunctionSpace",&escript::Data::getFunctionSpace,return_internal_reference<>())
128      .def("isEmpty",&escript::Data::isEmpty)      .def("isEmpty",&escript::Data::isEmpty)
129        .def("isProtected",&escript::Data::isProtected)
130        .def("setProtection",&escript::Data::setProtection)
131      .def("getShape",&escript::Data::getShapeTuple)      .def("getShape",&escript::Data::getShapeTuple)
132      .def("getRank",&escript::Data::getDataPointRank)      .def("getRank",&escript::Data::getDataPointRank)
133        .def("dump",&escript::Data::dump)
134      .def("copyWithMask",&escript::Data::copyWithMask)      .def("copyWithMask",&escript::Data::copyWithMask)
135      .def("setTaggedValue",&escript::Data::setTaggedValue)      .def("setTaggedValue",&escript::Data::setTaggedValue)
136      .def("setRefValue",&escript::Data::setRefValue)      .def("setTaggedValue",&escript::Data::setTaggedValueByName)
137      .def("getRefValue",&escript::Data::getRefValue)      .def("getNumberOfDataPoints",&escript::Data::getNumDataPoints)
138      .def("expand",&escript::Data::expand)      .def("expand",&escript::Data::expand)
139      .def("tag",&escript::Data::tag)      .def("tag",&escript::Data::tag)
140      .def("copy",&escript::Data::copy)      .def("copy",&escript::Data::copy)
141        .def("setValueOfDataPoint",&escript::Data::setValueOfDataPointToPyObject)
142        .def("setValueOfDataPoint",&escript::Data::setValueOfDataPointToArray)
143        .def("setValueOfDataPoint",&escript::Data::setValueOfDataPoint)
144        .def("getValueOfDataPoint",&escript::Data::getValueOfDataPoint)
145        .def("getValueOfGlobalDataPoint",&escript::Data::getValueOfGlobalDataPoint)
146        .def("setToZero",&escript::Data::setToZero)
147        .def("interpolate",&escript::Data::interpolate)
148        .def("minGlobalDataPoint",&escript::Data::minGlobalDataPoint)
149      .def("saveDX",&escript::Data::saveDX)      .def("saveDX",&escript::Data::saveDX)
150      .def("saveVTK",&escript::Data::saveVTK)      .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)  
     .def("convertToNumArray",&escript::Data::convertToNumArray)  
     .def("convertToNumArrayFromSampleNo",&escript::Data::convertToNumArrayFromSampleNo)  
     .def("convertToNumArrayFromDPNo",&escript::Data::convertToNumArrayFromDPNo)  
     .def("fillFromNumArray",&escript::Data::fillFromNumArray)  
151      .def("getTagNumber",&escript::Data::getTagNumber)      .def("getTagNumber",&escript::Data::getTagNumber)
152      .def("archiveData",&escript::Data::archiveData)      .def("archiveData",&escript::Data::archiveData)
153      .def("extractData",&escript::Data::extractData)      .def("extractData",&escript::Data::extractData)
154      .def("integrate",&escript::Data::integrate)      // Unary functions for Data
155      .def("transpose",&escript::Data::transpose)      .def("_interpolate",&escript::Data::interpolate)
156      .def("trace",&escript::Data::trace)      .def("_grad",&escript::Data::gradOn)
157      .def("sin",&escript::Data::sin)      .def("_grad",&escript::Data::grad)
158      .def("cos",&escript::Data::cos)      .def("_transpose",&escript::Data::transpose)
159      .def("tan",&escript::Data::tan)      .def("_trace",&escript::Data::trace)
160      .def("asin",&escript::Data::asin)      .def("_maxval",&escript::Data::maxval)
161      .def("acos",&escript::Data::acos)      .def("_minval",&escript::Data::minval)
162      .def("atan",&escript::Data::atan)      .def("_wherePositive",&escript::Data::wherePositive)
163      .def("sinh",&escript::Data::sinh)      .def("_whereNegative",&escript::Data::whereNegative)
164      .def("cosh",&escript::Data::cosh)      .def("_whereNonNegative",&escript::Data::whereNonNegative)
165      .def("tanh",&escript::Data::tanh)      .def("_whereNonPositive",&escript::Data::whereNonPositive)
166      .def("asinh",&escript::Data::asinh)      .def("_whereZero",&escript::Data::whereZero,(arg("tol")=0.0))
167      .def("acosh",&escript::Data::acosh)      .def("_whereNonZero",&escript::Data::whereNonZero,(arg("tol")=0.0))
168      .def("atanh",&escript::Data::atanh)      .def("_erf",&escript::Data::erf)
169      .def("log",&escript::Data::log)      .def("_sin",&escript::Data::sin)
170      .def("ln",&escript::Data::ln)      .def("_cos",&escript::Data::cos)
171      .def("Lsup",&escript::Data::Lsup)      .def("_tan",&escript::Data::tan)
172      .def("Linf",&escript::Data::Lsup)      .def("_asin",&escript::Data::asin)
173      .def("sup",&escript::Data::sup)      .def("_acos",&escript::Data::acos)
174      .def("inf",&escript::Data::inf)      .def("_atan",&escript::Data::atan)
175        .def("_sinh",&escript::Data::sinh)
176        .def("_cosh",&escript::Data::cosh)
177        .def("_tanh",&escript::Data::tanh)
178        .def("_asinh",&escript::Data::asinh)
179        .def("_acosh",&escript::Data::acosh)
180        .def("_atanh",&escript::Data::atanh)
181        .def("_exp",&escript::Data::exp)
182        .def("_sqrt",&escript::Data::sqrt)
183        .def("_log10",&escript::Data::log10)
184        .def("_log",&escript::Data::log)
185        .def("_sign",&escript::Data::sign)
186        .def("_symmetric",&escript::Data::symmetric)
187        .def("_nonsymmetric",&escript::Data::nonsymmetric)
188        .def("_trace",&escript::Data::trace)
189        .def("_swap_axes",&escript::Data::swapaxes)
190        .def("_eigenvalues",&escript::Data::eigenvalues)
191        .def("_eigenvalues_and_eigenvectors",&escript::Data::eigenvalues_and_eigenvectors,(arg("tol")=1.e-13))
192        // functions returning a single real number:
193        .def("_Lsup",&escript::Data::Lsup)
194        .def("_sup",&escript::Data::sup)
195        .def("_inf",&escript::Data::inf)
196        .def("_integrate",&escript::Data::integrate)
197    
198        // following implements the python abs operator
199      .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)  
200      // following implements the python "-" negation operator      // following implements the python "-" negation operator
201      .def("__neg__",&escript::Data::neg)      .def("__neg__",&escript::Data::neg)
     .def("neg",&escript::Data::neg)  
202      // following implements the python "+" identity operator      // following implements the python "+" identity operator
203      .def("__pos__",&escript::Data::pos)      .def("__pos__",&escript::Data::pos)
     .def("pos",&escript::Data::pos)  
204      // following two functions implement the python [] operator      // following two functions implement the python [] operator
205      .def("__getitem__",&escript::Data::getItem)      .def("__getitem__",&escript::Data::getItem)
206      .def("__setitem__",&escript::Data::setItemO)      .def("__setitem__",&escript::Data::setItemO)
# Line 197  BOOST_PYTHON_MODULE(escriptcpp) Line 208  BOOST_PYTHON_MODULE(escriptcpp)
208      // following two functions implement the python ** operator      // following two functions implement the python ** operator
209      .def("__pow__",&escript::Data::powO)      .def("__pow__",&escript::Data::powO)
210      .def("__pow__",&escript::Data::powD)      .def("__pow__",&escript::Data::powD)
211        .def("__rpow__",&escript::Data::rpowO)
212      // NOTE:: The order of these declarations is important. Anything      // NOTE:: The order of these declarations is important. Anything
213      // declared before the generic declaration isn't found so the generic      // declared before the generic declaration isn't found so the generic
214      // version will be called.      // version will be called.
     .def(self += other<object>())  
     .def(self += self)  
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>())      .def(self += other<object>())
219      .def(self -= self)      .def(self += self)
220    
221      .def(self - other<object>())      .def(self - other<object>())
222      .def(other<object>() - self)      .def(other<object>() - self)
223      .def(self - self)      .def(self - self)
224      .def(self *= other<object>())      .def(self -= other<object>())
225      .def(self *= self)      .def(self -= self)
226    
227      .def(self * other<object>())      .def(self * other<object>())
228      .def(other<object>() * self)      .def(other<object>() * self)
229      .def(self * self)      .def(self * self)
230      .def(self /= other<object>())      .def(self *= other<object>())
231      .def(self /= self)      .def(self *= self)
232    
233      .def(self / other<object>())      .def(self / other<object>())
234      .def(other<object>() / self)      .def(other<object>() / self)
235      .def(self / self)      .def(self / self)
236        .def(self /= other<object>())
237        .def(self /= self)
238      // Need scope resolution due to a bug either in the compiler or      // Need scope resolution due to a bug either in the compiler or
239      // the boost code. This calls operator << for Data.      // the boost code. This calls operator << for Data.
240      .def(self_ns::str(self));      .def(self_ns::str(self));
# Line 228  BOOST_PYTHON_MODULE(escriptcpp) Line 243  BOOST_PYTHON_MODULE(escriptcpp)
243    // Factory methods for function space    // Factory methods for function space
244    //    //
245    def("ContinuousFunction",escript::continuousFunction);    def("ContinuousFunction",escript::continuousFunction);
246      def("ReducedContinuousFunction",escript::reducedContinuousFunction);
247    def("Function",escript::function);    def("Function",escript::function);
248      def("ReducedFunction",escript::reducedFunction);
249    def("FunctionOnBoundary",escript::functionOnBoundary);    def("FunctionOnBoundary",escript::functionOnBoundary);
250      def("ReducedFunctionOnBoundary",escript::reducedFunctionOnBoundary);
251    def("FunctionOnContactZero",escript::functionOnContactZero);    def("FunctionOnContactZero",escript::functionOnContactZero);
252      def("ReducedFunctionOnContactZero",escript::reducedFunctionOnContactZero);
253    def("FunctionOnContactOne",escript::functionOnContactOne);    def("FunctionOnContactOne",escript::functionOnContactOne);
254      def("ReducedFunctionOnContactOne",escript::reducedFunctionOnContactOne);
255    def("Solution",escript::solution);    def("Solution",escript::solution);
256    def("ReducedSolution",escript::reducedSolution);    def("ReducedSolution",escript::reducedSolution);
257    def("DiracDeltaFunction",escript::diracDeltaFunction);    def("DiracDeltaFunction",escript::diracDeltaFunction);
# Line 239  BOOST_PYTHON_MODULE(escriptcpp) Line 259  BOOST_PYTHON_MODULE(escriptcpp)
259    //    //
260    // Factory methods for Data    // Factory methods for Data
261    //    //
262      def("load",escript::load);
263      def("loadIsConfigured",escript::loadConfigured);
264    def("Scalar",escript::Scalar,    def("Scalar",escript::Scalar,
265        (arg("value")=0.0,        (arg("value")=0.0,
266         arg("what")=escript::FunctionSpace(),         arg("what")=escript::FunctionSpace(),
# Line 261  BOOST_PYTHON_MODULE(escriptcpp) Line 283  BOOST_PYTHON_MODULE(escriptcpp)
283         arg("expanded")=false));         arg("expanded")=false));
284    
285    //    //
286      // Binary operators
287      //
288      def("C_GeneralTensorProduct",escript::C_GeneralTensorProduct,
289          (arg("arg0")=escript::Data(),
290           arg("arg1")=escript::Data(),
291           arg("axis_offset")=0,
292           arg("transpose")=0));
293    
294      //
295    // Interface for AbstractSystemMatrix    // Interface for AbstractSystemMatrix
296    //    //
297    class_<escript::AbstractSystemMatrix>("Operator",init<>())    class_<escript::AbstractSystemMatrix>("Operator",init<>())

Legend:
Removed from v.155  
changed lines
  Added in v.1137

  ViewVC Help
Powered by ViewVC 1.1.26