/[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 4284 by caltinay, Thu Mar 7 00:43:48 2013 UTC
# Line 1  Line 1 
1    
2  /*****************************************************************************  /*****************************************************************************
3  *  *
4  * Copyright (c) 2003-2012 by University of Queensland  * Copyright (c) 2003-2013 by University of Queensland
5  * http://www.uq.edu.au  * http://www.uq.edu.au
6  *  *
7  * Primary Business: Queensland, Australia  * Primary Business: Queensland, Australia
# Line 28  using namespace boost::python; Line 28  using namespace boost::python;
28  namespace ripley {  namespace ripley {
29    
30  escript::Data readBinaryGrid(std::string filename, escript::FunctionSpace fs,  escript::Data readBinaryGrid(std::string filename, escript::FunctionSpace fs,
31          const object& pyFirst, const object& pyNum, const object& pyShape,          const object& pyFirst, const object& pyNum, const object& pyMultiplier,
32          double fill=0.)          const object& pyShape, double fill=0.)
33  {  {
34      int dim=fs.getDim();      int dim=fs.getDim();
35      std::vector<int> first(dim), numValues(dim), shape;      std::vector<int> first(dim), numValues(dim), multiplier(dim), shape;
36    
37      if (extract<tuple>(pyFirst).check() || extract<list>(pyFirst).check()) {      if (extract<tuple>(pyFirst).check() || extract<list>(pyFirst).check()) {
38          if (len(pyFirst)==dim) {          if (len(pyFirst)==dim) {
# Line 61  escript::Data readBinaryGrid(std::string Line 61  escript::Data readBinaryGrid(std::string
61      } else      } else
62          throw RipleyException("Argument 'shape' must be a tuple or list");          throw RipleyException("Argument 'shape' must be a tuple or list");
63    
64        if (extract<tuple>(pyMultiplier).check() || extract<list>(pyMultiplier).check()) {
65            if (len(pyMultiplier)==dim) {
66                for (int i=0; i<dim; i++) {
67                    multiplier[i]=extract<int>(pyMultiplier[i]);
68                }
69            } else
70                throw RipleyException("Argument 'multiplier' has wrong length");
71        } else
72            throw RipleyException("Argument 'multiplier' must be a tuple or list");
73    
74      const RipleyDomain* dom=dynamic_cast<const RipleyDomain*>(fs.getDomain().get());      const RipleyDomain* dom=dynamic_cast<const RipleyDomain*>(fs.getDomain().get());
75      if (!dom)      if (!dom)
76          throw RipleyException("Function space must be on a ripley domain");          throw RipleyException("Function space must be on a ripley domain");
# Line 68  escript::Data readBinaryGrid(std::string Line 78  escript::Data readBinaryGrid(std::string
78    
79      escript::Data res(fill, shape, fs, true);      escript::Data res(fill, shape, fs, true);
80    
81      dom->readBinaryGrid(res, filename, first, numValues);      dom->readBinaryGrid(res, filename, first, numValues, multiplier);
82        return res;
83    }
84    
85    escript::Data readNcGrid(std::string filename, std::string varname,
86            escript::FunctionSpace fs, const object& pyFirst, const object& pyNum,
87            const object& pyMultiplier, const object& pyShape, double fill=0.)
88    {
89        int dim=fs.getDim();
90        std::vector<int> first(dim), numValues(dim), multiplier(dim), shape;
91    
92        if (extract<tuple>(pyFirst).check() || extract<list>(pyFirst).check()) {
93            if (len(pyFirst)==dim) {
94                for (int i=0; i<dim; i++) {
95                    first[i]=extract<int>(pyFirst[i]);
96                }
97            } else
98                throw RipleyException("Argument 'first' has wrong length");
99        } else
100            throw RipleyException("Argument 'first' must be a tuple or list");
101    
102        if (extract<tuple>(pyNum).check() || extract<list>(pyNum).check()) {
103            if (len(pyNum)==dim) {
104                for (int i=0; i<dim; i++) {
105                    numValues[i]=extract<int>(pyNum[i]);
106                }
107            } else
108                throw RipleyException("Argument 'numValues' has wrong length");
109        } else
110            throw RipleyException("Argument 'numValues' must be a tuple or list");
111    
112        if (extract<tuple>(pyMultiplier).check() || extract<list>(pyMultiplier).check()) {
113            if (len(pyMultiplier)==dim) {
114                for (int i=0; i<dim; i++) {
115                    multiplier[i]=extract<int>(pyMultiplier[i]);
116                }
117            } else
118                throw RipleyException("Argument 'multiplier' has wrong length");
119        } else
120            throw RipleyException("Argument 'multiplier' must be a tuple or list");
121    
122        if (extract<tuple>(pyShape).check() || extract<list>(pyShape).check()) {
123            for (int i=0; i<len(pyShape); i++) {
124                shape.push_back(extract<int>(pyShape[i]));
125            }
126        } else
127            throw RipleyException("Argument 'shape' must be a tuple or list");
128    
129        const RipleyDomain* dom=dynamic_cast<const RipleyDomain*>(fs.getDomain().get());
130        if (!dom)
131            throw RipleyException("Function space must be on a ripley domain");
132    
133    
134        escript::Data res(fill, shape, fs, true);
135    
136        dom->readNcGrid(res, filename, varname, first, numValues, multiplier);
137      return res;      return res;
138  }  }
139    
# Line 168  BOOST_PYTHON_MODULE(ripleycpp) Line 233  BOOST_PYTHON_MODULE(ripleycpp)
233    
234      register_exception_translator<ripley::RipleyException>(&(esysUtils::esysExceptionTranslator));      register_exception_translator<ripley::RipleyException>(&(esysUtils::esysExceptionTranslator));
235    
236        scope().attr("__doc__") = "To use this module, please import esys.ripley";
237    
238      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),
239  "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"
240  ":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 189  BOOST_PYTHON_MODULE(ripleycpp) Line 256  BOOST_PYTHON_MODULE(ripleycpp)
256  ":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"
257  ":param d1: number of subdivisions in direction 1\n:type d1: ``int``");  ":param d1: number of subdivisions in direction 1\n:type d1: ``int``");
258      def("_theculprit_", ripley::_who);      def("_theculprit_", ripley::_who);
     def("LoadMesh", ripley::RipleyDomain::loadMesh, (arg("filename")),  
            "Loads a ripley domain from a dump file" ":rtype: `Domain`");  
259    
260      def("ReadMesh", ripley::RipleyDomain::readMesh, (arg("filename")),      def("_readBinaryGrid", &ripley::readBinaryGrid, (arg("filename"), arg("functionspace"), arg("first"), arg("numValues"), arg("multiplier"), arg("shape"), arg("fill")=0.));
             "Reads a ripley domain from a file created by write().\n\n"  
             ":rtype: `RipleyDomain`\n:param filename:\n:type filename: ``string``\n");  
261    
262      def("_readBinaryGrid", &ripley::readBinaryGrid, (arg("filename"), arg("functionspace"), arg("first"), arg("numValues"), arg("shape"), arg("fill")=0.));      def("_readNcGrid", &ripley::readNcGrid, (arg("filename"), arg("varname"), arg("functionspace"), arg("first"), arg("numValues"), arg("multiplier"), arg("shape"), arg("fill")=0.));
263    
264      class_<ripley::RipleyDomain, bases<escript::AbstractContinuousDomain> >      class_<ripley::RipleyDomain, bases<escript::AbstractContinuousDomain>, boost::noncopyable >
265          ("RipleyDomain", "", no_init)          ("RipleyDomain", "", no_init)
         .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().")  
266          .def("print_mesh_info", &ripley::RipleyDomain::Print_Mesh_Info, (arg("full")=false),          .def("print_mesh_info", &ripley::RipleyDomain::Print_Mesh_Info, (arg("full")=false),
267                  "Prints out a summary about the mesh.\n"                  "Prints out a summary about the mesh.\n"
268                  ":param full: whether to output additional data\n:type full: ``bool``")                  ":param full: whether to output additional data\n:type full: ``bool``")

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

  ViewVC Help
Powered by ViewVC 1.1.26