Nektar++
GeomElements.cpp
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // File: TriGeom.cpp
4 //
5 // For more information, please see: http://www.nektar.info/
6 //
7 // The MIT License
8 //
9 // Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
10 // Department of Aeronautics, Imperial College London (UK), and Scientific
11 // Computing and Imaging Institute, University of Utah (USA).
12 //
13 // Permission is hereby granted, free of charge, to any person obtaining a
14 // copy of this software and associated documentation files (the "Software"),
15 // to deal in the Software without restriction, including without limitation
16 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
17 // and/or sell copies of the Software, and to permit persons to whom the
18 // Software is furnished to do so, subject to the following conditions:
19 //
20 // The above copyright notice and this permission notice shall be included
21 // in all copies or substantial portions of the Software.
22 //
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29 // DEALINGS IN THE SOFTWARE.
30 //
31 // Description: Python wrapper for TriGeom.
32 //
33 ////////////////////////////////////////////////////////////////////////////////
34 
36 #include <SpatialDomains/SegGeom.h>
37 #include <SpatialDomains/TriGeom.h>
39 #include <SpatialDomains/TetGeom.h>
41 #include <SpatialDomains/PyrGeom.h>
42 #include <SpatialDomains/HexGeom.h>
44 
45 using namespace Nektar;
46 using namespace Nektar::SpatialDomains;
47 
48 template<class T, class S>
49 std::shared_ptr<T> Geometry_Init(int id, py::list &facets)
50 {
51  std::vector<std::shared_ptr<S>> geomVec;
52 
53  for (int i = 0; i < py::len(facets); ++i)
54  {
55  geomVec.push_back(py::extract<std::shared_ptr<S>>(facets[i]));
56  }
57 
58  return std::make_shared<T>(id, &geomVec[0]);
59 }
60 
61 template<class T, class S, class PARENT>
62 void export_Geom(const char* name)
63 {
64  py::class_<T, py::bases<PARENT>, std::shared_ptr<T> >(name, py::init<>())
65  .def("__init__", py::make_constructor(
66  &Geometry_Init<T, S>, py::default_call_policies(), (
67  py::arg("id"), py::arg("segments")=py::list())));
68 }
69 
70 SegGeomSharedPtr SegGeom_Init(int id, int coordim, py::list &points,
71  py::object &curve)
72 {
73  std::vector<PointGeomSharedPtr> geomVec;
74 
75  for (int i = 0; i < py::len(points); ++i)
76  {
77  geomVec.push_back(py::extract<PointGeomSharedPtr>(points[i]));
78  }
79 
80  if (curve.is_none())
81  {
82  return std::make_shared<SegGeom>(id, coordim, &geomVec[0]);
83  }
84  else
85  {
86  return std::make_shared<SegGeom>(id, coordim, &geomVec[0],
87  py::extract<CurveSharedPtr>(curve));
88  }
89 }
90 
92 {
93  // Geometry dimensioned base classes
94  py::class_<Geometry1D, py::bases<Geometry>, std::shared_ptr<Geometry1D>,
95  boost::noncopyable>(
96  "Geometry1D", py::no_init);
97  py::class_<Geometry2D, py::bases<Geometry>, std::shared_ptr<Geometry2D>,
98  boost::noncopyable>(
99  "Geometry2D", py::no_init);
100  py::class_<Geometry3D, py::bases<Geometry>, std::shared_ptr<Geometry3D>,
101  boost::noncopyable>(
102  "Geometry3D", py::no_init);
103 
104  // Point geometries
105  py::class_<PointGeom, py::bases<Geometry>, std::shared_ptr<PointGeom> >(
106  "PointGeom", py::init<>())
107  .def(py::init<int, int, NekDouble, NekDouble, NekDouble>());
108 
109  // Segment geometries
110  py::class_<SegGeom, py::bases<Geometry>, std::shared_ptr<SegGeom> >(
111  "SegGeom", py::init<>())
112  .def("__init__", py::make_constructor(
113  &SegGeom_Init, py::default_call_policies(), (
114  py::arg("id"), py::arg("coordim"),
115  py::arg("points")=py::list(),
116  py::arg("curve")=py::object())))
117  .def("GetCurve", &SegGeom::GetCurve);
118 
119  export_Geom<TriGeom, SegGeom, Geometry2D>("TriGeom");
120  export_Geom<QuadGeom, SegGeom, Geometry2D>("QuadGeom");
121  export_Geom<TetGeom, TriGeom, Geometry3D>("TetGeom");
122  export_Geom<PrismGeom, Geometry2D, Geometry3D>("PrismGeom");
123  export_Geom<PyrGeom, Geometry2D, Geometry3D>("PyrGeom");
124  export_Geom<HexGeom, QuadGeom, Geometry3D>("HexGeom");
125 }
126 
void export_GeomElements()
std::shared_ptr< T > Geometry_Init(int id, py::list &facets)
SegGeomSharedPtr SegGeom_Init(int id, int coordim, py::list &points, py::object &curve)
void export_Geom(const char *name)
CurveSharedPtr GetCurve()
Definition: SegGeom.h:73
def extract(self, check_equality=False)
Definition: pycml.py:2657
std::shared_ptr< SegGeom > SegGeomSharedPtr
Definition: Geometry2D.h:62
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:1