/[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 3991 by caltinay, Tue Sep 25 23:52:22 2012 UTC revision 4013 by caltinay, Thu Oct 4 03:13:27 2012 UTC
# Line 72  escript::Data readBinaryGrid(std::string Line 72  escript::Data readBinaryGrid(std::string
72      return res;      return res;
73  }  }
74    
75    escript::Data readNcGrid(std::string filename, std::string varname,
76            escript::FunctionSpace fs, const object& pyFirst, const object& pyNum,
77            const object& pyShape, double fill=0.)
78    {
79        int dim=fs.getDim();
80        std::vector<int> first(dim), numValues(dim), shape;
81    
82        if (extract<tuple>(pyFirst).check() || extract<list>(pyFirst).check()) {
83            if (len(pyFirst)==dim) {
84                for (int i=0; i<dim; i++) {
85                    first[i]=extract<int>(pyFirst[i]);
86                }
87            } else
88                throw RipleyException("Argument 'first' has wrong length");
89        } else
90            throw RipleyException("Argument 'first' must be a tuple or list");
91    
92        if (extract<tuple>(pyNum).check() || extract<list>(pyNum).check()) {
93            if (len(pyNum)==dim) {
94                for (int i=0; i<dim; i++) {
95                    numValues[i]=extract<int>(pyNum[i]);
96                }
97            } else
98                throw RipleyException("Argument 'numValues' has wrong length");
99        } else
100            throw RipleyException("Argument 'numValues' must be a tuple or list");
101    
102        if (extract<tuple>(pyShape).check() || extract<list>(pyShape).check()) {
103            for (int i=0; i<len(pyShape); i++) {
104                shape.push_back(extract<int>(pyShape[i]));
105            }
106        } else
107            throw RipleyException("Argument 'shape' must be a tuple or list");
108    
109        const RipleyDomain* dom=dynamic_cast<const RipleyDomain*>(fs.getDomain().get());
110        if (!dom)
111            throw RipleyException("Function space must be on a ripley domain");
112    
113    
114        escript::Data res(fill, shape, fs, true);
115    
116        dom->readNcGrid(res, filename, varname, first, numValues);
117        return res;
118    }
119    
120  // These wrappers are required to make the shared pointers work through the  // These wrappers are required to make the shared pointers work through the
121  // Python wrapper  // Python wrapper
122    
# Line 168  BOOST_PYTHON_MODULE(ripleycpp) Line 213  BOOST_PYTHON_MODULE(ripleycpp)
213    
214      register_exception_translator<ripley::RipleyException>(&(esysUtils::esysExceptionTranslator));      register_exception_translator<ripley::RipleyException>(&(esysUtils::esysExceptionTranslator));
215    
216        scope().attr("__doc__") = "To use this module, please import esys.ripley";        
217        
218        
219      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),
220  "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"
221  ":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"
# Line 198  BOOST_PYTHON_MODULE(ripleycpp) Line 246  BOOST_PYTHON_MODULE(ripleycpp)
246    
247      def("_readBinaryGrid", &ripley::readBinaryGrid, (arg("filename"), arg("functionspace"), arg("first"), arg("numValues"), arg("shape"), arg("fill")=0.));      def("_readBinaryGrid", &ripley::readBinaryGrid, (arg("filename"), arg("functionspace"), arg("first"), arg("numValues"), arg("shape"), arg("fill")=0.));
248    
249        def("_readNcGrid", &ripley::readNcGrid, (arg("filename"), arg("varname"), arg("functionspace"), arg("first"), arg("numValues"), arg("shape"), arg("fill")=0.));
250    
251      class_<ripley::RipleyDomain, bases<escript::AbstractContinuousDomain> >      class_<ripley::RipleyDomain, bases<escript::AbstractContinuousDomain> >
252          ("RipleyDomain", "", no_init)          ("RipleyDomain", "", no_init)
253          .def("write", &ripley::RipleyDomain::write, args("filename"),          .def("write", &ripley::RipleyDomain::write, args("filename"),

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

  ViewVC Help
Powered by ViewVC 1.1.26