1 |
jgs |
102 |
|
2 |
ksteube |
1312 |
/******************************************************* |
3 |
ksteube |
1811 |
* |
4 |
jfenwick |
2548 |
* Copyright (c) 2003-2009 by University of Queensland |
5 |
ksteube |
1811 |
* Earth Systems Science Computational Center (ESSCC) |
6 |
|
|
* http://www.uq.edu.au/esscc |
7 |
|
|
* |
8 |
|
|
* Primary Business: Queensland, Australia |
9 |
|
|
* Licensed under the Open Software License version 3.0 |
10 |
|
|
* http://www.opensource.org/licenses/osl-3.0.php |
11 |
|
|
* |
12 |
|
|
*******************************************************/ |
13 |
ksteube |
1312 |
|
14 |
ksteube |
1811 |
|
15 |
jgs |
474 |
#include "Data.h" |
16 |
|
|
#include "FunctionSpace.h" |
17 |
|
|
#include "FunctionSpaceFactory.h" |
18 |
|
|
#include "DataFactory.h" |
19 |
|
|
#include "AbstractContinuousDomain.h" |
20 |
|
|
#include "AbstractDomain.h" |
21 |
|
|
#include "Utils.h" |
22 |
jgs |
480 |
#include "AbstractSystemMatrix.h" |
23 |
gross |
1364 |
#include "AbstractTransportProblem.h" |
24 |
gross |
797 |
#include "DataVector.h" |
25 |
ksteube |
1800 |
#include "paso/Paso_MPI.h" |
26 |
jfenwick |
1897 |
#include "EscriptParams.h" |
27 |
jfenwick |
2482 |
#include "TestDomain.h" |
28 |
jgs |
474 |
|
29 |
jfenwick |
1872 |
|
30 |
ksteube |
1312 |
extern "C" { |
31 |
phornby |
2078 |
#include "esysUtils/blocktimer.h" |
32 |
ksteube |
1312 |
} |
33 |
|
|
|
34 |
robwdcock |
682 |
#include "esysUtils/esysExceptionTranslator.h" |
35 |
jgs |
102 |
|
36 |
gross |
2100 |
#include <boost/version.hpp> |
37 |
jgs |
102 |
#include <boost/python.hpp> |
38 |
|
|
#include <boost/python/module.hpp> |
39 |
|
|
#include <boost/python/def.hpp> |
40 |
|
|
#include <boost/python/object.hpp> |
41 |
|
|
#include <boost/python/tuple.hpp> |
42 |
gross |
285 |
#include <boost/python/numeric.hpp> |
43 |
jfenwick |
1872 |
#include <boost/smart_ptr.hpp> |
44 |
jfenwick |
2064 |
#include <boost/version.hpp> |
45 |
gross |
285 |
|
46 |
jgs |
102 |
using namespace boost::python; |
47 |
|
|
|
48 |
jgs |
121 |
/*! \mainpage Esys Documentation |
49 |
|
|
* |
50 |
jfenwick |
2602 |
* \version 3.0.0 |
51 |
jgs |
121 |
* |
52 |
|
|
* - \ref escript |
53 |
|
|
* |
54 |
|
|
* - \ref esys_exception "Esys Exception" |
55 |
|
|
* |
56 |
|
|
* - \ref finley |
57 |
|
|
* |
58 |
jfenwick |
2283 |
* - <a href="../../epydoc/index.html">Python module documentation (epydoc generated)</a> |
59 |
jgs |
122 |
* |
60 |
jgs |
121 |
*/ |
61 |
jgs |
102 |
|
62 |
jgs |
121 |
/*! \page escript Escript |
63 |
|
|
* Escript is the python module that contains the interfaces |
64 |
|
|
* to the C++ side of escript. |
65 |
|
|
* |
66 |
jfenwick |
2459 |
* |
67 |
jgs |
121 |
* |
68 |
|
|
* \section class_desc Class Description: |
69 |
|
|
* Data |
70 |
|
|
* |
71 |
|
|
* \section class_limits Class Limitations: |
72 |
|
|
* None |
73 |
|
|
* |
74 |
|
|
* \section class_conds Class Conditions of Use: |
75 |
|
|
* None |
76 |
|
|
* |
77 |
|
|
* \section class_throws Throws: |
78 |
|
|
* None |
79 |
|
|
* |
80 |
|
|
*/ |
81 |
jgs |
102 |
|
82 |
|
|
BOOST_PYTHON_MODULE(escriptcpp) |
83 |
|
|
{ |
84 |
jfenwick |
2625 |
|
85 |
|
|
#if BOOST_VERSION >= 103500 |
86 |
|
|
// params are: bool show_user_defined, bool show_py_signatures, bool show_cpp_signatures |
87 |
|
|
docstring_options docopt(true,true,false); |
88 |
gross |
2100 |
#endif |
89 |
jfenwick |
2061 |
|
90 |
jfenwick |
2607 |
def("setNumberOfThreads",escript::setNumberOfThreads,"Use of this method is strongly discouraged."); |
91 |
jfenwick |
2625 |
def("getNumberOfThreads",escript::getNumberOfThreads,"Return the maximum number of threads" |
92 |
|
|
" available to OpenMP."); |
93 |
gross |
797 |
def("releaseUnusedMemory",escript::releaseUnusedMemory); |
94 |
ksteube |
1312 |
def("blocktimer_initialize",blocktimer_initialize); |
95 |
|
|
def("blocktimer_reportSortByName",blocktimer_reportSortByName); |
96 |
|
|
def("blocktimer_reportSortByTime",blocktimer_reportSortByTime); |
97 |
|
|
def("blocktimer_increment",blocktimer_increment); |
98 |
|
|
def("blocktimer_time",blocktimer_time); |
99 |
jfenwick |
2607 |
def("getVersion",escript::getSvnVersion,"This method will only report accurate version numbers for clean checkouts."); |
100 |
ksteube |
1561 |
def("printParallelThreadCounts",escript::printParallelThreadCnt); |
101 |
jfenwick |
2625 |
def("getMPISizeWorld",escript::getMPISizeWorld,"Return number of MPI processes in the job."); |
102 |
|
|
def("getMPIRankWorld",escript::getMPIRankWorld,"Return the rank of this process in the MPI World."); |
103 |
|
|
def("MPIBarrierWorld",escript::MPIBarrierWorld,"Wait until all MPI processes have reached this point."); |
104 |
|
|
def("getMPIWorldMax",escript::getMPIWorldMax,"\nEach MPI process calls this function with a" |
105 |
|
|
" value for arg1. The maximum value is computed and returned.\n\n:rtype: int"); |
106 |
|
|
def("getMPIWorldSum",escript::getMPIWorldSum,"\nEach MPI process calls this function with a" |
107 |
|
|
" value for arg1. The values are added up and the total value is returned.\n\n:rtype: int"); |
108 |
gross |
2100 |
def("getMachinePrecision",escript::getMachinePrecision); |
109 |
|
|
def("getMaxFloat",escript::getMaxFloat); |
110 |
jfenwick |
2644 |
def("_saveDataCSV",escript::saveDataCSV, (args("filename","arg","sep","csep"), arg("append")=false), |
111 |
|
|
"Saves data objects passed in a python dictionary to a file.\n" |
112 |
|
|
"The data objects must be over the same domain and be able to be interpolated to the same FunctionSpace.\n" |
113 |
|
|
"If one of the dictionary keys is named ``mask``, then only samples where ``mask`` has a positive\n" |
114 |
|
|
"value will be written to the file.\n\n" |
115 |
|
|
"A header line giving the names of each column will be output first.\n" |
116 |
|
|
"The keys given in the dictionary will be used to name columns.\n" |
117 |
|
|
"Then the data will be output, one line per sample (for all data).\n" |
118 |
|
|
"\n:param filename:\n:type filename: ``string``\n" |
119 |
|
|
":param arg: dictionary of named `Data` objects. If one is called ``mask`` it must be scalar data." |
120 |
|
|
"\n:type arg: ``dict``\n" |
121 |
|
|
":param sep:separator for columns (defaults to \", \"\n:type sep:``string``\n" |
122 |
|
|
":param csep:separator for fields within data object (defaults to \"_\"\n:type csep:``string``\n" |
123 |
|
|
":param append: If True, write to the end of ``filename``\n:type append: ``string``\n"); |
124 |
jfenwick |
2635 |
|
125 |
|
|
|
126 |
jgs |
102 |
// |
127 |
|
|
// Interface for AbstractDomain |
128 |
|
|
// |
129 |
jfenwick |
2061 |
class_<escript::AbstractDomain, escript::Domain_ptr>("Domain","Base class for all domains.",no_init) |
130 |
jfenwick |
2625 |
.def("getStatus",&escript::AbstractDomain::getStatus,"The status of a domain changes whenever the domain is modified\n\n:rtype: int") |
131 |
|
|
.def("setTagMap",&escript::AbstractDomain::setTagMap,args("name","tag"), |
132 |
|
|
"Give a tag number a name.\n\n:param name: Name for the tag\n:type name: ``string``\n" |
133 |
|
|
":param tag: numeric id\n:type tag: ``int``\n:note: Tag names must be unique within a domain") |
134 |
|
|
.def("getTag",&escript::AbstractDomain::getTag,args("name"),":return: tag id for " |
135 |
|
|
"``name``\n:rtype: ``string``") |
136 |
|
|
.def("isValidTagName",&escript::AbstractDomain::isValidTagName,args("name"), |
137 |
|
|
":return: True is ``name`` corresponds to a tag\n:rtype: ``bool``") |
138 |
|
|
.def("showTagNames",&escript::AbstractDomain::showTagNames,":return: A space separated list of tag names\n:rtype: ``string``") |
139 |
|
|
.def("getX",&escript::AbstractDomain::getX,":rtype: `Data`\n:return: Locations in the" |
140 |
|
|
"`Domain`. FunctionSpace is chosen appropriately") |
141 |
|
|
.def("getDim",&escript::AbstractDomain::getDim,":rtype: `int`\n:return: Spatial dimension of the `Domain`") |
142 |
|
|
.def("getNormal",&escript::AbstractDomain::getNormal,":rtype: `escript`\n:return: Boundary normals") |
143 |
|
|
.def("getSize",&escript::AbstractDomain::getSize,":return: the local size of samples. The function space is chosen appropriately\n:rtype: `Data`") |
144 |
|
|
.def("saveVTK",&escript::AbstractDomain::saveVTK,args("filename","arg", "metadata" |
145 |
|
|
, "metadata_schema"), |
146 |
|
|
":param filename: \n:type filename: ``string``\n:param arg: items to be added" |
147 |
|
|
"\n:type arg: ``dict``\n:param metadata: string representing some meta data to be added\n:type metadata: ``string``" |
148 |
|
|
"\n:param metadata_schema: schema type for metadata\n:type metadata_schema: ``string``") |
149 |
|
|
.def("dump",&escript::AbstractDomain::dump,args("filename"),"Dumps the domain to a file" |
150 |
|
|
":param filename:\n:type filename: string") |
151 |
|
|
.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``" |
152 |
|
|
"\n:param arg:\n:type arg: `dict`") |
153 |
|
|
.def("getMPISize",&escript::AbstractDomain::getMPISize,":return: the number of processes used for this `Domain`\n:rtype: ``int``") |
154 |
|
|
.def("getMPIRank",&escript::AbstractDomain::getMPIRank,":return: the rank of this process\n:rtype: ``int``") |
155 |
|
|
.def("MPIBarrier",&escript::AbstractDomain::MPIBarrier,"Wait until all processes have reached this point") |
156 |
|
|
.def("onMasterProcessor",&escript::AbstractDomain::onMasterProcessor,":return: True if this code is executing on the master process\n:rtype: `bool`") |
157 |
ksteube |
1312 |
|
158 |
jgs |
102 |
.def(self == self) |
159 |
|
|
.def(self != self); |
160 |
|
|
|
161 |
|
|
// |
162 |
|
|
// Interface for AbstractContinuousDomain |
163 |
|
|
// |
164 |
jfenwick |
2061 |
class_<escript::AbstractContinuousDomain, bases<escript::AbstractDomain> >("ContinuousDomain","Class representing continuous domains",no_init) |
165 |
jfenwick |
2625 |
.def("getSystemMatrixTypeId",&escript::AbstractContinuousDomain::getSystemMatrixTypeId, |
166 |
|
|
args("solver", "preconditioner", "package", "symmetry"), |
167 |
|
|
":return: the identifier of the matrix type to be used for the global stiffness matrix " |
168 |
|
|
"when a particular solver package and symmetric matrix is used.\n" |
169 |
|
|
":rtype: int") |
170 |
|
|
.def("getTransportTypeId",&escript::AbstractContinuousDomain::getTransportTypeId, |
171 |
|
|
args("solver", "preconditioner", "package", "symmetry")); |
172 |
jgs |
102 |
|
173 |
jfenwick |
2482 |
|
174 |
jgs |
102 |
// |
175 |
jfenwick |
2482 |
// Interface for TestDomain |
176 |
|
|
// |
177 |
|
|
class_ <escript::TestDomain, bases<escript::AbstractDomain> >("TestDomain", "Test Class for domains with no structure. May be removed from future releases without notice.", init<int,int>()); |
178 |
|
|
|
179 |
|
|
// This is the only python visible way to get a TestDomain |
180 |
jfenwick |
2625 |
def("getTestDomainFunctionSpace",&escript::getTestDomainFunctionSpace, args("dpps", |
181 |
|
|
"samples"), |
182 |
|
|
"For testing only. May be removed without notice."); |
183 |
jfenwick |
2482 |
|
184 |
|
|
// |
185 |
jgs |
102 |
// Interface for FunctionSpace |
186 |
|
|
// |
187 |
jfenwick |
2625 |
class_<escript::FunctionSpace> fs_definer("FunctionSpace","A FunctionSpace describes which points from the `Domain` to use to represent functions.",init<>()); // Doco goes in the empty string param |
188 |
|
|
fs_definer.def("getDim",&escript::FunctionSpace::getDim,":return: the spatial dimension of the underlying domain.\n:rtype: int"); |
189 |
jfenwick |
1872 |
// fs_definer.def("getDomain",&escript::FunctionSpace::getDomain, |
190 |
|
|
// return_internal_reference<>()); |
191 |
jfenwick |
2625 |
fs_definer.def("getDomain",&escript::FunctionSpace::getDomainPython,":return: the underlying `Domain` for this FunctionSpace.\n:rtype: `Domain`"); |
192 |
|
|
fs_definer.def("getX",&escript::FunctionSpace::getX,"\n:return: a function whose values are its input coordinates. ie an identity function.\n:rtype: `Data`"); |
193 |
|
|
fs_definer.def("getNormal",&escript::FunctionSpace::getNormal,":return: the surface normal field.\n\n:rtype: `Data`"); |
194 |
|
|
fs_definer.def("getSize",&escript::FunctionSpace::getSize,":return: sample size\n:rtype: `Data`"); |
195 |
|
|
fs_definer.def("setTags",&escript::FunctionSpace::setTags,args("newtag","mask"), |
196 |
|
|
"Set tags according to a mask\n\n:param newtag: tag number to set\n:type newtag: non-zero ``int``\n:param mask: Samples which correspond to positive values in the mask will be set to ``newtag``.\n:type mask: scalar `Data`"); |
197 |
trankine |
1426 |
fs_definer.def("getTagFromDataPointNo", |
198 |
jfenwick |
2625 |
&escript::FunctionSpace::getTagFromDataPointNo,":return: the tag associated with the given sample number.\n:rtype: int"); |
199 |
|
|
fs_definer.def("getReferenceIDFromDataPointNo", &escript::FunctionSpace::getReferenceIDFromDataPointNo,args("dataPointNo"),":return: the reference number associated with ``dataPointNo``\n:rtype: int "); |
200 |
|
|
fs_definer.def("getListOfTags",&escript::FunctionSpace::getListOfTags,":return: a list of the tags used in this function space\n:rtype: ``list``"); |
201 |
phornby |
1628 |
fs_definer.def("__str__", &escript::FunctionSpace::toString); |
202 |
trankine |
1426 |
fs_definer.def(self == self); |
203 |
|
|
fs_definer.def(self != self); |
204 |
jgs |
102 |
// |
205 |
|
|
// Interface for Data |
206 |
|
|
// |
207 |
jfenwick |
2061 |
class_<escript::Data>("Data","Represents a collection of datapoints. It is used to store the values of a function. For more details please consult the c++ class documentation.",init<>() ) |
208 |
jgs |
102 |
// various constructors for Data objects |
209 |
|
|
.def(init<const object&, optional<const escript::FunctionSpace&, bool> >(args("value","what","expand"))) |
210 |
|
|
.def(init<const double, const tuple&, optional<const escript::FunctionSpace&, bool> >(args("value","shape","what","expand"))) |
211 |
|
|
.def(init<const escript::Data&, const escript::FunctionSpace&>(args("value","what"))) |
212 |
|
|
.def(init<const escript::Data&>()) |
213 |
|
|
// Note for Lutz, Need to specify the call policy in order to return a |
214 |
|
|
// reference. In this case return_internal_reference. |
215 |
ksteube |
1312 |
.def("__str__",&escript::Data::toString) |
216 |
jfenwick |
2625 |
.def("getDomain",&escript::Data::getDomainPython,":rtype: `Domain`") |
217 |
|
|
.def("getFunctionSpace",&escript::Data::getFunctionSpace,return_value_policy<copy_const_reference>(),":rtype: `FunctionSpace`") |
218 |
|
|
.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.") |
219 |
|
|
.def("isProtected",&escript::Data::isProtected,"Can this instance be modified.\n:rtype: ``bool``") |
220 |
|
|
.def("setProtection",&escript::Data::setProtection,"Disallow modifications to this data object\n\n:note: This method does not allow you to undo protection.") |
221 |
|
|
.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``") |
222 |
|
|
.def("getRank",&escript::Data::getDataPointRank,":return: the number of indicies required to address a component of a datapoints\n:rtype: positive ``int``") |
223 |
|
|
.def("dump",&escript::Data::dump,args("fileName"),"Save the data as a netCDF file\n\n:param fileName: \n:type fileName: ``string``") |
224 |
|
|
.def("toListOfTuples",&escript::Data::toListOfTuples, (arg("scalarastuple")=false), |
225 |
|
|
"Return the datapoints of this object in a list. Each datapoint is stored as a tuple.\n\n" |
226 |
|
|
":param scalarastuple: if True, scalar data will be wrapped as a tuple." |
227 |
|
|
" True => [(0), (1), (2)]; False => [0, 1, 2]") |
228 |
|
|
.def("copyWithMask",&escript::Data::copyWithMask,args("other","mask"), |
229 |
|
|
"Selectively copy values from ``other`` `Data`." |
230 |
|
|
"Datapoints which correspond to postive values in ``mask`` will be copied from ``other``\n" |
231 |
|
|
"\n:param other: source of values\n" |
232 |
|
|
":type other: `Data`\n:param mask:\n:type mask: Scalar `Data`") |
233 |
|
|
.def("setTaggedValue",&escript::Data::setTaggedValue,args("tagKey","value"), |
234 |
|
|
"Set the value of tagged Data.\n\n:param tagKey: tag to update\n:type tagKey: ``int``\n") |
235 |
|
|
.def("setTaggedValue",&escript::Data::setTaggedValueByName,args("name","value"),":param name: tag to update\n:type name: ``string``\n" |
236 |
|
|
":param value: value to set tagged data to\n:type value: ``object`` which acts like an array, ``tuple`` or ``list``\n") |
237 |
|
|
.def("getNumberOfDataPoints",&escript::Data::getNumDataPoints,":rtype: ``int``\n:return: Number of datapoints in the object") |
238 |
|
|
.def("isExpanded",&escript::Data::isExpanded,":rtype: ``bool``\n:return: True if this ``Data`` is expanded.") |
239 |
|
|
.def("isTagged",&escript::Data::isTagged,":rtype: ``bool``\n:return: True if this ``Data`` is expanded.") |
240 |
|
|
.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.") |
241 |
|
|
.def("isLazy",&escript::Data::isLazy,":rtype: ``bool``\n:return: True if this ``Data`` is lazy.") |
242 |
|
|
.def("isReady",&escript::Data::isReady,":rtype: ``bool``\n:return: True if this ``Data`` is not lazy.") |
243 |
jfenwick |
2646 |
.def("hasNoSamples", &escript::Data::hasNoSamples,":rtype: ``bool``\n:return: True if this ``Data`` (locally)" |
244 |
|
|
" contains no samples.") |
245 |
jfenwick |
2625 |
.def("expand",&escript::Data::expand,"Convert the data to expanded representation if it is not expanded already.") |
246 |
|
|
.def("tag",&escript::Data::tag,"Convert data to tagged representation if it is not already tagged or expanded") |
247 |
|
|
.def("resolve",&escript::Data::resolve,"Convert the data to non-lazy representation.") |
248 |
|
|
.def("copy",&escript::Data::copy,args("other"),"Make this object a copy of ``other``\n" |
249 |
|
|
"\n:note: The two objects will act independently from now on. That is, changing ``other`` " |
250 |
|
|
"after this call will not change this object and vice versa.") |
251 |
|
|
.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.") |
252 |
|
|
.def("delay",&escript::Data::delay,"Convert this object into lazy representation") |
253 |
|
|
.def("setValueOfDataPoint",&escript::Data::setValueOfDataPointToPyObject,args("dataPointNo","value")) |
254 |
gross |
1034 |
.def("setValueOfDataPoint",&escript::Data::setValueOfDataPointToArray) |
255 |
jfenwick |
2625 |
.def("setValueOfDataPoint",&escript::Data::setValueOfDataPoint,"\nModify the value of a single datapoint.\n\n:param dataPointNo:\n" |
256 |
|
|
":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.") |
257 |
|
|
.def("getTupleForDataPoint",&escript::Data::getValueOfDataPointAsTuple,args("dataPointNo"), |
258 |
|
|
":return: Value of the specified datapoint\n:rtype: ``tuple``\n:param dataPointNo: datapoint to access\n:type dataPointNo: ``int``") |
259 |
|
|
.def("getTupleForGlobalDataPoint",&escript::Data::getValueOfGlobalDataPointAsTuple,args("procNo","dataPointNo"),"Get a specific datapoint from a specific process\n\n" |
260 |
|
|
":rtype: ``tuple``\n:param procNo: MPI rank of the process\n:type procNo: positive ``int``" |
261 |
|
|
"\n:param dataPointNo: datapoint to access\n:type dataPointNo: int") |
262 |
|
|
.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.") |
263 |
|
|
.def("interpolate",&escript::Data::interpolate,args("functionspace"),"Interpolate this object's values into a new functionspace.") |
264 |
jfenwick |
2646 |
.def("interpolateTable", &escript::Data::interpolateFromTable2DP, |
265 |
gross |
2649 |
(arg("table"),arg("Amin"),arg("Astep"), arg("B"), arg("Bmin"), arg("Bstep"), arg("undef")=1.e50), |
266 |
jfenwick |
2628 |
"Creates a new Data object by interpolating using the source data (which are\n" |
267 |
jfenwick |
2646 |
"looked up in ``table``)\n``A`` must be the outer dimension on the table\n\n" |
268 |
jfenwick |
2628 |
":param table: two dimensional collection of values\n" |
269 |
|
|
":param Amin: The base of locations in table\n:type Amin: float\n" |
270 |
|
|
":param Astep: size of gap between each item in the table\n:type Astep: float\n" |
271 |
|
|
":param undef: upper bound on interpolated values\n:type undef: float\n" |
272 |
|
|
":param B: Scalar representing the second coordinate to be mapped into the table\n" |
273 |
|
|
":type B: `Data`\n" |
274 |
|
|
":param Bmin: The base of locations in table for 2nd dimension\n:type Bmin: float\n" |
275 |
|
|
":param Bstep: size of gap between each item in the table for 2nd dimension\n:type Bstep: float\n" |
276 |
|
|
":raise RuntimeError(DataException): if the cordinates do not map into the table or if the interpolated value is above ``undef``" |
277 |
|
|
"\n:rtype: `Data`" |
278 |
|
|
) |
279 |
jfenwick |
2646 |
.def("interpolateTable", &escript::Data::interpolateFromTable1DP, |
280 |
gross |
2649 |
(arg("table"),arg("Amin"),arg("Astep"), arg("undef")=1.e50), |
281 |
jfenwick |
2646 |
"Creates a new Data object by interpolating using the source data (which are\n" |
282 |
|
|
"looked up in ``table``)\n\n" |
283 |
|
|
":param table: one dimensional collection of values\n" |
284 |
|
|
":param Amin: The base of locations in table\n:type Amin: float\n" |
285 |
|
|
":param Astep: size of gap between each item in the table\n:type Astep: float\n" |
286 |
|
|
":param undef: upper bound on interpolated values\n:type undef: float\n" |
287 |
|
|
":raise RuntimeError(DataException): if the cordinates do not map into the table or if the interpolated value is above ``undef``" |
288 |
|
|
"\n:rtype: `Data`" |
289 |
|
|
) |
290 |
jfenwick |
2628 |
|
291 |
jfenwick |
2646 |
|
292 |
gross |
921 |
.def("minGlobalDataPoint",&escript::Data::minGlobalDataPoint) |
293 |
jfenwick |
2476 |
.def("maxGlobalDataPoint",&escript::Data::maxGlobalDataPoint) |
294 |
jfenwick |
2625 |
.def("saveDX",&escript::Data::saveDX,args("fileName"),"Save the object in DX format.\n\n" |
295 |
|
|
":param fileName: filename\n:type fileName: string") |
296 |
|
|
.def("saveVTK",&escript::Data::saveVTK, args("fileName"),"Save the object in VTK format.\n\n" |
297 |
|
|
":param fileName: \n:type fileName: string") |
298 |
|
|
.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") |
299 |
gross |
285 |
// Unary functions for Data |
300 |
|
|
.def("_interpolate",&escript::Data::interpolate) |
301 |
|
|
.def("_grad",&escript::Data::gradOn) |
302 |
|
|
.def("_grad",&escript::Data::grad) |
303 |
|
|
.def("_transpose",&escript::Data::transpose) |
304 |
|
|
.def("_trace",&escript::Data::trace) |
305 |
|
|
.def("_maxval",&escript::Data::maxval) |
306 |
|
|
.def("_minval",&escript::Data::minval) |
307 |
gross |
698 |
.def("_wherePositive",&escript::Data::wherePositive) |
308 |
|
|
.def("_whereNegative",&escript::Data::whereNegative) |
309 |
|
|
.def("_whereNonNegative",&escript::Data::whereNonNegative) |
310 |
|
|
.def("_whereNonPositive",&escript::Data::whereNonPositive) |
311 |
jgs |
571 |
.def("_whereZero",&escript::Data::whereZero,(arg("tol")=0.0)) |
312 |
|
|
.def("_whereNonZero",&escript::Data::whereNonZero,(arg("tol")=0.0)) |
313 |
ksteube |
876 |
.def("_erf",&escript::Data::erf) |
314 |
gross |
285 |
.def("_sin",&escript::Data::sin) |
315 |
|
|
.def("_cos",&escript::Data::cos) |
316 |
|
|
.def("_tan",&escript::Data::tan) |
317 |
|
|
.def("_asin",&escript::Data::asin) |
318 |
|
|
.def("_acos",&escript::Data::acos) |
319 |
|
|
.def("_atan",&escript::Data::atan) |
320 |
|
|
.def("_sinh",&escript::Data::sinh) |
321 |
|
|
.def("_cosh",&escript::Data::cosh) |
322 |
|
|
.def("_tanh",&escript::Data::tanh) |
323 |
|
|
.def("_asinh",&escript::Data::asinh) |
324 |
|
|
.def("_acosh",&escript::Data::acosh) |
325 |
|
|
.def("_atanh",&escript::Data::atanh) |
326 |
|
|
.def("_exp",&escript::Data::exp) |
327 |
|
|
.def("_sqrt",&escript::Data::sqrt) |
328 |
|
|
.def("_log10",&escript::Data::log10) |
329 |
|
|
.def("_log",&escript::Data::log) |
330 |
|
|
.def("_sign",&escript::Data::sign) |
331 |
ksteube |
775 |
.def("_symmetric",&escript::Data::symmetric) |
332 |
|
|
.def("_nonsymmetric",&escript::Data::nonsymmetric) |
333 |
gross |
800 |
.def("_trace",&escript::Data::trace) |
334 |
gross |
804 |
.def("_swap_axes",&escript::Data::swapaxes) |
335 |
gross |
576 |
.def("_eigenvalues",&escript::Data::eigenvalues) |
336 |
|
|
.def("_eigenvalues_and_eigenvectors",&escript::Data::eigenvalues_and_eigenvectors,(arg("tol")=1.e-13)) |
337 |
gross |
285 |
// functions returning a single real number: |
338 |
jfenwick |
2625 |
.def("_Lsup",&escript::Data::Lsup,":return: the Lsup-norm of the object\n:rtype: float\n:note: If the ``Data`` contains no values, zero will be returned instead.") |
339 |
|
|
.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.") |
340 |
|
|
.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.") |
341 |
|
|
.def("_integrateToTuple",&escript::Data::integrateToTuple,":return: Calculate the integral over the function space domain as a python tuple\n:rtype: tuple") |
342 |
gross |
285 |
// following implements the python abs operator |
343 |
jfenwick |
2625 |
.def("__abs__",&escript::Data::abs,":return: absolute value\n\n:rtype: `Data`") |
344 |
jgs |
102 |
// following implements the python "-" negation operator |
345 |
jfenwick |
2625 |
.def("__neg__",&escript::Data::neg, ":return: negation of the values in this object\n:rtype: `Data`") |
346 |
jgs |
102 |
// following implements the python "+" identity operator |
347 |
jfenwick |
2646 |
.def("__pos__",&escript::Data::pos, "\nThe unary + operator\n\n:rtype: `Data`") |
348 |
jgs |
102 |
// following two functions implement the python [] operator |
349 |
jfenwick |
2625 |
.def("__getitem__",&escript::Data::getItem,"Used by the python [] operator\n\n:rtype: `Data`") |
350 |
|
|
.def("__setitem__",&escript::Data::setItemO,"Used by the python [] operator") |
351 |
|
|
.def("__setitem__",&escript::Data::setItemD,"Used by the python [] operator") |
352 |
jgs |
102 |
// following two functions implement the python ** operator |
353 |
jfenwick |
2625 |
.def("__pow__",&escript::Data::powO,"Used by the python ** operator\n\n:rtype: `Data`") |
354 |
jgs |
102 |
.def("__pow__",&escript::Data::powD) |
355 |
jfenwick |
2625 |
.def("__rpow__",&escript::Data::rpowO,"\nUsed by the python ** operator\n\n:rtype: `Data`") |
356 |
jgs |
102 |
// NOTE:: The order of these declarations is important. Anything |
357 |
|
|
// declared before the generic declaration isn't found so the generic |
358 |
|
|
// version will be called. |
359 |
|
|
.def(self + other<object>()) |
360 |
|
|
.def(other<object>() + self) |
361 |
|
|
.def(self + self) |
362 |
gross |
285 |
.def(self += other<object>()) |
363 |
|
|
.def(self += self) |
364 |
|
|
|
365 |
jgs |
102 |
.def(self - other<object>()) |
366 |
|
|
.def(other<object>() - self) |
367 |
|
|
.def(self - self) |
368 |
gross |
285 |
.def(self -= other<object>()) |
369 |
|
|
.def(self -= self) |
370 |
|
|
|
371 |
jgs |
102 |
.def(self * other<object>()) |
372 |
|
|
.def(other<object>() * self) |
373 |
|
|
.def(self * self) |
374 |
gross |
285 |
.def(self *= other<object>()) |
375 |
|
|
.def(self *= self) |
376 |
|
|
|
377 |
jgs |
102 |
.def(self / other<object>()) |
378 |
|
|
.def(other<object>() / self) |
379 |
|
|
.def(self / self) |
380 |
gross |
285 |
.def(self /= other<object>()) |
381 |
|
|
.def(self /= self) |
382 |
jgs |
102 |
// Need scope resolution due to a bug either in the compiler or |
383 |
|
|
// the boost code. This calls operator << for Data. |
384 |
|
|
.def(self_ns::str(self)); |
385 |
|
|
|
386 |
jfenwick |
2635 |
|
387 |
jgs |
102 |
// |
388 |
|
|
// Factory methods for function space |
389 |
|
|
// |
390 |
jfenwick |
2625 |
def("ContinuousFunction",escript::continuousFunction,args("domain"), |
391 |
|
|
":return: a continuous FunctionSpace (overlapped node values)\n" |
392 |
|
|
":rtype: `FunctionSpace`"); |
393 |
|
|
def("ReducedContinuousFunction",escript::reducedContinuousFunction,args("domain"), |
394 |
|
|
":return: a continuous with reduced order FunctionSpace (overlapped node values on reduced element order)\n" |
395 |
|
|
":rtype: `FunctionSpace`"); |
396 |
|
|
def("Function",escript::function,args("domain"),":return: a function `FunctionSpace`\n" |
397 |
|
|
":rtype: `FunctionSpace`"); |
398 |
|
|
def("ReducedFunction",escript::reducedFunction, args("domain"),":return: a function FunctionSpace with reduced integration order\n:rtype: `FunctionSpace`"); |
399 |
|
|
def("FunctionOnBoundary",escript::functionOnBoundary, args("domain"), ":return: a function on boundary FunctionSpace\n:rtype: `FunctionSpace`"); |
400 |
|
|
def("ReducedFunctionOnBoundary",escript::reducedFunctionOnBoundary, args("domain"), |
401 |
|
|
":return: a function on boundary FunctionSpace with reduced integration order\n" |
402 |
|
|
":rtype: `FunctionSpace`"); |
403 |
|
|
def("FunctionOnContactZero",escript::functionOnContactZero, args("domain"), ":return: Return a FunctionSpace on left side of contact\n:rtype: `FunctionSpace`"); |
404 |
|
|
def("ReducedFunctionOnContactZero",escript::reducedFunctionOnContactZero, args("domain"), |
405 |
|
|
":return: a FunctionSpace on left side of contact with reduced integration order\n:rtype: `FunctionSpace`"); |
406 |
|
|
def("FunctionOnContactOne",escript::functionOnContactOne, args("domain"), ":return: Return a FunctionSpace on right side of contact\n:rtype: `FunctionSpace`"); |
407 |
|
|
def("ReducedFunctionOnContactOne",escript::reducedFunctionOnContactOne, args("domain"), |
408 |
|
|
":return: Return a FunctionSpace on right side of contact with reduced integration order\n" |
409 |
|
|
":rtype: `FunctionSpace`"); |
410 |
|
|
def("Solution",escript::solution, args("domain"), ":rtype: `FunctionSpace`"); |
411 |
|
|
def("ReducedSolution",escript::reducedSolution, args("domain"), ":rtype: `FunctionSpace`"); |
412 |
|
|
def("DiracDeltaFunction",escript::diracDeltaFunction, args("domain"), ":rtype: `FunctionSpace`"); |
413 |
jgs |
102 |
|
414 |
jfenwick |
2635 |
|
415 |
|
|
|
416 |
|
|
|
417 |
|
|
|
418 |
jgs |
102 |
// |
419 |
|
|
// Factory methods for Data |
420 |
|
|
// |
421 |
jfenwick |
2625 |
def("load",escript::load, args("fileName","domain"), "reads Data on domain from file in netCDF format\n\n:param fileName:\n:type fileName: ``string``\n:param domain:\n:type domain: `Domain`"); |
422 |
|
|
def("loadIsConfigured",escript::loadConfigured,":return: True if the load function is configured."); |
423 |
jgs |
102 |
def("Scalar",escript::Scalar, |
424 |
|
|
(arg("value")=0.0, |
425 |
|
|
arg("what")=escript::FunctionSpace(), |
426 |
jfenwick |
2625 |
arg("expanded")=false), |
427 |
|
|
"Construct a Data object containing scalar data-points.\n\n:param value: scalar value for all points\n" |
428 |
|
|
"\n:rtype: `Data`\n:type value: float\n:param what: FunctionSpace for Data\n:type what: `FunctionSpace`\n" |
429 |
|
|
":param expanded: If True, a value is stored for each point. If False, more efficient representations may be used\n" |
430 |
|
|
":type expanded: ``bool``"); |
431 |
jgs |
102 |
def("Vector",escript::Vector, |
432 |
|
|
(arg("value")=0.0, |
433 |
|
|
arg("what")=escript::FunctionSpace(), |
434 |
jfenwick |
2625 |
arg("expanded")=false), |
435 |
|
|
"Construct a Data object containing rank1 data-points.\n\n:param value: scalar value for all points\n" |
436 |
|
|
"\n:rtype: `Data`\n:type value: float\n:param what: FunctionSpace for Data\n:type what: `FunctionSpace`\n" |
437 |
|
|
":param expanded: If True, a value is stored for each point. If False, more efficient representations may be used\n" |
438 |
|
|
":type expanded: ``bool``"); |
439 |
jgs |
102 |
def("Tensor",escript::Tensor, |
440 |
|
|
(arg("value")=0.0, |
441 |
|
|
arg("what")=escript::FunctionSpace(), |
442 |
jfenwick |
2625 |
arg("expanded")=false), |
443 |
|
|
"Construct a Data object containing rank2 data-points.\n\n:param value: scalar value for all points\n" |
444 |
|
|
"\n:rtype: `Data`\n:type value: float\n:param what: FunctionSpace for Data\n:type what: `FunctionSpace`\n" |
445 |
|
|
":param expanded: If True, a value is stored for each point. If False, more efficient representations may be used\n" |
446 |
|
|
":type expanded: ``bool``"); |
447 |
jgs |
102 |
def("Tensor3",escript::Tensor3, |
448 |
|
|
(arg("value")=0.0, |
449 |
|
|
arg("what")=escript::FunctionSpace(), |
450 |
jfenwick |
2625 |
arg("expanded")=false), |
451 |
|
|
"Construct a Data object containing rank3 data-points.\n\n:param value: scalar value for all points\n" |
452 |
|
|
"\n:rtype: `Data`\n:type value: float\n:param what: FunctionSpace for Data\n:type what: `FunctionSpace`\n" |
453 |
|
|
":param expanded: If True, a value is stored for each point. If False, more efficient representations may be used\n" |
454 |
|
|
":type expanded: ``bool``" |
455 |
|
|
); |
456 |
jgs |
102 |
def("Tensor4",escript::Tensor4, |
457 |
|
|
(arg("value")=0.0, |
458 |
|
|
arg("what")=escript::FunctionSpace(), |
459 |
jfenwick |
2625 |
arg("expanded")=false), |
460 |
|
|
"Construct a Data object containing rank4 data-points.\n\n:param value: scalar value for all points\n" |
461 |
|
|
"\n:rtype: `Data`\n:type value: float\n:param what: FunctionSpace for Data\n:type what: `FunctionSpace`\n" |
462 |
|
|
":param expanded: If True, a value is stored for each point. If False, more efficient representations may be used\n" |
463 |
|
|
":type expanded: ``bool``" |
464 |
|
|
); |
465 |
jgs |
102 |
|
466 |
|
|
// |
467 |
ksteube |
813 |
// Binary operators |
468 |
|
|
// |
469 |
|
|
def("C_GeneralTensorProduct",escript::C_GeneralTensorProduct, |
470 |
jfenwick |
2626 |
(arg("arg0"), |
471 |
|
|
arg("arg1"), |
472 |
ksteube |
813 |
arg("axis_offset")=0, |
473 |
jfenwick |
2625 |
arg("transpose")=0), |
474 |
|
|
"Compute a tensor product of two Data objects.\n\n:rtype: `Data`\n:param arg0:\n" |
475 |
|
|
":param arg1:\n:param axis_offset:\n:type axis_offset: ``int``\n" |
476 |
|
|
":param transpose: 0: transpose neither, 1: transpose arg0, 2: transpose arg1\n" |
477 |
|
|
":type transpose: int"); |
478 |
ksteube |
813 |
|
479 |
|
|
// |
480 |
jgs |
102 |
// Interface for AbstractSystemMatrix |
481 |
|
|
// |
482 |
jfenwick |
2061 |
class_<escript::AbstractSystemMatrix>("Operator","",init<>()) // Doco goes in the empty string param |
483 |
jfenwick |
2625 |
.def("isEmpty",&escript::AbstractSystemMatrix::isEmpty,":rtype: ``bool``\n" |
484 |
|
|
":return: True if matrix is empty") |
485 |
|
|
.def("solve",&escript::AbstractSystemMatrix::solve, args("in","options"), |
486 |
|
|
":return: the solution *u* of the linear system *this*u=in*\n\n:param in:\n:type in: `Data`") |
487 |
|
|
.def("of",&escript::AbstractSystemMatrix::vectorMultiply,args("right"), |
488 |
|
|
"matrix*vector multiplication") |
489 |
|
|
.def("saveMM",&escript::AbstractSystemMatrix::saveMM, args("fileName"), |
490 |
|
|
"writes the matrix to a file using the Matrix Market file format") |
491 |
|
|
.def("saveHB",&escript::AbstractSystemMatrix::saveHB, args("filename"), |
492 |
|
|
"writes the matrix to a file using the Harwell-Boeing file format") |
493 |
|
|
.def("resetValues",&escript::AbstractSystemMatrix::resetValues, "resets the matrix entries") |
494 |
jgs |
102 |
.def(self*other<escript::Data>()); |
495 |
gross |
1364 |
// |
496 |
|
|
// Interface for AbstractTransportProblem |
497 |
|
|
// |
498 |
jfenwick |
2061 |
class_<escript::AbstractTransportProblem>("TransportProblem","",init<>()) // Doco goes in the empty string param |
499 |
jfenwick |
2625 |
.def("isEmpty",&escript::AbstractTransportProblem::isEmpty,":rtype: ``int``") |
500 |
|
|
.def("solve",&escript::AbstractTransportProblem::solve, args("source","dt", "options"), |
501 |
|
|
"returns the solution *u* for a time step *dt>0*\n\n:rtype: `Data`\n" |
502 |
|
|
":param source:\n:type source: `Data`") |
503 |
|
|
.def("setInitialValue",&escript::AbstractTransportProblem::setInitialValue, args("u"), |
504 |
|
|
"sets the value for *u* at time *t=0*.") |
505 |
|
|
.def("insertConstraint",&escript::AbstractTransportProblem::insertConstraint, |
506 |
|
|
args("source", "q", "r","factor"), |
507 |
|
|
"inserts constraint *u_{,t}=r* where *q>0* into the problem using a weighting factor") |
508 |
|
|
.def("reset",&escript::AbstractTransportProblem::resetTransport, |
509 |
|
|
"resets the transport operator typically as they have been updated.") |
510 |
gross |
1841 |
.def("resetValues",&escript::AbstractTransportProblem::resetTransport) |
511 |
gross |
1859 |
.def("getSafeTimeStepSize",&escript::AbstractTransportProblem::getSafeTimeStepSize) |
512 |
|
|
.def("getUnlimitedTimeStepSize",&escript::AbstractTransportProblem::getUnlimitedTimeStepSize); |
513 |
jgs |
102 |
|
514 |
jfenwick |
1897 |
// Functions to modify global parameters |
515 |
|
|
def("setEscriptParamInt",escript::setEscriptParamInt, |
516 |
jfenwick |
2625 |
(arg("name"), arg("value")=0), "Modify the value of an escript tuning parameter\n\n" |
517 |
|
|
":param name:\n:type name: ``string``\n:param value:\n:type value: ``int``"); |
518 |
jfenwick |
1897 |
def("getEscriptParamInt",escript::getEscriptParamInt, |
519 |
jfenwick |
2625 |
(arg("name"),arg("sentinel")=0), "Read the value of an escript tuning paramter\n\n" |
520 |
|
|
":param name: parameter to lookup\n:type name: ``string``\n:param sentinel: Value to be returned if ``name`` is not a known parameter\n" |
521 |
|
|
":type sentinel: ``int``"); |
522 |
|
|
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."); |
523 |
jfenwick |
1897 |
|
524 |
jgs |
102 |
// |
525 |
|
|
// Register esysExceptionTranslator |
526 |
|
|
// |
527 |
|
|
register_exception_translator<esysUtils::EsysException>(&esysUtils::esysExceptionTranslator); |
528 |
|
|
} |