/[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 4618 by caltinay, Wed Jan 15 04:35:19 2014 UTC revision 4622 by sshaw, Fri Jan 17 04:55:41 2014 UTC
# Line 107  escript::Data readNcGrid(std::string fil Line 107  escript::Data readNcGrid(std::string fil
107  // 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
108  // truediv  // truediv
109  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,
110                   const object& l1, const object& l2, int d0, int d1, int d2)                   const object& l1, const object& l2, int d0, int d1, int d2,
111                     const object& objpoints, const object& objtags)
112  {  {
113      int n0=static_cast<int>(_n0), n1=static_cast<int>(_n1), n2=static_cast<int>(_n2);      int n0=static_cast<int>(_n0), n1=static_cast<int>(_n1), n2=static_cast<int>(_n2);
114      double x0=0., x1=1., y0=0., y1=1., z0=0., z1=1.;      double x0=0., x1=1., y0=0., y1=1., z0=0., z1=1.;
# Line 147  escript::Domain_ptr _brick(double _n0, d Line 148  escript::Domain_ptr _brick(double _n0, d
148      } else      } else
149          throw RipleyException("Argument l2 must be a float or 2-tuple");          throw RipleyException("Argument l2 must be a float or 2-tuple");
150    
151      return escript::Domain_ptr(new Brick(n0,n1,n2, x0,y0,z0, x1,y1,z1, d0,d1,d2));      boost::python::list pypoints=extract<boost::python::list>(objpoints);
152        boost::python::list pytags=extract<boost::python::list>(objtags);
153        int numpts=extract<int>(pypoints.attr("__len__")());
154        int numtags=extract<int>(pytags.attr("__len__")());
155        std::vector<double> points;
156        std::vector<int> tags;
157        tags.resize(numtags, -1);
158        for (int i=0;i<numpts;++i) {
159            boost::python::object temp=pypoints[i];
160            int l=extract<int>(temp.attr("__len__")());
161            for (int k=0;k<l;++k) {
162                points.push_back(extract<double>(temp[k]));
163            }
164        }
165        std::map<std::string, int> tagstonames;
166        int curmax=40;
167        // but which order to assign tags to names?????
168        for (int i=0;i<numtags;++i) {
169            extract<int> ex_int(pytags[i]);
170            extract<std::string> ex_str(pytags[i]);
171            if (ex_int.check()) {
172                tags[i]=ex_int();
173                if (tags[i]>= curmax) {
174                    curmax=tags[i]+1;
175                }
176            } else if (ex_str.check()) {
177                std::string s=ex_str();
178                std::map<std::string, int>::iterator it=tagstonames.find(s);
179                if (it!=tagstonames.end()) {
180                    // we have the tag already so look it up
181                    tags[i]=it->second;
182                } else {
183                    tagstonames[s]=curmax;
184                    tags[i]=curmax;
185                    curmax++;
186                }
187            } else {
188                throw RipleyException("Error - Unable to extract tag value.");
189            }
190        }
191        return escript::Domain_ptr(new Brick(n0,n1,n2, x0,y0,z0, x1,y1,z1, d0,d1,d2,
192                                                points, tags, tagstonames));
193  }  }
194    
195  const int _q[]={0x61686969,0x746c4144,0x79616e43};  const int _q[]={0x61686969,0x746c4144,0x79616e43};
196  escript::Domain_ptr _rectangle(double _n0, double _n1, const object& l0,  escript::Domain_ptr _rectangle(double _n0, double _n1, const object& l0,
197                                 const object& l1, int d0, int d1)                                 const object& l1, int d0, int d1,
198                                   const object& objpoints, const object& objtags)
199  {  {
200      int n0=static_cast<int>(_n0), n1=static_cast<int>(_n1);      int n0=static_cast<int>(_n0), n1=static_cast<int>(_n1);
201      double x0=0., x1=1., y0=0., y1=1.;      double x0=0., x1=1., y0=0., y1=1.;
# Line 179  escript::Domain_ptr _rectangle(double _n Line 222  escript::Domain_ptr _rectangle(double _n
222          y1=extract<double>(l1);          y1=extract<double>(l1);
223      } else      } else
224          throw RipleyException("Argument l1 must be a float or 2-tuple");          throw RipleyException("Argument l1 must be a float or 2-tuple");
225            
226      return escript::Domain_ptr(new Rectangle(n0,n1, x0,y0, x1,y1, d0,d1));      boost::python::list pypoints=extract<boost::python::list>(objpoints);
227        boost::python::list pytags=extract<boost::python::list>(objtags);
228        int numpts=extract<int>(pypoints.attr("__len__")());
229        int numtags=extract<int>(pytags.attr("__len__")());
230        std::vector<double> points;
231        std::vector<int> tags;
232        tags.resize(numtags, -1);
233        for (int i=0;i<numpts;++i) {
234            boost::python::object temp=pypoints[i];
235            int l=extract<int>(temp.attr("__len__")());
236            for (int k=0;k<l;++k) {
237                points.push_back(extract<double>(temp[k]));
238            }
239        }
240        std::map<std::string, int> tagstonames;
241        int curmax=40;
242        // but which order to assign tags to names?????
243        for (int i=0;i<numtags;++i) {
244            extract<int> ex_int(pytags[i]);
245            extract<std::string> ex_str(pytags[i]);
246            if (ex_int.check()) {
247                tags[i]=ex_int();
248                if (tags[i]>= curmax) {
249                    curmax=tags[i]+1;
250                }
251            } else if (ex_str.check()) {
252                std::string s=ex_str();
253                std::map<std::string, int>::iterator it=tagstonames.find(s);
254                if (it!=tagstonames.end()) {
255                    // we have the tag already so look it up
256                    tags[i]=it->second;
257                } else {
258                    tagstonames[s]=curmax;
259                    tags[i]=curmax;
260                    curmax++;
261                }
262            } else {
263                throw RipleyException("Error - Unable to extract tag value.");
264            }
265        }
266        return escript::Domain_ptr(new Rectangle(n0,n1, x0,y0, x1,y1, d0,d1,
267                                                 points, tags, tagstonames));
268  }  }
269  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];}
270    
# Line 205  BOOST_PYTHON_MODULE(ripleycpp) Line 289  BOOST_PYTHON_MODULE(ripleycpp)
289      scope().attr("DATATYPE_FLOAT32") = (int)ripley::DATATYPE_FLOAT32;      scope().attr("DATATYPE_FLOAT32") = (int)ripley::DATATYPE_FLOAT32;
290      scope().attr("DATATYPE_FLOAT64") = (int)ripley::DATATYPE_FLOAT64;      scope().attr("DATATYPE_FLOAT64") = (int)ripley::DATATYPE_FLOAT64;
291    
292      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,arg("diracPoints")=list(),arg("diracTags")=list()),
293  "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"
294  ":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"
295  ":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"
# Line 217  BOOST_PYTHON_MODULE(ripleycpp) Line 301  BOOST_PYTHON_MODULE(ripleycpp)
301  ":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"
302  ":param d2: number of subdivisions in direction 2\n:type d2: ``int``");  ":param d2: number of subdivisions in direction 2\n:type d2: ``int``");
303    
304      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,arg("diracPoints")=list(),arg("diracTags")=list()),
305  "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"
306  ":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"
307  ":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"
# Line 261  BOOST_PYTHON_MODULE(ripleycpp) Line 345  BOOST_PYTHON_MODULE(ripleycpp)
345          .def("getNumDataPointsGlobal", &ripley::RipleyDomain::getNumDataPointsGlobal,          .def("getNumDataPointsGlobal", &ripley::RipleyDomain::getNumDataPointsGlobal,
346  ":return: the number of data points summed across all MPI processes\n"  ":return: the number of data points summed across all MPI processes\n"
347  ":rtype: ``int``")  ":rtype: ``int``")
348            .def("addToSystem",&ripley::RipleyDomain::addToSystemFromPython,
349                args("mat", "rhs", "data"),
350                "adds a PDE to the system, results depend on domain\n\n"
351                ":param mat:\n:type mat: `OperatorAdapter`\n"
352                ":param rhs:\n:type rhs: `Data`\n"
353                ":param data:\ntype data: `list`")
354          .def("addPDEToSystem",&ripley::RipleyDomain::addPDEToSystem,          .def("addPDEToSystem",&ripley::RipleyDomain::addPDEToSystem,
355  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"),
356  "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"
# Line 275  args("mat", "rhs", "A", "B", "C", "D", " Line 365  args("mat", "rhs", "A", "B", "C", "D", "
365  ":param d_contact:\n:type d_contact: `Data`\n"  ":param d_contact:\n:type d_contact: `Data`\n"
366  ":param y_contact:\n:type y_contact: `Data`"  ":param y_contact:\n:type y_contact: `Data`"
367  )  )
368    
369          .def("addPDEToRHS",&ripley::RipleyDomain::addPDEToRHS,          .def("addPDEToRHS",&ripley::RipleyDomain::addPDEToRHS,
370  args("rhs", "X", "Y", "y", "y_contact"),  args("rhs", "X", "Y", "y", "y_contact"),
371  "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"
# Line 284  args("rhs", "X", "Y", "y", "y_contact"), Line 375  args("rhs", "X", "Y", "y", "y_contact"),
375  ":param y:\n:type y: `Data`\n"  ":param y:\n:type y: `Data`\n"
376  ":param y_contact:\n:type y_contact: `Data`"  ":param y_contact:\n:type y_contact: `Data`"
377  )  )
378            .def("addToRHS",&ripley::RipleyDomain::addToRHSFromPython,
379                args("rhs", "data"),
380                "adds a PDE onto the stiffness matrix mat and a rhs, "
381                "results depends on domain\n\n"
382                ":param rhs:\n:type rhs: `Data`\n"
383                ":param data:\ntype data: `list`")
384            .def("setAssembler", &ripley::RipleyDomain::setAssemblerFromPython,
385                args("typename", "options"),
386                "sets the domain to use the named assembler, if supported, using"
387                "the options if provided"
388                ":param typename:\n:type typename: `string`\n"
389                ":param options:\n:type options: `list`\n")
390          .def("addPDEToTransportProblem",&ripley::RipleyDomain::addPDEToTransportProblem,          .def("addPDEToTransportProblem",&ripley::RipleyDomain::addPDEToTransportProblem,
391  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"),
392  ":param tp:\n:type tp: `TransportProblemAdapter`\n"  ":param tp:\n:type tp: `TransportProblemAdapter`\n"

Legend:
Removed from v.4618  
changed lines
  Added in v.4622

  ViewVC Help
Powered by ViewVC 1.1.26