/[escript]/trunk/ripley/src/ripleycpp.cpp
ViewVC logotype

Annotation of /trunk/ripley/src/ripleycpp.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3892 - (hide annotations)
Tue Apr 10 08:57:23 2012 UTC (7 years ago) by jfenwick
File size: 13012 byte(s)
Merged changes across from the attempt2 branch.
This version builds and passes python2 tests.
It also passes most python3 tests.



1 caltinay 3670
2     /*******************************************************
3     *
4 caltinay 3781 * Copyright (c) 2003-2012 by University of Queensland
5 caltinay 3670 * 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    
14 caltinay 3691 #include <ripley/Brick.h>
15     #include <ripley/Rectangle.h>
16 caltinay 3670 #include <esysUtils/esysExceptionTranslator.h>
17    
18     #include <boost/python.hpp>
19     #include <boost/python/module.hpp>
20     #include <boost/python/def.hpp>
21     #include <boost/python/detail/defaults_gen.hpp>
22     #include <boost/version.hpp>
23    
24     using namespace boost::python;
25    
26 caltinay 3691 namespace ripley {
27 caltinay 3670
28 caltinay 3691 // These wrappers are required to make the shared pointers work through the
29     // Python wrapper
30 caltinay 3670
31 jfenwick 3892 // The double for n? is just to keep python happy when people need to deal with
32     // trudiv
33     escript::Domain_ptr _brick(double _n0, double _n1, double _n2, const object& l0,
34 caltinay 3781 const object& l1, const object& l2, int d0, int d1, int d2)
35 caltinay 3691 {
36 jfenwick 3892 int n0=static_cast<int>(_n0), n1=static_cast<int>(_n1), n2=static_cast<int>(_n2);
37 caltinay 3781 double x0=0., x1=1., y0=0., y1=1., z0=0., z1=1.;
38     if (extract<tuple>(l0).check()) {
39     tuple x=extract<tuple>(l0);
40     if (len(x)==2) {
41     x0=extract<double>(x[0]);
42     x1=extract<double>(x[1]);
43     } else
44     throw RipleyException("Argument l0 must be a float or 2-tuple");
45     } else if (extract<double>(l0).check()) {
46     x1=extract<double>(l0);
47     } else
48     throw RipleyException("Argument l0 must be a float or 2-tuple");
49    
50     if (extract<tuple>(l1).check()) {
51     tuple y=extract<tuple>(l1);
52     if (len(y)==2) {
53     y0=extract<double>(y[0]);
54     y1=extract<double>(y[1]);
55     } else
56     throw RipleyException("Argument l1 must be a float or 2-tuple");
57     } else if (extract<double>(l1).check()) {
58     y1=extract<double>(l1);
59     } else
60     throw RipleyException("Argument l1 must be a float or 2-tuple");
61    
62     if (extract<tuple>(l2).check()) {
63     tuple z=extract<tuple>(l2);
64     if (len(z)==2) {
65     z0=extract<double>(z[0]);
66     z1=extract<double>(z[1]);
67     } else
68     throw RipleyException("Argument l2 must be a float or 2-tuple");
69     } else if (extract<double>(l2).check()) {
70     z1=extract<double>(l2);
71     } else
72     throw RipleyException("Argument l2 must be a float or 2-tuple");
73    
74 caltinay 3791 return escript::Domain_ptr(new Brick(n0,n1,n2, x0,y0,z0, x1,y1,z1, d0,d1,d2));
75 caltinay 3691 }
76 caltinay 3670
77 caltinay 3791 const int _q[]={0x61686969,0x746c4144,0x79616e43};
78 jfenwick 3892 escript::Domain_ptr _rectangle(double _n0, double _n1, const object& l0,
79 caltinay 3781 const object& l1, int d0, int d1)
80 caltinay 3691 {
81 jfenwick 3892 int n0=static_cast<int>(_n0), n1=static_cast<int>(_n1);
82 caltinay 3781 double x0=0., x1=1., y0=0., y1=1.;
83     if (extract<tuple>(l0).check()) {
84     tuple x=extract<tuple>(l0);
85     if (len(x)==2) {
86     x0=extract<double>(x[0]);
87     x1=extract<double>(x[1]);
88     } else
89     throw RipleyException("Argument l0 must be a float or 2-tuple");
90     } else if (extract<double>(l0).check()) {
91     x1=extract<double>(l0);
92     } else
93     throw RipleyException("Argument l0 must be a float or 2-tuple");
94    
95     if (extract<tuple>(l1).check()) {
96     tuple y=extract<tuple>(l1);
97     if (len(y)==2) {
98     y0=extract<double>(y[0]);
99     y1=extract<double>(y[1]);
100     } else
101     throw RipleyException("Argument l1 must be a float or 2-tuple");
102     } else if (extract<double>(l1).check()) {
103     y1=extract<double>(l1);
104     } else
105     throw RipleyException("Argument l1 must be a float or 2-tuple");
106    
107 caltinay 3791 return escript::Domain_ptr(new Rectangle(n0,n1, x0,y0, x1,y1, d0,d1));
108 caltinay 3691 }
109 caltinay 3791 std::string _who(){int a[]={_q[0]^42,_q[1]^42,_q[2]^42,0};return (char*)&a[0];}
110 caltinay 3670
111 caltinay 3691 }
112 caltinay 3670
113 caltinay 3691 /**
114     \page ripley Ripley
115 caltinay 3791 ripleycpp is the python module name that contains the interfaces
116 caltinay 3691 to the C++ wrapper to ripley.
117 caltinay 3670 */
118    
119     BOOST_PYTHON_MODULE(ripleycpp)
120     {
121     // This feature was added in boost v1.34
122     #if ((BOOST_VERSION/100)%1000 > 34) || (BOOST_VERSION/100000 >1)
123 caltinay 3691 // params are: bool show_user_defined, bool show_py_signatures, bool show_cpp_signatures
124     docstring_options docopt(true, true, false);
125 caltinay 3670 #endif
126    
127 caltinay 3691 register_exception_translator<ripley::RipleyException>(&(esysUtils::esysExceptionTranslator));
128 caltinay 3670
129 caltinay 3691 def("Brick", ripley::_brick, (arg("n0"),arg("n1"),arg("n2"),arg("l0")=1.0,arg("l1")=1.0,arg("l2")=1.0,arg("d0")=1,arg("d1")=1,arg("d2")=1),
130     "Creates a hexagonal mesh with n0 x n1 x n2 elements over the brick [0,l0] x [0,l1] x [0,l2].\n\n"
131     ":param n0: number of elements in direction 0\n:type n0: ``int``\n"
132     ":param n1: number of elements in direction 1\n:type n1: ``int``\n"
133     ":param n2: number of elements in direction 2\n:type n2: ``int``\n"
134 caltinay 3781 ":param l0: length of side 0 or coordinate range of side 0\n:type l0: ``float`` or ``tuple``\n"
135     ":param l1: length of side 1 or coordinate range of side 1\n:type l1: ``float`` or ``tuple``\n"
136     ":param l2: length of side 2 or coordinate range of side 2\n:type l2: ``float`` or ``tuple``\n"
137 caltinay 3691 ":param d0: number of subdivisions in direction 0\n:type d0: ``int``\n"
138     ":param d1: number of subdivisions in direction 1\n:type d1: ``int``\n"
139     ":param d2: number of subdivisions in direction 2\n:type d2: ``int``");
140 caltinay 3670
141 caltinay 3691 def("Rectangle", ripley::_rectangle, (arg("n0"),arg("n1"),arg("l0")=1.0,arg("l1")=1.0,arg("d0")=1,arg("d1")=1),
142     "Creates a rectangular mesh with n0 x n1 elements over the rectangle [0,l0] x [0,l1].\n\n"
143     ":param n0: number of elements in direction 0\n:type n0: ``int``\n"
144     ":param n1: number of elements in direction 1\n:type n1: ``int``\n"
145 caltinay 3781 ":param l0: length of side 0 or coordinate range of side 0\n:type l0: ``float`` or ``tuple``\n"
146     ":param l1: length of side 1 or coordinate range of side 1\n:type l1: ``float`` or ``tuple``\n"
147 caltinay 3691 ":param d0: number of subdivisions in direction 0\n:type d0: ``int``\n"
148     ":param d1: number of subdivisions in direction 1\n:type d1: ``int``");
149 caltinay 3791 def("_theculprit_", ripley::_who),
150 caltinay 3691 def("LoadMesh", ripley::RipleyDomain::loadMesh, (arg("filename")),
151     "Loads a ripley domain from a dump file" ":rtype: `Domain`");
152 caltinay 3670
153 caltinay 3691 def("ReadMesh", ripley::RipleyDomain::readMesh, (arg("filename")),
154     "Reads a ripley domain from a file created by write().\n\n"
155     ":rtype: `RipleyDomain`\n:param filename:\n:type filename: ``string``\n");
156 caltinay 3670
157 caltinay 3691 class_<ripley::RipleyDomain, bases<escript::AbstractContinuousDomain> >
158     ("RipleyDomain", "", no_init)
159     .def("write", &ripley::RipleyDomain::write, args("filename"),
160     "Writes the current mesh to a file with the given name. It can subsequently be recovered using ReadMesh().")
161     .def("print_mesh_info", &ripley::RipleyDomain::Print_Mesh_Info, (arg("full")=false),
162     "Prints out a summary about the mesh.\n"
163     ":param full: whether to output additional data\n:type full: ``bool``")
164     .def("dump", &ripley::RipleyDomain::dump, args("filename"),
165     "Dumps the mesh to a file with the given name.")
166     .def("getDescription", &ripley::RipleyDomain::getDescription,
167 caltinay 3670 ":return: a description for this domain\n:rtype: ``string``")
168 caltinay 3691 .def("getDim", &ripley::RipleyDomain::getDim, ":rtype: ``int``")
169     .def("getDataShape", &ripley::RipleyDomain::getDataShape, args("functionSpaceCode"),
170 caltinay 3670 ":return: a pair (dps, ns) where dps=the number of data points per sample, and ns=the number of samples\n:rtype: ``tuple``")
171 caltinay 3691 .def("getNumDataPointsGlobal", &ripley::RipleyDomain::getNumDataPointsGlobal,
172 caltinay 3670 ":return: the number of data points summed across all MPI processes\n"
173     ":rtype: ``int``")
174 caltinay 3691 .def("addPDEToSystem",&ripley::RipleyDomain::addPDEToSystem,
175     args("mat", "rhs", "A", "B", "C", "D", "X", "Y", "d", "y", "d_contact", "y_contact"),
176 caltinay 3670 "adds a PDE onto the stiffness matrix mat and a rhs\n\n"
177     ":param mat:\n:type mat: `OperatorAdapter`\n:param rhs:\n:type rhs: `Data`\n"
178     ":param A:\n:type A: `Data`\n"
179     ":param B:\n:type B: `Data`\n"
180     ":param C:\n:type C: `Data`\n"
181     ":param D:\n:type D: `Data`\n"
182     ":param X:\n:type X: `Data`\n"
183     ":param Y:\n:type Y: `Data`\n"
184     ":param d:\n:type d: `Data`\n"
185     ":param d_contact:\n:type d_contact: `Data`\n"
186 caltinay 3791 ":param y_contact:\n:type y_contact: `Data`"
187 caltinay 3670 )
188 caltinay 3691 .def("addPDEToRHS",&ripley::RipleyDomain::addPDEToRHS,
189 caltinay 3670 args("rhs", "X", "Y", "y", "y_contact"),
190     "adds a PDE onto the stiffness matrix mat and a rhs\n\n"
191     ":param rhs:\n:type rhs: `Data`\n"
192     ":param X:\n:type X: `Data`\n"
193     ":param Y:\n:type Y: `Data`\n"
194     ":param y:\n:type y: `Data`\n"
195     ":param y_contact:\n:type y_contact: `Data`"
196     )
197 caltinay 3691 .def("addPDEToTransportProblem",&ripley::RipleyDomain::addPDEToTransportProblem,
198 caltinay 3670 args( "tp", "source", "M", "A", "B", "C", "D", "X", "Y", "d", "y", "d_contact", "y_contact"),
199     ":param tp:\n:type tp: `TransportProblemAdapter`\n"
200     ":param source:\n:type source: `Data`\n"
201     ":param M:\n:type M: `Data`\n"
202     ":param A:\n:type A: `Data`\n"
203     ":param B:\n:type B: `Data`\n"
204     ":param C:\n:type C: `Data`\n"
205     ":param D:\n:type D: `Data`\n"
206     ":param X:\n:type X: `Data`\n"
207     ":param Y:\n:type Y: `Data`\n"
208     ":param d:\n:type d: `Data`\n"
209     ":param y:\n:type y: `Data`\n"
210     ":param d_contact:\n:type d_contact: `Data`\n"
211 caltinay 3791 ":param y_contact:\n:type y_contact: `Data`"
212 caltinay 3670 )
213 caltinay 3691 .def("newOperator",&ripley::RipleyDomain::newSystemMatrix,
214 caltinay 3670 args("row_blocksize", "row_functionspace", "column_blocksize", "column_functionspace", "type"),
215     "creates a SystemMatrixAdapter stiffness matrix and initializes it with zeros\n\n"
216     ":param row_blocksize:\n:type row_blocksize: ``int``\n"
217     ":param row_functionspace:\n:type row_functionspace: `FunctionSpace`\n"
218     ":param column_blocksize:\n:type column_blocksize: ``int``\n"
219     ":param column_functionspace:\n:type column_functionspace: `FunctionSpace`\n"
220 caltinay 3791 ":param type:\n:type type: ``int``"
221 caltinay 3670 )
222 caltinay 3691 .def("newTransportProblem",&ripley::RipleyDomain::newTransportProblem,
223 caltinay 3670 args("theta", "blocksize", "functionspace", "type"),
224     "creates a TransportProblemAdapter\n\n"
225     ":param theta:\n:type theta: ``float``\n"
226     ":param blocksize:\n:type blocksize: ``int``\n"
227     ":param functionspace:\n:type functionspace: `FunctionSpace`\n"
228 caltinay 3791 ":param type:\n:type type: ``int``"
229 caltinay 3670 )
230 caltinay 3691 .def("getSystemMatrixTypeId",&ripley::RipleyDomain::getSystemMatrixTypeId,
231 caltinay 3670 args("solver", "preconditioner", "package", "symmetry"),
232 caltinay 3697 ":return: the identifier of the matrix type to be used for the global stiffness matrix when a particular solver, package, preconditioner, and symmetric matrix is used.\n"
233 caltinay 3670 ":rtype: ``int``\n"
234     ":param solver:\n:type solver: ``int``\n"
235     ":param preconditioner:\n:type preconditioner: ``int``\n"
236     ":param package:\n:type package: ``int``\n"
237 caltinay 3791 ":param symmetry:\n:type symmetry: ``int``"
238 caltinay 3670 )
239 caltinay 3691 .def("getTransportTypeId",&ripley::RipleyDomain::getTransportTypeId,
240 caltinay 3670 args("solver", "preconditioner", "package", "symmetry"),
241 caltinay 3697 ":return: the identifier of the transport problem type to be used when a particular solver, preconditioner, package and symmetric matrix is used.\n"
242 caltinay 3670 ":rtype: ``int``\n"
243     ":param solver:\n:type solver: ``int``\n"
244     ":param preconditioner:\n:type preconditioner: ``int``\n"
245     ":param package:\n:type package: ``int``\n"
246 caltinay 3791 ":param symmetry:\n:type symmetry: ``int``"
247 caltinay 3670 )
248 caltinay 3691 .def("getX",&ripley::RipleyDomain::getX, ":return: locations in the FEM nodes\n\n"
249 caltinay 3670 ":rtype: `Data`")
250 caltinay 3691 .def("getNormal",&ripley::RipleyDomain::getNormal,
251 caltinay 3670 ":return: boundary normals at the quadrature point on the face elements\n"
252     ":rtype: `Data`")
253 caltinay 3691 .def("getSize",&ripley::RipleyDomain::getSize,":return: the element size\n"
254 caltinay 3670 ":rtype: `Data`")
255 caltinay 3691 .def("setTagMap",&ripley::RipleyDomain::setTagMap,args("name","tag"),
256 caltinay 3670 "Give a tag number a name.\n\n:param name: Name for the tag\n:type name: ``string``\n"
257     ":param tag: numeric id\n:type tag: ``int``\n:note: Tag names must be unique within a domain")
258 caltinay 3691 .def("getTag",&ripley::RipleyDomain::getTag,args("name"),":return: tag id for "
259 caltinay 3670 "``name``\n:rtype: ``string``")
260 caltinay 3691 .def("isValidTagName",&ripley::RipleyDomain::isValidTagName,args("name"),
261     ":return: True if ``name`` corresponds to a tag, otherwise False\n:rtype: ``bool``")
262     .def("showTagNames",&ripley::RipleyDomain::showTagNames,":return: A space separated list of tag names\n:rtype: ``string``")
263     .def("getMPISize",&ripley::RipleyDomain::getMPISize,":return: the number of processes used for this `Domain`\n:rtype: ``int``")
264     .def("getMPIRank",&ripley::RipleyDomain::getMPIRank,":return: the rank of this process\n:rtype: ``int``")
265     .def("MPIBarrier",&ripley::RipleyDomain::MPIBarrier,"Wait until all processes have reached this point")
266     .def("onMasterProcessor",&ripley::RipleyDomain::onMasterProcessor,":return: True if this code is executing on the master process\n:rtype: `bool`");
267 caltinay 3670
268 caltinay 3691 class_<ripley::Brick, bases<ripley::RipleyDomain> >("RipleyBrick", "", no_init);
269     class_<ripley::Rectangle, bases<ripley::RipleyDomain> >("RipleyRectangle", "", no_init);
270 caltinay 3670 }
271    

  ViewVC Help
Powered by ViewVC 1.1.26