/[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 2308 by gross, Mon Mar 16 01:20:56 2009 UTC revision 2653 by jfenwick, Tue Sep 8 04:26:30 2009 UTC
# Line 1  Line 1 
1    
2  /*******************************************************  /*******************************************************
3  *  *
4  * Copyright (c) 2003-2008 by University of Queensland  * Copyright (c) 2003-2009 by University of Queensland
5  * Earth Systems Science Computational Center (ESSCC)  * Earth Systems Science Computational Center (ESSCC)
6  * http://www.uq.edu.au/esscc  * http://www.uq.edu.au/esscc
7  *  *
# Line 24  Line 24 
24  #include "DataVector.h"  #include "DataVector.h"
25  #include "paso/Paso_MPI.h"  #include "paso/Paso_MPI.h"
26  #include "EscriptParams.h"  #include "EscriptParams.h"
27    #include "TestDomain.h"
28    
29    
30  extern "C" {  extern "C" {
# Line 38  extern "C" { Line 39  extern "C" {
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>
 #include <boost/python/numeric.hpp>  
42  #include <boost/smart_ptr.hpp>  #include <boost/smart_ptr.hpp>
43  #include <boost/version.hpp>  #include <boost/version.hpp>
44    
# Line 46  using namespace boost::python; Line 46  using namespace boost::python;
46    
47  /*! \mainpage Esys Documentation  /*! \mainpage Esys Documentation
48   *   *
49   * \version 1.0.0   * \version 3.0.0
50   *   *
51   * - \ref escript   * - \ref escript
52   *   *
# Line 62  using namespace boost::python; Line 62  using namespace boost::python;
62   * Escript is the python module that contains the interfaces   * Escript is the python module that contains the interfaces
63   * to the C++ side of escript.   * to the C++ side of escript.
64   *   *
65   * \version 1.0.0   *
66   *   *
67   * \section class_desc Class Description:   * \section class_desc Class Description:
68   * Data   * Data
# Line 80  using namespace boost::python; Line 80  using namespace boost::python;
80    
81  BOOST_PYTHON_MODULE(escriptcpp)  BOOST_PYTHON_MODULE(escriptcpp)
82  {  {
83  // This feature was added in boost v1.34  
84  #if ((BOOST_VERSION/100)%1000 > 34) || (BOOST_VERSION/100000 >1)    #if BOOST_VERSION >= 103500
85  //#if ((BOOST_VERSION/100)%1000) > 34  // params are: bool show_user_defined, bool show_py_signatures, bool show_cpp_signatures
86    // params are: bool show_user_defined, bool show_py_signatures, bool show_cpp_signatures    docstring_options docopt(true,true,false);
   #if BOOST_VERSION > 103399  
   docstring_options docopt(true, true, false);  
87    #endif    #endif
 #endif  
88    
89    def("setNumberOfThreads",escript::setNumberOfThreads);    def("setNumberOfThreads",escript::setNumberOfThreads,"Use of this method is strongly discouraged.");
90    def("getNumberOfThreads",escript::getNumberOfThreads);    def("getNumberOfThreads",escript::getNumberOfThreads,"Return the maximum number of threads"
91    " available to OpenMP.");
92    def("releaseUnusedMemory",escript::releaseUnusedMemory);    def("releaseUnusedMemory",escript::releaseUnusedMemory);
93    def("blocktimer_initialize",blocktimer_initialize);    def("blocktimer_initialize",blocktimer_initialize);
94    def("blocktimer_reportSortByName",blocktimer_reportSortByName);    def("blocktimer_reportSortByName",blocktimer_reportSortByName);
95    def("blocktimer_reportSortByTime",blocktimer_reportSortByTime);    def("blocktimer_reportSortByTime",blocktimer_reportSortByTime);
96    def("blocktimer_increment",blocktimer_increment);    def("blocktimer_increment",blocktimer_increment);
97    def("blocktimer_time",blocktimer_time);    def("blocktimer_time",blocktimer_time);
98    def("getVersion",escript::getSvnVersion);    def("getVersion",escript::getSvnVersion,"This method will only report accurate version numbers for clean checkouts.");
99    def("printParallelThreadCounts",escript::printParallelThreadCnt);    def("printParallelThreadCounts",escript::printParallelThreadCnt);
100    def("getMPISizeWorld",escript::getMPISizeWorld);    def("getMPISizeWorld",escript::getMPISizeWorld,"Return number of MPI processes in the job.");
101    def("getMPIRankWorld",escript::getMPIRankWorld);    def("getMPIRankWorld",escript::getMPIRankWorld,"Return the rank of this process in the MPI World.");
102    def("getMPIWorldMax",escript::getMPIWorldMax);    def("MPIBarrierWorld",escript::MPIBarrierWorld,"Wait until all MPI processes have reached this point.");
103      def("getMPIWorldMax",escript::getMPIWorldMax,"\nEach MPI process calls this function with a"
104    " value for arg1. The maximum value is computed and returned.\n\n:rtype: int");
105      def("getMPIWorldSum",escript::getMPIWorldSum,"\nEach MPI process calls this function with a"
106    " value for arg1. The values are added up and the total value is returned.\n\n:rtype: int");
107    def("getMachinePrecision",escript::getMachinePrecision);    def("getMachinePrecision",escript::getMachinePrecision);
108    def("getMaxFloat",escript::getMaxFloat);    def("getMaxFloat",escript::getMaxFloat);
109      def("_saveDataCSV",escript::saveDataCSV, (args("filename","arg","sep","csep"), arg("append")=false),
110    "Saves data objects passed in a python dictionary to a file.\n"
111    "The data objects must be over the same domain and be able to be interpolated to the same FunctionSpace.\n"
112    "If one of the dictionary keys is named ``mask``, then only samples where ``mask`` has a positive\n"
113    "value will be written to the file.\n\n"
114    "A header line giving the names of each column will be output first.\n"
115    "The keys given in the dictionary will be used to name columns.\n"
116    "Then the data will be output, one line per sample (for all data).\n"
117    "\n:param filename:\n:type filename: ``string``\n"
118    ":param arg: dictionary of named `Data` objects. If one is called ``mask`` it must be scalar data."
119    "\n:type arg: ``dict``\n"
120    ":param sep:separator for columns (defaults to \", \"\n:type sep:``string``\n"
121    ":param csep:separator for fields within data object (defaults to \"_\"\n:type csep:``string``\n"
122    ":param append: If True, write to the end of ``filename``\n:type append: ``string``\n");
123    
124    
125    //    //
126    // Interface for AbstractDomain    // Interface for AbstractDomain
127    //    //
128    class_<escript::AbstractDomain, escript::Domain_ptr>("Domain","Base class for all domains.",no_init)    class_<escript::AbstractDomain, escript::Domain_ptr>("Domain","Base class for all domains.",no_init)
129       .def("setTagMap",&escript::AbstractDomain::setTagMap)       .def("getStatus",&escript::AbstractDomain::getStatus,"The status of a domain changes whenever the domain is modified\n\n:rtype: int")
130       .def("getTag",&escript::AbstractDomain::getTag)       .def("setTagMap",&escript::AbstractDomain::setTagMap,args("name","tag"),
131       .def("isValidTagName",&escript::AbstractDomain::isValidTagName)  "Give a tag number a name.\n\n:param name: Name for the tag\n:type name: ``string``\n"
132       .def("showTagNames",&escript::AbstractDomain::showTagNames)  ":param tag: numeric id\n:type tag: ``int``\n:note: Tag names must be unique within a domain")
133       .def("getX",&escript::AbstractDomain::getX)       .def("getTag",&escript::AbstractDomain::getTag,args("name"),":return: tag id for "
134       .def("getDim",&escript::AbstractDomain::getDim)  "``name``\n:rtype: ``string``")
135       .def("getNormal",&escript::AbstractDomain::getNormal)       .def("isValidTagName",&escript::AbstractDomain::isValidTagName,args("name"),
136       .def("getSize",&escript::AbstractDomain::getSize)  ":return: True is ``name`` corresponds to a tag\n:rtype: ``bool``")
137       .def("saveVTK",&escript::AbstractDomain::saveVTK)       .def("showTagNames",&escript::AbstractDomain::showTagNames,":return: A space separated list of tag names\n:rtype: ``string``")
138       .def("saveDX",&escript::AbstractDomain::saveDX)       .def("getX",&escript::AbstractDomain::getX,":rtype: `Data`\n:return: Locations in the"
139       .def("getMPISize",&escript::AbstractDomain::getMPISize)  "`Domain`. FunctionSpace is chosen appropriately")
140       .def("getMPIRank",&escript::AbstractDomain::getMPIRank)       .def("getDim",&escript::AbstractDomain::getDim,":rtype: `int`\n:return: Spatial dimension of the `Domain`")
141       .def("MPIBarrier",&escript::AbstractDomain::MPIBarrier)       .def("getNormal",&escript::AbstractDomain::getNormal,":rtype: `escript`\n:return: Boundary normals")
142       .def("onMasterProcessor",&escript::AbstractDomain::onMasterProcessor)       .def("getSize",&escript::AbstractDomain::getSize,":return: the local size of samples. The function space is chosen appropriately\n:rtype: `Data`")
143         .def("saveVTK",&escript::AbstractDomain::saveVTK,args("filename","arg", "metadata"
144    , "metadata_schema"),
145    ":param filename: \n:type filename: ``string``\n:param arg: items to be added"
146    "\n:type arg: ``dict``\n:param metadata: string representing some meta data to be added\n:type metadata: ``string``"
147    "\n:param metadata_schema: schema type for metadata\n:type metadata_schema: ``string``")
148         .def("dump",&escript::AbstractDomain::dump,args("filename"),"Dumps the domain to a file"
149    ":param filename:\n:type filename: string")
150         .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``"
151    "\n:param arg:\n:type arg: `dict`")
152         .def("getMPISize",&escript::AbstractDomain::getMPISize,":return: the number of processes used for this `Domain`\n:rtype: ``int``")
153         .def("getMPIRank",&escript::AbstractDomain::getMPIRank,":return: the rank of this process\n:rtype: ``int``")
154         .def("MPIBarrier",&escript::AbstractDomain::MPIBarrier,"Wait until all processes have reached this point")
155         .def("onMasterProcessor",&escript::AbstractDomain::onMasterProcessor,":return: True if this code is executing on the master process\n:rtype: `bool`")
156    
157       .def(self == self)       .def(self == self)
158       .def(self != self);       .def(self != self);
# Line 130  BOOST_PYTHON_MODULE(escriptcpp) Line 161  BOOST_PYTHON_MODULE(escriptcpp)
161    // Interface for AbstractContinuousDomain    // Interface for AbstractContinuousDomain
162    //    //
163    class_<escript::AbstractContinuousDomain, bases<escript::AbstractDomain> >("ContinuousDomain","Class representing continuous domains",no_init)    class_<escript::AbstractContinuousDomain, bases<escript::AbstractDomain> >("ContinuousDomain","Class representing continuous domains",no_init)
164         .def("getSystemMatrixTypeId",&escript::AbstractContinuousDomain::getSystemMatrixTypeId)         .def("getSystemMatrixTypeId",&escript::AbstractContinuousDomain::getSystemMatrixTypeId,
165         .def("getTransportTypeId",&escript::AbstractContinuousDomain::getTransportTypeId);  args("solver", "preconditioner", "package", "symmetry"),
166    ":return: the identifier of the matrix type to be used for the global stiffness matrix "
167    "when a particular solver package and symmetric matrix is used.\n"
168    ":rtype: int")
169           .def("getTransportTypeId",&escript::AbstractContinuousDomain::getTransportTypeId,
170    args("solver", "preconditioner", "package", "symmetry"));
171    
172    
173      //
174      // Interface for TestDomain
175      //
176      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>());
177    
178      // This is the only python visible way to get a TestDomain
179      def("getTestDomainFunctionSpace",&escript::getTestDomainFunctionSpace, args("dpps",
180     "samples"),
181    "For testing only. May be removed without notice.");
182    
183    //    //
184    // Interface for FunctionSpace    // Interface for FunctionSpace
185    //    //
186    class_<escript::FunctionSpace> fs_definer("FunctionSpace","",init<>());   // Doco goes in the empty string param    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
187    fs_definer.def("getDim",&escript::FunctionSpace::getDim);    fs_definer.def("getDim",&escript::FunctionSpace::getDim,":return: the spatial dimension of the underlying domain.\n:rtype: int");
188  //   fs_definer.def("getDomain",&escript::FunctionSpace::getDomain,  //   fs_definer.def("getDomain",&escript::FunctionSpace::getDomain,
189  //                  return_internal_reference<>());  //                  return_internal_reference<>());
190    fs_definer.def("getDomain",&escript::FunctionSpace::getDomainPython);    fs_definer.def("getDomain",&escript::FunctionSpace::getDomainPython,":return: the underlying `Domain` for this FunctionSpace.\n:rtype: `Domain`");
191    fs_definer.def("getX",&escript::FunctionSpace::getX);    fs_definer.def("getX",&escript::FunctionSpace::getX,"\n:return: a function whose values are its input coordinates. ie an identity function.\n:rtype: `Data`");
192    fs_definer.def("getNormal",&escript::FunctionSpace::getNormal);    fs_definer.def("getNormal",&escript::FunctionSpace::getNormal,":return: the surface normal field.\n\n:rtype: `Data`");
193    fs_definer.def("getSize",&escript::FunctionSpace::getSize);    fs_definer.def("getSize",&escript::FunctionSpace::getSize,":return: sample size\n:rtype: `Data`");
194    fs_definer.def("setTags",&escript::FunctionSpace::setTags);    fs_definer.def("setTags",&escript::FunctionSpace::setTags,args("newtag","mask"),
195    "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`");
196    fs_definer.def("getTagFromDataPointNo",    fs_definer.def("getTagFromDataPointNo",
197                   &escript::FunctionSpace::getTagFromDataPointNo);                   &escript::FunctionSpace::getTagFromDataPointNo,":return: the tag associated with the given sample number.\n:rtype: int");
198    fs_definer.def("getReferenceIDFromDataPointNo", &escript::FunctionSpace::getReferenceIDFromDataPointNo);    fs_definer.def("getReferenceIDFromDataPointNo", &escript::FunctionSpace::getReferenceIDFromDataPointNo,args("dataPointNo"),":return: the reference number associated with ``dataPointNo``\n:rtype: int ");
199    fs_definer.def("getListOfTags",&escript::FunctionSpace::getListOfTags);    fs_definer.def("getListOfTags",&escript::FunctionSpace::getListOfTags,":return: a list of the tags used in this function space\n:rtype: ``list``");
200    fs_definer.def("__str__", &escript::FunctionSpace::toString);    fs_definer.def("__str__", &escript::FunctionSpace::toString);
201    fs_definer.def(self == self);    fs_definer.def(self == self);
202    fs_definer.def(self != self);    fs_definer.def(self != self);
# Line 157  BOOST_PYTHON_MODULE(escriptcpp) Line 205  BOOST_PYTHON_MODULE(escriptcpp)
205    //    //
206    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<>() )    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<>() )
207      // various constructors for Data objects      // various constructors for Data objects
 //    .def(init<const numeric::array&, optional<const escript::FunctionSpace&, bool> >(args("value","what","expand")))  
208      .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")))
209      .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")))
210      .def(init<const escript::Data&, const escript::FunctionSpace&>(args("value","what")))      .def(init<const escript::Data&, const escript::FunctionSpace&>(args("value","what")))
# Line 165  BOOST_PYTHON_MODULE(escriptcpp) Line 212  BOOST_PYTHON_MODULE(escriptcpp)
212      // 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
213      // reference. In this case return_internal_reference.      // reference. In this case return_internal_reference.
214      .def("__str__",&escript::Data::toString)      .def("__str__",&escript::Data::toString)
215  //     .def("getDomain",&escript::Data::getDomain,return_internal_reference<>())      .def("getDomain",&escript::Data::getDomainPython,":rtype: `Domain`")
216      .def("getDomain",&escript::Data::getDomainPython)      .def("getFunctionSpace",&escript::Data::getFunctionSpace,return_value_policy<copy_const_reference>(),":rtype: `FunctionSpace`")
217      .def("getFunctionSpace",&escript::Data::getFunctionSpace,return_value_policy<copy_const_reference>())      .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.")
218      .def("isEmpty",&escript::Data::isEmpty)      .def("isProtected",&escript::Data::isProtected,"Can this instance be modified.\n:rtype: ``bool``")
219      .def("isProtected",&escript::Data::isProtected)      .def("setProtection",&escript::Data::setProtection,"Disallow modifications to this data object\n\n:note: This method does not allow you to undo protection.")
220      .def("setProtection",&escript::Data::setProtection)      .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``")
221      .def("getShape",&escript::Data::getShapeTuple)      .def("getRank",&escript::Data::getDataPointRank,":return: the number of indicies required to address a component of a datapoints\n:rtype: positive ``int``")
222      .def("getRank",&escript::Data::getDataPointRank)      .def("dump",&escript::Data::dump,args("fileName"),"Save the data as a netCDF file\n\n:param fileName: \n:type fileName: ``string``")
223      .def("dump",&escript::Data::dump)      .def("toListOfTuples",&escript::Data::toListOfTuples, (arg("scalarastuple")=false),
224      .def("copyWithMask",&escript::Data::copyWithMask)  "Return the datapoints of this object in a list. Each datapoint is stored as a tuple.\n\n"
225      .def("setTaggedValue",&escript::Data::setTaggedValue)  ":param scalarastuple: if True, scalar data will be wrapped as a tuple."
226      .def("setTaggedValue",&escript::Data::setTaggedValueByName)  " True => [(0), (1), (2)]; False => [0, 1, 2]")
227      .def("getNumberOfDataPoints",&escript::Data::getNumDataPoints)      .def("copyWithMask",&escript::Data::copyWithMask,args("other","mask"),
228      .def("isExpanded",&escript::Data::isExpanded)  "Selectively copy values from ``other`` `Data`."
229      .def("isTagged",&escript::Data::isTagged)  "Datapoints which correspond to postive values in ``mask`` will be copied from ``other``\n"
230      .def("isConstant",&escript::Data::isConstant)  "\n:param other: source of values\n"
231      .def("isLazy",&escript::Data::isLazy)  ":type other: `Data`\n:param mask:\n:type mask: Scalar `Data`")
232      .def("isReady",&escript::Data::isReady)      .def("setTaggedValue",&escript::Data::setTaggedValue,args("tagKey","value"),
233      .def("expand",&escript::Data::expand)  "Set the value of tagged Data.\n\n:param tagKey: tag to update\n:type tagKey: ``int``\n")
234      .def("tag",&escript::Data::tag)      .def("setTaggedValue",&escript::Data::setTaggedValueByName,args("name","value"),":param name: tag to update\n:type name: ``string``\n"
235      .def("resolve",&escript::Data::resolve)  ":param value: value to set tagged data to\n:type value: ``object`` which acts like an array, ``tuple`` or ``list``\n")
236      .def("copy",&escript::Data::copy)      .def("getNumberOfDataPoints",&escript::Data::getNumDataPoints,":rtype: ``int``\n:return: Number of datapoints in the object")
237      .def("copy",&escript::Data::copySelf)      .def("isExpanded",&escript::Data::isExpanded,":rtype: ``bool``\n:return: True if this ``Data`` is expanded.")
238      .def("delay",&escript::Data::delay)      .def("isTagged",&escript::Data::isTagged,":rtype: ``bool``\n:return: True if this ``Data`` is expanded.")
239      .def("setValueOfDataPoint",&escript::Data::setValueOfDataPointToPyObject)      .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.")
240        .def("isLazy",&escript::Data::isLazy,":rtype: ``bool``\n:return: True if this ``Data`` is lazy.")
241        .def("isReady",&escript::Data::isReady,":rtype: ``bool``\n:return: True if this ``Data`` is not lazy.")
242        .def("expand",&escript::Data::expand,"Convert the data to expanded representation if it is not expanded already.")
243        .def("tag",&escript::Data::tag,"Convert data to tagged representation if it is not already tagged or expanded")
244        .def("resolve",&escript::Data::resolve,"Convert the data to non-lazy representation.")
245        .def("copy",&escript::Data::copy,args("other"),"Make this object a copy of ``other``\n"
246    "\n:note: The two objects will act independently from now on. That is, changing ``other`` "
247    "after this call will not change this object and vice versa.")
248        .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.")
249        .def("delay",&escript::Data::delay,"Convert this object into lazy representation")
250        .def("setValueOfDataPoint",&escript::Data::setValueOfDataPointToPyObject,args("dataPointNo","value"))
251      .def("setValueOfDataPoint",&escript::Data::setValueOfDataPointToArray)      .def("setValueOfDataPoint",&escript::Data::setValueOfDataPointToArray)
252      .def("setValueOfDataPoint",&escript::Data::setValueOfDataPoint)      .def("setValueOfDataPoint",&escript::Data::setValueOfDataPoint,"\nModify the value of a single datapoint.\n\n:param dataPointNo:\n"
253      .def("getValueOfDataPoint",&escript::Data::getValueOfDataPoint)  ":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.")
254      .def("getTupleForDataPoint",&escript::Data::getValueOfDataPointAsTuple)      .def("getTupleForDataPoint",&escript::Data::getValueOfDataPointAsTuple,args("dataPointNo"),
255      .def("getValueOfGlobalDataPoint",&escript::Data::getValueOfGlobalDataPoint)  ":return: Value of the specified datapoint\n:rtype: ``tuple``\n:param dataPointNo: datapoint to access\n:type dataPointNo: ``int``")
256      .def("getTupleForGlobalDataPoint",&escript::Data::getValueOfGlobalDataPointAsTuple)      .def("getTupleForGlobalDataPoint",&escript::Data::getValueOfGlobalDataPointAsTuple,args("procNo","dataPointNo"),"Get a specific datapoint from a specific process\n\n"
257      .def("setToZero",&escript::Data::setToZero)  ":rtype: ``tuple``\n:param procNo: MPI rank of the process\n:type procNo: positive ``int``"
258      .def("interpolate",&escript::Data::interpolate)  "\n:param dataPointNo: datapoint to access\n:type dataPointNo: int")
259        .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.")
260        .def("interpolate",&escript::Data::interpolate,args("functionspace"),"Interpolate this object's values into a new functionspace.")
261        .def("interpolateTable", &escript::Data::interpolateFromTable2DP,
262    (arg("table"),arg("Amin"),arg("Astep"), arg("B"), arg("Bmin"), arg("Bstep"), arg("undef")=1.e50),
263    "Creates a new Data object by interpolating using the source data (which are\n"
264    "looked up in ``table``)\n``A`` must be the outer dimension on the table\n\n"
265    ":param table: two dimensional collection of values\n"
266    ":param Amin: The base of locations in table\n:type Amin: float\n"
267    ":param Astep: size of gap between each item in the table\n:type Astep: float\n"
268    ":param undef: upper bound on interpolated values\n:type undef: float\n"
269    ":param B: Scalar representing the second coordinate to be mapped into the table\n"
270    ":type B: `Data`\n"
271    ":param Bmin: The base of locations in table for 2nd dimension\n:type Bmin: float\n"
272    ":param Bstep: size of gap between each item in the table for 2nd dimension\n:type Bstep: float\n"
273    ":raise RuntimeError(DataException): if the cordinates do not map into the table or if the interpolated value is above ``undef``"
274    "\n:rtype: `Data`"
275    )
276        .def("interpolateTable", &escript::Data::interpolateFromTable1DP,
277    (arg("table"),arg("Amin"),arg("Astep"), arg("undef")=1.e50),
278    "Creates a new Data object by interpolating using the source data (which are\n"
279    "looked up in ``table``)\n\n"
280    ":param table: one dimensional collection of values\n"
281    ":param Amin: The base of locations in table\n:type Amin: float\n"
282    ":param Astep: size of gap between each item in the table\n:type Astep: float\n"
283    ":param undef: upper bound on interpolated values\n:type undef: float\n"
284    ":raise RuntimeError(DataException): if the cordinates do not map into the table or if the interpolated value is above ``undef``"
285    "\n:rtype: `Data`"
286    )
287    
288    
289      .def("minGlobalDataPoint",&escript::Data::minGlobalDataPoint)      .def("minGlobalDataPoint",&escript::Data::minGlobalDataPoint)
290      .def("saveDX",&escript::Data::saveDX)      .def("maxGlobalDataPoint",&escript::Data::maxGlobalDataPoint)
291      .def("saveVTK",&escript::Data::saveVTK)      .def("saveDX",&escript::Data::saveDX,args("fileName"),"Save the object in DX format.\n\n"
292      .def("getTagNumber",&escript::Data::getTagNumber)  ":param fileName: filename\n:type fileName: string")
293        .def("saveVTK",&escript::Data::saveVTK, args("fileName"),"Save the object in VTK format.\n\n"
294    ":param fileName: \n:type fileName: string")
295        .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")
296      // Unary functions for Data      // Unary functions for Data
297      .def("_interpolate",&escript::Data::interpolate)      .def("_interpolate",&escript::Data::interpolate)
298      .def("_grad",&escript::Data::gradOn)      .def("_grad",&escript::Data::gradOn)
# Line 241  BOOST_PYTHON_MODULE(escriptcpp) Line 332  BOOST_PYTHON_MODULE(escriptcpp)
332      .def("_eigenvalues",&escript::Data::eigenvalues)      .def("_eigenvalues",&escript::Data::eigenvalues)
333      .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))
334      // functions returning a single real number:      // functions returning a single real number:
335      .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.")
336      .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.")
337      .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.")
338      .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")
     .def("_integrateToTuple",&escript::Data::integrateToTuple)  
   
339      // following implements the python abs operator      // following implements the python abs operator
340      .def("__abs__",&escript::Data::abs)      .def("__abs__",&escript::Data::abs,":return: absolute value\n\n:rtype: `Data`")
341      // following implements the python "-" negation operator      // following implements the python "-" negation operator
342      .def("__neg__",&escript::Data::neg)      .def("__neg__",&escript::Data::neg, ":return: negation of the values in this object\n:rtype: `Data`")
343      // following implements the python "+" identity operator      // following implements the python "+" identity operator
344      .def("__pos__",&escript::Data::pos)      .def("__pos__",&escript::Data::pos, "\nThe unary + operator\n\n:rtype: `Data`")
345      // following two functions implement the python [] operator      // following two functions implement the python [] operator
346      .def("__getitem__",&escript::Data::getItem)      .def("__getitem__",&escript::Data::getItem,"Used by the python [] operator\n\n:rtype: `Data`")
347      .def("__setitem__",&escript::Data::setItemO)      .def("__setitem__",&escript::Data::setItemO,"Used by the python [] operator")
348      .def("__setitem__",&escript::Data::setItemD)      .def("__setitem__",&escript::Data::setItemD,"Used by the python [] operator")
349      // following two functions implement the python ** operator      // following two functions implement the python ** operator
350      .def("__pow__",&escript::Data::powO)      .def("__pow__",&escript::Data::powO,"Used by the python ** operator\n\n:rtype: `Data`")
351      .def("__pow__",&escript::Data::powD)      .def("__pow__",&escript::Data::powD)
352      .def("__rpow__",&escript::Data::rpowO)      .def("__rpow__",&escript::Data::rpowO,"\nUsed by the python ** operator\n\n:rtype: `Data`")
353      // NOTE:: The order of these declarations is important. Anything      // NOTE:: The order of these declarations is important. Anything
354      // declared before the generic declaration isn't found so the generic      // declared before the generic declaration isn't found so the generic
355      // version will be called.      // version will be called.
# Line 291  BOOST_PYTHON_MODULE(escriptcpp) Line 380  BOOST_PYTHON_MODULE(escriptcpp)
380      // the boost code. This calls operator << for Data.      // the boost code. This calls operator << for Data.
381      .def(self_ns::str(self));      .def(self_ns::str(self));
382    
383    
384    //    //
385    // Factory methods for function space    // Factory methods for function space
386    //    //
387    def("ContinuousFunction",escript::continuousFunction);    def("ContinuousFunction",escript::continuousFunction,args("domain"),
388    def("ReducedContinuousFunction",escript::reducedContinuousFunction);  ":return: a continuous FunctionSpace (overlapped node values)\n"
389    def("Function",escript::function);  ":rtype: `FunctionSpace`");
390    def("ReducedFunction",escript::reducedFunction);    def("ReducedContinuousFunction",escript::reducedContinuousFunction,args("domain"),
391    def("FunctionOnBoundary",escript::functionOnBoundary);  ":return: a continuous with reduced order FunctionSpace (overlapped node values on reduced element order)\n"
392    def("ReducedFunctionOnBoundary",escript::reducedFunctionOnBoundary);  ":rtype: `FunctionSpace`");
393    def("FunctionOnContactZero",escript::functionOnContactZero);    def("Function",escript::function,args("domain"),":return: a function `FunctionSpace`\n"
394    def("ReducedFunctionOnContactZero",escript::reducedFunctionOnContactZero);  ":rtype: `FunctionSpace`");
395    def("FunctionOnContactOne",escript::functionOnContactOne);    def("ReducedFunction",escript::reducedFunction, args("domain"),":return: a function FunctionSpace with reduced integration order\n:rtype: `FunctionSpace`");
396    def("ReducedFunctionOnContactOne",escript::reducedFunctionOnContactOne);    def("FunctionOnBoundary",escript::functionOnBoundary, args("domain"), ":return: a function on boundary FunctionSpace\n:rtype: `FunctionSpace`");
397    def("Solution",escript::solution);    def("ReducedFunctionOnBoundary",escript::reducedFunctionOnBoundary, args("domain"),
398    def("ReducedSolution",escript::reducedSolution);  ":return: a function on boundary FunctionSpace with reduced integration order\n"
399    def("DiracDeltaFunction",escript::diracDeltaFunction);  ":rtype: `FunctionSpace`");
400      def("FunctionOnContactZero",escript::functionOnContactZero, args("domain"), ":return: Return a FunctionSpace on left side of contact\n:rtype: `FunctionSpace`");
401      def("ReducedFunctionOnContactZero",escript::reducedFunctionOnContactZero, args("domain"),
402     ":return: a FunctionSpace  on left side of contact with reduced integration order\n:rtype: `FunctionSpace`");
403      def("FunctionOnContactOne",escript::functionOnContactOne, args("domain"), ":return: Return a FunctionSpace on right side of contact\n:rtype: `FunctionSpace`");
404      def("ReducedFunctionOnContactOne",escript::reducedFunctionOnContactOne, args("domain"),
405     ":return: Return a FunctionSpace on right side of contact with reduced integration order\n"
406    ":rtype: `FunctionSpace`");
407      def("Solution",escript::solution, args("domain"), ":rtype: `FunctionSpace`");
408      def("ReducedSolution",escript::reducedSolution, args("domain"), ":rtype: `FunctionSpace`");
409      def("DiracDeltaFunction",escript::diracDeltaFunction, args("domain"), ":rtype: `FunctionSpace`");
410    
411    
412    
413    
414    
415    //    //
416    // Factory methods for Data    // Factory methods for Data
417    //    //
418    def("load",escript::load);    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`");
419    def("loadIsConfigured",escript::loadConfigured);    def("loadIsConfigured",escript::loadConfigured,":return: True if the load function is configured.");
420    def("Scalar",escript::Scalar,    def("Scalar",escript::Scalar,
421        (arg("value")=0.0,        (arg("value")=0.0,
422         arg("what")=escript::FunctionSpace(),         arg("what")=escript::FunctionSpace(),
423         arg("expanded")=false));         arg("expanded")=false),
424    "Construct a Data object containing scalar data-points.\n\n:param value: scalar value for all points\n"
425    "\n:rtype: `Data`\n:type value: float\n:param what: FunctionSpace for Data\n:type what: `FunctionSpace`\n"
426    ":param expanded: If True, a value is stored for each point. If False, more efficient representations may be used\n"
427    ":type expanded: ``bool``");
428    def("Vector",escript::Vector,    def("Vector",escript::Vector,
429        (arg("value")=0.0,        (arg("value")=0.0,
430         arg("what")=escript::FunctionSpace(),         arg("what")=escript::FunctionSpace(),
431         arg("expanded")=false));         arg("expanded")=false),
432    "Construct a Data object containing rank1 data-points.\n\n:param value: scalar value for all points\n"
433    "\n:rtype: `Data`\n:type value: float\n:param what: FunctionSpace for Data\n:type what: `FunctionSpace`\n"
434    ":param expanded: If True, a value is stored for each point. If False, more efficient representations may be used\n"
435    ":type expanded: ``bool``");
436    def("Tensor",escript::Tensor,    def("Tensor",escript::Tensor,
437        (arg("value")=0.0,        (arg("value")=0.0,
438         arg("what")=escript::FunctionSpace(),         arg("what")=escript::FunctionSpace(),
439         arg("expanded")=false));         arg("expanded")=false),
440    "Construct a Data object containing rank2 data-points.\n\n:param value: scalar value for all points\n"
441    "\n:rtype: `Data`\n:type value: float\n:param what: FunctionSpace for Data\n:type what: `FunctionSpace`\n"
442    ":param expanded: If True, a value is stored for each point. If False, more efficient representations may be used\n"
443    ":type expanded: ``bool``");
444    def("Tensor3",escript::Tensor3,    def("Tensor3",escript::Tensor3,
445        (arg("value")=0.0,        (arg("value")=0.0,
446         arg("what")=escript::FunctionSpace(),         arg("what")=escript::FunctionSpace(),
447         arg("expanded")=false));         arg("expanded")=false),
448    "Construct a Data object containing rank3 data-points.\n\n:param value: scalar value for all points\n"
449    "\n:rtype: `Data`\n:type value: float\n:param what: FunctionSpace for Data\n:type what: `FunctionSpace`\n"
450    ":param expanded: If True, a value is stored for each point. If False, more efficient representations may be used\n"
451    ":type expanded: ``bool``"
452    );
453    def("Tensor4",escript::Tensor4,    def("Tensor4",escript::Tensor4,
454        (arg("value")=0.0,        (arg("value")=0.0,
455         arg("what")=escript::FunctionSpace(),         arg("what")=escript::FunctionSpace(),
456         arg("expanded")=false));         arg("expanded")=false),
457    "Construct a Data object containing rank4 data-points.\n\n:param value: scalar value for all points\n"
458    "\n:rtype: `Data`\n:type value: float\n:param what: FunctionSpace for Data\n:type what: `FunctionSpace`\n"
459    ":param expanded: If True, a value is stored for each point. If False, more efficient representations may be used\n"
460    ":type expanded: ``bool``"
461    );
462    
463    //    //
464    // Binary operators    // Binary operators
465    //    //
466    def("C_GeneralTensorProduct",escript::C_GeneralTensorProduct,    def("C_GeneralTensorProduct",escript::C_GeneralTensorProduct,
467        (arg("arg0")=escript::Data(),        (arg("arg0"),
468         arg("arg1")=escript::Data(),         arg("arg1"),
469         arg("axis_offset")=0,         arg("axis_offset")=0,
470         arg("transpose")=0));         arg("transpose")=0),
471    "Compute a tensor product of two Data objects.\n\n:rtype: `Data`\n:param arg0:\n"
472    ":param arg1:\n:param axis_offset:\n:type axis_offset: ``int``\n"
473    ":param transpose: 0: transpose neither, 1: transpose arg0, 2: transpose arg1\n"
474    ":type transpose: int");
475    
476    //    //
477    // Interface for AbstractSystemMatrix    // Interface for AbstractSystemMatrix
478    //    //
479    class_<escript::AbstractSystemMatrix>("Operator","",init<>())    // Doco goes in the empty string param    class_<escript::AbstractSystemMatrix>("Operator","",init<>())    // Doco goes in the empty string param
480       .def("isEmpty",&escript::AbstractSystemMatrix::isEmpty)       .def("isEmpty",&escript::AbstractSystemMatrix::isEmpty,":rtype: ``bool``\n"
481       .def("solve",&escript::AbstractSystemMatrix::solve)  ":return: True if matrix is empty")
482       .def("of",&escript::AbstractSystemMatrix::vectorMultiply)       .def("solve",&escript::AbstractSystemMatrix::solve, args("in","options"),
483       .def("saveMM",&escript::AbstractSystemMatrix::saveMM)  ":return: the solution *u* of the linear system *this*u=in*\n\n:param in:\n:type in: `Data`")
484       .def("saveHB",&escript::AbstractSystemMatrix::saveHB)       .def("of",&escript::AbstractSystemMatrix::vectorMultiply,args("right"),
485       .def("resetValues",&escript::AbstractSystemMatrix::resetValues)  "matrix*vector multiplication")
486         .def("saveMM",&escript::AbstractSystemMatrix::saveMM, args("fileName"),
487    "writes the matrix to a file using the Matrix Market file format")
488         .def("saveHB",&escript::AbstractSystemMatrix::saveHB, args("filename"),
489    "writes the matrix to a file using the Harwell-Boeing file format")
490         .def("resetValues",&escript::AbstractSystemMatrix::resetValues, "resets the matrix entries")
491       .def(self*other<escript::Data>());       .def(self*other<escript::Data>());
492    //    //
493    // Interface for AbstractTransportProblem    // Interface for AbstractTransportProblem
494    //    //
495    class_<escript::AbstractTransportProblem>("TransportProblem","",init<>())    // Doco goes in the empty string param    class_<escript::AbstractTransportProblem>("TransportProblem","",init<>())    // Doco goes in the empty string param
496       .def("isEmpty",&escript::AbstractTransportProblem::isEmpty)       .def("isEmpty",&escript::AbstractTransportProblem::isEmpty,":rtype: ``int``")
497       .def("solve",&escript::AbstractTransportProblem::solve)       .def("solve",&escript::AbstractTransportProblem::solve, args("source","dt", "options"),
498       .def("setInitialValue",&escript::AbstractTransportProblem::setInitialValue)  "returns the solution *u* for a time step *dt>0*\n\n:rtype: `Data`\n"
499       .def("insertConstraint",&escript::AbstractTransportProblem::insertConstraint)  ":param source:\n:type source: `Data`")
500       .def("reset",&escript::AbstractTransportProblem::resetTransport)       .def("setInitialValue",&escript::AbstractTransportProblem::setInitialValue, args("u"),
501    "sets the value for *u* at time *t=0*.")
502         .def("insertConstraint",&escript::AbstractTransportProblem::insertConstraint,
503    args("source", "q", "r","factor"),
504    "inserts constraint *u_{,t}=r* where *q>0*  into the problem using a weighting factor")
505         .def("reset",&escript::AbstractTransportProblem::resetTransport,
506    "resets the transport operator typically as they have been updated.")
507       .def("resetValues",&escript::AbstractTransportProblem::resetTransport)       .def("resetValues",&escript::AbstractTransportProblem::resetTransport)
508       .def("getSafeTimeStepSize",&escript::AbstractTransportProblem::getSafeTimeStepSize)       .def("getSafeTimeStepSize",&escript::AbstractTransportProblem::getSafeTimeStepSize)
509       .def("getUnlimitedTimeStepSize",&escript::AbstractTransportProblem::getUnlimitedTimeStepSize);       .def("getUnlimitedTimeStepSize",&escript::AbstractTransportProblem::getUnlimitedTimeStepSize);
510    
511    // Functions to modify global parameters    // Functions to modify global parameters
512    def("setEscriptParamInt",escript::setEscriptParamInt,    def("setEscriptParamInt",escript::setEscriptParamInt,
513        (arg("value")=0));        (arg("name"), arg("value")=0), "Modify the value of an escript tuning parameter\n\n"
514    ":param name:\n:type name: ``string``\n:param value:\n:type value: ``int``");
515    def("getEscriptParamInt",escript::getEscriptParamInt,    def("getEscriptParamInt",escript::getEscriptParamInt,
516        (arg("sentinel")=0));        (arg("name"),arg("sentinel")=0), "Read the value of an escript tuning paramter\n\n"
517    def("listEscriptParams",escript::listEscriptParams);  ":param name: parameter to lookup\n:type name: ``string``\n:param sentinel: Value to be returned if ``name`` is not a known parameter\n"
518    ":type sentinel: ``int``");
519      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.");
520    
521    //    //
522    // Register esysExceptionTranslator    // Register esysExceptionTranslator
523    //    //
524    register_exception_translator<esysUtils::EsysException>(&esysUtils::esysExceptionTranslator);    register_exception_translator<esysUtils::EsysException>(&esysUtils::esysExceptionTranslator);
   
525  }  }

Legend:
Removed from v.2308  
changed lines
  Added in v.2653

  ViewVC Help
Powered by ViewVC 1.1.26