From 89fe31b550e944faadfa609b51c718131a7f4c7c Mon Sep 17 00:00:00 2001 From: Christopher Lackner Date: Thu, 23 Feb 2017 16:41:27 +0100 Subject: [PATCH 01/10] Squashed commit of the following: commit fa556baaa222ba349d534027f7203588dcda6ad8 Author: Christopher Lackner Date: Thu Feb 23 15:56:47 2017 +0100 add python path to docker template commit 54eb7eedc77ad8c86952c347536e7e1a854b62ed Author: Matthias Hochsteger Date: Thu Feb 23 14:59:45 2017 +0100 install pytest in docker images commit 3c1c755891e8372762130a6ed8c39cf056430264 Author: Matthias Hochsteger Date: Thu Feb 23 14:52:32 2017 +0100 enable CTest properly, add pytest commit 4c4cf229ab8e7fd6057f535fb05c3079a9278f80 Author: Christopher Lackner Date: Thu Feb 23 14:02:13 2017 +0100 fix write splinesurface to savemesh commit 069fbdbc529c9dd91644663f3f365e08be5af70e Author: Christopher Lackner Date: Thu Feb 23 09:03:26 2017 +0100 fix lifetime of SplineSurface --- .gitlab-ci.yml | 7 ++++- CMakeLists.txt | 11 ++++--- libsrc/csg/csg.hpp | 4 +-- libsrc/csg/csgeom.cpp | 19 ++++++++++++ libsrc/csg/csgeom.hpp | 7 ++++- libsrc/csg/edgeflw.cpp | 4 +-- libsrc/csg/python_csg.cpp | 20 ++++++------ libsrc/csg/splinesurface.cpp | 58 ++++++++++++++++++++--------------- libsrc/csg/splinesurface.hpp | 34 ++++++++++---------- libsrc/meshing/meshfunc.cpp | 2 +- tests/CMakeLists.txt | 1 + tests/docker_15.10 | 2 +- tests/docker_16.04 | 2 +- tests/pytest/CMakeLists.txt | 4 +++ tests/pytest/test_savemesh.py | 52 +++++++++++++++++++++++++++++++ 15 files changed, 162 insertions(+), 65 deletions(-) create mode 100644 tests/CMakeLists.txt create mode 100644 tests/pytest/CMakeLists.txt create mode 100644 tests/pytest/test_savemesh.py diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 19d4c8ec..ae7e0095 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -138,7 +138,12 @@ test_win64: .template_test_linux: &test_linux stage: test script: - - docker run netgen_${CI_BUILD_REF_NAME}_installed:${UBUNTU_VERSION} bash -c 'cd /root/build/netgen && make test_netgen ARGS="-V"' + - >- + docker run + -e NETGENDIR=/opt/netgen/bin + -e PYTHONPATH=/opt/netgen/lib/python3/dist-packages + netgen_${CI_BUILD_REF_NAME}_installed:${UBUNTU_VERSION} + bash -c 'cd /root/build/netgen && make test_netgen ARGS="-V"' test_ubuntu_1510: <<: *ubuntu_1510 diff --git a/CMakeLists.txt b/CMakeLists.txt index f2bbd4e2..1befe02f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -258,6 +258,11 @@ execute_process(COMMAND hdiutil create -volname Netgen -srcfolder ${INSTALL_DIR} ") add_custom_target(bundle COMMAND ${CMAKE_COMMAND} "-P" "${CMAKE_CURRENT_BINARY_DIR}/fixup.cmake") ####################################################################### +# CTest +enable_testing() +include(CTest) + +####################################################################### add_subdirectory(libsrc) add_subdirectory(ng) @@ -269,13 +274,9 @@ add_subdirectory(py_tutorials) add_subdirectory(doc) add_subdirectory(windows) add_subdirectory(nglib) +add_subdirectory(tests) -####################################################################### -# CTest -enable_testing() -include(CTest) - ####################################################################### # Debian packager diff --git a/libsrc/csg/csg.hpp b/libsrc/csg/csg.hpp index d524903f..ec3ad1e1 100644 --- a/libsrc/csg/csg.hpp +++ b/libsrc/csg/csg.hpp @@ -10,7 +10,7 @@ #include #include #include - +#include // #include #include "../gprim/spline.hpp" #include "../gprim/splinegeometry.hpp" @@ -21,12 +21,12 @@ #include "solid.hpp" #include "identify.hpp" #include "singularref.hpp" +#include "splinesurface.hpp" #include "csgeom.hpp" #include "csgparser.hpp" #include "triapprox.hpp" #include "algprim.hpp" -#include "splinesurface.hpp" #include "brick.hpp" #include "spline3d.hpp" #include "manifold.hpp" diff --git a/libsrc/csg/csgeom.cpp b/libsrc/csg/csgeom.cpp index 0cb2c8c2..892d754f 100644 --- a/libsrc/csg/csgeom.cpp +++ b/libsrc/csg/csgeom.cpp @@ -345,7 +345,25 @@ namespace netgen const ExtrusionFace * ef = dynamic_cast< const ExtrusionFace * > (GetSurface(i)); const RevolutionFace * rf = dynamic_cast< const RevolutionFace * > (GetSurface(i)); const DummySurface * dummyf = dynamic_cast< const DummySurface * > (GetSurface(i)); + const SplineSurface * splines = dynamic_cast (GetSurface(i)); + if (splines) + { + splines->GetBase()->GetPrimitiveData(classname,coeffs); + out << classname << " " << coeffs.Size() << "\n"; + for (int j=0; jGetCuts())) + { + cut->GetPrimitiveData(classname,coeffs); + out << classname << " " << coeffs.Size() << "\n"; + for (int j=0; j> spline_surfaces; + public: CSGeometry (); CSGeometry (const string & afilename); @@ -315,7 +318,9 @@ namespace netgen virtual int GenerateMesh (shared_ptr & mesh, MeshingParameters & mparam); - virtual const Refinement & GetRefinement () const; + virtual const Refinement & GetRefinement () const; + + void AddSplineSurface (shared_ptr ss) { spline_surfaces.push_back(ss); } }; diff --git a/libsrc/csg/edgeflw.cpp b/libsrc/csg/edgeflw.cpp index 68cac826..30ac3b85 100644 --- a/libsrc/csg/edgeflw.cpp +++ b/libsrc/csg/edgeflw.cpp @@ -491,7 +491,7 @@ namespace netgen if(splinesurface) { auto name = splinesurface->GetBCNameOf(specpoints[startpoints.Get(refedges[i].edgenr)].p,specpoints[endpoints.Get(refedges[i].edgenr)].p); - mesh.SetCD2Name(refedges[i].edgenr,*name); + mesh.SetCD2Name(refedges[i].edgenr,name); } else { @@ -499,7 +499,7 @@ namespace netgen if(splinesurface2) { auto name = splinesurface2->GetBCNameOf(specpoints[startpoints.Get(refedges[i].edgenr)].p,specpoints[endpoints.Get(refedges[i].edgenr)].p); - mesh.SetCD2Name(refedges[i].edgenr,*name); + mesh.SetCD2Name(refedges[i].edgenr,name); } } diff --git a/libsrc/csg/python_csg.cpp b/libsrc/csg/python_csg.cpp index b8c4ffbf..b61a9934 100644 --- a/libsrc/csg/python_csg.cpp +++ b/libsrc/csg/python_csg.cpp @@ -207,11 +207,11 @@ DLL_HEADER void ExportCSG(py::module &m) ; py::class_> (m, "SplineSurface", - "A surface for co dim 2 integrals on the splines") + "A surface for co dim 2 integrals on the splines") .def("__init__", FunctionPointer ([](SplineSurface* instance, shared_ptr base, py::list cuts) { auto primitive = dynamic_cast (base->GetSolid()->GetPrimitive()); - auto acuts = new Array(); + auto acuts = make_shared>>(); for(int i = 0; i> sps(cuts[i]); @@ -219,13 +219,14 @@ DLL_HEADER void ExportCSG(py::module &m) throw NgException("Cut must be SurfacePrimitive in constructor of SplineSurface!"); auto sp = dynamic_cast(sps()->GetSolid()->GetPrimitive()); if(sp) - acuts->Append(sp); + acuts->push_back(shared_ptr(sp)); else throw NgException("Cut must be SurfacePrimitive in constructor of SplineSurface!"); } if(!primitive) throw NgException("Base is not a SurfacePrimitive in constructor of SplineSurface!"); - new (instance) SplineSurface(primitive,acuts); + new (instance) SplineSurface(shared_ptr(primitive),acuts); + py::object obj = py::cast(instance); }),py::arg("base"), py::arg("cuts")=py::list()) .def("AddPoint", FunctionPointer ([] (SplineSurface & self, double x, double y, double z, bool hpref) @@ -237,8 +238,8 @@ DLL_HEADER void ExportCSG(py::module &m) .def("AddSegment", FunctionPointer ([] (SplineSurface & self, int i1, int i2, string bcname, double maxh) { - auto str = new string(bcname); - self.AppendSegment(new LineSeg<3>(self.GetPoint(i1),self.GetPoint(i2)),str,maxh); + auto seg = make_shared>(self.GetPoint(i1),self.GetPoint(i2)); + self.AppendSegment(seg,bcname,maxh); }), py::arg("pnt1"),py::arg("pnt2"),py::arg("bcname")="default", py::arg("maxh")=-1.) ; @@ -433,14 +434,15 @@ DLL_HEADER void ExportCSG(py::module &m) ([] (CSGeometry & self, shared_ptr surf) { auto cuttings = surf->CreateCuttingSurfaces(); - auto spsol = make_shared(new Solid(&*surf)); + auto spsol = make_shared(new Solid(surf.get())); for(auto cut : (*cuttings)){ - spsol = make_shared(SPSolid::SECTION,spsol,make_shared(new Solid(cut))); + spsol = make_shared(SPSolid::SECTION,spsol,make_shared(new Solid(cut.get()))); } spsol->AddSurfaces(self); - int tlonr = self.SetTopLevelObject(spsol->GetSolid(), &*surf); + int tlonr = self.SetTopLevelObject(spsol->GetSolid(), surf.get()); for(auto p : surf->GetPoints()) self.AddUserPoint(p); + self.AddSplineSurface(surf); }), py::arg("SplineSurface")) diff --git a/libsrc/csg/splinesurface.cpp b/libsrc/csg/splinesurface.cpp index d66c8bff..65a0f988 100644 --- a/libsrc/csg/splinesurface.cpp +++ b/libsrc/csg/splinesurface.cpp @@ -6,22 +6,22 @@ namespace netgen void SplineSurface :: AppendPoint(const Point<3> & p, const double reffac, const bool hpref) { auto pp = Point<3>(p); - geompoints.Append(GeomPoint<3>(pp,reffac)); - geompoints.Last().hpref = hpref; + geompoints.push_back(GeomPoint<3>(pp,reffac)); + geompoints.back().hpref = hpref; } - void SplineSurface :: AppendSegment(SplineSeg<3>* spline, string* bcname, double amaxh) + void SplineSurface :: AppendSegment(shared_ptr> sp, string & bcname, double amaxh) { - splines.Append(spline); - bcnames.Append(bcname); + splines.push_back(sp); + bcnames.push_back(bcname); maxh.Append(amaxh); } - string* SplineSurface :: GetBCNameOf (Point<3> p1, Point<3> p2) const + string SplineSurface :: GetBCNameOf (Point<3> p1, Point<3> p2) const { double eps = 1e-5; - for(int i=0; i(splines[i]->GetPoint(0)); Project(pp1); @@ -32,36 +32,44 @@ void SplineSurface :: AppendPoint(const Point<3> & p, const double reffac, const return bcnames[i]; } } - return new string("default"); + return "default"; } - Array* SplineSurface :: CreateCuttingSurfaces() const + const shared_ptr>> SplineSurface :: CreateCuttingSurfaces() { - auto cuttings = new Array(); + if(all_cuts) + return all_cuts; + auto cuttings = make_shared>>(); for (auto cut : *cuts) - cuttings->Append(cut); - for(int i = 0; ipush_back(cut); + for(int i = 0; i*>(spline); - auto p1 = Point<3>(spline->GetPoint(0)); - Project(p1); - auto p2 = Point<3>(spline->GetPoint(1)); - Project(p2); - auto vec = Vec<3>(p2)-Vec<3>(p1); - auto plane = new Plane(p1,-Cross(vec,baseprimitive->GetNormalVector(p1))); - if(maxh[i]>0) - { - plane->SetMaxH(maxh[i]); - } - cuttings->Append(plane); + auto lineseg = dynamic_cast*>(spline.get()); + if(lineseg) + { + auto p1 = Point<3>(spline->GetPoint(0)); + Project(p1); + auto p2 = Point<3>(spline->GetPoint(1)); + Project(p2); + auto vec = Vec<3>(p2)-Vec<3>(p1); + auto plane = make_shared(p1,-Cross(vec,baseprimitive->GetNormalVector(p1))); + if(maxh[i]>0) + { + plane->SetMaxH(maxh[i]); + } + cuttings->push_back(plane); + } + else + throw NgException("Spline type not implemented for SplineSurface!"); } + all_cuts = cuttings; return cuttings; } void SplineSurface :: Print(ostream & str) const { - str << "SplineSurface " << endl; + str << "SplineSurface with base " << *baseprimitive << endl; } } diff --git a/libsrc/csg/splinesurface.hpp b/libsrc/csg/splinesurface.hpp index 1f68ae73..0bc5494c 100644 --- a/libsrc/csg/splinesurface.hpp +++ b/libsrc/csg/splinesurface.hpp @@ -7,37 +7,37 @@ namespace netgen class SplineSurface : public OneSurfacePrimitive { protected: - Array> geompoints; - Array*> splines; - Array bcnames; + std::vector> geompoints; + std::vector>> splines; + std::vector bcnames; Array maxh; - OneSurfacePrimitive* baseprimitive; - Array* cuts; + shared_ptr baseprimitive; + shared_ptr>> cuts; + shared_ptr>> all_cuts; public: - SplineSurface(OneSurfacePrimitive* abaseprimitive, Array* acuts) : + SplineSurface(shared_ptr abaseprimitive, shared_ptr>> acuts) : OneSurfacePrimitive(), baseprimitive(abaseprimitive), cuts(acuts) { ; } virtual ~SplineSurface() { ; } - const Array*> & GetSplines() const { return splines; } - int GetNSplines() const { return splines.Size(); } - const Array>& GetPoints() const { return geompoints; } + const auto & GetSplines() const { return splines; } + int GetNSplines() const { return splines.size(); } + const std::vector>& 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]; } - int GetNP() const { return geompoints.Size(); } + int GetNP() const { return geompoints.size(); } const GeomPoint<3> & GetPoint(int i) const { return geompoints[i]; } - string* GetBCName(int i) const { return bcnames[i]; } - string* GetBCNameOf(Point<3> p1, Point<3> p2) const; + string GetBCName(int i) const { return bcnames[i]; } + string GetBCNameOf(Point<3> p1, Point<3> p2) const; DLL_HEADER void AppendPoint(const Point<3> & p, const double reffac = 1., const bool hpref=false); - void AppendSegment(SplineSeg<3>* spline, string* bcname, double amaxh = -1); - - OneSurfacePrimitive* GetBase() const { return baseprimitive; } - - Array* CreateCuttingSurfaces() const; + 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 GetBase() const { return baseprimitive; } virtual void Project (Point<3> & p3d) const { baseprimitive->Project(p3d); } virtual double CalcFunctionValue (const Point<3> & point) const diff --git a/libsrc/meshing/meshfunc.cpp b/libsrc/meshing/meshfunc.cpp index 9af43005..21585384 100644 --- a/libsrc/meshing/meshfunc.cpp +++ b/libsrc/meshing/meshfunc.cpp @@ -75,7 +75,7 @@ namespace netgen (*testout) << "Meshing subdomain " << k << endl; mp.maxh = min2 (globmaxh, mesh3d.MaxHDomain(k)); - + mesh3d.CalcSurfacesOfNode(); mesh3d.FindOpenElements(k); diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 00000000..f898217f --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(pytest) diff --git a/tests/docker_15.10 b/tests/docker_15.10 index e159dfa8..a88f5673 100644 --- a/tests/docker_15.10 +++ b/tests/docker_15.10 @@ -1,4 +1,4 @@ FROM ubuntu:15.10 MAINTAINER Matthias Hochsteger -RUN apt-get update && apt-get -y install python3 libpython3-dev libxmu-dev libboost-python-dev tk-dev tcl-dev cmake git g++ libglu1-mesa-dev ccache +RUN apt-get update && apt-get -y install python3 libpython3-dev libxmu-dev tk-dev tcl-dev cmake git g++ libglu1-mesa-dev ccache python3-pytest python3-numpy ADD . /root/src/netgen diff --git a/tests/docker_16.04 b/tests/docker_16.04 index 2ab970e7..a1fe001e 100644 --- a/tests/docker_16.04 +++ b/tests/docker_16.04 @@ -1,4 +1,4 @@ FROM ubuntu:16.04 MAINTAINER Matthias Hochsteger -RUN apt-get update && apt-get -y install python3 libpython3-dev libxmu-dev libboost-python-dev tk-dev tcl-dev cmake git g++ libglu1-mesa-dev ccache +RUN apt-get update && apt-get -y install python3 libpython3-dev libxmu-dev tk-dev tcl-dev cmake git g++ libglu1-mesa-dev ccache python3-pytest python3-numpy ADD . /root/src/netgen diff --git a/tests/pytest/CMakeLists.txt b/tests/pytest/CMakeLists.txt new file mode 100644 index 00000000..9997622a --- /dev/null +++ b/tests/pytest/CMakeLists.txt @@ -0,0 +1,4 @@ +if(USE_PYTHON) + add_test(NAME pytest COMMAND ${PYTHON_EXECUTABLE} -m pytest WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) + add_custom_target(pytest ${PYTHON_EXECUTABLE} -m pytest WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) +endif(USE_PYTHON) diff --git a/tests/pytest/test_savemesh.py b/tests/pytest/test_savemesh.py new file mode 100644 index 00000000..6b7b7e2c --- /dev/null +++ b/tests/pytest/test_savemesh.py @@ -0,0 +1,52 @@ + +from netgen.csg import * +from netgen import meshing +import filecmp +import difflib +from math import sqrt, cos, sin + +def CreateQuad(): + base = Plane(Pnt(0,0,0),Vec(0,0,1)) + surface = SplineSurface(base) + pts = [(-0.2,-0.2,0),(-0.2,0.2,0),(0.2,0.2,0),(0.2,-0.2,0)] + geopts = [surface.AddPoint(*p) for p in pts] + for p1,p2,bc in [(0,1,"wire"), (1, 2,"contact"),(2,3,"wire"),(3,0,"wire")]: + surface.AddSegment(geopts[p1],geopts[p2],bc) + return surface + +Cross = lambda a,b: [a[1]*b[2]-a[2]*b[1],a[2]*b[0]-a[0]*b[2],a[0]*b[1]-b[0]*a[1]] + + +def CreateGeo(): + geo = CSGeometry() + air = OrthoBrick(Pnt(-1,-1,-1),Pnt(1,1,1)) + geo.Add(air.mat("air")) + surface = CreateQuad() + geo.AddSplineSurface(surface) + return geo + +def test_BBNDsave(): + mesh = CreateGeo().GenerateMesh(maxh=0.4,perfstepsend = meshing.MeshingStep.MESHSURFACE) + for i in range(2): + mesh.GenerateVolumeMesh(mp = MeshingParameters(only3D_domain=i+1,maxh=0.4)) + mesh.SetGeometry(None) + mesh.Save("test.vol") + mesh2 = meshing.Mesh() + mesh2.Load("test.vol") + mesh2.Save("test2.vol") + with open("test.vol","r") as f: + first = f.readlines() + with open("test2.vol","r") as f: + second = f.readlines() + # exclude the face colours section (because they aren't in the same order) + for i,line in enumerate(first): + if line[0:12] == "face_colours": + first = first[0:i] + second = second[0:i] + break + diff = difflib.context_diff(first,second) + print("File diff:") + l = list(diff) + print(*l) + assert len(l)==0 + From a698b5759659124952849382ea3d1b019e0a20f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20Sch=C3=B6berl?= Date: Fri, 24 Feb 2017 17:18:42 +0100 Subject: [PATCH 02/10] add unified GetMaterial for co-dimension --- libsrc/include/nginterface_v2.hpp | 3 +++ libsrc/include/nginterface_v2_impl.hpp | 15 +++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/libsrc/include/nginterface_v2.hpp b/libsrc/include/nginterface_v2.hpp index 5371a97e..f0d0d8bb 100644 --- a/libsrc/include/nginterface_v2.hpp +++ b/libsrc/include/nginterface_v2.hpp @@ -234,6 +234,9 @@ namespace netgen template int GetElementIndex (int nr) const; + /// material/boundary label of region, template argument is co-dimension + template + const string & GetMaterialCD (int region_nr) const; /// Curved Elements: /// elnr .. element nr diff --git a/libsrc/include/nginterface_v2_impl.hpp b/libsrc/include/nginterface_v2_impl.hpp index 78b829e2..b90ca8fc 100644 --- a/libsrc/include/nginterface_v2_impl.hpp +++ b/libsrc/include/nginterface_v2_impl.hpp @@ -175,8 +175,23 @@ NGX_INLINE DLL_HEADER Ng_Element Ngx_Mesh :: GetElement<3> (int nr) const +template <> NGX_INLINE DLL_HEADER +const string & Ngx_Mesh :: GetMaterialCD<0> (int region_nr) const +{ + return mesh->GetMaterial(region_nr+1); +} +template <> NGX_INLINE DLL_HEADER +const string & Ngx_Mesh :: GetMaterialCD<1> (int region_nr) const +{ + return mesh->GetBCName(region_nr); +} +template <> NGX_INLINE DLL_HEADER +const string & Ngx_Mesh :: GetMaterialCD<2> (int region_nr) const +{ + return mesh->GetCD2Name(region_nr); +} From c143aafaea246c564464736aee843499f83f9566 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20Sch=C3=B6berl?= Date: Fri, 24 Feb 2017 22:29:57 +0100 Subject: [PATCH 03/10] Array resize checks for trivially copyable --- libsrc/general/array.hpp | 11 ++++++- libsrc/meshing/meshtype.hpp | 16 +++++++++ libsrc/meshing/topology.hpp | 66 ++++++++++++++++++++++--------------- 3 files changed, 66 insertions(+), 27 deletions(-) diff --git a/libsrc/general/array.hpp b/libsrc/general/array.hpp index 9c6bcbe5..568a6d30 100644 --- a/libsrc/general/array.hpp +++ b/libsrc/general/array.hpp @@ -391,7 +391,16 @@ namespace netgen T * p = new T[nsize]; int mins = (nsize < size) ? nsize : size; - memcpy (p, data, mins * sizeof(T)); + // 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) + 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; diff --git a/libsrc/meshing/meshtype.hpp b/libsrc/meshing/meshtype.hpp index f3446192..92acaaf7 100644 --- a/libsrc/meshing/meshtype.hpp +++ b/libsrc/meshing/meshtype.hpp @@ -25,9 +25,25 @@ namespace netgen HEX = 25 }; + /* typedef int ELEMENT_EDGE[2]; // initial point, end point typedef int ELEMENT_FACE[4]; // points, last one is -1 for trig + */ + struct ELEMENT_EDGE + { + int vals[2]; + int & operator[] (size_t i) { return vals[i]; } + int operator[] (size_t i) const { return vals[i]; } + }; + + struct ELEMENT_FACE + { + int vals[4]; + int & operator[] (size_t i) { return vals[i]; } + int operator[] (size_t i) const { return vals[i]; } + }; + #define ELEMENT_MAXPOINTS 12 #define ELEMENT2D_MAXPOINTS 8 diff --git a/libsrc/meshing/topology.hpp b/libsrc/meshing/topology.hpp index 5acbcdbb..fdef9ba8 100644 --- a/libsrc/meshing/topology.hpp +++ b/libsrc/meshing/topology.hpp @@ -27,6 +27,14 @@ struct T_FACE int fnr; // 0-based }; + template + struct FixArray + { + T vals[S]; + T & operator[] (size_t i) { return vals[i]; } + T operator[] (size_t i) const { return vals[i]; } + }; + class MeshTopology { @@ -36,9 +44,15 @@ class MeshTopology Array edge2vert; Array face2vert; + /* Array edges; Array faces; Array surfedges; + */ + Array> edges; + Array> faces; + Array> surfedges; + Array segedges; Array surffaces; Array surf2volelement; @@ -337,22 +351,22 @@ inline short int MeshTopology :: GetNFaces (ELEMENT_TYPE et) const ELEMENT_EDGE * MeshTopology :: GetEdges1 (ELEMENT_TYPE et) { - static int segm_edges[1][2] = + static ELEMENT_EDGE segm_edges[1] = { { 1, 2 }}; - static int trig_edges[3][2] = + static ELEMENT_EDGE trig_edges[3] = { { 3, 1 }, { 2, 3 }, { 1, 2 }}; - static int quad_edges[4][2] = + static ELEMENT_EDGE quad_edges[4] = { { 1, 2 }, { 3, 4 }, { 4, 1 }, { 2, 3 }}; - static int tet_edges[6][2] = + static ELEMENT_EDGE tet_edges[6] = { { 4, 1 }, { 4, 2 }, { 4, 3 }, @@ -360,7 +374,7 @@ const ELEMENT_EDGE * MeshTopology :: GetEdges1 (ELEMENT_TYPE et) { 1, 3 }, { 2, 3 }}; - static int prism_edges[9][2] = + static ELEMENT_EDGE prism_edges[9] = { { 3, 1 }, { 1, 2 }, { 3, 2 }, @@ -371,7 +385,7 @@ const ELEMENT_EDGE * MeshTopology :: GetEdges1 (ELEMENT_TYPE et) { 1, 4 }, { 2, 5 }}; - static int pyramid_edges[8][2] = + static ELEMENT_EDGE pyramid_edges[8] = { { 1, 2 }, { 2, 3 }, { 1, 4 }, @@ -381,7 +395,7 @@ const ELEMENT_EDGE * MeshTopology :: GetEdges1 (ELEMENT_TYPE et) { 3, 5 }, { 4, 5 }}; - static int hex_edges[12][2] = + static ELEMENT_EDGE hex_edges[12] = { { 1, 2 }, { 3, 4 }, @@ -435,22 +449,22 @@ const ELEMENT_EDGE * MeshTopology :: GetEdges1 (ELEMENT_TYPE et) const ELEMENT_EDGE * MeshTopology :: GetEdges0 (ELEMENT_TYPE et) { - static int segm_edges[1][2] = + static ELEMENT_EDGE segm_edges[1] = { { 0, 1 }}; - static int trig_edges[3][2] = + static ELEMENT_EDGE trig_edges[3] = { { 2, 0 }, { 1, 2 }, { 0, 1 }}; - static int quad_edges[4][2] = + static ELEMENT_EDGE quad_edges[4] = { { 0, 1 }, { 2, 3 }, { 3, 0 }, { 1, 2 }}; - static int tet_edges[6][2] = + static ELEMENT_EDGE tet_edges[6] = { { 3, 0 }, { 3, 1 }, { 3, 2 }, @@ -458,7 +472,7 @@ const ELEMENT_EDGE * MeshTopology :: GetEdges0 (ELEMENT_TYPE et) { 0, 2 }, { 1, 2 }}; - static int prism_edges[9][2] = + static ELEMENT_EDGE prism_edges[9] = { { 2, 0 }, { 0, 1 }, { 2, 1 }, @@ -469,7 +483,7 @@ const ELEMENT_EDGE * MeshTopology :: GetEdges0 (ELEMENT_TYPE et) { 0, 3 }, { 1, 4 }}; - static int pyramid_edges[8][2] = + static ELEMENT_EDGE pyramid_edges[8] = { { 0, 1 }, { 1, 2 }, { 0, 3 }, @@ -479,7 +493,7 @@ const ELEMENT_EDGE * MeshTopology :: GetEdges0 (ELEMENT_TYPE et) { 2, 4 }, { 3, 4 }}; - static int hex_edges[12][2] = + static ELEMENT_EDGE hex_edges[12] = { { 0, 1 }, { 2, 3 }, @@ -540,18 +554,18 @@ const ELEMENT_EDGE * MeshTopology :: GetEdges0 (ELEMENT_TYPE et) inline const ELEMENT_FACE * MeshTopology :: GetFaces1 (ELEMENT_TYPE et) { - static const int trig_faces[1][4] = + static const ELEMENT_FACE trig_faces[1] = { { 1, 2, 3, 0 } }; - static const int quad_faces[1][4] = + static const ELEMENT_FACE quad_faces[1] = { { 1, 2, 3, 4 } }; - static const int tet_faces[4][4] = + static const ELEMENT_FACE tet_faces[4] = { { 4, 2, 3, 0 }, { 4, 3, 1, 0 }, { 4, 1, 2, 0 }, { 1, 3, 2, 0 } }; - static const int prism_faces[5][4] = + static const ELEMENT_FACE prism_faces[5] = { { 1, 3, 2, 0 }, { 4, 5, 6, 0 }, @@ -560,7 +574,7 @@ inline const ELEMENT_FACE * MeshTopology :: GetFaces1 (ELEMENT_TYPE et) { 2, 3, 6, 5 } }; - static const int pyramid_faces[5][4] = + static const ELEMENT_FACE pyramid_faces[5] = { { 1, 2, 5, 0 }, { 2, 3, 5, 0 }, @@ -569,7 +583,7 @@ inline const ELEMENT_FACE * MeshTopology :: GetFaces1 (ELEMENT_TYPE et) { 1, 4, 3, 2 } }; - static const int hex_faces[6][4] = + static const ELEMENT_FACE hex_faces[6] = { { 1, 4, 3, 2 }, { 5, 6, 7, 8 }, @@ -622,18 +636,18 @@ inline const ELEMENT_FACE * MeshTopology :: GetFaces1 (ELEMENT_TYPE et) inline const ELEMENT_FACE * MeshTopology :: GetFaces0 (ELEMENT_TYPE et) { - static const int trig_faces[1][4] = + static const ELEMENT_FACE trig_faces[1] = { { 0, 1, 2, -1 } }; - static const int quad_faces[1][4] = + static const ELEMENT_FACE quad_faces[1] = { { 0, 1, 2, 3 } }; - static const int tet_faces[4][4] = + static const ELEMENT_FACE tet_faces[4] = { { 3, 1, 2, -1 }, { 3, 2, 0, -1 }, { 3, 0, 1, -1 }, { 0, 2, 1, -1 } }; - static const int prism_faces[5][4] = + static const ELEMENT_FACE prism_faces[5] = { { 0, 2, 1, -1 }, { 3, 4, 5, -1 }, @@ -642,7 +656,7 @@ inline const ELEMENT_FACE * MeshTopology :: GetFaces0 (ELEMENT_TYPE et) { 1, 2, 5, 4 } }; - static const int pyramid_faces[5][4] = + static const ELEMENT_FACE pyramid_faces[5] = { { 0, 1, 4, -1 }, { 1, 2, 4, -1 }, @@ -651,7 +665,7 @@ inline const ELEMENT_FACE * MeshTopology :: GetFaces0 (ELEMENT_TYPE et) { 0, 3, 2, 1 } }; - static const int hex_faces[6][4] = + static const ELEMENT_FACE hex_faces[6] = { { 0, 3, 2, 1 }, { 4, 5, 6, 7 }, From c6330350433e28a27fc0cb42cfb027ceaa7fa0ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20Sch=C3=B6berl?= Date: Sat, 25 Feb 2017 17:11:30 +0100 Subject: [PATCH 04/10] more size_t --- libsrc/include/nginterface_v2.hpp | 36 ++++++++++++-------------- libsrc/include/nginterface_v2_impl.hpp | 16 ++++++------ 2 files changed, 25 insertions(+), 27 deletions(-) diff --git a/libsrc/include/nginterface_v2.hpp b/libsrc/include/nginterface_v2.hpp index f0d0d8bb..7f5de1ec 100644 --- a/libsrc/include/nginterface_v2.hpp +++ b/libsrc/include/nginterface_v2.hpp @@ -36,54 +36,52 @@ namespace netgen class Ng_Points { public: - int num; + size_t num; const int * ptr; - int Size() const { return num; } - int operator[] (int i) const { return ptr[i]-POINTINDEX_BASE; } + size_t Size() const { return num; } + int operator[] (size_t i) const { return ptr[i]-POINTINDEX_BASE; } }; class Ng_Vertices { public: - int num; + size_t num; const int * ptr; - int Size() const { return num; } - int operator[] (int i) const { return ptr[i]-POINTINDEX_BASE; } + size_t Size() const { return num; } + int operator[] (size_t i) const { return ptr[i]-POINTINDEX_BASE; } }; class Ng_Edges { public: - int num; + size_t num; const T_EDGE2 * ptr; - int Size() const { return num; } - // int operator[] (int i) const { return abs (ptr[i])-1; } - int operator[] (int i) const { return ptr[i].nr; } + size_t Size() const { return num; } + int operator[] (size_t i) const { return ptr[i].nr; } }; class Ng_Faces { public: - int num; + size_t num; const T_FACE2 * ptr; - int Size() const { return num; } - // int operator[] (int i) const { return (ptr[i]-1) / 8; } - int operator[] (int i) const { return ptr[i].nr; } + size_t Size() const { return num; } + int operator[] (size_t i) const { return ptr[i].nr; } }; class Ng_Facets { public: - int num; + size_t num; const int * ptr; - int Size() const { return num; } - int operator[] (int i) const { return ptr[i]; } + size_t Size() const { return num; } + int operator[] (size_t i) const { return ptr[i]; } }; @@ -229,10 +227,10 @@ namespace netgen Ng_Point GetPoint (int nr) const; template - Ng_Element GetElement (int nr) const; + Ng_Element GetElement (size_t nr) const; template - int GetElementIndex (int nr) const; + int GetElementIndex (size_t nr) const; /// material/boundary label of region, template argument is co-dimension template diff --git a/libsrc/include/nginterface_v2_impl.hpp b/libsrc/include/nginterface_v2_impl.hpp index b90ca8fc..8d27049d 100644 --- a/libsrc/include/nginterface_v2_impl.hpp +++ b/libsrc/include/nginterface_v2_impl.hpp @@ -5,13 +5,13 @@ NGX_INLINE DLL_HEADER Ng_Point Ngx_Mesh :: GetPoint (int nr) const template <> -NGX_INLINE DLL_HEADER int Ngx_Mesh :: GetElementIndex<0> (int nr) const +NGX_INLINE DLL_HEADER int Ngx_Mesh :: GetElementIndex<0> (size_t nr) const { return (*mesh).pointelements[nr].index; } template <> -NGX_INLINE DLL_HEADER int Ngx_Mesh :: GetElementIndex<1> (int nr) const +NGX_INLINE DLL_HEADER int Ngx_Mesh :: GetElementIndex<1> (size_t nr) const { if(mesh->GetDimension()==3) return (*mesh)[SegmentIndex(nr)].edgenr; @@ -20,21 +20,21 @@ NGX_INLINE DLL_HEADER int Ngx_Mesh :: GetElementIndex<1> (int nr) const } template <> -NGX_INLINE DLL_HEADER int Ngx_Mesh :: GetElementIndex<2> (int nr) const +NGX_INLINE DLL_HEADER int Ngx_Mesh :: GetElementIndex<2> (size_t nr) const { int ind = (*mesh)[SurfaceElementIndex(nr)].GetIndex(); return mesh->GetFaceDescriptor(ind).BCProperty(); } template <> -NGX_INLINE DLL_HEADER int Ngx_Mesh :: GetElementIndex<3> (int nr) const +NGX_INLINE DLL_HEADER int Ngx_Mesh :: GetElementIndex<3> (size_t nr) const { return (*mesh)[ElementIndex(nr)].GetIndex(); } template <> -NGX_INLINE DLL_HEADER Ng_Element Ngx_Mesh :: GetElement<0> (int nr) const +NGX_INLINE DLL_HEADER Ng_Element Ngx_Mesh :: GetElement<0> (size_t nr) const { const Element0d & el = mesh->pointelements[nr]; @@ -60,7 +60,7 @@ NGX_INLINE DLL_HEADER Ng_Element Ngx_Mesh :: GetElement<0> (int nr) const template <> -NGX_INLINE DLL_HEADER Ng_Element Ngx_Mesh :: GetElement<1> (int nr) const +NGX_INLINE DLL_HEADER Ng_Element Ngx_Mesh :: GetElement<1> (size_t nr) const { const Segment & el = mesh->LineSegment (SegmentIndex(nr)); @@ -107,7 +107,7 @@ NGX_INLINE DLL_HEADER Ng_Element Ngx_Mesh :: GetElement<1> (int nr) const } template <> -NGX_INLINE DLL_HEADER Ng_Element Ngx_Mesh :: GetElement<2> (int nr) const +NGX_INLINE DLL_HEADER Ng_Element Ngx_Mesh :: GetElement<2> (size_t nr) const { const Element2d & el = mesh->SurfaceElement (SurfaceElementIndex (nr)); @@ -146,7 +146,7 @@ NGX_INLINE DLL_HEADER Ng_Element Ngx_Mesh :: GetElement<2> (int nr) const } template <> -NGX_INLINE DLL_HEADER Ng_Element Ngx_Mesh :: GetElement<3> (int nr) const +NGX_INLINE DLL_HEADER Ng_Element Ngx_Mesh :: GetElement<3> (size_t nr) const { const Element & el = mesh->VolumeElement (ElementIndex (nr)); From 90d4c940286614d85c708a0d84ec9410fa63dc65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20Sch=C3=B6berl?= Date: Sat, 25 Feb 2017 19:48:37 +0100 Subject: [PATCH 05/10] make Topology a member of Mesh (rather then pointer) to reduce number of pointer dereferencing steps. This required move operators for Array and Table. --- libsrc/general/array.hpp | 19 ++++- libsrc/general/table.hpp | 16 +++- libsrc/meshing/meshclass.cpp | 23 +++--- libsrc/meshing/meshclass.hpp | 4 +- libsrc/meshing/topology.cpp | 154 ++++++++++++++++------------------- libsrc/meshing/topology.hpp | 25 +++--- 6 files changed, 131 insertions(+), 110 deletions(-) diff --git a/libsrc/general/array.hpp b/libsrc/general/array.hpp index 568a6d30..d6126e4b 100644 --- a/libsrc/general/array.hpp +++ b/libsrc/general/array.hpp @@ -267,6 +267,15 @@ namespace netgen (*this)[i] = a2[i]; } + /// array move + Array (Array && a2) + : FlatArray (a2.size, a2.data), allocsize(a2.allocsize), ownmem(a2.ownmem) + { + a2.size = 0; + a2.data = nullptr; + a2.allocsize = 0; + a2.ownmem = false; + } /// if responsible, deletes memory @@ -377,7 +386,15 @@ namespace netgen return *this; } - + Array & operator= (Array && a2) + { + Swap (data, a2.data); + Swap (size, a2.size); + Swap (allocsize, a2.allocsize); + Swap (ownmem, a2.ownmem); + return *this; + } + private: /// resize array, at least to size minsize. copy contents diff --git a/libsrc/general/table.hpp b/libsrc/general/table.hpp index f63b8074..e3ac08c4 100644 --- a/libsrc/general/table.hpp +++ b/libsrc/general/table.hpp @@ -34,11 +34,25 @@ protected: public: /// + BASE_TABLE (BASE_TABLE && table2) + : data(move(table2.data)), oneblock(table2.oneblock) + { + table2.oneblock = nullptr; + } + BASE_TABLE (int size); /// BASE_TABLE (const FlatArray & entrysizes, int elemsize); /// ~BASE_TABLE (); + + BASE_TABLE & operator= (BASE_TABLE && table2) + { + data = move(table2.data); + Swap (oneblock, table2.oneblock); + return *this; + } + /// void SetSize (int size); /// @@ -94,7 +108,7 @@ class TABLE : public BASE_TABLE public: /// Creates table. inline TABLE () : BASE_TABLE(0) { ; } - + /// Creates table of size size inline TABLE (int size) : BASE_TABLE (size) { ; } diff --git a/libsrc/meshing/meshclass.cpp b/libsrc/meshing/meshclass.cpp index c7930059..396631f4 100644 --- a/libsrc/meshing/meshclass.cpp +++ b/libsrc/meshing/meshclass.cpp @@ -7,7 +7,7 @@ namespace netgen static mutex buildsearchtree_mutex; Mesh :: Mesh () - : surfarea(*this) + : surfarea(*this), topology(*this) { // volelements.SetName ("vol elements"); // surfelements.SetName ("surf elements"); @@ -27,7 +27,7 @@ namespace netgen numvertices = -1; dimension = 3; - topology = new MeshTopology (*this); + // topology = new MeshTopology (*this); curvedelems = new CurvedElements (*this); clusters = new AnisotropicClusters (*this); ident = new Identifications (*this); @@ -57,7 +57,7 @@ namespace netgen delete segmentht; delete curvedelems; delete clusters; - delete topology; + // delete topology; delete ident; delete elementsearchtree; delete coarsemesh; @@ -126,8 +126,9 @@ namespace netgen delete ident; ident = new Identifications (*this); - delete topology; - topology = new MeshTopology (*this); + // delete topology; + // topology = new MeshTopology (*this); + topology = MeshTopology (*this); delete curvedelems; curvedelems = new CurvedElements (*this); delete clusters; @@ -1241,7 +1242,7 @@ namespace netgen if (ntasks == 1) // sequential run only { - topology -> Update(); + topology.Update(); clusters -> Update(); } @@ -1481,7 +1482,7 @@ namespace netgen CalcSurfacesOfNode (); - topology -> Update(); + topology.Update(); clusters -> Update(); SetNextMajorTimeStamp(); @@ -4878,12 +4879,12 @@ namespace netgen //(*testout) << "velement " << velement << endl; Array faces; - topology->GetElementFaces(velement,faces); + topology.GetElementFaces(velement,faces); //(*testout) << "faces " << faces << endl; for(int i=0; iGetFace2SurfaceElement(faces[i]); + faces[i] = topology.GetFace2SurfaceElement(faces[i]); //(*testout) << "surfel " << faces << endl; @@ -4910,7 +4911,7 @@ namespace netgen } Array faces2; - topology->GetElementFaces(velement,faces2); + topology.GetElementFaces(velement,faces2); /* cout << "no matching surf element" << endl << "p = " << p << endl @@ -5709,7 +5710,7 @@ namespace netgen void Mesh :: UpdateTopology (TaskManager tm) { - topology->Update(tm); + topology.Update(tm); clusters->Update(tm); #ifdef PARALLEL if (paralleltop) diff --git a/libsrc/meshing/meshclass.hpp b/libsrc/meshing/meshclass.hpp index 70cf0c02..c1135649 100644 --- a/libsrc/meshing/meshclass.hpp +++ b/libsrc/meshing/meshclass.hpp @@ -103,7 +103,7 @@ namespace netgen mutable int elementsearchtreets; /// element -> face, element -> edge etc ... - MeshTopology * topology; + MeshTopology topology; /// methods for high order elements class CurvedElements * curvedelems; @@ -687,7 +687,7 @@ namespace netgen const MeshTopology & GetTopology () const - { return *topology; } + { return topology; } DLL_HEADER void UpdateTopology (TaskManager tm = &DummyTaskManager); diff --git a/libsrc/meshing/topology.cpp b/libsrc/meshing/topology.cpp index 95dca2df..9d7961d5 100644 --- a/libsrc/meshing/topology.cpp +++ b/libsrc/meshing/topology.cpp @@ -44,23 +44,14 @@ namespace netgen MeshTopology :: MeshTopology (const Mesh & amesh) - : mesh(amesh) + : mesh(&amesh) { buildedges = 1; buildfaces = 1; - vert2element = 0; - vert2surfelement = 0; - vert2segment = 0; timestamp = -1; } - MeshTopology :: ~MeshTopology () - { - delete vert2element; - delete vert2surfelement; - delete vert2segment; - delete vert2pointelement; - } + MeshTopology :: ~MeshTopology () { ; } template void LoopOverEdges (const Mesh & mesh, MeshTopology & top, PointIndex v, @@ -350,13 +341,13 @@ namespace netgen #endif - if (timestamp > mesh.GetTimeStamp()) return; + if (timestamp > mesh->GetTimeStamp()) return; - int ne = mesh.GetNE(); - int nse = mesh.GetNSE(); - int nseg = mesh.GetNSeg(); - int np = mesh.GetNP(); - int nv = mesh.GetNV(); + int ne = mesh->GetNE(); + int nse = mesh->GetNSE(); + int nseg = mesh->GetNSeg(); + int np = mesh->GetNP(); + int nv = mesh->GetNV(); if (id == 0) PrintMessage (3, "Update mesh topology"); @@ -367,12 +358,7 @@ namespace netgen (*testout) << "nseg = " << nseg << endl; (*testout) << "np = " << np << endl; (*testout) << "nv = " << nv << endl; - - delete vert2element; - delete vert2surfelement; - delete vert2segment; - delete vert2pointelement; - + Array cnt(nv); Array vnums; @@ -382,69 +368,67 @@ namespace netgen vertex to surface element vertex to segment */ - - cnt = 0; for (ElementIndex ei = 0; ei < ne; ei++) { - const Element & el = mesh[ei]; + const Element & el = (*mesh)[ei]; for (int j = 0; j < el.GetNV(); j++) cnt[el[j]]++; } - vert2element = new TABLE (cnt); + vert2element = TABLE (cnt); for (ElementIndex ei = 0; ei < ne; ei++) { - const Element & el = mesh[ei]; + const Element & el = (*mesh)[ei]; for (int j = 0; j < el.GetNV(); j++) - vert2element->AddSave (el[j], ei); + vert2element.AddSave (el[j], ei); } cnt = 0; for (SurfaceElementIndex sei = 0; sei < nse; sei++) { - const Element2d & el = mesh[sei]; + const Element2d & el = (*mesh)[sei]; for (int j = 0; j < el.GetNV(); j++) cnt[el[j]]++; } - vert2surfelement = new TABLE (cnt); + vert2surfelement = TABLE (cnt); for (SurfaceElementIndex sei = 0; sei < nse; sei++) { - const Element2d & el = mesh[sei]; + const Element2d & el = (*mesh)[sei]; for (int j = 0; j < el.GetNV(); j++) - vert2surfelement->AddSave (el[j], sei); + vert2surfelement.AddSave (el[j], sei); } cnt = 0; for (SegmentIndex si = 0; si < nseg; si++) { - const Segment & seg = mesh.LineSegment(si); + const Segment & seg = mesh->LineSegment(si); cnt[seg[0]]++; cnt[seg[1]]++; } - vert2segment = new TABLE (cnt); + vert2segment = TABLE (cnt); for (SegmentIndex si = 0; si < nseg; si++) { - const Segment & seg = mesh.LineSegment(si); - vert2segment->AddSave (seg[0], si); - vert2segment->AddSave (seg[1], si); + const Segment & seg = mesh->LineSegment(si); + vert2segment.AddSave (seg[0], si); + vert2segment.AddSave (seg[1], si); } cnt = 0; - for (int pei = 0; pei < mesh.pointelements.Size(); pei++) + for (int pei = 0; pei < mesh->pointelements.Size(); pei++) { - const Element0d & pointel = mesh.pointelements[pei]; + const Element0d & pointel = mesh->pointelements[pei]; cnt[pointel.pnum]++; } - vert2pointelement = new TABLE (cnt); - for (int pei = 0; pei < mesh.pointelements.Size(); pei++) + vert2pointelement = TABLE (cnt); + for (int pei = 0; pei < mesh->pointelements.Size(); pei++) { - const Element0d & pointel = mesh.pointelements[pei]; - vert2pointelement->AddSave (pointel.pnum, pei); + const Element0d & pointel = mesh->pointelements[pei]; + vert2pointelement.AddSave (pointel.pnum, pei); } @@ -477,15 +461,15 @@ namespace netgen // ensure all coarse grid and intermediate level edges cnt = 0; - for (int i = mesh.mlbetweennodes.Begin(); i < mesh.mlbetweennodes.End(); i++) + for (int i = mesh->mlbetweennodes.Begin(); i < mesh->mlbetweennodes.End(); i++) { - INDEX_2 parents = Sort (mesh.mlbetweennodes[i]); + INDEX_2 parents = Sort (mesh->mlbetweennodes[i]); if (parents[0] >= PointIndex::BASE) cnt[parents[0]]++; } TABLE vert2vertcoarse (cnt); - for (int i = mesh.mlbetweennodes.Begin(); i < mesh.mlbetweennodes.End(); i++) + for (int i = mesh->mlbetweennodes.Begin(); i < mesh->mlbetweennodes.End(); i++) { - INDEX_2 parents = Sort (mesh.mlbetweennodes[i]); + INDEX_2 parents = Sort (mesh->mlbetweennodes[i]); if (parents[0] > PointIndex::BASE) vert2vertcoarse.AddSave (parents[0], parents[1]); } @@ -495,7 +479,7 @@ namespace netgen for (int i = PointIndex::BASE; i < nv+PointIndex::BASE; i++) { int onv = vert2edge[i].Size() + vert2vertcoarse[i].Size() + - 4*(*vert2element)[i].Size() + 2*(*vert2surfelement)[i].Size() + (*vert2segment)[i].Size(); + 4*(vert2element)[i].Size() + 2*(vert2surfelement)[i].Size() + (vert2segment)[i].Size(); max_edge_on_vertex = max (onv, max_edge_on_vertex); } @@ -504,7 +488,7 @@ namespace netgen cnt = 0; ParallelForRange - (tm, mesh.Points().Size(), + (tm, mesh->Points().Size(), [&] (size_t begin, size_t end) { INDEX_CLOSED_HASHTABLE v2eht(2*max_edge_on_vertex+10); @@ -527,7 +511,7 @@ namespace netgen v2eht.Set (v2, 33); // some value } - LoopOverEdges (mesh, *this, v, + LoopOverEdges (*mesh, *this, v, [&] (INDEX_2 edge, int elnr, int loc_edge, int element_dim, int edgedir) { if (!v2eht.Used (edge.I2())) @@ -542,7 +526,7 @@ namespace netgen // accumulate number of edges int ned = edge2vert.Size(); - for (auto v : mesh.Points().Range()) + for (auto v : mesh->Points().Range()) { auto hv = cnt[v]; cnt[v] = ned; @@ -556,7 +540,7 @@ namespace netgen // for (PointIndex v = PointIndex::BASE; v < nv+PointIndex::BASE; v++) ParallelForRange - (tm, mesh.Points().Size(), + (tm, mesh->Points().Size(), [&] (size_t begin, size_t end) { INDEX_CLOSED_HASHTABLE v2eht(2*max_edge_on_vertex+10); @@ -581,7 +565,7 @@ namespace netgen vertex2.Append (v2); } - LoopOverEdges (mesh, *this, v, + LoopOverEdges (*mesh, *this, v, [&](INDEX_2 edge, int elnr, int loc_edge, int element_dim, int edgedir) { if (!v2eht.Used(edge.I2())) @@ -600,7 +584,7 @@ namespace netgen ned++; } - LoopOverEdges (mesh, *this, v, + LoopOverEdges (*mesh, *this, v, [&](INDEX_2 edge, int elnr, int loc_edge, int element_dim, int edgedir) { int edgenum = v2eht.Get(edge.I2()); @@ -661,7 +645,7 @@ namespace netgen int max_face_on_vertex = 0; for (int i = PointIndex::BASE; i < nv+PointIndex::BASE; i++) { - int onv = vert2oldface[i].Size() + (*vert2element)[i].Size() + (*vert2surfelement)[i].Size(); + int onv = vert2oldface[i].Size() + vert2element[i].Size() + vert2surfelement[i].Size(); max_face_on_vertex = max (onv, max_face_on_vertex); } @@ -680,7 +664,7 @@ namespace netgen // for (auto v : mesh.Points().Range()) NgProfiler::StartTimer (timer2b1); ParallelForRange - (tm, mesh.Points().Size(), + (tm, mesh->Points().Size(), [&] (size_t begin, size_t end) { INDEX_3_CLOSED_HASHTABLE vert2face(2*max_face_on_vertex+10); @@ -698,7 +682,7 @@ namespace netgen vert2face.Set (face, 33); // something } int cnti = 0; - LoopOverFaces (mesh, *this, v, + LoopOverFaces (*mesh, *this, v, [&] (INDEX_4 i4, int elnr, int j, bool volume, int facedir) { INDEX_3 face(i4.I1(), i4.I2(), i4.I3()); @@ -715,7 +699,7 @@ namespace netgen // accumulate number of faces int nfa = oldnfa; - for (auto v : mesh.Points().Range()) + for (auto v : mesh->Points().Range()) { auto hv = cnt[v]; cnt[v] = nfa; @@ -726,7 +710,7 @@ namespace netgen // for (auto v : mesh.Points().Range()) ParallelForRange - (tm, mesh.Points().Size(), + (tm, mesh->Points().Size(), [&] (size_t begin, size_t end) { INDEX_3_CLOSED_HASHTABLE vert2face(2*max_face_on_vertex+10); @@ -746,7 +730,7 @@ namespace netgen vert2face.Set (face, fnr); } - LoopOverFaces (mesh, *this, v, + LoopOverFaces (*mesh, *this, v, [&] (INDEX_4 i4, int elnr, int j, bool volume, int facedir) { INDEX_3 face(i4.I1(), i4.I2(), i4.I3()); @@ -775,7 +759,7 @@ namespace netgen } - LoopOverFaces (mesh, *this, v, + LoopOverFaces (*mesh, *this, v, [&] (INDEX_4 i4, int elnr, int j, bool volume, int facedir) { INDEX_3 face(i4.I1(), i4.I2(), i4.I3()); @@ -1149,10 +1133,10 @@ namespace netgen { // (*testout) << "is face of element " << vertels[k] << endl; - if (mesh.coarsemesh && mesh.hpelements->Size() == mesh.GetNE() ) + if (mesh->coarsemesh && mesh->hpelements->Size() == mesh->GetNE() ) { const HPRefElement & hpref_el = - (*mesh.hpelements) [ mesh[vertels[k]].hp_elnr]; + (*mesh->hpelements) [ (*mesh)[vertels[k]].hp_elnr]; (*testout) << "coarse eleme = " << hpref_el.coarse_elnr << endl; } @@ -1306,7 +1290,7 @@ namespace netgen void MeshTopology :: GetElementEdges (int elnr, Array & eledges) const { - int ned = GetNEdges (mesh.VolumeElement(elnr).GetType()); + int ned = GetNEdges (mesh->VolumeElement(elnr).GetType()); eledges.SetSize (ned); for (int i = 0; i < ned; i++) eledges[i] = edges.Get(elnr)[i].nr+1; @@ -1314,7 +1298,7 @@ namespace netgen } void MeshTopology :: GetElementFaces (int elnr, Array & elfaces, bool withorientation) const { - int nfa = GetNFaces (mesh.VolumeElement(elnr).GetType()); + int nfa = GetNFaces (mesh->VolumeElement(elnr).GetType()); elfaces.SetSize (nfa); if (!withorientation) @@ -1342,7 +1326,7 @@ namespace netgen void MeshTopology :: GetElementEdgeOrientations (int elnr, Array & eorient) const { - int ned = GetNEdges (mesh.VolumeElement(elnr).GetType()); + int ned = GetNEdges (mesh->VolumeElement(elnr).GetType()); eorient.SetSize (ned); for (int i = 1; i <= ned; i++) // eorient.Elem(i) = (edges.Get(elnr)[i-1] > 0) ? 1 : -1; @@ -1352,7 +1336,7 @@ namespace netgen void MeshTopology :: GetElementFaceOrientations (int elnr, Array & forient) const { - int nfa = GetNFaces (mesh.VolumeElement(elnr).GetType()); + int nfa = GetNFaces (mesh->VolumeElement(elnr).GetType()); forient.SetSize (nfa); for (int i = 1; i <= nfa; i++) // forient.Elem(i) = faces.Get(elnr)[i-1].forient; @@ -1366,7 +1350,7 @@ namespace netgen { // int ned = GetNEdges (mesh.VolumeElement(elnr).GetType()); - if (mesh.GetDimension()==3 || 1) + if (mesh->GetDimension()==3 || 1) { if (orient) { @@ -1454,7 +1438,7 @@ namespace netgen void MeshTopology :: GetSurfaceElementEdges (int elnr, Array & eledges) const { - int ned = GetNEdges (mesh.SurfaceElement(elnr).GetType()); + int ned = GetNEdges (mesh->SurfaceElement(elnr).GetType()); eledges.SetSize (ned); for (int i = 0; i < ned; i++) // eledges[i] = abs (surfedges.Get(elnr)[i]); @@ -1463,7 +1447,7 @@ namespace netgen void MeshTopology :: GetEdges (SurfaceElementIndex elnr, Array & eledges) const { - int ned = GetNEdges (mesh[elnr].GetType()); + int ned = GetNEdges ( (*mesh)[elnr].GetType()); eledges.SetSize (ned); for (int i = 0; i < ned; i++) // eledges[i] = abs (surfedges[elnr][i])-1; @@ -1486,7 +1470,7 @@ namespace netgen void MeshTopology :: GetSurfaceElementEdgeOrientations (int elnr, Array & eorient) const { - int ned = GetNEdges (mesh.SurfaceElement(elnr).GetType()); + int ned = GetNEdges (mesh->SurfaceElement(elnr).GetType()); eorient.SetSize (ned); for (int i = 0; i < ned; i++) // eorient[i] = (surfedges.Get(elnr)[i] > 0) ? 1 : -1; @@ -1504,7 +1488,7 @@ namespace netgen int MeshTopology :: GetSurfaceElementEdges (int elnr, int * eledges, int * orient) const { int i; - if (mesh.GetDimension() == 3 || 1) + if (mesh->GetDimension() == 3 || 1) { if (orient) { @@ -1554,7 +1538,7 @@ namespace netgen int MeshTopology :: GetElementEdgeOrientation (int elnr, int locedgenr) const { - const Element & el = mesh.VolumeElement (elnr); + const Element & el = mesh->VolumeElement (elnr); const ELEMENT_EDGE * eledges = MeshTopology::GetEdges0 (el.GetType()); int k = locedgenr; @@ -1566,7 +1550,7 @@ namespace netgen int MeshTopology :: GetElementFaceOrientation (int elnr, int locfacenr) const { - const Element & el = mesh.VolumeElement (elnr); + const Element & el = mesh->VolumeElement (elnr); const ELEMENT_FACE * elfaces = MeshTopology::GetFaces0 (el.GetType()); @@ -1622,7 +1606,7 @@ namespace netgen int MeshTopology :: GetSurfaceElementEdgeOrientation (int elnr, int locedgenr) const { - const Element2d & el = mesh.SurfaceElement (elnr); + const Element2d & el = mesh->SurfaceElement (elnr); const ELEMENT_EDGE * eledges = MeshTopology::GetEdges0 (el.GetType()); int k = locedgenr; @@ -1633,7 +1617,7 @@ namespace netgen int MeshTopology :: GetSurfaceElementFaceOrientation2 (int elnr) const { - const Element2d & el = mesh.SurfaceElement (elnr); + const Element2d & el = mesh->SurfaceElement (elnr); const ELEMENT_FACE * elfaces = MeshTopology::GetFaces0 (el.GetType()); @@ -1687,7 +1671,7 @@ namespace netgen int MeshTopology :: GetSegmentEdgeOrientation (int elnr) const { - const Segment & el = mesh.LineSegment (elnr); + const Segment & el = mesh->LineSegment (elnr); const ELEMENT_EDGE * eledges = MeshTopology::GetEdges0 (el.GetType()); int k = 0; @@ -1760,7 +1744,7 @@ namespace netgen // find one element having all vertices of the face for (int i = 0; i < els.Size(); i++) { - const Element & el = mesh[els[i]]; + const Element & el = (*mesh)[els[i]]; int nref_faces = GetNFaces (el.GetType()); const ELEMENT_FACE * ref_faces = GetFaces1 (el.GetType()); int nfa_ref_edges = GetNEdges (GetFaceType(fnr)); @@ -1849,12 +1833,12 @@ namespace netgen void MeshTopology :: GetVertexElements (int vnr, Array & elements) const { - if (vert2element) + if (vert2element.Size()) { - int ne = vert2element->EntrySize(vnr); + int ne = vert2element.EntrySize(vnr); elements.SetSize(ne); for (int i = 1; i <= ne; i++) - elements.Elem(i) = vert2element->Get(vnr, i); + elements.Elem(i) = vert2element.Get(vnr, i); } } @@ -1884,13 +1868,13 @@ namespace netgen void MeshTopology :: GetVertexSurfaceElements( int vnr, Array & elements ) const { - if (vert2surfelement) + if (vert2surfelement.Size()) { int i; - int ne = vert2surfelement->EntrySize(vnr); + int ne = vert2surfelement.EntrySize(vnr); elements.SetSize(ne); for (i = 1; i <= ne; i++) - elements.Elem(i) = vert2surfelement->Get(vnr, i); + elements.Elem(i) = vert2surfelement.Get(vnr, i); } } diff --git a/libsrc/meshing/topology.hpp b/libsrc/meshing/topology.hpp index fdef9ba8..aca17d41 100644 --- a/libsrc/meshing/topology.hpp +++ b/libsrc/meshing/topology.hpp @@ -38,7 +38,7 @@ struct T_FACE class MeshTopology { - const Mesh & mesh; + const Mesh * mesh; bool buildedges; bool buildfaces; @@ -57,17 +57,22 @@ class MeshTopology Array surffaces; Array surf2volelement; Array face2surfel; - TABLE *vert2element; - TABLE *vert2surfelement; - TABLE *vert2segment; - TABLE *vert2pointelement = nullptr; + TABLE vert2element; + TABLE vert2surfelement; + TABLE vert2segment; + TABLE vert2pointelement; int timestamp; public: int GetNSurfedges() const {return surfedges.Size();} + MeshTopology () = default; + MeshTopology (const MeshTopology & top) = default; + MeshTopology (MeshTopology && top) = default; MeshTopology (const Mesh & amesh); ~MeshTopology (); - + MeshTopology & operator= (const MeshTopology & top) = default; + MeshTopology & operator= (MeshTopology && top) = default; + void SetBuildEdges (bool be) { buildedges = be; } void SetBuildFaces (bool bf) @@ -159,17 +164,17 @@ public: void GetVertexElements (int vnr, Array & elements) const; FlatArray GetVertexElements (int vnr) const - { return (*vert2element)[vnr]; } + { return vert2element[vnr]; } void GetVertexSurfaceElements( int vnr, Array& elements ) const; FlatArray GetVertexSurfaceElements (int vnr) const - { return (*vert2surfelement)[vnr]; } + { return vert2surfelement[vnr]; } FlatArray GetVertexSegments (int vnr) const - { return (*vert2segment)[vnr]; } + { return vert2segment[vnr]; } FlatArray GetVertexPointElements (int vnr) const - { return (*vert2pointelement)[vnr]; } + { return vert2pointelement[vnr]; } int GetVerticesEdge ( int v1, int v2) const; void GetSegmentVolumeElements ( int segnr, Array & els ) const; From 58555b96d98b91acd6dbc887112c7a2eafb3a028 Mon Sep 17 00:00:00 2001 From: Christopher Lackner Date: Mon, 27 Feb 2017 11:32:42 +0100 Subject: [PATCH 06/10] use Array instead of std::vector --- libsrc/csg/csgeom.hpp | 4 ++-- libsrc/csg/python_csg.cpp | 4 ++-- libsrc/csg/splinesurface.cpp | 20 ++++++++++---------- libsrc/csg/splinesurface.hpp | 22 +++++++++++----------- 4 files changed, 25 insertions(+), 25 deletions(-) diff --git a/libsrc/csg/csgeom.hpp b/libsrc/csg/csgeom.hpp index 3106326e..e925cb72 100644 --- a/libsrc/csg/csgeom.hpp +++ b/libsrc/csg/csgeom.hpp @@ -144,7 +144,7 @@ namespace netgen string filename; /// store splinesurfaces, such that added ones do not get deleted before geometry does - std::vector> spline_surfaces; + Array> spline_surfaces; public: CSGeometry (); @@ -320,7 +320,7 @@ namespace netgen virtual const Refinement & GetRefinement () const; - void AddSplineSurface (shared_ptr ss) { spline_surfaces.push_back(ss); } + void AddSplineSurface (shared_ptr ss) { spline_surfaces.Append(ss); } }; diff --git a/libsrc/csg/python_csg.cpp b/libsrc/csg/python_csg.cpp index b61a9934..a59f6f1f 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]); @@ -219,7 +219,7 @@ DLL_HEADER void ExportCSG(py::module &m) throw NgException("Cut must be SurfacePrimitive in constructor of SplineSurface!"); auto sp = dynamic_cast(sps()->GetSolid()->GetPrimitive()); if(sp) - acuts->push_back(shared_ptr(sp)); + acuts->Append(shared_ptr(sp)); else throw NgException("Cut must be SurfacePrimitive in constructor of SplineSurface!"); } diff --git a/libsrc/csg/splinesurface.cpp b/libsrc/csg/splinesurface.cpp index 65a0f988..a6e1124a 100644 --- a/libsrc/csg/splinesurface.cpp +++ b/libsrc/csg/splinesurface.cpp @@ -6,14 +6,14 @@ namespace netgen void SplineSurface :: AppendPoint(const Point<3> & p, const double reffac, const bool hpref) { auto pp = Point<3>(p); - geompoints.push_back(GeomPoint<3>(pp,reffac)); - geompoints.back().hpref = hpref; + geompoints.Append(GeomPoint<3>(pp,reffac)); + geompoints.Last().hpref = hpref; } void SplineSurface :: AppendSegment(shared_ptr> sp, string & bcname, double amaxh) { - splines.push_back(sp); - bcnames.push_back(bcname); + splines.Append(sp); + bcnames.Append(bcname); maxh.Append(amaxh); } @@ -21,7 +21,7 @@ void SplineSurface :: AppendPoint(const Point<3> & p, const double reffac, const { double eps = 1e-5; - for(int i=0; i(splines[i]->GetPoint(0)); Project(pp1); @@ -35,14 +35,14 @@ 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->push_back(cut); - for(int i = 0; iAppend(cut); + for(int i = 0; i*>(spline.get()); @@ -58,7 +58,7 @@ void SplineSurface :: AppendPoint(const Point<3> & p, const double reffac, const { plane->SetMaxH(maxh[i]); } - cuttings->push_back(plane); + cuttings->Append(plane); } else throw NgException("Spline type not implemented for SplineSurface!"); diff --git a/libsrc/csg/splinesurface.hpp b/libsrc/csg/splinesurface.hpp index 0bc5494c..e17f3eef 100644 --- a/libsrc/csg/splinesurface.hpp +++ b/libsrc/csg/splinesurface.hpp @@ -7,27 +7,27 @@ namespace netgen class SplineSurface : public OneSurfacePrimitive { protected: - std::vector> geompoints; - std::vector>> splines; - std::vector bcnames; + Array> geompoints; + Array>> splines; + Array bcnames; Array 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) { ; } virtual ~SplineSurface() { ; } const auto & GetSplines() const { return splines; } - int GetNSplines() const { return splines.size(); } - const std::vector>& GetPoints() const { return geompoints; } + int GetNSplines() const { return splines.Size(); } + const Array>& 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]; } - int GetNP() const { return geompoints.size(); } + int GetNP() const { return geompoints.Size(); } const GeomPoint<3> & GetPoint(int i) const { return geompoints[i]; } string GetBCName(int i) const { return bcnames[i]; } string GetBCNameOf(Point<3> p1, Point<3> p2) const; @@ -35,8 +35,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); } From 7b1d57b23cc05c9c5b37a5e5d04070c1a81874c9 Mon Sep 17 00:00:00 2001 From: Christopher Lackner Date: Mon, 27 Feb 2017 11:35:56 +0100 Subject: [PATCH 07/10] remove from csg header again --- libsrc/csg/csg.hpp | 1 - 1 file changed, 1 deletion(-) diff --git a/libsrc/csg/csg.hpp b/libsrc/csg/csg.hpp index ec3ad1e1..c04390a4 100644 --- a/libsrc/csg/csg.hpp +++ b/libsrc/csg/csg.hpp @@ -10,7 +10,6 @@ #include #include #include -#include // #include #include "../gprim/spline.hpp" #include "../gprim/splinegeometry.hpp" From b48a2bbd5eab69f7b11f6379b163721f239a95fc Mon Sep 17 00:00:00 2001 From: Matthias Hochsteger Date: Mon, 27 Feb 2017 07:29:57 -0800 Subject: [PATCH 08/10] Support (self written wrapper for) clcache on Windows Since clcache gets problems for .rc files, the ccache functionality is disabled in the ng/ subdirectory --- CMakeLists.txt | 5 ++--- ng/CMakeLists.txt | 2 ++ 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f2bbd4e2..4b42247f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,10 +40,9 @@ set(CPACK_PACKAGE_VERSION "${PACKAGE_VERSION}") ####################################################################### if(USE_CCACHE) - find_program(CCACHE_FOUND ccache) + find_program(CCACHE_FOUND NAMES ccache ccache.bat) if(CCACHE_FOUND) - set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache) - set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache) + set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ${CCACHE_FOUND}) endif(CCACHE_FOUND) endif(USE_CCACHE) diff --git a/ng/CMakeLists.txt b/ng/CMakeLists.txt index 33f0991d..0f36f434 100644 --- a/ng/CMakeLists.txt +++ b/ng/CMakeLists.txt @@ -5,6 +5,8 @@ if(USE_GUI) # add icon to netgen executable enable_language(RC) set(netgen_sources ${netgen_sources} ../windows/netgen.rc) + # Don't use ccache here due to incompatiblity with the resource compiler + set_directory_properties(PROPERTIES RULE_LAUNCH_COMPILE "") endif(WIN32) add_executable(netgen ${netgen_sources}) From 9c0f1b5bdbba612886ae4eb33a97b214960e550f Mon Sep 17 00:00:00 2001 From: Matthias Hochsteger Date: Tue, 7 Mar 2017 10:37:22 +0100 Subject: [PATCH 09/10] adapt parallelmesh.cpp to commit 90d4c940 (topology is a member of Mesh (rather than pointer)...) --- libsrc/meshing/parallelmesh.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/libsrc/meshing/parallelmesh.cpp b/libsrc/meshing/parallelmesh.cpp index 3de8511a..a9a84207 100644 --- a/libsrc/meshing/parallelmesh.cpp +++ b/libsrc/meshing/parallelmesh.cpp @@ -718,7 +718,7 @@ namespace netgen NgProfiler::StopTimer (timerloc2); - topology -> Update(); + topology.Update(); clusters -> Update(); // paralleltop -> UpdateCoarseGrid(); @@ -1218,7 +1218,7 @@ namespace netgen int ne = GetNE(); int nn = GetNP(); - int nedges = topology->GetNEdges(); + int nedges = topology.GetNEdges(); idxtype *xadj, * adjacency, *v_weights = NULL, *e_weights = NULL; @@ -1240,7 +1240,7 @@ namespace netgen for ( int edge = 1; edge <= nedges; edge++ ) { int v1, v2; - topology->GetEdgeVertices ( edge, v1, v2); + topology.GetEdgeVertices ( edge, v1, v2); cnt[v1-1] ++; cnt[v2-1] ++; } @@ -1257,7 +1257,7 @@ namespace netgen for ( int edge = 1; edge <= nedges; edge++ ) { int v1, v2; - topology->GetEdgeVertices ( edge, v1, v2); + topology.GetEdgeVertices ( edge, v1, v2); adjacency[ xadj[v1-1] + cnt[v1-1] ] = v2-1; adjacency[ xadj[v2-1] + cnt[v2-1] ] = v1-1; cnt[v1-1]++; @@ -1313,7 +1313,7 @@ namespace netgen // int nn = GetNP(); // int nedges = topology->GetNEdges(); - int nfaces = topology->GetNFaces(); + int nfaces = topology.GetNFaces(); idxtype *xadj, * adjacency, *v_weights = NULL, *e_weights = NULL; @@ -1340,7 +1340,7 @@ namespace netgen for ( int el=1; el <= ne; el++ ) { Element volel = VolumeElement(el); - topology->GetElementFaces(el, elfaces); + topology.GetElementFaces(el, elfaces); for ( int i = 0; i < elfaces.Size(); i++ ) { if ( facevolels1[elfaces[i]-1] == -1 ) From 5efaa2f85b40b1355c28ddd1e915a64869cecc3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20Sch=C3=B6berl?= Date: Wed, 8 Mar 2017 18:07:45 +0100 Subject: [PATCH 10/10] first add corner points to mesh, and then edge points (for consistent orientation on periodic edges) --- libsrc/geom2d/genmesh2d.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/libsrc/geom2d/genmesh2d.cpp b/libsrc/geom2d/genmesh2d.cpp index 53c33e3b..582c59c7 100644 --- a/libsrc/geom2d/genmesh2d.cpp +++ b/libsrc/geom2d/genmesh2d.cpp @@ -238,6 +238,29 @@ namespace netgen } } + // first add all vertices (for compatible orientation on periodic bnds) + { + double diam2 = Dist2(pmin, pmax); + for (int i = 0; i < splines.Size(); i++) + for (int j : { 1, 2 }) + { + Point<2> hnewp = (j == 1) ? splines[i]->StartPI() : splines[i]->EndPI(); + Point<3> newp(hnewp(0), hnewp(1), 0); + int layer = GetSpline(i).layer; + int npi = -1; + for (PointIndex pi = PointIndex::BASE; + pi < mesh2d.GetNP()+PointIndex::BASE; pi++) + if (Dist2 (mesh2d.Point(pi), newp) < 1e-12 * diam2 && mesh2d.Point(pi).GetLayer() == layer) + npi = pi; + + if (npi == -1) + { + npi = mesh2d.AddPoint (newp, layer); + searchtree.Insert (newp, npi); + } + } + } + for (int i = 0; i < splines.Size(); i++) if (GetSpline(i).copyfrom == -1) {