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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2881 - (hide annotations)
Thu Jan 28 02:03:15 2010 UTC (9 years, 8 months ago) by jfenwick
File size: 33610 byte(s)
Don't panic.
Updating copyright stamps

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 ksteube 1800 #include "paso/Paso_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     * - \ref finley
56     *
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     "So you can be sure that values in the same row correspond to the same input value.\n"
119 jfenwick 2644 "\n:param filename:\n:type filename: ``string``\n"
120     ":param arg: dictionary of named `Data` objects. If one is called ``mask`` it must be scalar data."
121     "\n:type arg: ``dict``\n"
122     ":param sep:separator for columns (defaults to \", \"\n:type sep:``string``\n"
123     ":param csep:separator for fields within data object (defaults to \"_\"\n:type csep:``string``\n"
124     ":param append: If True, write to the end of ``filename``\n:type append: ``string``\n");
125 jfenwick 2635
126    
127 jgs 102 //
128     // Interface for AbstractDomain
129     //
130 jfenwick 2061 class_<escript::AbstractDomain, escript::Domain_ptr>("Domain","Base class for all domains.",no_init)
131 jfenwick 2625 .def("getStatus",&escript::AbstractDomain::getStatus,"The status of a domain changes whenever the domain is modified\n\n:rtype: int")
132     .def("setTagMap",&escript::AbstractDomain::setTagMap,args("name","tag"),
133     "Give a tag number a name.\n\n:param name: Name for the tag\n:type name: ``string``\n"
134     ":param tag: numeric id\n:type tag: ``int``\n:note: Tag names must be unique within a domain")
135     .def("getTag",&escript::AbstractDomain::getTag,args("name"),":return: tag id for "
136     "``name``\n:rtype: ``string``")
137     .def("isValidTagName",&escript::AbstractDomain::isValidTagName,args("name"),
138     ":return: True is ``name`` corresponds to a tag\n:rtype: ``bool``")
139     .def("showTagNames",&escript::AbstractDomain::showTagNames,":return: A space separated list of tag names\n:rtype: ``string``")
140     .def("getX",&escript::AbstractDomain::getX,":rtype: `Data`\n:return: Locations in the"
141     "`Domain`. FunctionSpace is chosen appropriately")
142     .def("getDim",&escript::AbstractDomain::getDim,":rtype: `int`\n:return: Spatial dimension of the `Domain`")
143     .def("getNormal",&escript::AbstractDomain::getNormal,":rtype: `escript`\n:return: Boundary normals")
144     .def("getSize",&escript::AbstractDomain::getSize,":return: the local size of samples. The function space is chosen appropriately\n:rtype: `Data`")
145     .def("saveVTK",&escript::AbstractDomain::saveVTK,args("filename","arg", "metadata"
146     , "metadata_schema"),
147     ":param filename: \n:type filename: ``string``\n:param arg: items to be added"
148     "\n:type arg: ``dict``\n:param metadata: string representing some meta data to be added\n:type metadata: ``string``"
149     "\n:param metadata_schema: schema type for metadata\n:type metadata_schema: ``string``")
150     .def("dump",&escript::AbstractDomain::dump,args("filename"),"Dumps the domain to a file"
151     ":param filename:\n:type filename: string")
152     .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``"
153     "\n:param arg:\n:type arg: `dict`")
154     .def("getMPISize",&escript::AbstractDomain::getMPISize,":return: the number of processes used for this `Domain`\n:rtype: ``int``")
155     .def("getMPIRank",&escript::AbstractDomain::getMPIRank,":return: the rank of this process\n:rtype: ``int``")
156     .def("MPIBarrier",&escript::AbstractDomain::MPIBarrier,"Wait until all processes have reached this point")
157     .def("onMasterProcessor",&escript::AbstractDomain::onMasterProcessor,":return: True if this code is executing on the master process\n:rtype: `bool`")
158 ksteube 1312
159 jgs 102 .def(self == self)
160     .def(self != self);
161    
162     //
163     // Interface for AbstractContinuousDomain
164     //
165 jfenwick 2061 class_<escript::AbstractContinuousDomain, bases<escript::AbstractDomain> >("ContinuousDomain","Class representing continuous domains",no_init)
166 jfenwick 2625 .def("getSystemMatrixTypeId",&escript::AbstractContinuousDomain::getSystemMatrixTypeId,
167     args("solver", "preconditioner", "package", "symmetry"),
168     ":return: the identifier of the matrix type to be used for the global stiffness matrix "
169     "when a particular solver package and symmetric matrix is used.\n"
170     ":rtype: int")
171     .def("getTransportTypeId",&escript::AbstractContinuousDomain::getTransportTypeId,
172     args("solver", "preconditioner", "package", "symmetry"));
173 jgs 102
174 jfenwick 2482
175 jgs 102 //
176 jfenwick 2482 // Interface for TestDomain
177     //
178     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>());
179    
180     // This is the only python visible way to get a TestDomain
181 jfenwick 2625 def("getTestDomainFunctionSpace",&escript::getTestDomainFunctionSpace, args("dpps",
182     "samples"),
183     "For testing only. May be removed without notice.");
184 jfenwick 2482
185     //
186 jgs 102 // Interface for FunctionSpace
187     //
188 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
189     fs_definer.def("getDim",&escript::FunctionSpace::getDim,":return: the spatial dimension of the underlying domain.\n:rtype: int");
190 jfenwick 1872 // fs_definer.def("getDomain",&escript::FunctionSpace::getDomain,
191     // return_internal_reference<>());
192 jfenwick 2625 fs_definer.def("getDomain",&escript::FunctionSpace::getDomainPython,":return: the underlying `Domain` for this FunctionSpace.\n:rtype: `Domain`");
193     fs_definer.def("getX",&escript::FunctionSpace::getX,"\n:return: a function whose values are its input coordinates. ie an identity function.\n:rtype: `Data`");
194     fs_definer.def("getNormal",&escript::FunctionSpace::getNormal,":return: the surface normal field.\n\n:rtype: `Data`");
195     fs_definer.def("getSize",&escript::FunctionSpace::getSize,":return: sample size\n:rtype: `Data`");
196     fs_definer.def("setTags",&escript::FunctionSpace::setTags,args("newtag","mask"),
197     "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`");
198 jfenwick 2841 fs_definer.def("setTags",&escript::FunctionSpace::setTagsByString,args("newtag","mask"),
199     "Set tags according to a mask\n\n:param newtag: tag name to set\n:type newtag: string\n:param mask: Samples which correspond to positive values in the mask will be set to ``newtag``.\n:type mask: scalar `Data`");
200 trankine 1426 fs_definer.def("getTagFromDataPointNo",
201 jfenwick 2625 &escript::FunctionSpace::getTagFromDataPointNo,":return: the tag associated with the given sample number.\n:rtype: int");
202     fs_definer.def("getReferenceIDFromDataPointNo", &escript::FunctionSpace::getReferenceIDFromDataPointNo,args("dataPointNo"),":return: the reference number associated with ``dataPointNo``\n:rtype: int ");
203     fs_definer.def("getListOfTags",&escript::FunctionSpace::getListOfTags,":return: a list of the tags used in this function space\n:rtype: ``list``");
204 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``");
205 phornby 1628 fs_definer.def("__str__", &escript::FunctionSpace::toString);
206 trankine 1426 fs_definer.def(self == self);
207     fs_definer.def(self != self);
208 jgs 102 //
209     // Interface for Data
210     //
211 jfenwick 2061 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<>() )
212 jgs 102 // various constructors for Data objects
213     .def(init<const object&, optional<const escript::FunctionSpace&, bool> >(args("value","what","expand")))
214     .def(init<const double, const tuple&, optional<const escript::FunctionSpace&, bool> >(args("value","shape","what","expand")))
215     .def(init<const escript::Data&, const escript::FunctionSpace&>(args("value","what")))
216     .def(init<const escript::Data&>())
217     // Note for Lutz, Need to specify the call policy in order to return a
218     // reference. In this case return_internal_reference.
219 ksteube 1312 .def("__str__",&escript::Data::toString)
220 jfenwick 2625 .def("getDomain",&escript::Data::getDomainPython,":rtype: `Domain`")
221     .def("getFunctionSpace",&escript::Data::getFunctionSpace,return_value_policy<copy_const_reference>(),":rtype: `FunctionSpace`")
222     .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.")
223     .def("isProtected",&escript::Data::isProtected,"Can this instance be modified.\n:rtype: ``bool``")
224     .def("setProtection",&escript::Data::setProtection,"Disallow modifications to this data object\n\n:note: This method does not allow you to undo protection.")
225     .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``")
226     .def("getRank",&escript::Data::getDataPointRank,":return: the number of indicies required to address a component of a datapoints\n:rtype: positive ``int``")
227     .def("dump",&escript::Data::dump,args("fileName"),"Save the data as a netCDF file\n\n:param fileName: \n:type fileName: ``string``")
228     .def("toListOfTuples",&escript::Data::toListOfTuples, (arg("scalarastuple")=false),
229     "Return the datapoints of this object in a list. Each datapoint is stored as a tuple.\n\n"
230     ":param scalarastuple: if True, scalar data will be wrapped as a tuple."
231     " True => [(0), (1), (2)]; False => [0, 1, 2]")
232     .def("copyWithMask",&escript::Data::copyWithMask,args("other","mask"),
233     "Selectively copy values from ``other`` `Data`."
234     "Datapoints which correspond to postive values in ``mask`` will be copied from ``other``\n"
235     "\n:param other: source of values\n"
236     ":type other: `Data`\n:param mask:\n:type mask: Scalar `Data`")
237     .def("setTaggedValue",&escript::Data::setTaggedValue,args("tagKey","value"),
238     "Set the value of tagged Data.\n\n:param tagKey: tag to update\n:type tagKey: ``int``\n")
239     .def("setTaggedValue",&escript::Data::setTaggedValueByName,args("name","value"),":param name: tag to update\n:type name: ``string``\n"
240     ":param value: value to set tagged data to\n:type value: ``object`` which acts like an array, ``tuple`` or ``list``\n")
241     .def("getNumberOfDataPoints",&escript::Data::getNumDataPoints,":rtype: ``int``\n:return: Number of datapoints in the object")
242     .def("isExpanded",&escript::Data::isExpanded,":rtype: ``bool``\n:return: True if this ``Data`` is expanded.")
243     .def("isTagged",&escript::Data::isTagged,":rtype: ``bool``\n:return: True if this ``Data`` is expanded.")
244     .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.")
245     .def("isLazy",&escript::Data::isLazy,":rtype: ``bool``\n:return: True if this ``Data`` is lazy.")
246     .def("isReady",&escript::Data::isReady,":rtype: ``bool``\n:return: True if this ``Data`` is not lazy.")
247     .def("expand",&escript::Data::expand,"Convert the data to expanded representation if it is not expanded already.")
248     .def("tag",&escript::Data::tag,"Convert data to tagged representation if it is not already tagged or expanded")
249     .def("resolve",&escript::Data::resolve,"Convert the data to non-lazy representation.")
250     .def("copy",&escript::Data::copy,args("other"),"Make this object a copy of ``other``\n"
251     "\n:note: The two objects will act independently from now on. That is, changing ``other`` "
252     "after this call will not change this object and vice versa.")
253     .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.")
254     .def("delay",&escript::Data::delay,"Convert this object into lazy representation")
255     .def("setValueOfDataPoint",&escript::Data::setValueOfDataPointToPyObject,args("dataPointNo","value"))
256 gross 1034 .def("setValueOfDataPoint",&escript::Data::setValueOfDataPointToArray)
257 jfenwick 2625 .def("setValueOfDataPoint",&escript::Data::setValueOfDataPoint,"\nModify the value of a single datapoint.\n\n:param dataPointNo:\n"
258     ":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.")
259     .def("getTupleForDataPoint",&escript::Data::getValueOfDataPointAsTuple,args("dataPointNo"),
260     ":return: Value of the specified datapoint\n:rtype: ``tuple``\n:param dataPointNo: datapoint to access\n:type dataPointNo: ``int``")
261     .def("getTupleForGlobalDataPoint",&escript::Data::getValueOfGlobalDataPointAsTuple,args("procNo","dataPointNo"),"Get a specific datapoint from a specific process\n\n"
262     ":rtype: ``tuple``\n:param procNo: MPI rank of the process\n:type procNo: positive ``int``"
263     "\n:param dataPointNo: datapoint to access\n:type dataPointNo: int")
264     .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.")
265     .def("interpolate",&escript::Data::interpolate,args("functionspace"),"Interpolate this object's values into a new functionspace.")
266 jfenwick 2646 .def("interpolateTable", &escript::Data::interpolateFromTable2DP,
267 gross 2668 (arg("table"),arg("Amin"),arg("Astep"), arg("B"), arg("Bmin"), arg("Bstep"), arg("undef")=1.e50, arg("check_boundaries")=false),
268 jfenwick 2628 "Creates a new Data object by interpolating using the source data (which are\n"
269 jfenwick 2646 "looked up in ``table``)\n``A`` must be the outer dimension on the table\n\n"
270 jfenwick 2628 ":param table: two dimensional collection of values\n"
271     ":param Amin: The base of locations in table\n:type Amin: float\n"
272     ":param Astep: size of gap between each item in the table\n:type Astep: float\n"
273     ":param undef: upper bound on interpolated values\n:type undef: float\n"
274     ":param B: Scalar representing the second coordinate to be mapped into the table\n"
275     ":type B: `Data`\n"
276     ":param Bmin: The base of locations in table for 2nd dimension\n:type Bmin: float\n"
277     ":param Bstep: size of gap between each item in the table for 2nd dimension\n:type Bstep: float\n"
278 jfenwick 2673 ":param check_boundaries: if true, then values outside the boundaries will be rejected. If false, then boundary values will be used.\n"
279 jfenwick 2628 ":raise RuntimeError(DataException): if the cordinates do not map into the table or if the interpolated value is above ``undef``"
280     "\n:rtype: `Data`"
281     )
282 jfenwick 2646 .def("interpolateTable", &escript::Data::interpolateFromTable1DP,
283 gross 2668 (arg("table"),arg("Amin"),arg("Astep"), arg("undef")=1.e50, arg("check_boundaries")=false),
284 jfenwick 2646 "Creates a new Data object by interpolating using the source data (which are\n"
285     "looked up in ``table``)\n\n"
286     ":param table: one dimensional collection of values\n"
287     ":param Amin: The base of locations in table\n:type Amin: float\n"
288     ":param Astep: size of gap between each item in the table\n:type Astep: float\n"
289     ":param undef: upper bound on interpolated values\n:type undef: float\n"
290 jfenwick 2673 ":param check_boundaries: if true, then values outside the boundaries will be rejected. If false, then boundary values will be used.\n"
291 jfenwick 2646 ":raise RuntimeError(DataException): if the cordinates do not map into the table or if the interpolated value is above ``undef``"
292     "\n:rtype: `Data`"
293     )
294 jfenwick 2628
295 jfenwick 2646
296 jfenwick 2770 .def("minGlobalDataPoint",&escript::Data::minGlobalDataPoint,"Please consider using getInfLocator() from pdetools instead.")
297     .def("maxGlobalDataPoint",&escript::Data::maxGlobalDataPoint, "Please consider using getSupLocator() from pdetools instead.")
298 jfenwick 2625 .def("saveDX",&escript::Data::saveDX,args("fileName"),"Save the object in DX format.\n\n"
299     ":param fileName: filename\n:type fileName: string")
300     .def("saveVTK",&escript::Data::saveVTK, args("fileName"),"Save the object in VTK format.\n\n"
301     ":param fileName: \n:type fileName: string")
302     .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")
303 gross 285 // Unary functions for Data
304     .def("_interpolate",&escript::Data::interpolate)
305     .def("_grad",&escript::Data::gradOn)
306     .def("_grad",&escript::Data::grad)
307     .def("_transpose",&escript::Data::transpose)
308     .def("_trace",&escript::Data::trace)
309     .def("_maxval",&escript::Data::maxval)
310     .def("_minval",&escript::Data::minval)
311 gross 698 .def("_wherePositive",&escript::Data::wherePositive)
312     .def("_whereNegative",&escript::Data::whereNegative)
313     .def("_whereNonNegative",&escript::Data::whereNonNegative)
314     .def("_whereNonPositive",&escript::Data::whereNonPositive)
315 jgs 571 .def("_whereZero",&escript::Data::whereZero,(arg("tol")=0.0))
316     .def("_whereNonZero",&escript::Data::whereNonZero,(arg("tol")=0.0))
317 ksteube 876 .def("_erf",&escript::Data::erf)
318 gross 285 .def("_sin",&escript::Data::sin)
319     .def("_cos",&escript::Data::cos)
320     .def("_tan",&escript::Data::tan)
321     .def("_asin",&escript::Data::asin)
322     .def("_acos",&escript::Data::acos)
323     .def("_atan",&escript::Data::atan)
324     .def("_sinh",&escript::Data::sinh)
325     .def("_cosh",&escript::Data::cosh)
326     .def("_tanh",&escript::Data::tanh)
327     .def("_asinh",&escript::Data::asinh)
328     .def("_acosh",&escript::Data::acosh)
329     .def("_atanh",&escript::Data::atanh)
330     .def("_exp",&escript::Data::exp)
331     .def("_sqrt",&escript::Data::sqrt)
332     .def("_log10",&escript::Data::log10)
333     .def("_log",&escript::Data::log)
334     .def("_sign",&escript::Data::sign)
335 ksteube 775 .def("_symmetric",&escript::Data::symmetric)
336     .def("_nonsymmetric",&escript::Data::nonsymmetric)
337 gross 800 .def("_trace",&escript::Data::trace)
338 gross 804 .def("_swap_axes",&escript::Data::swapaxes)
339 gross 576 .def("_eigenvalues",&escript::Data::eigenvalues)
340     .def("_eigenvalues_and_eigenvectors",&escript::Data::eigenvalues_and_eigenvectors,(arg("tol")=1.e-13))
341 gross 285 // functions returning a single real number:
342 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.")
343     .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.")
344     .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.")
345     .def("_integrateToTuple",&escript::Data::integrateToTuple,":return: Calculate the integral over the function space domain as a python tuple\n:rtype: tuple")
346 gross 285 // following implements the python abs operator
347 jfenwick 2625 .def("__abs__",&escript::Data::abs,":return: absolute value\n\n:rtype: `Data`")
348 jgs 102 // following implements the python "-" negation operator
349 jfenwick 2625 .def("__neg__",&escript::Data::neg, ":return: negation of the values in this object\n:rtype: `Data`")
350 jgs 102 // following implements the python "+" identity operator
351 jfenwick 2646 .def("__pos__",&escript::Data::pos, "\nThe unary + operator\n\n:rtype: `Data`")
352 jgs 102 // following two functions implement the python [] operator
353 jfenwick 2625 .def("__getitem__",&escript::Data::getItem,"Used by the python [] operator\n\n:rtype: `Data`")
354     .def("__setitem__",&escript::Data::setItemO,"Used by the python [] operator")
355     .def("__setitem__",&escript::Data::setItemD,"Used by the python [] operator")
356 jgs 102 // following two functions implement the python ** operator
357 jfenwick 2625 .def("__pow__",&escript::Data::powO,"Used by the python ** operator\n\n:rtype: `Data`")
358 jgs 102 .def("__pow__",&escript::Data::powD)
359 jfenwick 2625 .def("__rpow__",&escript::Data::rpowO,"\nUsed by the python ** operator\n\n:rtype: `Data`")
360 jgs 102 // NOTE:: The order of these declarations is important. Anything
361     // declared before the generic declaration isn't found so the generic
362     // version will be called.
363     .def(self + other<object>())
364     .def(other<object>() + self)
365     .def(self + self)
366 gross 285 .def(self += other<object>())
367     .def(self += self)
368    
369 jgs 102 .def(self - other<object>())
370     .def(other<object>() - self)
371     .def(self - self)
372 gross 285 .def(self -= other<object>())
373     .def(self -= self)
374    
375 jgs 102 .def(self * other<object>())
376     .def(other<object>() * self)
377     .def(self * self)
378 gross 285 .def(self *= other<object>())
379     .def(self *= self)
380    
381 jgs 102 .def(self / other<object>())
382     .def(other<object>() / self)
383     .def(self / self)
384 gross 285 .def(self /= other<object>())
385     .def(self /= self)
386 jgs 102 // Need scope resolution due to a bug either in the compiler or
387     // the boost code. This calls operator << for Data.
388 jfenwick 2742 .def(self_ns::str(self))
389     .def("_inverse", &escript::Data::matrixInverse, ":return: inverse of square matricies\n");
390 jgs 102
391 jfenwick 2635
392 jgs 102 //
393     // Factory methods for function space
394     //
395 jfenwick 2625 def("ContinuousFunction",escript::continuousFunction,args("domain"),
396     ":return: a continuous FunctionSpace (overlapped node values)\n"
397     ":rtype: `FunctionSpace`");
398     def("ReducedContinuousFunction",escript::reducedContinuousFunction,args("domain"),
399     ":return: a continuous with reduced order FunctionSpace (overlapped node values on reduced element order)\n"
400     ":rtype: `FunctionSpace`");
401     def("Function",escript::function,args("domain"),":return: a function `FunctionSpace`\n"
402     ":rtype: `FunctionSpace`");
403     def("ReducedFunction",escript::reducedFunction, args("domain"),":return: a function FunctionSpace with reduced integration order\n:rtype: `FunctionSpace`");
404     def("FunctionOnBoundary",escript::functionOnBoundary, args("domain"), ":return: a function on boundary FunctionSpace\n:rtype: `FunctionSpace`");
405     def("ReducedFunctionOnBoundary",escript::reducedFunctionOnBoundary, args("domain"),
406     ":return: a function on boundary FunctionSpace with reduced integration order\n"
407     ":rtype: `FunctionSpace`");
408     def("FunctionOnContactZero",escript::functionOnContactZero, args("domain"), ":return: Return a FunctionSpace on left side of contact\n:rtype: `FunctionSpace`");
409     def("ReducedFunctionOnContactZero",escript::reducedFunctionOnContactZero, args("domain"),
410     ":return: a FunctionSpace on left side of contact with reduced integration order\n:rtype: `FunctionSpace`");
411     def("FunctionOnContactOne",escript::functionOnContactOne, args("domain"), ":return: Return a FunctionSpace on right side of contact\n:rtype: `FunctionSpace`");
412     def("ReducedFunctionOnContactOne",escript::reducedFunctionOnContactOne, args("domain"),
413     ":return: Return a FunctionSpace on right side of contact with reduced integration order\n"
414     ":rtype: `FunctionSpace`");
415     def("Solution",escript::solution, args("domain"), ":rtype: `FunctionSpace`");
416     def("ReducedSolution",escript::reducedSolution, args("domain"), ":rtype: `FunctionSpace`");
417     def("DiracDeltaFunction",escript::diracDeltaFunction, args("domain"), ":rtype: `FunctionSpace`");
418 jgs 102
419 jfenwick 2635
420    
421    
422    
423 jgs 102 //
424     // Factory methods for Data
425     //
426 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`");
427     def("loadIsConfigured",escript::loadConfigured,":return: True if the load function is configured.");
428 jgs 102 def("Scalar",escript::Scalar,
429     (arg("value")=0.0,
430     arg("what")=escript::FunctionSpace(),
431 jfenwick 2625 arg("expanded")=false),
432     "Construct a Data object containing scalar 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 jgs 102 def("Vector",escript::Vector,
437     (arg("value")=0.0,
438     arg("what")=escript::FunctionSpace(),
439 jfenwick 2625 arg("expanded")=false),
440     "Construct a Data object containing rank1 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 jfenwick 2838 def("Vector", escript::VectorFromObj,
445     (arg("value"),
446     arg("what")=escript::FunctionSpace(),
447     arg("expanded")=false));
448 jgs 102 def("Tensor",escript::Tensor,
449     (arg("value")=0.0,
450     arg("what")=escript::FunctionSpace(),
451 jfenwick 2625 arg("expanded")=false),
452     "Construct a Data object containing rank2 data-points.\n\n:param value: scalar value for all points\n"
453     "\n:rtype: `Data`\n:type value: float\n:param what: FunctionSpace for Data\n:type what: `FunctionSpace`\n"
454     ":param expanded: If True, a value is stored for each point. If False, more efficient representations may be used\n"
455     ":type expanded: ``bool``");
456 jfenwick 2838 def("Tensor", escript::TensorFromObj,
457     (arg("value"),
458     arg("what")=escript::FunctionSpace(),
459     arg("expanded")=false));
460 jgs 102 def("Tensor3",escript::Tensor3,
461     (arg("value")=0.0,
462     arg("what")=escript::FunctionSpace(),
463 jfenwick 2625 arg("expanded")=false),
464     "Construct a Data object containing rank3 data-points.\n\n:param value: scalar value for all points\n"
465     "\n:rtype: `Data`\n:type value: float\n:param what: FunctionSpace for Data\n:type what: `FunctionSpace`\n"
466     ":param expanded: If True, a value is stored for each point. If False, more efficient representations may be used\n"
467     ":type expanded: ``bool``"
468     );
469 jfenwick 2838 def("Tensor3", escript::Tensor3FromObj,
470     (arg("value"),
471     arg("what")=escript::FunctionSpace(),
472     arg("expanded")=false));
473 jgs 102 def("Tensor4",escript::Tensor4,
474     (arg("value")=0.0,
475     arg("what")=escript::FunctionSpace(),
476 jfenwick 2625 arg("expanded")=false),
477     "Construct a Data object containing rank4 data-points.\n\n:param value: scalar value for all points\n"
478     "\n:rtype: `Data`\n:type value: float\n:param what: FunctionSpace for Data\n:type what: `FunctionSpace`\n"
479     ":param expanded: If True, a value is stored for each point. If False, more efficient representations may be used\n"
480     ":type expanded: ``bool``"
481     );
482 jfenwick 2838 def("Tensor4", escript::Tensor4FromObj,
483     (arg("value"),
484     arg("what")=escript::FunctionSpace(),
485     arg("expanded")=false));
486 jgs 102
487     //
488 ksteube 813 // Binary operators
489     //
490     def("C_GeneralTensorProduct",escript::C_GeneralTensorProduct,
491 jfenwick 2626 (arg("arg0"),
492     arg("arg1"),
493 ksteube 813 arg("axis_offset")=0,
494 jfenwick 2625 arg("transpose")=0),
495     "Compute a tensor product of two Data objects.\n\n:rtype: `Data`\n:param arg0:\n"
496     ":param arg1:\n:param axis_offset:\n:type axis_offset: ``int``\n"
497     ":param transpose: 0: transpose neither, 1: transpose arg0, 2: transpose arg1\n"
498     ":type transpose: int");
499 ksteube 813
500     //
501 jgs 102 // Interface for AbstractSystemMatrix
502     //
503 jfenwick 2061 class_<escript::AbstractSystemMatrix>("Operator","",init<>()) // Doco goes in the empty string param
504 jfenwick 2625 .def("isEmpty",&escript::AbstractSystemMatrix::isEmpty,":rtype: ``bool``\n"
505     ":return: True if matrix is empty")
506     .def("solve",&escript::AbstractSystemMatrix::solve, args("in","options"),
507     ":return: the solution *u* of the linear system *this*u=in*\n\n:param in:\n:type in: `Data`")
508     .def("of",&escript::AbstractSystemMatrix::vectorMultiply,args("right"),
509     "matrix*vector multiplication")
510     .def("saveMM",&escript::AbstractSystemMatrix::saveMM, args("fileName"),
511     "writes the matrix to a file using the Matrix Market file format")
512     .def("saveHB",&escript::AbstractSystemMatrix::saveHB, args("filename"),
513     "writes the matrix to a file using the Harwell-Boeing file format")
514     .def("resetValues",&escript::AbstractSystemMatrix::resetValues, "resets the matrix entries")
515 jgs 102 .def(self*other<escript::Data>());
516 gross 1364 //
517     // Interface for AbstractTransportProblem
518     //
519 jfenwick 2061 class_<escript::AbstractTransportProblem>("TransportProblem","",init<>()) // Doco goes in the empty string param
520 jfenwick 2625 .def("isEmpty",&escript::AbstractTransportProblem::isEmpty,":rtype: ``int``")
521     .def("solve",&escript::AbstractTransportProblem::solve, args("source","dt", "options"),
522     "returns the solution *u* for a time step *dt>0*\n\n:rtype: `Data`\n"
523     ":param source:\n:type source: `Data`")
524     .def("setInitialValue",&escript::AbstractTransportProblem::setInitialValue, args("u"),
525     "sets the value for *u* at time *t=0*.")
526     .def("insertConstraint",&escript::AbstractTransportProblem::insertConstraint,
527     args("source", "q", "r","factor"),
528     "inserts constraint *u_{,t}=r* where *q>0* into the problem using a weighting factor")
529     .def("reset",&escript::AbstractTransportProblem::resetTransport,
530     "resets the transport operator typically as they have been updated.")
531 gross 1841 .def("resetValues",&escript::AbstractTransportProblem::resetTransport)
532 gross 1859 .def("getSafeTimeStepSize",&escript::AbstractTransportProblem::getSafeTimeStepSize)
533     .def("getUnlimitedTimeStepSize",&escript::AbstractTransportProblem::getUnlimitedTimeStepSize);
534 jgs 102
535 jfenwick 1897 // Functions to modify global parameters
536     def("setEscriptParamInt",escript::setEscriptParamInt,
537 jfenwick 2625 (arg("name"), arg("value")=0), "Modify the value of an escript tuning parameter\n\n"
538     ":param name:\n:type name: ``string``\n:param value:\n:type value: ``int``");
539 jfenwick 1897 def("getEscriptParamInt",escript::getEscriptParamInt,
540 jfenwick 2625 (arg("name"),arg("sentinel")=0), "Read the value of an escript tuning paramter\n\n"
541     ":param name: parameter to lookup\n:type name: ``string``\n:param sentinel: Value to be returned if ``name`` is not a known parameter\n"
542     ":type sentinel: ``int``");
543     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.");
544 jfenwick 1897
545 jfenwick 2799
546     def("resolveGroup", escript::resolveGroup);
547 jfenwick 2827
548     #ifdef IKNOWWHATIMDOING
549    
550     def("applyBinaryCFunction", escript::applyBinaryCFunction, (arg("function"), arg("outshape"),
551     arg("in1"),
552     arg("in2"))
553     );
554     #endif
555    
556 jgs 102 //
557     // Register esysExceptionTranslator
558     //
559     register_exception_translator<esysUtils::EsysException>(&esysUtils::esysExceptionTranslator);
560     }

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26