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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3780 - (show annotations)
Mon Jan 23 06:26:40 2012 UTC (7 years, 2 months ago) by caltinay
Original Path: branches/ripleygmg_from_3668/ripley/src/ripleycpp.cpp
File size: 10189 byte(s)
Removed addPDEToLumpedSystem() as it is handled at python level.
Ensured tests for setX() don't fail if unsupported.

1
2 /*******************************************************
3 *
4 * Copyright (c) 2003-2011 by University of Queensland
5 * 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 #include <ripley/Brick.h>
15 #include <ripley/Rectangle.h>
16 #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 namespace ripley {
27
28 // These wrappers are required to make the shared pointers work through the
29 // Python wrapper
30
31 escript::Domain_ptr _brick(int n0, int n1, int n2, double l0, double l1, double l2, int d0, int d1, int d2)
32 {
33 return escript::Domain_ptr(new Brick(n0, n1, n2, l0, l1, l2, d0, d1, d2));
34 }
35
36 escript::Domain_ptr _rectangle(int n0, int n1, double l0, double l1, int d0, int d1)
37 {
38 return escript::Domain_ptr(new Rectangle(n0, n1, l0, l1, d0, d1));
39 }
40
41 }
42
43 /**
44 \page ripley Ripley
45 Ripley is the python module name that contains the interfaces
46 to the C++ wrapper to ripley.
47 */
48
49 BOOST_PYTHON_MODULE(ripleycpp)
50 {
51 // This feature was added in boost v1.34
52 #if ((BOOST_VERSION/100)%1000 > 34) || (BOOST_VERSION/100000 >1)
53 // params are: bool show_user_defined, bool show_py_signatures, bool show_cpp_signatures
54 docstring_options docopt(true, true, false);
55 #endif
56
57 register_exception_translator<ripley::RipleyException>(&(esysUtils::esysExceptionTranslator));
58
59 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),
60 "Creates a hexagonal mesh with n0 x n1 x n2 elements over the brick [0,l0] x [0,l1] x [0,l2].\n\n"
61 ":param n0: number of elements in direction 0\n:type n0: ``int``\n"
62 ":param n1: number of elements in direction 1\n:type n1: ``int``\n"
63 ":param n2: number of elements in direction 2\n:type n2: ``int``\n"
64 ":param l0: length of side 0\n:type l0: ``float``\n"
65 ":param l1: length of side 1\n:type l1: ``float``\n"
66 ":param l2: length of side 2\n:type l2: ``float``\n"
67 ":param d0: number of subdivisions in direction 0\n:type d0: ``int``\n"
68 ":param d1: number of subdivisions in direction 1\n:type d1: ``int``\n"
69 ":param d2: number of subdivisions in direction 2\n:type d2: ``int``");
70
71 def("Rectangle", ripley::_rectangle, (arg("n0"),arg("n1"),arg("l0")=1.0,arg("l1")=1.0,arg("d0")=1,arg("d1")=1),
72 "Creates a rectangular mesh with n0 x n1 elements over the rectangle [0,l0] x [0,l1].\n\n"
73 ":param n0: number of elements in direction 0\n:type n0: ``int``\n"
74 ":param n1: number of elements in direction 1\n:type n1: ``int``\n"
75 ":param l0: length of side 0\n:type l0: ``float``\n"
76 ":param l1: length of side 1\n:type l1: ``float``\n"
77 ":param d0: number of subdivisions in direction 0\n:type d0: ``int``\n"
78 ":param d1: number of subdivisions in direction 1\n:type d1: ``int``");
79
80 def("LoadMesh", ripley::RipleyDomain::loadMesh, (arg("filename")),
81 "Loads a ripley domain from a dump file" ":rtype: `Domain`");
82
83 def("ReadMesh", ripley::RipleyDomain::readMesh, (arg("filename")),
84 "Reads a ripley domain from a file created by write().\n\n"
85 ":rtype: `RipleyDomain`\n:param filename:\n:type filename: ``string``\n");
86
87 class_<ripley::RipleyDomain, bases<escript::AbstractContinuousDomain> >
88 ("RipleyDomain", "", no_init)
89 .def("write", &ripley::RipleyDomain::write, args("filename"),
90 "Writes the current mesh to a file with the given name. It can subsequently be recovered using ReadMesh().")
91 .def("print_mesh_info", &ripley::RipleyDomain::Print_Mesh_Info, (arg("full")=false),
92 "Prints out a summary about the mesh.\n"
93 ":param full: whether to output additional data\n:type full: ``bool``")
94 .def("dump", &ripley::RipleyDomain::dump, args("filename"),
95 "Dumps the mesh to a file with the given name.")
96 .def("getDescription", &ripley::RipleyDomain::getDescription,
97 ":return: a description for this domain\n:rtype: ``string``")
98 .def("getDim", &ripley::RipleyDomain::getDim, ":rtype: ``int``")
99 .def("getDataShape", &ripley::RipleyDomain::getDataShape, args("functionSpaceCode"),
100 ":return: a pair (dps, ns) where dps=the number of data points per sample, and ns=the number of samples\n:rtype: ``tuple``")
101 .def("getNumDataPointsGlobal", &ripley::RipleyDomain::getNumDataPointsGlobal,
102 ":return: the number of data points summed across all MPI processes\n"
103 ":rtype: ``int``")
104 .def("addPDEToSystem",&ripley::RipleyDomain::addPDEToSystem,
105 args("mat", "rhs", "A", "B", "C", "D", "X", "Y", "d", "y", "d_contact", "y_contact"),
106 "adds a PDE onto the stiffness matrix mat and a rhs\n\n"
107 ":param mat:\n:type mat: `OperatorAdapter`\n:param rhs:\n:type rhs: `Data`\n"
108 ":param A:\n:type A: `Data`\n"
109 ":param B:\n:type B: `Data`\n"
110 ":param C:\n:type C: `Data`\n"
111 ":param D:\n:type D: `Data`\n"
112 ":param X:\n:type X: `Data`\n"
113 ":param Y:\n:type Y: `Data`\n"
114 ":param d:\n:type d: `Data`\n"
115 ":param d_contact:\n:type d_contact: `Data`\n"
116 ":param y_contact:\n:type y_contact: `Data`\n"
117 )
118 .def("addPDEToRHS",&ripley::RipleyDomain::addPDEToRHS,
119 args("rhs", "X", "Y", "y", "y_contact"),
120 "adds a PDE onto the stiffness matrix mat and a rhs\n\n"
121 ":param rhs:\n:type rhs: `Data`\n"
122 ":param X:\n:type X: `Data`\n"
123 ":param Y:\n:type Y: `Data`\n"
124 ":param y:\n:type y: `Data`\n"
125 ":param y_contact:\n:type y_contact: `Data`"
126 )
127 .def("addPDEToTransportProblem",&ripley::RipleyDomain::addPDEToTransportProblem,
128 args( "tp", "source", "M", "A", "B", "C", "D", "X", "Y", "d", "y", "d_contact", "y_contact"),
129 ":param tp:\n:type tp: `TransportProblemAdapter`\n"
130 ":param source:\n:type source: `Data`\n"
131 ":param M:\n:type M: `Data`\n"
132 ":param A:\n:type A: `Data`\n"
133 ":param B:\n:type B: `Data`\n"
134 ":param C:\n:type C: `Data`\n"
135 ":param D:\n:type D: `Data`\n"
136 ":param X:\n:type X: `Data`\n"
137 ":param Y:\n:type Y: `Data`\n"
138 ":param d:\n:type d: `Data`\n"
139 ":param y:\n:type y: `Data`\n"
140 ":param d_contact:\n:type d_contact: `Data`\n"
141 ":param y_contact:\n:type y_contact: `Data`\n"
142 )
143 .def("newOperator",&ripley::RipleyDomain::newSystemMatrix,
144 args("row_blocksize", "row_functionspace", "column_blocksize", "column_functionspace", "type"),
145 "creates a SystemMatrixAdapter stiffness matrix and initializes it with zeros\n\n"
146 ":param row_blocksize:\n:type row_blocksize: ``int``\n"
147 ":param row_functionspace:\n:type row_functionspace: `FunctionSpace`\n"
148 ":param column_blocksize:\n:type column_blocksize: ``int``\n"
149 ":param column_functionspace:\n:type column_functionspace: `FunctionSpace`\n"
150 ":param type:\n:type type: ``int``\n"
151 )
152 .def("newTransportProblem",&ripley::RipleyDomain::newTransportProblem,
153 args("theta", "blocksize", "functionspace", "type"),
154 "creates a TransportProblemAdapter\n\n"
155 ":param theta:\n:type theta: ``float``\n"
156 ":param blocksize:\n:type blocksize: ``int``\n"
157 ":param functionspace:\n:type functionspace: `FunctionSpace`\n"
158 ":param type:\n:type type: ``int``\n"
159 )
160 .def("getSystemMatrixTypeId",&ripley::RipleyDomain::getSystemMatrixTypeId,
161 args("solver", "preconditioner", "package", "symmetry"),
162 ":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"
163 ":rtype: ``int``\n"
164 ":param solver:\n:type solver: ``int``\n"
165 ":param preconditioner:\n:type preconditioner: ``int``\n"
166 ":param package:\n:type package: ``int``\n"
167 ":param symmetry:\n:type symmetry: ``int``\n"
168 )
169 .def("getTransportTypeId",&ripley::RipleyDomain::getTransportTypeId,
170 args("solver", "preconditioner", "package", "symmetry"),
171 ":return: the identifier of the transport problem type to be used when a particular solver, preconditioner, package and symmetric matrix is used.\n"
172 ":rtype: ``int``\n"
173 ":param solver:\n:type solver: ``int``\n"
174 ":param preconditioner:\n:type preconditioner: ``int``\n"
175 ":param package:\n:type package: ``int``\n"
176 ":param symmetry:\n:type symmetry: ``int``\n"
177 )
178 // .def("setX",&ripley::RipleyDomain::setNewX,
179 //args("arg"), "assigns new location to the domain\n\n:param arg:\n:type arg: `Data`")
180 .def("getX",&ripley::RipleyDomain::getX, ":return: locations in the FEM nodes\n\n"
181 ":rtype: `Data`")
182 .def("getNormal",&ripley::RipleyDomain::getNormal,
183 ":return: boundary normals at the quadrature point on the face elements\n"
184 ":rtype: `Data`")
185 .def("getSize",&ripley::RipleyDomain::getSize,":return: the element size\n"
186 ":rtype: `Data`")
187 .def("setTagMap",&ripley::RipleyDomain::setTagMap,args("name","tag"),
188 "Give a tag number a name.\n\n:param name: Name for the tag\n:type name: ``string``\n"
189 ":param tag: numeric id\n:type tag: ``int``\n:note: Tag names must be unique within a domain")
190 .def("getTag",&ripley::RipleyDomain::getTag,args("name"),":return: tag id for "
191 "``name``\n:rtype: ``string``")
192 .def("isValidTagName",&ripley::RipleyDomain::isValidTagName,args("name"),
193 ":return: True if ``name`` corresponds to a tag, otherwise False\n:rtype: ``bool``")
194 .def("showTagNames",&ripley::RipleyDomain::showTagNames,":return: A space separated list of tag names\n:rtype: ``string``")
195 .def("getMPISize",&ripley::RipleyDomain::getMPISize,":return: the number of processes used for this `Domain`\n:rtype: ``int``")
196 .def("getMPIRank",&ripley::RipleyDomain::getMPIRank,":return: the rank of this process\n:rtype: ``int``")
197 .def("MPIBarrier",&ripley::RipleyDomain::MPIBarrier,"Wait until all processes have reached this point")
198 .def("onMasterProcessor",&ripley::RipleyDomain::onMasterProcessor,":return: True if this code is executing on the master process\n:rtype: `bool`");
199
200 class_<ripley::Brick, bases<ripley::RipleyDomain> >("RipleyBrick", "", no_init);
201
202 class_<ripley::Rectangle, bases<ripley::RipleyDomain> >("RipleyRectangle", "", no_init);
203
204 }
205

  ViewVC Help
Powered by ViewVC 1.1.26