/[escript]/trunk/escript/src/escriptcpp.cpp
ViewVC logotype

Annotation of /trunk/escript/src/escriptcpp.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3522 - (hide annotations)
Tue May 24 00:57:58 2011 UTC (8 years, 4 months ago) by gross
File size: 38708 byte(s)
(almost) full support for Point elements
1 jgs 102
2 ksteube 1312 /*******************************************************
3 ksteube 1811 *
4 jfenwick 2881 * Copyright (c) 2003-2010 by University of Queensland
5 ksteube 1811 * Earth Systems Science Computational Center (ESSCC)
6     * http://www.uq.edu.au/esscc
7     *
8     * Primary Business: Queensland, Australia
9     * Licensed under the Open Software License version 3.0
10     * http://www.opensource.org/licenses/osl-3.0.php
11     *
12     *******************************************************/
13 ksteube 1312
14 ksteube 1811
15 jgs 474 #include "Data.h"
16     #include "FunctionSpace.h"
17     #include "FunctionSpaceFactory.h"
18     #include "DataFactory.h"
19     #include "AbstractContinuousDomain.h"
20     #include "AbstractDomain.h"
21     #include "Utils.h"
22 jgs 480 #include "AbstractSystemMatrix.h"
23 gross 1364 #include "AbstractTransportProblem.h"
24 gross 797 #include "DataVector.h"
25 jfenwick 3259 #include "esysUtils/Esys_MPI.h"
26 jfenwick 1897 #include "EscriptParams.h"
27 jfenwick 2482 #include "TestDomain.h"
28 jgs 474
29 jfenwick 1872
30 ksteube 1312 extern "C" {
31 phornby 2078 #include "esysUtils/blocktimer.h"
32 ksteube 1312 }
33    
34 robwdcock 682 #include "esysUtils/esysExceptionTranslator.h"
35 jgs 102
36 gross 2100 #include <boost/version.hpp>
37 jgs 102 #include <boost/python.hpp>
38     #include <boost/python/module.hpp>
39     #include <boost/python/def.hpp>
40     #include <boost/python/object.hpp>
41     #include <boost/python/tuple.hpp>
42 jfenwick 1872 #include <boost/smart_ptr.hpp>
43 jfenwick 2064 #include <boost/version.hpp>
44 gross 285
45 jgs 102 using namespace boost::python;
46    
47 jgs 121 /*! \mainpage Esys Documentation
48     *
49 jfenwick 2602 * \version 3.0.0
50 jgs 121 *
51     * - \ref escript
52     *
53     * - \ref esys_exception "Esys Exception"
54     *
55 jfenwick 3259 * - \ref dudley
56 jgs 121 *
57 jfenwick 2283 * - <a href="../../epydoc/index.html">Python module documentation (epydoc generated)</a>
58 jgs 122 *
59 jgs 121 */
60 jgs 102
61 jgs 121 /*! \page escript Escript
62     * Escript is the python module that contains the interfaces
63     * to the C++ side of escript.
64     *
65 jfenwick 2459 *
66 jgs 121 *
67     * \section class_desc Class Description:
68     * Data
69     *
70     * \section class_limits Class Limitations:
71     * None
72     *
73     * \section class_conds Class Conditions of Use:
74     * None
75     *
76     * \section class_throws Throws:
77     * None
78     *
79     */
80 jgs 102
81     BOOST_PYTHON_MODULE(escriptcpp)
82     {
83 jfenwick 2625
84     #if BOOST_VERSION >= 103500
85     // params are: bool show_user_defined, bool show_py_signatures, bool show_cpp_signatures
86     docstring_options docopt(true,true,false);
87 gross 2100 #endif
88 jfenwick 2061
89 jfenwick 2607 def("setNumberOfThreads",escript::setNumberOfThreads,"Use of this method is strongly discouraged.");
90 jfenwick 2625 def("getNumberOfThreads",escript::getNumberOfThreads,"Return the maximum number of threads"
91     " available to OpenMP.");
92 gross 797 def("releaseUnusedMemory",escript::releaseUnusedMemory);
93 ksteube 1312 def("blocktimer_initialize",blocktimer_initialize);
94     def("blocktimer_reportSortByName",blocktimer_reportSortByName);
95     def("blocktimer_reportSortByTime",blocktimer_reportSortByTime);
96     def("blocktimer_increment",blocktimer_increment);
97     def("blocktimer_time",blocktimer_time);
98 jfenwick 2607 def("getVersion",escript::getSvnVersion,"This method will only report accurate version numbers for clean checkouts.");
99 ksteube 1561 def("printParallelThreadCounts",escript::printParallelThreadCnt);
100 jfenwick 2625 def("getMPISizeWorld",escript::getMPISizeWorld,"Return number of MPI processes in the job.");
101     def("getMPIRankWorld",escript::getMPIRankWorld,"Return the rank of this process in the MPI World.");
102     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 gross 2100 def("getMachinePrecision",escript::getMachinePrecision);
108     def("getMaxFloat",escript::getMaxFloat);
109 jfenwick 2644 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 jfenwick 2766 "That is, items in each column will be printed in the same order.\n"
118 jfenwick 3360 "So you can be sure that values in the same row correspond to the same input value.\n\n"
119 jfenwick 2644 "\n:param filename:\n:type filename: ``string``\n"
120 jfenwick 3360 ":param arg: dictionary of named `Data` objects. If one is called ``mask`` it must be scalar data.\n"
121     ":type arg: ``dict``\n"
122     ":param sep: separator for columns (defaults to ',')\n"
123     ":type sep: ``string``\n"
124     ":param csep: separator for fields within data object (defaults to \"_\")\n:type csep: ``string``\n"
125 jfenwick 2644 ":param append: If True, write to the end of ``filename``\n:type append: ``string``\n");
126 jfenwick 2635
127    
128 jgs 102 //
129     // Interface for AbstractDomain
130     //
131 jfenwick 2061 class_<escript::AbstractDomain, escript::Domain_ptr>("Domain","Base class for all domains.",no_init)
132 jfenwick 2625 .def("getStatus",&escript::AbstractDomain::getStatus,"The status of a domain changes whenever the domain is modified\n\n:rtype: int")
133     .def("setTagMap",&escript::AbstractDomain::setTagMap,args("name","tag"),
134     "Give a tag number a name.\n\n:param name: Name for the tag\n:type name: ``string``\n"
135     ":param tag: numeric id\n:type tag: ``int``\n:note: Tag names must be unique within a domain")
136     .def("getTag",&escript::AbstractDomain::getTag,args("name"),":return: tag id for "
137     "``name``\n:rtype: ``string``")
138     .def("isValidTagName",&escript::AbstractDomain::isValidTagName,args("name"),
139     ":return: True is ``name`` corresponds to a tag\n:rtype: ``bool``")
140     .def("showTagNames",&escript::AbstractDomain::showTagNames,":return: A space separated list of tag names\n:rtype: ``string``")
141     .def("getX",&escript::AbstractDomain::getX,":rtype: `Data`\n:return: Locations in the"
142     "`Domain`. FunctionSpace is chosen appropriately")
143     .def("getDim",&escript::AbstractDomain::getDim,":rtype: `int`\n:return: Spatial dimension of the `Domain`")
144     .def("getNormal",&escript::AbstractDomain::getNormal,":rtype: `escript`\n:return: Boundary normals")
145     .def("getSize",&escript::AbstractDomain::getSize,":return: the local size of samples. The function space is chosen appropriately\n:rtype: `Data`")
146     .def("saveVTK",&escript::AbstractDomain::saveVTK,args("filename","arg", "metadata"
147     , "metadata_schema"),
148     ":param filename: \n:type filename: ``string``\n:param arg: items to be added"
149     "\n:type arg: ``dict``\n:param metadata: string representing some meta data to be added\n:type metadata: ``string``"
150     "\n:param metadata_schema: schema type for metadata\n:type metadata_schema: ``string``")
151     .def("dump",&escript::AbstractDomain::dump,args("filename"),"Dumps the domain to a file"
152     ":param filename:\n:type filename: string")
153     .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``"
154     "\n:param arg:\n:type arg: `dict`")
155     .def("getMPISize",&escript::AbstractDomain::getMPISize,":return: the number of processes used for this `Domain`\n:rtype: ``int``")
156     .def("getMPIRank",&escript::AbstractDomain::getMPIRank,":return: the rank of this process\n:rtype: ``int``")
157     .def("MPIBarrier",&escript::AbstractDomain::MPIBarrier,"Wait until all processes have reached this point")
158     .def("onMasterProcessor",&escript::AbstractDomain::onMasterProcessor,":return: True if this code is executing on the master process\n:rtype: `bool`")
159 jfenwick 3259 .def("supportsContactElements", &escript::AbstractDomain::supportsContactElements,"Does this domain support contact elements.")
160 jgs 102 .def(self == self)
161     .def(self != self);
162    
163     //
164     // Interface for AbstractContinuousDomain
165     //
166 jfenwick 2061 class_<escript::AbstractContinuousDomain, bases<escript::AbstractDomain> >("ContinuousDomain","Class representing continuous domains",no_init)
167 jfenwick 2625 .def("getSystemMatrixTypeId",&escript::AbstractContinuousDomain::getSystemMatrixTypeId,
168     args("solver", "preconditioner", "package", "symmetry"),
169     ":return: the identifier of the matrix type to be used for the global stiffness matrix "
170     "when a particular solver package and symmetric matrix is used.\n"
171     ":rtype: int")
172     .def("getTransportTypeId",&escript::AbstractContinuousDomain::getTransportTypeId,
173 jfenwick 3259 args("solver", "preconditioner", "package", "symmetry"))
174 jgs 102
175 jfenwick 3259 .def("addPDEToSystem",&escript::AbstractContinuousDomain::addPDEToSystem,
176 gross 3522 args("mat", "rhs","A", "B", "C", "D", "X", "Y", "d", "y", "d_contact", "y_contact", "d_dirac", "y_dirac"),
177 jfenwick 3259 "adds a PDE onto the stiffness matrix mat and a rhs\n\n"
178     ":param mat:\n:type mat: `OperatorAdapter`\n:param rhs:\n:type rhs: `Data`\n"
179     ":param A:\n:type A: `Data`\n"
180     ":param B:\n:type B: `Data`\n"
181     ":param C:\n:type C: `Data`\n"
182     ":param D:\n:type D: `Data`\n"
183     ":param X:\n:type X: `Data`\n"
184     ":param Y:\n:type Y: `Data`\n"
185     ":param d:\n:type d: `Data`\n"
186     ":param d_contact:\n:type d_contact: `Data`\n"
187     ":param y_contact:\n:type y_contact: `Data`\n"
188 gross 3522 ":param d_dirac:\n:type d_dirac: `Data`\n"
189     ":param y_dirac:\n:type y_dirac: `Data`\n"
190 jfenwick 3259 )
191     .def("addPDEToRHS",&escript::AbstractContinuousDomain::addPDEToRHS,
192 gross 3522 args("rhs", "X", "Y", "y", "y_contact", "d_dirac"),
193 jfenwick 3259 "adds a PDE onto the stiffness matrix mat and a rhs\n\n"
194     ":param rhs:\n:type rhs: `Data`\n"
195     ":param X:\n:type X: `Data`\n"
196     ":param Y:\n:type Y: `Data`\n"
197     ":param y:\n:type y: `Data`\n"
198     ":param y_contact:\n:type y_contact: `Data`"
199 gross 3522 ":param y_dirac:\n:type y_dirac: `Data`"
200 jfenwick 3259 )
201     .def("addPDEToTransportProblem",&escript::AbstractContinuousDomain::addPDEToTransportProblem,
202 gross 3522 args( "tp", "source", "M", "A", "B", "C", "D", "X", "Y", "d", "y", "d_contact", "y_contact", "d_dirac", "y_dirac"),
203 jfenwick 3259 ":param tp:\n:type tp: `TransportProblemAdapter`\n"
204     ":param source:\n:type source: `Data`\n"
205     ":param M:\n:type M: `Data`\n"
206     ":param A:\n:type A: `Data`\n"
207     ":param B:\n:type B: `Data`\n"
208     ":param C:\n:type C: `Data`\n"
209     ":param D:\n:type D: `Data`\n"
210     ":param X:\n:type X: `Data`\n"
211     ":param Y:\n:type Y: `Data`\n"
212     ":param d:\n:type d: `Data`\n"
213     ":param y:\n:type y: `Data`\n"
214     ":param d_contact:\n:type d_contact: `Data`\n"
215     ":param y_contact:\n:type y_contact: `Data`\n"
216 gross 3522 ":param d_dirac:\n:type d_dirac: `Data`\n"
217     ":param y_dirac:\n:type y_dirac: `Data`\n"
218 jfenwick 3259 )
219     .def("newOperator",&escript::AbstractContinuousDomain::newSystemMatrix,
220     args("row_blocksize", "row_functionspace", "column_blocksize", "column_functionspace", "type"),
221     "creates a SystemMatrixAdapter stiffness matrix and initializes it with zeros\n\n"
222     ":param row_blocksize:\n:type row_blocksize: ``int``\n"
223     ":param row_functionspace:\n:type row_functionspace: `FunctionSpace`\n"
224     ":param column_blocksize:\n:type column_blocksize: ``int``\n"
225     ":param column_functionspace:\n:type column_functionspace: `FunctionSpace`\n"
226     ":param type:\n:type type: ``int``\n"
227     )
228     .def("newTransportProblem",&escript::AbstractContinuousDomain::newTransportProblem,
229     args("theta", "blocksize", "functionspace", "type"),
230     "creates a TransportProblemAdapter\n\n"
231     ":param theta:\n:type theta: ``float``\n"
232     ":param blocksize:\n:type blocksize: ``int``\n"
233     ":param functionspace:\n:type functionspace: `FunctionSpace`\n"
234     ":param type:\n:type type: ``int``\n"
235     )
236     .def("getDataShape",&escript::AbstractContinuousDomain::getDataShape, args("functionSpaceCode"),
237     ":return: a pair (dps, ns) where dps=the number of data points per sample, and ns=the number of samples\n:rtype: ``tuple``")
238     .def("print_mesh_info",&escript::AbstractContinuousDomain::Print_Mesh_Info,(arg("full")=false),
239     ":param full:\n:type full: ``bool``")
240     .def("getDescription",&escript::AbstractContinuousDomain::getDescription,
241     ":return: a description for this domain\n:rtype: ``string``")
242     .def("setX",&escript::AbstractContinuousDomain::setNewX,
243     args("arg"), "assigns new location to the domain\n\n:param arg:\n:type arg: `Data`")
244     .def("getNumDataPointsGlobal",&escript::AbstractContinuousDomain::getNumDataPointsGlobal,
245     ":return: the number of data points summed across all MPI processes\n"
246     ":rtype: ``int``");
247 jfenwick 2482
248 jfenwick 3259
249    
250    
251 jgs 102 //
252 jfenwick 2482 // Interface for TestDomain
253     //
254     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>());
255    
256     // This is the only python visible way to get a TestDomain
257 jfenwick 2625 def("getTestDomainFunctionSpace",&escript::getTestDomainFunctionSpace, args("dpps",
258     "samples"),
259     "For testing only. May be removed without notice.");
260 jfenwick 2482
261     //
262 jgs 102 // Interface for FunctionSpace
263     //
264 jfenwick 2625 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
265     fs_definer.def("getDim",&escript::FunctionSpace::getDim,":return: the spatial dimension of the underlying domain.\n:rtype: int");
266 jfenwick 1872 // fs_definer.def("getDomain",&escript::FunctionSpace::getDomain,
267     // return_internal_reference<>());
268 jfenwick 2625 fs_definer.def("getDomain",&escript::FunctionSpace::getDomainPython,":return: the underlying `Domain` for this FunctionSpace.\n:rtype: `Domain`");
269     fs_definer.def("getX",&escript::FunctionSpace::getX,"\n:return: a function whose values are its input coordinates. ie an identity function.\n:rtype: `Data`");
270     fs_definer.def("getNormal",&escript::FunctionSpace::getNormal,":return: the surface normal field.\n\n:rtype: `Data`");
271     fs_definer.def("getSize",&escript::FunctionSpace::getSize,":return: sample size\n:rtype: `Data`");
272     fs_definer.def("setTags",&escript::FunctionSpace::setTags,args("newtag","mask"),
273 jfenwick 3360 "Set tags according to a mask\n\n:param newtag: tag number to set\n:type newtag: string, 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`");
274     fs_definer.def("setTags",&escript::FunctionSpace::setTagsByString,args("newtag","mask"));
275 trankine 1426 fs_definer.def("getTagFromDataPointNo",
276 jfenwick 2625 &escript::FunctionSpace::getTagFromDataPointNo,":return: the tag associated with the given sample number.\n:rtype: int");
277     fs_definer.def("getReferenceIDFromDataPointNo", &escript::FunctionSpace::getReferenceIDFromDataPointNo,args("dataPointNo"),":return: the reference number associated with ``dataPointNo``\n:rtype: int ");
278     fs_definer.def("getListOfTags",&escript::FunctionSpace::getListOfTags,":return: a list of the tags used in this function space\n:rtype: ``list``");
279 gross 2856 fs_definer.def("getApproximationOrder", &escript::FunctionSpace::getApproximationOrder,":return: the approximation order refering to the maximum degree of a polynomial which can be represenred exactly in interplation and/or integration.\n:rtype: ``int``");
280 phornby 1628 fs_definer.def("__str__", &escript::FunctionSpace::toString);
281 trankine 1426 fs_definer.def(self == self);
282     fs_definer.def(self != self);
283 jgs 102 //
284     // Interface for Data
285     //
286 jfenwick 3504 class_<escript::Data>("Data"/*,shared_ptr<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<>() )
287 jgs 102 // various constructors for Data objects
288     .def(init<const object&, optional<const escript::FunctionSpace&, bool> >(args("value","what","expand")))
289     .def(init<const double, const tuple&, optional<const escript::FunctionSpace&, bool> >(args("value","shape","what","expand")))
290     .def(init<const escript::Data&, const escript::FunctionSpace&>(args("value","what")))
291     .def(init<const escript::Data&>())
292     // Note for Lutz, Need to specify the call policy in order to return a
293     // reference. In this case return_internal_reference.
294 ksteube 1312 .def("__str__",&escript::Data::toString)
295 jfenwick 2625 .def("getDomain",&escript::Data::getDomainPython,":rtype: `Domain`")
296     .def("getFunctionSpace",&escript::Data::getFunctionSpace,return_value_policy<copy_const_reference>(),":rtype: `FunctionSpace`")
297     .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.")
298     .def("isProtected",&escript::Data::isProtected,"Can this instance be modified.\n:rtype: ``bool``")
299     .def("setProtection",&escript::Data::setProtection,"Disallow modifications to this data object\n\n:note: This method does not allow you to undo protection.")
300     .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``")
301     .def("getRank",&escript::Data::getDataPointRank,":return: the number of indicies required to address a component of a datapoints\n:rtype: positive ``int``")
302     .def("dump",&escript::Data::dump,args("fileName"),"Save the data as a netCDF file\n\n:param fileName: \n:type fileName: ``string``")
303     .def("toListOfTuples",&escript::Data::toListOfTuples, (arg("scalarastuple")=false),
304     "Return the datapoints of this object in a list. Each datapoint is stored as a tuple.\n\n"
305     ":param scalarastuple: if True, scalar data will be wrapped as a tuple."
306     " True => [(0), (1), (2)]; False => [0, 1, 2]")
307     .def("copyWithMask",&escript::Data::copyWithMask,args("other","mask"),
308     "Selectively copy values from ``other`` `Data`."
309     "Datapoints which correspond to postive values in ``mask`` will be copied from ``other``\n"
310     "\n:param other: source of values\n"
311     ":type other: `Data`\n:param mask:\n:type mask: Scalar `Data`")
312     .def("setTaggedValue",&escript::Data::setTaggedValue,args("tagKey","value"),
313     "Set the value of tagged Data.\n\n:param tagKey: tag to update\n:type tagKey: ``int``\n")
314     .def("setTaggedValue",&escript::Data::setTaggedValueByName,args("name","value"),":param name: tag to update\n:type name: ``string``\n"
315     ":param value: value to set tagged data to\n:type value: ``object`` which acts like an array, ``tuple`` or ``list``\n")
316     .def("getNumberOfDataPoints",&escript::Data::getNumDataPoints,":rtype: ``int``\n:return: Number of datapoints in the object")
317     .def("isExpanded",&escript::Data::isExpanded,":rtype: ``bool``\n:return: True if this ``Data`` is expanded.")
318     .def("isTagged",&escript::Data::isTagged,":rtype: ``bool``\n:return: True if this ``Data`` is expanded.")
319     .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.")
320     .def("isLazy",&escript::Data::isLazy,":rtype: ``bool``\n:return: True if this ``Data`` is lazy.")
321     .def("isReady",&escript::Data::isReady,":rtype: ``bool``\n:return: True if this ``Data`` is not lazy.")
322     .def("expand",&escript::Data::expand,"Convert the data to expanded representation if it is not expanded already.")
323     .def("tag",&escript::Data::tag,"Convert data to tagged representation if it is not already tagged or expanded")
324     .def("resolve",&escript::Data::resolve,"Convert the data to non-lazy representation.")
325     .def("copy",&escript::Data::copy,args("other"),"Make this object a copy of ``other``\n"
326     "\n:note: The two objects will act independently from now on. That is, changing ``other`` "
327     "after this call will not change this object and vice versa.")
328     .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.")
329     .def("delay",&escript::Data::delay,"Convert this object into lazy representation")
330     .def("setValueOfDataPoint",&escript::Data::setValueOfDataPointToPyObject,args("dataPointNo","value"))
331 gross 1034 .def("setValueOfDataPoint",&escript::Data::setValueOfDataPointToArray)
332 jfenwick 2625 .def("setValueOfDataPoint",&escript::Data::setValueOfDataPoint,"\nModify the value of a single datapoint.\n\n:param dataPointNo:\n"
333     ":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.")
334     .def("getTupleForDataPoint",&escript::Data::getValueOfDataPointAsTuple,args("dataPointNo"),
335     ":return: Value of the specified datapoint\n:rtype: ``tuple``\n:param dataPointNo: datapoint to access\n:type dataPointNo: ``int``")
336     .def("getTupleForGlobalDataPoint",&escript::Data::getValueOfGlobalDataPointAsTuple,args("procNo","dataPointNo"),"Get a specific datapoint from a specific process\n\n"
337     ":rtype: ``tuple``\n:param procNo: MPI rank of the process\n:type procNo: positive ``int``"
338     "\n:param dataPointNo: datapoint to access\n:type dataPointNo: int")
339     .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.")
340     .def("interpolate",&escript::Data::interpolate,args("functionspace"),"Interpolate this object's values into a new functionspace.")
341 jfenwick 3368 .def("_interpolateTable3d", &escript::Data::interpolateFromTable3DP,
342     (arg("table"),arg("Amin"),arg("Astep"), arg("B"), arg("Bmin"), arg("Bstep"), arg("C"), arg("Cmin"), arg("Cstep"), arg("undef")=1.e50, arg("check_boundaries")=false, "For internal use only. Please use the interpolateTable function.")
343     )
344    
345 jfenwick 2646 .def("interpolateTable", &escript::Data::interpolateFromTable2DP,
346 gross 2668 (arg("table"),arg("Amin"),arg("Astep"), arg("B"), arg("Bmin"), arg("Bstep"), arg("undef")=1.e50, arg("check_boundaries")=false),
347 jfenwick 2628 "Creates a new Data object by interpolating using the source data (which are\n"
348 jfenwick 2646 "looked up in ``table``)\n``A`` must be the outer dimension on the table\n\n"
349 jfenwick 2628 ":param table: two dimensional collection of values\n"
350     ":param Amin: The base of locations in table\n:type Amin: float\n"
351     ":param Astep: size of gap between each item in the table\n:type Astep: float\n"
352     ":param undef: upper bound on interpolated values\n:type undef: float\n"
353     ":param B: Scalar representing the second coordinate to be mapped into the table\n"
354     ":type B: `Data`\n"
355     ":param Bmin: The base of locations in table for 2nd dimension\n:type Bmin: float\n"
356     ":param Bstep: size of gap between each item in the table for 2nd dimension\n:type Bstep: float\n"
357 jfenwick 2673 ":param check_boundaries: if true, then values outside the boundaries will be rejected. If false, then boundary values will be used.\n"
358 jfenwick 2628 ":raise RuntimeError(DataException): if the cordinates do not map into the table or if the interpolated value is above ``undef``"
359     "\n:rtype: `Data`"
360     )
361 jfenwick 2646 .def("interpolateTable", &escript::Data::interpolateFromTable1DP,
362 jfenwick 3360 (arg("table"),arg("Amin"),arg("Astep"), arg("undef")=1.e50, arg("check_boundaries")=false)/*,
363 jfenwick 2646 "Creates a new Data object by interpolating using the source data (which are\n"
364     "looked up in ``table``)\n\n"
365     ":param table: one dimensional collection of values\n"
366     ":param Amin: The base of locations in table\n:type Amin: float\n"
367     ":param Astep: size of gap between each item in the table\n:type Astep: float\n"
368     ":param undef: upper bound on interpolated values\n:type undef: float\n"
369 jfenwick 2673 ":param check_boundaries: if true, then values outside the boundaries will be rejected. If false, then boundary values will be used.\n"
370 jfenwick 2646 ":raise RuntimeError(DataException): if the cordinates do not map into the table or if the interpolated value is above ``undef``"
371     "\n:rtype: `Data`"
372 jfenwick 3360 */
373 jfenwick 2646 )
374 jfenwick 2628
375 jfenwick 2646
376 jfenwick 2770 .def("minGlobalDataPoint",&escript::Data::minGlobalDataPoint,"Please consider using getInfLocator() from pdetools instead.")
377     .def("maxGlobalDataPoint",&escript::Data::maxGlobalDataPoint, "Please consider using getSupLocator() from pdetools instead.")
378 jfenwick 2625 .def("saveDX",&escript::Data::saveDX,args("fileName"),"Save the object in DX format.\n\n"
379     ":param fileName: filename\n:type fileName: string")
380     .def("saveVTK",&escript::Data::saveVTK, args("fileName"),"Save the object in VTK format.\n\n"
381     ":param fileName: \n:type fileName: string")
382     .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")
383 gross 285 // Unary functions for Data
384     .def("_interpolate",&escript::Data::interpolate)
385     .def("_grad",&escript::Data::gradOn)
386     .def("_grad",&escript::Data::grad)
387     .def("_transpose",&escript::Data::transpose)
388     .def("_trace",&escript::Data::trace)
389     .def("_maxval",&escript::Data::maxval)
390     .def("_minval",&escript::Data::minval)
391 gross 698 .def("_wherePositive",&escript::Data::wherePositive)
392     .def("_whereNegative",&escript::Data::whereNegative)
393     .def("_whereNonNegative",&escript::Data::whereNonNegative)
394     .def("_whereNonPositive",&escript::Data::whereNonPositive)
395 jgs 571 .def("_whereZero",&escript::Data::whereZero,(arg("tol")=0.0))
396     .def("_whereNonZero",&escript::Data::whereNonZero,(arg("tol")=0.0))
397 ksteube 876 .def("_erf",&escript::Data::erf)
398 gross 285 .def("_sin",&escript::Data::sin)
399     .def("_cos",&escript::Data::cos)
400     .def("_tan",&escript::Data::tan)
401     .def("_asin",&escript::Data::asin)
402     .def("_acos",&escript::Data::acos)
403     .def("_atan",&escript::Data::atan)
404     .def("_sinh",&escript::Data::sinh)
405     .def("_cosh",&escript::Data::cosh)
406     .def("_tanh",&escript::Data::tanh)
407     .def("_asinh",&escript::Data::asinh)
408     .def("_acosh",&escript::Data::acosh)
409     .def("_atanh",&escript::Data::atanh)
410     .def("_exp",&escript::Data::exp)
411     .def("_sqrt",&escript::Data::sqrt)
412     .def("_log10",&escript::Data::log10)
413     .def("_log",&escript::Data::log)
414     .def("_sign",&escript::Data::sign)
415 ksteube 775 .def("_symmetric",&escript::Data::symmetric)
416     .def("_nonsymmetric",&escript::Data::nonsymmetric)
417 gross 800 .def("_trace",&escript::Data::trace)
418 gross 804 .def("_swap_axes",&escript::Data::swapaxes)
419 gross 576 .def("_eigenvalues",&escript::Data::eigenvalues)
420     .def("_eigenvalues_and_eigenvectors",&escript::Data::eigenvalues_and_eigenvectors,(arg("tol")=1.e-13))
421 gross 285 // functions returning a single real number:
422 jfenwick 2625 .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.")
423     .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.")
424     .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.")
425     .def("_integrateToTuple",&escript::Data::integrateToTuple,":return: Calculate the integral over the function space domain as a python tuple\n:rtype: tuple")
426 gross 285 // following implements the python abs operator
427 jfenwick 2625 .def("__abs__",&escript::Data::abs,":return: absolute value\n\n:rtype: `Data`")
428 jgs 102 // following implements the python "-" negation operator
429 jfenwick 2625 .def("__neg__",&escript::Data::neg, ":return: negation of the values in this object\n:rtype: `Data`")
430 jgs 102 // following implements the python "+" identity operator
431 jfenwick 2646 .def("__pos__",&escript::Data::pos, "\nThe unary + operator\n\n:rtype: `Data`")
432 caltinay 3470 // following three functions implement the python [] operator
433 jfenwick 2625 .def("__getitem__",&escript::Data::getItem,"Used by the python [] operator\n\n:rtype: `Data`")
434     .def("__setitem__",&escript::Data::setItemO,"Used by the python [] operator")
435     .def("__setitem__",&escript::Data::setItemD,"Used by the python [] operator")
436 caltinay 3470 // following three functions implement the python ** operator
437 jfenwick 2625 .def("__pow__",&escript::Data::powO,"Used by the python ** operator\n\n:rtype: `Data`")
438 jgs 102 .def("__pow__",&escript::Data::powD)
439 jfenwick 2625 .def("__rpow__",&escript::Data::rpowO,"\nUsed by the python ** operator\n\n:rtype: `Data`")
440 caltinay 3470 // following two functions implement the newer python / operator
441 caltinay 3514 .def("__truediv__",&escript::Data::truedivO)
442 caltinay 3470 .def("__truediv__",&escript::Data::truedivD)
443 caltinay 3514 .def("__rtruediv__",&escript::Data::rtruedivO)
444 jgs 102 // NOTE:: The order of these declarations is important. Anything
445     // declared before the generic declaration isn't found so the generic
446     // version will be called.
447 jfenwick 3504 // .def(self + other<object>())
448     // .def(other<object>() + self)
449     // .def(self + self)
450 gross 285 .def(self += other<object>())
451     .def(self += self)
452    
453 jfenwick 3504 // .def(self - other<object>())
454     // .def(other<object>() - self)
455     // .def(self - self)
456 gross 285 .def(self -= other<object>())
457     .def(self -= self)
458    
459 jfenwick 3504 // .def(self * other<object>())
460     // .def(other<object>() * self)
461     // .def(self * self)
462 gross 285 .def(self *= other<object>())
463     .def(self *= self)
464    
465 jfenwick 3504 // .def(self / other<object>())
466     // .def(other<object>() / self)
467     // .def(self / self)
468 gross 285 .def(self /= other<object>())
469     .def(self /= self)
470 jgs 102 // Need scope resolution due to a bug either in the compiler or
471     // the boost code. This calls operator << for Data.
472 jfenwick 2742 .def(self_ns::str(self))
473 jfenwick 3504 .def("_inverse", &escript::Data::matrixInverse, ":return: inverse of square matricies\n")
474     // .def("__add__", &escript::Data::addOperatorD)
475     .def("__add__", &escript::Data::__add__)
476     .def("__radd__", &escript::Data::__add__) // its the same coz + is commutative
477     .def("__sub__", &escript::Data::__sub__)
478     .def("__rsub__", &escript::Data::__rsub__)
479     .def("__mul__", &escript::Data::__mul__)
480     .def("__rmul__", &escript::Data::__mul__) // commutative
481     .def("__div__", &escript::Data::__div__)
482     .def("__rdiv__", &escript::Data::__rdiv__) // commutative
483    
484     ;
485 jgs 102
486     //
487     // Factory methods for function space
488     //
489 jfenwick 2625 def("ContinuousFunction",escript::continuousFunction,args("domain"),
490     ":return: a continuous FunctionSpace (overlapped node values)\n"
491     ":rtype: `FunctionSpace`");
492     def("ReducedContinuousFunction",escript::reducedContinuousFunction,args("domain"),
493     ":return: a continuous with reduced order FunctionSpace (overlapped node values on reduced element order)\n"
494     ":rtype: `FunctionSpace`");
495     def("Function",escript::function,args("domain"),":return: a function `FunctionSpace`\n"
496     ":rtype: `FunctionSpace`");
497     def("ReducedFunction",escript::reducedFunction, args("domain"),":return: a function FunctionSpace with reduced integration order\n:rtype: `FunctionSpace`");
498     def("FunctionOnBoundary",escript::functionOnBoundary, args("domain"), ":return: a function on boundary FunctionSpace\n:rtype: `FunctionSpace`");
499     def("ReducedFunctionOnBoundary",escript::reducedFunctionOnBoundary, args("domain"),
500     ":return: a function on boundary FunctionSpace with reduced integration order\n"
501     ":rtype: `FunctionSpace`");
502     def("FunctionOnContactZero",escript::functionOnContactZero, args("domain"), ":return: Return a FunctionSpace on left side of contact\n:rtype: `FunctionSpace`");
503     def("ReducedFunctionOnContactZero",escript::reducedFunctionOnContactZero, args("domain"),
504     ":return: a FunctionSpace on left side of contact with reduced integration order\n:rtype: `FunctionSpace`");
505     def("FunctionOnContactOne",escript::functionOnContactOne, args("domain"), ":return: Return a FunctionSpace on right side of contact\n:rtype: `FunctionSpace`");
506     def("ReducedFunctionOnContactOne",escript::reducedFunctionOnContactOne, args("domain"),
507     ":return: Return a FunctionSpace on right side of contact with reduced integration order\n"
508     ":rtype: `FunctionSpace`");
509     def("Solution",escript::solution, args("domain"), ":rtype: `FunctionSpace`");
510     def("ReducedSolution",escript::reducedSolution, args("domain"), ":rtype: `FunctionSpace`");
511 gross 3515 def("DiracDeltaFunctions",escript::diracDeltaFunctions, args("domain"), ":rtype: `FunctionSpace`");
512 jgs 102
513 jfenwick 2635
514    
515    
516    
517 jgs 102 //
518     // Factory methods for Data
519     //
520 jfenwick 2625 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`");
521     def("loadIsConfigured",escript::loadConfigured,":return: True if the load function is configured.");
522 jgs 102 def("Scalar",escript::Scalar,
523     (arg("value")=0.0,
524     arg("what")=escript::FunctionSpace(),
525 jfenwick 2625 arg("expanded")=false),
526     "Construct a Data object containing scalar data-points.\n\n:param value: scalar value for all points\n"
527     "\n:rtype: `Data`\n:type value: float\n:param what: FunctionSpace for Data\n:type what: `FunctionSpace`\n"
528     ":param expanded: If True, a value is stored for each point. If False, more efficient representations may be used\n"
529     ":type expanded: ``bool``");
530 jgs 102 def("Vector",escript::Vector,
531     (arg("value")=0.0,
532     arg("what")=escript::FunctionSpace(),
533 jfenwick 2625 arg("expanded")=false),
534     "Construct a Data object containing rank1 data-points.\n\n:param value: scalar value for all points\n"
535     "\n:rtype: `Data`\n:type value: float\n:param what: FunctionSpace for Data\n:type what: `FunctionSpace`\n"
536     ":param expanded: If True, a value is stored for each point. If False, more efficient representations may be used\n"
537     ":type expanded: ``bool``");
538 jfenwick 2838 def("Vector", escript::VectorFromObj,
539     (arg("value"),
540     arg("what")=escript::FunctionSpace(),
541     arg("expanded")=false));
542 jgs 102 def("Tensor",escript::Tensor,
543     (arg("value")=0.0,
544     arg("what")=escript::FunctionSpace(),
545 jfenwick 2625 arg("expanded")=false),
546     "Construct a Data object containing rank2 data-points.\n\n:param value: scalar value for all points\n"
547     "\n:rtype: `Data`\n:type value: float\n:param what: FunctionSpace for Data\n:type what: `FunctionSpace`\n"
548     ":param expanded: If True, a value is stored for each point. If False, more efficient representations may be used\n"
549     ":type expanded: ``bool``");
550 jfenwick 2838 def("Tensor", escript::TensorFromObj,
551     (arg("value"),
552     arg("what")=escript::FunctionSpace(),
553     arg("expanded")=false));
554 jgs 102 def("Tensor3",escript::Tensor3,
555     (arg("value")=0.0,
556     arg("what")=escript::FunctionSpace(),
557 jfenwick 2625 arg("expanded")=false),
558     "Construct a Data object containing rank3 data-points.\n\n:param value: scalar value for all points\n"
559     "\n:rtype: `Data`\n:type value: float\n:param what: FunctionSpace for Data\n:type what: `FunctionSpace`\n"
560     ":param expanded: If True, a value is stored for each point. If False, more efficient representations may be used\n"
561     ":type expanded: ``bool``"
562     );
563 jfenwick 2838 def("Tensor3", escript::Tensor3FromObj,
564     (arg("value"),
565     arg("what")=escript::FunctionSpace(),
566     arg("expanded")=false));
567 jgs 102 def("Tensor4",escript::Tensor4,
568     (arg("value")=0.0,
569     arg("what")=escript::FunctionSpace(),
570 jfenwick 2625 arg("expanded")=false),
571     "Construct a Data object containing rank4 data-points.\n\n:param value: scalar value for all points\n"
572     "\n:rtype: `Data`\n:type value: float\n:param what: FunctionSpace for Data\n:type what: `FunctionSpace`\n"
573     ":param expanded: If True, a value is stored for each point. If False, more efficient representations may be used\n"
574     ":type expanded: ``bool``"
575     );
576 jfenwick 2838 def("Tensor4", escript::Tensor4FromObj,
577     (arg("value"),
578     arg("what")=escript::FunctionSpace(),
579     arg("expanded")=false));
580 jgs 102
581 jfenwick 3390
582 jfenwick 3506 def("RandomData", escript::randomData, (arg("shape"), arg("fs"), arg("seed")=0),
583 jfenwick 3390 "Creates a new expanded Data object containing (not very) random values.\n\n"
584     ":param shape: datapoint shape\n:type shape: tuple\n"
585     ":param fs: function space for data object.\n:type fs: `FunctionSpace`\n"
586 jfenwick 3506 ":param seed: seed for random number generator.\n:type seed: long\n");
587 jfenwick 3390
588 jgs 102 //
589 ksteube 813 // Binary operators
590     //
591     def("C_GeneralTensorProduct",escript::C_GeneralTensorProduct,
592 jfenwick 2626 (arg("arg0"),
593     arg("arg1"),
594 ksteube 813 arg("axis_offset")=0,
595 jfenwick 2625 arg("transpose")=0),
596     "Compute a tensor product of two Data objects.\n\n:rtype: `Data`\n:param arg0:\n"
597     ":param arg1:\n:param axis_offset:\n:type axis_offset: ``int``\n"
598     ":param transpose: 0: transpose neither, 1: transpose arg0, 2: transpose arg1\n"
599     ":type transpose: int");
600 ksteube 813
601     //
602 jgs 102 // Interface for AbstractSystemMatrix
603     //
604 jfenwick 3259 class_<escript::AbstractSystemMatrix,escript::ASM_ptr>("Operator","",init<>()) // Doco goes in the empty string param
605 jfenwick 2625 .def("isEmpty",&escript::AbstractSystemMatrix::isEmpty,":rtype: ``bool``\n"
606     ":return: True if matrix is empty")
607     .def("solve",&escript::AbstractSystemMatrix::solve, args("in","options"),
608     ":return: the solution *u* of the linear system *this*u=in*\n\n:param in:\n:type in: `Data`")
609     .def("of",&escript::AbstractSystemMatrix::vectorMultiply,args("right"),
610     "matrix*vector multiplication")
611     .def("saveMM",&escript::AbstractSystemMatrix::saveMM, args("fileName"),
612     "writes the matrix to a file using the Matrix Market file format")
613     .def("saveHB",&escript::AbstractSystemMatrix::saveHB, args("filename"),
614     "writes the matrix to a file using the Harwell-Boeing file format")
615     .def("resetValues",&escript::AbstractSystemMatrix::resetValues, "resets the matrix entries")
616 jgs 102 .def(self*other<escript::Data>());
617 gross 1364 //
618     // Interface for AbstractTransportProblem
619     //
620 jfenwick 3259 class_<escript::AbstractTransportProblem, escript::ATP_ptr>("TransportProblem","",init<>()) // Doco goes in the empty string param
621 jfenwick 2625 .def("isEmpty",&escript::AbstractTransportProblem::isEmpty,":rtype: ``int``")
622 gross 2987 .def("solve",&escript::AbstractTransportProblem::solve, args("u0","source","dt", "options"),
623     "returns the solution *u* for a time step *dt>0* with initial value u0\n\n:rtype: `Data`\n"
624 jfenwick 2625 ":param source:\n:type source: `Data`")
625     .def("insertConstraint",&escript::AbstractTransportProblem::insertConstraint,
626     args("source", "q", "r","factor"),
627     "inserts constraint *u_{,t}=r* where *q>0* into the problem using a weighting factor")
628     .def("reset",&escript::AbstractTransportProblem::resetTransport,
629     "resets the transport operator typically as they have been updated.")
630 gross 1841 .def("resetValues",&escript::AbstractTransportProblem::resetTransport)
631 gross 1859 .def("getSafeTimeStepSize",&escript::AbstractTransportProblem::getSafeTimeStepSize)
632     .def("getUnlimitedTimeStepSize",&escript::AbstractTransportProblem::getUnlimitedTimeStepSize);
633 jgs 102
634 jfenwick 1897 // Functions to modify global parameters
635     def("setEscriptParamInt",escript::setEscriptParamInt,
636 jfenwick 2625 (arg("name"), arg("value")=0), "Modify the value of an escript tuning parameter\n\n"
637     ":param name:\n:type name: ``string``\n:param value:\n:type value: ``int``");
638 jfenwick 1897 def("getEscriptParamInt",escript::getEscriptParamInt,
639 jfenwick 2625 (arg("name"),arg("sentinel")=0), "Read the value of an escript tuning paramter\n\n"
640     ":param name: parameter to lookup\n:type name: ``string``\n:param sentinel: Value to be returned if ``name`` is not a known parameter\n"
641     ":type sentinel: ``int``");
642     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.");
643 jfenwick 1897
644 jfenwick 2799
645     def("resolveGroup", escript::resolveGroup);
646 jfenwick 2827
647     #ifdef IKNOWWHATIMDOING
648    
649     def("applyBinaryCFunction", escript::applyBinaryCFunction, (arg("function"), arg("outshape"),
650     arg("in1"),
651     arg("in2"))
652     );
653     #endif
654    
655 jfenwick 3059 def("_condEval", escript::condEval, (arg("mask"), arg("trueval"), arg("falseval")));
656 jfenwick 3031
657 jgs 102 //
658     // Register esysExceptionTranslator
659     //
660     register_exception_translator<esysUtils::EsysException>(&esysUtils::esysExceptionTranslator);
661     }

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.26