/[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 3943 by caltinay, Thu Aug 9 04:43:24 2012 UTC revision 3971 by caltinay, Wed Sep 19 02:55:35 2012 UTC
# Line 25  using namespace boost::python; Line 25  using namespace boost::python;
25    
26  namespace ripley {  namespace ripley {
27    
28    escript::Data readBinaryGrid(std::string filename, escript::FunctionSpace fs,
29            const object& pyFirst, const object& pyNum, const object& pyShape,
30            double fill=0.)
31    {
32        int dim=fs.getDim();
33        std::vector<int> first(dim), numValues(dim), shape;
34    
35        if (extract<tuple>(pyFirst).check() || extract<list>(pyFirst).check()) {
36            if (len(pyFirst)==dim) {
37                for (int i=0; i<dim; i++) {
38                    first[i]=extract<int>(pyFirst[i]);
39                }
40            } else
41                throw RipleyException("Argument 'first' has wrong length");
42        } else
43            throw RipleyException("Argument 'first' must be a tuple or list");
44    
45        if (extract<tuple>(pyNum).check() || extract<list>(pyNum).check()) {
46            if (len(pyNum)==dim) {
47                for (int i=0; i<dim; i++) {
48                    numValues[i]=extract<int>(pyNum[i]);
49                }
50            } else
51                throw RipleyException("Argument 'numValues' has wrong length");
52        } else
53            throw RipleyException("Argument 'numValues' must be a tuple or list");
54    
55        if (extract<tuple>(pyShape).check() || extract<list>(pyShape).check()) {
56            for (int i=0; i<len(pyShape); i++) {
57                shape.push_back(extract<int>(pyShape[i]));
58            }
59        } else
60            throw RipleyException("Argument 'shape' must be a tuple or list");
61    
62        const RipleyDomain* dom=dynamic_cast<const RipleyDomain*>(fs.getDomain().get());
63        if (!dom)
64            throw RipleyException("Function space must be on a ripley domain");
65    
66    
67        escript::Data res(fill, shape, fs, true);
68    
69        dom->readBinaryGrid(res, filename, first, numValues);
70        return res;
71    }
72    
73  // These wrappers are required to make the shared pointers work through the  // These wrappers are required to make the shared pointers work through the
74  // Python wrapper  // Python wrapper
75    
76  // The double for n? is just to keep python happy when people need to deal with  // The double for n? is just to keep python happy when people need to deal with
77  // trudiv  // truediv
78  escript::Domain_ptr _brick(double _n0, double _n1, double _n2, const object& l0,  escript::Domain_ptr _brick(double _n0, double _n1, double _n2, const object& l0,
79                   const object& l1, const object& l2, int d0, int d1, int d2)                   const object& l1, const object& l2, int d0, int d1, int d2)
80  {  {
# Line 108  escript::Domain_ptr _rectangle(double _n Line 153  escript::Domain_ptr _rectangle(double _n
153  }  }
154  std::string _who(){int a[]={_q[0]^42,_q[1]^42,_q[2]^42,0};return (char*)&a[0];}  std::string _who(){int a[]={_q[0]^42,_q[1]^42,_q[2]^42,0};return (char*)&a[0];}
155    
156  }  } // end of namespace
157    
158  /**  /**
159      \page ripley Ripley      \page ripley Ripley
# Line 146  BOOST_PYTHON_MODULE(ripleycpp) Line 191  BOOST_PYTHON_MODULE(ripleycpp)
191  ":param l1: length of side 1 or coordinate range of side 1\n:type l1: ``float`` or ``tuple``\n"  ":param l1: length of side 1 or coordinate range of side 1\n:type l1: ``float`` or ``tuple``\n"
192  ":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"
193  ":param d1: number of subdivisions in direction 1\n:type d1: ``int``");  ":param d1: number of subdivisions in direction 1\n:type d1: ``int``");
194      def("_theculprit_", ripley::_who),      def("_theculprit_", ripley::_who);
195      def("LoadMesh", ripley::RipleyDomain::loadMesh, (arg("filename")),      def("LoadMesh", ripley::RipleyDomain::loadMesh, (arg("filename")),
196             "Loads a ripley domain from a dump file" ":rtype: `Domain`");             "Loads a ripley domain from a dump file" ":rtype: `Domain`");
197    
# Line 154  BOOST_PYTHON_MODULE(ripleycpp) Line 199  BOOST_PYTHON_MODULE(ripleycpp)
199              "Reads a ripley domain from a file created by write().\n\n"              "Reads a ripley domain from a file created by write().\n\n"
200              ":rtype: `RipleyDomain`\n:param filename:\n:type filename: ``string``\n");              ":rtype: `RipleyDomain`\n:param filename:\n:type filename: ``string``\n");
201    
202        def("_readBinaryGrid", &ripley::readBinaryGrid, (arg("filename"), arg("functionspace"), arg("first"), arg("numValues"), arg("shape"), arg("fill")=0.));
203    
204      class_<ripley::RipleyDomain, bases<escript::AbstractContinuousDomain> >      class_<ripley::RipleyDomain, bases<escript::AbstractContinuousDomain> >
205          ("RipleyDomain", "", no_init)          ("RipleyDomain", "", no_init)
206          .def("write", &ripley::RipleyDomain::write, args("filename"),          .def("write", &ripley::RipleyDomain::write, args("filename"),

Legend:
Removed from v.3943  
changed lines
  Added in v.3971

  ViewVC Help
Powered by ViewVC 1.1.26