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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5136 - (show annotations)
Tue Sep 9 07:13:55 2014 UTC (4 years, 7 months ago) by caltinay
File size: 16837 byte(s)
ripley now supports paso solvers again and returns an appropriate matrix type
id. Changed the getSystemMatrixTypeId() method to take a full SolverBuddy
instance and made some other simplifications.

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26