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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4286 - (show annotations)
Thu Mar 7 04:28:11 2013 UTC (6 years, 5 months ago) by caltinay
File size: 39587 byte(s)
Assorted spelling fixes.

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26