/[escript]/branches/trilinos_from_5897/finley/src/CPPAdapter/finleycpp.cpp
ViewVC logotype

Contents of /branches/trilinos_from_5897/finley/src/CPPAdapter/finleycpp.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5933 - (show annotations)
Wed Feb 17 23:53:30 2016 UTC (21 months, 4 weeks ago) by caltinay
File size: 14772 byte(s)
sync with trunk.

1
2 /*****************************************************************************
3 *
4 * Copyright (c) 2003-2016 by The 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 2012-2013 by School of Earth Sciences
13 * Development from 2014 by Centre for Geoscience Computing (GeoComp)
14 *
15 *****************************************************************************/
16
17 #define ESNEEDPYTHON
18 #include "esysUtils/first.h"
19
20 #include "esysUtils/Esys_MPI.h"
21 #include "../Finley.h"
22
23 #include "MeshAdapter.h"
24 #include "MeshAdapterFactory.h"
25
26 #include "FinleyAdapterException.h"
27 #include "esysUtils/esysExceptionTranslator.h"
28 #include "escript/AbstractContinuousDomain.h"
29
30 #include <boost/python.hpp>
31 #include <boost/python/module.hpp>
32 #include <boost/python/def.hpp>
33 #include <boost/python/detail/defaults_gen.hpp>
34 #include <boost/version.hpp>
35
36 using namespace boost::python;
37
38 BOOST_PYTHON_MODULE(finleycpp)
39 {
40 // This feature was added in boost v1.34
41 #if ((BOOST_VERSION/100)%1000 > 34) || (BOOST_VERSION/100000 >1)
42 // params are: bool show_user_defined, bool show_py_signatures, bool show_cpp_signatures
43 docstring_options docopt(true, true, false);
44 #endif
45
46 scope().attr("__doc__") = "To use this module, please import esys.finley";
47
48
49 //
50 // NOTE: The return_value_policy is necessary for functions that
51 // return pointers.
52 //
53 register_exception_translator<finley::FinleyAdapterException>(&(esysUtils::RuntimeErrorTranslator));
54
55 def("LoadMesh",finley::loadMesh,
56 (arg("fileName")="file.nc"),":rtype: `Domain`"
57 /* ,return_value_policy<manage_new_object>());*/
58 );
59
60
61 def("__ReadMesh_driver", finley::readMesh_driver,
62 (arg("params"))
63 // def("ReadMesh",finley::readMesh,
64 // (arg("fileName")="file.fly",arg("integrationOrder")=-1, arg("reducedIntegrationOrder")=-1, arg("optimize")=true)
65 ,"Read a mesh from a file. For MPI parallel runs fan out the mesh to multiple processes.\n\n"
66 ":rtype: `Domain`\n:param fileName:\n:type fileName: ``string``\n"
67 ":param integrationOrder: order of the quadrature scheme. If *integrationOrder<0* the integration order is selected independently.\n"
68 ":type integrationOrder: ``int``\n"
69 ":param reducedIntegrationOrder: order of the quadrature scheme. If *reducedIntegrationOrder<0* the integration order is selected independently.\n"
70 ":param optimize: Enable optimisation of node labels\n:type optimize: ``bool``");
71
72 def("__ReadGmsh_driver", finley::readGmsh_driver,
73 (arg("params"))
74 // def("ReadGmsh",finley::readGmsh,
75 // (arg("fileName")="file.msh",
76 // arg("numDim"),
77 // arg("integrationOrder")=-1,
78 // arg("reducedIntegrationOrder")=-1,
79 // arg("optimize")=true,
80 // arg("useMacroElements")=false)
81 ,"Read a gmsh mesh file\n\n"
82 ":rtype: `Domain`\n:param fileName:\n:type fileName: ``string``\n"
83 ":param integrationOrder: order of the quadrature scheme. If *integrationOrder<0* the integration order is selected independently.\n"
84 ":type integrationOrder: ``int``\n"
85 ":param reducedIntegrationOrder: order of the quadrature scheme. If *reducedIntegrationOrder<0* the integration order is selected independently.\n"
86 ":param optimize: Enable optimisation of node labels\n:type optimize: ``bool``\n"
87 ":param useMacroElements: Enable the usage of macro elements instead of second order elements.\n:type useMacroElements: ``bool``"
88 );
89
90 def ("__Brick_driver",finley::brick_driver,
91 (arg("params"))
92 ,"Creates a rectangular mesh with n0 x n1 x n2 elements over the brick [0,l0] x [0,l1] x [0,l2]."
93 "\n\n:param n0: number of elements in direction 0\n:type n0: ``int``\n:param n1: number of elements in direction 1\n:type n1: ``int``\n"
94 ":param n2:number of elements in direction 2\n:type n2: ``int``\n"
95 ":param order: =1, =-1 or =2 gives the order of shape function. If -1 macro elements of order 1 are used.\n"
96 ":param l0: length of side 0\n"
97 ":type l0: ``float``\n"
98 ":param l1: length of side 1\n"
99 ":type l1: ``float``\n"
100 ":param l2: length of side 2\n"
101 ":type l2: ``float``\n"
102 ":param periodic0: whether or not boundary conditions are periodic in direction 0\n:type periodic0: ``bool``\n"
103 ":param periodic1: whether or not boundary conditions are periodic in direction 1\n:type periodic1: ``bool``\n"
104 ":param periodic2: whether or not boundary conditions are periodic in direction 2\n:type periodic2: ``bool``\n"
105 ":param integrationOrder: order of the quadrature scheme. If integrationOrder<0 the integration order is selected independently.\n"
106 ":param reducedIntegrationOrder: order of the quadrature scheme. If reducedIntegrationOrder<0 the integration order is selected independently.\n"
107 ":param useElementsOnFace: whether or not to use elements on face\n"
108 ":type useElementsOnFace: ``int``\n"
109 ":param useFullElementOrder: Whether or not to use Hex27 elements\n"":type useFullElementOrder: ``bool``\n"
110 ":param optimize: Enable optimisation of node labels\n:type optimize: ``bool``"
111 );
112
113 def ("__Rectangle_driver",finley::rectangle_driver,
114 (arg("args"))
115 ,"Creates a rectangular mesh with n0 x n1 elements over the brick [0,l0] x [0,l1]."
116 "\n\n:param n0:\n:type n0:\n:param n1:\n:type n1:\n"
117 ":param order: =1, =-1 or =2 gives the order of shape function. If -1 macro elements of order 1 are used.\n"
118 ":param l0: length of side 0\n:param l1:\n"
119 ":param integrationOrder: order of the quadrature scheme. If integrationOrder<0 the integration order is selected independently.\n"
120 ":param reducedIntegrationOrder: order of the quadrature scheme. If reducedIntegrationOrder<0 the integration order is selected independently.\n"
121 ":param useElementsOnFace: whether or not to use elements on face\n"
122 ":type useElementsOnFace: ``int``"
123 ":param periodic0: whether or not boundary conditions are periodic\n"
124 ":param periodic1:\n"
125 ":param useFullElementOrder: Whether or not to use Rec9 elements\n"":type useFullElementOrder: ``bool``\n"
126 ":param optimize: Enable optimisation of node labels\n:type optimize: ``bool``"
127 );
128
129 def("Merge",finley::meshMerge,args("meshList")
130 ,"Merges a list of meshes into one mesh.\n\n:rtype: `Domain`"
131 );
132
133 def("GlueFaces",finley::glueFaces,
134 (arg("meshList"),arg("safetyFactor")=0.2,
135 arg("tolerance")=1.e-8,
136 arg("optimize")=true)
137 ,"Detects matching faces in the mesh, removes them from the mesh and joins the elements touched by the face elements."
138 );
139
140 def("JoinFaces",finley::joinFaces,
141 (arg("meshList"), arg("safetyFactor")=0.2,
142 arg("tolerance")=1.e-8,
143 arg("optimize")=true)
144 ,"Detects matching faces in the mesh and replaces them by joint elements."
145 );
146
147
148 class_<finley::MeshAdapter, bases<escript::AbstractContinuousDomain> >
149 ("MeshAdapter","A concrete class representing a domain. For more details, please consult the c++ documentation.",init<optional <finley::Mesh*> >())
150 .def(init<const finley::MeshAdapter&>())
151 .def("write",&finley::MeshAdapter::write,args("filename"),
152 "Write the current mesh to a file with the given name.")
153 .def("print_mesh_info",&finley::MeshAdapter::Print_Mesh_Info,(arg("full")=false),
154 ":param full:\n:type full: ``bool``")
155 .def("dump",&finley::MeshAdapter::dump,args("fileName")
156 ,"dumps the mesh to a file with the given name.")
157 .def("getDescription",&finley::MeshAdapter::getDescription,
158 ":return: a description for this domain\n:rtype: ``string``")
159 .def("getDim",&finley::MeshAdapter::getDim,":rtype: ``int``")
160 .def("getDataShape",&finley::MeshAdapter::getDataShape, args("functionSpaceCode"),
161 ":return: a pair (dps, ns) where dps=the number of data points per sample, and ns=the number of samples\n:rtype: ``tuple``")
162 .def("getNumDataPointsGlobal",&finley::MeshAdapter::getNumDataPointsGlobal,
163 ":return: the number of data points summed across all MPI processes\n"
164 ":rtype: ``int``")
165 .def("addPDEToSystem",&finley::MeshAdapter::addPDEToSystem,
166 args("mat", "rhs","A", "B", "C", "D", "X", "Y", "d", "y", "d_contact", "y_contact"),
167 "adds a PDE onto the stiffness matrix mat and a rhs\n\n"
168 ":param mat:\n:type mat: `OperatorAdapter`\n:param rhs:\n:type rhs: `Data`\n"
169 ":param A:\n:type A: `Data`\n"
170 ":param B:\n:type B: `Data`\n"
171 ":param C:\n:type C: `Data`\n"
172 ":param D:\n:type D: `Data`\n"
173 ":param X:\n:type X: `Data`\n"
174 ":param Y:\n:type Y: `Data`\n"
175 ":param d:\n:type d: `Data`\n"
176 ":param d_contact:\n:type d_contact: `Data`\n"
177 ":param y_contact:\n:type y_contact: `Data`\n"
178 )
179 .def("addPDEToLumpedSystem",&finley::MeshAdapter::addPDEToLumpedSystem,
180 args("mat", "D", "d"),
181 "adds a PDE onto the lumped stiffness matrix\n\n"
182 ":param mat:\n:type mat: `Data`\n"
183 ":param D:\n:type D: `Data`\n"
184 ":param d:\n:type d: `Data`\n"
185 ":param useHRZ:\n:type useHRZ: bool\n")
186 .def("addPDEToRHS",&finley::MeshAdapter::addPDEToRHS,
187 args("rhs", "X", "Y", "y", "y_contact"),
188 "adds a PDE onto the stiffness matrix mat and a rhs\n\n"
189 ":param rhs:\n:type rhs: `Data`\n"
190 ":param X:\n:type X: `Data`\n"
191 ":param Y:\n:type Y: `Data`\n"
192 ":param y:\n:type y: `Data`\n"
193 ":param y_contact:\n:type y_contact: `Data`"
194 )
195 .def("addPDEToTransportProblem",&finley::MeshAdapter::addPDEToTransportProblem,
196 args( "tp", "source", "M", "A", "B", "C", "D", "X", "Y", "d", "y", "d_contact", "y_contact"),
197 ":param tp:\n:type tp: `TransportProblem`\n"
198 ":param source:\n:type source: `Data`\n"
199 ":param M:\n:type M: `Data`\n"
200 ":param A:\n:type A: `Data`\n"
201 ":param B:\n:type B: `Data`\n"
202 ":param C:\n:type C: `Data`\n"
203 ":param D:\n:type D: `Data`\n"
204 ":param X:\n:type X: `Data`\n"
205 ":param Y:\n:type Y: `Data`\n"
206 ":param d:\n:type d: `Data`\n"
207 ":param y:\n:type y: `Data`\n"
208 ":param d_contact:\n:type d_contact: `Data`\n"
209 ":param y_contact:\n:type y_contact: `Data`\n"
210 )
211 .def("newOperator",&finley::MeshAdapter::newSystemMatrix,
212 args("row_blocksize", "row_functionspace", "column_blocksize", "column_functionspace", "type"),
213 "creates a stiffness matrix and initializes it with zeros\n\n"
214 ":param row_blocksize:\n:type row_blocksize: ``int``\n"
215 ":param row_functionspace:\n:type row_functionspace: `FunctionSpace`\n"
216 ":param column_blocksize:\n:type column_blocksize: ``int``\n"
217 ":param column_functionspace:\n:type column_functionspace: `FunctionSpace`\n"
218 ":param type:\n:type type: ``int``\n"
219 )
220 .def("newTransportProblem",&finley::MeshAdapter::newTransportProblem,
221 args("theta", "blocksize", "functionspace", "type"),
222 "creates a TransportProblem\n\n"
223 ":param theta:\n:type theta: ``float``\n"
224 ":param blocksize:\n:type blocksize: ``int``\n"
225 ":param functionspace:\n:type functionspace: `FunctionSpace`\n"
226 ":param type:\n:type type: ``int``\n"
227 )
228 .def("getSystemMatrixTypeId",&finley::MeshAdapter::getSystemMatrixTypeId,
229 args("options"),
230 ":return: the identifier of the matrix type to be used for the global stiffness matrix when particular solver options are used.\n"
231 ":rtype: ``int``\n"
232 ":param options:\n:type options: `SolverBuddy`\n"
233 )
234 .def("getTransportTypeId",&finley::MeshAdapter::getTransportTypeId,
235 args("solver", "preconditioner", "package", "symmetry"),
236 ":return: the identifier of the transport problem type to be used when a particular solver, preconditioner, package and symmetric matrix is used.\n"
237 ":rtype: ``int``\n"
238 ":param solver:\n:type solver: ``int``\n"
239 ":param preconditioner:\n:type preconditioner: ``int``\n"
240 ":param package:\n:type package: ``int``\n"
241 ":param symmetry:\n:type symmetry: ``int``\n"
242 )
243 .def("setX",&finley::MeshAdapter::setNewX,
244 args("arg"), "assigns new location to the domain\n\n:param arg:\n:type arg: `Data`")
245 .def("getX",&finley::MeshAdapter::getX, ":return: locations in the FEM nodes\n\n"
246 ":rtype: `Data`")
247 .def("getNormal",&finley::MeshAdapter::getNormal,
248 ":return: boundary normals at the quadrature point on the face elements\n"
249 ":rtype: `Data`")
250 .def("getSize",&finley::MeshAdapter::getSize,":return: the element size\n"
251 ":rtype: `Data`")
252 .def("setTagMap",&finley::MeshAdapter::setTagMap,args("name","tag"),
253 "Give a tag number a name.\n\n:param name: Name for the tag\n:type name: ``string``\n"
254 ":param tag: numeric id\n:type tag: ``int``\n:note: Tag names must be unique within a domain")
255 .def("getTag",&finley::MeshAdapter::getTag,args("name"),":return: tag id for "
256 "``name``\n:rtype: ``string``")
257 .def("isValidTagName",&finley::MeshAdapter::isValidTagName,args("name"),
258 ":return: True is ``name`` corresponds to a tag\n:rtype: ``bool``")
259 .def("showTagNames",&finley::MeshAdapter::showTagNames,":return: A space separated list of tag names\n:rtype: ``string``")
260 .def("getMPISize",&finley::MeshAdapter::getMPISize,":return: the number of processes used for this `Domain`\n:rtype: ``int``")
261 .def("getMPIRank",&finley::MeshAdapter::getMPIRank,":return: the rank of this process\n:rtype: ``int``")
262 .def("MPIBarrier",&finley::MeshAdapter::MPIBarrier,"Wait until all processes have reached this point")
263 .def("onMasterProcessor",&finley::MeshAdapter::onMasterProcessor,":return: True if this code is executing on the master process\n:rtype: `bool`")
264 // .def("addDiracPoints", &finley::MeshAdapter::addDiracPoints,(arg("points"), arg("tags")=finley::EmptyPythonList),
265 // "adds points to support more Dirac delta function.\n\n"
266 // ":param points: list of points where Dirac delta function are to be defined. The location will be adjusted to\n"
267 // " to match the nearest node of the finite element mesh.\n:type points: ``list`` of ``list``s of ``floats``\n"
268 // ":param tags: list of tags to be assigned to the points.\n:type tags: ``list`` of ``int``s or ``strings``\n"
269 // )
270 // .def("addDiracPoint", &finley::MeshAdapter::addDiracPoint,(arg("point"), arg("tag")=-1),
271 // "adds a point to support more Dirac delta function.\n\n"
272 // ":param point: point where Dirac delta function are to be defined. The location will be adjusted to\n"
273 // " to match the nearest node of the finite element mesh.\n:type point: ``list`` of ``floats``\n"
274 // ":param tags: tag to be assigned to the point.\n:type tag: ``int``s or ``strings``\n"
275 // )
276 // .def("addDiracPoint", &finley::MeshAdapter::addDiracPointWithTagName,(arg("point"), arg("tag")),
277 // "adds a point to support more Dirac delta function.\n\n"
278 // ":param point: point where Dirac delta function are to be defined. The location will be adjusted to\n"
279 // " to match the nearest node of the finite element mesh.\n:type point: ``list`` of ``floats``\n"
280 // ":param tags: tag to be assigned to the point.\n:type tag: ``int``s or ``strings``\n"
281 // )
282 ;
283 }
284

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26