/[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 767 by gross, Fri Jun 30 07:29:08 2006 UTC revision 2626 by jfenwick, Mon Aug 24 00:48:31 2009 UTC
# Line 1  Line 1 
1  //$Id$  
2  /*  /*******************************************************
3   ************************************************************  *
4   *          Copyright 2006 by ACcESS MNRF                   *  * Copyright (c) 2003-2009 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    #include "TestDomain.h"
28    
29    
30    extern "C" {
31    #include "esysUtils/blocktimer.h"
32    }
33    
34  #include "esysUtils/esysExceptionTranslator.h"  #include "esysUtils/esysExceptionTranslator.h"
35    
36    #include <boost/version.hpp>
37  #include <boost/python.hpp>  #include <boost/python.hpp>
38  #include <boost/python/module.hpp>  #include <boost/python/module.hpp>
39  #include <boost/python/def.hpp>  #include <boost/python/def.hpp>
40  #include <boost/python/object.hpp>  #include <boost/python/object.hpp>
41  #include <boost/python/tuple.hpp>  #include <boost/python/tuple.hpp>
42  #include <boost/python/numeric.hpp>  #include <boost/python/numeric.hpp>
43    #include <boost/smart_ptr.hpp>
44    #include <boost/version.hpp>
45    
46  using namespace boost::python;  using namespace boost::python;
47    
48  /*! \mainpage Esys Documentation  /*! \mainpage Esys Documentation
49   *   *
50   * \version 1.0.0   * \version 3.0.0
51   *   *
52   * - \ref escript   * - \ref escript
53   *   *
# Line 41  using namespace boost::python; Line 55  using namespace boost::python;
55   *   *
56   * - \ref finley   * - \ref finley
57   *   *
58   * - <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>
59   *   *
60   */   */
61    
# Line 49  using namespace boost::python; Line 63  using namespace boost::python;
63   * Escript is the python module that contains the interfaces   * Escript is the python module that contains the interfaces
64   * to the C++ side of escript.   * to the C++ side of escript.
65   *   *
66   * \version 1.0.0   *
67   *   *
68   * \section class_desc Class Description:   * \section class_desc Class Description:
69   * Data   * Data
# Line 67  using namespace boost::python; Line 81  using namespace boost::python;
81    
82  BOOST_PYTHON_MODULE(escriptcpp)  BOOST_PYTHON_MODULE(escriptcpp)
83  {  {
   def("setNumberOfThreads",escript::setNumberOfThreads);  
   def("getNumberOfThreads",escript::getNumberOfThreads);  
84    
85      #if BOOST_VERSION >= 103500
86    // params are: bool show_user_defined, bool show_py_signatures, bool show_cpp_signatures
87      docstring_options docopt(true,true,false);
88      #endif
89    
90      def("setNumberOfThreads",escript::setNumberOfThreads,"Use of this method is strongly discouraged.");
91      def("getNumberOfThreads",escript::getNumberOfThreads,"Return the maximum number of threads"
92    " available to OpenMP.");
93      def("releaseUnusedMemory",escript::releaseUnusedMemory);
94      def("blocktimer_initialize",blocktimer_initialize);
95      def("blocktimer_reportSortByName",blocktimer_reportSortByName);
96      def("blocktimer_reportSortByTime",blocktimer_reportSortByTime);
97      def("blocktimer_increment",blocktimer_increment);
98      def("blocktimer_time",blocktimer_time);
99      def("getVersion",escript::getSvnVersion,"This method will only report accurate version numbers for clean checkouts.");
100      def("printParallelThreadCounts",escript::printParallelThreadCnt);
101      def("getMPISizeWorld",escript::getMPISizeWorld,"Return number of MPI processes in the job.");
102      def("getMPIRankWorld",escript::getMPIRankWorld,"Return the rank of this process in the MPI World.");
103      def("MPIBarrierWorld",escript::MPIBarrierWorld,"Wait until all MPI processes have reached this point.");
104      def("getMPIWorldMax",escript::getMPIWorldMax,"\nEach MPI process calls this function with a"
105    " value for arg1. The maximum value is computed and returned.\n\n:rtype: int");
106      def("getMPIWorldSum",escript::getMPIWorldSum,"\nEach MPI process calls this function with a"
107    " value for arg1. The values are added up and the total value is returned.\n\n:rtype: int");
108      def("getMachinePrecision",escript::getMachinePrecision);
109      def("getMaxFloat",escript::getMaxFloat);
110    //    //
111    // Interface for AbstractDomain    // Interface for AbstractDomain
112    //    //
113    class_<escript::AbstractDomain>("Domain",no_init)    class_<escript::AbstractDomain, escript::Domain_ptr>("Domain","Base class for all domains.",no_init)
114       .def("getX",&escript::AbstractDomain::getX)       .def("getStatus",&escript::AbstractDomain::getStatus,"The status of a domain changes whenever the domain is modified\n\n:rtype: int")
115       .def("getNormal",&escript::AbstractDomain::getNormal)       .def("setTagMap",&escript::AbstractDomain::setTagMap,args("name","tag"),
116       .def("getSize",&escript::AbstractDomain::getSize)  "Give a tag number a name.\n\n:param name: Name for the tag\n:type name: ``string``\n"
117       .def("saveVTK",&escript::AbstractDomain::saveVTK)  ":param tag: numeric id\n:type tag: ``int``\n:note: Tag names must be unique within a domain")
118       .def("saveDX",&escript::AbstractDomain::saveDX)       .def("getTag",&escript::AbstractDomain::getTag,args("name"),":return: tag id for "
119    "``name``\n:rtype: ``string``")
120         .def("isValidTagName",&escript::AbstractDomain::isValidTagName,args("name"),
121    ":return: True is ``name`` corresponds to a tag\n:rtype: ``bool``")
122         .def("showTagNames",&escript::AbstractDomain::showTagNames,":return: A space separated list of tag names\n:rtype: ``string``")
123         .def("getX",&escript::AbstractDomain::getX,":rtype: `Data`\n:return: Locations in the"
124    "`Domain`. FunctionSpace is chosen appropriately")
125         .def("getDim",&escript::AbstractDomain::getDim,":rtype: `int`\n:return: Spatial dimension of the `Domain`")
126         .def("getNormal",&escript::AbstractDomain::getNormal,":rtype: `escript`\n:return: Boundary normals")
127         .def("getSize",&escript::AbstractDomain::getSize,":return: the local size of samples. The function space is chosen appropriately\n:rtype: `Data`")
128         .def("saveVTK",&escript::AbstractDomain::saveVTK,args("filename","arg", "metadata"
129    , "metadata_schema"),
130    ":param filename: \n:type filename: ``string``\n:param arg: items to be added"
131    "\n:type arg: ``dict``\n:param metadata: string representing some meta data to be added\n:type metadata: ``string``"
132    "\n:param metadata_schema: schema type for metadata\n:type metadata_schema: ``string``")
133         .def("dump",&escript::AbstractDomain::dump,args("filename"),"Dumps the domain to a file"
134    ":param filename:\n:type filename: string")
135         .def("saveDX",&escript::AbstractDomain::saveDX,args("filename","arg"),"Saves a dictonary of Data objects to an OpenDX input file.\n\n:param filename:\n:type filename: ``string``"
136    "\n:param arg:\n:type arg: `dict`")
137         .def("getMPISize",&escript::AbstractDomain::getMPISize,":return: the number of processes used for this `Domain`\n:rtype: ``int``")
138         .def("getMPIRank",&escript::AbstractDomain::getMPIRank,":return: the rank of this process\n:rtype: ``int``")
139         .def("MPIBarrier",&escript::AbstractDomain::MPIBarrier,"Wait until all processes have reached this point")
140         .def("onMasterProcessor",&escript::AbstractDomain::onMasterProcessor,":return: True if this code is executing on the master process\n:rtype: `bool`")
141    
142       .def(self == self)       .def(self == self)
143       .def(self != self);       .def(self != self);
144    
145    //    //
146    // Interface for AbstractContinuousDomain    // Interface for AbstractContinuousDomain
147    //    //
148    class_<escript::AbstractContinuousDomain, bases<escript::AbstractDomain> >("ContinuousDomain",no_init)    class_<escript::AbstractContinuousDomain, bases<escript::AbstractDomain> >("ContinuousDomain","Class representing continuous domains",no_init)
149         .def("getSystemMatrixTypeId",&escript::AbstractContinuousDomain::getSystemMatrixTypeId);         .def("getSystemMatrixTypeId",&escript::AbstractContinuousDomain::getSystemMatrixTypeId,
150    args("solver", "preconditioner", "package", "symmetry"),
151    ":return: the identifier of the matrix type to be used for the global stiffness matrix "
152    "when a particular solver package and symmetric matrix is used.\n"
153    ":rtype: int")
154           .def("getTransportTypeId",&escript::AbstractContinuousDomain::getTransportTypeId,
155    args("solver", "preconditioner", "package", "symmetry"));
156    
157    
158      //
159      // Interface for TestDomain
160      //
161      class_ <escript::TestDomain, bases<escript::AbstractDomain> >("TestDomain", "Test Class for domains with no structure. May be removed from future releases without notice.", init<int,int>());
162    
163      // This is the only python visible way to get a TestDomain
164      def("getTestDomainFunctionSpace",&escript::getTestDomainFunctionSpace, args("dpps",
165     "samples"),
166    "For testing only. May be removed without notice.");
167    
168    //    //
169    // Interface for FunctionSpace    // Interface for FunctionSpace
170    //    //
171    class_<escript::FunctionSpace>("FunctionSpace",init<>())    class_<escript::FunctionSpace> fs_definer("FunctionSpace","A FunctionSpace describes which points from the `Domain` to use to represent functions.",init<>());    // Doco goes in the empty string param
172       .def("getDim",&escript::FunctionSpace::getDim)    fs_definer.def("getDim",&escript::FunctionSpace::getDim,":return: the spatial dimension of the underlying domain.\n:rtype: int");
173       .def("getDomain",&escript::FunctionSpace::getDomain,return_internal_reference<>())  //   fs_definer.def("getDomain",&escript::FunctionSpace::getDomain,
174       .def("getX",&escript::FunctionSpace::getX)  //                  return_internal_reference<>());
175       .def("getNormal",&escript::FunctionSpace::getNormal)    fs_definer.def("getDomain",&escript::FunctionSpace::getDomainPython,":return: the underlying `Domain` for this FunctionSpace.\n:rtype: `Domain`");
176       .def("getSize",&escript::FunctionSpace::getSize)    fs_definer.def("getX",&escript::FunctionSpace::getX,"\n:return: a function whose values are its input coordinates. ie an identity function.\n:rtype: `Data`");
177       .def("setTags",&escript::FunctionSpace::setTags)    fs_definer.def("getNormal",&escript::FunctionSpace::getNormal,":return: the surface normal field.\n\n:rtype: `Data`");
178       .def("getTagFromDataPointNo",&escript::FunctionSpace::getTagFromDataPointNo)    fs_definer.def("getSize",&escript::FunctionSpace::getSize,":return: sample size\n:rtype: `Data`");
179       .def("__str__",&escript::FunctionSpace::toString)    fs_definer.def("setTags",&escript::FunctionSpace::setTags,args("newtag","mask"),
180       .def(self == self)  "Set tags according to a mask\n\n:param newtag: tag number to set\n:type newtag: non-zero ``int``\n:param mask: Samples which correspond to positive values in the mask will be set to ``newtag``.\n:type mask: scalar `Data`");
181       .def(self != self);    fs_definer.def("getTagFromDataPointNo",
182                     &escript::FunctionSpace::getTagFromDataPointNo,":return: the tag associated with the given sample number.\n:rtype: int");
183      fs_definer.def("getReferenceIDFromDataPointNo", &escript::FunctionSpace::getReferenceIDFromDataPointNo,args("dataPointNo"),":return: the reference number associated with ``dataPointNo``\n:rtype: int ");
184      fs_definer.def("getListOfTags",&escript::FunctionSpace::getListOfTags,":return: a list of the tags used in this function space\n:rtype: ``list``");
185      fs_definer.def("__str__", &escript::FunctionSpace::toString);
186      fs_definer.def(self == self);
187      fs_definer.def(self != self);
188    //    //
189    // Interface for Data    // Interface for Data
190    //    //
191    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<>() )
192      // various constructors for Data objects      // various constructors for Data objects
     .def(init<const numeric::array&, optional<const escript::FunctionSpace&, bool> >(args("value","what","expand")))  
193      .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")))
194      .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")))
195      .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 197  BOOST_PYTHON_MODULE(escriptcpp)
197      // 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
198      // reference. In this case return_internal_reference.      // reference. In this case return_internal_reference.
199      .def("__str__",&escript::Data::toString)      .def("__str__",&escript::Data::toString)
200      .def("getDomain",&escript::Data::getDomain,return_internal_reference<>())      .def("getDomain",&escript::Data::getDomainPython,":rtype: `Domain`")
201      .def("getFunctionSpace",&escript::Data::getFunctionSpace,return_internal_reference<>())      .def("getFunctionSpace",&escript::Data::getFunctionSpace,return_value_policy<copy_const_reference>(),":rtype: `FunctionSpace`")
202      .def("isEmpty",&escript::Data::isEmpty)      .def("isEmpty",&escript::Data::isEmpty,"Is this object an instance of ``DataEmpty``\n\n:rtype: ``bool``\n:note: This is not the same thing as asking if the object contains datapoints.")
203      .def("getShape",&escript::Data::getShapeTuple)      .def("isProtected",&escript::Data::isProtected,"Can this instance be modified.\n:rtype: ``bool``")
204      .def("getRank",&escript::Data::getDataPointRank)      .def("setProtection",&escript::Data::setProtection,"Disallow modifications to this data object\n\n:note: This method does not allow you to undo protection.")
205      .def("copyWithMask",&escript::Data::copyWithMask)      .def("getShape",&escript::Data::getShapeTuple,"\nReturns the shape of the datapoints in this object as a python tuple. Scalar data has the shape ``()``\n\n:rtype: ``tuple``")
206      .def("setTaggedValue",&escript::Data::setTaggedValue)      .def("getRank",&escript::Data::getDataPointRank,":return: the number of indicies required to address a component of a datapoints\n:rtype: positive ``int``")
207      .def("setRefValue",&escript::Data::setRefValue)      .def("dump",&escript::Data::dump,args("fileName"),"Save the data as a netCDF file\n\n:param fileName: \n:type fileName: ``string``")
208      .def("getRefValue",&escript::Data::getRefValue)      .def("toListOfTuples",&escript::Data::toListOfTuples, (arg("scalarastuple")=false),
209      .def("expand",&escript::Data::expand)  "Return the datapoints of this object in a list. Each datapoint is stored as a tuple.\n\n"
210      .def("tag",&escript::Data::tag)  ":param scalarastuple: if True, scalar data will be wrapped as a tuple."
211      .def("copy",&escript::Data::copy)  " True => [(0), (1), (2)]; False => [0, 1, 2]")
212      .def("convertToNumArray",&escript::Data::convertToNumArray)      .def("copyWithMask",&escript::Data::copyWithMask,args("other","mask"),
213      .def("convertToNumArrayFromSampleNo",&escript::Data::convertToNumArrayFromSampleNo)  "Selectively copy values from ``other`` `Data`."
214      .def("convertToNumArrayFromDPNo",&escript::Data::convertToNumArrayFromDPNo)  "Datapoints which correspond to postive values in ``mask`` will be copied from ``other``\n"
215      .def("fillFromNumArray",&escript::Data::fillFromNumArray)  "\n:param other: source of values\n"
216      .def("interpolate",&escript::Data::interpolate)  ":type other: `Data`\n:param mask:\n:type mask: Scalar `Data`")
217      .def("mindp",&escript::Data::mindp)      .def("setTaggedValue",&escript::Data::setTaggedValue,args("tagKey","value"),
218      .def("saveDX",&escript::Data::saveDX)  "Set the value of tagged Data.\n\n:param tagKey: tag to update\n:type tagKey: ``int``\n")
219      .def("saveVTK",&escript::Data::saveVTK)      .def("setTaggedValue",&escript::Data::setTaggedValueByName,args("name","value"),":param name: tag to update\n:type name: ``string``\n"
220      .def("getTagNumber",&escript::Data::getTagNumber)  ":param value: value to set tagged data to\n:type value: ``object`` which acts like an array, ``tuple`` or ``list``\n")
221      .def("archiveData",&escript::Data::archiveData)      .def("getNumberOfDataPoints",&escript::Data::getNumDataPoints,":rtype: ``int``\n:return: Number of datapoints in the object")
222      .def("extractData",&escript::Data::extractData)      .def("isExpanded",&escript::Data::isExpanded,":rtype: ``bool``\n:return: True if this ``Data`` is expanded.")
223        .def("isTagged",&escript::Data::isTagged,":rtype: ``bool``\n:return: True if this ``Data`` is expanded.")
224        .def("isConstant",&escript::Data::isConstant,":rtype: ``bool``\n:return: True if this ``Data`` is an instance of ``DataConstant``\n:note: This does not mean the data is immutable.")
225        .def("isLazy",&escript::Data::isLazy,":rtype: ``bool``\n:return: True if this ``Data`` is lazy.")
226        .def("isReady",&escript::Data::isReady,":rtype: ``bool``\n:return: True if this ``Data`` is not lazy.")
227        .def("expand",&escript::Data::expand,"Convert the data to expanded representation if it is not expanded already.")
228        .def("tag",&escript::Data::tag,"Convert data to tagged representation if it is not already tagged or expanded")
229        .def("resolve",&escript::Data::resolve,"Convert the data to non-lazy representation.")
230        .def("copy",&escript::Data::copy,args("other"),"Make this object a copy of ``other``\n"
231    "\n:note: The two objects will act independently from now on. That is, changing ``other`` "
232    "after this call will not change this object and vice versa.")
233        .def("copy",&escript::Data::copySelf,":note: In the no argument form, a new object will be returned which is an independent copy of this object.")
234        .def("delay",&escript::Data::delay,"Convert this object into lazy representation")
235        .def("setValueOfDataPoint",&escript::Data::setValueOfDataPointToPyObject,args("dataPointNo","value"))
236        .def("setValueOfDataPoint",&escript::Data::setValueOfDataPointToArray)
237        .def("setValueOfDataPoint",&escript::Data::setValueOfDataPoint,"\nModify the value of a single datapoint.\n\n:param dataPointNo:\n"
238    ":type dataPointNo: int\n:param value: \n:type value: ``float`` or an object which acts like an array, ``tuple`` or ``list``\n:warning: Use of this operation is discouraged. It prevents some optimisations from operating.")
239        .def("getTupleForDataPoint",&escript::Data::getValueOfDataPointAsTuple,args("dataPointNo"),
240    ":return: Value of the specified datapoint\n:rtype: ``tuple``\n:param dataPointNo: datapoint to access\n:type dataPointNo: ``int``")
241        .def("getTupleForGlobalDataPoint",&escript::Data::getValueOfGlobalDataPointAsTuple,args("procNo","dataPointNo"),"Get a specific datapoint from a specific process\n\n"
242    ":rtype: ``tuple``\n:param procNo: MPI rank of the process\n:type procNo: positive ``int``"
243    "\n:param dataPointNo: datapoint to access\n:type dataPointNo: int")
244        .def("setToZero",&escript::Data::setToZero,"After this call the object will store values of the same shape as before but all components will be zero.")
245        .def("interpolate",&escript::Data::interpolate,args("functionspace"),"Interpolate this object's values into a new functionspace.")
246        .def("minGlobalDataPoint",&escript::Data::minGlobalDataPoint)
247        .def("maxGlobalDataPoint",&escript::Data::maxGlobalDataPoint)
248        .def("saveDX",&escript::Data::saveDX,args("fileName"),"Save the object in DX format.\n\n"
249    ":param fileName: filename\n:type fileName: string")
250        .def("saveVTK",&escript::Data::saveVTK, args("fileName"),"Save the object in VTK format.\n\n"
251    ":param fileName: \n:type fileName: string")
252        .def("getTagNumber",&escript::Data::getTagNumber,args("dpno"),"Return tag number for the specified datapoint\n\n:rtype: int\n:param dpno: datapoint number\n:type dpno: int")
253      // Unary functions for Data      // Unary functions for Data
254      .def("_interpolate",&escript::Data::interpolate)      .def("_interpolate",&escript::Data::interpolate)
255      .def("_grad",&escript::Data::gradOn)      .def("_grad",&escript::Data::gradOn)
# Line 152  BOOST_PYTHON_MODULE(escriptcpp) Line 264  BOOST_PYTHON_MODULE(escriptcpp)
264      .def("_whereNonPositive",&escript::Data::whereNonPositive)      .def("_whereNonPositive",&escript::Data::whereNonPositive)
265      .def("_whereZero",&escript::Data::whereZero,(arg("tol")=0.0))      .def("_whereZero",&escript::Data::whereZero,(arg("tol")=0.0))
266      .def("_whereNonZero",&escript::Data::whereNonZero,(arg("tol")=0.0))      .def("_whereNonZero",&escript::Data::whereNonZero,(arg("tol")=0.0))
267        .def("_erf",&escript::Data::erf)
268      .def("_sin",&escript::Data::sin)      .def("_sin",&escript::Data::sin)
269      .def("_cos",&escript::Data::cos)      .def("_cos",&escript::Data::cos)
270      .def("_tan",&escript::Data::tan)      .def("_tan",&escript::Data::tan)
# Line 169  BOOST_PYTHON_MODULE(escriptcpp) Line 282  BOOST_PYTHON_MODULE(escriptcpp)
282      .def("_log10",&escript::Data::log10)      .def("_log10",&escript::Data::log10)
283      .def("_log",&escript::Data::log)      .def("_log",&escript::Data::log)
284      .def("_sign",&escript::Data::sign)      .def("_sign",&escript::Data::sign)
285        .def("_symmetric",&escript::Data::symmetric)
286        .def("_nonsymmetric",&escript::Data::nonsymmetric)
287        .def("_trace",&escript::Data::trace)
288        .def("_swap_axes",&escript::Data::swapaxes)
289      .def("_eigenvalues",&escript::Data::eigenvalues)      .def("_eigenvalues",&escript::Data::eigenvalues)
290      .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))
291      // functions returning a single real number:      // functions returning a single real number:
292      .def("_Lsup",&escript::Data::Lsup)      .def("_Lsup",&escript::Data::Lsup,":return: the Lsup-norm of the object\n:rtype: float\n:note: If the ``Data`` contains no values, zero will be returned instead.")
293      .def("_sup",&escript::Data::sup)      .def("_sup",&escript::Data::sup,":return: the maximum value over all data points.\n:rtype: float\n:note: If the ``Data`` contains no values a large negative value will be returned instead.")
294      .def("_inf",&escript::Data::inf)      .def("_inf",&escript::Data::inf,":return: minimum value over all components and all data points\n:rtype: float\n:note: If the ``Data`` contains no values a large positive value will be returned instead.")
295      .def("_integrate",&escript::Data::integrate)      .def("_integrateToTuple",&escript::Data::integrateToTuple,":return: Calculate the integral over the function space domain as a python tuple\n:rtype: tuple")
296    
297      // following implements the python abs operator      // following implements the python abs operator
298      .def("__abs__",&escript::Data::abs)      .def("__abs__",&escript::Data::abs,":return: absolute value\n\n:rtype: `Data`")
299      // following implements the python "-" negation operator      // following implements the python "-" negation operator
300      .def("__neg__",&escript::Data::neg)      .def("__neg__",&escript::Data::neg, ":return: negation of the values in this object\n:rtype: `Data`")
301      // following implements the python "+" identity operator      // following implements the python "+" identity operator
302      .def("__pos__",&escript::Data::pos)      .def("__pos__",&escript::Data::pos, "\nThe unary + operator\n\n:rtype: Data`")
303      // following two functions implement the python [] operator      // following two functions implement the python [] operator
304      .def("__getitem__",&escript::Data::getItem)      .def("__getitem__",&escript::Data::getItem,"Used by the python [] operator\n\n:rtype: `Data`")
305      .def("__setitem__",&escript::Data::setItemO)      .def("__setitem__",&escript::Data::setItemO,"Used by the python [] operator")
306      .def("__setitem__",&escript::Data::setItemD)      .def("__setitem__",&escript::Data::setItemD,"Used by the python [] operator")
307      // following two functions implement the python ** operator      // following two functions implement the python ** operator
308      .def("__pow__",&escript::Data::powO)      .def("__pow__",&escript::Data::powO,"Used by the python ** operator\n\n:rtype: `Data`")
309      .def("__pow__",&escript::Data::powD)      .def("__pow__",&escript::Data::powD)
310      .def("__rpow__",&escript::Data::rpowO)      .def("__rpow__",&escript::Data::rpowO,"\nUsed by the python ** operator\n\n:rtype: `Data`")
311      // NOTE:: The order of these declarations is important. Anything      // NOTE:: The order of these declarations is important. Anything
312      // declared before the generic declaration isn't found so the generic      // declared before the generic declaration isn't found so the generic
313      // version will be called.      // version will be called.
# Line 224  BOOST_PYTHON_MODULE(escriptcpp) Line 341  BOOST_PYTHON_MODULE(escriptcpp)
341    //    //
342    // Factory methods for function space    // Factory methods for function space
343    //    //
344    def("ContinuousFunction",escript::continuousFunction);    def("ContinuousFunction",escript::continuousFunction,args("domain"),
345    def("Function",escript::function);  ":return: a continuous FunctionSpace (overlapped node values)\n"
346    def("FunctionOnBoundary",escript::functionOnBoundary);  ":rtype: `FunctionSpace`");
347    def("FunctionOnContactZero",escript::functionOnContactZero);    def("ReducedContinuousFunction",escript::reducedContinuousFunction,args("domain"),
348    def("FunctionOnContactOne",escript::functionOnContactOne);  ":return: a continuous with reduced order FunctionSpace (overlapped node values on reduced element order)\n"
349    def("Solution",escript::solution);  ":rtype: `FunctionSpace`");
350    def("ReducedSolution",escript::reducedSolution);    def("Function",escript::function,args("domain"),":return: a function `FunctionSpace`\n"
351    def("DiracDeltaFunction",escript::diracDeltaFunction);  ":rtype: `FunctionSpace`");
352      def("ReducedFunction",escript::reducedFunction, args("domain"),":return: a function FunctionSpace with reduced integration order\n:rtype: `FunctionSpace`");
353      def("FunctionOnBoundary",escript::functionOnBoundary, args("domain"), ":return: a function on boundary FunctionSpace\n:rtype: `FunctionSpace`");
354      def("ReducedFunctionOnBoundary",escript::reducedFunctionOnBoundary, args("domain"),
355    ":return: a function on boundary FunctionSpace with reduced integration order\n"
356    ":rtype: `FunctionSpace`");
357      def("FunctionOnContactZero",escript::functionOnContactZero, args("domain"), ":return: Return a FunctionSpace on left side of contact\n:rtype: `FunctionSpace`");
358      def("ReducedFunctionOnContactZero",escript::reducedFunctionOnContactZero, args("domain"),
359     ":return: a FunctionSpace  on left side of contact with reduced integration order\n:rtype: `FunctionSpace`");
360      def("FunctionOnContactOne",escript::functionOnContactOne, args("domain"), ":return: Return a FunctionSpace on right side of contact\n:rtype: `FunctionSpace`");
361      def("ReducedFunctionOnContactOne",escript::reducedFunctionOnContactOne, args("domain"),
362     ":return: Return a FunctionSpace on right side of contact with reduced integration order\n"
363    ":rtype: `FunctionSpace`");
364      def("Solution",escript::solution, args("domain"), ":rtype: `FunctionSpace`");
365      def("ReducedSolution",escript::reducedSolution, args("domain"), ":rtype: `FunctionSpace`");
366      def("DiracDeltaFunction",escript::diracDeltaFunction, args("domain"), ":rtype: `FunctionSpace`");
367    
368    //    //
369    // Factory methods for Data    // Factory methods for Data
370    //    //
371      def("load",escript::load, args("fileName","domain"), "reads Data on domain from file in netCDF format\n\n:param fileName:\n:type fileName: ``string``\n:param domain:\n:type domain: `Domain`");
372      def("loadIsConfigured",escript::loadConfigured,":return: True if the load function is configured.");
373    def("Scalar",escript::Scalar,    def("Scalar",escript::Scalar,
374        (arg("value")=0.0,        (arg("value")=0.0,
375         arg("what")=escript::FunctionSpace(),         arg("what")=escript::FunctionSpace(),
376         arg("expanded")=false));         arg("expanded")=false),
377    "Construct a Data object containing scalar data-points.\n\n:param value: scalar value for all points\n"
378    "\n:rtype: `Data`\n:type value: float\n:param what: FunctionSpace for Data\n:type what: `FunctionSpace`\n"
379    ":param expanded: If True, a value is stored for each point. If False, more efficient representations may be used\n"
380    ":type expanded: ``bool``");
381    def("Vector",escript::Vector,    def("Vector",escript::Vector,
382        (arg("value")=0.0,        (arg("value")=0.0,
383         arg("what")=escript::FunctionSpace(),         arg("what")=escript::FunctionSpace(),
384         arg("expanded")=false));         arg("expanded")=false),
385    "Construct a Data object containing rank1 data-points.\n\n:param value: scalar value for all points\n"
386    "\n:rtype: `Data`\n:type value: float\n:param what: FunctionSpace for Data\n:type what: `FunctionSpace`\n"
387    ":param expanded: If True, a value is stored for each point. If False, more efficient representations may be used\n"
388    ":type expanded: ``bool``");
389    def("Tensor",escript::Tensor,    def("Tensor",escript::Tensor,
390        (arg("value")=0.0,        (arg("value")=0.0,
391         arg("what")=escript::FunctionSpace(),         arg("what")=escript::FunctionSpace(),
392         arg("expanded")=false));         arg("expanded")=false),
393    "Construct a Data object containing rank2 data-points.\n\n:param value: scalar value for all points\n"
394    "\n:rtype: `Data`\n:type value: float\n:param what: FunctionSpace for Data\n:type what: `FunctionSpace`\n"
395    ":param expanded: If True, a value is stored for each point. If False, more efficient representations may be used\n"
396    ":type expanded: ``bool``");
397    def("Tensor3",escript::Tensor3,    def("Tensor3",escript::Tensor3,
398        (arg("value")=0.0,        (arg("value")=0.0,
399         arg("what")=escript::FunctionSpace(),         arg("what")=escript::FunctionSpace(),
400         arg("expanded")=false));         arg("expanded")=false),
401    "Construct a Data object containing rank3 data-points.\n\n:param value: scalar value for all points\n"
402    "\n:rtype: `Data`\n:type value: float\n:param what: FunctionSpace for Data\n:type what: `FunctionSpace`\n"
403    ":param expanded: If True, a value is stored for each point. If False, more efficient representations may be used\n"
404    ":type expanded: ``bool``"
405    );
406    def("Tensor4",escript::Tensor4,    def("Tensor4",escript::Tensor4,
407        (arg("value")=0.0,        (arg("value")=0.0,
408         arg("what")=escript::FunctionSpace(),         arg("what")=escript::FunctionSpace(),
409         arg("expanded")=false));         arg("expanded")=false),
410    "Construct a Data object containing rank4 data-points.\n\n:param value: scalar value for all points\n"
411    "\n:rtype: `Data`\n:type value: float\n:param what: FunctionSpace for Data\n:type what: `FunctionSpace`\n"
412    ":param expanded: If True, a value is stored for each point. If False, more efficient representations may be used\n"
413    ":type expanded: ``bool``"
414    );
415    
416      //
417      // Binary operators
418      //
419      def("C_GeneralTensorProduct",escript::C_GeneralTensorProduct,
420          (arg("arg0"),
421           arg("arg1"),
422           arg("axis_offset")=0,
423           arg("transpose")=0),
424    "Compute a tensor product of two Data objects.\n\n:rtype: `Data`\n:param arg0:\n"
425    ":param arg1:\n:param axis_offset:\n:type axis_offset: ``int``\n"
426    ":param transpose: 0: transpose neither, 1: transpose arg0, 2: transpose arg1\n"
427    ":type transpose: int");
428    
429    //    //
430    // Interface for AbstractSystemMatrix    // Interface for AbstractSystemMatrix
431    //    //
432    class_<escript::AbstractSystemMatrix>("Operator",init<>())    class_<escript::AbstractSystemMatrix>("Operator","",init<>())    // Doco goes in the empty string param
433       .def("isEmpty",&escript::AbstractSystemMatrix::isEmpty)       .def("isEmpty",&escript::AbstractSystemMatrix::isEmpty,":rtype: ``bool``\n"
434       .def("solve",&escript::AbstractSystemMatrix::solve)  ":return: True if matrix is empty")
435       .def("of",&escript::AbstractSystemMatrix::vectorMultiply)       .def("solve",&escript::AbstractSystemMatrix::solve, args("in","options"),
436       .def("saveMM",&escript::AbstractSystemMatrix::saveMM)  ":return: the solution *u* of the linear system *this*u=in*\n\n:param in:\n:type in: `Data`")
437       .def("saveHB",&escript::AbstractSystemMatrix::saveHB)       .def("of",&escript::AbstractSystemMatrix::vectorMultiply,args("right"),
438       .def("resetValues",&escript::AbstractSystemMatrix::resetValues)  "matrix*vector multiplication")
439         .def("saveMM",&escript::AbstractSystemMatrix::saveMM, args("fileName"),
440    "writes the matrix to a file using the Matrix Market file format")
441         .def("saveHB",&escript::AbstractSystemMatrix::saveHB, args("filename"),
442    "writes the matrix to a file using the Harwell-Boeing file format")
443         .def("resetValues",&escript::AbstractSystemMatrix::resetValues, "resets the matrix entries")
444       .def(self*other<escript::Data>());       .def(self*other<escript::Data>());
445      //
446      // Interface for AbstractTransportProblem
447      //
448      class_<escript::AbstractTransportProblem>("TransportProblem","",init<>())    // Doco goes in the empty string param
449         .def("isEmpty",&escript::AbstractTransportProblem::isEmpty,":rtype: ``int``")
450         .def("solve",&escript::AbstractTransportProblem::solve, args("source","dt", "options"),
451    "returns the solution *u* for a time step *dt>0*\n\n:rtype: `Data`\n"
452    ":param source:\n:type source: `Data`")
453         .def("setInitialValue",&escript::AbstractTransportProblem::setInitialValue, args("u"),
454    "sets the value for *u* at time *t=0*.")
455         .def("insertConstraint",&escript::AbstractTransportProblem::insertConstraint,
456    args("source", "q", "r","factor"),
457    "inserts constraint *u_{,t}=r* where *q>0*  into the problem using a weighting factor")
458         .def("reset",&escript::AbstractTransportProblem::resetTransport,
459    "resets the transport operator typically as they have been updated.")
460         .def("resetValues",&escript::AbstractTransportProblem::resetTransport)
461         .def("getSafeTimeStepSize",&escript::AbstractTransportProblem::getSafeTimeStepSize)
462         .def("getUnlimitedTimeStepSize",&escript::AbstractTransportProblem::getUnlimitedTimeStepSize);
463    
464      // Functions to modify global parameters
465      def("setEscriptParamInt",escript::setEscriptParamInt,
466          (arg("name"), arg("value")=0), "Modify the value of an escript tuning parameter\n\n"
467    ":param name:\n:type name: ``string``\n:param value:\n:type value: ``int``");
468      def("getEscriptParamInt",escript::getEscriptParamInt,
469          (arg("name"),arg("sentinel")=0), "Read the value of an escript tuning paramter\n\n"
470    ":param name: parameter to lookup\n:type name: ``string``\n:param sentinel: Value to be returned if ``name`` is not a known parameter\n"
471    ":type sentinel: ``int``");
472      def("listEscriptParams",escript::listEscriptParams,":return: A list of pairs (p,d) where p is the name of a parameter for escript and d is a description.");
473    
474    //    //
475    // Register esysExceptionTranslator    // Register esysExceptionTranslator
476    //    //
477    register_exception_translator<esysUtils::EsysException>(&esysUtils::esysExceptionTranslator);    register_exception_translator<esysUtils::EsysException>(&esysUtils::esysExceptionTranslator);
   
478  }  }

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

  ViewVC Help
Powered by ViewVC 1.1.26