Segment array with size_t indexing

This commit is contained in:
Joachim Schöberl 2017-10-29 11:31:23 +01:00
parent 8f11b84911
commit 712e2c3fb4
3 changed files with 15 additions and 4 deletions

View File

@ -13,10 +13,16 @@ NGX_INLINE DLL_HEADER int Ngx_Mesh :: GetElementIndex<0> (size_t nr) const
template <> template <>
NGX_INLINE DLL_HEADER int Ngx_Mesh :: GetElementIndex<1> (size_t nr) const NGX_INLINE DLL_HEADER int Ngx_Mesh :: GetElementIndex<1> (size_t nr) const
{ {
/*
if(mesh->GetDimension()==3) if(mesh->GetDimension()==3)
return (*mesh)[SegmentIndex(nr)].edgenr; return (*mesh)[SegmentIndex(nr)].edgenr;
else else
return (*mesh)[SegmentIndex(nr)].si; return (*mesh)[SegmentIndex(nr)].si;
*/
if(mesh->GetDimension()==3)
return mesh->LineSegments()[nr].edgenr;
else
return mesh->LineSegments()[nr].si;
} }
template <> template <>
@ -66,7 +72,8 @@ NGX_INLINE DLL_HEADER Ng_Element Ngx_Mesh :: GetElement<0> (size_t nr) const
template <> template <>
NGX_INLINE DLL_HEADER Ng_Element Ngx_Mesh :: GetElement<1> (size_t nr) const NGX_INLINE DLL_HEADER Ng_Element Ngx_Mesh :: GetElement<1> (size_t nr) const
{ {
const Segment & el = mesh->LineSegment (SegmentIndex(nr)); // const Segment & el = mesh->LineSegment (SegmentIndex(nr));
const Segment & el = mesh->LineSegments()[nr];
Ng_Element ret; Ng_Element ret;
ret.type = NG_ELEMENT_TYPE(el.GetType()); ret.type = NG_ELEMENT_TYPE(el.GetType());

View File

@ -33,7 +33,7 @@ namespace netgen
T_POINTS points; T_POINTS points;
/// line-segments at edges /// line-segments at edges
Array<Segment> segments; Array<Segment, 0, size_t> segments;
/// surface elements, 2d-inner elements /// surface elements, 2d-inner elements
T_SURFELEMENTS surfelements; T_SURFELEMENTS surfelements;
/// volume elements /// volume elements
@ -255,8 +255,12 @@ namespace netgen
const Segment & operator[] (SegmentIndex si) const { return segments[si]; } const Segment & operator[] (SegmentIndex si) const { return segments[si]; }
Segment & operator[] (SegmentIndex si) { return segments[si]; } Segment & operator[] (SegmentIndex si) { return segments[si]; }
/*
const Array<Segment> & LineSegments() const { return segments; } const Array<Segment> & LineSegments() const { return segments; }
Array<Segment> & LineSegments() { return segments; } Array<Segment> & LineSegments() { return segments; }
*/
const auto & LineSegments() const { return segments; }
auto & LineSegments() { return segments; }
Array<Element0d> pointelements; // only via python interface Array<Element0d> pointelements; // only via python interface

View File

@ -425,7 +425,7 @@ DLL_HEADER void ExportNetgenMeshing(py::module &m)
ExportArray<Element,0,size_t>(m); ExportArray<Element,0,size_t>(m);
ExportArray<Element2d,0,size_t>(m); ExportArray<Element2d,0,size_t>(m);
ExportArray<Segment>(m); ExportArray<Segment,0,size_t>(m);
ExportArray<Element0d>(m); ExportArray<Element0d>(m);
ExportArray<MeshPoint,PointIndex::BASE,PointIndex>(m); ExportArray<MeshPoint,PointIndex::BASE,PointIndex>(m);
ExportArray<FaceDescriptor>(m); ExportArray<FaceDescriptor>(m);
@ -553,7 +553,7 @@ DLL_HEADER void ExportNetgenMeshing(py::module &m)
py::return_value_policy::reference) py::return_value_policy::reference)
.def("Elements1D", .def("Elements1D",
static_cast<Array<Segment>&(Mesh::*)()> (&Mesh::LineSegments), static_cast<Array<Segment,0,size_t>&(Mesh::*)()> (&Mesh::LineSegments),
py::return_value_policy::reference) py::return_value_policy::reference)
.def("Elements0D", FunctionPointer([] (Mesh & self) -> Array<Element0d>& .def("Elements0D", FunctionPointer([] (Mesh & self) -> Array<Element0d>&