From 3a937d1f36e168d82c414bb2eaa2d32859f5c9ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20Sch=C3=B6berl?= Date: Wed, 11 Nov 2015 18:46:18 +0100 Subject: [PATCH] 1d mesh with 0d boundary elements --- libsrc/include/nginterface_v2_impl.hpp | 29 ++++++++++++++++++- libsrc/interface/nginterface_v2.cpp | 34 +++++++++++++++++----- libsrc/meshing/meshclass.hpp | 5 ++-- libsrc/meshing/meshtype.cpp | 5 ++++ libsrc/meshing/meshtype.hpp | 7 +++++ libsrc/meshing/python_mesh.cpp | 40 +++++++++++++++++++++++++- 6 files changed, 108 insertions(+), 12 deletions(-) diff --git a/libsrc/include/nginterface_v2_impl.hpp b/libsrc/include/nginterface_v2_impl.hpp index 6596ed16..bd239483 100644 --- a/libsrc/include/nginterface_v2_impl.hpp +++ b/libsrc/include/nginterface_v2_impl.hpp @@ -7,7 +7,7 @@ NGX_INLINE DLL_HEADER Ng_Point Ngx_Mesh :: GetPoint (int nr) const template <> NGX_INLINE DLL_HEADER int Ngx_Mesh :: GetElementIndex<0> (int nr) const { - return 0; + return (*mesh).pointelements[nr].index; } template <> @@ -29,6 +29,33 @@ NGX_INLINE DLL_HEADER int Ngx_Mesh :: GetElementIndex<3> (int nr) const return (*mesh)[ElementIndex(nr)].GetIndex(); } + +template <> +NGX_INLINE DLL_HEADER Ng_Element Ngx_Mesh :: GetElement<0> (int nr) const +{ + const Element0d & el = mesh->pointelements[nr]; + + Ng_Element ret; + ret.type = NG_PNT; + ret.index = el.index; + + ret.points.num = 1; + ret.points.ptr = (int*)&el.pnum; + + ret.vertices.num = 1; + ret.vertices.ptr = (int*)&el.pnum; + + ret.edges.num = 0; + ret.edges.ptr = NULL; + + ret.faces.num = 0; + ret.faces.ptr = NULL; + + return ret; +} + + + template <> NGX_INLINE DLL_HEADER Ng_Element Ngx_Mesh :: GetElement<1> (int nr) const { diff --git a/libsrc/interface/nginterface_v2.cpp b/libsrc/interface/nginterface_v2.cpp index 84a5cd33..dc78cfa5 100644 --- a/libsrc/interface/nginterface_v2.cpp +++ b/libsrc/interface/nginterface_v2.cpp @@ -120,7 +120,7 @@ namespace netgen { switch (dim) { - case 0: return 0; // mesh -> GetNV(); + case 0: return mesh -> pointelements.Size(); case 1: return mesh -> GetNSeg(); case 2: return mesh -> GetNSE(); case 3: return mesh -> GetNE(); @@ -147,13 +147,30 @@ namespace netgen } */ + /* template <> DLL_HEADER Ng_Element Ngx_Mesh :: GetElement<0> (int nr) const { - cout << "Netgen does not support 0-D elements" << endl; - Ng_Element ret; - return ret; - } + const Element0d & el = mesh->pointelements[nr]; + + Ng_Element ret; + ret.type = NG_PNT; + ret.index = el.index; + ret.points.num = 1; + ret.points.ptr = (int*)&el.pnum; + + ret.vertices.num = 1; + ret.vertices.ptr = (int*)&el.pnum; + + ret.edges.num = 0; + ret.edges.ptr = NULL; + + ret.faces.num = 0; + ret.faces.ptr = NULL; + + return ret; + } + */ /* template <> DLL_HEADER Ng_Element Ngx_Mesh :: GetElement<1> (int nr) const { @@ -508,7 +525,9 @@ namespace netgen double * x, double * dxdxi) const { - cout << "1D not supported" << endl; + PointIndex pnum = mesh->pointelements[elnr].pnum; + if (x) x[0] = (*mesh)[pnum](0); + if (dxdxi) dxdxi[0] = 0; } @@ -574,7 +593,8 @@ namespace netgen double * x, size_t sx, double * dxdxi, size_t sdxdxi) const { - cout << "1D not supported" << endl; + for (int i = 0; i < npts; i++) + ElementTransformation<0,1> (elnr, xi + i*sxi, x+i*sx, dxdxi+i*sdxdxi); } diff --git a/libsrc/meshing/meshclass.hpp b/libsrc/meshing/meshclass.hpp index aac2e4b8..1f18832d 100644 --- a/libsrc/meshing/meshclass.hpp +++ b/libsrc/meshing/meshclass.hpp @@ -247,9 +247,8 @@ namespace netgen const Array & LineSegments() const { return segments; } Array & LineSegments() { return segments; } - - - + + Array pointelements; // only via python interface DLL_HEADER SurfaceElementIndex AddSurfaceElement (const Element2d & el); void DeleteSurfaceElement (int eli) diff --git a/libsrc/meshing/meshtype.cpp b/libsrc/meshing/meshtype.cpp index b1417f3c..042bfeac 100644 --- a/libsrc/meshing/meshtype.cpp +++ b/libsrc/meshing/meshtype.cpp @@ -914,6 +914,11 @@ namespace netgen + ostream & operator<<(ostream & s, const Element0d & el) + { + s << el.pnum << ", index = " << el.index; + return s; + } ostream & operator<<(ostream & s, const Element2d & el) diff --git a/libsrc/meshing/meshtype.hpp b/libsrc/meshing/meshtype.hpp index 458cbec6..7d5abfd0 100644 --- a/libsrc/meshing/meshtype.hpp +++ b/libsrc/meshing/meshtype.hpp @@ -907,7 +907,14 @@ namespace netgen ostream & operator<<(ostream & s, const Segment & seg); + class Element0d + { + public: + PointIndex pnum; + int index; + }; + ostream & operator<<(ostream & s, const Element0d & el); // class Surface; // class FaceDescriptor; diff --git a/libsrc/meshing/python_mesh.cpp b/libsrc/meshing/python_mesh.cpp index c47368a8..404d4b09 100644 --- a/libsrc/meshing/python_mesh.cpp +++ b/libsrc/meshing/python_mesh.cpp @@ -208,7 +208,7 @@ DLL_HEADER void ExportNetgenMeshing() )), "create segment element" ) - .def("__repr__", &ToString) + .def("__repr__", &ToString) .add_property("vertices", FunctionPointer ([](const Segment & self) -> bp::list { @@ -228,6 +228,33 @@ DLL_HEADER void ExportNetgenMeshing() ; + bp::class_("Element0D") + .def("__init__", bp::make_constructor + (FunctionPointer ([](PointIndex vertex, int index) + { + Element0d * tmp = new Element0d; + tmp->pnum = vertex; + tmp->index = index; + return tmp; + }), + bp::default_call_policies(), + (bp::arg("vertex"), + bp::arg("index")=1 + )), + "create point element" + ) + .def("__repr__", &ToString) + .add_property("vertices", + FunctionPointer ([](const Element0d & self) -> bp::list + { + bp::list li; + li.append (self.pnum); + return li; + })) + ; + + + bp::class_("FaceDescriptor") @@ -263,6 +290,7 @@ DLL_HEADER void ExportNetgenMeshing() ExportArray(); ExportArray(); ExportArray(); + ExportArray(); ExportArray(); ExportArray(); ; @@ -323,6 +351,11 @@ DLL_HEADER void ExportNetgenMeshing() static_cast&(Mesh::*)()> (&Mesh::LineSegments), bp::return_value_policy()) + .def("Elements0D", FunctionPointer([] (Mesh & self) -> Array& + { + return self.pointelements; + } ), + bp::return_value_policy()) .def("Points", static_cast (&Mesh::Points), @@ -355,6 +388,11 @@ DLL_HEADER void ExportNetgenMeshing() { return self.AddSegment (el); })) + + .def ("Add", FunctionPointer ([](Mesh & self, const Element0d & el) + { + return self.pointelements.Append (el); + })) .def ("Add", FunctionPointer ([](Mesh & self, const FaceDescriptor & fd) {