From cb87362f6452a8b791fb32b00d8c8a16687e5e52 Mon Sep 17 00:00:00 2001 From: Matthias Hochsteger Date: Tue, 9 Jul 2019 10:39:16 +0200 Subject: [PATCH 01/11] Rename Array to NgArray --- libsrc/csg/algprim.cpp | 32 +++--- libsrc/csg/algprim.hpp | 32 +++--- libsrc/csg/brick.cpp | 6 +- libsrc/csg/brick.hpp | 8 +- libsrc/csg/csgeom.cpp | 32 +++--- libsrc/csg/csgeom.hpp | 38 +++---- libsrc/csg/csgparser.cpp | 20 ++-- libsrc/csg/csgpkg.cpp | 4 +- libsrc/csg/edgeflw.cpp | 66 ++++++------ libsrc/csg/edgeflw.hpp | 40 +++---- libsrc/csg/explicitcurve2d.hpp | 4 +- libsrc/csg/extrusion.cpp | 16 +-- libsrc/csg/extrusion.hpp | 16 +-- libsrc/csg/genmesh.cpp | 16 +-- libsrc/csg/identify.cpp | 42 ++++---- libsrc/csg/identify.hpp | 30 +++--- libsrc/csg/polyhedra.cpp | 20 ++-- libsrc/csg/polyhedra.hpp | 22 ++-- libsrc/csg/python_csg.cpp | 14 +-- libsrc/csg/revolution.cpp | 18 ++-- libsrc/csg/revolution.hpp | 14 +-- libsrc/csg/singularref.cpp | 4 +- libsrc/csg/singularref.hpp | 10 +- libsrc/csg/solid.cpp | 46 ++++----- libsrc/csg/solid.hpp | 42 ++++---- libsrc/csg/specpoin.cpp | 48 ++++----- libsrc/csg/specpoin.hpp | 20 ++-- libsrc/csg/spline3d.hpp | 2 +- libsrc/csg/splinesurface.cpp | 4 +- libsrc/csg/splinesurface.hpp | 24 ++--- libsrc/csg/surface.cpp | 10 +- libsrc/csg/surface.hpp | 18 ++-- libsrc/csg/triapprox.cpp | 2 +- libsrc/csg/triapprox.hpp | 6 +- libsrc/csg/vscsg.cpp | 4 +- libsrc/csg/vscsg.hpp | 2 +- libsrc/csg/zrefine.cpp | 14 +-- libsrc/general/array.cpp | 6 +- libsrc/general/array.hpp | 48 ++++----- libsrc/general/bitarray.hpp | 2 +- libsrc/general/flags.cpp | 16 +-- libsrc/general/flags.hpp | 12 +-- libsrc/general/hashtabl.hpp | 16 +-- libsrc/general/mpi_interface.hpp | 20 ++-- libsrc/general/optmem.cpp | 2 +- libsrc/general/optmem.hpp | 2 +- libsrc/general/seti.hpp | 4 +- libsrc/general/sort.cpp | 12 +-- libsrc/general/sort.hpp | 10 +- libsrc/general/stack.hpp | 2 +- libsrc/general/table.hpp | 2 +- libsrc/geom2d/genmesh2d.cpp | 24 ++--- libsrc/geom2d/geometry2d.cpp | 14 +-- libsrc/geom2d/geometry2d.hpp | 14 +-- libsrc/geom2d/python_geom2d.cpp | 2 +- libsrc/geom2d/spline2d.hpp | 14 +-- libsrc/geom2d/vsgeom2d.cpp | 2 +- libsrc/gprim/adtree.cpp | 44 ++++---- libsrc/gprim/adtree.hpp | 46 ++++----- libsrc/gprim/geom2d.hpp | 2 +- libsrc/gprim/geom3d.cpp | 4 +- libsrc/gprim/geom3d.hpp | 2 +- libsrc/gprim/spline.cpp | 10 +- libsrc/gprim/spline.hpp | 36 +++---- libsrc/gprim/splinegeometry.cpp | 8 +- libsrc/gprim/splinegeometry.hpp | 10 +- libsrc/include/nginterface_v2_impl.hpp | 2 +- libsrc/interface/nginterface.cpp | 38 +++---- libsrc/interface/nginterface_v2.cpp | 4 +- libsrc/interface/read_fnf_mesh.cpp | 12 +-- libsrc/interface/readtetmesh.cpp | 30 +++--- libsrc/interface/readuser.cpp | 4 +- libsrc/interface/writeOpenFOAM15x.cpp | 24 ++--- libsrc/interface/writeabaqus.cpp | 4 +- libsrc/interface/writediffpack.cpp | 8 +- libsrc/interface/writefluent.cpp | 6 +- libsrc/interface/writejcm.cpp | 4 +- libsrc/interface/writetecplot.cpp | 2 +- libsrc/interface/writetet.cpp | 62 +++++------ libsrc/interface/writeuser.cpp | 12 +-- libsrc/interface/writeuser.hpp | 4 +- libsrc/interface/wuchemnitz.cpp | 10 +- libsrc/linalg/densemat.cpp | 6 +- libsrc/meshing/adfront2.cpp | 16 +-- libsrc/meshing/adfront2.hpp | 24 ++--- libsrc/meshing/adfront3.cpp | 34 +++--- libsrc/meshing/adfront3.hpp | 32 +++--- libsrc/meshing/basegeom.cpp | 2 +- libsrc/meshing/basegeom.hpp | 4 +- libsrc/meshing/bcfunctions.cpp | 20 ++-- libsrc/meshing/bcfunctions.hpp | 2 +- libsrc/meshing/bisect.cpp | 86 +++++++-------- libsrc/meshing/bisect.hpp | 4 +- libsrc/meshing/boundarylayer.cpp | 16 +-- libsrc/meshing/boundarylayer.hpp | 6 +- libsrc/meshing/classifyhpel.hpp | 16 +-- libsrc/meshing/clusters.cpp | 6 +- libsrc/meshing/clusters.hpp | 2 +- libsrc/meshing/curvedelems.cpp | 74 ++++++------- libsrc/meshing/curvedelems.hpp | 36 +++---- libsrc/meshing/delaunay.cpp | 42 ++++---- libsrc/meshing/delaunay2d.cpp | 12 +-- libsrc/meshing/findip.hpp | 8 +- libsrc/meshing/findip2.hpp | 4 +- libsrc/meshing/geomsearch.cpp | 8 +- libsrc/meshing/geomsearch.hpp | 10 +- libsrc/meshing/global.cpp | 2 +- libsrc/meshing/global.hpp | 2 +- libsrc/meshing/hprefinement.cpp | 40 +++---- libsrc/meshing/improve2.cpp | 22 ++-- libsrc/meshing/improve2.hpp | 4 +- libsrc/meshing/improve2gen.cpp | 26 ++--- libsrc/meshing/improve3.cpp | 40 +++---- libsrc/meshing/improve3.hpp | 8 +- libsrc/meshing/localh.cpp | 20 ++-- libsrc/meshing/localh.hpp | 14 +-- libsrc/meshing/meshclass.cpp | 68 ++++++------ libsrc/meshing/meshclass.hpp | 106 +++++++++---------- libsrc/meshing/meshfunc.cpp | 4 +- libsrc/meshing/meshing2.cpp | 52 +++++----- libsrc/meshing/meshing2.hpp | 18 ++-- libsrc/meshing/meshing3.cpp | 44 ++++---- libsrc/meshing/meshing3.hpp | 16 +-- libsrc/meshing/meshtool.cpp | 14 +-- libsrc/meshing/meshtool.hpp | 18 ++-- libsrc/meshing/meshtype.cpp | 30 +++--- libsrc/meshing/meshtype.hpp | 28 ++--- libsrc/meshing/msghandler.cpp | 4 +- libsrc/meshing/netrule2.cpp | 2 +- libsrc/meshing/netrule3.cpp | 36 +++---- libsrc/meshing/parallelmesh.cpp | 138 ++++++++++++------------- libsrc/meshing/paralleltop.cpp | 36 +++---- libsrc/meshing/paralleltop.hpp | 8 +- libsrc/meshing/parser2.cpp | 6 +- libsrc/meshing/parser3.cpp | 24 ++--- libsrc/meshing/python_mesh.cpp | 30 +++--- libsrc/meshing/refine.cpp | 16 +-- libsrc/meshing/ruler2.cpp | 16 +-- libsrc/meshing/ruler2.hpp | 30 +++--- libsrc/meshing/ruler3.cpp | 26 ++--- libsrc/meshing/ruler3.hpp | 46 ++++----- libsrc/meshing/secondorder.cpp | 10 +- libsrc/meshing/smoothing2.5.cpp | 14 +-- libsrc/meshing/smoothing2.cpp | 24 ++--- libsrc/meshing/smoothing3.cpp | 28 ++--- libsrc/meshing/specials.cpp | 4 +- libsrc/meshing/topology.cpp | 48 ++++----- libsrc/meshing/topology.hpp | 50 ++++----- libsrc/meshing/validate.cpp | 26 ++--- libsrc/meshing/validate.hpp | 14 +-- libsrc/occ/occgenmesh.cpp | 24 ++--- libsrc/occ/occgeom.cpp | 4 +- libsrc/occ/occgeom.hpp | 14 +-- libsrc/occ/occpkg.cpp | 20 ++-- libsrc/occ/vsocc.hpp | 4 +- libsrc/stlgeom/meshstlsurface.cpp | 30 +++--- libsrc/stlgeom/meshstlsurface.hpp | 6 +- libsrc/stlgeom/stlgeom.cpp | 70 ++++++------- libsrc/stlgeom/stlgeom.hpp | 68 ++++++------ libsrc/stlgeom/stlgeomchart.cpp | 32 +++--- libsrc/stlgeom/stlgeommesh.cpp | 56 +++++----- libsrc/stlgeom/stlline.cpp | 24 ++--- libsrc/stlgeom/stlline.hpp | 24 ++--- libsrc/stlgeom/stltool.cpp | 40 +++---- libsrc/stlgeom/stltool.hpp | 24 ++--- libsrc/stlgeom/stltopology.cpp | 22 ++-- libsrc/stlgeom/stltopology.hpp | 30 +++--- libsrc/stlgeom/vsstl.cpp | 4 +- libsrc/stlgeom/vsstl.hpp | 4 +- libsrc/visualization/meshdoc.hpp | 2 +- libsrc/visualization/mvdraw.cpp | 6 +- libsrc/visualization/mvdraw.hpp | 6 +- libsrc/visualization/stlmeshing.cpp | 4 +- libsrc/visualization/vsfieldlines.cpp | 32 +++--- libsrc/visualization/vsmesh.cpp | 22 ++-- libsrc/visualization/vssolution.cpp | 114 ++++++++++---------- libsrc/visualization/vssolution.hpp | 32 +++--- ng/demoview.hpp | 4 +- ng/ngappinit.cpp | 6 +- ng/ngpkg.cpp | 12 +-- ng/parallelfunc.cpp | 2 +- nglib/nglib.cpp | 4 +- 182 files changed, 1893 insertions(+), 1893 deletions(-) diff --git a/libsrc/csg/algprim.cpp b/libsrc/csg/algprim.cpp index 0f870d98..f72574d0 100644 --- a/libsrc/csg/algprim.cpp +++ b/libsrc/csg/algprim.cpp @@ -116,7 +116,7 @@ namespace netgen void Plane :: GetPrimitiveData (const char *& classname, - Array & coeffs) const + NgArray & coeffs) const { classname = "plane"; coeffs.SetSize (6); @@ -128,7 +128,7 @@ namespace netgen coeffs.Elem(6) = n(2); } - void Plane :: SetPrimitiveData (Array & coeffs) + void Plane :: SetPrimitiveData (NgArray & coeffs) { p(0) = coeffs.Elem(1); p(1) = coeffs.Elem(2); @@ -367,7 +367,7 @@ namespace netgen c1 = (c(0) * c(0) + c(1) * c(1) + c(2) * c(2)) / (2 * r) - r / 2; } - void Sphere :: GetPrimitiveData (const char *& classname, Array & coeffs) const + void Sphere :: GetPrimitiveData (const char *& classname, NgArray & coeffs) const { classname = "sphere"; coeffs.SetSize (4); @@ -377,7 +377,7 @@ namespace netgen coeffs.Elem(4) = r; } - void Sphere :: SetPrimitiveData (Array & coeffs) + void Sphere :: SetPrimitiveData (NgArray & coeffs) { c(0) = coeffs.Elem(1); c(1) = coeffs.Elem(2); @@ -731,7 +731,7 @@ namespace netgen - Cylinder :: Cylinder (Array & coeffs) + Cylinder :: Cylinder (NgArray & coeffs) { SetPrimitiveData(coeffs); } @@ -773,7 +773,7 @@ namespace netgen - void Cylinder :: GetPrimitiveData (const char *& classname, Array & coeffs) const + void Cylinder :: GetPrimitiveData (const char *& classname, NgArray & coeffs) const { classname = "cylinder"; coeffs.SetSize (7); @@ -786,7 +786,7 @@ namespace netgen coeffs.Elem(7) = r; } - void Cylinder :: SetPrimitiveData (Array & coeffs) + void Cylinder :: SetPrimitiveData (NgArray & coeffs) { a(0) = coeffs.Elem(1); a(1) = coeffs.Elem(2); @@ -1127,14 +1127,14 @@ namespace netgen CalcData(); } - EllipticCylinder :: EllipticCylinder (Array & coeffs) + EllipticCylinder :: EllipticCylinder (NgArray & coeffs) { SetPrimitiveData(coeffs); } - void EllipticCylinder :: GetPrimitiveData (const char *& classname, Array & coeffs) const + void EllipticCylinder :: GetPrimitiveData (const char *& classname, NgArray & coeffs) const { classname = "ellipticcylinder"; coeffs.SetSize (9); @@ -1149,7 +1149,7 @@ namespace netgen coeffs[8] = vs(2); } - void EllipticCylinder :: SetPrimitiveData (Array & coeffs) + void EllipticCylinder :: SetPrimitiveData (NgArray & coeffs) { a(0) = coeffs[0]; a(1) = coeffs[1]; @@ -1312,7 +1312,7 @@ namespace netgen - void Cone :: GetPrimitiveData (const char *& classname, Array & coeffs) const + void Cone :: GetPrimitiveData (const char *& classname, NgArray & coeffs) const { classname = "cone"; coeffs.SetSize (8); @@ -1326,7 +1326,7 @@ namespace netgen coeffs.Elem(8) = rb; } - void Cone :: SetPrimitiveData (Array & coeffs) + void Cone :: SetPrimitiveData (NgArray & coeffs) { a(0) = coeffs.Elem(1); a(1) = coeffs.Elem(2); @@ -1537,7 +1537,7 @@ Primitive * EllipticCone :: CreateDefault () } - void EllipticCone :: GetPrimitiveData (const char *& classname, Array & coeffs) const + void EllipticCone :: GetPrimitiveData (const char *& classname, NgArray & coeffs) const { classname = "ellipticcone"; coeffs.SetSize (15); @@ -1556,7 +1556,7 @@ Primitive * EllipticCone :: CreateDefault () } - void EllipticCone :: SetPrimitiveData (Array & coeffs) + void EllipticCone :: SetPrimitiveData (NgArray & coeffs) { a(0) = coeffs.Elem(1); @@ -1727,7 +1727,7 @@ void EllipticCone :: GetTriangleApproximation r = ar; } - void Torus :: GetPrimitiveData (const char *& classname, Array & coeffs) const + void Torus :: GetPrimitiveData (const char *& classname, NgArray & coeffs) const { classname = "torus"; coeffs.SetSize (8); @@ -1741,7 +1741,7 @@ void EllipticCone :: GetTriangleApproximation coeffs.Elem(8) = r; } - void Torus :: SetPrimitiveData (Array & coeffs) + void Torus :: SetPrimitiveData (NgArray & coeffs) { c(0) = coeffs.Elem(1); c(1) = coeffs.Elem(2); diff --git a/libsrc/csg/algprim.hpp b/libsrc/csg/algprim.hpp index 6daf643b..fde47dc4 100644 --- a/libsrc/csg/algprim.hpp +++ b/libsrc/csg/algprim.hpp @@ -80,8 +80,8 @@ namespace netgen Point<3> P() const { return p; } Vec<3> N() const { return n; } virtual void GetPrimitiveData (const char *& classname, - Array & coeffs) const; - virtual void SetPrimitiveData (Array & coeffs); + NgArray & coeffs) const; + virtual void SetPrimitiveData (NgArray & coeffs); static Primitive * CreateDefault (); virtual Primitive * Copy () const; @@ -153,8 +153,8 @@ namespace netgen } virtual void GetPrimitiveData (const char *& classname, - Array & coeffs) const; - virtual void SetPrimitiveData (Array & coeffs); + NgArray & coeffs) const; + virtual void SetPrimitiveData (NgArray & coeffs); static Primitive * CreateDefault (); virtual Primitive * Copy () const; @@ -208,7 +208,7 @@ namespace netgen public: Cylinder (const Point<3> & aa, const Point<3> & ab, double ar); - Cylinder (Array & coeffs); + Cylinder (NgArray & coeffs); // default constructor for archive Cylinder() {} @@ -220,8 +220,8 @@ namespace netgen Point<3> A() const { return a; } Point<3> B() const { return b; } double R() const { return r; } - virtual void GetPrimitiveData (const char *& classname, Array & coeffs) const; - virtual void SetPrimitiveData (Array & coeffs); + virtual void GetPrimitiveData (const char *& classname, NgArray & coeffs) const; + virtual void SetPrimitiveData (NgArray & coeffs); static Primitive * CreateDefault (); virtual Primitive * Copy () const; @@ -278,7 +278,7 @@ namespace netgen /// EllipticCylinder (const Point<3> & aa, const Vec<3> & avl, const Vec<3> & avs); - EllipticCylinder (Array & coeffs); + EllipticCylinder (NgArray & coeffs); // default constructor for archive EllipticCylinder() {} @@ -289,8 +289,8 @@ namespace netgen } // static Primitive * CreateDefault (); - virtual void GetPrimitiveData (const char *& classname, Array & coeffs) const; - virtual void SetPrimitiveData (Array & coeffs); + virtual void GetPrimitiveData (const char *& classname, NgArray & coeffs) const; + virtual void SetPrimitiveData (NgArray & coeffs); /// virtual INSOLID_TYPE BoxInSolid (const BoxSphere<3> & box) const; @@ -393,8 +393,8 @@ namespace netgen ar & a & b & ra & rb & minr & vab & t0vec & t1vec & vabl & t0 & t1 & cosphi; } static Primitive * CreateDefault (); - virtual void GetPrimitiveData (const char *& classname, Array & coeffs) const; - virtual void SetPrimitiveData (Array & coeffs); + virtual void GetPrimitiveData (const char *& classname, NgArray & coeffs) const; + virtual void SetPrimitiveData (NgArray & coeffs); /// virtual INSOLID_TYPE BoxInSolid (const BoxSphere<3> & box) const; @@ -445,8 +445,8 @@ namespace netgen ar & a & vl & vs & h & vlr; } static Primitive * CreateDefault (); - virtual void GetPrimitiveData (const char *& classname, Array & coeffs) const; - virtual void SetPrimitiveData (Array & coeffs); + virtual void GetPrimitiveData (const char *& classname, NgArray & coeffs) const; + virtual void SetPrimitiveData (NgArray & coeffs); /// virtual INSOLID_TYPE BoxInSolid (const BoxSphere<3> & box) const; @@ -513,9 +513,9 @@ namespace netgen virtual Point<3> GetSurfacePoint () const; /// OK virtual void GetPrimitiveData (const char *& classname, - Array & coeffs) const; + NgArray & coeffs) const; /// OK - virtual void SetPrimitiveData (Array & coeffs); + virtual void SetPrimitiveData (NgArray & coeffs); /// OK static Primitive * CreateDefault (); /// OK diff --git a/libsrc/csg/brick.cpp b/libsrc/csg/brick.cpp index b9508fba..3b3b7df6 100644 --- a/libsrc/csg/brick.cpp +++ b/libsrc/csg/brick.cpp @@ -343,7 +343,7 @@ INSOLID_TYPE Brick :: VecInSolid4 (const Point<3> & p, void Brick :: -GetPrimitiveData (const char *& classname, Array & coeffs) const +GetPrimitiveData (const char *& classname, NgArray & coeffs) const { classname = "brick"; coeffs.SetSize(12); @@ -364,7 +364,7 @@ GetPrimitiveData (const char *& classname, Array & coeffs) const coeffs.Elem(12) = p4(2); } -void Brick :: SetPrimitiveData (Array & coeffs) +void Brick :: SetPrimitiveData (NgArray & coeffs) { p1(0) = coeffs.Elem(1); p1(1) = coeffs.Elem(2); @@ -414,7 +414,7 @@ void Brick :: CalcData() { 1, 5, 3, 7 }, { 2, 4, 6, 8 } }; - Array data(6); + NgArray data(6); for (i = 0; i < 6; i++) { const Point<3> lp1 = pi[lface[i][0]-1]; diff --git a/libsrc/csg/brick.hpp b/libsrc/csg/brick.hpp index 7db7b02d..68bf13be 100644 --- a/libsrc/csg/brick.hpp +++ b/libsrc/csg/brick.hpp @@ -63,8 +63,8 @@ namespace netgen { Point<3> p1, p2, p3, p4; Vec<3> v12, v13, v14; - // Array faces; - Array faces; + // NgArray faces; + NgArray faces; public: Brick (Point<3> ap1, Point<3> ap2, Point<3> ap3, Point<3> ap4); @@ -115,8 +115,8 @@ namespace netgen { return *faces[i]; } - virtual void GetPrimitiveData (const char *& classname, Array & coeffs) const; - virtual void SetPrimitiveData (Array & coeffs); + virtual void GetPrimitiveData (const char *& classname, NgArray & coeffs) const; + virtual void SetPrimitiveData (NgArray & coeffs); virtual void Reduce (const BoxSphere<3> & box); virtual void UnReduce (); diff --git a/libsrc/csg/csgeom.cpp b/libsrc/csg/csgeom.cpp index 4aebe271..bc1c3539 100644 --- a/libsrc/csg/csgeom.cpp +++ b/libsrc/csg/csgeom.cpp @@ -75,7 +75,7 @@ namespace netgen void CSGeometry :: Clean () { - Array< Solid* > to_delete; + NgArray< Solid* > to_delete; for (int i = 0; i < solids.Size(); i++) if(!to_delete.Contains(solids[i]->S1())) @@ -162,7 +162,7 @@ namespace netgen if (prim) { const char * classname; - Array coeffs; + NgArray coeffs; prim -> GetPrimitiveData (classname, coeffs); @@ -237,7 +237,7 @@ namespace netgen char key[100], name[100], classname[100], sname[100]; int ncoeff, i, j; - Array coeff; + NgArray coeff; while (ist.good()) { @@ -343,7 +343,7 @@ namespace netgen - Array coeffs; + NgArray coeffs; const char * classname; out << "csgsurfaces " << GetNSurf() << "\n"; @@ -408,7 +408,7 @@ namespace netgen void CSGeometry :: LoadSurfaces (istream & in) { - Array coeffs; + NgArray coeffs; string classname; int nsurfaces,size; @@ -722,7 +722,7 @@ namespace netgen void CSGeometry :: SetFlags (const char * solidname, const Flags & flags) { Solid * solid = solids[solidname]; - Array surfind; + NgArray surfind; int i; double maxh = flags.GetNumFlag ("maxh", -1); @@ -752,7 +752,7 @@ namespace netgen if (flags.StringListFlagDefined ("bcname")) { - const Array & bcname = flags.GetStringListFlag("bcname"); + const NgArray & bcname = flags.GetStringListFlag("bcname"); Polyhedra * polyh; if(solid->S1()) @@ -762,7 +762,7 @@ namespace netgen if(polyh) { - Array < Array * > polysurfs; + NgArray < NgArray * > polysurfs; polyh->GetPolySurfs(polysurfs); if(bcname.Size() != polysurfs.Size()) cerr << "WARNING: solid \"" << solidname << "\" has " << polysurfs.Size() @@ -806,7 +806,7 @@ namespace netgen if (flags.NumListFlagDefined ("bc")) { - const Array & bcnum = flags.GetNumListFlag("bc"); + const NgArray & bcnum = flags.GetNumListFlag("bc"); Polyhedra * polyh; if(solid->S1()) @@ -816,7 +816,7 @@ namespace netgen if(polyh) { - Array < Array * > polysurfs; + NgArray < NgArray * > polysurfs; polyh->GetPolySurfs(polysurfs); if(bcnum.Size() != polysurfs.Size()) cerr << "WARNING: solid \"" << solidname << "\" has " << polysurfs.Size() @@ -880,7 +880,7 @@ namespace netgen void CSGeometry :: GetSurfaceIndices (const Solid * sol, const BoxSphere<3> & box, - Array & locsurf) const + NgArray & locsurf) const { ReducePrimitiveIterator rpi(box); UnReducePrimitiveIterator urpi; @@ -909,7 +909,7 @@ namespace netgen void CSGeometry :: GetIndependentSurfaceIndices (const Solid * sol, const BoxSphere<3> & box, - Array & locsurf) const + NgArray & locsurf) const { ReducePrimitiveIterator rpi(box); UnReducePrimitiveIterator urpi; @@ -968,7 +968,7 @@ namespace netgen void CSGeometry :: GetIndependentSurfaceIndices (const Solid * sol, const Point<3> & p, Vec<3> & v, - Array & locsurf) const + NgArray & locsurf) const { cout << "very dangerous" << endl; Point<3> p2 = p + 1e-2 * v; @@ -980,7 +980,7 @@ namespace netgen */ void CSGeometry :: - GetIndependentSurfaceIndices (Array & locsurf) const + GetIndependentSurfaceIndices (NgArray & locsurf) const { for (int i = 0; i < locsurf.Size(); i++) locsurf[i] = isidenticto[locsurf[i]]; @@ -1022,7 +1022,7 @@ namespace netgen delete triapprox[i]; triapprox.SetSize (ntlo); - Array surfind; + NgArray surfind; IndexSet iset(GetNSurf()); for (int i = 0; i < ntlo; i++) @@ -1159,7 +1159,7 @@ namespace netgen // IndexSet iset(GetNSurf()); locsol -> GetSurfaceIndices (iset); - const Array & lsurfi = iset.GetArray(); + const NgArray & lsurfi = iset.GetArray(); locsol -> IterateSolid (urpi); diff --git a/libsrc/csg/csgeom.hpp b/libsrc/csg/csgeom.hpp index dc5a4d4f..d178b81c 100644 --- a/libsrc/csg/csgeom.hpp +++ b/libsrc/csg/csgeom.hpp @@ -106,10 +106,10 @@ namespace netgen public: /// primitive of surface - Array surf2prim; + NgArray surf2prim; private: - Array delete_them; + NgArray delete_them; /// all named solids SymbolTable solids; @@ -120,7 +120,7 @@ namespace netgen SymbolTable< SplineGeometry<3>* > splinecurves3d; /// all top level objects: solids and surfaces - Array toplevelobjects; + NgArray toplevelobjects; public: /// additional points specified by user @@ -139,14 +139,14 @@ namespace netgen }; private: - // Array > userpoints; - Array userpoints; - Array userpoints_ref_factor; + // NgArray > userpoints; + NgArray userpoints; + NgArray userpoints_ref_factor; - mutable Array > identpoints; + mutable NgArray > identpoints; /// triangular approximation of top level objects - Array triapprox; + NgArray triapprox; /// increment, if geometry is changed static int changeval; @@ -159,7 +159,7 @@ namespace netgen /// identic surfaces are stored by pair of indizes, val = inverse INDEX_2_HASHTABLE identicsurfaces; - Array isidenticto; + NgArray isidenticto; /// identification of boundaries (periodic, thin domains, ...) double ideps; @@ -168,7 +168,7 @@ namespace netgen string filename; /// store splinesurfaces, such that added ones do not get deleted before geometry does - Array> spline_surfaces; + NgArray> spline_surfaces; shared_ptr solid_ball = Solid::ball; @@ -263,10 +263,10 @@ namespace netgen // quick implementations: - Array singfaces; - Array singedges; - Array singpoints; - Array identifications; + NgArray singfaces; + NgArray singedges; + NgArray singpoints; + NgArray identifications; int GetNIdentifications (void) const { return identifications.Size(); } void AddIdentification (Identification * ident); @@ -280,19 +280,19 @@ namespace netgen /// void GetSurfaceIndices (const Solid * sol, const BoxSphere<3> & box, - Array & locsurf) const; + NgArray & locsurf) const; /// void GetIndependentSurfaceIndices (const Solid * sol, const BoxSphere<3> & box, - Array & locsurf) const; + NgArray & locsurf) const; /// /* void GetIndependentSurfaceIndices (const Solid * sol, const Point<3> & p, Vec<3> & v, - Array & locsurf) const; + NgArray & locsurf) const; */ /// - void GetIndependentSurfaceIndices (Array & locsurf) const; + void GetIndependentSurfaceIndices (NgArray & locsurf) const; /// int GetSurfaceClassRepresentant (int si) const @@ -344,7 +344,7 @@ namespace netgen string * bcname; }; - Array bcmodifications; + NgArray bcmodifications; virtual int GenerateMesh (shared_ptr & mesh, MeshingParameters & mparam) override; diff --git a/libsrc/csg/csgparser.cpp b/libsrc/csg/csgparser.cpp index c202c9fd..142bf04a 100644 --- a/libsrc/csg/csgparser.cpp +++ b/libsrc/csg/csgparser.cpp @@ -399,7 +399,7 @@ namespace netgen int inputface = 0; while (1) { - Array pnums,cleaned_pnums; + NgArray pnums,cleaned_pnums; for(int i=0; i<3; i++) { pnums.Append((int) (ParseNumber (scan))); @@ -786,7 +786,7 @@ namespace netgen if(scan.GetToken() == '-' || scan.GetToken() == TOK_NUM) { - Array vals; + NgArray vals; vals.Append (ParseNumber(scan)); while (scan.GetToken() == ',') { @@ -798,7 +798,7 @@ namespace netgen } else { // string list - Array vals; + NgArray vals; string val = scan.GetStringValue(); vals.Append(new char[val.size()+1]); strcpy(vals.Last(),val.c_str()); @@ -908,7 +908,7 @@ namespace netgen if (flags.NumListFlagDefined ("col")) { - const Array & col = + const NgArray & col = flags.GetNumListFlag ("col"); tlo->SetRGB (col[0], col[1], col[2]); } @@ -934,7 +934,7 @@ namespace netgen ParseChar (scan, ';'); - Array si; + NgArray si; geom->GetSolid(surfname)->GetSurfaceIndices(si); int tlonr = geom->SetTopLevelObject ((Solid*)geom->GetSolid(name), @@ -942,7 +942,7 @@ namespace netgen TopLevelObject * tlo = geom->GetTopLevelObject (tlonr); if (flags.NumListFlagDefined ("col")) { - const Array & col = flags.GetNumListFlag ("col"); + const NgArray & col = flags.GetNumListFlag ("col"); tlo->SetRGB (col.Get(1), col.Get(2), col.Get(3)); } if (flags.GetDefineFlag ("transparent")) @@ -980,7 +980,7 @@ namespace netgen ParseChar (scan, ';'); - Array si1, si2; + NgArray si1, si2; geom->GetSolid(name1)->GetSurfaceIndices(si1); geom->GetSolid(name2)->GetSurfaceIndices(si2); @@ -1016,7 +1016,7 @@ namespace netgen ParseChar (scan, ';'); - Array si1, si2; + NgArray si1, si2; geom->GetSolid(name1)->GetSurfaceIndices(si1); geom->GetSolid(name2)->GetSurfaceIndices(si2); @@ -1246,7 +1246,7 @@ namespace netgen CSGeometry::BCModification bcm; bcm.bcname = NULL; - Array si; + NgArray si; geom->GetSolid(name1)->GetSurfaceIndices(si); if(si.Size() == 0) @@ -1298,7 +1298,7 @@ namespace netgen bcm.bcname = NULL; - Array si; + NgArray si; geom->GetSolid(name1)->GetSurfaceIndices(si); if(si.Size() == 0) diff --git a/libsrc/csg/csgpkg.cpp b/libsrc/csg/csgpkg.cpp index dcea1258..0e1e39d9 100644 --- a/libsrc/csg/csgpkg.cpp +++ b/libsrc/csg/csgpkg.cpp @@ -154,7 +154,7 @@ namespace netgen tcl_const char * name = argv[1]; tcl_const char * value = argv[2]; - Array coeffs; + NgArray coeffs; cout << "Set primitive data, name = " << name @@ -222,7 +222,7 @@ namespace netgen const char * classname; - Array coeffs; + NgArray coeffs; geometry->GetSolid (name)->GetPrimitive()->GetPrimitiveData (classname, coeffs); diff --git a/libsrc/csg/edgeflw.cpp b/libsrc/csg/edgeflw.cpp index 61ca2530..ee1b6819 100644 --- a/libsrc/csg/edgeflw.cpp +++ b/libsrc/csg/edgeflw.cpp @@ -10,7 +10,7 @@ namespace netgen EdgeCalculation :: EdgeCalculation (const CSGeometry & ageometry, - Array & aspecpoints, + NgArray & aspecpoints, MeshingParameters & amparam) : geometry(ageometry), specpoints(aspecpoints), mparam(amparam) { @@ -48,7 +48,7 @@ namespace netgen // add all special points before edge points (important for periodic identification) // JS, Jan 2007 const double di=1e-7*geometry.MaxSize(); - Array locsearch; + NgArray locsearch; for (int i = 0; i < specpoints.Size(); i++) if (specpoints[i].unconditional) @@ -96,9 +96,9 @@ namespace netgen void EdgeCalculation :: CalcEdges1 (double h, Mesh & mesh) { - Array hsp(specpoints.Size()); - Array glob2hsp(specpoints.Size()); - Array startpoints, endpoints; + NgArray hsp(specpoints.Size()); + NgArray glob2hsp(specpoints.Size()); + NgArray startpoints, endpoints; int pos, ep; @@ -107,11 +107,11 @@ namespace netgen Point<3> p, np; int pi1, s1, s2, s1_orig, s2_orig; - Array > edgepoints; - Array curvelength; + NgArray > edgepoints; + NgArray curvelength; int copyedge = 0, copyfromedge = -1, copyedgeidentification = -1; - Array locsurfind, locind; + NgArray locsurfind, locind; int checkedcopy = 0; @@ -406,8 +406,8 @@ namespace netgen } - Array refedges; - Array refedgesinv; + NgArray refedges; + NgArray refedgesinv; AnalyzeEdge (s1_orig, s2_orig, s1, s2, pos, layer, @@ -546,7 +546,7 @@ namespace netgen SegmentIndex si; PointIndex pi; - Array osedges(cntedge); + NgArray osedges(cntedge); INDEX_2_HASHTABLE osedgesht (cntedge+1); osedges = 2; @@ -678,17 +678,17 @@ namespace netgen void EdgeCalculation :: FollowEdge (int pi1, int & ep, int & pos, - const Array & hsp, + const NgArray & hsp, double h, const Mesh & mesh, - Array > & edgepoints, - Array & curvelength) + NgArray > & edgepoints, + NgArray & curvelength) { int s1, s2, s1_rep, s2_rep; double len, steplen, cursteplen, loch; Point<3> p, np, pnp; Vec<3> a1, a2, t; - Array locind; + NgArray locind; double size = geometry.MaxSize(); double epspointdist2 = size * 1e-6; @@ -904,14 +904,14 @@ namespace netgen void EdgeCalculation :: AnalyzeEdge (int s1, int s2, int s1_rep, int s2_rep, int pos, int layer, - const Array > & edgepoints, - Array & refedges, - Array & refedgesinv) + const NgArray > & edgepoints, + NgArray & refedges, + NgArray & refedgesinv) { Segment seg; - Array locsurfind, locsurfind2; + NgArray locsurfind, locsurfind2; - Array edges_priority; + NgArray edges_priority; double size = geometry.MaxSize(); bool debug = 0; @@ -1062,7 +1062,7 @@ namespace netgen //int k; double eps = 1e-8*size; - Array pre_ok(2); + NgArray pre_ok(2); do { @@ -1291,10 +1291,10 @@ namespace netgen void EdgeCalculation :: - StoreEdge (const Array & refedges, - const Array & refedgesinv, - const Array > & edgepoints, - const Array & curvelength, + StoreEdge (const NgArray & refedges, + const NgArray & refedgesinv, + const NgArray > & edgepoints, + const NgArray & curvelength, int layer, Mesh & mesh) { @@ -1340,7 +1340,7 @@ namespace netgen const double di=1e-7*geometry.MaxSize(); - Array locsearch; + NgArray locsearch; meshpoint_tree -> GetIntersecting (p-Vec<3> (di,di,di), p+Vec<3> (di,di,di), locsearch); if (locsearch.Size()) @@ -1463,10 +1463,10 @@ namespace netgen void EdgeCalculation :: - StoreShortEdge (const Array & refedges, - const Array & refedgesinv, - const Array > & edgepoints, - const Array & curvelength, + StoreShortEdge (const NgArray & refedges, + const NgArray & refedgesinv, + const NgArray > & edgepoints, + const NgArray & curvelength, int layer, Mesh & mesh) { @@ -1594,8 +1594,8 @@ namespace netgen void EdgeCalculation :: - CopyEdge (const Array & refedges, - const Array & refedgesinv, + CopyEdge (const NgArray & refedges, + const NgArray & refedgesinv, int copyfromedge, const Point<3> & fromstart, const Point<3> & fromend, const Point<3> & tostart, const Point<3> & toend, @@ -1742,7 +1742,7 @@ namespace netgen int layer = 0; Solid * tansol; - Array tansurfind; + NgArray tansurfind; double size = geometry.MaxSize(); int nsol = geometry.GetNTopLevelObjects(); diff --git a/libsrc/csg/edgeflw.hpp b/libsrc/csg/edgeflw.hpp index f9bfdb97..ac93b4a9 100644 --- a/libsrc/csg/edgeflw.hpp +++ b/libsrc/csg/edgeflw.hpp @@ -26,7 +26,7 @@ namespace netgen points have to be given. */ extern void CalcEdges (const CSGeometry & geometry, - const Array & specpoints, + const NgArray & specpoints, double h, Mesh & mesh); @@ -36,7 +36,7 @@ namespace netgen class EdgeCalculation { const CSGeometry & geometry; - Array & specpoints; + NgArray & specpoints; Point3dTree * searchtree; Point3dTree * meshpoint_tree; int cntedge; @@ -46,7 +46,7 @@ namespace netgen public: EdgeCalculation (const CSGeometry & ageometry, - Array & aspecpoints, + NgArray & aspecpoints, MeshingParameters & amparam); ~EdgeCalculation(); @@ -61,34 +61,34 @@ namespace netgen void FollowEdge (int pi1, int & ep, int & pos, - // const Array & hsp, - const Array & hsp, + // const NgArray & hsp, + const NgArray & hsp, double h, const Mesh & mesh, - Array > & edgepoints, - Array & curvelength); + NgArray > & edgepoints, + NgArray & curvelength); void AnalyzeEdge (int s1, int s2, int s1_rep, int s2_rep, int pos, int layer, - const Array > & edgepoints, - Array & refedges, - Array & refedgesinv); + const NgArray > & edgepoints, + NgArray & refedges, + NgArray & refedgesinv); - void StoreEdge (const Array & refedges, - const Array & refedgesinv, - const Array > & edgepoints, - const Array & curvelength, + void StoreEdge (const NgArray & refedges, + const NgArray & refedgesinv, + const NgArray > & edgepoints, + const NgArray & curvelength, int layer, Mesh & mesh); - void StoreShortEdge (const Array & refedges, - const Array & refedgesinv, - const Array > & edgepoints, - const Array & curvelength, + void StoreShortEdge (const NgArray & refedges, + const NgArray & refedgesinv, + const NgArray > & edgepoints, + const NgArray & curvelength, int layer, Mesh & mesh); - void CopyEdge (const Array & refedges, - const Array & refedgesinv, + void CopyEdge (const NgArray & refedges, + const NgArray & refedgesinv, int copyfromedge, const Point<3> & fromstart, const Point<3> & fromend, const Point<3> & tostart, const Point<3> & toend, diff --git a/libsrc/csg/explicitcurve2d.hpp b/libsrc/csg/explicitcurve2d.hpp index 559030b2..e6d30344 100644 --- a/libsrc/csg/explicitcurve2d.hpp +++ b/libsrc/csg/explicitcurve2d.hpp @@ -70,9 +70,9 @@ namespace netgen class BSplineCurve2d : public ExplicitCurve2d { /// - Array > points; + NgArray > points; /// - Array intervallused; + NgArray intervallused; /// int redlevel; diff --git a/libsrc/csg/extrusion.cpp b/libsrc/csg/extrusion.cpp index 61446b0c..4354bc05 100644 --- a/libsrc/csg/extrusion.cpp +++ b/libsrc/csg/extrusion.cpp @@ -7,7 +7,7 @@ namespace netgen { - Array > project1, project2; + NgArray > project1, project2; @@ -57,13 +57,13 @@ namespace netgen Init(); } - ExtrusionFace :: ExtrusionFace(const Array & raw_data) + ExtrusionFace :: ExtrusionFace(const NgArray & raw_data) { deletable = true; int pos=0; - Array< Point<2> > p(3); + NgArray< Point<2> > p(3); int ptype = int(raw_data[pos]); pos++; @@ -142,7 +142,7 @@ namespace netgen double cutdist = -1; - Array mindist(path->GetNSplines()); + NgArray mindist(path->GetNSplines()); for(int i = 0; i < path->GetNSplines(); i++) { @@ -453,7 +453,7 @@ namespace netgen v2d(1) = v * loc_z_dir[seg]; Vec<2> n(v2d(1),-v2d(0)); - Array < Point<2> > ips; + NgArray < Point<2> > ips; profile->LineIntersections(v2d(1), @@ -593,7 +593,7 @@ namespace netgen } - void ExtrusionFace :: GetRawData(Array & data) const + void ExtrusionFace :: GetRawData(NgArray & data) const { data.DeleteAll(); profile->GetRawData(data); @@ -695,7 +695,7 @@ namespace netgen INSOLID_TYPE Extrusion :: PointInSolid (const Point<3> & p, const double eps, - Array * const facenums) const + NgArray * const facenums) const { Vec<3> random_vec(-0.4561,0.7382,0.4970247); @@ -741,7 +741,7 @@ namespace netgen const Vec<3> & v, double eps) const { - Array facenums; + NgArray facenums; INSOLID_TYPE pInSolid = PointInSolid(p,eps,&facenums); if(pInSolid != DOES_INTERSECT) diff --git a/libsrc/csg/extrusion.hpp b/libsrc/csg/extrusion.hpp index 2d6b3bbe..70a9e4f3 100644 --- a/libsrc/csg/extrusion.hpp +++ b/libsrc/csg/extrusion.hpp @@ -15,11 +15,11 @@ namespace netgen bool deletable; - Array< const SplineSeg3<3> * > spline3_path; - Array< const LineSeg<3> * > line_path; + NgArray< const SplineSeg3<3> * > spline3_path; + NgArray< const LineSeg<3> * > line_path; - mutable Array < Vec<3> > x_dir, y_dir, z_dir, loc_z_dir; - mutable Array < Point<3> > p0; + mutable NgArray < Vec<3> > x_dir, y_dir, z_dir, loc_z_dir; + mutable NgArray < Point<3> > p0; mutable Vec<3> profile_tangent; mutable double profile_par; @@ -48,7 +48,7 @@ namespace netgen const SplineGeometry<3> * path_in, const Vec<3> & z_direction); - ExtrusionFace(const Array & raw_data); + ExtrusionFace(const NgArray & raw_data); // default constructor for archive ExtrusionFace() {} @@ -102,7 +102,7 @@ namespace netgen const Vec<3> & GetProfileTangent (void) const {return profile_tangent;} double GetProfilePar(void) const {return profile_par;} - void GetRawData(Array & data) const; + void GetRawData(NgArray & data) const; void CalcLocalCoordinates (int seg, double t, Vec<3> & ex, Vec<3> & ey, Vec<3> & ez) const; @@ -123,7 +123,7 @@ namespace netgen Vec<3> z_direction; - Array faces; + NgArray faces; mutable int latestfacenum; @@ -145,7 +145,7 @@ namespace netgen double eps) const; INSOLID_TYPE PointInSolid (const Point<3> & p, double eps, - Array * const facenums) const; + NgArray * const facenums) const; virtual INSOLID_TYPE VecInSolid (const Point<3> & p, const Vec<3> & v, double eps) const; diff --git a/libsrc/csg/genmesh.cpp b/libsrc/csg/genmesh.cpp index 4683c4e2..b00ecc34 100644 --- a/libsrc/csg/genmesh.cpp +++ b/libsrc/csg/genmesh.cpp @@ -10,8 +10,8 @@ namespace netgen { - Array specpoints; - static Array spoints; + NgArray specpoints; + static NgArray spoints; #define TCL_OK 0 #define TCL_ERROR 1 @@ -140,7 +140,7 @@ namespace netgen } } - Array loc; + NgArray loc; if (!ec.point_on_edge_problem) for (SegmentIndex si = 0; si < mesh.GetNSeg(); si++) { @@ -234,17 +234,17 @@ namespace netgen const char * savetask = multithread.task; multithread.task = "Surface meshing"; - Array segments; + NgArray segments; int noldp = mesh.GetNP(); double starttime = GetTime(); // find master faces from identified - Array masterface(mesh.GetNFD()); + NgArray masterface(mesh.GetNFD()); for (int i = 1; i <= mesh.GetNFD(); i++) masterface.Elem(i) = i; - Array fpairs; + NgArray fpairs; bool changed; do { @@ -382,7 +382,7 @@ namespace netgen for (int j = 0; j < geom.singfaces.Size(); j++) { - Array surfs; + NgArray surfs; geom.GetIndependentSurfaceIndices (geom.singfaces[j]->GetSolid(), geom.BoundingBox(), surfs); for (int k = 1; k <= mesh.GetNFD(); k++) @@ -680,7 +680,7 @@ namespace netgen mesh->SetGlobalH (mparam.maxh); mesh->SetMinimalH (mparam.minh); - Array maxhdom(geom.GetNTopLevelObjects()); + NgArray maxhdom(geom.GetNTopLevelObjects()); for (int i = 0; i < maxhdom.Size(); i++) maxhdom[i] = geom.GetTopLevelObject(i)->GetMaxH(); diff --git a/libsrc/csg/identify.cpp b/libsrc/csg/identify.cpp index 95a6bb13..935ed22f 100644 --- a/libsrc/csg/identify.cpp +++ b/libsrc/csg/identify.cpp @@ -28,7 +28,7 @@ ostream & operator<< (ostream & ost, Identification & ident) /* -void Identification :: IdentifySpecialPoints (Array & points) +void Identification :: IdentifySpecialPoints (NgArray & points) { ; } @@ -84,7 +84,7 @@ void Identification :: IdentifyFaces (class Mesh & mesh) } void Identification :: -BuildSurfaceElements (Array & segs, +BuildSurfaceElements (NgArray & segs, Mesh & mesh, const Surface * surf) { cout << "Identification::BuildSurfaceElements called for base-class" << endl; @@ -93,14 +93,14 @@ BuildSurfaceElements (Array & segs, void Identification :: -BuildVolumeElements (Array & surfels, +BuildVolumeElements (NgArray & surfels, class Mesh & mesh) { ; } void Identification :: -GetIdentifiedFaces (Array & idfaces) const +GetIdentifiedFaces (NgArray & idfaces) const { idfaces.SetSize(0); for (int i = 1; i <= identfaces.GetNBags(); i++) @@ -136,7 +136,7 @@ PeriodicIdentification :: ~PeriodicIdentification () /* void PeriodicIdentification :: IdentifySpecialPoints -(Array & points) +(NgArray & points) { int i, j; int bestj; @@ -446,7 +446,7 @@ void PeriodicIdentification :: IdentifyFaces (class Mesh & mesh) void PeriodicIdentification :: -BuildSurfaceElements (Array & segs, +BuildSurfaceElements (NgArray & segs, Mesh & mesh, const Surface * surf) { int found = 0; @@ -458,7 +458,7 @@ BuildSurfaceElements (Array & segs, if (geom.GetSurface(surfnr) == s1 || geom.GetSurface(surfnr) == s2) { - Array copy_points; + NgArray copy_points; for (SurfaceElementIndex sei = 0; sei < mesh.GetNSE(); sei++) { @@ -609,7 +609,7 @@ void CloseSurfaceIdentification :: GetData (ostream & ost) const /* void CloseSurfaceIdentification :: IdentifySpecialPoints -(Array & points) +(NgArray & points) { int i, j; int bestj; @@ -677,7 +677,7 @@ Identifyable (const SpecialPoint & sp1, const SpecialPoint & sp2, if (!dom_surf_valid) { const_cast (dom_surf_valid) = 1; - Array & hsurf = const_cast&> (domain_surfaces); + NgArray & hsurf = const_cast&> (domain_surfaces); if (domain) { @@ -887,7 +887,7 @@ GetIdentifiedPoint (class Mesh & mesh, int pi) const Surface *snew; const Point<3> & p = mesh.Point (pi); - Array identmap(mesh.GetNP()); + NgArray identmap(mesh.GetNP()); mesh.GetIdentifications().GetMap (nr, identmap); if (identmap.Get(pi)) return identmap.Get(pi); @@ -958,13 +958,13 @@ void CloseSurfaceIdentification :: IdentifyPoints (Mesh & mesh) { int np = mesh.GetNP(); - Array points_on_surf2; + NgArray points_on_surf2; for (int i2 = 1; i2 <= np; i2++) if (s2->PointOnSurface (mesh.Point(i2))) points_on_surf2.Append (i2); - Array surfs_of_p1; + NgArray surfs_of_p1; for (int i1 = 1; i1 <= np; i1++) { @@ -1080,7 +1080,7 @@ void CloseSurfaceIdentification :: IdentifyFaces (class Mesh & mesh) s2rep = geom.GetSurfaceClassRepresentant(i); } - Array segs_on_face1, segs_on_face2; + NgArray segs_on_face1, segs_on_face2; identfaces.DeleteData(); @@ -1219,13 +1219,13 @@ void CloseSurfaceIdentification :: IdentifyFaces (class Mesh & mesh) void CloseSurfaceIdentification :: -BuildSurfaceElements (Array & segs, +BuildSurfaceElements (NgArray & segs, Mesh & mesh, const Surface * surf) { bool found = 0; int cntquads = 0; - Array identmap; + NgArray identmap; identmap = 0; mesh.GetIdentifications().GetMap (nr, identmap); @@ -1240,7 +1240,7 @@ BuildSurfaceElements (Array & segs, //(*testout) << "segs = " << endl << segs << endl; //(*testout) << "identmap = " << endl << identmap << endl; - //Array foundseg(segs.Size()); + //NgArray foundseg(segs.Size()); //foundseg = false; // insert quad layer: @@ -1301,7 +1301,7 @@ BuildSurfaceElements (Array & segs, { PrintMessage(3, "insert quad layer of ", cntquads, " elements at face ", segs.Get(1).si); - //Array aux; + //NgArray aux; //for(int i=0; i & segs, void CloseSurfaceIdentification :: -BuildSurfaceElements2 (Array & segs, +BuildSurfaceElements2 (NgArray & segs, Mesh & mesh, const Surface * surf) { // copy mesh @@ -1420,7 +1420,7 @@ BuildSurfaceElements2 (Array & segs, void CloseSurfaceIdentification :: -BuildVolumeElements (Array & surfels, +BuildVolumeElements (NgArray & surfels, class Mesh & mesh) { ; @@ -1481,7 +1481,7 @@ void CloseEdgesIdentification :: GetData (ostream & ost) const /* void CloseEdgesIdentification :: IdentifySpecialPoints -(Array & points) +(NgArray & points) { int i, j; int bestj; @@ -1633,7 +1633,7 @@ void CloseEdgesIdentification :: IdentifyPoints (Mesh & mesh) } void CloseEdgesIdentification :: -BuildSurfaceElements (Array & segs, +BuildSurfaceElements (NgArray & segs, Mesh & mesh, const Surface * surf) { int found = 0; diff --git a/libsrc/csg/identify.hpp b/libsrc/csg/identify.hpp index 96ae5bce..361e6025 100644 --- a/libsrc/csg/identify.hpp +++ b/libsrc/csg/identify.hpp @@ -34,7 +34,7 @@ namespace netgen DLL_HEADER virtual void GetData (ostream & ost) const = 0; /// obsolete - // virtual void IdentifySpecialPoints (Array & points); + // virtual void IdentifySpecialPoints (NgArray & points); /// can identify both special points (fixed direction) /// (identified points, same tangent) @@ -59,16 +59,16 @@ namespace netgen virtual int GetIdentifiedPoint (class Mesh & mesh, int pi1); /// copy surfaces, or fill rectangles - virtual void BuildSurfaceElements (Array & segs, + virtual void BuildSurfaceElements (NgArray & segs, class Mesh & mesh, const Surface * surf); /// insert volume elements in thin layers - virtual void BuildVolumeElements (Array & surfels, + virtual void BuildVolumeElements (NgArray & surfels, class Mesh & mesh); /// get list of identified faces - virtual void GetIdentifiedFaces (Array & idfaces) const; + virtual void GetIdentifiedFaces (NgArray & idfaces) const; friend ostream & operator<< (ostream & ost, Identification & ident); }; @@ -91,7 +91,7 @@ namespace netgen virtual void GetData (ostream & ost) const override; - // virtual void IdentifySpecialPoints (Array & points); + // virtual void IdentifySpecialPoints (NgArray & points); virtual int Identifyable (const SpecialPoint & sp1, const SpecialPoint & sp2, const TABLE & specpoint2solid, const TABLE & specpoint2surface) const override; @@ -100,7 +100,7 @@ namespace netgen virtual int GetIdentifiedPoint (class Mesh & mesh, int pi1) override; virtual void IdentifyPoints (class Mesh & mesh) override; virtual void IdentifyFaces (class Mesh & mesh) override; - virtual void BuildSurfaceElements (Array & segs, + virtual void BuildSurfaceElements (NgArray & segs, class Mesh & mesh, const Surface * surf) override; }; @@ -123,9 +123,9 @@ namespace netgen int ref_levels_s2; /// double eps_n; - Array slices; + NgArray slices; /// used only for domain-local identification: - Array domain_surfaces; + NgArray domain_surfaces; /// bool dom_surf_valid; @@ -146,7 +146,7 @@ namespace netgen virtual void GetData (ostream & ost) const; - // virtual void IdentifySpecialPoints (Array & points); + // virtual void IdentifySpecialPoints (NgArray & points); virtual int Identifyable (const SpecialPoint & sp1, const SpecialPoint & sp2, const TABLE & specpoint2solid, const TABLE & specpoint2surface) const; @@ -154,17 +154,17 @@ namespace netgen virtual int IdentifyableCandidate (const SpecialPoint & sp1) const; virtual int ShortEdge (const SpecialPoint & sp1, const SpecialPoint & sp2) const; virtual int GetIdentifiedPoint (class Mesh & mesh, int pi1); - const Array & GetSlices () const { return slices; } + const NgArray & GetSlices () const { return slices; } virtual void IdentifyPoints (class Mesh & mesh); virtual void IdentifyFaces (class Mesh & mesh); - virtual void BuildSurfaceElements (Array & segs, + virtual void BuildSurfaceElements (NgArray & segs, class Mesh & mesh, const Surface * surf); - void BuildSurfaceElements2 (Array & segs, + void BuildSurfaceElements2 (NgArray & segs, class Mesh & mesh, const Surface * surf); - virtual void BuildVolumeElements (Array & surfels, + virtual void BuildVolumeElements (NgArray & surfels, class Mesh & mesh); int RefLevels () const { return ref_levels; } @@ -196,14 +196,14 @@ namespace netgen virtual void Print (ostream & ost) const; virtual void GetData (ostream & ost) const; - // virtual void IdentifySpecialPoints (Array & points); + // virtual void IdentifySpecialPoints (NgArray & points); virtual int Identifyable (const SpecialPoint & sp1, const SpecialPoint & sp2, const TABLE & specpoint2solid, const TABLE & specpoint2surface) const; virtual void IdentifyPoints (class Mesh & mesh); - virtual void BuildSurfaceElements (Array & segs, + virtual void BuildSurfaceElements (NgArray & segs, class Mesh & mesh, const Surface * surf); }; diff --git a/libsrc/csg/polyhedra.cpp b/libsrc/csg/polyhedra.cpp index 1bb1d1d2..5e35241b 100644 --- a/libsrc/csg/polyhedra.cpp +++ b/libsrc/csg/polyhedra.cpp @@ -7,7 +7,7 @@ namespace netgen { Polyhedra::Face::Face (int pi1, int pi2, int pi3, - const Array > & points, + const NgArray > & points, int ainputnr) { inputnr = ainputnr; @@ -165,7 +165,7 @@ INSOLID_TYPE Polyhedra :: PointInSolid (const Point<3> & p, void Polyhedra :: GetTangentialSurfaceIndices (const Point<3> & p, - Array & surfind, double eps) const + NgArray & surfind, double eps) const { for (int i = 0; i < faces.Size(); i++) { @@ -192,7 +192,7 @@ INSOLID_TYPE Polyhedra :: VecInSolid (const Point<3> & p, const Vec<3> & v, double eps) const { - Array point_on_faces; + NgArray point_on_faces; INSOLID_TYPE res(DOES_INTERSECT); Vec<3> vn = v; @@ -388,7 +388,7 @@ INSOLID_TYPE Polyhedra :: VecInSolid2 (const Point<3> & p, void Polyhedra :: GetTangentialVecSurfaceIndices2 (const Point<3> & p, const Vec<3> & v1, const Vec<3> & v2, - Array & surfind, double eps) const + NgArray & surfind, double eps) const { Vec<3> v1n = v1; v1n.Normalize(); @@ -447,7 +447,7 @@ void Polyhedra :: GetTangentialVecSurfaceIndices2 (const Point<3> & p, const Vec void Polyhedra :: GetPrimitiveData (const char *& classname, - Array & coeffs) const + NgArray & coeffs) const { classname = "Polyhedra"; coeffs.SetSize(0); @@ -471,7 +471,7 @@ void Polyhedra :: GetPrimitiveData (const char *& classname, */ } -void Polyhedra :: SetPrimitiveData (Array & /* coeffs */) +void Polyhedra :: SetPrimitiveData (NgArray & /* coeffs */) { ; } @@ -590,7 +590,7 @@ int Polyhedra :: FaceBoxIntersection (int fnr, const BoxSphere<3> & box) const } -void Polyhedra :: GetPolySurfs(Array < Array * > & polysurfs) +void Polyhedra :: GetPolySurfs(NgArray < NgArray * > & polysurfs) { int maxnum = -1; @@ -602,14 +602,14 @@ void Polyhedra :: GetPolySurfs(Array < Array * > & polysurfs) polysurfs.SetSize(maxnum+1); for(int i=0; i; + polysurfs[i] = new NgArray; for(int i = 0; iAppend(faces[i].planenr); } -void Polyhedra::CalcSpecialPoints (Array > & pts) const +void Polyhedra::CalcSpecialPoints (NgArray > & pts) const { for (int i = 0; i < points.Size(); i++) pts.Append (points[i]); @@ -617,7 +617,7 @@ void Polyhedra::CalcSpecialPoints (Array > & pts) const void Polyhedra :: AnalyzeSpecialPoint (const Point<3> & /* pt */, - Array > & /* specpts */) const + NgArray > & /* specpts */) const { ; } diff --git a/libsrc/csg/polyhedra.hpp b/libsrc/csg/polyhedra.hpp index 0a785042..f7a14cd4 100644 --- a/libsrc/csg/polyhedra.hpp +++ b/libsrc/csg/polyhedra.hpp @@ -35,13 +35,13 @@ namespace netgen Face () { ; } Face (int pi1, int pi2, int pi3, - const Array > & points, + const NgArray > & points, int ainputnr); }; - Array > points; - Array faces; - Array planes; + NgArray > points; + NgArray faces; + NgArray planes; Box<3> poly_bbox; double eps_base1; @@ -65,15 +65,15 @@ namespace netgen double eps) const; virtual void GetTangentialSurfaceIndices (const Point<3> & p, - Array & surfind, double eps) const; + NgArray & surfind, double eps) const; virtual void GetTangentialVecSurfaceIndices2 (const Point<3> & p, const Vec<3> & v1, const Vec<3> & v2, - Array & surfind, double eps) const; + NgArray & surfind, double eps) const; - virtual void CalcSpecialPoints (Array > & pts) const; + virtual void CalcSpecialPoints (NgArray > & pts) const; virtual void AnalyzeSpecialPoint (const Point<3> & pt, - Array > & specpts) const; + NgArray > & specpts) const; virtual Vec<3> SpecialPointTangentialVector (const Point<3> & p, int s1, int s2) const; virtual int GetNSurfaces() const @@ -83,8 +83,8 @@ namespace netgen virtual const Surface & GetSurface (int i) const { return *planes[i]; } - virtual void GetPrimitiveData (const char *& classname, Array & coeffs) const; - virtual void SetPrimitiveData (Array & coeffs); + virtual void GetPrimitiveData (const char *& classname, NgArray & coeffs) const; + virtual void SetPrimitiveData (NgArray & coeffs); virtual void Reduce (const BoxSphere<3> & box); virtual void UnReduce (); @@ -92,7 +92,7 @@ namespace netgen int AddPoint (const Point<3> & p); int AddFace (int pi1, int pi2, int pi3, int inputnum); - void GetPolySurfs(Array < Array * > & polysurfs); + void GetPolySurfs(NgArray < NgArray * > & polysurfs); protected: int FaceBoxIntersection (int fnr, const BoxSphere<3> & box) const; diff --git a/libsrc/csg/python_csg.cpp b/libsrc/csg/python_csg.cpp index c82db668..47f85d58 100644 --- a/libsrc/csg/python_csg.cpp +++ b/libsrc/csg/python_csg.cpp @@ -211,7 +211,7 @@ DLL_HEADER void ExportCSG(py::module &m) .def("__init__", FunctionPointer ([](SplineSurface* instance, shared_ptr base, py::list cuts) { auto primitive = dynamic_cast (base->GetSolid()->GetPrimitive()); - auto acuts = make_shared>>(); + auto acuts = make_shared>>(); for(int i = 0; i> sps(cuts[i]); @@ -409,7 +409,7 @@ However, when r = 0, the top part becomes a point(tip) and meshing fails! if (py::extract(val).check()) mod_nr = py::extract (val)(); if (py::extract(val).check()) bcname = new string ( py::extract (val)()); - Array si; + NgArray si; mod_solid -> GetSolid() -> GetSurfaceIndices (si); // cout << "change bc on surfaces: " << si << " to " << mod_nr << endl; @@ -459,7 +459,7 @@ However, when r = 0, the top part becomes a point(tip) and meshing fails! self.GetTopLevelObject(tlonr) -> SetBCProp(surf->GetBase()->GetBCProperty()); self.GetTopLevelObject(tlonr) -> SetBCName(surf->GetBase()->GetBCName()); self.GetTopLevelObject(tlonr) -> SetMaxH(surf->GetBase()->GetMaxH()); - Array> non_midpoints; + NgArray> non_midpoints; for(auto spline : surf->GetSplines()) { non_midpoints.Append(spline->GetPoint(0)); @@ -494,7 +494,7 @@ However, when r = 0, the top part becomes a point(tip) and meshing fails! .def("CloseSurfaces", FunctionPointer ([] (CSGeometry & self, shared_ptr s1, shared_ptr s2, py::list aslices ) { - Array si1, si2; + NgArray si1, si2; s1->GetSolid()->GetSurfaceIndices (si1); s2->GetSolid()->GetSurfaceIndices (si2); cout << "surface ids1 = " << si1 << endl; @@ -505,7 +505,7 @@ However, when r = 0, the top part becomes a point(tip) and meshing fails! try { int n = py::len(aslices); - Array slices(n); + NgArray slices(n); for(int i=0; i(aslices[i])(); @@ -531,7 +531,7 @@ However, when r = 0, the top part becomes a point(tip) and meshing fails! ([] (CSGeometry & self, shared_ptr s1, shared_ptr s2, int reflevels, shared_ptr domain_solid) { - Array si1, si2; + NgArray si1, si2; s1->GetSolid()->GetSurfaceIndices (si1); s2->GetSolid()->GetSurfaceIndices (si2); cout << "surface ids1 = " << si1 << endl; @@ -556,7 +556,7 @@ However, when r = 0, the top part becomes a point(tip) and meshing fails! ([] (CSGeometry & self, shared_ptr s1, shared_ptr s2, Transformation<3> trafo) { - Array si1, si2; + NgArray si1, si2; s1->GetSolid()->GetSurfaceIndices (si1); s2->GetSolid()->GetSurfaceIndices (si2); cout << "identify surfaces " << si1[0] << " and " << si2[0] << endl; diff --git a/libsrc/csg/revolution.cpp b/libsrc/csg/revolution.cpp index f1d202d2..57498cb4 100644 --- a/libsrc/csg/revolution.cpp +++ b/libsrc/csg/revolution.cpp @@ -52,13 +52,13 @@ namespace netgen } - RevolutionFace :: RevolutionFace(const Array & raw_data) + RevolutionFace :: RevolutionFace(const NgArray & raw_data) { deletable = true; int pos = 0; - Array< Point<2> > p(3); + NgArray< Point<2> > p(3); int stype = int(raw_data[pos]); pos++; @@ -333,7 +333,7 @@ namespace netgen { double retval = spline->MaxCurvature(); - Array < Point<2> > checkpoints; + NgArray < Point<2> > checkpoints; const SplineSeg3<2> * ss3 = dynamic_cast *>(spline); const LineSeg<2> * ls = dynamic_cast *>(spline); @@ -386,7 +386,7 @@ namespace netgen // find smallest y value of spline: - Array testt; + NgArray testt; if(!isfirst) testt.Append(0); @@ -624,7 +624,7 @@ namespace netgen - void RevolutionFace :: GetRawData(Array & data) const + void RevolutionFace :: GetRawData(NgArray & data) const { data.DeleteAll(); spline->GetRawData(data); @@ -718,7 +718,7 @@ namespace netgen return DOES_INTERSECT; else { - Array < Point<3> > pext(2); + NgArray < Point<3> > pext(2); Point<3> p; pext[0] = box.PMin(); @@ -772,7 +772,7 @@ namespace netgen const double b = -randomx; const double c = -a*p2d(0)-b*p2d(1); - Array < Point<2> > points; + NgArray < Point<2> > points; //(*testout) << "face intersections at: " << endl; for(int i=0; i & p, - Array & surfind, double eps) const + NgArray & surfind, double eps) const { for (int j = 0; j < faces.Size(); j++) if (faces[j] -> PointInFace(p, eps)) @@ -823,7 +823,7 @@ namespace netgen return pInSolid; } - Array intersecting_faces; + NgArray intersecting_faces; for(int i=0; iPointInFace(p,eps)) // == DOES_INTERSECT) diff --git a/libsrc/csg/revolution.hpp b/libsrc/csg/revolution.hpp index 879829fd..0a395e3f 100644 --- a/libsrc/csg/revolution.hpp +++ b/libsrc/csg/revolution.hpp @@ -23,9 +23,9 @@ namespace netgen mutable Vector spline_coefficient_shifted; - Array < Vec<2>* > checklines_vec; - Array < Point<2>* > checklines_start; - Array < Vec<2>* > checklines_normal; + NgArray < Vec<2>* > checklines_vec; + NgArray < Point<2>* > checklines_start; + NgArray < Vec<2>* > checklines_normal; private: void Init (void); @@ -44,7 +44,7 @@ namespace netgen bool last = false, const int id_in = 0); - RevolutionFace(const Array & raw_data); + RevolutionFace(const NgArray & raw_data); // default constructor for archive RevolutionFace() {} @@ -87,7 +87,7 @@ namespace netgen /* INSOLID_TYPE */ bool PointInFace (const Point<3> & p, const double eps) const; - void GetRawData(Array & data) const; + void GetRawData(NgArray & data) const; }; @@ -111,7 +111,7 @@ namespace netgen int type; - Array faces; + NgArray faces; mutable int intersecting_face; @@ -143,7 +143,7 @@ namespace netgen double eps) const; virtual void GetTangentialSurfaceIndices (const Point<3> & p, - Array & surfind, double eps) const; + NgArray & surfind, double eps) const; virtual INSOLID_TYPE VecInSolid (const Point<3> & p, const Vec<3> & v, diff --git a/libsrc/csg/singularref.cpp b/libsrc/csg/singularref.cpp index 0ad13db9..a230c518 100644 --- a/libsrc/csg/singularref.cpp +++ b/libsrc/csg/singularref.cpp @@ -41,7 +41,7 @@ void SingularEdge :: FindPointsOnEdge (class Mesh & mesh) segms.SetSize(0); - Array si1, si2; + NgArray si1, si2; sol1->GetSurfaceIndices (si1); sol2->GetSurfaceIndices (si2); @@ -150,7 +150,7 @@ SingularPoint :: SingularPoint (double abeta, void SingularPoint :: FindPoints (class Mesh & mesh) { points.SetSize(0); - Array surfk, surf; + NgArray surfk, surf; for (PointIndex pi = PointIndex::BASE; diff --git a/libsrc/csg/singularref.hpp b/libsrc/csg/singularref.hpp index c6984dc1..2412cf8a 100644 --- a/libsrc/csg/singularref.hpp +++ b/libsrc/csg/singularref.hpp @@ -29,8 +29,8 @@ namespace netgen int domnr; const Solid *sol; double factor; - // Array > points; - // Array segms; + // NgArray > points; + // NgArray segms; public: SingularFace (int adomnr, const Solid * asol, double sf) : domnr(adomnr), sol(asol), factor(sf) { ; } @@ -47,8 +47,8 @@ namespace netgen int domnr; const CSGeometry& geom; const Solid *sol1, *sol2; - Array > points; - Array segms; + NgArray > points; + NgArray segms; double factor; double maxhinit; @@ -68,7 +68,7 @@ namespace netgen public: double beta; const Solid *sol1, *sol2, *sol3; - Array > points; + NgArray > points; double factor; public: diff --git a/libsrc/csg/solid.cpp b/libsrc/csg/solid.cpp index d11973ab..6ba50cf7 100644 --- a/libsrc/csg/solid.cpp +++ b/libsrc/csg/solid.cpp @@ -557,14 +557,14 @@ namespace netgen - void Solid :: Boundaries (const Point<3> & p, Array & bounds) const + void Solid :: Boundaries (const Point<3> & p, NgArray & bounds) const { int in, strin; bounds.SetSize (0); RecBoundaries (p, bounds, in, strin); } - void Solid :: RecBoundaries (const Point<3> & p, Array & bounds, + void Solid :: RecBoundaries (const Point<3> & p, NgArray & bounds, int & in, int & strin) const { switch (op) @@ -585,7 +585,7 @@ namespace netgen case SECTION: { int i, in1, in2, strin1, strin2; - Array bounds1, bounds2; + NgArray bounds1, bounds2; s1 -> RecBoundaries (p, bounds1, in1, strin1); s2 -> RecBoundaries (p, bounds2, in2, strin2); @@ -604,7 +604,7 @@ namespace netgen case UNION: { int i, in1, in2, strin1, strin2; - Array bounds1, bounds2; + NgArray bounds1, bounds2; s1 -> RecBoundaries (p, bounds1, in1, strin1); s2 -> RecBoundaries (p, bounds2, in2, strin2); @@ -638,7 +638,7 @@ namespace netgen } - void Solid :: TangentialSolid (const Point<3> & p, Solid *& tansol, Array & surfids, double eps) const + void Solid :: TangentialSolid (const Point<3> & p, Solid *& tansol, NgArray & surfids, double eps) const { int in, strin; RecTangentialSolid (p, tansol, surfids, in, strin, eps); @@ -648,7 +648,7 @@ namespace netgen } - void Solid :: RecTangentialSolid (const Point<3> & p, Solid *& tansol, Array & surfids, + void Solid :: RecTangentialSolid (const Point<3> & p, Solid *& tansol, NgArray & surfids, int & in, int & strin, double eps) const { tansol = NULL; @@ -742,7 +742,7 @@ namespace netgen void Solid :: TangentialSolid2 (const Point<3> & p, const Vec<3> & t, - Solid *& tansol, Array & surfids, double eps) const + Solid *& tansol, NgArray & surfids, double eps) const { int in, strin; surfids.SetSize (0); @@ -752,7 +752,7 @@ namespace netgen } void Solid :: RecTangentialSolid2 (const Point<3> & p, const Vec<3> & t, - Solid *& tansol, Array & surfids, + Solid *& tansol, NgArray & surfids, int & in, int & strin, double eps) const { tansol = NULL; @@ -856,7 +856,7 @@ namespace netgen void Solid :: TangentialSolid3 (const Point<3> & p, const Vec<3> & t, const Vec<3> & t2, - Solid *& tansol, Array & surfids, + Solid *& tansol, NgArray & surfids, double eps) const { int in, strin; @@ -869,7 +869,7 @@ namespace netgen void Solid :: RecTangentialSolid3 (const Point<3> & p, const Vec<3> & t, const Vec<3> & t2, - Solid *& tansol, Array & surfids, + Solid *& tansol, NgArray & surfids, int & in, int & strin, double eps) const { tansol = NULL; @@ -967,7 +967,7 @@ namespace netgen void Solid :: TangentialEdgeSolid (const Point<3> & p, const Vec<3> & t, const Vec<3> & t2, const Vec<3> & m, - Solid *& tansol, Array & surfids, + Solid *& tansol, NgArray & surfids, double eps) const { int in, strin; @@ -982,7 +982,7 @@ namespace netgen void Solid :: RecTangentialEdgeSolid (const Point<3> & p, const Vec<3> & t, const Vec<3> & t2, const Vec<3> & m, - Solid *& tansol, Array & surfids, + Solid *& tansol, NgArray & surfids, int & in, int & strin, double eps) const { tansol = NULL; @@ -1450,13 +1450,13 @@ namespace netgen return 0; } - void Solid :: GetSurfaceIndices (Array & surfind) const + void Solid :: GetSurfaceIndices (NgArray & surfind) const { surfind.SetSize (0); RecGetSurfaceIndices (surfind); } - void Solid :: RecGetSurfaceIndices (Array & surfind) const + void Solid :: RecGetSurfaceIndices (NgArray & surfind) const { switch (op) { @@ -1533,13 +1533,13 @@ namespace netgen } - void Solid :: GetTangentialSurfaceIndices (const Point<3> & p, Array & surfind, double eps) const + void Solid :: GetTangentialSurfaceIndices (const Point<3> & p, NgArray & surfind, double eps) const { surfind.SetSize (0); RecGetTangentialSurfaceIndices (p, surfind, eps); } - void Solid :: RecGetTangentialSurfaceIndices (const Point<3> & p, Array & surfind, double eps) const + void Solid :: RecGetTangentialSurfaceIndices (const Point<3> & p, NgArray & surfind, double eps) const { switch (op) { @@ -1576,14 +1576,14 @@ namespace netgen void Solid :: GetTangentialSurfaceIndices2 (const Point<3> & p, const Vec<3> & v, - Array & surfind, double eps) const + NgArray & surfind, double eps) const { surfind.SetSize (0); RecGetTangentialSurfaceIndices2 (p, v, surfind, eps); } void Solid :: RecGetTangentialSurfaceIndices2 (const Point<3> & p, const Vec<3> & v, - Array & surfind, double eps) const + NgArray & surfind, double eps) const { switch (op) { @@ -1628,14 +1628,14 @@ namespace netgen void Solid :: GetTangentialSurfaceIndices3 (const Point<3> & p, const Vec<3> & v, const Vec<3> & v2, - Array & surfind, double eps) const + NgArray & surfind, double eps) const { surfind.SetSize (0); RecGetTangentialSurfaceIndices3 (p, v, v2, surfind, eps); } void Solid :: RecGetTangentialSurfaceIndices3 (const Point<3> & p, const Vec<3> & v, const Vec<3> & v2, - Array & surfind, double eps) const + NgArray & surfind, double eps) const { switch (op) { @@ -1697,7 +1697,7 @@ namespace netgen void Solid :: RecGetTangentialEdgeSurfaceIndices (const Point<3> & p, const Vec<3> & v, const Vec<3> & v2, const Vec<3> & m, - Array & surfind, double eps) const + NgArray & surfind, double eps) const { switch (op) { @@ -1801,7 +1801,7 @@ namespace netgen } - void Solid :: CalcOnePrimitiveSpecialPoints (const Box<3> & box, Array > & pts) const + void Solid :: CalcOnePrimitiveSpecialPoints (const Box<3> & box, NgArray > & pts) const { double eps = 1e-8 * box.Diam (); @@ -1814,7 +1814,7 @@ namespace netgen } } - void Solid :: RecCalcOnePrimitiveSpecialPoints (Array > & pts) const + void Solid :: RecCalcOnePrimitiveSpecialPoints (NgArray > & pts) const { switch (op) { diff --git a/libsrc/csg/solid.hpp b/libsrc/csg/solid.hpp index c78e6af8..51720275 100644 --- a/libsrc/csg/solid.hpp +++ b/libsrc/csg/solid.hpp @@ -81,14 +81,14 @@ namespace netgen void IterateSolid (SolidIterator & it, bool only_once = 0); - void Boundaries (const Point<3> & p, Array & bounds) const; + void Boundaries (const Point<3> & p, NgArray & bounds) const; int NumPrimitives () const; - void GetSurfaceIndices (Array & surfind) const; + void GetSurfaceIndices (NgArray & surfind) const; void GetSurfaceIndices (IndexSet & iset) const; - void GetTangentialSurfaceIndices (const Point<3> & p, Array & surfids, double eps) const; - void GetTangentialSurfaceIndices2 (const Point<3> & p, const Vec<3> & v, Array & surfids, double eps) const; - void GetTangentialSurfaceIndices3 (const Point<3> & p, const Vec<3> & v, const Vec<3> & v2, Array & surfids, double eps) const; + void GetTangentialSurfaceIndices (const Point<3> & p, NgArray & surfids, double eps) const; + void GetTangentialSurfaceIndices2 (const Point<3> & p, const Vec<3> & v, NgArray & surfids, double eps) const; + void GetTangentialSurfaceIndices3 (const Point<3> & p, const Vec<3> & v, const Vec<3> & v2, NgArray & surfids, double eps) const; void ForEachSurface (const std::function & lambda, bool inv = false) const; @@ -114,16 +114,16 @@ namespace netgen /// compute localization in point p - void TangentialSolid (const Point<3> & p, Solid *& tansol, Array & surfids, double eps) const; + void TangentialSolid (const Point<3> & p, Solid *& tansol, NgArray & surfids, double eps) const; /// compute localization in point p tangential to vector t void TangentialSolid2 (const Point<3> & p, const Vec<3> & t, - Solid *& tansol, Array & surfids, double eps) const; + Solid *& tansol, NgArray & surfids, double eps) const; /** compute localization in point p, with second order approximation to edge p + s t + s*s/2 t2 **/ void TangentialSolid3 (const Point<3> & p, const Vec<3> & t, const Vec<3> & t2, - Solid *& tansol, Array & surfids, double eps) const; + Solid *& tansol, NgArray & surfids, double eps) const; @@ -135,10 +135,10 @@ namespace netgen **/ void TangentialEdgeSolid (const Point<3> & p, const Vec<3> & t, const Vec<3> & t2, const Vec<3> & m, - Solid *& tansol, Array & surfids, double eps) const; + Solid *& tansol, NgArray & surfids, double eps) const; - void CalcOnePrimitiveSpecialPoints (const Box<3> & box, Array > & pts) const; + void CalcOnePrimitiveSpecialPoints (const Box<3> & box, NgArray > & pts) const; /// int Edge (const Point<3> & p, const Vec<3> & v, double eps) const; @@ -176,23 +176,23 @@ namespace netgen protected: /// - void RecBoundaries (const Point<3> & p, Array & bounds, + void RecBoundaries (const Point<3> & p, NgArray & bounds, int & in, int & strin) const; /// - void RecTangentialSolid (const Point<3> & p, Solid *& tansol, Array & surfids, + void RecTangentialSolid (const Point<3> & p, Solid *& tansol, NgArray & surfids, int & in, int & strin, double eps) const; void RecTangentialSolid2 (const Point<3> & p, const Vec<3> & vec, - Solid *& tansol, Array & surfids, + Solid *& tansol, NgArray & surfids, int & in, int & strin, double eps) const; /// void RecTangentialSolid3 (const Point<3> & p, const Vec<3> & vec,const Vec<3> & vec2, - Solid *& tansol, Array & surfids, + Solid *& tansol, NgArray & surfids, int & in, int & strin, double eps) const; /// void RecTangentialEdgeSolid (const Point<3> & p, const Vec<3> & t, const Vec<3> & t2, const Vec<3> & m, - Solid *& tansol, Array & surfids, + Solid *& tansol, NgArray & surfids, int & in, int & strin, double eps) const; /// @@ -203,16 +203,16 @@ namespace netgen /// Solid * RecGetReducedSolid (const BoxSphere<3> & box, INSOLID_TYPE & in) const; /// - void RecGetSurfaceIndices (Array & surfind) const; - void RecGetTangentialSurfaceIndices (const Point<3> & p, Array & surfids, double eps) const; - void RecGetTangentialSurfaceIndices2 (const Point<3> & p, const Vec<3> & v, Array & surfids, double eps) const; + void RecGetSurfaceIndices (NgArray & surfind) const; + void RecGetTangentialSurfaceIndices (const Point<3> & p, NgArray & surfids, double eps) const; + void RecGetTangentialSurfaceIndices2 (const Point<3> & p, const Vec<3> & v, NgArray & surfids, double eps) const; void RecGetTangentialSurfaceIndices3 (const Point<3> & p, const Vec<3> & v, const Vec<3> & v2, - Array & surfids, double eps) const; + NgArray & surfids, double eps) const; void RecGetTangentialEdgeSurfaceIndices (const Point<3> & p, const Vec<3> & v, const Vec<3> & v2, const Vec<3> & m, - Array & surfids, double eps) const; + NgArray & surfids, double eps) const; void RecGetSurfaceIndices (IndexSet & iset) const; - void RecCalcOnePrimitiveSpecialPoints (Array > & pts) const; + void RecCalcOnePrimitiveSpecialPoints (NgArray > & pts) const; friend class SolidIterator; friend class ClearVisitedIt; diff --git a/libsrc/csg/specpoin.cpp b/libsrc/csg/specpoin.cpp index 13187ace..1bdd5015 100644 --- a/libsrc/csg/specpoin.cpp +++ b/libsrc/csg/specpoin.cpp @@ -21,7 +21,7 @@ namespace netgen { - Array > boxes; + NgArray > boxes; void ProjectToEdge (const Surface * f1, const Surface * f2, Point<3> & hp); @@ -64,7 +64,7 @@ namespace netgen } - static Array numprim_hist; + static NgArray numprim_hist; SpecialPointCalculation :: SpecialPointCalculation () { @@ -73,7 +73,7 @@ namespace netgen void SpecialPointCalculation :: CalcSpecialPoints (const CSGeometry & ageometry, - Array & apoints) + NgArray & apoints) { static int timer = NgProfiler::CreateTimer ("CSG: find special points"); NgProfiler::RegionTimer reg (timer); @@ -112,7 +112,7 @@ namespace netgen if (tlo->GetSolid()) { - Array > hpts; + NgArray > hpts; tlo->GetSolid()->CalcOnePrimitiveSpecialPoints (box, hpts); // if (hpts.Size()) // cout << "oneprimitivespecialpoints = " << hpts << endl; @@ -210,7 +210,7 @@ namespace netgen bool possiblecrossp, possibleexp; // possible cross or extremalpoint bool surecrossp = 0, sureexp = 0; // sure ... - // static Array locsurf; // attention: array is static + // static NgArray locsurf; // attention: array is static ArrayMem locsurf; // static int cntbox = 0; @@ -273,8 +273,8 @@ namespace netgen if (nquad == numprim && nplane >= numprim-1) { - Array > pts; - Array surfids; + NgArray > pts; + NgArray surfids; for (int k1 = 0; k1 < numprim - 2; k1++) for (int k2 = k1 + 1; k2 < numprim - 1; k2++) @@ -392,8 +392,8 @@ namespace netgen if (nsphere == numprim) // && calccp == false) { - Array > pts; - Array surfids; + NgArray > pts; + NgArray surfids; @@ -541,7 +541,7 @@ namespace netgen BoxSphere<3> boxp (pp, pp); boxp.Increase (1e-3*size); boxp.CalcDiamCenter(); - Array locsurf2; + NgArray locsurf2; geometry -> GetIndependentSurfaceIndices (sol, boxp, locsurf2); @@ -1132,7 +1132,7 @@ namespace netgen ComputeCrossPoints (const Plane * plane1, const Plane * plane2, const Plane * plane3, - Array > & pts) + NgArray > & pts) { Mat<3> mat; Vec<3> rhs, sol; @@ -1174,7 +1174,7 @@ namespace netgen ComputeCrossPoints (const Plane * plane1, const Plane * plane2, const QuadraticSurface * quadric, - Array > & pts) + NgArray > & pts) { Mat<2,3> mat; Mat<3,2> inv; @@ -1244,7 +1244,7 @@ namespace netgen ComputeCrossPoints (const Sphere * sphere1, const Sphere * sphere2, const Sphere * sphere3, - Array > & pts) + NgArray > & pts) { Mat<2,3> mat; Mat<3,2> inv; @@ -1327,7 +1327,7 @@ namespace netgen void SpecialPointCalculation :: ComputeExtremalPoints (const Plane * plane, const QuadraticSurface * quadric, - Array > & pts) + NgArray > & pts) { // 3 equations: // surf1 = 0 <===> plane_a + plane_b x = 0; @@ -1416,7 +1416,7 @@ namespace netgen void SpecialPointCalculation :: ComputeExtremalPoints (const Sphere * sphere1, const Sphere * sphere2, - Array > & pts) + NgArray > & pts) { // 3 equations: // surf1 = 0 <===> |x-c1|^2 - r1^2 = 0; @@ -1666,19 +1666,19 @@ namespace netgen void SpecialPointCalculation :: AnalyzeSpecialPoints (const CSGeometry & ageometry, - Array & apoints, - Array & specpoints) + NgArray & apoints, + NgArray & specpoints) { static int timer = NgProfiler::CreateTimer ("CSG: analyze special points"); NgProfiler::RegionTimer reg (timer); - Array surfind, rep_surfind, surfind2, rep_surfind2, surfind3; + NgArray surfind, rep_surfind, surfind2, rep_surfind2, surfind3; - Array > normalvecs; + NgArray > normalvecs; Vec<3> nsurf = 0.0; - Array specpoint2point; + NgArray specpoint2point; specpoints.SetSize (0); geometry = &ageometry; @@ -1698,7 +1698,7 @@ namespace netgen */ Vec<3> dir(1.2, 1.7, 0.9); - Array coord(apoints.Size()); + NgArray coord(apoints.Size()); for (int i = 0; i < apoints.Size(); i++) coord[i] = dir * Vec<3> (apoints[i]); @@ -1717,7 +1717,7 @@ namespace netgen (*testout) << "points = " << apoints << endl; Point3dTree searchtree (bbox.PMin(), bbox.PMax()); - Array locsearch; + NgArray locsearch; for (int si = 0; si < ageometry.GetNTopLevelObjects(); si++) { @@ -1882,7 +1882,7 @@ namespace netgen #ifdef DEVELOP (*testout) << "surfind2 = " << endl << surfind2 << endl; #endif - Array surfind2_aux(surfind2); + NgArray surfind2_aux(surfind2); ageometry.GetIndependentSurfaceIndices (surfind2_aux); #ifdef DEVELOP (*testout) << "surfind2,rep = " << endl << surfind2_aux << endl; @@ -2067,7 +2067,7 @@ namespace netgen if(testuncond.Test(i)) continue; - Array same; + NgArray same; same.Append(i); for(int j = i+1; j * points; + NgArray * points; /// - Array boxesinlevel; + NgArray boxesinlevel; /// double size; @@ -102,11 +102,11 @@ namespace netgen /// void CalcSpecialPoints (const CSGeometry & ageometry, - Array & points); + NgArray & points); /// void AnalyzeSpecialPoints (const CSGeometry & geometry, - Array & points, - Array & specpoints); + NgArray & points, + NgArray & specpoints); protected: /// @@ -161,27 +161,27 @@ namespace netgen void ComputeExtremalPoints (const Plane * plane, const QuadraticSurface * quadric, - Array > & pts); + NgArray > & pts); void ComputeExtremalPoints (const Sphere * sphere1, const Sphere * sphere2, - Array > & pts); + NgArray > & pts); void ComputeCrossPoints (const Plane * plane1, const Plane * plane2, const Plane * plane3, - Array > & pts); + NgArray > & pts); void ComputeCrossPoints (const Plane * plane1, const Plane * plane2, const QuadraticSurface * quadratic, - Array > & pts); + NgArray > & pts); void ComputeCrossPoints (const Sphere * sphere1, const Sphere * sphere2, const Sphere * sphere3, - Array > & pts); + NgArray > & pts); }; } diff --git a/libsrc/csg/spline3d.hpp b/libsrc/csg/spline3d.hpp index db3a40c5..39508678 100644 --- a/libsrc/csg/spline3d.hpp +++ b/libsrc/csg/spline3d.hpp @@ -27,7 +27,7 @@ namespace netgen class spline3d { /// - Array segments; + NgArray segments; public: /// diff --git a/libsrc/csg/splinesurface.cpp b/libsrc/csg/splinesurface.cpp index 6134b1f4..25b0dd31 100644 --- a/libsrc/csg/splinesurface.cpp +++ b/libsrc/csg/splinesurface.cpp @@ -36,11 +36,11 @@ void SplineSurface :: AppendPoint(const Point<3> & p, const double reffac, const return "default"; } - const shared_ptr>> SplineSurface :: CreateCuttingSurfaces() + const shared_ptr>> SplineSurface :: CreateCuttingSurfaces() { if(all_cuts) return all_cuts; - auto cuttings = make_shared>>(); + auto cuttings = make_shared>>(); for (auto cut : *cuts) cuttings->Append(cut); for(int i = 0; i> geompoints; - Array>> splines; - Array bcnames; - Array maxh; + NgArray> geompoints; + NgArray>> splines; + NgArray bcnames; + NgArray maxh; shared_ptr baseprimitive; - shared_ptr>> cuts; - shared_ptr>> all_cuts; + shared_ptr>> cuts; + shared_ptr>> all_cuts; public: - SplineSurface(shared_ptr abaseprimitive, shared_ptr>> acuts) : + SplineSurface(shared_ptr abaseprimitive, shared_ptr>> acuts) : OneSurfacePrimitive(), baseprimitive(abaseprimitive), cuts(acuts) { ; } // default constructor for archive @@ -25,7 +25,7 @@ namespace netgen const auto & GetSplines() const { return splines; } int GetNSplines() const { return splines.Size(); } - const Array>& GetPoints() const { return geompoints; } + const NgArray>& GetPoints() const { return geompoints; } string GetSplineType(const int i) const { return splines[i]->GetType(); } SplineSeg<3> & GetSpline(const int i) { return *splines[i]; } const SplineSeg<3> & GetSpline(const int i) const { return *splines[i]; } @@ -37,8 +37,8 @@ namespace netgen DLL_HEADER void AppendPoint(const Point<3> & p, const double reffac = 1., const bool hpref=false); void AppendSegment(shared_ptr> spline, string & bcname, double amaxh = -1); - const shared_ptr>> CreateCuttingSurfaces(); - const shared_ptr>> GetCuts() const { return all_cuts; } + const shared_ptr>> CreateCuttingSurfaces(); + const shared_ptr>> GetCuts() const { return all_cuts; } const shared_ptr GetBase() const { return baseprimitive; } virtual void Project (Point<3> & p3d) const { baseprimitive->Project(p3d); } @@ -50,7 +50,7 @@ namespace netgen { return baseprimitive->HesseNorm(); } virtual Point<3> GetSurfacePoint () const { return baseprimitive->GetSurfacePoint(); } - virtual void CalcSpecialPoints(Array> & pts) const + virtual void CalcSpecialPoints(NgArray> & pts) const { baseprimitive->CalcSpecialPoints(pts); } virtual INSOLID_TYPE BoxInSolid(const BoxSphere<3> & box) const @@ -67,7 +67,7 @@ namespace netgen virtual void CalcGradient (const Point<3> & point, Vec<3> & grad) const; virtual double HesseNorm () const; virtual Point<3> GetSurfacePoint () const; - virtual void CalcSpecialPoints(Array> & pts) const; + virtual void CalcSpecialPoints(NgArray> & pts) const; virtual INSOLID_TYPE BoxInSolid(const BoxSphere<3> & box) const; diff --git a/libsrc/csg/surface.cpp b/libsrc/csg/surface.cpp index f829840b..8efe1f7a 100644 --- a/libsrc/csg/surface.cpp +++ b/libsrc/csg/surface.cpp @@ -230,13 +230,13 @@ void Primitive :: SetSurfaceId (int i, int id) void Primitive :: GetPrimitiveData (const char *& classname, - Array & coeffs) const + NgArray & coeffs) const { classname = "undef"; coeffs.SetSize (0); } -void Primitive :: SetPrimitiveData (Array & coeffs) +void Primitive :: SetPrimitiveData (NgArray & coeffs) { ; } @@ -277,7 +277,7 @@ void Primitive :: Transform (Transformation<3> & trans) } void Primitive :: GetTangentialSurfaceIndices (const Point<3> & p, - Array & surfind, double eps) const + NgArray & surfind, double eps) const { for (int j = 0; j < GetNSurfaces(); j++) if (fabs (GetSurface(j).CalcFunctionValue (p)) < eps) @@ -288,7 +288,7 @@ void Primitive :: GetTangentialSurfaceIndices (const Point<3> & p, void Primitive :: GetTangentialVecSurfaceIndices (const Point<3> & p, const Vec<3> & v, - Array & surfind, double eps) const + NgArray & surfind, double eps) const { cout << "get tangvecsurfind not implemented" << endl; surfind.SetSize (0); @@ -296,7 +296,7 @@ GetTangentialVecSurfaceIndices (const Point<3> & p, const Vec<3> & v, void Primitive :: GetTangentialVecSurfaceIndices2 (const Point<3> & p, const Vec<3> & v1, const Vec<3> & v2, - Array & surfind, double eps) const + NgArray & surfind, double eps) const { for (int j = 0; j < GetNSurfaces(); j++) { diff --git a/libsrc/csg/surface.hpp b/libsrc/csg/surface.hpp index 39a6ceee..a17fd3da 100644 --- a/libsrc/csg/surface.hpp +++ b/libsrc/csg/surface.hpp @@ -241,8 +241,8 @@ namespace netgen class Primitive { protected: - Array surfaceids; - Array surfaceactive; + NgArray surfaceids; + NgArray surfaceactive; public: @@ -268,7 +268,7 @@ namespace netgen double eps) const = 0; virtual void GetTangentialSurfaceIndices (const Point<3> & p, - Array & surfind, double eps) const; + NgArray & surfind, double eps) const; virtual INSOLID_TYPE VecInSolid (const Point<3> & p, const Vec<3> & v, @@ -294,15 +294,15 @@ namespace netgen double eps) const; virtual void GetTangentialVecSurfaceIndices (const Point<3> & p, const Vec<3> & v, - Array & surfind, double eps) const; + NgArray & surfind, double eps) const; virtual void GetTangentialVecSurfaceIndices2 (const Point<3> & p, const Vec<3> & v1, const Vec<3> & v2, - Array & surfind, double eps) const; + NgArray & surfind, double eps) const; - virtual void CalcSpecialPoints (Array > & /* pts */) const { ; } + virtual void CalcSpecialPoints (NgArray > & /* pts */) const { ; } virtual void AnalyzeSpecialPoint (const Point<3> & /* pt */, - Array > & /* specpts */) const { ; } + NgArray > & /* specpts */) const { ; } virtual Vec<3> SpecialPointTangentialVector (const Point<3> & /* p */, int /* s1 */, int /* s2 */) const { return Vec<3> (0,0,0); } @@ -318,8 +318,8 @@ namespace netgen virtual int SurfaceInverted (int /* i */ = 0) const { return 0; } virtual void GetPrimitiveData (const char *& classname, - Array & coeffs) const; - virtual void SetPrimitiveData (Array & coeffs); + NgArray & coeffs) const; + virtual void SetPrimitiveData (NgArray & coeffs); static Primitive * CreatePrimitive (const char * classname); diff --git a/libsrc/csg/triapprox.cpp b/libsrc/csg/triapprox.cpp index 0c4f2b14..3c285c27 100644 --- a/libsrc/csg/triapprox.cpp +++ b/libsrc/csg/triapprox.cpp @@ -29,7 +29,7 @@ namespace netgen void TriangleApproximation :: RemoveUnusedPoints () { BitArray used(GetNP()); - Array map (GetNP()); + NgArray map (GetNP()); int i, j; int cnt = 0; diff --git a/libsrc/csg/triapprox.hpp b/libsrc/csg/triapprox.hpp index dab9a833..e97b62bc 100644 --- a/libsrc/csg/triapprox.hpp +++ b/libsrc/csg/triapprox.hpp @@ -36,9 +36,9 @@ namespace netgen class TriangleApproximation { - Array > points; - Array > normals; - Array trigs; + NgArray > points; + NgArray > normals; + NgArray trigs; public: TriangleApproximation(); diff --git a/libsrc/csg/vscsg.cpp b/libsrc/csg/vscsg.cpp index f28a49bc..f34e9289 100644 --- a/libsrc/csg/vscsg.cpp +++ b/libsrc/csg/vscsg.cpp @@ -18,8 +18,8 @@ namespace netgen /* *********************** Draw Geometry **************** */ extern shared_ptr mesh; - extern Array specpoints; - extern Array > boxes; + extern NgArray specpoints; + extern NgArray > boxes; diff --git a/libsrc/csg/vscsg.hpp b/libsrc/csg/vscsg.hpp index dc705a80..4805a246 100644 --- a/libsrc/csg/vscsg.hpp +++ b/libsrc/csg/vscsg.hpp @@ -13,7 +13,7 @@ namespace netgen class DLL_HEADER VisualSceneGeometry : public VisualScene { class CSGeometry * geometry; - Array trilists; + NgArray trilists; int selsurf; public: VisualSceneGeometry (); diff --git a/libsrc/csg/zrefine.cpp b/libsrc/csg/zrefine.cpp index 81800cef..4fbebb82 100644 --- a/libsrc/csg/zrefine.cpp +++ b/libsrc/csg/zrefine.cpp @@ -211,7 +211,7 @@ namespace netgen { int i, j; int nseg = mesh.GetNSeg(); - Array edgesonpoint(mesh.GetNP()); + NgArray edgesonpoint(mesh.GetNP()); for (i = 1; i <= mesh.GetNP(); i++) edgesonpoint.Elem(i) = 0; @@ -251,9 +251,9 @@ namespace netgen // markers for z-refinement: p1, p2, levels // p1-p2 is an edge to be refined - Array ref_uniform; - Array ref_singular; - Array ref_slices; + NgArray ref_uniform; + NgArray ref_singular; + NgArray ref_slices; BitArray first_id(geom->identifications.Size()); first_id.Set(); @@ -287,7 +287,7 @@ namespace netgen } else { - //const Array & slices = csid->GetSlices(); + //const NgArray & slices = csid->GetSlices(); INDEX_4 i4; i4[0] = pair.I1(); i4[1] = pair.I2(); @@ -301,7 +301,7 @@ namespace netgen - Array epgi; + NgArray epgi; while (1) { @@ -389,7 +389,7 @@ namespace netgen edge.Sort(); if (!refedges.Used(edge)) { - const Array & slices = csid->GetSlices(); + const NgArray & slices = csid->GetSlices(); //(*testout) << "idnr " << idnr << " i " << i << endl; //(*testout) << "slices " << slices << endl; double slicefac = slices.Get(slicenr); diff --git a/libsrc/general/array.cpp b/libsrc/general/array.cpp index d3f48d36..3b822d1a 100644 --- a/libsrc/general/array.cpp +++ b/libsrc/general/array.cpp @@ -9,7 +9,7 @@ /**************************************************************************/ /* - Abstract data type Array + Abstract data type NgArray */ #include @@ -65,8 +65,8 @@ namespace netgen { if (!actsize) { - throw Exception ("Array should not be empty"); - // cerr << "Array souldn't be empty"; + throw Exception ("NgArray should not be empty"); + // cerr << "NgArray souldn't be empty"; } } #endif diff --git a/libsrc/general/array.hpp b/libsrc/general/array.hpp index 07ec23d7..e005e493 100644 --- a/libsrc/general/array.hpp +++ b/libsrc/general/array.hpp @@ -67,7 +67,7 @@ namespace netgen /** A simple array container. - Array represented by size and data-pointer. + NgArray represented by size and data-pointer. No memory allocation and deallocation, must be provided by user. Helper functions for printing. Optional range check by macro RANGE_CHECK @@ -124,7 +124,7 @@ namespace netgen { #ifdef DEBUG if (i < 1 || i > size) - cout << "Array<" << typeid(T).name() + cout << "NgArray<" << typeid(T).name() << ">::Elem out of range, i = " << i << ", s = " << size << endl; #endif @@ -137,7 +137,7 @@ namespace netgen { #ifdef DEBUG if (i < 1 || i > size) - cout << "Array<" << typeid(T).name() << ">::Get out of range, i = " << i + cout << "NgArray<" << typeid(T).name() << ">::Get out of range, i = " << i << ", s = " << size << endl; #endif @@ -149,7 +149,7 @@ namespace netgen { #ifdef DEBUG if (i < 1 || i > size) - cout << "Array<" << typeid(T).name() << ">::Set out of range, i = " << i + cout << "NgArray<" << typeid(T).name() << ">::Set out of range, i = " << i << ", s = " << size << endl; #endif @@ -215,13 +215,13 @@ namespace netgen /** Dynamic array container. - Array is an automatically increasing array container. + NgArray is an automatically increasing array container. The allocated memory doubles on overflow. Either the container takes care of memory allocation and deallocation, or the user provides one block of data. */ template - class Array : public FlatArray + class NgArray : public FlatArray { protected: using FlatArray::size; @@ -235,14 +235,14 @@ namespace netgen public: /// Generate array of logical and physical size asize - explicit Array() + explicit NgArray() : FlatArray (0, NULL) { allocsize = 0; ownmem = 1; } - explicit Array(size_t asize) + explicit NgArray(size_t asize) : FlatArray (asize, asize ? new T[asize] : nullptr) { allocsize = asize; @@ -250,7 +250,7 @@ namespace netgen } /// Generate array in user data - Array(TIND asize, T* adata) + NgArray(TIND asize, T* adata) : FlatArray (asize, adata) { allocsize = asize; @@ -258,7 +258,7 @@ namespace netgen } /// array copy - explicit Array (const Array & a2) + explicit NgArray (const NgArray & a2) : FlatArray (a2.Size(), a2.Size() ? new T[a2.Size()] : 0) { allocsize = size; @@ -268,7 +268,7 @@ namespace netgen } /// array move - Array (Array && a2) + NgArray (NgArray && a2) : FlatArray (a2.size, a2.data), allocsize(a2.allocsize), ownmem(a2.ownmem) { a2.size = 0; @@ -279,7 +279,7 @@ namespace netgen /// if responsible, deletes memory - ~Array() + ~NgArray() { if (ownmem) delete [] data; @@ -362,14 +362,14 @@ namespace netgen } /// Fill array with val - Array & operator= (const T & val) + NgArray & operator= (const T & val) { FlatArray::operator= (val); return *this; } /// array copy - Array & operator= (const Array & a2) + NgArray & operator= (const NgArray & a2) { SetSize (a2.Size()); for (TIND i (BASE); i < size+BASE; i++) @@ -378,7 +378,7 @@ namespace netgen } /// array copy - Array & operator= (const FlatArray & a2) + NgArray & operator= (const FlatArray & a2) { SetSize (a2.Size()); for (TIND i = BASE; i < size+BASE; i++) @@ -386,7 +386,7 @@ namespace netgen return *this; } - Array & operator= (Array && a2) + NgArray & operator= (NgArray && a2) { Swap (data, a2.data); Swap (size, a2.size); @@ -458,11 +458,11 @@ namespace netgen template - class ArrayMem : public Array + class ArrayMem : public NgArray { - using Array::size; - using Array::data; - using Array::ownmem; + using NgArray::size; + using NgArray::data; + using NgArray::ownmem; T mem[S]; // Intel C++ calls dummy constructor // char mem[S*sizeof(T)]; @@ -470,7 +470,7 @@ namespace netgen public: /// Generate array of logical and physical size asize explicit ArrayMem(size_t asize = 0) - : Array (S, static_cast (static_cast(&mem[0]))) + : NgArray (S, static_cast (static_cast(&mem[0]))) { size = asize; if (asize > S) @@ -483,7 +483,7 @@ namespace netgen ArrayMem & operator= (const T & val) { - Array::operator= (val); + NgArray::operator= (val); return *this; } @@ -777,7 +777,7 @@ namespace netgen template void Intersection (const FlatArray & in1, const FlatArray & in2, - Array & out) + NgArray & out) { out.SetSize(0); for(int i=0; i void Intersection (const FlatArray & in1, const FlatArray & in2, const FlatArray & in3, - Array & out) + NgArray & out) { out.SetSize(0); for(int i=0; i class BitArrayChar { /// - Array data; + NgArray data; public: /// diff --git a/libsrc/general/flags.cpp b/libsrc/general/flags.cpp index 993413ed..f284f7d0 100644 --- a/libsrc/general/flags.cpp +++ b/libsrc/general/flags.cpp @@ -56,9 +56,9 @@ namespace netgen } - void Flags :: SetFlag (const char * name, const Array & val) + void Flags :: SetFlag (const char * name, const NgArray & val) { - Array * strarray = new Array; + NgArray * strarray = new NgArray; for (int i = 1; i <= val.Size(); i++) { strarray->Append (new char[strlen(val.Get(i))+1]); @@ -67,9 +67,9 @@ namespace netgen strlistflags.Set (name, strarray); } - void Flags :: SetFlag (const char * name, const Array & val) + void Flags :: SetFlag (const char * name, const NgArray & val) { - Array * numarray = new Array; + NgArray * numarray = new NgArray; for (int i = 1; i <= val.Size(); i++) numarray->Append (val.Get(i)); numlistflags.Set (name, numarray); @@ -118,26 +118,26 @@ namespace netgen } - const Array & + const NgArray & Flags :: GetStringListFlag (const char * name) const { if (strlistflags.Used (name)) return *strlistflags[name]; else { - static Array dummy_array(0); + static NgArray dummy_array(0); return dummy_array; } } - const Array & + const NgArray & Flags ::GetNumListFlag (const char * name) const { if (numlistflags.Used (name)) return *numlistflags[name]; else { - static Array dummy_array(0); + static NgArray dummy_array(0); return dummy_array; } } diff --git a/libsrc/general/flags.hpp b/libsrc/general/flags.hpp index e7ba0382..1f5ec3ba 100644 --- a/libsrc/general/flags.hpp +++ b/libsrc/general/flags.hpp @@ -25,9 +25,9 @@ class Flags /// SymbolTable defflags; /// - SymbolTable*> strlistflags; + SymbolTable*> strlistflags; /// - SymbolTable*> numlistflags; + SymbolTable*> numlistflags; public: /// DLL_HEADER Flags (); @@ -43,9 +43,9 @@ public: /// Sets boolean flag DLL_HEADER void SetFlag (const char * name); /// Sets string arary flag - DLL_HEADER void SetFlag (const char * name, const Array & val); + DLL_HEADER void SetFlag (const char * name, const NgArray & val); /// Sets double array flag - DLL_HEADER void SetFlag (const char * name, const Array & val); + DLL_HEADER void SetFlag (const char * name, const NgArray & val); /// Save flags to file DLL_HEADER void SaveFlags (const char * filename) const; @@ -67,9 +67,9 @@ public: /// Returns boolean flag DLL_HEADER bool GetDefineFlag (const char * name) const; /// Returns string list flag, empty array if not exist - DLL_HEADER const Array & GetStringListFlag (const char * name) const; + DLL_HEADER const NgArray & GetStringListFlag (const char * name) const; /// Returns num list flag, empty array if not exist - DLL_HEADER const Array & GetNumListFlag (const char * name) const; + DLL_HEADER const NgArray & GetNumListFlag (const char * name) const; /// Test, if string flag is defined diff --git a/libsrc/general/hashtabl.hpp b/libsrc/general/hashtabl.hpp index 4d8fadc8..2096747a 100644 --- a/libsrc/general/hashtabl.hpp +++ b/libsrc/general/hashtabl.hpp @@ -480,7 +480,7 @@ class BASE_INDEX_CLOSED_HASHTABLE protected: /// // MoveableArray hash; - Array hash; + NgArray hash; /// int invalid; public: @@ -556,7 +556,7 @@ class INDEX_CLOSED_HASHTABLE : public BASE_INDEX_CLOSED_HASHTABLE { /// // MoveableArray cont; - Array cont; + NgArray cont; public: /// @@ -653,7 +653,7 @@ class BASE_INDEX_2_CLOSED_HASHTABLE protected: /// // MoveableArray hash; - Array hash; + NgArray hash; /// int invalid; size_t mask; @@ -718,7 +718,7 @@ protected: template class INDEX_2_CLOSED_HASHTABLE : public BASE_INDEX_2_CLOSED_HASHTABLE { - Array cont; + NgArray cont; public: INDEX_2_CLOSED_HASHTABLE (size_t size) : BASE_INDEX_2_CLOSED_HASHTABLE(size), cont(RoundUp2(size)) @@ -813,7 +813,7 @@ inline ostream & operator<< (ostream & ost, const INDEX_2_CLOSED_HASHTABLE & class BASE_INDEX_3_CLOSED_HASHTABLE { protected: - Array hash; + NgArray hash; int invalid; size_t mask; @@ -922,7 +922,7 @@ template class INDEX_3_CLOSED_HASHTABLE : public BASE_INDEX_3_CLOSED_HASHTABLE { // MoveableArray cont; - Array cont; + NgArray cont; public: INDEX_3_CLOSED_HASHTABLE (int size) @@ -1376,9 +1376,9 @@ inline size_t HashValue (INDEX_2 i2, size_t size) { return (113*size_t(i2[0])+si /// size_t used; /// - Array hash; + NgArray hash; /// - Array cont; + NgArray cont; public: /// ClosedHashTable (size_t asize = 128) diff --git a/libsrc/general/mpi_interface.hpp b/libsrc/general/mpi_interface.hpp index 6dc3070f..66109bb4 100644 --- a/libsrc/general/mpi_interface.hpp +++ b/libsrc/general/mpi_interface.hpp @@ -95,7 +95,7 @@ namespace netgen #endif #ifdef PARALLEL - inline MPI_Comm MyMPI_SubCommunicator(MPI_Comm comm, Array & procs) + inline MPI_Comm MyMPI_SubCommunicator(MPI_Comm comm, NgArray & procs) { MPI_Comm subcomm; MPI_Group gcomm, gsubcomm; @@ -105,7 +105,7 @@ namespace netgen return subcomm; } #else - inline MPI_Comm MyMPI_SubCommunicator(MPI_Comm comm, Array & procs) + inline MPI_Comm MyMPI_SubCommunicator(MPI_Comm comm, NgArray & procs) { return comm; } #endif @@ -160,7 +160,7 @@ namespace netgen } template - inline void MyMPI_Recv ( Array & s, int src, int tag, MPI_Comm comm /* = ng_comm */) + inline void MyMPI_Recv ( NgArray & s, int src, int tag, MPI_Comm comm /* = ng_comm */) { MPI_Status status; int len; @@ -172,7 +172,7 @@ namespace netgen } template - inline int MyMPI_Recv ( Array & s, int tag, MPI_Comm comm /* = ng_comm */) + inline int MyMPI_Recv ( NgArray & s, int tag, MPI_Comm comm /* = ng_comm */) { MPI_Status status; int len; @@ -257,7 +257,7 @@ namespace netgen MPI_Comm_size(comm, &ntasks); MPI_Comm_rank(comm, &rank); - Array requests; + NgArray requests; for (int dest = 0; dest < ntasks; dest++) if (dest != rank) requests.Append (MyMPI_ISend (send_data[dest], dest, tag, comm)); @@ -288,8 +288,8 @@ namespace netgen int rank = comm.Rank(); int ntasks = comm.Size(); - Array send_sizes(ntasks); - Array recv_sizes(ntasks); + NgArray send_sizes(ntasks); + NgArray recv_sizes(ntasks); for (int i = 0; i < ntasks; i++) send_sizes[i] = send_data[i].Size(); @@ -304,7 +304,7 @@ namespace netgen for (int i = 0; i < ntasks; i++) recv_data.SetEntrySize (i, recv_sizes[i], sizeof(T)); - Array requests; + NgArray requests; for (int dest = 0; dest < ntasks; dest++) if (dest != rank && send_data[dest].Size()) requests.Append (MyMPI_ISend (send_data[dest], dest, tag, comm)); @@ -336,7 +336,7 @@ namespace netgen } template - inline void MyMPI_Bcast (Array & s, NgMPI_Comm comm /* = ng_comm */) + inline void MyMPI_Bcast (NgArray & s, NgMPI_Comm comm /* = ng_comm */) { int size = s.Size(); MyMPI_Bcast (size, comm); @@ -346,7 +346,7 @@ namespace netgen } template - inline void MyMPI_Bcast (Array & s, int root, MPI_Comm comm /* = ng_comm */) + inline void MyMPI_Bcast (NgArray & s, int root, MPI_Comm comm /* = ng_comm */) { int id; MPI_Comm_rank(comm, &id); diff --git a/libsrc/general/optmem.cpp b/libsrc/general/optmem.cpp index 40cfb4c5..a9c5e440 100644 --- a/libsrc/general/optmem.cpp +++ b/libsrc/general/optmem.cpp @@ -5,7 +5,7 @@ /**************************************************************************/ /* - Abstract data type Array + Abstract data type NgArray */ diff --git a/libsrc/general/optmem.hpp b/libsrc/general/optmem.hpp index 0d2b9de7..99ffb67d 100644 --- a/libsrc/general/optmem.hpp +++ b/libsrc/general/optmem.hpp @@ -22,7 +22,7 @@ private: /// void * freelist; /// - Array bablocks; + NgArray bablocks; mutex block_allocator_mutex; public: /// diff --git a/libsrc/general/seti.hpp b/libsrc/general/seti.hpp index 4adbb09c..56d1754a 100644 --- a/libsrc/general/seti.hpp +++ b/libsrc/general/seti.hpp @@ -16,7 +16,7 @@ namespace netgen */ class IndexSet { - Array set; + NgArray set; BitArray flags; public: IndexSet (int maxind); @@ -41,7 +41,7 @@ public: void Del (int ind); void Clear (); - const Array & GetArray() { return set; } + const NgArray & GetArray() { return set; } }; } diff --git a/libsrc/general/sort.cpp b/libsrc/general/sort.cpp index a6adda1a..b44f391b 100644 --- a/libsrc/general/sort.cpp +++ b/libsrc/general/sort.cpp @@ -16,8 +16,8 @@ namespace netgen { - void Sort (const Array & values, - Array & order) + void Sort (const NgArray & values, + NgArray & order) { int n = values.Size(); int i, j; @@ -35,8 +35,8 @@ namespace netgen } - void QuickSortRec (const Array & values, - Array & order, + void QuickSortRec (const NgArray & values, + NgArray & order, int left, int right) { int i, j; @@ -62,8 +62,8 @@ namespace netgen if (i < right) QuickSortRec (values, order, i, right); } - void QuickSort (const Array & values, - Array & order) + void QuickSort (const NgArray & values, + NgArray & order) { int i, n = values.Size(); order.SetSize (n); diff --git a/libsrc/general/sort.hpp b/libsrc/general/sort.hpp index 3a9b41db..aa653934 100644 --- a/libsrc/general/sort.hpp +++ b/libsrc/general/sort.hpp @@ -11,11 +11,11 @@ namespace netgen { // order(i) is sorted index of element i -extern void Sort (const Array & values, - Array & order); +extern void Sort (const NgArray & values, + NgArray & order); -extern void QuickSort (const Array & values, - Array & order); +extern void QuickSort (const NgArray & values, + NgArray & order); @@ -35,7 +35,7 @@ inline void BubbleSort (int size, T * data) } template -inline void BubbleSort (Array & data) +inline void BubbleSort (NgArray & data) { if(data.Size() > 0) BubbleSort (data.Size(), &data[data.Begin()]); diff --git a/libsrc/general/stack.hpp b/libsrc/general/stack.hpp index 83adee64..7e86b524 100644 --- a/libsrc/general/stack.hpp +++ b/libsrc/general/stack.hpp @@ -41,7 +41,7 @@ public: private: /// - Array elems; + NgArray elems; /// INDEX size; }; diff --git a/libsrc/general/table.hpp b/libsrc/general/table.hpp index 6a08b3dc..3847395f 100644 --- a/libsrc/general/table.hpp +++ b/libsrc/general/table.hpp @@ -29,7 +29,7 @@ protected: }; /// - Array data; + NgArray data; char * oneblock; public: diff --git a/libsrc/geom2d/genmesh2d.cpp b/libsrc/geom2d/genmesh2d.cpp index fde8b16c..cdd6eb4f 100644 --- a/libsrc/geom2d/genmesh2d.cpp +++ b/libsrc/geom2d/genmesh2d.cpp @@ -14,14 +14,14 @@ namespace netgen // double l, MeshingParameters & mp, Mesh & mesh, // double h, double h1, double h2, double hcurve, - double elto0, Array & points) + double elto0, NgArray & points) { double fperel, oldf, f; int n = 10000; - Array > xi(n); - Array hi(n); + NgArray > xi(n); + NgArray hi(n); for (int i = 0; i < n; i++) { @@ -98,7 +98,7 @@ namespace netgen int n = 100; Point<2> mark, oldmark; - Array curvepoints; + NgArray curvepoints; double edgelength, edgelengthold; CalcPartition (spline, mp, mesh, elto0, curvepoints); @@ -111,7 +111,7 @@ namespace netgen double lold = 0; oldmark = pold; edgelengthold = 0; - Array locsearch; + NgArray locsearch; for (int i = 1; i <= n; i++) { @@ -310,8 +310,8 @@ namespace netgen { // const int D = 2; - Array mappoints (mesh.GetNP()); - Array param (mesh.GetNP()); + NgArray mappoints (mesh.GetNP()); + NgArray param (mesh.GetNP()); mappoints = -1; param = 0; @@ -452,7 +452,7 @@ namespace netgen for (int i = 1; i <= maxdomnr; i++) mesh->AddFaceDescriptor (FaceDescriptor (i, 0, 0, i)); - // set Array bcnames... + // set NgArray bcnames... // number of bcnames int maxsegmentindex = 0; for (SegmentIndex si = 0; si < mesh->GetNSeg(); si++) @@ -478,8 +478,8 @@ namespace netgen if (geometry.GetDomainTensorMeshing (domnr)) { // tensor product mesh - Array nextpi(bnp); - Array si1(bnp), si2(bnp); + NgArray nextpi(bnp); + NgArray si1(bnp), si2(bnp); PointIndex firstpi; nextpi = -1; @@ -518,7 +518,7 @@ namespace netgen - Array pts ( (nex+1) * (ney+1) ); // x ... inner loop + NgArray pts ( (nex+1) * (ney+1) ); // x ... inner loop pts = -1; for (PointIndex pi = c1, i = 0; pi != c2; pi = nextpi[pi], i++) @@ -572,7 +572,7 @@ namespace netgen Meshing2 meshing (mp, Box<3> (pmin, pmax)); - Array compress(bnp); + NgArray compress(bnp); compress = -1; int cnt = 0; for (PointIndex pi : BndPntRange) diff --git a/libsrc/geom2d/geometry2d.cpp b/libsrc/geom2d/geometry2d.cpp index 91ad9b78..3f5cac0c 100644 --- a/libsrc/geom2d/geometry2d.cpp +++ b/libsrc/geom2d/geometry2d.cpp @@ -187,7 +187,7 @@ namespace netgen { int npts; infile >> npts; - Array< Point > pts(npts); + NgArray< Point > pts(npts); for (int j = 0; j < npts; j++) for(int k=0; k> pts[j](k); @@ -358,7 +358,7 @@ namespace netgen { int npts; infile >> npts; - Array< Point > pts(npts); + NgArray< Point > pts(npts); for (int j = 0; j < npts; j++) for(int k=0; k> pts[j](k); @@ -489,8 +489,8 @@ namespace netgen string keyword; - Array < GeomPoint > infilepoints (0); - Array pointnrs (0); + NgArray < GeomPoint > infilepoints (0); + NgArray pointnrs (0); nump = 0; int numdomains = 0; @@ -654,7 +654,7 @@ namespace netgen { int npts; infile >> npts; - Array< Point > pts(npts); + NgArray< Point > pts(npts); for (int j = 0; j < npts; j++) for(int k=0; k> pts[j](k); @@ -666,7 +666,7 @@ namespace netgen int npts,order; infile >> npts; infile >> order; - Array< Point > pts(npts); + NgArray< Point > pts(npts); for (int j = 0; j < npts; j++) for(int k=0; k> pts[j](k); @@ -830,7 +830,7 @@ namespace netgen /* void CalcPartition (const SplineSegExt & spline, double l, double h, double h1, double h2, - double hcurve, double elto0, Array & points) + double hcurve, double elto0, NgArray & points) { double fperel, oldf, f; diff --git a/libsrc/geom2d/geometry2d.hpp b/libsrc/geom2d/geometry2d.hpp index 0d4bcb00..f8b55430 100644 --- a/libsrc/geom2d/geometry2d.hpp +++ b/libsrc/geom2d/geometry2d.hpp @@ -94,7 +94,7 @@ namespace netgen seg->GetCoeff (coeffs); } - virtual void GetPoints (int n, Array > & points) const + virtual void GetPoints (int n, NgArray > & points) const { seg->GetPoints (n, points); } @@ -131,12 +131,12 @@ namespace netgen class SplineGeometry2d : public SplineGeometry<2>, public NetgenGeometry { protected: - Array materials; - Array maxh; - Array quadmeshing; - Array tensormeshing; - Array layer; - Array bcnames; + NgArray materials; + NgArray maxh; + NgArray quadmeshing; + NgArray tensormeshing; + NgArray layer; + NgArray bcnames; double elto0 = 1.0; diff --git a/libsrc/geom2d/python_geom2d.cpp b/libsrc/geom2d/python_geom2d.cpp index fbfa22d9..e42450ae 100644 --- a/libsrc/geom2d/python_geom2d.cpp +++ b/libsrc/geom2d/python_geom2d.cpp @@ -144,7 +144,7 @@ DLL_HEADER void ExportGeom2d(py::module &m) int leftdomain, int rightdomain, py::object bc, double maxh) { int n = 1000; - Array> points; + NgArray> points; for (int i = 0; i <= n; i++) { double t = double(i)/n; diff --git a/libsrc/geom2d/spline2d.hpp b/libsrc/geom2d/spline2d.hpp index 52ec0df1..7f52bdf4 100644 --- a/libsrc/geom2d/spline2d.hpp +++ b/libsrc/geom2d/spline2d.hpp @@ -85,13 +85,13 @@ public: virtual void GetCoeff (Vector & coeffs) const = 0; - virtual void GetPoints (int n, Array > & points); + virtual void GetPoints (int n, NgArray > & points); /** calculates lineintersections: for lines $$ a x + b y + c = 0 $$ the interecting points are calculated and stored in points */ virtual void LineIntersections (const double a, const double b, const double c, - Array < Point<2> > & points, const double eps) const + NgArray < Point<2> > & points, const double eps) const {points.SetSize(0);} virtual double MaxCurvature(void) const = 0; @@ -123,7 +123,7 @@ public: virtual string GetType(void) const {return "line";} virtual void LineIntersections (const double a, const double b, const double c, - Array < Point<2> > & points, const double eps) const; + NgArray < Point<2> > & points, const double eps) const; virtual double MaxCurvature(void) const {return 0;} }; @@ -154,7 +154,7 @@ public: const GeomPoint2d & TangentPoint (void) const { return p2; } virtual void LineIntersections (const double a, const double b, const double c, - Array < Point<2> > & points, const double eps) const; + NgArray < Point<2> > & points, const double eps) const; virtual double MaxCurvature(void) const; }; @@ -195,7 +195,7 @@ public: virtual string GetType(void) const {return "circle";} virtual void LineIntersections (const double a, const double b, const double c, - Array < Point<2> > & points, const double eps) const; + NgArray < Point<2> > & points, const double eps) const; virtual double MaxCurvature(void) const {return 1./radius;} }; @@ -208,11 +208,11 @@ public: /// class DiscretePointsSegment : public SplineSegment { - Array > pts; + NgArray > pts; GeomPoint2d p1, p2; public: /// - DiscretePointsSegment (const Array > & apts); + DiscretePointsSegment (const NgArray > & apts); /// virtual ~DiscretePointsSegment (); /// diff --git a/libsrc/geom2d/vsgeom2d.cpp b/libsrc/geom2d/vsgeom2d.cpp index f0cff330..ebfc7923 100644 --- a/libsrc/geom2d/vsgeom2d.cpp +++ b/libsrc/geom2d/vsgeom2d.cpp @@ -52,7 +52,7 @@ namespace netgen glColor3f (0, 0, 1); - Array > points, otherpoints; + NgArray > points, otherpoints; for (int i = 1; i <= geometry2d->GetSplines().Size(); i++) { diff --git a/libsrc/gprim/adtree.cpp b/libsrc/gprim/adtree.cpp index cba845a7..78cd43f2 100644 --- a/libsrc/gprim/adtree.cpp +++ b/libsrc/gprim/adtree.cpp @@ -206,7 +206,7 @@ namespace netgen } - void ADTree :: GetMatch (Array & matches) + void ADTree :: GetMatch (NgArray & matches) { int nodenr; @@ -398,10 +398,10 @@ namespace netgen void ADTree3 :: GetIntersecting (const float * bmin, const float * bmax, - Array & pis) const + NgArray & pis) const { - static Array stack(1000); - static Array stackdir(1000); + static NgArray stack(1000); + static NgArray stackdir(1000); ADTreeNode3 * node; int dir, stacks; @@ -658,10 +658,10 @@ namespace netgen void ADTree3Div :: GetIntersecting (const float * bmin, const float * bmax, - Array & pis) const + NgArray & pis) const { - static Array stack(1000); - static Array stackdir(1000); + static NgArray stack(1000); + static NgArray stackdir(1000); ADTreeNode3Div * node; int dir, i, stacks; @@ -917,10 +917,10 @@ namespace netgen void ADTree3M :: GetIntersecting (const float * bmin, const float * bmax, - Array & pis) const + NgArray & pis) const { - static Array stack(1000); - static Array stackdir(1000); + static NgArray stack(1000); + static NgArray stackdir(1000); ADTreeNode3M * node; int dir, i, stacks; @@ -1163,9 +1163,9 @@ namespace netgen void ADTree3F :: GetIntersecting (const float * bmin, const float * bmax, - Array & pis) const + NgArray & pis) const { - static Array stack(1000); + static NgArray stack(1000); ADTreeNode3F * node; int dir, i, stacks; @@ -1427,9 +1427,9 @@ namespace netgen void ADTree3FM :: GetIntersecting (const float * bmin, const float * bmax, - Array & pis) const + NgArray & pis) const { - static Array stack(1000); + static NgArray stack(1000); ADTreeNode3FM * node; int dir, i, stacks; @@ -1700,9 +1700,9 @@ namespace netgen void ADTree6 :: GetIntersecting (const float * bmin, const float * bmax, - Array & pis) const + NgArray & pis) const { - // static Array stack(10000); + // static NgArray stack(10000); // stack.SetSize (10000); ArrayMem stack(10000); pis.SetSize(0); @@ -1920,9 +1920,9 @@ namespace netgen template void T_ADTree :: GetIntersecting (Point bmin, Point bmax, - Array & pis) const + NgArray & pis) const { - // static Array stack(10000); + // static NgArray stack(10000); // stack.SetSize (10000); ArrayMem,10000> stack(10000); pis.SetSize(0); @@ -2195,9 +2195,9 @@ namespace netgen void ADTree6F :: GetIntersecting (const float * bmin, const float * bmax, - Array & pis) const + NgArray & pis) const { - static Array stack(1000); + static NgArray stack(1000); ADTreeNode6F * node; int dir, i, stacks; @@ -2329,7 +2329,7 @@ namespace netgen } void Point3dTree :: GetIntersecting (const Point<3> & pmin, const Point<3> & pmax, - Array & pis) const + NgArray & pis) const { float pmi[3], pma[3]; for (int i = 0; i < 3; i++) @@ -2397,7 +2397,7 @@ namespace netgen template void BoxTree ::GetIntersecting (const Point & pmin, const Point & pmax, - Array & pis) const + NgArray & pis) const { Point<2*dim> tpmin, tpmax; double tol = Tolerance(); diff --git a/libsrc/gprim/adtree.hpp b/libsrc/gprim/adtree.hpp index 11694b67..b78ec069 100644 --- a/libsrc/gprim/adtree.hpp +++ b/libsrc/gprim/adtree.hpp @@ -51,11 +51,11 @@ class ADTree int dim; ADTreeNode * root; float *cmin, *cmax; - Array ela; + NgArray ela; const ADTreeCriterion * criterion; - Array stack; - Array stackdir; + NgArray stack; + NgArray stackdir; int stackindex; public: @@ -65,11 +65,11 @@ public: void Insert (const float * p, int pi); // void GetIntersecting (const float * bmin, const float * bmax, - // Array & pis) const; + // NgArray & pis) const; void SetCriterion (ADTreeCriterion & acriterion); void Reset (); int Next (); - void GetMatch (Array & matches); + void GetMatch (NgArray & matches); void DeleteElement (int pi); @@ -105,7 +105,7 @@ class ADTree3 { ADTreeNode3 * root; float cmin[3], cmax[3]; - Array ela; + NgArray ela; public: ADTree3 (const float * acmin, @@ -114,7 +114,7 @@ public: void Insert (const float * p, int pi); void GetIntersecting (const float * bmin, const float * bmax, - Array & pis) const; + NgArray & pis) const; void DeleteElement (int pi); @@ -155,7 +155,7 @@ class ADTree3Div { ADTreeNode3Div * root; float cmin[3], cmax[3]; - Array ela; + NgArray ela; public: ADTree3Div (const float * acmin, @@ -164,7 +164,7 @@ public: void Insert (const float * p, int pi); void GetIntersecting (const float * bmin, const float * bmax, - Array & pis) const; + NgArray & pis) const; void DeleteElement (int pi); @@ -204,7 +204,7 @@ class ADTree3M { ADTreeNode3M * root; float cmin[3], cmax[3]; - Array ela; + NgArray ela; public: ADTree3M (const float * acmin, @@ -213,7 +213,7 @@ public: void Insert (const float * p, int pi); void GetIntersecting (const float * bmin, const float * bmax, - Array & pis) const; + NgArray & pis) const; void DeleteElement (int pi); @@ -253,7 +253,7 @@ class ADTree3F { ADTreeNode3F * root; float cmin[3], cmax[3]; - Array ela; + NgArray ela; public: ADTree3F (const float * acmin, @@ -262,7 +262,7 @@ public: void Insert (const float * p, int pi); void GetIntersecting (const float * bmin, const float * bmax, - Array & pis) const; + NgArray & pis) const; void DeleteElement (int pi); @@ -300,7 +300,7 @@ class ADTree3FM { ADTreeNode3FM * root; float cmin[3], cmax[3]; - Array ela; + NgArray ela; public: ADTree3FM (const float * acmin, @@ -309,7 +309,7 @@ public: void Insert (const float * p, int pi); void GetIntersecting (const float * bmin, const float * bmax, - Array & pis) const; + NgArray & pis) const; void DeleteElement (int pi); @@ -351,7 +351,7 @@ class ADTree6 { ADTreeNode6 * root; float cmin[6], cmax[6]; - Array ela; + NgArray ela; public: ADTree6 (const float * acmin, @@ -360,7 +360,7 @@ public: void Insert (const float * p, int pi); void GetIntersecting (const float * bmin, const float * bmax, - Array & pis) const; + NgArray & pis) const; void DeleteElement (int pi); @@ -443,7 +443,7 @@ public: T_ADTreeNode * root; // float cmin[dim], cmax[dim]; Point cmin, cmax; - // Array*> ela; + // NgArray*> ela; ClosedHashTable*> ela; public: T_ADTree (Point acmin, Point acmax); @@ -451,7 +451,7 @@ public: void Insert (Point p, T pi); void GetIntersecting (Point bmin, Point bmax, - Array & pis) const; + NgArray & pis) const; void DeleteElement (T pi); @@ -501,7 +501,7 @@ class ADTree6F { ADTreeNode6F * root; float cmin[6], cmax[6]; - Array ela; + NgArray ela; public: ADTree6F (const float * acmin, @@ -510,7 +510,7 @@ public: void Insert (const float * p, int pi); void GetIntersecting (const float * bmin, const float * bmax, - Array & pis) const; + NgArray & pis) const; void DeleteElement (int pi); @@ -547,7 +547,7 @@ public: void DeleteElement (int pi) { tree->DeleteElement(pi); } DLL_HEADER void GetIntersecting (const Point<3> & pmin, const Point<3> & pmax, - Array & pis) const; + NgArray & pis) const; const ADTree3 & Tree() const { return *tree; }; }; @@ -569,7 +569,7 @@ public: void DeleteElement (T pi) { tree->DeleteElement(pi); } void GetIntersecting (const Point & pmin, const Point & pmax, - Array & pis) const; + NgArray & pis) const; double Tolerance() const { return 1e-7 * Dist(boxpmax, boxpmin); } // single precision const auto & Tree() const { return *tree; }; auto & Tree() { return *tree; }; diff --git a/libsrc/gprim/geom2d.hpp b/libsrc/gprim/geom2d.hpp index 334df09c..b86c74b7 100644 --- a/libsrc/gprim/geom2d.hpp +++ b/libsrc/gprim/geom2d.hpp @@ -613,7 +613,7 @@ namespace netgen class Polygon2d { protected: - Array points; + NgArray points; public: Polygon2d (); diff --git a/libsrc/gprim/geom3d.cpp b/libsrc/gprim/geom3d.cpp index cb1f92c2..bad0657b 100644 --- a/libsrc/gprim/geom3d.cpp +++ b/libsrc/gprim/geom3d.cpp @@ -711,8 +711,8 @@ void referencetransform :: ToPlain (const Point3d & p, Point3d & pp) const pp.Z() = (ez_h * v); } -void referencetransform :: ToPlain (const Array & p, - Array & pp) const +void referencetransform :: ToPlain (const NgArray & p, + NgArray & pp) const { Vec3d v; int i; diff --git a/libsrc/gprim/geom3d.hpp b/libsrc/gprim/geom3d.hpp index 05216d8f..9a01b529 100644 --- a/libsrc/gprim/geom3d.hpp +++ b/libsrc/gprim/geom3d.hpp @@ -735,7 +735,7 @@ namespace netgen /// void ToPlain (const Point3d & p, Point3d & pp) const; /// - void ToPlain (const Array & p, Array & pp) const; + void ToPlain (const NgArray & p, NgArray & pp) const; /// void FromPlain (const Point3d & pp, Point3d & p) const; }; diff --git a/libsrc/gprim/spline.cpp b/libsrc/gprim/spline.cpp index 3f8ccf98..a2778d91 100644 --- a/libsrc/gprim/spline.cpp +++ b/libsrc/gprim/spline.cpp @@ -35,14 +35,14 @@ namespace netgen template <> void CircleSeg<3> :: LineIntersections (const double a, const double b, const double c, - Array < Point<3> > & points, const double eps) const + NgArray < Point<3> > & points, const double eps) const { cerr << "CircleSeg<3>::LineIntersections not implemented" << endl; } template <> void CircleSeg<2> :: LineIntersections (const double a, const double b, const double c, - Array < Point<2> > & points, const double eps) const + NgArray < Point<2> > & points, const double eps) const { points.SetSize(0); @@ -62,7 +62,7 @@ namespace netgen if(discr < 0) return; - Array t; + NgArray t; if(fabs(discr) < 1e-20) t.Append(-0.5*c2/c1); @@ -488,7 +488,7 @@ namespace netgen template void SplineSeg3 :: LineIntersections (const double a, const double b, const double c, - Array < Point > & points, const double eps) const + NgArray < Point > & points, const double eps) const { points.SetSize(0); @@ -535,7 +535,7 @@ namespace netgen template < int D > - void SplineSeg3 :: GetRawData (Array & data) const + void SplineSeg3 :: GetRawData (NgArray & data) const { data.Append(3); for(int i=0; i p0) const { ; } - virtual void GetPoints (int n, Array > & points) const; + virtual void GetPoints (int n, NgArray > & points) const; /** calculates (2D) lineintersections: for lines $$ a x + b y + c = 0 $$ the interecting points are calculated and stored in points */ virtual void LineIntersections (const double a, const double b, const double c, - Array < Point > & points, const double eps) const + NgArray < Point > & points, const double eps) const {points.SetSize(0);} // is the point in the convex hull (increased by eps) of the spline ? @@ -113,7 +113,7 @@ namespace netgen virtual void Project (const Point point, Point & point_on_curve, double & t) const { cerr << "Project not implemented for spline base-class" << endl;} - virtual void GetRawData (Array & data) const + virtual void GetRawData (NgArray & data) const { cerr << "GetRawData not implemented for spline base-class" << endl;} }; @@ -157,7 +157,7 @@ namespace netgen virtual string GetType(void) const {return "line";} virtual void LineIntersections (const double a, const double b, const double c, - Array < Point > & points, const double eps) const; + NgArray < Point > & points, const double eps) const; virtual bool InConvexHull (Point p, double eps) const { @@ -168,7 +168,7 @@ namespace netgen virtual void Project (const Point point, Point & point_on_curve, double & t) const; - virtual void GetRawData (Array & data) const; + virtual void GetRawData (NgArray & data) const; }; @@ -214,7 +214,7 @@ namespace netgen const GeomPoint & TangentPoint (void) const { return p2; } DLL_HEADER virtual void LineIntersections (const double a, const double b, const double c, - Array < Point > & points, const double eps) const; + NgArray < Point > & points, const double eps) const; virtual bool InConvexHull (Point p, double eps) const { @@ -225,7 +225,7 @@ namespace netgen DLL_HEADER virtual void Project (const Point point, Point & point_on_curve, double & t) const; - DLL_HEADER virtual void GetRawData (Array & data) const; + DLL_HEADER virtual void GetRawData (NgArray & data) const; }; @@ -271,7 +271,7 @@ namespace netgen virtual string GetType(void) const {return "circle";} virtual void LineIntersections (const double a, const double b, const double c, - Array < Point > & points, const double eps) const; + NgArray < Point > & points, const double eps) const; virtual bool InConvexHull (Point p, double eps) const { @@ -290,11 +290,11 @@ namespace netgen template class DiscretePointsSeg : public SplineSeg { - Array > pts; + NgArray > pts; GeomPoint p1n, p2n; public: /// - DiscretePointsSeg (const Array > & apts); + DiscretePointsSeg (const NgArray > & apts); // default constructor for archive DiscretePointsSeg() {} virtual void DoArchive(Archive& ar) @@ -346,7 +346,7 @@ namespace netgen template - void SplineSeg :: GetPoints (int n, Array > & points) const + void SplineSeg :: GetPoints (int n, NgArray > & points) const { points.SetSize (n); if (n >= 2) @@ -445,7 +445,7 @@ namespace netgen template void LineSeg :: LineIntersections (const double a, const double b, const double c, - Array < Point > & points, const double eps) const + NgArray < Point > & points, const double eps) const { points.SetSize(0); @@ -478,7 +478,7 @@ namespace netgen template - void LineSeg :: GetRawData (Array & data) const + void LineSeg :: GetRawData (NgArray & data) const { data.Append(2); for(int i=0; i - DiscretePointsSeg :: DiscretePointsSeg (const Array > & apts) + DiscretePointsSeg :: DiscretePointsSeg (const NgArray > & apts) : pts (apts) { for(int i=0; i class BSplineSeg : public SplineSeg { - Array > pts; + NgArray > pts; GeomPoint p1n, p2n; - Array ti; + NgArray ti; public: /// - BSplineSeg (const Array > & apts); + BSplineSeg (const NgArray > & apts); /// //default constructor for archive BSplineSeg() {} @@ -680,7 +680,7 @@ namespace netgen // Constructor template - BSplineSeg :: BSplineSeg (const Array > & apts) + BSplineSeg :: BSplineSeg (const NgArray > & apts) : pts (apts) { /* diff --git a/libsrc/gprim/splinegeometry.cpp b/libsrc/gprim/splinegeometry.cpp index 213f5224..c7002e95 100644 --- a/libsrc/gprim/splinegeometry.cpp +++ b/libsrc/gprim/splinegeometry.cpp @@ -23,7 +23,7 @@ namespace netgen template - void SplineGeometry :: GetRawData (Array & raw_data) const + void SplineGeometry :: GetRawData (NgArray & raw_data) const { raw_data.Append(D); // raw_data.Append(elto0); @@ -36,7 +36,7 @@ namespace netgen template - int SplineGeometry :: Load (const Array & raw_data, const int startpos) + int SplineGeometry :: Load (const NgArray & raw_data, const int startpos) { int pos = startpos; if(raw_data[pos] != D) @@ -49,7 +49,7 @@ namespace netgen splines.SetSize(int(raw_data[pos])); pos++; - Array< Point > pts(3); + NgArray< Point > pts(3); for(int i=0; i > points; + NgArray > points; for (int i = 0; i < splines.Size(); i++) { splines[i]->GetPoints (20, points); diff --git a/libsrc/gprim/splinegeometry.hpp b/libsrc/gprim/splinegeometry.hpp index 14a28b4b..7701afaa 100644 --- a/libsrc/gprim/splinegeometry.hpp +++ b/libsrc/gprim/splinegeometry.hpp @@ -26,23 +26,23 @@ namespace netgen { // protected: public: - Array < GeomPoint > geompoints; - Array < SplineSeg* > splines; + NgArray < GeomPoint > geompoints; + NgArray < SplineSeg* > splines; SplineGeometry() : geompoints{}, splines{} { ; } DLL_HEADER ~SplineGeometry(); - DLL_HEADER int Load (const Array & raw_data, const int startpos = 0); + DLL_HEADER int Load (const NgArray & raw_data, const int startpos = 0); virtual void DoArchive(Archive& ar) { ar & geompoints & splines; } - DLL_HEADER void GetRawData (Array & raw_data) const; + DLL_HEADER void GetRawData (NgArray & raw_data) const; - const Array*> & GetSplines () const + const NgArray*> & GetSplines () const { return splines; } int GetNSplines (void) const { return splines.Size(); } diff --git a/libsrc/include/nginterface_v2_impl.hpp b/libsrc/include/nginterface_v2_impl.hpp index 5b1efd6d..382c4408 100644 --- a/libsrc/include/nginterface_v2_impl.hpp +++ b/libsrc/include/nginterface_v2_impl.hpp @@ -306,7 +306,7 @@ template <> NGX_INLINE DLL_HEADER const Ng_Node<2> Ngx_Mesh :: GetNode<2> (int n NGX_INLINE DLL_HEADER Ng_Buffer Ngx_Mesh :: GetPeriodicVertices(int idnr) const { - Array apairs; + NgArray apairs; mesh->GetIdentifications().GetPairs (idnr+1, apairs); for(auto& ind : apairs) { diff --git a/libsrc/interface/nginterface.cpp b/libsrc/interface/nginterface.cpp index c143e5ef..7353e8c7 100644 --- a/libsrc/interface/nginterface.cpp +++ b/libsrc/interface/nginterface.cpp @@ -58,8 +58,8 @@ namespace netgen #ifdef SOCKETS extern AutoPtr clientsocket; - //extern Array< AutoPtr < ServerInfo > > servers; - extern Array< ServerInfo* > servers; + //extern NgArray< AutoPtr < ServerInfo > > servers; + extern NgArray< ServerInfo* > servers; #endif @@ -141,7 +141,7 @@ void Ng_LoadMesh (const char * filename, ngcore::NgMPI_Comm comm) } istream * infile; - Array buf; // for distributing geometry! + NgArray buf; // for distributing geometry! int strs; if( id == 0) { @@ -191,9 +191,9 @@ void Ng_LoadMesh (const char * filename, ngcore::NgMPI_Comm comm) bool endfile = false; int n, dummy; - Array segment_weights; - Array surface_weights; - Array volume_weights; + NgArray segment_weights; + NgArray surface_weights; + NgArray volume_weights; while (weightsfile.good() && !endfile) { @@ -479,14 +479,14 @@ const char * Ng_GetDomainMaterial (int dom) int Ng_GetUserDataSize (char * id) { - Array da; + NgArray da; mesh->GetUserData (id, da); return da.Size(); } void Ng_GetUserData (char * id, double * data) { - Array da; + NgArray da; mesh->GetUserData (id, da); for (int i = 0; i < da.Size(); i++) data[i] = da[i]; @@ -640,12 +640,12 @@ int Ng_FindElementOfPoint (double * p, double * lami, int build_searchtree, const int * const indices, const int numind) { - Array * dummy(NULL); + NgArray * dummy(NULL); int ind = -1; if(indices != NULL) { - dummy = new Array(numind); + dummy = new NgArray(numind); for(int i=0; i * dummy(NULL); + NgArray * dummy(NULL); int ind = -1; if(indices != NULL) { - dummy = new Array(numind); + dummy = new NgArray(numind); for(int i=0; iGetTopology(); - Array ia; + NgArray ia; topology.GetSurfaceElementEdges (elnr, ia); ned = ia.Size(); for (i = 1; i <= ned; i++) @@ -1800,7 +1800,7 @@ int Ng_GetClusterRepElement (int pi) int Ng_GetNPeriodicVertices (int idnr) { - Array apairs; + NgArray apairs; mesh->GetIdentifications().GetPairs (idnr, apairs); return apairs.Size(); } @@ -1809,7 +1809,7 @@ int Ng_GetNPeriodicVertices (int idnr) // pairs should be an integer array of 2*npairs void Ng_GetPeriodicVertices (int idnr, int * pairs) { - Array apairs; + NgArray apairs; mesh->GetIdentifications().GetPairs (idnr, apairs); for (int i = 0; i < apairs.Size(); i++) { @@ -1823,7 +1823,7 @@ void Ng_GetPeriodicVertices (int idnr, int * pairs) int Ng_GetNPeriodicEdges (int idnr) { - Array map; + NgArray map; //const MeshTopology & top = mesh->GetTopology(); int nse = mesh->GetNSeg(); @@ -1850,7 +1850,7 @@ int Ng_GetNPeriodicEdges (int idnr) void Ng_GetPeriodicEdges (int idnr, int * pairs) { - Array map; + NgArray map; const MeshTopology & top = mesh->GetTopology(); int nse = mesh->GetNSeg(); @@ -2157,9 +2157,9 @@ int Ng_Bisect_WithInfo ( const char * refinementfile, double ** qualityloss, int mesh->LocalHFunction().SetGrading (mparam.grading); - Array * qualityloss_arr = NULL; + NgArray * qualityloss_arr = NULL; if(qualityloss != NULL) - qualityloss_arr = new Array; + qualityloss_arr = new NgArray; ref -> Bisect (*mesh, biopt, qualityloss_arr); diff --git a/libsrc/interface/nginterface_v2.cpp b/libsrc/interface/nginterface_v2.cpp index 072bf8f0..c9db3b10 100644 --- a/libsrc/interface/nginterface_v2.cpp +++ b/libsrc/interface/nginterface_v2.cpp @@ -1070,7 +1070,7 @@ namespace netgen int * const indices, int numind) const { - Array dummy(numind); + NgArray dummy(numind); for (int i = 0; i < numind; i++) dummy[i] = indices[i]+1; double lam3[3]; @@ -1111,7 +1111,7 @@ namespace netgen int * const indices, int numind) const { - Array dummy(numind); + NgArray dummy(numind); for (int i = 0; i < numind; i++) dummy[i] = indices[i]+1; Point<3> p3d(p[0], p[1], p[2]); diff --git a/libsrc/interface/read_fnf_mesh.cpp b/libsrc/interface/read_fnf_mesh.cpp index 5620dadc..955a1356 100644 --- a/libsrc/interface/read_fnf_mesh.cpp +++ b/libsrc/interface/read_fnf_mesh.cpp @@ -53,7 +53,7 @@ namespace netgen string name; string placement; string valuetype; - Array places; + NgArray places; }; @@ -188,7 +188,7 @@ namespace netgen else if (token == "MATERIALS") { *testout << "parse materials" << endl; - Array young_modulus, poisson_ratio, mass_density; + NgArray young_modulus, poisson_ratio, mass_density; while (1) { @@ -264,7 +264,7 @@ namespace netgen string propid; sbuf >> elnr >> def >> ch; sbuf >> typid >> matid >> propid; - Array pnums; + NgArray pnums; while (1) { int pn; @@ -305,7 +305,7 @@ namespace netgen sbuf >> nr >> kw >> ch; if (kw == "NODES") { - Array enums; + NgArray enums; while (1) { int en; @@ -329,7 +329,7 @@ namespace netgen sbuf >> nr >> kw >> ch; if (kw == "FACES") { - Array fnums; + NgArray fnums; while (1) { int fn; @@ -375,7 +375,7 @@ namespace netgen else if (token == "LOADS") { - Array loadtypes; + NgArray loadtypes; while (1) { diff --git a/libsrc/interface/readtetmesh.cpp b/libsrc/interface/readtetmesh.cpp index db18f2ed..e061c722 100644 --- a/libsrc/interface/readtetmesh.cpp +++ b/libsrc/interface/readtetmesh.cpp @@ -49,17 +49,17 @@ namespace netgen Point3d p; int numObj3D,numObj2D,numObj1D,numObj0D; // bool nullstarted; - Array eldom; + NgArray eldom; int minId3D = -1, minId2D = -1; int maxId3D(-1), maxId2D(-1), maxId1D(-1), maxId0D(-1); - Array *> segmentdata; - Array tris; + NgArray *> segmentdata; + NgArray tris; - Array userdata_int; // just save data for 1:1 output - Array userdata_double; - Array point_pids; - Array tetfacedata; - Array uid_to_group_3D, uid_to_group_2D, uid_to_group_1D, uid_to_group_0D; + NgArray userdata_int; // just save data for 1:1 output + NgArray userdata_double; + NgArray point_pids; + NgArray tetfacedata; + NgArray uid_to_group_3D, uid_to_group_2D, uid_to_group_1D, uid_to_group_0D; while(!done) { @@ -226,7 +226,7 @@ namespace netgen segmentdata.SetSize(nedges); for(int i=0; i(7); + segmentdata[i] = new NgArray(7); *segmentdata[i] = -1; in >> dummyint; in >> (*segmentdata[i])[0] >> (*segmentdata[i])[1]; @@ -350,8 +350,8 @@ namespace netgen for(int i=0; i nodes1(3),nodes2(3); - Array sortval1(3),sortval2(3); + NgArray nodes1(3),nodes2(3); + NgArray sortval1(3),sortval2(3); in >> tri1 >> tri2 >> transl; if(transl > maxtransl) @@ -455,7 +455,7 @@ namespace netgen cout << endl; - // Array indextodescriptor(maxId2D+1); + // NgArray indextodescriptor(maxId2D+1); // for(int i=1; i<=mesh.GetNFD(); i++) // indextodescriptor[mesh.GetFaceDescriptor(i).SurfNr()] = i; @@ -538,7 +538,7 @@ namespace netgen case 27: // Object2D GroupID, #Faces FaceID List { - Array ports; + NgArray ports; //int totnum = 0; uid_to_group_2D.SetSize(maxId2D+1); uid_to_group_2D = -1; @@ -665,7 +665,7 @@ namespace netgen mesh.SetUserData("TETmesh:uid_to_group_0D",uid_to_group_0D); - Array surfindices(tris.Size()); + NgArray surfindices(tris.Size()); surfindices = -1; for(int i=0; i indextodescriptor(maxId2D+1); + // NgArray indextodescriptor(maxId2D+1); // for(int i=1; i<=mesh.GetNFD(); i++) // indextodescriptor[mesh.GetFaceDescriptor(i).SurfNr()] = i; diff --git a/libsrc/interface/readuser.cpp b/libsrc/interface/readuser.cpp index f5edcc91..8321a962 100644 --- a/libsrc/interface/readuser.cpp +++ b/libsrc/interface/readuser.cpp @@ -99,7 +99,7 @@ namespace netgen // map from unv element nr to our element number + an index if it is vol (0), bnd(1), ... std::map> element_map; - Array tmp_segments; + NgArray tmp_segments; while (in.good()) { in >> reco; @@ -449,7 +449,7 @@ namespace netgen int bcprop; ifstream inpkt (pktfile.c_str()); inpkt >> np; - Array values(np); + NgArray values(np); for (i = 1; i <= np; i++) { Point3d p(0,0,0); diff --git a/libsrc/interface/writeOpenFOAM15x.cpp b/libsrc/interface/writeOpenFOAM15x.cpp index 574fc2ec..b824039b 100644 --- a/libsrc/interface/writeOpenFOAM15x.cpp +++ b/libsrc/interface/writeOpenFOAM15x.cpp @@ -39,11 +39,11 @@ namespace netgen // Global arrays used to maintain the owner, neighbour and face lists // so that they are accessible across functions - static Array owner_facelist; - static Array owner_celllist; - static Array neighbour_celllist; - static Array surfelem_bclist; - static Array surfelem_lists; + static NgArray owner_facelist; + static NgArray owner_celllist; + static NgArray neighbour_celllist; + static NgArray surfelem_bclist; + static NgArray surfelem_lists; @@ -118,17 +118,17 @@ namespace netgen // Initialise arrays to zero if required neighbour_celllist = 0; - // Array used to keep track of Faces which have already been + // NgArray used to keep track of Faces which have already been // processed and added to the Owner list... In addition, also the // location where the face appears in the Owner list is also stored // to speed up creation of the Neighbour list - Array ownerfaces(totfaces); + NgArray ownerfaces(totfaces); ownerfaces = 0; - // Array to hold the set of local faces of each volume element + // NgArray to hold the set of local faces of each volume element // while running through the set of volume elements // NOTE: The size is set automatically by the Netgen topology function - Array locfaces; + NgArray locfaces; // Secondary indices used to independently advance the owner // and boundary condition arrays within the main loop @@ -383,9 +383,9 @@ namespace netgen *outfile << "(\n"; - // Array to hold the indices of the points of each face to + // NgArray to hold the indices of the points of each face to // flip if required - Array facepnts; + NgArray facepnts; // Write the faces in the order specified in the owners lists of the // internal cells and the boundary cells @@ -545,7 +545,7 @@ namespace netgen *outfile << "\n"; - Array bcarray; + NgArray bcarray; int ind = 1; // Since the boundary conditions are already sorted in ascending diff --git a/libsrc/interface/writeabaqus.cpp b/libsrc/interface/writeabaqus.cpp index 6f2f165c..04c84ff0 100644 --- a/libsrc/interface/writeabaqus.cpp +++ b/libsrc/interface/writeabaqus.cpp @@ -139,7 +139,7 @@ void WriteAbaqusFormat (const Mesh & mesh, int masternode(0); - Array pairs; + NgArray pairs; BitArray master(np), help(np); master.Set(); for (i = 1; i <= 3; i++) @@ -158,7 +158,7 @@ void WriteAbaqusFormat (const Mesh & mesh, cout << "masternode = " << masternode << " = " << mesh.Point(masternode) << endl; - Array slaves(3); + NgArray slaves(3); for (i = 1; i <= 3; i++) { mesh.GetIdentifications().GetPairs (i, pairs); diff --git a/libsrc/interface/writediffpack.cpp b/libsrc/interface/writediffpack.cpp index edf9f70f..b1c30fba 100644 --- a/libsrc/interface/writediffpack.cpp +++ b/libsrc/interface/writediffpack.cpp @@ -39,8 +39,8 @@ void WriteDiffPackFormat (const Mesh & mesh, int np = mesh.GetNP(); int ne = mesh.GetNE(); int nse = mesh.GetNSE(); - Array BIname; - Array BCsinpoint; + NgArray BIname; + NgArray BCsinpoint; int i, j, k, l; @@ -203,8 +203,8 @@ void WriteDiffPackFormat (const Mesh & mesh, int np = mesh.GetNP(); //int ne = mesh.GetNE(); int nse = mesh.GetNSE(); - Array BIname; - Array BCsinpoint; + NgArray BIname; + NgArray BCsinpoint; int i, j, k, l; diff --git a/libsrc/interface/writefluent.cpp b/libsrc/interface/writefluent.cpp index 792203d6..1fb07cdb 100644 --- a/libsrc/interface/writefluent.cpp +++ b/libsrc/interface/writefluent.cpp @@ -65,9 +65,9 @@ void WriteFluentFormat (const Mesh & mesh, Element2d face, face2; int i2, j2; - Array surfaceelp; - Array surfaceeli; - Array locels; + NgArray surfaceelp; + NgArray surfaceeli; + NgArray locels; //no cells=no tets //no faces=2*tets diff --git a/libsrc/interface/writejcm.cpp b/libsrc/interface/writejcm.cpp index 59b64101..f418cd64 100644 --- a/libsrc/interface/writejcm.cpp +++ b/libsrc/interface/writejcm.cpp @@ -33,7 +33,7 @@ void WriteJCMFormat (const Mesh & mesh, int np = mesh.GetNP(); // Identic points - Array identmap1, identmap2, identmap3; + NgArray identmap1, identmap2, identmap3; mesh.GetIdentifications().GetMap(1, identmap1); mesh.GetIdentifications().GetMap(2, identmap2); mesh.GetIdentifications().GetMap(3, identmap3); @@ -95,7 +95,7 @@ void WriteJCMFormat (const Mesh & mesh, int nbquad = 0; // array with 1 if point on any tetra, 0 else // this is needed in order to arrange the prism points in the right order - Array pointsOnTetras; + NgArray pointsOnTetras; pointsOnTetras.SetSize (mesh.GetNP()); pointsOnTetras = 0; for (i = 1; i <= ne; i++) diff --git a/libsrc/interface/writetecplot.cpp b/libsrc/interface/writetecplot.cpp index 4730b983..323f8c46 100644 --- a/libsrc/interface/writetecplot.cpp +++ b/libsrc/interface/writetecplot.cpp @@ -27,7 +27,7 @@ void WriteTecPlotFormat (const Mesh & mesh, INDEX ne = mesh.GetNE(); INDEX nse = mesh.GetNSE(); - Array sn(np); + NgArray sn(np); ofstream outfile(filename.c_str()); outfile << "TITLE=\" " << filename << "\"" << endl; diff --git a/libsrc/interface/writetet.cpp b/libsrc/interface/writetet.cpp index bcab41c2..69447a1a 100644 --- a/libsrc/interface/writetet.cpp +++ b/libsrc/interface/writetet.cpp @@ -23,16 +23,16 @@ namespace netgen cout << "starting .tet export to file " << filename << endl; - Array point_ids,edge_ids,face_ids; - Array elnum(mesh.GetNE()); + NgArray point_ids,edge_ids,face_ids; + NgArray elnum(mesh.GetNE()); elnum = -1; - Array userdata_int; - Array userdata_double; - Array ports; + NgArray userdata_int; + NgArray userdata_double; + NgArray ports; - Array uid_to_group_3D, uid_to_group_2D, uid_to_group_1D, uid_to_group_0D; + NgArray uid_to_group_3D, uid_to_group_2D, uid_to_group_1D, uid_to_group_0D; int pos_int = 0; int pos_double = 0; @@ -98,9 +98,9 @@ namespace netgen INDEX_2_CLOSED_HASHTABLE edgenumbers(6*mesh.GetNE()+3*mesh.GetNSE());; INDEX_3_CLOSED_HASHTABLE facenumbers(4*mesh.GetNE()+mesh.GetNSE()); - Array edge2node; - Array face2edge; - Array element2face; + NgArray edge2node; + NgArray face2edge; + NgArray element2face; int numelems(0),numfaces(0),numedges(0),numnodes(0); @@ -285,7 +285,7 @@ namespace netgen int numObj0D,numObj1D,numObj2D,numObj3D; int numports = ports.Size(); - Array nodenum(point_ids.Size()+1); + NgArray nodenum(point_ids.Size()+1); nodenum = -1; @@ -367,18 +367,18 @@ namespace netgen uidpid = "UID"; - Array< Array* > idmaps; + NgArray< NgArray* > idmaps; for(int i=1; i<=mesh.GetIdentifications().GetMaxNr(); i++) { if(mesh.GetIdentifications().GetType(i) == Identifications::PERIODIC) { - idmaps.Append(new Array); + idmaps.Append(new NgArray); mesh.GetIdentifications().GetMap(i,*idmaps.Last(),true); } } - Array id_num,id_type; - Array< Array *> id_groups; + NgArray id_num,id_type; + NgArray< NgArray *> id_groups; // sst 2008-03-12: Write problem class... @@ -449,7 +449,7 @@ namespace netgen if(nodenum[i] == -1) continue; - Array group; + NgArray group; group.Append(i); for(int j=0; j 1) { - id_groups.Append(new Array(group)); + id_groups.Append(new NgArray(group)); if(group.Size() == 2) { id_type[i] = 1; @@ -590,18 +590,18 @@ namespace netgen - Array< Array* > vertex_to_edge(mesh.GetNP()+1); + NgArray< NgArray* > vertex_to_edge(mesh.GetNP()+1); for(int i=0; i<=mesh.GetNP(); i++) - vertex_to_edge[i] = new Array; + vertex_to_edge[i] = new NgArray; - Array< Array* > idmaps_edge(idmaps.Size()); + NgArray< NgArray* > idmaps_edge(idmaps.Size()); for(int i=0; i(numedges); + idmaps_edge[i] = new NgArray(numedges); (*idmaps_edge[i]) = 0; } - Array possible; + NgArray possible; for(int i=0; i group; + NgArray group; group.Append(i); for(int j=0; j 1) { id_num[i] = 1; - id_groups.Append(new Array(group)); + id_groups.Append(new NgArray(group)); if(group.Size() == 2) { id_type[i] = 1; @@ -701,7 +701,7 @@ namespace netgen continue; - Array group; + NgArray group; group.Append(i); for(int j=0; j 1) { id_num[i] = 1; - id_groups.Append(new Array(group)); + id_groups.Append(new NgArray(group)); if(group.Size() == 2) { id_type[i] = 1; @@ -805,9 +805,9 @@ namespace netgen - Array< Array* > edge_to_face(numedges+1); + NgArray< NgArray* > edge_to_face(numedges+1); for(int i=0; i; + edge_to_face[i] = new NgArray; for(int i=0; i group; + NgArray group; group.Append(i); for(int j=0; j 1) { id_num[i] = -1; - id_groups.Append(new Array(group)); + id_groups.Append(new NgArray(group)); if(group.Size() == 2) n2++; else @@ -981,7 +981,7 @@ namespace netgen << endl; - Array< Array * > groups; + NgArray< NgArray * > groups; int maxg = -1; for(int i = 0; i; + groups[i] = new NgArray; for(ElementIndex i=0; i= 0) diff --git a/libsrc/interface/writeuser.cpp b/libsrc/interface/writeuser.cpp index 99a88dde..5ad3c674 100644 --- a/libsrc/interface/writeuser.cpp +++ b/libsrc/interface/writeuser.cpp @@ -18,8 +18,8 @@ namespace netgen extern MeshingParameters mparam; - void RegisterUserFormats (Array & names, - Array & extensions) + void RegisterUserFormats (NgArray & names, + NgArray & extensions) { const char *types[] = @@ -392,7 +392,7 @@ void WriteSTLExtFormat (const Mesh & mesh, int numBCs = 0; - Array faceBCs; + NgArray faceBCs; TABLE faceBCMapping; faceBCs.SetSize(mesh.GetNFD()); @@ -427,7 +427,7 @@ void WriteSTLExtFormat (const Mesh & mesh, for(int faceNr = 1;faceNr <= faceBCMapping.EntrySize(bcInd); faceNr++) { - Array faceSei; + NgArray faceSei; mesh.GetSurfaceElementsOfFace(faceBCMapping.Get(bcInd,faceNr),faceSei); for (int i = 0; i < faceSei.Size(); i++) @@ -778,7 +778,7 @@ void WriteEdgeElementFormat (const Mesh & mesh, int inverttets = mparam.inverttets; int invertsurf = mparam.inverttrigs; - Array edges; + NgArray edges; ofstream outfile (filename.c_str()); @@ -935,7 +935,7 @@ void WriteFile (int typ, INDEX_2_HASHTABLE edgeht(mesh.GetNP()); // list of edges - Array edgelist; + NgArray edgelist; // edge (point) on boundary ? BitArray bedge, bpoint(mesh.GetNP()); diff --git a/libsrc/interface/writeuser.hpp b/libsrc/interface/writeuser.hpp index 5ceda0ba..3e98c433 100644 --- a/libsrc/interface/writeuser.hpp +++ b/libsrc/interface/writeuser.hpp @@ -154,8 +154,8 @@ void WriteDolfinFormat (const Mesh & mesh, const string & filename); -extern void DLL_HEADER RegisterUserFormats (Array & names, - Array & extensions); +extern void DLL_HEADER RegisterUserFormats (NgArray & names, + NgArray & extensions); extern bool DLL_HEADER WriteUserFormat (const string & format, diff --git a/libsrc/interface/wuchemnitz.cpp b/libsrc/interface/wuchemnitz.cpp index 46872fb0..872dcc76 100644 --- a/libsrc/interface/wuchemnitz.cpp +++ b/libsrc/interface/wuchemnitz.cpp @@ -54,12 +54,12 @@ namespace netgen int p1, p2; }; - static Array points; - static Array volelements; - static Array surfelements; + static NgArray points; + static NgArray volelements; + static NgArray surfelements; - static Array faces; - static Array edges; + static NgArray faces; + static NgArray edges; void ReadFile (char * filename) diff --git a/libsrc/linalg/densemat.cpp b/libsrc/linalg/densemat.cpp index f8d58c2a..ef896616 100644 --- a/libsrc/linalg/densemat.cpp +++ b/libsrc/linalg/densemat.cpp @@ -427,7 +427,7 @@ namespace netgen double max, hr; - Array p(n); // pivot-permutation + NgArray p(n); // pivot-permutation Vector hv(n); @@ -1154,7 +1154,7 @@ namespace netgen } - void DenseMatrix :: MultElementMatrix (const Array & pnum, + void DenseMatrix :: MultElementMatrix (const NgArray & pnum, const Vector & hx, Vector & hy) { int i, j; @@ -1180,7 +1180,7 @@ namespace netgen } - void DenseMatrix :: MultTransElementMatrix (const Array & pnum, + void DenseMatrix :: MultTransElementMatrix (const NgArray & pnum, const Vector & hx, Vector & hy) { int i, j; diff --git a/libsrc/meshing/adfront2.cpp b/libsrc/meshing/adfront2.cpp index 11dd7421..0eb86f11 100644 --- a/libsrc/meshing/adfront2.cpp +++ b/libsrc/meshing/adfront2.cpp @@ -62,7 +62,7 @@ namespace netgen } /* - void AdFront2 :: GetPoints (Array > & apoints) const + void AdFront2 :: GetPoints (NgArray > & apoints) const { apoints.Append (points); // for (int i = 0; i < points.Size(); i++) @@ -270,11 +270,11 @@ namespace netgen int AdFront2 :: GetLocals (int baselineindex, - Array & locpoints, - Array & pgeominfo, - Array & loclines, // local index - Array & pindex, - Array & lindex, + NgArray & locpoints, + NgArray & pgeominfo, + NgArray & loclines, // local index + NgArray & pindex, + NgArray & lindex, double xh) { static int timer = NgProfiler::CreateTimer ("adfront2::GetLocals"); @@ -312,7 +312,7 @@ namespace netgen } } - // static Array invpindex; + // static NgArray invpindex; invpindex.SetSize (points.Size()); // invpindex = -1; for (int i = 0; i < nearpoints.Size(); i++) @@ -498,7 +498,7 @@ namespace netgen } bool AdFront2 :: SameSide (const Point<2> & lp1, const Point<2> & lp2, - const Array * testfaces) const + const NgArray * testfaces) const { int cnt = 0; diff --git a/libsrc/meshing/adfront2.hpp b/libsrc/meshing/adfront2.hpp index 11d9593b..dd5bf128 100644 --- a/libsrc/meshing/adfront2.hpp +++ b/libsrc/meshing/adfront2.hpp @@ -165,21 +165,21 @@ class AdFront2 { /// - Array points; /// front points - Array lines; /// front lines + NgArray points; /// front points + NgArray lines; /// front lines Box3d boundingbox; BoxTree<3> linesearchtree; /// search tree for lines Point3dTree pointsearchtree; /// search tree for points Point3dTree cpointsearchtree; /// search tree for cone points (not used ???) - Array delpointl; /// list of deleted front points - Array dellinel; /// list of deleted front lines + NgArray delpointl; /// list of deleted front points + NgArray dellinel; /// list of deleted front lines int nfl; /// number of front lines; INDEX_2_HASHTABLE * allflines; /// all front lines ever have been - Array invpindex; + NgArray invpindex; int minval; int starti; @@ -192,7 +192,7 @@ public: ~AdFront2 (); /// - // void GetPoints (Array > & apoints) const; + // void GetPoints (NgArray > & apoints) const; /// void Print (ostream & ost) const; @@ -216,11 +216,11 @@ public: /// int GetLocals (int baseline, - Array & locpoints, - Array & pgeominfo, - Array & loclines, // local index - Array & pindex, - Array & lindex, + NgArray & locpoints, + NgArray & pgeominfo, + NgArray & loclines, // local index + NgArray & pindex, + NgArray & lindex, double xh); /// @@ -262,7 +262,7 @@ public: bool Inside (const Point<2> & p) const; bool SameSide (const Point<2> & lp1, const Point<2> & lp2, - const Array * /* testfaces */ = NULL) const; + const NgArray * /* testfaces */ = NULL) const; /* { return Inside (lp1) == Inside (lp2); diff --git a/libsrc/meshing/adfront3.cpp b/libsrc/meshing/adfront3.cpp index d809eb18..8a3021f4 100644 --- a/libsrc/meshing/adfront3.cpp +++ b/libsrc/meshing/adfront3.cpp @@ -84,7 +84,7 @@ AdFront3 :: ~AdFront3 () delete connectedpairs; } -void AdFront3 :: GetPoints (Array > & apoints) const +void AdFront3 :: GetPoints (NgArray > & apoints) const { for (PointIndex pi = points.Begin(); pi < points.End(); pi++) @@ -267,7 +267,7 @@ void AdFront3 :: CreateTrees () void AdFront3 :: GetIntersectingFaces (const Point<3> & pmin, const Point<3> & pmax, - Array & ifaces) const + NgArray & ifaces) const { facetree -> GetIntersecting (pmin, pmax, ifaces); } @@ -357,7 +357,7 @@ void AdFront3 :: RebuildInternalTables () if (usecl.Test(i)) cntcl++; - Array clvol (np); + NgArray clvol (np); clvol = 0.0; for (int i = 1; i <= faces.Size(); i++) @@ -485,10 +485,10 @@ int AdFront3 :: SelectBaseElement () int AdFront3 :: GetLocals (int fstind, - Array & locpoints, - Array & locfaces, // local index - Array & pindex, - Array & findex, + NgArray & locpoints, + NgArray & locfaces, // local index + NgArray & pindex, + NgArray & findex, INDEX_2_HASHTABLE & getconnectedpairs, float xh, float relh, @@ -509,11 +509,11 @@ int AdFront3 :: GetLocals (int fstind, PointIndex pstind; Point3d midp, p0; - // static Array invpindex; + // static NgArray invpindex; - Array locfaces2; //all local faces in radius xh - Array locfaces3; // all faces in outer radius relh - Array findex2; + NgArray locfaces2; //all local faces in radius xh + NgArray locfaces3; // all faces in outer radius relh + NgArray findex2; locfaces2.SetSize(0); locfaces3.SetSize(0); @@ -657,12 +657,12 @@ int AdFront3 :: GetLocals (int fstind, // returns all points connected with fi void AdFront3 :: GetGroup (int fi, - Array & grouppoints, - Array & groupelements, - Array & pindex, - Array & findex) + NgArray & grouppoints, + NgArray & groupelements, + NgArray & pindex, + NgArray & findex) { - // static Array pingroup; + // static NgArray pingroup; int changed; pingroup.SetSize(points.Size()); @@ -833,7 +833,7 @@ bool AdFront3 :: Inside (const Point<3> & p) const int AdFront3 :: SameSide (const Point<3> & lp1, const Point<3> & lp2, - const Array * testfaces) const + const NgArray * testfaces) const { const Point<3> *line[2]; line[0] = &lp1; diff --git a/libsrc/meshing/adfront3.hpp b/libsrc/meshing/adfront3.hpp index 9b7f3818..c7c8dfb5 100644 --- a/libsrc/meshing/adfront3.hpp +++ b/libsrc/meshing/adfront3.hpp @@ -176,11 +176,11 @@ public: class AdFront3 { /// - Array points; + NgArray points; /// - Array faces; + NgArray faces; /// - Array delpointl; + NgArray delpointl; /// which points are connected to pi ? TABLE * connectedpairs; @@ -208,8 +208,8 @@ class AdFront3 int lasti; /// minimal selection-value of baseelements int minval; - Array invpindex; - Array pingroup; + NgArray invpindex; + NgArray pingroup; /// class BoxTree<3> * facetree; @@ -220,7 +220,7 @@ public: /// ~AdFront3 (); /// - void GetPoints (Array > & apoints) const; + void GetPoints (NgArray > & apoints) const; /// int GetNP() const { return points.Size(); } @@ -254,17 +254,17 @@ public: /// void GetIntersectingFaces (const Point<3> & pmin, const Point<3> & pmax, - Array & ifaces) const; + NgArray & ifaces) const; /// void GetFaceBoundingBox (int i, Box3d & box) const; /// int GetLocals (int baseelement, - Array & locpoints, - Array & locfaces, // local index - Array & pindex, - Array & findex, + NgArray & locpoints, + NgArray & locfaces, // local index + NgArray & pindex, + NgArray & findex, INDEX_2_HASHTABLE & connectedpairs, float xh, float relh, @@ -272,10 +272,10 @@ public: /// void GetGroup (int fi, - Array & grouppoints, - Array & groupelements, - Array & pindex, - Array & findex); + NgArray & grouppoints, + NgArray & groupelements, + NgArray & pindex, + NgArray & findex); /// void DeleteFace (INDEX fi); @@ -300,7 +300,7 @@ public: bool Inside (const Point<3> & p) const; /// both points on same side ? int SameSide (const Point<3> & lp1, const Point<3> & lp2, - const Array * testfaces = NULL) const; + const NgArray * testfaces = NULL) const; /// diff --git a/libsrc/meshing/basegeom.cpp b/libsrc/meshing/basegeom.cpp index e9b9aa5e..6df0cf6e 100644 --- a/libsrc/meshing/basegeom.cpp +++ b/libsrc/meshing/basegeom.cpp @@ -5,7 +5,7 @@ namespace netgen { DLL_HEADER GeometryRegisterArray geometryregister; - //DLL_HEADER Array geometryregister; + //DLL_HEADER NgArray geometryregister; GeometryRegister :: ~GeometryRegister() { ; } diff --git a/libsrc/meshing/basegeom.hpp b/libsrc/meshing/basegeom.hpp index ceb703f2..f6e63046 100644 --- a/libsrc/meshing/basegeom.hpp +++ b/libsrc/meshing/basegeom.hpp @@ -44,7 +44,7 @@ namespace netgen virtual void SetParameters (Tcl_Interp * /* interp */) { ; } }; - class DLL_HEADER GeometryRegisterArray : public Array + class DLL_HEADER GeometryRegisterArray : public NgArray { public: virtual ~GeometryRegisterArray() @@ -56,7 +56,7 @@ namespace netgen virtual shared_ptr LoadFromMeshFile (istream & ist) const; }; - // extern DLL_HEADER Array geometryregister; + // extern DLL_HEADER NgArray geometryregister; extern DLL_HEADER GeometryRegisterArray geometryregister; } diff --git a/libsrc/meshing/bcfunctions.cpp b/libsrc/meshing/bcfunctions.cpp index 46317661..1bede57c 100644 --- a/libsrc/meshing/bcfunctions.cpp +++ b/libsrc/meshing/bcfunctions.cpp @@ -51,7 +51,7 @@ namespace netgen Function to create a list of all the unique colours available in a given mesh */ - void GetFaceColours(Mesh & mesh, Array & face_colours) + void GetFaceColours(Mesh & mesh, NgArray & face_colours) { face_colours.SetSize(1); face_colours.Elem(1) = mesh.GetFaceDescriptor(1).SurfColour(); @@ -143,9 +143,9 @@ namespace netgen // Arrays to hold the specified RGB colour triplets as well // as the associated boundary condition number - Array bc_colours(numentries); - Array bc_num(numentries); - Array bc_used(numentries); + NgArray bc_colours(numentries); + NgArray bc_num(numentries); + NgArray bc_used(numentries); // Actually read in the data from the file for(int i = 1; i <= numentries; i++) @@ -198,7 +198,7 @@ namespace netgen PrintMessage(3, "Highest boundary number in list = ",max_bcnum); - Array all_colours; + NgArray all_colours; // Extract all the colours to see how many there are GetFaceColours(mesh,all_colours); @@ -290,9 +290,9 @@ namespace netgen */ void AutoColourAlg_Sorted(Mesh & mesh) { - Array all_colours; - Array faces_sorted; - Array colours_sorted; + NgArray all_colours; + NgArray faces_sorted; + NgArray colours_sorted; // Extract all the colours to see how many there are GetFaceColours(mesh,all_colours); @@ -322,7 +322,7 @@ namespace netgen colours_sorted.SetSize(all_colours.Size()+1); faces_sorted = 0; - // Slave Array to identify the colours the faces were assigned to, + // Slave NgArray to identify the colours the faces were assigned to, // after the bubble sort routine to sort the automatic boundary // identifiers according to the number of surface mesh elements // of a given colour @@ -342,7 +342,7 @@ namespace netgen // And save this number into an array for later sorting for(int face_index = 1; face_index <= nfd; face_index++) { - Array se_face; + NgArray se_face; mesh.GetSurfaceElementsOfFace(face_index, se_face); diff --git a/libsrc/meshing/bcfunctions.hpp b/libsrc/meshing/bcfunctions.hpp index 074654ae..55aca571 100644 --- a/libsrc/meshing/bcfunctions.hpp +++ b/libsrc/meshing/bcfunctions.hpp @@ -45,7 +45,7 @@ namespace netgen //extern void OCCAutoColourBcProps(Mesh & mesh, OCCGeometry & occgeometry, const char *occcolourfile); extern DLL_HEADER void AutoColourBcProps(Mesh & mesh, const char *bccolourfile); - extern DLL_HEADER void GetFaceColours(Mesh & mesh, Array & face_colours); + extern DLL_HEADER void GetFaceColours(Mesh & mesh, NgArray & face_colours); extern DLL_HEADER bool ColourMatch(Vec3d col1, Vec3d col2, double eps = 2.5e-05); } diff --git a/libsrc/meshing/bisect.cpp b/libsrc/meshing/bisect.cpp index d73718be..8cb57bcd 100644 --- a/libsrc/meshing/bisect.cpp +++ b/libsrc/meshing/bisect.cpp @@ -12,11 +12,11 @@ namespace netgen class MarkedTri; class MarkedQuad; - typedef Array T_MTETS; - typedef Array T_MPRISMS; - typedef Array T_MIDS; - typedef Array T_MTRIS; - typedef Array T_MQUADS; + typedef NgArray T_MTETS; + typedef NgArray T_MPRISMS; + typedef NgArray T_MIDS; + typedef NgArray T_MTRIS; + typedef NgArray T_MQUADS; @@ -303,7 +303,7 @@ namespace netgen int BTSortEdges (const Mesh & mesh, - const Array< Array* > & idmaps, + const NgArray< NgArray* > & idmaps, INDEX_2_CLOSED_HASHTABLE & edgenumber) { PrintMessage(4,"sorting ... "); @@ -313,8 +313,8 @@ namespace netgen { // new, fast version - Array edges; - Array eclasses; + NgArray edges; + NgArray eclasses; int i, j, k; int cntedges = 0; @@ -585,7 +585,7 @@ namespace netgen // } // compute classlength: - Array edgelength(cntedges); + NgArray edgelength(cntedges); /* for (i = 1; i <= cntedges; i++) @@ -676,7 +676,7 @@ namespace netgen // sort edges: - Array sorted(cntedges); + NgArray sorted(cntedges); QuickSort (edgelength, sorted); @@ -974,7 +974,7 @@ namespace netgen bool BTDefineMarkedId(const Element2d & el, INDEX_2_CLOSED_HASHTABLE & edgenumber, - const Array & idmap, + const NgArray & idmap, MarkedIdentification & mi) { @@ -1392,7 +1392,7 @@ namespace netgen void BTBisectIdentification (const MarkedIdentification & oldid, - Array & newp, + NgArray & newp, MarkedIdentification & newid1, MarkedIdentification & newid2) { @@ -1626,10 +1626,10 @@ namespace netgen { int i,j,k; - Array< Array* > idmaps; + NgArray< NgArray* > idmaps; for(i=1; i<=mesh.GetIdentifications().GetMaxNr(); i++) { - idmaps.Append(new Array); + idmaps.Append(new NgArray); mesh.GetIdentifications().GetMap(i,*idmaps.Last()); } @@ -1847,7 +1847,7 @@ namespace netgen void ConnectToNodeRec (int node, int tonode, - const TABLE & conto, Array & connecttonode) + const TABLE & conto, NgArray & connecttonode) { // (*testout) << "connect " << node << " to " << tonode << endl; for (int i = 1; i <= conto.EntrySize(node); i++) @@ -1955,7 +1955,7 @@ namespace netgen void BisectTetsCopyMesh (Mesh & mesh, const NetgenGeometry *, BisectionOptions & opt, - const Array< Array* > & idmaps, + const NgArray< NgArray* > & idmaps, const string & refinfofile) { // mtets.SetName ("bisection, tets"); @@ -2201,24 +2201,24 @@ namespace netgen /* void UpdateEdgeMarks2(Mesh & mesh, - const Array< Array* > & idmaps) + const NgArray< NgArray* > & idmaps) { - Array< Array*,PointIndex::BASE > mtets_old(mesh.GetNP()); - Array< Array*,PointIndex::BASE > mprisms_old(mesh.GetNP()); - Array< Array*,PointIndex::BASE > mids_old(mesh.GetNP()); - Array< Array*,PointIndex::BASE > mtris_old(mesh.GetNP()); - Array< Array*,PointIndex::BASE > mquads_old(mesh.GetNP()); + NgArray< NgArray*,PointIndex::BASE > mtets_old(mesh.GetNP()); + NgArray< NgArray*,PointIndex::BASE > mprisms_old(mesh.GetNP()); + NgArray< NgArray*,PointIndex::BASE > mids_old(mesh.GetNP()); + NgArray< NgArray*,PointIndex::BASE > mtris_old(mesh.GetNP()); + NgArray< NgArray*,PointIndex::BASE > mquads_old(mesh.GetNP()); for(int i=PointIndex::BASE; i; + mtets_old[i] = new NgArray; for(int i=PointIndex::BASE; i; + mprisms_old[i] = new NgArray; for(int i=PointIndex::BASE; i; + mids_old[i] = new NgArray; for(int i=PointIndex::BASE; i; + mtris_old[i] = new NgArray; for(int i=PointIndex::BASE; i; + mquads_old[i] = new NgArray; for(int i=0; iAppend(mtets[i]); @@ -2454,11 +2454,11 @@ namespace netgen void UpdateEdgeMarks (Mesh & mesh, - const Array< Array* > & idmaps) - //const Array < Array* > & elements_before, - //const Array < Array* > & markedelts_num, - // const Array < Array* > & surfelements_before, - // const Array < Array* > & markedsurfelts_num) + const NgArray< NgArray* > & idmaps) + //const NgArray < NgArray* > & elements_before, + //const NgArray < NgArray* > & markedelts_num, + // const NgArray < NgArray* > & surfelements_before, + // const NgArray < NgArray* > & markedsurfelts_num) { /* T_MTETS mtets_old; mtets_old.Copy(mtets); @@ -2687,7 +2687,7 @@ namespace netgen void Refinement :: Bisect (Mesh & mesh, BisectionOptions & opt, - Array * quality_loss) const + NgArray * quality_loss) const { PrintMessage(1,"Mesh bisection"); PushStatus("Mesh bisection"); @@ -2717,12 +2717,12 @@ namespace netgen LocalizeEdgePoints(mesh); delete loct; - Array< Array* > idmaps; + NgArray< NgArray* > idmaps; for(int i=1; i<=mesh.GetIdentifications().GetMaxNr(); i++) { if(mesh.GetIdentifications().GetType(i) == Identifications::PERIODIC) { - idmaps.Append(new Array); + idmaps.Append(new NgArray); mesh.GetIdentifications().GetMap(i,*idmaps.Last(),true); } } @@ -2805,7 +2805,7 @@ namespace netgen #ifndef SABINE //Nachbarelemente mit ordx,ordy,ordz - Array v_order (mesh.GetNP()); + NgArray v_order (mesh.GetNP()); v_order = 0; for (ElementIndex ei = 0; ei < ne; ei++) @@ -3181,7 +3181,7 @@ namespace netgen else { // vertices with 2 different bnds - Array bndind(np); + NgArray bndind(np); bndind = 0; for (int i = 1; i <= mesh.GetNSeg(); i++) { @@ -3347,11 +3347,11 @@ namespace netgen if (mids.Elem(i).marked) { MarkedIdentification oldid,newid1,newid2; - Array newp; + NgArray newp; oldid = mids.Get(i); - Array edges; + NgArray edges; edges.Append(INDEX_2(oldid.pnums[oldid.markededge], oldid.pnums[(oldid.markededge+1)%oldid.np])); edges.Append(INDEX_2(oldid.pnums[oldid.markededge + oldid.np], @@ -3617,7 +3617,7 @@ namespace netgen if (opt.refine_hp) { // - Array v_order (mesh.GetNP()); + NgArray v_order (mesh.GetNP()); v_order = 0; if (mesh.GetDimension() == 3) { @@ -3917,7 +3917,7 @@ namespace netgen // update identification tables for (int i = 1; i <= mesh.GetIdentifications().GetMaxNr(); i++) { - Array identmap; + NgArray identmap; mesh.GetIdentifications().GetMap (i, identmap); @@ -3995,8 +3995,8 @@ namespace netgen NgProfiler::RegionTimer * regt(NULL); regt = new NgProfiler::RegionTimer(reptimer); - Array bad_elts; - Array pure_badness; + NgArray bad_elts; + NgArray pure_badness; if(do_repair || quality_loss != NULL) { diff --git a/libsrc/meshing/bisect.hpp b/libsrc/meshing/bisect.hpp index 4fa61a93..7da7443c 100644 --- a/libsrc/meshing/bisect.hpp +++ b/libsrc/meshing/bisect.hpp @@ -46,7 +46,7 @@ public: void Refine (Mesh & mesh) const; void Refine (Mesh & mesh); - void Bisect (Mesh & mesh, class BisectionOptions & opt, Array * quality_loss = NULL) const; + void Bisect (Mesh & mesh, class BisectionOptions & opt, NgArray * quality_loss = NULL) const; void MakeSecondOrder (Mesh & mesh) const; void MakeSecondOrder (Mesh & mesh); @@ -82,7 +82,7 @@ public: void ValidateSecondOrder (Mesh & mesh); void ValidateRefinedMesh (Mesh & mesh, - Array & parents); + NgArray & parents); MeshOptimize2d * Get2dOptimizer(void) const { diff --git a/libsrc/meshing/boundarylayer.cpp b/libsrc/meshing/boundarylayer.cpp index ab424dff..b0746dc9 100644 --- a/libsrc/meshing/boundarylayer.cpp +++ b/libsrc/meshing/boundarylayer.cpp @@ -20,7 +20,7 @@ namespace netgen cout << "Trigs: " << mesh.GetNSE() << endl; BitArray bndnodes(np); - Array mapto(np); + NgArray mapto(np); bndnodes.Clear(); for (i = 1; i <= mesh.GetNSeg(); i++) @@ -151,11 +151,11 @@ namespace netgen double angleThreshold = 5.0; - Array surfid (blp.surfid); + NgArray surfid (blp.surfid); int prismlayers = blp.prismlayers; double hfirst = blp.hfirst; double growthfactor = blp.growthfactor; - Array heights (blp.heights); + NgArray heights (blp.heights); bool grow_edges = false; // grow layer at edges @@ -213,11 +213,11 @@ namespace netgen BitArray bndnodes(np+1); // big enough for 1-based array // Map of the old points to the new points - Array mapto(np); + NgArray mapto(np); // Growth vectors for the prismatic layer based on // the effective surface normal at a given point - Array growthvectors(np); + NgArray growthvectors(np); // Bit array to identify all the points belonging // to the surface of interest @@ -324,8 +324,8 @@ namespace netgen if(!surfid.Contains(mesh[sej].si)) { SurfaceElementIndex pnt_commelem = 0; - Array pnt1_elems; - Array pnt2_elems; + NgArray pnt1_elems; + NgArray pnt2_elems; meshtopo.GetVertexSurfaceElements(segpair_p1,pnt1_elems); @@ -583,7 +583,7 @@ namespace netgen for (int i = 1; i <= np; i++) { - Array vertelems; + NgArray vertelems; if(bndnodes.Test(i)) { diff --git a/libsrc/meshing/boundarylayer.hpp b/libsrc/meshing/boundarylayer.hpp index 29a3ff29..a174a55a 100644 --- a/libsrc/meshing/boundarylayer.hpp +++ b/libsrc/meshing/boundarylayer.hpp @@ -12,9 +12,9 @@ class BoundaryLayerParameters { public: // parameters by Philippose .. - Array surfid; - Array heights; - Array new_matnrs; + NgArray surfid; + NgArray heights; + NgArray new_matnrs; int prismlayers = 1; int bulk_matnr = 1; int new_matnr = 1; diff --git a/libsrc/meshing/classifyhpel.hpp b/libsrc/meshing/classifyhpel.hpp index c1555371..00bf6c0d 100644 --- a/libsrc/meshing/classifyhpel.hpp +++ b/libsrc/meshing/classifyhpel.hpp @@ -1,6 +1,6 @@ HPREF_ELEMENT_TYPE ClassifyTet(HPRefElement & el, INDEX_2_HASHTABLE & edges, INDEX_2_HASHTABLE & edgepoint_dom, BitArray & cornerpoint, BitArray & edgepoint, INDEX_3_HASHTABLE & faces, INDEX_2_HASHTABLE & face_edges, - INDEX_2_HASHTABLE & surf_edges, Array & facepoint) + INDEX_2_HASHTABLE & surf_edges, NgArray & facepoint) { int ep1(0), ep2(0), ep3(0), ep4(0), cp1(0), cp2(0), cp3(0), cp4(0), fp1, fp2, fp3, fp4; int isedge1(0), isedge2(0), isedge3(0), isedge4(0), isedge5(0), isedge6(0); @@ -424,7 +424,7 @@ HPREF_ELEMENT_TYPE ClassifyTet(HPRefElement & el, INDEX_2_HASHTABLE & edges HPREF_ELEMENT_TYPE ClassifyPrism(HPRefElement & el, INDEX_2_HASHTABLE & edges, INDEX_2_HASHTABLE & edgepoint_dom, BitArray & cornerpoint, BitArray & edgepoint, INDEX_3_HASHTABLE & faces, INDEX_2_HASHTABLE & face_edges, - INDEX_2_HASHTABLE & surf_edges, Array & facepoint) + INDEX_2_HASHTABLE & surf_edges, NgArray & facepoint) { HPREF_ELEMENT_TYPE type = HP_NONE; @@ -661,7 +661,7 @@ HPREF_ELEMENT_TYPE ClassifyPrism(HPRefElement & el, INDEX_2_HASHTABLE & edg // #ifdef SABINE HPREF_ELEMENT_TYPE ClassifyTrig(HPRefElement & el, INDEX_2_HASHTABLE & edges, INDEX_2_HASHTABLE & edgepoint_dom, BitArray & cornerpoint, BitArray & edgepoint, INDEX_3_HASHTABLE & faces, INDEX_2_HASHTABLE & face_edges, - INDEX_2_HASHTABLE & surf_edges, Array & facepoint, int dim, const FaceDescriptor & fd) + INDEX_2_HASHTABLE & surf_edges, NgArray & facepoint, int dim, const FaceDescriptor & fd) { HPREF_ELEMENT_TYPE type = HP_NONE; @@ -876,7 +876,7 @@ HPREF_ELEMENT_TYPE ClassifyTrig(HPRefElement & el, INDEX_2_HASHTABLE & edge #ifdef HPREF_OLD HPREF_ELEMENT_TYPE ClassifyTrig(HPRefElement & el, INDEX_2_HASHTABLE & edges, INDEX_2_HASHTABLE & edgepoint_dom, BitArray & cornerpoint, BitArray & edgepoint, INDEX_3_HASHTABLE & faces, INDEX_2_HASHTABLE & face_edges, - INDEX_2_HASHTABLE & surf_edges, Array & facepoint, int dim, const FaceDescriptor & fd) + INDEX_2_HASHTABLE & surf_edges, NgArray & facepoint, int dim, const FaceDescriptor & fd) { HPREF_ELEMENT_TYPE type = HP_NONE; @@ -1137,7 +1137,7 @@ HPREF_ELEMENT_TYPE ClassifyTrig(HPRefElement & el, INDEX_2_HASHTABLE & edge #endif HPREF_ELEMENT_TYPE ClassifyQuad(HPRefElement & el, INDEX_2_HASHTABLE & edges, INDEX_2_HASHTABLE & edgepoint_dom, BitArray & cornerpoint, BitArray & edgepoint, INDEX_3_HASHTABLE & faces, INDEX_2_HASHTABLE & face_edges, - INDEX_2_HASHTABLE & surf_edges, Array & facepoint, int dim, const FaceDescriptor & fd) + INDEX_2_HASHTABLE & surf_edges, NgArray & facepoint, int dim, const FaceDescriptor & fd) { HPREF_ELEMENT_TYPE type = HP_NONE; @@ -1487,7 +1487,7 @@ HPREF_ELEMENT_TYPE ClassifyQuad(HPRefElement & el, INDEX_2_HASHTABLE & edge HPREF_ELEMENT_TYPE ClassifyHex(HPRefElement & el, INDEX_2_HASHTABLE & edges, INDEX_2_HASHTABLE & edgepoint_dom, BitArray & cornerpoint, BitArray & edgepoint, INDEX_3_HASHTABLE & faces, INDEX_2_HASHTABLE & face_edges, - INDEX_2_HASHTABLE & surf_edges, Array & facepoint) + INDEX_2_HASHTABLE & surf_edges, NgArray & facepoint) { HPREF_ELEMENT_TYPE type = HP_NONE; @@ -1587,7 +1587,7 @@ HPREF_ELEMENT_TYPE ClassifyHex(HPRefElement & el, INDEX_2_HASHTABLE & edges HPREF_ELEMENT_TYPE ClassifySegm(HPRefElement & hpel, INDEX_2_HASHTABLE & edges, INDEX_2_HASHTABLE & edgepoint_dom, BitArray & cornerpoint, BitArray & edgepoint, INDEX_3_HASHTABLE & faces, INDEX_2_HASHTABLE & face_edges, - INDEX_2_HASHTABLE & surf_edges, Array & facepoint) + INDEX_2_HASHTABLE & surf_edges, NgArray & facepoint) { int cp1 = cornerpoint.Test (hpel[0]); @@ -1630,7 +1630,7 @@ HPREF_ELEMENT_TYPE ClassifySegm(HPRefElement & hpel, INDEX_2_HASHTABLE & ed HPREF_ELEMENT_TYPE ClassifyPyramid(HPRefElement & el, INDEX_2_HASHTABLE & edges, INDEX_2_HASHTABLE & edgepoint_dom, BitArray & cornerpoint, BitArray & edgepoint, INDEX_3_HASHTABLE & faces, INDEX_2_HASHTABLE & face_edges, - INDEX_2_HASHTABLE & surf_edges, Array & facepoint) + INDEX_2_HASHTABLE & surf_edges, NgArray & facepoint) { HPREF_ELEMENT_TYPE type = HP_NONE; diff --git a/libsrc/meshing/clusters.cpp b/libsrc/meshing/clusters.cpp index 544a8767..32c43c71 100644 --- a/libsrc/meshing/clusters.cpp +++ b/libsrc/meshing/clusters.cpp @@ -46,10 +46,10 @@ namespace netgen cluster_reps.SetSize (nv+ned+nfa+ne); cluster_reps = -1; - Array llist (nv+ned+nfa+ne); + NgArray llist (nv+ned+nfa+ne); llist = 0; - Array nnums, ednums, fanums; + NgArray nnums, ednums, fanums; int changed; // NgProfiler::StartTimer(timer1); @@ -85,7 +85,7 @@ namespace netgen (tm, ne, [&] (size_t begin, size_t end) { - Array nnums, ednums, fanums; + NgArray nnums, ednums, fanums; for (int i = begin+1; i <= end; i++) { const Element & el = mesh.VolumeElement(i); diff --git a/libsrc/meshing/clusters.hpp b/libsrc/meshing/clusters.hpp index 2cd701b4..bf9a5a56 100644 --- a/libsrc/meshing/clusters.hpp +++ b/libsrc/meshing/clusters.hpp @@ -21,7 +21,7 @@ class AnisotropicClusters int nv, ned, nfa, ne; // connected nodes, nodes = vertices, edges, faces, elements - Array cluster_reps; + NgArray cluster_reps; public: AnisotropicClusters (const Mesh & amesh); diff --git a/libsrc/meshing/curvedelems.cpp b/libsrc/meshing/curvedelems.cpp index a5d7c37b..3040846f 100644 --- a/libsrc/meshing/curvedelems.cpp +++ b/libsrc/meshing/curvedelems.cpp @@ -11,7 +11,7 @@ namespace netgen // bool rational = true; - static void ComputeGaussRule (int n, Array & xi, Array & wi) + static void ComputeGaussRule (int n, NgArray & xi, NgArray & wi) { xi.SetSize (n); wi.SetSize (n); @@ -407,7 +407,7 @@ namespace netgen } - static Array> jacpols2; + static NgArray> jacpols2; void CurvedElements::buildJacPols() { @@ -566,7 +566,7 @@ namespace netgen const ParallelMeshTopology & partop = mesh.GetParallelTopology (); // MPI_Comm_dup (mesh.GetCommunicator(), &curve_comm); - Array procs; + NgArray procs; #else // curve_comm = mesh.GetCommunicator(); #endif @@ -597,7 +597,7 @@ namespace netgen rational = arational; - Array edgenrs; + NgArray edgenrs; int nedges = top.GetNEdges(); int nfaces = top.GetNFaces(); @@ -670,7 +670,7 @@ namespace netgen if (ntasks > 1 && working) { - Array cnt(ntasks); + NgArray cnt(ntasks); cnt = 0; for (int e = 0; e < edgeorder.Size(); e++) { @@ -723,7 +723,7 @@ namespace netgen return; } - Array xi, weight; + NgArray xi, weight; ComputeGaussRule (aorder+4, xi, weight); // on (0,1) @@ -733,9 +733,9 @@ namespace netgen if (mesh.GetDimension() == 3 || rational) { static Timer tce("curve edges"); RegionTimer reg(tce); - Array surfnr(nedges); - Array gi0(nedges); - Array gi1(nedges); + NgArray surfnr(nedges); + NgArray gi0(nedges); + NgArray gi1(nedges); surfnr = -1; if (working) @@ -792,7 +792,7 @@ namespace netgen MyMPI_ExchangeTable (senddata, recvdata, MPI_TAG_CURVE, curve_comm); - Array cnt(ntasks); + NgArray cnt(ntasks); cnt = 0; if (working) for (int e = 0; e < nedges; e++) @@ -947,12 +947,12 @@ namespace netgen } - Array use_edge(nedges); - Array edge_surfnr1(nedges); - Array edge_surfnr2(nedges); - Array swap_edge(nedges); - Array edge_gi0(nedges); - Array edge_gi1(nedges); + NgArray use_edge(nedges); + NgArray edge_surfnr1(nedges); + NgArray edge_surfnr2(nedges); + NgArray swap_edge(nedges); + NgArray edge_gi0(nedges); + NgArray edge_gi1(nedges); use_edge = 0; if (working) @@ -999,7 +999,7 @@ namespace netgen } } MyMPI_ExchangeTable (senddata, recvdata, MPI_TAG_CURVE, curve_comm); - Array cnt(ntasks); + NgArray cnt(ntasks); cnt = 0; if (working) for (int e = 0; e < edge_surfnr1.Size(); e++) @@ -1169,7 +1169,7 @@ namespace netgen PrintMessage (3, "Curving faces"); - Array surfnr(nfaces); + NgArray surfnr(nfaces); surfnr = -1; if (working) @@ -1195,7 +1195,7 @@ namespace netgen if (ntasks > 1 && working) { - Array cnt(ntasks); + NgArray cnt(ntasks); cnt = 0; for (int f = 0; f < nfaces; f++) { @@ -1239,8 +1239,8 @@ namespace netgen dmat = 0.0; int np = sqr(xi.Size()); - Array > xia(np); - Array > xa(np); + NgArray > xia(np); + NgArray > xa(np); for (int jx = 0, jj = 0; jx < xi.Size(); jx++) for (int jy = 0; jy < xi.Size(); jy++, jj++) @@ -1248,7 +1248,7 @@ namespace netgen // CalcMultiPointSurfaceTransformation (&xia, i, &xa, NULL); - Array edgenrs; + NgArray edgenrs; top.GetFaceEdges (facenr+1, edgenrs); for (int k = 0; k < edgenrs.Size(); k++) edgenrs[k]--; @@ -1453,7 +1453,7 @@ namespace netgen // TVector shapes, dshapes; - // Array > coefs; + // NgArray > coefs; SegmentInfo info; info.elnr = elnr; @@ -1582,7 +1582,7 @@ namespace netgen } void CurvedElements :: - GetCoefficients (SegmentInfo & info, Array > & coefs) const + GetCoefficients (SegmentInfo & info, NgArray > & coefs) const { const Segment & el = mesh[info.elnr]; @@ -2366,7 +2366,7 @@ namespace netgen template void CurvedElements :: - GetCoefficients (SurfaceElementInfo & info, Array > & coefs) const + GetCoefficients (SurfaceElementInfo & info, NgArray > & coefs) const { const Element2d & el = mesh[info.elnr]; coefs.SetSize (info.ndof); @@ -2400,10 +2400,10 @@ namespace netgen template void CurvedElements :: - GetCoefficients<2> (SurfaceElementInfo & info, Array > & coefs) const; + GetCoefficients<2> (SurfaceElementInfo & info, NgArray > & coefs) const; template void CurvedElements :: - GetCoefficients<3> (SurfaceElementInfo & info, Array > & coefs) const; + GetCoefficients<3> (SurfaceElementInfo & info, NgArray > & coefs) const; @@ -3966,9 +3966,9 @@ namespace netgen /* void CurvedElements :: - CalcMultiPointSegmentTransformation (Array * xi, SegmentIndex segnr, - Array > * x, - Array > * dxdxi) + CalcMultiPointSegmentTransformation (NgArray * xi, SegmentIndex segnr, + NgArray > * x, + NgArray > * dxdxi) { ; } @@ -4030,9 +4030,9 @@ namespace netgen void CurvedElements :: - CalcMultiPointSurfaceTransformation (Array< Point<2> > * xi, SurfaceElementIndex elnr, - Array< Point<3> > * x, - Array< Mat<3,2> > * dxdxi) + CalcMultiPointSurfaceTransformation (NgArray< Point<2> > * xi, SurfaceElementIndex elnr, + NgArray< Point<3> > * x, + NgArray< Mat<3,2> > * dxdxi) { double * px = (x) ? &(*x)[0](0) : NULL; double * pdxdxi = (dxdxi) ? &(*dxdxi)[0](0) : NULL; @@ -4343,9 +4343,9 @@ namespace netgen void CurvedElements :: - CalcMultiPointElementTransformation (Array< Point<3> > * xi, ElementIndex elnr, - Array< Point<3> > * x, - Array< Mat<3,3> > * dxdxi) + CalcMultiPointElementTransformation (NgArray< Point<3> > * xi, ElementIndex elnr, + NgArray< Point<3> > * x, + NgArray< Mat<3,3> > * dxdxi) { double * px = (x) ? &(*x)[0](0) : NULL; double * pdxdxi = (dxdxi) ? &(*dxdxi)[0](0) : NULL; @@ -4448,7 +4448,7 @@ namespace netgen // info.ndof += facecoeffsindex[info.facenr+1] - facecoeffsindex[info.facenr]; } - Array > coefs(info.ndof); + NgArray > coefs(info.ndof); GetCoefficients (info, &coefs[0]); if (x) { diff --git a/libsrc/meshing/curvedelems.hpp b/libsrc/meshing/curvedelems.hpp index cd78d708..e774fe58 100644 --- a/libsrc/meshing/curvedelems.hpp +++ b/libsrc/meshing/curvedelems.hpp @@ -18,16 +18,16 @@ class CurvedElements { const Mesh & mesh; - Array edgeorder; - Array faceorder; + NgArray edgeorder; + NgArray faceorder; - Array edgecoeffsindex; - Array facecoeffsindex; + NgArray edgecoeffsindex; + NgArray facecoeffsindex; - Array< Vec<3> > edgecoeffs; - Array< Vec<3> > facecoeffs; + NgArray< Vec<3> > edgecoeffs; + NgArray< Vec<3> > facecoeffs; - Array< double > edgeweight; // for rational 2nd order splines + NgArray< double > edgeweight; // for rational 2nd order splines int order; bool rational; @@ -124,9 +124,9 @@ public: /* - void CalcMultiPointSegmentTransformation (Array * xi, SegmentIndex segnr, - Array > * x, - Array > * dxdxi); + void CalcMultiPointSegmentTransformation (NgArray * xi, SegmentIndex segnr, + NgArray > * x, + NgArray > * dxdxi); */ template @@ -135,9 +135,9 @@ public: T * x, size_t sx, T * dxdxi, size_t sdxdxi); - void CalcMultiPointSurfaceTransformation (Array< Point<2> > * xi, SurfaceElementIndex elnr, - Array< Point<3> > * x, - Array< Mat<3,2> > * dxdxi); + void CalcMultiPointSurfaceTransformation (NgArray< Point<2> > * xi, SurfaceElementIndex elnr, + NgArray< Point<3> > * x, + NgArray< Mat<3,2> > * dxdxi); template void CalcMultiPointSurfaceTransformation (SurfaceElementIndex elnr, int n, @@ -145,9 +145,9 @@ public: T * x, size_t sx, T * dxdxi, size_t sdxdxi); - void CalcMultiPointElementTransformation (Array< Point<3> > * xi, ElementIndex elnr, - Array< Point<3> > * x, - Array< Mat<3,3> > * dxdxi); + void CalcMultiPointElementTransformation (NgArray< Point<3> > * xi, ElementIndex elnr, + NgArray< Point<3> > * x, + NgArray< Mat<3,3> > * dxdxi); template void CalcMultiPointElementTransformation (ElementIndex elnr, int n, @@ -188,7 +188,7 @@ private: template void CalcElementShapes (SegmentInfo & elnr, T xi, TFlatVector shapes) const; - void GetCoefficients (SegmentInfo & elnr, Array > & coefs) const; + void GetCoefficients (SegmentInfo & elnr, NgArray > & coefs) const; template void CalcElementDShapes (SegmentInfo & elnr, T xi, TFlatVector dshapes) const; @@ -231,7 +231,7 @@ private: template void CalcElementShapes (SurfaceElementInfo & elinfo, const Point<2,T> xi, TFlatVector shapes) const; template - void GetCoefficients (SurfaceElementInfo & elinfo, Array > & coefs) const; + void GetCoefficients (SurfaceElementInfo & elinfo, NgArray > & coefs) const; template void CalcElementDShapes (SurfaceElementInfo & elinfo, const Point<2,T> xi, MatrixFixWidth<2,T> dshapes) const; diff --git a/libsrc/meshing/delaunay.cpp b/libsrc/meshing/delaunay.cpp index c51598b7..c11a0946 100644 --- a/libsrc/meshing/delaunay.cpp +++ b/libsrc/meshing/delaunay.cpp @@ -81,12 +81,12 @@ namespace netgen INDEX_3_CLOSED_HASHTABLE faces; // - Array & tets; + NgArray & tets; public: // estimated number of points - MeshNB (Array & atets, int np) + MeshNB (NgArray & atets, int np) : faces(200), tets(atets) { ; } @@ -155,7 +155,7 @@ namespace netgen */ class SphereList { - Array links; + NgArray links; public: SphereList () { ; } @@ -178,11 +178,11 @@ namespace netgen links.Elem (toi) = eli; } - void GetList (int eli, Array & linked) const; + void GetList (int eli, NgArray & linked) const; }; - void SphereList :: GetList (int eli, Array & linked) const + void SphereList :: GetList (int eli, NgArray & linked) const { linked.SetSize (0); int pi = eli; @@ -212,13 +212,13 @@ namespace netgen void AddDelaunayPoint (PointIndex newpi, const Point3d & newp, - Array & tempels, + NgArray & tempels, Mesh & mesh, BoxTree<3> & tettree, MeshNB & meshnb, - Array > & centers, Array & radi2, - Array & connected, Array & treesearch, - Array & freelist, SphereList & list, + NgArray > & centers, NgArray & radi2, + NgArray & connected, NgArray & treesearch, + NgArray & freelist, SphereList & list, IndexSet & insphere, IndexSet & closesphere) { // static Timer t("Meshing3::AddDelaunayPoint"); RegionTimer reg(t); @@ -363,8 +363,8 @@ namespace netgen } } // while (changed) - // Array newels; - Array newels; + // NgArray newels; + NgArray newels; Element2d face(TRIG); @@ -517,13 +517,13 @@ namespace netgen void Delaunay1 (Mesh & mesh, const MeshingParameters & mp, AdFront3 * adfront, - Array & tempels, + NgArray & tempels, int oldnp, DelaunayTet & startel, Point3d & pmin, Point3d & pmax) { static Timer t("Meshing3::Delaunay1"); RegionTimer reg(t); - Array> centers; - Array radi2; + NgArray> centers; + NgArray radi2; Box<3> bbox(Box<3>::EMPTY_BOX); @@ -576,7 +576,7 @@ namespace netgen usep.Set (pi); - Array freelist; + NgArray freelist; int cntp = 0; @@ -592,7 +592,7 @@ namespace netgen tempels.Append (startel); meshnb.Add (1); list.AddElement (1); - Array connected, treesearch; + NgArray connected, treesearch; Box<3> tbox(Box<3>::EMPTY_BOX); for (size_t k = 0; k < 4; k++) @@ -618,7 +618,7 @@ namespace netgen IndexSet closesphere(mesh.GetNP()); // "random" reordering of points (speeds a factor 3 - 5 !!!) - Array mixed(np); + NgArray mixed(np); int prims[] = { 11, 13, 17, 19, 23, 29, 31, 37 }; int prim; @@ -696,7 +696,7 @@ namespace netgen PushStatus ("Delaunay meshing"); - Array tempels; + NgArray tempels; Point3d pmin, pmax; DelaunayTet startel; @@ -856,7 +856,7 @@ namespace netgen // find surface triangles which are no face of any tet INDEX_3_HASHTABLE openeltab(mesh.GetNOpenElements()+3); - Array openels; + NgArray openels; for (int i = 1; i <= mesh.GetNOpenElements(); i++) { const Element2d & tri = mesh.OpenElement(i); @@ -1044,7 +1044,7 @@ namespace netgen } } - Array neartrias; + NgArray neartrias; for (int i = 1; i <= tempels.Size(); i++) { const Point<3> *pp[4]; @@ -1321,7 +1321,7 @@ namespace netgen BitArray inner(ne), outer(ne); inner.Clear(); outer.Clear(); - Array elstack; + NgArray elstack; /* int starti = 0; diff --git a/libsrc/meshing/delaunay2d.cpp b/libsrc/meshing/delaunay2d.cpp index f2de6216..0fc535dc 100644 --- a/libsrc/meshing/delaunay2d.cpp +++ b/libsrc/meshing/delaunay2d.cpp @@ -74,7 +74,7 @@ namespace netgen cout << "rel filldist = " << filldist << endl; PrintMessage (3, "blockfill local h"); - Array > npoints; + NgArray > npoints; // adfront -> CreateTrees(); @@ -287,21 +287,21 @@ namespace netgen hp(2) = -1; hbox.Add (hp); BoxTree<3> searchtree(hbox); - Array tempels; + NgArray tempels; startel.CalcCenter (mesh); tempels.Append (startel); searchtree.Insert(startel.BoundingBox(), 0); - Array closeels; - Array intersecting; - Array edges; + NgArray closeels; + NgArray intersecting; + NgArray edges; // reorder points - Array mixed(old_points.Size()); + NgArray mixed(old_points.Size()); int prims[] = { 11, 13, 17, 19, 23, 29, 31, 37 }; int prim; diff --git a/libsrc/meshing/findip.hpp b/libsrc/meshing/findip.hpp index f5d8e424..10caa73f 100644 --- a/libsrc/meshing/findip.hpp +++ b/libsrc/meshing/findip.hpp @@ -2,8 +2,8 @@ -inline void Minimize (const Array & a, - const Array & c, +inline void Minimize (const NgArray & a, + const NgArray & c, int * act, Vec<3> & x, double & f, int * sol) @@ -75,8 +75,8 @@ inline int FindInnerPoint (POINTArray & points, static int timer = NgProfiler::CreateTimer ("FindInnerPoint"); NgProfiler::RegionTimer reg (timer); - Array a; - Array c; + NgArray a; + NgArray c; Mat<3> m, inv; Vec<3> rs, x = 0.0, center; double f; diff --git a/libsrc/meshing/findip2.hpp b/libsrc/meshing/findip2.hpp index 95385534..62009b25 100644 --- a/libsrc/meshing/findip2.hpp +++ b/libsrc/meshing/findip2.hpp @@ -8,8 +8,8 @@ inline int FindInnerPoint2 (POINTArray & points, static int timer = NgProfiler::CreateTimer ("FindInnerPoint2"); NgProfiler::RegionTimer reg (timer); - Array a; - Array c; + NgArray a; + NgArray c; Mat<3> m, inv; Vec<3> rs, x, pmin; diff --git a/libsrc/meshing/geomsearch.cpp b/libsrc/meshing/geomsearch.cpp index 5a2192ea..dde4d5ac 100644 --- a/libsrc/meshing/geomsearch.cpp +++ b/libsrc/meshing/geomsearch.cpp @@ -19,7 +19,7 @@ namespace netgen } } - void GeomSearch3d :: Init (Array *pointsi, Array *facesi) + void GeomSearch3d :: Init (NgArray *pointsi, NgArray *facesi) { points = pointsi; faces = facesi; @@ -120,7 +120,7 @@ namespace netgen for (k = 1; k <= size.i3; k++) { INDEX ind=i+(j-1)*size.i1+(k-1)*size.i2*size.i1; - hashtable.Elem(ind) = new Array (); + hashtable.Elem(ind) = new NgArray (); } } } @@ -175,7 +175,7 @@ namespace netgen } } - void GeomSearch3d :: GetLocals(Array & locfaces, Array & findex, + void GeomSearch3d :: GetLocals(NgArray & locfaces, NgArray & findex, INDEX fstind, const Point3d& p0, double xh) { hashcount++; @@ -212,7 +212,7 @@ namespace netgen INDEX ind=ix+(iy-1)*size.i1+(iz-1)*size.i2*size.i1; //go through all elements in one hash area - const Array & area = *hashtable.Elem(ind); + const NgArray & area = *hashtable.Elem(ind); for (k = 1; k <= area.Size(); k++) { cnt2++; diff --git a/libsrc/meshing/geomsearch.hpp b/libsrc/meshing/geomsearch.hpp index d483c823..5adba567 100644 --- a/libsrc/meshing/geomsearch.hpp +++ b/libsrc/meshing/geomsearch.hpp @@ -22,7 +22,7 @@ public: virtual ~GeomSearch3d(); /// - void Init (Array *pointsi, Array *facesi); + void Init (NgArray *pointsi, NgArray *facesi); ///get elements max extension void ElemMaxExt(Point3d& minp, Point3d& maxp, const MiniElement2d& elem); @@ -41,15 +41,15 @@ public: void AddElem(const MiniElement2d& elem, INDEX elemnum); ///GetLocal faces in sphere with radius xh and middlepoint p - void GetLocals(Array & locfaces, Array & findex, + void GetLocals(NgArray & locfaces, NgArray & findex, INDEX fstind, const Point3d& p0, double xh); private: - Array *faces; // Pointers to Arrays in Adfront - Array *points; + NgArray *faces; // Pointers to Arrays in Adfront + NgArray *points; - Array *> hashtable; + NgArray *> hashtable; Point3d minext; //extension of Hashdomain Point3d maxext; diff --git a/libsrc/meshing/global.cpp b/libsrc/meshing/global.cpp index e614e1bd..883b7c8b 100644 --- a/libsrc/meshing/global.cpp +++ b/libsrc/meshing/global.cpp @@ -77,7 +77,7 @@ namespace netgen - Array tets_in_qualclass; + NgArray tets_in_qualclass; mutex tcl_todo_mutex; diff --git a/libsrc/meshing/global.hpp b/libsrc/meshing/global.hpp index b1da9344..d21cf105 100644 --- a/libsrc/meshing/global.hpp +++ b/libsrc/meshing/global.hpp @@ -27,7 +27,7 @@ namespace netgen // extern DLL_HEADER MeshingParameters mparam; - DLL_HEADER extern Array tets_in_qualclass; + DLL_HEADER extern NgArray tets_in_qualclass; DLL_HEADER extern mutex tcl_todo_mutex; diff --git a/libsrc/meshing/hprefinement.cpp b/libsrc/meshing/hprefinement.cpp index d2752ba8..765130db 100644 --- a/libsrc/meshing/hprefinement.cpp +++ b/libsrc/meshing/hprefinement.cpp @@ -552,12 +552,12 @@ namespace netgen bool CheckSingularities(Mesh & mesh, INDEX_2_HASHTABLE & edges, INDEX_2_HASHTABLE & edgepoiclt_dom, BitArray & cornerpoint, BitArray & edgepoint, INDEX_3_HASHTABLE & faces, INDEX_2_HASHTABLE & face_edges, - INDEX_2_HASHTABLE & surf_edges, Array & facepoint, int & levels, int & act_ref); + INDEX_2_HASHTABLE & surf_edges, NgArray & facepoint, int & levels, int & act_ref); - bool ClassifyHPElements (Mesh & mesh, Array & elements, int & act_ref, int & levels); + bool ClassifyHPElements (Mesh & mesh, NgArray & elements, int & act_ref, int & levels); - void InitHPElements(Mesh & mesh, Array & elements) + void InitHPElements(Mesh & mesh, NgArray & elements) { for(ElementIndex i = 0; i < mesh.GetNE(); i++) { @@ -612,7 +612,7 @@ namespace netgen /* ******************************* DoRefinement *************************************** */ - void DoRefinement (Mesh & mesh, Array & elements, + void DoRefinement (Mesh & mesh, NgArray & elements, Refinement * ref, double fac1) { elements.SetAllocSize (5 * elements.Size()); @@ -868,7 +868,7 @@ namespace netgen /* ************************** DoRefineDummies ******************************** */ - void DoRefineDummies (Mesh & mesh, Array & elements, + void DoRefineDummies (Mesh & mesh, NgArray & elements, Refinement * ref) { int oldelsize = elements.Size(); @@ -947,7 +947,7 @@ namespace netgen - void SubdivideDegeneratedHexes (Mesh & mesh, Array & elements, double fac1) + void SubdivideDegeneratedHexes (Mesh & mesh, NgArray & elements, double fac1) { int oldne = elements.Size(); for (int i = 0; i < oldne; i++) @@ -988,7 +988,7 @@ namespace netgen for (int j = 0; j < 6; j++) { - Array pts; + NgArray pts; for (int k = 0; k < 4; k++) { bool same = 0; @@ -1086,7 +1086,7 @@ namespace netgen } - void CalcStatistics (Array & elements) + void CalcStatistics (NgArray & elements) { return; #ifdef ABC @@ -1238,9 +1238,9 @@ namespace netgen - void ReorderPoints (Mesh & mesh, Array & hpelements) + void ReorderPoints (Mesh & mesh, NgArray & hpelements) { - Array map (mesh.GetNP()); + NgArray map (mesh.GetNP()); for (int i = 1; i <= mesh.GetNP(); i++) map[i] = i; @@ -1281,7 +1281,7 @@ namespace netgen cout << nwrong << " wrong prisms, " << nright << " right prisms" << endl; - Array hpts(mesh.GetNP()); + NgArray hpts(mesh.GetNP()); for (int i = 1; i <= mesh.GetNP(); i++) hpts[map[i]] = mesh.Point(i); @@ -1318,13 +1318,13 @@ namespace netgen delete mesh.hpelements; - mesh.hpelements = new Array; + mesh.hpelements = new NgArray; - Array & hpelements = *mesh.hpelements; + NgArray & hpelements = *mesh.hpelements; InitHPElements(mesh,hpelements); - Array nplevel; + NgArray nplevel; nplevel.Append (mesh.GetNP()); int act_ref=1; @@ -1559,7 +1559,7 @@ namespace netgen bool CheckSingularities(Mesh & mesh, INDEX_2_HASHTABLE & edges, INDEX_2_HASHTABLE & edgepoint_dom, BitArray & cornerpoint, BitArray & edgepoint, INDEX_3_HASHTABLE & faces, INDEX_2_HASHTABLE & face_edges, - INDEX_2_HASHTABLE & surf_edges, Array & facepoint, int & levels, int & act_ref) + INDEX_2_HASHTABLE & surf_edges, NgArray & facepoint, int & levels, int & act_ref) { bool sing = 0; if (mesh.GetDimension() == 3) @@ -1567,7 +1567,7 @@ bool CheckSingularities(Mesh & mesh, INDEX_2_HASHTABLE & edges, INDEX_2_HAS /* // check, if point has as least 3 different surfs: - Array surfonpoint(mesh.GetNP()); + NgArray surfonpoint(mesh.GetNP()); surfonpoint = INDEX_3(0,0,0); for (SurfaceElementIndex sei = 0; sei < mesh.GetNSE(); sei++) @@ -1710,7 +1710,7 @@ bool CheckSingularities(Mesh & mesh, INDEX_2_HASHTABLE & edges, INDEX_2_HAS // 2D case // check, if point has as least 3 different surfs: - Array surfonpoint(mesh.GetNP()); + NgArray surfonpoint(mesh.GetNP()); for (int i = 1; i <= mesh.GetNP(); i++) surfonpoint.Elem(i) = INDEX_3(0,0,0); @@ -1809,7 +1809,7 @@ bool CheckSingularities(Mesh & mesh, INDEX_2_HASHTABLE & edges, INDEX_2_HAS - bool ClassifyHPElements (Mesh & mesh, Array & elements, int & act_ref, int & levels) + bool ClassifyHPElements (Mesh & mesh, NgArray & elements, int & act_ref, int & levels) { INDEX_2_HASHTABLE edges(mesh.GetNSeg()+1); BitArray edgepoint(mesh.GetNP()); @@ -1824,7 +1824,7 @@ bool CheckSingularities(Mesh & mesh, INDEX_2_HASHTABLE & edges, INDEX_2_HAS INDEX_3_HASHTABLE faces(mesh.GetNSE()+1); INDEX_2_HASHTABLE face_edges(mesh.GetNSE()+1); INDEX_2_HASHTABLE surf_edges(mesh.GetNSE()+1); - Array facepoint(mesh.GetNP()); + NgArray facepoint(mesh.GetNP()); bool sing = CheckSingularities(mesh, edges, edgepoint_dom, cornerpoint, edgepoint, faces, face_edges, @@ -1833,7 +1833,7 @@ bool CheckSingularities(Mesh & mesh, INDEX_2_HASHTABLE & edges, INDEX_2_HAS if(sing==0) return(sing); int cnt_undef = 0, cnt_nonimplement = 0; - Array misses(10000); + NgArray misses(10000); misses = 0; (*testout) << "edgepoint_dom = " << endl << edgepoint_dom << endl; diff --git a/libsrc/meshing/improve2.cpp b/libsrc/meshing/improve2.cpp index 97fcb764..022debba 100644 --- a/libsrc/meshing/improve2.cpp +++ b/libsrc/meshing/improve2.cpp @@ -84,7 +84,7 @@ namespace netgen NgProfiler::StartTimer (timerstart); - Array seia; + NgArray seia; mesh.GetSurfaceElementsOfFace (faceindex, seia); for (int i = 0; i < seia.Size(); i++) @@ -96,13 +96,13 @@ namespace netgen int surfnr = mesh.GetFaceDescriptor (faceindex).SurfNr(); - Array neighbors(mesh.GetNSE()); + NgArray neighbors(mesh.GetNSE()); INDEX_2_HASHTABLE other(seia.Size() + 2); - Array swapped(mesh.GetNSE()); - Array pdef(mesh.GetNP()); - Array pangle(mesh.GetNP()); + NgArray swapped(mesh.GetNSE()); + NgArray pdef(mesh.GetNP()); + NgArray pangle(mesh.GetNP()); // int e; @@ -172,7 +172,7 @@ namespace netgen } /* - Array normals(mesh.GetNP()); + NgArray normals(mesh.GetNP()); for (i = 1; i <= mesh.GetNSE(); i++) { Element2d & hel = mesh.SurfaceElement(i); @@ -462,7 +462,7 @@ namespace netgen // SurfaceElementIndex sei; - Array seia; + NgArray seia; mesh.GetSurfaceElementsOfFace (faceindex, seia); @@ -486,7 +486,7 @@ namespace netgen //int nse = mesh.GetNSE(); TABLE elementsonnode(np); - Array hasonepi, hasbothpi; + NgArray hasonepi, hasbothpi; for (int i = 0; i < seia.Size(); i++) { @@ -495,7 +495,7 @@ namespace netgen elementsonnode.Add (el[j], seia[i]); } - Array fixed(np); + NgArray fixed(np); fixed = false; NgProfiler::StopTimer (timerstart1); @@ -531,7 +531,7 @@ namespace netgen - Array,PointIndex::BASE> normals(np); + NgArray,PointIndex::BASE> normals(np); for (PointIndex pi = mesh.Points().Begin(); pi < mesh.Points().End(); pi++) { @@ -812,7 +812,7 @@ namespace netgen int surfnr; Vec3d n, ng; - Array ngs(3); + NgArray ngs(3); (*mycout) << "Check Surface Approximation" << endl; (*testout) << "Check Surface Approximation" << endl; diff --git a/libsrc/meshing/improve2.hpp b/libsrc/meshing/improve2.hpp index 9c3c1be1..e0e0c70a 100644 --- a/libsrc/meshing/improve2.hpp +++ b/libsrc/meshing/improve2.hpp @@ -19,8 +19,8 @@ public: void ImproveMesh (Mesh & mesh2d, const MeshingParameters & mp); void ImproveMeshJacobian (Mesh & mesh2d, const MeshingParameters & mp); void ImproveVolumeMesh (Mesh & mesh); - void ProjectBoundaryPoints(Array & surfaceindex, - const Array* > & from, Array* > & dest); + void ProjectBoundaryPoints(NgArray & surfaceindex, + const NgArray* > & from, NgArray* > & dest); void EdgeSwapping (Mesh & mesh, int usemetric); void CombineImprove (Mesh & mesh); diff --git a/libsrc/meshing/improve2gen.cpp b/libsrc/meshing/improve2gen.cpp index fab74c66..ef10e322 100644 --- a/libsrc/meshing/improve2gen.cpp +++ b/libsrc/meshing/improve2gen.cpp @@ -9,11 +9,11 @@ namespace netgen class ImprovementRule { public: - Array oldels; - Array newels; - Array deledges; - Array incelsonnode; - Array reused; + NgArray oldels; + NgArray newels; + NgArray deledges; + NgArray incelsonnode; + NgArray reused; int bonus; int onp; }; @@ -50,11 +50,11 @@ namespace netgen bool ok; int olddef, newdef; - Array rules; - Array elmap; - Array elrot; - Array pmap; - Array pgi; + NgArray rules; + NgArray elmap; + NgArray elrot; + NgArray pmap; + NgArray pgi; int surfnr = mesh.GetFaceDescriptor (faceindex).SurfNr(); @@ -195,8 +195,8 @@ namespace netgen - Array mapped(rules.Size()); - Array used(rules.Size()); + NgArray mapped(rules.Size()); + NgArray used(rules.Size()); used = 0; mapped = 0; @@ -236,7 +236,7 @@ namespace netgen TABLE elonnode(np); - Array nelonnode(np); + NgArray nelonnode(np); TABLE nbels(ne); nelonnode = -4; diff --git a/libsrc/meshing/improve3.cpp b/libsrc/meshing/improve3.cpp index 544592b3..f00ff82e 100644 --- a/libsrc/meshing/improve3.cpp +++ b/libsrc/meshing/improve3.cpp @@ -28,10 +28,10 @@ void MeshOptimize3d :: CombineImprove (Mesh & mesh, int ne = mesh.GetNE(); TABLE elementsonnode(np); - Array hasonepi, hasbothpi; + NgArray hasonepi, hasbothpi; - Array oneperr; - Array elerrs (ne); + NgArray oneperr; + NgArray elerrs (ne); PrintMessage (3, "CombineImprove"); (*testout) << "Start CombineImprove" << "\n"; @@ -285,12 +285,12 @@ void MeshOptimize3d :: SplitImprove (Mesh & mesh, int ne = mesh.GetNE(); TABLE elementsonnode(np); - Array hasbothpoints; + NgArray hasbothpoints; BitArray origpoint(np+1), boundp(np+1); // big enough for 0 and 1-based origpoint.Set(); - Array elerrs(ne); + NgArray elerrs(ne); BitArray illegaltet(ne); illegaltet.Clear(); @@ -300,7 +300,7 @@ void MeshOptimize3d :: SplitImprove (Mesh & mesh, PrintMessage (3, "SplitImprove"); (*testout) << "start SplitImprove" << "\n"; - Array locfaces; + NgArray locfaces; INDEX_2_HASHTABLE edgetested (np); @@ -591,7 +591,7 @@ void MeshOptimize3d :: SwapImprove (Mesh & mesh, OPTIMIZEGOAL goal, // contains at least all elements at node TABLE elementsonnode(np); - Array hasbothpoints; + NgArray hasbothpoints; PrintMessage (3, "SwapImprove "); (*testout) << "\n" << "Start SwapImprove" << endl; @@ -1448,10 +1448,10 @@ void MeshOptimize3d :: SwapImprove (Mesh & mesh, OPTIMIZEGOAL goal, void MeshOptimize3d :: SwapImproveSurface (Mesh & mesh, OPTIMIZEGOAL goal, const BitArray * working_elements, - const Array< Array* > * idmaps) + const NgArray< NgArray* > * idmaps) { - Array< Array* > locidmaps; - const Array< Array* > * used_idmaps; + NgArray< NgArray* > locidmaps; + const NgArray< NgArray* > * used_idmaps; if(idmaps) used_idmaps = idmaps; @@ -1463,7 +1463,7 @@ void MeshOptimize3d :: SwapImproveSurface (Mesh & mesh, OPTIMIZEGOAL goal, { if(mesh.GetIdentifications().GetType(i) == Identifications::PERIODIC) { - locidmaps.Append(new Array); + locidmaps.Append(new NgArray); mesh.GetIdentifications().GetMap(i,*locidmaps.Last(),true); } } @@ -1490,8 +1490,8 @@ void MeshOptimize3d :: SwapImproveSurface (Mesh & mesh, OPTIMIZEGOAL goal, TABLE surfaceelementsonnode(np); TABLE surfaceindicesonnode(np); - Array hasbothpoints; - Array hasbothpointsother; + NgArray hasbothpoints; + NgArray hasbothpointsother; PrintMessage (3, "SwapImproveSurface "); (*testout) << "\n" << "Start SwapImproveSurface" << endl; @@ -1817,7 +1817,7 @@ void MeshOptimize3d :: SwapImproveSurface (Mesh & mesh, OPTIMIZEGOAL goal, int nsuround = hasbothpoints.Size(); int nsuroundother = hasbothpointsother.Size(); - Array < int > outerpoints(nsuround+1); + NgArray < int > outerpoints(nsuround+1); outerpoints[0] = sp1; for(int i=0; i outerpointsother; + NgArray < int > outerpointsother; if(nsuroundother > 0) { @@ -1988,8 +1988,8 @@ void MeshOptimize3d :: SwapImproveSurface (Mesh & mesh, OPTIMIZEGOAL goal, startpointsother = outerpointsother.Size(); - Array < Array < Element* > * > newelts(startpoints); - Array < Array < Element* > * > neweltsother(startpointsother); + NgArray < NgArray < Element* > * > newelts(startpoints); + NgArray < NgArray < Element* > * > neweltsother(startpointsother); double minbad = 1e50, minbadother = 1e50, currbad; int minpos = -1, minposother = -1; @@ -1998,7 +1998,7 @@ void MeshOptimize3d :: SwapImproveSurface (Mesh & mesh, OPTIMIZEGOAL goal, for(int i=0; i(2*(nsuround-1)); + newelts[i] = new NgArray (2*(nsuround-1)); for(int jj=0; jj face_index; + NgArray face_index; for(int k = 0; k(2*(nsuroundother)); + neweltsother[i] = new NgArray (2*(nsuroundother)); for(int jj=0; jj* > * idmaps = NULL); + const NgArray< NgArray* > * idmaps = NULL); void SwapImprove2 (Mesh & mesh, OPTIMIZEGOAL goal = OPT_QUALITY); double @@ -61,7 +61,7 @@ extern int WrongOrientation (const Mesh::T_POINTS & points, const Element & el); class MinFunctionSum : public MinFunction { protected: - Array functions; + NgArray functions; public: @@ -81,12 +81,12 @@ public: class PointFunction1 : public MinFunction { Mesh::T_POINTS & points; - const Array & faces; + const NgArray & faces; const MeshingParameters & mp; double h; public: PointFunction1 (Mesh::T_POINTS & apoints, - const Array & afaces, + const NgArray & afaces, const MeshingParameters & amp, double ah); diff --git a/libsrc/meshing/localh.cpp b/libsrc/meshing/localh.cpp index 83faadad..48919975 100644 --- a/libsrc/meshing/localh.cpp +++ b/libsrc/meshing/localh.cpp @@ -415,8 +415,8 @@ namespace netgen (*testout) << "inner = " << root->flags.pinner << " =?= " << testinner(Point3d(root->xmid[0], root->xmid[1], root->xmid[2])) << endl; - Array faceinds(nf); - Array faceboxes(nf); + NgArray faceinds(nf); + NgArray faceboxes(nf); for (int i = 1; i <= nf; i++) { @@ -432,8 +432,8 @@ namespace netgen void LocalH :: FindInnerBoxesRec2 (GradingBox * box, class AdFront3 * adfront, - Array & faceboxes, - Array & faceinds, int nfinbox) + NgArray & faceboxes, + NgArray & faceinds, int nfinbox) { if (!box) return; @@ -569,8 +569,8 @@ namespace netgen int nf = adfront->GetNFL(); - Array faceinds(nf); - Array > faceboxes(nf); + NgArray faceinds(nf); + NgArray > faceboxes(nf); for (int i = 0; i < nf; i++) { @@ -590,8 +590,8 @@ namespace netgen void LocalH :: FindInnerBoxesRec2 (GradingBox * box, class AdFront2 * adfront, - Array > & faceboxes, - Array & faceinds, int nfinbox) + NgArray > & faceboxes, + NgArray & faceinds, int nfinbox) { if (!box) return; @@ -735,7 +735,7 @@ namespace netgen } } - void LocalH :: GetInnerPoints (Array > & points) + void LocalH :: GetInnerPoints (NgArray > & points) { if (dimension == 2) { @@ -753,7 +753,7 @@ namespace netgen } - void LocalH :: GetOuterPoints (Array > & points) + void LocalH :: GetOuterPoints (NgArray > & points) { for (int i = 0; i < boxes.Size(); i++) if (!boxes[i]->flags.isinner && !boxes[i]->flags.cutboundary) diff --git a/libsrc/meshing/localh.hpp b/libsrc/meshing/localh.hpp index 361d506e..d15b11cd 100644 --- a/libsrc/meshing/localh.hpp +++ b/libsrc/meshing/localh.hpp @@ -72,7 +72,7 @@ namespace netgen /// double grading; /// - Array boxes; + NgArray boxes; /// Box<3> boundingbox; /// octree or quadtree @@ -119,10 +119,10 @@ namespace netgen void WidenRefinement (); /// get points in inner elements - void GetInnerPoints (Array > & points); + void GetInnerPoints (NgArray > & points); /// get points in outer closure - void GetOuterPoints (Array > & points); + void GetOuterPoints (NgArray > & points); /// void Convexify (); @@ -147,8 +147,8 @@ namespace netgen /// void FindInnerBoxesRec2 (GradingBox * box, class AdFront3 * adfront, - Array & faceboxes, - Array & finds, int nfinbox); + NgArray & faceboxes, + NgArray & finds, int nfinbox); @@ -158,8 +158,8 @@ namespace netgen /// void FindInnerBoxesRec2 (GradingBox * box, class AdFront2 * adfront, - Array > & faceboxes, - Array & finds, int nfinbox); + NgArray > & faceboxes, + NgArray & finds, int nfinbox); diff --git a/libsrc/meshing/meshclass.cpp b/libsrc/meshing/meshclass.cpp index f5dfc7de..a29fc662 100644 --- a/libsrc/meshing/meshclass.cpp +++ b/libsrc/meshing/meshclass.cpp @@ -637,7 +637,7 @@ namespace netgen if (ident -> GetMaxNr() > 0) { outfile << "identifications\n"; - Array identpairs; + NgArray identpairs; int cnt = 0; for (i = 1; i <= ident -> GetMaxNr(); i++) { @@ -1138,7 +1138,7 @@ namespace netgen if ( strcmp (str, "bcnames" ) == 0 ) { infile >> n; - Array bcnrs(n); + NgArray bcnrs(n); SetNBCNames(n); for ( i = 1; i <= n; i++ ) { @@ -1179,7 +1179,7 @@ namespace netgen if ( strcmp (str, "cd2names" ) == 0) { infile >> n; - Array cd2nrs(n); + NgArray cd2nrs(n); SetNCD2Names(n); for( i=1; i<=n; i++) { @@ -1891,7 +1891,7 @@ namespace netgen int ne = GetNE(); int nse = GetNSE(); - Array numonpoint(np); + NgArray numonpoint(np); numonpoint = 0; @@ -1933,7 +1933,7 @@ namespace netgen } - Array hasface(GetNFD()); + NgArray hasface(GetNFD()); int i; for (i = 1; i <= GetNFD(); i++) @@ -2533,7 +2533,7 @@ namespace netgen int i, j, k; PointIndex pi; const int large = 9999; - Array dist(GetNP()); + NgArray dist(GetNP()); dist = large; @@ -2666,7 +2666,7 @@ namespace netgen return 1e10; } - void Mesh :: SetMaxHDomain (const Array & mhd) + void Mesh :: SetMaxHDomain (const NgArray & mhd) { maxhdomain.SetSize(mhd.Size()); for (int i = 1; i <= mhd.Size(); i++) @@ -3003,7 +3003,7 @@ namespace netgen int nseg = GetNSeg(); int nse = GetNSE(); - Array normals(np); + NgArray normals(np); BitArray linepoint(np); linepoint.Clear(); @@ -3266,8 +3266,8 @@ namespace netgen { static Timer t("Mesh::Compress"); RegionTimer reg(t); - Array op2np(GetNP()); - Array hpoints; + NgArray op2np(GetNP()); + NgArray hpoints; BitArrayChar pused(GetNP()); /* @@ -3540,7 +3540,7 @@ namespace netgen Point3d pmin, pmax; GetBox (pmin, pmax); BoxTree<3> setree(pmin, pmax); - Array inters; + NgArray inters; bool overlap = 0; bool incons_layers = 0; @@ -4430,7 +4430,7 @@ namespace netgen Vec3d rhs, sol; const double eps = 1e-6; - Array loctrigs; + NgArray loctrigs; //SZ @@ -4963,7 +4963,7 @@ namespace netgen Vec3d rhs, sol; const double eps = 1.e-4; - Array loctets; + NgArray loctets; VolumeElement(element).GetTets (loctets); @@ -4994,8 +4994,8 @@ namespace netgen if (sol.X() >= -eps && sol.Y() >= -eps && sol.Z() >= -eps && sol.X() + sol.Y() + sol.Z() <= 1+eps) { - Array loctetsloc; - Array > pointsloc; + NgArray loctetsloc; + NgArray > pointsloc; VolumeElement(element).GetTetsLocal (loctetsloc); VolumeElement(element).GetNodesLocalNew (pointsloc); @@ -5027,7 +5027,7 @@ namespace netgen { if(index != -1) { - Array dummy(1); + NgArray dummy(1); dummy[0] = index; return GetElementOfPoint(p,lami,&dummy,build_searchtree,allowindex); } @@ -5040,7 +5040,7 @@ namespace netgen int Mesh :: GetElementOfPoint (const netgen::Point<3> & p, double lami[3], - const Array * const indices, + const NgArray * const indices, bool build_searchtree, const bool allowindex) const { @@ -5060,7 +5060,7 @@ namespace netgen if(ps_startelement != 0 && ps_startelement <= GetNSE() && PointContainedIn2DElement(p,lami,ps_startelement)) return ps_startelement; - Array locels; + NgArray locels; if (elementsearchtree || build_searchtree) { // update if necessary: @@ -5106,7 +5106,7 @@ namespace netgen if(ps_startelement != 0 && PointContainedIn3DElement(p,lami,ps_startelement)) return ps_startelement; - Array locels; + NgArray locels; if (elementsearchtree || build_searchtree) { // update if necessary: @@ -5183,7 +5183,7 @@ namespace netgen { if(index != -1) { - Array dummy(1); + NgArray dummy(1); dummy[0] = index; return GetSurfaceElementOfPoint(p,lami,&dummy,build_searchtree,allowindex); } @@ -5196,7 +5196,7 @@ namespace netgen int Mesh :: GetSurfaceElementOfPoint (const netgen::Point<3> & p, double lami[3], - const Array * const indices, + const NgArray * const indices, bool build_searchtree, const bool allowindex) const { @@ -5220,7 +5220,7 @@ namespace netgen return velement; } - Array faces; + NgArray faces; topology.GetElementFaces(velement,faces); //(*testout) << "faces " << faces << endl; @@ -5252,7 +5252,7 @@ namespace netgen } } - Array faces2; + NgArray faces2; topology.GetElementFaces(velement,faces2); /* cout << "no matching surf element" << endl @@ -5269,7 +5269,7 @@ namespace netgen void Mesh::GetIntersectingVolEls(const Point3d& p1, const Point3d& p2, - Array & locels) const + NgArray & locels) const { elementsearchtree->GetIntersecting (p1, p2, locels); } @@ -5394,7 +5394,7 @@ namespace netgen int np = GetNP(); BitArray usedp(np); - Array els_of_face; + NgArray els_of_face; fdi = 1; while (fdi <= GetNFD()) @@ -5568,7 +5568,7 @@ namespace netgen } } - void Mesh :: GetSurfaceElementsOfFace (int facenr, Array & sei) const + void Mesh :: GetSurfaceElementsOfFace (int facenr, NgArray & sei) const { static int timer = NgProfiler::CreateTimer ("GetSurfaceElementsOfFace"); NgProfiler::RegionTimer reg (timer); @@ -5792,7 +5792,7 @@ namespace netgen // } - // void Mesh :: GetIdentificationMap (int identnr, Array & identmap) const + // void Mesh :: GetIdentificationMap (int identnr, NgArray & identmap) const // { // int i, j; @@ -5815,7 +5815,7 @@ namespace netgen // } - // void Mesh :: GetIdentificationPairs (int identnr, Array & identpairs) const + // void Mesh :: GetIdentificationPairs (int identnr, NgArray & identpairs) const // { // int i, j; @@ -6242,16 +6242,16 @@ namespace netgen return defaultstring; } - void Mesh :: SetUserData(const char * id, Array & data) + void Mesh :: SetUserData(const char * id, NgArray & data) { if(userdata_int.Used(id)) delete userdata_int[id]; - Array * newdata = new Array(data); + NgArray * newdata = new NgArray(data); userdata_int.Set(id,newdata); } - bool Mesh :: GetUserData(const char * id, Array & data, int shift) const + bool Mesh :: GetUserData(const char * id, NgArray & data, int shift) const { if(userdata_int.Used(id)) { @@ -6267,16 +6267,16 @@ namespace netgen return false; } } - void Mesh :: SetUserData(const char * id, Array & data) + void Mesh :: SetUserData(const char * id, NgArray & data) { if(userdata_double.Used(id)) delete userdata_double[id]; - Array * newdata = new Array(data); + NgArray * newdata = new NgArray(data); userdata_double.Set(id,newdata); } - bool Mesh :: GetUserData(const char * id, Array & data, int shift) const + bool Mesh :: GetUserData(const char * id, NgArray & data, int shift) const { if(userdata_double.Used(id)) { diff --git a/libsrc/meshing/meshclass.hpp b/libsrc/meshing/meshclass.hpp index ecd4936a..78ea8035 100644 --- a/libsrc/meshing/meshclass.hpp +++ b/libsrc/meshing/meshclass.hpp @@ -24,9 +24,9 @@ namespace netgen { public: typedef ::netgen::T_POINTS T_POINTS; - typedef Array T_VOLELEMENTS; - // typedef Array T_SURFELEMENTS; - typedef Array T_SURFELEMENTS; + typedef NgArray T_VOLELEMENTS; + // typedef NgArray T_SURFELEMENTS; + typedef NgArray T_SURFELEMENTS; private: /// point coordinates @@ -36,13 +36,13 @@ namespace netgen NgMPI_Comm comm; /// line-segments at edges - Array segments; + NgArray segments; /// surface elements, 2d-inner elements T_SURFELEMENTS surfelements; /// volume elements T_VOLELEMENTS volelements; /// points will be fixed forever - Array lockedpoints; + NgArray lockedpoints; /// surface indices at boundary nodes @@ -55,9 +55,9 @@ namespace netgen INDEX_3_CLOSED_HASHTABLE * surfelementht; /// faces of rest-solid - Array openelements; + NgArray openelements; /// open segmenets for surface meshing - Array opensegments; + NgArray opensegments; @@ -70,32 +70,32 @@ namespace netgen /// double hmin; /// - Array maxhdomain; + NgArray maxhdomain; /** the face-index of the surface element maps into this table. */ - Array facedecoding; + NgArray facedecoding; /** the edge-index of the line element maps into this table. */ - Array edgedecoding; + NgArray edgedecoding; /// sub-domain materials - Array materials; + NgArray materials; /// labels for boundary conditions - Array bcnames; + NgArray bcnames; /// labels for co dim 2 bboundary conditions - Array cd2names; + NgArray cd2names; /// labels for co dim 3 bbboundary conditions - Array cd3names; + NgArray cd3names; /// Periodic surface, close surface, etc. identifications Identifications * ident; @@ -130,13 +130,13 @@ namespace netgen /// mesh access semaphors. NgMutex majormutex; - SymbolTable< Array* > userdata_int; - SymbolTable< Array* > userdata_double; + SymbolTable< NgArray* > userdata_int; + SymbolTable< NgArray* > userdata_double; - mutable Array< Point3d > pointcurves; - mutable Array pointcurves_startpoint; - mutable Array pointcurves_red,pointcurves_green,pointcurves_blue; + mutable NgArray< Point3d > pointcurves; + mutable NgArray pointcurves_startpoint; + mutable NgArray pointcurves_red,pointcurves_green,pointcurves_blue; /// start element for point search (GetElementOfPoint) @@ -170,18 +170,18 @@ namespace netgen public: // store coarse mesh before hp-refinement - Array * hpelements; + NgArray * hpelements; Mesh * coarsemesh; /// number of refinement levels int mglevels; /// refinement hierarchy - Array,PointIndex::BASE> mlbetweennodes; + NgArray,PointIndex::BASE> mlbetweennodes; /// parent element of volume element - Array mlparentelement; + NgArray mlparentelement; /// parent element of surface element - Array mlparentsurfaceelement; + NgArray mlparentsurfaceelement; @@ -262,13 +262,13 @@ namespace netgen Segment & operator[] (SegmentIndex si) { return segments[si]; } /* - const Array & LineSegments() const { return segments; } - Array & LineSegments() { return segments; } + const NgArray & LineSegments() const { return segments; } + NgArray & LineSegments() { return segments; } */ const auto & LineSegments() const { return segments; } auto & LineSegments() { return segments; } - Array pointelements; // only via python interface + NgArray pointelements; // only via python interface DLL_HEADER SurfaceElementIndex AddSurfaceElement (const Element2d & el); // write to pre-allocated container, thread-safe @@ -310,7 +310,7 @@ namespace netgen DLL_HEADER void RebuildSurfaceElementLists (); - DLL_HEADER void GetSurfaceElementsOfFace (int facenr, Array & sei) const; + DLL_HEADER void GetSurfaceElementsOfFace (int facenr, NgArray & sei) const; DLL_HEADER ElementIndex AddVolumeElement (const Element & el); // write to pre-allocated container, thread-safe @@ -429,7 +429,7 @@ namespace netgen /// DLL_HEADER double MaxHDomain (int dom) const; /// - DLL_HEADER void SetMaxHDomain (const Array & mhd); + DLL_HEADER void SetMaxHDomain (const NgArray & mhd); /// DLL_HEADER double GetH (const Point3d & p) const; /// @@ -525,9 +525,9 @@ namespace netgen /// void ImproveMeshJacobianOnSurface (const MeshingParameters & mp, const BitArray & usepoint, - const Array< Vec<3>* > & nv, + const NgArray< Vec<3>* > & nv, OPTIMIZEGOAL goal = OPT_QUALITY, - const Array< Array* > * idmaps = NULL); + const NgArray< NgArray* > * idmaps = NULL); /** free nodes in environment of openelements for optimiztion @@ -580,7 +580,7 @@ namespace netgen const bool allowindex = true) const; int GetElementOfPoint (const netgen::Point<3> & p, double * lami, - const Array * const indices, + const NgArray * const indices, bool build_searchtree = 0, const bool allowindex = true) const; int GetSurfaceElementOfPoint (const netgen::Point<3> & p, @@ -590,13 +590,13 @@ namespace netgen const bool allowindex = true) const; int GetSurfaceElementOfPoint (const netgen::Point<3> & p, double * lami, - const Array * const indices, + const NgArray * const indices, bool build_searchtree = 0, const bool allowindex = true) const; /// give list of vol elements which are int the box(p1,p2) void GetIntersectingVolEls(const Point3d& p1, const Point3d& p2, - Array & locels) const; + NgArray & locels) const; /// int AddFaceDescriptor(const FaceDescriptor& fd) @@ -687,9 +687,9 @@ namespace netgen // } // /// - // void GetIdentificationMap (int identnr, Array & identmap) const; + // void GetIdentificationMap (int identnr, NgArray & identmap) const; // /// - // void GetIdentificationPairs (int identnr, Array & identpairs) const; + // void GetIdentificationPairs (int identnr, NgArray & identpairs) const; // /// // int GetMaxIdentificationNr () const // { @@ -804,13 +804,13 @@ namespace netgen } /// - void SetUserData(const char * id, Array & data); + void SetUserData(const char * id, NgArray & data); /// - bool GetUserData(const char * id, Array & data, int shift = 0) const; + bool GetUserData(const char * id, NgArray & data, int shift = 0) const; /// - void SetUserData(const char * id, Array & data); + void SetUserData(const char * id, NgArray & data); /// - bool GetUserData(const char * id, Array & data, int shift = 0) const; + bool GetUserData(const char * id, NgArray & data, int shift = 0) const; /// friend void OptimizeRestart (Mesh & mesh3d); @@ -833,8 +833,8 @@ namespace netgen /// distributes the master-mesh to local meshes void Distribute (); - void Distribute (Array & volume_weights, Array & surface_weights, - Array & segment_weights); + void Distribute (NgArray & volume_weights, NgArray & surface_weights, + NgArray & segment_weights); /// find connection to parallel meshes @@ -844,32 +844,32 @@ namespace netgen // void FindExchangeFaces (); /// use metis to decompose master mesh - void ParallelMetis (); // Array & neloc ); - void ParallelMetis (Array & volume_weights, Array & surface_weights, - Array & segment_weights); + void ParallelMetis (); // NgArray & neloc ); + void ParallelMetis (NgArray & volume_weights, NgArray & surface_weights, + NgArray & segment_weights); - void PartHybridMesh (); // Array & neloc ); - void PartDualHybridMesh (); // Array & neloc ); - void PartDualHybridMesh2D (); // ( Array & neloc ); + void PartHybridMesh (); // NgArray & neloc ); + void PartDualHybridMesh (); // NgArray & neloc ); + void PartDualHybridMesh2D (); // ( NgArray & neloc ); /// send mesh from master to local procs void SendRecvMesh (); /// send mesh to parallel machine, keep global mesh at master - void SendMesh ( ) const; // Mesh * mastermesh, Array & neloc) const; + void SendMesh ( ) const; // Mesh * mastermesh, NgArray & neloc) const; /// loads a mesh sent from master processor void ReceiveParallelMesh (); - Array vol_partition; - Array surf_partition; - Array seg_partition; + NgArray vol_partition; + NgArray surf_partition; + NgArray seg_partition; #else void Distribute () {} void SendRecvMesh () {} - void Distribute (Array & volume_weights, Array & surface_weights, - Array & segment_weights){ } + void Distribute (NgArray & volume_weights, NgArray & surface_weights, + NgArray & segment_weights){ } #endif diff --git a/libsrc/meshing/meshfunc.cpp b/libsrc/meshing/meshfunc.cpp index e3fab9b8..b3630df6 100644 --- a/libsrc/meshing/meshfunc.cpp +++ b/libsrc/meshing/meshfunc.cpp @@ -19,7 +19,7 @@ namespace netgen int oldne; int meshed; - Array connectednodes; + NgArray connectednodes; if (!mesh3d.HasLocalHFunction()) mesh3d.CalcLocalH(mp.grading); @@ -237,7 +237,7 @@ namespace netgen // Meshing3 meshing(rulefile); Meshing3 meshing(tetrules); - Array glob2loc(mesh3d.GetNP()); + NgArray glob2loc(mesh3d.GetNP()); glob2loc = -1; for (PointIndex pi = mesh3d.Points().Begin(); pi < mesh3d.Points().End(); pi++) diff --git a/libsrc/meshing/meshing2.cpp b/libsrc/meshing/meshing2.cpp index d51c358a..91b008e3 100644 --- a/libsrc/meshing/meshing2.cpp +++ b/libsrc/meshing/meshing2.cpp @@ -7,11 +7,11 @@ namespace netgen // global variable for visualization -// static Array locpoints; -// static Array legalpoints; -// static Array plainpoints; -// static Array plainzones; -// static Array loclines; +// static NgArray locpoints; +// static NgArray legalpoints; +// static NgArray plainpoints; +// static NgArray plainzones; +// static NgArray loclines; // // static int geomtrig; // //static const char * rname; // static int cntelem, trials, nfaces; @@ -175,9 +175,9 @@ namespace netgen } void Meshing2 :: - GetChartBoundary (Array & points, - Array & points3d, - Array & lines, double h) const + GetChartBoundary (NgArray & points, + NgArray & points3d, + NgArray & lines, double h) const { points.SetSize (0); points3d.SetSize (0); @@ -208,13 +208,13 @@ namespace netgen NgProfiler::StartTimer (ts1); - Array pindex, lindex; - Array delpoints, dellines; + NgArray pindex, lindex; + NgArray delpoints, dellines; - Array upgeominfo; // unique info - Array mpgeominfo; // multiple info + NgArray upgeominfo; // unique info + NgArray mpgeominfo; // multiple info - Array locelements; + NgArray locelements; int z1, z2, oldnp(-1); bool found; @@ -230,11 +230,11 @@ namespace netgen double h, his, hshould; - Array locpoints; - Array legalpoints; - Array plainpoints; - Array plainzones; - Array loclines; + NgArray locpoints; + NgArray legalpoints; + NgArray plainpoints; + NgArray plainzones; + NgArray loclines; int cntelem = 0, trials = 0, nfaces = 0; int oldnl = 0; int qualclass; @@ -245,8 +245,8 @@ namespace netgen BoxTree<3> surfeltree (boundingbox.PMin(), boundingbox.PMax()); - Array intersecttrias; - Array critpoints; + NgArray intersecttrias; + NgArray critpoints; // test for doubled edges //INDEX_2_HASHTABLE doubleedge(300000); @@ -256,14 +256,14 @@ namespace netgen StartMesh(); - Array chartboundpoints; - Array chartboundpoints3d; - Array chartboundlines; + NgArray chartboundpoints; + NgArray chartboundpoints3d; + NgArray chartboundlines; // illegal points: points with more then 50 elements per node int maxlegalpoint(-1), maxlegalline(-1); - Array trigsonnode; - Array illegalpoint; + NgArray trigsonnode; + NgArray illegalpoint; trigsonnode.SetSize (mesh.GetNP()); illegalpoint.SetSize (mesh.GetNP()); @@ -293,7 +293,7 @@ namespace netgen } } */ - Array seia; + NgArray seia; mesh.GetSurfaceElementsOfFace (facenr, seia); for (int i = 0; i < seia.Size(); i++) { diff --git a/libsrc/meshing/meshing2.hpp b/libsrc/meshing/meshing2.hpp index 4e145964..a23e06d2 100644 --- a/libsrc/meshing/meshing2.hpp +++ b/libsrc/meshing/meshing2.hpp @@ -31,9 +31,9 @@ class Meshing2 /// the current advancing front AdFront2 * adfront; /// rules for mesh generation - Array rules; + NgArray rules; /// statistics - Array ruleused, canuse, foundmap; + NgArray ruleused, canuse, foundmap; /// Box<3> boundingbox; /// @@ -126,21 +126,21 @@ protected: /* get (projected) boundary of current chart */ - virtual void GetChartBoundary (Array & points, - Array & points3d, - Array & lines, double p) const; + virtual void GetChartBoundary (NgArray & points, + NgArray & points3d, + NgArray & lines, double p) const; virtual double Area () const; /** Applies 2D rules. Tests all 2D rules */ - int ApplyRules (Array & lpoints, - Array & legalpoints, + int ApplyRules (NgArray & lpoints, + NgArray & legalpoints, int maxlegalpoint, - Array & llines, + NgArray & llines, int maxlegelline, - Array & elements, Array & dellines, + NgArray & elements, NgArray & dellines, int tolerance, const MeshingParameters & mp); diff --git a/libsrc/meshing/meshing3.cpp b/libsrc/meshing/meshing3.cpp index 1aa99c83..5030470f 100644 --- a/libsrc/meshing/meshing3.cpp +++ b/libsrc/meshing/meshing3.cpp @@ -76,8 +76,8 @@ Meshing3 :: ~Meshing3 () /* // was war das ???? -static double CalcLocH (const Array & locpoints, - const Array & locfaces, +static double CalcLocH (const NgArray & locpoints, + const NgArray & locfaces, double h) { return h; @@ -181,16 +181,16 @@ GenerateMesh (Mesh & mesh, const MeshingParameters & mp) // NgProfiler::RegionTimer reg (meshing3_timer); - Array locpoints; // local points - Array locfaces; // local faces - Array pindex; // mapping from local to front point numbering - Array allowpoint; // point is allowed ? - Array findex; // mapping from local to front face numbering + NgArray locpoints; // local points + NgArray locfaces; // local faces + NgArray pindex; // mapping from local to front point numbering + NgArray allowpoint; // point is allowed ? + NgArray findex; // mapping from local to front face numbering //INDEX_2_HASHTABLE connectedpairs(100); // connecgted pairs for prism meshing - Array plainpoints; // points in reference coordinates - Array delpoints, delfaces; // points and lines to be deleted - Array locelements; // new generated elements + NgArray plainpoints; // points in reference coordinates + NgArray delpoints, delfaces; // points and lines to be deleted + NgArray locelements; // new generated elements int j, oldnp, oldnf; int found; @@ -211,10 +211,10 @@ GenerateMesh (Mesh & mesh, const MeshingParameters & mp) // for star-shaped domain meshing - Array grouppoints; - Array groupfaces; - Array grouppindex; - Array groupfindex; + NgArray grouppoints; + NgArray groupfaces; + NgArray grouppindex; + NgArray groupfindex; float minerr; @@ -223,10 +223,10 @@ GenerateMesh (Mesh & mesh, const MeshingParameters & mp) // int giveup = 0; - Array tempnewpoints; - Array tempnewfaces; - Array tempdelfaces; - Array templocelements; + NgArray tempnewpoints; + NgArray tempnewfaces; + NgArray tempdelfaces; + NgArray templocelements; stat.h = mp.maxh; @@ -774,9 +774,9 @@ void Meshing3 :: BlockFill (Mesh & mesh, double gh) PrintMessage (5, "n1 = ", n1, " n2 = ", n2, " n3 = ", n3); - Array inner(n); - Array pointnr(n); - Array frontpointnr(n); + NgArray inner(n); + NgArray pointnr(n); + NgArray frontpointnr(n); // initialize inner to 1 @@ -1107,7 +1107,7 @@ void Meshing3 :: BlockFillLocalH (Mesh & mesh, PrintMessage (3, "blockfill local h"); - Array > npoints; + NgArray > npoints; adfront -> CreateTrees(); diff --git a/libsrc/meshing/meshing3.hpp b/libsrc/meshing/meshing3.hpp index 2acd209d..65b153b9 100644 --- a/libsrc/meshing/meshing3.hpp +++ b/libsrc/meshing/meshing3.hpp @@ -21,11 +21,11 @@ class Meshing3 /// current state of front AdFront3 * adfront; /// 3d generation rules - Array rules; + NgArray rules; /// counts how often a rule is used - Array ruleused, canuse, foundmap; + NgArray ruleused, canuse, foundmap; /// describes, why a rule is not applied - Array problems; + NgArray problems; /// tolerance criterion double tolfak; public: @@ -42,12 +42,12 @@ public: MESHING3_RESULT GenerateMesh (Mesh & mesh, const MeshingParameters & mp); /// - int ApplyRules (Array & lpoints, - Array & allowpoint, - Array & lfaces, INDEX lfacesplit, + int ApplyRules (NgArray & lpoints, + NgArray & allowpoint, + NgArray & lfaces, INDEX lfacesplit, INDEX_2_HASHTABLE & connectedpairs, - Array & elements, - Array & delfaces, int tolerance, + NgArray & elements, + NgArray & delfaces, int tolerance, double sloppy, int rotind1, float & retminerr); diff --git a/libsrc/meshing/meshtool.cpp b/libsrc/meshing/meshtool.cpp index b807cb1a..74d5283a 100644 --- a/libsrc/meshing/meshtool.cpp +++ b/libsrc/meshing/meshtool.cpp @@ -129,7 +129,7 @@ namespace netgen void MeshQuality2d (const Mesh & mesh) { int ncl = 20, cl; - Array incl(ncl); + NgArray incl(ncl); INDEX i; SurfaceElementIndex sei; double qual; @@ -540,7 +540,7 @@ namespace netgen /* - double CalcVolume (const Array & points, + double CalcVolume (const NgArray & points, const Element & el) { Vec3d v1 = points.Get(el.PNum(2)) - @@ -554,8 +554,8 @@ namespace netgen } */ - double CalcVolume (const Array & points, - const Array & elements) + double CalcVolume (const NgArray & points, + const NgArray & elements) { double vol; Vec3d v1, v2, v3; @@ -574,11 +574,11 @@ namespace netgen - void MeshQuality3d (const Mesh & mesh, Array * inclass) + void MeshQuality3d (const Mesh & mesh, NgArray * inclass) { int ncl = 20; signed int cl; - Array incl(ncl); + NgArray incl(ncl); INDEX i; double qual; double sum = 0; @@ -697,7 +697,7 @@ namespace netgen #ifdef OLD void Save2DMesh ( const Mesh & mesh2d, - const Array * splines, + const NgArray * splines, ostream & outfile) { diff --git a/libsrc/meshing/meshtool.hpp b/libsrc/meshing/meshtool.hpp index 1da22bb0..4bfac0e3 100644 --- a/libsrc/meshing/meshtool.hpp +++ b/libsrc/meshing/meshtool.hpp @@ -7,7 +7,7 @@ extern void MeshQuality2d (const Mesh & mesh); /// extern void MeshQuality3d (const Mesh & mesh, - Array * inclass = NULL); + NgArray * inclass = NULL); /// extern void SaveEdges (const Mesh & mesh, @@ -23,17 +23,17 @@ extern void SaveSurfaceMesh (const Mesh & mesh, /// extern void Save2DMesh ( const Mesh & mesh2d, - const Array * splines, + const NgArray * splines, ostream & outfile); */ class Surface; /// extern void SaveVolumeMesh ( - const Array & points, - const Array & elements, - const Array & volelements, - const Array & surfaces, + const NgArray & points, + const NgArray & elements, + const NgArray & volelements, + const NgArray & surfaces, char * filename); /// @@ -61,13 +61,13 @@ extern double CalcTetBadnessGrad (const Point3d & p1, const Point3d & p2, /** Calculates volume of an element. The volume of the tetrahedron el is computed */ -// extern double CalcVolume (const Array & points, +// extern double CalcVolume (const NgArray & points, // const Element & el); /** The total volume of all elements is computed. This function calculates the volume of the mesh */ -extern double CalcVolume (const Array & points, - const Array & elements); +extern double CalcVolume (const NgArray & points, + const NgArray & elements); /// extern int CheckSurfaceMesh (const Mesh & mesh); diff --git a/libsrc/meshing/meshtype.cpp b/libsrc/meshing/meshtype.cpp index 5eaa02d0..f32714c5 100644 --- a/libsrc/meshing/meshtype.cpp +++ b/libsrc/meshing/meshtype.cpp @@ -398,8 +398,8 @@ namespace netgen - Array ipdtrig; - Array ipdquad; + NgArray ipdtrig; + NgArray ipdquad; int Element2d :: GetNIP () const @@ -445,7 +445,7 @@ namespace netgen } void Element2d :: - GetTransformation (int ip, const Array & points, + GetTransformation (int ip, const NgArray & points, DenseMatrix & trans) const { int np = GetNP(); @@ -664,7 +664,7 @@ namespace netgen void Element2d :: - GetPointMatrix (const Array & points, + GetPointMatrix (const NgArray & points, DenseMatrix & pmat) const { int np = GetNP(); @@ -689,7 +689,7 @@ namespace netgen - double Element2d :: CalcJacobianBadness (const Array & points) const + double Element2d :: CalcJacobianBadness (const NgArray & points) const { int i, j; int nip = GetNIP(); @@ -733,7 +733,7 @@ namespace netgen }; double Element2d :: - CalcJacobianBadnessDirDeriv (const Array & points, + CalcJacobianBadnessDirDeriv (const NgArray & points, int pi, Vec2d & dir, double & dd) const { if (typ == QUAD) @@ -1283,7 +1283,7 @@ namespace netgen - void Element :: GetTets (Array & locels) const + void Element :: GetTets (NgArray & locels) const { GetTetsLocal (locels); int i, j; @@ -1292,7 +1292,7 @@ namespace netgen locels.Elem(i).PNum(j) = PNum ( locels.Elem(i).PNum(j) ); } - void Element :: GetTetsLocal (Array & locels) const + void Element :: GetTetsLocal (NgArray & locels) const { int i, j; locels.SetSize(0); @@ -1400,7 +1400,7 @@ namespace netgen #ifdef OLD - void Element :: GetNodesLocal (Array & points) const + void Element :: GetNodesLocal (NgArray & points) const { const static double tetpoints[4][3] = { { 0, 0, 0 }, @@ -1500,7 +1500,7 @@ namespace netgen - void Element :: GetNodesLocalNew (Array > & points) const + void Element :: GetNodesLocalNew (NgArray > & points) const { const static double tetpoints[4][3] = { @@ -1617,7 +1617,7 @@ namespace netgen - void Element :: GetSurfaceTriangles (Array & surftrigs) const + void Element :: GetSurfaceTriangles (NgArray & surftrigs) const { static int tet4trigs[][3] = { { 2, 3, 4 }, @@ -1730,8 +1730,8 @@ namespace netgen - Array< shared_ptr < IntegrationPointData > > ipdtet; - Array< shared_ptr < IntegrationPointData > > ipdtet10; + NgArray< shared_ptr < IntegrationPointData > > ipdtet; + NgArray< shared_ptr < IntegrationPointData > > ipdtet10; @@ -2650,7 +2650,7 @@ namespace netgen } - void Identifications :: GetMap (int identnr, Array & identmap, bool symmetric) const + void Identifications :: GetMap (int identnr, NgArray & identmap, bool symmetric) const { identmap.SetSize (mesh.GetNP()); identmap = 0; @@ -2688,7 +2688,7 @@ namespace netgen void Identifications :: GetPairs (int identnr, - Array & identpairs) const + NgArray & identpairs) const { identpairs.SetSize(0); diff --git a/libsrc/meshing/meshtype.hpp b/libsrc/meshing/meshtype.hpp index a2f76986..aae6c710 100644 --- a/libsrc/meshing/meshtype.hpp +++ b/libsrc/meshing/meshtype.hpp @@ -343,7 +343,7 @@ namespace netgen - typedef Array T_POINTS; + typedef NgArray T_POINTS; @@ -533,7 +533,7 @@ namespace netgen int GetNIP () const; void GetIntegrationPoint (int ip, Point2d & p, double & weight) const; - void GetTransformation (int ip, const Array & points, + void GetTransformation (int ip, const NgArray & points, class DenseMatrix & trans) const; void GetTransformation (int ip, class DenseMatrix & pmat, class DenseMatrix & trans) const; @@ -548,16 +548,16 @@ namespace netgen void GetDShapeNew (const Point<2,T> & p, class MatrixFixWidth<2,T> & dshape) const; /// matrix 2 * np - void GetPointMatrix (const Array & points, + void GetPointMatrix (const NgArray & points, class DenseMatrix & pmat) const; void ComputeIntegrationPointData () const; - double CalcJacobianBadness (const Array & points) const; + double CalcJacobianBadness (const NgArray & points) const; double CalcJacobianBadness (const T_POINTS & points, const Vec<3> & n) const; - double CalcJacobianBadnessDirDeriv (const Array & points, + double CalcJacobianBadnessDirDeriv (const NgArray & points, int pi, Vec2d & dir, double & dd) const; @@ -824,15 +824,15 @@ namespace netgen void Invert (); /// split into 4 node tets - void GetTets (Array & locels) const; + void GetTets (NgArray & locels) const; /// split into 4 node tets, local point nrs - void GetTetsLocal (Array & locels) const; + void GetTetsLocal (NgArray & locels) const; /// returns coordinates of nodes - // void GetNodesLocal (Array > & points) const; - void GetNodesLocalNew (Array > & points) const; + // void GetNodesLocal (NgArray > & points) const; + void GetNodesLocalNew (NgArray > & points) const; /// split surface into 3 node trigs - void GetSurfaceTriangles (Array & surftrigs) const; + void GetSurfaceTriangles (NgArray & surftrigs) const; /// get number of 'integration points' @@ -1290,7 +1290,7 @@ namespace netgen MeshSizePoint & operator= (const MeshSizePoint &) = default; MeshSizePoint & operator= (MeshSizePoint &&) = default; }; - Array meshsize_points; + NgArray meshsize_points; void (*render_function)(bool) = NULL; void Render(bool blocking = false) @@ -1429,7 +1429,7 @@ namespace netgen /// sorted by identification nr TABLE idpoints_table; - Array type; + NgArray type; /// number of identifications (or, actually used identifications ?) int maxidentnr; @@ -1475,7 +1475,7 @@ namespace netgen } /// - void GetMap (int identnr, Array & identmap, bool symmetric = false) const; + void GetMap (int identnr, NgArray & identmap, bool symmetric = false) const; /// ID_TYPE GetType(int identnr) const { @@ -1492,7 +1492,7 @@ namespace netgen } /// - void GetPairs (int identnr, Array & identpairs) const; + void GetPairs (int identnr, NgArray & identpairs) const; /// int GetMaxNr () const { return maxidentnr; } diff --git a/libsrc/meshing/msghandler.cpp b/libsrc/meshing/msghandler.cpp index abb7a20f..191384f5 100644 --- a/libsrc/meshing/msghandler.cpp +++ b/libsrc/meshing/msghandler.cpp @@ -112,8 +112,8 @@ void PrintTime(const MyStr& s1, const MyStr& s2, const MyStr& s3, const MyStr& s } -static Array msgstatus_stack(0); -static Array threadpercent_stack(0); +static NgArray msgstatus_stack(0); +static NgArray threadpercent_stack(0); static MyStr msgstatus = ""; diff --git a/libsrc/meshing/netrule2.cpp b/libsrc/meshing/netrule2.cpp index ace0d0f8..a26209a6 100644 --- a/libsrc/meshing/netrule2.cpp +++ b/libsrc/meshing/netrule2.cpp @@ -39,7 +39,7 @@ void netrule :: SetFreeZoneTransformation (const Vector & devp, int tolclass) { oldutofreearea_i[tolclass-1] -> Mult (devp, devfree); - Array & fzi = *freezone_i[tolclass-1]; + NgArray & fzi = *freezone_i[tolclass-1]; for (int i = 0; i < fzs; i++) { transfreezone[i].X() = fzi[i].X() + devfree[2*i]; diff --git a/libsrc/meshing/netrule3.cpp b/libsrc/meshing/netrule3.cpp index de0e35e4..753abbb0 100644 --- a/libsrc/meshing/netrule3.cpp +++ b/libsrc/meshing/netrule3.cpp @@ -84,7 +84,7 @@ void vnetrule :: SetFreeZoneTransformation (const Vector & allp, int tolclass) for (fs = 1; fs <= freesets.Size(); fs++) { - Array & freesetfaces = *freefaces.Get(fs); + NgArray & freesetfaces = *freefaces.Get(fs); DenseMatrix & freesetinequ = *freefaceinequ.Get(fs); for (i = 1; i <= freesetfaces.Size(); i++) @@ -142,9 +142,9 @@ int vnetrule :: ConvexFreeZone () const { const DenseMatrix & freesetinequ = *freefaceinequ.Get(fs); - // const Array & freeset = *freesets.Get(fs); - const Array & freesetedges = *freeedges.Get(fs); - // const Array & freesetfaces = *freefaces.Get(fs); + // const NgArray & freeset = *freesets.Get(fs); + const NgArray & freesetedges = *freeedges.Get(fs); + // const NgArray & freesetfaces = *freefaces.Get(fs); for (i = 1; i <= freesetedges.Size(); i++) { @@ -175,7 +175,7 @@ int vnetrule :: IsInFreeZone (const Point3d & p) const for (fs = 1; fs <= freesets.Size(); fs++) { inthis = 1; - Array & freesetfaces = *freefaces.Get(fs); + NgArray & freesetfaces = *freefaces.Get(fs); DenseMatrix & freesetinequ = *freefaceinequ.Get(fs); for (i = 1; i <= freesetfaces.Size() && inthis; i++) @@ -195,7 +195,7 @@ int vnetrule :: IsInFreeZone (const Point3d & p) const int vnetrule :: IsTriangleInFreeZone (const Point3d & p1, const Point3d & p2, const Point3d & p3, - const Array & pi, int newone) + const NgArray & pi, int newone) { int fs; int infreeset, cannot = 0; @@ -218,7 +218,7 @@ int vnetrule :: IsTriangleInFreeZone (const Point3d & p1, for (fs = 1; fs <= freesets.Size(); fs++) { - const Array & freeseti = *freesets.Get(fs); + const NgArray & freeseti = *freesets.Get(fs); for (i = 1; i <= 3; i++) { pfi2.Elem(i) = 0; @@ -239,7 +239,7 @@ int vnetrule :: IsTriangleInFreeZone (const Point3d & p1, int vnetrule :: IsTriangleInFreeSet (const Point3d & p1, const Point3d & p2, const Point3d & p3, int fs, - const Array & pi, int newone) + const NgArray & pi, int newone) { int i, ii; Vec3d n; @@ -251,13 +251,13 @@ int vnetrule :: IsTriangleInFreeSet (const Point3d & p1, const Point3d & p2, double hpx, hpy, hpz, v1x, v1y, v1z, v2x, v2y, v2z; int act1, act2, act3, it; int cntout; - Array activefaces; + NgArray activefaces; int isin; // MARK(triinfz); - Array & freesetfaces = *freefaces.Get(fs); + NgArray & freesetfaces = *freefaces.Get(fs); DenseMatrix & freesetinequ = *freefaceinequ.Get(fs); @@ -575,7 +575,7 @@ int vnetrule :: IsTriangleInFreeSet (const Point3d & p1, const Point3d & p2, case 3: trivec = (p3 - p2); break; } - Array lpi(freezonepi.Size()); + NgArray lpi(freezonepi.Size()); for (i = 1; i <= lpi.Size(); i++) lpi.Elem(i) = 0; lpi.Elem(pi1) = 1; @@ -614,7 +614,7 @@ int vnetrule :: IsTriangleInFreeSet (const Point3d & p1, const Point3d & p2, { // MARK(triinfz3); - Array lpi(freezonepi.Size()); + NgArray lpi(freezonepi.Size()); for (i = 1; i <= lpi.Size(); i++) lpi.Elem(i) = 0; @@ -862,7 +862,7 @@ int vnetrule :: IsQuadInFreeZone (const Point3d & p1, const Point3d & p2, const Point3d & p3, const Point3d & p4, - const Array & pi, int newone) + const NgArray & pi, int newone) { int fs; int infreeset, cannot = 0; @@ -885,7 +885,7 @@ int vnetrule :: IsQuadInFreeZone (const Point3d & p1, for (fs = 1; fs <= freesets.Size(); fs++) { - const Array & freeseti = *freesets.Get(fs); + const NgArray & freeseti = *freesets.Get(fs); for (i = 1; i <= 4; i++) { pfi2.Elem(i) = 0; @@ -905,7 +905,7 @@ int vnetrule :: IsQuadInFreeZone (const Point3d & p1, int vnetrule :: IsQuadInFreeSet (const Point3d & p1, const Point3d & p2, const Point3d & p3, const Point3d & p4, - int fs, const Array & pi, int newone) + int fs, const NgArray & pi, int newone) { int i; @@ -985,9 +985,9 @@ float vnetrule :: CalcPointDist (int pi, const Point3d & p) const int vnetrule :: TestOk () const { - Array cntpused(points.Size()); - Array edge1, edge2; - Array delf(faces.Size()); + NgArray cntpused(points.Size()); + NgArray edge1, edge2; + NgArray delf(faces.Size()); int i, j, k; int pi1, pi2; int found; diff --git a/libsrc/meshing/parallelmesh.cpp b/libsrc/meshing/parallelmesh.cpp index cbbc8d45..1e576c9e 100644 --- a/libsrc/meshing/parallelmesh.cpp +++ b/libsrc/meshing/parallelmesh.cpp @@ -70,7 +70,7 @@ namespace netgen void Mesh :: SendMesh () const { - Array sendrequests; + NgArray sendrequests; NgMPI_Comm comm = GetCommunicator(); int id = comm.Rank(); @@ -91,7 +91,7 @@ namespace netgen PrintMessage ( 3, "Sending nr of elements"); - Array num_els_on_proc(ntasks); + NgArray num_els_on_proc(ntasks); num_els_on_proc = 0; for (ElementIndex ei = 0; ei < GetNE(); ei++) // num_els_on_proc[(*this)[ei].GetPartition()]++; @@ -107,7 +107,7 @@ namespace netgen PrintMessage ( 3, "Building vertex/proc mapping"); - Array num_sels_on_proc(ntasks); + NgArray num_sels_on_proc(ntasks); num_sels_on_proc = 0; for (SurfaceElementIndex ei = 0; ei < GetNSE(); ei++) // num_sels_on_proc[(*this)[ei].GetPartition()]++; @@ -118,7 +118,7 @@ namespace netgen // sels_of_proc.Add ( (*this)[ei].GetPartition(), ei); sels_of_proc.Add (surf_partition[ei], ei); - Array num_segs_on_proc(ntasks); + NgArray num_segs_on_proc(ntasks); num_segs_on_proc = 0; for (SegmentIndex ei = 0; ei < GetNSeg(); ei++) // num_segs_on_proc[(*this)[ei].GetPartition()]++; @@ -148,8 +148,8 @@ namespace netgen **/ /** First, we build tables for vertex identification. **/ - Array per_pairs; - Array pp2; + NgArray per_pairs; + NgArray pp2; auto & idents = GetIdentifications(); bool has_periodic = false; for (int idnr = 1; idnr < idents.GetMaxNr()+1; idnr++) @@ -159,7 +159,7 @@ namespace netgen idents.GetPairs(idnr, pp2); per_pairs.Append(pp2); } - Array npvs(GetNV()); + NgArray npvs(GetNV()); npvs = 0; for (int k = 0; k < per_pairs.Size(); k++) { npvs[per_pairs[k].I1()]++; @@ -178,7 +178,7 @@ namespace netgen /** The same table as per_verts, but TRANSITIVE!! **/ auto iterate_per_verts_trans = [&](auto f){ - Array allvs; + NgArray allvs; for (int k = PointIndex::BASE; k < GetNV()+PointIndex::BASE; k++) { allvs.SetSize(0); @@ -214,9 +214,9 @@ namespace netgen } /** Now we build the vertex-data to send to the workers. **/ - Array vert_flag (GetNV()); - Array num_procs_on_vert (GetNV()); - Array num_verts_on_proc (ntasks); + NgArray vert_flag (GetNV()); + NgArray num_procs_on_vert (GetNV()); + NgArray num_verts_on_proc (ntasks); num_verts_on_proc = 0; num_procs_on_vert = 0; auto iterate_vertices = [&](auto f) { @@ -305,7 +305,7 @@ namespace netgen int numv = verts.Size(); MPI_Datatype newtype; - Array blocklen (numv); + NgArray blocklen (numv); blocklen = 1; MPI_Type_indexed (numv, &blocklen[0], @@ -318,7 +318,7 @@ namespace netgen sendrequests.Append (request); } - Array num_distpnums(ntasks); + NgArray num_distpnums(ntasks); num_distpnums = 0; @@ -334,7 +334,7 @@ namespace netgen **/ PrintMessage ( 3, "Sending Vertices - identifications"); int maxidentnr = idents.GetMaxNr(); - Array ppd_sizes(ntasks); + NgArray ppd_sizes(ntasks); ppd_sizes = 1 + 2*maxidentnr; for (int idnr = 1; idnr < idents.GetMaxNr()+1; idnr++) { @@ -378,7 +378,7 @@ namespace netgen } } } - Array req_per; + NgArray req_per; for(int dest = 1; dest < ntasks; dest++) req_per.Append(MyMPI_ISend(pp_data[dest], dest, MPI_TAG_MESH+1, comm)); MPI_Waitall(req_per.Size(), &req_per[0], MPI_STATUS_IGNORE); @@ -414,7 +414,7 @@ namespace netgen PrintMessage ( 3, "Sending elements" ); - Array elarraysize (ntasks); + NgArray elarraysize (ntasks); elarraysize = 0; for ( int ei = 1; ei <= GetNE(); ei++) { @@ -445,7 +445,7 @@ namespace netgen PrintMessage ( 3, "Sending Face Descriptors" ); - Array fddata (6 * GetNFD()); + NgArray fddata (6 * GetNFD()); for (int fdi = 1; fdi <= GetNFD(); fdi++) { fddata[6*fdi-6] = GetFaceDescriptor(fdi).SurfNr(); @@ -464,12 +464,12 @@ namespace netgen PrintMessage ( 3, "Sending Surface elements" ); // build sel-identification size_t nse = GetNSE(); - Array ided_sel(nse); + NgArray ided_sel(nse); ided_sel = -1; bool has_ided_sels = false; if(GetNE() && has_periodic) //we can only have identified surf-els if we have vol-els (right?) { - Array os1, os2; + NgArray os1, os2; for(SurfaceElementIndex sei = 0; sei < GetNSE(); sei++) { if(ided_sel[sei]!=-1) continue; @@ -520,7 +520,7 @@ namespace netgen } } }; - Array nlocsel(ntasks), bufsize(ntasks); + NgArray nlocsel(ntasks), bufsize(ntasks); nlocsel = 0; bufsize = 1; iterate_sels([&](SurfaceElementIndex sei, const Element2d & sel, int dest){ @@ -549,8 +549,8 @@ namespace netgen /** Segments **/ PrintMessage ( 3, "Sending Edge Segments"); auto iterate_segs1 = [&](auto f) { - Array osegs1, osegs2, osegs_both; - Array type1, type2; + NgArray osegs1, osegs2, osegs_both; + NgArray type1, type2; for(SegmentIndex segi = 0; segi < GetNSeg(); segi++) { const Segment & seg = (*this)[segi]; @@ -603,7 +603,7 @@ namespace netgen } } }; - Array per_seg_size(GetNSeg()); + NgArray per_seg_size(GetNSeg()); per_seg_size = 0; iterate_segs1([&](SegmentIndex segi1, SegmentIndex segi2) { per_seg_size[segi1]++; }); @@ -612,7 +612,7 @@ namespace netgen { per_seg.Add(segi1, segi2); }); // make per_seg transitive auto iterate_per_seg_trans = [&](auto f){ - Array allsegs; + NgArray allsegs; for (SegmentIndex segi = 0; segi < GetNSeg(); segi++) { allsegs.SetSize(0); @@ -636,17 +636,17 @@ namespace netgen f(segi, allsegs); } }; - iterate_per_seg_trans([&](SegmentIndex segi, Array & segs){ + iterate_per_seg_trans([&](SegmentIndex segi, NgArray & segs){ for (int j = 0; j < segs.Size(); j++) per_seg_size[segi] = segs.Size(); }); TABLE per_seg_trans(per_seg_size); - iterate_per_seg_trans([&](SegmentIndex segi, Array & segs){ + iterate_per_seg_trans([&](SegmentIndex segi, NgArray & segs){ for (int j = 0; j < segs.Size(); j++) per_seg_trans.Add(segi, segs[j]); }); // build segment data - Array dests; + NgArray dests; auto iterate_segs2 = [&](auto f) { for (SegmentIndex segi = 0; segi nloc_seg(ntasks); + NgArray nloc_seg(ntasks); // bufsize = 1; //was originally this - why?? bufsize = 0; nloc_seg = 0; @@ -721,7 +721,7 @@ namespace netgen for (int k = 0; k < nnames[3]; k++) func(cd3names[k]); }; // sizes of names - Array name_sizes(tot_nn); + NgArray name_sizes(tot_nn); tot_nn = 0; iterate_names([&](auto ptr) { name_sizes[tot_nn++] = (ptr==NULL) ? 0 : ptr->size(); }); for( int k = 1; k < ntasks; k++) @@ -729,7 +729,7 @@ namespace netgen // names int strs = 0; iterate_names([&](auto ptr) { strs += (ptr==NULL) ? 0 : ptr->size(); }); - Array compiled_names(strs); + NgArray compiled_names(strs); strs = 0; iterate_names([&](auto ptr) { if (ptr==NULL) return; @@ -751,8 +751,8 @@ namespace netgen self.points = T_POINTS(0); self.surfelements = T_SURFELEMENTS(0); self.volelements = T_VOLELEMENTS(0); - self.segments = Array(0); - self.lockedpoints = Array(0); + self.segments = NgArray(0); + self.lockedpoints = NgArray(0); auto cleanup_ptr = [](auto & ptr) { if (ptr != nullptr) { delete ptr; @@ -763,12 +763,12 @@ namespace netgen cleanup_ptr(self.boundaryedges); cleanup_ptr(self.segmentht); cleanup_ptr(self.surfelementht); - self.openelements = Array(0); - self.opensegments = Array(0); + self.openelements = NgArray(0); + self.opensegments = NgArray(0); self.numvertices = 0; - self.mlbetweennodes = Array,PointIndex::BASE> (0); - self.mlparentelement = Array(0); - self.mlparentsurfaceelement = Array(0); + self.mlbetweennodes = NgArray,PointIndex::BASE> (0); + self.mlparentelement = NgArray(0); + self.mlparentsurfaceelement = NgArray(0); self.curvedelems = new CurvedElements (self); self.clusters = new AnisotropicClusters (self); self.ident = new Identifications (self); @@ -816,7 +816,7 @@ namespace netgen // receive vertices NgProfiler::StartTimer (timer_pts); - Array verts; + NgArray verts; MyMPI_Recv (verts, 0, MPI_TAG_MESH+1, comm); int numvert = verts.Size(); @@ -839,7 +839,7 @@ namespace netgen MPI_Status status; MPI_Recv( &points[1], numvert, mptype, 0, MPI_TAG_MESH+1, comm, &status); - Array pp_data; + NgArray pp_data; MyMPI_Recv(pp_data, 0, MPI_TAG_MESH+1, comm); int maxidentnr = pp_data[0]; @@ -863,7 +863,7 @@ namespace netgen } } - Array dist_pnums; + NgArray dist_pnums; MyMPI_Recv (dist_pnums, 0, MPI_TAG_MESH+1, comm); for (int hi = 0; hi < dist_pnums.Size(); hi += 3) @@ -874,7 +874,7 @@ namespace netgen *testout << "got " << numvert << " vertices" << endl; { - Array elarray; + NgArray elarray; MyMPI_Recv (elarray, 0, MPI_TAG_MESH+2, comm); NgProfiler::RegionTimer reg(timer_els); @@ -895,7 +895,7 @@ namespace netgen } { - Array fddata; + NgArray fddata; MyMPI_Recv (fddata, 0, MPI_TAG_MESH+3, comm); for (int i = 0; i < fddata.Size(); i += 6) { @@ -909,7 +909,7 @@ namespace netgen { NgProfiler::RegionTimer reg(timer_sels); - Array selbuf; + NgArray selbuf; MyMPI_Recv ( selbuf, 0, MPI_TAG_MESH+4, comm); @@ -941,7 +941,7 @@ namespace netgen { - Array segmbuf; + NgArray segmbuf; MyMPI_Recv ( segmbuf, 0, MPI_TAG_MESH+5, comm); Segment seg; @@ -994,12 +994,12 @@ namespace netgen cd3names.SetSize(nnames[3]); int tot_nn = nnames[0] + nnames[1] + nnames[2] + nnames[3]; - Array name_sizes(tot_nn); + NgArray name_sizes(tot_nn); MPI_Recv(&name_sizes[0], tot_nn, MPI_INT, 0, MPI_TAG_MESH+6, comm, MPI_STATUS_IGNORE); int tot_size = 0; for (int k = 0; k < tot_nn; k++) tot_size += name_sizes[k]; - Array compiled_names(tot_size); + NgArray compiled_names(tot_size); MPI_Recv(&(compiled_names[0]), tot_size, MPI_CHAR, 0, MPI_TAG_MESH+6, comm, MPI_STATUS_IGNORE); tot_nn = tot_size = 0; @@ -1088,7 +1088,7 @@ namespace netgen idx_t ne = GetNE() + GetNSE() + GetNSeg(); idx_t nn = GetNP(); - Array eptr, eind; + NgArray eptr, eind; for (int i = 0; i < GetNE(); i++) { eptr.Append (eind.Size()); @@ -1111,7 +1111,7 @@ namespace netgen eind.Append (el[1]-1); } eptr.Append (eind.Size()); - Array epart(ne), npart(nn); + NgArray epart(ne), npart(nn); idxtype nparts = GetCommunicator().Size()-1; @@ -1163,7 +1163,7 @@ namespace netgen // surface elements attached to volume elements - Array boundarypoints (GetNP()); + NgArray boundarypoints (GetNP()); boundarypoints = false; if(GetDimension() == 3) @@ -1183,7 +1183,7 @@ namespace netgen // Build Pnt2Element table, boundary points only - Array cnt(GetNP()); + NgArray cnt(GetNP()); cnt = 0; auto loop_els_2d = [&](auto f) { @@ -1350,7 +1350,7 @@ namespace netgen // distribute the mesh to the slave processors // call it only for the master ! - void Mesh :: Distribute (Array & volume_weights , Array & surface_weights, Array & segment_weights) + void Mesh :: Distribute (NgArray & volume_weights , NgArray & surface_weights, NgArray & segment_weights) { NgMPI_Comm comm = GetCommunicator(); int id = comm.Rank(); @@ -1378,7 +1378,7 @@ namespace netgen #ifdef METIS5 - void Mesh :: ParallelMetis (Array & volume_weights , Array & surface_weights, Array & segment_weights) + void Mesh :: ParallelMetis (NgArray & volume_weights , NgArray & surface_weights, NgArray & segment_weights) { PrintMessage (3, "call metis 5 with weights ..."); @@ -1392,7 +1392,7 @@ namespace netgen idx_t ne = GetNE() + GetNSE() + GetNSeg(); idx_t nn = GetNP(); - Array eptr, eind , nwgt; + NgArray eptr, eind , nwgt; for (int i = 0; i < GetNE(); i++) { eptr.Append (eind.Size()); @@ -1442,7 +1442,7 @@ namespace netgen } eptr.Append (eind.Size()); - Array epart(ne), npart(nn); + NgArray epart(ne), npart(nn); idxtype nparts = GetCommunicator().Size()-1; vol_partition.SetSize(GetNE()); @@ -1555,7 +1555,7 @@ namespace netgen // uniform (TET) mesh, JS int npe = VolumeElement(1).GetNP(); - Array elmnts(ne*npe); + NgArray elmnts(ne*npe); int etype; if (elementtype == TET) @@ -1572,7 +1572,7 @@ namespace netgen int nparts = ntasks-1; int ncommon = 3; int edgecut; - Array epart(ne), npart(nn); + NgArray epart(ne), npart(nn); // if ( ntasks == 1 ) // { @@ -1604,7 +1604,7 @@ namespace netgen cout << "call metis(5)_PartMeshDual ... " << endl; // idx_t options[METIS_NOPTIONS]; - Array eptr(ne+1); + NgArray eptr(ne+1); for (int j = 0; j < ne+1; j++) eptr[j] = 4*j; @@ -1671,7 +1671,7 @@ namespace netgen xadj = new idxtype[nn+1]; part = new idxtype[nn]; - Array cnt(nn+1); + NgArray cnt(nn+1); cnt = 0; for ( int edge = 1; edge <= nedges; edge++ ) @@ -1714,7 +1714,7 @@ namespace netgen cout << "currently not supported (metis5), A" << endl; #endif - Array nodesinpart(ntasks); + NgArray nodesinpart(ntasks); vol_partition.SetSize(ne); for ( int el = 1; el <= ne; el++ ) { @@ -1744,7 +1744,7 @@ namespace netgen } - void Mesh :: PartDualHybridMesh ( ) // Array & neloc ) + void Mesh :: PartDualHybridMesh ( ) // NgArray & neloc ) { #ifdef METIS int ne = GetNE(); @@ -1764,15 +1764,15 @@ namespace netgen int edgecut; idxtype * part; - Array facevolels1(nfaces), facevolels2(nfaces); + NgArray facevolels1(nfaces), facevolels2(nfaces); facevolels1 = -1; facevolels2 = -1; - Array elfaces; + NgArray elfaces; xadj = new idxtype[ne+1]; part = new idxtype[ne]; - Array cnt(ne+1); + NgArray cnt(ne+1); cnt = 0; for ( int el=1; el <= ne; el++ ) @@ -1832,7 +1832,7 @@ namespace netgen NgProfiler::StopTimer (timermetis); - Array nodesinpart(ntasks); + NgArray nodesinpart(ntasks); vol_partition.SetSize(ne); for ( int el = 1; el <= ne; el++ ) @@ -1870,11 +1870,11 @@ namespace netgen idxtype ne = GetNSE(); int nv = GetNV(); - Array xadj(ne+1); - Array adjacency(ne*4); + NgArray xadj(ne+1); + NgArray adjacency(ne*4); // first, build the vertex 2 element table: - Array cnt(nv); + NgArray cnt(nv); cnt = 0; for (SurfaceElementIndex sei = 0; sei < GetNSE(); sei++) for (int j = 0; j < (*this)[sei].GetNP(); j++) @@ -1888,7 +1888,7 @@ namespace netgen // find all neighbour elements int cntnb = 0; - Array marks(ne); // to visit each neighbour just once + NgArray marks(ne); // to visit each neighbour just once marks = -1; for (SurfaceElementIndex sei = 0; sei < ne; sei++) { @@ -1928,7 +1928,7 @@ namespace netgen idxtype nparts = ntasks - 1; idxtype edgecut; - Array part(ne); + NgArray part(ne); for ( int el = 0; el < ne; el++ ) BubbleSort (adjacency.Range (xadj[el], xadj[el+1])); diff --git a/libsrc/meshing/paralleltop.cpp b/libsrc/meshing/paralleltop.cpp index 53d78dfb..fb4b9794 100644 --- a/libsrc/meshing/paralleltop.cpp +++ b/libsrc/meshing/paralleltop.cpp @@ -130,19 +130,19 @@ namespace netgen if ( id == 0 ) { - Array*> sendarrays(ntasks); + NgArray*> sendarrays(ntasks); for (int dest = 1; dest < ntasks; dest++) - sendarrays[dest] = new Array; + sendarrays[dest] = new NgArray; - Array edges, faces; + NgArray edges, faces; for (int el = 1; el <= mesh.GetNE(); el++) { topology.GetElementFaces (el, faces); topology.GetElementEdges (el, edges); const Element & volel = mesh.VolumeElement (el); - // Array & sendarray = *sendarrays[volel.GetPartition()]; - Array & sendarray = *sendarrays[mesh.vol_partition[el-1]]; + // NgArray & sendarray = *sendarrays[volel.GetPartition()]; + NgArray & sendarray = *sendarrays[mesh.vol_partition[el-1]]; for ( int i = 0; i < edges.Size(); i++ ) sendarray.Append (edges[i]); @@ -154,15 +154,15 @@ namespace netgen { topology.GetSurfaceElementEdges (el, edges); const Element2d & surfel = mesh.SurfaceElement (el); - // Array & sendarray = *sendarrays[surfel.GetPartition()]; - Array & sendarray = *sendarrays[mesh.surf_partition[el-1]]; + // NgArray & sendarray = *sendarrays[surfel.GetPartition()]; + NgArray & sendarray = *sendarrays[mesh.surf_partition[el-1]]; for ( int i = 0; i < edges.Size(); i++ ) sendarray.Append (edges[i]); sendarray.Append (topology.GetSurfaceElementFace (el)); } - Array sendrequests; + NgArray sendrequests; for (int dest = 1; dest < ntasks; dest++) sendrequests.Append (MyMPI_ISend (*sendarrays[dest], dest, MPI_TAG_MESH+10, comm)); MPI_Waitall (sendrequests.Size(), &sendrequests[0], MPI_STATUS_IGNORE); @@ -174,12 +174,12 @@ namespace netgen else { - Array recvarray; + NgArray recvarray; MyMPI_Recv (recvarray, 0, MPI_TAG_MESH+10, comm); int ii = 0; - Array faces, edges; + NgArray faces, edges; for (int volel = 1; volel <= mesh.GetNE(); volel++) { @@ -248,7 +248,7 @@ namespace netgen const MeshTopology & topology = mesh.GetTopology(); - Array cnt_send(ntasks-1); + NgArray cnt_send(ntasks-1); // update new vertices after mesh-refinement @@ -322,7 +322,7 @@ namespace netgen TABLE send_verts(cnt_send); - Array loc2exchange(mesh.GetNV()); + NgArray loc2exchange(mesh.GetNV()); for (int dest = 1; dest < ntasks; dest++) if (dest != id) { @@ -388,7 +388,7 @@ namespace netgen } } - Array sendarray, recvarray; + NgArray sendarray, recvarray; // cout << "UpdateCoarseGrid - edges" << endl; // static int timerv = NgProfiler::CreateTimer ("UpdateCoarseGrid - ex vertices"); @@ -436,7 +436,7 @@ namespace netgen } - Array loc2exchange(mesh.GetNV()); + NgArray loc2exchange(mesh.GetNV()); for (int dest = 1; dest < ntasks; dest++) { loc2exchange = -1; @@ -510,7 +510,7 @@ namespace netgen if (mesh.GetDimension() == 3) { NgProfiler::StartTimer (timerf); - Array verts; + NgArray verts; // exchange faces cnt_send = 0; @@ -539,7 +539,7 @@ namespace netgen for (int & c : cnt_send) c*=3; TABLE send_faces(cnt_send); - Array loc2exchange(mesh.GetNV()); + NgArray loc2exchange(mesh.GetNV()); for (int dest = 1; dest < ntasks; dest++) if (dest != id) { @@ -628,7 +628,7 @@ namespace netgen /* - Array glob2loc; + NgArray glob2loc; int maxface = 0; for (int face = 1; face <= nfa; face++) @@ -642,7 +642,7 @@ namespace netgen glob2loc[GetGlobalFaceNum(loc)] = loc; cnt_send = 0; - Array verts; + NgArray verts; for (int face = 1; face <= nfa; face++) { topology.GetFaceVertices (face, verts); diff --git a/libsrc/meshing/paralleltop.hpp b/libsrc/meshing/paralleltop.hpp index cb4b41ab..dc125cd6 100644 --- a/libsrc/meshing/paralleltop.hpp +++ b/libsrc/meshing/paralleltop.hpp @@ -17,8 +17,8 @@ namespace netgen TABLE loc2distvert, loc2distedge, loc2distface; - Array glob_vert, glob_edge, glob_face; - Array glob_el, glob_surfel, glob_segm; + NgArray glob_vert, glob_edge, glob_face; + NgArray glob_el, glob_surfel, glob_segm; bool is_updated; @@ -77,7 +77,7 @@ namespace netgen distfacenums[i] = loc2distface[locfacenum-1][i]; } - void GetDistantFaceNums (int locfacenum, Array & distfacenums ) const + void GetDistantFaceNums (int locfacenum, NgArray & distfacenums ) const { distfacenums = loc2distface[locfacenum-1]; } @@ -88,7 +88,7 @@ namespace netgen distedgenums[i] = loc2distedge[locedgenum-1][i]; } - void GetDistantEdgeNums (int locedgenum, Array & distedgenums ) const + void GetDistantEdgeNums (int locedgenum, NgArray & distedgenums ) const { distedgenums = loc2distedge[locedgenum-1]; } diff --git a/libsrc/meshing/parser2.cpp b/libsrc/meshing/parser2.cpp index 2e8530b8..3f4892e6 100644 --- a/libsrc/meshing/parser2.cpp +++ b/libsrc/meshing/parser2.cpp @@ -429,7 +429,7 @@ void netrule :: LoadRule (istream & ist) { char ok; int minn; - Array pnearness (noldp); + NgArray pnearness (noldp); for (i = 1; i <= pnearness.Size(); i++) pnearness.Elem(i) = 1000; @@ -480,8 +480,8 @@ void netrule :: LoadRule (istream & ist) for (int k = 0; k < oldutofreearea.Width(); k++) mati(j,k) = lam1 * oldutofreearea(j,k) + (1 - lam1) * oldutofreearealimit(j,k); - freezone_i[i] = new Array (freezone.Size()); - Array & fzi = *freezone_i[i]; + freezone_i[i] = new NgArray (freezone.Size()); + NgArray & fzi = *freezone_i[i]; for (int j = 0; j < freezone.Size(); j++) fzi[j] = freezonelimit[j] + lam1 * (freezone[j] - freezonelimit[j]); } diff --git a/libsrc/meshing/parser3.cpp b/libsrc/meshing/parser3.cpp index a5c6fd4b..5f5a6365 100644 --- a/libsrc/meshing/parser3.cpp +++ b/libsrc/meshing/parser3.cpp @@ -53,8 +53,8 @@ void LoadVMatrixLine (istream & ist, DenseMatrix & m, int line) int vnetrule :: NeighbourTrianglePoint (const threeint & t1, const threeint & t2) const { - Array tr1(3); - Array tr2(3); + NgArray tr1(3); + NgArray tr2(3); tr1.Elem(1)=t1.i1; tr1.Elem(2)=t1.i2; tr1.Elem(3)=t1.i3; @@ -472,7 +472,7 @@ void vnetrule :: LoadRule (istream & ist) else if (strcmp (buf, "freeset") == 0) { - freesets.Append (new Array); + freesets.Append (new NgArray); ist >> ch; @@ -706,7 +706,7 @@ void vnetrule :: LoadRule (istream & ist) if (freesets.Size() == 0) { - freesets.Append (new Array); + freesets.Append (new NgArray); for (i = 1; i <= freezone.Size(); i++) freesets.Elem(1)->Append(i); } @@ -736,10 +736,10 @@ void vnetrule :: LoadRule (istream & ist) for (fs = 1; fs <= freesets.Size(); fs++) { - freefaces.Append (new Array); + freefaces.Append (new NgArray); - Array & freeset = *freesets.Elem(fs); - Array & freesetfaces = *freefaces.Last(); + NgArray & freeset = *freesets.Elem(fs); + NgArray & freesetfaces = *freefaces.Last(); for (ii1 = 1; ii1 <= freeset.Size(); ii1++) for (ii2 = 1; ii2 <= freeset.Size(); ii2++) @@ -785,7 +785,7 @@ void vnetrule :: LoadRule (istream & ist) { int minn; - // Array pnearness (noldp); + // NgArray pnearness (noldp); pnearness.SetSize (noldp); for (i = 1; i <= pnearness.Size(); i++) @@ -874,11 +874,11 @@ void vnetrule :: LoadRule (istream & ist) //Table of edges: for (fs = 1; fs <= freesets.Size(); fs++) { - freeedges.Append (new Array); + freeedges.Append (new NgArray); - // Array & freeset = *freesets.Get(fs); - Array & freesetedges = *freeedges.Last(); - Array & freesetfaces = *freefaces.Get(fs); + // NgArray & freeset = *freesets.Get(fs); + NgArray & freesetedges = *freeedges.Last(); + NgArray & freesetfaces = *freefaces.Get(fs); int k,l; INDEX ind; diff --git a/libsrc/meshing/python_mesh.cpp b/libsrc/meshing/python_mesh.cpp index d2946e04..e027bb0d 100644 --- a/libsrc/meshing/python_mesh.cpp +++ b/libsrc/meshing/python_mesh.cpp @@ -41,12 +41,12 @@ namespace netgen template void ExportArray (py::module &m) { - using TA = Array; + using TA = NgArray; string name = string("Array_") + typeid(T).name(); - py::class_>(m, name.c_str()) - .def ("__len__", [] ( Array &self ) { return self.Size(); } ) + py::class_>(m, name.c_str()) + .def ("__len__", [] ( NgArray &self ) { return self.Size(); } ) .def ("__getitem__", - FunctionPointer ([](Array & self, TIND i) -> T& + FunctionPointer ([](NgArray & self, TIND i) -> T& { if (i < BASE || i >= BASE+self.Size()) throw py::index_error(); @@ -108,7 +108,7 @@ DLL_HEADER void ExportNetgenMeshing(py::module &m) .def("Min", [](NgMPI_Comm & c, size_t x) { return MyMPI_AllReduceNG(x, MPI_MIN, c); }) .def("Max", [](NgMPI_Comm & c, size_t x) { return MyMPI_AllReduceNG(x, MPI_MAX, c); }) .def("SubComm", [](NgMPI_Comm & c, std::vector proc_list) { - Array procs(proc_list.size()); + NgArray procs(proc_list.size()); for (int i = 0; i < procs.Size(); i++) procs[i] = proc_list[i]; if (!procs.Contains(c.Rank())) @@ -609,7 +609,7 @@ DLL_HEADER void ExportNetgenMeshing(py::module &m) } istream * infile; - Array buf; // for distributing geometry! + NgArray buf; // for distributing geometry! int strs; if( id == 0) { @@ -655,9 +655,9 @@ DLL_HEADER void ExportNetgenMeshing(py::module &m) bool endfile = false; int n, dummy; - Array segment_weights; - Array surface_weights; - Array volume_weights; + NgArray segment_weights; + NgArray surface_weights; + NgArray volume_weights; while (weightsfile.good() && !endfile) { @@ -725,7 +725,7 @@ DLL_HEADER void ExportNetgenMeshing(py::module &m) if (WriteUserFormat (format, self, /* *self.GetGeometry(), */ filename)) { string err = string ("nothing known about format")+format; - Array names, extensions; + NgArray names, extensions; RegisterUserFormats (names, extensions); err += "\navailable formats are:\n"; for (auto name : names) @@ -738,18 +738,18 @@ DLL_HEADER void ExportNetgenMeshing(py::module &m) .def_property("dim", &Mesh::GetDimension, &Mesh::SetDimension) .def("Elements3D", - static_cast&(Mesh::*)()> (&Mesh::VolumeElements), + static_cast&(Mesh::*)()> (&Mesh::VolumeElements), py::return_value_policy::reference) .def("Elements2D", - static_cast&(Mesh::*)()> (&Mesh::SurfaceElements), + static_cast&(Mesh::*)()> (&Mesh::SurfaceElements), py::return_value_policy::reference) .def("Elements1D", - static_cast&(Mesh::*)()> (&Mesh::LineSegments), + static_cast&(Mesh::*)()> (&Mesh::LineSegments), py::return_value_policy::reference) - .def("Elements0D", FunctionPointer([] (Mesh & self) -> Array& + .def("Elements0D", FunctionPointer([] (Mesh & self) -> NgArray& { return self.pointelements; } ), @@ -849,7 +849,7 @@ DLL_HEADER void ExportNetgenMeshing(py::module &m) .def ("CalcLocalH", &Mesh::CalcLocalH) .def ("SetMaxHDomain", [] (Mesh& self, py::list maxhlist) { - Array maxh; + NgArray maxh; for(auto el : maxhlist) maxh.Append(py::cast(el)); self.SetMaxHDomain(maxh); diff --git a/libsrc/meshing/refine.cpp b/libsrc/meshing/refine.cpp index 54c9f592..ca7f737b 100644 --- a/libsrc/meshing/refine.cpp +++ b/libsrc/meshing/refine.cpp @@ -37,7 +37,7 @@ namespace netgen // new version with consistent ordering across sub-domains - Array parents; + NgArray parents; for (SegmentIndex si = 0; si < mesh.GetNSeg(); si++) { const Segment & el = mesh[si]; @@ -109,7 +109,7 @@ namespace netgen PrintMessage (5, "have points"); - Array par_nr(parents.Size()); + NgArray par_nr(parents.Size()); for (int i = 0; i < par_nr.Size(); i++) par_nr[i] = i; QuickSort (parents, par_nr); @@ -121,13 +121,13 @@ namespace netgen } mesh.SetNP(mesh.GetNV() + parents.Size()); - Array pointset(mesh.GetNP()); + NgArray pointset(mesh.GetNP()); pointset = false; PrintMessage (5, "sorting complete"); // refine edges - Array epgi; + NgArray epgi; int oldns = mesh.GetNSeg(); for (SegmentIndex si = 0; si < oldns; si++) @@ -176,7 +176,7 @@ namespace netgen PrintMessage (5, "have 1d elements"); // refine surface elements - Array surfgi (8*mesh.GetNP()); + NgArray surfgi (8*mesh.GetNP()); for (int i = PointIndex::BASE; i < surfgi.Size()+PointIndex::BASE; i++) surfgi[i].trignum = -1; @@ -711,7 +711,7 @@ namespace netgen // update identification tables for (int i = 1; i <= mesh.GetIdentifications().GetMaxNr(); i++) { - Array identmap; + NgArray identmap; mesh.GetIdentifications().GetMap (i, identmap); for (int j = 1; j <= between.GetNBags(); j++) @@ -754,8 +754,8 @@ namespace netgen cout << "WARNING: " << wrongels << " with wrong orientation found" << endl; int np = mesh.GetNP(); - Array > should(np); - Array > can(np); + NgArray > should(np); + NgArray > can(np); for (int i = 1; i <= np; i++) { should.Elem(i) = can.Elem(i) = mesh.Point(i); diff --git a/libsrc/meshing/ruler2.cpp b/libsrc/meshing/ruler2.cpp index a6d5410f..ae9f267a 100644 --- a/libsrc/meshing/ruler2.cpp +++ b/libsrc/meshing/ruler2.cpp @@ -5,7 +5,7 @@ namespace netgen { - static double CalcElementBadness (const Array & points, + static double CalcElementBadness (const NgArray & points, const Element2d & elem) { // badness = sqrt(3) /36 * circumference^2 / area - 1 + @@ -45,13 +45,13 @@ namespace netgen - int Meshing2 ::ApplyRules (Array & lpoints, - Array & legalpoints, + int Meshing2 ::ApplyRules (NgArray & lpoints, + NgArray & legalpoints, int maxlegalpoint, - Array & llines1, + NgArray & llines1, int maxlegalline, - Array & elements, - Array & dellines, int tolerance, + NgArray & elements, + NgArray & dellines, int tolerance, const MeshingParameters & mp) { static int timer = NgProfiler::CreateTimer ("meshing2::ApplyRules"); @@ -135,8 +135,8 @@ namespace netgen // resort lines after lnearness - Array llines(llines1.Size()); - Array sortlines(llines1.Size()); + NgArray llines(llines1.Size()); + NgArray sortlines(llines1.Size()); int lnearness_class[MAX_NEARNESS]; for (int j = 0; j < MAX_NEARNESS; j++) diff --git a/libsrc/meshing/ruler2.hpp b/libsrc/meshing/ruler2.hpp index afbe6b98..0341faf2 100644 --- a/libsrc/meshing/ruler2.hpp +++ b/libsrc/meshing/ruler2.hpp @@ -23,33 +23,33 @@ private: /// char * name; /// - Array points; + NgArray points; /// - Array lines; + NgArray lines; /// - Array freezone, freezonelimit; + NgArray freezone, freezonelimit; /// - Array*> freezone_i; + NgArray*> freezone_i; /// - Array transfreezone; + NgArray transfreezone; /// - Array dellines; + NgArray dellines; /// - Array elements; + NgArray elements; /// - Array tolerances, linetolerances; + NgArray tolerances, linetolerances; /// - Array orientations; + NgArray orientations; /// DenseMatrix oldutonewu, oldutofreearea, oldutofreearealimit; /// - Array oldutofreearea_i; + NgArray oldutofreearea_i; /// MatrixFixWidth<3> freesetinequ; /// - Array linevecs; + NgArray linevecs; /// int noldp, noldl; @@ -57,7 +57,7 @@ private: float fzminx, fzmaxx, fzminy, fzmaxy; /// topological distance of line to base element - Array lnearness; + NgArray lnearness; public: @@ -96,9 +96,9 @@ public: /// int GetDelLine (int i) const { return dellines.Get(i); } /// - const Array & GetDelLines() const { return dellines; } + const NgArray & GetDelLines() const { return dellines; } /// - void GetFreeZone (Array & afreearea); + void GetFreeZone (NgArray & afreearea); /// double CalcPointDist (int pi, const Point2d & p) const @@ -144,7 +144,7 @@ public: /// int ConvexFreeZone () const; /// - const Array & GetTransFreeZone () { return transfreezone; } + const NgArray & GetTransFreeZone () { return transfreezone; } /// int GetPointNr (int ln, int endp) const { return lines.Get(ln).I(endp); } diff --git a/libsrc/meshing/ruler3.cpp b/libsrc/meshing/ruler3.cpp index 10fa5e69..42f87a22 100644 --- a/libsrc/meshing/ruler3.cpp +++ b/libsrc/meshing/ruler3.cpp @@ -8,7 +8,7 @@ extern double minother; extern double minwithoutother; - static double CalcElementBadness (const Array & points, + static double CalcElementBadness (const NgArray & points, const Element & elem) { double vol, l, l4, l5, l6; @@ -49,13 +49,13 @@ extern double minwithoutother; int Meshing3 :: ApplyRules ( - Array & lpoints, // in: local points, out: old+new local points - Array & allowpoint, // in: 2 .. it is allowed to use pointi, 1..will be allowed later, 0..no means - Array & lfaces, // in: local faces, out: old+new local faces + NgArray & lpoints, // in: local points, out: old+new local points + NgArray & allowpoint, // in: 2 .. it is allowed to use pointi, 1..will be allowed later, 0..no means + NgArray & lfaces, // in: local faces, out: old+new local faces INDEX lfacesplit, // for local faces in outer radius INDEX_2_HASHTABLE & connectedpairs, // connected pairs for prism-meshing - Array & elements, // out: new elements - Array & delfaces, // out: face indices of faces to delete + NgArray & elements, // out: new elements + NgArray & delfaces, // out: face indices of faces to delete int tolerance, // quality class: 1 best double sloppy, // quality strength int rotind1, // how to rotate base element @@ -78,7 +78,7 @@ int Meshing3 :: ApplyRules int loktestmode; - Array pused; // point is already mapped, number of uses + NgArray pused; // point is already mapped, number of uses ArrayMem fused; // face is already mapped ArrayMem pmap; // map of reference point to local point ArrayMem pfixed; // point mapped by face-map @@ -88,13 +88,13 @@ int Meshing3 :: ApplyRules INDEX_2_CLOSED_HASHTABLE ledges(100); // edges in local environment ArrayMem tempnewpoints; - Array tempnewfaces; + NgArray tempnewfaces; ArrayMem tempdelfaces; - Array tempelements; + NgArray tempelements; ArrayMem triboxes; // bounding boxes of local faces - Array pnearness; - Array fnearness; + NgArray pnearness; + NgArray fnearness; static int cnt = 0; cnt++; @@ -650,7 +650,7 @@ int Meshing3 :: ApplyRules if (loktestmode) { - const Array & fz = rule->GetTransFreeZone(); + const NgArray & fz = rule->GetTransFreeZone(); (*testout) << "Freezone: " << endl; for (int i = 1; i <= fz.Size(); i++) (*testout) << fz.Get(i) << endl; @@ -685,7 +685,7 @@ int Meshing3 :: ApplyRules for (int i = 1; i <= lfaces.Size() && ok; i++) { - static Array lpi(4); + static NgArray lpi(4); if (!fused.Get(i)) { diff --git a/libsrc/meshing/ruler3.hpp b/libsrc/meshing/ruler3.hpp index fcbf8f59..91ee4653 100644 --- a/libsrc/meshing/ruler3.hpp +++ b/libsrc/meshing/ruler3.hpp @@ -13,33 +13,33 @@ private: /// name of rule char * name; /// point coordinates in reference position - Array points; + NgArray points; /// old and new faces in reference numbering - Array faces; + NgArray faces; /// additional edges of rule - Array edges; + NgArray edges; /// points of freezone in reference coordinates - Array freezone; + NgArray freezone; /// points of freezone in reference coordinates if tolcalss to infty - Array freezonelimit; + NgArray freezonelimit; /// point index, if point equal to mappoint, otherwise 0 - Array freezonepi; + NgArray freezonepi; /// faces of each convex part of freezone - Array*> freefaces; + NgArray*> freefaces; /// set of points of each convex part of freezone - Array*> freesets; + NgArray*> freesets; /// points of transformed freezone - Array transfreezone; + NgArray transfreezone; /// edges of each convex part of freezone - Array*> freeedges; + NgArray*> freeedges; /// face numbers to be deleted - Array delfaces; + NgArray delfaces; /// elements to be generated - Array elements; + NgArray elements; /// tolerances for points and faces (used ??) - Array tolerances, linetolerances; + NgArray tolerances, linetolerances; /// transformation matrix DenseMatrix oldutonewu; /// transformation matrix: deviation old point to dev. freezone @@ -55,21 +55,21 @@ private: a point is outside of convex part of freezone, iff mat * (point, 1) >= 0 for each component (correct ?) */ - Array freefaceinequ; + NgArray freefaceinequ; /// - Array orientations; + NgArray orientations; /** flags specified in rule-description file: t .. test rule */ - Array flags; + NgArray flags; /** topological distance of face to base element non-connected: > 100 (??) */ - Array fnearness; - Array pnearness; + NgArray fnearness; + NgArray pnearness; int maxpnearness; /// number of old points in rule @@ -144,19 +144,19 @@ public: -1 maybe */ int IsTriangleInFreeZone (const Point3d & p1, const Point3d & p2, - const Point3d & p3, const Array & pi, int newone); + const Point3d & p3, const NgArray & pi, int newone); /// int IsQuadInFreeZone (const Point3d & p1, const Point3d & p2, const Point3d & p3, const Point3d & p4, - const Array & pi, int newone); + const NgArray & pi, int newone); /// int IsTriangleInFreeSet (const Point3d & p1, const Point3d & p2, - const Point3d & p3, int fs, const Array & pi, int newone); + const Point3d & p3, int fs, const NgArray & pi, int newone); /// int IsQuadInFreeSet (const Point3d & p1, const Point3d & p2, const Point3d & p3, const Point3d & p4, - int fs, const Array & pi, int newone); + int fs, const NgArray & pi, int newone); /// int ConvexFreeZone () const; @@ -194,7 +194,7 @@ public: void LoadRule (istream & ist); /// - const Array & GetTransFreeZone () { return transfreezone; } + const NgArray & GetTransFreeZone () { return transfreezone; } /// int TestOk () const; diff --git a/libsrc/meshing/secondorder.cpp b/libsrc/meshing/secondorder.cpp index c70841b3..25a27dab 100644 --- a/libsrc/meshing/secondorder.cpp +++ b/libsrc/meshing/secondorder.cpp @@ -351,7 +351,7 @@ namespace netgen // update identification tables for (int i = 1; i <= mesh.GetIdentifications().GetMaxNr(); i++) { - Array identmap; + NgArray identmap; mesh.GetIdentifications().GetMap (i, identmap); for (INDEX_2_HASHTABLE::Iterator it = between.Begin(); @@ -425,7 +425,7 @@ namespace netgen int np = mesh.GetNP(); int ne = mesh.GetNE(); // int i, j; - Array parents(np); + NgArray parents(np); for (int i = 1; i <= np; i++) parents.Elem(i) = INDEX_2(0,0); @@ -459,7 +459,7 @@ namespace netgen void Refinement :: ValidateRefinedMesh (Mesh & mesh, - Array & parents) + NgArray & parents) { // int i, j, k; @@ -490,8 +490,8 @@ namespace netgen cout << "WARNING: " << wrongels << " illegal element(s) found" << endl; int np = mesh.GetNP(); - Array > should(np); - Array > can(np); + NgArray > should(np); + NgArray > can(np); for (int i = 1; i <= np; i++) { diff --git a/libsrc/meshing/smoothing2.5.cpp b/libsrc/meshing/smoothing2.5.cpp index b09b4e30..351771e6 100644 --- a/libsrc/meshing/smoothing2.5.cpp +++ b/libsrc/meshing/smoothing2.5.cpp @@ -7,8 +7,8 @@ namespace netgen { - void MeshOptimize2d :: ProjectBoundaryPoints(Array & surfaceindex, - const Array* > & from, Array* > & dest) + void MeshOptimize2d :: ProjectBoundaryPoints(NgArray & surfaceindex, + const NgArray* > & from, NgArray* > & dest) { for(int i=0; i seia; + NgArray seia; mesh.GetSurfaceElementsOfFace (faceindex, seia); /* @@ -73,9 +73,9 @@ namespace netgen Vector x(3); - Array savepoints(mesh.GetNP()); + NgArray savepoints(mesh.GetNP()); - Array nelementsonpoint(mesh.GetNP()); + NgArray nelementsonpoint(mesh.GetNP()); nelementsonpoint = 0; for (i = 0; i < seia.Size(); i++) @@ -139,8 +139,8 @@ namespace netgen int cnt = 0; - Array locelements(0); - Array locrots(0); + NgArray locelements(0); + NgArray locrots(0); for (PointIndex pi = mesh.Points().Begin(); pi < mesh.Points().End(); pi++) { diff --git a/libsrc/meshing/smoothing2.cpp b/libsrc/meshing/smoothing2.cpp index 419cc640..ec245b16 100644 --- a/libsrc/meshing/smoothing2.cpp +++ b/libsrc/meshing/smoothing2.cpp @@ -186,10 +186,10 @@ namespace netgen MeshPoint sp1; PointGeomInfo gi1; Vec<3> normal, t1, t2; - Array locelements; - Array locrots; - Array lochs; - Array > loc_pnts2, loc_pnts3; + NgArray locelements; + NgArray locrots; + NgArray lochs; + NgArray > loc_pnts2, loc_pnts3; // static int locerr2; double locmetricweight; double loch; @@ -584,7 +584,7 @@ namespace netgen // meshthis -> ProjectPoint (surfi, pp1); // meshthis -> GetNormalVector (surfi, pp1, n); - static Array pts2d; + static NgArray pts2d; pts2d.SetSize(mesh.GetNP()); grad = 0; @@ -655,7 +655,7 @@ namespace netgen // pp1.Add2 (x.Get(1), t1, x.Get(2), t2); pp1 = ld.sp1 + x(0) * ld.t1 + x(1) * ld.t2; - static Array pts2d; + static NgArray pts2d; pts2d.SetSize(mesh.GetNP()); deriv = 0; @@ -741,7 +741,7 @@ namespace netgen Opti2dLocalData ld; - Array seia; + NgArray seia; mesh.GetSurfaceElementsOfFace (faceindex, seia); bool mixed = 0; for (int i = 0; i < seia.Size(); i++) @@ -753,12 +753,12 @@ namespace netgen Vector x(2); - Array savepoints(mesh.GetNP()); + NgArray savepoints(mesh.GetNP()); ld.uselocalh = mp.uselocalh; - Array compress(mesh.GetNP()); - Array icompress; + NgArray compress(mesh.GetNP()); + NgArray icompress; for (int i = 0; i < seia.Size(); i++) { const Element2d & el = mesh[seia[i]]; @@ -775,7 +775,7 @@ namespace netgen icompress.Append(el[j]); } } - Array cnta(icompress.Size()); + NgArray cnta(icompress.Size()); cnta = 0; for (int i = 0; i < seia.Size(); i++) { @@ -793,7 +793,7 @@ namespace netgen /* - Array nelementsonpoint(mesh.GetNP()); + NgArray nelementsonpoint(mesh.GetNP()); nelementsonpoint = 0; for (int i = 0; i < seia.Size(); i++) { diff --git a/libsrc/meshing/smoothing3.cpp b/libsrc/meshing/smoothing3.cpp index f85af08f..fd814fec 100644 --- a/libsrc/meshing/smoothing3.cpp +++ b/libsrc/meshing/smoothing3.cpp @@ -88,7 +88,7 @@ namespace netgen } PointFunction1 :: PointFunction1 (Mesh::T_POINTS & apoints, - const Array & afaces, + const NgArray & afaces, const MeshingParameters & amp, double ah) : points(apoints), faces(afaces), mp(amp) @@ -176,12 +176,12 @@ namespace netgen class CheapPointFunction1 : public MinFunction { Mesh::T_POINTS & points; - const Array & faces; + const NgArray & faces; DenseMatrix m; double h; public: CheapPointFunction1 (Mesh::T_POINTS & apoints, - const Array & afaces, + const NgArray & afaces, double ah); virtual double Func (const Vector & x) const; @@ -189,7 +189,7 @@ namespace netgen }; CheapPointFunction1 :: CheapPointFunction1 (Mesh::T_POINTS & apoints, - const Array & afaces, + const NgArray & afaces, double ah) : points(apoints), faces(afaces) { @@ -422,7 +422,7 @@ namespace netgen int PointFunction :: MovePointToInner () { // try point movement - Array faces; + NgArray faces; for (int j = 0; j < elementsonpoint[actpind].Size(); j++) { @@ -1366,7 +1366,7 @@ void Mesh :: ImproveMesh (const MeshingParameters & mp, OPTIMIZEGOAL goal) int ne = GetNE(); - Array perrs(np); + NgArray perrs(np); perrs = 1.0; double bad1 = 0; @@ -1422,7 +1422,7 @@ void Mesh :: ImproveMesh (const MeshingParameters & mp, OPTIMIZEGOAL goal) par.maxit_linsearch = 20; par.maxit_bfgs = 20; - Array pointh (points.Size()); + NgArray pointh (points.Size()); if(lochfunc) { @@ -1551,7 +1551,7 @@ void Mesh :: ImproveMeshJacobian (const MeshingParameters & mp, badnodes.Set (el.PNum(j)); } - Array pointh (points.Size()); + NgArray pointh (points.Size()); if(lochfunc) { @@ -1639,9 +1639,9 @@ void Mesh :: ImproveMeshJacobian (const MeshingParameters & mp, // Improve Condition number of Jacobian, any elements void Mesh :: ImproveMeshJacobianOnSurface (const MeshingParameters & mp, const BitArray & usepoint, - const Array< Vec<3>* > & nv, + const NgArray< Vec<3>* > & nv, OPTIMIZEGOAL goal, - const Array< Array* > * idmaps) + const NgArray< NgArray* > * idmaps) { int i, j; @@ -1658,8 +1658,8 @@ void Mesh :: ImproveMeshJacobianOnSurface (const MeshingParameters & mp, JacobianPointFunction pf(points, volelements); - Array< Array* > locidmaps; - const Array< Array* > * used_idmaps; + NgArray< NgArray* > locidmaps; + const NgArray< NgArray* > * used_idmaps; if(idmaps) used_idmaps = idmaps; @@ -1671,7 +1671,7 @@ void Mesh :: ImproveMeshJacobianOnSurface (const MeshingParameters & mp, { if(GetIdentifications().GetType(i) == Identifications::PERIODIC) { - locidmaps.Append(new Array); + locidmaps.Append(new NgArray); GetIdentifications().GetMap(i,*locidmaps.Last(),true); } } @@ -1706,7 +1706,7 @@ void Mesh :: ImproveMeshJacobianOnSurface (const MeshingParameters & mp, badnodes.Set (el.PNum(j)); } - Array pointh (points.Size()); + NgArray pointh (points.Size()); if(lochfunc) { diff --git a/libsrc/meshing/specials.cpp b/libsrc/meshing/specials.cpp index 3d0dbbdd..1d993a2c 100644 --- a/libsrc/meshing/specials.cpp +++ b/libsrc/meshing/specials.cpp @@ -20,7 +20,7 @@ void CutOffAndCombine (Mesh & mesh, const Mesh & othermesh) othermesh.GetNP(), " points, ", othermesh.GetNSE(), " surface elements."); - Array otherbounds(nse); + NgArray otherbounds(nse); Box3d otherbox; double maxh = 0; @@ -135,7 +135,7 @@ void CutOffAndCombine (Mesh & mesh, const Mesh & othermesh) - Array pmat(onp); + NgArray pmat(onp); for (i = 1; i <= onp; i++) pmat.Elem(i) = mesh.AddPoint (othermesh.Point(i)); diff --git a/libsrc/meshing/topology.cpp b/libsrc/meshing/topology.cpp index 27046ff7..9e663bc7 100644 --- a/libsrc/meshing/topology.cpp +++ b/libsrc/meshing/topology.cpp @@ -363,8 +363,8 @@ namespace netgen (*testout) << "nv = " << nv << endl; (*tracer) ("Topology::Update setup tables", false); - Array cnt(nv); - Array vnums; + NgArray cnt(nv); + NgArray vnums; /* generate: @@ -598,7 +598,7 @@ namespace netgen // INDEX_CLOSED_HASHTABLE v2eht(2*max_edge_on_vertex+10); - // Array vertex2; + // NgArray vertex2; // for (PointIndex v = PointIndex::BASE; v < nv+PointIndex::BASE; v++) ParallelForRange @@ -606,7 +606,7 @@ namespace netgen [&] (size_t begin, size_t end) { INDEX_CLOSED_HASHTABLE v2eht(2*max_edge_on_vertex+10); - Array vertex2; + NgArray vertex2; for (PointIndex v = begin+PointIndex::BASE; v < end+PointIndex::BASE; v++) { @@ -1146,11 +1146,11 @@ namespace netgen #endif (*tracer) ("Topology::Update count face_els", false); - Array face_els(nfa), face_surfels(nfa); + NgArray face_els(nfa), face_surfels(nfa); face_els = 0; face_surfels = 0; /* - Array hfaces; + NgArray hfaces; for (int i = 1; i <= ne; i++) { GetElementFaces (i, hfaces); @@ -1162,7 +1162,7 @@ namespace netgen (tm, ne, [&] (size_t begin, size_t end) { - Array hfaces; + NgArray hfaces; for (ElementIndex ei = begin; ei < end; ei++) { GetElementFaces (ei+1, hfaces); @@ -1370,7 +1370,7 @@ namespace netgen - void MeshTopology :: GetElementEdges (int elnr, Array & eledges) const + void MeshTopology :: GetElementEdges (int elnr, NgArray & eledges) const { int ned = GetNEdges (mesh->VolumeElement(elnr).GetType()); eledges.SetSize (ned); @@ -1378,7 +1378,7 @@ namespace netgen eledges[i] = edges.Get(elnr)[i].nr+1; // eledges[i] = abs (edges.Get(elnr)[i]); } - void MeshTopology :: GetElementFaces (int elnr, Array & elfaces, bool withorientation) const + void MeshTopology :: GetElementFaces (int elnr, NgArray & elfaces, bool withorientation) const { int nfa = GetNFaces (mesh->VolumeElement(elnr).GetType()); elfaces.SetSize (nfa); @@ -1406,7 +1406,7 @@ namespace netgen } } - void MeshTopology :: GetElementEdgeOrientations (int elnr, Array & eorient) const + void MeshTopology :: GetElementEdgeOrientations (int elnr, NgArray & eorient) const { int ned = GetNEdges (mesh->VolumeElement(elnr).GetType()); eorient.SetSize (ned); @@ -1416,7 +1416,7 @@ namespace netgen eorient.Elem(i) = GetElementEdgeOrientation (elnr, i-1) ? -1 : 1; } - void MeshTopology :: GetElementFaceOrientations (int elnr, Array & forient) const + void MeshTopology :: GetElementFaceOrientations (int elnr, NgArray & forient) const { int nfa = GetNFaces (mesh->VolumeElement(elnr).GetType()); forient.SetSize (nfa); @@ -1518,7 +1518,7 @@ namespace netgen return 6; } - void MeshTopology :: GetSurfaceElementEdges (int elnr, Array & eledges) const + void MeshTopology :: GetSurfaceElementEdges (int elnr, NgArray & eledges) const { int ned = GetNEdges (mesh->SurfaceElement(elnr).GetType()); eledges.SetSize (ned); @@ -1527,7 +1527,7 @@ namespace netgen eledges[i] = surfedges.Get(elnr)[i].nr+1; } - void MeshTopology :: GetEdges (SurfaceElementIndex elnr, Array & eledges) const + void MeshTopology :: GetEdges (SurfaceElementIndex elnr, NgArray & eledges) const { int ned = GetNEdges ( (*mesh)[elnr].GetType()); eledges.SetSize (ned); @@ -1550,7 +1550,7 @@ namespace netgen void MeshTopology :: - GetSurfaceElementEdgeOrientations (int elnr, Array & eorient) const + GetSurfaceElementEdgeOrientations (int elnr, NgArray & eorient) const { int ned = GetNEdges (mesh->SurfaceElement(elnr).GetType()); eorient.SetSize (ned); @@ -1764,7 +1764,7 @@ namespace netgen - void MeshTopology :: GetFaceVertices (int fnr, Array & vertices) const + void MeshTopology :: GetFaceVertices (int fnr, NgArray & vertices) const { vertices.SetSize(4); for (int i = 0; i < 4; i++) @@ -1798,7 +1798,7 @@ namespace netgen } - void MeshTopology :: GetFaceEdges (int fnr, Array & fedges, bool withorientation) const + void MeshTopology :: GetFaceEdges (int fnr, NgArray & fedges, bool withorientation) const { ArrayMem pi(4); ArrayMem eledges; @@ -1913,7 +1913,7 @@ namespace netgen */ - void MeshTopology :: GetVertexElements (int vnr, Array & elements) const + void MeshTopology :: GetVertexElements (int vnr, NgArray & elements) const { if (vert2element.Size()) { @@ -1948,7 +1948,7 @@ namespace netgen */ void MeshTopology :: GetVertexSurfaceElements( int vnr, - Array & elements ) const + NgArray & elements ) const { if (vert2surfelement.Size()) { @@ -1963,8 +1963,8 @@ namespace netgen int MeshTopology :: GetVerticesEdge ( int v1, int v2 ) const { - Array elements_v1; - Array elementedges; + NgArray elements_v1; + NgArray elementedges; GetVertexElements ( v1, elements_v1); int edv1, edv2; @@ -1985,11 +1985,11 @@ namespace netgen void MeshTopology :: - GetSegmentVolumeElements ( int segnr, Array & volels ) const + GetSegmentVolumeElements ( int segnr, NgArray & volels ) const { int v1, v2; GetEdgeVertices ( GetSegmentEdge (segnr), v1, v2 ); - Array volels1, volels2; + NgArray volels1, volels2; GetVertexElements ( v1, volels1 ); GetVertexElements ( v2, volels2 ); volels.SetSize(0); @@ -2000,11 +2000,11 @@ namespace netgen } void MeshTopology :: - GetSegmentSurfaceElements (int segnr, Array & els) const + GetSegmentSurfaceElements (int segnr, NgArray & els) const { int v1, v2; GetEdgeVertices ( GetSegmentEdge (segnr), v1, v2 ); - Array els1, els2; + NgArray els1, els2; GetVertexSurfaceElements ( v1, els1 ); GetVertexSurfaceElements ( v2, els2 ); els.SetSize(0); diff --git a/libsrc/meshing/topology.hpp b/libsrc/meshing/topology.hpp index 8dccce33..e20aa121 100644 --- a/libsrc/meshing/topology.hpp +++ b/libsrc/meshing/topology.hpp @@ -42,21 +42,21 @@ class MeshTopology bool buildedges; bool buildfaces; - Array edge2vert; - Array face2vert; + NgArray edge2vert; + NgArray face2vert; /* - Array edges; - Array faces; - Array surfedges; + NgArray edges; + NgArray faces; + NgArray surfedges; */ - Array> edges; - Array> faces; - Array> surfedges; + NgArray> edges; + NgArray> faces; + NgArray> surfedges; - Array segedges; - Array surffaces; - Array surf2volelement; - Array face2surfel; + NgArray segedges; + NgArray surffaces; + NgArray surf2volelement; + NgArray face2surfel; TABLE vert2element; TABLE vert2surfelement; TABLE vert2segment; @@ -109,10 +109,10 @@ public: orient = GetSegmentEdgeOrientation(segnr); } - void GetElementEdges (int elnr, Array & edges) const; - void GetElementFaces (int elnr, Array & faces, bool withorientation = false) const; - void GetElementEdgeOrientations (int elnr, Array & eorient) const; - void GetElementFaceOrientations (int elnr, Array & forient) const; + void GetElementEdges (int elnr, NgArray & edges) const; + void GetElementFaces (int elnr, NgArray & faces, bool withorientation = false) const; + void GetElementEdgeOrientations (int elnr, NgArray & eorient) const; + void GetElementFaceOrientations (int elnr, NgArray & forient) const; int GetElementEdges (int elnr, int * edges, int * orient) const; int GetElementFaces (int elnr, int * faces, int * orient) const; @@ -124,22 +124,22 @@ public: int GetSegmentEdgeOrientation (int elnr) const; // old style - void GetFaceVertices (int fnr, Array & vertices) const; + void GetFaceVertices (int fnr, NgArray & vertices) const; void GetFaceVertices (int fnr, int * vertices) const; void GetEdgeVertices (int enr, int & v1, int & v2) const; void GetEdgeVertices (int enr, PointIndex & v1, PointIndex & v2) const; const int * GetEdgeVerticesPtr (int enr) const { return &edge2vert[enr][0]; } const int * GetFaceVerticesPtr (int fnr) const { return &face2vert[fnr][0]; } - void GetFaceEdges (int fnr, Array & edges, bool withorientation = false) const; + void GetFaceEdges (int fnr, NgArray & edges, bool withorientation = false) const; ELEMENT_TYPE GetFaceType (int fnr) const { return (face2vert.Get(fnr)[3] == 0) ? TRIG : QUAD; } - void GetSurfaceElementEdges (int elnr, Array & edges) const; + void GetSurfaceElementEdges (int elnr, NgArray & edges) const; int GetSurfaceElementFace (int elnr) const; - void GetSurfaceElementEdgeOrientations (int elnr, Array & eorient) const; + void GetSurfaceElementEdgeOrientations (int elnr, NgArray & eorient) const; int GetSurfaceElementFaceOrientation (int elnr) const; - void GetEdges (SurfaceElementIndex elnr, Array & edges) const; + void GetEdges (SurfaceElementIndex elnr, NgArray & edges) const; int GetFace (SurfaceElementIndex elnr) const { return surffaces[elnr].fnr; } @@ -161,11 +161,11 @@ public: int GetFace2SurfaceElement (int fnr) const { return face2surfel[fnr-1]; } - void GetVertexElements (int vnr, Array & elements) const; + void GetVertexElements (int vnr, NgArray & elements) const; FlatArray GetVertexElements (int vnr) const { return vert2element[vnr]; } - void GetVertexSurfaceElements( int vnr, Array& elements ) const; + void GetVertexSurfaceElements( int vnr, NgArray& elements ) const; FlatArray GetVertexSurfaceElements (int vnr) const { return vert2surfelement[vnr]; } @@ -176,8 +176,8 @@ public: { return vert2pointelement[vnr]; } int GetVerticesEdge ( int v1, int v2) const; - void GetSegmentVolumeElements ( int segnr, Array & els ) const; - void GetSegmentSurfaceElements ( int segnr, Array & els ) const; + void GetSegmentVolumeElements ( int segnr, NgArray & els ) const; + void GetSegmentSurfaceElements ( int segnr, NgArray & els ) const; }; diff --git a/libsrc/meshing/validate.cpp b/libsrc/meshing/validate.cpp index 44b983cc..743f5b74 100644 --- a/libsrc/meshing/validate.cpp +++ b/libsrc/meshing/validate.cpp @@ -5,7 +5,7 @@ namespace netgen { - void GetPureBadness(Mesh & mesh, Array & pure_badness, + void GetPureBadness(Mesh & mesh, NgArray & pure_badness, const BitArray & isnewpoint) { //const int ne = mesh.GetNE(); @@ -14,7 +14,7 @@ namespace netgen pure_badness.SetSize(np+PointIndex::BASE+1); pure_badness = -1; - Array< Point<3>* > backup(np); + NgArray< Point<3>* > backup(np); for(int i=0; i & bad_elements, - const Array & pure_badness, + double Validate(const Mesh & mesh, NgArray & bad_elements, + const NgArray & pure_badness, double max_worsening, const bool uselocalworsening, - Array * quality_loss) + NgArray * quality_loss) { PrintMessage(3,"!!!! Validating !!!!"); //if(max_worsening > 0) @@ -105,7 +105,7 @@ namespace netgen void GetWorkingArea(BitArray & working_elements, BitArray & working_points, - const Mesh & mesh, const Array & bad_elements, + const Mesh & mesh, const NgArray & bad_elements, const int width) { working_elements.Clear(); @@ -151,11 +151,11 @@ namespace netgen - void RepairBisection(Mesh & mesh, Array & bad_elements, + void RepairBisection(Mesh & mesh, NgArray & bad_elements, const BitArray & isnewpoint, const Refinement & refinement, - const Array & pure_badness, + const NgArray & pure_badness, double max_worsening, const bool uselocalworsening, - const Array< Array* > & idmaps) + const NgArray< NgArray* > & idmaps) { ostringstream ostrstr; @@ -175,9 +175,9 @@ namespace netgen PushStatus("Repair Bisection"); - Array* > should(np); - Array* > can(np); - Array* > nv(np); + NgArray* > should(np); + NgArray* > can(np); + NgArray* > nv(np); for(int i=0; i; @@ -196,7 +196,7 @@ namespace netgen isedgepoint.Set(seg[1]); } - Array surfaceindex(np); + NgArray surfaceindex(np); surfaceindex = -1; for (int i = 1; i <= mesh.GetNSE(); i++) diff --git a/libsrc/meshing/validate.hpp b/libsrc/meshing/validate.hpp index 1cc01bec..86201f3c 100644 --- a/libsrc/meshing/validate.hpp +++ b/libsrc/meshing/validate.hpp @@ -4,17 +4,17 @@ namespace netgen { - void GetPureBadness(Mesh & mesh, Array & pure_badness, + void GetPureBadness(Mesh & mesh, NgArray & pure_badness, const BitArray & isnewpoint); - double Validate(const Mesh & mesh, Array & bad_elements, - const Array & pure_badness, + double Validate(const Mesh & mesh, NgArray & bad_elements, + const NgArray & pure_badness, double max_worsening, const bool uselocalworsening, - Array * quality_loss = NULL); - void RepairBisection(Mesh & mesh, Array & bad_elements, + NgArray * quality_loss = NULL); + void RepairBisection(Mesh & mesh, NgArray & bad_elements, const BitArray & isnewpoint, const Refinement & refinement, - const Array & pure_badness, + const NgArray & pure_badness, double max_worsening, const bool uselocalworsening, - const Array< Array* > & idmaps); + const NgArray< NgArray* > & idmaps); } diff --git a/libsrc/occ/occgenmesh.cpp b/libsrc/occ/occgenmesh.cpp index a41ce215..74d0328c 100644 --- a/libsrc/occ/occgenmesh.cpp +++ b/libsrc/occ/occgenmesh.cpp @@ -231,8 +231,8 @@ namespace netgen - void DivideEdge (TopoDS_Edge & edge, Array & ps, - Array & params, Mesh & mesh) + void DivideEdge (TopoDS_Edge & edge, NgArray & ps, + NgArray & params, Mesh & mesh) { double s0, s1; double maxh = mparam.maxh; @@ -350,7 +350,7 @@ namespace netgen int first_ep = mesh.GetNP()+1; - Array face2solid[2]; + NgArray face2solid[2]; for (int i = 0; i<2; i++) { face2solid[i].SetSize (geom.fmap.Extent()); @@ -471,12 +471,12 @@ namespace netgen int geomedgenr = geom.emap.FindIndex(edge); - Array mp; - Array params; + NgArray mp; + NgArray params; DivideEdge (edge, mp, params, mesh); - Array pnums; + NgArray pnums; pnums.SetSize (mp.Size()+2); if (!merge_solids) @@ -620,7 +620,7 @@ namespace netgen double starttime = GetTime(); - Array glob2loc(noldp); + NgArray glob2loc(noldp); //int projecttype = PARAMETERSPACE; @@ -726,7 +726,7 @@ namespace netgen cntp+=2; - Array< PointGeomInfo > gis; + NgArray< PointGeomInfo > gis; gis.SetAllocSize (cntp); gis.SetSize (0); @@ -993,7 +993,7 @@ namespace netgen mesh.SetGlobalH (mparam.maxh); mesh.SetMinimalH (mparam.minh); - Array maxhdom; + NgArray maxhdom; maxhdom.SetSize (geom.NrSolids()); maxhdom = mparam.maxh; @@ -1178,7 +1178,7 @@ namespace netgen int sections = 100; - Array lines(sections*nedges); + NgArray lines(sections*nedges); BoxTree<3> * searchtree = new BoxTree<3> (bb.PMin(), bb.PMax()); @@ -1225,7 +1225,7 @@ namespace netgen } } - Array linenums; + NgArray linenums; for (int i = 0; i < nlines; i++) { @@ -1313,7 +1313,7 @@ namespace netgen int i, j; int np = mesh->GetNP(); - Array equalto; + NgArray equalto; equalto.SetSize (np); equalto = 0; diff --git a/libsrc/occ/occgeom.cpp b/libsrc/occ/occgeom.cpp index 8567d940..2191aaaf 100644 --- a/libsrc/occ/occgeom.cpp +++ b/libsrc/occ/occgeom.cpp @@ -1616,8 +1616,8 @@ void STEP_GetEntityName(const TopoDS_Shape & theShape, STEPCAFControl_Reader * a // double dmax; // int cnt = 0; - Array edgeLengths; - Array order; + NgArray edgeLengths; + NgArray order; edgeLengths.SetSize (emap.Extent()); order.SetSize (emap.Extent()); diff --git a/libsrc/occ/occgeom.hpp b/libsrc/occ/occgeom.hpp index 8c93ff1f..f461effd 100644 --- a/libsrc/occ/occgeom.hpp +++ b/libsrc/occ/occgeom.hpp @@ -196,9 +196,9 @@ namespace netgen public: TopoDS_Shape shape; TopTools_IndexedMapOfShape fmap, emap, vmap, somap, shmap, wmap; - Array fsingular, esingular, vsingular; + NgArray fsingular, esingular, vsingular; Box<3> boundingbox; - Array fnames, enames, snames; + NgArray fnames, enames, snames; // Philippose - 29/01/2009 // OpenCascade XDE Support // XCAF Handle to make the face colours available to the rest of @@ -206,25 +206,25 @@ namespace netgen Handle_XCAFDoc_ColorTool face_colours; mutable int changed; - Array facemeshstatus; + NgArray facemeshstatus; // Philippose - 15/01/2009 // Maximum mesh size for a given face // (Used to explicitly define mesh size limits on individual faces) - Array face_maxh; + NgArray face_maxh; // Philippose - 14/01/2010 // Boolean array to detect whether a face has been explicitly modified // by the user or not - Array face_maxh_modified; + NgArray face_maxh_modified; // Philippose - 15/01/2009 // Indicates which faces have been selected by the user in geometry mode // (Currently handles only selection of one face at a time, but an array would // help to extend this to multiple faces) - Array face_sel_status; + NgArray face_sel_status; - Array fvispar, evispar, vvispar; + NgArray fvispar, evispar, vvispar; double tolerance; bool fixsmalledges; diff --git a/libsrc/occ/occpkg.cpp b/libsrc/occ/occpkg.cpp index 3a562641..a5f64dcc 100644 --- a/libsrc/occ/occpkg.cpp +++ b/libsrc/occ/occpkg.cpp @@ -16,7 +16,7 @@ #include "vsocc.hpp" // __declspec(dllimport) void AutoColourBcProps(Mesh & mesh, const char *bccolourfile); -// __declspec(dllimport) void GetFaceColours(Mesh & mesh, Array & face_colours); +// __declspec(dllimport) void GetFaceColours(Mesh & mesh, NgArray & face_colours); // __declspec(dllimport) bool ColourMatch(Vec3d col1, Vec3d col2, double eps = 2.5e-05); extern "C" int Ng_occ_Init (Tcl_Interp * interp); @@ -686,7 +686,7 @@ namespace netgen if(strcmp(argv[1], "getcolours") == 0) { stringstream outVar; - Array face_colours; + NgArray face_colours; GetFaceColours(*mesh, face_colours); for(int i = 0; i < face_colours.Size();i++) @@ -703,14 +703,14 @@ namespace netgen if(strcmp(argv[1], "showalso") == 0) { - Array face_colours; + NgArray face_colours; GetFaceColours(*mesh,face_colours); int colourind = atoi (argv[2]); for(int i = 1; i <= mesh->GetNFD(); i++) { - Array surfElems; + NgArray surfElems; mesh->GetSurfaceElementsOfFace(i,surfElems); if(ColourMatch(face_colours[colourind],mesh->GetFaceDescriptor(i).SurfColour())) @@ -727,14 +727,14 @@ namespace netgen if(strcmp(argv[1], "hidealso") == 0) { - Array face_colours; + NgArray face_colours; GetFaceColours(*mesh,face_colours); int colourind = atoi (argv[2]); for(int i = 1; i <= mesh->GetNFD(); i++) { - Array surfElems; + NgArray surfElems; mesh->GetSurfaceElementsOfFace(i,surfElems); if(ColourMatch(face_colours[colourind],mesh->GetFaceDescriptor(i).SurfColour())) @@ -751,14 +751,14 @@ namespace netgen if(strcmp(argv[1], "showonly") == 0) { - Array face_colours; + NgArray face_colours; GetFaceColours(*mesh,face_colours); int colourind = atoi (argv[2]); for(int i = 1; i <= mesh->GetNFD(); i++) { - Array surfElems; + NgArray surfElems; mesh->GetSurfaceElementsOfFace(i,surfElems); if(ColourMatch(face_colours[colourind],mesh->GetFaceDescriptor(i).SurfColour())) @@ -782,14 +782,14 @@ namespace netgen if(strcmp(argv[1], "hideonly") == 0) { - Array face_colours; + NgArray face_colours; GetFaceColours(*mesh,face_colours); int colourind = atoi (argv[2]); for(int i = 1; i <= mesh->GetNFD(); i++) { - Array surfElems; + NgArray surfElems; mesh->GetSurfaceElementsOfFace(i,surfElems); if(ColourMatch(face_colours[colourind],mesh->GetFaceDescriptor(i).SurfColour())) diff --git a/libsrc/occ/vsocc.hpp b/libsrc/occ/vsocc.hpp index 3021fe7c..777028f4 100644 --- a/libsrc/occ/vsocc.hpp +++ b/libsrc/occ/vsocc.hpp @@ -12,8 +12,8 @@ namespace netgen class VisualSceneOCCGeometry : public VisualScene { - Array trilists; - Array linelists; + NgArray trilists; + NgArray linelists; int selsurf; class OCCGeometry * occgeometry; public: diff --git a/libsrc/stlgeom/meshstlsurface.cpp b/libsrc/stlgeom/meshstlsurface.cpp index 02753fb8..6aef6e27 100644 --- a/libsrc/stlgeom/meshstlsurface.cpp +++ b/libsrc/stlgeom/meshstlsurface.cpp @@ -25,8 +25,8 @@ static void STLFindEdges (STLGeometry & geom, PushStatusF("Mesh Lines"); - Array meshlines; - Array meshpoints; + NgArray meshlines; + NgArray meshpoints; PrintMessage(3,"Mesh Lines"); @@ -451,8 +451,8 @@ int STLSurfaceMeshing (STLGeometry & geom, class Mesh & mesh) - Array refpts; - Array refh; + NgArray refpts; + NgArray refh; // was commented: @@ -539,7 +539,7 @@ void STLSurfaceMeshing1 (STLGeometry & geom, mesh.FindOpenSegments(); - Array spiralps(0); + NgArray spiralps(0); spiralps.SetSize(0); for (int i = 1; i <= geom.GetNP(); i++) if (geom.GetSpiralPoint(i)) @@ -549,18 +549,18 @@ void STLSurfaceMeshing1 (STLGeometry & geom, //int spfound; /* - Array meshsp(mesh.GetNP()); + NgArray meshsp(mesh.GetNP()); meshsp = 0; for (int i = 1; i <= mesh.GetNP(); i++) for (int j = 1; j <= spiralps.Size(); j++) if (Dist2(geom.GetPoint(spiralps.Get(j)), mesh.Point(i)) < 1e-20) meshsp.Elem(i) = spiralps.Get(j); - Array imeshsp; + NgArray imeshsp; for (int i = 1; i <= meshsp.Size(); i++) if (meshsp.Elem(i)) imeshsp.Append(i); */ - Array imeshsp; - Array ispiral_point; + NgArray imeshsp; + NgArray ispiral_point; for (int i = 1; i <= mesh.GetNP(); i++) { for (int j = 1; j <= spiralps.Size(); j++) @@ -577,11 +577,11 @@ void STLSurfaceMeshing1 (STLGeometry & geom, // int oldnp = mesh.GetNP(); - Array compress(mesh.GetNP()); + NgArray compress(mesh.GetNP()); compress = 0; - Array icompress; + NgArray icompress; - Array opensegsperface(mesh.GetNFD()); + NgArray opensegsperface(mesh.GetNFD()); opensegsperface = 0; for (int i = 1; i <= mesh.GetNOpenSegments(); i++) opensegsperface[mesh.GetOpenSegment(i).si]++; @@ -926,9 +926,9 @@ IsLineVertexOnChart (const Point3d & p1, const Point3d & p2, } void MeshingSTLSurface :: -GetChartBoundary (Array & points, - Array & points3d, - Array & lines, double h) const +GetChartBoundary (NgArray & points, + NgArray & points3d, + NgArray & lines, double h) const { points.SetSize (0); points3d.SetSize (0); diff --git a/libsrc/stlgeom/meshstlsurface.hpp b/libsrc/stlgeom/meshstlsurface.hpp index ae0855f9..e7274c6a 100644 --- a/libsrc/stlgeom/meshstlsurface.hpp +++ b/libsrc/stlgeom/meshstlsurface.hpp @@ -52,9 +52,9 @@ protected: virtual int IsLineVertexOnChart (const Point3d & p1, const Point3d & p2, int endpoint, const PointGeomInfo & gi); - virtual void GetChartBoundary (Array & points, - Array & poitns3d, - Array & lines, double h) const; + virtual void GetChartBoundary (NgArray & points, + NgArray & poitns3d, + NgArray & lines, double h) const; /// virtual double CalcLocalH (const Point3d & p, double gh) const; diff --git a/libsrc/stlgeom/stlgeom.cpp b/libsrc/stlgeom/stlgeom.cpp index ebb5136f..2ccbf5f3 100644 --- a/libsrc/stlgeom/stlgeom.cpp +++ b/libsrc/stlgeom/stlgeom.cpp @@ -307,7 +307,7 @@ void STLGeometry :: SmoothNormals() // find critical: - Array critpairs; + NgArray critpairs; for (i = 1; i <= nt; i++) { const STLTriangle & trig = GetTriangle (i); @@ -360,7 +360,7 @@ void STLGeometry :: SmoothNormals() if (critpairs.Size()) { - Array friends; + NgArray friends; double area1 = 0, area2 = 0; for (i = 1; i <= critpairs.Size(); i++) @@ -597,7 +597,7 @@ twoint STLGeometry :: GetNearestSelectedDefinedEdge() //Point3d pestimate = GetTriangle(GetSelectTrig()).center; int i, j, en; - Array vic; + NgArray vic; GetVicinity(GetSelectTrig(),4,vic); @@ -716,7 +716,7 @@ void STLGeometry :: ImportEdges() int ne; fin >> ne; - Array > eps; + NgArray > eps; int i; Point<3> p; @@ -730,18 +730,18 @@ void STLGeometry :: ImportEdges() AddEdges(eps); } -void STLGeometry :: AddEdges(const Array >& eps) +void STLGeometry :: AddEdges(const NgArray >& eps) { int i; int ne = eps.Size()/2; - Array epsi; + NgArray epsi; Box<3> bb = GetBoundingBox(); bb.Increase(1); Point3dTree ptree (bb.PMin(), bb.PMax()); - Array pintersect; + NgArray pintersect; double gtol = GetBoundingBox().Diam()/1.E10; Point<3> p; @@ -809,9 +809,9 @@ void STLGeometry :: ImportExternalEdges(const char * filename) filter[flen] = 0; char buf[20]; - Array importpoints; - Array importlines; - Array importpnums; + NgArray importpoints; + NgArray importlines; + NgArray importpnums; while (inf.good()) { @@ -897,7 +897,7 @@ void STLGeometry :: ImportExternalEdges(const char * filename) ebb.AddPoint (importpoints.Get(i)); PrintMessage(7,"edgep - bb: ", ebb.PMin(), " - ", ebb.PMax()); - Array pintersect; + NgArray pintersect; double gtol = GetBoundingBox().Diam()/1.E6; @@ -1522,7 +1522,7 @@ void STLGeometry :: ShowSelectedTrigCoords() /* //testing!!!! - Array trigs; + NgArray trigs; GetSortedTrianglesAroundPoint(GetTriangle(st).PNum(GetNodeOfSelTrig()),st,trigs); */ @@ -1613,11 +1613,11 @@ void STLGeometry :: NeighbourAnglesOfSelectedTrig() } } -void STLGeometry :: GetVicinity(int starttrig, int size, Array& vic) +void STLGeometry :: GetVicinity(int starttrig, int size, NgArray& vic) { if (starttrig == 0 || starttrig > GetNT()) {return;} - Array vicarray; + NgArray vicarray; vicarray.SetSize(GetNT()); int i; @@ -1630,9 +1630,9 @@ void STLGeometry :: GetVicinity(int starttrig, int size, Array& vic) int j = 0,k; - Array list1; + NgArray list1; list1.SetSize(0); - Array list2; + NgArray list2; list2.SetSize(0); list1.Append(starttrig); @@ -1684,9 +1684,9 @@ void STLGeometry :: CalcVicinity(int starttrig) int j = 0,k; - Array list1; + NgArray list1; list1.SetSize(0); - Array list2; + NgArray list2; list2.SetSize(0); list1.Append(starttrig); @@ -2033,7 +2033,7 @@ double STLGeometry :: GetGeomAngle(int t1, int t2) } -void STLGeometry :: InitSTLGeometry(const Array & readtrias) +void STLGeometry :: InitSTLGeometry(const NgArray & readtrias) { PrintFnStart("Init STL Geometry"); STLTopology::InitSTLGeometry(readtrias); @@ -2045,7 +2045,7 @@ void STLGeometry :: InitSTLGeometry(const Array & readtrias) int np = GetNP(); PrintMessage(5,"NO points= ", GetNP()); normals.SetSize(GetNP()); - Array normal_cnt(GetNP()); // counts number of added normals in a point + NgArray normal_cnt(GetNP()); // counts number of added normals in a point for (i = 1; i <= np; i++) { @@ -2145,7 +2145,7 @@ int STLGeometry :: CheckGeometryOverlapping() ParallelFor( 1, GetNT()+1, [&] (int first, int next) { - Array inters; + NgArray inters; for (int i=first; i normal_cnt; // counts number of added normals in a point + NgArray normal_cnt; // counts number of added normals in a point Box3d bb (GetBoundingBox().PMin() + Vec3d (-1,-1,-1), GetBoundingBox().PMax() + Vec3d (1, 1, 1)); Point3dTree pointtree (bb.PMin(), bb.PMax()); - Array pintersect; + NgArray pintersect; double gtol = GetBoundingBox().CalcDiam()/geometry_tol_fact; @@ -2647,8 +2647,8 @@ void STLGeometry :: AddFaceEdges() //für Kugel eine STLLine hinzufügen (Vorteil: verfeinerbar, unabhängig von Auflösung der Geometrie!!!): //Grenze von 1. gefundener chart - Array edgecnt; - Array chartindex; + NgArray edgecnt; + NgArray chartindex; edgecnt.SetSize(GetNOFaces()); chartindex.SetSize(GetNOFaces()); @@ -2728,7 +2728,7 @@ void STLGeometry :: LinkEdges() int rev(0); //indicates, that edge is inserted reverse //worked edges - Array we(GetNE()); + NgArray we(GetNE()); //setlineendpoints; wenn 180°, dann keine endpunkte //nur punkte mit 2 edges kommen in frage, da bei mehr oder weniger punkten ohnehin ein meshpoint hinkommt @@ -2919,7 +2919,7 @@ int STLGeometry :: GetNOBodys() int i, k, nnt; int bodycnt = 0; - Array bodynum(GetNT()); + NgArray bodynum(GetNT()); for (i = 1; i <= GetNT(); i++) bodynum.Elem(i)=0; @@ -2936,8 +2936,8 @@ int STLGeometry :: GetNOBodys() } } //add all triangles around starttriangle, which is reachable without going over an edge - Array todolist; - Array nextlist; + NgArray todolist; + NgArray nextlist; bodycnt++; markedtrigs1++; bodynum.Elem(starttrig) = bodycnt; @@ -2998,8 +2998,8 @@ void STLGeometry :: CalcFaceNums() } } //add all triangles around starttriangle, which is reachable without going over an edge - Array todolist; - Array nextlist; + NgArray todolist; + NgArray nextlist; facecnt++; markedtrigs1++; GetTriangle(starttrig).SetFaceNum(facecnt); @@ -3120,7 +3120,7 @@ int STLGeometry :: IsSmoothEdge (int pi1, int pi2) const /* //function is not used now -int IsInArray(int n, const Array& ia) +int IsInArray(int n, const NgArray& ia) { int i; for (i = 1; i <= ia.Size(); i++) @@ -3183,8 +3183,8 @@ void STLGeometry :: AddConeAndSpiralEdges() cnt = 0; int edgecnt = 0; - Array trigsaroundp; - Array chartpointchecked; //gets number of chart, if in this chart already checked + NgArray trigsaroundp; + NgArray chartpointchecked; //gets number of chart, if in this chart already checked chartpointchecked.SetSize(GetNP()); for (i = 1; i <= GetNP(); i++) @@ -3407,7 +3407,7 @@ void STLGeometry :: AddConeAndSpiralEdges() } //get trigs at a point, started with starttrig, then every left -void STLGeometry :: GetSortedTrianglesAroundPoint(int p, int starttrig, Array& trigs) +void STLGeometry :: GetSortedTrianglesAroundPoint(int p, int starttrig, NgArray& trigs) { int acttrig = starttrig; trigs.SetAllocSize(trigsperpoint.EntrySize(p)); diff --git a/libsrc/stlgeom/stlgeom.hpp b/libsrc/stlgeom/stlgeom.hpp index 8d8d640f..5d7a5af1 100644 --- a/libsrc/stlgeom/stlgeom.hpp +++ b/libsrc/stlgeom/stlgeom.hpp @@ -27,12 +27,12 @@ namespace netgen { /* - inline int IsInArray(int n, const Array& ia) + inline int IsInArray(int n, const NgArray& ia) { return ia.Contains(n); } - inline bool AddIfNotExists(Array& list, int x) + inline bool AddIfNotExists(NgArray& list, int x) { if (list.Contains(x)) return false; list.Append(x); @@ -56,7 +56,7 @@ namespace netgen class STLEdgeDataList { - Array storedstatus; + NgArray storedstatus; STLTopology & geom; public: @@ -88,8 +88,8 @@ namespace netgen void Write(ofstream& of) const; void Read(ifstream& ifs); - void BuildLineWithEdge(int ep1, int ep2, Array& line); - void BuildClusterWithEdge(int ep1, int ep2, Array& line); + void BuildLineWithEdge(int ep1, int ep2, NgArray& line); + void BuildClusterWithEdge(int ep1, int ep2, NgArray& line); int GetNEPPStat(int p, int status) const; int GetNConfCandEPP(int p) const; @@ -103,20 +103,20 @@ namespace netgen class STLGeometry : public NetgenGeometry, public STLTopology { // edges to be meshed: - Array edges; + NgArray edges; //edges per point TABLE edgesperpoint; // line: a connection of edges - Array lines; - Array lineendpoints; //per geometrypoint, 1 = is endpoint; 0 = no endpoint, + NgArray lines; + NgArray lineendpoints; //per geometrypoint, 1 = is endpoint; 0 = no endpoint, - Array normals; //normals belong to points! + NgArray normals; //normals belong to points! - Array externaledges; + NgArray externaledges; int undoexternaledges; - Array storedexternaledges; + NgArray storedexternaledges; STLEdgeDataList * edgedata; // STLEdgeDataList edgedata_store; @@ -129,27 +129,27 @@ namespace netgen int facecnt; //meshpoint is only set, if an edge is at this point!!! - Array vicinity; //is one, if a triangle belongs to vicinity (eg. of selecttrig) - Array markedtrigs; //is one, if a triangle belongs to marked triangles (calcdirtystrigs) - Array markedsegs; //every pointpair is a segment!!! - Array selectedmultiedge; + NgArray vicinity; //is one, if a triangle belongs to vicinity (eg. of selecttrig) + NgArray markedtrigs; //is one, if a triangle belongs to marked triangles (calcdirtystrigs) + NgArray markedsegs; //every pointpair is a segment!!! + NgArray selectedmultiedge; //spiralpoints: - Array spiralpoints; + NgArray spiralpoints; // - Array atlas; + NgArray atlas; //marks all already charted trigs with chartnumber - Array chartmark; + NgArray chartmark; //outerchartspertrig, ascending sorted TABLE outerchartspertrig; //for meshing and project: - Array meshcharttrigs; //per trig: 1=belong to chart, 0 not + NgArray meshcharttrigs; //per trig: 1=belong to chart, 0 not int meshchart; - Array ha_points; // help array, np long, filled with 0 + NgArray ha_points; // help array, np long, filled with 0 // sharp geometric edges not declared as edges @@ -176,8 +176,8 @@ namespace netgen //int selecttrig, nodeofseltrig; //only for testing; - Array meshlines; - Array meshpoints; + NgArray meshlines; + NgArray meshpoints; double area; public: @@ -211,14 +211,14 @@ namespace netgen //void ClearSelectedMultiEdge() {selectedmultiedge.SetSize(0);} //void AddSelectedMultiEdge(twoint ep) {selectedmultiedge.Append(ep);} //int SelectedMultiEdgeSize() {return selectedmultiedge.Size();} - const Array& SelectedMultiEdge() {return selectedmultiedge;} + const NgArray& SelectedMultiEdge() {return selectedmultiedge;} twoint GetNearestSelectedDefinedEdge(); void BuildSelectedMultiEdge(twoint ep); void BuildSelectedEdge(twoint ep); void BuildSelectedCluster(twoint ep); DLL_HEADER void ImportEdges(); - DLL_HEADER void AddEdges(const Array >& eps); + DLL_HEADER void AddEdges(const NgArray >& eps); DLL_HEADER void ExportEdges(); DLL_HEADER void LoadEdgeData(const char* file); DLL_HEADER void SaveEdgeData(const char* file); @@ -287,7 +287,7 @@ namespace netgen } int GetNMarkedSegs() {return markedsegs.Size()/2;} DLL_HEADER void CalcVicinity(int starttrig); - DLL_HEADER void GetVicinity(int starttrig, int size, Array& vic); + DLL_HEADER void GetVicinity(int starttrig, int size, NgArray& vic); DLL_HEADER int Vicinity(int trig) const; @@ -330,7 +330,7 @@ namespace netgen /// ///ReadTriangle->STLTriangle, initialise some important variables, always after load!!! - virtual void InitSTLGeometry (const Array & readtrigs); + virtual void InitSTLGeometry (const NgArray & readtrigs); virtual void TopologyChanged(); //do some things, if topology changed! int CheckGeometryOverlapping(); @@ -367,14 +367,14 @@ namespace netgen void AddConeAndSpiralEdges(); void AddFaceEdges(); //each face should have at least one starting edge (outherwise it won't be meshed) - void GetDirtyChartTrigs(int chartnum, STLChart& chart, const Array& outercharttrigs, - Array& chartpointchecked, Array& dirtytrigs); + void GetDirtyChartTrigs(int chartnum, STLChart& chart, const NgArray& outercharttrigs, + NgArray& chartpointchecked, NgArray& dirtytrigs); void ClearSpiralPoints(); void SetSpiralPoint(int pn) {spiralpoints.Elem(pn) = 1;}; int GetSpiralPoint(int pn) const {return spiralpoints.Get(pn);}; - void GetSortedTrianglesAroundPoint(int p, int starttrig, Array& trigs); + void GetSortedTrianglesAroundPoint(int p, int starttrig, NgArray& trigs); // smooth edges: sharp geometric edges not declared as edges void BuildSmoothEdges (); @@ -403,13 +403,13 @@ namespace netgen STLChart& GetChart(int nr) {return *(atlas.Get(nr));}; int AtlasMade() const; - void GetInnerChartLimes(Array& limes, int chartnum); + void GetInnerChartLimes(NgArray& limes, int chartnum); //FOR MESHING int GetMeshChartNr () { return meshchart; } - void GetMeshChartBoundary (Array & points, - Array & points3d, - Array & lines, double h); + void GetMeshChartBoundary (NgArray & points, + NgArray & points3d, + NgArray & lines, double h); Point<3> PointBetween(const Point<3> & p1, int t1, const Point<3> & p2, int t2); @@ -452,7 +452,7 @@ namespace netgen DLL_HEADER void RestrictLocalH(class Mesh & mesh, double gh); void RestrictLocalHCurv(class Mesh & mesh, double gh); - void RestrictHChartDistOneChart(int chartnum, Array& acttrigs, class Mesh & mesh, + void RestrictHChartDistOneChart(int chartnum, NgArray& acttrigs, class Mesh & mesh, double gh, double fact, double minh); friend class MeshingSTLSurface; diff --git a/libsrc/stlgeom/stlgeomchart.cpp b/libsrc/stlgeom/stlgeomchart.cpp index 5962ac82..4186265a 100644 --- a/libsrc/stlgeom/stlgeomchart.cpp +++ b/libsrc/stlgeom/stlgeomchart.cpp @@ -69,16 +69,16 @@ void STLGeometry :: MakeAtlas(Mesh & mesh) double sinchartangle = sin(chartangle); double sinouterchartangle = sin(outerchartangle); - Array outermark(GetNT()); //marks all trigs form actual outer region - Array outertested(GetNT()); //marks tested trigs for outer region - Array pointstochart(GetNP()); //point in chart becomes chartnum - Array innerpointstochart(GetNP()); //point in chart becomes chartnum - Array chartpoints; //point in chart becomes chartnum - Array innerchartpoints; - Array> innerchartpts; - Array dirtycharttrigs; + NgArray outermark(GetNT()); //marks all trigs form actual outer region + NgArray outertested(GetNT()); //marks tested trigs for outer region + NgArray pointstochart(GetNP()); //point in chart becomes chartnum + NgArray innerpointstochart(GetNP()); //point in chart becomes chartnum + NgArray chartpoints; //point in chart becomes chartnum + NgArray innerchartpoints; + NgArray> innerchartpts; + NgArray dirtycharttrigs; - Array chartdistacttrigs (GetNT()); //outercharttrigs + NgArray chartdistacttrigs (GetNT()); //outercharttrigs chartdistacttrigs = 0; @@ -86,7 +86,7 @@ void STLGeometry :: MakeAtlas(Mesh & mesh) //int chartboundarydivisions = 10; markedsegs.SetSize(0); //for testing!!! - Array chartpointchecked(GetNP()); //for dirty-chart-trigs + NgArray chartpointchecked(GetNP()); //for dirty-chart-trigs pointstochart.SetSize(GetNP()); innerpointstochart.SetSize(GetNP()); @@ -659,7 +659,7 @@ int STLGeometry :: AtlasMade() const /* //return 1 if not exists -int AddIfNotExists(Array& list, int x) +int AddIfNotExists(NgArray& list, int x) { int i; for (i = 1; i <= list.Size(); i++) @@ -671,7 +671,7 @@ int AddIfNotExists(Array& list, int x) } */ -void STLGeometry :: GetInnerChartLimes(Array& limes, int chartnum) +void STLGeometry :: GetInnerChartLimes(NgArray& limes, int chartnum) { int j, k; @@ -732,9 +732,9 @@ void STLGeometry :: GetInnerChartLimes(Array& limes, int chartnum) void STLGeometry :: GetDirtyChartTrigs(int chartnum, STLChart& chart, - const Array& outercharttrigs, - Array& chartpointchecked, - Array& dirtytrigs) + const NgArray& outercharttrigs, + NgArray& chartpointchecked, + NgArray& dirtytrigs) { dirtytrigs.SetSize(0); int j,k,n; @@ -765,7 +765,7 @@ void STLGeometry :: GetDirtyChartTrigs(int chartnum, STLChart& chart, cnt = 0; int ap1, ap2, tn1, tn2, l, problem, pn; - Array trigsaroundp; + NgArray trigsaroundp; for (j = chart.GetNChartT(); j >= 1; j--) { diff --git a/libsrc/stlgeom/stlgeommesh.cpp b/libsrc/stlgeom/stlgeommesh.cpp index bc4613d3..a5e8cbcf 100644 --- a/libsrc/stlgeom/stlgeommesh.cpp +++ b/libsrc/stlgeom/stlgeommesh.cpp @@ -12,7 +12,7 @@ namespace netgen { -int EdgeUsed(int p1, int p2, Array& edges, INDEX_2_HASHTABLE& hashtab) +int EdgeUsed(int p1, int p2, NgArray& edges, INDEX_2_HASHTABLE& hashtab) { if (p1 > p2) {swap (p1,p2);} @@ -41,9 +41,9 @@ Point<3> STLGeometry :: PointBetween(const Point<3> & ap1, int t1, TABLE edgepointorigines; TABLE edgepointoriginps; - Array edgetrigs; - Array edgepointnums; - Array edgetriglocinds; + NgArray edgetrigs; + NgArray edgepointnums; + NgArray edgetriglocinds; int size = 3*GetNT(); INDEX_2_HASHTABLE hashtab(size); @@ -59,8 +59,8 @@ Point<3> STLGeometry :: PointBetween(const Point<3> & ap1, int t1, edgepointnums.SetSize(size); edgetriglocinds.SetSize(size); - Array edgelist1; - Array edgelist2; + NgArray edgelist1; + NgArray edgelist2; edgelist1.SetSize(0); edgelist2.SetSize(0); @@ -238,7 +238,7 @@ Point<3> STLGeometry :: PointBetween(const Point<3> & ap1, int t1, if (!endpointorigine) {PrintSysError("No connection found!");} - Array plist; + NgArray plist; plist.Append(ap2); int laste = endpointorigine; @@ -300,9 +300,9 @@ void STLGeometry :: PrepareSurfaceMeshing() meshcharttrigs = 0; } -void STLGeometry::GetMeshChartBoundary (Array & apoints, - Array & points3d, - Array & alines, double h) +void STLGeometry::GetMeshChartBoundary (NgArray & apoints, + NgArray & points3d, + NgArray & alines, double h) { twoint seg, newseg; int zone; @@ -403,7 +403,7 @@ void STLGeometry :: SelectChartOfPoint (const Point<3> & p) { int i, ii; - Array trigsinbox; + NgArray trigsinbox; Box<3> box(p,p); box.Increase (1e-6); @@ -462,7 +462,7 @@ void STLGeometry :: ToPlane (const Point<3> & locpoint, int * trigs, else { - Array trigsinbox; + NgArray trigsinbox; if (!geomsearchtreeon) { @@ -473,7 +473,7 @@ void STLGeometry :: ToPlane (const Point<3> & locpoint, int * trigs, } else { - Array trigsinbox2; + NgArray trigsinbox2; Box<3> box(locpoint, locpoint); box.Increase (range); GetTrianglesInBox (box, trigsinbox2); @@ -737,7 +737,7 @@ void STLGeometry :: RestrictLocalHCurv(class Mesh & mesh, double gh) if (stlparam.resthatlasenable) { - Array minh; //minimales h pro punkt + NgArray minh; //minimales h pro punkt minh.SetSize(GetNP()); for (i = 1; i <= GetNP(); i++) { @@ -841,7 +841,7 @@ void STLGeometry :: RestrictLocalH(class Mesh & mesh, double gh) { PushStatusF("Restrict H due to surface curvature"); - Array minh; //minimales h pro punkt + NgArray minh; //minimales h pro punkt minh.SetSize(GetNP()); for (i = 1; i <= GetNP(); i++) { @@ -933,8 +933,8 @@ void STLGeometry :: RestrictLocalH(class Mesh & mesh, double gh) BoxTree<3> * lsearchtree = new BoxTree<3> (GetBoundingBox().PMin() - Vec3d(1,1,1), GetBoundingBox().PMax() + Vec3d(1,1,1)); - Array pmins(GetNLines()); - Array pmaxs(GetNLines()); + NgArray pmins(GetNLines()); + NgArray pmaxs(GetNLines()); double maxhline; for (i = 1; i <= GetNLines(); i++) @@ -958,7 +958,7 @@ void STLGeometry :: RestrictLocalH(class Mesh & mesh, double gh) pmaxs.Elem(i) = box.PMax(); } - Array linenums; + NgArray linenums; int k2; for (i = 1; i <= GetNLines(); i++) @@ -1068,7 +1068,7 @@ void STLGeometry :: RestrictLocalH(class Mesh & mesh, double gh) //berechne minimale distanz von chart zu einem nicht-outerchart-punkt in jedem randpunkt einer chart - Array acttrigs(GetNT()); //outercharttrigs + NgArray acttrigs(GetNT()); //outercharttrigs acttrigs = 0; for (i = 1; i <= GetNOCharts(); i++) @@ -1116,7 +1116,7 @@ void STLGeometry :: RestrictLocalH(class Mesh & mesh, double gh) } } -void STLGeometry :: RestrictHChartDistOneChart(int chartnum, Array& acttrigs, +void STLGeometry :: RestrictHChartDistOneChart(int chartnum, NgArray& acttrigs, class Mesh & mesh, double gh, double fact, double minh) { static int timer1 = NgProfiler::CreateTimer ("restrictH OneChart 1"); @@ -1131,16 +1131,16 @@ void STLGeometry :: RestrictHChartDistOneChart(int chartnum, Array& acttrig // mincalch = 1E10; //maxcalch = -1E10; - Array limes1; - Array limes2; + NgArray limes1; + NgArray limes2; - Array plimes1; - Array plimes2; + NgArray plimes1; + NgArray plimes2; - Array plimes1trigs; //check from which trig the points come - Array plimes2trigs; + NgArray plimes1trigs; //check from which trig the points come + NgArray plimes2trigs; - Array plimes1origin; //either the original pointnumber or zero, if new point + NgArray plimes1origin; //either the original pointnumber or zero, if new point int divisions = 10; @@ -1276,7 +1276,7 @@ void STLGeometry :: RestrictHChartDistOneChart(int chartnum, Array& acttrig Point3dTree stree(bbox.PMin(), bbox.PMax()); for (int j = 1; j <= plimes2.Size(); j++) stree.Insert (plimes2.Get(j), j); - Array foundpts; + NgArray foundpts; NgProfiler::StopTimer (timer3a); NgProfiler::StartTimer (timer3b); diff --git a/libsrc/stlgeom/stlline.cpp b/libsrc/stlgeom/stlline.cpp index 9a49b748..c95dbd43 100644 --- a/libsrc/stlgeom/stlline.cpp +++ b/libsrc/stlgeom/stlline.cpp @@ -197,7 +197,7 @@ int STLEdgeDataList :: GetNConfCandEPP(int p) const } -void STLEdgeDataList :: BuildLineWithEdge(int ep1, int ep2, Array& line) +void STLEdgeDataList :: BuildLineWithEdge(int ep1, int ep2, NgArray& line) { int status = Get(GetEdgeNum(ep1,ep2)).GetStatus(); @@ -424,7 +424,7 @@ int STLEdgeDataList :: GetNConfCandEPP(int p) const } -void STLEdgeDataList :: BuildLineWithEdge(int ep1, int ep2, Array& line) +void STLEdgeDataList :: BuildLineWithEdge(int ep1, int ep2, NgArray& line) { int status = Get(GetEdgeNum(ep1,ep2)).GetStatus(); @@ -473,7 +473,7 @@ void STLEdgeDataList :: BuildLineWithEdge(int ep1, int ep2, Array& line) } -int Exists(int p1, int p2, const Array& line) +int Exists(int p1, int p2, const NgArray& line) { int i; for (i = 1; i <= line.Size(); i++) @@ -485,7 +485,7 @@ int Exists(int p1, int p2, const Array& line) return 0; } -void STLEdgeDataList :: BuildClusterWithEdge(int ep1, int ep2, Array& line) +void STLEdgeDataList :: BuildClusterWithEdge(int ep1, int ep2, NgArray& line) { int status = Get(GetEdgeNum(ep1,ep2)).GetStatus(); @@ -581,12 +581,12 @@ int STLLine :: GetRightTrig(int nr) const return righttrigs.Get(nr); }; -double STLLine :: GetSegLen(const Array >& ap, int nr) const +double STLLine :: GetSegLen(const NgArray >& ap, int nr) const { return Dist(ap.Get(PNum(nr)),ap.Get(PNum(nr+1))); } -double STLLine :: GetLength(const Array >& ap) const +double STLLine :: GetLength(const NgArray >& ap) const { double len = 0; for (int i = 2; i <= pts.Size(); i++) @@ -596,7 +596,7 @@ double STLLine :: GetLength(const Array >& ap) const return len; } -void STLLine :: GetBoundingBox (const Array > & ap, Box<3> & box) const +void STLLine :: GetBoundingBox (const NgArray > & ap, Box<3> & box) const { box.Set (ap.Get (pts[0])); for (int i = 1; i < pts.Size(); i++) @@ -606,7 +606,7 @@ void STLLine :: GetBoundingBox (const Array > & ap, Box<3> & box) const Point<3> STLLine :: -GetPointInDist(const Array >& ap, double dist, int& index) const +GetPointInDist(const NgArray >& ap, double dist, int& index) const { if (dist <= 0) { @@ -644,8 +644,8 @@ double GetH(const Point3d& p, double x) return stlgh;//+0.5)*(x+0.5); } */ -STLLine* STLLine :: Mesh(const Array >& ap, - Array& mp, double ghi, +STLLine* STLLine :: Mesh(const NgArray >& ap, + NgArray& mp, double ghi, class Mesh& mesh) const { static int timer1a = NgProfiler::CreateTimer ("mesh stl-line 1a"); @@ -678,8 +678,8 @@ STLLine* STLLine :: Mesh(const Array >& ap, int nph = 10+int(maxseglen / minh); //anzahl der integralauswertungen pro segment - Array inthi(GetNS()*nph); - Array curvelen(GetNS()*nph); + NgArray inthi(GetNS()*nph); + NgArray curvelen(GetNS()*nph); NgProfiler::StopTimer (timer1a); NgProfiler::StartTimer (timer1b); diff --git a/libsrc/stlgeom/stlline.hpp b/libsrc/stlgeom/stlline.hpp index 06ce5857..547dd44b 100644 --- a/libsrc/stlgeom/stlline.hpp +++ b/libsrc/stlgeom/stlline.hpp @@ -79,7 +79,7 @@ class STLEdgeDataList { private: INDEX_2_HASHTABLE hashtab; - Array edgedata; + NgArray edgedata; TABLE edgesperpoint; public: @@ -118,7 +118,7 @@ public: void Write(ofstream& of) const; void Read(ifstream& ifs); - void BuildLineWithEdge(int ep1, int ep2, Array& line); + void BuildLineWithEdge(int ep1, int ep2, NgArray& line); int GetNEPPStat(int p, int status) const; int GetNConfCandEPP(int p) const; @@ -145,10 +145,10 @@ class STLLine { private: const STLGeometry * geometry; - Array pts; - Array lefttrigs; - Array righttrigs; - Array dists; + NgArray pts; + NgArray lefttrigs; + NgArray righttrigs; + NgArray dists; int split; public: @@ -158,11 +158,11 @@ public: int NP() const {return pts.Size();} int GetNS() const; void GetSeg(int nr, int& p1, int& p2) const; - double GetSegLen(const Array >& ap, int nr) const; + double GetSegLen(const NgArray >& ap, int nr) const; int GetLeftTrig(int nr) const; int GetRightTrig(int nr) const; double GetDist(int nr) const { return dists.Get(nr);}; - void GetBoundingBox (const Array > & ap, Box<3> & box) const; + void GetBoundingBox (const NgArray > & ap, Box<3> & box) const; void AddLeftTrig(int nr) {lefttrigs.Append(nr);} void AddRightTrig(int nr) {righttrigs.Append(nr);} @@ -170,15 +170,15 @@ public: int StartP() const {return pts.Get(1);} int EndP() const {return pts.Get(pts.Size());} - double GetLength(const Array >& ap) const; + double GetLength(const NgArray >& ap) const; //suche punkt in entfernung (in linienkoordinaten) dist //in index ist letzter punkt VOR dist (d.h. max pts.Size()-1) - Point<3> GetPointInDist(const Array >& ap, double dist, int& index) const; + Point<3> GetPointInDist(const NgArray >& ap, double dist, int& index) const; //return a meshed polyline - STLLine* Mesh(const Array >& ap, - Array& mp, double ghi, + STLLine* Mesh(const NgArray >& ap, + NgArray& mp, double ghi, class Mesh& mesh) const; void DoSplit() {split = 1;} diff --git a/libsrc/stlgeom/stltool.cpp b/libsrc/stlgeom/stltool.cpp index 41f0f1d7..683fdc83 100644 --- a/libsrc/stlgeom/stltool.cpp +++ b/libsrc/stlgeom/stltool.cpp @@ -13,7 +13,7 @@ namespace netgen //add a point into a pointlist, return pointnumber -int AddPointIfNotExists(Array& ap, const Point3d& p, double eps) +int AddPointIfNotExists(NgArray& ap, const Point3d& p, double eps) { double eps2 = sqr(eps); for (int i = 1; i <= ap.Size(); i++) @@ -349,7 +349,7 @@ int STLTriangle :: GetNeighbourPointsAndOpposite(const STLTriangle& t, int& p1, return 0; } -Vec<3> STLTriangle :: GeomNormal(const Array >& ap) const +Vec<3> STLTriangle :: GeomNormal(const NgArray >& ap) const { const Point<3> & p1 = ap.Get(PNum(1)); const Point<3> & p2 = ap.Get(PNum(2)); @@ -382,13 +382,13 @@ void STLTriangle :: ChangeOrientation() -double STLTriangle :: Area(const Array >& ap) const +double STLTriangle :: Area(const NgArray >& ap) const { return 0.5 * Cross(ap.Get(PNum(2))-ap.Get(PNum(1)), ap.Get(PNum(3))-ap.Get(PNum(1))).Length(); } -double STLTriangle :: MinHeight(const Array >& ap) const +double STLTriangle :: MinHeight(const NgArray >& ap) const { double ml = MaxLength(ap); if (ml != 0) {return 2.*Area(ap)/ml;} @@ -396,14 +396,14 @@ double STLTriangle :: MinHeight(const Array >& ap) const return 0; } -double STLTriangle :: MaxLength(const Array >& ap) const +double STLTriangle :: MaxLength(const NgArray >& ap) const { return max3(Dist(ap.Get(PNum(1)),ap.Get(PNum(2))), Dist(ap.Get(PNum(2)),ap.Get(PNum(3))), Dist(ap.Get(PNum(3)),ap.Get(PNum(1)))); } -void STLTriangle :: ProjectInPlain(const Array >& ap, +void STLTriangle :: ProjectInPlain(const NgArray >& ap, const Vec<3> & n, Point<3> & pp) const { const Point<3> & p1 = ap.Get(PNum(1)); @@ -430,7 +430,7 @@ void STLTriangle :: ProjectInPlain(const Array >& ap, } -int STLTriangle :: ProjectInPlain (const Array >& ap, +int STLTriangle :: ProjectInPlain (const NgArray >& ap, const Vec<3> & nproj, Point<3> & pp, Vec<3> & lam) const { @@ -468,7 +468,7 @@ int STLTriangle :: ProjectInPlain (const Array >& ap, -void STLTriangle :: ProjectInPlain(const Array >& ap, +void STLTriangle :: ProjectInPlain(const NgArray >& ap, Point<3> & pp) const { const Point<3> & p1 = ap.Get(PNum(1)); @@ -488,7 +488,7 @@ void STLTriangle :: ProjectInPlain(const Array >& ap, pp = pp + (nfact) * nt; } -int STLTriangle :: PointInside(const Array > & ap, +int STLTriangle :: PointInside(const NgArray > & ap, const Point<3> & pp) const { const Point<3> & p1 = ap.Get(PNum(1)); @@ -532,7 +532,7 @@ int STLTriangle :: PointInside(const Array > & ap, return 0; } -double STLTriangle :: GetNearestPoint(const Array >& ap, +double STLTriangle :: GetNearestPoint(const NgArray >& ap, Point<3> & p3d) const { Point<3> p = p3d; @@ -609,10 +609,10 @@ STLTopEdge :: STLTopEdge (int p1, int p2, int trig1, int trig2) STLChart :: STLChart(STLGeometry * ageometry) { - // charttrigs = new Array (0,0); - // outertrigs = new Array (0,0); - // ilimit = new Array (0,0); - // olimit = new Array (0,0); + // charttrigs = new NgArray (0,0); + // outertrigs = new NgArray (0,0); + // ilimit = new NgArray (0,0); + // olimit = new NgArray (0,0); geometry = ageometry; @@ -702,7 +702,7 @@ int STLChart :: IsInWholeChart(int nr) const void STLChart :: GetTrianglesInBox (const Point3d & pmin, const Point3d & pmax, - Array & trias) const + NgArray & trias) const { if (geomsearchtreeon) {PrintMessage(5,"geomsearchtreeon is set!!!");} @@ -731,7 +731,7 @@ void STLChart :: GetTrianglesInBox (const Point3d & pmin, } //trigs may contain the same triangle double -void STLChart :: MoveToOuterChart(const Array& trigs) +void STLChart :: MoveToOuterChart(const NgArray& trigs) { if (!trigs.Size()) return; for (int i = 1; i <= trigs.Size(); i++) @@ -744,7 +744,7 @@ void STLChart :: MoveToOuterChart(const Array& trigs) } //trigs may contain the same triangle double -void STLChart :: DelChartTrigs(const Array& trigs) +void STLChart :: DelChartTrigs(const NgArray& trigs) { if (!trigs.Size()) return; @@ -820,7 +820,7 @@ public: /* STLBoundarySeg :: -STLBoundarySeg (int ai1, int ai2, const Array > & points, +STLBoundarySeg (int ai1, int ai2, const NgArray > & points, const STLChart * chart) { i1 = ai1; @@ -1040,7 +1040,7 @@ void STLBoundary ::AddTriangle(const STLTriangle & t) } int STLBoundary :: TestSeg(const Point<3>& p1, const Point<3> & p2, const Vec<3> & sn, - double sinchartangle, int divisions, Array >& points, double eps) + double sinchartangle, int divisions, NgArray >& points, double eps) { if (usechartnormal) return TestSegChartNV (p1, p2, sn); @@ -1049,7 +1049,7 @@ int STLBoundary :: TestSeg(const Point<3>& p1, const Point<3> & p2, const Vec<3> // for statistics { int i; - static Array cntclass; + static NgArray cntclass; static int cnt = 0; static int cnti = 0, cnto = 0; static long int cntsegs = 0; diff --git a/libsrc/stlgeom/stltool.hpp b/libsrc/stlgeom/stltool.hpp index 1f2478a4..b602ad94 100644 --- a/libsrc/stlgeom/stltool.hpp +++ b/libsrc/stlgeom/stltool.hpp @@ -18,7 +18,7 @@ extern int usechartnormal; extern int chartdebug; extern int geomsearchtreeon; -extern int AddPointIfNotExists(Array& ap, const Point3d& p, double eps = 1e-8); +extern int AddPointIfNotExists(NgArray& ap, const Point3d& p, double eps = 1e-8); //get distance from line lp1-lp2 to point p extern double GetDistFromLine(const Point<3>& lp1, const Point<3>& lp2, Point<3>& p); extern double GetDistFromInfiniteLine(const Point<3>& lp1, const Point<3>& lp2, const Point<3>& p); @@ -35,7 +35,7 @@ extern void FIOReadStringE(istream& ios, char* str, int len); extern void FIOWriteString(ostream& ios, char* str, int len); -typedef Array * ArrayINTPTR; +typedef NgArray * ArrayINTPTR; class STLGeometry; @@ -43,12 +43,12 @@ class STLChart { private: STLGeometry * geometry; - Array charttrigs; // trigs which only belong to this chart - Array outertrigs; // trigs which belong to other charts + NgArray charttrigs; // trigs which only belong to this chart + NgArray outertrigs; // trigs which belong to other charts BoxTree<3> * searchtree; // ADT containing outer trigs - Array olimit; //outer limit of outer chart - Array ilimit; //outer limit of inner chart + NgArray olimit; //outer limit of outer chart + NgArray ilimit; //outer limit of inner chart public: @@ -75,7 +75,7 @@ public: void GetTrianglesInBox (const Point3d & pmin, const Point3d & pmax, - Array & trias) const; + NgArray & trias) const; void AddOLimit(twoint l) {olimit.Append(l);} void AddILimit(twoint l) {ilimit.Append(l);} @@ -89,8 +89,8 @@ public: twoint GetILimit(int i) const {return ilimit.Get(i);} //move triangles trigs (local chart-trig numbers) to outer chart - void MoveToOuterChart(const Array& trigs); - void DelChartTrigs(const Array& trigs); + void MoveToOuterChart(const NgArray& trigs); + void DelChartTrigs(const NgArray& trigs); // define local coordinate system, JS: @@ -120,7 +120,7 @@ class STLBoundarySeg int smoothedge; public: STLBoundarySeg () { ; } - STLBoundarySeg (int ai1, int ai2, const Array > & points, + STLBoundarySeg (int ai1, int ai2, const NgArray > & points, const STLChart * chart) : p1(points.Get(ai1)), p2(points.Get(ai2)), i1(ai1), i2(ai2) @@ -160,7 +160,7 @@ class STLBoundary private: STLGeometry * geometry; const STLChart * chart; - Array boundary; + NgArray boundary; ClosedHashTable boundary_ht; BoxTree<2,INDEX_2> * searchtree = nullptr; public: @@ -181,7 +181,7 @@ public: void BuildSearchTree(); void DeleteSearchTree(); int TestSeg(const Point<3> & p1, const Point<3> & p2, const Vec<3> & sn, - double sinchartangle, int divisions, Array >& points, + double sinchartangle, int divisions, NgArray >& points, double eps); int TestSegChartNV(const Point3d& p1, const Point3d& p2, const Vec3d& sn); diff --git a/libsrc/stlgeom/stltopology.cpp b/libsrc/stlgeom/stltopology.cpp index 7c32b0e4..a1a1ef61 100644 --- a/libsrc/stlgeom/stltopology.cpp +++ b/libsrc/stlgeom/stltopology.cpp @@ -31,7 +31,7 @@ STLTopology :: ~STLTopology() STLGeometry * STLTopology :: LoadBinary (istream & ist) { STLGeometry * geom = new STLGeometry(); - Array readtrigs; + NgArray readtrigs; PrintMessage(1,"Read STL binary file"); @@ -191,7 +191,7 @@ STLGeometry * STLTopology :: LoadNaomi (istream & ist) { int i; STLGeometry * geom = new STLGeometry(); - Array readtrigs; + NgArray readtrigs; PrintFnStart("read NAOMI file format"); @@ -204,7 +204,7 @@ STLGeometry * STLTopology :: LoadNaomi (istream & ist) int noface, novertex; - Array > readpoints; + NgArray > readpoints; ist >> buf; if (strcmp (buf, "NODES") == 0) @@ -340,7 +340,7 @@ STLGeometry * STLTopology ::Load (istream & ist) { STLGeometry * geom = new STLGeometry(); - Array readtrigs; + NgArray readtrigs; char buf[100]; Point<3> pts[3]; @@ -444,7 +444,7 @@ STLGeometry * STLTopology ::Load (istream & ist) -void STLTopology :: InitSTLGeometry(const Array & readtrigs) +void STLTopology :: InitSTLGeometry(const NgArray & readtrigs) { // const double geometry_tol_fact = 1E6; // distances lower than max_box_size/tol are ignored @@ -470,7 +470,7 @@ void STLTopology :: InitSTLGeometry(const Array & readtrigs) pointtree = new Point3dTree (bb.PMin(), bb.PMax()); - Array pintersect; + NgArray pintersect; pointtol = boundingbox.Diam() * stldoctor.geom_tol_fact; PrintMessage(5,"point tolerance = ", pointtol); @@ -534,7 +534,7 @@ int STLTopology :: GetPointNum (const Point<3> & p) Point<3> pmin = p - Vec<3> (pointtol, pointtol, pointtol); Point<3> pmax = p + Vec<3> (pointtol, pointtol, pointtol); - Array pintersect; + NgArray pintersect; pointtree->GetIntersecting (pmin, pmax, pintersect); if (pintersect.Size() == 1) @@ -853,7 +853,7 @@ void STLTopology :: GetTrianglesInBox (/* const Point<3> & pmax, */ const Box<3> & box, - Array & btrias) const + NgArray & btrias) const { if (searchtree) @@ -1004,7 +1004,7 @@ void STLTopology :: OrientAfterTrig (int trig) if (starttrig >= 1 && starttrig <= GetNT()) { - Array oriented; + NgArray oriented; oriented.SetSize(GetNT()); int i; for (i = 1; i <= oriented.Size(); i++) @@ -1016,9 +1016,9 @@ void STLTopology :: OrientAfterTrig (int trig) int k; - Array list1; + NgArray list1; list1.SetSize(0); - Array list2; + NgArray list2; list2.SetSize(0); list1.Append(starttrig); diff --git a/libsrc/stlgeom/stltopology.hpp b/libsrc/stlgeom/stltopology.hpp index a76d5ee5..0c4abeb9 100644 --- a/libsrc/stlgeom/stltopology.hpp +++ b/libsrc/stlgeom/stltopology.hpp @@ -149,7 +149,7 @@ public: // NON-normalized geometry - normal vector - Vec<3> GeomNormal(const Array >& ap) const; + Vec<3> GeomNormal(const NgArray >& ap) const; // Stored normal vector, normalized void SetNormal (const Vec<3> & n); @@ -159,10 +159,10 @@ public: void ChangeOrientation(); //project with a certain normal vector in plane - void ProjectInPlain(const Array >& ap, + void ProjectInPlain(const NgArray >& ap, const Vec<3> & n, Point<3> & pp) const; //project with the triangle's normal vector in plane - void ProjectInPlain(const Array > & ap, Point<3> & pp) const; + void ProjectInPlain(const NgArray > & ap, Point<3> & pp) const; /* @@ -177,20 +177,20 @@ public: pp(output) = P1 + lam1 v1 + lam2 v2 */ - int ProjectInPlain (const Array >& ap, + int ProjectInPlain (const NgArray >& ap, const Vec<3> & nproj, Point<3> & pp, Vec<3> & lam) const; - int PointInside(const Array >& ap, const Point<3> & pp) const; + int PointInside(const NgArray >& ap, const Point<3> & pp) const; //get nearest point on triangle and distance to it - double GetNearestPoint(const Array >& ap, + double GetNearestPoint(const NgArray >& ap, Point<3> & p3d) const; - double Area(const Array >& ap) const; + double Area(const NgArray >& ap) const; - double MinHeight(const Array >& ap) const; - double MaxLength(const Array >& ap) const; + double MinHeight(const NgArray >& ap) const; + double MaxLength(const NgArray >& ap) const; //max length of a side of triangle int GetFaceNum() {return facenum;} @@ -250,9 +250,9 @@ ostream& operator<<(ostream& os, const STLTriangle& t); class STLTopology { protected: - Array trias; - Array topedges; - Array > points; + NgArray trias; + NgArray topedges; + NgArray > points; // mapping of sorted pair of points to topedge INDEX_2_HASHTABLE * ht_topedges; @@ -298,7 +298,7 @@ public: FindNeighbourTrigs(); } - virtual void InitSTLGeometry (const Array & readtrigs); + virtual void InitSTLGeometry (const NgArray & readtrigs); virtual void TopologyChanged() {}; //do some things, if topology changed! @@ -307,7 +307,7 @@ public: void GetTrianglesInBox (const Box<3> & box, - Array & trias) const; + NgArray & trias) const; int GetNP() const { return points.Size(); } @@ -315,7 +315,7 @@ public: const Point<3> & GetPoint(int nr) const { return points.Get(nr); } int GetPointNum (const Point<3> & p); void SetPoint(int nr, const Point<3> & p) { points.Elem(nr) = p; } - const Array >& GetPoints() const { return points; } + const NgArray >& GetPoints() const { return points; } const Point<3> & operator[] (STLPointIndex i) const { return points[i]; } Point<3> & operator[] (STLPointIndex i) { return points[i]; } diff --git a/libsrc/stlgeom/vsstl.cpp b/libsrc/stlgeom/vsstl.cpp index ca1f2cbf..ac8c42ff 100644 --- a/libsrc/stlgeom/vsstl.cpp +++ b/libsrc/stlgeom/vsstl.cpp @@ -153,7 +153,7 @@ void VisualSceneSTLMeshing :: DrawScene () MoCombine cb1(&z1,&z2); model.Add(&cb1); - Array trigs; + NgArray trigs; model.GetTriangles(trigs); int i, k; glBegin (GL_TRIANGLES); @@ -382,7 +382,7 @@ void VisualSceneSTLMeshing :: DrawScene () { //multiedge - const Array& me = stlgeometry->SelectedMultiEdge(); + const NgArray& me = stlgeometry->SelectedMultiEdge(); if (stlgeometry->GetSelectTrig() > 0 && stlgeometry->GetSelectTrig() <= stlgeometry->GetNT() && me.Size()) diff --git a/libsrc/stlgeom/vsstl.hpp b/libsrc/stlgeom/vsstl.hpp index 8ebd52bc..6a98d8a6 100644 --- a/libsrc/stlgeom/vsstl.hpp +++ b/libsrc/stlgeom/vsstl.hpp @@ -12,7 +12,7 @@ namespace netgen class VisualSceneSTLGeometry : public VisualScene { - Array trilists; + NgArray trilists; class STLGeometry * stlgeometry; public: @@ -27,7 +27,7 @@ namespace netgen class VisualSceneSTLMeshing : public VisualScene { - Array trilists; + NgArray trilists; int selecttrig, nodeofseltrig; class STLGeometry * stlgeometry; diff --git a/libsrc/visualization/meshdoc.hpp b/libsrc/visualization/meshdoc.hpp index a5091b23..6cdb1d8c 100644 --- a/libsrc/visualization/meshdoc.hpp +++ b/libsrc/visualization/meshdoc.hpp @@ -12,7 +12,7 @@ class VisualSceneMeshDoctor : public VisualScene int selpoint, selpoint2; // for edgemarking: - Array edgedist; + NgArray edgedist; int markedgedist; diff --git a/libsrc/visualization/mvdraw.cpp b/libsrc/visualization/mvdraw.cpp index ca563714..65f25975 100644 --- a/libsrc/visualization/mvdraw.cpp +++ b/libsrc/visualization/mvdraw.cpp @@ -202,7 +202,7 @@ namespace netgen } - void VisualScene :: ArbitraryRotation (const Array & alpha, const Array & vec) + void VisualScene :: ArbitraryRotation (const NgArray & alpha, const NgArray & vec) { glPushMatrix(); @@ -229,8 +229,8 @@ namespace netgen void VisualScene :: ArbitraryRotation (const double alpha, const Vec3d & vec) { - Array a(1); a[0] = alpha; - Array v(1); v[0] = vec; + NgArray a(1); a[0] = alpha; + NgArray v(1); v[0] = vec; ArbitraryRotation(a,v); } diff --git a/libsrc/visualization/mvdraw.hpp b/libsrc/visualization/mvdraw.hpp index 39efbc5f..9df510a7 100644 --- a/libsrc/visualization/mvdraw.hpp +++ b/libsrc/visualization/mvdraw.hpp @@ -49,7 +49,7 @@ namespace netgen DLL_HEADER void CalcTransformationMatrices(); DLL_HEADER void StandardRotation (const char * dir); - DLL_HEADER void ArbitraryRotation (const Array & alpha, const Array & vec); + DLL_HEADER void ArbitraryRotation (const NgArray & alpha, const NgArray & vec); DLL_HEADER void ArbitraryRotation (const double alpha, const Vec3d & vec); DLL_HEADER void MouseMove(int oldx, int oldy, @@ -142,8 +142,8 @@ namespace netgen #ifdef PARALLELGL - Array par_linelists; - Array par_filledlists; + NgArray par_linelists; + NgArray par_filledlists; #endif MouseEventHandler * user_me_handler; diff --git a/libsrc/visualization/stlmeshing.cpp b/libsrc/visualization/stlmeshing.cpp index 452dbd92..70699c56 100644 --- a/libsrc/visualization/stlmeshing.cpp +++ b/libsrc/visualization/stlmeshing.cpp @@ -153,7 +153,7 @@ void VisualSceneSTLMeshing :: DrawScene () MoCombine cb1(&z1,&z2); model.Add(&cb1); - Array trigs; + NgArray trigs; model.GetTriangles(trigs); int i, k; glBegin (GL_TRIANGLES); @@ -382,7 +382,7 @@ void VisualSceneSTLMeshing :: DrawScene () { //multiedge - const Array& me = stlgeometry->SelectedMultiEdge(); + const NgArray& me = stlgeometry->SelectedMultiEdge(); if (stlgeometry->GetSelectTrig() > 0 && stlgeometry->GetSelectTrig() <= stlgeometry->GetNT() && me.Size()) diff --git a/libsrc/visualization/vsfieldlines.cpp b/libsrc/visualization/vsfieldlines.cpp index 5e259b42..dce298bd 100644 --- a/libsrc/visualization/vsfieldlines.cpp +++ b/libsrc/visualization/vsfieldlines.cpp @@ -38,7 +38,7 @@ namespace netgen { c.SetSize(2); c[0] = 0; c[1] = 0.5; b.SetSize(2); b[0] = 0; b[1] = 1; - Array size(2); + NgArray size(2); size[0] = 0; size[1] = 1; a = new TABLE(size); a->Set(2,1,0.5); // Set, Get: 1-based! @@ -48,7 +48,7 @@ namespace netgen { c.SetSize(3); c[0] = 0; c[1] = 1; c[2] = 0.5; b.SetSize(3); b[0] = b[1] = 1./6.; b[2] = 2./3.; - Array size(3); + NgArray size(3); size[0] = 0; size[1] = 1; size[2] = 2; a = new TABLE(size); a->Set(2,1,1); @@ -59,7 +59,7 @@ namespace netgen { c.SetSize(4); c[0] = 0; c[1] = c[2] = 0.5; c[3] = 1; b.SetSize(4); b[0] = b[3] = 1./6.; b[1] = b[2] = 1./3.; - Array size(4); + NgArray size(4); size[0] = 0; size[1] = 1; size[2] = 2; size[3] = 3; a = new TABLE(size); a->Set(2,1,0.5); @@ -181,15 +181,15 @@ namespace netgen - void FieldLineCalc :: GenerateFieldLines(Array & potential_startpoints, const int numlines, const int gllist, + void FieldLineCalc :: GenerateFieldLines(NgArray & potential_startpoints, const int numlines, const int gllist, const double minval, const double maxval, const int logscale, double phaser, double phasei) { - Array points; - Array values; - Array drawelems; - Array dirstart; + NgArray points; + NgArray values; + NgArray drawelems; + NgArray dirstart; if(vsol -> iscomplex) @@ -317,7 +317,7 @@ namespace netgen - void FieldLineCalc :: Calc(const Point3d & startpoint, Array & points, Array & vals, Array & drawelems, Array & dirstart) + void FieldLineCalc :: Calc(const Point3d & startpoint, NgArray & points, NgArray & vals, NgArray & drawelems, NgArray & dirstart) { double lami[3], startlami[3]; double values[6]; @@ -440,7 +440,7 @@ namespace netgen - void VisualSceneSolution :: BuildFieldLinesFromBox(Array & startpoints) + void VisualSceneSolution :: BuildFieldLinesFromBox(NgArray & startpoints) { shared_ptr mesh = GetMesh(); if (!mesh) return; @@ -470,7 +470,7 @@ namespace netgen } } - void VisualSceneSolution :: BuildFieldLinesFromLine(Array & startpoints) + void VisualSceneSolution :: BuildFieldLinesFromLine(NgArray & startpoints) { shared_ptr mesh = GetMesh(); if (!mesh) return; @@ -489,7 +489,7 @@ namespace netgen } - void VisualSceneSolution :: BuildFieldLinesFromFile(Array & startpoints) + void VisualSceneSolution :: BuildFieldLinesFromFile(NgArray & startpoints) { shared_ptr mesh = GetMesh(); if (!mesh) return; @@ -546,7 +546,7 @@ namespace netgen for(int i=0; i<6; i++) (*infile) >> fieldlines_startarea_parameter[i]; (*infile) >> iparam; - Array auxpoints(iparam); + NgArray auxpoints(iparam); if (keyword == "box") BuildFieldLinesFromBox(auxpoints); @@ -571,12 +571,12 @@ namespace netgen } - void VisualSceneSolution :: BuildFieldLinesFromFace(Array & startpoints) + void VisualSceneSolution :: BuildFieldLinesFromFace(NgArray & startpoints) { shared_ptr mesh = GetMesh(); if (!mesh) return; - Array elements_2d; + NgArray elements_2d; //cout << "fieldlines_startface " << fieldlines_startface << endl; mesh->GetSurfaceElementsOfFace(fieldlines_startface,elements_2d); @@ -694,7 +694,7 @@ namespace netgen num_startpoints *= 10; - Array startpoints(num_startpoints); + NgArray startpoints(num_startpoints); for (int ln = 0; ln < num_fieldlineslists; ln++) diff --git a/libsrc/visualization/vsmesh.cpp b/libsrc/visualization/vsmesh.cpp index 04ec7e7b..bb677d33 100644 --- a/libsrc/visualization/vsmesh.cpp +++ b/libsrc/visualization/vsmesh.cpp @@ -344,7 +344,7 @@ namespace netgen Point3d pmin, pmax; static double oldrad = 0; - Array faces; + NgArray faces; int meshtimestamp = mesh->GetTimeStamp(); if (meshtimestamp > vstimestamp || zoomall) @@ -490,7 +490,7 @@ namespace netgen if (vispar.drawfacenumbers) { const MeshTopology & top = mesh->GetTopology(); - Array v; + NgArray v; for (int i = 1; i <= top.GetNFaces(); i++) { top.GetFaceVertices (i, v); @@ -521,11 +521,11 @@ namespace netgen if (vispar.drawelementnumbers) { - Array v; + NgArray v; for (int i = 1; i <= mesh->GetNE(); i++) { // const ELEMENTTYPE & eltype = mesh->ElementType(i); - Array pnums; + NgArray pnums; Point3d p; const Element & el = mesh->VolumeElement (i); @@ -1005,7 +1005,7 @@ namespace netgen int hoplotn = 1 << vispar.subdivisions; - Array seia; + NgArray seia; for (int faceindex = 1; faceindex <= mesh->GetNFD(); faceindex++) @@ -1815,7 +1815,7 @@ namespace netgen - Array faces; + NgArray faces; BitArray shownode(mesh->GetNP()); if (vispar.clipping.enable) @@ -1955,8 +1955,8 @@ namespace netgen int order = curv.GetOrder(); - Array > ploc ( (order+1)*(order+1) ); - Array > pglob ( (order+1)*(order+1) ); + NgArray > ploc ( (order+1)*(order+1) ); + NgArray > pglob ( (order+1)*(order+1) ); Point<3> fpts[3]; for (int trig = 0; trig < 4; trig++) @@ -2141,7 +2141,7 @@ namespace netgen static float prismcol[] = { 0.0f, 1.0f, 1.0f, 1.0f }; glLineWidth (1.0f); - Array faces; + NgArray faces; glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, prismcol); @@ -2470,7 +2470,7 @@ namespace netgen glLineWidth (1.0f); glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, hexcol); - Array faces; + NgArray faces; // int hoplotn = 1 << vispar.subdivisions; for (ElementIndex ei = 0; ei < mesh->GetNE(); ei++) @@ -2682,7 +2682,7 @@ namespace netgen glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, pyramidcol); glLineWidth (1.0f); - Array faces; + NgArray faces; for (ElementIndex ei = 0; ei < mesh->GetNE(); ei++) { diff --git a/libsrc/visualization/vssolution.cpp b/libsrc/visualization/vssolution.cpp index af054509..1b66a7b3 100644 --- a/libsrc/visualization/vssolution.cpp +++ b/libsrc/visualization/vssolution.cpp @@ -881,7 +881,7 @@ namespace netgen if (autoscale) GetMinMax (vecfunction, 0, minval, maxval); - Array cpp; + NgArray cpp; GetClippingPlaneGrid (cpp); for (int i = 0; i < cpp.Size(); i++) @@ -1107,8 +1107,8 @@ namespace netgen clipplane_isolinelist = glGenLists (1); glNewList (clipplane_isolinelist, GL_COMPILE); - Array cpt; - Array pts; + NgArray cpt; + NgArray pts; GetClippingPlaneTrigs (cpt, pts); bool drawelem; @@ -1157,8 +1157,8 @@ namespace netgen glNewList (element1dlist, GL_COMPILE); int npt = (1 << subdivisions) + 1; - Array pref(npt), values(npt); - Array > points(npt); + NgArray pref(npt), values(npt); + NgArray > points(npt); const SolData * sol = NULL; if (scalfunction != -1) sol = soldata[scalfunction]; @@ -1169,7 +1169,7 @@ namespace netgen int ncomp = 0; if (sol) ncomp = sol->components; if (vsol) ncomp = vsol->components; - Array mvalues(ncomp); + NgArray mvalues(ncomp); for (int i = 0; i < npt; i++) @@ -1300,29 +1300,29 @@ namespace netgen int n = 1 << subdivisions; int npt = sqr(n+1); - Array > pref (npt); - Array > points (npt); - Array > dxdxis (npt); - Array > nvs(npt); - Array values(npt); + NgArray > pref (npt); + NgArray > points (npt); + NgArray > dxdxis (npt); + NgArray > nvs(npt); + NgArray values(npt); - Array mvalues(npt); + NgArray mvalues(npt); int sol_comp = (sol && sol->draw_surface) ? sol->components : 0; - Array> > simd_pref ( (npt+SIMD::Size()-1)/SIMD::Size() ); - Array> > simd_points ( (npt+SIMD::Size()-1)/SIMD::Size() ); - Array> > simd_dxdxis ( (npt+SIMD::Size()-1)/SIMD::Size() ); - Array> > simd_nvs( (npt+SIMD::Size()-1)/SIMD::Size() ); - Array> simd_values( (npt+SIMD::Size()-1)/SIMD::Size() * sol_comp); + NgArray> > simd_pref ( (npt+SIMD::Size()-1)/SIMD::Size() ); + NgArray> > simd_points ( (npt+SIMD::Size()-1)/SIMD::Size() ); + NgArray> > simd_dxdxis ( (npt+SIMD::Size()-1)/SIMD::Size() ); + NgArray> > simd_nvs( (npt+SIMD::Size()-1)/SIMD::Size() ); + NgArray> simd_values( (npt+SIMD::Size()-1)/SIMD::Size() * sol_comp); - // Array> glob_pnts; - // Array> glob_nvs; - // Array glob_values; + // NgArray> glob_pnts; + // NgArray> glob_nvs; + // NgArray glob_values; if (sol && sol->draw_surface) mvalues.SetSize (npt * sol->components); - Array > valuesc(npt); + NgArray > valuesc(npt); #ifdef USE_BUFFERS if (has_surfel_vbo) @@ -1526,7 +1526,7 @@ namespace netgen simd_pref[i](1) = [&] (size_t j) { size_t ii = i*simd_size+j; return (ii < npt) ? pref[ii](1) : 0; }; } - Array ind_reftrig; + NgArray ind_reftrig; for (int iy = 0, ii = 0; iy < n; iy++,ii++) for (int ix = 0; ix < n-iy; ix++, ii++) { @@ -1536,7 +1536,7 @@ namespace netgen for (int j = 0; j < nv; j++) ind_reftrig.Append (ind[j]); } - Array glob_ind; + NgArray glob_ind; glob_ind.SetSize(ind_reftrig.Size()); @@ -1950,12 +1950,12 @@ namespace netgen int n = 1 << subdivisions; int n3 = (n+1)*(n+1)*(n+1); - Array > grid(n3); - Array > locgrid(n3); - Array > trans(n3); - Array val1(n3*sol->components); - Array > grads1(n3); - Array compress(n3); + NgArray > grid(n3); + NgArray > locgrid(n3); + NgArray > trans(n3); + NgArray val1(n3*sol->components); + NgArray > grads1(n3); + NgArray compress(n3); MatrixFixWidth<3> pointmat(8); grads1 = Vec<3> (0.0); @@ -2191,7 +2191,7 @@ namespace netgen - void VisualSceneSolution :: DrawTrigSurfaceVectors(const Array< Point<3> > & lp, + void VisualSceneSolution :: DrawTrigSurfaceVectors(const NgArray< Point<3> > & lp, const Point<3> & pmin, const Point<3> & pmax, const int sei, const SolData * vsol) { @@ -2345,7 +2345,7 @@ namespace netgen if (el.GetType() == TRIG || el.GetType() == TRIG6) { - Array< Point<3> > lp(3); + NgArray< Point<3> > lp(3); lp[0] = mesh->Point(el[2]); lp[1] = mesh->Point(el[0]); @@ -2452,7 +2452,7 @@ namespace netgen else if (el.GetType() == QUAD) { /* - Array < Point<3> > lp(3); + NgArray < Point<3> > lp(3); lp[0] = mesh->Point(el[0]); lp[1] = mesh->Point(el[1]); @@ -3961,8 +3961,8 @@ namespace netgen - void VisualSceneSolution :: GetClippingPlaneTrigs (Array & trigs, - Array & pts) + void VisualSceneSolution :: GetClippingPlaneTrigs (NgArray & trigs, + NgArray & pts) { shared_ptr mesh = GetMesh(); @@ -3991,23 +3991,23 @@ namespace netgen int cntce; int cpe1 = 0, cpe2 = 0, cpe3 = 0; - // Array loctets; - // Array loctetsloc; - // Array > pointsloc; + // NgArray loctets; + // NgArray loctetsloc; + // NgArray > pointsloc; int n = 1 << subdivisions; int n3 = (n+1)*(n+1)*(n+1); - Array > grid(n3); - Array > locgrid(n3); - Array > trans(n3); - Array val(n3); - Array locposval(n3); - Array compress(n3); + NgArray > grid(n3); + NgArray > locgrid(n3); + NgArray > trans(n3); + NgArray val(n3); + NgArray locposval(n3); + NgArray compress(n3); // NgProfiler::StartTimer (timer_vals); - Array vertval(mesh->GetNP()); - Array posval(mesh->GetNP()); + NgArray vertval(mesh->GetNP()); + NgArray posval(mesh->GetNP()); for (PointIndex pi = vertval.Begin(); pi < vertval.End(); pi++) { Point<3> vert = (*mesh)[pi]; @@ -4309,7 +4309,7 @@ namespace netgen } } - void VisualSceneSolution :: GetClippingPlaneGrid (Array & pts) + void VisualSceneSolution :: GetClippingPlaneGrid (NgArray & pts) { shared_ptr mesh = GetMesh(); @@ -4377,7 +4377,7 @@ namespace netgen { InitParallelGL(); - Array parlists (ntasks); + NgArray parlists (ntasks); MyMPI_SendCmd ("redraw"); MyMPI_SendCmd ("clipplanetrigs"); @@ -4410,8 +4410,8 @@ namespace netgen glNewList (clipplanelist_scal, GL_COMPILE); - Array trigs; - Array points; + NgArray trigs; + NgArray points; GetClippingPlaneTrigs (trigs, points); glNormal3d (-clipplane[0], -clipplane[1], -clipplane[2]); @@ -4433,14 +4433,14 @@ namespace netgen for (int j = 0; j < 3; j++) maxlpnr = max2 (maxlpnr, trigs[i].points[j].locpnr); - Array vals(maxlpnr+1); - Array > valsc(maxlpnr+1); - Array elnrs(maxlpnr+1); - Array trigok(maxlpnr+1); - Array > locpoints(maxlpnr+1); - Array > globpoints(maxlpnr+1); - Array > jacobi(maxlpnr+1); - Array mvalues( (maxlpnr+1) * sol->components); + NgArray vals(maxlpnr+1); + NgArray > valsc(maxlpnr+1); + NgArray elnrs(maxlpnr+1); + NgArray trigok(maxlpnr+1); + NgArray > locpoints(maxlpnr+1); + NgArray > globpoints(maxlpnr+1); + NgArray > jacobi(maxlpnr+1); + NgArray mvalues( (maxlpnr+1) * sol->components); trigok = false; elnrs = -1; diff --git a/libsrc/visualization/vssolution.hpp b/libsrc/visualization/vssolution.hpp index 56d757df..1fa815f8 100644 --- a/libsrc/visualization/vssolution.hpp +++ b/libsrc/visualization/vssolution.hpp @@ -76,7 +76,7 @@ class DLL_HEADER VisualSceneSolution : public VisualScene int fieldlineslist; int num_fieldlineslists; int fieldlines_startarea; - Array fieldlines_startarea_parameter; + NgArray fieldlines_startarea_parameter; int fieldlines_startface; string fieldlines_filename; double fieldlines_reltolerance; @@ -102,11 +102,11 @@ class DLL_HEADER VisualSceneSolution : public VisualScene #ifdef PARALLELGL - Array par_linelists; - Array par_surfellists; + NgArray par_linelists; + NgArray par_surfellists; #endif - Array user_vis; + NgArray user_vis; public: @@ -154,7 +154,7 @@ public: - Array soldata; + NgArray soldata; int usetexture; // 0..no, 1..1D texture (standard), 2..2D-texture (complex) @@ -183,10 +183,10 @@ public: bool imag_part; private: - void BuildFieldLinesFromFile(Array & startpoints); - void BuildFieldLinesFromFace(Array & startpoints); - void BuildFieldLinesFromBox(Array & startpoints); - void BuildFieldLinesFromLine(Array & startpoints); + void BuildFieldLinesFromFile(NgArray & startpoints); + void BuildFieldLinesFromFace(NgArray & startpoints); + void BuildFieldLinesFromBox(NgArray & startpoints); + void BuildFieldLinesFromLine(NgArray & startpoints); // weak_ptr wp_mesh; public: VisualSceneSolution (); @@ -236,8 +236,8 @@ public: private: - void GetClippingPlaneTrigs (Array & trigs, Array & pts); - void GetClippingPlaneGrid (Array & pts); + void GetClippingPlaneTrigs (NgArray & trigs, NgArray & pts); + void GetClippingPlaneGrid (NgArray & pts); void DrawCone (const Point<3> & p1, const Point<3> & p2, double r); void DrawCylinder (const Point<3> & p1, const Point<3> & p2, double r); @@ -314,7 +314,7 @@ public: void Draw1DElements(); void DrawSurfaceVectors (); - void DrawTrigSurfaceVectors(const Array< Point<3> > & lp, const Point<3> & pmin, const Point<3> & pmax, + void DrawTrigSurfaceVectors(const NgArray< Point<3> > & lp, const Point<3> & pmin, const Point<3> & pmax, const int sei, const SolData * vsol); void DrawIsoSurface(const SolData * sol, const SolData * grad, int comp); @@ -357,14 +357,14 @@ public: class RKStepper { private: - Array c,b; + NgArray c,b; TABLE *a; int steps; int order; double tolerance; - Array K; + NgArray K; int stepcount; @@ -438,9 +438,9 @@ public: void Randomized(void) { randomized = true; } void NotRandomized(void) { randomized = false; } - void Calc(const Point3d & startpoint, Array & points, Array & vals, Array & drawelems, Array & dirstart); + void Calc(const Point3d & startpoint, NgArray & points, NgArray & vals, NgArray & drawelems, NgArray & dirstart); - void GenerateFieldLines(Array & potential_startpoints, const int numlines, const int gllist, + void GenerateFieldLines(NgArray & potential_startpoints, const int numlines, const int gllist, const double minval, const double maxval, const int logscale, double phaser, double phasei); }; diff --git a/ng/demoview.hpp b/ng/demoview.hpp index 91ae8fe3..907d3f2a 100644 --- a/ng/demoview.hpp +++ b/ng/demoview.hpp @@ -98,7 +98,7 @@ template class InterpolationSpline { protected: - // Array < InterpolationPoint[3] > ip; + // NgArray < InterpolationPoint[3] > ip; class intpts { @@ -106,7 +106,7 @@ protected: InterpolationPoint pts[3]; InterpolationPoint & operator[](int i) { return pts[i]; } }; - Array < intpts > ip; + NgArray < intpts > ip; int finished; diff --git a/ng/ngappinit.cpp b/ng/ngappinit.cpp index 04faa4b7..17aca99f 100644 --- a/ng/ngappinit.cpp +++ b/ng/ngappinit.cpp @@ -32,7 +32,7 @@ DLL_HEADER extern bool nodisplay; using netgen::parameters; using netgen::ngdir; using netgen::verbose; -using netgen::Array; +using netgen::NgArray; using netgen::RegisterUserFormats; @@ -252,8 +252,8 @@ int main(int argc, char ** argv) // lookup user file formats and insert into format list: - Array userformats; - Array extensions; + NgArray userformats; + NgArray extensions; RegisterUserFormats (userformats, extensions); ostringstream fstr; diff --git a/ng/ngpkg.cpp b/ng/ngpkg.cpp index d84f0068..cc48d234 100644 --- a/ng/ngpkg.cpp +++ b/ng/ngpkg.cpp @@ -94,8 +94,8 @@ namespace netgen #ifdef SOCKETS AutoPtr clientsocket; ServerSocketManager serversocketmanager; - //Array< AutoPtr < ServerInfo > > servers; - Array< ServerInfo* > servers; + //NgArray< AutoPtr < ServerInfo > > servers; + NgArray< ServerInfo* > servers; AutoPtr serversocketusernetgen; #endif @@ -1083,7 +1083,7 @@ namespace netgen // Use an array to support creation of boundary // layers for multiple surfaces in the future... - Array surfid; + NgArray surfid; int surfinp = 0; int prismlayers = 1; double hfirst = 0.01; @@ -2007,7 +2007,7 @@ namespace netgen int w = Togl_PixelScale(togl)*Togl_Width (togl); int h = Togl_PixelScale(togl)*Togl_Height (togl); - Array buffer(w*h*3); + NgArray buffer(w*h*3); glPixelStorei(GL_UNPACK_ALIGNMENT,1); glPixelStorei(GL_PACK_ALIGNMENT,1); glReadPixels (0, 0, w, h, GL_RGB, GL_UNSIGNED_BYTE, &buffer[0]); @@ -2231,8 +2231,8 @@ namespace netgen int argc, tcl_const char *argv[]) { SetVisualScene(interp); - Array alpha; - Array vec; + NgArray alpha; + NgArray vec; for(int i=1; i conf_ids(nconfs); + NgArray conf_ids(nconfs); for(int k=0;k readtrias; //only before initstlgeometry - Array > readedges; //only before init stlgeometry + NgArray readtrias; //only before initstlgeometry + NgArray > readedges; //only before init stlgeometry // loads geometry from STL file DLL_HEADER Ng_STL_Geometry * Ng_STL_LoadGeometry (const char * filename, int binary) From 2d46d21a529d8fb5ea0bf43bef3490018205cf24 Mon Sep 17 00:00:00 2001 From: Matthias Hochsteger Date: Tue, 9 Jul 2019 10:40:35 +0200 Subject: [PATCH 02/11] Rename FlatArray to NgFlatArray --- libsrc/general/array.hpp | 66 +++++++++++++------------- libsrc/general/hashtabl.hpp | 2 +- libsrc/general/mpi_interface.hpp | 22 ++++----- libsrc/general/netgenout.hpp | 6 +-- libsrc/general/table.cpp | 2 +- libsrc/general/table.hpp | 12 ++--- libsrc/include/nginterface_v2_impl.hpp | 12 ++--- libsrc/interface/nginterface.cpp | 6 +-- libsrc/interface/nginterface_v2.cpp | 6 +-- libsrc/interface/writediffpack.cpp | 2 +- libsrc/meshing/adfront3.hpp | 2 +- libsrc/meshing/improve2gen.cpp | 2 +- libsrc/meshing/improve3.cpp | 8 ++-- libsrc/meshing/meshclass.cpp | 4 +- libsrc/meshing/meshtype.hpp | 16 +++---- libsrc/meshing/parallelmesh.cpp | 32 ++++++------- libsrc/meshing/paralleltop.cpp | 12 ++--- libsrc/meshing/paralleltop.hpp | 6 +-- libsrc/meshing/topology.cpp | 20 ++++---- libsrc/meshing/topology.hpp | 8 ++-- libsrc/stlgeom/meshstlsurface.cpp | 4 +- libsrc/visualization/vssolution.cpp | 2 +- 22 files changed, 126 insertions(+), 126 deletions(-) diff --git a/libsrc/general/array.hpp b/libsrc/general/array.hpp index e005e493..345f5c44 100644 --- a/libsrc/general/array.hpp +++ b/libsrc/general/array.hpp @@ -46,15 +46,15 @@ namespace netgen template - class FlatArray; + class NgFlatArray; template class ArrayIterator { - FlatArray ar; + NgFlatArray ar; TIND ind; public: - ArrayIterator (FlatArray aar, TIND ai) : ar(aar), ind(ai) { ; } + ArrayIterator (NgFlatArray aar, TIND ai) : ar(aar), ind(ai) { ; } ArrayIterator operator++ (int) { return ArrayIterator(ar, ind++); } ArrayIterator operator++ () { return ArrayIterator(ar, ++ind); } T operator*() const { return ar[ind]; } @@ -74,7 +74,7 @@ namespace netgen */ template - class FlatArray + class NgFlatArray { protected: /// the size @@ -85,7 +85,7 @@ namespace netgen typedef T TELEM; /// provide size and memory - FlatArray (size_t asize, T * adata) + NgFlatArray (size_t asize, T * adata) : size(asize), data(adata) { ; } /// the size @@ -112,9 +112,9 @@ namespace netgen } template - IndirectArray > operator[] (const FlatArray & ia) const + IndirectArray > operator[] (const NgFlatArray & ia) const { - return IndirectArray > (*this, ia); + return IndirectArray > (*this, ia); } @@ -170,7 +170,7 @@ namespace netgen } /// Fill array with value val - FlatArray & operator= (const T & val) + NgFlatArray & operator= (const T & val) { for (int i = 0; i < size; i++) data[i] = val; @@ -178,9 +178,9 @@ namespace netgen } /// takes range starting from position start of end-start elements - const FlatArray Range (TIND start, TIND end) + const NgFlatArray Range (TIND start, TIND end) { - return FlatArray (end-start, data+start); + return NgFlatArray (end-start, data+start); } /// first position of element elem, returns -1 if element not contained in array @@ -203,7 +203,7 @@ namespace netgen // print array template - inline ostream & operator<< (ostream & s, const FlatArray & a) + inline ostream & operator<< (ostream & s, const NgFlatArray & a) { for (TIND i = a.Begin(); i < a.End(); i++) s << i << ": " << a[i] << endl; @@ -221,11 +221,11 @@ namespace netgen or the user provides one block of data. */ template - class NgArray : public FlatArray + class NgArray : public NgFlatArray { protected: - using FlatArray::size; - using FlatArray::data; + using NgFlatArray::size; + using NgFlatArray::data; /// physical size of array size_t allocsize; @@ -236,14 +236,14 @@ namespace netgen /// Generate array of logical and physical size asize explicit NgArray() - : FlatArray (0, NULL) + : NgFlatArray (0, NULL) { allocsize = 0; ownmem = 1; } explicit NgArray(size_t asize) - : FlatArray (asize, asize ? new T[asize] : nullptr) + : NgFlatArray (asize, asize ? new T[asize] : nullptr) { allocsize = asize; ownmem = (asize == 0) ? 0 : 1; @@ -251,7 +251,7 @@ namespace netgen /// Generate array in user data NgArray(TIND asize, T* adata) - : FlatArray (asize, adata) + : NgFlatArray (asize, adata) { allocsize = asize; ownmem = 0; @@ -259,7 +259,7 @@ namespace netgen /// array copy explicit NgArray (const NgArray & a2) - : FlatArray (a2.Size(), a2.Size() ? new T[a2.Size()] : 0) + : NgFlatArray (a2.Size(), a2.Size() ? new T[a2.Size()] : 0) { allocsize = size; ownmem = 1; @@ -269,7 +269,7 @@ namespace netgen /// array move NgArray (NgArray && a2) - : FlatArray (a2.size, a2.data), allocsize(a2.allocsize), ownmem(a2.ownmem) + : NgFlatArray (a2.size, a2.data), allocsize(a2.allocsize), ownmem(a2.ownmem) { a2.size = 0; a2.data = nullptr; @@ -312,7 +312,7 @@ namespace netgen } template - void Append (FlatArray a2) + void Append (NgFlatArray a2) { if (size+a2.Size() > allocsize) ReSize (size+a2.Size()); @@ -364,7 +364,7 @@ namespace netgen /// Fill array with val NgArray & operator= (const T & val) { - FlatArray::operator= (val); + NgFlatArray::operator= (val); return *this; } @@ -378,7 +378,7 @@ namespace netgen } /// array copy - NgArray & operator= (const FlatArray & a2) + NgArray & operator= (const NgFlatArray & a2) { SetSize (a2.Size()); for (TIND i = BASE; i < size+BASE; i++) @@ -488,7 +488,7 @@ namespace netgen } /// array copy - ArrayMem & operator= (const FlatArray & a2) + ArrayMem & operator= (const NgFlatArray & a2) { this->SetSize (a2.Size()); for (size_t i = 0; i < size; i++) @@ -505,11 +505,11 @@ namespace netgen template class IndirectArray { - const FlatArray & array; - const FlatArray & ia; + const NgFlatArray & array; + const NgFlatArray & ia; public: - IndirectArray (const FlatArray & aa, const FlatArray & aia) + IndirectArray (const NgFlatArray & aa, const NgFlatArray & aia) : array(aa), ia(aia) { ; } int Size() const { return ia.Size(); } const T & operator[] (int i) const { return array[ia[i]]; } @@ -703,7 +703,7 @@ namespace netgen /// bubble sort array template - inline void BubbleSort (const FlatArray & data) + inline void BubbleSort (const NgFlatArray & data) { for (int i = 0; i < data.Size(); i++) for (int j = i+1; j < data.Size(); j++) @@ -717,7 +717,7 @@ namespace netgen /// bubble sort array template - inline void BubbleSort (FlatArray & data, FlatArray & slave) + inline void BubbleSort (NgFlatArray & data, NgFlatArray & slave) { for (int i = 0; i < data.Size(); i++) for (int j = i+1; j < data.Size(); j++) @@ -735,8 +735,8 @@ namespace netgen template - void QuickSortRec (FlatArray & data, - FlatArray & slave, + void QuickSortRec (NgFlatArray & data, + NgFlatArray & slave, int left, int right) { int i = left; @@ -761,7 +761,7 @@ namespace netgen } template - void QuickSort (FlatArray & data, FlatArray & slave) + void QuickSort (NgFlatArray & data, NgFlatArray & slave) { if (data.Size() > 1) QuickSortRec (data, slave, 0, data.Size()-1); @@ -776,7 +776,7 @@ namespace netgen template - void Intersection (const FlatArray & in1, const FlatArray & in2, + void Intersection (const NgFlatArray & in1, const NgFlatArray & in2, NgArray & out) { out.SetSize(0); @@ -785,7 +785,7 @@ namespace netgen out.Append(in1[i]); } template - void Intersection (const FlatArray & in1, const FlatArray & in2, const FlatArray & in3, + void Intersection (const NgFlatArray & in1, const NgFlatArray & in2, const NgFlatArray & in3, NgArray & out) { out.SetSize(0); diff --git a/libsrc/general/hashtabl.hpp b/libsrc/general/hashtabl.hpp index 2096747a..a08466db 100644 --- a/libsrc/general/hashtabl.hpp +++ b/libsrc/general/hashtabl.hpp @@ -1391,7 +1391,7 @@ inline size_t HashValue (INDEX_2 i2, size_t size) { return (113*size_t(i2[0])+si ClosedHashTable (ClosedHashTable && ht2) = default; // who needs that ? - ClosedHashTable (FlatArray _hash, FlatArray _cont) + ClosedHashTable (NgFlatArray _hash, NgFlatArray _cont) : size(_hash.Size()), used(0), hash(_hash.Size(), _hash.Addr(0)), cont(_cont.Size(), _cont.Addr(0)) { for (auto & v : hash) diff --git a/libsrc/general/mpi_interface.hpp b/libsrc/general/mpi_interface.hpp index 66109bb4..08a15662 100644 --- a/libsrc/general/mpi_interface.hpp +++ b/libsrc/general/mpi_interface.hpp @@ -147,13 +147,13 @@ namespace netgen template - inline void MyMPI_Send (FlatArray s, int dest, int tag, MPI_Comm comm /* = ng_comm */) + inline void MyMPI_Send (NgFlatArray s, int dest, int tag, MPI_Comm comm /* = ng_comm */) { MPI_Send( &s.First(), s.Size(), MyGetMPIType(), dest, tag, comm); } template - inline void MyMPI_Recv ( FlatArray s, int src, int tag, MPI_Comm comm /* = ng_comm */) + inline void MyMPI_Recv ( NgFlatArray s, int src, int tag, MPI_Comm comm /* = ng_comm */) { MPI_Status status; MPI_Recv( &s.First(), s.Size(), MyGetMPIType(), src, tag, comm, &status); @@ -191,21 +191,21 @@ namespace netgen /* template - inline void MyMPI_ISend (FlatArray s, int dest, int tag, MPI_Request & request) + inline void MyMPI_ISend (NgFlatArray s, int dest, int tag, MPI_Request & request) { MPI_Isend( &s.First(), s.Size(), MyGetMPIType(), dest, tag, MPI_COMM_WORLD, & request); } template - inline void MyMPI_IRecv (FlatArray s, int dest, int tag, MPI_Request & request) + inline void MyMPI_IRecv (NgFlatArray s, int dest, int tag, MPI_Request & request) { MPI_Irecv( &s.First(), s.Size(), MyGetMPIType(), dest, tag, MPI_COMM_WORLD, & request); } */ template - inline MPI_Request MyMPI_ISend (FlatArray s, int dest, int tag, MPI_Comm comm /* = ng_comm */) + inline MPI_Request MyMPI_ISend (NgFlatArray s, int dest, int tag, MPI_Comm comm /* = ng_comm */) { MPI_Request request; MPI_Isend( &s.First(), s.Size(), MyGetMPIType(), dest, tag, comm, &request); @@ -214,7 +214,7 @@ namespace netgen template - inline MPI_Request MyMPI_IRecv (FlatArray s, int dest, int tag, MPI_Comm comm /* = ng_comm */) + inline MPI_Request MyMPI_IRecv (NgFlatArray s, int dest, int tag, MPI_Comm comm /* = ng_comm */) { MPI_Request request; MPI_Irecv( &s.First(), s.Size(), MyGetMPIType(), dest, tag, comm, &request); @@ -223,7 +223,7 @@ namespace netgen /* template - inline void MyMPI_ISend (FlatArray s, int dest, int tag) + inline void MyMPI_ISend (NgFlatArray s, int dest, int tag) { MPI_Request request; MPI_Isend( &s.First(), s.Size(), MyGetMPIType(), dest, tag, MPI_COMM_WORLD, &request); @@ -232,7 +232,7 @@ namespace netgen template - inline void MyMPI_IRecv (FlatArray s, int dest, int tag) + inline void MyMPI_IRecv (NgFlatArray s, int dest, int tag) { MPI_Request request; MPI_Irecv( &s.First(), s.Size(), MyGetMPIType(), dest, tag, MPI_COMM_WORLD, &request); @@ -359,19 +359,19 @@ namespace netgen } template - inline void MyMPI_Allgather (const T & send, FlatArray recv, MPI_Comm comm /* = ng_comm */) + inline void MyMPI_Allgather (const T & send, NgFlatArray recv, MPI_Comm comm /* = ng_comm */) { MPI_Allgather( const_cast (&send), 1, MyGetMPIType(), &recv[0], 1, MyGetMPIType(), comm); } template - inline void MyMPI_Alltoall (FlatArray send, FlatArray recv, MPI_Comm comm /* = ng_comm */) + inline void MyMPI_Alltoall (NgFlatArray send, NgFlatArray recv, MPI_Comm comm /* = ng_comm */) { MPI_Alltoall( &send[0], 1, MyGetMPIType(), &recv[0], 1, MyGetMPIType(), comm); } // template -// inline void MyMPI_Alltoall_Block (FlatArray send, FlatArray recv, int blocklen, MPI_Comm comm = ng_comm) +// inline void MyMPI_Alltoall_Block (NgFlatArray send, NgFlatArray recv, int blocklen, MPI_Comm comm = ng_comm) // { // MPI_Alltoall( &send[0], blocklen, MyGetMPIType(), &recv[0], blocklen, MyGetMPIType(), comm); // } diff --git a/libsrc/general/netgenout.hpp b/libsrc/general/netgenout.hpp index 076a6df1..7364f363 100644 --- a/libsrc/general/netgenout.hpp +++ b/libsrc/general/netgenout.hpp @@ -39,13 +39,13 @@ public: class Procs { - const netgen::FlatArray procs; + const netgen::NgFlatArray procs; public: - Procs ( const netgen::FlatArray & aprocs ) : procs (aprocs) { ; } + Procs ( const netgen::NgFlatArray & aprocs ) : procs (aprocs) { ; } - const netgen::FlatArray & GetProcs () const { return procs; } + const netgen::NgFlatArray & GetProcs () const { return procs; } }; diff --git a/libsrc/general/table.cpp b/libsrc/general/table.cpp index c964c470..732d63c3 100644 --- a/libsrc/general/table.cpp +++ b/libsrc/general/table.cpp @@ -27,7 +27,7 @@ namespace netgen oneblock = NULL; } - BASE_TABLE :: BASE_TABLE (const FlatArray & entrysizes, int elemsize) + BASE_TABLE :: BASE_TABLE (const NgFlatArray & entrysizes, int elemsize) : data(entrysizes.Size()) { size_t cnt = 0; diff --git a/libsrc/general/table.hpp b/libsrc/general/table.hpp index 3847395f..7d2f6999 100644 --- a/libsrc/general/table.hpp +++ b/libsrc/general/table.hpp @@ -42,7 +42,7 @@ public: BASE_TABLE (int size); /// - BASE_TABLE (const FlatArray & entrysizes, int elemsize); + BASE_TABLE (const NgFlatArray & entrysizes, int elemsize); /// ~BASE_TABLE (); @@ -115,8 +115,8 @@ public: inline TABLE (int size) : BASE_TABLE (size) { ; } /// Creates fixed maximal element size table - inline TABLE (const FlatArray & entrysizes) - : BASE_TABLE (FlatArray (entrysizes.Size(), const_cast(&entrysizes[BASE])), + inline TABLE (const NgFlatArray & entrysizes) + : BASE_TABLE (NgFlatArray (entrysizes.Size(), const_cast(&entrysizes[BASE])), sizeof(T)) { ; } @@ -228,14 +228,14 @@ public: } /// Access entry. - FlatArray operator[] (int i) const + NgFlatArray operator[] (int i) const { #ifdef DEBUG if (i-BASE < 0 || i-BASE >= data.Size()) cout << "table out of range, i = " << i << ", s = " << data.Size() << endl; #endif - return FlatArray (data[i-BASE].size, (T*)data[i-BASE].col); + return NgFlatArray (data[i-BASE].size, (T*)data[i-BASE].col); } void DoArchive (Archive & ar) @@ -251,7 +251,7 @@ inline ostream & operator<< (ostream & ost, const TABLE & table) for (int i = BASE; i < table.Size()+BASE; i++) { ost << i << ": "; - FlatArray row = table[i]; + NgFlatArray row = table[i]; ost << "(" << row.Size() << ") "; for (int j = 0; j < row.Size(); j++) ost << row[j] << " "; diff --git a/libsrc/include/nginterface_v2_impl.hpp b/libsrc/include/nginterface_v2_impl.hpp index 382c4408..6d6d1b85 100644 --- a/libsrc/include/nginterface_v2_impl.hpp +++ b/libsrc/include/nginterface_v2_impl.hpp @@ -250,33 +250,33 @@ template <> NGX_INLINE DLL_HEADER const Ng_Node<0> Ngx_Mesh :: GetNode<0> (int v { case 3: { - FlatArray ia = mesh->GetTopology().GetVertexElements(vnr); + NgFlatArray ia = mesh->GetTopology().GetVertexElements(vnr); node.elements.ne = ia.Size(); node.elements.ptr = (int*)&ia[0]; - FlatArray bia = mesh->GetTopology().GetVertexSurfaceElements(vnr); + NgFlatArray bia = mesh->GetTopology().GetVertexSurfaceElements(vnr); node.bnd_elements.ne = bia.Size(); node.bnd_elements.ptr = (int*)&bia[0]; break; } case 2: { - FlatArray ia = mesh->GetTopology().GetVertexSurfaceElements(vnr); + NgFlatArray ia = mesh->GetTopology().GetVertexSurfaceElements(vnr); node.elements.ne = ia.Size(); node.elements.ptr = (int*)&ia[0]; - FlatArray bia = mesh->GetTopology().GetVertexSegments(vnr); + NgFlatArray bia = mesh->GetTopology().GetVertexSegments(vnr); node.bnd_elements.ne = bia.Size(); node.bnd_elements.ptr = (int*)&bia[0]; break; } case 1: { - FlatArray ia = mesh->GetTopology().GetVertexSegments(vnr); + NgFlatArray ia = mesh->GetTopology().GetVertexSegments(vnr); node.elements.ne = ia.Size(); node.elements.ptr = (int*)&ia[0]; - FlatArray bia = mesh->GetTopology().GetVertexPointElements(vnr); + NgFlatArray bia = mesh->GetTopology().GetVertexPointElements(vnr); node.bnd_elements.ne = bia.Size(); node.bnd_elements.ptr = (int*)&bia[0]; break; diff --git a/libsrc/interface/nginterface.cpp b/libsrc/interface/nginterface.cpp index 7353e8c7..a8ff165b 100644 --- a/libsrc/interface/nginterface.cpp +++ b/libsrc/interface/nginterface.cpp @@ -1638,19 +1638,19 @@ void Ng_GetVertexElements (int vnr, int * els) { case 3: { - FlatArray ia = mesh->GetTopology().GetVertexElements(vnr); + NgFlatArray ia = mesh->GetTopology().GetVertexElements(vnr); for (int i = 0; i < ia.Size(); i++) els[i] = ia[i]+1; break; } case 2: { - FlatArray ia = mesh->GetTopology().GetVertexSurfaceElements(vnr); + NgFlatArray ia = mesh->GetTopology().GetVertexSurfaceElements(vnr); for (int i = 0; i < ia.Size(); i++) els[i] = ia[i]+1; break; } case 1: { - FlatArray ia = mesh->GetTopology().GetVertexSegments(vnr); + NgFlatArray ia = mesh->GetTopology().GetVertexSegments(vnr); for (int i = 0; i < ia.Size(); i++) els[i] = ia[i]+1; break; /* diff --git a/libsrc/interface/nginterface_v2.cpp b/libsrc/interface/nginterface_v2.cpp index c9db3b10..68618f54 100644 --- a/libsrc/interface/nginterface_v2.cpp +++ b/libsrc/interface/nginterface_v2.cpp @@ -1291,17 +1291,17 @@ void Ngx_Mesh::SetSurfaceElementOrders (int enr, int ox, int oy) { case 0: { - FlatArray dn = mesh->GetParallelTopology().GetDistantPNums(locnum); + NgFlatArray dn = mesh->GetParallelTopology().GetDistantPNums(locnum); return std::tuple(dn.Size(), &dn[0]); } case 1: { - FlatArray dn = mesh->GetParallelTopology().GetDistantEdgeNums(locnum); + NgFlatArray dn = mesh->GetParallelTopology().GetDistantEdgeNums(locnum); return std::tuple(dn.Size(), &dn[0]); } case 2: { - FlatArray dn = mesh->GetParallelTopology().GetDistantFaceNums(locnum); + NgFlatArray dn = mesh->GetParallelTopology().GetDistantFaceNums(locnum); return std::tuple(dn.Size(), &dn[0]); } default: diff --git a/libsrc/interface/writediffpack.cpp b/libsrc/interface/writediffpack.cpp index b1c30fba..6e25793d 100644 --- a/libsrc/interface/writediffpack.cpp +++ b/libsrc/interface/writediffpack.cpp @@ -112,7 +112,7 @@ void WriteDiffPackFormat (const Mesh & mesh, /* for (j = 1; j <= nse; j++) */ - FlatArray sels = point2sel[i]; + NgFlatArray sels = point2sel[i]; for (int jj = 0; jj < sels.Size(); jj++) { for (k = 1; k <= mesh[sels[jj]].GetNP(); k++) diff --git a/libsrc/meshing/adfront3.hpp b/libsrc/meshing/adfront3.hpp index c7c8dfb5..9985c13c 100644 --- a/libsrc/meshing/adfront3.hpp +++ b/libsrc/meshing/adfront3.hpp @@ -89,7 +89,7 @@ public: const PointIndex PNum (int i) const { return pnum[i-1]; } PointIndex & PNum (int i) { return pnum[i-1]; } const PointIndex PNumMod (int i) const { return pnum[(i-1)%np]; } - auto PNums() const { return FlatArray (np, &pnum[0]); } + auto PNums() const { return NgFlatArray (np, &pnum[0]); } void Delete () { deleted = true; for (PointIndex & p : pnum) p.Invalidate(); } bool IsDeleted () const { return deleted; } }; diff --git a/libsrc/meshing/improve2gen.cpp b/libsrc/meshing/improve2gen.cpp index ef10e322..ab62bc79 100644 --- a/libsrc/meshing/improve2gen.cpp +++ b/libsrc/meshing/improve2gen.cpp @@ -296,7 +296,7 @@ namespace netgen if (mesh[sei].IsDeleted()) continue; elmap[0] = sei; - FlatArray neighbours = nbels[sei]; + NgFlatArray neighbours = nbels[sei]; for (elrot[0] = 0; elrot[0] < mesh[sei].GetNP(); elrot[0]++) { diff --git a/libsrc/meshing/improve3.cpp b/libsrc/meshing/improve3.cpp index f00ff82e..0c43ef9c 100644 --- a/libsrc/meshing/improve3.cpp +++ b/libsrc/meshing/improve3.cpp @@ -105,7 +105,7 @@ void MeshOptimize3d :: CombineImprove (Mesh & mesh, hasonepi.SetSize(0); hasbothpi.SetSize(0); - FlatArray row1 = elementsonnode[pi1]; + NgFlatArray row1 = elementsonnode[pi1]; for (int k = 0; k < row1.Size(); k++) { Element & elem = mesh[row1[k]]; @@ -122,7 +122,7 @@ void MeshOptimize3d :: CombineImprove (Mesh & mesh, } } - FlatArray row2 = elementsonnode[pi2]; + NgFlatArray row2 = elementsonnode[pi2]; for (int k = 0; k < row2.Size(); k++) { Element & elem = mesh[row2[k]]; @@ -209,7 +209,7 @@ void MeshOptimize3d :: CombineImprove (Mesh & mesh, mesh[pi1] = pnew; cnt++; - FlatArray row = elementsonnode[pi2]; + NgFlatArray row = elementsonnode[pi2]; for (int k = 0; k < row.Size(); k++) { Element & elem = mesh[row[k]]; @@ -2439,7 +2439,7 @@ void MeshOptimize3d :: SwapImprove2 (Mesh & mesh, OPTIMIZEGOAL goal) if (bface) continue; - FlatArray row = elementsonnode[pi1]; + NgFlatArray row = elementsonnode[pi1]; for (int k = 0; k < row.Size(); k++) { ElementIndex eli2 = row[k]; diff --git a/libsrc/meshing/meshclass.cpp b/libsrc/meshing/meshclass.cpp index a29fc662..d6d15ea5 100644 --- a/libsrc/meshing/meshclass.cpp +++ b/libsrc/meshing/meshclass.cpp @@ -2019,7 +2019,7 @@ namespace netgen { faceht.SetSize (2 * selsonpoint[pi].Size() + 4 * elsonpoint[pi].Size()); - FlatArray row = selsonpoint[pi]; + NgFlatArray row = selsonpoint[pi]; for (ii = 0; ii < row.Size(); ii++) { Element2d hel = SurfaceElement(row[ii]); @@ -2058,7 +2058,7 @@ namespace netgen } - FlatArray rowel = elsonpoint[pi]; + NgFlatArray rowel = elsonpoint[pi]; for (ii = 0; ii < rowel.Size(); ii++) { const Element & el = VolumeElement(rowel[ii]); diff --git a/libsrc/meshing/meshtype.hpp b/libsrc/meshing/meshtype.hpp index aae6c710..fcb78f0c 100644 --- a/libsrc/meshing/meshtype.hpp +++ b/libsrc/meshing/meshtype.hpp @@ -456,12 +456,12 @@ namespace netgen /// const PointIndex & operator[] (int i) const { return pnum[i]; } - FlatArray PNums () const - { return FlatArray (np, &pnum[0]); } - FlatArray PNums () - { return FlatArray (np, &pnum[0]); } + NgFlatArray PNums () const + { return NgFlatArray (np, &pnum[0]); } + NgFlatArray PNums () + { return NgFlatArray (np, &pnum[0]); } auto Vertices() const - { return FlatArray (GetNV(), &pnum[0]); } + { return NgFlatArray (GetNV(), &pnum[0]); } /// PointIndex & PNum (int i) { return pnum[i-1]; } @@ -748,10 +748,10 @@ namespace netgen /// const PointIndex & operator[] (int i) const { return pnum[i]; } - FlatArray PNums () const - { return FlatArray (np, &pnum[0]); } + NgFlatArray PNums () const + { return NgFlatArray (np, &pnum[0]); } - FlatArray Vertices() const { return { GetNV(), &pnum[0] }; } + NgFlatArray Vertices() const { return { GetNV(), &pnum[0] }; } /// PointIndex & PNum (int i) { return pnum[i-1]; } diff --git a/libsrc/meshing/parallelmesh.cpp b/libsrc/meshing/parallelmesh.cpp index 1e576c9e..b7930162 100644 --- a/libsrc/meshing/parallelmesh.cpp +++ b/libsrc/meshing/parallelmesh.cpp @@ -223,21 +223,21 @@ namespace netgen vert_flag = -1; for (int dest = 1; dest < ntasks; dest++) { - FlatArray els = els_of_proc[dest]; + NgFlatArray els = els_of_proc[dest]; for (int hi = 0; hi < els.Size(); hi++) { const Element & el = (*this) [ els[hi] ]; for (int i = 0; i < el.GetNP(); i++) f(el[i], dest); } - FlatArray sels = sels_of_proc[dest]; + NgFlatArray sels = sels_of_proc[dest]; for (int hi = 0; hi < sels.Size(); hi++) { const Element2d & el = (*this) [ sels[hi] ]; for (int i = 0; i < el.GetNP(); i++) f(el[i], dest); } - FlatArray segs = segs_of_proc[dest]; + NgFlatArray segs = segs_of_proc[dest]; for (int hi = 0; hi < segs.Size(); hi++) { const Segment & el = (*this) [segs[hi]]; @@ -285,7 +285,7 @@ namespace netgen **/ for (int vert = 1; vert <= GetNP(); vert++ ) { - FlatArray procs = procs_of_vert[vert]; + NgFlatArray procs = procs_of_vert[vert]; for (int j = 0; j < procs.Size(); j++) { int dest = procs[j]; @@ -297,7 +297,7 @@ namespace netgen for (int dest = 1; dest < ntasks; dest++) { - FlatArray verts = verts_of_proc[dest]; + NgFlatArray verts = verts_of_proc[dest]; sendrequests.Append (MyMPI_ISend (verts, dest, MPI_TAG_MESH+1, comm)); MPI_Datatype mptype = MeshPoint::MyGetMPIType(); @@ -387,7 +387,7 @@ namespace netgen for (int vert = 1; vert <= GetNP(); vert++) { - FlatArray procs = procs_of_vert[vert]; + NgFlatArray procs = procs_of_vert[vert]; for (int j = 0; j < procs.Size(); j++) num_distpnums[procs[j]] += 3 * (procs.Size()-1); } @@ -396,7 +396,7 @@ namespace netgen for (int vert = 1; vert <= GetNP(); vert++) { - FlatArray procs = procs_of_vert[vert]; + NgFlatArray procs = procs_of_vert[vert]; for (int j = 0; j < procs.Size(); j++) for (int k = 0; k < procs.Size(); k++) if (j != k) @@ -474,7 +474,7 @@ namespace netgen { if(ided_sel[sei]!=-1) continue; const Element2d & sel = (*this)[sei]; - FlatArray points = sel.PNums(); + NgFlatArray points = sel.PNums(); auto ided1 = per_verts[points[0]]; os1.SetSize(0); for (int j = 0; j < ided1.Size(); j++) @@ -498,7 +498,7 @@ namespace netgen throw NgException("SurfaceElement identified with more than one other??"); } const Element2d & sel2 = (*this)[sei]; - FlatArray points2 = sel2.PNums(); + NgFlatArray points2 = sel2.PNums(); has_ided_sels = true; ided_sel[sei] = os1[0]; ided_sel[os1[0]] = sei; @@ -854,7 +854,7 @@ namespace netgen for(int idnr = 1; idnr < maxidentnr+1; idnr++) { int npairs = pp_data[maxidentnr+idnr]; - FlatArray pairdata(2*npairs, &pp_data[offset]); + NgFlatArray pairdata(2*npairs, &pp_data[offset]); offset += 2*npairs; for (int k = 0; k els = pnt2el[pi1]; - FlatArray els = pnt2el[pi1]; + // NgFlatArray els = pnt2el[pi1]; + NgFlatArray els = pnt2el[pi1]; // sel.SetPartition (-1); surf_partition[sei] = -1; @@ -1270,7 +1270,7 @@ namespace netgen { Segment & sel = (*this)[si]; PointIndex pi1 = sel[0]; - FlatArray els = pnt2el[pi1]; + NgFlatArray els = pnt2el[pi1]; // sel.SetPartition (-1); seg_partition[si] = -1; @@ -1311,7 +1311,7 @@ namespace netgen seg_partition[segi] = -1; PointIndex pi1 = seg[0]; - FlatArray sels = pnt2el[pi1]; + NgFlatArray sels = pnt2el[pi1]; for (int j = 0; j < sels.Size(); j++) { SurfaceElementIndex sei = sels[j]; @@ -1703,7 +1703,7 @@ namespace netgen for ( int vert = 0; vert < nn; vert++ ) { - FlatArray array ( cnt[vert], &adjacency[ xadj[vert] ] ); + NgFlatArray array ( cnt[vert], &adjacency[ xadj[vert] ] ); BubbleSort(array); } @@ -1815,7 +1815,7 @@ namespace netgen for ( int el = 0; el < ne; el++ ) { - FlatArray array ( cnt[el], &adjacency[ xadj[el] ] ); + NgFlatArray array ( cnt[el], &adjacency[ xadj[el] ] ); BubbleSort(array); } diff --git a/libsrc/meshing/paralleltop.cpp b/libsrc/meshing/paralleltop.cpp index fb4b9794..6a5d562c 100644 --- a/libsrc/meshing/paralleltop.cpp +++ b/libsrc/meshing/paralleltop.cpp @@ -366,7 +366,7 @@ namespace netgen for (PointIndex pi : dest2vert[dest-1]) loc2exchange[pi] = cnt++; - FlatArray recvarray = recv_verts[dest-1]; + NgFlatArray recvarray = recv_verts[dest-1]; for (int ii = 0; ii < recvarray.Size(); ii+=2) for (PointIndex pi : dest2pair[dest-1]) // for (PointIndex pi = PointIndex::BASE; pi < newnv+PointIndex::BASE; pi++) @@ -464,7 +464,7 @@ namespace netgen for (int dest = 1; dest < ntasks; dest++) { auto ex2loc = dest2vert[dest-1]; - FlatArray recvarray = recv_edges[dest-1]; + NgFlatArray recvarray = recv_edges[dest-1]; for (int ii = 0; ii < recvarray.Size(); ii+=2) for (int edge : dest2edge[dest-1]) { @@ -490,7 +490,7 @@ namespace netgen vert2edge.Set(INDEX_2(v1,v2), edge); } - FlatArray recvarray = recv_edges[dest-1]; + NgFlatArray recvarray = recv_edges[dest-1]; for (int ii = 0; ii < recvarray.Size(); ii+=2) { INDEX_2 re(ex2loc[recvarray[ii]], @@ -585,7 +585,7 @@ namespace netgen for (PointIndex pi : dest2vert[dest-1]) loc2exchange[pi] = cnt++; - FlatArray recvarray = recv_faces[dest-1]; + NgFlatArray recvarray = recv_faces[dest-1]; for (int ii = 0; ii < recvarray.Size(); ii+=3) for (int face : dest2face[dest-1]) { @@ -611,7 +611,7 @@ namespace netgen vert2face.Set(INDEX_3(verts[0], verts[1], verts[2]), face); } - FlatArray recvarray = recv_faces[dest-1]; + NgFlatArray recvarray = recv_faces[dest-1]; for (int ii = 0; ii < recvarray.Size(); ii+=3) { INDEX_3 re(ex2loc[recvarray[ii]], @@ -676,7 +676,7 @@ namespace netgen for (int sender = 1; sender < ntasks; sender ++) if (id != sender) { - FlatArray recvarray = recv_faces[sender-1]; + NgFlatArray recvarray = recv_faces[sender-1]; for (int ii = 0; ii < recvarray.Size(); ) { diff --git a/libsrc/meshing/paralleltop.hpp b/libsrc/meshing/paralleltop.hpp index dc125cd6..197ba62e 100644 --- a/libsrc/meshing/paralleltop.hpp +++ b/libsrc/meshing/paralleltop.hpp @@ -93,9 +93,9 @@ namespace netgen distedgenums = loc2distedge[locedgenum-1]; } - FlatArray GetDistantPNums (int locnum) const { return loc2distvert[locnum]; } - FlatArray GetDistantFaceNums (int locnum) const { return loc2distface[locnum]; } - FlatArray GetDistantEdgeNums (int locnum) const { return loc2distedge[locnum]; } + NgFlatArray GetDistantPNums (int locnum) const { return loc2distvert[locnum]; } + NgFlatArray GetDistantFaceNums (int locnum) const { return loc2distface[locnum]; } + NgFlatArray GetDistantEdgeNums (int locnum) const { return loc2distedge[locnum]; } bool IsExchangeVert (int dest, int vnum) const { diff --git a/libsrc/meshing/topology.cpp b/libsrc/meshing/topology.cpp index 9e663bc7..a2075176 100644 --- a/libsrc/meshing/topology.cpp +++ b/libsrc/meshing/topology.cpp @@ -6,7 +6,7 @@ namespace netgen template - void QuickSortRec (FlatArray data, + void QuickSortRec (NgFlatArray data, int left, int right) { int i = left; @@ -30,7 +30,7 @@ namespace netgen } template - void QuickSort (FlatArray data) + void QuickSort (NgFlatArray data) { if (data.Size() > 1) QuickSortRec (data, 0, data.Size()-1); @@ -1205,7 +1205,7 @@ namespace netgen (*testout) << (*mesh)[(PointIndex)face2vert[i].I(j+1)] << " "; (*testout) << endl; - FlatArray vertels = GetVertexElements (face2vert[i].I(1)); + NgFlatArray vertels = GetVertexElements (face2vert[i].I(1)); for (int k = 0; k < vertels.Size(); k++) { int elfaces[10], orient[10]; @@ -1821,7 +1821,7 @@ namespace netgen // GetVertexElements (pi[0], els); - FlatArray els = GetVertexElements (pi[0]); + NgFlatArray els = GetVertexElements (pi[0]); // find one element having all vertices of the face for (int i = 0; i < els.Size(); i++) @@ -1925,25 +1925,25 @@ namespace netgen } /* - FlatArray MeshTopology :: GetVertexElements (int vnr) const + NgFlatArray MeshTopology :: GetVertexElements (int vnr) const { if (vert2element) return (*vert2element)[vnr]; - return FlatArray (0,0); + return NgFlatArray (0,0); } - FlatArray MeshTopology :: GetVertexSurfaceElements (int vnr) const + NgFlatArray MeshTopology :: GetVertexSurfaceElements (int vnr) const { if (vert2surfelement) return (*vert2surfelement)[vnr]; - return FlatArray (0,0); + return NgFlatArray (0,0); } - FlatArray MeshTopology :: GetVertexSegments (int vnr) const + NgFlatArray MeshTopology :: GetVertexSegments (int vnr) const { if (vert2segment) return (*vert2segment)[vnr]; - return FlatArray (0,0); + return NgFlatArray (0,0); } */ diff --git a/libsrc/meshing/topology.hpp b/libsrc/meshing/topology.hpp index e20aa121..558646a2 100644 --- a/libsrc/meshing/topology.hpp +++ b/libsrc/meshing/topology.hpp @@ -162,17 +162,17 @@ public: int GetFace2SurfaceElement (int fnr) const { return face2surfel[fnr-1]; } void GetVertexElements (int vnr, NgArray & elements) const; - FlatArray GetVertexElements (int vnr) const + NgFlatArray GetVertexElements (int vnr) const { return vert2element[vnr]; } void GetVertexSurfaceElements( int vnr, NgArray& elements ) const; - FlatArray GetVertexSurfaceElements (int vnr) const + NgFlatArray GetVertexSurfaceElements (int vnr) const { return vert2surfelement[vnr]; } - FlatArray GetVertexSegments (int vnr) const + NgFlatArray GetVertexSegments (int vnr) const { return vert2segment[vnr]; } - FlatArray GetVertexPointElements (int vnr) const + NgFlatArray GetVertexPointElements (int vnr) const { return vert2pointelement[vnr]; } int GetVerticesEdge ( int v1, int v2) const; diff --git a/libsrc/stlgeom/meshstlsurface.cpp b/libsrc/stlgeom/meshstlsurface.cpp index 6aef6e27..4c1d940d 100644 --- a/libsrc/stlgeom/meshstlsurface.cpp +++ b/libsrc/stlgeom/meshstlsurface.cpp @@ -637,7 +637,7 @@ void STLSurfaceMeshing1 (STLGeometry & geom, } } */ - FlatArray segs = opensegments[fnr]; + NgFlatArray segs = opensegments[fnr]; for (int hi = 0; hi < segs.Size(); hi++) { int i = segs[hi]; @@ -706,7 +706,7 @@ void STLSurfaceMeshing1 (STLGeometry & geom, */ - // FlatArray segs = opensegments[fnr]; + // NgFlatArray segs = opensegments[fnr]; for (int hi = 0; hi < segs.Size(); hi++) { int i = segs[hi]; diff --git a/libsrc/visualization/vssolution.cpp b/libsrc/visualization/vssolution.cpp index 1b66a7b3..5faf42e6 100644 --- a/libsrc/visualization/vssolution.cpp +++ b/libsrc/visualization/vssolution.cpp @@ -340,7 +340,7 @@ namespace netgen { double values[3], sumvalues[3] = { 0, 0, 0 }; - FlatArray els = mesh->GetTopology().GetVertexElements(pi); + NgFlatArray els = mesh->GetTopology().GetVertexElements(pi); for (int j = 0; j < els.Size(); j++) { From 7f7b38638872fd6692e6f57b8c4bc770aae402b0 Mon Sep 17 00:00:00 2001 From: Matthias Hochsteger Date: Tue, 9 Jul 2019 10:41:40 +0200 Subject: [PATCH 03/11] Move array.hpp to ngarray.hpp --- libsrc/general/CMakeLists.txt | 4 ++-- libsrc/general/myadt.hpp | 2 +- libsrc/general/{array.cpp => ngarray.cpp} | 6 +++--- libsrc/general/{array.hpp => ngarray.hpp} | 8 ++++---- 4 files changed, 10 insertions(+), 10 deletions(-) rename libsrc/general/{array.cpp => ngarray.cpp} (94%) rename libsrc/general/{array.hpp => ngarray.hpp} (99%) diff --git a/libsrc/general/CMakeLists.txt b/libsrc/general/CMakeLists.txt index 3f6c2aad..a9620cbc 100644 --- a/libsrc/general/CMakeLists.txt +++ b/libsrc/general/CMakeLists.txt @@ -2,14 +2,14 @@ add_definitions(-DNGINTERFACE_EXPORTS) add_library(gen INTERFACE) set(sdir ${CMAKE_CURRENT_SOURCE_DIR}) target_sources(gen INTERFACE - ${sdir}/array.cpp ${sdir}/bitarray.cpp ${sdir}/dynamicmem.cpp ${sdir}/flags.cpp + ${sdir}/ngarray.cpp ${sdir}/bitarray.cpp ${sdir}/dynamicmem.cpp ${sdir}/flags.cpp ${sdir}/hashtabl.cpp ${sdir}/mystring.cpp ${sdir}/optmem.cpp ${sdir}/parthreads.cpp ${sdir}/seti.cpp ${sdir}/sort.cpp ${sdir}/spbita2d.cpp ${sdir}/table.cpp ${sdir}/mpi_interface.cpp ${sdir}/gzstream.cpp ) install(FILES - array.hpp autodiff.hpp autoptr.hpp bitarray.hpp + ngarray.hpp autodiff.hpp autoptr.hpp bitarray.hpp dynamicmem.hpp flags.hpp hashtabl.hpp mpi_interface.hpp myadt.hpp ngsimd.hpp mystring.hpp netgenout.hpp ngpython.hpp optmem.hpp parthreads.hpp seti.hpp sort.hpp diff --git a/libsrc/general/myadt.hpp b/libsrc/general/myadt.hpp index 4284a42f..aac10338 100644 --- a/libsrc/general/myadt.hpp +++ b/libsrc/general/myadt.hpp @@ -28,7 +28,7 @@ namespace netgen #include "dynamicmem.hpp" #include "template.hpp" -#include "array.hpp" +#include "ngarray.hpp" #include "table.hpp" #include "hashtabl.hpp" diff --git a/libsrc/general/array.cpp b/libsrc/general/ngarray.cpp similarity index 94% rename from libsrc/general/array.cpp rename to libsrc/general/ngarray.cpp index 3b822d1a..5078900e 100644 --- a/libsrc/general/array.cpp +++ b/libsrc/general/ngarray.cpp @@ -1,5 +1,5 @@ -#ifndef FILE_NGSTD_ArrayCPP -#define FILE_NGSTD_ArrayCPP +#ifndef FILE_NGSTD_NgArrayCPP +#define FILE_NGSTD_NgArrayCPP // necessary for SGI ???? /**************************************************************************/ @@ -71,5 +71,5 @@ namespace netgen } #endif } -#endif +#endif // FILE_NGSTD_NgArrayCPP diff --git a/libsrc/general/array.hpp b/libsrc/general/ngarray.hpp similarity index 99% rename from libsrc/general/array.hpp rename to libsrc/general/ngarray.hpp index 345f5c44..9637e50f 100644 --- a/libsrc/general/array.hpp +++ b/libsrc/general/ngarray.hpp @@ -1,8 +1,8 @@ -#ifndef FILE_Array -#define FILE_Array +#ifndef NGARRAY_HPP_INCLUDED +#define NGARRAY_HPP_INCLUDED /**************************************************************************/ -/* File: array.hpp */ +/* File: ngarray.hpp */ /* Author: Joachim Schoeberl */ /* Date: 01. Jun. 95 */ /**************************************************************************/ @@ -795,5 +795,5 @@ namespace netgen } } -#endif +#endif // NGARRAY_HPP_INCLUDED From e1d4cc041050895abd730fb2b088fe7d849922ef Mon Sep 17 00:00:00 2001 From: Matthias Hochsteger Date: Tue, 9 Jul 2019 12:12:41 +0200 Subject: [PATCH 04/11] Add Array, TaskManager and concurrentqueue from NGSolve MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Array and TaskManager was mainly developed by Joachim Schöberl. For complete version history, check NGSolve: https://github.com/NGSolve/ngsolve The concurrentqueue is from https://github.com/cameron314/concurrentqueue revision dea078cf5b6e742cd67a0d725e36f872feca4de4 --- libsrc/core/CMakeLists.txt | 3 +- libsrc/core/array.hpp | 1475 ++++++++++++++ libsrc/core/concurrentqueue.h | 3619 +++++++++++++++++++++++++++++++++ libsrc/core/ngcore.hpp | 4 +- libsrc/core/taskmanager.cpp | 812 ++++++++ libsrc/core/taskmanager.hpp | 1021 ++++++++++ libsrc/core/utils.hpp | 9 + 7 files changed, 6941 insertions(+), 2 deletions(-) create mode 100644 libsrc/core/array.hpp create mode 100644 libsrc/core/concurrentqueue.h create mode 100644 libsrc/core/taskmanager.cpp create mode 100644 libsrc/core/taskmanager.hpp diff --git a/libsrc/core/CMakeLists.txt b/libsrc/core/CMakeLists.txt index 8e66226e..13ebaec5 100644 --- a/libsrc/core/CMakeLists.txt +++ b/libsrc/core/CMakeLists.txt @@ -1,5 +1,5 @@ -add_library(ngcore SHARED archive.cpp logging.cpp paje_trace.cpp utils.cpp profiler.cpp) +add_library(ngcore SHARED archive.cpp logging.cpp paje_trace.cpp utils.cpp profiler.cpp taskmanager.cpp) target_compile_definitions(ngcore PRIVATE NGCORE_EXPORTS) if(NOT WIN32) @@ -34,6 +34,7 @@ endif(USE_PYTHON) install(FILES ngcore.hpp archive.hpp type_traits.hpp version.hpp ngcore_api.hpp logging.hpp exception.hpp symboltable.hpp paje_trace.hpp utils.hpp profiler.hpp mpi_wrapper.hpp + array.hpp taskmanager.hpp concurrentqueue.h DESTINATION ${NG_INSTALL_DIR_INCLUDE}/core COMPONENT netgen_devel) if(ENABLE_CPP_CORE_GUIDELINES_CHECK) diff --git a/libsrc/core/array.hpp b/libsrc/core/array.hpp new file mode 100644 index 00000000..e1f6d006 --- /dev/null +++ b/libsrc/core/array.hpp @@ -0,0 +1,1475 @@ +#ifndef NETGEN_CORE_ARRAY_HPP +#define NETGEN_CORE_ARRAY_HPP + +/**************************************************************************/ +/* File: array.hpp */ +/* Author: Joachim Schoeberl */ +/* Date: 01. Jun. 95 */ +/**************************************************************************/ + + +#include "utils.hpp" + +#ifdef DEBUG +#define CHECK_RANGE +#endif + +namespace ngcore +{ + using std::ostream; + + /** + Exception thrown by array range check. + Only thrown when compiled with RANGE_CHECK + */ + class ArrayRangeException : public Exception + { + public: + ArrayRangeException () : Exception("ArrayRangeException\n") { ; } + }; + + template class Tuple + { + public: + int Size() const { return 0; } + }; + + template + class Tuple : Tuple + { + typedef Tuple BASE; + HEAD head; + public: + Tuple () { ; } + Tuple (HEAD h, TAIL ... t) : Tuple (t...), head(h) { ; } + + HEAD Head() const { return head; } + Tuple Tail() const { return *this; } + + int Size() const { return BASE::Size()+1; } + }; + + template + ostream & operator<< (ostream & ost, Tuple tup) + { + return ost; + } + + template + ostream & operator<< (ostream & ost, Tuple tup) + { + ost << tup.Head() << ", " << tup.Tail(); + return ost; + } + + + template + Tuple MakeTuple (ARGS ... args) + { + return Tuple (args...); + } + + + /* + Some class which can be treated as array + */ + template // , typename TA = T> + class BaseArrayObject + { + public: + NETGEN_INLINE BaseArrayObject() { ; } + + NETGEN_INLINE const T & Spec() const { return static_cast (*this); } + NETGEN_INLINE size_t Size() const { return Spec().Size(); } + template + NETGEN_INLINE bool Contains(const T2 & el) const + { + for (size_t i = 0; i < Size(); i++) + if (Spec()[i] == el) + return true; + return false; + } + + static constexpr size_t ILLEGAL_POSITION = size_t(-1); + template + NETGEN_INLINE size_t Pos(const T2 & el) const + { + for (size_t i = 0; i < Size(); i++) + if (Spec()[i] == el) + return i; + return ILLEGAL_POSITION; + } + + template + NETGEN_INLINE size_t PosSure(const T2 & el) const + { + for (size_t i = 0; ; i++) + if (Spec()[i] == el) + return i; + } + + // NETGEN_INLINE auto & operator[] (size_t i) { return Spec()[i]; } + NETGEN_INLINE auto operator[] (size_t i) const { return Spec()[i]; } + }; + + + template + class AOWrapperIterator + { + const AO & ao; + size_t ind; + public: + NETGEN_INLINE AOWrapperIterator (const AO & aao, size_t ai) + : ao(aao), ind(ai) { ; } + NETGEN_INLINE AOWrapperIterator operator++ (int) + { return AOWrapperIterator(ao, ind++); } + NETGEN_INLINE AOWrapperIterator operator++ () + { return AOWrapperIterator(ao, ++ind); } + NETGEN_INLINE auto operator*() const -> decltype(ao[ind]) { return ao[ind]; } + NETGEN_INLINE auto operator*() -> decltype(ao[ind]) { return ao[ind]; } + NETGEN_INLINE bool operator != (AOWrapperIterator d2) { return ind != d2.ind; } + NETGEN_INLINE bool operator == (AOWrapperIterator d2) { return ind == d2.ind; } + }; + + + + template + class AOWrapper : public BaseArrayObject> + { + T ar; + public: + NETGEN_INLINE AOWrapper (T aar) : ar(aar) { ; } + NETGEN_INLINE operator T () const { return ar; } + NETGEN_INLINE size_t Size() const { return ar.Size(); } + NETGEN_INLINE auto operator[] (size_t i) { return ar[i]; } + NETGEN_INLINE auto operator[] (size_t i) const { return ar[i]; } + NETGEN_INLINE AOWrapperIterator begin () const { return AOWrapperIterator (*this, 0); } + NETGEN_INLINE AOWrapperIterator end () const { return AOWrapperIterator (*this, Size()); } + }; + + template + NETGEN_INLINE AOWrapper ArrayObject (const T & ar) + { + return AOWrapper (ar); + } + + template + NETGEN_INLINE AOWrapper ArrayObject (T && ar) + { + return AOWrapper (ar); + } + + template + auto ArrayObject (size_t s, FUNC f) + { + class Dummy + { + size_t s; + FUNC f; + public: + Dummy (size_t _s, FUNC _f) : s(_s), f(_f) { ; } + size_t Size() const { return s; } + auto operator[] (size_t i) const { return f(i); } + }; + return ArrayObject(Dummy(s,f)); + } + + template + auto Substitute (const BaseArrayObject & ao, FUNC f) + { + return ArrayObject(ao.Size(), + [&ao,f] (size_t i) { return f(ao[i]); }); + } + + + + + /** + nothing more but a new type for a C array. + return value for Addr - operator of array + */ + template + class CArray + { + protected: + /// the data + T * data; + public: + + /// initialize array + NETGEN_INLINE CArray () { data = 0; } + + /// provide size and memory + NETGEN_INLINE CArray (T * adata) + : data(adata) { ; } + + /// Access array + NETGEN_INLINE T & operator[] (size_t i) const + { + return data[i]; + } + + NETGEN_INLINE operator T* () const { return data; } + }; + + template class FlatArray; + + + template + class ArrayIterator + { + FlatArray ar; + TSIZE ind; + public: + NETGEN_INLINE ArrayIterator (FlatArray aar, TSIZE ai) + : ar(aar), ind(ai) { ; } + NETGEN_INLINE ArrayIterator operator++ (int) + { return ArrayIterator(ar, ind++); } + NETGEN_INLINE ArrayIterator operator++ () + { return ArrayIterator(ar, ++ind); } + NETGEN_INLINE TELEM operator*() const { return ar[ind]; } + NETGEN_INLINE TELEM & operator*() { return ar[ind]; } + NETGEN_INLINE bool operator != (ArrayIterator d2) { return ind != d2.ind; } + NETGEN_INLINE bool operator == (ArrayIterator d2) { return ind == d2.ind; } + }; + + + + template + class ArrayRangeIterator + { + TSIZE ind; + public: + NETGEN_INLINE ArrayRangeIterator (TSIZE ai) : ind(ai) { ; } + NETGEN_INLINE ArrayRangeIterator operator++ (int) { return ind++; } + NETGEN_INLINE ArrayRangeIterator operator++ () { return ++ind; } + NETGEN_INLINE TSIZE operator*() const { return ind; } + NETGEN_INLINE TSIZE Index() { return ind; } + NETGEN_INLINE operator TSIZE () const { return ind; } + NETGEN_INLINE bool operator != (ArrayRangeIterator d2) { return ind != d2.ind; } + NETGEN_INLINE bool operator == (ArrayRangeIterator d2) { return ind == d2.ind; } + }; + + /// a range of integers + template + class T_Range : public BaseArrayObject > + { + T first, next; + public: + NETGEN_INLINE T_Range () { ; } + NETGEN_INLINE T_Range (T n) : first(0), next(n) {;} + NETGEN_INLINE T_Range (T f, T n) : first(f), next(n) {;} + template + NETGEN_INLINE T_Range(T_Range r2) : first(r2.First()), next(r2.Next()) { ; } + NETGEN_INLINE T First() const { return first; } + NETGEN_INLINE T Next() const { return next; } + NETGEN_INLINE T & First() { return first; } + NETGEN_INLINE T & Next() { return next; } + NETGEN_INLINE auto Size() const { return next-first; } + NETGEN_INLINE T operator[] (T i) const { return first+i; } + NETGEN_INLINE bool Contains (T i) const { return ((i >= first) && (i < next)); } + + NETGEN_INLINE ArrayRangeIterator begin() const { return first; } + NETGEN_INLINE ArrayRangeIterator end() const { return next; } + + T_Range Split (size_t nr, int tot) const + { + T diff = next-first; + return T_Range (first + nr * diff / tot, + first + (nr+1) * diff / tot); + } + // NETGEN_INLINE operator IntRange () const { return IntRange(first,next); } + }; + + using IntRange = T_Range; + + template + NETGEN_INLINE T_Range Range (T a, T b) + { + return T_Range(a,b); + } + + template + NETGEN_INLINE T_Range Range_impl (T n, std::true_type) + { + return T_Range (0, n); + } + + template + NETGEN_INLINE auto Range_impl (const T & ao, std::false_type) + -> T_Range + { + return T_Range (0, ao.Size()); + } + + template + auto Range(const T & x) -> decltype(Range_impl(x, std::is_integral())) { + return Range_impl(x, std::is_integral()); + } + + + NETGEN_INLINE IntRange operator+ (const IntRange & range, int shift) + { + return IntRange (range.First()+shift, range.Next()+shift); + } + + NETGEN_INLINE IntRange operator+ (int shift, const IntRange & range) + { + return IntRange (range.First()+shift, range.Next()+shift); + } + + NETGEN_INLINE IntRange operator* (int scale, const IntRange & range) + { + return IntRange (scale*range.First(), scale*range.Next()); + } + + NETGEN_INLINE IntRange operator* (const IntRange & range, int scale) + { + return IntRange (scale*range.First(), scale*range.Next()); + } + + template + inline ostream & operator<< (ostream & s, T_Range ir) + { + s << "[" << ir.First() << "," << ir.Next() << ")"; + return s; + } + + template + ostream & operator<< (ostream & ost, Tuple tup) + { + ost << tup.Head() << ", " << tup.Tail(); + return ost; + } + + + template + inline ostream & operator<< (ostream & ost, const BaseArrayObject & array) + { + for (auto i : Range(array.Size())) + ost << i << ":" << array[i] << std::endl; + return ost; + } + + + template + class IndirectArray : public BaseArrayObject > + { + FlatArray ba; + const INDEX_ARRAY & ia; + + public: + NETGEN_INLINE IndirectArray (FlatArray aba, + const INDEX_ARRAY & aia) + : ba(aba), ia(aia) { ; } + + NETGEN_INLINE size_t Size() const { return ia.Size(); } + NETGEN_INLINE T operator[] (size_t i) const { return ba[ia[i]]; } + NETGEN_INLINE T & operator[] (size_t i) { return ba[ia[i]]; } + + NETGEN_INLINE IndirectArray operator= (const T & val) + { + for (auto i : Range(Size())) + (*this)[i] = val; + return IndirectArray (ba, ia); + } + + template + NETGEN_INLINE IndirectArray operator= (const BaseArrayObject & a2) + { + for (auto i : Range(Size())) + (*this)[i] = a2[i]; + return IndirectArray (ba, ia); + } + + }; + + + /** + A simple array container. + Array represented by size and data-pointer. + No memory allocation and deallocation, must be provided by user. + Helper functions for printing. + Optional range check by macro CHECK_RANGE + */ + template + class FlatArray : public BaseArrayObject > + { + protected: + /// the size + size_t size; + /// the data + T * __restrict data; + public: + using BaseArrayObject >::ILLEGAL_POSITION; + + /// initialize array + NETGEN_INLINE FlatArray () = default; + // { ; } // size = 0; data = 0; } + + /// copy constructor allows size-type conversion + NETGEN_INLINE FlatArray (const FlatArray & a2) = default; + // : size(a2.Size()), data(a2.data) { ; } + + /// provide size and memory + NETGEN_INLINE FlatArray (size_t asize, T * adata) + : size(asize), data(adata) { ; } + +// /// memory from local heap +// NETGEN_INLINE FlatArray(size_t asize, Allocator & lh) +// : size(asize), data(new (lh) T[asize]) +// { ; } +// +// NETGEN_INLINE FlatArray(size_t asize, LocalHeap & lh) +// : size(asize), data (lh.Alloc (asize)) +// { ; } + + /// the size + NETGEN_INLINE size_t Size() const { return size; } + + /// Fill array with value val + NETGEN_INLINE const FlatArray & operator= (const T & val) const + { + size_t hsize = size; + T * hdata = data; + for (size_t i = 0; i < hsize; i++) + hdata[i] = val; + return *this; + } + + /// copies array + NETGEN_INLINE const FlatArray & operator= (const FlatArray & a2) const + { + size_t hsize = size; + T * hdata = data; + for (size_t i = 0; i < hsize; i++) hdata[i] = a2[i]; + return *this; + } + + template + NETGEN_INLINE const FlatArray & operator= (const BaseArrayObject & a2) const + { + size_t hsize = size; + T * hdata = data; + for (size_t i = 0; i < hsize; i++) hdata[i] = a2[i]; + return *this; + } + + NETGEN_INLINE const FlatArray & operator= (const std::function & func) const + { + for (size_t i = 0; i < size; i++) + data[i] = func(i); + return *this; + } + +// template +// const FlatArray operator= (ParallelValue val); +// template +// const FlatArray operator= (ParallelFunction val); + + /// copies pointers + NETGEN_INLINE const FlatArray & Assign (const FlatArray & a2) + { + size = a2.size; + data = a2.data; + return *this; + } + +// /// assigns memory from local heap +// NETGEN_INLINE const FlatArray & Assign (size_t asize, LocalHeap & lh) +// { +// size = asize; +// data = lh.Alloc (asize); +// return *this; +// } + + /// Access array. range check by macro CHECK_RANGE + NETGEN_INLINE T & operator[] (size_t i) const + { +#ifdef CHECK_RANGE + if (i < 0 || i >= size) + throw RangeException ("FlatArray::operator[]", i, 0, size-1); +#endif + return data[i]; + } + + NETGEN_INLINE T_Range Range () const + { + return T_Range (0, Size()); + } + + NETGEN_INLINE const CArray Addr (size_t pos) const + { + return CArray (data+pos); + } + + // const CArray operator+ (int pos) + // { return CArray (data+pos); } + NETGEN_INLINE T * operator+ (size_t pos) const { return data+pos; } + + /// access last element. check by macro CHECK_RANGE + T & Last () const + { +#ifdef CHECK_RANGE + if (!size) + throw Exception ("Array should not be empty"); +#endif + return data[size-1]; + } + + /// takes sub-array starting from position pos + NETGEN_INLINE const FlatArray Part (size_t pos) + { + return FlatArray (size-pos, data+pos); + } + + /// takes subsize elements starting from position pos + NETGEN_INLINE const FlatArray Part (size_t pos, size_t subsize) + { + return FlatArray (subsize, data+pos); + } + + /// takes range starting from position start of end-start elements + NETGEN_INLINE FlatArray Range (size_t start, size_t end) const + { + return FlatArray (end-start, data+start); + } + + /// takes range starting from position start of end-start elements + NETGEN_INLINE FlatArray Range (T_Range range) const + { + return FlatArray (range.Size(), data+range.First()); + } + + /// takes range starting from position start of end-start elements + NETGEN_INLINE const FlatArray operator[] (IntRange range) const + { + return FlatArray (range.Size(), data+range.First()); + } + + template + IndirectArray > + operator[] (const BaseArrayObject & ind_array) const + { + return IndirectArray > (*this, ind_array); + } + + /// first position of element elem, returns -1 if element not contained in array + NETGEN_INLINE size_t Pos(const T & el) const + { + for (size_t i = 0; i < Size(); i++) + if (data[i] == el) + return i; + return ILLEGAL_POSITION; + } + + /// does the array contain element elem ? + NETGEN_INLINE bool Contains(const T & elem) const + { + return Pos(elem) != ILLEGAL_POSITION; + } + + ArrayIterator begin() const + { return ArrayIterator (*this, 0); } + ArrayIterator end() const + { return ArrayIterator (*this, size); } + }; + + template + FlatArray View (FlatArray fa) { return fa; } + + /// print array + template + inline ostream & operator<< (ostream & s, const FlatArray & a) + { + for (auto i : a.Range()) + s << i << ": " << a[i] << "\n"; + return s; + } + + /// have arrays the same contents ? + template + inline bool operator== (const FlatArray & a1, + const FlatArray & a2) + { + if (a1.Size () != a2.Size()) return 0; + for (size_t i = 0; i < a1.Size(); i++) + if (a1[i] != a2[i]) return false; + return true; + } + + + + /** + Dynamic array container. + + Array is an automatically increasing array container. + The allocated memory doubles on overflow. + Either the container takes care of memory allocation and deallocation, + or the user provides one block of data. + */ + template + class Array : public FlatArray + { + protected: + /// physical size of array + size_t allocsize; + /// that's the data we have to delete, nullptr for not owning the memory + T * mem_to_delete; + + using FlatArray::size; + using FlatArray::data; + + public: + /// Generate array of logical and physical size asize + NETGEN_INLINE explicit Array() + : FlatArray (0, nullptr) + { + allocsize = 0; + mem_to_delete = nullptr; + } + + NETGEN_INLINE explicit Array(size_t asize) + : FlatArray (asize, new T[asize]) + { + allocsize = asize; + mem_to_delete = data; + } + + + /// Generate array in user data + NETGEN_INLINE Array(size_t asize, T* adata, bool ownMemory = false) + : FlatArray (asize, adata) + { + allocsize = asize; + if(ownMemory) + mem_to_delete = adata; + else + mem_to_delete = nullptr; + } + + /// Generate array in user data + template + NETGEN_INLINE Array(size_t asize, ALLOCATOR & lh) + : FlatArray (asize, lh) + { + allocsize = asize; + mem_to_delete = nullptr; + } + + NETGEN_INLINE Array (Array && a2) + { + size = a2.size; + data = a2.data; + allocsize = a2.allocsize; + mem_to_delete = a2.mem_to_delete; + a2.size = 0; + a2.allocsize = 0; + a2.data = nullptr; + a2.mem_to_delete = nullptr; + } + + /// array copy + NETGEN_INLINE explicit Array (const Array & a2) + : FlatArray (a2.Size(), a2.Size() ? new T[a2.Size()] : nullptr) + { + allocsize = size; + mem_to_delete = data; + for (size_t i = 0; i < size; i++) + data[i] = a2[i]; + } + + + template + explicit Array (const BaseArrayObject & a2) + : FlatArray (a2.Size(), + a2.Size() ? new T[a2.Size()] : nullptr) + { + allocsize = size; + mem_to_delete = data; + for (size_t i = 0; i < size; i++) + data[i] = a2[i]; + } + + Array (std::initializer_list list) + : FlatArray (list.size(), + list.size() ? new T[list.size()] : NULL) + { + allocsize = size; + mem_to_delete = data; + size_t cnt = 0; + for (auto val : list) + data[cnt++] = val; + } + + /// array merge-copy + explicit Array (const Array & a2, const Array & a3) + : FlatArray (a2.Size()+a3.Size(), + a2.Size()+a3.Size() ? new T[a2.Size()+a3.Size()] : 0) + { + allocsize = size; + mem_to_delete = data; + for(size_t i = 0; i < a2.Size(); i++) + (*this)[i] = a2[i]; + for (size_t i = a2.Size(), j=0; i < size; i++,j++) + (*this)[i] = a3[j]; + } + + /// if responsible, deletes memory + NETGEN_INLINE ~Array() + { + delete [] mem_to_delete; + } + +// // Only provide this function if T is archivable +// template +// auto DoArchive(Archive& archive) -> typename std::enable_if_t, void> +// { +// if(archive.Output()) +// archive << size; +// else +// { +// size_t s; +// archive & s; +// SetSize(s); +// } +// archive.Do(data, size); +// } + + /// we tell the compiler that there is no need for deleting the array .. + NETGEN_INLINE void NothingToDelete () + { + mem_to_delete = nullptr; + } + + /// Change logical size. If necessary, do reallocation. Keeps contents. + NETGEN_INLINE void SetSize(size_t nsize) + { + if (nsize > allocsize) ReSize (nsize); + size = nsize; + } + + /// + NETGEN_INLINE void SetSize0() + { + size = 0; + } + + /// Change physical size. Keeps logical size. Keeps contents. + NETGEN_INLINE void SetAllocSize (size_t nallocsize) + { + if (nallocsize > allocsize) + ReSize (nallocsize); + } + + /// Change physical size. Keeps logical size. Keeps contents. + NETGEN_INLINE size_t AllocSize () const + { + return allocsize; + } + + +// /// assigns memory from local heap +// NETGEN_INLINE const Array & Assign (size_t asize, LocalHeap & lh) +// { +// delete [] mem_to_delete; +// size = allocsize = asize; +// data = lh.Alloc (asize); +// mem_to_delete = nullptr; +// return *this; +// } + + /// Add element at end of array. reallocation if necessary. + NETGEN_INLINE size_t Append (const T & el) + { + if (size == allocsize) + ReSize (size+1); + data[size] = el; + size++; + return size; + } + + /// Add element at end of array. reallocation not necessary. + NETGEN_INLINE size_t AppendHaveMem (const T & el) + { + data[size] = el; + size++; + return size; + } + + + /// Add element at end of array. reallocation if necessary. + NETGEN_INLINE size_t Append (T && el) + { + if (size == allocsize) + ReSize (size+1); + data[size] = move(el); + size++; + return size; + } + + // Add elements of initializer list to end of array. Reallocation if necessary. + NETGEN_INLINE size_t Append(std::initializer_list lst) + { + if(allocsize < size + lst.size()) + ReSize(size+lst.size()); + for(auto val : lst) + data[size++] = val; + return size; + } + + /// Add element at end of array. reallocation if necessary. + NETGEN_INLINE void Insert (size_t pos, const T & el) + { + if (size == allocsize) + ReSize (size+1); + for (size_t i = size; i > pos; i--) + data[i] = data[i-1]; + data[pos] = el; + size++; + } + + NETGEN_INLINE Array & operator += (const T & el) + { + Append (el); + return *this; + } + + + /// Append array at end of array. reallocation if necessary. + // int Append (const Array & source) + NETGEN_INLINE size_t Append (FlatArray source) + { + if(size + source.Size() >= allocsize) + ReSize (size + source.Size() + 1); + + for(size_t i = size, j=0; jsize-1; j++) + this->data[j] = this->data[j+1]; + this->size--; + } + + + /// Delete last element. + NETGEN_INLINE void DeleteLast () + { +#ifdef CHECK_RANGE + // CheckNonEmpty(); +#endif + size--; + } + + /// Deallocate memory + NETGEN_INLINE void DeleteAll () + { + delete [] mem_to_delete; + mem_to_delete = NULL; + data = 0; + size = allocsize = 0; + } + + /// Fill array with val + NETGEN_INLINE Array & operator= (const T & val) + { + FlatArray::operator= (val); + return *this; + } + + /// array copy + NETGEN_INLINE Array & operator= (const Array & a2) + { + SetSize0 (); + SetSize (a2.Size()); + for (size_t i = 0; i < size; i++) + (*this)[i] = a2[i]; + return *this; + } + + /// steal array + NETGEN_INLINE Array & operator= (Array && a2) + { + ngcore::Swap (size, a2.size); + ngcore::Swap (data, a2.data); + ngcore::Swap (allocsize, a2.allocsize); + ngcore::Swap (mem_to_delete, a2.mem_to_delete); + return *this; + } + + + /// array copy + NETGEN_INLINE Array & operator= (const FlatArray & a2) + { + SetSize (a2.Size()); + for (size_t i = 0; i < size; i++) + (*this)[i] = a2[i]; + return *this; + } + + /* + /// fill array with first, first+1, ... + Array & operator= (const IntRange & range) + { + SetSize (range.Size()); + for (int i = 0; i < size; i++) + (*this)[i] = range.First()+i; + return *this; + } + */ + template + Array & operator= (const BaseArrayObject & a2) + { + size_t newsize = a2.Spec().Size(); + SetSize0 (); + SetSize (newsize); + // for (size_t i = 0; i < newsize; i++) + // (*this)[i] = a2.Spec()[i]; + size_t i = 0; + for (auto val : a2.Spec()) + (*this)[i++] = val; + + return *this; + } + + template + Array & operator= (Tuple tup) + { + SetSize (ArraySize (tup)); + StoreToArray (*this, tup); + return *this; + } + + Array & operator= (std::initializer_list list) + { + *this = Array (list); + return *this; + } + + +// template +// Array & operator= (ParallelValue val) +// { +// FlatArray::operator= (val); +// return *this; +// } +// template +// Array & operator= (ParallelFunction val) +// { +// FlatArray::operator= (val); +// return *this; +// } + + + NETGEN_INLINE void Swap (Array & b) + { + ngcore::Swap (size, b.size); + ngcore::Swap (data, b.data); + ngcore::Swap (allocsize, b.allocsize); + ngcore::Swap (mem_to_delete, b.mem_to_delete); + } + + private: + + /// resize array, at least to size minsize. copy contents + NETGEN_INLINE void ReSize (size_t minsize); + }; + + + /// resize array, at least to size minsize. copy contents + template + NETGEN_INLINE void Array :: ReSize (size_t minsize) + { + size_t nsize = 2 * allocsize; + if (nsize < minsize) nsize = minsize; + + T * hdata = data; + data = new T[nsize]; + + if (hdata) + { + size_t mins = (nsize < size) ? nsize : size; +#if defined(__GNUG__) && __GNUC__ < 5 && !defined(__clang__) + for (size_t i = 0; i < mins; i++) data[i] = move(hdata[i]); +#else + if (std::is_trivially_copyable::value) + memcpy ((void*)data, hdata, sizeof(T)*mins); + else + for (size_t i = 0; i < mins; i++) data[i] = move(hdata[i]); +#endif + delete [] mem_to_delete; + } + + mem_to_delete = data; + allocsize = nsize; + } + + //extern template class Array; + + + /** + Array with static and dynamic memory management. + Declares a static array which size is given by the template parameter. + If the dynamic size fits into the static size, use static memory, + otherwise perform dynamic allocation + */ + template + class ArrayMem : public Array + { + T mem[S]; + + using Array::size; + using Array::allocsize; + using Array::data; + using Array::mem_to_delete; + // using Array::ownmem; + + public: + /// Generate array of logical and physical size asize + explicit ArrayMem(size_t asize = 0) + : Array (S, mem) + { + size = asize; + if (asize > S) + { + data = new T[asize]; + allocsize = size; + mem_to_delete = data; + } + } + + /// copies from Array a2 + explicit ArrayMem(const Array & a2) + : Array (S, (T*)mem) + { + Array::operator= (a2); + } + + /// copies from ArrayMem a2 + explicit ArrayMem(const ArrayMem & a2) + : Array (S, (T*)mem) + { + Array::operator= (a2); + } + + ArrayMem(ArrayMem && a2) + : Array (a2.Size(), (T*)mem) + { + if (a2.mem_to_delete) + { + mem_to_delete = a2.mem_to_delete; + data = a2.data; + allocsize = a2.allocsize; + a2.mem_to_delete = nullptr; + a2.data = nullptr; + a2.size = 0; + } + else + { + allocsize = S; + for (size_t i = 0; i < S; i++) + mem[i] = a2.mem[i]; + } + } + + ArrayMem (std::initializer_list list) + : ArrayMem (list.size()) + { + size_t cnt = 0; + for (auto val : list) + data[cnt++] = val; + } + + + ArrayMem & operator= (const T & val) + { + FlatArray::operator= (val); + return *this; + } + + /// array copy + ArrayMem & operator= (const FlatArray & a2) + { + this->SetSize (a2.Size()); + for (size_t i = 0; i < size; i++) + (*this)[i] = a2[i]; + return *this; + } + + + template + ArrayMem & operator= (const BaseArrayObject & a2) + { + this->SetSize (a2.Spec().Size()); + + size_t i = 0; + for (auto val : a2.Spec()) + (*this)[i++] = val; + + return *this; + } + + }; + + + + + + template + size_t ArraySize (Tuple tup) + { return 0;} + + template + size_t ArraySize (Tuple tup) + { return 1+ArraySize(tup.Tail()); } + + template + size_t ArraySize (Tuple tup) + { return tup.Head().Size()+ArraySize(tup.Tail()); } + + + template + void StoreToArray (FlatArray a, Tuple tup) { ; } + + template + void StoreToArray (FlatArray a, Tuple tup) + { + a[0] = tup.Head(); + StoreToArray (a.Range(1, a.Size()), tup.Tail()); + } + + template + void StoreToArray (FlatArray a, Tuple tup) + { + IntRange r = tup.Head(); + a.Range(0,r.Size()) = r; + StoreToArray (a.Range(r.Size(), a.Size()), tup.Tail()); + } + + /* + template template + NETGEN_INLINE Array & Array :: operator= (Tuple tup) + { + SetSize (ArraySize (tup)); + StoreToArray (*this, tup); + } + */ + + /* + /// append integers to array + inline Array & operator+= (Array & array, const IntRange & range) + { + int oldsize = array.Size(); + int s = range.Next() - range.First(); + + array.SetSize (oldsize+s); + + for (int i = 0; i < s; i++) + array[oldsize+i] = range.First()+i; + + return array; + } + */ + + + /* + template + inline Array & operator+= (Array & array, const BaseArrayObject & a2) + { + size_t oldsize = array.Size(); + size_t s = a2.Spec().Size(); + + array.SetSize (oldsize+s); + + for (size_t i = 0; i < s; i++) + array[oldsize+i] = a2.Spec()[i]; + + return array; + } + */ + + template + inline Array & operator+= (Array & array, const BaseArrayObject & a2) + { + auto oldsize = array.Size(); + auto s = a2.Spec().Size(); + + array.SetSize (oldsize+s); + + for (auto val : a2.Spec()) + array[oldsize++] = val; + + return array; + } + + + + /// bubble sort array + template + inline void BubbleSort (FlatArray data) + { + T hv; + for (size_t i = 0; i < data.Size(); i++) + for (size_t j = i+1; j < data.Size(); j++) + if (data[i] > data[j]) + { + hv = data[i]; + data[i] = data[j]; + data[j] = hv; + } + } + + /// bubble sort array + template + inline void BubbleSort (FlatArray data, FlatArray slave) + { + for (size_t i = 0; i < data.Size(); i++) + for (size_t j = i+1; j < data.Size(); j++) + if (data[i] > data[j]) + { + T hv = data[i]; + data[i] = data[j]; + data[j] = hv; + + S hvs = slave[i]; + slave[i] = slave[j]; + slave[j] = hvs; + } + } + + + + + template + void QuickSort (FlatArray data, TLESS less) + { + if (data.Size() <= 1) return; + + ptrdiff_t i = 0; + ptrdiff_t j = data.Size()-1; + + T midval = data[ (i+j)/2 ]; + + do + { + while (less (data[i], midval)) i++; + while (less (midval, data[j])) j--; + + if (i <= j) + { + Swap (data[i], data[j]); + i++; j--; + } + } + while (i <= j); + + QuickSort (data.Range (0, j+1), less); + QuickSort (data.Range (i, data.Size()), less); + } + + template + NETGEN_INLINE bool DefaultLess (const T & a, const T & b) + { + return a < b; + } + + template + class DefaultLessCl + { + public: + bool operator() (const T & a, const T & b) const + { + return a < b; + } + }; + + + + template + NETGEN_INLINE void QuickSort (FlatArray data) + { + QuickSort (data, DefaultLessCl()); + } + + + + template + void QuickSortI (FlatArray data, FlatArray index, TLESS less) + { + if (index.Size() <= 1) return; + + ptrdiff_t i = 0; + ptrdiff_t j = index.Size()-1; + + int midval = index[ (i+j)/2 ]; + + do + { + while (less (data[index[i]],data[midval]) ) i++; + while (less (data[midval], data[index[j]])) j--; + + if (i <= j) + { + Swap (index[i], index[j]); + i++; j--; + } + } + while (i <= j); + + QuickSortI (data, index.Range (0, j+1), less); + QuickSortI (data, index.Range (i, index.Size()), less); + } + + + template + NETGEN_INLINE void QuickSortI (FlatArray data, FlatArray index) + { + QuickSortI (data, index, DefaultLessCl()); + } + + + + + + template + NETGEN_INLINE T xxxRemoveRef (const T & x) + { + return x; + } + + template + class SumArray : public BaseArrayObject> + { + const TA1 & a1; + const TA2 & a2; + public: + SumArray (const TA1 & aa1, const TA2 & aa2) : a1(aa1), a2(aa2) { ; } + size_t Size() const { return a1.Size()+a2.Size(); } + auto operator[] (size_t i) const -> decltype (xxxRemoveRef (a1[0])) + { + return (i < a1.Size()) ? a1[i] : a2[i-a1.Size()]; + } + }; + + template + SumArray operator+ (const BaseArrayObject & a1, + const BaseArrayObject & a2) + { + return SumArray (a1.Spec(), a2.Spec()); + } + + + // head-tail array + template + class HTArray + { + HTArray tail; + T head; + public: + HTArray () = default; + HTArray (const HTArray &) = default; + HTArray & operator= (const HTArray &) = default; + + T * Ptr () { return tail.Ptr(); } + T & operator[] (size_t i) { return Ptr()[i]; } + + const T * Ptr () const { return tail.Ptr(); } + const T & operator[] (size_t i) const { return Ptr()[i]; } + template + T & Elem() { return (NR==S-1) ? head : tail.template Elem(); } + }; + + template + class HTArray<1,T> + { + T head; + public: + HTArray () = default; + HTArray (const HTArray &) = default; + HTArray & operator= (const HTArray &) = default; + + T * Ptr () { return &head; } + T & operator[] (size_t i) { return Ptr()[i]; } + + const T * Ptr () const { return &head; } + const T & operator[] (size_t i) const { return Ptr()[i]; } + template + T & Elem() + { + // assert(NR==0, "HTArray index error"); + return head; + } + }; + + template + class HTArray<0,T> + { + // T head; // dummy variable + public: + HTArray () = default; + HTArray (const HTArray &) = default; + HTArray & operator= (const HTArray &) = default; + + /* + T * Ptr () { return &head; } + T & operator[] (size_t i) { return Ptr()[i]; } + + const T * Ptr () const { return &head; } + const T & operator[] (size_t i) const { return Ptr()[i]; } + template + T & Elem() + { + // assert(false, "HTArray index error"); + return head; + } + */ + // T * Ptr () { return (T*)(void*)&head; } + T * Ptr () { return (T*)(void*)this; } + T & operator[] (size_t i) { return Ptr()[i]; } + // const T * Ptr () const { return (const T*)(const void*)&head; } + const T * Ptr () const { return (const T*)(const void*)this; } + const T & operator[] (size_t i) const { return Ptr()[i]; } + template + T & Elem() + { + throw Exception("illegal HTArray<0>::Elem<0>"); + } + + }; + + template + const T * operator+ (const HTArray & ar, size_t i) + { + return ar.Ptr()+i; + } + template + T * operator+ (HTArray & ar, size_t i) + { + return ar.Ptr()+i; + } +} + + +#endif // NETGEN_CORE_ARRAY_HPP + diff --git a/libsrc/core/concurrentqueue.h b/libsrc/core/concurrentqueue.h new file mode 100644 index 00000000..62689834 --- /dev/null +++ b/libsrc/core/concurrentqueue.h @@ -0,0 +1,3619 @@ +// Provides a C++11 implementation of a multi-producer, multi-consumer lock-free queue. +// An overview, including benchmark results, is provided here: +// http://moodycamel.com/blog/2014/a-fast-general-purpose-lock-free-queue-for-c++ +// The full design is also described in excruciating detail at: +// http://moodycamel.com/blog/2014/detailed-design-of-a-lock-free-queue + +// Boost Software License - Version 1.0 - August 17th, 2003 +// +// Permission is hereby granted, free of charge, to any person or organization obtaining a copy of the software and accompanying documentation covered by this license (the "Software") to use, reproduce, display, distribute, execute, and transmit the Software, and to prepare derivative works of the Software, and to permit third-parties to whom the Software is furnished to do so, all subject to the following: +// +// The copyright notices in the Software and this entire statement, including the above license grant, this restriction and the following disclaimer, must be included in all copies of the Software, in whole or in part, and all derivative works of the Software, unless such copies or derivative works are solely in the form of machine-executable object code generated by a source language processor. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE + +#pragma once + +#if defined(__GNUC__) +// Disable -Wconversion warnings (spuriously triggered when Traits::size_t and +// Traits::index_t are set to < 32 bits, causing integer promotion, causing warnings +// upon assigning any computed values) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" + +#ifdef MCDBGQ_USE_RELACY +#pragma GCC diagnostic ignored "-Wint-to-pointer-cast" +#endif +#endif + +#if defined(__APPLE__) +#include "TargetConditionals.h" +#endif + +#ifdef MCDBGQ_USE_RELACY +#include "relacy/relacy_std.hpp" +#include "relacy_shims.h" +// We only use malloc/free anyway, and the delete macro messes up `= delete` method declarations. +// We'll override the default trait malloc ourselves without a macro. +#undef new +#undef delete +#undef malloc +#undef free +#else +#include // Requires C++11. Sorry VS2010. +#include +#endif +#include // for max_align_t +#include +#include +#include +#include +#include +#include +#include // for CHAR_BIT +#include +#include // partly for __WINPTHREADS_VERSION if on MinGW-w64 w/ POSIX threading + +// Platform-specific definitions of a numeric thread ID type and an invalid value +namespace moodycamel { namespace details { + template struct thread_id_converter { + typedef thread_id_t thread_id_numeric_size_t; + typedef thread_id_t thread_id_hash_t; + static thread_id_hash_t prehash(thread_id_t const& x) { return x; } + }; +} } +#if defined(MCDBGQ_USE_RELACY) +namespace moodycamel { namespace details { + typedef std::uint32_t thread_id_t; + static const thread_id_t invalid_thread_id = 0xFFFFFFFFU; + static const thread_id_t invalid_thread_id2 = 0xFFFFFFFEU; + static inline thread_id_t thread_id() { return rl::thread_index(); } +} } +#elif defined(_WIN32) || defined(__WINDOWS__) || defined(__WIN32__) +// No sense pulling in windows.h in a header, we'll manually declare the function +// we use and rely on backwards-compatibility for this not to break +extern "C" __declspec(dllimport) unsigned long __stdcall GetCurrentThreadId(void); +namespace moodycamel { namespace details { + static_assert(sizeof(unsigned long) == sizeof(std::uint32_t), "Expected size of unsigned long to be 32 bits on Windows"); + typedef std::uint32_t thread_id_t; + static const thread_id_t invalid_thread_id = 0; // See http://blogs.msdn.com/b/oldnewthing/archive/2004/02/23/78395.aspx + static const thread_id_t invalid_thread_id2 = 0xFFFFFFFFU; // Not technically guaranteed to be invalid, but is never used in practice. Note that all Win32 thread IDs are presently multiples of 4. + static inline thread_id_t thread_id() { return static_cast(::GetCurrentThreadId()); } +} } +#elif defined(__arm__) || defined(_M_ARM) || defined(__aarch64__) || (defined(__APPLE__) && TARGET_OS_IPHONE) +namespace moodycamel { namespace details { + static_assert(sizeof(std::thread::id) == 4 || sizeof(std::thread::id) == 8, "std::thread::id is expected to be either 4 or 8 bytes"); + + typedef std::thread::id thread_id_t; + static const thread_id_t invalid_thread_id; // Default ctor creates invalid ID + + // Note we don't define a invalid_thread_id2 since std::thread::id doesn't have one; it's + // only used if MOODYCAMEL_CPP11_THREAD_LOCAL_SUPPORTED is defined anyway, which it won't + // be. + static inline thread_id_t thread_id() { return std::this_thread::get_id(); } + + template struct thread_id_size { }; + template<> struct thread_id_size<4> { typedef std::uint32_t numeric_t; }; + template<> struct thread_id_size<8> { typedef std::uint64_t numeric_t; }; + + template<> struct thread_id_converter { + typedef thread_id_size::numeric_t thread_id_numeric_size_t; +#ifndef __APPLE__ + typedef std::size_t thread_id_hash_t; +#else + typedef thread_id_numeric_size_t thread_id_hash_t; +#endif + + static thread_id_hash_t prehash(thread_id_t const& x) + { +#ifndef __APPLE__ + return std::hash()(x); +#else + return *reinterpret_cast(&x); +#endif + } + }; +} } +#else +// Use a nice trick from this answer: http://stackoverflow.com/a/8438730/21475 +// In order to get a numeric thread ID in a platform-independent way, we use a thread-local +// static variable's address as a thread identifier :-) +#if defined(__GNUC__) || defined(__INTEL_COMPILER) +#define MOODYCAMEL_THREADLOCAL __thread +#elif defined(_MSC_VER) +#define MOODYCAMEL_THREADLOCAL __declspec(thread) +#else +// Assume C++11 compliant compiler +#define MOODYCAMEL_THREADLOCAL thread_local +#endif +namespace moodycamel { namespace details { + typedef std::uintptr_t thread_id_t; + static const thread_id_t invalid_thread_id = 0; // Address can't be nullptr + static const thread_id_t invalid_thread_id2 = 1; // Member accesses off a null pointer are also generally invalid. Plus it's not aligned. + static inline thread_id_t thread_id() { static MOODYCAMEL_THREADLOCAL int x; return reinterpret_cast(&x); } +} } +#endif + +// Exceptions +#ifndef MOODYCAMEL_EXCEPTIONS_ENABLED +#if (defined(_MSC_VER) && defined(_CPPUNWIND)) || (defined(__GNUC__) && defined(__EXCEPTIONS)) || (!defined(_MSC_VER) && !defined(__GNUC__)) +#define MOODYCAMEL_EXCEPTIONS_ENABLED +#endif +#endif +#ifdef MOODYCAMEL_EXCEPTIONS_ENABLED +#define MOODYCAMEL_TRY try +#define MOODYCAMEL_CATCH(...) catch(__VA_ARGS__) +#define MOODYCAMEL_RETHROW throw +#define MOODYCAMEL_THROW(expr) throw (expr) +#else +#define MOODYCAMEL_TRY if (true) +#define MOODYCAMEL_CATCH(...) else if (false) +#define MOODYCAMEL_RETHROW +#define MOODYCAMEL_THROW(expr) +#endif + +#ifndef MOODYCAMEL_NOEXCEPT +#if !defined(MOODYCAMEL_EXCEPTIONS_ENABLED) +#define MOODYCAMEL_NOEXCEPT +#define MOODYCAMEL_NOEXCEPT_CTOR(type, valueType, expr) true +#define MOODYCAMEL_NOEXCEPT_ASSIGN(type, valueType, expr) true +#elif defined(_MSC_VER) && defined(_NOEXCEPT) && _MSC_VER < 1800 +// VS2012's std::is_nothrow_[move_]constructible is broken and returns true when it shouldn't :-( +// We have to assume *all* non-trivial constructors may throw on VS2012! +#define MOODYCAMEL_NOEXCEPT _NOEXCEPT +#define MOODYCAMEL_NOEXCEPT_CTOR(type, valueType, expr) (std::is_rvalue_reference::value && std::is_move_constructible::value ? std::is_trivially_move_constructible::value : std::is_trivially_copy_constructible::value) +#define MOODYCAMEL_NOEXCEPT_ASSIGN(type, valueType, expr) ((std::is_rvalue_reference::value && std::is_move_assignable::value ? std::is_trivially_move_assignable::value || std::is_nothrow_move_assignable::value : std::is_trivially_copy_assignable::value || std::is_nothrow_copy_assignable::value) && MOODYCAMEL_NOEXCEPT_CTOR(type, valueType, expr)) +#elif defined(_MSC_VER) && defined(_NOEXCEPT) && _MSC_VER < 1900 +#define MOODYCAMEL_NOEXCEPT _NOEXCEPT +#define MOODYCAMEL_NOEXCEPT_CTOR(type, valueType, expr) (std::is_rvalue_reference::value && std::is_move_constructible::value ? std::is_trivially_move_constructible::value || std::is_nothrow_move_constructible::value : std::is_trivially_copy_constructible::value || std::is_nothrow_copy_constructible::value) +#define MOODYCAMEL_NOEXCEPT_ASSIGN(type, valueType, expr) ((std::is_rvalue_reference::value && std::is_move_assignable::value ? std::is_trivially_move_assignable::value || std::is_nothrow_move_assignable::value : std::is_trivially_copy_assignable::value || std::is_nothrow_copy_assignable::value) && MOODYCAMEL_NOEXCEPT_CTOR(type, valueType, expr)) +#else +#define MOODYCAMEL_NOEXCEPT noexcept +#define MOODYCAMEL_NOEXCEPT_CTOR(type, valueType, expr) noexcept(expr) +#define MOODYCAMEL_NOEXCEPT_ASSIGN(type, valueType, expr) noexcept(expr) +#endif +#endif + +#ifndef MOODYCAMEL_CPP11_THREAD_LOCAL_SUPPORTED +#ifdef MCDBGQ_USE_RELACY +#define MOODYCAMEL_CPP11_THREAD_LOCAL_SUPPORTED +#else +// VS2013 doesn't support `thread_local`, and MinGW-w64 w/ POSIX threading has a crippling bug: http://sourceforge.net/p/mingw-w64/bugs/445 +// g++ <=4.7 doesn't support thread_local either. +// Finally, iOS/ARM doesn't have support for it either, and g++/ARM allows it to compile but it's unconfirmed to actually work +#if (!defined(_MSC_VER) || _MSC_VER >= 1900) && (!defined(__MINGW32__) && !defined(__MINGW64__) || !defined(__WINPTHREADS_VERSION)) && (!defined(__GNUC__) || __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)) && (!defined(__APPLE__) || !TARGET_OS_IPHONE) && !defined(__arm__) && !defined(_M_ARM) && !defined(__aarch64__) +// Assume `thread_local` is fully supported in all other C++11 compilers/platforms +//#define MOODYCAMEL_CPP11_THREAD_LOCAL_SUPPORTED // always disabled for now since several users report having problems with it on +#endif +#endif +#endif + +// VS2012 doesn't support deleted functions. +// In this case, we declare the function normally but don't define it. A link error will be generated if the function is called. +#ifndef MOODYCAMEL_DELETE_FUNCTION +#if defined(_MSC_VER) && _MSC_VER < 1800 +#define MOODYCAMEL_DELETE_FUNCTION +#else +#define MOODYCAMEL_DELETE_FUNCTION = delete +#endif +#endif + +// Compiler-specific likely/unlikely hints +namespace moodycamel { namespace details { +#if defined(__GNUC__) + static inline bool (likely)(bool x) { return __builtin_expect((x), true); } + static inline bool (unlikely)(bool x) { return __builtin_expect((x), false); } +#else + static inline bool (likely)(bool x) { return x; } + static inline bool (unlikely)(bool x) { return x; } +#endif +} } + +#ifdef MOODYCAMEL_QUEUE_INTERNAL_DEBUG +#include "internal/concurrentqueue_internal_debug.h" +#endif + +namespace moodycamel { +namespace details { + template + struct const_numeric_max { + static_assert(std::is_integral::value, "const_numeric_max can only be used with integers"); + static const T value = std::numeric_limits::is_signed + ? (static_cast(1) << (sizeof(T) * CHAR_BIT - 1)) - static_cast(1) + : static_cast(-1); + }; + +#if defined(__GLIBCXX__) + typedef ::max_align_t std_max_align_t; // libstdc++ forgot to add it to std:: for a while +#else + typedef std::max_align_t std_max_align_t; // Others (e.g. MSVC) insist it can *only* be accessed via std:: +#endif + + // Some platforms have incorrectly set max_align_t to a type with <8 bytes alignment even while supporting + // 8-byte aligned scalar values (*cough* 32-bit iOS). Work around this with our own union. See issue #64. + typedef union { + std_max_align_t x; + long long y; + void* z; + } max_align_t; +} + +// Default traits for the ConcurrentQueue. To change some of the +// traits without re-implementing all of them, inherit from this +// struct and shadow the declarations you wish to be different; +// since the traits are used as a template type parameter, the +// shadowed declarations will be used where defined, and the defaults +// otherwise. +struct ConcurrentQueueDefaultTraits +{ + // General-purpose size type. std::size_t is strongly recommended. + typedef std::size_t size_t; + + // The type used for the enqueue and dequeue indices. Must be at least as + // large as size_t. Should be significantly larger than the number of elements + // you expect to hold at once, especially if you have a high turnover rate; + // for example, on 32-bit x86, if you expect to have over a hundred million + // elements or pump several million elements through your queue in a very + // short space of time, using a 32-bit type *may* trigger a race condition. + // A 64-bit int type is recommended in that case, and in practice will + // prevent a race condition no matter the usage of the queue. Note that + // whether the queue is lock-free with a 64-int type depends on the whether + // std::atomic is lock-free, which is platform-specific. + typedef std::size_t index_t; + + // Internally, all elements are enqueued and dequeued from multi-element + // blocks; this is the smallest controllable unit. If you expect few elements + // but many producers, a smaller block size should be favoured. For few producers + // and/or many elements, a larger block size is preferred. A sane default + // is provided. Must be a power of 2. + static const size_t BLOCK_SIZE = 32; + + // For explicit producers (i.e. when using a producer token), the block is + // checked for being empty by iterating through a list of flags, one per element. + // For large block sizes, this is too inefficient, and switching to an atomic + // counter-based approach is faster. The switch is made for block sizes strictly + // larger than this threshold. + static const size_t EXPLICIT_BLOCK_EMPTY_COUNTER_THRESHOLD = 32; + + // How many full blocks can be expected for a single explicit producer? This should + // reflect that number's maximum for optimal performance. Must be a power of 2. + static const size_t EXPLICIT_INITIAL_INDEX_SIZE = 32; + + // How many full blocks can be expected for a single implicit producer? This should + // reflect that number's maximum for optimal performance. Must be a power of 2. + static const size_t IMPLICIT_INITIAL_INDEX_SIZE = 32; + + // The initial size of the hash table mapping thread IDs to implicit producers. + // Note that the hash is resized every time it becomes half full. + // Must be a power of two, and either 0 or at least 1. If 0, implicit production + // (using the enqueue methods without an explicit producer token) is disabled. + static const size_t INITIAL_IMPLICIT_PRODUCER_HASH_SIZE = 32; + + // Controls the number of items that an explicit consumer (i.e. one with a token) + // must consume before it causes all consumers to rotate and move on to the next + // internal queue. + static const std::uint32_t EXPLICIT_CONSUMER_CONSUMPTION_QUOTA_BEFORE_ROTATE = 256; + + // The maximum number of elements (inclusive) that can be enqueued to a sub-queue. + // Enqueue operations that would cause this limit to be surpassed will fail. Note + // that this limit is enforced at the block level (for performance reasons), i.e. + // it's rounded up to the nearest block size. + static const size_t MAX_SUBQUEUE_SIZE = details::const_numeric_max::value; + + +#ifndef MCDBGQ_USE_RELACY + // Memory allocation can be customized if needed. + // malloc should return nullptr on failure, and handle alignment like std::malloc. +#if defined(malloc) || defined(free) + // Gah, this is 2015, stop defining macros that break standard code already! + // Work around malloc/free being special macros: + static inline void* WORKAROUND_malloc(size_t size) { return malloc(size); } + static inline void WORKAROUND_free(void* ptr) { return free(ptr); } + static inline void* (malloc)(size_t size) { return WORKAROUND_malloc(size); } + static inline void (free)(void* ptr) { return WORKAROUND_free(ptr); } +#else + static inline void* malloc(size_t size) { return std::malloc(size); } + static inline void free(void* ptr) { return std::free(ptr); } +#endif +#else + // Debug versions when running under the Relacy race detector (ignore + // these in user code) + static inline void* malloc(size_t size) { return rl::rl_malloc(size, $); } + static inline void free(void* ptr) { return rl::rl_free(ptr, $); } +#endif +}; + + +// When producing or consuming many elements, the most efficient way is to: +// 1) Use one of the bulk-operation methods of the queue with a token +// 2) Failing that, use the bulk-operation methods without a token +// 3) Failing that, create a token and use that with the single-item methods +// 4) Failing that, use the single-parameter methods of the queue +// Having said that, don't create tokens willy-nilly -- ideally there should be +// a maximum of one token per thread (of each kind). +struct ProducerToken; +struct ConsumerToken; + +template class ConcurrentQueue; +template class BlockingConcurrentQueue; +class ConcurrentQueueTests; + + +namespace details +{ + struct ConcurrentQueueProducerTypelessBase + { + ConcurrentQueueProducerTypelessBase* next; + std::atomic inactive; + ProducerToken* token; + + ConcurrentQueueProducerTypelessBase() + : next(nullptr), inactive(false), token(nullptr) + { + } + }; + + template struct _hash_32_or_64 { + static inline std::uint32_t hash(std::uint32_t h) + { + // MurmurHash3 finalizer -- see https://code.google.com/p/smhasher/source/browse/trunk/MurmurHash3.cpp + // Since the thread ID is already unique, all we really want to do is propagate that + // uniqueness evenly across all the bits, so that we can use a subset of the bits while + // reducing collisions significantly + h ^= h >> 16; + h *= 0x85ebca6b; + h ^= h >> 13; + h *= 0xc2b2ae35; + return h ^ (h >> 16); + } + }; + template<> struct _hash_32_or_64<1> { + static inline std::uint64_t hash(std::uint64_t h) + { + h ^= h >> 33; + h *= 0xff51afd7ed558ccd; + h ^= h >> 33; + h *= 0xc4ceb9fe1a85ec53; + return h ^ (h >> 33); + } + }; + template struct hash_32_or_64 : public _hash_32_or_64<(size > 4)> { }; + + static inline size_t hash_thread_id(thread_id_t id) + { + static_assert(sizeof(thread_id_t) <= 8, "Expected a platform where thread IDs are at most 64-bit values"); + return static_cast(hash_32_or_64::thread_id_hash_t)>::hash( + thread_id_converter::prehash(id))); + } + + template + static inline bool circular_less_than(T a, T b) + { +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable: 4554) +#endif + static_assert(std::is_integral::value && !std::numeric_limits::is_signed, "circular_less_than is intended to be used only with unsigned integer types"); + return static_cast(a - b) > static_cast(static_cast(1) << static_cast(sizeof(T) * CHAR_BIT - 1)); +#ifdef _MSC_VER +#pragma warning(pop) +#endif + } + + template + static inline char* align_for(char* ptr) + { + const std::size_t alignment = std::alignment_of::value; + return ptr + (alignment - (reinterpret_cast(ptr) % alignment)) % alignment; + } + + template + static inline T ceil_to_pow_2(T x) + { + static_assert(std::is_integral::value && !std::numeric_limits::is_signed, "ceil_to_pow_2 is intended to be used only with unsigned integer types"); + + // Adapted from http://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2 + --x; + x |= x >> 1; + x |= x >> 2; + x |= x >> 4; + for (std::size_t i = 1; i < sizeof(T); i <<= 1) { + x |= x >> (i << 3); + } + ++x; + return x; + } + + template + static inline void swap_relaxed(std::atomic& left, std::atomic& right) + { + T temp = std::move(left.load(std::memory_order_relaxed)); + left.store(std::move(right.load(std::memory_order_relaxed)), std::memory_order_relaxed); + right.store(std::move(temp), std::memory_order_relaxed); + } + + template + static inline T const& nomove(T const& x) + { + return x; + } + + template + struct nomove_if + { + template + static inline T const& eval(T const& x) + { + return x; + } + }; + + template<> + struct nomove_if + { + template + static inline auto eval(U&& x) + -> decltype(std::forward(x)) + { + return std::forward(x); + } + }; + + template + static inline auto deref_noexcept(It& it) MOODYCAMEL_NOEXCEPT -> decltype(*it) + { + return *it; + } + +#if defined(__clang__) || !defined(__GNUC__) || __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8) + template struct is_trivially_destructible : std::is_trivially_destructible { }; +#else + template struct is_trivially_destructible : std::has_trivial_destructor { }; +#endif + +#ifdef MOODYCAMEL_CPP11_THREAD_LOCAL_SUPPORTED +#ifdef MCDBGQ_USE_RELACY + typedef RelacyThreadExitListener ThreadExitListener; + typedef RelacyThreadExitNotifier ThreadExitNotifier; +#else + struct ThreadExitListener + { + typedef void (*callback_t)(void*); + callback_t callback; + void* userData; + + ThreadExitListener* next; // reserved for use by the ThreadExitNotifier + }; + + + class ThreadExitNotifier + { + public: + static void subscribe(ThreadExitListener* listener) + { + auto& tlsInst = instance(); + listener->next = tlsInst.tail; + tlsInst.tail = listener; + } + + static void unsubscribe(ThreadExitListener* listener) + { + auto& tlsInst = instance(); + ThreadExitListener** prev = &tlsInst.tail; + for (auto ptr = tlsInst.tail; ptr != nullptr; ptr = ptr->next) { + if (ptr == listener) { + *prev = ptr->next; + break; + } + prev = &ptr->next; + } + } + + private: + ThreadExitNotifier() : tail(nullptr) { } + ThreadExitNotifier(ThreadExitNotifier const&) MOODYCAMEL_DELETE_FUNCTION; + ThreadExitNotifier& operator=(ThreadExitNotifier const&) MOODYCAMEL_DELETE_FUNCTION; + + ~ThreadExitNotifier() + { + // This thread is about to exit, let everyone know! + assert(this == &instance() && "If this assert fails, you likely have a buggy compiler! Change the preprocessor conditions such that MOODYCAMEL_CPP11_THREAD_LOCAL_SUPPORTED is no longer defined."); + for (auto ptr = tail; ptr != nullptr; ptr = ptr->next) { + ptr->callback(ptr->userData); + } + } + + // Thread-local + static inline ThreadExitNotifier& instance() + { + static thread_local ThreadExitNotifier notifier; + return notifier; + } + + private: + ThreadExitListener* tail; + }; +#endif +#endif + + template struct static_is_lock_free_num { enum { value = 0 }; }; + template<> struct static_is_lock_free_num { enum { value = ATOMIC_CHAR_LOCK_FREE }; }; + template<> struct static_is_lock_free_num { enum { value = ATOMIC_SHORT_LOCK_FREE }; }; + template<> struct static_is_lock_free_num { enum { value = ATOMIC_INT_LOCK_FREE }; }; + template<> struct static_is_lock_free_num { enum { value = ATOMIC_LONG_LOCK_FREE }; }; + template<> struct static_is_lock_free_num { enum { value = ATOMIC_LLONG_LOCK_FREE }; }; + template struct static_is_lock_free : static_is_lock_free_num::type> { }; + template<> struct static_is_lock_free { enum { value = ATOMIC_BOOL_LOCK_FREE }; }; + template struct static_is_lock_free { enum { value = ATOMIC_POINTER_LOCK_FREE }; }; +} + + +struct ProducerToken +{ + template + explicit ProducerToken(ConcurrentQueue& queue); + + template + explicit ProducerToken(BlockingConcurrentQueue& queue); + + ProducerToken(ProducerToken&& other) MOODYCAMEL_NOEXCEPT + : producer(other.producer) + { + other.producer = nullptr; + if (producer != nullptr) { + producer->token = this; + } + } + + inline ProducerToken& operator=(ProducerToken&& other) MOODYCAMEL_NOEXCEPT + { + swap(other); + return *this; + } + + void swap(ProducerToken& other) MOODYCAMEL_NOEXCEPT + { + std::swap(producer, other.producer); + if (producer != nullptr) { + producer->token = this; + } + if (other.producer != nullptr) { + other.producer->token = &other; + } + } + + // A token is always valid unless: + // 1) Memory allocation failed during construction + // 2) It was moved via the move constructor + // (Note: assignment does a swap, leaving both potentially valid) + // 3) The associated queue was destroyed + // Note that if valid() returns true, that only indicates + // that the token is valid for use with a specific queue, + // but not which one; that's up to the user to track. + inline bool valid() const { return producer != nullptr; } + + ~ProducerToken() + { + if (producer != nullptr) { + producer->token = nullptr; + producer->inactive.store(true, std::memory_order_release); + } + } + + // Disable copying and assignment + ProducerToken(ProducerToken const&) MOODYCAMEL_DELETE_FUNCTION; + ProducerToken& operator=(ProducerToken const&) MOODYCAMEL_DELETE_FUNCTION; + +private: + template friend class ConcurrentQueue; + friend class ConcurrentQueueTests; + +protected: + details::ConcurrentQueueProducerTypelessBase* producer; +}; + + +struct ConsumerToken +{ + template + explicit ConsumerToken(ConcurrentQueue& q); + + template + explicit ConsumerToken(BlockingConcurrentQueue& q); + + ConsumerToken(ConsumerToken&& other) MOODYCAMEL_NOEXCEPT + : initialOffset(other.initialOffset), lastKnownGlobalOffset(other.lastKnownGlobalOffset), itemsConsumedFromCurrent(other.itemsConsumedFromCurrent), currentProducer(other.currentProducer), desiredProducer(other.desiredProducer) + { + } + + inline ConsumerToken& operator=(ConsumerToken&& other) MOODYCAMEL_NOEXCEPT + { + swap(other); + return *this; + } + + void swap(ConsumerToken& other) MOODYCAMEL_NOEXCEPT + { + std::swap(initialOffset, other.initialOffset); + std::swap(lastKnownGlobalOffset, other.lastKnownGlobalOffset); + std::swap(itemsConsumedFromCurrent, other.itemsConsumedFromCurrent); + std::swap(currentProducer, other.currentProducer); + std::swap(desiredProducer, other.desiredProducer); + } + + // Disable copying and assignment + ConsumerToken(ConsumerToken const&) MOODYCAMEL_DELETE_FUNCTION; + ConsumerToken& operator=(ConsumerToken const&) MOODYCAMEL_DELETE_FUNCTION; + +private: + template friend class ConcurrentQueue; + friend class ConcurrentQueueTests; + +private: // but shared with ConcurrentQueue + std::uint32_t initialOffset; + std::uint32_t lastKnownGlobalOffset; + std::uint32_t itemsConsumedFromCurrent; + details::ConcurrentQueueProducerTypelessBase* currentProducer; + details::ConcurrentQueueProducerTypelessBase* desiredProducer; +}; + +// Need to forward-declare this swap because it's in a namespace. +// See http://stackoverflow.com/questions/4492062/why-does-a-c-friend-class-need-a-forward-declaration-only-in-other-namespaces +template +inline void swap(typename ConcurrentQueue::ImplicitProducerKVP& a, typename ConcurrentQueue::ImplicitProducerKVP& b) MOODYCAMEL_NOEXCEPT; + + +template +class ConcurrentQueue +{ +public: + typedef ::moodycamel::ProducerToken producer_token_t; + typedef ::moodycamel::ConsumerToken consumer_token_t; + + typedef typename Traits::index_t index_t; + typedef typename Traits::size_t size_t; + + static const size_t BLOCK_SIZE = static_cast(Traits::BLOCK_SIZE); + static const size_t EXPLICIT_BLOCK_EMPTY_COUNTER_THRESHOLD = static_cast(Traits::EXPLICIT_BLOCK_EMPTY_COUNTER_THRESHOLD); + static const size_t EXPLICIT_INITIAL_INDEX_SIZE = static_cast(Traits::EXPLICIT_INITIAL_INDEX_SIZE); + static const size_t IMPLICIT_INITIAL_INDEX_SIZE = static_cast(Traits::IMPLICIT_INITIAL_INDEX_SIZE); + static const size_t INITIAL_IMPLICIT_PRODUCER_HASH_SIZE = static_cast(Traits::INITIAL_IMPLICIT_PRODUCER_HASH_SIZE); + static const std::uint32_t EXPLICIT_CONSUMER_CONSUMPTION_QUOTA_BEFORE_ROTATE = static_cast(Traits::EXPLICIT_CONSUMER_CONSUMPTION_QUOTA_BEFORE_ROTATE); +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable: 4307) // + integral constant overflow (that's what the ternary expression is for!) +#pragma warning(disable: 4309) // static_cast: Truncation of constant value +#endif + static const size_t MAX_SUBQUEUE_SIZE = (details::const_numeric_max::value - static_cast(Traits::MAX_SUBQUEUE_SIZE) < BLOCK_SIZE) ? details::const_numeric_max::value : ((static_cast(Traits::MAX_SUBQUEUE_SIZE) + (BLOCK_SIZE - 1)) / BLOCK_SIZE * BLOCK_SIZE); +#ifdef _MSC_VER +#pragma warning(pop) +#endif + + static_assert(!std::numeric_limits::is_signed && std::is_integral::value, "Traits::size_t must be an unsigned integral type"); + static_assert(!std::numeric_limits::is_signed && std::is_integral::value, "Traits::index_t must be an unsigned integral type"); + static_assert(sizeof(index_t) >= sizeof(size_t), "Traits::index_t must be at least as wide as Traits::size_t"); + static_assert((BLOCK_SIZE > 1) && !(BLOCK_SIZE & (BLOCK_SIZE - 1)), "Traits::BLOCK_SIZE must be a power of 2 (and at least 2)"); + static_assert((EXPLICIT_BLOCK_EMPTY_COUNTER_THRESHOLD > 1) && !(EXPLICIT_BLOCK_EMPTY_COUNTER_THRESHOLD & (EXPLICIT_BLOCK_EMPTY_COUNTER_THRESHOLD - 1)), "Traits::EXPLICIT_BLOCK_EMPTY_COUNTER_THRESHOLD must be a power of 2 (and greater than 1)"); + static_assert((EXPLICIT_INITIAL_INDEX_SIZE > 1) && !(EXPLICIT_INITIAL_INDEX_SIZE & (EXPLICIT_INITIAL_INDEX_SIZE - 1)), "Traits::EXPLICIT_INITIAL_INDEX_SIZE must be a power of 2 (and greater than 1)"); + static_assert((IMPLICIT_INITIAL_INDEX_SIZE > 1) && !(IMPLICIT_INITIAL_INDEX_SIZE & (IMPLICIT_INITIAL_INDEX_SIZE - 1)), "Traits::IMPLICIT_INITIAL_INDEX_SIZE must be a power of 2 (and greater than 1)"); + static_assert((INITIAL_IMPLICIT_PRODUCER_HASH_SIZE == 0) || !(INITIAL_IMPLICIT_PRODUCER_HASH_SIZE & (INITIAL_IMPLICIT_PRODUCER_HASH_SIZE - 1)), "Traits::INITIAL_IMPLICIT_PRODUCER_HASH_SIZE must be a power of 2"); + static_assert(INITIAL_IMPLICIT_PRODUCER_HASH_SIZE == 0 || INITIAL_IMPLICIT_PRODUCER_HASH_SIZE >= 1, "Traits::INITIAL_IMPLICIT_PRODUCER_HASH_SIZE must be at least 1 (or 0 to disable implicit enqueueing)"); + +public: + // Creates a queue with at least `capacity` element slots; note that the + // actual number of elements that can be inserted without additional memory + // allocation depends on the number of producers and the block size (e.g. if + // the block size is equal to `capacity`, only a single block will be allocated + // up-front, which means only a single producer will be able to enqueue elements + // without an extra allocation -- blocks aren't shared between producers). + // This method is not thread safe -- it is up to the user to ensure that the + // queue is fully constructed before it starts being used by other threads (this + // includes making the memory effects of construction visible, possibly with a + // memory barrier). + explicit ConcurrentQueue(size_t capacity = 6 * BLOCK_SIZE) + : producerListTail(nullptr), + producerCount(0), + initialBlockPoolIndex(0), + nextExplicitConsumerId(0), + globalExplicitConsumerOffset(0) + { + implicitProducerHashResizeInProgress.clear(std::memory_order_relaxed); + populate_initial_implicit_producer_hash(); + populate_initial_block_list(capacity / BLOCK_SIZE + ((capacity & (BLOCK_SIZE - 1)) == 0 ? 0 : 1)); + +#ifdef MOODYCAMEL_QUEUE_INTERNAL_DEBUG + // Track all the producers using a fully-resolved typed list for + // each kind; this makes it possible to debug them starting from + // the root queue object (otherwise wacky casts are needed that + // don't compile in the debugger's expression evaluator). + explicitProducers.store(nullptr, std::memory_order_relaxed); + implicitProducers.store(nullptr, std::memory_order_relaxed); +#endif + } + + // Computes the correct amount of pre-allocated blocks for you based + // on the minimum number of elements you want available at any given + // time, and the maximum concurrent number of each type of producer. + ConcurrentQueue(size_t minCapacity, size_t maxExplicitProducers, size_t maxImplicitProducers) + : producerListTail(nullptr), + producerCount(0), + initialBlockPoolIndex(0), + nextExplicitConsumerId(0), + globalExplicitConsumerOffset(0) + { + implicitProducerHashResizeInProgress.clear(std::memory_order_relaxed); + populate_initial_implicit_producer_hash(); + size_t blocks = (((minCapacity + BLOCK_SIZE - 1) / BLOCK_SIZE) - 1) * (maxExplicitProducers + 1) + 2 * (maxExplicitProducers + maxImplicitProducers); + populate_initial_block_list(blocks); + +#ifdef MOODYCAMEL_QUEUE_INTERNAL_DEBUG + explicitProducers.store(nullptr, std::memory_order_relaxed); + implicitProducers.store(nullptr, std::memory_order_relaxed); +#endif + } + + // Note: The queue should not be accessed concurrently while it's + // being deleted. It's up to the user to synchronize this. + // This method is not thread safe. + ~ConcurrentQueue() + { + // Destroy producers + auto ptr = producerListTail.load(std::memory_order_relaxed); + while (ptr != nullptr) { + auto next = ptr->next_prod(); + if (ptr->token != nullptr) { + ptr->token->producer = nullptr; + } + destroy(ptr); + ptr = next; + } + + // Destroy implicit producer hash tables + if (INITIAL_IMPLICIT_PRODUCER_HASH_SIZE != 0) { + auto hash = implicitProducerHash.load(std::memory_order_relaxed); + while (hash != nullptr) { + auto prev = hash->prev; + if (prev != nullptr) { // The last hash is part of this object and was not allocated dynamically + for (size_t i = 0; i != hash->capacity; ++i) { + hash->entries[i].~ImplicitProducerKVP(); + } + hash->~ImplicitProducerHash(); + (Traits::free)(hash); + } + hash = prev; + } + } + + // Destroy global free list + auto block = freeList.head_unsafe(); + while (block != nullptr) { + auto next = block->freeListNext.load(std::memory_order_relaxed); + if (block->dynamicallyAllocated) { + destroy(block); + } + block = next; + } + + // Destroy initial free list + destroy_array(initialBlockPool, initialBlockPoolSize); + } + + // Disable copying and copy assignment + ConcurrentQueue(ConcurrentQueue const&) MOODYCAMEL_DELETE_FUNCTION; + ConcurrentQueue& operator=(ConcurrentQueue const&) MOODYCAMEL_DELETE_FUNCTION; + + // Moving is supported, but note that it is *not* a thread-safe operation. + // Nobody can use the queue while it's being moved, and the memory effects + // of that move must be propagated to other threads before they can use it. + // Note: When a queue is moved, its tokens are still valid but can only be + // used with the destination queue (i.e. semantically they are moved along + // with the queue itself). + ConcurrentQueue(ConcurrentQueue&& other) MOODYCAMEL_NOEXCEPT + : producerListTail(other.producerListTail.load(std::memory_order_relaxed)), + producerCount(other.producerCount.load(std::memory_order_relaxed)), + initialBlockPoolIndex(other.initialBlockPoolIndex.load(std::memory_order_relaxed)), + initialBlockPool(other.initialBlockPool), + initialBlockPoolSize(other.initialBlockPoolSize), + freeList(std::move(other.freeList)), + nextExplicitConsumerId(other.nextExplicitConsumerId.load(std::memory_order_relaxed)), + globalExplicitConsumerOffset(other.globalExplicitConsumerOffset.load(std::memory_order_relaxed)) + { + // Move the other one into this, and leave the other one as an empty queue + implicitProducerHashResizeInProgress.clear(std::memory_order_relaxed); + populate_initial_implicit_producer_hash(); + swap_implicit_producer_hashes(other); + + other.producerListTail.store(nullptr, std::memory_order_relaxed); + other.producerCount.store(0, std::memory_order_relaxed); + other.nextExplicitConsumerId.store(0, std::memory_order_relaxed); + other.globalExplicitConsumerOffset.store(0, std::memory_order_relaxed); + +#ifdef MOODYCAMEL_QUEUE_INTERNAL_DEBUG + explicitProducers.store(other.explicitProducers.load(std::memory_order_relaxed), std::memory_order_relaxed); + other.explicitProducers.store(nullptr, std::memory_order_relaxed); + implicitProducers.store(other.implicitProducers.load(std::memory_order_relaxed), std::memory_order_relaxed); + other.implicitProducers.store(nullptr, std::memory_order_relaxed); +#endif + + other.initialBlockPoolIndex.store(0, std::memory_order_relaxed); + other.initialBlockPoolSize = 0; + other.initialBlockPool = nullptr; + + reown_producers(); + } + + inline ConcurrentQueue& operator=(ConcurrentQueue&& other) MOODYCAMEL_NOEXCEPT + { + return swap_internal(other); + } + + // Swaps this queue's state with the other's. Not thread-safe. + // Swapping two queues does not invalidate their tokens, however + // the tokens that were created for one queue must be used with + // only the swapped queue (i.e. the tokens are tied to the + // queue's movable state, not the object itself). + inline void swap(ConcurrentQueue& other) MOODYCAMEL_NOEXCEPT + { + swap_internal(other); + } + +private: + ConcurrentQueue& swap_internal(ConcurrentQueue& other) + { + if (this == &other) { + return *this; + } + + details::swap_relaxed(producerListTail, other.producerListTail); + details::swap_relaxed(producerCount, other.producerCount); + details::swap_relaxed(initialBlockPoolIndex, other.initialBlockPoolIndex); + std::swap(initialBlockPool, other.initialBlockPool); + std::swap(initialBlockPoolSize, other.initialBlockPoolSize); + freeList.swap(other.freeList); + details::swap_relaxed(nextExplicitConsumerId, other.nextExplicitConsumerId); + details::swap_relaxed(globalExplicitConsumerOffset, other.globalExplicitConsumerOffset); + + swap_implicit_producer_hashes(other); + + reown_producers(); + other.reown_producers(); + +#ifdef MOODYCAMEL_QUEUE_INTERNAL_DEBUG + details::swap_relaxed(explicitProducers, other.explicitProducers); + details::swap_relaxed(implicitProducers, other.implicitProducers); +#endif + + return *this; + } + +public: + // Enqueues a single item (by copying it). + // Allocates memory if required. Only fails if memory allocation fails (or implicit + // production is disabled because Traits::INITIAL_IMPLICIT_PRODUCER_HASH_SIZE is 0, + // or Traits::MAX_SUBQUEUE_SIZE has been defined and would be surpassed). + // Thread-safe. + inline bool enqueue(T const& item) + { + if (INITIAL_IMPLICIT_PRODUCER_HASH_SIZE == 0) return false; + return inner_enqueue(item); + } + + // Enqueues a single item (by moving it, if possible). + // Allocates memory if required. Only fails if memory allocation fails (or implicit + // production is disabled because Traits::INITIAL_IMPLICIT_PRODUCER_HASH_SIZE is 0, + // or Traits::MAX_SUBQUEUE_SIZE has been defined and would be surpassed). + // Thread-safe. + inline bool enqueue(T&& item) + { + if (INITIAL_IMPLICIT_PRODUCER_HASH_SIZE == 0) return false; + return inner_enqueue(std::move(item)); + } + + // Enqueues a single item (by copying it) using an explicit producer token. + // Allocates memory if required. Only fails if memory allocation fails (or + // Traits::MAX_SUBQUEUE_SIZE has been defined and would be surpassed). + // Thread-safe. + inline bool enqueue(producer_token_t const& token, T const& item) + { + return inner_enqueue(token, item); + } + + // Enqueues a single item (by moving it, if possible) using an explicit producer token. + // Allocates memory if required. Only fails if memory allocation fails (or + // Traits::MAX_SUBQUEUE_SIZE has been defined and would be surpassed). + // Thread-safe. + inline bool enqueue(producer_token_t const& token, T&& item) + { + return inner_enqueue(token, std::move(item)); + } + + // Enqueues several items. + // Allocates memory if required. Only fails if memory allocation fails (or + // implicit production is disabled because Traits::INITIAL_IMPLICIT_PRODUCER_HASH_SIZE + // is 0, or Traits::MAX_SUBQUEUE_SIZE has been defined and would be surpassed). + // Note: Use std::make_move_iterator if the elements should be moved instead of copied. + // Thread-safe. + template + bool enqueue_bulk(It itemFirst, size_t count) + { + if (INITIAL_IMPLICIT_PRODUCER_HASH_SIZE == 0) return false; + return inner_enqueue_bulk(itemFirst, count); + } + + // Enqueues several items using an explicit producer token. + // Allocates memory if required. Only fails if memory allocation fails + // (or Traits::MAX_SUBQUEUE_SIZE has been defined and would be surpassed). + // Note: Use std::make_move_iterator if the elements should be moved + // instead of copied. + // Thread-safe. + template + bool enqueue_bulk(producer_token_t const& token, It itemFirst, size_t count) + { + return inner_enqueue_bulk(token, itemFirst, count); + } + + // Enqueues a single item (by copying it). + // Does not allocate memory. Fails if not enough room to enqueue (or implicit + // production is disabled because Traits::INITIAL_IMPLICIT_PRODUCER_HASH_SIZE + // is 0). + // Thread-safe. + inline bool try_enqueue(T const& item) + { + if (INITIAL_IMPLICIT_PRODUCER_HASH_SIZE == 0) return false; + return inner_enqueue(item); + } + + // Enqueues a single item (by moving it, if possible). + // Does not allocate memory (except for one-time implicit producer). + // Fails if not enough room to enqueue (or implicit production is + // disabled because Traits::INITIAL_IMPLICIT_PRODUCER_HASH_SIZE is 0). + // Thread-safe. + inline bool try_enqueue(T&& item) + { + if (INITIAL_IMPLICIT_PRODUCER_HASH_SIZE == 0) return false; + return inner_enqueue(std::move(item)); + } + + // Enqueues a single item (by copying it) using an explicit producer token. + // Does not allocate memory. Fails if not enough room to enqueue. + // Thread-safe. + inline bool try_enqueue(producer_token_t const& token, T const& item) + { + return inner_enqueue(token, item); + } + + // Enqueues a single item (by moving it, if possible) using an explicit producer token. + // Does not allocate memory. Fails if not enough room to enqueue. + // Thread-safe. + inline bool try_enqueue(producer_token_t const& token, T&& item) + { + return inner_enqueue(token, std::move(item)); + } + + // Enqueues several items. + // Does not allocate memory (except for one-time implicit producer). + // Fails if not enough room to enqueue (or implicit production is + // disabled because Traits::INITIAL_IMPLICIT_PRODUCER_HASH_SIZE is 0). + // Note: Use std::make_move_iterator if the elements should be moved + // instead of copied. + // Thread-safe. + template + bool try_enqueue_bulk(It itemFirst, size_t count) + { + if (INITIAL_IMPLICIT_PRODUCER_HASH_SIZE == 0) return false; + return inner_enqueue_bulk(itemFirst, count); + } + + // Enqueues several items using an explicit producer token. + // Does not allocate memory. Fails if not enough room to enqueue. + // Note: Use std::make_move_iterator if the elements should be moved + // instead of copied. + // Thread-safe. + template + bool try_enqueue_bulk(producer_token_t const& token, It itemFirst, size_t count) + { + return inner_enqueue_bulk(token, itemFirst, count); + } + + + + // Attempts to dequeue from the queue. + // Returns false if all producer streams appeared empty at the time they + // were checked (so, the queue is likely but not guaranteed to be empty). + // Never allocates. Thread-safe. + template + bool try_dequeue(U& item) + { + // Instead of simply trying each producer in turn (which could cause needless contention on the first + // producer), we score them heuristically. + size_t nonEmptyCount = 0; + ProducerBase* best = nullptr; + size_t bestSize = 0; + for (auto ptr = producerListTail.load(std::memory_order_acquire); nonEmptyCount < 3 && ptr != nullptr; ptr = ptr->next_prod()) { + auto size = ptr->size_approx(); + if (size > 0) { + if (size > bestSize) { + bestSize = size; + best = ptr; + } + ++nonEmptyCount; + } + } + + // If there was at least one non-empty queue but it appears empty at the time + // we try to dequeue from it, we need to make sure every queue's been tried + if (nonEmptyCount > 0) { + if ((details::likely)(best->dequeue(item))) { + return true; + } + for (auto ptr = producerListTail.load(std::memory_order_acquire); ptr != nullptr; ptr = ptr->next_prod()) { + if (ptr != best && ptr->dequeue(item)) { + return true; + } + } + } + return false; + } + + // Attempts to dequeue from the queue. + // Returns false if all producer streams appeared empty at the time they + // were checked (so, the queue is likely but not guaranteed to be empty). + // This differs from the try_dequeue(item) method in that this one does + // not attempt to reduce contention by interleaving the order that producer + // streams are dequeued from. So, using this method can reduce overall throughput + // under contention, but will give more predictable results in single-threaded + // consumer scenarios. This is mostly only useful for internal unit tests. + // Never allocates. Thread-safe. + template + bool try_dequeue_non_interleaved(U& item) + { + for (auto ptr = producerListTail.load(std::memory_order_acquire); ptr != nullptr; ptr = ptr->next_prod()) { + if (ptr->dequeue(item)) { + return true; + } + } + return false; + } + + // Attempts to dequeue from the queue using an explicit consumer token. + // Returns false if all producer streams appeared empty at the time they + // were checked (so, the queue is likely but not guaranteed to be empty). + // Never allocates. Thread-safe. + template + bool try_dequeue(consumer_token_t& token, U& item) + { + // The idea is roughly as follows: + // Every 256 items from one producer, make everyone rotate (increase the global offset) -> this means the highest efficiency consumer dictates the rotation speed of everyone else, more or less + // If you see that the global offset has changed, you must reset your consumption counter and move to your designated place + // If there's no items where you're supposed to be, keep moving until you find a producer with some items + // If the global offset has not changed but you've run out of items to consume, move over from your current position until you find an producer with something in it + + if (token.desiredProducer == nullptr || token.lastKnownGlobalOffset != globalExplicitConsumerOffset.load(std::memory_order_relaxed)) { + if (!update_current_producer_after_rotation(token)) { + return false; + } + } + + // If there was at least one non-empty queue but it appears empty at the time + // we try to dequeue from it, we need to make sure every queue's been tried + if (static_cast(token.currentProducer)->dequeue(item)) { + if (++token.itemsConsumedFromCurrent == EXPLICIT_CONSUMER_CONSUMPTION_QUOTA_BEFORE_ROTATE) { + globalExplicitConsumerOffset.fetch_add(1, std::memory_order_relaxed); + } + return true; + } + + auto tail = producerListTail.load(std::memory_order_acquire); + auto ptr = static_cast(token.currentProducer)->next_prod(); + if (ptr == nullptr) { + ptr = tail; + } + while (ptr != static_cast(token.currentProducer)) { + if (ptr->dequeue(item)) { + token.currentProducer = ptr; + token.itemsConsumedFromCurrent = 1; + return true; + } + ptr = ptr->next_prod(); + if (ptr == nullptr) { + ptr = tail; + } + } + return false; + } + + // Attempts to dequeue several elements from the queue. + // Returns the number of items actually dequeued. + // Returns 0 if all producer streams appeared empty at the time they + // were checked (so, the queue is likely but not guaranteed to be empty). + // Never allocates. Thread-safe. + template + size_t try_dequeue_bulk(It itemFirst, size_t max) + { + size_t count = 0; + for (auto ptr = producerListTail.load(std::memory_order_acquire); ptr != nullptr; ptr = ptr->next_prod()) { + count += ptr->dequeue_bulk(itemFirst, max - count); + if (count == max) { + break; + } + } + return count; + } + + // Attempts to dequeue several elements from the queue using an explicit consumer token. + // Returns the number of items actually dequeued. + // Returns 0 if all producer streams appeared empty at the time they + // were checked (so, the queue is likely but not guaranteed to be empty). + // Never allocates. Thread-safe. + template + size_t try_dequeue_bulk(consumer_token_t& token, It itemFirst, size_t max) + { + if (token.desiredProducer == nullptr || token.lastKnownGlobalOffset != globalExplicitConsumerOffset.load(std::memory_order_relaxed)) { + if (!update_current_producer_after_rotation(token)) { + return 0; + } + } + + size_t count = static_cast(token.currentProducer)->dequeue_bulk(itemFirst, max); + if (count == max) { + if ((token.itemsConsumedFromCurrent += static_cast(max)) >= EXPLICIT_CONSUMER_CONSUMPTION_QUOTA_BEFORE_ROTATE) { + globalExplicitConsumerOffset.fetch_add(1, std::memory_order_relaxed); + } + return max; + } + token.itemsConsumedFromCurrent += static_cast(count); + max -= count; + + auto tail = producerListTail.load(std::memory_order_acquire); + auto ptr = static_cast(token.currentProducer)->next_prod(); + if (ptr == nullptr) { + ptr = tail; + } + while (ptr != static_cast(token.currentProducer)) { + auto dequeued = ptr->dequeue_bulk(itemFirst, max); + count += dequeued; + if (dequeued != 0) { + token.currentProducer = ptr; + token.itemsConsumedFromCurrent = static_cast(dequeued); + } + if (dequeued == max) { + break; + } + max -= dequeued; + ptr = ptr->next_prod(); + if (ptr == nullptr) { + ptr = tail; + } + } + return count; + } + + + + // Attempts to dequeue from a specific producer's inner queue. + // If you happen to know which producer you want to dequeue from, this + // is significantly faster than using the general-case try_dequeue methods. + // Returns false if the producer's queue appeared empty at the time it + // was checked (so, the queue is likely but not guaranteed to be empty). + // Never allocates. Thread-safe. + template + inline bool try_dequeue_from_producer(producer_token_t const& producer, U& item) + { + return static_cast(producer.producer)->dequeue(item); + } + + // Attempts to dequeue several elements from a specific producer's inner queue. + // Returns the number of items actually dequeued. + // If you happen to know which producer you want to dequeue from, this + // is significantly faster than using the general-case try_dequeue methods. + // Returns 0 if the producer's queue appeared empty at the time it + // was checked (so, the queue is likely but not guaranteed to be empty). + // Never allocates. Thread-safe. + template + inline size_t try_dequeue_bulk_from_producer(producer_token_t const& producer, It itemFirst, size_t max) + { + return static_cast(producer.producer)->dequeue_bulk(itemFirst, max); + } + + + // Returns an estimate of the total number of elements currently in the queue. This + // estimate is only accurate if the queue has completely stabilized before it is called + // (i.e. all enqueue and dequeue operations have completed and their memory effects are + // visible on the calling thread, and no further operations start while this method is + // being called). + // Thread-safe. + size_t size_approx() const + { + size_t size = 0; + for (auto ptr = producerListTail.load(std::memory_order_acquire); ptr != nullptr; ptr = ptr->next_prod()) { + size += ptr->size_approx(); + } + return size; + } + + + // Returns true if the underlying atomic variables used by + // the queue are lock-free (they should be on most platforms). + // Thread-safe. + static bool is_lock_free() + { + return + details::static_is_lock_free::value == 2 && + details::static_is_lock_free::value == 2 && + details::static_is_lock_free::value == 2 && + details::static_is_lock_free::value == 2 && + details::static_is_lock_free::value == 2 && + details::static_is_lock_free::thread_id_numeric_size_t>::value == 2; + } + + +private: + friend struct ProducerToken; + friend struct ConsumerToken; + struct ExplicitProducer; + friend struct ExplicitProducer; + struct ImplicitProducer; + friend struct ImplicitProducer; + friend class ConcurrentQueueTests; + + enum AllocationMode { CanAlloc, CannotAlloc }; + + + /////////////////////////////// + // Queue methods + /////////////////////////////// + + template + inline bool inner_enqueue(producer_token_t const& token, U&& element) + { + return static_cast(token.producer)->ConcurrentQueue::ExplicitProducer::template enqueue(std::forward(element)); + } + + template + inline bool inner_enqueue(U&& element) + { + auto producer = get_or_add_implicit_producer(); + return producer == nullptr ? false : producer->ConcurrentQueue::ImplicitProducer::template enqueue(std::forward(element)); + } + + template + inline bool inner_enqueue_bulk(producer_token_t const& token, It itemFirst, size_t count) + { + return static_cast(token.producer)->ConcurrentQueue::ExplicitProducer::template enqueue_bulk(itemFirst, count); + } + + template + inline bool inner_enqueue_bulk(It itemFirst, size_t count) + { + auto producer = get_or_add_implicit_producer(); + return producer == nullptr ? false : producer->ConcurrentQueue::ImplicitProducer::template enqueue_bulk(itemFirst, count); + } + + inline bool update_current_producer_after_rotation(consumer_token_t& token) + { + // Ah, there's been a rotation, figure out where we should be! + auto tail = producerListTail.load(std::memory_order_acquire); + if (token.desiredProducer == nullptr && tail == nullptr) { + return false; + } + auto prodCount = producerCount.load(std::memory_order_relaxed); + auto globalOffset = globalExplicitConsumerOffset.load(std::memory_order_relaxed); + if ((details::unlikely)(token.desiredProducer == nullptr)) { + // Aha, first time we're dequeueing anything. + // Figure out our local position + // Note: offset is from start, not end, but we're traversing from end -- subtract from count first + std::uint32_t offset = prodCount - 1 - (token.initialOffset % prodCount); + token.desiredProducer = tail; + for (std::uint32_t i = 0; i != offset; ++i) { + token.desiredProducer = static_cast(token.desiredProducer)->next_prod(); + if (token.desiredProducer == nullptr) { + token.desiredProducer = tail; + } + } + } + + std::uint32_t delta = globalOffset - token.lastKnownGlobalOffset; + if (delta >= prodCount) { + delta = delta % prodCount; + } + for (std::uint32_t i = 0; i != delta; ++i) { + token.desiredProducer = static_cast(token.desiredProducer)->next_prod(); + if (token.desiredProducer == nullptr) { + token.desiredProducer = tail; + } + } + + token.lastKnownGlobalOffset = globalOffset; + token.currentProducer = token.desiredProducer; + token.itemsConsumedFromCurrent = 0; + return true; + } + + + /////////////////////////// + // Free list + /////////////////////////// + + template + struct FreeListNode + { + FreeListNode() : freeListRefs(0), freeListNext(nullptr) { } + + std::atomic freeListRefs; + std::atomic freeListNext; + }; + + // A simple CAS-based lock-free free list. Not the fastest thing in the world under heavy contention, but + // simple and correct (assuming nodes are never freed until after the free list is destroyed), and fairly + // speedy under low contention. + template // N must inherit FreeListNode or have the same fields (and initialization of them) + struct FreeList + { + FreeList() : freeListHead(nullptr) { } + FreeList(FreeList&& other) : freeListHead(other.freeListHead.load(std::memory_order_relaxed)) { other.freeListHead.store(nullptr, std::memory_order_relaxed); } + void swap(FreeList& other) { details::swap_relaxed(freeListHead, other.freeListHead); } + + FreeList(FreeList const&) MOODYCAMEL_DELETE_FUNCTION; + FreeList& operator=(FreeList const&) MOODYCAMEL_DELETE_FUNCTION; + + inline void add(N* node) + { +#if MCDBGQ_NOLOCKFREE_FREELIST + debug::DebugLock lock(mutex); +#endif + // We know that the should-be-on-freelist bit is 0 at this point, so it's safe to + // set it using a fetch_add + if (node->freeListRefs.fetch_add(SHOULD_BE_ON_FREELIST, std::memory_order_acq_rel) == 0) { + // Oh look! We were the last ones referencing this node, and we know + // we want to add it to the free list, so let's do it! + add_knowing_refcount_is_zero(node); + } + } + + inline N* try_get() + { +#if MCDBGQ_NOLOCKFREE_FREELIST + debug::DebugLock lock(mutex); +#endif + auto head = freeListHead.load(std::memory_order_acquire); + while (head != nullptr) { + auto prevHead = head; + auto refs = head->freeListRefs.load(std::memory_order_relaxed); + if ((refs & REFS_MASK) == 0 || !head->freeListRefs.compare_exchange_strong(refs, refs + 1, std::memory_order_acquire, std::memory_order_relaxed)) { + head = freeListHead.load(std::memory_order_acquire); + continue; + } + + // Good, reference count has been incremented (it wasn't at zero), which means we can read the + // next and not worry about it changing between now and the time we do the CAS + auto next = head->freeListNext.load(std::memory_order_relaxed); + if (freeListHead.compare_exchange_strong(head, next, std::memory_order_acquire, std::memory_order_relaxed)) { + // Yay, got the node. This means it was on the list, which means shouldBeOnFreeList must be false no + // matter the refcount (because nobody else knows it's been taken off yet, it can't have been put back on). + assert((head->freeListRefs.load(std::memory_order_relaxed) & SHOULD_BE_ON_FREELIST) == 0); + + // Decrease refcount twice, once for our ref, and once for the list's ref + head->freeListRefs.fetch_sub(2, std::memory_order_release); + return head; + } + + // OK, the head must have changed on us, but we still need to decrease the refcount we increased. + // Note that we don't need to release any memory effects, but we do need to ensure that the reference + // count decrement happens-after the CAS on the head. + refs = prevHead->freeListRefs.fetch_sub(1, std::memory_order_acq_rel); + if (refs == SHOULD_BE_ON_FREELIST + 1) { + add_knowing_refcount_is_zero(prevHead); + } + } + + return nullptr; + } + + // Useful for traversing the list when there's no contention (e.g. to destroy remaining nodes) + N* head_unsafe() const { return freeListHead.load(std::memory_order_relaxed); } + + private: + inline void add_knowing_refcount_is_zero(N* node) + { + // Since the refcount is zero, and nobody can increase it once it's zero (except us, and we run + // only one copy of this method per node at a time, i.e. the single thread case), then we know + // we can safely change the next pointer of the node; however, once the refcount is back above + // zero, then other threads could increase it (happens under heavy contention, when the refcount + // goes to zero in between a load and a refcount increment of a node in try_get, then back up to + // something non-zero, then the refcount increment is done by the other thread) -- so, if the CAS + // to add the node to the actual list fails, decrease the refcount and leave the add operation to + // the next thread who puts the refcount back at zero (which could be us, hence the loop). + auto head = freeListHead.load(std::memory_order_relaxed); + while (true) { + node->freeListNext.store(head, std::memory_order_relaxed); + node->freeListRefs.store(1, std::memory_order_release); + if (!freeListHead.compare_exchange_strong(head, node, std::memory_order_release, std::memory_order_relaxed)) { + // Hmm, the add failed, but we can only try again when the refcount goes back to zero + if (node->freeListRefs.fetch_add(SHOULD_BE_ON_FREELIST - 1, std::memory_order_release) == 1) { + continue; + } + } + return; + } + } + + private: + // Implemented like a stack, but where node order doesn't matter (nodes are inserted out of order under contention) + std::atomic freeListHead; + + static const std::uint32_t REFS_MASK = 0x7FFFFFFF; + static const std::uint32_t SHOULD_BE_ON_FREELIST = 0x80000000; + +#if MCDBGQ_NOLOCKFREE_FREELIST + debug::DebugMutex mutex; +#endif + }; + + + /////////////////////////// + // Block + /////////////////////////// + + enum InnerQueueContext { implicit_context = 0, explicit_context = 1 }; + + struct Block + { + Block() + : next(nullptr), elementsCompletelyDequeued(0), freeListRefs(0), freeListNext(nullptr), shouldBeOnFreeList(false), dynamicallyAllocated(true) + { +#if MCDBGQ_TRACKMEM + owner = nullptr; +#endif + } + + template + inline bool is_empty() const + { + if (context == explicit_context && BLOCK_SIZE <= EXPLICIT_BLOCK_EMPTY_COUNTER_THRESHOLD) { + // Check flags + for (size_t i = 0; i < BLOCK_SIZE; ++i) { + if (!emptyFlags[i].load(std::memory_order_relaxed)) { + return false; + } + } + + // Aha, empty; make sure we have all other memory effects that happened before the empty flags were set + std::atomic_thread_fence(std::memory_order_acquire); + return true; + } + else { + // Check counter + if (elementsCompletelyDequeued.load(std::memory_order_relaxed) == BLOCK_SIZE) { + std::atomic_thread_fence(std::memory_order_acquire); + return true; + } + assert(elementsCompletelyDequeued.load(std::memory_order_relaxed) <= BLOCK_SIZE); + return false; + } + } + + // Returns true if the block is now empty (does not apply in explicit context) + template + inline bool set_empty(index_t i) + { + if (context == explicit_context && BLOCK_SIZE <= EXPLICIT_BLOCK_EMPTY_COUNTER_THRESHOLD) { + // Set flag + assert(!emptyFlags[BLOCK_SIZE - 1 - static_cast(i & static_cast(BLOCK_SIZE - 1))].load(std::memory_order_relaxed)); + emptyFlags[BLOCK_SIZE - 1 - static_cast(i & static_cast(BLOCK_SIZE - 1))].store(true, std::memory_order_release); + return false; + } + else { + // Increment counter + auto prevVal = elementsCompletelyDequeued.fetch_add(1, std::memory_order_release); + assert(prevVal < BLOCK_SIZE); + return prevVal == BLOCK_SIZE - 1; + } + } + + // Sets multiple contiguous item statuses to 'empty' (assumes no wrapping and count > 0). + // Returns true if the block is now empty (does not apply in explicit context). + template + inline bool set_many_empty(index_t i, size_t count) + { + if (context == explicit_context && BLOCK_SIZE <= EXPLICIT_BLOCK_EMPTY_COUNTER_THRESHOLD) { + // Set flags + std::atomic_thread_fence(std::memory_order_release); + i = BLOCK_SIZE - 1 - static_cast(i & static_cast(BLOCK_SIZE - 1)) - count + 1; + for (size_t j = 0; j != count; ++j) { + assert(!emptyFlags[i + j].load(std::memory_order_relaxed)); + emptyFlags[i + j].store(true, std::memory_order_relaxed); + } + return false; + } + else { + // Increment counter + auto prevVal = elementsCompletelyDequeued.fetch_add(count, std::memory_order_release); + assert(prevVal + count <= BLOCK_SIZE); + return prevVal + count == BLOCK_SIZE; + } + } + + template + inline void set_all_empty() + { + if (context == explicit_context && BLOCK_SIZE <= EXPLICIT_BLOCK_EMPTY_COUNTER_THRESHOLD) { + // Set all flags + for (size_t i = 0; i != BLOCK_SIZE; ++i) { + emptyFlags[i].store(true, std::memory_order_relaxed); + } + } + else { + // Reset counter + elementsCompletelyDequeued.store(BLOCK_SIZE, std::memory_order_relaxed); + } + } + + template + inline void reset_empty() + { + if (context == explicit_context && BLOCK_SIZE <= EXPLICIT_BLOCK_EMPTY_COUNTER_THRESHOLD) { + // Reset flags + for (size_t i = 0; i != BLOCK_SIZE; ++i) { + emptyFlags[i].store(false, std::memory_order_relaxed); + } + } + else { + // Reset counter + elementsCompletelyDequeued.store(0, std::memory_order_relaxed); + } + } + + inline T* operator[](index_t idx) MOODYCAMEL_NOEXCEPT { return static_cast(static_cast(elements)) + static_cast(idx & static_cast(BLOCK_SIZE - 1)); } + inline T const* operator[](index_t idx) const MOODYCAMEL_NOEXCEPT { return static_cast(static_cast(elements)) + static_cast(idx & static_cast(BLOCK_SIZE - 1)); } + + private: + // IMPORTANT: This must be the first member in Block, so that if T depends on the alignment of + // addresses returned by malloc, that alignment will be preserved. Apparently clang actually + // generates code that uses this assumption for AVX instructions in some cases. Ideally, we + // should also align Block to the alignment of T in case it's higher than malloc's 16-byte + // alignment, but this is hard to do in a cross-platform way. Assert for this case: + static_assert(std::alignment_of::value <= std::alignment_of::value, "The queue does not support super-aligned types at this time"); + // Additionally, we need the alignment of Block itself to be a multiple of max_align_t since + // otherwise the appropriate padding will not be added at the end of Block in order to make + // arrays of Blocks all be properly aligned (not just the first one). We use a union to force + // this. + union { + char elements[sizeof(T) * BLOCK_SIZE]; + details::max_align_t dummy; + }; + public: + Block* next; + std::atomic elementsCompletelyDequeued; + std::atomic emptyFlags[BLOCK_SIZE <= EXPLICIT_BLOCK_EMPTY_COUNTER_THRESHOLD ? BLOCK_SIZE : 1]; + public: + std::atomic freeListRefs; + std::atomic freeListNext; + std::atomic shouldBeOnFreeList; + bool dynamicallyAllocated; // Perhaps a better name for this would be 'isNotPartOfInitialBlockPool' + +#if MCDBGQ_TRACKMEM + void* owner; +#endif + }; + static_assert(std::alignment_of::value >= std::alignment_of::value, "Internal error: Blocks must be at least as aligned as the type they are wrapping"); + + +#if MCDBGQ_TRACKMEM +public: + struct MemStats; +private: +#endif + + /////////////////////////// + // Producer base + /////////////////////////// + + struct ProducerBase : public details::ConcurrentQueueProducerTypelessBase + { + ProducerBase(ConcurrentQueue* parent_, bool isExplicit_) : + tailIndex(0), + headIndex(0), + dequeueOptimisticCount(0), + dequeueOvercommit(0), + tailBlock(nullptr), + isExplicit(isExplicit_), + parent(parent_) + { + } + + virtual ~ProducerBase() { }; + + template + inline bool dequeue(U& element) + { + if (isExplicit) { + return static_cast(this)->dequeue(element); + } + else { + return static_cast(this)->dequeue(element); + } + } + + template + inline size_t dequeue_bulk(It& itemFirst, size_t max) + { + if (isExplicit) { + return static_cast(this)->dequeue_bulk(itemFirst, max); + } + else { + return static_cast(this)->dequeue_bulk(itemFirst, max); + } + } + + inline ProducerBase* next_prod() const { return static_cast(next); } + + inline size_t size_approx() const + { + auto tail = tailIndex.load(std::memory_order_relaxed); + auto head = headIndex.load(std::memory_order_relaxed); + return details::circular_less_than(head, tail) ? static_cast(tail - head) : 0; + } + + inline index_t getTail() const { return tailIndex.load(std::memory_order_relaxed); } + protected: + std::atomic tailIndex; // Where to enqueue to next + std::atomic headIndex; // Where to dequeue from next + + std::atomic dequeueOptimisticCount; + std::atomic dequeueOvercommit; + + Block* tailBlock; + + public: + bool isExplicit; + ConcurrentQueue* parent; + + protected: +#if MCDBGQ_TRACKMEM + friend struct MemStats; +#endif + }; + + + /////////////////////////// + // Explicit queue + /////////////////////////// + + struct ExplicitProducer : public ProducerBase + { + explicit ExplicitProducer(ConcurrentQueue* parent) : + ProducerBase(parent, true), + blockIndex(nullptr), + pr_blockIndexSlotsUsed(0), + pr_blockIndexSize(EXPLICIT_INITIAL_INDEX_SIZE >> 1), + pr_blockIndexFront(0), + pr_blockIndexEntries(nullptr), + pr_blockIndexRaw(nullptr) + { + size_t poolBasedIndexSize = details::ceil_to_pow_2(parent->initialBlockPoolSize) >> 1; + if (poolBasedIndexSize > pr_blockIndexSize) { + pr_blockIndexSize = poolBasedIndexSize; + } + + new_block_index(0); // This creates an index with double the number of current entries, i.e. EXPLICIT_INITIAL_INDEX_SIZE + } + + ~ExplicitProducer() + { + // Destruct any elements not yet dequeued. + // Since we're in the destructor, we can assume all elements + // are either completely dequeued or completely not (no halfways). + if (this->tailBlock != nullptr) { // Note this means there must be a block index too + // First find the block that's partially dequeued, if any + Block* halfDequeuedBlock = nullptr; + if ((this->headIndex.load(std::memory_order_relaxed) & static_cast(BLOCK_SIZE - 1)) != 0) { + // The head's not on a block boundary, meaning a block somewhere is partially dequeued + // (or the head block is the tail block and was fully dequeued, but the head/tail are still not on a boundary) + size_t i = (pr_blockIndexFront - pr_blockIndexSlotsUsed) & (pr_blockIndexSize - 1); + while (details::circular_less_than(pr_blockIndexEntries[i].base + BLOCK_SIZE, this->headIndex.load(std::memory_order_relaxed))) { + i = (i + 1) & (pr_blockIndexSize - 1); + } + assert(details::circular_less_than(pr_blockIndexEntries[i].base, this->headIndex.load(std::memory_order_relaxed))); + halfDequeuedBlock = pr_blockIndexEntries[i].block; + } + + // Start at the head block (note the first line in the loop gives us the head from the tail on the first iteration) + auto block = this->tailBlock; + do { + block = block->next; + if (block->ConcurrentQueue::Block::template is_empty()) { + continue; + } + + size_t i = 0; // Offset into block + if (block == halfDequeuedBlock) { + i = static_cast(this->headIndex.load(std::memory_order_relaxed) & static_cast(BLOCK_SIZE - 1)); + } + + // Walk through all the items in the block; if this is the tail block, we need to stop when we reach the tail index + auto lastValidIndex = (this->tailIndex.load(std::memory_order_relaxed) & static_cast(BLOCK_SIZE - 1)) == 0 ? BLOCK_SIZE : static_cast(this->tailIndex.load(std::memory_order_relaxed) & static_cast(BLOCK_SIZE - 1)); + while (i != BLOCK_SIZE && (block != this->tailBlock || i != lastValidIndex)) { + (*block)[i++]->~T(); + } + } while (block != this->tailBlock); + } + + // Destroy all blocks that we own + if (this->tailBlock != nullptr) { + auto block = this->tailBlock; + do { + auto nextBlock = block->next; + if (block->dynamicallyAllocated) { + destroy(block); + } + else { + this->parent->add_block_to_free_list(block); + } + block = nextBlock; + } while (block != this->tailBlock); + } + + // Destroy the block indices + auto header = static_cast(pr_blockIndexRaw); + while (header != nullptr) { + auto prev = static_cast(header->prev); + header->~BlockIndexHeader(); + (Traits::free)(header); + header = prev; + } + } + + template + inline bool enqueue(U&& element) + { + index_t currentTailIndex = this->tailIndex.load(std::memory_order_relaxed); + index_t newTailIndex = 1 + currentTailIndex; + if ((currentTailIndex & static_cast(BLOCK_SIZE - 1)) == 0) { + // We reached the end of a block, start a new one + auto startBlock = this->tailBlock; + auto originalBlockIndexSlotsUsed = pr_blockIndexSlotsUsed; + if (this->tailBlock != nullptr && this->tailBlock->next->ConcurrentQueue::Block::template is_empty()) { + // We can re-use the block ahead of us, it's empty! + this->tailBlock = this->tailBlock->next; + this->tailBlock->ConcurrentQueue::Block::template reset_empty(); + + // We'll put the block on the block index (guaranteed to be room since we're conceptually removing the + // last block from it first -- except instead of removing then adding, we can just overwrite). + // Note that there must be a valid block index here, since even if allocation failed in the ctor, + // it would have been re-attempted when adding the first block to the queue; since there is such + // a block, a block index must have been successfully allocated. + } + else { + // Whatever head value we see here is >= the last value we saw here (relatively), + // and <= its current value. Since we have the most recent tail, the head must be + // <= to it. + auto head = this->headIndex.load(std::memory_order_relaxed); + assert(!details::circular_less_than(currentTailIndex, head)); + if (!details::circular_less_than(head, currentTailIndex + BLOCK_SIZE) + || (MAX_SUBQUEUE_SIZE != details::const_numeric_max::value && (MAX_SUBQUEUE_SIZE == 0 || MAX_SUBQUEUE_SIZE - BLOCK_SIZE < currentTailIndex - head))) { + // We can't enqueue in another block because there's not enough leeway -- the + // tail could surpass the head by the time the block fills up! (Or we'll exceed + // the size limit, if the second part of the condition was true.) + return false; + } + // We're going to need a new block; check that the block index has room + if (pr_blockIndexRaw == nullptr || pr_blockIndexSlotsUsed == pr_blockIndexSize) { + // Hmm, the circular block index is already full -- we'll need + // to allocate a new index. Note pr_blockIndexRaw can only be nullptr if + // the initial allocation failed in the constructor. + + if (allocMode == CannotAlloc || !new_block_index(pr_blockIndexSlotsUsed)) { + return false; + } + } + + // Insert a new block in the circular linked list + auto newBlock = this->parent->ConcurrentQueue::template requisition_block(); + if (newBlock == nullptr) { + return false; + } +#if MCDBGQ_TRACKMEM + newBlock->owner = this; +#endif + newBlock->ConcurrentQueue::Block::template reset_empty(); + if (this->tailBlock == nullptr) { + newBlock->next = newBlock; + } + else { + newBlock->next = this->tailBlock->next; + this->tailBlock->next = newBlock; + } + this->tailBlock = newBlock; + ++pr_blockIndexSlotsUsed; + } + + if (!MOODYCAMEL_NOEXCEPT_CTOR(T, U, new (nullptr) T(std::forward(element)))) { + // The constructor may throw. We want the element not to appear in the queue in + // that case (without corrupting the queue): + MOODYCAMEL_TRY { + new ((*this->tailBlock)[currentTailIndex]) T(std::forward(element)); + } + MOODYCAMEL_CATCH (...) { + // Revert change to the current block, but leave the new block available + // for next time + pr_blockIndexSlotsUsed = originalBlockIndexSlotsUsed; + this->tailBlock = startBlock == nullptr ? this->tailBlock : startBlock; + MOODYCAMEL_RETHROW; + } + } + else { + (void)startBlock; + (void)originalBlockIndexSlotsUsed; + } + + // Add block to block index + auto& entry = blockIndex.load(std::memory_order_relaxed)->entries[pr_blockIndexFront]; + entry.base = currentTailIndex; + entry.block = this->tailBlock; + blockIndex.load(std::memory_order_relaxed)->front.store(pr_blockIndexFront, std::memory_order_release); + pr_blockIndexFront = (pr_blockIndexFront + 1) & (pr_blockIndexSize - 1); + + if (!MOODYCAMEL_NOEXCEPT_CTOR(T, U, new (nullptr) T(std::forward(element)))) { + this->tailIndex.store(newTailIndex, std::memory_order_release); + return true; + } + } + + // Enqueue + new ((*this->tailBlock)[currentTailIndex]) T(std::forward(element)); + + this->tailIndex.store(newTailIndex, std::memory_order_release); + return true; + } + + template + bool dequeue(U& element) + { + auto tail = this->tailIndex.load(std::memory_order_relaxed); + auto overcommit = this->dequeueOvercommit.load(std::memory_order_relaxed); + if (details::circular_less_than(this->dequeueOptimisticCount.load(std::memory_order_relaxed) - overcommit, tail)) { + // Might be something to dequeue, let's give it a try + + // Note that this if is purely for performance purposes in the common case when the queue is + // empty and the values are eventually consistent -- we may enter here spuriously. + + // Note that whatever the values of overcommit and tail are, they are not going to change (unless we + // change them) and must be the same value at this point (inside the if) as when the if condition was + // evaluated. + + // We insert an acquire fence here to synchronize-with the release upon incrementing dequeueOvercommit below. + // This ensures that whatever the value we got loaded into overcommit, the load of dequeueOptisticCount in + // the fetch_add below will result in a value at least as recent as that (and therefore at least as large). + // Note that I believe a compiler (signal) fence here would be sufficient due to the nature of fetch_add (all + // read-modify-write operations are guaranteed to work on the latest value in the modification order), but + // unfortunately that can't be shown to be correct using only the C++11 standard. + // See http://stackoverflow.com/questions/18223161/what-are-the-c11-memory-ordering-guarantees-in-this-corner-case + std::atomic_thread_fence(std::memory_order_acquire); + + // Increment optimistic counter, then check if it went over the boundary + auto myDequeueCount = this->dequeueOptimisticCount.fetch_add(1, std::memory_order_relaxed); + + // Note that since dequeueOvercommit must be <= dequeueOptimisticCount (because dequeueOvercommit is only ever + // incremented after dequeueOptimisticCount -- this is enforced in the `else` block below), and since we now + // have a version of dequeueOptimisticCount that is at least as recent as overcommit (due to the release upon + // incrementing dequeueOvercommit and the acquire above that synchronizes with it), overcommit <= myDequeueCount. + // However, we can't assert this since both dequeueOptimisticCount and dequeueOvercommit may (independently) + // overflow; in such a case, though, the logic still holds since the difference between the two is maintained. + + // Note that we reload tail here in case it changed; it will be the same value as before or greater, since + // this load is sequenced after (happens after) the earlier load above. This is supported by read-read + // coherency (as defined in the standard), explained here: http://en.cppreference.com/w/cpp/atomic/memory_order + tail = this->tailIndex.load(std::memory_order_acquire); + if ((details::likely)(details::circular_less_than(myDequeueCount - overcommit, tail))) { + // Guaranteed to be at least one element to dequeue! + + // Get the index. Note that since there's guaranteed to be at least one element, this + // will never exceed tail. We need to do an acquire-release fence here since it's possible + // that whatever condition got us to this point was for an earlier enqueued element (that + // we already see the memory effects for), but that by the time we increment somebody else + // has incremented it, and we need to see the memory effects for *that* element, which is + // in such a case is necessarily visible on the thread that incremented it in the first + // place with the more current condition (they must have acquired a tail that is at least + // as recent). + auto index = this->headIndex.fetch_add(1, std::memory_order_acq_rel); + + + // Determine which block the element is in + + auto localBlockIndex = blockIndex.load(std::memory_order_acquire); + auto localBlockIndexHead = localBlockIndex->front.load(std::memory_order_acquire); + + // We need to be careful here about subtracting and dividing because of index wrap-around. + // When an index wraps, we need to preserve the sign of the offset when dividing it by the + // block size (in order to get a correct signed block count offset in all cases): + auto headBase = localBlockIndex->entries[localBlockIndexHead].base; + auto blockBaseIndex = index & ~static_cast(BLOCK_SIZE - 1); + auto offset = static_cast(static_cast::type>(blockBaseIndex - headBase) / BLOCK_SIZE); + auto block = localBlockIndex->entries[(localBlockIndexHead + offset) & (localBlockIndex->size - 1)].block; + + // Dequeue + auto& el = *((*block)[index]); + if (!MOODYCAMEL_NOEXCEPT_ASSIGN(T, T&&, element = std::move(el))) { + // Make sure the element is still fully dequeued and destroyed even if the assignment + // throws + struct Guard { + Block* block; + index_t index; + + ~Guard() + { + (*block)[index]->~T(); + block->ConcurrentQueue::Block::template set_empty(index); + } + } guard = { block, index }; + + element = std::move(el); + } + else { + element = std::move(el); + el.~T(); + block->ConcurrentQueue::Block::template set_empty(index); + } + + return true; + } + else { + // Wasn't anything to dequeue after all; make the effective dequeue count eventually consistent + this->dequeueOvercommit.fetch_add(1, std::memory_order_release); // Release so that the fetch_add on dequeueOptimisticCount is guaranteed to happen before this write + } + } + + return false; + } + + template + bool enqueue_bulk(It itemFirst, size_t count) + { + // First, we need to make sure we have enough room to enqueue all of the elements; + // this means pre-allocating blocks and putting them in the block index (but only if + // all the allocations succeeded). + index_t startTailIndex = this->tailIndex.load(std::memory_order_relaxed); + auto startBlock = this->tailBlock; + auto originalBlockIndexFront = pr_blockIndexFront; + auto originalBlockIndexSlotsUsed = pr_blockIndexSlotsUsed; + + Block* firstAllocatedBlock = nullptr; + + // Figure out how many blocks we'll need to allocate, and do so + size_t blockBaseDiff = ((startTailIndex + count - 1) & ~static_cast(BLOCK_SIZE - 1)) - ((startTailIndex - 1) & ~static_cast(BLOCK_SIZE - 1)); + index_t currentTailIndex = (startTailIndex - 1) & ~static_cast(BLOCK_SIZE - 1); + if (blockBaseDiff > 0) { + // Allocate as many blocks as possible from ahead + while (blockBaseDiff > 0 && this->tailBlock != nullptr && this->tailBlock->next != firstAllocatedBlock && this->tailBlock->next->ConcurrentQueue::Block::template is_empty()) { + blockBaseDiff -= static_cast(BLOCK_SIZE); + currentTailIndex += static_cast(BLOCK_SIZE); + + this->tailBlock = this->tailBlock->next; + firstAllocatedBlock = firstAllocatedBlock == nullptr ? this->tailBlock : firstAllocatedBlock; + + auto& entry = blockIndex.load(std::memory_order_relaxed)->entries[pr_blockIndexFront]; + entry.base = currentTailIndex; + entry.block = this->tailBlock; + pr_blockIndexFront = (pr_blockIndexFront + 1) & (pr_blockIndexSize - 1); + } + + // Now allocate as many blocks as necessary from the block pool + while (blockBaseDiff > 0) { + blockBaseDiff -= static_cast(BLOCK_SIZE); + currentTailIndex += static_cast(BLOCK_SIZE); + + auto head = this->headIndex.load(std::memory_order_relaxed); + assert(!details::circular_less_than(currentTailIndex, head)); + bool full = !details::circular_less_than(head, currentTailIndex + BLOCK_SIZE) || (MAX_SUBQUEUE_SIZE != details::const_numeric_max::value && (MAX_SUBQUEUE_SIZE == 0 || MAX_SUBQUEUE_SIZE - BLOCK_SIZE < currentTailIndex - head)); + if (pr_blockIndexRaw == nullptr || pr_blockIndexSlotsUsed == pr_blockIndexSize || full) { + if (allocMode == CannotAlloc || full || !new_block_index(originalBlockIndexSlotsUsed)) { + // Failed to allocate, undo changes (but keep injected blocks) + pr_blockIndexFront = originalBlockIndexFront; + pr_blockIndexSlotsUsed = originalBlockIndexSlotsUsed; + this->tailBlock = startBlock == nullptr ? firstAllocatedBlock : startBlock; + return false; + } + + // pr_blockIndexFront is updated inside new_block_index, so we need to + // update our fallback value too (since we keep the new index even if we + // later fail) + originalBlockIndexFront = originalBlockIndexSlotsUsed; + } + + // Insert a new block in the circular linked list + auto newBlock = this->parent->ConcurrentQueue::template requisition_block(); + if (newBlock == nullptr) { + pr_blockIndexFront = originalBlockIndexFront; + pr_blockIndexSlotsUsed = originalBlockIndexSlotsUsed; + this->tailBlock = startBlock == nullptr ? firstAllocatedBlock : startBlock; + return false; + } + +#if MCDBGQ_TRACKMEM + newBlock->owner = this; +#endif + newBlock->ConcurrentQueue::Block::template set_all_empty(); + if (this->tailBlock == nullptr) { + newBlock->next = newBlock; + } + else { + newBlock->next = this->tailBlock->next; + this->tailBlock->next = newBlock; + } + this->tailBlock = newBlock; + firstAllocatedBlock = firstAllocatedBlock == nullptr ? this->tailBlock : firstAllocatedBlock; + + ++pr_blockIndexSlotsUsed; + + auto& entry = blockIndex.load(std::memory_order_relaxed)->entries[pr_blockIndexFront]; + entry.base = currentTailIndex; + entry.block = this->tailBlock; + pr_blockIndexFront = (pr_blockIndexFront + 1) & (pr_blockIndexSize - 1); + } + + // Excellent, all allocations succeeded. Reset each block's emptiness before we fill them up, and + // publish the new block index front + auto block = firstAllocatedBlock; + while (true) { + block->ConcurrentQueue::Block::template reset_empty(); + if (block == this->tailBlock) { + break; + } + block = block->next; + } + + if (MOODYCAMEL_NOEXCEPT_CTOR(T, decltype(*itemFirst), new (nullptr) T(details::deref_noexcept(itemFirst)))) { + blockIndex.load(std::memory_order_relaxed)->front.store((pr_blockIndexFront - 1) & (pr_blockIndexSize - 1), std::memory_order_release); + } + } + + // Enqueue, one block at a time + index_t newTailIndex = startTailIndex + static_cast(count); + currentTailIndex = startTailIndex; + auto endBlock = this->tailBlock; + this->tailBlock = startBlock; + assert((startTailIndex & static_cast(BLOCK_SIZE - 1)) != 0 || firstAllocatedBlock != nullptr || count == 0); + if ((startTailIndex & static_cast(BLOCK_SIZE - 1)) == 0 && firstAllocatedBlock != nullptr) { + this->tailBlock = firstAllocatedBlock; + } + while (true) { + auto stopIndex = (currentTailIndex & ~static_cast(BLOCK_SIZE - 1)) + static_cast(BLOCK_SIZE); + if (details::circular_less_than(newTailIndex, stopIndex)) { + stopIndex = newTailIndex; + } + if (MOODYCAMEL_NOEXCEPT_CTOR(T, decltype(*itemFirst), new (nullptr) T(details::deref_noexcept(itemFirst)))) { + while (currentTailIndex != stopIndex) { + new ((*this->tailBlock)[currentTailIndex++]) T(*itemFirst++); + } + } + else { + MOODYCAMEL_TRY { + while (currentTailIndex != stopIndex) { + // Must use copy constructor even if move constructor is available + // because we may have to revert if there's an exception. + // Sorry about the horrible templated next line, but it was the only way + // to disable moving *at compile time*, which is important because a type + // may only define a (noexcept) move constructor, and so calls to the + // cctor will not compile, even if they are in an if branch that will never + // be executed + new ((*this->tailBlock)[currentTailIndex]) T(details::nomove_if<(bool)!MOODYCAMEL_NOEXCEPT_CTOR(T, decltype(*itemFirst), new (nullptr) T(details::deref_noexcept(itemFirst)))>::eval(*itemFirst)); + ++currentTailIndex; + ++itemFirst; + } + } + MOODYCAMEL_CATCH (...) { + // Oh dear, an exception's been thrown -- destroy the elements that + // were enqueued so far and revert the entire bulk operation (we'll keep + // any allocated blocks in our linked list for later, though). + auto constructedStopIndex = currentTailIndex; + auto lastBlockEnqueued = this->tailBlock; + + pr_blockIndexFront = originalBlockIndexFront; + pr_blockIndexSlotsUsed = originalBlockIndexSlotsUsed; + this->tailBlock = startBlock == nullptr ? firstAllocatedBlock : startBlock; + + if (!details::is_trivially_destructible::value) { + auto block = startBlock; + if ((startTailIndex & static_cast(BLOCK_SIZE - 1)) == 0) { + block = firstAllocatedBlock; + } + currentTailIndex = startTailIndex; + while (true) { + stopIndex = (currentTailIndex & ~static_cast(BLOCK_SIZE - 1)) + static_cast(BLOCK_SIZE); + if (details::circular_less_than(constructedStopIndex, stopIndex)) { + stopIndex = constructedStopIndex; + } + while (currentTailIndex != stopIndex) { + (*block)[currentTailIndex++]->~T(); + } + if (block == lastBlockEnqueued) { + break; + } + block = block->next; + } + } + MOODYCAMEL_RETHROW; + } + } + + if (this->tailBlock == endBlock) { + assert(currentTailIndex == newTailIndex); + break; + } + this->tailBlock = this->tailBlock->next; + } + + if (!MOODYCAMEL_NOEXCEPT_CTOR(T, decltype(*itemFirst), new (nullptr) T(details::deref_noexcept(itemFirst))) && firstAllocatedBlock != nullptr) { + blockIndex.load(std::memory_order_relaxed)->front.store((pr_blockIndexFront - 1) & (pr_blockIndexSize - 1), std::memory_order_release); + } + + this->tailIndex.store(newTailIndex, std::memory_order_release); + return true; + } + + template + size_t dequeue_bulk(It& itemFirst, size_t max) + { + auto tail = this->tailIndex.load(std::memory_order_relaxed); + auto overcommit = this->dequeueOvercommit.load(std::memory_order_relaxed); + auto desiredCount = static_cast(tail - (this->dequeueOptimisticCount.load(std::memory_order_relaxed) - overcommit)); + if (details::circular_less_than(0, desiredCount)) { + desiredCount = desiredCount < max ? desiredCount : max; + std::atomic_thread_fence(std::memory_order_acquire); + + auto myDequeueCount = this->dequeueOptimisticCount.fetch_add(desiredCount, std::memory_order_relaxed);; + + tail = this->tailIndex.load(std::memory_order_acquire); + auto actualCount = static_cast(tail - (myDequeueCount - overcommit)); + if (details::circular_less_than(0, actualCount)) { + actualCount = desiredCount < actualCount ? desiredCount : actualCount; + if (actualCount < desiredCount) { + this->dequeueOvercommit.fetch_add(desiredCount - actualCount, std::memory_order_release); + } + + // Get the first index. Note that since there's guaranteed to be at least actualCount elements, this + // will never exceed tail. + auto firstIndex = this->headIndex.fetch_add(actualCount, std::memory_order_acq_rel); + + // Determine which block the first element is in + auto localBlockIndex = blockIndex.load(std::memory_order_acquire); + auto localBlockIndexHead = localBlockIndex->front.load(std::memory_order_acquire); + + auto headBase = localBlockIndex->entries[localBlockIndexHead].base; + auto firstBlockBaseIndex = firstIndex & ~static_cast(BLOCK_SIZE - 1); + auto offset = static_cast(static_cast::type>(firstBlockBaseIndex - headBase) / BLOCK_SIZE); + auto indexIndex = (localBlockIndexHead + offset) & (localBlockIndex->size - 1); + + // Iterate the blocks and dequeue + auto index = firstIndex; + do { + auto firstIndexInBlock = index; + auto endIndex = (index & ~static_cast(BLOCK_SIZE - 1)) + static_cast(BLOCK_SIZE); + endIndex = details::circular_less_than(firstIndex + static_cast(actualCount), endIndex) ? firstIndex + static_cast(actualCount) : endIndex; + auto block = localBlockIndex->entries[indexIndex].block; + if (MOODYCAMEL_NOEXCEPT_ASSIGN(T, T&&, details::deref_noexcept(itemFirst) = std::move((*(*block)[index])))) { + while (index != endIndex) { + auto& el = *((*block)[index]); + *itemFirst++ = std::move(el); + el.~T(); + ++index; + } + } + else { + MOODYCAMEL_TRY { + while (index != endIndex) { + auto& el = *((*block)[index]); + *itemFirst = std::move(el); + ++itemFirst; + el.~T(); + ++index; + } + } + MOODYCAMEL_CATCH (...) { + // It's too late to revert the dequeue, but we can make sure that all + // the dequeued objects are properly destroyed and the block index + // (and empty count) are properly updated before we propagate the exception + do { + block = localBlockIndex->entries[indexIndex].block; + while (index != endIndex) { + (*block)[index++]->~T(); + } + block->ConcurrentQueue::Block::template set_many_empty(firstIndexInBlock, static_cast(endIndex - firstIndexInBlock)); + indexIndex = (indexIndex + 1) & (localBlockIndex->size - 1); + + firstIndexInBlock = index; + endIndex = (index & ~static_cast(BLOCK_SIZE - 1)) + static_cast(BLOCK_SIZE); + endIndex = details::circular_less_than(firstIndex + static_cast(actualCount), endIndex) ? firstIndex + static_cast(actualCount) : endIndex; + } while (index != firstIndex + actualCount); + + MOODYCAMEL_RETHROW; + } + } + block->ConcurrentQueue::Block::template set_many_empty(firstIndexInBlock, static_cast(endIndex - firstIndexInBlock)); + indexIndex = (indexIndex + 1) & (localBlockIndex->size - 1); + } while (index != firstIndex + actualCount); + + return actualCount; + } + else { + // Wasn't anything to dequeue after all; make the effective dequeue count eventually consistent + this->dequeueOvercommit.fetch_add(desiredCount, std::memory_order_release); + } + } + + return 0; + } + + private: + struct BlockIndexEntry + { + index_t base; + Block* block; + }; + + struct BlockIndexHeader + { + size_t size; + std::atomic front; // Current slot (not next, like pr_blockIndexFront) + BlockIndexEntry* entries; + void* prev; + }; + + + bool new_block_index(size_t numberOfFilledSlotsToExpose) + { + auto prevBlockSizeMask = pr_blockIndexSize - 1; + + // Create the new block + pr_blockIndexSize <<= 1; + auto newRawPtr = static_cast((Traits::malloc)(sizeof(BlockIndexHeader) + std::alignment_of::value - 1 + sizeof(BlockIndexEntry) * pr_blockIndexSize)); + if (newRawPtr == nullptr) { + pr_blockIndexSize >>= 1; // Reset to allow graceful retry + return false; + } + + auto newBlockIndexEntries = reinterpret_cast(details::align_for(newRawPtr + sizeof(BlockIndexHeader))); + + // Copy in all the old indices, if any + size_t j = 0; + if (pr_blockIndexSlotsUsed != 0) { + auto i = (pr_blockIndexFront - pr_blockIndexSlotsUsed) & prevBlockSizeMask; + do { + newBlockIndexEntries[j++] = pr_blockIndexEntries[i]; + i = (i + 1) & prevBlockSizeMask; + } while (i != pr_blockIndexFront); + } + + // Update everything + auto header = new (newRawPtr) BlockIndexHeader; + header->size = pr_blockIndexSize; + header->front.store(numberOfFilledSlotsToExpose - 1, std::memory_order_relaxed); + header->entries = newBlockIndexEntries; + header->prev = pr_blockIndexRaw; // we link the new block to the old one so we can free it later + + pr_blockIndexFront = j; + pr_blockIndexEntries = newBlockIndexEntries; + pr_blockIndexRaw = newRawPtr; + blockIndex.store(header, std::memory_order_release); + + return true; + } + + private: + std::atomic blockIndex; + + // To be used by producer only -- consumer must use the ones in referenced by blockIndex + size_t pr_blockIndexSlotsUsed; + size_t pr_blockIndexSize; + size_t pr_blockIndexFront; // Next slot (not current) + BlockIndexEntry* pr_blockIndexEntries; + void* pr_blockIndexRaw; + +#ifdef MOODYCAMEL_QUEUE_INTERNAL_DEBUG + public: + ExplicitProducer* nextExplicitProducer; + private: +#endif + +#if MCDBGQ_TRACKMEM + friend struct MemStats; +#endif + }; + + + ////////////////////////////////// + // Implicit queue + ////////////////////////////////// + + struct ImplicitProducer : public ProducerBase + { + ImplicitProducer(ConcurrentQueue* parent) : + ProducerBase(parent, false), + nextBlockIndexCapacity(IMPLICIT_INITIAL_INDEX_SIZE), + blockIndex(nullptr) + { + new_block_index(); + } + + ~ImplicitProducer() + { + // Note that since we're in the destructor we can assume that all enqueue/dequeue operations + // completed already; this means that all undequeued elements are placed contiguously across + // contiguous blocks, and that only the first and last remaining blocks can be only partially + // empty (all other remaining blocks must be completely full). + +#ifdef MOODYCAMEL_CPP11_THREAD_LOCAL_SUPPORTED + // Unregister ourselves for thread termination notification + if (!this->inactive.load(std::memory_order_relaxed)) { + details::ThreadExitNotifier::unsubscribe(&threadExitListener); + } +#endif + + // Destroy all remaining elements! + auto tail = this->tailIndex.load(std::memory_order_relaxed); + auto index = this->headIndex.load(std::memory_order_relaxed); + Block* block = nullptr; + assert(index == tail || details::circular_less_than(index, tail)); + bool forceFreeLastBlock = index != tail; // If we enter the loop, then the last (tail) block will not be freed + while (index != tail) { + if ((index & static_cast(BLOCK_SIZE - 1)) == 0 || block == nullptr) { + if (block != nullptr) { + // Free the old block + this->parent->add_block_to_free_list(block); + } + + block = get_block_index_entry_for_index(index)->value.load(std::memory_order_relaxed); + } + + ((*block)[index])->~T(); + ++index; + } + // Even if the queue is empty, there's still one block that's not on the free list + // (unless the head index reached the end of it, in which case the tail will be poised + // to create a new block). + if (this->tailBlock != nullptr && (forceFreeLastBlock || (tail & static_cast(BLOCK_SIZE - 1)) != 0)) { + this->parent->add_block_to_free_list(this->tailBlock); + } + + // Destroy block index + auto localBlockIndex = blockIndex.load(std::memory_order_relaxed); + if (localBlockIndex != nullptr) { + for (size_t i = 0; i != localBlockIndex->capacity; ++i) { + localBlockIndex->index[i]->~BlockIndexEntry(); + } + do { + auto prev = localBlockIndex->prev; + localBlockIndex->~BlockIndexHeader(); + (Traits::free)(localBlockIndex); + localBlockIndex = prev; + } while (localBlockIndex != nullptr); + } + } + + template + inline bool enqueue(U&& element) + { + index_t currentTailIndex = this->tailIndex.load(std::memory_order_relaxed); + index_t newTailIndex = 1 + currentTailIndex; + if ((currentTailIndex & static_cast(BLOCK_SIZE - 1)) == 0) { + // We reached the end of a block, start a new one + auto head = this->headIndex.load(std::memory_order_relaxed); + assert(!details::circular_less_than(currentTailIndex, head)); + if (!details::circular_less_than(head, currentTailIndex + BLOCK_SIZE) || (MAX_SUBQUEUE_SIZE != details::const_numeric_max::value && (MAX_SUBQUEUE_SIZE == 0 || MAX_SUBQUEUE_SIZE - BLOCK_SIZE < currentTailIndex - head))) { + return false; + } +#if MCDBGQ_NOLOCKFREE_IMPLICITPRODBLOCKINDEX + debug::DebugLock lock(mutex); +#endif + // Find out where we'll be inserting this block in the block index + BlockIndexEntry* idxEntry; + if (!insert_block_index_entry(idxEntry, currentTailIndex)) { + return false; + } + + // Get ahold of a new block + auto newBlock = this->parent->ConcurrentQueue::template requisition_block(); + if (newBlock == nullptr) { + rewind_block_index_tail(); + idxEntry->value.store(nullptr, std::memory_order_relaxed); + return false; + } +#if MCDBGQ_TRACKMEM + newBlock->owner = this; +#endif + newBlock->ConcurrentQueue::Block::template reset_empty(); + + if (!MOODYCAMEL_NOEXCEPT_CTOR(T, U, new (nullptr) T(std::forward(element)))) { + // May throw, try to insert now before we publish the fact that we have this new block + MOODYCAMEL_TRY { + new ((*newBlock)[currentTailIndex]) T(std::forward(element)); + } + MOODYCAMEL_CATCH (...) { + rewind_block_index_tail(); + idxEntry->value.store(nullptr, std::memory_order_relaxed); + this->parent->add_block_to_free_list(newBlock); + MOODYCAMEL_RETHROW; + } + } + + // Insert the new block into the index + idxEntry->value.store(newBlock, std::memory_order_relaxed); + + this->tailBlock = newBlock; + + if (!MOODYCAMEL_NOEXCEPT_CTOR(T, U, new (nullptr) T(std::forward(element)))) { + this->tailIndex.store(newTailIndex, std::memory_order_release); + return true; + } + } + + // Enqueue + new ((*this->tailBlock)[currentTailIndex]) T(std::forward(element)); + + this->tailIndex.store(newTailIndex, std::memory_order_release); + return true; + } + + template + bool dequeue(U& element) + { + // See ExplicitProducer::dequeue for rationale and explanation + index_t tail = this->tailIndex.load(std::memory_order_relaxed); + index_t overcommit = this->dequeueOvercommit.load(std::memory_order_relaxed); + if (details::circular_less_than(this->dequeueOptimisticCount.load(std::memory_order_relaxed) - overcommit, tail)) { + std::atomic_thread_fence(std::memory_order_acquire); + + index_t myDequeueCount = this->dequeueOptimisticCount.fetch_add(1, std::memory_order_relaxed); + tail = this->tailIndex.load(std::memory_order_acquire); + if ((details::likely)(details::circular_less_than(myDequeueCount - overcommit, tail))) { + index_t index = this->headIndex.fetch_add(1, std::memory_order_acq_rel); + + // Determine which block the element is in + auto entry = get_block_index_entry_for_index(index); + + // Dequeue + auto block = entry->value.load(std::memory_order_relaxed); + auto& el = *((*block)[index]); + + if (!MOODYCAMEL_NOEXCEPT_ASSIGN(T, T&&, element = std::move(el))) { +#if MCDBGQ_NOLOCKFREE_IMPLICITPRODBLOCKINDEX + // Note: Acquiring the mutex with every dequeue instead of only when a block + // is released is very sub-optimal, but it is, after all, purely debug code. + debug::DebugLock lock(producer->mutex); +#endif + struct Guard { + Block* block; + index_t index; + BlockIndexEntry* entry; + ConcurrentQueue* parent; + + ~Guard() + { + (*block)[index]->~T(); + if (block->ConcurrentQueue::Block::template set_empty(index)) { + entry->value.store(nullptr, std::memory_order_relaxed); + parent->add_block_to_free_list(block); + } + } + } guard = { block, index, entry, this->parent }; + + element = std::move(el); + } + else { + element = std::move(el); + el.~T(); + + if (block->ConcurrentQueue::Block::template set_empty(index)) { + { +#if MCDBGQ_NOLOCKFREE_IMPLICITPRODBLOCKINDEX + debug::DebugLock lock(mutex); +#endif + // Add the block back into the global free pool (and remove from block index) + entry->value.store(nullptr, std::memory_order_relaxed); + } + this->parent->add_block_to_free_list(block); // releases the above store + } + } + + return true; + } + else { + this->dequeueOvercommit.fetch_add(1, std::memory_order_release); + } + } + + return false; + } + + template + bool enqueue_bulk(It itemFirst, size_t count) + { + // First, we need to make sure we have enough room to enqueue all of the elements; + // this means pre-allocating blocks and putting them in the block index (but only if + // all the allocations succeeded). + + // Note that the tailBlock we start off with may not be owned by us any more; + // this happens if it was filled up exactly to the top (setting tailIndex to + // the first index of the next block which is not yet allocated), then dequeued + // completely (putting it on the free list) before we enqueue again. + + index_t startTailIndex = this->tailIndex.load(std::memory_order_relaxed); + auto startBlock = this->tailBlock; + Block* firstAllocatedBlock = nullptr; + auto endBlock = this->tailBlock; + + // Figure out how many blocks we'll need to allocate, and do so + size_t blockBaseDiff = ((startTailIndex + count - 1) & ~static_cast(BLOCK_SIZE - 1)) - ((startTailIndex - 1) & ~static_cast(BLOCK_SIZE - 1)); + index_t currentTailIndex = (startTailIndex - 1) & ~static_cast(BLOCK_SIZE - 1); + if (blockBaseDiff > 0) { +#if MCDBGQ_NOLOCKFREE_IMPLICITPRODBLOCKINDEX + debug::DebugLock lock(mutex); +#endif + do { + blockBaseDiff -= static_cast(BLOCK_SIZE); + currentTailIndex += static_cast(BLOCK_SIZE); + + // Find out where we'll be inserting this block in the block index + BlockIndexEntry* idxEntry = nullptr; // initialization here unnecessary but compiler can't always tell + Block* newBlock; + bool indexInserted = false; + auto head = this->headIndex.load(std::memory_order_relaxed); + assert(!details::circular_less_than(currentTailIndex, head)); + bool full = !details::circular_less_than(head, currentTailIndex + BLOCK_SIZE) || (MAX_SUBQUEUE_SIZE != details::const_numeric_max::value && (MAX_SUBQUEUE_SIZE == 0 || MAX_SUBQUEUE_SIZE - BLOCK_SIZE < currentTailIndex - head)); + if (full || !(indexInserted = insert_block_index_entry(idxEntry, currentTailIndex)) || (newBlock = this->parent->ConcurrentQueue::template requisition_block()) == nullptr) { + // Index allocation or block allocation failed; revert any other allocations + // and index insertions done so far for this operation + if (indexInserted) { + rewind_block_index_tail(); + idxEntry->value.store(nullptr, std::memory_order_relaxed); + } + currentTailIndex = (startTailIndex - 1) & ~static_cast(BLOCK_SIZE - 1); + for (auto block = firstAllocatedBlock; block != nullptr; block = block->next) { + currentTailIndex += static_cast(BLOCK_SIZE); + idxEntry = get_block_index_entry_for_index(currentTailIndex); + idxEntry->value.store(nullptr, std::memory_order_relaxed); + rewind_block_index_tail(); + } + this->parent->add_blocks_to_free_list(firstAllocatedBlock); + this->tailBlock = startBlock; + + return false; + } + +#if MCDBGQ_TRACKMEM + newBlock->owner = this; +#endif + newBlock->ConcurrentQueue::Block::template reset_empty(); + newBlock->next = nullptr; + + // Insert the new block into the index + idxEntry->value.store(newBlock, std::memory_order_relaxed); + + // Store the chain of blocks so that we can undo if later allocations fail, + // and so that we can find the blocks when we do the actual enqueueing + if ((startTailIndex & static_cast(BLOCK_SIZE - 1)) != 0 || firstAllocatedBlock != nullptr) { + assert(this->tailBlock != nullptr); + this->tailBlock->next = newBlock; + } + this->tailBlock = newBlock; + endBlock = newBlock; + firstAllocatedBlock = firstAllocatedBlock == nullptr ? newBlock : firstAllocatedBlock; + } while (blockBaseDiff > 0); + } + + // Enqueue, one block at a time + index_t newTailIndex = startTailIndex + static_cast(count); + currentTailIndex = startTailIndex; + this->tailBlock = startBlock; + assert((startTailIndex & static_cast(BLOCK_SIZE - 1)) != 0 || firstAllocatedBlock != nullptr || count == 0); + if ((startTailIndex & static_cast(BLOCK_SIZE - 1)) == 0 && firstAllocatedBlock != nullptr) { + this->tailBlock = firstAllocatedBlock; + } + while (true) { + auto stopIndex = (currentTailIndex & ~static_cast(BLOCK_SIZE - 1)) + static_cast(BLOCK_SIZE); + if (details::circular_less_than(newTailIndex, stopIndex)) { + stopIndex = newTailIndex; + } + if (MOODYCAMEL_NOEXCEPT_CTOR(T, decltype(*itemFirst), new (nullptr) T(details::deref_noexcept(itemFirst)))) { + while (currentTailIndex != stopIndex) { + new ((*this->tailBlock)[currentTailIndex++]) T(*itemFirst++); + } + } + else { + MOODYCAMEL_TRY { + while (currentTailIndex != stopIndex) { + new ((*this->tailBlock)[currentTailIndex]) T(details::nomove_if<(bool)!MOODYCAMEL_NOEXCEPT_CTOR(T, decltype(*itemFirst), new (nullptr) T(details::deref_noexcept(itemFirst)))>::eval(*itemFirst)); + ++currentTailIndex; + ++itemFirst; + } + } + MOODYCAMEL_CATCH (...) { + auto constructedStopIndex = currentTailIndex; + auto lastBlockEnqueued = this->tailBlock; + + if (!details::is_trivially_destructible::value) { + auto block = startBlock; + if ((startTailIndex & static_cast(BLOCK_SIZE - 1)) == 0) { + block = firstAllocatedBlock; + } + currentTailIndex = startTailIndex; + while (true) { + stopIndex = (currentTailIndex & ~static_cast(BLOCK_SIZE - 1)) + static_cast(BLOCK_SIZE); + if (details::circular_less_than(constructedStopIndex, stopIndex)) { + stopIndex = constructedStopIndex; + } + while (currentTailIndex != stopIndex) { + (*block)[currentTailIndex++]->~T(); + } + if (block == lastBlockEnqueued) { + break; + } + block = block->next; + } + } + + currentTailIndex = (startTailIndex - 1) & ~static_cast(BLOCK_SIZE - 1); + for (auto block = firstAllocatedBlock; block != nullptr; block = block->next) { + currentTailIndex += static_cast(BLOCK_SIZE); + auto idxEntry = get_block_index_entry_for_index(currentTailIndex); + idxEntry->value.store(nullptr, std::memory_order_relaxed); + rewind_block_index_tail(); + } + this->parent->add_blocks_to_free_list(firstAllocatedBlock); + this->tailBlock = startBlock; + MOODYCAMEL_RETHROW; + } + } + + if (this->tailBlock == endBlock) { + assert(currentTailIndex == newTailIndex); + break; + } + this->tailBlock = this->tailBlock->next; + } + this->tailIndex.store(newTailIndex, std::memory_order_release); + return true; + } + + template + size_t dequeue_bulk(It& itemFirst, size_t max) + { + auto tail = this->tailIndex.load(std::memory_order_relaxed); + auto overcommit = this->dequeueOvercommit.load(std::memory_order_relaxed); + auto desiredCount = static_cast(tail - (this->dequeueOptimisticCount.load(std::memory_order_relaxed) - overcommit)); + if (details::circular_less_than(0, desiredCount)) { + desiredCount = desiredCount < max ? desiredCount : max; + std::atomic_thread_fence(std::memory_order_acquire); + + auto myDequeueCount = this->dequeueOptimisticCount.fetch_add(desiredCount, std::memory_order_relaxed); + + tail = this->tailIndex.load(std::memory_order_acquire); + auto actualCount = static_cast(tail - (myDequeueCount - overcommit)); + if (details::circular_less_than(0, actualCount)) { + actualCount = desiredCount < actualCount ? desiredCount : actualCount; + if (actualCount < desiredCount) { + this->dequeueOvercommit.fetch_add(desiredCount - actualCount, std::memory_order_release); + } + + // Get the first index. Note that since there's guaranteed to be at least actualCount elements, this + // will never exceed tail. + auto firstIndex = this->headIndex.fetch_add(actualCount, std::memory_order_acq_rel); + + // Iterate the blocks and dequeue + auto index = firstIndex; + BlockIndexHeader* localBlockIndex; + auto indexIndex = get_block_index_index_for_index(index, localBlockIndex); + do { + auto blockStartIndex = index; + auto endIndex = (index & ~static_cast(BLOCK_SIZE - 1)) + static_cast(BLOCK_SIZE); + endIndex = details::circular_less_than(firstIndex + static_cast(actualCount), endIndex) ? firstIndex + static_cast(actualCount) : endIndex; + + auto entry = localBlockIndex->index[indexIndex]; + auto block = entry->value.load(std::memory_order_relaxed); + if (MOODYCAMEL_NOEXCEPT_ASSIGN(T, T&&, details::deref_noexcept(itemFirst) = std::move((*(*block)[index])))) { + while (index != endIndex) { + auto& el = *((*block)[index]); + *itemFirst++ = std::move(el); + el.~T(); + ++index; + } + } + else { + MOODYCAMEL_TRY { + while (index != endIndex) { + auto& el = *((*block)[index]); + *itemFirst = std::move(el); + ++itemFirst; + el.~T(); + ++index; + } + } + MOODYCAMEL_CATCH (...) { + do { + entry = localBlockIndex->index[indexIndex]; + block = entry->value.load(std::memory_order_relaxed); + while (index != endIndex) { + (*block)[index++]->~T(); + } + + if (block->ConcurrentQueue::Block::template set_many_empty(blockStartIndex, static_cast(endIndex - blockStartIndex))) { +#if MCDBGQ_NOLOCKFREE_IMPLICITPRODBLOCKINDEX + debug::DebugLock lock(mutex); +#endif + entry->value.store(nullptr, std::memory_order_relaxed); + this->parent->add_block_to_free_list(block); + } + indexIndex = (indexIndex + 1) & (localBlockIndex->capacity - 1); + + blockStartIndex = index; + endIndex = (index & ~static_cast(BLOCK_SIZE - 1)) + static_cast(BLOCK_SIZE); + endIndex = details::circular_less_than(firstIndex + static_cast(actualCount), endIndex) ? firstIndex + static_cast(actualCount) : endIndex; + } while (index != firstIndex + actualCount); + + MOODYCAMEL_RETHROW; + } + } + if (block->ConcurrentQueue::Block::template set_many_empty(blockStartIndex, static_cast(endIndex - blockStartIndex))) { + { +#if MCDBGQ_NOLOCKFREE_IMPLICITPRODBLOCKINDEX + debug::DebugLock lock(mutex); +#endif + // Note that the set_many_empty above did a release, meaning that anybody who acquires the block + // we're about to free can use it safely since our writes (and reads!) will have happened-before then. + entry->value.store(nullptr, std::memory_order_relaxed); + } + this->parent->add_block_to_free_list(block); // releases the above store + } + indexIndex = (indexIndex + 1) & (localBlockIndex->capacity - 1); + } while (index != firstIndex + actualCount); + + return actualCount; + } + else { + this->dequeueOvercommit.fetch_add(desiredCount, std::memory_order_release); + } + } + + return 0; + } + + private: + // The block size must be > 1, so any number with the low bit set is an invalid block base index + static const index_t INVALID_BLOCK_BASE = 1; + + struct BlockIndexEntry + { + std::atomic key; + std::atomic value; + }; + + struct BlockIndexHeader + { + size_t capacity; + std::atomic tail; + BlockIndexEntry* entries; + BlockIndexEntry** index; + BlockIndexHeader* prev; + }; + + template + inline bool insert_block_index_entry(BlockIndexEntry*& idxEntry, index_t blockStartIndex) + { + auto localBlockIndex = blockIndex.load(std::memory_order_relaxed); // We're the only writer thread, relaxed is OK + if (localBlockIndex == nullptr) { + return false; // this can happen if new_block_index failed in the constructor + } + auto newTail = (localBlockIndex->tail.load(std::memory_order_relaxed) + 1) & (localBlockIndex->capacity - 1); + idxEntry = localBlockIndex->index[newTail]; + if (idxEntry->key.load(std::memory_order_relaxed) == INVALID_BLOCK_BASE || + idxEntry->value.load(std::memory_order_relaxed) == nullptr) { + + idxEntry->key.store(blockStartIndex, std::memory_order_relaxed); + localBlockIndex->tail.store(newTail, std::memory_order_release); + return true; + } + + // No room in the old block index, try to allocate another one! + if (allocMode == CannotAlloc || !new_block_index()) { + return false; + } + localBlockIndex = blockIndex.load(std::memory_order_relaxed); + newTail = (localBlockIndex->tail.load(std::memory_order_relaxed) + 1) & (localBlockIndex->capacity - 1); + idxEntry = localBlockIndex->index[newTail]; + assert(idxEntry->key.load(std::memory_order_relaxed) == INVALID_BLOCK_BASE); + idxEntry->key.store(blockStartIndex, std::memory_order_relaxed); + localBlockIndex->tail.store(newTail, std::memory_order_release); + return true; + } + + inline void rewind_block_index_tail() + { + auto localBlockIndex = blockIndex.load(std::memory_order_relaxed); + localBlockIndex->tail.store((localBlockIndex->tail.load(std::memory_order_relaxed) - 1) & (localBlockIndex->capacity - 1), std::memory_order_relaxed); + } + + inline BlockIndexEntry* get_block_index_entry_for_index(index_t index) const + { + BlockIndexHeader* localBlockIndex; + auto idx = get_block_index_index_for_index(index, localBlockIndex); + return localBlockIndex->index[idx]; + } + + inline size_t get_block_index_index_for_index(index_t index, BlockIndexHeader*& localBlockIndex) const + { +#if MCDBGQ_NOLOCKFREE_IMPLICITPRODBLOCKINDEX + debug::DebugLock lock(mutex); +#endif + index &= ~static_cast(BLOCK_SIZE - 1); + localBlockIndex = blockIndex.load(std::memory_order_acquire); + auto tail = localBlockIndex->tail.load(std::memory_order_acquire); + auto tailBase = localBlockIndex->index[tail]->key.load(std::memory_order_relaxed); + assert(tailBase != INVALID_BLOCK_BASE); + // Note: Must use division instead of shift because the index may wrap around, causing a negative + // offset, whose negativity we want to preserve + auto offset = static_cast(static_cast::type>(index - tailBase) / BLOCK_SIZE); + size_t idx = (tail + offset) & (localBlockIndex->capacity - 1); + assert(localBlockIndex->index[idx]->key.load(std::memory_order_relaxed) == index && localBlockIndex->index[idx]->value.load(std::memory_order_relaxed) != nullptr); + return idx; + } + + bool new_block_index() + { + auto prev = blockIndex.load(std::memory_order_relaxed); + size_t prevCapacity = prev == nullptr ? 0 : prev->capacity; + auto entryCount = prev == nullptr ? nextBlockIndexCapacity : prevCapacity; + auto raw = static_cast((Traits::malloc)( + sizeof(BlockIndexHeader) + + std::alignment_of::value - 1 + sizeof(BlockIndexEntry) * entryCount + + std::alignment_of::value - 1 + sizeof(BlockIndexEntry*) * nextBlockIndexCapacity)); + if (raw == nullptr) { + return false; + } + + auto header = new (raw) BlockIndexHeader; + auto entries = reinterpret_cast(details::align_for(raw + sizeof(BlockIndexHeader))); + auto index = reinterpret_cast(details::align_for(reinterpret_cast(entries) + sizeof(BlockIndexEntry) * entryCount)); + if (prev != nullptr) { + auto prevTail = prev->tail.load(std::memory_order_relaxed); + auto prevPos = prevTail; + size_t i = 0; + do { + prevPos = (prevPos + 1) & (prev->capacity - 1); + index[i++] = prev->index[prevPos]; + } while (prevPos != prevTail); + assert(i == prevCapacity); + } + for (size_t i = 0; i != entryCount; ++i) { + new (entries + i) BlockIndexEntry; + entries[i].key.store(INVALID_BLOCK_BASE, std::memory_order_relaxed); + index[prevCapacity + i] = entries + i; + } + header->prev = prev; + header->entries = entries; + header->index = index; + header->capacity = nextBlockIndexCapacity; + header->tail.store((prevCapacity - 1) & (nextBlockIndexCapacity - 1), std::memory_order_relaxed); + + blockIndex.store(header, std::memory_order_release); + + nextBlockIndexCapacity <<= 1; + + return true; + } + + private: + size_t nextBlockIndexCapacity; + std::atomic blockIndex; + +#ifdef MOODYCAMEL_CPP11_THREAD_LOCAL_SUPPORTED + public: + details::ThreadExitListener threadExitListener; + private: +#endif + +#ifdef MOODYCAMEL_QUEUE_INTERNAL_DEBUG + public: + ImplicitProducer* nextImplicitProducer; + private: +#endif + +#if MCDBGQ_NOLOCKFREE_IMPLICITPRODBLOCKINDEX + mutable debug::DebugMutex mutex; +#endif +#if MCDBGQ_TRACKMEM + friend struct MemStats; +#endif + }; + + + ////////////////////////////////// + // Block pool manipulation + ////////////////////////////////// + + void populate_initial_block_list(size_t blockCount) + { + initialBlockPoolSize = blockCount; + if (initialBlockPoolSize == 0) { + initialBlockPool = nullptr; + return; + } + + initialBlockPool = create_array(blockCount); + if (initialBlockPool == nullptr) { + initialBlockPoolSize = 0; + } + for (size_t i = 0; i < initialBlockPoolSize; ++i) { + initialBlockPool[i].dynamicallyAllocated = false; + } + } + + inline Block* try_get_block_from_initial_pool() + { + if (initialBlockPoolIndex.load(std::memory_order_relaxed) >= initialBlockPoolSize) { + return nullptr; + } + + auto index = initialBlockPoolIndex.fetch_add(1, std::memory_order_relaxed); + + return index < initialBlockPoolSize ? (initialBlockPool + index) : nullptr; + } + + inline void add_block_to_free_list(Block* block) + { +#if MCDBGQ_TRACKMEM + block->owner = nullptr; +#endif + freeList.add(block); + } + + inline void add_blocks_to_free_list(Block* block) + { + while (block != nullptr) { + auto next = block->next; + add_block_to_free_list(block); + block = next; + } + } + + inline Block* try_get_block_from_free_list() + { + return freeList.try_get(); + } + + // Gets a free block from one of the memory pools, or allocates a new one (if applicable) + template + Block* requisition_block() + { + auto block = try_get_block_from_initial_pool(); + if (block != nullptr) { + return block; + } + + block = try_get_block_from_free_list(); + if (block != nullptr) { + return block; + } + + if (canAlloc == CanAlloc) { + return create(); + } + + return nullptr; + } + + +#if MCDBGQ_TRACKMEM + public: + struct MemStats { + size_t allocatedBlocks; + size_t usedBlocks; + size_t freeBlocks; + size_t ownedBlocksExplicit; + size_t ownedBlocksImplicit; + size_t implicitProducers; + size_t explicitProducers; + size_t elementsEnqueued; + size_t blockClassBytes; + size_t queueClassBytes; + size_t implicitBlockIndexBytes; + size_t explicitBlockIndexBytes; + + friend class ConcurrentQueue; + + private: + static MemStats getFor(ConcurrentQueue* q) + { + MemStats stats = { 0 }; + + stats.elementsEnqueued = q->size_approx(); + + auto block = q->freeList.head_unsafe(); + while (block != nullptr) { + ++stats.allocatedBlocks; + ++stats.freeBlocks; + block = block->freeListNext.load(std::memory_order_relaxed); + } + + for (auto ptr = q->producerListTail.load(std::memory_order_acquire); ptr != nullptr; ptr = ptr->next_prod()) { + bool implicit = dynamic_cast(ptr) != nullptr; + stats.implicitProducers += implicit ? 1 : 0; + stats.explicitProducers += implicit ? 0 : 1; + + if (implicit) { + auto prod = static_cast(ptr); + stats.queueClassBytes += sizeof(ImplicitProducer); + auto head = prod->headIndex.load(std::memory_order_relaxed); + auto tail = prod->tailIndex.load(std::memory_order_relaxed); + auto hash = prod->blockIndex.load(std::memory_order_relaxed); + if (hash != nullptr) { + for (size_t i = 0; i != hash->capacity; ++i) { + if (hash->index[i]->key.load(std::memory_order_relaxed) != ImplicitProducer::INVALID_BLOCK_BASE && hash->index[i]->value.load(std::memory_order_relaxed) != nullptr) { + ++stats.allocatedBlocks; + ++stats.ownedBlocksImplicit; + } + } + stats.implicitBlockIndexBytes += hash->capacity * sizeof(typename ImplicitProducer::BlockIndexEntry); + for (; hash != nullptr; hash = hash->prev) { + stats.implicitBlockIndexBytes += sizeof(typename ImplicitProducer::BlockIndexHeader) + hash->capacity * sizeof(typename ImplicitProducer::BlockIndexEntry*); + } + } + for (; details::circular_less_than(head, tail); head += BLOCK_SIZE) { + //auto block = prod->get_block_index_entry_for_index(head); + ++stats.usedBlocks; + } + } + else { + auto prod = static_cast(ptr); + stats.queueClassBytes += sizeof(ExplicitProducer); + auto tailBlock = prod->tailBlock; + bool wasNonEmpty = false; + if (tailBlock != nullptr) { + auto block = tailBlock; + do { + ++stats.allocatedBlocks; + if (!block->ConcurrentQueue::Block::template is_empty() || wasNonEmpty) { + ++stats.usedBlocks; + wasNonEmpty = wasNonEmpty || block != tailBlock; + } + ++stats.ownedBlocksExplicit; + block = block->next; + } while (block != tailBlock); + } + auto index = prod->blockIndex.load(std::memory_order_relaxed); + while (index != nullptr) { + stats.explicitBlockIndexBytes += sizeof(typename ExplicitProducer::BlockIndexHeader) + index->size * sizeof(typename ExplicitProducer::BlockIndexEntry); + index = static_cast(index->prev); + } + } + } + + auto freeOnInitialPool = q->initialBlockPoolIndex.load(std::memory_order_relaxed) >= q->initialBlockPoolSize ? 0 : q->initialBlockPoolSize - q->initialBlockPoolIndex.load(std::memory_order_relaxed); + stats.allocatedBlocks += freeOnInitialPool; + stats.freeBlocks += freeOnInitialPool; + + stats.blockClassBytes = sizeof(Block) * stats.allocatedBlocks; + stats.queueClassBytes += sizeof(ConcurrentQueue); + + return stats; + } + }; + + // For debugging only. Not thread-safe. + MemStats getMemStats() + { + return MemStats::getFor(this); + } + private: + friend struct MemStats; +#endif + + + ////////////////////////////////// + // Producer list manipulation + ////////////////////////////////// + + ProducerBase* recycle_or_create_producer(bool isExplicit) + { + bool recycled; + return recycle_or_create_producer(isExplicit, recycled); + } + + ProducerBase* recycle_or_create_producer(bool isExplicit, bool& recycled) + { +#if MCDBGQ_NOLOCKFREE_IMPLICITPRODHASH + debug::DebugLock lock(implicitProdMutex); +#endif + // Try to re-use one first + for (auto ptr = producerListTail.load(std::memory_order_acquire); ptr != nullptr; ptr = ptr->next_prod()) { + if (ptr->inactive.load(std::memory_order_relaxed) && ptr->isExplicit == isExplicit) { + bool expected = true; + if (ptr->inactive.compare_exchange_strong(expected, /* desired */ false, std::memory_order_acquire, std::memory_order_relaxed)) { + // We caught one! It's been marked as activated, the caller can have it + recycled = true; + return ptr; + } + } + } + + recycled = false; + return add_producer(isExplicit ? static_cast(create(this)) : create(this)); + } + + ProducerBase* add_producer(ProducerBase* producer) + { + // Handle failed memory allocation + if (producer == nullptr) { + return nullptr; + } + + producerCount.fetch_add(1, std::memory_order_relaxed); + + // Add it to the lock-free list + auto prevTail = producerListTail.load(std::memory_order_relaxed); + do { + producer->next = prevTail; + } while (!producerListTail.compare_exchange_weak(prevTail, producer, std::memory_order_release, std::memory_order_relaxed)); + +#ifdef MOODYCAMEL_QUEUE_INTERNAL_DEBUG + if (producer->isExplicit) { + auto prevTailExplicit = explicitProducers.load(std::memory_order_relaxed); + do { + static_cast(producer)->nextExplicitProducer = prevTailExplicit; + } while (!explicitProducers.compare_exchange_weak(prevTailExplicit, static_cast(producer), std::memory_order_release, std::memory_order_relaxed)); + } + else { + auto prevTailImplicit = implicitProducers.load(std::memory_order_relaxed); + do { + static_cast(producer)->nextImplicitProducer = prevTailImplicit; + } while (!implicitProducers.compare_exchange_weak(prevTailImplicit, static_cast(producer), std::memory_order_release, std::memory_order_relaxed)); + } +#endif + + return producer; + } + + void reown_producers() + { + // After another instance is moved-into/swapped-with this one, all the + // producers we stole still think their parents are the other queue. + // So fix them up! + for (auto ptr = producerListTail.load(std::memory_order_relaxed); ptr != nullptr; ptr = ptr->next_prod()) { + ptr->parent = this; + } + } + + + ////////////////////////////////// + // Implicit producer hash + ////////////////////////////////// + + struct ImplicitProducerKVP + { + std::atomic key; + ImplicitProducer* value; // No need for atomicity since it's only read by the thread that sets it in the first place + + ImplicitProducerKVP() : value(nullptr) { } + + ImplicitProducerKVP(ImplicitProducerKVP&& other) MOODYCAMEL_NOEXCEPT + { + key.store(other.key.load(std::memory_order_relaxed), std::memory_order_relaxed); + value = other.value; + } + + inline ImplicitProducerKVP& operator=(ImplicitProducerKVP&& other) MOODYCAMEL_NOEXCEPT + { + swap(other); + return *this; + } + + inline void swap(ImplicitProducerKVP& other) MOODYCAMEL_NOEXCEPT + { + if (this != &other) { + details::swap_relaxed(key, other.key); + std::swap(value, other.value); + } + } + }; + + template + friend void moodycamel::swap(typename ConcurrentQueue::ImplicitProducerKVP&, typename ConcurrentQueue::ImplicitProducerKVP&) MOODYCAMEL_NOEXCEPT; + + struct ImplicitProducerHash + { + size_t capacity; + ImplicitProducerKVP* entries; + ImplicitProducerHash* prev; + }; + + inline void populate_initial_implicit_producer_hash() + { + if (INITIAL_IMPLICIT_PRODUCER_HASH_SIZE == 0) return; + + implicitProducerHashCount.store(0, std::memory_order_relaxed); + auto hash = &initialImplicitProducerHash; + hash->capacity = INITIAL_IMPLICIT_PRODUCER_HASH_SIZE; + hash->entries = &initialImplicitProducerHashEntries[0]; + for (size_t i = 0; i != INITIAL_IMPLICIT_PRODUCER_HASH_SIZE; ++i) { + initialImplicitProducerHashEntries[i].key.store(details::invalid_thread_id, std::memory_order_relaxed); + } + hash->prev = nullptr; + implicitProducerHash.store(hash, std::memory_order_relaxed); + } + + void swap_implicit_producer_hashes(ConcurrentQueue& other) + { + if (INITIAL_IMPLICIT_PRODUCER_HASH_SIZE == 0) return; + + // Swap (assumes our implicit producer hash is initialized) + initialImplicitProducerHashEntries.swap(other.initialImplicitProducerHashEntries); + initialImplicitProducerHash.entries = &initialImplicitProducerHashEntries[0]; + other.initialImplicitProducerHash.entries = &other.initialImplicitProducerHashEntries[0]; + + details::swap_relaxed(implicitProducerHashCount, other.implicitProducerHashCount); + + details::swap_relaxed(implicitProducerHash, other.implicitProducerHash); + if (implicitProducerHash.load(std::memory_order_relaxed) == &other.initialImplicitProducerHash) { + implicitProducerHash.store(&initialImplicitProducerHash, std::memory_order_relaxed); + } + else { + ImplicitProducerHash* hash; + for (hash = implicitProducerHash.load(std::memory_order_relaxed); hash->prev != &other.initialImplicitProducerHash; hash = hash->prev) { + continue; + } + hash->prev = &initialImplicitProducerHash; + } + if (other.implicitProducerHash.load(std::memory_order_relaxed) == &initialImplicitProducerHash) { + other.implicitProducerHash.store(&other.initialImplicitProducerHash, std::memory_order_relaxed); + } + else { + ImplicitProducerHash* hash; + for (hash = other.implicitProducerHash.load(std::memory_order_relaxed); hash->prev != &initialImplicitProducerHash; hash = hash->prev) { + continue; + } + hash->prev = &other.initialImplicitProducerHash; + } + } + + // Only fails (returns nullptr) if memory allocation fails + ImplicitProducer* get_or_add_implicit_producer() + { + // Note that since the data is essentially thread-local (key is thread ID), + // there's a reduced need for fences (memory ordering is already consistent + // for any individual thread), except for the current table itself. + + // Start by looking for the thread ID in the current and all previous hash tables. + // If it's not found, it must not be in there yet, since this same thread would + // have added it previously to one of the tables that we traversed. + + // Code and algorithm adapted from http://preshing.com/20130605/the-worlds-simplest-lock-free-hash-table + +#if MCDBGQ_NOLOCKFREE_IMPLICITPRODHASH + debug::DebugLock lock(implicitProdMutex); +#endif + + auto id = details::thread_id(); + auto hashedId = details::hash_thread_id(id); + + auto mainHash = implicitProducerHash.load(std::memory_order_acquire); + for (auto hash = mainHash; hash != nullptr; hash = hash->prev) { + // Look for the id in this hash + auto index = hashedId; + while (true) { // Not an infinite loop because at least one slot is free in the hash table + index &= hash->capacity - 1; + + auto probedKey = hash->entries[index].key.load(std::memory_order_relaxed); + if (probedKey == id) { + // Found it! If we had to search several hashes deep, though, we should lazily add it + // to the current main hash table to avoid the extended search next time. + // Note there's guaranteed to be room in the current hash table since every subsequent + // table implicitly reserves space for all previous tables (there's only one + // implicitProducerHashCount). + auto value = hash->entries[index].value; + if (hash != mainHash) { + index = hashedId; + while (true) { + index &= mainHash->capacity - 1; + probedKey = mainHash->entries[index].key.load(std::memory_order_relaxed); + auto empty = details::invalid_thread_id; +#ifdef MOODYCAMEL_CPP11_THREAD_LOCAL_SUPPORTED + auto reusable = details::invalid_thread_id2; + if ((probedKey == empty && mainHash->entries[index].key.compare_exchange_strong(empty, id, std::memory_order_relaxed, std::memory_order_relaxed)) || + (probedKey == reusable && mainHash->entries[index].key.compare_exchange_strong(reusable, id, std::memory_order_acquire, std::memory_order_acquire))) { +#else + if ((probedKey == empty && mainHash->entries[index].key.compare_exchange_strong(empty, id, std::memory_order_relaxed, std::memory_order_relaxed))) { +#endif + mainHash->entries[index].value = value; + break; + } + ++index; + } + } + + return value; + } + if (probedKey == details::invalid_thread_id) { + break; // Not in this hash table + } + ++index; + } + } + + // Insert! + auto newCount = 1 + implicitProducerHashCount.fetch_add(1, std::memory_order_relaxed); + while (true) { + if (newCount >= (mainHash->capacity >> 1) && !implicitProducerHashResizeInProgress.test_and_set(std::memory_order_acquire)) { + // We've acquired the resize lock, try to allocate a bigger hash table. + // Note the acquire fence synchronizes with the release fence at the end of this block, and hence when + // we reload implicitProducerHash it must be the most recent version (it only gets changed within this + // locked block). + mainHash = implicitProducerHash.load(std::memory_order_acquire); + if (newCount >= (mainHash->capacity >> 1)) { + auto newCapacity = mainHash->capacity << 1; + while (newCount >= (newCapacity >> 1)) { + newCapacity <<= 1; + } + auto raw = static_cast((Traits::malloc)(sizeof(ImplicitProducerHash) + std::alignment_of::value - 1 + sizeof(ImplicitProducerKVP) * newCapacity)); + if (raw == nullptr) { + // Allocation failed + implicitProducerHashCount.fetch_sub(1, std::memory_order_relaxed); + implicitProducerHashResizeInProgress.clear(std::memory_order_relaxed); + return nullptr; + } + + auto newHash = new (raw) ImplicitProducerHash; + newHash->capacity = newCapacity; + newHash->entries = reinterpret_cast(details::align_for(raw + sizeof(ImplicitProducerHash))); + for (size_t i = 0; i != newCapacity; ++i) { + new (newHash->entries + i) ImplicitProducerKVP; + newHash->entries[i].key.store(details::invalid_thread_id, std::memory_order_relaxed); + } + newHash->prev = mainHash; + implicitProducerHash.store(newHash, std::memory_order_release); + implicitProducerHashResizeInProgress.clear(std::memory_order_release); + mainHash = newHash; + } + else { + implicitProducerHashResizeInProgress.clear(std::memory_order_release); + } + } + + // If it's < three-quarters full, add to the old one anyway so that we don't have to wait for the next table + // to finish being allocated by another thread (and if we just finished allocating above, the condition will + // always be true) + if (newCount < (mainHash->capacity >> 1) + (mainHash->capacity >> 2)) { + bool recycled; + auto producer = static_cast(recycle_or_create_producer(false, recycled)); + if (producer == nullptr) { + implicitProducerHashCount.fetch_sub(1, std::memory_order_relaxed); + return nullptr; + } + if (recycled) { + implicitProducerHashCount.fetch_sub(1, std::memory_order_relaxed); + } + +#ifdef MOODYCAMEL_CPP11_THREAD_LOCAL_SUPPORTED + producer->threadExitListener.callback = &ConcurrentQueue::implicit_producer_thread_exited_callback; + producer->threadExitListener.userData = producer; + details::ThreadExitNotifier::subscribe(&producer->threadExitListener); +#endif + + auto index = hashedId; + while (true) { + index &= mainHash->capacity - 1; + auto probedKey = mainHash->entries[index].key.load(std::memory_order_relaxed); + + auto empty = details::invalid_thread_id; +#ifdef MOODYCAMEL_CPP11_THREAD_LOCAL_SUPPORTED + auto reusable = details::invalid_thread_id2; + if ((probedKey == empty && mainHash->entries[index].key.compare_exchange_strong(empty, id, std::memory_order_relaxed, std::memory_order_relaxed)) || + (probedKey == reusable && mainHash->entries[index].key.compare_exchange_strong(reusable, id, std::memory_order_acquire, std::memory_order_acquire))) { +#else + if ((probedKey == empty && mainHash->entries[index].key.compare_exchange_strong(empty, id, std::memory_order_relaxed, std::memory_order_relaxed))) { +#endif + mainHash->entries[index].value = producer; + break; + } + ++index; + } + return producer; + } + + // Hmm, the old hash is quite full and somebody else is busy allocating a new one. + // We need to wait for the allocating thread to finish (if it succeeds, we add, if not, + // we try to allocate ourselves). + mainHash = implicitProducerHash.load(std::memory_order_acquire); + } + } + +#ifdef MOODYCAMEL_CPP11_THREAD_LOCAL_SUPPORTED + void implicit_producer_thread_exited(ImplicitProducer* producer) + { + // Remove from thread exit listeners + details::ThreadExitNotifier::unsubscribe(&producer->threadExitListener); + + // Remove from hash +#if MCDBGQ_NOLOCKFREE_IMPLICITPRODHASH + debug::DebugLock lock(implicitProdMutex); +#endif + auto hash = implicitProducerHash.load(std::memory_order_acquire); + assert(hash != nullptr); // The thread exit listener is only registered if we were added to a hash in the first place + auto id = details::thread_id(); + auto hashedId = details::hash_thread_id(id); + details::thread_id_t probedKey; + + // We need to traverse all the hashes just in case other threads aren't on the current one yet and are + // trying to add an entry thinking there's a free slot (because they reused a producer) + for (; hash != nullptr; hash = hash->prev) { + auto index = hashedId; + do { + index &= hash->capacity - 1; + probedKey = hash->entries[index].key.load(std::memory_order_relaxed); + if (probedKey == id) { + hash->entries[index].key.store(details::invalid_thread_id2, std::memory_order_release); + break; + } + ++index; + } while (probedKey != details::invalid_thread_id); // Can happen if the hash has changed but we weren't put back in it yet, or if we weren't added to this hash in the first place + } + + // Mark the queue as being recyclable + producer->inactive.store(true, std::memory_order_release); + } + + static void implicit_producer_thread_exited_callback(void* userData) + { + auto producer = static_cast(userData); + auto queue = producer->parent; + queue->implicit_producer_thread_exited(producer); + } +#endif + + ////////////////////////////////// + // Utility functions + ////////////////////////////////// + + template + static inline U* create_array(size_t count) + { + assert(count > 0); + auto p = static_cast((Traits::malloc)(sizeof(U) * count)); + if (p == nullptr) { + return nullptr; + } + + for (size_t i = 0; i != count; ++i) { + new (p + i) U(); + } + return p; + } + + template + static inline void destroy_array(U* p, size_t count) + { + if (p != nullptr) { + assert(count > 0); + for (size_t i = count; i != 0; ) { + (p + --i)->~U(); + } + (Traits::free)(p); + } + } + + template + static inline U* create() + { + auto p = (Traits::malloc)(sizeof(U)); + return p != nullptr ? new (p) U : nullptr; + } + + template + static inline U* create(A1&& a1) + { + auto p = (Traits::malloc)(sizeof(U)); + return p != nullptr ? new (p) U(std::forward(a1)) : nullptr; + } + + template + static inline void destroy(U* p) + { + if (p != nullptr) { + p->~U(); + } + (Traits::free)(p); + } + +private: + std::atomic producerListTail; + std::atomic producerCount; + + std::atomic initialBlockPoolIndex; + Block* initialBlockPool; + size_t initialBlockPoolSize; + +#if !MCDBGQ_USEDEBUGFREELIST + FreeList freeList; +#else + debug::DebugFreeList freeList; +#endif + + std::atomic implicitProducerHash; + std::atomic implicitProducerHashCount; // Number of slots logically used + ImplicitProducerHash initialImplicitProducerHash; + std::array initialImplicitProducerHashEntries; + std::atomic_flag implicitProducerHashResizeInProgress; + + std::atomic nextExplicitConsumerId; + std::atomic globalExplicitConsumerOffset; + +#if MCDBGQ_NOLOCKFREE_IMPLICITPRODHASH + debug::DebugMutex implicitProdMutex; +#endif + +#ifdef MOODYCAMEL_QUEUE_INTERNAL_DEBUG + std::atomic explicitProducers; + std::atomic implicitProducers; +#endif +}; + + +template +ProducerToken::ProducerToken(ConcurrentQueue& queue) + : producer(queue.recycle_or_create_producer(true)) +{ + if (producer != nullptr) { + producer->token = this; + } +} + +template +ProducerToken::ProducerToken(BlockingConcurrentQueue& queue) + : producer(reinterpret_cast*>(&queue)->recycle_or_create_producer(true)) +{ + if (producer != nullptr) { + producer->token = this; + } +} + +template +ConsumerToken::ConsumerToken(ConcurrentQueue& queue) + : itemsConsumedFromCurrent(0), currentProducer(nullptr), desiredProducer(nullptr) +{ + initialOffset = queue.nextExplicitConsumerId.fetch_add(1, std::memory_order_release); + lastKnownGlobalOffset = -1; +} + +template +ConsumerToken::ConsumerToken(BlockingConcurrentQueue& queue) + : itemsConsumedFromCurrent(0), currentProducer(nullptr), desiredProducer(nullptr) +{ + initialOffset = reinterpret_cast*>(&queue)->nextExplicitConsumerId.fetch_add(1, std::memory_order_release); + lastKnownGlobalOffset = -1; +} + +template +inline void swap(ConcurrentQueue& a, ConcurrentQueue& b) MOODYCAMEL_NOEXCEPT +{ + a.swap(b); +} + +inline void swap(ProducerToken& a, ProducerToken& b) MOODYCAMEL_NOEXCEPT +{ + a.swap(b); +} + +inline void swap(ConsumerToken& a, ConsumerToken& b) MOODYCAMEL_NOEXCEPT +{ + a.swap(b); +} + +template +inline void swap(typename ConcurrentQueue::ImplicitProducerKVP& a, typename ConcurrentQueue::ImplicitProducerKVP& b) MOODYCAMEL_NOEXCEPT +{ + a.swap(b); +} + +} + +#if defined(__GNUC__) +#pragma GCC diagnostic pop +#endif diff --git a/libsrc/core/ngcore.hpp b/libsrc/core/ngcore.hpp index 8cc937c0..8685ced5 100644 --- a/libsrc/core/ngcore.hpp +++ b/libsrc/core/ngcore.hpp @@ -2,11 +2,13 @@ #define NETGEN_CORE_NGCORE_HPP #include "archive.hpp" +#include "array.hpp" #include "exception.hpp" #include "logging.hpp" +#include "mpi_wrapper.hpp" #include "profiler.hpp" #include "symboltable.hpp" +#include "taskmanager.hpp" #include "version.hpp" -#include "mpi_wrapper.hpp" #endif // NETGEN_CORE_NGCORE_HPP diff --git a/libsrc/core/taskmanager.cpp b/libsrc/core/taskmanager.cpp new file mode 100644 index 00000000..eca6e923 --- /dev/null +++ b/libsrc/core/taskmanager.cpp @@ -0,0 +1,812 @@ +/********************************************************************/ +/* File: taskmanager.cpp */ +/* Author: M. Hochsterger, J. Schoeberl */ +/* Date: 10. Mar. 2015 */ +/********************************************************************/ + +#include +#include +#include +#include + +#include "concurrentqueue.h" +#include "paje_trace.hpp" +#include "profiler.hpp" +#include "taskmanager.hpp" + +#ifdef USE_MKL +#include +#endif + + + +namespace ngcore +{ + using std::mutex; + using std::lock_guard; + using std::memory_order_release; + using std::memory_order_relaxed; + using std::make_tuple; + + TaskManager * task_manager = nullptr; + bool TaskManager :: use_paje_trace = false; + int TaskManager :: max_threads = getenv("NGS_NUM_THREADS") ? atoi(getenv("NGS_NUM_THREADS")) : std::thread::hardware_concurrency(); + int TaskManager :: num_threads = 1; + + +#ifndef __clang__ + thread_local int TaskManager :: thread_id = 0; +#else + __thread int TaskManager :: thread_id; +#endif + + thread_local int thread_id = 0; + + const function * TaskManager::func; + const function * TaskManager::startup_function = nullptr; + const function * TaskManager::cleanup_function = nullptr; + + atomic TaskManager::ntasks; + Exception * TaskManager::ex; + + atomic TaskManager::jobnr; + + atomic TaskManager::complete[8]; // max nodes + atomic TaskManager::done; + atomic TaskManager::active_workers; + atomic TaskManager::workers_on_node[8]; // max nodes + + + int TaskManager::sleep_usecs = 1000; + bool TaskManager::sleep = false; + + TaskManager::NodeData *TaskManager::nodedata[8]; + int TaskManager::num_nodes; + + static mutex copyex_mutex; + + int EnterTaskManager () + { + if (task_manager) + { + // no task manager started + return 0; + } + + task_manager = new TaskManager(); + + // TODO: use logger for output + std::cout << "task-based parallelization (C++11 threads) using "<< task_manager->GetNumThreads() << " threads" << std::endl; + +#ifdef USE_NUMA + numa_run_on_node (0); +#endif + +#ifndef WIN32 + // master has maximal priority ! + int policy; + struct sched_param param; + pthread_getschedparam(pthread_self(), &policy, ¶m); + param.sched_priority = sched_get_priority_max(policy); + pthread_setschedparam(pthread_self(), policy, ¶m); +#endif // WIN32 + + + task_manager->StartWorkers(); + + ParallelFor (Range(100), [&] (int i) { ; }); // startup + return task_manager->GetNumThreads(); + } + + + void ExitTaskManager (int num_threads) + { + if(num_threads > 0) + { + task_manager->StopWorkers(); + delete task_manager; + task_manager = nullptr; + } + } + + void RunWithTaskManager (function alg) + { + int num_threads = EnterTaskManager(); + alg(); + ExitTaskManager(num_threads); + } + + + + + void TaskManager :: SetNumThreads(int amax_threads) + { + if(task_manager && task_manager->active_workers>0) + { + std::cerr << "Warning: can't change number of threads while TaskManager active!" << std::endl; + return; + } + max_threads = amax_threads; + } + + + TaskManager :: TaskManager() + { + num_threads = GetMaxThreads(); + // if (MyMPI_GetNTasks() > 1) num_threads = 1; + +#ifdef USE_NUMA + numa_available(); + num_nodes = numa_max_node() + 1; + if (num_nodes > num_threads) num_nodes = num_threads; + + for (int j = 0; j < num_nodes; j++) + { + void * mem = numa_alloc_onnode (sizeof(NodeData), j); + nodedata[j] = new (mem) NodeData; + complete[j] = -1; + workers_on_node[j] = 0; + } +#else + num_nodes = 1; + nodedata[0] = new NodeData; + complete[0] = -1; + workers_on_node[0] = 0; +#endif + + jobnr = 0; + done = 0; + sleep = false; + sleep_usecs = 1000; + active_workers = 0; + + static int cnt = 0; + char buf[100]; + if (use_paje_trace) + { +#ifdef PARALLEL + int is_init = -1; + MPI_Initialized(&is_init); + if (is_init) + sprintf(buf, "ng%d_rank%d.trace", cnt++, NgMPI_Comm(MPI_COMM_WORLD).Rank()); + else +#endif + sprintf(buf, "ng%d.trace", cnt++); + } + else + buf[0] = 0; + //sprintf(buf, ""); + trace = new PajeTrace(num_threads, buf); + } + + + TaskManager :: ~TaskManager () + { + delete trace; + trace = nullptr; + num_threads = 1; + } + + /* + int TaskManager :: GetThreadId() + { + return thread_id; + } + */ + + void TaskManager :: StartWorkers() + { + done = false; + + for (int i = 1; i < num_threads; i++) + { + std::thread([this,i]() { this->Loop(i); }).detach(); + } + thread_id = 0; + + size_t alloc_size = num_threads*NgProfiler::SIZE; + NgProfiler::thread_times = new size_t[alloc_size]; + for (size_t i = 0; i < alloc_size; i++) + NgProfiler::thread_times[i] = 0; + NgProfiler::thread_flops = new size_t[alloc_size]; + for (size_t i = 0; i < alloc_size; i++) + NgProfiler::thread_flops[i] = 0; + + while (active_workers < num_threads-1) + ; + } + + static size_t calibrate_init_tsc = __rdtsc(); + typedef std::chrono::system_clock TClock; + static TClock::time_point calibrate_init_clock = TClock::now(); + + void TaskManager :: StopWorkers() + { + done = true; + double delta_tsc = __rdtsc()-calibrate_init_tsc; + double delta_sec = std::chrono::duration(TClock::now()-calibrate_init_clock).count(); + double frequ = (delta_sec != 0) ? delta_tsc/delta_sec : 2.7e9; + + // cout << "cpu frequ = " << frequ << endl; + // collect timings + for (size_t i = 0; i < num_threads; i++) + for (size_t j = NgProfiler::SIZE; j-- > 0; ) + { + if (!NgProfiler::timers[j].usedcounter) break; + NgProfiler::timers[j].tottime += 1.0/frequ * NgProfiler::thread_times[i*NgProfiler::SIZE+j]; + NgProfiler::timers[j].flops += NgProfiler::thread_flops[i*NgProfiler::SIZE+j]; + } + delete [] NgProfiler::thread_times; + NgProfiler::thread_times = NgProfiler::dummy_thread_times.data(); + delete [] NgProfiler::thread_flops; + NgProfiler::thread_flops = NgProfiler::dummy_thread_flops.data(); + + while (active_workers) + ; + } + + /////////////////////// NEW: nested tasks using concurrent queue + + struct TNestedTask + { + const function * func; + atomic * endcnt; + int mynr; + int total; + + TNestedTask () { ; } + TNestedTask (const function & _func, + int _mynr, int _total, + atomic & _endcnt) + : func(&_func), mynr(_mynr), total(_total), endcnt(&_endcnt) + { + ; + } + }; + + typedef moodycamel::ConcurrentQueue TQueue; + typedef moodycamel::ProducerToken TPToken; + typedef moodycamel::ConsumerToken TCToken; + + static TQueue taskqueue; + + void AddTask (const function & afunc, + atomic & endcnt) + + { + TPToken ptoken(taskqueue); + + int num = endcnt; + for (int i = 0; i < num; i++) + taskqueue.enqueue (ptoken, { afunc, i, num, endcnt }); + } + + mutex m; + bool ProcessTask() + { + TNestedTask task; + TCToken ctoken(taskqueue); + + if (taskqueue.try_dequeue(ctoken, task)) + { + TaskInfo ti; + ti.task_nr = task.mynr; + ti.ntasks = task.total; + ti.thread_nr = thread_id; + ti.nthreads = TaskManager::GetNumThreads(); + /* + { + lock_guard guard(m); + cout << "process nested, nr = " << ti.task_nr << "/" << ti.ntasks << endl; + } + */ + (*task.func)(ti); + --*task.endcnt; + return true; + } + return false; + } + + + void TaskManager :: CreateJob (const function & afunc, + int antasks) + { + if (num_threads == 1 || !task_manager) // || func) + { + if (startup_function) (*startup_function)(); + + TaskInfo ti; + ti.ntasks = antasks; + ti.thread_nr = 0; ti.nthreads = 1; + // ti.node_nr = 0; ti.nnodes = 1; + for (ti.task_nr = 0; ti.task_nr < antasks; ti.task_nr++) + afunc(ti); + + if (cleanup_function) (*cleanup_function)(); + return; + } + + + if (func) + { // we are already parallel, use nested tasks + // startup for inner function not supported ... + // if (startup_function) (*startup_function)(); + + if (antasks == 1) + { + TaskInfo ti; + ti.task_nr = 0; + ti.ntasks = 1; + ti.thread_nr = 0; ti.nthreads = 1; + afunc(ti); + return; + } + + atomic endcnt(antasks); + AddTask (afunc, endcnt); + while (endcnt > 0) + { + ProcessTask(); + } + + // if (cleanup_function) (*cleanup_function)(); + return; + } + + + trace->StartJob(jobnr, afunc.target_type()); + + func = &afunc; + + ntasks.store (antasks); // , memory_order_relaxed); + ex = nullptr; + + + nodedata[0]->start_cnt.store (0, memory_order_relaxed); + + jobnr++; + + for (int j = 0; j < num_nodes; j++) + nodedata[j]->participate |= 1; + + if (startup_function) (*startup_function)(); + + int thd = 0; + int thds = GetNumThreads(); + int mynode = num_nodes * thd/thds; + + IntRange mytasks = Range(int(ntasks)).Split (mynode, num_nodes); + NodeData & mynode_data = *(nodedata[mynode]); + + TaskInfo ti; + ti.nthreads = thds; + ti.thread_nr = thd; + // ti.nnodes = num_nodes; + // ti.node_nr = mynode; + + try + { + while (1) + { + int mytask = mynode_data.start_cnt++; + if (mytask >= mytasks.Size()) break; + + ti.task_nr = mytasks.First()+mytask; + ti.ntasks = ntasks; + + { + RegionTracer t(ti.thread_nr, jobnr, RegionTracer::ID_JOB, ti.task_nr); + (*func)(ti); + } + } + + } + catch (Exception e) + { + { + lock_guard guard(copyex_mutex); + delete ex; + ex = new Exception (e); + mynode_data.start_cnt = mytasks.Size(); + } + } + + if (cleanup_function) (*cleanup_function)(); + + for (int j = 0; j < num_nodes; j++) + if (workers_on_node[j]) + { + while (complete[j] != jobnr) + _mm_pause(); + } + + func = nullptr; + if (ex) + throw Exception (*ex); + + trace->StopJob(); + } + + void TaskManager :: Loop(int thd) + { + /* + static Timer tADD("add entry counter"); + static Timer tCASready1("spin-CAS ready tick1"); + static Timer tCASready2("spin-CAS ready tick2"); + static Timer tCASyield("spin-CAS yield"); + static Timer tCAS1("spin-CAS wait"); + static Timer texit("exit zone"); + static Timer tdec("decrement"); + */ + thread_id = thd; + + int thds = GetNumThreads(); + + int mynode = num_nodes * thd/thds; + + NodeData & mynode_data = *(nodedata[mynode]); + + + + TaskInfo ti; + ti.nthreads = thds; + ti.thread_nr = thd; + // ti.nnodes = num_nodes; + // ti.node_nr = mynode; + + +#ifdef USE_NUMA + numa_run_on_node (mynode); +#endif + active_workers++; + workers_on_node[mynode]++; + int jobdone = 0; + + +#ifdef USE_MKL + auto mkl_max = mkl_get_max_threads(); + mkl_set_num_threads_local(1); +#endif + + + while (!done) + { + if (complete[mynode] > jobdone) + jobdone = complete[mynode]; + + if (jobnr == jobdone) + { + // RegionTracer t(ti.thread_nr, tCASyield, ti.task_nr); + while (ProcessTask()); // do the nested tasks + + if(sleep) + std::this_thread::sleep_for(std::chrono::microseconds(sleep_usecs)); + else + { +#ifdef WIN32 + std::this_thread::yield(); +#else // WIN32 + sched_yield(); +#endif // WIN32 + } + continue; + } + + { + // RegionTracer t(ti.thread_nr, tADD, ti.task_nr); + + // non-atomic fast check ... + if ( (mynode_data.participate & 1) == 0) continue; + + int oldval = mynode_data.participate += 2; + if ( (oldval & 1) == 0) + { // job not active, going out again + mynode_data.participate -= 2; + continue; + } + } + + if (startup_function) (*startup_function)(); + + IntRange mytasks = Range(int(ntasks)).Split (mynode, num_nodes); + + try + { + + while (1) + { + if (mynode_data.start_cnt >= mytasks.Size()) break; + int mytask = mynode_data.start_cnt.fetch_add(1, memory_order_relaxed); + if (mytask >= mytasks.Size()) break; + + ti.task_nr = mytasks.First()+mytask; + ti.ntasks = ntasks; + + { + RegionTracer t(ti.thread_nr, jobnr, RegionTracer::ID_JOB, ti.task_nr); + (*func)(ti); + } + } + + } + catch (Exception e) + { + { + // cout << "got exception in TM" << endl; + lock_guard guard(copyex_mutex); + delete ex; + ex = new Exception (e); + mynode_data.start_cnt = mytasks.Size(); + } + } + +#ifndef __MIC__ + atomic_thread_fence (memory_order_release); +#endif // __MIC__ + + if (cleanup_function) (*cleanup_function)(); + + jobdone = jobnr; + + mynode_data.participate-=2; + + { + int oldpart = 1; + if (mynode_data.participate.compare_exchange_strong (oldpart, 0)) + { + if (jobdone < jobnr.load()) + { // reopen gate + mynode_data.participate |= 1; + } + else + { + if (mynode != 0) + mynode_data.start_cnt = 0; + complete[mynode] = jobnr.load(); + } + } + } + } + + +#ifdef USE_MKL + mkl_set_num_threads_local(mkl_max); +#endif + + workers_on_node[mynode]--; + active_workers--; + } + + + std::list> TaskManager :: Timing () + { + /* + list>timings; + double time = + RunTiming + ( [&] () + { + ParallelJob ( [] (TaskInfo ti) { ; } , + TasksPerThread(1) ); + }); + timings.push_back (make_tuple("parallel job with 1 task per thread", time*1e9)); + + time = + RunTiming + ( [&] () + { + ParallelJob ( [] (TaskInfo ti) { ; } , + TasksPerThread(10) ); + }); + timings.push_back (make_tuple("parallel job with 10 tasks per thread", time*1e9)); + + time = + RunTiming + ( [&] () + { + ParallelJob ( [] (TaskInfo ti) { ; } , + TasksPerThread(100) ); + }); + timings.push_back (make_tuple("parallel job with 100 tasks per thread", time*1e9)); + + return timings; + */ + + + + // this is the old function moved from the py-interface: + std::list>timings; + double starttime, time; + double maxtime = 0.5; + size_t steps; + + starttime = WallTime(); + steps = 0; + do + { + for (size_t i = 0; i < 1000; i++) + ParallelJob ( [] (TaskInfo ti) { ; }, + TasksPerThread(1)); + steps += 1000; + time = WallTime()-starttime; + } + while (time < maxtime); + timings.push_back(make_tuple("ParallelJob 1 task/thread", time/steps*1e9)); + + + starttime = WallTime(); + steps = 0; + do + { + for (size_t i = 0; i < 1000; i++) + ParallelJob ( [] (TaskInfo ti) { ; }, + TasksPerThread(100)); + steps += 1000; + time = WallTime()-starttime; + } + while (time < maxtime); + timings.push_back(make_tuple("ParallelJob 100 task/thread", time/steps*1e9)); + + + starttime = WallTime(); + steps = 0; + do + { + for (int k = 0; k < 10000; k++) + { + SharedLoop2 sl(1000); + steps += 1; + } + time = WallTime()-starttime; + } + while (time < maxtime); + timings.push_back(make_tuple("SharedLoop init", time/steps*1e9)); + + starttime = WallTime(); + steps = 0; + do + { + for (int k = 0; k < 1000; k++) + { + SharedLoop sl(5); + ParallelJob ( [&sl] (TaskInfo ti) + { + for (auto i : sl) + (void)i; // silence warning + } ); + } + steps += 1000; + time = WallTime()-starttime; + } + while (time < maxtime); + timings.push_back(make_tuple("short SharedLoop", time/steps*1e9)); + + + starttime = WallTime(); + steps = 0; + do + { + for (int k = 0; k < 1000; k++) + { + SharedLoop sl1(5), sl2(5), sl3(5), sl4(5), sl5(5); + ParallelJob ( [&sl1, &sl2, &sl3, &sl4, &sl5] (TaskInfo ti) + { + for (auto i : sl1) + (void)i; // silence warning + for (auto i : sl2) + (void)i; // silence warning + for (auto i : sl3) + (void)i; // silence warning + for (auto i : sl4) + (void)i; // silence warning + for (auto i : sl5) + (void)i; // silence warning + } ); + } + steps += 1000; + time = WallTime()-starttime; + } + while (time < maxtime); + timings.push_back(make_tuple("5 short SharedLoops", time/steps*1e9)); + + + starttime = WallTime(); + steps = 0; + SharedLoop2 sl2(5); + do + { + for (int k = 0; k < 1000; k++) + { + sl2.Reset(5); + ParallelJob ( [&sl2] (TaskInfo ti) + { + for (auto i : sl2) + (void)i; // silence warning + } ); + } + steps += 1000; + time = WallTime()-starttime; + } + while (time < maxtime); + timings.push_back(make_tuple("short SharedLoop2", time/steps*1e9)); + + { + starttime = WallTime(); + steps = 0; + SharedLoop2 sl1(5), sl2(5), sl3(5), sl4(5), sl5(5); + do + { + for (int k = 0; k < 1000; k++) + { + sl1.Reset(5); + sl2.Reset(5); + sl3.Reset(5); + sl4.Reset(5); + sl5.Reset(5); + ParallelJob ( [&sl1,&sl2,&sl3,&sl4,&sl5] (TaskInfo ti) + { + for (auto i : sl1) + (void)i; // silence warning + for (auto i : sl2) + (void)i; // silence warning + for (auto i : sl3) + (void)i; // silence warning + for (auto i : sl4) + (void)i; // silence warning + for (auto i : sl5) + (void)i; // silence warning + } ); + } + steps += 1000; + time = WallTime()-starttime; + } + while (time < maxtime); + timings.push_back(make_tuple("5 short SharedLoop2", time/steps*1e9)); + } + + + starttime = WallTime(); + steps = 0; + { + SharedLoop2 sl(1000); + do + { + for (int k = 0; k < 1000; k++) + { + sl.Reset(1000); + ParallelJob ( [&sl] (TaskInfo ti) + { + for (auto i : sl) + (void)i; // silence warning + } ); + steps += 1000; + } + time = WallTime()-starttime; + } + while (time < maxtime); + timings.push_back(make_tuple("SharedLoop2 1000, time per iteration", time/steps*1e9)); + } + + { + starttime = WallTime(); + steps = 0; + SharedLoop2 sl(1000000); + do + { + sl.Reset(1000000); + ParallelJob ( [&sl] (TaskInfo ti) + { + for (auto i : sl) + (void)i; // silence warning + } ); + steps += 1000000; + time = WallTime()-starttime; + } + while (time < maxtime); + timings.push_back(make_tuple("SharedLoop2 1000000, time per iteration", time/steps*1e9)); + } + + return timings; + } + +} diff --git a/libsrc/core/taskmanager.hpp b/libsrc/core/taskmanager.hpp new file mode 100644 index 00000000..0c64a242 --- /dev/null +++ b/libsrc/core/taskmanager.hpp @@ -0,0 +1,1021 @@ +#ifndef NETGEN_CORE_TASKMANAGER_HPP +#define NETGEN_CORE_TASKMANAGER_HPP + +/*********************************************************************/ +/* File: taskmanager.hpp */ +/* Author: M. Hochsterger, J. Schoeberl */ +/* Date: 10. Mar. 2015 */ +/*********************************************************************/ + +#include +#include +#include +#include +#include + +#include "array.hpp" +#include "paje_trace.hpp" + +namespace ngcore +{ + using std::atomic; + using std::function; + + class TaskInfo + { + public: + int task_nr; + int ntasks; + + int thread_nr; + int nthreads; + + // int node_nr; + // int nnodes; + }; + + NGCORE_API extern class TaskManager * task_manager; + + class TaskManager + { +// PajeTrace *trace; + + class alignas(64) NodeData //: public AlignedAlloc + { + public: + atomic start_cnt{0}; + atomic participate{0}; + }; + + static const function * func; + static const function * startup_function; + static const function * cleanup_function; + static atomic ntasks; + static Exception * ex; + + static atomic jobnr; + + static atomic complete[8]; // max nodes + static atomic done; + static atomic active_workers; + static atomic workers_on_node[8]; // max nodes + // Array*> sync; + static int sleep_usecs; + static bool sleep; + + static NodeData *nodedata[8]; + + static int num_nodes; + NGCORE_API static int num_threads; + NGCORE_API static int max_threads; + + + +#ifndef __clang__ + static thread_local int thread_id; +#else + static __thread int thread_id; +#endif + + NGCORE_API static bool use_paje_trace; + public: + + TaskManager(); + ~TaskManager(); + + + void StartWorkers(); + void StopWorkers(); + + void SuspendWorkers(int asleep_usecs = 1000 ) + { + sleep_usecs = asleep_usecs; + sleep = true; + } + void ResumeWorkers() { sleep = false; } + + static void SetNumThreads(int amax_threads); + static int GetMaxThreads() { return max_threads; } + // static int GetNumThreads() { return task_manager ? task_manager->num_threads : 1; } + static int GetNumThreads() { return num_threads; } + static int GetThreadId() { return thread_id; } + int GetNumNodes() const { return num_nodes; } + + static void SetPajeTrace (bool use) { use_paje_trace = use; } + + NGCORE_API static void CreateJob (const function & afunc, + int antasks = task_manager->GetNumThreads()); + + static void SetStartupFunction (const function & func) { startup_function = &func; } + static void SetStartupFunction () { startup_function = nullptr; } + static void SetCleanupFunction (const function & func) { cleanup_function = &func; } + static void SetCleanupFunction () { cleanup_function = nullptr; } + + void Done() { done = true; } + void Loop(int thread_num); + + static std::list> Timing (); + }; + + + + + + + + + + NGCORE_API void RunWithTaskManager (function alg); + + // For Python context manager + int EnterTaskManager (); + void ExitTaskManager (int num_threads); + + NETGEN_INLINE int TasksPerThread (int tpt) + { + // return task_manager ? tpt*task_manager->GetNumThreads() : 1; + return tpt*TaskManager::GetNumThreads(); + } + + + class TotalCosts + { + size_t cost; + public: + TotalCosts (size_t _cost) : cost(_cost) { ; } + size_t operator ()() { return cost; } + }; + + template + NETGEN_INLINE void ParallelFor (T_Range r, TFUNC f, + int antasks = TaskManager::GetNumThreads(), + TotalCosts costs = 1000) + { + // if (task_manager && costs() >= 1000) + + TaskManager::CreateJob + ([r, f] (TaskInfo & ti) + { + auto myrange = r.Split (ti.task_nr, ti.ntasks); + for (auto i : myrange) f(i); + }, + antasks); + + /* + else + for (auto i : r) f(i); + */ + } + + /* + template + NETGEN_INLINE void ParallelFor (size_t n, TFUNC f, + int antasks = task_manager ? task_manager->GetNumThreads() : 0) + { + ParallelFor (IntRange (n), f, antasks); + } + */ + template + NETGEN_INLINE void ParallelFor (size_t n, Args...args) + { + ParallelFor (IntRange (n), args...); + } + + template + NETGEN_INLINE void ParallelForRange (T_Range r, TFUNC f, + int antasks = TaskManager::GetNumThreads(), + TotalCosts costs = 1000) + { + // if (task_manager && costs() >= 1000) + + TaskManager::CreateJob + ([r, f] (TaskInfo & ti) + { + auto myrange = r.Split (ti.task_nr, ti.ntasks); + f(myrange); + }, + antasks); + /* + else + f(r); + */ + } + + /* + template + NETGEN_INLINE void ParallelForRange (size_t n, TFUNC f, + int antasks = task_manager ? task_manager->GetNumThreads() : 0) + { + ParallelForRange (IntRange(n), f, antasks); + } + */ + template + NETGEN_INLINE void ParallelForRange (size_t n, Args...args) + { + ParallelForRange (IntRange(n), args...); + } + + template + NETGEN_INLINE void ParallelJob (TFUNC f, + int antasks = TaskManager::GetNumThreads()) + { + TaskManager::CreateJob (f, antasks); + } + + + /* + Usage example: + + ShareLoop myloop(100); + task_manager->CreateJob ([]() + { + for (int i : myloop) + cout << "i = " << i << endl; + }); + + */ + + class SharedLoop + { + atomic cnt; + IntRange r; + + + class SharedIterator + { + atomic & cnt; + int myval; + int endval; + public: + SharedIterator (atomic & acnt, int aendval, bool begin_iterator) + : cnt (acnt) + { + endval = aendval; + myval = begin_iterator ? cnt++ : endval; + if (myval > endval) myval = endval; + } + + SharedIterator & operator++ () + { + myval = cnt++; + if (myval > endval) myval = endval; + return *this; + } + + int operator* () const { return myval; } + bool operator!= (const SharedIterator & it2) const { return myval != it2.myval; } + }; + + + public: + SharedLoop (IntRange ar) : r(ar) { cnt = r.begin(); } + SharedIterator begin() { return SharedIterator (cnt, r.end(), true); } + SharedIterator end() { return SharedIterator (cnt, r.end(), false); } + }; + + + /* +class alignas(4096) AtomicRange +{ + mutex lock; + int begin; + int end; +public: + + void Set (IntRange r) + { + lock_guard guard(lock); + begin = r.begin(); + end = r.end(); + } + + IntRange Get() + { + lock_guard guard(lock); + return IntRange(begin, end); + } + + bool PopFirst (int & first) + { + lock_guard guard(lock); + bool non_empty = end > begin; + first = begin; + if (non_empty) begin++; + return non_empty; + } + + bool PopHalf (IntRange & r) + { + lock_guard guard(lock); + bool non_empty = end > begin; + if (non_empty) + { + int mid = (begin+end+1)/2; + r = IntRange(begin, mid); + begin = mid; + } + return non_empty; + } +}; +*/ + + + + // lock free popfirst + // faster for large loops, bug slower for small loops (~1000) ???? + /* + class alignas(4096) AtomicRange +{ + mutex lock; + atomic begin; + int end; +public: + + void Set (IntRange r) + { + lock_guard guard(lock); + // begin = r.begin(); + begin.store(r.begin(), std::memory_order_relaxed); + end = r.end(); + } + + void SetNoLock (IntRange r) + { + begin.store(r.begin(), std::memory_order_relaxed); + end = r.end(); + } + + // IntRange Get() + // { + // lock_guard guard(lock); + // return IntRange(begin, end); + // } + + bool PopFirst (int & first) + { + // int oldbegin = begin; + int oldbegin = begin.load(std::memory_order_relaxed); + if (oldbegin >= end) return false; + while (!begin.compare_exchange_weak (oldbegin, oldbegin+1, + std::memory_order_relaxed, std::memory_order_relaxed)) + if (oldbegin >= end) return false; + + first = oldbegin; + return true; + } + + bool PopHalf (IntRange & r) + { + // int oldbegin = begin; + int oldbegin = begin.load(std::memory_order_relaxed); + if (oldbegin >= end) return false; + + lock_guard guard(lock); + while (!begin.compare_exchange_weak (oldbegin, (oldbegin+end+1)/2, + std::memory_order_relaxed, std::memory_order_relaxed)) + if (oldbegin >= end) return false; + + r = IntRange(oldbegin, (oldbegin+end+1)/2); + return true; + } +}; + + + // inline ostream & operator<< (ostream & ost, AtomicRange & r) + // { + // ost << r.Get(); + // return ost; + // } + */ + + + + class alignas(4096) AtomicRange //: public AlignedAlloc + { + atomic begin; + atomic end; + public: + + void Set (IntRange r) + { + begin.store(std::numeric_limits::max(), std::memory_order_release); + end.store(r.end(), std::memory_order_release); + begin.store(r.begin(), std::memory_order_release); + } + + void SetNoLock (IntRange r) + { + end.store(r.end(), std::memory_order_release); + begin.store(r.begin(), std::memory_order_release); + } + + // IntRange Get() + // { + // lock_guard guard(lock); + // return IntRange(begin, end); + // } + + bool PopFirst (size_t & first) + { + first = begin++; + return first < end; + /* + // int oldbegin = begin; + size_t oldbegin = begin.load(std::memory_order_acquire); + if (oldbegin >= end) return false; + while (!begin.compare_exchange_weak (oldbegin, oldbegin+1, + std::memory_order_relaxed, std::memory_order_relaxed)) + if (oldbegin >= end) return false; + + first = oldbegin; + return true; + */ + } + + bool PopHalf (IntRange & r) + { + // int oldbegin = begin; + size_t oldbegin = begin.load(std::memory_order_acquire); + size_t oldend = end.load(std::memory_order_acquire); + if (oldbegin >= oldend) return false; + + // lock_guard guard(lock); + while (!begin.compare_exchange_weak (oldbegin, (oldbegin+oldend+1)/2, + std::memory_order_relaxed, std::memory_order_relaxed)) + { + oldend = end.load(std::memory_order_acquire); + if (oldbegin >= oldend) return false; + } + + r = IntRange(oldbegin, (oldbegin+oldend+1)/2); + return true; + } + }; + + + + + class SharedLoop2 + { + Array ranges; + atomic processed; + atomic total; + atomic participants; + + class SharedIterator + { + FlatArray ranges; + atomic & processed; + size_t total; + size_t myval; + size_t processed_by_me = 0; + int me; + int steal_from; + public: + SharedIterator (FlatArray _ranges, atomic & _processed, size_t _total, + int _me, bool begin_it) + : ranges(_ranges), processed(_processed), total(_total) + { + if (begin_it) + { + // me = TaskManager::GetThreadId(); + me = _me; + steal_from = me; + GetNext(); + } + } + ~SharedIterator() + { + if (processed_by_me) + processed += processed_by_me; + } + + SharedIterator & operator++ () { GetNext(); return *this;} + + void GetNext() + { + size_t nr; + if (ranges[me].PopFirst(nr)) + { + processed_by_me++; + myval = nr; + return; + } + GetNext2(); + } + + void GetNext2() + { + processed += processed_by_me; + processed_by_me = 0; + + // done with my work, going to steal ... + while (1) + { + if (processed >= total) return; + + steal_from++; + if (steal_from == ranges.Size()) steal_from = 0; + + // steal half of the work reserved for 'from': + IntRange steal; + if (ranges[steal_from].PopHalf(steal)) + { + myval = steal.First(); + processed_by_me++; + if (myval+1 < steal.Next()) + ranges[me].Set (IntRange(myval+1, steal.Next())); + return; + } + } + } + + size_t operator* () const { return myval; } + bool operator!= (const SharedIterator & it2) const { return processed < total; } + }; + + + public: + SharedLoop2 () + : ranges(TaskManager::GetNumThreads()) + { ; } + + SharedLoop2 (IntRange r) + : ranges(TaskManager::GetNumThreads()) + { + Reset (r); + } + + void Reset (IntRange r) + { + for (size_t i = 0; i < ranges.Size(); i++) + ranges[i].SetNoLock (r.Split(i,ranges.Size())); + + total.store(r.Size(), std::memory_order_relaxed); + participants.store(0, std::memory_order_relaxed); + processed.store(0, std::memory_order_release); + } + + SharedIterator begin() + { + /* + int me = participants++; + if (me < ranges.Size()) + return SharedIterator (ranges, processed, total, me, true); + else + // more participants than buckets. set processed to total, and the loop is terminated immediately + return SharedIterator (ranges, total, total, me, true); + */ + return SharedIterator (ranges, processed, total, TaskManager::GetThreadId(), true); + } + + SharedIterator end() { return SharedIterator (ranges, processed, total, -1, false); } + }; + + + + + + class Partitioning + { + Array part; + size_t total_costs; + public: + Partitioning () { ; } + + template + Partitioning (const Array & apart) { part = apart; } + + template + Partitioning & operator= (const Array & apart) { part = apart; return *this; } + + size_t GetTotalCosts() const { return total_costs; } + + template + void Calc (size_t n, TFUNC costs, int size = task_manager ? task_manager->GetNumThreads() : 1) + { + Array prefix (n); + + /* + size_t sum = 0; + for (auto i : ngstd::Range(n)) + { + sum += costs(i); + prefix[i] = sum; + } + total_costs = sum; + */ + + Array partial_sums(TaskManager::GetNumThreads()+1); + partial_sums[0] = 0; + ParallelJob + ([&] (TaskInfo ti) + { + IntRange r = IntRange(n).Split(ti.task_nr, ti.ntasks); + size_t mysum = 0; + for (size_t i : r) + { + size_t c = costs(i); + mysum += c; + prefix[i] = c; + } + partial_sums[ti.task_nr+1] = mysum; + }); + + for (size_t i = 1; i < partial_sums.Size(); i++) + partial_sums[i] += partial_sums[i-1]; + total_costs = partial_sums.Last(); + + ParallelJob + ([&] (TaskInfo ti) + { + IntRange r = IntRange(n).Split(ti.task_nr, ti.ntasks); + size_t mysum = partial_sums[ti.task_nr]; + for (size_t i : r) + { + mysum += prefix[i]; + prefix[i] = mysum; + } + }); + + + part.SetSize (size+1); + part[0] = 0; + + for (int i = 1; i <= size; i++) + part[i] = BinSearch (prefix, total_costs*i/size); + } + + size_t Size() const { return part.Size()-1; } + IntRange operator[] (size_t i) const { return ngcore::Range(part[i], part[i+1]); } + IntRange Range() const { return ngcore::Range(part[0], part[Size()]); } + + + + + private: + template + int BinSearch(const Tarray & v, size_t i) { + int n = v.Size(); + if (n == 0) return 0; + + int first = 0; + int last = n-1; + if(v[0]>i) return 0; + if(v[n-1] <= i) return n; + while(last-first>1) { + int m = (first+last)/2; + if(v[m] + NETGEN_INLINE void ParallelFor (const Partitioning & part, TFUNC f, int tasks_per_thread = 1) + { + if (task_manager) + { + int ntasks = tasks_per_thread * task_manager->GetNumThreads(); + if (ntasks % part.Size() != 0) + throw Exception ("tasks must be a multiple of part.size"); + + task_manager -> CreateJob + ([&] (TaskInfo & ti) + { + int tasks_per_part = ti.ntasks / part.Size(); + int mypart = ti.task_nr / tasks_per_part; + int num_in_part = ti.task_nr % tasks_per_part; + + auto myrange = part[mypart].Split (num_in_part, tasks_per_part); + for (auto i : myrange) f(i); + }, ntasks); + } + else + { + for (auto i : part.Range()) + f(i); + } + } + + + + + + template + NETGEN_INLINE void ParallelForRange (const Partitioning & part, TFUNC f, + int tasks_per_thread = 1, TotalCosts costs = 1000) + { + if (task_manager && costs() >= 1000) + { + int ntasks = tasks_per_thread * task_manager->GetNumThreads(); + if (ntasks % part.Size() != 0) + throw Exception ("tasks must be a multiple of part.size"); + + task_manager -> CreateJob + ([&] (TaskInfo & ti) + { + int tasks_per_part = ti.ntasks / part.Size(); + int mypart = ti.task_nr / tasks_per_part; + int num_in_part = ti.task_nr % tasks_per_part; + + auto myrange = part[mypart].Split (num_in_part, tasks_per_part); + f(myrange); + }, ntasks); + } + else + { + f(part.Range()); + } + } + + + + + + template + auto ParallelReduce (size_t n, FUNC f, OP op, T initial1) + { + typedef decltype (op(initial1,initial1)) TRES; + TRES initial(initial1); + /* + for (size_t i = 0; i < n; i++) + initial = op(initial, f(i)); + */ + Array part_reduce(TaskManager::GetNumThreads()); + ParallelJob ([&] (TaskInfo ti) + { + auto r = Range(n).Split(ti.task_nr, ti.ntasks); + auto var = initial; + for (auto i : r) + var = op(var, f(i)); + part_reduce[ti.task_nr] = var; + }); + for (auto v : part_reduce) + initial = op(initial, v); + return initial; + } + + + + + + + +// // some suggar for working with arrays +// +// template template +// const FlatArray FlatArray::operator= (ParallelValue val) +// { +// ParallelForRange (Size(), +// [this, val] (IntRange r) +// { +// for (auto i : r) +// (*this)[i] = val; +// }); +// return *this; +// } +// +// template template +// const FlatArray FlatArray::operator= (ParallelFunction func) +// { +// ParallelForRange (Size(), +// [this, func] (IntRange r) +// { +// for (auto i : r) +// (*this)[i] = func(i); +// }); +// return *this; +// } + +class Tasks +{ + size_t num; +public: + explicit Tasks (size_t _num = TaskManager::GetNumThreads()) : num(_num) { ; } + auto GetNum() const { return num; } +}; + +/* currently not used, plus causing problems on MSVC 2017 +template ::value, int>::type = 0> +inline ParallelFunction operator| (const T & func, Tasks tasks) +{ + return func; +} + +template ::value, int>::type = 0> +inline ParallelValue operator| (const T & obj, Tasks tasks) +{ + return obj; +} + +inline Tasks operator "" _tasks_per_thread (unsigned long long n) +{ + return Tasks(n * TaskManager::GetNumThreads()); +} +*/ + +/* + thought to be used as: array = 1 | tasks +class DefaultTasks +{ +public: + operator Tasks () const { return TaskManager::GetNumThreads(); } +}; +static DefaultTasks tasks; +*/ + + + + + + + +#ifdef USE_NUMA + +template +class NumaInterleavedArray : public Array +{ + T * numa_ptr; + size_t numa_size; +public: + NumaInterleavedArray () { numa_size = 0; numa_ptr = nullptr; } + NumaInterleavedArray (size_t s) + : Array (s, (T*)numa_alloc_interleaved(s*sizeof(T))) + { + numa_ptr = this->data; + numa_size = s; + } + + ~NumaInterleavedArray () + { + numa_free (numa_ptr, numa_size*sizeof(T)); + } + + NumaInterleavedArray & operator= (T val) + { + Array::operator= (val); + return *this; + } + + NumaInterleavedArray & operator= (NumaInterleavedArray && a2) + { + Array::operator= ((Array&&)a2); + ngcore::Swap (numa_ptr, a2.numa_ptr); + ngcore::Swap (numa_size, a2.numa_size); + return *this; + } + + void Swap (NumaInterleavedArray & b) + { + Array::Swap(b); + ngcore::Swap (numa_ptr, b.numa_ptr); + ngcore::Swap (numa_size, b.numa_size); + } + + void SetSize (size_t size) + { + cerr << "************************* NumaDistArray::SetSize not overloaded" << endl; + Array::SetSize(size); + } +}; + +template +class NumaDistributedArray : public Array +{ + T * numa_ptr; + size_t numa_size; +public: + NumaDistributedArray () { numa_size = 0; numa_ptr = nullptr; } + NumaDistributedArray (size_t s) + : Array (s, (T*)numa_alloc_local(s*sizeof(T))) + { + numa_ptr = this->data; + numa_size = s; + + /* int avail = */ numa_available(); // initialize libnuma + int num_nodes = numa_num_configured_nodes(); + size_t pagesize = numa_pagesize(); + + int npages = ceil ( double(s)*sizeof(T) / pagesize ); + + // cout << "size = " << numa_size << endl; + // cout << "npages = " << npages << endl; + + for (int i = 0; i < num_nodes; i++) + { + int beg = (i * npages) / num_nodes; + int end = ( (i+1) * npages) / num_nodes; + // cout << "node " << i << " : [" << beg << "-" << end << ")" << endl; + numa_tonode_memory(numa_ptr+beg*pagesize/sizeof(T), (end-beg)*pagesize, i); + } + } + + ~NumaDistributedArray () + { + numa_free (numa_ptr, numa_size*sizeof(T)); + } + + NumaDistributedArray & operator= (NumaDistributedArray && a2) + { + Array::operator= ((Array&&)a2); + ngcore::Swap (numa_ptr, a2.numa_ptr); + ngcore::Swap (numa_size, a2.numa_size); + return *this; + } + + void Swap (NumaDistributedArray & b) + { + Array::Swap(b); + ngcore::Swap (numa_ptr, b.numa_ptr); + ngcore::Swap (numa_size, b.numa_size); + } + + void SetSize (size_t size) + { + cerr << "************************* NumaDistArray::SetSize not overloaded" << endl; + Array::SetSize(size); + } +}; + + + +template +class NumaLocalArray : public Array +{ + T * numa_ptr; + size_t numa_size; +public: + NumaLocalArray () { numa_size = 0; numa_ptr = nullptr; } + NumaLocalArray (size_t s) + : Array (s, (T*)numa_alloc_local(s*sizeof(T))) + { + numa_ptr = this->data; + numa_size = s; + } + + ~NumaLocalArray () + { + numa_free (numa_ptr, numa_size*sizeof(T)); + } + + NumaLocalArray & operator= (T val) + { + Array::operator= (val); + return *this; + } + + NumaLocalArray & operator= (NumaLocalArray && a2) + { + Array::operator= ((Array&&)a2); + ngcore::Swap (numa_ptr, a2.numa_ptr); + ngcore::Swap (numa_size, a2.numa_size); + return *this; + } + + void Swap (NumaLocalArray & b) + { + Array::Swap(b); + ngcore::Swap (numa_ptr, b.numa_ptr); + ngcore::Swap (numa_size, b.numa_size); + } + + void SetSize (size_t size) + { + cerr << "************************* NumaDistArray::SetSize not overloaded" << endl; + Array::SetSize(size); + } +}; + + +#else // USE_NUMA + + template + using NumaDistributedArray = Array; + + template + using NumaInterleavedArray = Array; + + template + using NumaLocalArray = Array; + +#endif // USE_NUMA + +} + + + +#endif // NETGEN_CORE_TASKMANAGER_HPP diff --git a/libsrc/core/utils.hpp b/libsrc/core/utils.hpp index f2a73578..4dca6c8b 100644 --- a/libsrc/core/utils.hpp +++ b/libsrc/core/utils.hpp @@ -65,6 +65,15 @@ namespace ngcore ost << "\n" << val.first << ": " << val.second; return ost; } + + template + NETGEN_INLINE void Swap (T & a, T & b) + { + T temp = std::move(a); + a = std::move(b); + b = std::move(temp); + } + } // namespace ngcore #endif // NETGEN_CORE_UTILS_HPP From c5acbacadb6ba5fc3fef20a1d9ae5206b29e8a38 Mon Sep 17 00:00:00 2001 From: Matthias Hochsteger Date: Tue, 9 Jul 2019 18:00:12 +0200 Subject: [PATCH 05/11] Rename ArrayMem to NgArrayMem --- libsrc/csg/csgeom.cpp | 2 +- libsrc/csg/specpoin.cpp | 2 +- libsrc/general/ngarray.hpp | 8 ++--- libsrc/gprim/adtree.cpp | 4 +-- libsrc/interface/nginterface.cpp | 12 ++++---- libsrc/interface/nginterface_v2.cpp | 2 +- libsrc/meshing/adfront2.cpp | 4 +-- libsrc/meshing/adfront3.cpp | 2 +- libsrc/meshing/clusters.cpp | 2 +- libsrc/meshing/curvedelems.cpp | 48 ++++++++++++++--------------- libsrc/meshing/curvedelems.hpp | 2 +- libsrc/meshing/improve3.cpp | 4 +-- libsrc/meshing/localh.cpp | 12 ++++---- libsrc/meshing/meshtype.cpp | 2 +- libsrc/meshing/netrule3.cpp | 6 ++-- libsrc/meshing/refine.cpp | 14 ++++----- libsrc/meshing/ruler2.cpp | 14 ++++----- libsrc/meshing/ruler3.cpp | 18 +++++------ libsrc/meshing/topology.cpp | 6 ++-- libsrc/stlgeom/stltool.cpp | 2 +- libsrc/visualization/vssolution.cpp | 18 +++++------ 21 files changed, 92 insertions(+), 92 deletions(-) diff --git a/libsrc/csg/csgeom.cpp b/libsrc/csg/csgeom.cpp index bc1c3539..2d222ce5 100644 --- a/libsrc/csg/csgeom.cpp +++ b/libsrc/csg/csgeom.cpp @@ -1148,7 +1148,7 @@ namespace netgen //return; int pinds[6]; - ArrayMem surfused(GetNSurf()); + NgArrayMem surfused(GetNSurf()); ReducePrimitiveIterator rpi(box); UnReducePrimitiveIterator urpi; diff --git a/libsrc/csg/specpoin.cpp b/libsrc/csg/specpoin.cpp index 1bdd5015..9069f36c 100644 --- a/libsrc/csg/specpoin.cpp +++ b/libsrc/csg/specpoin.cpp @@ -211,7 +211,7 @@ namespace netgen bool surecrossp = 0, sureexp = 0; // sure ... // static NgArray locsurf; // attention: array is static - ArrayMem locsurf; + NgArrayMem locsurf; // static int cntbox = 0; // cntbox++; diff --git a/libsrc/general/ngarray.hpp b/libsrc/general/ngarray.hpp index 9637e50f..e819fcc2 100644 --- a/libsrc/general/ngarray.hpp +++ b/libsrc/general/ngarray.hpp @@ -458,7 +458,7 @@ namespace netgen template - class ArrayMem : public NgArray + class NgArrayMem : public NgArray { using NgArray::size; using NgArray::data; @@ -469,7 +469,7 @@ namespace netgen // double mem[(S*sizeof(T)+7) / 8]; public: /// Generate array of logical and physical size asize - explicit ArrayMem(size_t asize = 0) + explicit NgArrayMem(size_t asize = 0) : NgArray (S, static_cast (static_cast(&mem[0]))) { size = asize; @@ -481,14 +481,14 @@ namespace netgen // SetSize (asize); } - ArrayMem & operator= (const T & val) + NgArrayMem & operator= (const T & val) { NgArray::operator= (val); return *this; } /// array copy - ArrayMem & operator= (const NgFlatArray & a2) + NgArrayMem & operator= (const NgFlatArray & a2) { this->SetSize (a2.Size()); for (size_t i = 0; i < size; i++) diff --git a/libsrc/gprim/adtree.cpp b/libsrc/gprim/adtree.cpp index 78cd43f2..9e4fc5e3 100644 --- a/libsrc/gprim/adtree.cpp +++ b/libsrc/gprim/adtree.cpp @@ -1704,7 +1704,7 @@ namespace netgen { // static NgArray stack(10000); // stack.SetSize (10000); - ArrayMem stack(10000); + NgArrayMem stack(10000); pis.SetSize(0); stack[0].node = root; @@ -1924,7 +1924,7 @@ namespace netgen { // static NgArray stack(10000); // stack.SetSize (10000); - ArrayMem,10000> stack(10000); + NgArrayMem,10000> stack(10000); pis.SetSize(0); stack[0].node = root; diff --git a/libsrc/interface/nginterface.cpp b/libsrc/interface/nginterface.cpp index a8ff165b..1896583a 100644 --- a/libsrc/interface/nginterface.cpp +++ b/libsrc/interface/nginterface.cpp @@ -1581,7 +1581,7 @@ int Ng_GetSurfaceElement_Face (int selnr, int * orient) int Ng_GetFace_Vertices (int fnr, int * vert) { const MeshTopology & topology = mesh->GetTopology(); - ArrayMem ia; + NgArrayMem ia; topology.GetFaceVertices (fnr, ia); for (int i = 0; i < ia.Size(); i++) vert[i] = ia[i]; @@ -1593,7 +1593,7 @@ int Ng_GetFace_Vertices (int fnr, int * vert) int Ng_GetFace_Edges (int fnr, int * edge) { const MeshTopology & topology = mesh->GetTopology(); - ArrayMem ia; + NgArrayMem ia; topology.GetFaceEdges (fnr, ia); for (int i = 0; i < ia.Size(); i++) edge[i] = ia[i]; @@ -1928,7 +1928,7 @@ int Ng_IsRunning() int Ng_GetVertex_Elements( int vnr, int* elems ) { const MeshTopology& topology = mesh->GetTopology(); - ArrayMem indexArray; + NgArrayMem indexArray; topology.GetVertexElements( vnr, indexArray ); for( int i=0; iGetTopology(); - ArrayMem indexArray; + NgArrayMem indexArray; topology.GetVertexSurfaceElements( vnr, indexArray ); for( int i=0; iGetTopology(); - ArrayMem indexArray; + NgArrayMem indexArray; topology.GetVertexElements( vnr, indexArray ); return indexArray.Size(); @@ -1991,7 +1991,7 @@ int Ng_GetVertex_NSurfaceElements( int vnr ) case 3: { const MeshTopology& topology = mesh->GetTopology(); - ArrayMem indexArray; + NgArrayMem indexArray; topology.GetVertexSurfaceElements( vnr, indexArray ); return indexArray.Size(); } diff --git a/libsrc/interface/nginterface_v2.cpp b/libsrc/interface/nginterface_v2.cpp index 68618f54..1d8f9366 100644 --- a/libsrc/interface/nginterface_v2.cpp +++ b/libsrc/interface/nginterface_v2.cpp @@ -756,7 +756,7 @@ namespace netgen Ng_BufferMS Ngx_Mesh::GetFaceEdges (int fnr) const { const MeshTopology & topology = mesh->GetTopology(); - ArrayMem ia; + NgArrayMem ia; topology.GetFaceEdges (fnr+1, ia); Ng_BufferMS res(ia.Size()); for (size_t i = 0; i < ia.Size(); i++) diff --git a/libsrc/meshing/adfront2.cpp b/libsrc/meshing/adfront2.cpp index 0eb86f11..e4e6bda2 100644 --- a/libsrc/meshing/adfront2.cpp +++ b/libsrc/meshing/adfront2.cpp @@ -290,8 +290,8 @@ namespace netgen loclines.Append(lines[baselineindex].L()); lindex.Append(baselineindex); - ArrayMem nearlines(0); - ArrayMem nearpoints(0); + NgArrayMem nearlines(0); + NgArrayMem nearpoints(0); // dominating costs !! linesearchtree.GetIntersecting (p0 - Vec3d(xh, xh, xh), diff --git a/libsrc/meshing/adfront3.cpp b/libsrc/meshing/adfront3.cpp index 8a3021f4..506c8660 100644 --- a/libsrc/meshing/adfront3.cpp +++ b/libsrc/meshing/adfront3.cpp @@ -845,7 +845,7 @@ int AdFront3 :: SameSide (const Point<3> & lp1, const Point<3> & lp2, pmin.SetToMin (lp2); pmax.SetToMax (lp2); - ArrayMem aprif; + NgArrayMem aprif; aprif.SetSize(0); if (!testfaces) diff --git a/libsrc/meshing/clusters.cpp b/libsrc/meshing/clusters.cpp index 32c43c71..86045061 100644 --- a/libsrc/meshing/clusters.cpp +++ b/libsrc/meshing/clusters.cpp @@ -141,7 +141,7 @@ namespace netgen (tm, nse, [&] (size_t begin, size_t end) { - ArrayMem nnums, ednums; + NgArrayMem nnums, ednums; for (int i = begin+1; i <= end; i++) { const Element2d & el = mesh.SurfaceElement(i); diff --git a/libsrc/meshing/curvedelems.cpp b/libsrc/meshing/curvedelems.cpp index 3040846f..77a06f72 100644 --- a/libsrc/meshing/curvedelems.cpp +++ b/libsrc/meshing/curvedelems.cpp @@ -1216,7 +1216,7 @@ namespace netgen // if (el.GetType() == TRIG && order >= 3) if (top.GetFaceType(facenr+1) == TRIG && order >= 3) { - ArrayMem verts(3); + NgArrayMem verts(3); top.GetFaceVertices (facenr+1, verts); int fnums[] = { 0, 1, 2 }; @@ -1467,10 +1467,10 @@ namespace netgen info.ndof += edgeorder[info.edgenr]-1; } - ArrayMem,100> coefs(info.ndof); - ArrayMem shapes_mem(info.ndof); + NgArrayMem,100> coefs(info.ndof); + NgArrayMem shapes_mem(info.ndof); TFlatVector shapes(info.ndof, &shapes_mem[0]); - ArrayMem dshapes_mem(info.ndof); + NgArrayMem dshapes_mem(info.ndof); TFlatVector dshapes(info.ndof, &dshapes_mem[0]); @@ -1778,10 +1778,10 @@ namespace netgen } - ArrayMem,100> coefs(info.ndof); - ArrayMem shapes_mem(info.ndof); + NgArrayMem,100> coefs(info.ndof); + NgArrayMem shapes_mem(info.ndof); TFlatVector shapes(info.ndof, &shapes_mem[0]); - ArrayMem dshapes_mem(2*info.ndof); + NgArrayMem dshapes_mem(2*info.ndof); MatrixFixWidth<2> dshapes(info.ndof, &dshapes_mem[0]); @@ -2175,7 +2175,7 @@ namespace netgen { -1, 1 } }; // double hshapes[20], hdshapes[20]; - ArrayMem hshapes(order+1), hdshapes(order+1); + NgArrayMem hshapes(order+1), hdshapes(order+1); int ii = 4; const ELEMENT_EDGE * edges = MeshTopology::GetEdges1 (QUAD); @@ -2588,9 +2588,9 @@ namespace netgen } } - ArrayMem mem(info.ndof); + NgArrayMem mem(info.ndof); TFlatVector shapes(info.ndof, &mem[0]); - ArrayMem dshapes_mem(info.ndof*3); + NgArrayMem dshapes_mem(info.ndof*3); MatrixFixWidth<3> dshapes(info.ndof, &dshapes_mem[0]); CalcElementShapes (info, xi, shapes); @@ -3248,7 +3248,7 @@ namespace netgen vi1 = vi1 % 3; vi2 = vi2 % 3; - ArrayMem shapei_mem(order+1); + NgArrayMem shapei_mem(order+1); TFlatVector shapei(order+1, &shapei_mem[0]); CalcScaledEdgeShapeDxDt<3> (order, lami[vi1]-lami[vi2], lami[vi1]+lami[vi2], &dshapes(ii,0) ); CalcScaledEdgeShape(order, lami[vi1]-lami[vi2], lami[vi1]+lami[vi2], &shapei(0) ); @@ -3331,8 +3331,8 @@ namespace netgen if(el[fav[1]] > el[fav[2]]) swap(fav[1],fav[2]); if(el[fav[0]] > el[fav[1]]) swap(fav[0],fav[1]); - ArrayMem dshapei_mem(ndf); - ArrayMem shapei_mem(ndf); + NgArrayMem dshapei_mem(ndf); + NgArrayMem shapei_mem(ndf); MatrixFixWidth<2,T> dshapei(ndf, &dshapei_mem[0]); TFlatVector shapei(ndf, &shapei_mem[0]); @@ -3472,7 +3472,7 @@ namespace netgen int vi1 = (edges[i][0]-1), vi2 = (edges[i][1]-1); if (el[vi1] > el[vi2]) swap (vi1, vi2); - ArrayMem shapei_mem(eorder+1); + NgArrayMem shapei_mem(eorder+1); TFlatVector shapei(eorder+1,&shapei_mem[0]); CalcScaledEdgeShapeDxDt<3> (eorder, sigma[vi1]-sigma[vi2], 1-z, &dshapes(ii,0) ); CalcScaledEdgeShape(eorder, sigma[vi1]-sigma[vi2], 1-z, &shapei(0) ); @@ -3633,7 +3633,7 @@ namespace netgen { -1, 1, 1 } }; - ArrayMem hshapes(order+1), hdshapes(order+1); + NgArrayMem hshapes(order+1), hdshapes(order+1); int ii = 8; const ELEMENT_EDGE * edges = MeshTopology::GetEdges1 (HEX); @@ -4062,7 +4062,7 @@ namespace netgen T lami[4]; TFlatVector vlami(4, lami); - ArrayMem, 50> coarse_xi (npts); + NgArrayMem, 50> coarse_xi (npts); for (int pi = 0; pi < npts; pi++) { @@ -4216,13 +4216,13 @@ namespace netgen // THESE LAST LINES ARE COPIED FROM CurvedElements::CalcSurfaceTransformation - ArrayMem,100> coefs(info.ndof); + NgArrayMem,100> coefs(info.ndof); GetCoefficients (info, coefs); - ArrayMem shapes_mem(info.ndof); + NgArrayMem shapes_mem(info.ndof); TFlatVector shapes(info.ndof, &shapes_mem[0]); - ArrayMem dshapes_mem(info.ndof*2); + NgArrayMem dshapes_mem(info.ndof*2); MatrixFixWidth<2,T> dshapes(info.ndof,&shapes_mem[0]); @@ -4368,7 +4368,7 @@ namespace netgen FlatVector vlami(8, lami); - ArrayMem, 50> coarse_xi (xi->Size()); + NgArrayMem, 50> coarse_xi (xi->Size()); for (int pi = 0; pi < xi->Size(); pi++) { @@ -4527,7 +4527,7 @@ namespace netgen TFlatVector vlami(8, &lami[0]); - ArrayMem coarse_xi (3*n); + NgArrayMem coarse_xi (3*n); for (int pi = 0; pi < n; pi++) { @@ -4645,12 +4645,12 @@ namespace netgen } if (ok) return; - ArrayMem,100> coefs(info.ndof); - ArrayMem shapes_mem(info.ndof); + NgArrayMem,100> coefs(info.ndof); + NgArrayMem shapes_mem(info.ndof); TFlatVector shapes(info.ndof, &shapes_mem[0]); - ArrayMem dshapes_mem(3*info.ndof); + NgArrayMem dshapes_mem(3*info.ndof); MatrixFixWidth<3,T> dshapes(info.ndof, &dshapes_mem[0]); // NgProfiler::StopTimer (timer3); diff --git a/libsrc/meshing/curvedelems.hpp b/libsrc/meshing/curvedelems.hpp index e774fe58..f0d5d21c 100644 --- a/libsrc/meshing/curvedelems.hpp +++ b/libsrc/meshing/curvedelems.hpp @@ -224,7 +224,7 @@ private: int order; int nv; int ndof; - ArrayMem edgenrs; + NgArrayMem edgenrs; int facenr; }; diff --git a/libsrc/meshing/improve3.cpp b/libsrc/meshing/improve3.cpp index 0c43ef9c..98400ded 100644 --- a/libsrc/meshing/improve3.cpp +++ b/libsrc/meshing/improve3.cpp @@ -1182,8 +1182,8 @@ void MeshOptimize3d :: SwapImprove (Mesh & mesh, OPTIMIZEGOAL goal, { Element hel(TET); - ArrayMem suroundpts(nsuround); - ArrayMem tetused(nsuround); + NgArrayMem suroundpts(nsuround); + NgArrayMem tetused(nsuround); Element & elem = mesh[hasbothpoints[0]]; diff --git a/libsrc/meshing/localh.cpp b/libsrc/meshing/localh.cpp index 48919975..d8445b11 100644 --- a/libsrc/meshing/localh.cpp +++ b/libsrc/meshing/localh.cpp @@ -449,9 +449,9 @@ namespace netgen Box3d boxcfc(c,fc); - ArrayMem faceused; - ArrayMem faceused2; - ArrayMem facenotused; + NgArrayMem faceused; + NgArrayMem faceused2; + NgArrayMem facenotused; /* faceused.SetSize(0); @@ -606,9 +606,9 @@ namespace netgen Box3d fboxc(fc-fv, fc+fv); Box3d boxcfc(c,fc); - ArrayMem faceused; - ArrayMem faceused2; - ArrayMem facenotused; + NgArrayMem faceused; + NgArrayMem faceused2; + NgArrayMem facenotused; for (int j = 0; j < nfinbox; j++) { diff --git a/libsrc/meshing/meshtype.cpp b/libsrc/meshing/meshtype.cpp index f32714c5..32402d43 100644 --- a/libsrc/meshing/meshtype.cpp +++ b/libsrc/meshing/meshtype.cpp @@ -2146,7 +2146,7 @@ namespace netgen { int np = GetNP(); double eps = 1e-6; - ArrayMem mem(2*np); + NgArrayMem mem(2*np); TFlatVector shaper(np, &mem[0]); TFlatVector shapel(np, &mem[np]); // Vector shaper(np), shapel(np); diff --git a/libsrc/meshing/netrule3.cpp b/libsrc/meshing/netrule3.cpp index 753abbb0..b45de522 100644 --- a/libsrc/meshing/netrule3.cpp +++ b/libsrc/meshing/netrule3.cpp @@ -201,7 +201,7 @@ int vnetrule :: IsTriangleInFreeZone (const Point3d & p1, int infreeset, cannot = 0; - ArrayMem pfi(3), pfi2(3); + NgArrayMem pfi(3), pfi2(3); // convert from local index to freeset index int i, j; @@ -868,7 +868,7 @@ int vnetrule :: IsQuadInFreeZone (const Point3d & p1, int infreeset, cannot = 0; - ArrayMem pfi(4), pfi2(4); + NgArrayMem pfi(4), pfi2(4); // convert from local index to freeset index int i, j; @@ -931,7 +931,7 @@ int vnetrule :: IsQuadInFreeSet (const Point3d & p1, const Point3d & p2, return 1; } - ArrayMem pi3(3); + NgArrayMem pi3(3); int res; pi3.Elem(1) = pi.Get(1); diff --git a/libsrc/meshing/refine.cpp b/libsrc/meshing/refine.cpp index ca7f737b..7b0e2c3c 100644 --- a/libsrc/meshing/refine.cpp +++ b/libsrc/meshing/refine.cpp @@ -192,8 +192,8 @@ namespace netgen case TRIG: case TRIG6: { - ArrayMem pnums(6); - ArrayMem pgis(6); + NgArrayMem pnums(6); + NgArrayMem pgis(6); static int betw[3][3] = { { 2, 3, 4 }, @@ -275,8 +275,8 @@ namespace netgen case QUAD6: case QUAD8: { - ArrayMem pnums(9); - ArrayMem pgis(9); + NgArrayMem pnums(9); + NgArrayMem pgis(9); static int betw[5][3] = { { 1, 2, 5 }, @@ -367,7 +367,7 @@ namespace netgen case TET: case TET10: { - ArrayMem pnums(10); + NgArrayMem pnums(10); static int betw[6][3] = { { 1, 2, 5 }, { 1, 3, 6 }, @@ -458,7 +458,7 @@ namespace netgen } case HEX: { - ArrayMem pnums(27); + NgArrayMem pnums(27); static int betw[13][3] = { { 1, 2, 9 }, { 3, 4, 10 }, @@ -584,7 +584,7 @@ namespace netgen } case PRISM: { - ArrayMem pnums(18); + NgArrayMem pnums(18); static int betw[9][3] = { { 3, 1, 7 }, { 1, 2, 8 }, diff --git a/libsrc/meshing/ruler2.cpp b/libsrc/meshing/ruler2.cpp index ae9f267a..b37c3b1b 100644 --- a/libsrc/meshing/ruler2.cpp +++ b/libsrc/meshing/ruler2.cpp @@ -66,15 +66,15 @@ namespace netgen int noldll = llines1.Size(); - ArrayMem pused(maxlegalpoint), lused(maxlegalline); - ArrayMem pnearness(noldlp), lnearness(llines1.Size()); + NgArrayMem pused(maxlegalpoint), lused(maxlegalline); + NgArrayMem pnearness(noldlp), lnearness(llines1.Size()); - ArrayMem pmap, pfixed, lmap; + NgArrayMem pmap, pfixed, lmap; - ArrayMem tempnewpoints; - ArrayMem tempnewlines; - ArrayMem tempdellines; - ArrayMem tempelements; + NgArrayMem tempnewpoints; + NgArrayMem tempnewlines; + NgArrayMem tempdellines; + NgArrayMem tempelements; elements.SetSize (0); diff --git a/libsrc/meshing/ruler3.cpp b/libsrc/meshing/ruler3.cpp index 42f87a22..a853de03 100644 --- a/libsrc/meshing/ruler3.cpp +++ b/libsrc/meshing/ruler3.cpp @@ -79,19 +79,19 @@ int Meshing3 :: ApplyRules NgArray pused; // point is already mapped, number of uses - ArrayMem fused; // face is already mapped - ArrayMem pmap; // map of reference point to local point - ArrayMem pfixed; // point mapped by face-map - ArrayMem fmapi; // face in reference is mapped to face nr ... - ArrayMem fmapr; // face in reference is rotated to map - ArrayMem transfreezone; // transformed free-zone + NgArrayMem fused; // face is already mapped + NgArrayMem pmap; // map of reference point to local point + NgArrayMem pfixed; // point mapped by face-map + NgArrayMem fmapi; // face in reference is mapped to face nr ... + NgArrayMem fmapr; // face in reference is rotated to map + NgArrayMem transfreezone; // transformed free-zone INDEX_2_CLOSED_HASHTABLE ledges(100); // edges in local environment - ArrayMem tempnewpoints; + NgArrayMem tempnewpoints; NgArray tempnewfaces; - ArrayMem tempdelfaces; + NgArrayMem tempdelfaces; NgArray tempelements; - ArrayMem triboxes; // bounding boxes of local faces + NgArrayMem triboxes; // bounding boxes of local faces NgArray pnearness; NgArray fnearness; diff --git a/libsrc/meshing/topology.cpp b/libsrc/meshing/topology.cpp index a2075176..850ab808 100644 --- a/libsrc/meshing/topology.cpp +++ b/libsrc/meshing/topology.cpp @@ -1800,8 +1800,8 @@ namespace netgen void MeshTopology :: GetFaceEdges (int fnr, NgArray & fedges, bool withorientation) const { - ArrayMem pi(4); - ArrayMem eledges; + NgArrayMem pi(4); + NgArrayMem eledges; fedges.SetSize (0); GetFaceVertices(fnr, pi); @@ -1812,7 +1812,7 @@ namespace netgen // e3 = op e1(f2,f3) // e4 = op e2(f1,f3) - /* ArrayMem fp; + /* NgArrayMem fp; fp[0] = pi[0]; for(int k=1;kfp[0]) swap(fp[k],fp[0]); diff --git a/libsrc/stlgeom/stltool.cpp b/libsrc/stlgeom/stltool.cpp index 683fdc83..5a2eb61e 100644 --- a/libsrc/stlgeom/stltool.cpp +++ b/libsrc/stlgeom/stltool.cpp @@ -1308,7 +1308,7 @@ int STLBoundary :: TestSegChartNV(const Point3d & p1, const Point3d& p2, { // NgProfiler::RegionTimer reg(timerquick); - ArrayMem pis; + NgArrayMem pis; searchtree -> GetIntersecting (box2d.PMin(), box2d.PMax(), pis); for (auto i2 : pis) diff --git a/libsrc/visualization/vssolution.cpp b/libsrc/visualization/vssolution.cpp index 5faf42e6..93245546 100644 --- a/libsrc/visualization/vssolution.cpp +++ b/libsrc/visualization/vssolution.cpp @@ -1852,8 +1852,8 @@ namespace netgen CurvedElements & curv = mesh->GetCurvedElements(); int n = 1 << subdivisions; - ArrayMem, 65> ptsloc(n+1); - ArrayMem, 65> ptsglob(n+1); + NgArrayMem, 65> ptsloc(n+1); + NgArrayMem, 65> ptsglob(n+1); double trigpts[3][2] = { { 0, 0 }, { 0, 1 }, { 1, 0} }; double trigvecs[3][2] = { { 1, 0 }, { 0, -1 }, { -1, 1} }; @@ -2829,7 +2829,7 @@ namespace netgen if (comp == 0) { - ArrayMem values(data->components); + NgArrayMem values(data->components); ok = GetValues (data, elnr, xref, x, dxdxref, &values[0]); val = ExtractValue (data, 0, &values[0]); @@ -3000,7 +3000,7 @@ namespace netgen if (comp == 0) { - ArrayMem values(data->components); + NgArrayMem values(data->components); ok = GetValues (data, elnr, lam1, lam2, lam3, &values[0]); val = ExtractValue (data, 0, &values[0]); return ok; @@ -3383,7 +3383,7 @@ namespace netgen { case SOL_VIRTUALFUNCTION: { - ArrayMem values(data->components); + NgArrayMem values(data->components); bool ok; ok = data->solclass->GetSurfValue (selnr, facetnr, lam1, lam2, &values[0]); @@ -3413,7 +3413,7 @@ namespace netgen if (comp == 0) { val = 0; - ArrayMem values(data->components); + NgArrayMem values(data->components); ok = GetSurfValues (data, selnr, facetnr, lam1, lam2, &values[0]); val = ExtractValue (data, 0, &values[0]); return ok; @@ -3425,7 +3425,7 @@ namespace netgen case SOL_VIRTUALFUNCTION: { - ArrayMem values(data->components); + NgArrayMem values(data->components); bool ok; ok = data->solclass->GetSurfValue (selnr, facetnr, lam1, lam2, &values[0]); @@ -3655,7 +3655,7 @@ namespace netgen if (comp == 0) { val = 0; - ArrayMem values(data->components); + NgArrayMem values(data->components); ok = GetSurfValues (data, selnr, facetnr, xref, x, dxdxref, &values[0]); val = ExtractValue (data, 0, &values[0]); return ok; @@ -3666,7 +3666,7 @@ namespace netgen { case SOL_VIRTUALFUNCTION: { - ArrayMem values(data->components); + NgArrayMem values(data->components); bool ok; // ok = data->solclass->GetSurfValue (selnr, lam1, lam2, &values[0]); From 05aafdc3b6470f6e28c86173125ae190b781fb37 Mon Sep 17 00:00:00 2001 From: Matthias Hochsteger Date: Tue, 9 Jul 2019 18:07:19 +0200 Subject: [PATCH 06/11] Add LocalHeap, some NGCORE_API --- libsrc/core/CMakeLists.txt | 12 +- libsrc/core/array.hpp | 84 +++++----- libsrc/core/localheap.cpp | 72 ++++++++ libsrc/core/localheap.hpp | 318 ++++++++++++++++++++++++++++++++++++ libsrc/core/ngcore.hpp | 1 + libsrc/core/taskmanager.hpp | 48 +++--- 6 files changed, 468 insertions(+), 67 deletions(-) create mode 100644 libsrc/core/localheap.cpp create mode 100644 libsrc/core/localheap.hpp diff --git a/libsrc/core/CMakeLists.txt b/libsrc/core/CMakeLists.txt index 13ebaec5..74a470ef 100644 --- a/libsrc/core/CMakeLists.txt +++ b/libsrc/core/CMakeLists.txt @@ -1,5 +1,13 @@ -add_library(ngcore SHARED archive.cpp logging.cpp paje_trace.cpp utils.cpp profiler.cpp taskmanager.cpp) +add_library(ngcore SHARED + archive.cpp + localheap.cpp + logging.cpp + paje_trace.cpp + profiler.cpp + taskmanager.cpp + utils.cpp + ) target_compile_definitions(ngcore PRIVATE NGCORE_EXPORTS) if(NOT WIN32) @@ -34,7 +42,7 @@ endif(USE_PYTHON) install(FILES ngcore.hpp archive.hpp type_traits.hpp version.hpp ngcore_api.hpp logging.hpp exception.hpp symboltable.hpp paje_trace.hpp utils.hpp profiler.hpp mpi_wrapper.hpp - array.hpp taskmanager.hpp concurrentqueue.h + array.hpp taskmanager.hpp concurrentqueue.h localheap.hpp DESTINATION ${NG_INSTALL_DIR_INCLUDE}/core COMPONENT netgen_devel) if(ENABLE_CPP_CORE_GUIDELINES_CHECK) diff --git a/libsrc/core/array.hpp b/libsrc/core/array.hpp index e1f6d006..e1aabdc1 100644 --- a/libsrc/core/array.hpp +++ b/libsrc/core/array.hpp @@ -8,6 +8,8 @@ /**************************************************************************/ +#include "archive.hpp" +#include "localheap.hpp" #include "utils.hpp" #ifdef DEBUG @@ -415,14 +417,14 @@ namespace ngcore NETGEN_INLINE FlatArray (size_t asize, T * adata) : size(asize), data(adata) { ; } -// /// memory from local heap -// NETGEN_INLINE FlatArray(size_t asize, Allocator & lh) -// : size(asize), data(new (lh) T[asize]) -// { ; } -// -// NETGEN_INLINE FlatArray(size_t asize, LocalHeap & lh) -// : size(asize), data (lh.Alloc (asize)) -// { ; } + /// memory from local heap + NETGEN_INLINE FlatArray(size_t asize, Allocator & lh) + : size(asize), data(new (lh) T[asize]) + { ; } + + NETGEN_INLINE FlatArray(size_t asize, LocalHeap & lh) + : size(asize), data (lh.Alloc (asize)) + { ; } /// the size NETGEN_INLINE size_t Size() const { return size; } @@ -475,13 +477,13 @@ namespace ngcore return *this; } -// /// assigns memory from local heap -// NETGEN_INLINE const FlatArray & Assign (size_t asize, LocalHeap & lh) -// { -// size = asize; -// data = lh.Alloc (asize); -// return *this; -// } + /// assigns memory from local heap + NETGEN_INLINE const FlatArray & Assign (size_t asize, LocalHeap & lh) + { + size = asize; + data = lh.Alloc (asize); + return *this; + } /// Access array. range check by macro CHECK_RANGE NETGEN_INLINE T & operator[] (size_t i) const @@ -721,20 +723,20 @@ namespace ngcore delete [] mem_to_delete; } -// // Only provide this function if T is archivable -// template -// auto DoArchive(Archive& archive) -> typename std::enable_if_t, void> -// { -// if(archive.Output()) -// archive << size; -// else -// { -// size_t s; -// archive & s; -// SetSize(s); -// } -// archive.Do(data, size); -// } + // Only provide this function if T is archivable + template + auto DoArchive(Archive& archive) -> typename std::enable_if_t, void> + { + if(archive.Output()) + archive << size; + else + { + size_t s; + archive & s; + SetSize(s); + } + archive.Do(data, size); + } /// we tell the compiler that there is no need for deleting the array .. NETGEN_INLINE void NothingToDelete () @@ -769,15 +771,15 @@ namespace ngcore } -// /// assigns memory from local heap -// NETGEN_INLINE const Array & Assign (size_t asize, LocalHeap & lh) -// { -// delete [] mem_to_delete; -// size = allocsize = asize; -// data = lh.Alloc (asize); -// mem_to_delete = nullptr; -// return *this; -// } + /// assigns memory from local heap + NETGEN_INLINE const Array & Assign (size_t asize, LocalHeap & lh) + { + delete [] mem_to_delete; + size = allocsize = asize; + data = lh.Alloc (asize); + mem_to_delete = nullptr; + return *this; + } /// Add element at end of array. reallocation if necessary. NETGEN_INLINE size_t Append (const T & el) @@ -803,7 +805,7 @@ namespace ngcore { if (size == allocsize) ReSize (size+1); - data[size] = move(el); + data[size] = std::move(el); size++; return size; } @@ -1011,12 +1013,12 @@ namespace ngcore { size_t mins = (nsize < size) ? nsize : size; #if defined(__GNUG__) && __GNUC__ < 5 && !defined(__clang__) - for (size_t i = 0; i < mins; i++) data[i] = move(hdata[i]); + for (size_t i = 0; i < mins; i++) data[i] = std::move(hdata[i]); #else if (std::is_trivially_copyable::value) memcpy ((void*)data, hdata, sizeof(T)*mins); else - for (size_t i = 0; i < mins; i++) data[i] = move(hdata[i]); + for (size_t i = 0; i < mins; i++) data[i] = std::move(hdata[i]); #endif delete [] mem_to_delete; } diff --git a/libsrc/core/localheap.cpp b/libsrc/core/localheap.cpp new file mode 100644 index 00000000..5706a07e --- /dev/null +++ b/libsrc/core/localheap.cpp @@ -0,0 +1,72 @@ +/**************************************************************************/ +/* File: localheap.cpp */ +/* Author: Joachim Schoeberl */ +/* Date: 19. Apr. 2002 */ +/**************************************************************************/ + +#include +#include + +#include "localheap.hpp" +#include "taskmanager.hpp" + +namespace ngcore +{ + + LocalHeap :: LocalHeap (size_t asize, const char * aname, bool mult_by_threads) + { + if (mult_by_threads) + asize *= TaskManager::GetMaxThreads(); + totsize = asize; + try + { + data = new char[asize]; + } + catch (std::exception & e) + { + throw Exception (ToString ("Could not allocate localheap, heapsize = ") + ToString(asize)); + } + + next = data + totsize; + p = data; + owner = true; + name = aname; + CleanUp(); // align pointer + } + + LocalHeap LocalHeap :: Split() const + { + int pieces = TaskManager::GetNumThreads(); + int i = TaskManager::GetThreadId(); + size_t freemem = totsize - (p - data); + size_t size_of_piece = freemem / pieces; + return LocalHeap (p + i * size_of_piece, size_of_piece, name); + } + + void LocalHeap :: ThrowException() // throw (LocalHeapOverflow) + { + /* + cout << "allocated: " << (p-data) << endl; + cout << "throw LocalHeapOverflow, totsize = "<< totsize << endl; + cout << "heap name = " << name << endl; + */ + throw LocalHeapOverflow(totsize); + } + + + LocalHeapOverflow :: LocalHeapOverflow (size_t size) + : Exception("Local Heap overflow\n") + { + std::stringstream str; + str << "Current heapsize is " << size << '\n'; + Append (str.str()); + // Append ("please use 'define constant heapsize = xxx' with larger value\n"); + } + + LocalHeapOverflow :: ~LocalHeapOverflow () + { + ; + } + +} + diff --git a/libsrc/core/localheap.hpp b/libsrc/core/localheap.hpp new file mode 100644 index 00000000..75de3c87 --- /dev/null +++ b/libsrc/core/localheap.hpp @@ -0,0 +1,318 @@ +#ifndef NETGEN_CORE_LOCALHEAP_HPP +#define NETGEN_CORE_LOCALHEAP_HPP + +/**************************************************************************/ +/* File: localheap.hpp */ +/* Author: Joachim Schoeberl */ +/* Date: 19. Apr. 2000 */ +/**************************************************************************/ + +#include + +#include "exception.hpp" +#include "ngcore_api.hpp" +#include "utils.hpp" + +namespace ngcore +{ + +class Allocator +{ +public: + virtual ~Allocator() {} + virtual void * Alloc (size_t size) + { + return new char[size]; + } + virtual void Delete(void* p) + { + delete (char*) p; + } + virtual void ArrayDelete(void* p) + { + delete [] (char*) p; + } +}; +static Allocator global_alloc; + +/** + Exception on heap overflow. + Thrown by allocation on LocalHeap. +*/ +class NGCORE_API LocalHeapOverflow : public Exception +{ +public: + LocalHeapOverflow (size_t size); + virtual ~LocalHeapOverflow (); +}; + + + +/** + Optimized memory handler. + One block of data is organized as stack memory. + One can allocate memory out of it. This increases the stack pointer. + With \Ref{CleanUp}, the pointer is reset to the beginning or to a + specific position. +*/ +class LocalHeap : public Allocator +{ + char * data; + char * next; + char * p; + size_t totsize; +public: + bool owner; + const char * name; + +#if defined(__MIC__) || defined (__AVX512F__) + enum { ALIGN = 64 }; +#else + enum { ALIGN = 32 }; +#endif + +public: + /// Allocate one block of size asize. + NGCORE_API LocalHeap (size_t asize, + const char * aname = "noname", + bool mult_by_threads = false); + + /// Use provided memory for the LocalHeap + NETGEN_INLINE LocalHeap (char * adata, size_t asize, + const char * aname = "noname") throw () + { + totsize = asize; + data = adata; + next = data + totsize; + owner = 0; + // p = data; + name = aname; + CleanUp(); + } + + /* + /// Use provided memory for the LocalHeap + NETGEN_INLINE LocalHeap (const LocalHeap & lh2) + : data(lh2.data), p(lh2.p), totsize(lh2.totsize), owner(false), + name(lh2.name) + { + next = data + totsize; + } + */ + NETGEN_INLINE LocalHeap (const LocalHeap & lh2) = delete; + + NETGEN_INLINE LocalHeap (LocalHeap && lh2) + : data(lh2.data), p(lh2.p), totsize(lh2.totsize), owner(lh2.owner), + name(lh2.name) + { + next = data + totsize; + lh2.owner = false; + } + + NETGEN_INLINE LocalHeap Borrow() + { + return LocalHeap (p, Available()); + } + + + NETGEN_INLINE LocalHeap & operator= (LocalHeap && lh2) + { + if (owner) + delete [] data; + + data = lh2.data; + p = lh2.p; + totsize = lh2.totsize; + owner = lh2.owner; + name = lh2.name; + + next = data + totsize; + lh2.owner = false; + return *this; + } + + NETGEN_INLINE LocalHeap () + : data(nullptr), next(nullptr), p(nullptr), totsize(0), owner(false) { ; } + + + /// free memory + NETGEN_INLINE virtual ~LocalHeap () + { + if (owner) + delete [] data; + } + + /// delete all memory on local heap + NETGEN_INLINE void CleanUp() throw () + { + p = data; + // p += (16 - (long(p) & 15) ); + p += (ALIGN - (size_t(p) & (ALIGN-1) ) ); + } + + /// returns heap-pointer + NETGEN_INLINE void * GetPointer () throw () + { + return p; + } + + /// deletes memory back to heap-pointer + NETGEN_INLINE void CleanUp (void * addr) throw () + { + p = (char*)addr; + } + + /// allocates size bytes of memory from local heap + NETGEN_INLINE void * Alloc (size_t size) final // throw (LocalHeapOverflow) + { + char * oldp = p; + + // 16 byte alignment + size += (ALIGN - size % ALIGN); + p += size; + + // if ( size_t(p - data) >= totsize ) +#ifndef FULLSPEED + if (likely(p >= next)) + ThrowException(); +#endif + return oldp; + } + + /// allocates size objects of type T on local heap + template + NETGEN_INLINE T * Alloc (size_t size) // throw (LocalHeapOverflow) + { + char * oldp = p; + size *= sizeof (T); + + // 16 byte alignment + size += (ALIGN - size % ALIGN); + p += size; + +#ifndef FULLSPEED + if (likely(p >= next)) + ThrowException(); +#endif + + return reinterpret_cast (oldp); + } + + virtual void Delete(void* p) {} + + virtual void ArrayDelete(void* p) {} + private: + /// +#ifndef __CUDA_ARCH__ + [[noreturn]] NGCORE_API void ThrowException(); +#else + NETGEN_INLINE void ThrowException() { ; } +#endif + + public: + /// free memory (dummy function) + NETGEN_INLINE void Free (void * data) throw () + { + ; + } + + /// available memory on LocalHeap + NETGEN_INLINE size_t Available () const throw () { return (totsize - (p-data)); } + + /// Split free memory on heap into pieces for each thread + NGCORE_API LocalHeap Split () const; + + /// Split free memory on heap into pieces + NETGEN_INLINE LocalHeap Split (int partnr, int nparts) const + { + int pieces = nparts; + int i = partnr; + + size_t freemem = totsize - (p - data); + size_t size_of_piece = freemem / pieces; + return LocalHeap (p + i * size_of_piece, size_of_piece, name); + } + + + NETGEN_INLINE void ClearValues () + { + for (size_t i = 0; i < totsize; i++) data[i] = 47; + } + + NETGEN_INLINE size_t UsedSize () + { + for (size_t i = totsize-1; i != 0; i--) + if (data[i] != 47) return i; + return 0; + } + }; + + + + /** + Optimized memory handler. + Provides static memory for the local heap. The template argument specifies the size in number of chars. + */ + template + class LocalHeapMem : public LocalHeap + { + char mem[S]; + public: + NETGEN_INLINE LocalHeapMem (const char * aname) throw () : LocalHeap (mem, S, aname) { ; } + }; + + + + + + + + + /** + A reset for the heap-pointer of a LocalHeap.. + The constructor stores the heap-pointer, the constructor at the end of the regions resets the heap-pointer. + */ + class HeapReset + { + LocalHeap & lh; + void * pointer; + public: + /// + NETGEN_INLINE HeapReset (LocalHeap & alh) + : lh(alh), pointer (alh.GetPointer()) { ; } + + /// + NETGEN_INLINE ~HeapReset () + { + lh.CleanUp (pointer); + } + }; + +} + + + +NETGEN_INLINE void * operator new (size_t size, ngcore::Allocator & alloc) +{ + return alloc.Alloc(size); +} + +NETGEN_INLINE void * operator new [] (size_t size, ngcore::Allocator & alloc) +{ + return alloc.Alloc(size); +} + + +NETGEN_INLINE void operator delete (void * p, ngcore::Allocator & lh) +{ + lh.Delete(p); +} + +NETGEN_INLINE void operator delete [] (void * p, ngcore::Allocator & lh) +{ + lh.ArrayDelete(p); +} + + + +#endif // NETGEN_CORE_LOCALHEAP_HPP diff --git a/libsrc/core/ngcore.hpp b/libsrc/core/ngcore.hpp index 8685ced5..5de0bd20 100644 --- a/libsrc/core/ngcore.hpp +++ b/libsrc/core/ngcore.hpp @@ -4,6 +4,7 @@ #include "archive.hpp" #include "array.hpp" #include "exception.hpp" +#include "localheap.hpp" #include "logging.hpp" #include "mpi_wrapper.hpp" #include "profiler.hpp" diff --git a/libsrc/core/taskmanager.hpp b/libsrc/core/taskmanager.hpp index 0c64a242..e9056659 100644 --- a/libsrc/core/taskmanager.hpp +++ b/libsrc/core/taskmanager.hpp @@ -47,21 +47,21 @@ namespace ngcore atomic participate{0}; }; - static const function * func; - static const function * startup_function; - static const function * cleanup_function; - static atomic ntasks; - static Exception * ex; + NGCORE_API static const function * func; + NGCORE_API static const function * startup_function; + NGCORE_API static const function * cleanup_function; + NGCORE_API static atomic ntasks; + NGCORE_API static Exception * ex; - static atomic jobnr; + NGCORE_API static atomic jobnr; static atomic complete[8]; // max nodes static atomic done; static atomic active_workers; static atomic workers_on_node[8]; // max nodes // Array*> sync; - static int sleep_usecs; - static bool sleep; + NGCORE_API static int sleep_usecs; + NGCORE_API static bool sleep; static NodeData *nodedata[8]; @@ -80,12 +80,12 @@ namespace ngcore NGCORE_API static bool use_paje_trace; public: - TaskManager(); - ~TaskManager(); + NGCORE_API TaskManager(); + NGCORE_API ~TaskManager(); - void StartWorkers(); - void StopWorkers(); + NGCORE_API void StartWorkers(); + NGCORE_API void StopWorkers(); void SuspendWorkers(int asleep_usecs = 1000 ) { @@ -94,12 +94,12 @@ namespace ngcore } void ResumeWorkers() { sleep = false; } - static void SetNumThreads(int amax_threads); - static int GetMaxThreads() { return max_threads; } + NGCORE_API static void SetNumThreads(int amax_threads); + NGCORE_API static int GetMaxThreads() { return max_threads; } // static int GetNumThreads() { return task_manager ? task_manager->num_threads : 1; } - static int GetNumThreads() { return num_threads; } - static int GetThreadId() { return thread_id; } - int GetNumNodes() const { return num_nodes; } + NGCORE_API static int GetNumThreads() { return num_threads; } + NGCORE_API static int GetThreadId() { return thread_id; } + NGCORE_API int GetNumNodes() const { return num_nodes; } static void SetPajeTrace (bool use) { use_paje_trace = use; } @@ -112,9 +112,9 @@ namespace ngcore static void SetCleanupFunction () { cleanup_function = nullptr; } void Done() { done = true; } - void Loop(int thread_num); + NGCORE_API void Loop(int thread_num); - static std::list> Timing (); + NGCORE_API static std::list> Timing (); }; @@ -128,8 +128,8 @@ namespace ngcore NGCORE_API void RunWithTaskManager (function alg); // For Python context manager - int EnterTaskManager (); - void ExitTaskManager (int num_threads); + NGCORE_API int EnterTaskManager (); + NGCORE_API void ExitTaskManager (int num_threads); NETGEN_INLINE int TasksPerThread (int tpt) { @@ -888,7 +888,7 @@ public: void SetSize (size_t size) { - cerr << "************************* NumaDistArray::SetSize not overloaded" << endl; + std::cerr << "************************* NumaDistArray::SetSize not overloaded" << std::endl; Array::SetSize(size); } }; @@ -946,7 +946,7 @@ public: void SetSize (size_t size) { - cerr << "************************* NumaDistArray::SetSize not overloaded" << endl; + std::cerr << "************************* NumaDistArray::SetSize not overloaded" << std::endl; Array::SetSize(size); } }; @@ -995,7 +995,7 @@ public: void SetSize (size_t size) { - cerr << "************************* NumaDistArray::SetSize not overloaded" << endl; + std::cerr << "************************* NumaDistArray::SetSize not overloaded" << std::endl; Array::SetSize(size); } }; From b848bdc237d0f958800010bcadb663ae95cd8971 Mon Sep 17 00:00:00 2001 From: Matthias Hochsteger Date: Wed, 10 Jul 2019 10:56:55 +0200 Subject: [PATCH 07/11] Fix MPI build --- CMakeLists.txt | 13 ++++++++++--- libsrc/core/CMakeLists.txt | 1 + libsrc/core/mpi_wrapper.hpp | 7 ++++--- libsrc/core/taskmanager.cpp | 1 + libsrc/meshing/CMakeLists.txt | 2 +- 5 files changed, 17 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5527d2ba..ed6c3e55 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -287,13 +287,20 @@ if (USE_PYTHON) endif (USE_PYTHON) ####################################################################### +add_library(netgen_mpi INTERFACE) +add_library(netgen_metis INTERFACE) if (USE_MPI) find_package(MPI REQUIRED) + target_include_directories(netgen_mpi INTERFACE ${MPI_CXX_INCLUDE_PATH}) + target_link_libraries(netgen_mpi INTERFACE ${MPI_mpi_LIBRARY} ${MPI_CXX_LIBRARIES} ) + target_compile_definitions(netgen_mpi INTERFACE PARALLEL ) + find_package(METIS REQUIRED) - add_definitions(-DPARALLEL -DMETIS) - include_directories(${MPI_CXX_INCLUDE_PATH}) - include_directories(${METIS_INCLUDE_DIR}) + target_include_directories(netgen_metis INTERFACE ${METIS_INCLUDE_DIR}) + target_link_libraries(netgen_metis INTERFACE ${METIS_LIBRARY} ) + target_compile_definitions(netgen_metis INTERFACE METIS ) endif (USE_MPI) +install(TARGETS netgen_mpi netgen_metis ${NG_INSTALL_DIR}) ####################################################################### if (USE_OCC) diff --git a/libsrc/core/CMakeLists.txt b/libsrc/core/CMakeLists.txt index 74a470ef..a62c030c 100644 --- a/libsrc/core/CMakeLists.txt +++ b/libsrc/core/CMakeLists.txt @@ -39,6 +39,7 @@ if(USE_PYTHON) target_include_directories(ngcore PRIVATE ${PYTHON_INCLUDE_DIRS}) target_link_libraries(ngcore PRIVATE ${PYTHON_LIBRARIES}) endif(USE_PYTHON) +target_link_libraries(ngcore PUBLIC netgen_mpi) install(FILES ngcore.hpp archive.hpp type_traits.hpp version.hpp ngcore_api.hpp logging.hpp exception.hpp symboltable.hpp paje_trace.hpp utils.hpp profiler.hpp mpi_wrapper.hpp diff --git a/libsrc/core/mpi_wrapper.hpp b/libsrc/core/mpi_wrapper.hpp index 329fee57..b42c551e 100644 --- a/libsrc/core/mpi_wrapper.hpp +++ b/libsrc/core/mpi_wrapper.hpp @@ -6,6 +6,7 @@ #include #endif +#include "exception.hpp" namespace ngcore { @@ -191,7 +192,7 @@ namespace ngcore }; -#else +#else // PARALLEL class MPI_Comm { int nr; public: @@ -240,7 +241,7 @@ namespace ngcore void Bcast (T & s, int root = 0) const { ; } }; -#endif +#endif // PARALLEL @@ -252,5 +253,5 @@ namespace ngcore } -#endif +#endif // NGCORE_MPIWRAPPER_HPP diff --git a/libsrc/core/taskmanager.cpp b/libsrc/core/taskmanager.cpp index eca6e923..a411034b 100644 --- a/libsrc/core/taskmanager.cpp +++ b/libsrc/core/taskmanager.cpp @@ -10,6 +10,7 @@ #include #include "concurrentqueue.h" +#include "mpi_wrapper.hpp" #include "paje_trace.hpp" #include "profiler.hpp" #include "taskmanager.hpp" diff --git a/libsrc/meshing/CMakeLists.txt b/libsrc/meshing/CMakeLists.txt index 23f302a7..94268db0 100644 --- a/libsrc/meshing/CMakeLists.txt +++ b/libsrc/meshing/CMakeLists.txt @@ -23,7 +23,7 @@ endif(APPLE) target_link_libraries( mesh PUBLIC ngcore PRIVATE gprim la gen ) -target_link_libraries( mesh PRIVATE ${ZLIB_LIBRARIES} ${MPI_CXX_LIBRARIES} ${PYTHON_LIBRARIES} ${METIS_LIBRARY}) +target_link_libraries( mesh PRIVATE netgen_metis ${ZLIB_LIBRARIES} ${PYTHON_LIBRARIES} ) if(NOT WIN32) install( TARGETS mesh ${NG_INSTALL_DIR}) endif(NOT WIN32) From c3a7fc2aabeeefc6cbf6729cb67199bc6b91f1da Mon Sep 17 00:00:00 2001 From: Matthias Hochsteger Date: Wed, 10 Jul 2019 12:57:19 +0200 Subject: [PATCH 08/11] Switch to C++17 --- CMakeLists.txt | 4 ++-- libsrc/general/ngarray.hpp | 7 +------ 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ed6c3e55..2e899ac1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,7 +6,7 @@ if(WIN32) # we are linking to object libraries on Windows cmake_minimum_required(VERSION 3.12) else(WIN32) - cmake_minimum_required(VERSION 3.1.3) + cmake_minimum_required(VERSION 3.8) endif(WIN32) if(NOT WIN32) @@ -216,7 +216,7 @@ macro(get_dll_from_lib dll_path lib_path) get_filename_component(lib_name ${lib} name) endmacro() -set(CMAKE_CXX_STANDARD 14) +set(CMAKE_CXX_STANDARD 17) if(WIN32) get_WIN32_WINNT(ver) add_definitions(-D_WIN32_WINNT=${ver} -DWNT -DWNT_WINDOW -DNOMINMAX) diff --git a/libsrc/general/ngarray.hpp b/libsrc/general/ngarray.hpp index e819fcc2..2c4aed21 100644 --- a/libsrc/general/ngarray.hpp +++ b/libsrc/general/ngarray.hpp @@ -429,16 +429,11 @@ namespace netgen T * p = new T[nsize]; size_t mins = (nsize < size) ? nsize : size; - // memcpy (p, data, mins * sizeof(T)); -#if defined(__GNUG__) && __GNUC__ < 5 && !defined(__clang__) - for (size_t i = 0; i < mins; i++) p[i] = move(data[i]); -#else - if (std::is_trivially_copyable::value) + if constexpr(std::is_trivially_copyable::value) memcpy (p, data, sizeof(T)*mins); else for (size_t i = 0; i < mins; i++) p[i] = move(data[i]); -#endif if (ownmem) delete [] data; From 5fb91f26ed5ca964a105868fffa377efbb2a2b27 Mon Sep 17 00:00:00 2001 From: Matthias Hochsteger Date: Wed, 10 Jul 2019 13:21:57 +0200 Subject: [PATCH 09/11] User AlignedAlloc for over-aligned types MacOS < 10.13 doesn't support new with alignment>16 bytes --- CMakeLists.txt | 1 + libsrc/core/taskmanager.hpp | 4 ++-- libsrc/core/utils.hpp | 29 +++++++++++++++++++++++++++ libsrc/general/ngarray.hpp | 12 ++++++------ libsrc/general/ngsimd.hpp | 39 +++---------------------------------- 5 files changed, 41 insertions(+), 44 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2e899ac1..d573504d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -115,6 +115,7 @@ endif (ADDITIONAL_PATHS) ####################################################################### # build options include_directories ("${PROJECT_SOURCE_DIR}/include") +include_directories ("${PROJECT_SOURCE_DIR}/libsrc") include_directories ("${PROJECT_SOURCE_DIR}/libsrc/include") include_directories ("${PROJECT_BINARY_DIR}") diff --git a/libsrc/core/taskmanager.hpp b/libsrc/core/taskmanager.hpp index e9056659..059a1678 100644 --- a/libsrc/core/taskmanager.hpp +++ b/libsrc/core/taskmanager.hpp @@ -40,7 +40,7 @@ namespace ngcore { // PajeTrace *trace; - class alignas(64) NodeData //: public AlignedAlloc + class alignas(64) NodeData : public AlignedAlloc { public: atomic start_cnt{0}; @@ -390,7 +390,7 @@ public: - class alignas(4096) AtomicRange //: public AlignedAlloc + class alignas(4096) AtomicRange : public AlignedAlloc { atomic begin; atomic end; diff --git a/libsrc/core/utils.hpp b/libsrc/core/utils.hpp index 4dca6c8b..35877d42 100644 --- a/libsrc/core/utils.hpp +++ b/libsrc/core/utils.hpp @@ -74,6 +74,35 @@ namespace ngcore b = std::move(temp); } + template + class AlignedAlloc + { + protected: + static void * aligned_malloc(size_t s) + { + // Assume 16 byte alignment of standard library + if(alignof(T)<=16) + return malloc(s); + else + return _mm_malloc(s, alignof(T)); + } + + static void aligned_free(void *p) + { + if(alignof(T)<=16) + free(p); + else + _mm_free(p); + } + + public: + void * operator new (size_t s, void *p) { return p; } + void * operator new (size_t s) { return aligned_malloc(s); } + void * operator new[] (size_t s) { return aligned_malloc(s); } + void operator delete (void * p) { aligned_free(p); } + void operator delete[] (void * p) { aligned_free(p); } + }; + } // namespace ngcore #endif // NETGEN_CORE_UTILS_HPP diff --git a/libsrc/general/ngarray.hpp b/libsrc/general/ngarray.hpp index 2c4aed21..4b66d65d 100644 --- a/libsrc/general/ngarray.hpp +++ b/libsrc/general/ngarray.hpp @@ -388,10 +388,10 @@ namespace netgen NgArray & operator= (NgArray && a2) { - Swap (data, a2.data); - Swap (size, a2.size); - Swap (allocsize, a2.allocsize); - Swap (ownmem, a2.ownmem); + ngcore::Swap (data, a2.data); + ngcore::Swap (size, a2.size); + ngcore::Swap (allocsize, a2.allocsize); + ngcore::Swap (ownmem, a2.ownmem); return *this; } @@ -745,8 +745,8 @@ namespace netgen if (i <= j) { - Swap (data[i], data[j]); - Swap (slave[i], slave[j]); + ngcore::Swap (data[i], data[j]); + ngcore::Swap (slave[i], slave[j]); i++; j--; } } diff --git a/libsrc/general/ngsimd.hpp b/libsrc/general/ngsimd.hpp index 97e92052..feba2523 100644 --- a/libsrc/general/ngsimd.hpp +++ b/libsrc/general/ngsimd.hpp @@ -13,6 +13,8 @@ #include #include +#include + #ifdef WIN32 #ifndef AVX_OPERATORS_DEFINED #define AVX_OPERATORS_DEFINED @@ -48,6 +50,7 @@ NG_INLINE __m256d operator/= (__m256d &a, __m256d b) { return a = a/b; } namespace ngsimd { + using ngcore::AlignedAlloc; // MSVC does not define SSE. It's always present on 64bit cpus #if (defined(_M_AMD64) || defined(_M_X64) || defined(__AVX__)) @@ -121,42 +124,6 @@ namespace ngsimd NG_INLINE SIMD operator/ (SIMD a, T b) { return a / SIMD(b); } -#ifdef __AVX__ - template - class AlignedAlloc - { - protected: - static void * aligned_malloc(size_t s) - { - // Assume 16 byte alignment of standard library - if(alignof(T)<=16) - return malloc(s); - else - return _mm_malloc(s, alignof(T)); - } - - static void aligned_free(void *p) - { - if(alignof(T)<=16) - free(p); - else - _mm_free(p); - } - - public: - void * operator new (size_t s, void *p) { return p; } - void * operator new (size_t s) { return aligned_malloc(s); } - void * operator new[] (size_t s) { return aligned_malloc(s); } - void operator delete (void * p) { aligned_free(p); } - void operator delete[] (void * p) { aligned_free(p); } - }; -#else - // it's only a dummy without AVX - template - class AlignedAlloc { ; }; - -#endif - using std::sqrt; using std::fabs; From b26286d9cd767cd3d2b03dce1dc8e580a8f7389c Mon Sep 17 00:00:00 2001 From: Matthias Hochsteger Date: Wed, 10 Jul 2019 15:21:04 +0200 Subject: [PATCH 10/11] Fix thread_id linkage --- libsrc/core/taskmanager.cpp | 6 +----- libsrc/core/taskmanager.hpp | 2 +- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/libsrc/core/taskmanager.cpp b/libsrc/core/taskmanager.cpp index a411034b..b54264f1 100644 --- a/libsrc/core/taskmanager.cpp +++ b/libsrc/core/taskmanager.cpp @@ -41,8 +41,6 @@ namespace ngcore __thread int TaskManager :: thread_id; #endif - thread_local int thread_id = 0; - const function * TaskManager::func; const function * TaskManager::startup_function = nullptr; const function * TaskManager::cleanup_function = nullptr; @@ -188,12 +186,10 @@ namespace ngcore num_threads = 1; } - /* int TaskManager :: GetThreadId() { return thread_id; } - */ void TaskManager :: StartWorkers() { @@ -293,7 +289,7 @@ namespace ngcore TaskInfo ti; ti.task_nr = task.mynr; ti.ntasks = task.total; - ti.thread_nr = thread_id; + ti.thread_nr = TaskManager::GetThreadId(); ti.nthreads = TaskManager::GetNumThreads(); /* { diff --git a/libsrc/core/taskmanager.hpp b/libsrc/core/taskmanager.hpp index 059a1678..4e057013 100644 --- a/libsrc/core/taskmanager.hpp +++ b/libsrc/core/taskmanager.hpp @@ -98,7 +98,7 @@ namespace ngcore NGCORE_API static int GetMaxThreads() { return max_threads; } // static int GetNumThreads() { return task_manager ? task_manager->num_threads : 1; } NGCORE_API static int GetNumThreads() { return num_threads; } - NGCORE_API static int GetThreadId() { return thread_id; } + NGCORE_API static int GetThreadId(); NGCORE_API int GetNumNodes() const { return num_nodes; } static void SetPajeTrace (bool use) { use_paje_trace = use; } From 133bd82aa94545ffea59b5f8c0fe9c043acd92a5 Mon Sep 17 00:00:00 2001 From: Matthias Hochsteger Date: Wed, 10 Jul 2019 16:04:03 +0200 Subject: [PATCH 11/11] Fix linkage of pthread --- libsrc/core/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libsrc/core/CMakeLists.txt b/libsrc/core/CMakeLists.txt index a62c030c..de4b33c0 100644 --- a/libsrc/core/CMakeLists.txt +++ b/libsrc/core/CMakeLists.txt @@ -39,7 +39,7 @@ if(USE_PYTHON) target_include_directories(ngcore PRIVATE ${PYTHON_INCLUDE_DIRS}) target_link_libraries(ngcore PRIVATE ${PYTHON_LIBRARIES}) endif(USE_PYTHON) -target_link_libraries(ngcore PUBLIC netgen_mpi) +target_link_libraries(ngcore PUBLIC netgen_mpi PRIVATE ${CMAKE_THREAD_LIBS_INIT}) install(FILES ngcore.hpp archive.hpp type_traits.hpp version.hpp ngcore_api.hpp logging.hpp exception.hpp symboltable.hpp paje_trace.hpp utils.hpp profiler.hpp mpi_wrapper.hpp