/[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 1805 by ksteube, Wed Sep 24 23:39:00 2008 UTC
# Line 1  Line 1 
1  //$Id$  
2  /*=============================================================================  /* $Id$ */
3    
4   ******************************************************************************  /*******************************************************
5   *                                                                            *   *
6   *       COPYRIGHT ACcESS 2004 -  All Rights Reserved                         *   *           Copyright 2003-2007 by ACceSS MNRF
7   *                                                                            *   *       Copyright 2007 by University of Queensland
8   * This software is the property of ACcESS.  No part of this code             *   *
9   * may be copied in any form or by any means without the expressed written    *   *                http://esscc.uq.edu.au
10   * consent of ACcESS.  Copying, use or modification of this software          *   *        Primary Business: Queensland, Australia
11   * by any unauthorised person is illegal unless that                          *   *  Licensed under the Open Software License version 3.0
12   * person has a software license agreement with ACcESS.                       *   *     http://www.opensource.org/licenses/osl-3.0.php
13   *                                                                            *   *
14   ******************************************************************************   *******************************************************/
15    
16  ******************************************************************************/  #include "Data.h"
17    #include "FunctionSpace.h"
18  #include "escript/Data/Data.h"  #include "FunctionSpaceFactory.h"
19  #include "escript/Data/DataVariable.h"  #include "DataFactory.h"
20  #include "escript/Data/FunctionSpace.h"  #include "AbstractContinuousDomain.h"
21  #include "escript/Data/FunctionSpaceFactory.h"  #include "AbstractDomain.h"
22  #include "escript/Data/DataFactory.h"  #include "Utils.h"
23  #include "escript/Data/AbstractContinuousDomain.h"  #include "AbstractSystemMatrix.h"
24  #include "escript/Data/AbstractDomain.h"  #include "AbstractTransportProblem.h"
25    #include "DataVector.h"
26    #include "paso/Paso_MPI.h"
27    
28    extern "C" {
29    #include "escript/blocktimer.h"
30    }
31    
32  #include "esysUtils/esysExceptionTranslator.h"  #include "esysUtils/esysExceptionTranslator.h"
33    
34  #include <boost/python.hpp>  #include <boost/python.hpp>
# Line 29  Line 36 
36  #include <boost/python/def.hpp>  #include <boost/python/def.hpp>
37  #include <boost/python/object.hpp>  #include <boost/python/object.hpp>
38  #include <boost/python/tuple.hpp>  #include <boost/python/tuple.hpp>
39                                                                                                                                              #include <boost/python/numeric.hpp>
40    
41  using namespace boost::python;  using namespace boost::python;
42    
43  /*! \mainpage Esys Documentation  /*! \mainpage Esys Documentation
# Line 42  using namespace boost::python; Line 50  using namespace boost::python;
50   *   *
51   * - \ref finley   * - \ref finley
52   *   *
53   * - <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>
54   *   *
55   */   */
56    
# Line 68  using namespace boost::python; Line 76  using namespace boost::python;
76    
77  BOOST_PYTHON_MODULE(escriptcpp)  BOOST_PYTHON_MODULE(escriptcpp)
78  {  {
79      def("setNumberOfThreads",escript::setNumberOfThreads);
80      def("getNumberOfThreads",escript::getNumberOfThreads);
81      def("releaseUnusedMemory",escript::releaseUnusedMemory);
82      def("blocktimer_initialize",blocktimer_initialize);
83      def("blocktimer_reportSortByName",blocktimer_reportSortByName);
84      def("blocktimer_reportSortByTime",blocktimer_reportSortByTime);
85      def("blocktimer_increment",blocktimer_increment);
86      def("blocktimer_time",blocktimer_time);
87      def("getVersion",escript::getSvnVersion);
88      def("printParallelThreadCounts",escript::printParallelThreadCnt);
89      def("getMPISizeWorld",escript::getMPISizeWorld);
90      def("getMPIRankWorld",escript::getMPIRankWorld);
91    
92    
93    //    //
94    // Interface for AbstractDomain    // Interface for AbstractDomain
95    //    //
96    class_<escript::AbstractDomain>("Domain",no_init)    class_<escript::AbstractDomain>("Domain",no_init)
97         .def("setTagMap",&escript::AbstractDomain::setTagMap)
98         .def("getTag",&escript::AbstractDomain::getTag)
99         .def("isValidTagName",&escript::AbstractDomain::isValidTagName)
100         .def("showTagNames",&escript::AbstractDomain::showTagNames)
101       .def("getX",&escript::AbstractDomain::getX)       .def("getX",&escript::AbstractDomain::getX)
102         .def("getDim",&escript::AbstractDomain::getDim)
103       .def("getNormal",&escript::AbstractDomain::getNormal)       .def("getNormal",&escript::AbstractDomain::getNormal)
104       .def("getSize",&escript::AbstractDomain::getSize)       .def("getSize",&escript::AbstractDomain::getSize)
105       .def("saveVTK",&escript::AbstractDomain::saveVTK)       .def("saveVTK",&escript::AbstractDomain::saveVTK)
106       .def("saveDX",&escript::AbstractDomain::saveDX)       .def("saveDX",&escript::AbstractDomain::saveDX)
107         .def("getMPISize",&escript::AbstractDomain::getMPISize)
108         .def("getMPIRank",&escript::AbstractDomain::getMPIRank)
109    
110       .def(self == self)       .def(self == self)
111       .def(self != self);       .def(self != self);
112    
# Line 90  BOOST_PYTHON_MODULE(escriptcpp) Line 119  BOOST_PYTHON_MODULE(escriptcpp)
119    //    //
120    // Interface for FunctionSpace    // Interface for FunctionSpace
121    //    //
122    class_<escript::FunctionSpace>("FunctionSpace",init<>())    class_<escript::FunctionSpace> fs_definer("FunctionSpace",init<>());
123       .def("getDim",&escript::FunctionSpace::getDim)    fs_definer.def("getDim",&escript::FunctionSpace::getDim);
124       .def("getDomain",&escript::FunctionSpace::getDomain,return_internal_reference<>())    fs_definer.def("getDomain",&escript::FunctionSpace::getDomain,
125       .def("getX",&escript::FunctionSpace::getX)                   return_internal_reference<>());
126       .def("getNormal",&escript::FunctionSpace::getNormal)    fs_definer.def("getX",&escript::FunctionSpace::getX);
127       .def("getSize",&escript::FunctionSpace::getSize)    fs_definer.def("getNormal",&escript::FunctionSpace::getNormal);
128       .def("getTagFromDataPointNo",&escript::FunctionSpace::getTagFromDataPointNo)    fs_definer.def("getSize",&escript::FunctionSpace::getSize);
129       .def("__str__",&escript::FunctionSpace::toString)    fs_definer.def("setTags",&escript::FunctionSpace::setTags);
130       .def(self == self)    fs_definer.def("getTagFromDataPointNo",
131       .def(self != self);                   &escript::FunctionSpace::getTagFromDataPointNo);
132      fs_definer.def("getReferenceIDFromDataPointNo", &escript::FunctionSpace::getReferenceIDFromDataPointNo);
133    //    fs_definer.def("getListOfTags",&escript::FunctionSpace::getListOfTags);
134    // Interface for DataVariable    fs_definer.def("__str__", &escript::FunctionSpace::toString);
135    //    fs_definer.def(self == self);
136    class_<escript::DataVariable>("DataVariable",init<>())    fs_definer.def(self != self);
     .def(init<escript::Data*>())  
     .def("evaluate",&escript::DataVariable::evaluate)  
     .def("sum",&escript::DataVariable::sum)  
     .def("diff",&escript::DataVariable::diff);  
   
137    //    //
138    // Interface for Data    // Interface for Data
139    //    //
# Line 122  BOOST_PYTHON_MODULE(escriptcpp) Line 146  BOOST_PYTHON_MODULE(escriptcpp)
146      .def(init<const escript::Data&>())      .def(init<const escript::Data&>())
147      // 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
148      // reference. In this case return_internal_reference.      // reference. In this case return_internal_reference.
149      .def("toString",&escript::Data::toString)      .def("__str__",&escript::Data::toString)
150      .def("getDomain",&escript::Data::getDomain,return_internal_reference<>())      .def("getDomain",&escript::Data::getDomain,return_internal_reference<>())
151      .def("getFunctionSpace",&escript::Data::getFunctionSpace,return_internal_reference<>())      .def("getFunctionSpace",&escript::Data::getFunctionSpace,return_internal_reference<>())
152      .def("isEmpty",&escript::Data::isEmpty)      .def("isEmpty",&escript::Data::isEmpty)
153        .def("isProtected",&escript::Data::isProtected)
154        .def("setProtection",&escript::Data::setProtection)
155      .def("getShape",&escript::Data::getShapeTuple)      .def("getShape",&escript::Data::getShapeTuple)
156      .def("getRank",&escript::Data::getDataPointRank)      .def("getRank",&escript::Data::getDataPointRank)
157        .def("dump",&escript::Data::dump)
158      .def("copyWithMask",&escript::Data::copyWithMask)      .def("copyWithMask",&escript::Data::copyWithMask)
159      .def("setTaggedValue",&escript::Data::setTaggedValue)      .def("setTaggedValue",&escript::Data::setTaggedValue)
160      .def("setRefValue",&escript::Data::setRefValue)      .def("setTaggedValue",&escript::Data::setTaggedValueByName)
161      .def("getRefValue",&escript::Data::getRefValue)      .def("getNumberOfDataPoints",&escript::Data::getNumDataPoints)
162        .def("isExpanded",&escript::Data::isExpanded)
163        .def("isTagged",&escript::Data::isTagged)
164      .def("expand",&escript::Data::expand)      .def("expand",&escript::Data::expand)
165      .def("tag",&escript::Data::tag)      .def("tag",&escript::Data::tag)
166      .def("copy",&escript::Data::copy)      .def("copy",&escript::Data::copy)
167        .def("copy",&escript::Data::copySelf,return_value_policy<manage_new_object>())
168        .def("setValueOfDataPoint",&escript::Data::setValueOfDataPointToPyObject)
169        .def("setValueOfDataPoint",&escript::Data::setValueOfDataPointToArray)
170        .def("setValueOfDataPoint",&escript::Data::setValueOfDataPoint)
171        .def("getValueOfDataPoint",&escript::Data::getValueOfDataPoint)
172        .def("getValueOfGlobalDataPoint",&escript::Data::getValueOfGlobalDataPoint)
173        .def("setToZero",&escript::Data::setToZero)
174        .def("interpolate",&escript::Data::interpolate)
175        .def("minGlobalDataPoint",&escript::Data::minGlobalDataPoint)
176      .def("saveDX",&escript::Data::saveDX)      .def("saveDX",&escript::Data::saveDX)
177      .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)  
178      .def("getTagNumber",&escript::Data::getTagNumber)      .def("getTagNumber",&escript::Data::getTagNumber)
179      .def("archiveData",&escript::Data::archiveData)      // Unary functions for Data
180      .def("extractData",&escript::Data::extractData)      .def("_interpolate",&escript::Data::interpolate)
181      .def("integrate",&escript::Data::integrate)      .def("_grad",&escript::Data::gradOn)
182      .def("transpose",&escript::Data::transpose)      .def("_grad",&escript::Data::grad)
183      .def("trace",&escript::Data::trace)      .def("_transpose",&escript::Data::transpose)
184      .def("sin",&escript::Data::sin)      .def("_trace",&escript::Data::trace)
185      .def("cos",&escript::Data::cos)      .def("_maxval",&escript::Data::maxval)
186      .def("tan",&escript::Data::tan)      .def("_minval",&escript::Data::minval)
187      .def("asin",&escript::Data::asin)      .def("_wherePositive",&escript::Data::wherePositive)
188      .def("acos",&escript::Data::acos)      .def("_whereNegative",&escript::Data::whereNegative)
189      .def("atan",&escript::Data::atan)      .def("_whereNonNegative",&escript::Data::whereNonNegative)
190      .def("sinh",&escript::Data::sinh)      .def("_whereNonPositive",&escript::Data::whereNonPositive)
191      .def("cosh",&escript::Data::cosh)      .def("_whereZero",&escript::Data::whereZero,(arg("tol")=0.0))
192      .def("tanh",&escript::Data::tanh)      .def("_whereNonZero",&escript::Data::whereNonZero,(arg("tol")=0.0))
193      .def("asinh",&escript::Data::asinh)      .def("_erf",&escript::Data::erf)
194      .def("acosh",&escript::Data::acosh)      .def("_sin",&escript::Data::sin)
195      .def("atanh",&escript::Data::atanh)      .def("_cos",&escript::Data::cos)
196      .def("log",&escript::Data::log)      .def("_tan",&escript::Data::tan)
197      .def("ln",&escript::Data::ln)      .def("_asin",&escript::Data::asin)
198      .def("Lsup",&escript::Data::Lsup)      .def("_acos",&escript::Data::acos)
199      .def("Linf",&escript::Data::Lsup)      .def("_atan",&escript::Data::atan)
200      .def("sup",&escript::Data::sup)      .def("_sinh",&escript::Data::sinh)
201      .def("inf",&escript::Data::inf)      .def("_cosh",&escript::Data::cosh)
202        .def("_tanh",&escript::Data::tanh)
203        .def("_asinh",&escript::Data::asinh)
204        .def("_acosh",&escript::Data::acosh)
205        .def("_atanh",&escript::Data::atanh)
206        .def("_exp",&escript::Data::exp)
207        .def("_sqrt",&escript::Data::sqrt)
208        .def("_log10",&escript::Data::log10)
209        .def("_log",&escript::Data::log)
210        .def("_sign",&escript::Data::sign)
211        .def("_symmetric",&escript::Data::symmetric)
212        .def("_nonsymmetric",&escript::Data::nonsymmetric)
213        .def("_trace",&escript::Data::trace)
214        .def("_swap_axes",&escript::Data::swapaxes)
215        .def("_eigenvalues",&escript::Data::eigenvalues)
216        .def("_eigenvalues_and_eigenvectors",&escript::Data::eigenvalues_and_eigenvectors,(arg("tol")=1.e-13))
217        // functions returning a single real number:
218        .def("_Lsup",&escript::Data::Lsup)
219        .def("_sup",&escript::Data::sup)
220        .def("_inf",&escript::Data::inf)
221        .def("_integrate",&escript::Data::integrate)
222    
223        // following implements the python abs operator
224      .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)  
225      // following implements the python "-" negation operator      // following implements the python "-" negation operator
226      .def("__neg__",&escript::Data::neg)      .def("__neg__",&escript::Data::neg)
     .def("neg",&escript::Data::neg)  
227      // following implements the python "+" identity operator      // following implements the python "+" identity operator
228      .def("__pos__",&escript::Data::pos)      .def("__pos__",&escript::Data::pos)
     .def("pos",&escript::Data::pos)  
229      // following two functions implement the python [] operator      // following two functions implement the python [] operator
230      .def("__getitem__",&escript::Data::getItem)      .def("__getitem__",&escript::Data::getItem)
231      .def("__setitem__",&escript::Data::setItemO)      .def("__setitem__",&escript::Data::setItemO)
# Line 197  BOOST_PYTHON_MODULE(escriptcpp) Line 233  BOOST_PYTHON_MODULE(escriptcpp)
233      // following two functions implement the python ** operator      // following two functions implement the python ** operator
234      .def("__pow__",&escript::Data::powO)      .def("__pow__",&escript::Data::powO)
235      .def("__pow__",&escript::Data::powD)      .def("__pow__",&escript::Data::powD)
236        .def("__rpow__",&escript::Data::rpowO)
237      // NOTE:: The order of these declarations is important. Anything      // NOTE:: The order of these declarations is important. Anything
238      // declared before the generic declaration isn't found so the generic      // declared before the generic declaration isn't found so the generic
239      // version will be called.      // version will be called.
     .def(self += other<object>())  
     .def(self += self)  
240      .def(self + other<object>())      .def(self + other<object>())
241      .def(other<object>() + self)      .def(other<object>() + self)
242      .def(self + self)      .def(self + self)
243      .def(self -= other<object>())      .def(self += other<object>())
244      .def(self -= self)      .def(self += self)
245    
246      .def(self - other<object>())      .def(self - other<object>())
247      .def(other<object>() - self)      .def(other<object>() - self)
248      .def(self - self)      .def(self - self)
249      .def(self *= other<object>())      .def(self -= other<object>())
250      .def(self *= self)      .def(self -= self)
251    
252      .def(self * other<object>())      .def(self * other<object>())
253      .def(other<object>() * self)      .def(other<object>() * self)
254      .def(self * self)      .def(self * self)
255      .def(self /= other<object>())      .def(self *= other<object>())
256      .def(self /= self)      .def(self *= self)
257    
258      .def(self / other<object>())      .def(self / other<object>())
259      .def(other<object>() / self)      .def(other<object>() / self)
260      .def(self / self)      .def(self / self)
261        .def(self /= other<object>())
262        .def(self /= self)
263      // Need scope resolution due to a bug either in the compiler or      // Need scope resolution due to a bug either in the compiler or
264      // the boost code. This calls operator << for Data.      // the boost code. This calls operator << for Data.
265      .def(self_ns::str(self));      .def(self_ns::str(self));
# Line 228  BOOST_PYTHON_MODULE(escriptcpp) Line 268  BOOST_PYTHON_MODULE(escriptcpp)
268    // Factory methods for function space    // Factory methods for function space
269    //    //
270    def("ContinuousFunction",escript::continuousFunction);    def("ContinuousFunction",escript::continuousFunction);
271      def("ReducedContinuousFunction",escript::reducedContinuousFunction);
272    def("Function",escript::function);    def("Function",escript::function);
273      def("ReducedFunction",escript::reducedFunction);
274    def("FunctionOnBoundary",escript::functionOnBoundary);    def("FunctionOnBoundary",escript::functionOnBoundary);
275      def("ReducedFunctionOnBoundary",escript::reducedFunctionOnBoundary);
276    def("FunctionOnContactZero",escript::functionOnContactZero);    def("FunctionOnContactZero",escript::functionOnContactZero);
277      def("ReducedFunctionOnContactZero",escript::reducedFunctionOnContactZero);
278    def("FunctionOnContactOne",escript::functionOnContactOne);    def("FunctionOnContactOne",escript::functionOnContactOne);
279      def("ReducedFunctionOnContactOne",escript::reducedFunctionOnContactOne);
280    def("Solution",escript::solution);    def("Solution",escript::solution);
281    def("ReducedSolution",escript::reducedSolution);    def("ReducedSolution",escript::reducedSolution);
282    def("DiracDeltaFunction",escript::diracDeltaFunction);    def("DiracDeltaFunction",escript::diracDeltaFunction);
# Line 239  BOOST_PYTHON_MODULE(escriptcpp) Line 284  BOOST_PYTHON_MODULE(escriptcpp)
284    //    //
285    // Factory methods for Data    // Factory methods for Data
286    //    //
287      def("load",escript::load);
288      def("loadIsConfigured",escript::loadConfigured);
289    def("Scalar",escript::Scalar,    def("Scalar",escript::Scalar,
290        (arg("value")=0.0,        (arg("value")=0.0,
291         arg("what")=escript::FunctionSpace(),         arg("what")=escript::FunctionSpace(),
# Line 261  BOOST_PYTHON_MODULE(escriptcpp) Line 308  BOOST_PYTHON_MODULE(escriptcpp)
308         arg("expanded")=false));         arg("expanded")=false));
309    
310    //    //
311      // Binary operators
312      //
313      def("C_GeneralTensorProduct",escript::C_GeneralTensorProduct,
314          (arg("arg0")=escript::Data(),
315           arg("arg1")=escript::Data(),
316           arg("axis_offset")=0,
317           arg("transpose")=0));
318    
319      //
320    // Interface for AbstractSystemMatrix    // Interface for AbstractSystemMatrix
321    //    //
322    class_<escript::AbstractSystemMatrix>("Operator",init<>())    class_<escript::AbstractSystemMatrix>("Operator",init<>())
# Line 271  BOOST_PYTHON_MODULE(escriptcpp) Line 327  BOOST_PYTHON_MODULE(escriptcpp)
327       .def("saveHB",&escript::AbstractSystemMatrix::saveHB)       .def("saveHB",&escript::AbstractSystemMatrix::saveHB)
328       .def("resetValues",&escript::AbstractSystemMatrix::resetValues)       .def("resetValues",&escript::AbstractSystemMatrix::resetValues)
329       .def(self*other<escript::Data>());       .def(self*other<escript::Data>());
330      //
331      // Interface for AbstractTransportProblem
332      //
333      class_<escript::AbstractTransportProblem>("TransportProblem",init<>())
334         .def("isEmpty",&escript::AbstractTransportProblem::isEmpty)
335         .def("solve",&escript::AbstractTransportProblem::solve)
336         .def("setInitialValue",&escript::AbstractTransportProblem::setInitialValue)
337         .def("insertConstraint",&escript::AbstractTransportProblem::insertConstraint)
338         .def("reset",&escript::AbstractTransportProblem::resetTransport)
339         .def("getSafeTimeStepSize",&escript::AbstractTransportProblem::getSafeTimeStepSize);
340    
341    //    //
342    // Register esysExceptionTranslator    // Register esysExceptionTranslator

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

  ViewVC Help
Powered by ViewVC 1.1.26