1d mesh with 0d boundary elements

This commit is contained in:
Joachim Schöberl 2015-11-11 18:46:18 +01:00
parent 4176c41670
commit 3a937d1f36
6 changed files with 108 additions and 12 deletions

View File

@ -7,7 +7,7 @@ NGX_INLINE DLL_HEADER Ng_Point Ngx_Mesh :: GetPoint (int nr) const
template <> template <>
NGX_INLINE DLL_HEADER int Ngx_Mesh :: GetElementIndex<0> (int nr) const NGX_INLINE DLL_HEADER int Ngx_Mesh :: GetElementIndex<0> (int nr) const
{ {
return 0; return (*mesh).pointelements[nr].index;
} }
template <> template <>
@ -29,6 +29,33 @@ NGX_INLINE DLL_HEADER int Ngx_Mesh :: GetElementIndex<3> (int nr) const
return (*mesh)[ElementIndex(nr)].GetIndex(); 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 <> template <>
NGX_INLINE DLL_HEADER Ng_Element Ngx_Mesh :: GetElement<1> (int nr) const NGX_INLINE DLL_HEADER Ng_Element Ngx_Mesh :: GetElement<1> (int nr) const
{ {

View File

@ -120,7 +120,7 @@ namespace netgen
{ {
switch (dim) switch (dim)
{ {
case 0: return 0; // mesh -> GetNV(); case 0: return mesh -> pointelements.Size();
case 1: return mesh -> GetNSeg(); case 1: return mesh -> GetNSeg();
case 2: return mesh -> GetNSE(); case 2: return mesh -> GetNSE();
case 3: return mesh -> GetNE(); case 3: return mesh -> GetNE();
@ -147,13 +147,30 @@ namespace netgen
} }
*/ */
/*
template <> DLL_HEADER Ng_Element Ngx_Mesh :: GetElement<0> (int nr) const template <> DLL_HEADER Ng_Element Ngx_Mesh :: GetElement<0> (int nr) const
{ {
cout << "Netgen does not support 0-D elements" << endl; const Element0d & el = mesh->pointelements[nr];
Ng_Element ret;
return ret; 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 template <> DLL_HEADER Ng_Element Ngx_Mesh :: GetElement<1> (int nr) const
{ {
@ -508,7 +525,9 @@ namespace netgen
double * x, double * x,
double * dxdxi) const 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 * x, size_t sx,
double * dxdxi, size_t sdxdxi) const 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);
} }

View File

@ -247,9 +247,8 @@ namespace netgen
const Array<Segment> & LineSegments() const { return segments; } const Array<Segment> & LineSegments() const { return segments; }
Array<Segment> & LineSegments() { return segments; } Array<Segment> & LineSegments() { return segments; }
Array<Element0d> pointelements; // only via python interface
DLL_HEADER SurfaceElementIndex AddSurfaceElement (const Element2d & el); DLL_HEADER SurfaceElementIndex AddSurfaceElement (const Element2d & el);
void DeleteSurfaceElement (int eli) void DeleteSurfaceElement (int eli)

View File

@ -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) ostream & operator<<(ostream & s, const Element2d & el)

View File

@ -907,7 +907,14 @@ namespace netgen
ostream & operator<<(ostream & s, const Segment & seg); ostream & operator<<(ostream & s, const Segment & seg);
class Element0d
{
public:
PointIndex pnum;
int index;
};
ostream & operator<<(ostream & s, const Element0d & el);
// class Surface; // class Surface;
// class FaceDescriptor; // class FaceDescriptor;

View File

@ -208,7 +208,7 @@ DLL_HEADER void ExportNetgenMeshing()
)), )),
"create segment element" "create segment element"
) )
.def("__repr__", &ToString<Element>) .def("__repr__", &ToString<Segment>)
.add_property("vertices", .add_property("vertices",
FunctionPointer ([](const Segment & self) -> bp::list FunctionPointer ([](const Segment & self) -> bp::list
{ {
@ -228,6 +228,33 @@ DLL_HEADER void ExportNetgenMeshing()
; ;
bp::class_<Element0d>("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<Element0d>)
.add_property("vertices",
FunctionPointer ([](const Element0d & self) -> bp::list
{
bp::list li;
li.append (self.pnum);
return li;
}))
;
bp::class_<FaceDescriptor>("FaceDescriptor") bp::class_<FaceDescriptor>("FaceDescriptor")
@ -263,6 +290,7 @@ DLL_HEADER void ExportNetgenMeshing()
ExportArray<Element>(); ExportArray<Element>();
ExportArray<Element2d>(); ExportArray<Element2d>();
ExportArray<Segment>(); ExportArray<Segment>();
ExportArray<Element0d>();
ExportArray<MeshPoint,PointIndex::BASE,PointIndex>(); ExportArray<MeshPoint,PointIndex::BASE,PointIndex>();
ExportArray<FaceDescriptor>(); ExportArray<FaceDescriptor>();
; ;
@ -323,6 +351,11 @@ DLL_HEADER void ExportNetgenMeshing()
static_cast<Array<Segment>&(Mesh::*)()> (&Mesh::LineSegments), static_cast<Array<Segment>&(Mesh::*)()> (&Mesh::LineSegments),
bp::return_value_policy<bp::reference_existing_object>()) bp::return_value_policy<bp::reference_existing_object>())
.def("Elements0D", FunctionPointer([] (Mesh & self) -> Array<Element0d>&
{
return self.pointelements;
} ),
bp::return_value_policy<bp::reference_existing_object>())
.def("Points", .def("Points",
static_cast<Mesh::T_POINTS&(Mesh::*)()> (&Mesh::Points), static_cast<Mesh::T_POINTS&(Mesh::*)()> (&Mesh::Points),
@ -355,6 +388,11 @@ DLL_HEADER void ExportNetgenMeshing()
{ {
return self.AddSegment (el); 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) .def ("Add", FunctionPointer ([](Mesh & self, const FaceDescriptor & fd)
{ {