/[escript]/release/3.3.1/escript/src/escriptcpp.cpp
ViewVC logotype

Contents of /release/3.3.1/escript/src/escriptcpp.cpp

Parent Directory Parent Directory | Revision Log Revision Log


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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26