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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3991 - (show annotations)
Tue Sep 25 23:52:22 2012 UTC (6 years, 11 months ago) by caltinay
File size: 38843 byte(s)
Updated doxygen cfg file and made a few first changes to doco.

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26