/[escript]/trunk/finley/src/finleycpp.cpp
ViewVC logotype

Contents of /trunk/finley/src/finleycpp.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6939 - (show annotations)
Mon Jan 20 03:37:18 2020 UTC (4 months, 1 week ago) by uqaeller
File size: 13015 byte(s)
Updated the copyright header.


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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26