Index operators

This commit is contained in:
Joachim Schoeberl 2025-01-06 11:26:50 +01:00
parent 59e5974a28
commit c0b33db5c0
2 changed files with 19 additions and 15 deletions

View File

@ -479,8 +479,8 @@ namespace netgen
mp.sloppy = 5; mp.sloppy = 5;
meshing.GenerateMesh (mesh, mp); meshing.GenerateMesh (mesh, mp);
for (ElementIndex ei = oldne; ei < mesh.GetNE(); ei++) for (auto & el : mesh.VolumeElements().Range(oldne, END))
mesh[ei].SetIndex (domain); el.SetIndex (domain);
mesh.CalcSurfacesOfNode(); mesh.CalcSurfacesOfNode();

View File

@ -202,15 +202,15 @@ namespace netgen
template <typename T, typename TIndex, int Base> template <typename T, typename TIndex, int Base>
constexpr inline auto operator- (Index<T,TIndex,Base> pi, int i) -> TIndex { return TIndex(pi.i-i); } constexpr inline auto operator- (Index<T,TIndex,Base> pi, int i) -> TIndex { return TIndex(pi.i-i); }
template <typename T, typename TIndex, int Base> template <typename T, typename TIndex, int Base>
constexpr inline int operator- (Index<T,TIndex,Base> pa, Index<T,TIndex,Base> pb) { return pa.i-pb.i; } constexpr inline auto operator- (Index<T,TIndex,Base> pa, Index<T,TIndex,Base> pb) { return pa.i-pb.i; }
template <typename T, typename TIndex, int Base> template <typename T, typename TIndex, int Base>
inline bool operator< (Index<T,TIndex,Base> a, Index<T,TIndex,Base> b) { return a.i-b.i < 0; } inline bool operator< (Index<T,TIndex,Base> a, Index<T,TIndex,Base> b) { return a-b < 0; }
template <typename T, typename TIndex, int Base> template <typename T, typename TIndex, int Base>
inline bool operator> (Index<T,TIndex,Base> a, Index<T,TIndex,Base> b) { return a.i-b.i > 0; } inline bool operator> (Index<T,TIndex,Base> a, Index<T,TIndex,Base> b) { return a-b > 0; }
template <typename T, typename TIndex, int Base> template <typename T, typename TIndex, int Base>
inline bool operator>= (Index<T,TIndex,Base> a, Index<T,TIndex,Base> b) { return a.i-b.i >= 0; } inline bool operator>= (Index<T,TIndex,Base> a, Index<T,TIndex,Base> b) { return a-b >= 0; }
template <typename T, typename TIndex, int Base> template <typename T, typename TIndex, int Base>
inline bool operator<= (Index<T,TIndex,Base> a, Index<T,TIndex,Base> b) { return a.i-b.i <= 0; } inline bool operator<= (Index<T,TIndex,Base> a, Index<T,TIndex,Base> b) { return a-b <= 0; }
template <typename T, typename TIndex, int Base> template <typename T, typename TIndex, int Base>
inline bool operator== (Index<T,TIndex,Base> a, Index<T,TIndex,Base> b) { return a.i == b.i; } inline bool operator== (Index<T,TIndex,Base> a, Index<T,TIndex,Base> b) { return a.i == b.i; }
template <typename T, typename TIndex, int Base> template <typename T, typename TIndex, int Base>
@ -421,27 +421,28 @@ namespace netgen
class ElementIndex : public Index<int,ElementIndex,0> class ElementIndex : public Index<int,ElementIndex,0>
{ {
public: public:
using Index<int,ElementIndex,0>::Index; using Index::Index; // <int,ElementIndex,0>::Index;
}; };
inline istream & operator>> (istream & ist, ElementIndex & pi) inline istream & operator>> (istream & ist, ElementIndex & ei)
{ {
int i; ist >> i; pi = i; return ist; int i; ist >> i; ei = ElementIndex::Base()+i; return ist;
} }
inline ostream & operator<< (ostream & ost, const ElementIndex & ei) inline ostream & operator<< (ostream & ost, const ElementIndex & ei)
{ {
return (ost << ei-IndexBASE<ElementIndex>()); return ost << int(ei-ElementIndex::Base());
} }
/*
// these should not be needed soon // these should not be needed soon
inline bool operator== (Index<int,ElementIndex,0> ei1, int ei2) { return int(ei1) == int(ei2); }; inline bool operator== (Index<int,ElementIndex,0> ei1, int ei2) { return int(ei1) == int(ei2); };
inline bool operator< (size_t s, Index<int,ElementIndex,0> ei2) { return int(s) < int(ei2); }; inline bool operator< (size_t s, Index<int,ElementIndex,0> ei2) { return int(s) < int(ei2); };
inline bool operator< ( Index<int,ElementIndex,0> ei1, size_t s) { return int(ei1) < int(s); }; // should not need inline bool operator< ( Index<int,ElementIndex,0> ei1, size_t s) { return int(ei1) < int(s); }; // should not need
inline bool operator< ( Index<int,ElementIndex,0> ei1, int s) { return int(ei1) < int(s); }; // should not need inline bool operator< ( Index<int,ElementIndex,0> ei1, int s) { return int(ei1) < int(s); }; // should not need
inline bool operator>= (size_t s, Index<int,ElementIndex,0> ei2) { return int(s) >= int(ei2); }; inline bool operator>= (size_t s, Index<int,ElementIndex,0> ei2) { return int(s) >= int(ei2); };
*/
class SurfaceElementIndex : public Index<int,SurfaceElementIndex,0> class SurfaceElementIndex : public Index<int,SurfaceElementIndex,0>
{ {
@ -451,6 +452,7 @@ namespace netgen
// these should not be needed soon // these should not be needed soon
/*
inline bool operator== (Index<int, SurfaceElementIndex,0> ei1, int ei2) { return int(ei1) == int(ei2); }; inline bool operator== (Index<int, SurfaceElementIndex,0> ei1, int ei2) { return int(ei1) == int(ei2); };
inline bool operator== (int ei2, Index<int, SurfaceElementIndex,0> ei1) { return int(ei1) == int(ei2); }; inline bool operator== (int ei2, Index<int, SurfaceElementIndex,0> ei1) { return int(ei1) == int(ei2); };
inline bool operator!= (Index<int, SurfaceElementIndex,0> ei1, int ei2) { return int(ei1) != int(ei2); }; inline bool operator!= (Index<int, SurfaceElementIndex,0> ei1, int ei2) { return int(ei1) != int(ei2); };
@ -459,7 +461,7 @@ namespace netgen
inline bool operator< (Index<int, SurfaceElementIndex,0> ei1, int s) { return int(ei1) < int(s); }; // should not need inline bool operator< (Index<int, SurfaceElementIndex,0> ei1, int s) { return int(ei1) < int(s); }; // should not need
inline bool operator>= (size_t s, Index<int, SurfaceElementIndex,0> ei2) { return int(s) >= int(ei2); }; inline bool operator>= (size_t s, Index<int, SurfaceElementIndex,0> ei2) { return int(s) >= int(ei2); };
inline bool operator>= (Index<int, SurfaceElementIndex,0> ei1, int s) { return int(ei1) >= int(s); }; inline bool operator>= (Index<int, SurfaceElementIndex,0> ei1, int s) { return int(ei1) >= int(s); };
*/
inline void SetInvalid (SurfaceElementIndex & id) { id = -1; } inline void SetInvalid (SurfaceElementIndex & id) { id = -1; }
inline bool IsInvalid (SurfaceElementIndex & id) { return id == -1; } inline bool IsInvalid (SurfaceElementIndex & id) { return id == -1; }
@ -482,10 +484,12 @@ namespace netgen
}; };
// these should not be needed soon // these should not be needed soon
/*
inline bool operator== (Index<int, SegmentIndex,0> ei1, int ei2) { return int(ei1) == int(ei2); }; inline bool operator== (Index<int, SegmentIndex,0> ei1, int ei2) { return int(ei1) == int(ei2); };
inline bool operator< (size_t s, Index<int,SegmentIndex,0> ei2) { return int(s) < int(ei2); }; inline bool operator< (size_t s, Index<int,SegmentIndex,0> ei2) { return int(s) < int(ei2); };
inline bool operator< (Index<int, SegmentIndex,0> ei1, size_t s) { return int(ei1) < int(s); }; inline bool operator< (Index<int, SegmentIndex,0> ei1, size_t s) { return int(ei1) < int(s); };
inline bool operator< (Index<int, SegmentIndex,0> ei1, int s) { return int(ei1) < int(s); }; inline bool operator< (Index<int, SegmentIndex,0> ei1, int s) { return int(ei1) < int(s); };
*/
inline void SetInvalid (SegmentIndex & id) { id = -1; } inline void SetInvalid (SegmentIndex & id) { id = -1; }
inline bool IsInvalid (SegmentIndex & id) { return id == -1; } inline bool IsInvalid (SegmentIndex & id) { return id == -1; }