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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 3690 by caltinay, Wed Nov 16 02:21:18 2011 UTC revision 3691 by caltinay, Wed Nov 23 23:07:37 2011 UTC
# Line 11  Line 11 
11  *  *
12  *******************************************************/  *******************************************************/
13    
14  #include <ripley/RipleyDomainFactory.h>  #include <ripley/Brick.h>
15    #include <ripley/Rectangle.h>
16  #include <esysUtils/esysExceptionTranslator.h>  #include <esysUtils/esysExceptionTranslator.h>
17    
18  #include <boost/python.hpp>  #include <boost/python.hpp>
# Line 22  Line 23 
23    
24  using namespace boost::python;  using namespace boost::python;
25    
26  /**  namespace ripley {
    \page ripley Ripley  
    Ripley is the python module name that contains the interfaces  
    to the C++ wrapper to ripley.  
27    
28     \version 1.0.0  // These wrappers are required to make the shared pointers work through the
29    // Python wrapper
30    
31     \section class_desc Class Description:  escript::Domain_ptr _brick(int n0, int n1, int n2, double l0, double l1, double l2, int d0, int d1, int d2)
32     None  {
33        return escript::Domain_ptr(new Brick(n0, n1, n2, l0, l1, l2, d0, d1, d2));
34    }
35    
36     \section class_limits Class Limitations:  escript::Domain_ptr _rectangle(int n0, int n1, double l0, double l1, int d0, int d1)
37     None  {
38        return escript::Domain_ptr(new Rectangle(n0, n1, l0, l1, d0, d1));
39    }
40    
41     \section class_conds Class Conditions of Use:  }
    None  
42    
43     \section throws Throws:  /**
44     None      \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)  BOOST_PYTHON_MODULE(ripleycpp)
50  {  {
51  // This feature was added in boost v1.34  // This feature was added in boost v1.34
52  #if ((BOOST_VERSION/100)%1000 > 34) || (BOOST_VERSION/100000 >1)  #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      // params are: bool show_user_defined, bool show_py_signatures, bool show_cpp_signatures
54    docstring_options docopt(true, true, false);      docstring_options docopt(true, true, false);
55  #endif  #endif
56    
57    register_exception_translator<ripley::RipleyException>(&(esysUtils::esysExceptionTranslator));      register_exception_translator<ripley::RipleyException>(&(esysUtils::esysExceptionTranslator));
   
   def("LoadMesh",ripley::loadMesh, (arg("fileName")), ":rtype: `Domain`");  
58    
59    def("ReadMesh",ripley::readMesh, (arg("fileName"), arg("optimize")=true)      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          ,"Reads a mesh from a file. For MPI parallel runs the mesh is fanned out to multiple processes.\n\n"  "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          ":rtype: `Domain`\n:param fileName:\n:type fileName: ``string``\n"  ":param n0: number of elements in direction 0\n:type n0: ``int``\n"
62          ":param optimize: Whether to optimize node labels\n:type optimize: ``bool``");  ":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    def("ReadGmsh",ripley::readGmsh,  ":param l0: length of side 0\n:type l0: ``float``\n"
65        (arg("fileName"), arg("numDim"), arg("optimize")=true)  ":param l1: length of side 1\n:type l1: ``float``\n"
66          ,"Reads a gmsh mesh file\n\n"  ":param l2: length of side 2\n:type l2: ``float``\n"
67          ":rtype: `Domain`\n:param fileName:\n:type fileName: ``string``\n"  ":param d0: number of subdivisions in direction 0\n:type d0: ``int``\n"
68          ":param optimize: Whether to optimize node labels\n:type optimize: ``bool``\n");  ":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    def ("Brick", ripley::brick,  
71        (arg("n0")=1, arg("n1")=1, arg("n2")=1,      def("Rectangle", ripley::_rectangle, (arg("n0"),arg("n1"),arg("l0")=1.0,arg("l1")=1.0,arg("d0")=1,arg("d1")=1),
72        arg("l0")=1.0, arg("l1")=1.0, arg("l2")=1.0,  "Creates a rectangular mesh with n0 x n1 elements over the rectangle [0,l0] x [0,l1].\n\n"
73        arg("optimize")=false)  ":param n0: number of elements in direction 0\n:type n0: ``int``\n"
74          ,"Creates a rectangular mesh with n0 x n1 x n2 elements over the brick [0,l0] x [0,l1] x [0,l2]."  ":param n1: number of elements in direction 1\n:type n1: ``int``\n"
75          "\n\n:param n0:\n:type n0:\n:param n1:\n:type n1:\n:param n2:\n:type n2:\n"  ":param l0: length of side 0\n:type l0: ``float``\n"
76          ":param l0: length of side 0\n:param l1:\n:param l2:\n"  ":param l1: length of side 1\n:type l1: ``float``\n"
77          ":param optimize: Whether to optimize node labels\n:type optimize: ``bool``");  ":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    def ("Rectangle", ripley::rectangle,  
80        (arg("n0")=1, arg("n1")=1, arg("l0")=1.0, arg("l1")=1.0,      def("LoadMesh", ripley::RipleyDomain::loadMesh, (arg("filename")),
81        arg("optimize")=false)             "Loads a ripley domain from a dump file" ":rtype: `Domain`");
82          ,"Creates a rectangular mesh with n0 x n1 elements over the rectangle [0,l0] x [0,l1]."  
83          "\n\n:param n0:\n:type n0:\n:param n1:\n:type n1:\n"      def("ReadMesh", ripley::RipleyDomain::readMesh, (arg("filename")),
84          ":param l0: length of side 0\n:param l1:\n"              "Reads a ripley domain from a file created by write().\n\n"
85          ":param optimize: Whether to optimize node labels\n:type optimize: ``bool``");              ":rtype: `RipleyDomain`\n:param filename:\n:type filename: ``string``\n");
86    
87    class_<ripley::RipleyDomain, bases<escript::AbstractContinuousDomain> >      class_<ripley::RipleyDomain, bases<escript::AbstractContinuousDomain> >
88        ("RipleyDomain","A concrete class representing a domain. For more details, please consult the c++ documentation.", no_init)          ("RipleyDomain", "", no_init)
89        .def(init<const ripley::RipleyDomain&>())          .def("write", &ripley::RipleyDomain::write, args("filename"),
90        .def("write",&ripley::RipleyDomain::write,args("filename"),                  "Writes the current mesh to a file with the given name. It can subsequently be recovered using ReadMesh().")
91  "Write the current mesh to a file with the given name.")          .def("print_mesh_info", &ripley::RipleyDomain::Print_Mesh_Info, (arg("full")=false),
92        .def("print_mesh_info",&ripley::RipleyDomain::Print_Mesh_Info,(arg("full")=false),                  "Prints out a summary about the mesh.\n"
93  ":param full:\n:type full: ``bool``")                  ":param full: whether to output additional data\n:type full: ``bool``")
94        .def("dump",&ripley::RipleyDomain::dump,args("fileName")          .def("dump", &ripley::RipleyDomain::dump, args("filename"),
95  ,"dumps the mesh to a file with the given name.")                  "Dumps the mesh to a file with the given name.")
96        .def("getDescription",&ripley::RipleyDomain::getDescription,          .def("getDescription", &ripley::RipleyDomain::getDescription,
97  ":return: a description for this domain\n:rtype: ``string``")  ":return: a description for this domain\n:rtype: ``string``")
98        .def("getDim",&ripley::RipleyDomain::getDim,":rtype: ``int``")          .def("getDim", &ripley::RipleyDomain::getDim, ":rtype: ``int``")
99        .def("getDataShape",&ripley::RipleyDomain::getDataShape, args("functionSpaceCode"),          .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``")  ":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,          .def("getNumDataPointsGlobal", &ripley::RipleyDomain::getNumDataPointsGlobal,
102  ":return: the number of data points summed across all MPI processes\n"  ":return: the number of data points summed across all MPI processes\n"
103  ":rtype: ``int``")  ":rtype: ``int``")
104        .def("addPDEToSystem",&ripley::RipleyDomain::addPDEToSystem,          .def("addPDEToSystem",&ripley::RipleyDomain::addPDEToSystem,
105  args("mat", "rhs","A", "B", "C", "D", "X", "Y", "d", "y", "d_contact", "y_contact"),  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"  "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"  ":param mat:\n:type mat: `OperatorAdapter`\n:param rhs:\n:type rhs: `Data`\n"
108  ":param A:\n:type A: `Data`\n"  ":param A:\n:type A: `Data`\n"
# Line 113  args("mat", "rhs","A", "B", "C", "D", "X Line 115  args("mat", "rhs","A", "B", "C", "D", "X
115  ":param d_contact:\n:type d_contact: `Data`\n"  ":param d_contact:\n:type d_contact: `Data`\n"
116  ":param y_contact:\n:type y_contact: `Data`\n"  ":param y_contact:\n:type y_contact: `Data`\n"
117  )  )
118        .def("addPDEToLumpedSystem",&ripley::RipleyDomain::addPDEToLumpedSystem,          .def("addPDEToLumpedSystem",&ripley::RipleyDomain::addPDEToLumpedSystem,
119  args("mat", "D", "d"),  args("mat", "D", "d"),
120  "adds a PDE onto the lumped stiffness matrix\n\n"  "adds a PDE onto the lumped stiffness matrix\n\n"
121  ":param mat:\n:type mat: `Data`\n"  ":param mat:\n:type mat: `Data`\n"
# Line 121  args("mat", "D", "d"), Line 123  args("mat", "D", "d"),
123  ":param d:\n:type d: `Data`\n"  ":param d:\n:type d: `Data`\n"
124  ":param useHRZ:\n:type useHRZ: bool\n"  ":param useHRZ:\n:type useHRZ: bool\n"
125  )  )
126        .def("addPDEToRHS",&ripley::RipleyDomain::addPDEToRHS,          .def("addPDEToRHS",&ripley::RipleyDomain::addPDEToRHS,
127  args("rhs", "X", "Y", "y", "y_contact"),  args("rhs", "X", "Y", "y", "y_contact"),
128  "adds a PDE onto the stiffness matrix mat and a rhs\n\n"  "adds a PDE onto the stiffness matrix mat and a rhs\n\n"
129  ":param rhs:\n:type rhs: `Data`\n"  ":param rhs:\n:type rhs: `Data`\n"
# Line 130  args("rhs", "X", "Y", "y", "y_contact"), Line 132  args("rhs", "X", "Y", "y", "y_contact"),
132  ":param y:\n:type y: `Data`\n"  ":param y:\n:type y: `Data`\n"
133  ":param y_contact:\n:type y_contact: `Data`"  ":param y_contact:\n:type y_contact: `Data`"
134  )  )
135        .def("addPDEToTransportProblem",&ripley::RipleyDomain::addPDEToTransportProblem,          .def("addPDEToTransportProblem",&ripley::RipleyDomain::addPDEToTransportProblem,
136  args( "tp", "source", "M", "A", "B", "C", "D", "X", "Y", "d", "y", "d_contact", "y_contact"),  args( "tp", "source", "M", "A", "B", "C", "D", "X", "Y", "d", "y", "d_contact", "y_contact"),
137  ":param tp:\n:type tp: `TransportProblemAdapter`\n"  ":param tp:\n:type tp: `TransportProblemAdapter`\n"
138  ":param source:\n:type source: `Data`\n"  ":param source:\n:type source: `Data`\n"
# Line 146  args( "tp", "source", "M", "A", "B", "C" Line 148  args( "tp", "source", "M", "A", "B", "C"
148  ":param d_contact:\n:type d_contact: `Data`\n"  ":param d_contact:\n:type d_contact: `Data`\n"
149  ":param y_contact:\n:type y_contact: `Data`\n"  ":param y_contact:\n:type y_contact: `Data`\n"
150  )  )
151        .def("newOperator",&ripley::RipleyDomain::newSystemMatrix,          .def("newOperator",&ripley::RipleyDomain::newSystemMatrix,
152  args("row_blocksize", "row_functionspace", "column_blocksize", "column_functionspace", "type"),  args("row_blocksize", "row_functionspace", "column_blocksize", "column_functionspace", "type"),
153  "creates a SystemMatrixAdapter stiffness matrix and initializes it with zeros\n\n"  "creates a SystemMatrixAdapter stiffness matrix and initializes it with zeros\n\n"
154  ":param row_blocksize:\n:type row_blocksize: ``int``\n"  ":param row_blocksize:\n:type row_blocksize: ``int``\n"
# Line 155  args("row_blocksize", "row_functionspace Line 157  args("row_blocksize", "row_functionspace
157  ":param column_functionspace:\n:type column_functionspace: `FunctionSpace`\n"  ":param column_functionspace:\n:type column_functionspace: `FunctionSpace`\n"
158  ":param type:\n:type type: ``int``\n"  ":param type:\n:type type: ``int``\n"
159  )  )
160        .def("newTransportProblem",&ripley::RipleyDomain::newTransportProblem,          .def("newTransportProblem",&ripley::RipleyDomain::newTransportProblem,
161  args("theta", "blocksize", "functionspace", "type"),  args("theta", "blocksize", "functionspace", "type"),
162  "creates a TransportProblemAdapter\n\n"  "creates a TransportProblemAdapter\n\n"
163  ":param theta:\n:type theta: ``float``\n"  ":param theta:\n:type theta: ``float``\n"
# Line 163  args("theta", "blocksize", "functionspac Line 165  args("theta", "blocksize", "functionspac
165  ":param functionspace:\n:type functionspace: `FunctionSpace`\n"  ":param functionspace:\n:type functionspace: `FunctionSpace`\n"
166  ":param type:\n:type type: ``int``\n"  ":param type:\n:type type: ``int``\n"
167  )  )
168        .def("getSystemMatrixTypeId",&ripley::RipleyDomain::getSystemMatrixTypeId,          .def("getSystemMatrixTypeId",&ripley::RipleyDomain::getSystemMatrixTypeId,
169  args("solver", "preconditioner", "package", "symmetry"),  args("solver", "preconditioner", "package", "symmetry"),
170  ":return: the identifier of the matrix type to be used for the global stiffness matrix when a particular solver, package, perconditioner, and symmetric matrix is used.\n"  ":return: the identifier of the matrix type to be used for the global stiffness matrix when a particular solver, package, perconditioner, and symmetric matrix is used.\n"
171  ":rtype: ``int``\n"  ":rtype: ``int``\n"
# Line 172  args("solver", "preconditioner", "packag Line 174  args("solver", "preconditioner", "packag
174  ":param package:\n:type package: ``int``\n"  ":param package:\n:type package: ``int``\n"
175  ":param symmetry:\n:type symmetry: ``int``\n"  ":param symmetry:\n:type symmetry: ``int``\n"
176  )  )
177        .def("getTransportTypeId",&ripley::RipleyDomain::getTransportTypeId,          .def("getTransportTypeId",&ripley::RipleyDomain::getTransportTypeId,
178  args("solver", "preconditioner", "package", "symmetry"),  args("solver", "preconditioner", "package", "symmetry"),
179  ":return: the identifier of the transport problem type to be used when a particular solver, perconditioner, package and symmetric matrix is used.\n"  ":return: the identifier of the transport problem type to be used when a particular solver, perconditioner, package and symmetric matrix is used.\n"
180  ":rtype: ``int``\n"  ":rtype: ``int``\n"
# Line 181  args("solver", "preconditioner", "packag Line 183  args("solver", "preconditioner", "packag
183  ":param package:\n:type package: ``int``\n"  ":param package:\n:type package: ``int``\n"
184  ":param symmetry:\n:type symmetry: ``int``\n"  ":param symmetry:\n:type symmetry: ``int``\n"
185  )  )
186        .def("setX",&ripley::RipleyDomain::setNewX,  //      .def("setX",&ripley::RipleyDomain::setNewX,
187  args("arg"), "assigns new location to the domain\n\n:param arg:\n:type arg: `Data`")  //args("arg"), "assigns new location to the domain\n\n:param arg:\n:type arg: `Data`")
188        .def("getX",&ripley::RipleyDomain::getX, ":return: locations in the FEM nodes\n\n"          .def("getX",&ripley::RipleyDomain::getX, ":return: locations in the FEM nodes\n\n"
189  ":rtype: `Data`")  ":rtype: `Data`")
190        .def("getNormal",&ripley::RipleyDomain::getNormal,          .def("getNormal",&ripley::RipleyDomain::getNormal,
191  ":return: boundary normals at the quadrature point on the face elements\n"  ":return: boundary normals at the quadrature point on the face elements\n"
192  ":rtype: `Data`")  ":rtype: `Data`")
193        .def("getSize",&ripley::RipleyDomain::getSize,":return: the element size\n"          .def("getSize",&ripley::RipleyDomain::getSize,":return: the element size\n"
194  ":rtype: `Data`")  ":rtype: `Data`")
195        .def("setTagMap",&ripley::RipleyDomain::setTagMap,args("name","tag"),          .def("setTagMap",&ripley::RipleyDomain::setTagMap,args("name","tag"),
196  "Give a tag number a name.\n\n:param name: Name for the tag\n:type name: ``string``\n"  "Give a tag number a name.\n\n:param name: Name for the tag\n:type name: ``string``\n"
197  ":param tag: numeric id\n:type tag: ``int``\n:note: Tag names must be unique within a domain")  ":param tag: numeric id\n:type tag: ``int``\n:note: Tag names must be unique within a domain")
198        .def("getTag",&ripley::RipleyDomain::getTag,args("name"),":return: tag id for "          .def("getTag",&ripley::RipleyDomain::getTag,args("name"),":return: tag id for "
199  "``name``\n:rtype: ``string``")  "``name``\n:rtype: ``string``")
200        .def("isValidTagName",&ripley::RipleyDomain::isValidTagName,args("name"),          .def("isValidTagName",&ripley::RipleyDomain::isValidTagName,args("name"),
201  ":return: True is ``name`` corresponds to a tag\n:rtype: ``bool``")  ":return: True if ``name`` corresponds to a tag, otherwise False\n:rtype: ``bool``")
202        .def("showTagNames",&ripley::RipleyDomain::showTagNames,":return: A space separated list of tag names\n:rtype: ``string``")          .def("showTagNames",&ripley::RipleyDomain::showTagNames,":return: A space separated list of tag names\n:rtype: ``string``")
203        .def("getMPISize",&ripley::RipleyDomain::getMPISize,":return: the number of processes used for this `Domain`\n:rtype: ``int``")          .def("getMPISize",&ripley::RipleyDomain::getMPISize,":return: the number of processes used for this `Domain`\n:rtype: ``int``")
204        .def("getMPIRank",&ripley::RipleyDomain::getMPIRank,":return: the rank of this process\n:rtype: ``int``")          .def("getMPIRank",&ripley::RipleyDomain::getMPIRank,":return: the rank of this process\n:rtype: ``int``")
205        .def("MPIBarrier",&ripley::RipleyDomain::MPIBarrier,"Wait until all processes have reached this point")          .def("MPIBarrier",&ripley::RipleyDomain::MPIBarrier,"Wait until all processes have reached this point")
206        .def("onMasterProcessor",&ripley::RipleyDomain::onMasterProcessor,":return: True if this code is executing on the master process\n:rtype: `bool`");          .def("onMasterProcessor",&ripley::RipleyDomain::onMasterProcessor,":return: True if this code is executing on the master process\n:rtype: `bool`");
207    
208    class_<ripley::SystemMatrixAdapter, bases<escript::AbstractSystemMatrix> >      class_<ripley::Brick, bases<ripley::RipleyDomain> >("RipleyBrick", "", no_init);
209        ("OperatorAdapter","A concrete class representing an operator. For more details, please see the c++ documentation.", no_init)  
210        .def("print_matrix_info",&ripley::SystemMatrixAdapter::Print_Matrix_Info,(arg("full")=false),"prints information about a system matrix")      class_<ripley::Rectangle, bases<ripley::RipleyDomain> >("RipleyRectangle", "", no_init);
211        .def("nullifyRowsAndCols",&ripley::SystemMatrixAdapter::nullifyRowsAndCols)  
       .def("resetValues",&ripley::SystemMatrixAdapter::resetValues, "resets the matrix entries")  
       .def("saveMM",&ripley::SystemMatrixAdapter::saveMM,args("fileName"),  
 "writes the matrix to a file using the Matrix Market file format")  
       .def("saveHB",&ripley::SystemMatrixAdapter::saveHB, args("filename"),  
 "writes the matrix to a file using the Harwell-Boeing file format");  
   
   class_<ripley::TransportProblemAdapter, bases<escript::AbstractTransportProblem> >  
       ("TransportProblemAdapter","",no_init)  
       .def("getSafeTimeStepSize",&ripley::TransportProblemAdapter::getSafeTimeStepSize)  
       .def("getUnlimitedTimeStepSize",&ripley::TransportProblemAdapter::getUnlimitedTimeStepSize)  
       .def("resetTransport",&ripley::TransportProblemAdapter::resetTransport,  
 "resets the transport operator typically as they have been updated");  
212  }  }
213    

Legend:
Removed from v.3690  
changed lines
  Added in v.3691

  ViewVC Help
Powered by ViewVC 1.1.26