/[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

branches/ripleygmg_from_3668/ripley/src/ripleycpp.cpp revision 3697 by caltinay, Mon Nov 28 04:52:00 2011 UTC trunk/ripley/src/ripleycpp.cpp revision 3991 by caltinay, Tue Sep 25 23:52:22 2012 UTC
# Line 1  Line 1 
1    
2  /*******************************************************  /*****************************************************************************
3  *  *
4  * Copyright (c) 2003-2011 by University of Queensland  * Copyright (c) 2003-2012 by University of Queensland
5  * Earth Systems Science Computational Center (ESSCC)  * http://www.uq.edu.au
 * http://www.uq.edu.au/esscc  
6  *  *
7  * Primary Business: Queensland, Australia  * Primary Business: Queensland, Australia
8  * Licensed under the Open Software License version 3.0  * Licensed under the Open Software License version 3.0
9  * http://www.opensource.org/licenses/osl-3.0.php  * http://www.opensource.org/licenses/osl-3.0.php
10  *  *
11  *******************************************************/  * Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12    * Development since 2012 by School of Earth Sciences
13    *
14    *****************************************************************************/
15    
16  #include <ripley/Brick.h>  #include <ripley/Brick.h>
17  #include <ripley/Rectangle.h>  #include <ripley/Rectangle.h>
# Line 25  using namespace boost::python; Line 27  using namespace boost::python;
27    
28  namespace ripley {  namespace ripley {
29    
30    escript::Data readBinaryGrid(std::string filename, escript::FunctionSpace fs,
31            const object& pyFirst, const object& pyNum, const object& pyShape,
32            double fill=0.)
33    {
34        int dim=fs.getDim();
35        std::vector<int> first(dim), numValues(dim), shape;
36    
37        if (extract<tuple>(pyFirst).check() || extract<list>(pyFirst).check()) {
38            if (len(pyFirst)==dim) {
39                for (int i=0; i<dim; i++) {
40                    first[i]=extract<int>(pyFirst[i]);
41                }
42            } else
43                throw RipleyException("Argument 'first' has wrong length");
44        } else
45            throw RipleyException("Argument 'first' must be a tuple or list");
46    
47        if (extract<tuple>(pyNum).check() || extract<list>(pyNum).check()) {
48            if (len(pyNum)==dim) {
49                for (int i=0; i<dim; i++) {
50                    numValues[i]=extract<int>(pyNum[i]);
51                }
52            } else
53                throw RipleyException("Argument 'numValues' has wrong length");
54        } else
55            throw RipleyException("Argument 'numValues' must be a tuple or list");
56    
57        if (extract<tuple>(pyShape).check() || extract<list>(pyShape).check()) {
58            for (int i=0; i<len(pyShape); i++) {
59                shape.push_back(extract<int>(pyShape[i]));
60            }
61        } else
62            throw RipleyException("Argument 'shape' must be a tuple or list");
63    
64        const RipleyDomain* dom=dynamic_cast<const RipleyDomain*>(fs.getDomain().get());
65        if (!dom)
66            throw RipleyException("Function space must be on a ripley domain");
67    
68    
69        escript::Data res(fill, shape, fs, true);
70    
71        dom->readBinaryGrid(res, filename, first, numValues);
72        return res;
73    }
74    
75  // These wrappers are required to make the shared pointers work through the  // These wrappers are required to make the shared pointers work through the
76  // Python wrapper  // Python wrapper
77    
78  escript::Domain_ptr _brick(int n0, int n1, int n2, double l0, double l1, double l2, int d0, int d1, int d2)  // The double for n? is just to keep python happy when people need to deal with
79    // truediv
80    escript::Domain_ptr _brick(double _n0, double _n1, double _n2, const object& l0,
81                     const object& l1, const object& l2, int d0, int d1, int d2)
82  {  {
83      return escript::Domain_ptr(new Brick(n0, n1, n2, l0, l1, l2, d0, d1, d2));      int n0=static_cast<int>(_n0), n1=static_cast<int>(_n1), n2=static_cast<int>(_n2);
84        double x0=0., x1=1., y0=0., y1=1., z0=0., z1=1.;
85        if (extract<tuple>(l0).check()) {
86            tuple x=extract<tuple>(l0);
87            if (len(x)==2) {
88                x0=extract<double>(x[0]);
89                x1=extract<double>(x[1]);
90            } else
91                throw RipleyException("Argument l0 must be a float or 2-tuple");
92        } else if (extract<double>(l0).check()) {
93            x1=extract<double>(l0);
94        } else
95            throw RipleyException("Argument l0 must be a float or 2-tuple");
96    
97        if (extract<tuple>(l1).check()) {
98            tuple y=extract<tuple>(l1);
99            if (len(y)==2) {
100                y0=extract<double>(y[0]);
101                y1=extract<double>(y[1]);
102            } else
103                throw RipleyException("Argument l1 must be a float or 2-tuple");
104        } else if (extract<double>(l1).check()) {
105            y1=extract<double>(l1);
106        } else
107            throw RipleyException("Argument l1 must be a float or 2-tuple");
108    
109        if (extract<tuple>(l2).check()) {
110            tuple z=extract<tuple>(l2);
111            if (len(z)==2) {
112                z0=extract<double>(z[0]);
113                z1=extract<double>(z[1]);
114            } else
115                throw RipleyException("Argument l2 must be a float or 2-tuple");
116        } else if (extract<double>(l2).check()) {
117            z1=extract<double>(l2);
118        } else
119            throw RipleyException("Argument l2 must be a float or 2-tuple");
120    
121        return escript::Domain_ptr(new Brick(n0,n1,n2, x0,y0,z0, x1,y1,z1, d0,d1,d2));
122  }  }
123    
124  escript::Domain_ptr _rectangle(int n0, int n1, double l0, double l1, int d0, int d1)  const int _q[]={0x61686969,0x746c4144,0x79616e43};
125    escript::Domain_ptr _rectangle(double _n0, double _n1, const object& l0,
126                                   const object& l1, int d0, int d1)
127  {  {
128      return escript::Domain_ptr(new Rectangle(n0, n1, l0, l1, d0, d1));      int n0=static_cast<int>(_n0), n1=static_cast<int>(_n1);
129  }      double x0=0., x1=1., y0=0., y1=1.;
130        if (extract<tuple>(l0).check()) {
131            tuple x=extract<tuple>(l0);
132            if (len(x)==2) {
133                x0=extract<double>(x[0]);
134                x1=extract<double>(x[1]);
135            } else
136                throw RipleyException("Argument l0 must be a float or 2-tuple");
137        } else if (extract<double>(l0).check()) {
138            x1=extract<double>(l0);
139        } else
140            throw RipleyException("Argument l0 must be a float or 2-tuple");
141    
142        if (extract<tuple>(l1).check()) {
143            tuple y=extract<tuple>(l1);
144            if (len(y)==2) {
145                y0=extract<double>(y[0]);
146                y1=extract<double>(y[1]);
147            } else
148                throw RipleyException("Argument l1 must be a float or 2-tuple");
149        } else if (extract<double>(l1).check()) {
150            y1=extract<double>(l1);
151        } else
152            throw RipleyException("Argument l1 must be a float or 2-tuple");
153    
154        return escript::Domain_ptr(new Rectangle(n0,n1, x0,y0, x1,y1, d0,d1));
155  }  }
156    std::string _who(){int a[]={_q[0]^42,_q[1]^42,_q[2]^42,0};return (char*)&a[0];}
157    
158    } // end of namespace
159    
 /**  
     \page ripley Ripley  
     Ripley is the python module name that contains the interfaces  
     to the C++ wrapper to ripley.  
 */  
160    
161  BOOST_PYTHON_MODULE(ripleycpp)  BOOST_PYTHON_MODULE(ripleycpp)
162  {  {
# Line 56  BOOST_PYTHON_MODULE(ripleycpp) Line 168  BOOST_PYTHON_MODULE(ripleycpp)
168    
169      register_exception_translator<ripley::RipleyException>(&(esysUtils::esysExceptionTranslator));      register_exception_translator<ripley::RipleyException>(&(esysUtils::esysExceptionTranslator));
170    
171      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),      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),
172  "Creates a hexagonal mesh with n0 x n1 x n2 elements over the brick [0,l0] x [0,l1] x [0,l2].\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"
173  ":param n0: number of elements in direction 0\n:type n0: ``int``\n"  ":param n0: number of elements in direction 0\n:type n0: ``int``\n"
174  ":param n1: number of elements in direction 1\n:type n1: ``int``\n"  ":param n1: number of elements in direction 1\n:type n1: ``int``\n"
175  ":param n2: number of elements in direction 2\n:type n2: ``int``\n"  ":param n2: number of elements in direction 2\n:type n2: ``int``\n"
176  ":param l0: length of side 0\n:type l0: ``float``\n"  ":param l0: length of side 0 or coordinate range of side 0\n:type l0: ``float`` or ``tuple``\n"
177  ":param l1: length of side 1\n:type l1: ``float``\n"  ":param l1: length of side 1 or coordinate range of side 1\n:type l1: ``float`` or ``tuple``\n"
178  ":param l2: length of side 2\n:type l2: ``float``\n"  ":param l2: length of side 2 or coordinate range of side 2\n:type l2: ``float`` or ``tuple``\n"
179  ":param d0: number of subdivisions in direction 0\n:type d0: ``int``\n"  ":param d0: number of subdivisions in direction 0\n:type d0: ``int``\n"
180  ":param d1: number of subdivisions in direction 1\n:type d1: ``int``\n"  ":param d1: number of subdivisions in direction 1\n:type d1: ``int``\n"
181  ":param d2: number of subdivisions in direction 2\n:type d2: ``int``");  ":param d2: number of subdivisions in direction 2\n:type d2: ``int``");
182    
183      def("Rectangle", ripley::_rectangle, (arg("n0"),arg("n1"),arg("l0")=1.0,arg("l1")=1.0,arg("d0")=1,arg("d1")=1),      def("Rectangle", ripley::_rectangle, (arg("n0"),arg("n1"),arg("l0")=1.0,arg("l1")=1.0,arg("d0")=-1,arg("d1")=-1),
184  "Creates a rectangular mesh with n0 x n1 elements over the rectangle [0,l0] x [0,l1].\n\n"  "Creates a rectangular mesh with n0 x n1 elements over the rectangle [0,l0] x [0,l1].\n\n"
185  ":param n0: number of elements in direction 0\n:type n0: ``int``\n"  ":param n0: number of elements in direction 0\n:type n0: ``int``\n"
186  ":param n1: number of elements in direction 1\n:type n1: ``int``\n"  ":param n1: number of elements in direction 1\n:type n1: ``int``\n"
187  ":param l0: length of side 0\n:type l0: ``float``\n"  ":param l0: length of side 0 or coordinate range of side 0\n:type l0: ``float`` or ``tuple``\n"
188  ":param l1: length of side 1\n:type l1: ``float``\n"  ":param l1: length of side 1 or coordinate range of side 1\n:type l1: ``float`` or ``tuple``\n"
189  ":param d0: number of subdivisions in direction 0\n:type d0: ``int``\n"  ":param d0: number of subdivisions in direction 0\n:type d0: ``int``\n"
190  ":param d1: number of subdivisions in direction 1\n:type d1: ``int``");  ":param d1: number of subdivisions in direction 1\n:type d1: ``int``");
191        def("_theculprit_", ripley::_who);
192      def("LoadMesh", ripley::RipleyDomain::loadMesh, (arg("filename")),      def("LoadMesh", ripley::RipleyDomain::loadMesh, (arg("filename")),
193             "Loads a ripley domain from a dump file" ":rtype: `Domain`");             "Loads a ripley domain from a dump file" ":rtype: `Domain`");
194    
# Line 84  BOOST_PYTHON_MODULE(ripleycpp) Line 196  BOOST_PYTHON_MODULE(ripleycpp)
196              "Reads a ripley domain from a file created by write().\n\n"              "Reads a ripley domain from a file created by write().\n\n"
197              ":rtype: `RipleyDomain`\n:param filename:\n:type filename: ``string``\n");              ":rtype: `RipleyDomain`\n:param filename:\n:type filename: ``string``\n");
198    
199        def("_readBinaryGrid", &ripley::readBinaryGrid, (arg("filename"), arg("functionspace"), arg("first"), arg("numValues"), arg("shape"), arg("fill")=0.));
200    
201      class_<ripley::RipleyDomain, bases<escript::AbstractContinuousDomain> >      class_<ripley::RipleyDomain, bases<escript::AbstractContinuousDomain> >
202          ("RipleyDomain", "", no_init)          ("RipleyDomain", "", no_init)
203          .def("write", &ripley::RipleyDomain::write, args("filename"),          .def("write", &ripley::RipleyDomain::write, args("filename"),
# Line 113  args("mat", "rhs", "A", "B", "C", "D", " Line 227  args("mat", "rhs", "A", "B", "C", "D", "
227  ":param Y:\n:type Y: `Data`\n"  ":param Y:\n:type Y: `Data`\n"
228  ":param d:\n:type d: `Data`\n"  ":param d:\n:type d: `Data`\n"
229  ":param d_contact:\n:type d_contact: `Data`\n"  ":param d_contact:\n:type d_contact: `Data`\n"
230  ":param y_contact:\n:type y_contact: `Data`\n"  ":param y_contact:\n:type y_contact: `Data`"
 )  
         .def("addPDEToLumpedSystem",&ripley::RipleyDomain::addPDEToLumpedSystem,  
 args("mat", "D", "d"),  
 "adds a PDE onto the lumped stiffness matrix\n\n"  
 ":param mat:\n:type mat: `Data`\n"  
 ":param D:\n:type D: `Data`\n"  
 ":param d:\n:type d: `Data`\n"  
 ":param useHRZ:\n:type useHRZ: bool\n"  
231  )  )
232          .def("addPDEToRHS",&ripley::RipleyDomain::addPDEToRHS,          .def("addPDEToRHS",&ripley::RipleyDomain::addPDEToRHS,
233  args("rhs", "X", "Y", "y", "y_contact"),  args("rhs", "X", "Y", "y", "y_contact"),
# Line 146  args( "tp", "source", "M", "A", "B", "C" Line 252  args( "tp", "source", "M", "A", "B", "C"
252  ":param d:\n:type d: `Data`\n"  ":param d:\n:type d: `Data`\n"
253  ":param y:\n:type y: `Data`\n"  ":param y:\n:type y: `Data`\n"
254  ":param d_contact:\n:type d_contact: `Data`\n"  ":param d_contact:\n:type d_contact: `Data`\n"
255  ":param y_contact:\n:type y_contact: `Data`\n"  ":param y_contact:\n:type y_contact: `Data`"
256  )  )
257          .def("newOperator",&ripley::RipleyDomain::newSystemMatrix,          .def("newOperator",&ripley::RipleyDomain::newSystemMatrix,
258  args("row_blocksize", "row_functionspace", "column_blocksize", "column_functionspace", "type"),  args("row_blocksize", "row_functionspace", "column_blocksize", "column_functionspace", "type"),
# Line 155  args("row_blocksize", "row_functionspace Line 261  args("row_blocksize", "row_functionspace
261  ":param row_functionspace:\n:type row_functionspace: `FunctionSpace`\n"  ":param row_functionspace:\n:type row_functionspace: `FunctionSpace`\n"
262  ":param column_blocksize:\n:type column_blocksize: ``int``\n"  ":param column_blocksize:\n:type column_blocksize: ``int``\n"
263  ":param column_functionspace:\n:type column_functionspace: `FunctionSpace`\n"  ":param column_functionspace:\n:type column_functionspace: `FunctionSpace`\n"
264  ":param type:\n:type type: ``int``\n"  ":param type:\n:type type: ``int``"
265  )  )
266          .def("newTransportProblem",&ripley::RipleyDomain::newTransportProblem,          .def("newTransportProblem",&ripley::RipleyDomain::newTransportProblem,
267  args("theta", "blocksize", "functionspace", "type"),  args("theta", "blocksize", "functionspace", "type"),
# Line 163  args("theta", "blocksize", "functionspac Line 269  args("theta", "blocksize", "functionspac
269  ":param theta:\n:type theta: ``float``\n"  ":param theta:\n:type theta: ``float``\n"
270  ":param blocksize:\n:type blocksize: ``int``\n"  ":param blocksize:\n:type blocksize: ``int``\n"
271  ":param functionspace:\n:type functionspace: `FunctionSpace`\n"  ":param functionspace:\n:type functionspace: `FunctionSpace`\n"
272  ":param type:\n:type type: ``int``\n"  ":param type:\n:type type: ``int``"
273  )  )
274          .def("getSystemMatrixTypeId",&ripley::RipleyDomain::getSystemMatrixTypeId,          .def("getSystemMatrixTypeId",&ripley::RipleyDomain::getSystemMatrixTypeId,
275  args("solver", "preconditioner", "package", "symmetry"),  args("solver", "preconditioner", "package", "symmetry"),
# Line 172  args("solver", "preconditioner", "packag Line 278  args("solver", "preconditioner", "packag
278  ":param solver:\n:type solver: ``int``\n"  ":param solver:\n:type solver: ``int``\n"
279  ":param preconditioner:\n:type preconditioner: ``int``\n"  ":param preconditioner:\n:type preconditioner: ``int``\n"
280  ":param package:\n:type package: ``int``\n"  ":param package:\n:type package: ``int``\n"
281  ":param symmetry:\n:type symmetry: ``int``\n"  ":param symmetry:\n:type symmetry: ``int``"
282  )  )
283          .def("getTransportTypeId",&ripley::RipleyDomain::getTransportTypeId,          .def("getTransportTypeId",&ripley::RipleyDomain::getTransportTypeId,
284  args("solver", "preconditioner", "package", "symmetry"),  args("solver", "preconditioner", "package", "symmetry"),
# Line 181  args("solver", "preconditioner", "packag Line 287  args("solver", "preconditioner", "packag
287  ":param solver:\n:type solver: ``int``\n"  ":param solver:\n:type solver: ``int``\n"
288  ":param preconditioner:\n:type preconditioner: ``int``\n"  ":param preconditioner:\n:type preconditioner: ``int``\n"
289  ":param package:\n:type package: ``int``\n"  ":param package:\n:type package: ``int``\n"
290  ":param symmetry:\n:type symmetry: ``int``\n"  ":param symmetry:\n:type symmetry: ``int``"
291  )  )
 //      .def("setX",&ripley::RipleyDomain::setNewX,  
 //args("arg"), "assigns new location to the domain\n\n:param arg:\n:type arg: `Data`")  
292          .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"
293  ":rtype: `Data`")  ":rtype: `Data`")
294          .def("getNormal",&ripley::RipleyDomain::getNormal,          .def("getNormal",&ripley::RipleyDomain::getNormal,
# Line 206  args("solver", "preconditioner", "packag Line 310  args("solver", "preconditioner", "packag
310          .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`");
311    
312      class_<ripley::Brick, bases<ripley::RipleyDomain> >("RipleyBrick", "", no_init);      class_<ripley::Brick, bases<ripley::RipleyDomain> >("RipleyBrick", "", no_init);
   
313      class_<ripley::Rectangle, bases<ripley::RipleyDomain> >("RipleyRectangle", "", no_init);      class_<ripley::Rectangle, bases<ripley::RipleyDomain> >("RipleyRectangle", "", no_init);
   
314  }  }
315    

Legend:
Removed from v.3697  
changed lines
  Added in v.3991

  ViewVC Help
Powered by ViewVC 1.1.26