From 5e2d2f685c2e21652fdeb86ada0c7a3b84be8a9e Mon Sep 17 00:00:00 2001 From: Matthias Hochsteger Date: Thu, 23 Mar 2017 15:53:55 +0100 Subject: [PATCH 01/63] Fix warnings (Intel compiler) ICC complains about ambigous variable 'i' applying old/new scoping rules. Therefore, use local loop variables in for loops. --- libsrc/meshing/meshing3.cpp | 54 ++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/libsrc/meshing/meshing3.cpp b/libsrc/meshing/meshing3.cpp index 5f12c32d..9bb6b584 100644 --- a/libsrc/meshing/meshing3.cpp +++ b/libsrc/meshing/meshing3.cpp @@ -109,7 +109,7 @@ static double CalcLocH (const Array & locpoints, sum = 0; weight = 0; - for (i = 1; i <= locfaces.Size(); i++) + for(int i = 1; i <= locfaces.Size(); i++) { pc.X() = pc.Y() = pc.Z() = 0; for (j = 1; j <= 3; j++) @@ -187,7 +187,7 @@ GenerateMesh (Mesh & mesh, const MeshingParameters & mp) Array delpoints, delfaces; // points and lines to be deleted Array locelements; // new generated elements - int i, j, oldnp, oldnf; + int j, oldnp, oldnf; int found; referencetransform trans; int rotind; @@ -344,7 +344,7 @@ GenerateMesh (Mesh & mesh, const MeshingParameters & mp) allowpoint.SetSize(locpoints.Size()); if (uselocalh && stat.qualclass <= 3) - for (i = 1; i <= allowpoint.Size(); i++) + for(int i = 1; i <= allowpoint.Size(); i++) { allowpoint.Elem(i) = (mesh.GetH (locpoints.Get(i)) > 0.4 * hshould / mp.sloppy) ? 2 : 1; @@ -378,10 +378,10 @@ GenerateMesh (Mesh & mesh, const MeshingParameters & mp) { (*testout) << "inner point found" << endl; - for (i = 1; i <= groupfaces.Size(); i++) + for(int i = 1; i <= groupfaces.Size(); i++) adfront -> DeleteFace (groupfindex.Get(i)); - for (i = 1; i <= groupfaces.Size(); i++) + for(int i = 1; i <= groupfaces.Size(); i++) for (j = 1; j <= locfaces.Size(); j++) if (findex.Get(j) == groupfindex.Get(i)) delfaces.Append (j); @@ -396,7 +396,7 @@ GenerateMesh (Mesh & mesh, const MeshingParameters & mp) newel.SetNP(4); newel.PNum(4) = npi; - for (i = 1; i <= groupfaces.Size(); i++) + for(int i = 1; i <= groupfaces.Size(); i++) { for (j = 1; j <= 3; j++) { @@ -417,14 +417,14 @@ GenerateMesh (Mesh & mesh, const MeshingParameters & mp) // int optother = 0; /* - for (i = 1; i <= locfaces.Size(); i++) + for(int i = 1; i <= locfaces.Size(); i++) { (*testout) << "Face " << i << ": "; for (j = 1; j <= locfaces.Get(i).GetNP(); j++) (*testout) << pindex.Get(locfaces.Get(i).PNum(j)) << " "; (*testout) << endl; } - for (i = 1; i <= locpoints.Size(); i++) + for(int i = 1; i <= locpoints.Size(); i++) { (*testout) << "p" << i << ", gi = " << pindex.Get(i) @@ -470,7 +470,7 @@ GenerateMesh (Mesh & mesh, const MeshingParameters & mp) if (stat.cnttrials % 100 == 0) { (*testout) << "\n"; - for (i = 1; i <= canuse.Size(); i++) + for(int i = 1; i <= canuse.Size(); i++) { (*testout) << foundmap.Get(i) << "/" << canuse.Get(i) << "/" @@ -565,7 +565,7 @@ GenerateMesh (Mesh & mesh, const MeshingParameters & mp) if (testmode) { (*testout) << "found is active, 3" << endl; - for (i = 1; i <= plainpoints.Size(); i++) + for(int i = 1; i <= plainpoints.Size(); i++) { (*testout) << "p"; if (i <= pindex.Size()) @@ -582,19 +582,19 @@ GenerateMesh (Mesh & mesh, const MeshingParameters & mp) minerr = err; tempnewpoints.SetSize (0); - for (i = oldnp+1; i <= locpoints.Size(); i++) + for(int i = oldnp+1; i <= locpoints.Size(); i++) tempnewpoints.Append (locpoints.Get(i)); tempnewfaces.SetSize (0); - for (i = oldnf+1; i <= locfaces.Size(); i++) + for(int i = oldnf+1; i <= locfaces.Size(); i++) tempnewfaces.Append (locfaces.Get(i)); tempdelfaces.SetSize (0); - for (i = 1; i <= delfaces.Size(); i++) + for(int i = 1; i <= delfaces.Size(); i++) tempdelfaces.Append (delfaces.Get(i)); templocelements.SetSize (0); - for (i = 1; i <= locelements.Size(); i++) + for(int i = 1; i <= locelements.Size(); i++) templocelements.Append (locelements.Get(i)); /* @@ -624,20 +624,20 @@ GenerateMesh (Mesh & mesh, const MeshingParameters & mp) } */ - for (i = 1; i <= tempnewpoints.Size(); i++) + for(int i = 1; i <= tempnewpoints.Size(); i++) locpoints.Append (tempnewpoints.Get(i)); - for (i = 1; i <= tempnewfaces.Size(); i++) + for(int i = 1; i <= tempnewfaces.Size(); i++) locfaces.Append (tempnewfaces.Get(i)); - for (i = 1; i <= tempdelfaces.Size(); i++) + for(int i = 1; i <= tempdelfaces.Size(); i++) delfaces.Append (tempdelfaces.Get(i)); - for (i = 1; i <= templocelements.Size(); i++) + for(int i = 1; i <= templocelements.Size(); i++) locelements.Append (templocelements.Get(i)); if (loktestmode) { (*testout) << "apply rule" << endl; - for (i = 1; i <= locpoints.Size(); i++) + for(int i = 1; i <= locpoints.Size(); i++) { (*testout) << "p"; if (i <= pindex.Size()) @@ -676,7 +676,7 @@ GenerateMesh (Mesh & mesh, const MeshingParameters & mp) stat.cntelem++; } - for (i = oldnf+1; i <= locfaces.Size(); i++) + for(int i = oldnf+1; i <= locfaces.Size(); i++) { for (j = 1; j <= locfaces.Get(i).GetNP(); j++) locfaces.Elem(i).PNum(j) = @@ -685,7 +685,7 @@ GenerateMesh (Mesh & mesh, const MeshingParameters & mp) adfront->AddFace (locfaces.Get(i)); } - for (i = 1; i <= delfaces.Size(); i++) + for(int i = 1; i <= delfaces.Size(); i++) adfront->DeleteFace (findex.Get(delfaces.Get(i))); } else @@ -709,7 +709,7 @@ GenerateMesh (Mesh & mesh, const MeshingParameters & mp) PrintMessage (5, ""); // line feed after statistics - for (i = 1; i <= ruleused.Size(); i++) + for(int i = 1; i <= ruleused.Size(); i++) (*testout) << setw(4) << ruleused.Get(i) << " times used rule " << rules.Get(i) -> Name() << endl; @@ -742,7 +742,7 @@ void Meshing3 :: BlockFill (Mesh & mesh, double gh) double xminb, xmaxb, yminb, ymaxb, zminb, zmaxb; //double rad = 0.7 * gh; - for (i = 1; i <= adfront->GetNP(); i++) + for(int i = 1; i <= adfront->GetNP(); i++) { const Point3d & p = adfront->GetPoint(PointIndex(i)); if (i == 1) @@ -780,13 +780,13 @@ void Meshing3 :: BlockFill (Mesh & mesh, double gh) // initialize inner to 1 - for (i = 1; i <= n; i++) + for(int i = 1; i <= n; i++) inner.Elem(i) = BLOCKUNDEF; // set blocks cutting surfaces to 0 - for (i = 1; i <= adfront->GetNF(); i++) + for(int i = 1; i <= adfront->GetNF(); i++) { const MiniElement2d & el = adfront->GetFace(i); xminb = xmax; xmaxb = xmin; @@ -916,14 +916,14 @@ void Meshing3 :: BlockFill (Mesh & mesh, double gh) filled = 0; - for (i = 1; i <= n; i++) + for(int i = 1; i <= n; i++) if (inner.Elem(i) == BLOCKINNER) { filled++; } PrintMessage (5, "Filled blocks: ", filled); - for (i = 1; i <= n; i++) + for(int i = 1; i <= n; i++) { pointnr.Elem(i) = 0; frontpointnr.Elem(i) = 0; From 2d835e25cc39addab544fc89b7c2f03f4b28b518 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20Sch=C3=B6berl?= Date: Mon, 27 Mar 2017 15:12:43 +0200 Subject: [PATCH 02/63] add prototype GetBoundaryNeightbouringDomains --- libsrc/include/nginterface_v2.hpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libsrc/include/nginterface_v2.hpp b/libsrc/include/nginterface_v2.hpp index 7f5de1ec..d2407ea8 100644 --- a/libsrc/include/nginterface_v2.hpp +++ b/libsrc/include/nginterface_v2.hpp @@ -269,6 +269,9 @@ namespace netgen template int GetNNodes (); + // returns domain numbers of domains next to boundary bnr -> (domin, domout) + // 3D only + // std::pair GetBoundaryNeighbouringDomains (int bnr); void Refine (NG_REFINEMENT_TYPE reftype, void (*taskmanager)(function) = &DummyTaskManager2); From 9a48710988cd38a596e3170c34b6608f2a4753d2 Mon Sep 17 00:00:00 2001 From: Christoph Wintersteiger Date: Wed, 29 Mar 2017 11:22:29 +0200 Subject: [PATCH 03/63] add implementation of GetBoundaryNeighbouringDomains --- libsrc/include/nginterface_v2.hpp | 4 ++-- libsrc/interface/nginterface_v2.cpp | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/libsrc/include/nginterface_v2.hpp b/libsrc/include/nginterface_v2.hpp index d2407ea8..6dd9ff07 100644 --- a/libsrc/include/nginterface_v2.hpp +++ b/libsrc/include/nginterface_v2.hpp @@ -271,8 +271,8 @@ namespace netgen // returns domain numbers of domains next to boundary bnr -> (domin, domout) // 3D only - // std::pair GetBoundaryNeighbouringDomains (int bnr); - + std::pair GetBoundaryNeighbouringDomains (int bnr); + void Refine (NG_REFINEMENT_TYPE reftype, void (*taskmanager)(function) = &DummyTaskManager2); diff --git a/libsrc/interface/nginterface_v2.cpp b/libsrc/interface/nginterface_v2.cpp index d7548127..509d1274 100644 --- a/libsrc/interface/nginterface_v2.cpp +++ b/libsrc/interface/nginterface_v2.cpp @@ -141,6 +141,16 @@ namespace netgen return -1; } + std::pair Ngx_Mesh :: GetBoundaryNeighbouringDomains (int bnr) + { + if ( mesh->GetDimension() == 3 ) + return std::pair(mesh->GetFaceDescriptor(bnr+1).DomainIn(), + mesh->GetFaceDescriptor(bnr+1).DomainOut()); + else + return std::pair(-1,-1); + } + + /* Ng_Point Ngx_Mesh :: GetPoint (int nr) const { From 3d3a2ca18624b7203b405708df9f06a2b5415d50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20Sch=C3=B6berl?= Date: Wed, 29 Mar 2017 15:02:36 +0200 Subject: [PATCH 04/63] Revert "Merge branch 'neighbouringdomains' into 'master'" This reverts merge request !38 --- libsrc/include/nginterface_v2.hpp | 4 ++-- libsrc/interface/nginterface_v2.cpp | 10 ---------- 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/libsrc/include/nginterface_v2.hpp b/libsrc/include/nginterface_v2.hpp index 6dd9ff07..d2407ea8 100644 --- a/libsrc/include/nginterface_v2.hpp +++ b/libsrc/include/nginterface_v2.hpp @@ -271,8 +271,8 @@ namespace netgen // returns domain numbers of domains next to boundary bnr -> (domin, domout) // 3D only - std::pair GetBoundaryNeighbouringDomains (int bnr); - + // std::pair GetBoundaryNeighbouringDomains (int bnr); + void Refine (NG_REFINEMENT_TYPE reftype, void (*taskmanager)(function) = &DummyTaskManager2); diff --git a/libsrc/interface/nginterface_v2.cpp b/libsrc/interface/nginterface_v2.cpp index 509d1274..d7548127 100644 --- a/libsrc/interface/nginterface_v2.cpp +++ b/libsrc/interface/nginterface_v2.cpp @@ -141,16 +141,6 @@ namespace netgen return -1; } - std::pair Ngx_Mesh :: GetBoundaryNeighbouringDomains (int bnr) - { - if ( mesh->GetDimension() == 3 ) - return std::pair(mesh->GetFaceDescriptor(bnr+1).DomainIn(), - mesh->GetFaceDescriptor(bnr+1).DomainOut()); - else - return std::pair(-1,-1); - } - - /* Ng_Point Ngx_Mesh :: GetPoint (int nr) const { From 794d1b6598767f367e94c4aa4c1627d45478b2f4 Mon Sep 17 00:00:00 2001 From: Christopher Lackner Date: Thu, 30 Mar 2017 15:22:19 +0200 Subject: [PATCH 05/63] fix el.mat for bbnd elements in 3D --- libsrc/include/nginterface_v2_impl.hpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/libsrc/include/nginterface_v2_impl.hpp b/libsrc/include/nginterface_v2_impl.hpp index 8d27049d..53147aca 100644 --- a/libsrc/include/nginterface_v2_impl.hpp +++ b/libsrc/include/nginterface_v2_impl.hpp @@ -73,7 +73,14 @@ NGX_INLINE DLL_HEADER Ng_Element Ngx_Mesh :: GetElement<1> (size_t nr) const if (mesh->GetDimension() == 2) ret.mat = mesh->GetBCNamePtr(el.si-1); else - ret.mat = nullptr; + { + if (mesh->GetDimension() == 3){ + ret.mat = &mesh->GetCD2Name(el.edgenr-1); + } + else + ret.mat = nullptr; + } + ret.points.num = el.GetNP(); ret.points.ptr = (int*)&(el[0]); From 240a1320788e128e3ed5a4e9cd239cbbd2502e04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20Sch=C3=B6berl?= Date: Sat, 1 Apr 2017 20:59:47 +0200 Subject: [PATCH 06/63] avoid size_t-int narrowing in nginterfacev2 - GetElement --- libsrc/include/nginterface_v2_impl.hpp | 6 ++++-- libsrc/meshing/meshclass.hpp | 5 +++-- libsrc/meshing/python_mesh.cpp | 4 ++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/libsrc/include/nginterface_v2_impl.hpp b/libsrc/include/nginterface_v2_impl.hpp index 53147aca..973310a2 100644 --- a/libsrc/include/nginterface_v2_impl.hpp +++ b/libsrc/include/nginterface_v2_impl.hpp @@ -116,7 +116,8 @@ NGX_INLINE DLL_HEADER Ng_Element Ngx_Mesh :: GetElement<1> (size_t nr) const template <> NGX_INLINE DLL_HEADER Ng_Element Ngx_Mesh :: GetElement<2> (size_t nr) const { - const Element2d & el = mesh->SurfaceElement (SurfaceElementIndex (nr)); + // const Element2d & el = mesh->SurfaceElement (SurfaceElementIndex (nr)); + const Element2d & el = mesh->SurfaceElements()[nr]; Ng_Element ret; ret.type = NG_ELEMENT_TYPE(el.GetType()); @@ -155,7 +156,8 @@ NGX_INLINE DLL_HEADER Ng_Element Ngx_Mesh :: GetElement<2> (size_t nr) const template <> NGX_INLINE DLL_HEADER Ng_Element Ngx_Mesh :: GetElement<3> (size_t nr) const { - const Element & el = mesh->VolumeElement (ElementIndex (nr)); + // const Element & el = mesh->VolumeElement (ElementIndex (nr)); + const Element & el = mesh->VolumeElements()[nr]; Ng_Element ret; ret.type = NG_ELEMENT_TYPE(el.GetType()); diff --git a/libsrc/meshing/meshclass.hpp b/libsrc/meshing/meshclass.hpp index c1135649..7fc6ca1a 100644 --- a/libsrc/meshing/meshclass.hpp +++ b/libsrc/meshing/meshclass.hpp @@ -24,8 +24,9 @@ namespace netgen { public: typedef ::netgen::T_POINTS T_POINTS; - typedef Array T_VOLELEMENTS; - typedef Array T_SURFELEMENTS; + typedef Array T_VOLELEMENTS; + // typedef Array T_SURFELEMENTS; + typedef Array T_SURFELEMENTS; private: /// point coordinates diff --git a/libsrc/meshing/python_mesh.cpp b/libsrc/meshing/python_mesh.cpp index a12d21c9..c589676f 100644 --- a/libsrc/meshing/python_mesh.cpp +++ b/libsrc/meshing/python_mesh.cpp @@ -458,11 +458,11 @@ 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", From 619f9ff47f5672ef3dd0be1988a1907a16165b17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20Sch=C3=B6berl?= Date: Mon, 3 Apr 2017 11:17:47 +0200 Subject: [PATCH 07/63] GetElement returns Facet-Array. Since for 1D these are point numbers, and point numbers are (still) 1-based, we have to return also the base --- libsrc/include/nginterface_v2.hpp | 5 +++-- libsrc/include/nginterface_v2_impl.hpp | 12 +++++++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/libsrc/include/nginterface_v2.hpp b/libsrc/include/nginterface_v2.hpp index d2407ea8..b6271ecf 100644 --- a/libsrc/include/nginterface_v2.hpp +++ b/libsrc/include/nginterface_v2.hpp @@ -78,10 +78,11 @@ namespace netgen { public: size_t num; + int base; const int * ptr; - + size_t Size() const { return num; } - int operator[] (size_t i) const { return ptr[i]; } + int operator[] (size_t i) const { return ptr[i]-base; } }; diff --git a/libsrc/include/nginterface_v2_impl.hpp b/libsrc/include/nginterface_v2_impl.hpp index 973310a2..472f7e61 100644 --- a/libsrc/include/nginterface_v2_impl.hpp +++ b/libsrc/include/nginterface_v2_impl.hpp @@ -96,15 +96,14 @@ NGX_INLINE DLL_HEADER Ng_Element Ngx_Mesh :: GetElement<1> (size_t nr) const if (mesh->GetDimension() == 2) { ret.facets.num = 1; + ret.facets.base = 0; ret.facets.ptr = (int*)ret.edges.ptr; } else { - ret.facets.num = 0; - ret.facets.ptr = nullptr; - // not working as long as vertices are 1-based - // ret.facets.num = 2; - // ret.facets.ptr = (int*)&(el[0]); + ret.facets.num = 2; + ret.facets.base = 1; + ret.facets.ptr = (int*)&(el[0]); } // ret.is_curved = mesh->GetCurvedElements().IsSegmentCurved(nr); @@ -142,11 +141,13 @@ NGX_INLINE DLL_HEADER Ng_Element Ngx_Mesh :: GetElement<2> (size_t nr) const if (mesh->GetDimension() == 3) { ret.facets.num = ret.faces.num; + ret.facets.base = 0; ret.facets.ptr = (int*)ret.faces.ptr; } else { ret.facets.num = ret.edges.num; + ret.facets.base = 0; ret.facets.ptr = (int*)ret.edges.ptr; } ret.is_curved = el.IsCurved(); @@ -176,6 +177,7 @@ NGX_INLINE DLL_HEADER Ng_Element Ngx_Mesh :: GetElement<3> (size_t nr) const ret.faces.ptr = (T_FACE2*)mesh->GetTopology().GetElementFacesPtr (nr); ret.facets.num = ret.faces.num; + ret.facets.base = 0; ret.facets.ptr = (int*)ret.faces.ptr; ret.is_curved = el.IsCurved(); From 8f936f82ea3f70991697a72b0e8e492b844787ce Mon Sep 17 00:00:00 2001 From: Gerhard Kitzler Date: Mon, 3 Apr 2017 16:24:56 +0200 Subject: [PATCH 08/63] Fix data types for Python exports in python_mesh.cpp --- libsrc/meshing/python_mesh.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libsrc/meshing/python_mesh.cpp b/libsrc/meshing/python_mesh.cpp index c589676f..d80fcdb7 100644 --- a/libsrc/meshing/python_mesh.cpp +++ b/libsrc/meshing/python_mesh.cpp @@ -375,8 +375,8 @@ DLL_HEADER void ExportNetgenMeshing(py::module &m) - ExportArray(m); - ExportArray(m); + ExportArray(m); + ExportArray(m); ExportArray(m); ExportArray(m); ExportArray(m); From e1917c8d8af28d22511ccad225ce8249e3bfec21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20Sch=C3=B6berl?= Date: Mon, 3 Apr 2017 16:45:54 +0200 Subject: [PATCH 09/63] fix warnings --- libsrc/csg/zrefine.cpp | 8 ++++---- libsrc/meshing/bisect.cpp | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/libsrc/csg/zrefine.cpp b/libsrc/csg/zrefine.cpp index be18f50b..6e0df241 100644 --- a/libsrc/csg/zrefine.cpp +++ b/libsrc/csg/zrefine.cpp @@ -259,11 +259,11 @@ namespace netgen first_id.Set(); - INDEX_2_HASHTABLE & identpts = - mesh.GetIdentifications().GetIdentifiedPoints (); - - if (&identpts) + if (mesh.GetIdentifications().HasIdentifiedPoints()) { + INDEX_2_HASHTABLE & identpts = + mesh.GetIdentifications().GetIdentifiedPoints (); + for (i = 1; i <= identpts.GetNBags(); i++) for (j = 1; j <= identpts.GetBagSize(i); j++) { diff --git a/libsrc/meshing/bisect.cpp b/libsrc/meshing/bisect.cpp index 05078bf5..1662417b 100644 --- a/libsrc/meshing/bisect.cpp +++ b/libsrc/meshing/bisect.cpp @@ -46,7 +46,7 @@ namespace netgen MarkedTet() { - for (int i = 0; i < 4; i++) { faceedges[i] = 255; } + for (int i = 0; i < 4; i++) { faceedges[i] = 127; } } }; From 701d6a2369665984da0ebd2279fb8ba00de5f1f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20Sch=C3=B6berl?= Date: Mon, 3 Apr 2017 18:15:34 +0200 Subject: [PATCH 10/63] inline GetCD2NamePtr --- libsrc/include/nginterface_v2_impl.hpp | 5 ++--- libsrc/meshing/meshclass.cpp | 1 + libsrc/meshing/meshclass.hpp | 6 ++++++ 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/libsrc/include/nginterface_v2_impl.hpp b/libsrc/include/nginterface_v2_impl.hpp index 472f7e61..0bcd71d9 100644 --- a/libsrc/include/nginterface_v2_impl.hpp +++ b/libsrc/include/nginterface_v2_impl.hpp @@ -74,9 +74,8 @@ NGX_INLINE DLL_HEADER Ng_Element Ngx_Mesh :: GetElement<1> (size_t nr) const ret.mat = mesh->GetBCNamePtr(el.si-1); else { - if (mesh->GetDimension() == 3){ - ret.mat = &mesh->GetCD2Name(el.edgenr-1); - } + if (mesh->GetDimension() == 3) + ret.mat = mesh->GetCD2NamePtr(el.edgenr-1); else ret.mat = nullptr; } diff --git a/libsrc/meshing/meshclass.cpp b/libsrc/meshing/meshclass.cpp index 396631f4..396bb167 100644 --- a/libsrc/meshing/meshclass.cpp +++ b/libsrc/meshing/meshclass.cpp @@ -5832,6 +5832,7 @@ namespace netgen cd2names[cd2nr] = nullptr; } + string Mesh :: cd2_default_name = "default"; const string & Mesh :: GetCD2Name (int cd2nr) const { static string defaultstring = "default"; diff --git a/libsrc/meshing/meshclass.hpp b/libsrc/meshing/meshclass.hpp index 7fc6ca1a..cf5e7de2 100644 --- a/libsrc/meshing/meshclass.hpp +++ b/libsrc/meshing/meshclass.hpp @@ -606,6 +606,12 @@ namespace netgen DLL_HEADER void SetCD2Name (int cd2nr, const string & abcname); const string & GetCD2Name (int cd2nr ) const; + static string cd2_default_name; + string * GetCD2NamePtr (int cd2nr ) const + { + if (cd2nr < cd2names.Size() && cd2names[cd2nr]) return cd2names[cd2nr]; + return &cd2_default_name; + } size_t GetNCD2Names() const { return cd2names.Size(); } string * GetBCNamePtr (int bcnr) const From 65a474b8ef0341b0a8c7bdb7c47959d9243f0270 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20Sch=C3=B6berl?= Date: Tue, 4 Apr 2017 11:34:24 +0200 Subject: [PATCH 11/63] avoid shared-ptr copy --- libsrc/visualization/vssolution.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/libsrc/visualization/vssolution.cpp b/libsrc/visualization/vssolution.cpp index ad5223bb..95c81740 100644 --- a/libsrc/visualization/vssolution.cpp +++ b/libsrc/visualization/vssolution.cpp @@ -3350,8 +3350,6 @@ namespace netgen double lam1, double lam2, int comp, double & val) const { - shared_ptr mesh = GetMesh(); - bool ok; if (comp == 0) { @@ -3399,6 +3397,7 @@ namespace netgen case SOL_NODAL: { + shared_ptr mesh = GetMesh(); const Element2d & el = (*mesh)[selnr]; double lami[8]; @@ -3457,6 +3456,7 @@ namespace netgen case SOL_ELEMENT: { + shared_ptr mesh = GetMesh(); int el1, el2; mesh->GetTopology().GetSurface2VolumeElement (selnr+1, el1, el2); el1--; @@ -3480,6 +3480,7 @@ namespace netgen case SOL_SURFACE_NONCONTINUOUS: { + shared_ptr mesh = GetMesh(); const Element2d & el = (*mesh)[selnr]; double lami[8]; @@ -3554,12 +3555,14 @@ namespace netgen case SOL_MARKED_ELEMENTS: { + shared_ptr mesh = GetMesh(); val = (*mesh)[selnr].TestRefinementFlag(); return 1; } case SOL_ELEMENT_ORDER: - { + { + shared_ptr mesh = GetMesh(); val = (*mesh)[selnr].GetOrder(); return 1; } From dda40cf1f45dceb15c52e2e7a878cd260c72ccaf Mon Sep 17 00:00:00 2001 From: Gerhard Kitzler Date: Tue, 4 Apr 2017 11:49:32 +0200 Subject: [PATCH 12/63] MultiPoint evaluation for DrawIsoSurface --- libsrc/visualization/vssolution.cpp | 54 +++++++++++++++++++++-------- 1 file changed, 39 insertions(+), 15 deletions(-) diff --git a/libsrc/visualization/vssolution.cpp b/libsrc/visualization/vssolution.cpp index ad5223bb..5811efbd 100644 --- a/libsrc/visualization/vssolution.cpp +++ b/libsrc/visualization/vssolution.cpp @@ -1928,12 +1928,12 @@ namespace netgen Array > grid(n3); Array > locgrid(n3); Array > trans(n3); - Array val(n3); - Array > grads(n3); + Array val1(n3*sol->components); + Array > grads1(n3); Array compress(n3); MatrixFixWidth<3> pointmat(8); - grads = Vec<3> (0.0); + grads1 = Vec<3> (0.0); for (ElementIndex ei = 0; ei < ne; ei++) { @@ -2023,26 +2023,47 @@ namespace netgen } bool has_pos = 0, has_neg = 0; - + GetMultiValues( sol, ei, -1, n3, + &locgrid[0](0), &locgrid[1](0)-&locgrid[0](0), + &grid[0](0), &grid[1](0)-&grid[0](0), + &trans[0](0), &trans[1](0)-&trans[0](0), + &val1[0], sol->components); for (int i = 0; i < cnt_valid; i++) { - GetValue (sol, ei, &locgrid[i](0), &grid[i](0), &trans[i](0), comp, val[i]); - - val[i] -= minval; + // GetValue (sol, ei, &locgrid[i](0), &grid[i](0), &trans[i](0), comp, val[i]); - if (vsol) - GetValues (vsol, ei, &locgrid[i](0), &grid[i](0), &trans[i](0), &grads[i](0)); - grads[i] *= -1; + // val[i] -= minval; + val1[sol->components*i+comp-1] -= minval; - if (val[i] > 0) + // if (vsol) + // GetValues (vsol, ei, &locgrid[i](0), &grid[i](0), &trans[i](0), &grads[i](0)); + // grads[i] *= -1; + + if (val1[i*sol->components+comp-1] > 0) has_pos = 1; else has_neg = 1; + // if (val[i] > 0) + // has_pos = 1; + // else + // has_neg = 1; } if (!has_pos || !has_neg) continue; - + if (vsol) + { + GetMultiValues(vsol, ei, -1, n3, + &locgrid[0](0), &locgrid[1](0)-&locgrid[0](0), + &grid[0](0), &grid[1](0)-&grid[0](0), + &trans[0](0), &trans[1](0)-&trans[0](0), + &grads1[0](0), vsol->components); + // for (int i = 0; i < cnt_valid; i++) + // grads1[i*sol->components+comp-1] *= -1; + for (int i = 0; i < cnt_valid; i++) + grads1[i] *= -1; + + } for (int ix = 0; ix < n; ix++) for (int iy = 0; iy < n; iy++) for (int iz = 0; iz < n; iz++) @@ -2075,8 +2096,10 @@ namespace netgen if (!is_valid) continue; + // for (int j = 0; j < 4; j++) + // nodevali[j] = val[teti[j]]; for (int j = 0; j < 4; j++) - nodevali[j] = val[teti[j]]; + nodevali[j] = val1[sol->components*teti[j]+comp-1]; cntce = 0; for (int j = 0; j < 6; j++) @@ -2091,8 +2114,9 @@ namespace netgen edgelam[j] = nodevali[lpi2] / (nodevali[lpi2] - nodevali[lpi1]); edgep[j] = grid[teti[lpi1]] + (1-edgelam[j]) * (grid[teti[lpi2]]-grid[teti[lpi1]]); - normp[j] = grads[teti[lpi1]] + (1-edgelam[j]) * (grads[teti[lpi2]]-grads[teti[lpi1]]); - + // normp[j] = grads[teti[lpi1]] + (1-edgelam[j]) * (grads[teti[lpi2]]-grads[teti[lpi1]]); + normp[j] = grads1[teti[lpi1]] + (1-edgelam[j]) * (grads1[teti[lpi2]]-grads1[teti[lpi1]]); + // normp[j] = grads1[sol->components*teti[lpi1]+comp-1] + (1-edgelam[j]) * (grads1[sol->components*teti[lpi2]+comp-1]-grads1[sol->components*teti[lpi1]+comp-1]); cntce++; cpe3 = cpe2; cpe2 = cpe1; From b68bfdcc73bfaaa015b1383f78822cd937154c0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20Sch=C3=B6berl?= Date: Thu, 6 Apr 2017 21:41:26 +0200 Subject: [PATCH 13/63] more parallel --- libsrc/meshing/clusters.cpp | 38 +++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/libsrc/meshing/clusters.cpp b/libsrc/meshing/clusters.cpp index c19862b0..478013be 100644 --- a/libsrc/meshing/clusters.cpp +++ b/libsrc/meshing/clusters.cpp @@ -21,6 +21,7 @@ namespace netgen static int timer = NgProfiler::CreateTimer ("clusters"); static int timer1 = NgProfiler::CreateTimer ("clusters1"); static int timer2 = NgProfiler::CreateTimer ("clusters2"); + static int timer3 = NgProfiler::CreateTimer ("clusters3"); NgProfiler::RegionTimer reg (timer); const MeshTopology & top = mesh.GetTopology(); @@ -110,7 +111,7 @@ namespace netgen NgProfiler::StopTimer(timer1); NgProfiler::StartTimer(timer2); - + /* for (int i = 1; i <= nse; i++) { const Element2d & el = mesh.SurfaceElement(i); @@ -132,7 +133,40 @@ namespace netgen for (int j = 0; j < nnums.Size(); j++) cluster_reps.Elem(nnums[j]) = nnums[j]; } + */ + ParallelForRange + (tm, nse, + [&] (size_t begin, size_t end) + { + ArrayMem nnums, ednums; + for (int i = begin+1; i <= end; i++) + { + const Element2d & el = mesh.SurfaceElement(i); + ELEMENT_TYPE typ = el.GetType(); + + top.GetSurfaceElementEdges (i, ednums); + int fanum = top.GetSurfaceElementFace (i); + + int elnv = top.GetNVertices (typ); + int elned = ednums.Size(); + + nnums.SetSize(elnv+elned+1); + for (int j = 1; j <= elnv; j++) + nnums.Elem(j) = el.PNum(j)+1-PointIndex::BASE; + for (int j = 1; j <= elned; j++) + nnums.Elem(elnv+j) = nv+ednums.Elem(j); + nnums.Elem(elnv+elned+1) = fanum; + + for (int j = 0; j < nnums.Size(); j++) + cluster_reps.Elem(nnums[j]) = nnums[j]; + } + }); + + NgProfiler::StopTimer(timer2); + NgProfiler::StartTimer(timer3); + + static const int hex_cluster[] = { 1, 2, 3, 4, 1, 2, 3, 4, @@ -300,7 +334,7 @@ namespace netgen } } while (changed); - NgProfiler::StopTimer(timer2); + NgProfiler::StopTimer(timer3); /* (*testout) << "cluster reps:" << endl; for (i = 1; i <= cluster_reps.Size(); i++) From 8bdd94dab3f85aeced24e6050b38125f966008d7 Mon Sep 17 00:00:00 2001 From: Matthias Hochsteger Date: Fri, 7 Apr 2017 10:14:00 +0200 Subject: [PATCH 14/63] gitlab-ci: disable 32bit builds --- .gitlab-ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index a81b1469..738d4c7c 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -76,7 +76,7 @@ stages: -DCMAKE_BUILD_TYPE=Release - cmake --build . --target INSTALL --config Release -build_netgen_win32: +.build_netgen_win32: <<: *win32 <<: *tbuild_netgen_win cache: @@ -126,7 +126,7 @@ build_ubuntu_1604: - cd .. # skip since we have no machine with 32 bits -test_win32: +.test_win32: <<: *win32 <<: *test_win @@ -197,7 +197,7 @@ win64_cleanup: when: always allow_failure: true -win32_cleanup: +.win32_cleanup: <<: *win32 stage: cleanup tags: From 85a79f0ca17e1715d862959dcccb85b9d99345cd Mon Sep 17 00:00:00 2001 From: Matthias Hochsteger Date: Fri, 7 Apr 2017 16:52:01 +0200 Subject: [PATCH 15/63] Enable TkDND on MacOS --- cmake/external_projects/tcltk.cmake | 31 +++++++++++++---------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/cmake/external_projects/tcltk.cmake b/cmake/external_projects/tcltk.cmake index 174a8644..ad8c5e4a 100644 --- a/cmake/external_projects/tcltk.cmake +++ b/cmake/external_projects/tcltk.cmake @@ -30,24 +30,21 @@ if(APPLE) LOG_INSTALL 1 ) - #ExternalProject_Add(tkdnd - #DEPENDS tcl tk - #URL "http://sourceforge.net/projects/tkdnd/files/TkDND/TkDND%202.8/tkdnd2.8-src.tar.gz" - #URL_MD5 a6d47a996ea957416469b12965d4db91 - #DOWNLOAD_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external_dependencies - #PATCH_COMMAND patch -p1 < ${CMAKE_CURRENT_LIST_DIR}/tkdnd_macosx.patch - #UPDATE_COMMAND "" # Disable update - #BUILD_IN_SOURCE 1 - #CONFIGURE_COMMAND ./configure --with-tcl=${CMAKE_INSTALL_PREFIX}/../Frameworks/Tcl.framework --with-tk=${CMAKE_INSTALL_PREFIX}/../Frameworks/Tk.framework --prefix=${CMAKE_INSTALL_PREFIX}/../MacOS --libdir=${CMAKE_INSTALL_PREFIX}/../MacOS - #BUILD_COMMAND make - #INSTALL_COMMAND make install - #LOG_DOWNLOAD 1 - #LOG_CONFIGURE 1 - #LOG_BUILD 1 - #LOG_INSTALL 1 - #) + ExternalProject_Add(project_tkdnd + URL "https://sourceforge.net/projects/tkdnd/files/OS%20X%20Binaries/TkDND%202.8/tkdnd2.8-OSX-MountainLion.tar.gz" + URL_MD5 2dbb471b1d66c5f391f3c3c5b71548fb + DOWNLOAD_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external_dependencies + BUILD_IN_SOURCE 1 + CONFIGURE_COMMAND "" + BUILD_COMMAND "" + INSTALL_COMMAND ${CMAKE_COMMAND} -E copy_directory . ${CMAKE_INSTALL_PREFIX}/../MacOS + LOG_DOWNLOAD 1 + LOG_CONFIGURE 1 + LOG_BUILD 1 + LOG_INSTALL 1 + ) - list(APPEND NETGEN_DEPENDENCIES project_tcl project_tk) + list(APPEND NETGEN_DEPENDENCIES project_tcl project_tk project_tkdnd) list(APPEND CMAKE_PREFIX_PATH ${CMAKE_INSTALL_PREFIX}../Frameworks) set(TCL_INCLUDE_PATH ${CMAKE_INSTALL_PREFIX}/../Frameworks/Tcl.framework/Headers) set(TCL_LIBRARY ${CMAKE_INSTALL_PREFIX}/../Frameworks/Tcl.framework) From e6b853e995037e9f7bc36f170eeac351e5acf906 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20Sch=C3=B6berl?= Date: Tue, 11 Apr 2017 09:01:36 +0200 Subject: [PATCH 16/63] hashtables roundup to power of 2, optimize bisect --- libsrc/general/hashtabl.cpp | 28 +++++++---- libsrc/general/hashtabl.hpp | 91 +++++++++++++++++++----------------- libsrc/meshing/bisect.cpp | 89 ++++++++++++++++++++++------------- libsrc/meshing/meshclass.cpp | 31 ++++++++---- libsrc/meshing/meshclass.hpp | 2 +- libsrc/meshing/meshtype.hpp | 2 + 6 files changed, 147 insertions(+), 96 deletions(-) diff --git a/libsrc/general/hashtabl.cpp b/libsrc/general/hashtabl.cpp index fd2fbfbd..9856431e 100644 --- a/libsrc/general/hashtabl.cpp +++ b/libsrc/general/hashtabl.cpp @@ -213,19 +213,24 @@ namespace netgen BASE_INDEX_2_CLOSED_HASHTABLE :: - BASE_INDEX_2_CLOSED_HASHTABLE (int size) - : hash(size) + BASE_INDEX_2_CLOSED_HASHTABLE (size_t size) + : hash(RoundUp2(size)) { + size = hash.Size(); + mask = size-1; // hash.SetName ("i2-hashtable, hash"); invalid = -1; - for (int i = 1; i <= size; i++) - hash.Elem(i).I1() = invalid; + for (size_t i = 0; i < size; i++) + hash[i].I1() = invalid; } void BASE_INDEX_2_CLOSED_HASHTABLE :: BaseSetSize (int size) { + size = RoundUp2 (size); + mask = size-1; + hash.SetSize(size); for (int i = 1; i <= size; i++) hash.Elem(i).I1() = invalid; @@ -245,25 +250,28 @@ namespace netgen } } - int BASE_INDEX_2_CLOSED_HASHTABLE :: + bool BASE_INDEX_2_CLOSED_HASHTABLE :: PositionCreate2 (const INDEX_2 & ind, int & apos) { int i = HashValue(ind); int startpos = i; while (1) { + /* i++; if (i > hash.Size()) i = 1; - if (hash.Get(i) == ind) + */ + i = (i+1) % hash.Size(); + if (hash[i] == ind) { apos = i; - return 0; + return false; } - if (hash.Get(i).I1() == invalid) + if (hash[i].I1() == invalid) { - hash.Elem(i) = ind; + hash[i] = ind; apos = i; - return 1; + return true; } if (i == startpos) throw NgException ("Try to set new element in full closed hashtable"); diff --git a/libsrc/general/hashtabl.hpp b/libsrc/general/hashtabl.hpp index b856bbc6..72263cba 100644 --- a/libsrc/general/hashtabl.hpp +++ b/libsrc/general/hashtabl.hpp @@ -628,7 +628,12 @@ public: - + inline size_t RoundUp2 (size_t i) + { + size_t res = 1; + while (res < i) res *= 2; // hope it will never be too large + return res; + } /// Closed Hashing HT @@ -640,47 +645,52 @@ protected: Array hash; /// int invalid; + size_t mask; public: /// - BASE_INDEX_2_CLOSED_HASHTABLE (int size); + BASE_INDEX_2_CLOSED_HASHTABLE (size_t size); int Size() const { return hash.Size(); } - int UsedPos (int pos) const { return ! (hash.Get(pos).I1() == invalid); } + bool UsedPos0 (int pos) const { return ! (hash[pos].I1() == invalid); } int UsedElements () const; /// int HashValue (const INDEX_2 & ind) const { - return (ind.I1() + 71 * ind.I2()) % hash.Size() + 1; + // return (ind.I1() + 71 * ind.I2()) % hash.Size() + 1; + return (ind.I1() + 71 * ind.I2()) & mask; } - int Position (const INDEX_2 & ind) const + int Position0 (const INDEX_2 & ind) const { int i = HashValue(ind); while (1) { - if (hash.Get(i) == ind) return i; - if (hash.Get(i).I1() == invalid) return 0; + if (hash[i] == ind) return i; + if (hash[i].I1() == invalid) return -1; + i = (i+1) & mask; + /* i++; if (i > hash.Size()) i = 1; + */ } } // returns 1, if new postion is created - int PositionCreate (const INDEX_2 & ind, int & apos) + bool PositionCreate0 (const INDEX_2 & ind, int & apos) { int i = HashValue (ind); - if (hash.Get(i) == ind) + if (hash[i] == ind) { apos = i; - return 0; + return false; } - if (hash.Get(i).I1() == invalid) + if (hash[i].I1() == invalid) { - hash.Elem(i) = ind; + hash[i] = ind; apos = i; - return 1; + return true; } return PositionCreate2 (ind, apos); } @@ -689,7 +699,7 @@ protected: /// int Position2 (const INDEX_2 & ind) const; - int PositionCreate2 (const INDEX_2 & ind, int & apos); + bool PositionCreate2 (const INDEX_2 & ind, int & apos); void BaseSetSize (int asize); }; @@ -711,15 +721,15 @@ public: /// inline bool Used (const INDEX_2 & ahash) const; /// - inline void SetData (int pos, const INDEX_2 & ahash, const T & acont); + inline void SetData0 (int pos, const INDEX_2 & ahash, const T & acont); /// - inline void GetData (int pos, INDEX_2 & ahash, T & acont) const; + inline void GetData0 (int pos, INDEX_2 & ahash, T & acont) const; /// - inline void SetData (int pos, const T & acont); + inline void SetData0 (int pos, const T & acont); /// - inline void GetData (int pos, T & acont) const; + inline void GetData0 (int pos, T & acont) const; /// - const T & GetData (int pos) { return cont.Get(pos); } + const T & GetData0 (int pos) { return cont[pos]; } /// inline void SetSize (int size); /// @@ -755,13 +765,6 @@ inline ostream & operator<< (ostream & ost, const INDEX_2_CLOSED_HASHTABLE & - inline size_t RoundUp2 (size_t i) - { - size_t res = 1; - while (res < i) res *= 2; // hope it will never be too large - return res; - } - class BASE_INDEX_3_CLOSED_HASHTABLE { protected: @@ -1192,7 +1195,7 @@ inline void INDEX_HASHTABLE :: PrintMemInfo (ostream & ost) const template inline INDEX_2_CLOSED_HASHTABLE :: INDEX_2_CLOSED_HASHTABLE (int size) - : BASE_INDEX_2_CLOSED_HASHTABLE(size), cont(size) + : BASE_INDEX_2_CLOSED_HASHTABLE(size), cont(RoundUp2(size)) { // cont.SetName ("i2-hashtable, contents"); } @@ -1202,55 +1205,55 @@ inline void INDEX_2_CLOSED_HASHTABLE :: Set (const INDEX_2 & ahash, const T & acont) { int pos; - PositionCreate (ahash, pos); - hash.Elem(pos) = ahash; - cont.Elem(pos) = acont; + PositionCreate0 (ahash, pos); + hash[pos] = ahash; + cont[pos] = acont; } template inline const T & INDEX_2_CLOSED_HASHTABLE :: Get (const INDEX_2 & ahash) const { - int pos = Position (ahash); - return cont.Get(pos); + int pos = Position0 (ahash); + return cont[pos]; } template inline bool INDEX_2_CLOSED_HASHTABLE :: Used (const INDEX_2 & ahash) const { - int pos = Position (ahash); - return (pos != 0); + int pos = Position0 (ahash); + return (pos != -1); } template inline void INDEX_2_CLOSED_HASHTABLE :: -SetData (int pos, const INDEX_2 & ahash, const T & acont) +SetData0 (int pos, const INDEX_2 & ahash, const T & acont) { - hash.Elem(pos) = ahash; - cont.Elem(pos) = acont; + hash[pos] = ahash; + cont[pos] = acont; } template inline void INDEX_2_CLOSED_HASHTABLE :: -GetData (int pos, INDEX_2 & ahash, T & acont) const +GetData0 (int pos, INDEX_2 & ahash, T & acont) const { - ahash = hash.Get(pos); - acont = cont.Get(pos); + ahash = hash[pos]; + acont = cont[pos]; } template inline void INDEX_2_CLOSED_HASHTABLE :: -SetData (int pos, const T & acont) +SetData0 (int pos, const T & acont) { - cont.Elem(pos) = acont; + cont[pos] = acont; } template inline void INDEX_2_CLOSED_HASHTABLE :: -GetData (int pos, T & acont) const +GetData0 (int pos, T & acont) const { - acont = cont.Get(pos); + acont = cont[pos]; } diff --git a/libsrc/meshing/bisect.cpp b/libsrc/meshing/bisect.cpp index 1662417b..d4941b97 100644 --- a/libsrc/meshing/bisect.cpp +++ b/libsrc/meshing/bisect.cpp @@ -1723,27 +1723,28 @@ namespace netgen - int MarkHangingTris (T_MTRIS & mtris, + bool MarkHangingTris (T_MTRIS & mtris, const INDEX_2_CLOSED_HASHTABLE & cutedges) { - int hanging = 0; - for (int i = 1; i <= mtris.Size(); i++) + bool hanging = false; + // for (int i = 1; i <= mtris.Size(); i++) + for (auto & tri : mtris) { - if (mtris.Get(i).marked) + if (tri.marked) { - hanging = 1; + hanging = true; continue; } for (int j = 0; j < 2; j++) for (int k = j+1; k < 3; k++) { - INDEX_2 edge(mtris.Get(i).pnums[j], - mtris.Get(i).pnums[k]); + INDEX_2 edge(tri.pnums[j], + tri.pnums[k]); edge.Sort(); if (cutedges.Used (edge)) { - mtris.Elem(i).marked = 1; - hanging = 1; + tri.marked = 1; + hanging = true; } } } @@ -2620,14 +2621,22 @@ namespace netgen static int timer = NgProfiler::CreateTimer ("Bisect"); static int timer1 = NgProfiler::CreateTimer ("Bisect 1"); + static int timer1a = NgProfiler::CreateTimer ("Bisect 1a"); + static int timer1b = NgProfiler::CreateTimer ("Bisect 1b"); static int timer2 = NgProfiler::CreateTimer ("Bisect 2"); + static int timer2a = NgProfiler::CreateTimer ("Bisect 2a"); + static int timer2b = NgProfiler::CreateTimer ("Bisect 2b"); + static int timer2c = NgProfiler::CreateTimer ("Bisect 2c"); static int timer3 = NgProfiler::CreateTimer ("Bisect 3"); + static int timer3a = NgProfiler::CreateTimer ("Bisect 3a"); + static int timer3b = NgProfiler::CreateTimer ("Bisect 3b"); static int timer_bisecttet = NgProfiler::CreateTimer ("Bisect tets"); static int timer_bisecttrig = NgProfiler::CreateTimer ("Bisect trigs"); + static int timer_bisectsegms = NgProfiler::CreateTimer ("Bisect segms"); NgProfiler::RegionTimer reg1 (timer); NgProfiler::StartTimer (timer1); - + NgProfiler::StartTimer (timer1a); static int localizetimer = NgProfiler::CreateTimer("localize edgepoints"); NgProfiler::RegionTimer * loct = new NgProfiler::RegionTimer(localizetimer); LocalizeEdgePoints(mesh); @@ -2756,7 +2765,8 @@ namespace netgen INDEX_2_CLOSED_HASHTABLE cutedges(10 + 9 * (mtets.Size()+mprisms.Size()+mtris.Size()+mquads.Size())); bool noprojection = false; - + NgProfiler::StopTimer (timer1a); + for (int l = 1; l <= 1; l++) { int marked = 0; @@ -3169,7 +3179,6 @@ namespace netgen //string yn; //cin >> yn; - NgProfiler::StopTimer (timer1); (*testout) << "refine volume elements" << endl; do @@ -3369,7 +3378,10 @@ namespace netgen mtris.Append (newtri2); mesh.mlparentsurfaceelement.Append (i); } - + + NgProfiler::StopTimer (timer_bisecttrig); + + int nquad = mquads.Size(); for (int i = 1; i <= nquad; i++) if (mquads.Elem(i).marked) @@ -3461,15 +3473,15 @@ namespace netgen mquads.Elem(i) = newquad1; mquads.Append (newquad2); } - - NgProfiler::StopTimer (timer_bisecttrig); - + + NgProfiler::StartTimer (timer1b); hangingsurf = MarkHangingTris (mtris, cutedges) + MarkHangingQuads (mquads, cutedges); hangingedge = 0; - + NgProfiler::StopTimer (timer1b); + NgProfiler::StartTimer (timer_bisectsegms); int nseg = mesh.GetNSeg (); for (int i = 1; i <= nseg; i++) { @@ -3506,6 +3518,8 @@ namespace netgen mesh.AddSegment (nseg2); } } + + NgProfiler::StopTimer (timer_bisectsegms); } while (hangingvol || hangingsurf || hangingedge); @@ -3534,6 +3548,8 @@ namespace netgen PrintMessage (4, mesh.GetNP(), " points"); } + NgProfiler::StopTimer (timer1); + // (*testout) << "mtets = " << mtets << endl; @@ -3579,6 +3595,8 @@ namespace netgen } NgProfiler::StartTimer (timer2); + + NgProfiler::StartTimer (timer2a); mtets.SetAllocSize (mtets.Size()); mprisms.SetAllocSize (mprisms.Size()); @@ -3654,15 +3672,18 @@ namespace netgen } mesh.ClearSurfaceElements(); - for (int i = 1; i <= mtris.Size(); i++) + mesh.SurfaceElements().SetAllocSize (mtris.Size()+mquads.Size()); + NgProfiler::StopTimer (timer2a); + NgProfiler::StartTimer (timer2b); + for (auto & trig : mtris) { Element2d el(TRIG); - el.SetIndex (mtris.Get(i).surfid); - el.SetOrder (mtris.Get(i).order); - for (int j = 1; j <= 3; j++) + el.SetIndex (trig.surfid); + el.SetOrder (trig.order); + for (int j = 0; j < 3; j++) { - el.PNum(j) = mtris.Get(i).pnums[j-1]; - el.GeomInfoPi(j) = mtris.Get(i).pgeominfo[j-1]; + el[j] = trig.pnums[j]; + el.GeomInfoPi(j+1) = trig.pgeominfo[j]; } mesh.AddSurfaceElement (el); } @@ -3675,7 +3696,7 @@ namespace netgen Swap (el.PNum(3), el.PNum(4)); mesh.AddSurfaceElement (el); } - + NgProfiler::StopTimer (timer2b); // write multilevel hierarchy to mesh: @@ -3705,12 +3726,12 @@ namespace netgen BitArray isnewpoint(np); isnewpoint.Clear(); - for (int i = 1; i <= cutedges.Size(); i++) - if (cutedges.UsedPos(i)) + for (int i = 0; i < cutedges.Size(); i++) + if (cutedges.UsedPos0(i)) { INDEX_2 edge; PointIndex newpi; - cutedges.GetData (i, edge, newpi); + cutedges.GetData0 (i, edge, newpi); isnewpoint.Set(newpi); mesh.mlbetweennodes.Elem(newpi) = edge; } @@ -3811,12 +3832,12 @@ namespace netgen } */ - for (int j = 1; j <= cutedges.Size(); j++) - if (cutedges.UsedPos(j)) + for (int j = 0; j < cutedges.Size(); j++) + if (cutedges.UsedPos0(j)) { INDEX_2 i2; PointIndex newpi; - cutedges.GetData (j, i2, newpi); + cutedges.GetData0 (j, i2, newpi); INDEX_2 oi2(identmap.Get(i2.I1()), identmap.Get(i2.I2())); oi2.Sort(); @@ -3960,9 +3981,10 @@ namespace netgen NgProfiler::StopTimer (timer2); NgProfiler::StartTimer (timer3); - - mesh.UpdateTopology(opt.task_manager); + NgProfiler::StartTimer (timer3a); + mesh.UpdateTopology(opt.task_manager); + NgProfiler::StopTimer (timer3a); @@ -3976,8 +3998,9 @@ namespace netgen ofst.close(); } - + NgProfiler::StartTimer (timer3b); mesh.CalcSurfacesOfNode(); + NgProfiler::StopTimer (timer3b); PrintMessage (1, "Bisection done"); diff --git a/libsrc/meshing/meshclass.cpp b/libsrc/meshing/meshclass.cpp index 396bb167..17fd6ba4 100644 --- a/libsrc/meshing/meshclass.cpp +++ b/libsrc/meshing/meshclass.cpp @@ -116,7 +116,7 @@ namespace netgen surfelements.SetSize(0); volelements.SetSize(0); lockedpoints.SetSize(0); - surfacesonnode.SetSize(0); + // surfacesonnode.SetSize(0); delete boundaryedges; boundaryedges = NULL; @@ -1593,12 +1593,14 @@ namespace netgen void Mesh :: CalcSurfacesOfNode () { - surfacesonnode.SetSize (GetNP()); + // surfacesonnode.SetSize (GetNP()); + TABLE surfacesonnode(GetNP()); delete boundaryedges; boundaryedges = NULL; delete surfelementht; + surfelementht = nullptr; delete segmentht; /* @@ -1606,9 +1608,11 @@ namespace netgen segmentht = new INDEX_2_HASHTABLE (GetNSeg() + 1); */ - surfelementht = new INDEX_3_CLOSED_HASHTABLE (3*GetNSE() + 1); + if (dimension == 3) + surfelementht = new INDEX_3_CLOSED_HASHTABLE (3*GetNSE() + 1); segmentht = new INDEX_2_CLOSED_HASHTABLE (3*GetNSeg() + 1); + if (dimension == 3) for (SurfaceElementIndex sei = 0; sei < GetNSE(); sei++) { const Element2d & sel = surfelements[sei]; @@ -1619,6 +1623,9 @@ namespace netgen for (int j = 0; j < sel.GetNP(); j++) { PointIndex pi = sel[j]; + if (!surfacesonnode[pi].Contains(si)) + surfacesonnode.Add (pi, si); + /* bool found = 0; for (int k = 0; k < surfacesonnode[pi].Size(); k++) if (surfacesonnode[pi][k] == si) @@ -1629,6 +1636,7 @@ namespace netgen if (!found) surfacesonnode.Add (pi, si); + */ } } /* @@ -1647,6 +1655,8 @@ namespace netgen surfelementht -> AllocateElements(); */ + + if (dimension==3) for (SurfaceElementIndex sei = 0; sei < GetNSE(); sei++) { const Element2d & sel = surfelements[sei]; @@ -3665,11 +3675,11 @@ namespace netgen { bool sege = false, be = false; - int pos = boundaryedges -> Position(INDEX_2::Sort(el[i], el[j])); - if (pos) + int pos = boundaryedges -> Position0(INDEX_2::Sort(el[i], el[j])); + if (pos != -1) { be = true; - if (boundaryedges -> GetData(pos) == 2) + if (boundaryedges -> GetData0(pos) == 2) sege = true; } @@ -5545,6 +5555,7 @@ namespace netgen if (el[j] > numvertices) numvertices = el[j]; } + /* for (i = 1; i <= nse; i++) { const Element2d & el = SurfaceElement(i); @@ -5553,6 +5564,10 @@ namespace netgen if (el.PNum(j) > numvertices) numvertices = el.PNum(j); } + */ + for (auto & el : SurfaceElements()) + for (PointIndex v : el.Vertices()) + if (v > numvertices) numvertices = v; numvertices += 1- PointIndex::BASE; } @@ -5917,8 +5932,8 @@ namespace netgen << sizeof (Element) << " = " << GetNE() * sizeof(Element) << endl; - ost << "surfs on node:"; - surfacesonnode.PrintMemInfo (cout); + // ost << "surfs on node:"; + // surfacesonnode.PrintMemInfo (cout); ost << "boundaryedges: "; if (boundaryedges) diff --git a/libsrc/meshing/meshclass.hpp b/libsrc/meshing/meshclass.hpp index cf5e7de2..6ec7627a 100644 --- a/libsrc/meshing/meshclass.hpp +++ b/libsrc/meshing/meshclass.hpp @@ -43,7 +43,7 @@ namespace netgen /// surface indices at boundary nodes - TABLE surfacesonnode; + // TABLE surfacesonnode; /// boundary edges (1..normal bedge, 2..segment) INDEX_2_CLOSED_HASHTABLE * boundaryedges; /// diff --git a/libsrc/meshing/meshtype.hpp b/libsrc/meshing/meshtype.hpp index 92acaaf7..1471c541 100644 --- a/libsrc/meshing/meshtype.hpp +++ b/libsrc/meshing/meshtype.hpp @@ -422,6 +422,8 @@ namespace netgen { return FlatArray (np, &pnum[0]); } FlatArray PNums () { return FlatArray (np, &pnum[0]); } + auto Vertices() const + { return FlatArray (GetNV(), &pnum[0]); } /// PointIndex & PNum (int i) { return pnum[i-1]; } From 4382fc116895d0727b040a89bbb96c51ee49c5d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20Sch=C3=B6berl?= Date: Tue, 11 Apr 2017 10:04:33 +0200 Subject: [PATCH 17/63] fix hashtable --- libsrc/general/hashtabl.cpp | 4 +- libsrc/general/hashtabl.hpp | 151 +++++++++++++----------------------- 2 files changed, 56 insertions(+), 99 deletions(-) diff --git a/libsrc/general/hashtabl.cpp b/libsrc/general/hashtabl.cpp index 9856431e..a9ef002c 100644 --- a/libsrc/general/hashtabl.cpp +++ b/libsrc/general/hashtabl.cpp @@ -232,8 +232,8 @@ namespace netgen mask = size-1; hash.SetSize(size); - for (int i = 1; i <= size; i++) - hash.Elem(i).I1() = invalid; + for (size_t i = 0; i < size; i++) + hash[i].I1() = invalid; } diff --git a/libsrc/general/hashtabl.hpp b/libsrc/general/hashtabl.hpp index 72263cba..cdc504b5 100644 --- a/libsrc/general/hashtabl.hpp +++ b/libsrc/general/hashtabl.hpp @@ -707,31 +707,65 @@ protected: template class INDEX_2_CLOSED_HASHTABLE : public BASE_INDEX_2_CLOSED_HASHTABLE { - /// -// MoveableArray cont; Array cont; - public: + INDEX_2_CLOSED_HASHTABLE (size_t size) + : BASE_INDEX_2_CLOSED_HASHTABLE(size), cont(RoundUp2(size)) + { ; } + + void Set (const INDEX_2 & ahash, const T & acont) + { + int pos; + PositionCreate0 (ahash, pos); + hash[pos] = ahash; + cont[pos] = acont; + } + + const T & Get (const INDEX_2 & ahash) const + { + int pos = Position0 (ahash); + return cont[pos]; + } + + inline bool Used (const INDEX_2 & ahash) const + { + int pos = Position0 (ahash); + return (pos != -1); + } + + inline void SetData0 (int pos, const INDEX_2 & ahash, const T & acont) + { + hash[pos] = ahash; + cont[pos] = acont; + } + /// - inline INDEX_2_CLOSED_HASHTABLE (int size); - /// - inline void Set (const INDEX_2 & ahash, const T & acont); - /// - inline const T & Get (const INDEX_2 & ahash) const; - /// - inline bool Used (const INDEX_2 & ahash) const; - /// - inline void SetData0 (int pos, const INDEX_2 & ahash, const T & acont); - /// - inline void GetData0 (int pos, INDEX_2 & ahash, T & acont) const; - /// - inline void SetData0 (int pos, const T & acont); - /// - inline void GetData0 (int pos, T & acont) const; + inline void GetData0 (int pos, INDEX_2 & ahash, T & acont) const + { + ahash = hash[pos]; + acont = cont[pos]; + } + + inline void SetData0 (int pos, const T & acont) + { + cont[pos] = acont; + } + + inline void GetData0 (int pos, T & acont) const + { + acont = cont[pos]; + } + /// const T & GetData0 (int pos) { return cont[pos]; } /// - inline void SetSize (int size); + inline void SetSize (size_t size) + { + BaseSetSize(size); + cont.SetSize(RoundUp2(size)); + } + + /// inline void PrintMemInfo (ostream & ost) const; /// @@ -756,7 +790,7 @@ inline ostream & operator<< (ostream & ost, const INDEX_2_CLOSED_HASHTABLE & { INDEX_2 hash; T data; - ht.GetData (i, hash, data); + ht.GetData0 (i, hash, data); ost << "hash = " << hash << ", data = " << data << endl; } return ost; @@ -1189,83 +1223,6 @@ inline void INDEX_HASHTABLE :: PrintMemInfo (ostream & ost) const /* *********** Closed Hashing ************************* */ - - - -template -inline INDEX_2_CLOSED_HASHTABLE :: -INDEX_2_CLOSED_HASHTABLE (int size) - : BASE_INDEX_2_CLOSED_HASHTABLE(size), cont(RoundUp2(size)) -{ - // cont.SetName ("i2-hashtable, contents"); -} - -template -inline void INDEX_2_CLOSED_HASHTABLE :: -Set (const INDEX_2 & ahash, const T & acont) -{ - int pos; - PositionCreate0 (ahash, pos); - hash[pos] = ahash; - cont[pos] = acont; -} - -template -inline const T & INDEX_2_CLOSED_HASHTABLE :: -Get (const INDEX_2 & ahash) const -{ - int pos = Position0 (ahash); - return cont[pos]; -} - -template -inline bool INDEX_2_CLOSED_HASHTABLE :: -Used (const INDEX_2 & ahash) const -{ - int pos = Position0 (ahash); - return (pos != -1); -} - -template -inline void INDEX_2_CLOSED_HASHTABLE :: -SetData0 (int pos, const INDEX_2 & ahash, const T & acont) -{ - hash[pos] = ahash; - cont[pos] = acont; -} - -template -inline void INDEX_2_CLOSED_HASHTABLE :: -GetData0 (int pos, INDEX_2 & ahash, T & acont) const -{ - ahash = hash[pos]; - acont = cont[pos]; -} - -template -inline void INDEX_2_CLOSED_HASHTABLE :: -SetData0 (int pos, const T & acont) -{ - cont[pos] = acont; -} - -template -inline void INDEX_2_CLOSED_HASHTABLE :: -GetData0 (int pos, T & acont) const -{ - acont = cont[pos]; -} - - -template -inline void INDEX_2_CLOSED_HASHTABLE :: -SetSize (int size) -{ - BaseSetSize(size); - cont.SetSize(size); -} - - template inline void INDEX_2_CLOSED_HASHTABLE :: From 0074d8b407a07945ebee8362ef7a2e49cdd54bec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20Sch=C3=B6berl?= Date: Tue, 11 Apr 2017 10:45:11 +0200 Subject: [PATCH 18/63] inline GetTimeStamp --- libsrc/meshing/global.cpp | 4 +++- libsrc/meshing/meshtype.hpp | 14 +++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/libsrc/meshing/global.cpp b/libsrc/meshing/global.cpp index f01a0ab8..4a6237c3 100644 --- a/libsrc/meshing/global.cpp +++ b/libsrc/meshing/global.cpp @@ -88,7 +88,8 @@ namespace netgen DebugParameters debugparam; bool verbose = 0; - int timestamp = 0; + size_t timestamp = 0; + /* int GetTimeStamp() { return timestamp; @@ -99,4 +100,5 @@ namespace netgen timestamp++; return timestamp; } + */ } diff --git a/libsrc/meshing/meshtype.hpp b/libsrc/meshing/meshtype.hpp index 1471c541..fe2b98af 100644 --- a/libsrc/meshing/meshtype.hpp +++ b/libsrc/meshing/meshtype.hpp @@ -54,10 +54,22 @@ namespace netgen enum OPTIMIZEGOAL { OPT_QUALITY, OPT_CONFORM, OPT_REST, OPT_WORSTCASE, OPT_LEGAL }; + extern size_t timestamp; + inline size_t GetTimeStamp() + { + return timestamp; + } + inline size_t NextTimeStamp() + { + timestamp++; + return timestamp; + } + + /* extern DLL_HEADER int GetTimeStamp(); extern DLL_HEADER int NextTimeStamp(); - + */ class PointGeomInfo { public: From e464fe9771c748b08c4be1fc5082e0d22616e685 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20Sch=C3=B6berl?= Date: Tue, 11 Apr 2017 10:45:31 +0200 Subject: [PATCH 19/63] parallel trig-marking for bisection --- libsrc/meshing/bisect.cpp | 53 +++++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 22 deletions(-) diff --git a/libsrc/meshing/bisect.cpp b/libsrc/meshing/bisect.cpp index d4941b97..765ee80e 100644 --- a/libsrc/meshing/bisect.cpp +++ b/libsrc/meshing/bisect.cpp @@ -1724,30 +1724,39 @@ namespace netgen bool MarkHangingTris (T_MTRIS & mtris, - const INDEX_2_CLOSED_HASHTABLE & cutedges) + const INDEX_2_CLOSED_HASHTABLE & cutedges, + TaskManager tm) { bool hanging = false; // for (int i = 1; i <= mtris.Size(); i++) - for (auto & tri : mtris) - { - if (tri.marked) - { - hanging = true; - continue; - } - for (int j = 0; j < 2; j++) - for (int k = j+1; k < 3; k++) - { - INDEX_2 edge(tri.pnums[j], - tri.pnums[k]); - edge.Sort(); - if (cutedges.Used (edge)) - { - tri.marked = 1; - hanging = true; - } - } - } + // for (auto & tri : mtris) + ParallelForRange + (tm, mtris.Size(), [&] (size_t begin, size_t end) + { + bool my_hanging = false; + for (size_t i = begin; i < end; i++) + { + auto & tri = mtris[i]; + if (tri.marked) + { + my_hanging = true; + continue; + } + for (int j = 0; j < 2; j++) + for (int k = j+1; k < 3; k++) + { + INDEX_2 edge(tri.pnums[j], + tri.pnums[k]); + edge.Sort(); + if (cutedges.Used (edge)) + { + tri.marked = 1; + my_hanging = true; + } + } + } + if (my_hanging) hanging = true; + }); return hanging; } @@ -3476,7 +3485,7 @@ namespace netgen NgProfiler::StartTimer (timer1b); hangingsurf = - MarkHangingTris (mtris, cutedges) + + MarkHangingTris (mtris, cutedges, opt.task_manager) + MarkHangingQuads (mquads, cutedges); hangingedge = 0; From 5e320a55565e47f657ac430cc03854f8930d318a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20Sch=C3=B6berl?= Date: Tue, 11 Apr 2017 10:51:08 +0200 Subject: [PATCH 20/63] dll-header ? --- libsrc/meshing/meshtype.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libsrc/meshing/meshtype.hpp b/libsrc/meshing/meshtype.hpp index fe2b98af..bf053a88 100644 --- a/libsrc/meshing/meshtype.hpp +++ b/libsrc/meshing/meshtype.hpp @@ -54,7 +54,7 @@ namespace netgen enum OPTIMIZEGOAL { OPT_QUALITY, OPT_CONFORM, OPT_REST, OPT_WORSTCASE, OPT_LEGAL }; - extern size_t timestamp; + extern DLL_HEADER size_t timestamp; inline size_t GetTimeStamp() { return timestamp; From c50bd79beb38560ef3fa5e40e9c6ba8f57c55e66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20Sch=C3=B6berl?= Date: Tue, 11 Apr 2017 21:06:30 +0200 Subject: [PATCH 21/63] default constructors assignment operators, cheaper Array-Resize --- libsrc/meshing/bisect.cpp | 6 ++++++ libsrc/meshing/improve3.cpp | 2 +- libsrc/meshing/meshclass.cpp | 12 +++++++----- libsrc/meshing/meshtype.cpp | 8 +++----- libsrc/meshing/meshtype.hpp | 24 +++++++++++++++++++----- libsrc/meshing/parser2.cpp | 2 +- libsrc/meshing/parser3.cpp | 2 +- libsrc/meshing/secondorder.cpp | 2 +- libsrc/meshing/smoothing3.cpp | 2 +- 9 files changed, 40 insertions(+), 20 deletions(-) diff --git a/libsrc/meshing/bisect.cpp b/libsrc/meshing/bisect.cpp index 765ee80e..5f073dc2 100644 --- a/libsrc/meshing/bisect.cpp +++ b/libsrc/meshing/bisect.cpp @@ -178,6 +178,12 @@ namespace netgen class MarkedTri { public: + MarkedTri () = default; + MarkedTri (const MarkedTri&) = default; + MarkedTri (MarkedTri &&) = default; + MarkedTri & operator= (const MarkedTri&) = default; + MarkedTri & operator= (MarkedTri&&) = default; + /// three point numbers PointIndex pnums[3]; /// three geominfos diff --git a/libsrc/meshing/improve3.cpp b/libsrc/meshing/improve3.cpp index 7aa5b43d..0dde9ba6 100644 --- a/libsrc/meshing/improve3.cpp +++ b/libsrc/meshing/improve3.cpp @@ -455,7 +455,7 @@ void MeshOptimize3d :: SplitImprove (Mesh & mesh, if (el[l] == pi1 || el[l] == pi2) { INDEX_3 i3; - Element2d face; + Element2d face(TRIG); el.GetFace (l+1, face); for (int kk = 1; kk <= 3; kk++) i3.I(kk) = face.PNum(kk); diff --git a/libsrc/meshing/meshclass.cpp b/libsrc/meshing/meshclass.cpp index 17fd6ba4..6b55df4a 100644 --- a/libsrc/meshing/meshclass.cpp +++ b/libsrc/meshing/meshclass.cpp @@ -1901,7 +1901,7 @@ namespace netgen int ii; PointIndex pi; SurfaceElementIndex sei; - Element2d hel; + // Element2d hel; INDEX_3_CLOSED_HASHTABLE faceht(100); @@ -1915,7 +1915,7 @@ namespace netgen FlatArray row = selsonpoint[pi]; for (ii = 0; ii < row.Size(); ii++) { - hel = SurfaceElement(row[ii]); + Element2d hel = SurfaceElement(row[ii]); if (hel.GetType() == TRIG6) hel.SetType(TRIG); int ind = hel.GetIndex(); @@ -1960,6 +1960,7 @@ namespace netgen { for (int j = 1; j <= el.GetNFaces(); j++) { + Element2d hel; el.GetFace (j, hel); hel.Invert(); hel.NormalizeNumbering(); @@ -2014,8 +2015,9 @@ namespace netgen faceht.GetData (i, i3, i2); if (i2.I1() != PointIndex::BASE-1) { - Element2d tri; - tri.SetType ( (i2.I2() == PointIndex::BASE-1) ? TRIG : QUAD); + // Element2d tri; + // tri.SetType ( (i2.I2() == PointIndex::BASE-1) ? TRIG : QUAD); + Element2d tri ( (i2.I2() == PointIndex::BASE-1) ? TRIG : QUAD); for (int l = 0; l < 3; l++) tri[l] = i3.I(l+1); tri.PNum(4) = i2.I2(); @@ -5361,7 +5363,7 @@ namespace netgen // angles in faces for (j = 1; j <= 4; j++) { - Element2d face; + Element2d face(TRIG); el.GetFace (j, face); for (lpi1 = 1; lpi1 <= 3; lpi1++) { diff --git a/libsrc/meshing/meshtype.cpp b/libsrc/meshing/meshtype.cpp index b45171b1..1d01fb4c 100644 --- a/libsrc/meshing/meshtype.cpp +++ b/libsrc/meshing/meshtype.cpp @@ -157,10 +157,9 @@ namespace netgen << " si = " << seg.si << ", edgenr = " << seg.edgenr; return s; } - - + /* Element2d :: Element2d () - { + { for (int i = 0; i < ELEMENT2D_MAXPOINTS; i++) { pnum[i] = 0; @@ -177,8 +176,7 @@ namespace netgen strongrefflag = false; is_curved = false; } - - + */ Element2d :: Element2d (int anp) { for (int i = 0; i < ELEMENT2D_MAXPOINTS; i++) diff --git a/libsrc/meshing/meshtype.hpp b/libsrc/meshing/meshtype.hpp index bf053a88..a735047c 100644 --- a/libsrc/meshing/meshtype.hpp +++ b/libsrc/meshing/meshtype.hpp @@ -76,8 +76,13 @@ namespace netgen int trignum; // for STL Meshing double u, v; // for OCC Meshing - PointGeomInfo () - : trignum(-1), u(0), v(0) { ; } + PointGeomInfo () = default; + // : trignum(-1), u(0), v(0) { ; } + PointGeomInfo (const PointGeomInfo&) = default; + PointGeomInfo (PointGeomInfo &&) = default; + PointGeomInfo & operator= (const PointGeomInfo&) = default; + PointGeomInfo & operator= (PointGeomInfo&&) = default; + }; inline ostream & operator<< (ostream & ost, const PointGeomInfo & gi) @@ -145,9 +150,14 @@ namespace netgen { int i; public: - PointIndex () { ; } + PointIndex () = default; + PointIndex (const PointIndex&) = default; + PointIndex (PointIndex &&) = default; + PointIndex & operator= (const PointIndex&) = default; + PointIndex & operator= (PointIndex&&) = default; + PointIndex (int ai) : i(ai) { ; } - PointIndex & operator= (const PointIndex &ai) { i = ai.i; return *this; } + // PointIndex & operator= (const PointIndex &ai) { i = ai.i; return *this; } operator int () const { return i; } PointIndex operator++ (int) { PointIndex hi(*this); i++; return hi; } PointIndex operator-- (int) { PointIndex hi(*this); i--; return hi; } @@ -364,7 +374,11 @@ namespace netgen public: /// - Element2d (); + Element2d () = default; + Element2d (const Element2d &) = default; + Element2d (Element2d &&) = default; + Element2d & operator= (const Element2d &) = default; + Element2d & operator= (Element2d &&) = default; /// Element2d (int anp); /// diff --git a/libsrc/meshing/parser2.cpp b/libsrc/meshing/parser2.cpp index 55bd1a5d..2e8530b8 100644 --- a/libsrc/meshing/parser2.cpp +++ b/libsrc/meshing/parser2.cpp @@ -329,7 +329,7 @@ void netrule :: LoadRule (istream & ist) while (ch == '(') { - elements.Append (Element2d()); + elements.Append (Element2d(TRIG)); ist >> elements.Last().PNum(1); ist >> ch; // ',' diff --git a/libsrc/meshing/parser3.cpp b/libsrc/meshing/parser3.cpp index 7b69212d..a5c6fd4b 100644 --- a/libsrc/meshing/parser3.cpp +++ b/libsrc/meshing/parser3.cpp @@ -84,7 +84,7 @@ void vnetrule :: LoadRule (istream & ist) char buf[256]; char ch, ok; Point3d p; - Element2d face; + Element2d face(TRIG); int i, j, i1, i2, i3, fs, ii, ii1, ii2, ii3; twoint edge; DenseMatrix tempoldutonewu(30, 20), diff --git a/libsrc/meshing/secondorder.cpp b/libsrc/meshing/secondorder.cpp index 5d3bd2f0..c7d906c3 100644 --- a/libsrc/meshing/secondorder.cpp +++ b/libsrc/meshing/secondorder.cpp @@ -112,7 +112,7 @@ namespace netgen int onp(0); - Element2d newel; + Element2d newel(TRIG); newel.SetIndex (el.GetIndex()); static int betw_trig[3][3] = diff --git a/libsrc/meshing/smoothing3.cpp b/libsrc/meshing/smoothing3.cpp index 6efb8f9b..7f5f3bf2 100644 --- a/libsrc/meshing/smoothing3.cpp +++ b/libsrc/meshing/smoothing3.cpp @@ -432,7 +432,7 @@ namespace netgen for (int k = 1; k <= 4; k++) if (el.PNum(k) == actpind) { - Element2d face; + Element2d face(TRIG); el.GetFace (k, face); Swap (face.PNum(2), face.PNum(3)); faces.Append (face); From 7027df2f73929faa4acd95cb24daeba599e0821d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20Sch=C3=B6berl?= Date: Wed, 12 Apr 2017 16:44:02 +0200 Subject: [PATCH 22/63] fix 1->2 simd trafos --- libsrc/interface/nginterface_v2.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libsrc/interface/nginterface_v2.cpp b/libsrc/interface/nginterface_v2.cpp index d7548127..d95f71e1 100644 --- a/libsrc/interface/nginterface_v2.cpp +++ b/libsrc/interface/nginterface_v2.cpp @@ -780,16 +780,16 @@ namespace netgen { double hxi[4][1]; double hx[4][2]; - double hdxdxi[4][4]; + double hdxdxi[4][2]; for (int j = 0; j < 4; j++) for (int k = 0; k < 1; k++) hxi[j][k] = ((double*)&(xi[k]))[j]; - MultiElementTransformation<1,2> (elnr, 4, &hxi[0][0], 1, &hx[0][0], 2, &hdxdxi[0][0], 4); + MultiElementTransformation<1,2> (elnr, 4, &hxi[0][0], 1, &hx[0][0], 2, &hdxdxi[0][0], 2); for (int j = 0; j < 4; j++) for (int k = 0; k < 2; k++) ((double*)&(x[k]))[j] = hx[j][k]; for (int j = 0; j < 4; j++) - for (int k = 0; k < 4; k++) + for (int k = 0; k < 2; k++) ((double*)&(dxdxi[k]))[j] = hdxdxi[j][k]; xi += sxi; From ec20b74722eca539f10ca52d585d43f51de8f923 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20Sch=C3=B6berl?= Date: Thu, 13 Apr 2017 10:40:47 +0200 Subject: [PATCH 23/63] make Element default constructable/movable --- libsrc/meshing/bisect.cpp | 61 ++++++++++++++++++++-------------- libsrc/meshing/meshclass.cpp | 6 ++-- libsrc/meshing/meshing3.cpp | 2 +- libsrc/meshing/meshtype.cpp | 12 ++++--- libsrc/meshing/meshtype.hpp | 9 +++-- libsrc/meshing/refine.cpp | 2 +- libsrc/meshing/secondorder.cpp | 2 +- 7 files changed, 56 insertions(+), 38 deletions(-) diff --git a/libsrc/meshing/bisect.cpp b/libsrc/meshing/bisect.cpp index 5f073dc2..35e27ed9 100644 --- a/libsrc/meshing/bisect.cpp +++ b/libsrc/meshing/bisect.cpp @@ -1663,32 +1663,43 @@ namespace netgen int MarkHangingTets (T_MTETS & mtets, - const INDEX_2_CLOSED_HASHTABLE & cutedges) + const INDEX_2_CLOSED_HASHTABLE & cutedges, + TaskManager tm) { + static int timer = NgProfiler::CreateTimer ("MarkHangingTets"); + NgProfiler::RegionTimer reg (timer); + int hanging = 0; - for (int i = 1; i <= mtets.Size(); i++) - { - MarkedTet & teti = mtets.Elem(i); - - if (teti.marked) - { - hanging = 1; - continue; - } - - for (int j = 0; j < 3; j++) - for (int k = j+1; k < 4; k++) - { - INDEX_2 edge(teti.pnums[j], - teti.pnums[k]); - edge.Sort(); - if (cutedges.Used (edge)) - { - teti.marked = 1; - hanging = 1; - } - } - } + // for (int i = 1; i <= mtets.Size(); i++) + ParallelForRange + (tm, mtets.Size(), [&] (size_t begin, size_t end) + { + bool my_hanging = false; + for (size_t i = begin; i < end; i++) + { + MarkedTet & teti = mtets[i]; + + if (teti.marked) + { + my_hanging = true; + continue; + } + + for (int j = 0; j < 3; j++) + for (int k = j+1; k < 4; k++) + { + INDEX_2 edge(teti.pnums[j], + teti.pnums[k]); + edge.Sort(); + if (cutedges.Used (edge)) + { + teti.marked = 1; + my_hanging = true; + } + } + } + if (my_hanging) hanging = true; + }); return hanging; } @@ -3336,7 +3347,7 @@ namespace netgen hangingvol = - MarkHangingTets (mtets, cutedges) + + MarkHangingTets (mtets, cutedges, opt.task_manager) + MarkHangingPrisms (mprisms, cutedges) + MarkHangingIdentifications (mids, cutedges); diff --git a/libsrc/meshing/meshclass.cpp b/libsrc/meshing/meshclass.cpp index 6b55df4a..81d7ead7 100644 --- a/libsrc/meshing/meshclass.cpp +++ b/libsrc/meshing/meshclass.cpp @@ -926,7 +926,7 @@ namespace netgen PrintMessage (3, n, " volume elements"); for (i = 1; i <= n; i++) { - Element el; + Element el(TET); int hi, nep; infile >> hi; if (hi == 0) hi = 1; @@ -1423,7 +1423,7 @@ namespace netgen PrintMessage (3, n, " volume elements"); for (i = 1; i <= n; i++) { - Element el; + Element el(TET); int hi, nep; infile >> hi; if (hi == 0) hi = 1; @@ -1960,7 +1960,7 @@ namespace netgen { for (int j = 1; j <= el.GetNFaces(); j++) { - Element2d hel; + Element2d hel(TRIG); el.GetFace (j, hel); hel.Invert(); hel.NormalizeNumbering(); diff --git a/libsrc/meshing/meshing3.cpp b/libsrc/meshing/meshing3.cpp index 9bb6b584..65854e62 100644 --- a/libsrc/meshing/meshing3.cpp +++ b/libsrc/meshing/meshing3.cpp @@ -390,7 +390,7 @@ GenerateMesh (Mesh & mesh, const MeshingParameters & mp) delfaces.SetSize (0); INDEX npi; - Element newel; + Element newel(TET); npi = mesh.AddPoint (inp); newel.SetNP(4); diff --git a/libsrc/meshing/meshtype.cpp b/libsrc/meshing/meshtype.cpp index 1d01fb4c..5fab1c5d 100644 --- a/libsrc/meshing/meshtype.cpp +++ b/libsrc/meshing/meshtype.cpp @@ -967,7 +967,7 @@ namespace netgen return s; } - + /* Element :: Element () { typ = TET; @@ -990,9 +990,8 @@ namespace netgen #ifdef PARALLEL partitionNumber = -1; #endif - } - + */ Element :: Element (int anp) { @@ -1061,12 +1060,15 @@ namespace netgen flags.fixed = 0; orderx = ordery = orderz = 1; is_curved = typ != TET; // false; +#ifdef PARALLEL + partitionNumber = -1; +#endif } - + /* Element & Element :: operator= (const Element & el2) { typ = el2.typ; @@ -1083,7 +1085,7 @@ namespace netgen is_curved = el2.is_curved; return *this; } - + */ void Element :: SetNP (int anp) diff --git a/libsrc/meshing/meshtype.hpp b/libsrc/meshing/meshtype.hpp index a735047c..129e1fce 100644 --- a/libsrc/meshing/meshtype.hpp +++ b/libsrc/meshing/meshtype.hpp @@ -660,13 +660,18 @@ namespace netgen flagstruct flags; /// - DLL_HEADER Element (); + DLL_HEADER Element () = default; + Element (const Element &) = default; + Element (Element &&) = default; + Element & operator= (const Element &) = default; + Element & operator= (Element &&) = default; + /// Element (int anp); /// Element (ELEMENT_TYPE type); /// - Element & operator= (const Element & el2); + // Element & operator= (const Element & el2); /// void SetNP (int anp); diff --git a/libsrc/meshing/refine.cpp b/libsrc/meshing/refine.cpp index 3cb40d18..e6e1f7cb 100644 --- a/libsrc/meshing/refine.cpp +++ b/libsrc/meshing/refine.cpp @@ -436,7 +436,7 @@ namespace netgen int ind = el.GetIndex(); for (int j = 0; j < 8; j++) { - Element nel; + Element nel(TET); for (int k = 1; k <= 4; k++) nel.PNum(k) = pnums.Get(reftab[j][k-1]); nel.SetIndex(ind); diff --git a/libsrc/meshing/secondorder.cpp b/libsrc/meshing/secondorder.cpp index c7d906c3..861f99ed 100644 --- a/libsrc/meshing/secondorder.cpp +++ b/libsrc/meshing/secondorder.cpp @@ -204,7 +204,7 @@ namespace netgen const Element & el = mesh.VolumeElement(i); int onp = 0; - Element newel; + Element newel(TET); newel.SetIndex (el.GetIndex()); static int betw_tet[6][3] = From 5ed3de978b08ac0b77ea64416c355fcad4e4652b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20Sch=C3=B6berl?= Date: Tue, 18 Apr 2017 08:43:23 +0200 Subject: [PATCH 24/63] default constructable/movable tet for bisection-refinement --- libsrc/meshing/bisect.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/libsrc/meshing/bisect.cpp b/libsrc/meshing/bisect.cpp index 35e27ed9..8947e879 100644 --- a/libsrc/meshing/bisect.cpp +++ b/libsrc/meshing/bisect.cpp @@ -44,10 +44,17 @@ namespace netgen bool incorder; unsigned int order:6; - MarkedTet() + MarkedTet() = default; + /* { for (int i = 0; i < 4; i++) { faceedges[i] = 127; } } + */ + MarkedTet (const MarkedTet&) = default; + MarkedTet (MarkedTet &&) = default; + MarkedTet & operator= (const MarkedTet&) = default; + MarkedTet & operator= (MarkedTet&&) = default; + }; ostream & operator<< (ostream & ost, const MarkedTet & mt) From 70da438d6d8f969bb5a8e2463a29e7ea988bb3e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20Sch=C3=B6berl?= Date: Tue, 18 Apr 2017 15:06:40 +0200 Subject: [PATCH 25/63] on mesh loading, set dummy-geometry if no geometry in mesh-file --- libsrc/interface/nginterface.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libsrc/interface/nginterface.cpp b/libsrc/interface/nginterface.cpp index 206e703d..39ddacd3 100644 --- a/libsrc/interface/nginterface.cpp +++ b/libsrc/interface/nginterface.cpp @@ -108,7 +108,8 @@ void Ng_LoadMeshFromStream ( istream & input ) break; } } - + if (!ng_geometry) + ng_geometry = make_shared(); mesh->SetGeometry (ng_geometry); } From 643c89538d41935dac18e8f44105ac7def81f9ae Mon Sep 17 00:00:00 2001 From: Matthias Hochsteger Date: Wed, 19 Apr 2017 18:02:27 +0200 Subject: [PATCH 26/63] Add support for AVX512 Restructure mysimd.hpp and add support for AVX512. Changes include - Move mysimd.hpp to ngsimd.hpp - Expose ngsimd.hpp to NGSolve - New namespace ngsimd - Second template parameter (width) for SIMD class, default to the largest width available - Avoid raw avx register types in the interface, use SIMD<> instead --- libsrc/general/CMakeLists.txt | 2 +- libsrc/general/myadt.hpp | 2 +- libsrc/general/mysimd.hpp | 403 -------------------- libsrc/general/ngsimd.hpp | 553 ++++++++++++++++++++++++++++ libsrc/include/CMakeLists.txt | 2 +- libsrc/include/ngsimd.hpp | 1 + libsrc/interface/nginterface_v2.cpp | 70 ++-- libsrc/visualization/soldata.hpp | 12 +- libsrc/visualization/vssolution.cpp | 8 +- 9 files changed, 597 insertions(+), 456 deletions(-) delete mode 100644 libsrc/general/mysimd.hpp create mode 100644 libsrc/general/ngsimd.hpp create mode 100644 libsrc/include/ngsimd.hpp diff --git a/libsrc/general/CMakeLists.txt b/libsrc/general/CMakeLists.txt index f0c5b97f..811bc80d 100644 --- a/libsrc/general/CMakeLists.txt +++ b/libsrc/general/CMakeLists.txt @@ -13,7 +13,7 @@ install( FILES ngexception.hpp DESTINATION ${INCDIR} COMPONENT netgen_devel ) install(FILES archive_base.hpp array.hpp autodiff.hpp autoptr.hpp bitarray.hpp dynamicmem.hpp flags.hpp hashtabl.hpp mpi_interface.hpp myadt.hpp - mysimd.hpp mystring.hpp netgenout.hpp ngexception.hpp ngpython.hpp + ngsimd.hpp mystring.hpp netgenout.hpp ngexception.hpp ngpython.hpp optmem.hpp parthreads.hpp profiler.hpp seti.hpp sort.hpp spbita2d.hpp stack.hpp symbolta.hpp table.hpp template.hpp gzstream.h diff --git a/libsrc/general/myadt.hpp b/libsrc/general/myadt.hpp index 8fa8b95d..40279563 100644 --- a/libsrc/general/myadt.hpp +++ b/libsrc/general/myadt.hpp @@ -46,7 +46,7 @@ #include "gzstream.h" #include "archive_base.hpp" -#include "mysimd.hpp" +#include "ngsimd.hpp" #endif diff --git a/libsrc/general/mysimd.hpp b/libsrc/general/mysimd.hpp deleted file mode 100644 index 124ff91b..00000000 --- a/libsrc/general/mysimd.hpp +++ /dev/null @@ -1,403 +0,0 @@ -#ifndef FILE_MYSIMD -#define FILE_MYSIMD - -/**************************************************************************/ -/* File: mysimd.hpp */ -/* Author: Joachim Schoeberl */ -/* Date: 25. Mar. 16 */ -/**************************************************************************/ - -#include - -#ifdef WIN32 -#ifndef AVX_OPERATORS_DEFINED -#define AVX_OPERATORS_DEFINED -inline __m128d operator- (__m128d a) { return _mm_xor_pd(a, _mm_set1_pd(-0.0)); } -inline __m128d operator+ (__m128d a, __m128d b) { return _mm_add_pd(a,b); } -inline __m128d operator- (__m128d a, __m128d b) { return _mm_sub_pd(a,b); } -inline __m128d operator* (__m128d a, __m128d b) { return _mm_mul_pd(a,b); } -inline __m128d operator/ (__m128d a, __m128d b) { return _mm_div_pd(a,b); } -inline __m128d operator* (double a, __m128d b) { return _mm_set1_pd(a)*b; } -inline __m128d operator* (__m128d b, double a) { return _mm_set1_pd(a)*b; } - -inline __m128d operator+= (__m128d &a, __m128d b) { return a = a+b; } -inline __m128d operator-= (__m128d &a, __m128d b) { return a = a-b; } -inline __m128d operator*= (__m128d &a, __m128d b) { return a = a*b; } -inline __m128d operator/= (__m128d &a, __m128d b) { return a = a/b; } - -inline __m256d operator- (__m256d a) { return _mm256_xor_pd(a, _mm256_set1_pd(-0.0)); } -inline __m256d operator+ (__m256d a, __m256d b) { return _mm256_add_pd(a,b); } -inline __m256d operator- (__m256d a, __m256d b) { return _mm256_sub_pd(a,b); } -inline __m256d operator* (__m256d a, __m256d b) { return _mm256_mul_pd(a,b); } -inline __m256d operator/ (__m256d a, __m256d b) { return _mm256_div_pd(a,b); } -inline __m256d operator* (double a, __m256d b) { return _mm256_set1_pd(a)*b; } -inline __m256d operator* (__m256d b, double a) { return _mm256_set1_pd(a)*b; } - -inline __m256d operator+= (__m256d &a, __m256d b) { return a = a+b; } -inline __m256d operator-= (__m256d &a, __m256d b) { return a = a-b; } -inline __m256d operator*= (__m256d &a, __m256d b) { return a = a*b; } -inline __m256d operator/= (__m256d &a, __m256d b) { return a = a/b; } -#endif -#endif - - - -namespace netgen -{ - template class SIMD; - - template - struct has_call_operator - { - template static std::true_type check( decltype( sizeof(&C::operator() )) ) { return std::true_type(); } - template static std::false_type check(...) { return std::false_type(); } - typedef decltype( check(sizeof(char)) ) type; - static constexpr type value = type(); - }; - -#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); } - }; - - template<> - class alignas(32) SIMD : public AlignedAlloc> - { - __m256d data; - - public: - static constexpr int Size() { return 4; } - SIMD () = default; - SIMD (const SIMD &) = default; - SIMD & operator= (const SIMD &) = default; - - SIMD (double val) - { - data = _mm256_set1_pd(val); - } - - SIMD (__m256d adata) - : data(adata) - { ; } - - /* - template - SIMD (const T & val) - { -// SIMD_function(val, std::is_convertible>()); - SIMD_function(val, has_call_operator::value); - } - */ - - /* - template - SIMD & operator= (const T & val) - { -// SIMD_function(val, std::is_convertible>()); - SIMD_function(val, has_call_operator::value); - return *this; - } - */ - - - template - void SIMD_function (const Function & func, std::true_type) - { - data = _mm256_set_pd(func(3), func(2), func(1), func(0)); - } - - // not a function - void SIMD_function (double const * p, std::false_type) - { - data = _mm256_loadu_pd(p); - } - - void SIMD_function (double val, std::false_type) - { - data = _mm256_set1_pd(val); - } - - void SIMD_function (__m256d _data, std::false_type) - { - data = _data; - } - - inline double operator[] (int i) const { return ((double*)(&data))[i]; } - inline __m256d Data() const { return data; } - inline __m256d & Data() { return data; } - }; - - - inline SIMD operator+ (SIMD a, SIMD b) { return a.Data()+b.Data(); } - inline SIMD operator- (SIMD a, SIMD b) { return a.Data()-b.Data(); } - inline SIMD operator- (SIMD a) { return -a.Data(); } - inline SIMD operator* (SIMD a, SIMD b) { return a.Data()*b.Data(); } - inline SIMD operator/ (SIMD a, SIMD b) { return a.Data()/b.Data(); } - inline SIMD operator* (double a, SIMD b) { return SIMD(a)*b; } - inline SIMD operator* (SIMD b, double a) { return SIMD(a)*b; } - inline SIMD operator+= (SIMD & a, SIMD b) { return a.Data()+=b.Data(); } - inline SIMD operator-= (SIMD & a, SIMD b) { return a.Data()-=b.Data(); } - inline SIMD operator*= (SIMD & a, SIMD b) { return a.Data()*=b.Data(); } - inline SIMD operator/= (SIMD & a, SIMD b) { return a.Data()/=b.Data(); } - - using std::sqrt; - using std::fabs; - - inline SIMD sqrt (SIMD a) { return _mm256_sqrt_pd(a.Data()); } - inline SIMD fabs (SIMD a) { return _mm256_max_pd(a.Data(), -a.Data()); } - inline SIMD L2Norm2 (SIMD a) { return a.Data()*a.Data(); } - inline SIMD Trans (SIMD a) { return a; } - inline SIMD IfPos (SIMD a, SIMD b, SIMD c) - { - auto cp = _mm256_cmp_pd (a.Data(), _mm256_setzero_pd(), _CMP_GT_OS); - return _mm256_blendv_pd(c.Data(), b.Data(), cp); - } - - inline double HSum (SIMD sd) - { - __m128d hv = _mm_add_pd (_mm256_extractf128_pd(sd.Data(),0), _mm256_extractf128_pd(sd.Data(),1)); - return _mm_cvtsd_f64 (_mm_hadd_pd (hv, hv)); - } - - - - -#else - - // it's only a dummy without AVX - template - class AlignedAlloc { ; }; - - template<> - class SIMD - { - double data; - - public: - static constexpr int Size() { return 1; } - SIMD () = default; - SIMD (const SIMD &) = default; - SIMD & operator= (const SIMD &) = default; - - SIMD (double val) - : data(val) { ; } - - /* - template - SIMD (const T & val) - { -// SIMD_function(val, std::is_convertible>()); - SIMD_function(val, has_call_operator::value); - } - */ - - - template - SIMD & operator= (const T & val) - { -// SIMD_function(val, std::is_convertible>()); - SIMD_function(val, has_call_operator::value); - return *this; - } - - template - void SIMD_function (const Function & func, std::true_type) - { - data = func(0); - } - - // not a function - void SIMD_function (double const * p, std::false_type) - { - data = *p; - } - - void SIMD_function (double val, std::false_type) - { - data = val; - } - - double operator[] (int i) const { return ((double*)(&data))[i]; } - double Data() const { return data; } - double & Data() { return data; } - }; - - - inline SIMD operator+ (SIMD a, SIMD b) { return a.Data()+b.Data(); } - inline SIMD operator- (SIMD a, SIMD b) { return a.Data()-b.Data(); } - inline SIMD operator- (SIMD a) { return -a.Data(); } - inline SIMD operator* (SIMD a, SIMD b) { return a.Data()*b.Data(); } - inline SIMD operator/ (SIMD a, SIMD b) { return a.Data()/b.Data(); } - inline SIMD operator* (double a, SIMD b) { return SIMD(a)*b; } - inline SIMD operator* (SIMD b, double a) { return SIMD(a)*b; } - inline SIMD operator+= (SIMD & a, SIMD b) { return a.Data()+=b.Data(); } - inline SIMD operator-= (SIMD & a, SIMD b) { return a.Data()-=b.Data(); } - inline SIMD operator*= (SIMD & a, SIMD b) { return a.Data()*=b.Data(); } - inline SIMD operator/= (SIMD & a, SIMD b) { return a.Data()/=b.Data(); } - - using std::sqrt; - using std::fabs; - - inline SIMD sqrt (SIMD a) { return std::sqrt(a.Data()); } - inline SIMD fabs (SIMD a) { return std::fabs(a.Data()); } - inline SIMD L2Norm2 (SIMD a) { return a.Data()*a.Data(); } - inline SIMD Trans (SIMD a) { return a; } - inline SIMD IfPos (SIMD a, SIMD b, SIMD c) - { - return (a.Data() > 0) ? b : c; - } - - inline double HSum (SIMD sd) - { return sd.Data(); } - -#endif - - - - - - - - template - ostream & operator<< (ostream & ost, SIMD simd) - { - ost << simd[0]; - for (int i = 1; i < simd.Size(); i++) - ost << " " << simd[i]; - return ost; - } - - /* - using std::exp; - inline netgen::SIMD exp (netgen::SIMD a) { - return netgen::SIMD([&](int i)->double { return exp(a[i]); } ); -} - - using std::log; -inline netgen::SIMD log (netgen::SIMD a) { - return netgen::SIMD([&](int i)->double { return log(a[i]); } ); -} - - using std::pow; -inline netgen::SIMD pow (netgen::SIMD a, double x) { - return netgen::SIMD([&](int i)->double { return pow(a[i],x); } ); -} - */ - - - template - class MultiSIMD - { - SIMD head; - MultiSIMD tail; - public: - MultiSIMD () = default; - MultiSIMD (const MultiSIMD & ) = default; - MultiSIMD (T v) : head(v), tail(v) { ; } - MultiSIMD (SIMD _head, MultiSIMD _tail) - : head(_head), tail(_tail) { ; } - SIMD Head() const { return head; } - MultiSIMD Tail() const { return tail; } - SIMD & Head() { return head; } - MultiSIMD & Tail() { return tail; } - - template - SIMD Get() const { return NR==0 ? head : tail.template Get(); } - template - SIMD & Get() { return NR==0 ? head : tail.template Get(); } - }; - - template - class MultiSIMD<2,T> - { - SIMD v0, v1; - public: - MultiSIMD () = default; - MultiSIMD (const MultiSIMD & ) = default; - MultiSIMD (T v) : v0(v), v1(v) { ; } - MultiSIMD (SIMD _v0, SIMD _v1) : v0(_v0), v1(_v1) { ; } - - SIMD Head() const { return v0; } - SIMD Tail() const { return v1; } - SIMD & Head() { return v0; } - SIMD & Tail() { return v1; } - - template - SIMD Get() const { return NR==0 ? v0 : v1; } - template - SIMD & Get() { return NR==0 ? v0 : v1; } - }; - - template inline MultiSIMD operator+ (MultiSIMD a, MultiSIMD b) - { return MultiSIMD (a.Head()+b.Head(), a.Tail()+b.Tail()); } - template inline MultiSIMD operator+ (double a, MultiSIMD b) - { return MultiSIMD (a+b.Head(), a+b.Tail()); } - template inline MultiSIMD operator+ (MultiSIMD b, double a) - { return MultiSIMD (a+b.Head(), a+b.Tail()); } - - template inline MultiSIMD operator- (MultiSIMD a, MultiSIMD b) - { return MultiSIMD (a.Head()-b.Head(), a.Tail()-b.Tail()); } - template inline MultiSIMD operator- (double a, MultiSIMD b) - { return MultiSIMD (a-b.Head(), a-b.Tail()); } - template inline MultiSIMD operator- (MultiSIMD b, double a) - { return MultiSIMD (b.Head()-a, b.Tail()-a); } - template inline MultiSIMD operator- (MultiSIMD a) - { return MultiSIMD (-a.Head(), -a.Tail()); } - template inline MultiSIMD operator* (MultiSIMD a, MultiSIMD b) - { return MultiSIMD (a.Head()*b.Head(), a.Tail()*b.Tail()); } - template inline MultiSIMD operator/ (MultiSIMD a, MultiSIMD b) - { return MultiSIMD (a.Head()/b.Head(), a.Tail()/b.Tail()); } - template inline MultiSIMD operator* (double a, MultiSIMD b) - { return MultiSIMD ( a*b.Head(), a*b.Tail()); } - template inline MultiSIMD operator* (MultiSIMD b, double a) - { return MultiSIMD ( a*b.Head(), a*b.Tail()); } - - template inline MultiSIMD & operator+= (MultiSIMD & a, MultiSIMD b) - { a.Head()+=b.Head(); a.Tail()+=b.Tail(); return a; } - template inline MultiSIMD operator-= (MultiSIMD & a, double b) - { a.Head()-=b; a.Tail()-=b; return a; } - template inline MultiSIMD operator-= (MultiSIMD & a, MultiSIMD b) - { a.Head()-=b.Head(); a.Tail()-=b.Tail(); return a; } - template inline MultiSIMD & operator*= (MultiSIMD & a, MultiSIMD b) - { a.Head()*=b.Head(); a.Tail()*=b.Tail(); return a; } - template inline MultiSIMD & operator*= (MultiSIMD & a, double b) - { a.Head()*=b; a.Tail()*=b; return a; } - // inline MultiSIMD operator/= (MultiSIMD & a, MultiSIMD b) { return a.Data()/=b.Data(); } - - - template - ostream & operator<< (ostream & ost, MultiSIMD multi) - { - ost << multi.Head() << " " << multi.Tail(); - return ost; - } - -} - -#endif diff --git a/libsrc/general/ngsimd.hpp b/libsrc/general/ngsimd.hpp new file mode 100644 index 00000000..feb0c046 --- /dev/null +++ b/libsrc/general/ngsimd.hpp @@ -0,0 +1,553 @@ +#ifndef FILE_NGSIMD +#define FILE_NGSIMD +/**************************************************************************/ +/* File: ngsimd.hpp */ +/* Author: Joachim Schoeberl */ +/* Date: 25. Mar. 16 */ +/**************************************************************************/ + +#include +#include +#include +#include +#include +#include + +#ifdef WIN32 +#ifndef AVX_OPERATORS_DEFINED +#define AVX_OPERATORS_DEFINED +inline __m128d operator- (__m128d a) { return _mm_xor_pd(a, _mm_set1_pd(-0.0)); } +inline __m128d operator+ (__m128d a, __m128d b) { return _mm_add_pd(a,b); } +inline __m128d operator- (__m128d a, __m128d b) { return _mm_sub_pd(a,b); } +inline __m128d operator* (__m128d a, __m128d b) { return _mm_mul_pd(a,b); } +inline __m128d operator/ (__m128d a, __m128d b) { return _mm_div_pd(a,b); } +inline __m128d operator* (double a, __m128d b) { return _mm_set1_pd(a)*b; } +inline __m128d operator* (__m128d b, double a) { return _mm_set1_pd(a)*b; } + +inline __m128d operator+= (__m128d &a, __m128d b) { return a = a+b; } +inline __m128d operator-= (__m128d &a, __m128d b) { return a = a-b; } +inline __m128d operator*= (__m128d &a, __m128d b) { return a = a*b; } +inline __m128d operator/= (__m128d &a, __m128d b) { return a = a/b; } + +inline __m256d operator- (__m256d a) { return _mm256_xor_pd(a, _mm256_set1_pd(-0.0)); } +inline __m256d operator+ (__m256d a, __m256d b) { return _mm256_add_pd(a,b); } +inline __m256d operator- (__m256d a, __m256d b) { return _mm256_sub_pd(a,b); } +inline __m256d operator* (__m256d a, __m256d b) { return _mm256_mul_pd(a,b); } +inline __m256d operator/ (__m256d a, __m256d b) { return _mm256_div_pd(a,b); } +inline __m256d operator* (double a, __m256d b) { return _mm256_set1_pd(a)*b; } +inline __m256d operator* (__m256d b, double a) { return _mm256_set1_pd(a)*b; } + +inline __m256d operator+= (__m256d &a, __m256d b) { return a = a+b; } +inline __m256d operator-= (__m256d &a, __m256d b) { return a = a-b; } +inline __m256d operator*= (__m256d &a, __m256d b) { return a = a*b; } +inline __m256d operator/= (__m256d &a, __m256d b) { return a = a/b; } +#endif +#endif + + + +namespace ngsimd +{ + constexpr int GetDefaultSIMDSize() { +#if defined __AVX512F__ + return 8; +#elif defined __AVX__ + return 4; +#else + return 1; +#endif + } + + template class SIMD; + + template + struct has_call_operator + { + template static std::true_type check( decltype( sizeof(&C::operator() )) ) { return std::true_type(); } + template static std::false_type check(...) { return std::false_type(); } + typedef decltype( check(sizeof(char)) ) type; + static constexpr type value = type(); + }; + + template + // a*b+c + inline auto FMA(T1 a, T2 b, T3 c) + { + return a*b+c; + } + + template::value, int>::type = 0> + inline SIMD operator+ (T a, SIMD b) { return SIMD(a) + b; } + template::value, int>::type = 0> + inline SIMD operator- (T a, SIMD b) { return SIMD(a) - b; } + template::value, int>::type = 0> + inline SIMD operator* (T a, SIMD b) { return SIMD(a) * b; } + template::value, int>::type = 0> + inline SIMD operator/ (T a, SIMD b) { return SIMD(a) / b; } + template::value, int>::type = 0> + inline SIMD operator+ (SIMD a, T b) { return a + SIMD(b); } + template::value, int>::type = 0> + inline SIMD operator- (SIMD a, T b) { return a - SIMD(b); } + template::value, int>::type = 0> + inline SIMD operator* (SIMD a, T b) { return a * SIMD(b); } + template::value, int>::type = 0> + 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; + + class ExceptionNOSIMD : public std::runtime_error + { + public: + using std::runtime_error::runtime_error; + std::string What() { return what(); } + }; + + using std::exp; + template inline SIMD exp (SIMD a) + { + return SIMD([&](int i)->double { return exp(a[i]); } ); + } + + using std::log; + template inline SIMD log (SIMD a) + { + return SIMD([&](int i)->double { return log(a[i]); } ); + } + + using std::pow; + template inline SIMD pow (SIMD a, double x) + { + return SIMD([&](int i)->double { return pow(a[i],x); } ); + } + + using std::sin; + template inline SIMD sin (SIMD a) + { + return SIMD([&](int i)->double { return sin(a[i]); } ); + } + + using std::cos; + template inline SIMD cos (SIMD a) + { + return SIMD([&](int i)->double { return cos(a[i]); } ); + } + + using std::tan; + template inline SIMD tan (SIMD a) + { + return SIMD([&](int i)->double { return tan(a[i]); } ); + } + + using std::atan; + template inline SIMD atan (SIMD a) + { + return SIMD([&](int i)->double { return atan(a[i]); } ); + } + + +///////////////////////////////////////////////////////////////////////////// +// SIMD width 1 (in case no AVX support is available) +///////////////////////////////////////////////////////////////////////////// + template<> + class SIMD + { + double data; + + public: + static constexpr int Size() { return 1; } + SIMD () = default; + SIMD (const SIMD &) = default; + SIMD & operator= (const SIMD &) = default; + + // only called if T has a call operator of appropriate type + template>::value, int>::type = 0> + SIMD (const T & func) + { + data = func(0); + } + + // only called if T is arithmetic (integral or floating point types) + template::value, int>::type = 0> + SIMD (const T & val) + { + data = val; + } + + SIMD (double const * p) + { + data = *p; + } + + inline operator double() const { return data; } + inline double operator[] (int i) const { return ((double*)(&data))[i]; } + inline double Data() const { return data; } + inline double & Data() { return data; } + + inline SIMD &operator+= (SIMD b) { data+=b.Data(); return *this; } + inline SIMD &operator-= (SIMD b) { data-=b.Data(); return *this; } + inline SIMD &operator*= (SIMD b) { data*=b.Data(); return *this; } + inline SIMD &operator/= (SIMD b) { data/=b.Data(); return *this; } + + }; + + inline SIMD operator+ (SIMD a, SIMD b) { return a.Data()+b.Data(); } + inline SIMD operator- (SIMD a, SIMD b) { return a.Data()-b.Data(); } + inline SIMD operator- (SIMD a) { return -a.Data(); } + inline SIMD operator* (SIMD a, SIMD b) { return a.Data()*b.Data(); } + inline SIMD operator/ (SIMD a, SIMD b) { return a.Data()/b.Data(); } + + inline SIMD sqrt (SIMD a) { return std::sqrt(a.Data()); } + inline SIMD fabs (SIMD a) { return std::fabs(a.Data()); } + inline SIMD L2Norm2 (SIMD a) { return a.Data()*a.Data(); } + inline SIMD Trans (SIMD a) { return a; } + inline SIMD IfPos (SIMD a, SIMD b, SIMD c) + { + return (a.Data() > 0) ? b : c; + } + + inline double HSum (SIMD sd) + { + return sd.Data(); + } + +///////////////////////////////////////////////////////////////////////////// +// AVX - Simd width 4 +///////////////////////////////////////////////////////////////////////////// +#ifdef __AVX__ + template<> + class alignas(32) SIMD : public AlignedAlloc> + { + __m256d data; + + public: + static constexpr int Size() { return 4; } + SIMD () = default; + SIMD (const SIMD &) = default; + SIMD & operator= (const SIMD &) = default; + + SIMD (__m256d adata) + : data(adata) + { ; } + + // only called if T has a call operator of appropriate type + template>::value, int>::type = 0> + SIMD (const T & func) + { + data = _mm256_set_pd(func(3), func(2), func(1), func(0)); + } + + // only called if T is arithmetic (integral or floating point types) + template::value, int>::type = 0> + SIMD (const T & val) + { + data = _mm256_set1_pd(val); + } + + SIMD (double const * p) + { + data = _mm256_loadu_pd(p); + } + + inline operator __m256d() const { return data; } + inline double operator[] (int i) const { return ((double*)(&data))[i]; } + inline __m256d Data() const { return data; } + inline __m256d & Data() { return data; } + + inline SIMD &operator+= (SIMD b) { data+=b.Data(); return *this; } + inline SIMD &operator-= (SIMD b) { data-=b.Data(); return *this; } + inline SIMD &operator*= (SIMD b) { data*=b.Data(); return *this; } + inline SIMD &operator/= (SIMD b) { data/=b.Data(); return *this; } + + }; + + inline SIMD operator+ (SIMD a, SIMD b) { return a.Data()+b.Data(); } + inline SIMD operator- (SIMD a, SIMD b) { return a.Data()-b.Data(); } + inline SIMD operator- (SIMD a) { return -a.Data(); } + inline SIMD operator* (SIMD a, SIMD b) { return a.Data()*b.Data(); } + inline SIMD operator/ (SIMD a, SIMD b) { return a.Data()/b.Data(); } + + inline SIMD sqrt (SIMD a) { return _mm256_sqrt_pd(a.Data()); } + inline SIMD fabs (SIMD a) { return _mm256_max_pd(a.Data(), -a.Data()); } + inline SIMD L2Norm2 (SIMD a) { return a.Data()*a.Data(); } + inline SIMD Trans (SIMD a) { return a; } + inline SIMD IfPos (SIMD a, SIMD b, SIMD c) + { + auto cp = _mm256_cmp_pd (a.Data(), _mm256_setzero_pd(), _CMP_GT_OS); + return _mm256_blendv_pd(c.Data(), b.Data(), cp); + } + + inline double HSum (SIMD sd) + { + __m128d hv = _mm_add_pd (_mm256_extractf128_pd(sd.Data(),0), _mm256_extractf128_pd(sd.Data(),1)); + return _mm_cvtsd_f64 (_mm_hadd_pd (hv, hv)); + } + + inline auto HSum (SIMD sd1, SIMD sd2) + { + __m256d hv = _mm256_hadd_pd(sd1.Data(), sd2.Data()); + __m128d hv2 = _mm_add_pd (_mm256_extractf128_pd(hv,0), _mm256_extractf128_pd(hv,1)); + return std::make_tuple(_mm_cvtsd_f64 (hv2), _mm_cvtsd_f64(_mm_shuffle_pd (hv2, hv2, 3))); + } + + inline SIMD HSum (SIMD v1, SIMD v2, SIMD v3, SIMD v4) + { + __m256d hsum1 = _mm256_hadd_pd (v1.Data(), v2.Data()); + __m256d hsum2 = _mm256_hadd_pd (v3.Data(), v4.Data()); + __m256d hsum = _mm256_add_pd (_mm256_permute2f128_pd (hsum1, hsum2, 1+2*16), + _mm256_blend_pd (hsum1, hsum2, 12)); + return hsum; + } + +#endif // __AVX__ + +///////////////////////////////////////////////////////////////////////////// +// AVX512 - Simd width 8 +///////////////////////////////////////////////////////////////////////////// +#ifdef __AVX512F__ + template<> + class alignas(64) SIMD : public AlignedAlloc> + { + __m512d data; + + public: + static constexpr int Size() { return 8; } + SIMD () = default; + SIMD (const SIMD &) = default; + SIMD & operator= (const SIMD &) = default; + + SIMD (__m512d adata) + : data(adata) + { ; } + + // only called if T has a call operator of appropriate type + template>::value, int>::type = 0> + SIMD (const T & func) + { + data = _mm512_set_pd(func(7), func(6), func(5), func(4), + func(3), func(2), func(1), func(0)); + } + + // only called if T is arithmetic (integral or floating point types) + template::value, int>::type = 0> + SIMD (const T & val) + { + data = _mm512_set1_pd(val); + } + + SIMD (double const * p) + { + data = _mm512_loadu_pd(p); + } + + inline operator __m512d() const { return data; } + inline double operator[] (int i) const { return ((double*)(&data))[i]; } + inline __m512d Data() const { return data; } + inline __m512d & Data() { return data; } + + inline SIMD &operator+= (SIMD b) { data+=b.Data(); return *this; } + inline SIMD &operator-= (SIMD b) { data-=b.Data(); return *this; } + inline SIMD &operator*= (SIMD b) { data*=b.Data(); return *this; } + inline SIMD &operator/= (SIMD b) { data/=b.Data(); return *this; } + + }; + + inline SIMD operator- (SIMD a) { return _mm512_sub_pd(_mm512_setzero_pd(), a.Data()); } + + inline SIMD operator+ (SIMD a, SIMD b) { return _mm512_add_pd(a.Data(),b.Data()); } + inline SIMD operator- (SIMD a, SIMD b) { return _mm512_sub_pd(a.Data(),b.Data()); } + inline SIMD operator* (SIMD a, SIMD b) { return _mm512_mul_pd(a.Data(),b.Data()); } + inline SIMD operator/ (SIMD a, SIMD b) { return _mm512_div_pd(a.Data(),b.Data()); } + + inline SIMD sqrt (SIMD a) { return _mm512_sqrt_pd(a.Data()); } + inline SIMD fabs (SIMD a) { return _mm512_max_pd(a.Data(), -a.Data()); } + inline SIMD L2Norm2 (SIMD a) { return a.Data()*a.Data(); } + inline SIMD Trans (SIMD a) { return a; } + inline SIMD IfPos (SIMD a, SIMD b, SIMD c) + { + auto cp = _mm512_cmp_pd_mask (a.Data(), _mm512_setzero_pd(), _MM_CMPINT_GT); + return _mm512_mask_blend_pd(cp, c.Data(), b.Data()); + } + + + template<> inline auto FMA (SIMD a, SIMD b, SIMD c) + { + return _mm512_fmadd_pd (a.Data(), b.Data(), c.Data()); + } + + inline double HSum (SIMD sd) + { + SIMD low = _mm512_extractf64x4_pd(sd.Data(),0); + SIMD high = _mm512_extractf64x4_pd(sd.Data(),1); + return HSum(low)+HSum(high); + } + + inline auto HSum (SIMD sd1, SIMD sd2) + { + return std::make_tuple(HSum(sd1), HSum(sd2)); + } + + inline SIMD HSum (SIMD v1, SIMD v2, SIMD v3, SIMD v4) + { + SIMD high1 = _mm512_extractf64x4_pd(v1.Data(),1); + SIMD high2 = _mm512_extractf64x4_pd(v2.Data(),1); + SIMD high3 = _mm512_extractf64x4_pd(v3.Data(),1); + SIMD high4 = _mm512_extractf64x4_pd(v4.Data(),1); + SIMD low1 = _mm512_extractf64x4_pd(v1.Data(),0); + SIMD low2 = _mm512_extractf64x4_pd(v2.Data(),0); + SIMD low3 = _mm512_extractf64x4_pd(v3.Data(),0); + SIMD low4 = _mm512_extractf64x4_pd(v4.Data(),0); + return HSum(low1,low2,low3,low4) + HSum(high1,high2,high3,high4); + } +#endif // __AVX512F__ + + +//////////////////////////////////////////////////////////////////////////////// +// MultiSIMD - Multiple SIMD values in one struct using head-tail implementation +//////////////////////////////////////////////////////////////////////////////// + template + class MultiSIMD : public AlignedAlloc> + { + SIMD head; + MultiSIMD tail; + public: + MultiSIMD () = default; + MultiSIMD (const MultiSIMD & ) = default; + MultiSIMD (T v) : head(v), tail(v) { ; } + MultiSIMD (SIMD _head, MultiSIMD _tail) + : head(_head), tail(_tail) { ; } + SIMD Head() const { return head; } + MultiSIMD Tail() const { return tail; } + SIMD & Head() { return head; } + MultiSIMD & Tail() { return tail; } + + template + SIMD Get() const { return NR==0 ? head : tail.template Get(); } + template + SIMD & Get() { return NR==0 ? head : tail.template Get(); } + }; + + template + class MultiSIMD<2,T> : public AlignedAlloc> + { + SIMD v0, v1; + public: + MultiSIMD () = default; + MultiSIMD (const MultiSIMD & ) = default; + MultiSIMD (T v) : v0(v), v1(v) { ; } + MultiSIMD (SIMD _v0, SIMD _v1) : v0(_v0), v1(_v1) { ; } + + SIMD Head() const { return v0; } + SIMD Tail() const { return v1; } + SIMD & Head() { return v0; } + SIMD & Tail() { return v1; } + + template + SIMD Get() const { return NR==0 ? v0 : v1; } + template + SIMD & Get() { return NR==0 ? v0 : v1; } + }; + + template inline MultiSIMD operator+ (MultiSIMD a, MultiSIMD b) + { return MultiSIMD (a.Head()+b.Head(), a.Tail()+b.Tail()); } + template inline MultiSIMD operator+ (double a, MultiSIMD b) + { return MultiSIMD (a+b.Head(), a+b.Tail()); } + template inline MultiSIMD operator+ (MultiSIMD b, double a) + { return MultiSIMD (a+b.Head(), a+b.Tail()); } + + template inline MultiSIMD operator- (MultiSIMD a, MultiSIMD b) + { return MultiSIMD (a.Head()-b.Head(), a.Tail()-b.Tail()); } + template inline MultiSIMD operator- (double a, MultiSIMD b) + { return MultiSIMD (a-b.Head(), a-b.Tail()); } + template inline MultiSIMD operator- (MultiSIMD b, double a) + { return MultiSIMD (b.Head()-a, b.Tail()-a); } + template inline MultiSIMD operator- (MultiSIMD a) + { return MultiSIMD (-a.Head(), -a.Tail()); } + template inline MultiSIMD operator* (MultiSIMD a, MultiSIMD b) + { return MultiSIMD (a.Head()*b.Head(), a.Tail()*b.Tail()); } + template inline MultiSIMD operator/ (MultiSIMD a, MultiSIMD b) + { return MultiSIMD (a.Head()/b.Head(), a.Tail()/b.Tail()); } + template inline MultiSIMD operator* (double a, MultiSIMD b) + { return MultiSIMD ( a*b.Head(), a*b.Tail()); } + template inline MultiSIMD operator* (MultiSIMD b, double a) + { return MultiSIMD ( a*b.Head(), a*b.Tail()); } + + template inline MultiSIMD & operator+= (MultiSIMD & a, MultiSIMD b) + { a.Head()+=b.Head(); a.Tail()+=b.Tail(); return a; } + template inline MultiSIMD operator-= (MultiSIMD & a, double b) + { a.Head()-=b; a.Tail()-=b; return a; } + template inline MultiSIMD operator-= (MultiSIMD & a, MultiSIMD b) + { a.Head()-=b.Head(); a.Tail()-=b.Tail(); return a; } + template inline MultiSIMD & operator*= (MultiSIMD & a, MultiSIMD b) + { a.Head()*=b.Head(); a.Tail()*=b.Tail(); return a; } + template inline MultiSIMD & operator*= (MultiSIMD & a, double b) + { a.Head()*=b; a.Tail()*=b; return a; } + // inline MultiSIMD operator/= (MultiSIMD & a, MultiSIMD b) { return a.Data()/=b.Data(); } + + inline SIMD HVSum (SIMD a) { return a; } + template + inline SIMD HVSum (MultiSIMD a) { return a.Head() + HVSum(a.Tail()); } + + template inline double HSum (MultiSIMD a) { return HSum(HVSum(a)); } + template inline auto HSum (MultiSIMD a, MultiSIMD b) + { return HSum(HVSum(a), HVSum(b)); } + + template + std::ostream & operator<< (std::ostream & ost, MultiSIMD multi) + { + ost << multi.Head() << " " << multi.Tail(); + return ost; + } + + template + std::ostream & operator<< (std::ostream & ost, SIMD simd) + { + ost << simd[0]; + for (int i = 1; i < simd.Size(); i++) + ost << " " << simd[i]; + return ost; + } +} + +namespace netgen +{ + using namespace ngsimd; +} +#endif diff --git a/libsrc/include/CMakeLists.txt b/libsrc/include/CMakeLists.txt index dfb2c416..1bd3dc2f 100644 --- a/libsrc/include/CMakeLists.txt +++ b/libsrc/include/CMakeLists.txt @@ -3,7 +3,7 @@ install(FILES nginterface.h nginterface_v2.hpp DESTINATION ${INCDIR} COMPONENT n install(FILES acisgeom.hpp csg.hpp geometry2d.hpp gprim.hpp incopengl.hpp inctcl.hpp incvis.hpp linalg.hpp meshing.hpp myadt.hpp mydefs.hpp - mystdlib.h nginterface_v2_impl.hpp occgeom.hpp + mystdlib.h nginterface_v2_impl.hpp occgeom.hpp ngsimd.hpp opti.hpp parallel.hpp parallelinterface.hpp stlgeom.hpp visual.hpp DESTINATION ${INCDIR}/include COMPONENT netgen_devel ) diff --git a/libsrc/include/ngsimd.hpp b/libsrc/include/ngsimd.hpp new file mode 100644 index 00000000..933f002a --- /dev/null +++ b/libsrc/include/ngsimd.hpp @@ -0,0 +1 @@ +#include <../general/ngsimd.hpp> diff --git a/libsrc/interface/nginterface_v2.cpp b/libsrc/interface/nginterface_v2.cpp index d95f71e1..ff5acc79 100644 --- a/libsrc/interface/nginterface_v2.cpp +++ b/libsrc/interface/nginterface_v2.cpp @@ -646,29 +646,26 @@ namespace netgen -#ifdef __AVX__ -#include - template<> DLL_HEADER void Ngx_Mesh :: MultiElementTransformation<1,1> (int elnr, int npts, - const __m256d * xi, size_t sxi, - __m256d * x, size_t sx, - __m256d * dxdxi, size_t sdxdxi) const + const SIMD * xi, size_t sxi, + SIMD * x, size_t sx, + SIMD * dxdxi, size_t sdxdxi) const { cout << "multi-eltrafo simd called, 1,1,simd" << endl; } template<> DLL_HEADER void Ngx_Mesh :: MultiElementTransformation<2,2> (int elnr, int npts, - const __m256d * xi, size_t sxi, - __m256d * x, size_t sx, - __m256d * dxdxi, size_t sdxdxi) const + const SIMD * xi, size_t sxi, + SIMD * x, size_t sx, + SIMD * dxdxi, size_t sdxdxi) const { mesh->GetCurvedElements().CalcMultiPointSurfaceTransformation<2> (elnr, npts, - reinterpret_cast*> (xi), sxi, - reinterpret_cast*> (x), sx, - reinterpret_cast*> (dxdxi), sdxdxi); + xi, sxi, + x, sx, + dxdxi, sdxdxi); /* for (int i = 0; i < npts; i++) { @@ -695,15 +692,15 @@ namespace netgen template<> DLL_HEADER void Ngx_Mesh :: MultiElementTransformation<3,3> (int elnr, int npts, - const __m256d * xi, size_t sxi, - __m256d * x, size_t sx, - __m256d * dxdxi, size_t sdxdxi) const + const SIMD * xi, size_t sxi, + SIMD * x, size_t sx, + SIMD * dxdxi, size_t sdxdxi) const { mesh->GetCurvedElements().CalcMultiPointElementTransformation (elnr, npts, - reinterpret_cast*> (xi), sxi, - reinterpret_cast*> (x), sx, - reinterpret_cast*> (dxdxi), sdxdxi); + xi, sxi, + x, sx, + dxdxi, sdxdxi); /* for (int i = 0; i < npts; i++) { @@ -730,27 +727,27 @@ namespace netgen template<> DLL_HEADER void Ngx_Mesh :: MultiElementTransformation<0,2> (int elnr, int npts, - const __m256d *xi, size_t sxi, - __m256d * x, size_t sx, - __m256d * dxdxi, size_t sdxdxi) const + const SIMD *xi, size_t sxi, + SIMD * x, size_t sx, + SIMD * dxdxi, size_t sdxdxi) const { cout << "MultiElementtransformation<0,2> simd not implemented" << endl; } template<> DLL_HEADER void Ngx_Mesh :: MultiElementTransformation<0,1> (int elnr, int npts, - const __m256d * xi, size_t sxi, - __m256d * x, size_t sx, - __m256d * dxdxi, size_t sdxdxi) const + const SIMD * xi, size_t sxi, + SIMD * x, size_t sx, + SIMD * dxdxi, size_t sdxdxi) const { cout << "multi-eltrafo simd called, 0,1,simd" << endl; } template<> DLL_HEADER void Ngx_Mesh :: MultiElementTransformation<1,3> (int elnr, int npts, - const __m256d * xi, size_t sxi, - __m256d * x, size_t sx, - __m256d * dxdxi, size_t sdxdxi) const + const SIMD * xi, size_t sxi, + SIMD * x, size_t sx, + SIMD * dxdxi, size_t sdxdxi) const { double hxi[4][1]; double hx[4][3]; @@ -772,9 +769,9 @@ namespace netgen template<> DLL_HEADER void Ngx_Mesh :: MultiElementTransformation<1,2> (int elnr, int npts, - const __m256d * xi, size_t sxi, - __m256d * x, size_t sx, - __m256d * dxdxi, size_t sdxdxi) const + const SIMD * xi, size_t sxi, + SIMD * x, size_t sx, + SIMD * dxdxi, size_t sdxdxi) const { for (int i = 0; i < npts; i++) { @@ -801,15 +798,15 @@ namespace netgen template<> DLL_HEADER void Ngx_Mesh :: MultiElementTransformation<2,3> (int elnr, int npts, - const __m256d * xi, size_t sxi, - __m256d * x, size_t sx, - __m256d * dxdxi, size_t sdxdxi) const + const SIMD * xi, size_t sxi, + SIMD * x, size_t sx, + SIMD * dxdxi, size_t sdxdxi) const { mesh->GetCurvedElements().CalcMultiPointSurfaceTransformation<3> (elnr, npts, - reinterpret_cast*> (xi), sxi, - reinterpret_cast*> (x), sx, - reinterpret_cast*> (dxdxi), sdxdxi); + xi, sxi, + x, sx, + dxdxi, sdxdxi); /* for (int i = 0; i < npts; i++) { @@ -834,7 +831,6 @@ namespace netgen */ } -#endif diff --git a/libsrc/visualization/soldata.hpp b/libsrc/visualization/soldata.hpp index 20028762..0ae4b453 100644 --- a/libsrc/visualization/soldata.hpp +++ b/libsrc/visualization/soldata.hpp @@ -92,17 +92,15 @@ namespace netgen return res; } -#ifdef __AVX__ virtual bool GetMultiSurfValue (size_t selnr, size_t facetnr, size_t npts, - const __m256d * xref, - const __m256d * x, - const __m256d * dxdxref, - __m256d * values) + const SIMD * xref, + const SIMD * x, + const SIMD * dxdxref, + SIMD * values) { - cerr << "GetMultiSurfVaue not overloaded" << endl; + cerr << "GetMultiSurfVaue not overloaded for SIMD" << endl; return false; } -#endif virtual bool GetSegmentValue (int segnr, double xref, double * values) { return false; } diff --git a/libsrc/visualization/vssolution.cpp b/libsrc/visualization/vssolution.cpp index 457b3e6f..a61036e6 100644 --- a/libsrc/visualization/vssolution.cpp +++ b/libsrc/visualization/vssolution.cpp @@ -1279,7 +1279,6 @@ namespace netgen Array mvalues(npt); int sol_comp = (sol && sol->draw_surface) ? sol->components : 0; -#ifdef __AVX__ 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() ); @@ -1287,7 +1286,6 @@ namespace netgen Array> simd_values( (npt+SIMD::Size()-1)/SIMD::Size() * sol_comp); -#endif // Array> glob_pnts; // Array> glob_nvs; @@ -1486,7 +1484,6 @@ namespace netgen NgProfiler::StartTimer(timerloops); size_t base_pi = 0; -#ifdef __AVX__ for (int iy = 0, ii = 0; iy <= n; iy++) for (int ix = 0; ix <= n-iy; ix++, ii++) pref[ii] = Point<2> (ix*invn, iy*invn); @@ -1496,10 +1493,9 @@ namespace netgen for (size_t i = 0; i < simd_npt; i++) { - simd_pref[i](0).SIMD_function ([&] (size_t j) { size_t ii = i*simd_size+j; return (ii < npt) ? pref[ii](0) : 0; }, std::true_type()); - simd_pref[i](1).SIMD_function ([&] (size_t j) { size_t ii = i*simd_size+j; return (ii < npt) ? pref[ii](1) : 0; }, std::true_type()); + simd_pref[i](0) = [&] (size_t j) { size_t ii = i*simd_size+j; return (ii < npt) ? pref[ii](0) : 0; }; + simd_pref[i](1) = [&] (size_t j) { size_t ii = i*simd_size+j; return (ii < npt) ? pref[ii](1) : 0; }; } -#endif Array ind_reftrig; for (int iy = 0, ii = 0; iy < n; iy++,ii++) From 9247c89fd73e6a197af379cc97622899fd549d5f Mon Sep 17 00:00:00 2001 From: Matthias Hochsteger Date: Thu, 20 Apr 2017 11:41:16 +0200 Subject: [PATCH 27/63] add missing function HSum(a,b) for SIMD --- libsrc/general/ngsimd.hpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libsrc/general/ngsimd.hpp b/libsrc/general/ngsimd.hpp index feb0c046..c12b5aff 100644 --- a/libsrc/general/ngsimd.hpp +++ b/libsrc/general/ngsimd.hpp @@ -248,6 +248,11 @@ using std::fabs; return sd.Data(); } + inline auto HSum (SIMD sd1, SIMD sd2) + { + return std::make_tuple(sd1.Data(), sd2.Data()); + } + ///////////////////////////////////////////////////////////////////////////// // AVX - Simd width 4 ///////////////////////////////////////////////////////////////////////////// From 247afdb1bd2983e2709452c7134b132a95ca659f Mon Sep 17 00:00:00 2001 From: Matthias Hochsteger Date: Thu, 20 Apr 2017 16:22:50 +0200 Subject: [PATCH 28/63] Define NG_INLINE and use it in ngsimd.hpp (works around a bug in gcc5) --- libsrc/general/ngsimd.hpp | 244 +++++++++++++++++++------------------- libsrc/include/mydefs.hpp | 16 +++ 2 files changed, 138 insertions(+), 122 deletions(-) diff --git a/libsrc/general/ngsimd.hpp b/libsrc/general/ngsimd.hpp index c12b5aff..7475190b 100644 --- a/libsrc/general/ngsimd.hpp +++ b/libsrc/general/ngsimd.hpp @@ -16,31 +16,31 @@ #ifdef WIN32 #ifndef AVX_OPERATORS_DEFINED #define AVX_OPERATORS_DEFINED -inline __m128d operator- (__m128d a) { return _mm_xor_pd(a, _mm_set1_pd(-0.0)); } -inline __m128d operator+ (__m128d a, __m128d b) { return _mm_add_pd(a,b); } -inline __m128d operator- (__m128d a, __m128d b) { return _mm_sub_pd(a,b); } -inline __m128d operator* (__m128d a, __m128d b) { return _mm_mul_pd(a,b); } -inline __m128d operator/ (__m128d a, __m128d b) { return _mm_div_pd(a,b); } -inline __m128d operator* (double a, __m128d b) { return _mm_set1_pd(a)*b; } -inline __m128d operator* (__m128d b, double a) { return _mm_set1_pd(a)*b; } +NG_INLINE __m128d operator- (__m128d a) { return _mm_xor_pd(a, _mm_set1_pd(-0.0)); } +NG_INLINE __m128d operator+ (__m128d a, __m128d b) { return _mm_add_pd(a,b); } +NG_INLINE __m128d operator- (__m128d a, __m128d b) { return _mm_sub_pd(a,b); } +NG_INLINE __m128d operator* (__m128d a, __m128d b) { return _mm_mul_pd(a,b); } +NG_INLINE __m128d operator/ (__m128d a, __m128d b) { return _mm_div_pd(a,b); } +NG_INLINE __m128d operator* (double a, __m128d b) { return _mm_set1_pd(a)*b; } +NG_INLINE __m128d operator* (__m128d b, double a) { return _mm_set1_pd(a)*b; } -inline __m128d operator+= (__m128d &a, __m128d b) { return a = a+b; } -inline __m128d operator-= (__m128d &a, __m128d b) { return a = a-b; } -inline __m128d operator*= (__m128d &a, __m128d b) { return a = a*b; } -inline __m128d operator/= (__m128d &a, __m128d b) { return a = a/b; } +NG_INLINE __m128d operator+= (__m128d &a, __m128d b) { return a = a+b; } +NG_INLINE __m128d operator-= (__m128d &a, __m128d b) { return a = a-b; } +NG_INLINE __m128d operator*= (__m128d &a, __m128d b) { return a = a*b; } +NG_INLINE __m128d operator/= (__m128d &a, __m128d b) { return a = a/b; } -inline __m256d operator- (__m256d a) { return _mm256_xor_pd(a, _mm256_set1_pd(-0.0)); } -inline __m256d operator+ (__m256d a, __m256d b) { return _mm256_add_pd(a,b); } -inline __m256d operator- (__m256d a, __m256d b) { return _mm256_sub_pd(a,b); } -inline __m256d operator* (__m256d a, __m256d b) { return _mm256_mul_pd(a,b); } -inline __m256d operator/ (__m256d a, __m256d b) { return _mm256_div_pd(a,b); } -inline __m256d operator* (double a, __m256d b) { return _mm256_set1_pd(a)*b; } -inline __m256d operator* (__m256d b, double a) { return _mm256_set1_pd(a)*b; } +NG_INLINE __m256d operator- (__m256d a) { return _mm256_xor_pd(a, _mm256_set1_pd(-0.0)); } +NG_INLINE __m256d operator+ (__m256d a, __m256d b) { return _mm256_add_pd(a,b); } +NG_INLINE __m256d operator- (__m256d a, __m256d b) { return _mm256_sub_pd(a,b); } +NG_INLINE __m256d operator* (__m256d a, __m256d b) { return _mm256_mul_pd(a,b); } +NG_INLINE __m256d operator/ (__m256d a, __m256d b) { return _mm256_div_pd(a,b); } +NG_INLINE __m256d operator* (double a, __m256d b) { return _mm256_set1_pd(a)*b; } +NG_INLINE __m256d operator* (__m256d b, double a) { return _mm256_set1_pd(a)*b; } -inline __m256d operator+= (__m256d &a, __m256d b) { return a = a+b; } -inline __m256d operator-= (__m256d &a, __m256d b) { return a = a-b; } -inline __m256d operator*= (__m256d &a, __m256d b) { return a = a*b; } -inline __m256d operator/= (__m256d &a, __m256d b) { return a = a/b; } +NG_INLINE __m256d operator+= (__m256d &a, __m256d b) { return a = a+b; } +NG_INLINE __m256d operator-= (__m256d &a, __m256d b) { return a = a-b; } +NG_INLINE __m256d operator*= (__m256d &a, __m256d b) { return a = a*b; } +NG_INLINE __m256d operator/= (__m256d &a, __m256d b) { return a = a/b; } #endif #endif @@ -71,27 +71,27 @@ namespace ngsimd template // a*b+c - inline auto FMA(T1 a, T2 b, T3 c) + NG_INLINE auto FMA(T1 a, T2 b, T3 c) { return a*b+c; } template::value, int>::type = 0> - inline SIMD operator+ (T a, SIMD b) { return SIMD(a) + b; } + NG_INLINE SIMD operator+ (T a, SIMD b) { return SIMD(a) + b; } template::value, int>::type = 0> - inline SIMD operator- (T a, SIMD b) { return SIMD(a) - b; } + NG_INLINE SIMD operator- (T a, SIMD b) { return SIMD(a) - b; } template::value, int>::type = 0> - inline SIMD operator* (T a, SIMD b) { return SIMD(a) * b; } + NG_INLINE SIMD operator* (T a, SIMD b) { return SIMD(a) * b; } template::value, int>::type = 0> - inline SIMD operator/ (T a, SIMD b) { return SIMD(a) / b; } + NG_INLINE SIMD operator/ (T a, SIMD b) { return SIMD(a) / b; } template::value, int>::type = 0> - inline SIMD operator+ (SIMD a, T b) { return a + SIMD(b); } + NG_INLINE SIMD operator+ (SIMD a, T b) { return a + SIMD(b); } template::value, int>::type = 0> - inline SIMD operator- (SIMD a, T b) { return a - SIMD(b); } + NG_INLINE SIMD operator- (SIMD a, T b) { return a - SIMD(b); } template::value, int>::type = 0> - inline SIMD operator* (SIMD a, T b) { return a * SIMD(b); } + NG_INLINE SIMD operator* (SIMD a, T b) { return a * SIMD(b); } template::value, int>::type = 0> - inline SIMD operator/ (SIMD a, T b) { return a / SIMD(b); } + NG_INLINE SIMD operator/ (SIMD a, T b) { return a / SIMD(b); } #ifdef __AVX__ @@ -141,43 +141,43 @@ using std::fabs; }; using std::exp; - template inline SIMD exp (SIMD a) + template NG_INLINE SIMD exp (SIMD a) { return SIMD([&](int i)->double { return exp(a[i]); } ); } using std::log; - template inline SIMD log (SIMD a) + template NG_INLINE SIMD log (SIMD a) { return SIMD([&](int i)->double { return log(a[i]); } ); } using std::pow; - template inline SIMD pow (SIMD a, double x) + template NG_INLINE SIMD pow (SIMD a, double x) { return SIMD([&](int i)->double { return pow(a[i],x); } ); } using std::sin; - template inline SIMD sin (SIMD a) + template NG_INLINE SIMD sin (SIMD a) { return SIMD([&](int i)->double { return sin(a[i]); } ); } using std::cos; - template inline SIMD cos (SIMD a) + template NG_INLINE SIMD cos (SIMD a) { return SIMD([&](int i)->double { return cos(a[i]); } ); } using std::tan; - template inline SIMD tan (SIMD a) + template NG_INLINE SIMD tan (SIMD a) { return SIMD([&](int i)->double { return tan(a[i]); } ); } using std::atan; - template inline SIMD atan (SIMD a) + template NG_INLINE SIMD atan (SIMD a) { return SIMD([&](int i)->double { return atan(a[i]); } ); } @@ -216,39 +216,39 @@ using std::fabs; data = *p; } - inline operator double() const { return data; } - inline double operator[] (int i) const { return ((double*)(&data))[i]; } - inline double Data() const { return data; } - inline double & Data() { return data; } + NG_INLINE operator double() const { return data; } + NG_INLINE double operator[] (int i) const { return ((double*)(&data))[i]; } + NG_INLINE double Data() const { return data; } + NG_INLINE double & Data() { return data; } - inline SIMD &operator+= (SIMD b) { data+=b.Data(); return *this; } - inline SIMD &operator-= (SIMD b) { data-=b.Data(); return *this; } - inline SIMD &operator*= (SIMD b) { data*=b.Data(); return *this; } - inline SIMD &operator/= (SIMD b) { data/=b.Data(); return *this; } + NG_INLINE SIMD &operator+= (SIMD b) { data+=b.Data(); return *this; } + NG_INLINE SIMD &operator-= (SIMD b) { data-=b.Data(); return *this; } + NG_INLINE SIMD &operator*= (SIMD b) { data*=b.Data(); return *this; } + NG_INLINE SIMD &operator/= (SIMD b) { data/=b.Data(); return *this; } }; - inline SIMD operator+ (SIMD a, SIMD b) { return a.Data()+b.Data(); } - inline SIMD operator- (SIMD a, SIMD b) { return a.Data()-b.Data(); } - inline SIMD operator- (SIMD a) { return -a.Data(); } - inline SIMD operator* (SIMD a, SIMD b) { return a.Data()*b.Data(); } - inline SIMD operator/ (SIMD a, SIMD b) { return a.Data()/b.Data(); } + NG_INLINE SIMD operator+ (SIMD a, SIMD b) { return a.Data()+b.Data(); } + NG_INLINE SIMD operator- (SIMD a, SIMD b) { return a.Data()-b.Data(); } + NG_INLINE SIMD operator- (SIMD a) { return -a.Data(); } + NG_INLINE SIMD operator* (SIMD a, SIMD b) { return a.Data()*b.Data(); } + NG_INLINE SIMD operator/ (SIMD a, SIMD b) { return a.Data()/b.Data(); } - inline SIMD sqrt (SIMD a) { return std::sqrt(a.Data()); } - inline SIMD fabs (SIMD a) { return std::fabs(a.Data()); } - inline SIMD L2Norm2 (SIMD a) { return a.Data()*a.Data(); } - inline SIMD Trans (SIMD a) { return a; } - inline SIMD IfPos (SIMD a, SIMD b, SIMD c) + NG_INLINE SIMD sqrt (SIMD a) { return std::sqrt(a.Data()); } + NG_INLINE SIMD fabs (SIMD a) { return std::fabs(a.Data()); } + NG_INLINE SIMD L2Norm2 (SIMD a) { return a.Data()*a.Data(); } + NG_INLINE SIMD Trans (SIMD a) { return a; } + NG_INLINE SIMD IfPos (SIMD a, SIMD b, SIMD c) { return (a.Data() > 0) ? b : c; } - inline double HSum (SIMD sd) + NG_INLINE double HSum (SIMD sd) { return sd.Data(); } - inline auto HSum (SIMD sd1, SIMD sd2) + NG_INLINE auto HSum (SIMD sd1, SIMD sd2) { return std::make_tuple(sd1.Data(), sd2.Data()); } @@ -291,48 +291,48 @@ using std::fabs; data = _mm256_loadu_pd(p); } - inline operator __m256d() const { return data; } - inline double operator[] (int i) const { return ((double*)(&data))[i]; } - inline __m256d Data() const { return data; } - inline __m256d & Data() { return data; } + NG_INLINE operator __m256d() const { return data; } + NG_INLINE double operator[] (int i) const { return ((double*)(&data))[i]; } + NG_INLINE __m256d Data() const { return data; } + NG_INLINE __m256d & Data() { return data; } - inline SIMD &operator+= (SIMD b) { data+=b.Data(); return *this; } - inline SIMD &operator-= (SIMD b) { data-=b.Data(); return *this; } - inline SIMD &operator*= (SIMD b) { data*=b.Data(); return *this; } - inline SIMD &operator/= (SIMD b) { data/=b.Data(); return *this; } + NG_INLINE SIMD &operator+= (SIMD b) { data+=b.Data(); return *this; } + NG_INLINE SIMD &operator-= (SIMD b) { data-=b.Data(); return *this; } + NG_INLINE SIMD &operator*= (SIMD b) { data*=b.Data(); return *this; } + NG_INLINE SIMD &operator/= (SIMD b) { data/=b.Data(); return *this; } }; - inline SIMD operator+ (SIMD a, SIMD b) { return a.Data()+b.Data(); } - inline SIMD operator- (SIMD a, SIMD b) { return a.Data()-b.Data(); } - inline SIMD operator- (SIMD a) { return -a.Data(); } - inline SIMD operator* (SIMD a, SIMD b) { return a.Data()*b.Data(); } - inline SIMD operator/ (SIMD a, SIMD b) { return a.Data()/b.Data(); } + NG_INLINE SIMD operator+ (SIMD a, SIMD b) { return a.Data()+b.Data(); } + NG_INLINE SIMD operator- (SIMD a, SIMD b) { return a.Data()-b.Data(); } + NG_INLINE SIMD operator- (SIMD a) { return -a.Data(); } + NG_INLINE SIMD operator* (SIMD a, SIMD b) { return a.Data()*b.Data(); } + NG_INLINE SIMD operator/ (SIMD a, SIMD b) { return a.Data()/b.Data(); } - inline SIMD sqrt (SIMD a) { return _mm256_sqrt_pd(a.Data()); } - inline SIMD fabs (SIMD a) { return _mm256_max_pd(a.Data(), -a.Data()); } - inline SIMD L2Norm2 (SIMD a) { return a.Data()*a.Data(); } - inline SIMD Trans (SIMD a) { return a; } - inline SIMD IfPos (SIMD a, SIMD b, SIMD c) + NG_INLINE SIMD sqrt (SIMD a) { return _mm256_sqrt_pd(a.Data()); } + NG_INLINE SIMD fabs (SIMD a) { return _mm256_max_pd(a.Data(), -a.Data()); } + NG_INLINE SIMD L2Norm2 (SIMD a) { return a.Data()*a.Data(); } + NG_INLINE SIMD Trans (SIMD a) { return a; } + NG_INLINE SIMD IfPos (SIMD a, SIMD b, SIMD c) { auto cp = _mm256_cmp_pd (a.Data(), _mm256_setzero_pd(), _CMP_GT_OS); return _mm256_blendv_pd(c.Data(), b.Data(), cp); } - inline double HSum (SIMD sd) + NG_INLINE double HSum (SIMD sd) { __m128d hv = _mm_add_pd (_mm256_extractf128_pd(sd.Data(),0), _mm256_extractf128_pd(sd.Data(),1)); return _mm_cvtsd_f64 (_mm_hadd_pd (hv, hv)); } - inline auto HSum (SIMD sd1, SIMD sd2) + NG_INLINE auto HSum (SIMD sd1, SIMD sd2) { __m256d hv = _mm256_hadd_pd(sd1.Data(), sd2.Data()); __m128d hv2 = _mm_add_pd (_mm256_extractf128_pd(hv,0), _mm256_extractf128_pd(hv,1)); return std::make_tuple(_mm_cvtsd_f64 (hv2), _mm_cvtsd_f64(_mm_shuffle_pd (hv2, hv2, 3))); } - inline SIMD HSum (SIMD v1, SIMD v2, SIMD v3, SIMD v4) + NG_INLINE SIMD HSum (SIMD v1, SIMD v2, SIMD v3, SIMD v4) { __m256d hsum1 = _mm256_hadd_pd (v1.Data(), v2.Data()); __m256d hsum2 = _mm256_hadd_pd (v3.Data(), v4.Data()); @@ -382,54 +382,54 @@ using std::fabs; data = _mm512_loadu_pd(p); } - inline operator __m512d() const { return data; } - inline double operator[] (int i) const { return ((double*)(&data))[i]; } - inline __m512d Data() const { return data; } - inline __m512d & Data() { return data; } + NG_INLINE operator __m512d() const { return data; } + NG_INLINE double operator[] (int i) const { return ((double*)(&data))[i]; } + NG_INLINE __m512d Data() const { return data; } + NG_INLINE __m512d & Data() { return data; } - inline SIMD &operator+= (SIMD b) { data+=b.Data(); return *this; } - inline SIMD &operator-= (SIMD b) { data-=b.Data(); return *this; } - inline SIMD &operator*= (SIMD b) { data*=b.Data(); return *this; } - inline SIMD &operator/= (SIMD b) { data/=b.Data(); return *this; } + NG_INLINE SIMD &operator+= (SIMD b) { data+=b.Data(); return *this; } + NG_INLINE SIMD &operator-= (SIMD b) { data-=b.Data(); return *this; } + NG_INLINE SIMD &operator*= (SIMD b) { data*=b.Data(); return *this; } + NG_INLINE SIMD &operator/= (SIMD b) { data/=b.Data(); return *this; } }; - inline SIMD operator- (SIMD a) { return _mm512_sub_pd(_mm512_setzero_pd(), a.Data()); } + NG_INLINE SIMD operator- (SIMD a) { return _mm512_sub_pd(_mm512_setzero_pd(), a.Data()); } - inline SIMD operator+ (SIMD a, SIMD b) { return _mm512_add_pd(a.Data(),b.Data()); } - inline SIMD operator- (SIMD a, SIMD b) { return _mm512_sub_pd(a.Data(),b.Data()); } - inline SIMD operator* (SIMD a, SIMD b) { return _mm512_mul_pd(a.Data(),b.Data()); } - inline SIMD operator/ (SIMD a, SIMD b) { return _mm512_div_pd(a.Data(),b.Data()); } + NG_INLINE SIMD operator+ (SIMD a, SIMD b) { return _mm512_add_pd(a.Data(),b.Data()); } + NG_INLINE SIMD operator- (SIMD a, SIMD b) { return _mm512_sub_pd(a.Data(),b.Data()); } + NG_INLINE SIMD operator* (SIMD a, SIMD b) { return _mm512_mul_pd(a.Data(),b.Data()); } + NG_INLINE SIMD operator/ (SIMD a, SIMD b) { return _mm512_div_pd(a.Data(),b.Data()); } - inline SIMD sqrt (SIMD a) { return _mm512_sqrt_pd(a.Data()); } - inline SIMD fabs (SIMD a) { return _mm512_max_pd(a.Data(), -a.Data()); } - inline SIMD L2Norm2 (SIMD a) { return a.Data()*a.Data(); } - inline SIMD Trans (SIMD a) { return a; } - inline SIMD IfPos (SIMD a, SIMD b, SIMD c) + NG_INLINE SIMD sqrt (SIMD a) { return _mm512_sqrt_pd(a.Data()); } + NG_INLINE SIMD fabs (SIMD a) { return _mm512_max_pd(a.Data(), -a.Data()); } + NG_INLINE SIMD L2Norm2 (SIMD a) { return a.Data()*a.Data(); } + NG_INLINE SIMD Trans (SIMD a) { return a; } + NG_INLINE SIMD IfPos (SIMD a, SIMD b, SIMD c) { auto cp = _mm512_cmp_pd_mask (a.Data(), _mm512_setzero_pd(), _MM_CMPINT_GT); return _mm512_mask_blend_pd(cp, c.Data(), b.Data()); } - template<> inline auto FMA (SIMD a, SIMD b, SIMD c) + template<> NG_INLINE auto FMA (SIMD a, SIMD b, SIMD c) { return _mm512_fmadd_pd (a.Data(), b.Data(), c.Data()); } - inline double HSum (SIMD sd) + NG_INLINE double HSum (SIMD sd) { SIMD low = _mm512_extractf64x4_pd(sd.Data(),0); SIMD high = _mm512_extractf64x4_pd(sd.Data(),1); return HSum(low)+HSum(high); } - inline auto HSum (SIMD sd1, SIMD sd2) + NG_INLINE auto HSum (SIMD sd1, SIMD sd2) { return std::make_tuple(HSum(sd1), HSum(sd2)); } - inline SIMD HSum (SIMD v1, SIMD v2, SIMD v3, SIMD v4) + NG_INLINE SIMD HSum (SIMD v1, SIMD v2, SIMD v3, SIMD v4) { SIMD high1 = _mm512_extractf64x4_pd(v1.Data(),1); SIMD high2 = _mm512_extractf64x4_pd(v2.Data(),1); @@ -490,48 +490,48 @@ using std::fabs; SIMD & Get() { return NR==0 ? v0 : v1; } }; - template inline MultiSIMD operator+ (MultiSIMD a, MultiSIMD b) + template NG_INLINE MultiSIMD operator+ (MultiSIMD a, MultiSIMD b) { return MultiSIMD (a.Head()+b.Head(), a.Tail()+b.Tail()); } - template inline MultiSIMD operator+ (double a, MultiSIMD b) + template NG_INLINE MultiSIMD operator+ (double a, MultiSIMD b) { return MultiSIMD (a+b.Head(), a+b.Tail()); } - template inline MultiSIMD operator+ (MultiSIMD b, double a) + template NG_INLINE MultiSIMD operator+ (MultiSIMD b, double a) { return MultiSIMD (a+b.Head(), a+b.Tail()); } - template inline MultiSIMD operator- (MultiSIMD a, MultiSIMD b) + template NG_INLINE MultiSIMD operator- (MultiSIMD a, MultiSIMD b) { return MultiSIMD (a.Head()-b.Head(), a.Tail()-b.Tail()); } - template inline MultiSIMD operator- (double a, MultiSIMD b) + template NG_INLINE MultiSIMD operator- (double a, MultiSIMD b) { return MultiSIMD (a-b.Head(), a-b.Tail()); } - template inline MultiSIMD operator- (MultiSIMD b, double a) + template NG_INLINE MultiSIMD operator- (MultiSIMD b, double a) { return MultiSIMD (b.Head()-a, b.Tail()-a); } - template inline MultiSIMD operator- (MultiSIMD a) + template NG_INLINE MultiSIMD operator- (MultiSIMD a) { return MultiSIMD (-a.Head(), -a.Tail()); } - template inline MultiSIMD operator* (MultiSIMD a, MultiSIMD b) + template NG_INLINE MultiSIMD operator* (MultiSIMD a, MultiSIMD b) { return MultiSIMD (a.Head()*b.Head(), a.Tail()*b.Tail()); } - template inline MultiSIMD operator/ (MultiSIMD a, MultiSIMD b) + template NG_INLINE MultiSIMD operator/ (MultiSIMD a, MultiSIMD b) { return MultiSIMD (a.Head()/b.Head(), a.Tail()/b.Tail()); } - template inline MultiSIMD operator* (double a, MultiSIMD b) + template NG_INLINE MultiSIMD operator* (double a, MultiSIMD b) { return MultiSIMD ( a*b.Head(), a*b.Tail()); } - template inline MultiSIMD operator* (MultiSIMD b, double a) + template NG_INLINE MultiSIMD operator* (MultiSIMD b, double a) { return MultiSIMD ( a*b.Head(), a*b.Tail()); } - template inline MultiSIMD & operator+= (MultiSIMD & a, MultiSIMD b) + template NG_INLINE MultiSIMD & operator+= (MultiSIMD & a, MultiSIMD b) { a.Head()+=b.Head(); a.Tail()+=b.Tail(); return a; } - template inline MultiSIMD operator-= (MultiSIMD & a, double b) + template NG_INLINE MultiSIMD operator-= (MultiSIMD & a, double b) { a.Head()-=b; a.Tail()-=b; return a; } - template inline MultiSIMD operator-= (MultiSIMD & a, MultiSIMD b) + template NG_INLINE MultiSIMD operator-= (MultiSIMD & a, MultiSIMD b) { a.Head()-=b.Head(); a.Tail()-=b.Tail(); return a; } - template inline MultiSIMD & operator*= (MultiSIMD & a, MultiSIMD b) + template NG_INLINE MultiSIMD & operator*= (MultiSIMD & a, MultiSIMD b) { a.Head()*=b.Head(); a.Tail()*=b.Tail(); return a; } - template inline MultiSIMD & operator*= (MultiSIMD & a, double b) + template NG_INLINE MultiSIMD & operator*= (MultiSIMD & a, double b) { a.Head()*=b; a.Tail()*=b; return a; } - // inline MultiSIMD operator/= (MultiSIMD & a, MultiSIMD b) { return a.Data()/=b.Data(); } + // NG_INLINE MultiSIMD operator/= (MultiSIMD & a, MultiSIMD b) { return a.Data()/=b.Data(); } - inline SIMD HVSum (SIMD a) { return a; } + NG_INLINE SIMD HVSum (SIMD a) { return a; } template - inline SIMD HVSum (MultiSIMD a) { return a.Head() + HVSum(a.Tail()); } + NG_INLINE SIMD HVSum (MultiSIMD a) { return a.Head() + HVSum(a.Tail()); } - template inline double HSum (MultiSIMD a) { return HSum(HVSum(a)); } - template inline auto HSum (MultiSIMD a, MultiSIMD b) + template NG_INLINE double HSum (MultiSIMD a) { return HSum(HVSum(a)); } + template NG_INLINE auto HSum (MultiSIMD a, MultiSIMD b) { return HSum(HVSum(a), HVSum(b)); } template diff --git a/libsrc/include/mydefs.hpp b/libsrc/include/mydefs.hpp index bf3cb1e9..794e6521 100644 --- a/libsrc/include/mydefs.hpp +++ b/libsrc/include/mydefs.hpp @@ -36,6 +36,22 @@ #endif +#ifndef NG_INLINE +#ifdef __INTEL_COMPILER +#ifdef WIN32 +#define NG_INLINE __forceinline inline +#else +#define NG_INLINE __forceinline inline +#endif +#else +#ifdef __GNUC__ +#define NG_INLINE __attribute__ ((__always_inline__)) inline +#define VLA +#else +#define NG_INLINE inline +#endif +#endif +#endif // #define BASE0 From 9fb7fcacfca4b30878b0de1c6f6d3bf18264b76e Mon Sep 17 00:00:00 2001 From: Matthias Hochsteger Date: Thu, 20 Apr 2017 17:55:56 +0200 Subject: [PATCH 29/63] Revert interface code to preserve compatibility with NGSolve --- libsrc/gprim/geomobjects.hpp | 6 +-- libsrc/interface/nginterface_v2.cpp | 70 +++++++++++++++-------------- libsrc/visualization/soldata.hpp | 10 +++-- 3 files changed, 46 insertions(+), 40 deletions(-) diff --git a/libsrc/gprim/geomobjects.hpp b/libsrc/gprim/geomobjects.hpp index e1e56785..f32376fb 100644 --- a/libsrc/gprim/geomobjects.hpp +++ b/libsrc/gprim/geomobjects.hpp @@ -17,7 +17,7 @@ namespace netgen template - class Point : public AlignedAlloc> + class Point : public ngsimd::AlignedAlloc> { protected: @@ -67,7 +67,7 @@ namespace netgen }; template - class Vec : public AlignedAlloc> + class Vec : public ngsimd::AlignedAlloc> { protected: @@ -150,7 +150,7 @@ namespace netgen template - class Mat : public AlignedAlloc> + class Mat : public ngsimd::AlignedAlloc> { protected: diff --git a/libsrc/interface/nginterface_v2.cpp b/libsrc/interface/nginterface_v2.cpp index ff5acc79..d95f71e1 100644 --- a/libsrc/interface/nginterface_v2.cpp +++ b/libsrc/interface/nginterface_v2.cpp @@ -646,26 +646,29 @@ namespace netgen +#ifdef __AVX__ +#include + template<> DLL_HEADER void Ngx_Mesh :: MultiElementTransformation<1,1> (int elnr, int npts, - const SIMD * xi, size_t sxi, - SIMD * x, size_t sx, - SIMD * dxdxi, size_t sdxdxi) const + const __m256d * xi, size_t sxi, + __m256d * x, size_t sx, + __m256d * dxdxi, size_t sdxdxi) const { cout << "multi-eltrafo simd called, 1,1,simd" << endl; } template<> DLL_HEADER void Ngx_Mesh :: MultiElementTransformation<2,2> (int elnr, int npts, - const SIMD * xi, size_t sxi, - SIMD * x, size_t sx, - SIMD * dxdxi, size_t sdxdxi) const + const __m256d * xi, size_t sxi, + __m256d * x, size_t sx, + __m256d * dxdxi, size_t sdxdxi) const { mesh->GetCurvedElements().CalcMultiPointSurfaceTransformation<2> (elnr, npts, - xi, sxi, - x, sx, - dxdxi, sdxdxi); + reinterpret_cast*> (xi), sxi, + reinterpret_cast*> (x), sx, + reinterpret_cast*> (dxdxi), sdxdxi); /* for (int i = 0; i < npts; i++) { @@ -692,15 +695,15 @@ namespace netgen template<> DLL_HEADER void Ngx_Mesh :: MultiElementTransformation<3,3> (int elnr, int npts, - const SIMD * xi, size_t sxi, - SIMD * x, size_t sx, - SIMD * dxdxi, size_t sdxdxi) const + const __m256d * xi, size_t sxi, + __m256d * x, size_t sx, + __m256d * dxdxi, size_t sdxdxi) const { mesh->GetCurvedElements().CalcMultiPointElementTransformation (elnr, npts, - xi, sxi, - x, sx, - dxdxi, sdxdxi); + reinterpret_cast*> (xi), sxi, + reinterpret_cast*> (x), sx, + reinterpret_cast*> (dxdxi), sdxdxi); /* for (int i = 0; i < npts; i++) { @@ -727,27 +730,27 @@ namespace netgen template<> DLL_HEADER void Ngx_Mesh :: MultiElementTransformation<0,2> (int elnr, int npts, - const SIMD *xi, size_t sxi, - SIMD * x, size_t sx, - SIMD * dxdxi, size_t sdxdxi) const + const __m256d *xi, size_t sxi, + __m256d * x, size_t sx, + __m256d * dxdxi, size_t sdxdxi) const { cout << "MultiElementtransformation<0,2> simd not implemented" << endl; } template<> DLL_HEADER void Ngx_Mesh :: MultiElementTransformation<0,1> (int elnr, int npts, - const SIMD * xi, size_t sxi, - SIMD * x, size_t sx, - SIMD * dxdxi, size_t sdxdxi) const + const __m256d * xi, size_t sxi, + __m256d * x, size_t sx, + __m256d * dxdxi, size_t sdxdxi) const { cout << "multi-eltrafo simd called, 0,1,simd" << endl; } template<> DLL_HEADER void Ngx_Mesh :: MultiElementTransformation<1,3> (int elnr, int npts, - const SIMD * xi, size_t sxi, - SIMD * x, size_t sx, - SIMD * dxdxi, size_t sdxdxi) const + const __m256d * xi, size_t sxi, + __m256d * x, size_t sx, + __m256d * dxdxi, size_t sdxdxi) const { double hxi[4][1]; double hx[4][3]; @@ -769,9 +772,9 @@ namespace netgen template<> DLL_HEADER void Ngx_Mesh :: MultiElementTransformation<1,2> (int elnr, int npts, - const SIMD * xi, size_t sxi, - SIMD * x, size_t sx, - SIMD * dxdxi, size_t sdxdxi) const + const __m256d * xi, size_t sxi, + __m256d * x, size_t sx, + __m256d * dxdxi, size_t sdxdxi) const { for (int i = 0; i < npts; i++) { @@ -798,15 +801,15 @@ namespace netgen template<> DLL_HEADER void Ngx_Mesh :: MultiElementTransformation<2,3> (int elnr, int npts, - const SIMD * xi, size_t sxi, - SIMD * x, size_t sx, - SIMD * dxdxi, size_t sdxdxi) const + const __m256d * xi, size_t sxi, + __m256d * x, size_t sx, + __m256d * dxdxi, size_t sdxdxi) const { mesh->GetCurvedElements().CalcMultiPointSurfaceTransformation<3> (elnr, npts, - xi, sxi, - x, sx, - dxdxi, sdxdxi); + reinterpret_cast*> (xi), sxi, + reinterpret_cast*> (x), sx, + reinterpret_cast*> (dxdxi), sdxdxi); /* for (int i = 0; i < npts; i++) { @@ -831,6 +834,7 @@ namespace netgen */ } +#endif diff --git a/libsrc/visualization/soldata.hpp b/libsrc/visualization/soldata.hpp index 0ae4b453..4c846d62 100644 --- a/libsrc/visualization/soldata.hpp +++ b/libsrc/visualization/soldata.hpp @@ -92,15 +92,17 @@ namespace netgen return res; } +#ifdef __AVX__ virtual bool GetMultiSurfValue (size_t selnr, size_t facetnr, size_t npts, - const SIMD * xref, - const SIMD * x, - const SIMD * dxdxref, - SIMD * values) + const __m256d * xref, + const __m256d * x, + const __m256d * dxdxref, + __m256d * values) { cerr << "GetMultiSurfVaue not overloaded for SIMD" << endl; return false; } +#endif virtual bool GetSegmentValue (int segnr, double xref, double * values) { return false; } From 94fd57154f556450a04808b244eb8c83e7a95fb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20Sch=C3=B6berl?= Date: Wed, 26 Apr 2017 12:15:05 +0200 Subject: [PATCH 30/63] disable VBO on windows --- libsrc/visualization/vssolution.hpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libsrc/visualization/vssolution.hpp b/libsrc/visualization/vssolution.hpp index 80cf1c5b..bb2b4c7d 100644 --- a/libsrc/visualization/vssolution.hpp +++ b/libsrc/visualization/vssolution.hpp @@ -43,7 +43,13 @@ class DLL_HEADER VisualSceneSolution : public VisualScene Point<3> p; }; +#ifndef WIN32 + // use OpenGL vertex buffers from OpenGL 2.x + // not supported by some drivers on windows + // try on your own responsibility #define USE_BUFFERS +#endif + #ifdef USE_BUFFERS bool has_surfel_vbo = false; GLuint surfel_vbo[4]; // From 990d0fce78e8ec1dc0ed1cad185eca21aa8d0815 Mon Sep 17 00:00:00 2001 From: Matthias Hochsteger Date: Mon, 8 May 2017 16:42:49 +0200 Subject: [PATCH 31/63] GUI support from Python Enables experimental support for starting the Netgen GUI from Python directly. To use it, just import the gui module: > import netgen.gui --- libsrc/meshing/global.cpp | 4 +- ng/CMakeLists.txt | 6 ++ ng/gui.cpp | 222 ++++++++++++++++++++++++++++++++++++++ ng/ngappinit.cpp | 2 + 4 files changed, 233 insertions(+), 1 deletion(-) create mode 100644 ng/gui.cpp diff --git a/libsrc/meshing/global.cpp b/libsrc/meshing/global.cpp index 4a6237c3..dd3e14bd 100644 --- a/libsrc/meshing/global.cpp +++ b/libsrc/meshing/global.cpp @@ -27,7 +27,9 @@ namespace netgen global_mesh = m; } - + // true if netgen was started using the netgen executable + // false if netgen.gui was imported from python + DLL_HEADER bool netgen_executable_started = false; // Flags parameters; int silentflag = 0; diff --git a/ng/CMakeLists.txt b/ng/CMakeLists.txt index 0f36f434..10db4536 100644 --- a/ng/CMakeLists.txt +++ b/ng/CMakeLists.txt @@ -11,11 +11,17 @@ if(USE_GUI) add_executable(netgen ${netgen_sources}) target_link_libraries( netgen nglib ${ZLIB_LIBRARIES} ${LIBTOGL} ${TK_LIBRARY} ${TCL_LIBRARY} ${JPEG_LIBRARIES} ${FFMPEG_LIBRARIES} ${X11_X11_LIB} ${OCC_LIBRARIES}) + add_library(gui SHARED ${netgen_sources} gui.cpp) + target_link_libraries( gui nglib ${ZLIB_LIBRARIES} ${LIBTOGL} ${TK_LIBRARY} ${TCL_LIBRARY} ${JPEG_LIBRARIES} ${FFMPEG_LIBRARIES} ${X11_X11_LIB} ${OCC_LIBRARIES}) if(NOT WIN32) target_link_libraries( netgen mesh stlvis stl geom2dvis interface geom2d csg stl visual csgvis ) + target_link_libraries( gui mesh stlvis stl geom2dvis interface geom2d csg stl visual csgvis ) endif(NOT WIN32) install(TARGETS netgen ${ng_install_dir}) + install(TARGETS gui DESTINATION ${PYTHON_PACKAGES_INSTALL_DIR}/netgen) + set_target_properties( gui PROPERTIES PREFIX "") # name output file gui.so instead of libgui.so + if(APPLE) set_target_properties(netgen PROPERTIES OUTPUT_NAME netgen) endif(APPLE) diff --git a/ng/gui.cpp b/ng/gui.cpp new file mode 100644 index 00000000..ab7bcfab --- /dev/null +++ b/ng/gui.cpp @@ -0,0 +1,222 @@ +#include +#include +#include + +#include "../libsrc/interface/writeuser.hpp" +#include + +namespace netgen +{ + DLL_HEADER extern Flags parameters; + DLL_HEADER extern bool netgen_executable_started; + DLL_HEADER extern int printmessage_importance; +} + +using netgen::parameters; +using netgen::ngdir; +using netgen::verbose; +using netgen::Array; +using netgen::RegisterUserFormats; + +extern "C" int Ng_ServerSocketManagerInit (int port); +extern "C" int Ng_ServerSocketManagerRun (void); + +int Tcl_AppInit(Tcl_Interp * interp); + +extern bool nodisplay; +extern bool shellmode; + +void main_gui() +{ + if(netgen::netgen_executable_started) + return; + + if ( netgen::id == 0 ) + { + cout << "NETGEN-" << PACKAGE_VERSION << endl; + + cout << "Developed by Joachim Schoeberl at" << endl + << "2010-xxxx Vienna University of Technology" << endl + << "2006-2010 RWTH Aachen University" << endl + << "1996-2006 Johannes Kepler University Linz" << endl; + +#ifdef OCCGEOMETRY + cout << "Including OpenCascade geometry kernel" << endl; +#endif + +#ifdef ACIS + cout << "Including ACIS geometry kernel" << endl; +#endif + +#ifdef DEBUG + cout << "You are running the debug version !" << endl; +#endif + + + } + +// netgen::h_argc = argc; +// netgen::h_argv = argv; + + if (getenv ("NETGENDIR") && strlen (getenv ("NETGENDIR"))) + ngdir = getenv ("NETGENDIR"); + else + ngdir = "."; + + verbose = parameters.GetDefineFlag ("V"); + + if (verbose) + cout << "NETGENDIR = " << ngdir << endl; + + + if ( netgen::id == 0 ) + { + if (parameters.StringFlagDefined ("testout")) + netgen::testout = new ofstream (parameters.GetStringFlag ("testout", "test.out")); + + + if(parameters.GetDefineFlag("batchmode")) + nodisplay = true; + + + if(parameters.GetDefineFlag("shellmode")) + { + nodisplay = true; + shellmode = true; + } + + Tcl_FindExecutable(NULL); + + // initialize application + Tcl_Interp * myinterp = Tcl_CreateInterp (); + if (Tcl_AppInit (myinterp) == TCL_ERROR) + { + cerr << "Exit Netgen due to initialization problem" << endl; + exit (1); + } + + + + // parse tcl-script + int errcode; + + bool internaltcl = false; + if (shellmode) + internaltcl = false; + + if (verbose) + { + cout << "Tcl header version = " << TCL_PATCH_LEVEL << endl; + Tcl_Eval (myinterp, "puts \"Tcl runtime version = [info patchlevel] \";"); + } + + if (parameters.GetDefineFlag ("internaltcl")) + internaltcl=true; + if (parameters.GetDefineFlag ("externaltcl")) + internaltcl=false; + + + + if (internaltcl) + { + if (verbose) + cout << "using internal Tcl-script" << endl; + + // connect to one string + extern const char * ngscript[]; + const char ** hcp = ngscript; + int len = 0; + while (*hcp) + len += strlen (*hcp++); + + char * tr1 = new char[len+1]; + *tr1 = 0; + hcp = ngscript; + + char * tt1 = tr1; + while (*hcp) + { + strcat (tt1, *hcp); + tt1 += strlen (*hcp++); + } + + errcode = Tcl_Eval (myinterp, tr1); + delete [] tr1; + } + + else + + { + string startfile = ngdir + "/ng.tcl"; + + if (verbose) + cout << "Load Tcl-script from " << startfile << endl; + + errcode = Tcl_EvalFile (myinterp, (char*)startfile.c_str()); + } + + if (errcode) + { + cout << "Error in Tcl-Script:" << endl; + // cout << "result = " << myinterp->result << endl; + cout << "result = " << Tcl_GetStringResult (myinterp) << endl; + // cout << "in line " << myinterp->errorLine << endl; + + cout << "\nMake sure to set environment variable NETGENDIR to directory containing ng.tcl" << endl; + exit (1); + } + + + // lookup user file formats and insert into format list: + Array userformats; + Array extensions; + RegisterUserFormats (userformats, extensions); + + ostringstream fstr; + + tcl_const char * exportft = Tcl_GetVar (myinterp, "exportfiletype", 0); + for (int i = 1; i <= userformats.Size(); i++) + { + fstr << ".ngmenu.file.filetype add radio -label \"" + << userformats.Get(i) << "\" -variable exportfiletype\n"; + fstr << "lappend meshexportformats { {" << userformats.Get(i) << "} {" << extensions.Get(i) << "} }\n"; + } + + Tcl_Eval (myinterp, (char*)fstr.str().c_str()); + Tcl_SetVar (myinterp, "exportfiletype", exportft, 0); + + + // start event-loop + Tk_MainLoop(); + Tcl_DeleteInterp (myinterp); +// Tcl_Exit(0); + } +} + + + +extern "C" int Ng_Init (Tcl_Interp * interp); +extern "C" int Ng_Vis_Init (Tcl_Interp * interp); + +extern "C" void Ng_TclCmd(string); + +struct GuiThread { + std::thread t; + ~GuiThread() { + Ng_TclCmd(".ngmenu.file invoke \"Quit\";"); + if(netgen::printmessage_importance>2) + cout << "waiting for GUI to finish..." << endl; + t.join(); + } +}; + +static GuiThread gui_thread; + +PYBIND11_PLUGIN(gui) { + pybind11::module m("gui", "pybind gui"); + gui_thread.t = std::thread([]() + { + main_gui(); + }); + return m.ptr(); +} diff --git a/ng/ngappinit.cpp b/ng/ngappinit.cpp index cf2f25bd..69623bc4 100644 --- a/ng/ngappinit.cpp +++ b/ng/ngappinit.cpp @@ -34,6 +34,7 @@ namespace netgen namespace netgen { Flags parameters; + DLL_HEADER extern bool netgen_executable_started; } @@ -70,6 +71,7 @@ bool shellmode = false; int main(int argc, char ** argv) { + netgen::netgen_executable_started = true; #ifdef PARALLEL int mpi_required = MPI_THREAD_MULTIPLE; From 2b0d3f02ba6c58f8c4c2a394bc24d1a0905d181e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20Sch=C3=B6berl?= Date: Mon, 8 May 2017 21:20:36 +0200 Subject: [PATCH 32/63] load opengl buffer-functions only if USE_BUFFERS is set --- libsrc/visualization/vssolution.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libsrc/visualization/vssolution.cpp b/libsrc/visualization/vssolution.cpp index a61036e6..06a2b2bb 100644 --- a/libsrc/visualization/vssolution.cpp +++ b/libsrc/visualization/vssolution.cpp @@ -4836,12 +4836,14 @@ void (*glGenBuffers) (GLsizei a, GLuint *b); void (*glBufferData) (GLenum a, GLsizeiptr b, const GLvoid *c, GLenum d); void (*glBufferSubData) (GLenum a, GLintptr b, GLsizeiptr c, const GLvoid *d); DLL_HEADER void LoadOpenGLFunctionPointers() { +#ifdef USE_BUFFERS glBindBuffer = (decltype(glBindBuffer)) wglGetProcAddress("glBindBuffer"); glBufferSubData = (decltype(glBufferSubData)) wglGetProcAddress("glBufferSubData"); glBufferData = (decltype(glBufferData)) wglGetProcAddress("glBufferData"); glDeleteBuffers = (decltype(glDeleteBuffers)) wglGetProcAddress("glDeleteBuffers"); glGenBuffers = (decltype(glGenBuffers)) wglGetProcAddress("glGenBuffers"); if(!glBindBuffer) throw std::runtime_error("Could not load OpenGL functions!"); +#endif } #else // WIN32 DLL_HEADER void LoadOpenGLFunctionPointers() { } From 2da1465d520fdc6dd45ae23436c9524990e5332e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20Sch=C3=B6berl?= Date: Wed, 10 May 2017 17:41:44 +0200 Subject: [PATCH 33/63] get surface element from face --- libsrc/include/nginterface_v2.hpp | 1 + libsrc/include/nginterface_v2_impl.hpp | 1 + 2 files changed, 2 insertions(+) diff --git a/libsrc/include/nginterface_v2.hpp b/libsrc/include/nginterface_v2.hpp index b6271ecf..ca72a3f1 100644 --- a/libsrc/include/nginterface_v2.hpp +++ b/libsrc/include/nginterface_v2.hpp @@ -184,6 +184,7 @@ namespace netgen public: Ng_Vertices vertices; Ng_Edges edges; + int surface_el; // -1 if face not on surface }; diff --git a/libsrc/include/nginterface_v2_impl.hpp b/libsrc/include/nginterface_v2_impl.hpp index 0bcd71d9..22815720 100644 --- a/libsrc/include/nginterface_v2_impl.hpp +++ b/libsrc/include/nginterface_v2_impl.hpp @@ -274,6 +274,7 @@ template <> NGX_INLINE DLL_HEADER const Ng_Node<2> Ngx_Mesh :: GetNode<2> (int n Ng_Node<2> node; node.vertices.ptr = mesh->GetTopology().GetFaceVerticesPtr(nr); node.vertices.nv = (node.vertices.ptr[3] == 0) ? 3 : 4; + node.surface_el = mesh->GetTopology().GetFace2SurfaceElement (nr+1)-1; return node; } From 025f8750be630ab3bae4a0024b7497220922843b Mon Sep 17 00:00:00 2001 From: Matthias Hochsteger Date: Wed, 10 May 2017 19:34:42 +0200 Subject: [PATCH 34/63] GUI support from Python and some cleanup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Squashed commit of the following: commit 5058ceb9351548937487aa94073e7f59236ae9fe Merge: d37f0af 2da1465 Author: Matthias Hochsteger Date: Wed May 10 19:33:55 2017 +0200 Merge remote-tracking branch 'origin/master' into native_tcl_macos commit d37f0afcc1389c0c3ec0899da9c1af158c926ca5 Author: Matthias Date: Wed May 10 19:27:12 2017 +0200 link gui to netgen, some fixes commit 297141455cd4fab81709c13d6253ad8114beee4a Author: Matthias Date: Wed May 10 19:02:47 2017 +0200 windows fixes commit 9bf290a60835f29762b15ee3b722da132678f90c Author: Matthias Hochsteger Date: Wed May 10 18:59:53 2017 +0200 More cleanup, proper code separation ... between netgen exectuable and gui library commit f46d438d3c9dd32f9f94642b4ec00b85611ef1dd Author: Matthias Hochsteger Date: Wed May 10 14:03:53 2017 +0200 fix typos commit b3d301ff4e321189aef469bff77f7cffa7b69e98 Author: Matthias Hochsteger Date: Wed May 10 13:32:57 2017 +0200 also link tk to togl on windows... commit c3519abee7b041e45c913a45999ed2d29d4ff325 Author: Matthias Hochsteger Date: Wed May 10 13:30:16 2017 +0200 link TCL to togl on windows commit 80b607436b45f38f4bac2708a78ef03561ad44e5 Author: Matthias Hochsteger Date: Wed May 10 13:26:45 2017 +0200 linkt TCL only to netgen executable commit 080139a431e949e14cb9f05194e19c5129aca3d3 Author: Matthias Hochsteger Date: Wed May 10 13:20:36 2017 +0200 fix dll ex/import commit dd68efacb01fbbbe3f136168f12fed41fa3c3c8a Author: Matthias Hochsteger Date: Wed May 10 13:15:39 2017 +0200 fix dll export commit 9023b9ca49b4c2b99f228f64564990e2d0246b8c Author: Matthias Hochsteger Date: Wed May 10 12:06:14 2017 +0200 use system tcl/tk on MacOS, but download tcl/tk for windows commit 16eb4c1b01eb5229f93274791187b2c666bb8b8e Author: Matthias Hochsteger Date: Wed May 10 12:01:36 2017 +0200 more cleanup commit 6df5b82a7d9a1177a755446d563d6c4b98ff6329 Merge: af23786 2b0d3f0 Author: Matthias Hochsteger Date: Wed May 10 11:45:42 2017 +0200 Merge remote-tracking branch 'origin/master' into native_tcl_macos commit af2378637a6513de3b50841ed6314cd7e12f7205 Author: Matthias Hochsteger Date: Wed May 10 11:45:40 2017 +0200 some cleanup commit 81bbe117efe25df53c71f9ae603c50ee4557703a Author: Joachim Schöberl Date: Tue May 9 20:14:46 2017 +0200 tk-gui commit 387e6da678661dd3b9d75d696733f46fe43d789a Merge: e658b5b e653d8e Author: Joachim Schöberl Date: Tue May 9 18:49:20 2017 +0200 Merge remote-tracking branch 'origin/gui_from_python' into native_tcl_macos commit e658b5b2c1ac3264f4165b5f6d2b821b3b1b0926 Author: Matthias Hochsteger Date: Tue May 9 18:30:35 2017 +0200 use native tcl on macos commit e653d8e6789d20e24b16a68bf760415940e881f8 Author: Matthias Hochsteger Date: Mon May 8 16:37:23 2017 +0200 next fix commit f663c80b00754d141a02fa6abde2077c841bbafb Author: Matthias Hochsteger Date: Mon May 8 16:23:21 2017 +0200 Fix symbol export on windows commit 70d99782423d33d3fa6f80e758a7377d0cb52840 Author: Matthias Hochsteger Date: Mon May 8 15:14:56 2017 +0200 GUI support from Python Enables experimental support for starting the Netgen GUI from Python directly. To use it, just import the gui module: > import netgen.gui --- cmake/external_projects/tcltk.cmake | 106 ++++++------- libsrc/visualization/CMakeLists.txt | 2 +- ng/CMakeLists.txt | 26 +++- ng/Togl2.1/CMakeLists.txt | 5 +- ng/Togl2.1/togl.c | 11 +- ng/gui.cpp | 231 +++------------------------- ng/ng.tcl | 3 + ng/ngappinit.cpp | 53 +------ nglib/CMakeLists.txt | 2 +- python/CMakeLists.txt | 2 +- python/__init__.py | 12 +- python/gui.py | 11 ++ 12 files changed, 135 insertions(+), 329 deletions(-) create mode 100644 python/gui.py diff --git a/cmake/external_projects/tcltk.cmake b/cmake/external_projects/tcltk.cmake index ad8c5e4a..65d06df0 100644 --- a/cmake/external_projects/tcltk.cmake +++ b/cmake/external_projects/tcltk.cmake @@ -1,56 +1,58 @@ if(APPLE) - set(HOME $ENV{HOME}) - set(tcl_prefix ${CMAKE_INSTALL_PREFIX}/../../) - ExternalProject_Add(project_tcl - URL "http://sourceforge.net/projects/tcl/files/Tcl/8.6.4/tcl8.6.4-src.tar.gz" - URL_MD5 d7cbb91f1ded1919370a30edd1534304 - DOWNLOAD_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external_dependencies - UPDATE_COMMAND "" # Disable update - CONFIGURE_COMMAND ../project_tcl/macosx/configure --enable-threads --enable-framework --prefix=${tcl_prefix} --libdir=${tcl_prefix}/Contents/Frameworks --bindir=${tcl_prefix}/Contents/Frameworks/Tcl.framework/bin - BUILD_COMMAND make -j4 binaries libraries - INSTALL_COMMAND make install-binaries install-headers install-libraries install-private-headers - LOG_DOWNLOAD 1 - LOG_BUILD 1 - LOG_CONFIGURE 1 - LOG_INSTALL 1 - ) - - ExternalProject_Add(project_tk - DEPENDS project_tcl - URL "http://sourceforge.net/projects/tcl/files/Tcl/8.6.4/tk8.6.4-src.tar.gz" - URL_MD5 261754d7dc2a582f00e35547777e1fea - DOWNLOAD_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external_dependencies - UPDATE_COMMAND "" # Disable update - CONFIGURE_COMMAND ../project_tk/macosx/configure --enable-aqua=yes --enable-threads --enable-framework --prefix=${tcl_prefix} --libdir=${tcl_prefix}/Contents/Frameworks --bindir=${tcl_prefix}/Contents/Frameworks/Tcl.framework/bin --with-tcl=${tcl_prefix}/Contents/Frameworks/Tcl.framework - BUILD_COMMAND make -j4 binaries libraries - INSTALL_COMMAND make install-binaries install-headers install-libraries install-private-headers - LOG_DOWNLOAD 1 - LOG_BUILD 1 - LOG_CONFIGURE 1 - LOG_INSTALL 1 - ) - - ExternalProject_Add(project_tkdnd - URL "https://sourceforge.net/projects/tkdnd/files/OS%20X%20Binaries/TkDND%202.8/tkdnd2.8-OSX-MountainLion.tar.gz" - URL_MD5 2dbb471b1d66c5f391f3c3c5b71548fb - DOWNLOAD_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external_dependencies - BUILD_IN_SOURCE 1 - CONFIGURE_COMMAND "" - BUILD_COMMAND "" - INSTALL_COMMAND ${CMAKE_COMMAND} -E copy_directory . ${CMAKE_INSTALL_PREFIX}/../MacOS - LOG_DOWNLOAD 1 - LOG_CONFIGURE 1 - LOG_BUILD 1 - LOG_INSTALL 1 - ) - - list(APPEND NETGEN_DEPENDENCIES project_tcl project_tk project_tkdnd) - list(APPEND CMAKE_PREFIX_PATH ${CMAKE_INSTALL_PREFIX}../Frameworks) - set(TCL_INCLUDE_PATH ${CMAKE_INSTALL_PREFIX}/../Frameworks/Tcl.framework/Headers) - set(TCL_LIBRARY ${CMAKE_INSTALL_PREFIX}/../Frameworks/Tcl.framework) - set(TK_LIBRARY ${CMAKE_INSTALL_PREFIX}/../Frameworks/Tk.framework) - set(TK_INCLUDE_PATH ${CMAKE_INSTALL_PREFIX}/../Frameworks/Tk.framework/Headers) - + # use system tcl/tk + find_package(TCL 8.5 REQUIRED) +# set(HOME $ENV{HOME}) +# set(tcl_prefix ${CMAKE_INSTALL_PREFIX}/../../) +# ExternalProject_Add(project_tcl +# URL "http://sourceforge.net/projects/tcl/files/Tcl/8.6.4/tcl8.6.4-src.tar.gz" +# URL_MD5 d7cbb91f1ded1919370a30edd1534304 +# DOWNLOAD_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external_dependencies +# UPDATE_COMMAND "" # Disable update +# CONFIGURE_COMMAND ../project_tcl/macosx/configure --enable-threads --enable-framework --prefix=${tcl_prefix} --libdir=${tcl_prefix}/Contents/Frameworks --bindir=${tcl_prefix}/Contents/Frameworks/Tcl.framework/bin +# BUILD_COMMAND make -j4 binaries libraries +# INSTALL_COMMAND make install-binaries install-headers install-libraries install-private-headers +# LOG_DOWNLOAD 1 +# LOG_BUILD 1 +# LOG_CONFIGURE 1 +# LOG_INSTALL 1 +# ) +# +# ExternalProject_Add(project_tk +# DEPENDS project_tcl +# URL "http://sourceforge.net/projects/tcl/files/Tcl/8.6.4/tk8.6.4-src.tar.gz" +# URL_MD5 261754d7dc2a582f00e35547777e1fea +# DOWNLOAD_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external_dependencies +# UPDATE_COMMAND "" # Disable update +# CONFIGURE_COMMAND ../project_tk/macosx/configure --enable-aqua=yes --enable-threads --enable-framework --prefix=${tcl_prefix} --libdir=${tcl_prefix}/Contents/Frameworks --bindir=${tcl_prefix}/Contents/Frameworks/Tcl.framework/bin --with-tcl=${tcl_prefix}/Contents/Frameworks/Tcl.framework +# BUILD_COMMAND make -j4 binaries libraries +# INSTALL_COMMAND make install-binaries install-headers install-libraries install-private-headers +# LOG_DOWNLOAD 1 +# LOG_BUILD 1 +# LOG_CONFIGURE 1 +# LOG_INSTALL 1 +# ) +# +# ExternalProject_Add(project_tkdnd +# URL "https://sourceforge.net/projects/tkdnd/files/OS%20X%20Binaries/TkDND%202.8/tkdnd2.8-OSX-MountainLion.tar.gz" +# URL_MD5 2dbb471b1d66c5f391f3c3c5b71548fb +# DOWNLOAD_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external_dependencies +# BUILD_IN_SOURCE 1 +# CONFIGURE_COMMAND "" +# BUILD_COMMAND "" +# INSTALL_COMMAND ${CMAKE_COMMAND} -E copy_directory . ${CMAKE_INSTALL_PREFIX}/../MacOS +# LOG_DOWNLOAD 1 +# LOG_CONFIGURE 1 +# LOG_BUILD 1 +# LOG_INSTALL 1 +# ) +# +# list(APPEND NETGEN_DEPENDENCIES project_tcl project_tk project_tkdnd) +# list(APPEND CMAKE_PREFIX_PATH ${CMAKE_INSTALL_PREFIX}../Frameworks) +# set(TCL_INCLUDE_PATH ${CMAKE_INSTALL_PREFIX}/../Frameworks/Tcl.framework/Headers) +# set(TCL_LIBRARY ${CMAKE_INSTALL_PREFIX}/../Frameworks/Tcl.framework) +# set(TK_LIBRARY ${CMAKE_INSTALL_PREFIX}/../Frameworks/Tk.framework) +# set(TK_INCLUDE_PATH ${CMAKE_INSTALL_PREFIX}/../Frameworks/Tk.framework/Headers) +# elseif(WIN32) ExternalProject_Add(project_win_extlibs diff --git a/libsrc/visualization/CMakeLists.txt b/libsrc/visualization/CMakeLists.txt index 5031cbab..ceedbc7b 100644 --- a/libsrc/visualization/CMakeLists.txt +++ b/libsrc/visualization/CMakeLists.txt @@ -12,7 +12,7 @@ endif(USE_GUI) add_library(visual ${NG_LIB_TYPE} ${LIB_VISUAL_SOURCES}) if(NOT WIN32) - target_link_libraries( visual ${PYTHON_LIBRARIES} ${MPI_CXX_LIBRARIES} ${OPENGL_LIBRARIES} ${TCL_LIBRARY} ) + target_link_libraries( visual ${PYTHON_LIBRARIES} ${MPI_CXX_LIBRARIES} ${OPENGL_LIBRARIES} ) install( TARGETS visual ${ng_install_dir}) endif(NOT WIN32) diff --git a/ng/CMakeLists.txt b/ng/CMakeLists.txt index 10db4536..6749dd2f 100644 --- a/ng/CMakeLists.txt +++ b/ng/CMakeLists.txt @@ -1,4 +1,11 @@ -set(netgen_sources demoview.cpp ngappinit.cpp onetcl.cpp parallelfunc.cpp ngpkg.cpp ../libsrc/stlgeom/stlpkg.cpp ../libsrc/visualization/visualpkg.cpp ../libsrc/csg/csgpkg.cpp ../libsrc/geom2d/geom2dpkg.cpp ../libsrc/occ/occpkg.cpp ../libsrc/occ/vsocc.cpp) +set(gui_sources + gui.cpp ngpkg.cpp demoview.cpp parallelfunc.cpp + ../libsrc/stlgeom/stlpkg.cpp ../libsrc/visualization/visualpkg.cpp + ../libsrc/csg/csgpkg.cpp ../libsrc/geom2d/geom2dpkg.cpp + ../libsrc/occ/occpkg.cpp ../libsrc/occ/vsocc.cpp + ) + +set(netgen_sources ngappinit.cpp onetcl.cpp ) if(USE_GUI) if(WIN32) @@ -10,21 +17,26 @@ if(USE_GUI) endif(WIN32) add_executable(netgen ${netgen_sources}) - target_link_libraries( netgen nglib ${ZLIB_LIBRARIES} ${LIBTOGL} ${TK_LIBRARY} ${TCL_LIBRARY} ${JPEG_LIBRARIES} ${FFMPEG_LIBRARIES} ${X11_X11_LIB} ${OCC_LIBRARIES}) - add_library(gui SHARED ${netgen_sources} gui.cpp) - target_link_libraries( gui nglib ${ZLIB_LIBRARIES} ${LIBTOGL} ${TK_LIBRARY} ${TCL_LIBRARY} ${JPEG_LIBRARIES} ${FFMPEG_LIBRARIES} ${X11_X11_LIB} ${OCC_LIBRARIES}) + add_library(gui SHARED ${gui_sources}) + + target_link_libraries( netgen nglib gui ${ZLIB_LIBRARIES} ${TK_LIBRARY} ${TCL_LIBRARY} ${JPEG_LIBRARIES} ${FFMPEG_LIBRARIES} ${X11_X11_LIB} ${OCC_LIBRARIES}) + target_link_libraries( gui PUBLIC nglib ${ZLIB_LIBRARIES} ${JPEG_LIBRARIES} ${FFMPEG_LIBRARIES} ${X11_X11_LIB} ${OCC_LIBRARIES} ) + target_link_libraries( gui PRIVATE ${LIBTOGL}) + if(NOT WIN32) target_link_libraries( netgen mesh stlvis stl geom2dvis interface geom2d csg stl visual csgvis ) - target_link_libraries( gui mesh stlvis stl geom2dvis interface geom2d csg stl visual csgvis ) + target_link_libraries( gui PUBLIC mesh stlvis stl geom2dvis interface geom2d csg stl visual csgvis ) endif(NOT WIN32) install(TARGETS netgen ${ng_install_dir}) - install(TARGETS gui DESTINATION ${PYTHON_PACKAGES_INSTALL_DIR}/netgen) - set_target_properties( gui PROPERTIES PREFIX "") # name output file gui.so instead of libgui.so + install(TARGETS gui ${ng_install_dir}) if(APPLE) set_target_properties(netgen PROPERTIES OUTPUT_NAME netgen) endif(APPLE) + if(WIN32) + set_target_properties( gui PROPERTIES OUTPUT_NAME libgui ) + endif(WIN32) endif(USE_GUI) diff --git a/ng/Togl2.1/CMakeLists.txt b/ng/Togl2.1/CMakeLists.txt index 442a2de4..98ae1310 100644 --- a/ng/Togl2.1/CMakeLists.txt +++ b/ng/Togl2.1/CMakeLists.txt @@ -8,12 +8,13 @@ if(WIN32) add_definitions("-DBUILD_togl -DUNICODE -D_UNICODE -DTOGL_USE_FONTS=0 -DSTDC_HEADERS -DSTDC_HEADER") add_library(togl SHARED togl.c toglProcAddr.c toglStubInit.c) install(TARGETS togl DESTINATION ${ng_install_dir} COMPONENT netgen) + target_link_libraries(togl ${TCL_LIBRARY} ${TK_LIBRARY}) else(WIN32) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fomit-frame-pointer -Wno-implicit-int") add_definitions("-DPACKAGE_NAME=\"Togl\" -DPACKAGE_TARNAME=\"togl\" -DPACKAGE_VERSION=\"2.1\" -DPACKAGE_STRING=\"Togl\ 2.1\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DSTDC_HEADERS=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=0 -DHAVE_LIMITS_H=1 -DHAVE_SYS_PARAM_H=1 -DUSE_THREAD_ALLOC=1 -D_REENTRANT=1 -D_THREAD_SAFE=1 -DTCL_THREADS=1 -DMODULE_SCOPE=extern\ __attribute__\(\(__visibility__\(\"hidden\"\)\)\) -D_LARGEFILE64_SOURCE=1 -DTCL_WIDE_INT_IS_LONG=1 -DUSE_TCL_STUBS=1 -DUSE_TK_STUBS=1 -DAUTOSTEREOD=\"\"") include_directories(BEFORE "${TCL_INCLUDE_PATH}/tcl-private/generic" "${TCL_INCLUDE_PATH}/tcl-private/unix") - include_directories(BEFORE "${TCL_INCLUDE_PATH}/tk-private/generic" "${TCL_INCLUDE_PATH}/tk-private/unix") + include_directories(BEFORE "${TK_INCLUDE_PATH}/tk-private/generic" "${TK_INCLUDE_PATH}/tk-private/unix" "${TK_INCLUDE_PATH}/tk-private") include_directories(BEFORE "${TCL_INCLUDE_PATH}/tk-private/generic/ttk") include_directories(BEFORE "${TK_INCLUDE_PATH}/../PrivateHeaders") include_directories(BEFORE "${TCL_INCLUDE_PATH}") @@ -23,5 +24,5 @@ else(WIN32) target_link_libraries(togl -ldl) endif(WIN32) -target_link_libraries(togl ${OPENGL_LIBRARIES} ${TK_LIBRARY} ${TCL_LIBRARY} ) +target_link_libraries(togl ${OPENGL_LIBRARIES}) set_target_properties(togl PROPERTIES POSITION_INDEPENDENT_CODE ON ) diff --git a/ng/Togl2.1/togl.c b/ng/Togl2.1/togl.c index 1a3ed598..67f13392 100644 --- a/ng/Togl2.1/togl.c +++ b/ng/Togl2.1/togl.c @@ -165,11 +165,12 @@ # endif #endif /* TOGL_AGL */ -#if defined(TOGL_NSOPENGL) -# if TK_MAJOR_VERSION < 8 || (TK_MAJOR_VERSION == 8 && TK_MINOR_VERSION < 6) -# error Sorry Mac Cocoa version requires Tcl/Tk ver 8.6.0 or higher. -# endif -#endif /* TOGL_NSOPENGL */ +// Seems to work with Apple Tcl 8.5 too.... +// #if defined(TOGL_NSOPENGL) +// # if TK_MAJOR_VERSION < 8 || (TK_MAJOR_VERSION == 8 && TK_MINOR_VERSION < 6) +// # error Sorry Mac Cocoa version requires Tcl/Tk ver 8.6.0 or higher. +// # endif +// #endif /* TOGL_NSOPENGL */ #if defined(TOGL_WGL) && defined(_MSC_VER) # define snprintf _snprintf diff --git a/ng/gui.cpp b/ng/gui.cpp index ab7bcfab..680a3417 100644 --- a/ng/gui.cpp +++ b/ng/gui.cpp @@ -2,221 +2,40 @@ #include #include -#include "../libsrc/interface/writeuser.hpp" -#include +#ifdef WIN32 + #define DLL_HEADER_IMPORT __declspec(dllimport) + #define DLL_HEADER_EXPORT __declspec(dllexport) +#else + #define DLL_HEADER_IMPORT + #define DLL_HEADER_EXPORT +#endif + namespace netgen { - DLL_HEADER extern Flags parameters; - DLL_HEADER extern bool netgen_executable_started; - DLL_HEADER extern int printmessage_importance; + DLL_HEADER_EXPORT Flags parameters; } -using netgen::parameters; -using netgen::ngdir; -using netgen::verbose; -using netgen::Array; -using netgen::RegisterUserFormats; - -extern "C" int Ng_ServerSocketManagerInit (int port); -extern "C" int Ng_ServerSocketManagerRun (void); - -int Tcl_AppInit(Tcl_Interp * interp); - -extern bool nodisplay; -extern bool shellmode; - -void main_gui() -{ - if(netgen::netgen_executable_started) - return; - - if ( netgen::id == 0 ) - { - cout << "NETGEN-" << PACKAGE_VERSION << endl; - - cout << "Developed by Joachim Schoeberl at" << endl - << "2010-xxxx Vienna University of Technology" << endl - << "2006-2010 RWTH Aachen University" << endl - << "1996-2006 Johannes Kepler University Linz" << endl; - -#ifdef OCCGEOMETRY - cout << "Including OpenCascade geometry kernel" << endl; -#endif - -#ifdef ACIS - cout << "Including ACIS geometry kernel" << endl; -#endif - -#ifdef DEBUG - cout << "You are running the debug version !" << endl; -#endif - - - } - -// netgen::h_argc = argc; -// netgen::h_argv = argv; - - if (getenv ("NETGENDIR") && strlen (getenv ("NETGENDIR"))) - ngdir = getenv ("NETGENDIR"); - else - ngdir = "."; - - verbose = parameters.GetDefineFlag ("V"); - - if (verbose) - cout << "NETGENDIR = " << ngdir << endl; - - - if ( netgen::id == 0 ) - { - if (parameters.StringFlagDefined ("testout")) - netgen::testout = new ofstream (parameters.GetStringFlag ("testout", "test.out")); - - - if(parameters.GetDefineFlag("batchmode")) - nodisplay = true; - - - if(parameters.GetDefineFlag("shellmode")) - { - nodisplay = true; - shellmode = true; - } - - Tcl_FindExecutable(NULL); - - // initialize application - Tcl_Interp * myinterp = Tcl_CreateInterp (); - if (Tcl_AppInit (myinterp) == TCL_ERROR) - { - cerr << "Exit Netgen due to initialization problem" << endl; - exit (1); - } - - - - // parse tcl-script - int errcode; - - bool internaltcl = false; - if (shellmode) - internaltcl = false; - - if (verbose) - { - cout << "Tcl header version = " << TCL_PATCH_LEVEL << endl; - Tcl_Eval (myinterp, "puts \"Tcl runtime version = [info patchlevel] \";"); - } - - if (parameters.GetDefineFlag ("internaltcl")) - internaltcl=true; - if (parameters.GetDefineFlag ("externaltcl")) - internaltcl=false; - - - - if (internaltcl) - { - if (verbose) - cout << "using internal Tcl-script" << endl; - - // connect to one string - extern const char * ngscript[]; - const char ** hcp = ngscript; - int len = 0; - while (*hcp) - len += strlen (*hcp++); - - char * tr1 = new char[len+1]; - *tr1 = 0; - hcp = ngscript; - - char * tt1 = tr1; - while (*hcp) - { - strcat (tt1, *hcp); - tt1 += strlen (*hcp++); - } - - errcode = Tcl_Eval (myinterp, tr1); - delete [] tr1; - } - - else - - { - string startfile = ngdir + "/ng.tcl"; - - if (verbose) - cout << "Load Tcl-script from " << startfile << endl; - - errcode = Tcl_EvalFile (myinterp, (char*)startfile.c_str()); - } - - if (errcode) - { - cout << "Error in Tcl-Script:" << endl; - // cout << "result = " << myinterp->result << endl; - cout << "result = " << Tcl_GetStringResult (myinterp) << endl; - // cout << "in line " << myinterp->errorLine << endl; - - cout << "\nMake sure to set environment variable NETGENDIR to directory containing ng.tcl" << endl; - exit (1); - } - - - // lookup user file formats and insert into format list: - Array userformats; - Array extensions; - RegisterUserFormats (userformats, extensions); - - ostringstream fstr; - - tcl_const char * exportft = Tcl_GetVar (myinterp, "exportfiletype", 0); - for (int i = 1; i <= userformats.Size(); i++) - { - fstr << ".ngmenu.file.filetype add radio -label \"" - << userformats.Get(i) << "\" -variable exportfiletype\n"; - fstr << "lappend meshexportformats { {" << userformats.Get(i) << "} {" << extensions.Get(i) << "} }\n"; - } - - Tcl_Eval (myinterp, (char*)fstr.str().c_str()); - Tcl_SetVar (myinterp, "exportfiletype", exportft, 0); - - - // start event-loop - Tk_MainLoop(); - Tcl_DeleteInterp (myinterp); -// Tcl_Exit(0); - } -} - - +DLL_HEADER_EXPORT bool nodisplay = false; extern "C" int Ng_Init (Tcl_Interp * interp); extern "C" int Ng_Vis_Init (Tcl_Interp * interp); - extern "C" void Ng_TclCmd(string); -struct GuiThread { - std::thread t; - ~GuiThread() { - Ng_TclCmd(".ngmenu.file invoke \"Quit\";"); - if(netgen::printmessage_importance>2) - cout << "waiting for GUI to finish..." << endl; - t.join(); - } -}; +// tcl package dynamic load +extern "C" int DLL_HEADER_EXPORT Gui_Init (Tcl_Interp * interp) +{ + if (Ng_Init(interp) == TCL_ERROR) { + cerr << "Problem in Ng_Init: " << endl; + cout << "result = " << Tcl_GetStringResult (interp) << endl; + return TCL_ERROR; + } + + if (!nodisplay && Ng_Vis_Init(interp) == TCL_ERROR) { + cerr << "Problem in Ng_Vis_Init: " << endl; + cout << "result = " << Tcl_GetStringResult (interp) << endl; + return TCL_ERROR; + } -static GuiThread gui_thread; - -PYBIND11_PLUGIN(gui) { - pybind11::module m("gui", "pybind gui"); - gui_thread.t = std::thread([]() - { - main_gui(); - }); - return m.ptr(); + return TCL_OK; } diff --git a/ng/ng.tcl b/ng/ng.tcl index 21f11195..18a870db 100644 --- a/ng/ng.tcl +++ b/ng/ng.tcl @@ -1,4 +1,7 @@ catch {lappend auto_path $env(NETGENDIR) } +catch {lappend auto_path $env(NETGENDIR)/../lib } + +load libgui[info sharedlibextension] gui set batchmode [Ng_GetCommandLineParameter batchmode] if {$batchmode=="undefined"} { diff --git a/ng/ngappinit.cpp b/ng/ngappinit.cpp index 69623bc4..21589aaf 100644 --- a/ng/ngappinit.cpp +++ b/ng/ngappinit.cpp @@ -7,17 +7,6 @@ #include #include -#ifdef NGPYTHON -#include -#endif - -/* -namespace netgen -{ - int id = 0, ntasks = 1; -} -*/ - #ifdef PARALLEL #include @@ -33,10 +22,11 @@ namespace netgen namespace netgen { - Flags parameters; + DLL_HEADER extern Flags parameters; DLL_HEADER extern bool netgen_executable_started; } +DLL_HEADER extern bool nodisplay; using netgen::parameters; @@ -59,7 +49,6 @@ using netgen::RegisterUserFormats; extern "C" int Ng_ServerSocketManagerInit (int port); extern "C" int Ng_ServerSocketManagerRun (void); -bool nodisplay = false; bool shellmode = false; @@ -350,26 +339,6 @@ int Tcl_AppInit(Tcl_Interp * interp) // return TCL_ERROR; } - - if (Ng_Init(interp) == TCL_ERROR) { - cerr << "Problem in Ng_Init: " << endl; - cout << "result = " << Tcl_GetStringResult (interp) << endl; - // cerr << interp->result << endl; - // return TCL_ERROR; - } - - if (!nodisplay && Ng_Vis_Init(interp) == TCL_ERROR) { - cerr << "Problem in Ng_Vis_Init: " << endl; - cout << "result = " << Tcl_GetStringResult (interp) << endl; - // cerr << interp->result << endl; - // return TCL_ERROR; - } - - - - - - #ifdef TRAFO // extern int Trafo_Init (Tcl_Interp * interp); // if (Trafo_Init(interp) == TCL_ERROR) @@ -429,21 +398,3 @@ int Tcl_AppInit(Tcl_Interp * interp) return TCL_OK; } - - - - -// link MKL with netgen -// necessary for MKL 11.x, since MKL complains if started -// from the ngsolve shared library - -#ifdef LINKMKL -extern "C" double ddot_(int *n, double *dx, int *incx, double *dy, - int *incy); -void mkldummy() -{ - int n = 1, one = 1; - double a = 1, b = 1; - ddot_(&n, &a, &one, &b, &one); -} -#endif diff --git a/nglib/CMakeLists.txt b/nglib/CMakeLists.txt index eb18a638..e56feec0 100644 --- a/nglib/CMakeLists.txt +++ b/nglib/CMakeLists.txt @@ -28,7 +28,7 @@ if(NOT WIN32) endif(USE_GUI) endif(NOT WIN32) -target_link_libraries( nglib ${OCC_LIBRARIES} ${MPI_CXX_LIBRARIES} ${OPENGL_LIBRARIES} ${TK_LIBRARY} ${TCL_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} ${X11_Xmu_LIB} ${JPEG_LIBRARIES} ${MKL_LIBRARIES} ${ZLIB_LIBRARIES} ${OCC_LIBRARIES} ) +target_link_libraries( nglib ${OCC_LIBRARIES} ${MPI_CXX_LIBRARIES} ${OPENGL_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${X11_Xmu_LIB} ${JPEG_LIBRARIES} ${MKL_LIBRARIES} ${ZLIB_LIBRARIES} ${OCC_LIBRARIES} ) if(USE_OCC AND NOT WIN32) target_link_libraries(nglib occ) diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index da3db3aa..d35278f3 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -1,4 +1,4 @@ -install(FILES __init__.py meshing.py csg.py geom2d.py stl.py +install(FILES __init__.py meshing.py csg.py geom2d.py stl.py gui.py DESTINATION ${PYTHON_PACKAGES_INSTALL_DIR}/netgen COMPONENT netgen ) diff --git a/python/__init__.py b/python/__init__.py index 1c1346cf..ca1e91bd 100644 --- a/python/__init__.py +++ b/python/__init__.py @@ -3,11 +3,17 @@ from sys import path from sys import platform as __platform if __platform.startswith('linux'): - path.append(os.path.dirname(__file__) + '/../../..') + _netgen_bin_dir=os.path.realpath(os.path.join(os.path.dirname(__file__),'../../../../bin')) + _netgen_lib_dir=os.path.realpath(os.path.join(os.path.dirname(__file__),'../../../../lib')) if __platform.startswith('win'): - path.append(os.path.dirname(__file__) + '/../../../bin') + _netgen_bin_dir=os.path.realpath(os.path.join(os.path.dirname(__file__) + '/../../../bin')) + _netgen_lib_dir=_netgen_bin_dir if __platform.startswith('darwin'): - path.append(os.path.dirname(__file__) + '/../../../../../MacOS') + _netgen_bin_dir=os.path.realpath(os.path.join(os.path.dirname(__file__) + '/../../../../../MacOS')) + _netgen_lib_dir=_netgen_bin_dir + +path.append(_netgen_lib_dir) +path.append(_netgen_bin_dir) import libngpy del path diff --git a/python/gui.py b/python/gui.py new file mode 100644 index 00000000..dad53584 --- /dev/null +++ b/python/gui.py @@ -0,0 +1,11 @@ +from tkinter import Tk + +from . import _netgen_lib_dir +from . import _netgen_bin_dir + +win = Tk() +import os +dir_path = os.path.dirname(os.path.realpath(__file__)) +win.tk.eval("source "+os.path.realpath(os.path.join(_netgen_bin_dir, 'ng.tcl')).replace('\\','/')) + +# %gui tk From b87e76306f91f4faa1e1eac2174770896311d6ff Mon Sep 17 00:00:00 2001 From: Christopher Lackner Date: Thu, 11 May 2017 10:25:29 +0200 Subject: [PATCH 35/63] use std::move in delete element of array --- libsrc/general/array.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libsrc/general/array.hpp b/libsrc/general/array.hpp index d6126e4b..d288b7d1 100644 --- a/libsrc/general/array.hpp +++ b/libsrc/general/array.hpp @@ -329,7 +329,7 @@ namespace netgen RangeCheck (i+1); #endif - data[i] = data[size-1]; + data[i] = std::move(data[size-1]); size--; // DeleteElement (i+1); } @@ -342,7 +342,7 @@ namespace netgen RangeCheck (i); #endif - data[i-1] = data[size-1]; + data[i-1] = std::move(data[size-1]); size--; } From 3eef3a66bcc8039d822820955b140f8e14c26832 Mon Sep 17 00:00:00 2001 From: Matthias Hochsteger Date: Thu, 11 May 2017 11:21:55 +0200 Subject: [PATCH 36/63] link TCL to gui library --- ng/CMakeLists.txt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/ng/CMakeLists.txt b/ng/CMakeLists.txt index 6749dd2f..1a553edc 100644 --- a/ng/CMakeLists.txt +++ b/ng/CMakeLists.txt @@ -16,13 +16,14 @@ if(USE_GUI) set_directory_properties(PROPERTIES RULE_LAUNCH_COMPILE "") endif(WIN32) - add_executable(netgen ${netgen_sources}) add_library(gui SHARED ${gui_sources}) + add_executable(netgen ${netgen_sources}) - target_link_libraries( netgen nglib gui ${ZLIB_LIBRARIES} ${TK_LIBRARY} ${TCL_LIBRARY} ${JPEG_LIBRARIES} ${FFMPEG_LIBRARIES} ${X11_X11_LIB} ${OCC_LIBRARIES}) - target_link_libraries( gui PUBLIC nglib ${ZLIB_LIBRARIES} ${JPEG_LIBRARIES} ${FFMPEG_LIBRARIES} ${X11_X11_LIB} ${OCC_LIBRARIES} ) + target_link_libraries( gui PUBLIC nglib ${TK_LIBRARY} ${TCL_LIBRARY} ${ZLIB_LIBRARIES} ${JPEG_LIBRARIES} ${FFMPEG_LIBRARIES} ${X11_X11_LIB} ${OCC_LIBRARIES} ) target_link_libraries( gui PRIVATE ${LIBTOGL}) + target_link_libraries( netgen nglib gui ) + if(NOT WIN32) target_link_libraries( netgen mesh stlvis stl geom2dvis interface geom2d csg stl visual csgvis ) target_link_libraries( gui PUBLIC mesh stlvis stl geom2dvis interface geom2d csg stl visual csgvis ) From 4a331a8a382bc0f626d3fc487dc1f9d1598cc003 Mon Sep 17 00:00:00 2001 From: Matthias Hochsteger Date: Thu, 11 May 2017 11:49:58 +0200 Subject: [PATCH 37/63] Stop TCL timer when GUI quits --- ng/menustat.tcl | 1 + 1 file changed, 1 insertion(+) diff --git a/ng/menustat.tcl b/ng/menustat.tcl index 610d6a6b..38fd589a 100644 --- a/ng/menustat.tcl +++ b/ng/menustat.tcl @@ -421,6 +421,7 @@ set videoactive 0 # puts "error: $result" } + after cancel { timer2 } Ng_Exit; destroy . } From e1d7cd879d0630379a44a281332692c382d4f85c Mon Sep 17 00:00:00 2001 From: Matthias Hochsteger Date: Fri, 12 May 2017 13:10:10 +0200 Subject: [PATCH 38/63] Don't link TCL/TK to gui lib on MacOS In case there are multiple versions of tcl/tk available on MacOS, the system complains about it if we link against one version and python/tkinter links against another. Thus don't link with any tcl at all in the gui library. This means the library will use the version loaded by tkinter. --- ng/CMakeLists.txt | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/ng/CMakeLists.txt b/ng/CMakeLists.txt index 1a553edc..9fca6c27 100644 --- a/ng/CMakeLists.txt +++ b/ng/CMakeLists.txt @@ -19,11 +19,20 @@ if(USE_GUI) add_library(gui SHARED ${gui_sources}) add_executable(netgen ${netgen_sources}) - target_link_libraries( gui PUBLIC nglib ${TK_LIBRARY} ${TCL_LIBRARY} ${ZLIB_LIBRARIES} ${JPEG_LIBRARIES} ${FFMPEG_LIBRARIES} ${X11_X11_LIB} ${OCC_LIBRARIES} ) + target_link_libraries( gui PUBLIC nglib ${ZLIB_LIBRARIES} ${JPEG_LIBRARIES} ${FFMPEG_LIBRARIES} ${X11_X11_LIB} ${OCC_LIBRARIES} ) target_link_libraries( gui PRIVATE ${LIBTOGL}) target_link_libraries( netgen nglib gui ) + if(APPLE) + # Leave decision about which tcl/tk version to use open to python (and it's tkinter package). + # Thus, only link tcl/tk to the netgen executable and not to the gui library. + target_link_libraries( netgen ${TK_LIBRARY} ${TCL_LIBRARY}) + else(APPLE) + # On other systems assume that the found libraries are compatible with python/tkinter + target_link_libraries( gui PUBLIC ${TK_LIBRARY} ${TCL_LIBRARY}) + endif(APPLE) + if(NOT WIN32) target_link_libraries( netgen mesh stlvis stl geom2dvis interface geom2d csg stl visual csgvis ) target_link_libraries( gui PUBLIC mesh stlvis stl geom2dvis interface geom2d csg stl visual csgvis ) From c53913b4d1a6ea68eaccc62c6f328b22d0b161eb Mon Sep 17 00:00:00 2001 From: Matthias Hochsteger Date: Fri, 12 May 2017 13:17:19 +0200 Subject: [PATCH 39/63] Remove unused code in CMake files --- CMakeLists.txt | 5 ----- libsrc/interface/CMakeLists.txt | 8 -------- libsrc/visualization/CMakeLists.txt | 2 -- nglib/CMakeLists.txt | 12 ------------ windows/CMakeLists.txt | 3 --- 5 files changed, 30 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e5a99d3c..63a74bc1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,7 +37,6 @@ string(TIMESTAMP NETGEN_VERSION_PATCH "%y%U%w" ) set(NETGEN_VERSION "${NETGEN_VERSION_MAJOR}.${NETGEN_VERSION_MINOR}-dev") set(PACKAGE_VERSION "${NETGEN_VERSION_MAJOR}.${NETGEN_VERSION_MINOR}-${NETGEN_VERSION_PATCH}") set(CPACK_PACKAGE_VERSION "${PACKAGE_VERSION}") -# set(CPACK_DEBIAN_PACKAGE_VERSION "${PACKAGE_VERSION}" ####################################################################### @@ -133,8 +132,6 @@ if(WIN32) get_WIN32_WINNT(ver) add_definitions(-D_WIN32_WINNT=${ver} -DWNT -DWNT_WINDOW -DNOMINMAX) set(CMAKE_MFC_FLAG 0) -# add_definitions(-DNGINTERFACE_EXPORTS) -# add_definitions(-DNGLIB_EXPORTS) add_definitions(-DMSVC_EXPRESS -D_CRT_SECURE_NO_WARNINGS -DHAVE_STRUCT_TIMESPEC) # build convenience (aka object) libraries in windows) set(NG_LIB_TYPE OBJECT) @@ -145,9 +142,7 @@ else(WIN32) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14") endif(WIN32) if(APPLE) -# set(MACOSX_BUNDLE ON) set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -undefined dynamic_lookup") -# set(CMAKE_SHARED_LIBRARY_SUFFIX ".so") endif(APPLE) ####################################################################### diff --git a/libsrc/interface/CMakeLists.txt b/libsrc/interface/CMakeLists.txt index aca57060..29213966 100644 --- a/libsrc/interface/CMakeLists.txt +++ b/libsrc/interface/CMakeLists.txt @@ -1,11 +1,5 @@ add_definitions(-DNGINTERFACE_EXPORTS) add_library(interface ${NG_LIB_TYPE} -# $ -# $ -# $ -# $ -# $ -# $ nginterface.cpp nginterface_v2.cpp read_fnf_mesh.cpp readtetmesh.cpp readuser.cpp writeabaqus.cpp writediffpack.cpp writedolfin.cpp writeelmer.cpp writefeap.cpp writefluent.cpp writegmsh.cpp writejcm.cpp @@ -13,8 +7,6 @@ add_library(interface ${NG_LIB_TYPE} wuchemnitz.cpp writegmsh2.cpp writeOpenFOAM15x.cpp ) -# TARGET_LINK_LIBRARIES(interface ${MPI_CXX_LIBRARIES} ${PYTHON_LIBS}) -# TARGET_LINK_LIBRARIES( interface ${LIBPTHREAD} ${OCC_LIBRARIES} ${LIBTOGL} ${MPI_CXX_LIBRARIES} ${OPENGL_LIBRARIES} ${TK_LIBRARY} ${TCL_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} ${X11_Xmu_LIB} ${JPEG_LIBRARIES} ${MKL_LIBRARIES} ${ZLIB_LIBRARIES} ) if(NOT WIN32) target_link_libraries(interface mesh csg geom2d) if(USE_GUI) diff --git a/libsrc/visualization/CMakeLists.txt b/libsrc/visualization/CMakeLists.txt index ceedbc7b..273829a6 100644 --- a/libsrc/visualization/CMakeLists.txt +++ b/libsrc/visualization/CMakeLists.txt @@ -1,8 +1,6 @@ add_definitions(-DNGINTERFACE_EXPORTS) install(FILES soldata.hpp DESTINATION ${INCDIR} COMPONENT netgen_devel ) -# AM_CPPFLAGS = $(MPI_INCLUDES) -I$(top_srcdir)/libsrc/include -DOPENGL -D$(TOGL_WINDOWINGSYSTEM) $(OCCFLAGS) $(TCL_INCLUDES) - if(USE_GUI) set( LIB_VISUAL_SOURCES meshdoc.cpp mvdraw.cpp vsfieldlines.cpp vsmesh.cpp vssolution.cpp importsolution.cpp ) else(USE_GUI) diff --git a/nglib/CMakeLists.txt b/nglib/CMakeLists.txt index e56feec0..a61556bc 100644 --- a/nglib/CMakeLists.txt +++ b/nglib/CMakeLists.txt @@ -38,16 +38,4 @@ if(USE_PYTHON) target_link_libraries(nglib ${PYTHON_LIBRARIES}) endif(USE_PYTHON) -# if(NOT WIN32) -# add_executable(ng_vol ng_vol.cpp ${nglib_objects}) -# target_link_libraries( ng_vol nglib ${OCC_LIBRARIES} ${MPI_CXX_LIBRARIES} ) -# target_link_libraries( ng_vol nglib interface geom2d csg stl occ mesh ) -# -# add_executable(ng_stl ng_stl.cpp ${nglib_objects}) -# target_link_libraries( ng_stl nglib ${OCC_LIBRARIES} ${OCC_OCAF_LIBRARIES} ${MPI_CXX_LIBRARIES} ) -# target_link_libraries( ng_stl nglib interface geom2d csg stl occ mesh ) -# -# install(TARGETS nglib ng_vol ng_stl ${ng_install_dir}) -# endif(NOT WIN32) - install(TARGETS nglib ${ng_install_dir}) diff --git a/windows/CMakeLists.txt b/windows/CMakeLists.txt index 78b81fba..e69de29b 100644 --- a/windows/CMakeLists.txt +++ b/windows/CMakeLists.txt @@ -1,3 +0,0 @@ -# dist_noinst_DATA = netgen.sln netgen.vcproj \ -# postBuild_netgen.bat nglib.sln nglib.vcproj \ -# postBuild_nglib.bat netgen.ico netgen.rc From ca8df788c8ff233546757479a6de3f8ce52107a9 Mon Sep 17 00:00:00 2001 From: Matthias Hochsteger Date: Fri, 12 May 2017 13:19:05 +0200 Subject: [PATCH 40/63] Install nglib.h --- nglib/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/nglib/CMakeLists.txt b/nglib/CMakeLists.txt index a61556bc..4a1faee0 100644 --- a/nglib/CMakeLists.txt +++ b/nglib/CMakeLists.txt @@ -39,3 +39,4 @@ if(USE_PYTHON) endif(USE_PYTHON) install(TARGETS nglib ${ng_install_dir}) +install(FILES nglib.h DESTINATION ${INCDIR}/include COMPONENT netgen_devel) From b4f3107fef875e1a58c011cf408985b3af9f4ee9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20Sch=C3=B6berl?= Date: Sat, 13 May 2017 10:24:12 +0200 Subject: [PATCH 41/63] default material name --- libsrc/meshing/meshclass.cpp | 6 +++--- libsrc/meshing/meshclass.hpp | 5 ++++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/libsrc/meshing/meshclass.cpp b/libsrc/meshing/meshclass.cpp index 81d7ead7..356192fc 100644 --- a/libsrc/meshing/meshclass.cpp +++ b/libsrc/meshing/meshclass.cpp @@ -5758,8 +5758,8 @@ namespace netgen { int olds = materials.Size(); materials.SetSize (domnr); - for (int i = olds; i < domnr; i++) - materials[i] = 0; + for (int i = olds; i < domnr-1; i++) + materials[i] = new string("default"); } /* materials.Elem(domnr) = new char[strlen(mat)+1]; @@ -5772,7 +5772,7 @@ namespace netgen { if (domnr <= materials.Size()) return *materials.Get(domnr); - static string emptystring; + static string emptystring("default"); return emptystring; } diff --git a/libsrc/meshing/meshclass.hpp b/libsrc/meshing/meshclass.hpp index 6ec7627a..40d8ebb4 100644 --- a/libsrc/meshing/meshclass.hpp +++ b/libsrc/meshing/meshclass.hpp @@ -594,7 +594,10 @@ namespace netgen /// const string & GetMaterial (int domnr) const; const string * GetMaterialPtr (int domnr) const // 1-based - { return domnr <= materials.Size() ? materials.Get(domnr) : nullptr; } + { + static string defaultmat = "default"; + return domnr <= materials.Size() ? materials.Get(domnr) : &defaultmat; + } DLL_HEADER void SetNBCNames ( int nbcn ); From 9a7307fb396d200d1a99f75e90d0c1a35816437c Mon Sep 17 00:00:00 2001 From: Matthias Hochsteger Date: Mon, 15 May 2017 18:56:47 +0200 Subject: [PATCH 42/63] Start GUI from Python only if Netgen exe is not running --- libsrc/meshing/python_mesh.cpp | 3 +++ python/gui.py | 21 +++++++++++++-------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/libsrc/meshing/python_mesh.cpp b/libsrc/meshing/python_mesh.cpp index d80fcdb7..04d00d10 100644 --- a/libsrc/meshing/python_mesh.cpp +++ b/libsrc/meshing/python_mesh.cpp @@ -13,6 +13,7 @@ using namespace netgen; namespace netgen { + extern bool netgen_executable_started; extern shared_ptr ng_geometry; } @@ -49,6 +50,8 @@ static Transformation<3> global_trafo(Vec<3> (0,0,0)); DLL_HEADER void ExportNetgenMeshing(py::module &m) { + m.attr("_netgen_executable_started") = py::cast(netgen::netgen_executable_started); + py::class_(m, "NGDummyArgument") .def("__bool__", []( NGDummyArgument &self ) { return false; } ) ; diff --git a/python/gui.py b/python/gui.py index dad53584..bf29a41e 100644 --- a/python/gui.py +++ b/python/gui.py @@ -1,11 +1,16 @@ -from tkinter import Tk +import netgen -from . import _netgen_lib_dir -from . import _netgen_bin_dir +def StartGUI(): + import os + from tkinter import Tk -win = Tk() -import os -dir_path = os.path.dirname(os.path.realpath(__file__)) -win.tk.eval("source "+os.path.realpath(os.path.join(_netgen_bin_dir, 'ng.tcl')).replace('\\','/')) + from . import _netgen_lib_dir + from . import _netgen_bin_dir -# %gui tk + global win + win = Tk() + dir_path = os.path.dirname(os.path.realpath(__file__)) + win.tk.eval("source "+os.path.realpath(os.path.join(_netgen_bin_dir, 'ng.tcl')).replace('\\','/')) + +if not netgen.libngpy._meshing._netgen_executable_started: + StartGUI() From 3ba7d2c276c3ef3bf408d3cf998be45a5c05606f Mon Sep 17 00:00:00 2001 From: Christopher Lackner Date: Wed, 17 May 2017 16:04:56 +0200 Subject: [PATCH 43/63] add meshsizefilename to python meshingparameters --- libsrc/meshing/python_mesh.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libsrc/meshing/python_mesh.cpp b/libsrc/meshing/python_mesh.cpp index 04d00d10..b4c3f8d3 100644 --- a/libsrc/meshing/python_mesh.cpp +++ b/libsrc/meshing/python_mesh.cpp @@ -687,7 +687,7 @@ DLL_HEADER void ExportNetgenMeshing(py::module &m) .def(py::init<>()) .def("__init__", [](MP *instance, double maxh, bool quad_dominated, int optsteps2d, int optsteps3d, - MESHING_STEP perfstepsend, int only3D_domain) + MESHING_STEP perfstepsend, int only3D_domain, const string & meshsizefilename) { new (instance) MeshingParameters; instance->maxh = maxh; @@ -696,6 +696,7 @@ DLL_HEADER void ExportNetgenMeshing(py::module &m) instance->optsteps3d = optsteps3d; instance->only3D_domain_nr = only3D_domain; instance->perfstepsend = perfstepsend; + instance->meshsizefilename = meshsizefilename; }, py::arg("maxh")=1000, py::arg("quad_dominated")=false, @@ -703,6 +704,7 @@ DLL_HEADER void ExportNetgenMeshing(py::module &m) py::arg("optsteps3d") = 3, py::arg("perfstepsend") = MESHCONST_OPTVOLUME, py::arg("only3D_domain") = 0, + py::arg("meshsizefilename") = "", "create meshing parameters" ) .def("__str__", &ToString) From 030ad1d7323e1efbcd7d85a6cabefe66479406aa Mon Sep 17 00:00:00 2001 From: Matthias Hochsteger Date: Mon, 22 May 2017 17:24:17 +0200 Subject: [PATCH 44/63] Update screenshot code for Togl 2 --- ng/menustat.tcl | 2 +- ng/ngpkg.cpp | 146 +++++++++++++++++++----------------------------- ng/onetcl.cpp | 29 +++++----- 3 files changed, 75 insertions(+), 102 deletions(-) diff --git a/ng/menustat.tcl b/ng/menustat.tcl index 38fd589a..1ae6a022 100644 --- a/ng/menustat.tcl +++ b/ng/menustat.tcl @@ -352,7 +352,7 @@ proc demoredraw { } { set file [tk_getSaveFile -filetypes $types] # -defaultextension ".ppm"] if {$file != ""} { - .ndraw Ng_SnapShot $file } + Ng_SnapShot .ndraw $file } } diff --git a/ng/ngpkg.cpp b/ng/ngpkg.cpp index 76e2b1c9..dcece2fa 100644 --- a/ng/ngpkg.cpp +++ b/ng/ngpkg.cpp @@ -1994,91 +1994,26 @@ namespace netgen } -#if TOGL_MAJOR_VERSION==1 - -#ifndef JPEGLIB - static int Ng_SnapShot (struct Togl * togl, - int argc, tcl_const char *argv[]) + static int Ng_SnapShot(ClientData clientData, Tcl_Interp *interp, int argc, Tcl_Obj *const *argv) { - const char * filename = argv[2]; + struct Togl *togl; + if (Togl_GetToglFromObj(interp, argv[1], &togl) != TCL_OK) + return TCL_ERROR; + const char * filename = Tcl_GetString(argv[2]); - char str[250]; - char filename2[250]; int len = strlen(filename); - strcpy (filename2, filename); - - filename2[len-3] = 'p'; - filename2[len-2] = 'p'; - filename2[len-1] = 'm'; - filename2[len] = 0; - - cout << "Snapshot to file '" << filename << endl; int w = Togl_Width (togl); - w = int((w + 1) / 4) * 4 + 4; int h = Togl_Height (togl); - // unsigned char * buffer = new unsigned char[w*h*4]; - unsigned char * buffer = new unsigned char[w*h*3]; - glReadPixels (0, 0, w, h, GL_RGB, GL_UNSIGNED_BYTE, buffer); - - ofstream outfile(filename2); - outfile << "P6" << endl - << "# CREATOR: Netgen" << endl - << w << " " << h << endl - << "255" << endl; - for (int i = 0; i < h; i++) - for (int j = 0; j < w; j++) - for (int k = 0; k < 3; k++) - outfile.put (buffer[k+3*j+3*w*(h-i-1)]); - outfile << flush; - - delete[] buffer; - - // convert image file (Unix/Linux only): - sprintf(str,"convert -quality 100 %s %s", filename2, filename); - - int err = system(str); - if (err != 0) - { - Tcl_SetResult (Togl_Interp(togl), (char*)"Cannot convert image file", TCL_VOLATILE); - return TCL_ERROR; - } - sprintf(str,"rm %s", filename2); - - err = system(str); - if (err != 0) - { - Tcl_SetResult (Togl_Interp(togl), (char*)"Cannot delete temporary file", TCL_VOLATILE); - return TCL_ERROR; - } - - return TCL_OK; - } - - - -#else - - - static int Ng_SnapShot (struct Togl * togl, - int argc, tcl_const char *argv[]) - { - const char * filename = argv[2]; - int len = strlen(filename); + Array buffer(w*h*3); + glReadPixels (0, 0, w, h, GL_RGB, GL_UNSIGNED_BYTE, &buffer[0]); +#ifdef JPEGLIB if (strcmp ("jpg", filename+len-3) == 0) { cout << "Snapshot to file '" << filename << "'" << endl; - int w = Togl_Width (togl); - // w = int((w + 1) / 4) * 4 + 4; - int h = Togl_Height (togl); - - // unsigned char * buffer = new unsigned char[w*h*4]; - unsigned char * buffer = new unsigned char[w*h*3]; - glReadPixels (0, 0, w, h, GL_RGB, GL_UNSIGNED_BYTE, buffer); - struct jpeg_compress_struct cinfo; struct jpeg_error_mgr jerr; FILE *outfile = fopen(filename,"wb"); @@ -2112,10 +2047,57 @@ namespace netgen fprintf( stdout, "done [ok]\n" ); fflush( stdout ); - free( buffer ); return TCL_OK; } - else +#endif // JPEGLIB + { + char str[250]; + char filename2[250]; + int len = strlen(filename); + strcpy (filename2, filename); + + filename2[len-3] = 'p'; + filename2[len-2] = 'p'; + filename2[len-1] = 'm'; + filename2[len] = 0; + + cout << "Snapshot to file '" << filename << endl; + + int w = Togl_Width (togl); + w = int((w + 1) / 4) * 4 + 4; + int h = Togl_Height (togl); + + ofstream outfile(filename2); + outfile << "P6" << endl + << "# CREATOR: Netgen" << endl + << w << " " << h << endl + << "255" << endl; + for (int i = 0; i < h; i++) + for (int j = 0; j < w; j++) + for (int k = 0; k < 3; k++) + outfile.put (buffer[k+3*j+3*w*(h-i-1)]); + outfile << flush; + + // convert image file (Unix/Linux only): + sprintf(str,"convert -quality 100 %s %s", filename2, filename); + + int err = system(str); + if (err != 0) + { + Tcl_SetResult (Togl_Interp(togl), (char*)"Cannot convert image file", TCL_VOLATILE); + return TCL_ERROR; + } + sprintf(str,"rm %s", filename2); + + err = system(str); + if (err != 0) + { + Tcl_SetResult (Togl_Interp(togl), (char*)"Cannot delete temporary file", TCL_VOLATILE); + return TCL_ERROR; + } + + } + { cout << "Snapshot to " << filename << " not supported" << endl; return TCL_ERROR; @@ -2123,18 +2105,6 @@ namespace netgen } -#endif - - -#else - -// TODO: JPEGLIB for Togl2 - - -#endif - - - #ifdef FFMPEG static int Ng_VideoClip(ClientData clientData, Tcl_Interp *interp, int argc, Tcl_Obj *const *argv) @@ -3083,7 +3053,7 @@ void PlayAnimFile(const char* name, int speed, int maxcnt) Tcl_CreateObjCommand(interp, "reshape", reshape, NULL, NULL); // Togl_TimerFunc( idle ); - // Togl_CreateCommand( (char*)"Ng_SnapShot", Ng_SnapShot); + Tcl_CreateObjCommand(interp, "Ng_SnapShot", Ng_SnapShot, NULL, NULL); Tcl_CreateObjCommand(interp, "Ng_VideoClip", Ng_VideoClip, NULL, NULL); } diff --git a/ng/onetcl.cpp b/ng/onetcl.cpp index cfb516a6..5a9df978 100644 --- a/ng/onetcl.cpp +++ b/ng/onetcl.cpp @@ -1,5 +1,7 @@ const char * ngscript[] = {"" ,"catch {lappend auto_path $env(NETGENDIR) }\n" +,"catch {lappend auto_path $env(NETGENDIR)/../lib }\n" +,"load libgui[info sharedlibextension] gui\n" ,"set batchmode [Ng_GetCommandLineParameter batchmode]\n" ,"if {$batchmode==\"undefined\"} {\n" ,"if {[catch {package require tkdnd } result ]} {\n" @@ -922,7 +924,7 @@ const char * ngscript[] = {"" ,"global videoactive\n" ,"if { $videoactive == 1 } {\n" ,"puts \"addframe\"\n" -,".ndraw Ng_VideoClip addframe\n" +,"Ng_VideoClip .ndraw addframe\n" ,"}\n" ,"if { $result == 0 && $stopdemo == 0 } {\n" ,"after 1 { demoredraw }\n" @@ -949,7 +951,7 @@ const char * ngscript[] = {"" ,"}\n" ,"set file [tk_getSaveFile -filetypes $types]\n" ,"if {$file != \"\"} {\n" -,".ndraw Ng_SnapShot $file }\n" +,"Ng_SnapShot .ndraw $file }\n" ,"}\n" ,".ngmenu.file add cascade -label \"Video clip\" -menu .ngmenu.file.video\n" ,"menu .ngmenu.file.video\n" @@ -961,13 +963,13 @@ const char * ngscript[] = {"" ,"}\n" ,"set file [tk_getSaveFile -filetypes $types]\n" ,"if {$file != \"\"} {\n" -,".ndraw Ng_VideoClip init $file\n" +,"Ng_VideoClip .ndraw init $file\n" ,"global videoactive\n" ,"set videoactive 1\n" ,"}\n" ,"}\n" ,".ngmenu.file.video add command -label \"add frame...\" \\\n" -,"-command {.ndraw Ng_VideoClip addframe }\n" +,"-command {Ng_VideoClip .ndraw addframe }\n" ,".ngmenu.file.video add command -label \"one cycle\" \\\n" ,"-command {\n" ,"set visoptions.redrawperiodic 1\n" @@ -975,13 +977,13 @@ const char * ngscript[] = {"" ,"puts \"j = $j\"\n" ,"Ng_Vis_Set time [expr (1000 * $j / 100)]\n" ,"redraw\n" -,".ndraw Ng_VideoClip addframe\n" +,"Ng_VideoClip .ndraw addframe\n" ,"after 200\n" ,"}\n" ,"}\n" ,".ngmenu.file.video add command -label \"finalize...\" \\\n" ,"-command {\n" -,".ndraw Ng_VideoClip finalize\n" +,"Ng_VideoClip .ndraw finalize\n" ,"global videoactive\n" ,"set videoactive 0\n" ,"}\n" @@ -993,6 +995,7 @@ const char * ngscript[] = {"" ,"puts \"Thank you for using $progname\";\n" ,"if { [catch { unload libngsolve[info sharedlibextension] ngsolve } result ] } {\n" ,"}\n" +,"after cancel { timer2 }\n" ,"Ng_Exit;\n" ,"destroy .\n" ,"}\n" @@ -1336,7 +1339,7 @@ const char * ngscript[] = {"" ,"global videoactive\n" ,"if { $videoactive == 1 } {\n" ,"puts \"addframe\"\n" -,".ndraw Ng_VideoClip addframe\n" +,"Ng_VideoClip .ndraw addframe\n" ,"}\n" ,"}\n" ,"if { $multithread_redraw == 2 } {\n" @@ -1345,7 +1348,7 @@ const char * ngscript[] = {"" ,"global videoactive\n" ,"if { $videoactive == 1 } {\n" ,"puts \"addframe\"\n" -,".ndraw Ng_VideoClip addframe\n" +,"Ng_VideoClip .ndraw addframe\n" ,"}\n" ,"after 1 { timer2 }\n" ,"return\n" @@ -2535,10 +2538,10 @@ const char * ngscript[] = {"" ,"wm deiconify $w\n" ,"} {\n" ,"toplevel $w\n" -,"frame $w.face -borderwidth 3\n" +,"ttk::frame $w.face -borderwidth 3\n" ,"pack $w.face -fill x\n" ,"ttk::label $w.face.lab -text \"face index:\"\n" -,"ttk::label $w.face.ent -text 1 -padx 4\n" +,"ttk::label $w.face.ent -text 1\n" ,"ttk::button $w.face.next -text \"next\" -command {\n" ,"set w .bcprop_dlg;\n" ,"set facenr [$w.face.ent cget -text]\n" @@ -2570,7 +2573,7 @@ const char * ngscript[] = {"" ,"redraw\n" ,"}\n" ,"pack $w.face.lab $w.face.ent $w.face.prev $w.face.next -side left\n" -,"frame $w.bc -borderwidth 3\n" +,"ttk::frame $w.bc -borderwidth 3\n" ,"pack $w.bc -fill x\n" ,"ttk::label $w.bc.lab -text \"bc property:\"\n" ,"entry $w.bc.ent -width 5 -relief sunken\n" @@ -2583,12 +2586,12 @@ const char * ngscript[] = {"" ,"Ng_BCProp setall [$w.bc.ent get];\n" ,"}\n" ,"pack $w.bc.lab $w.bc.ent $w.bc.but $w.bc.but2 -side left -expand yes\n" -,"frame $w.bcname -borderwidth 3\n" +,"ttk::frame $w.bcname -borderwidth 3\n" ,"pack $w.bcname -fill x\n" ,"ttk::label $w.bcname.lab -text \"bc name:\"\n" ,"ttk::label $w.bcname.ent -text \"-\"\n" ,"pack $w.bcname.lab $w.bcname.ent -side left -expand yes\n" -,"frame $w.bu\n" +,"ttk::frame $w.bu\n" ,"pack $w.bu -fill x -ipady 3\n" ,"ttk::button $w.bu.close -text \"Close\" -command { destroy .bcprop_dlg }\n" ,"pack $w.bu.close -expand yes -side left\n" From 6627b0b17f9789e8418ea5e1346705727a3afdf8 Mon Sep 17 00:00:00 2001 From: Matthias Hochsteger Date: Tue, 23 May 2017 20:49:36 +0200 Subject: [PATCH 45/63] Update Pybind11 --- external_dependencies/pybind11 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/external_dependencies/pybind11 b/external_dependencies/pybind11 index 07de0d86..fe0cf8b7 160000 --- a/external_dependencies/pybind11 +++ b/external_dependencies/pybind11 @@ -1 +1 @@ -Subproject commit 07de0d8627101be53986e841cd4e21ee38c2498a +Subproject commit fe0cf8b73b8e068c205e062c779eb694b194d6b4 From f6a0b31b96b68b73d52f5e1d369500b2b0025ef5 Mon Sep 17 00:00:00 2001 From: Matthias Hochsteger Date: Mon, 29 May 2017 21:19:34 +0200 Subject: [PATCH 46/63] Cleanup CMake build system - Use CMAKE_INSTALL_PREFIX instead of INSTALL_DIR - Allow finer control of install directories - Use compiled TCL code by default - Fix RPATH usage on Linux and MacOSX ### Allow finer control of install directories The following variables can be set to either absolute or relative paths NG_INSTALL_DIR_PYTHON: Python files NG_INSTALL_DIR_BIN: Executables NG_INSTALL_DIR_LIB: Libraries NG_INSTALL_DIR_INCLUDE: header files NG_INSTALL_DIR_CMAKE: CMake files NG_INSTALL_DIR_RES: Resources ### Use compiled TCL code by default The tcl files contained in Netgen are stored in onetcl.cpp as c-string. This way it's not necessary to install tcl files or set NETGENDIR ### Fix RPATH usage on Linux and MacOSX The Netgen installation should be completely relocatable now. Squashed commit of the following: commit 201eda5e62726bd87d76beb13c3e5643cd4c7810 Author: Matthias Hochsteger Date: Mon May 29 21:10:08 2017 +0200 cleanup commit b4cd46a9d2f390b40c5223c8d9971f576b979644 Author: Matthias Hochsteger Date: Mon May 29 20:47:46 2017 +0200 fix commit 6506a834dbee2fd7b6df3b3f3709d0b27344356f Author: Matthias Hochsteger Date: Mon May 29 20:41:45 2017 +0200 allow gui test to fail commit 56c5fc131f61259e6fb67b60f7fff955d2e8d2da Author: Matthias Hochsteger Date: Mon May 29 20:26:18 2017 +0200 add python3-tk to docker images commit 4d1b5aac1d028867339819599708a08f2098bbd6 Author: Matthias Hochsteger Date: Mon May 29 11:22:18 2017 -0700 windows fix commit 92b5f8a95491ba3508143d7f1b94359edc0655ce Author: Matthias Hochsteger Date: Mon May 29 11:08:08 2017 -0700 fix for windows commit 3f7bf51434ef3b637b3563930ddb61d04af645cb Author: Matthias Hochsteger Date: Mon May 29 19:28:13 2017 +0200 fixes, test for gui commit ef1d0164a50fadf374e3b1e43a745b5f69a16ad6 Author: Matthias Hochsteger Date: Mon May 29 19:06:55 2017 +0200 fixes commit 67645bb896012149c23c851b03287199c21fa129 Author: Matthias Hochsteger Date: Mon May 29 17:24:58 2017 +0200 netgen config commit b587b77a282768719cffc366c56d82a1746e0be0 Author: Matthias Hochsteger Date: Mon May 29 16:53:47 2017 +0200 remove comments commit 2b34cc78818afa1cf21484bd0976413a91db0851 Author: Matthias Hochsteger Date: Mon May 29 05:03:00 2017 -0700 fix windows commit 9e98efa54065624e264eaf1acf74b44ef022a68d Author: Matthias Hochsteger Date: Mon May 29 13:42:11 2017 +0200 fixes commit 394b470a07d73431079f80caa36c7c7042077f40 Author: Matthias Hochsteger Date: Mon May 29 12:24:40 2017 +0200 fix rpath issue commit 6787eae384a8592f90598258ccd8207cd499d9fc Author: Matthias Hochsteger Date: Mon May 29 11:37:05 2017 +0200 some more fixes with install dir commit fcf22659c60300e8d39d12e14b21c58a062e739c Author: Matthias Hochsteger Date: Mon May 29 01:34:06 2017 -0700 some fixes commit ede1f0c462978bb70d3b4e2251cb555a592e82e3 Author: Matthias Hochsteger Date: Mon May 29 10:16:34 2017 +0200 fixes commit b6a1259876a77f54e419a44f1b44d03d5bb49b82 Merge: c79f9a3 6627b0b Author: Matthias Hochsteger Date: Wed May 24 09:35:50 2017 +0200 Merge remote-tracking branch 'origin/master' into cmake_cleanup commit c79f9a3421d4d2937c31dab4a601ce09d52b0e54 Merge: 99c3550 030ad1d Author: Matthias Hochsteger Date: Mon May 22 17:52:24 2017 +0200 Merge remote-tracking branch 'origin/master' into cmake_cleanup commit 99c35500850e08fdc847013bb384169b1483acb4 Author: Matthias Hochsteger Date: Fri May 19 14:37:28 2017 +0200 fix rpath commit 8215e9748d9ee225266bc941da1ca252aebd27de Author: Matthias Hochsteger Date: Thu May 18 13:29:41 2017 +0200 remove INSTALL_DIR, rename var to NETGEN_INSTALL_DIR_INCLUDE, install libngpy to python package folder commit 23d028c4cf7572de9e2e277cda8f6b07b6b1d9f9 Merge: 57027c8 f72a247 Author: Matthias Hochsteger Date: Thu May 18 12:03:59 2017 +0200 Merge remote-tracking branch 'origin/master' into cmake_cleanup commit 57027c8c706ff755bdf26887884bbdeca129fe8f Author: Matthias Hochsteger Date: Fri May 12 17:32:05 2017 +0200 New CMake option: USE_INTERNAL_TCL (ON by default) This option uses the tcl code compiled in onetcl.cpp instead of separate tcl files by default. When set at configure time, no tcl files will be installed anymore. commit 27ce5b7edd66d64e2453f5045f5ac08c313f7608 Author: Matthias Hochsteger Date: Fri May 12 17:16:52 2017 +0200 WIP: Cleanup of CMake files - Fix RPATH on Linux (TODO: other platforms) - New variables to specify install behaviour: NG_INSTALL_DIR_BIN NG_INSTALL_DIR_LIB NG_INSTALL_DIR_CMAKE NG_INSTALL_DIR_INCLUDE --- CMakeLists.txt | 145 ++++++++++++++++++++-------- cmake/NetgenConfig.cmake.in | 17 +++- cmake/SuperBuild.cmake | 26 ++--- cmake/external_projects/tcltk.cmake | 2 +- doc/CMakeLists.txt | 2 +- libsrc/csg/CMakeLists.txt | 6 +- libsrc/general/CMakeLists.txt | 4 +- libsrc/geom2d/CMakeLists.txt | 6 +- libsrc/gprim/CMakeLists.txt | 2 +- libsrc/include/CMakeLists.txt | 4 +- libsrc/interface/CMakeLists.txt | 4 +- libsrc/linalg/CMakeLists.txt | 2 +- libsrc/meshing/CMakeLists.txt | 5 +- libsrc/meshing/python_mesh.cpp | 8 ++ libsrc/occ/CMakeLists.txt | 4 +- libsrc/stlgeom/CMakeLists.txt | 6 +- libsrc/visualization/CMakeLists.txt | 6 +- ng/CMakeLists.txt | 59 ++++++----- ng/Togl2.1/CMakeLists.txt | 2 +- ng/ng.tcl | 4 +- ng/ngappinit.cpp | 2 +- ng/onetcl.cpp | 3 + ng/onetcl.py | 3 +- nglib/CMakeLists.txt | 4 +- py_tutorials/CMakeLists.txt | 2 +- python/CMakeLists.txt | 9 +- python/__init__.py | 24 ++--- python/csg.py | 9 +- python/geom2d.py | 4 +- python/gui.py | 11 +-- python/meshing.py | 2 +- python/stl.py | 5 +- tests/docker_15.10 | 2 +- tests/docker_16.04 | 2 +- tests/pytest/test_gui.py | 11 +++ tutorials/CMakeLists.txt | 2 +- 36 files changed, 249 insertions(+), 160 deletions(-) create mode 100644 tests/pytest/test_gui.py diff --git a/CMakeLists.txt b/CMakeLists.txt index 63a74bc1..53b67bde 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,19 +16,51 @@ option( USE_MPEG "enable video recording with FFmpeg, uses libavcodec" OFF ) option( INTEL_MIC "cross compile for intel xeon phi") option( INSTALL_PROFILES "install environment variable settings to /etc/profile.d" OFF ) option( USE_CCACHE "use ccache") +option( USE_INTERNAL_TCL "Compile tcl files into the code and don't install them" ON) option( USE_SUPERBUILD "use ccache" ON) set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" "${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_modules") +if(APPLE) + set(INSTALL_DIR_DEFAULT /Applications/Netgen.app) +else(APPLE) + if(WIN32) + set(INSTALL_DIR_DEFAULT "C:/netgen") + else(WIN32) + set(INSTALL_DIR_DEFAULT /opt/netgen) + endif(WIN32) +endif(APPLE) + +if(INSTALL_DIR) + message(WARNING "INSTALL_DIR is deprecated, use CMAKE_INSTALL_PREFIX instead") + set(INSTALL_DIR_DEFAULT ${INSTALL_DIR}) +endif(INSTALL_DIR) + +if(UNIX) + message("Checking for write permissions in install directory...") + execute_process(COMMAND mkdir -p ${CMAKE_INSTALL_PREFIX}) + execute_process(COMMAND test -w ${CMAKE_INSTALL_PREFIX} RESULT_VARIABLE res) + if(res) + message(WARNING "No write access at install directory, please set correct permissions") + endif() +endif(UNIX) + if (USE_SUPERBUILD) project (SUPERBUILD) + if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) + set(CMAKE_INSTALL_PREFIX "${INSTALL_DIR_DEFAULT}" CACHE PATH "Install directory" FORCE) + endif() + # execute the superbuild (this script will be invoked again without the # USE_SUPERBUILD option this time) include (cmake/SuperBuild.cmake) return() # stop processing this file further else() project(Netgen) + if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) + set(CMAKE_INSTALL_PREFIX "${INSTALL_DIR_DEFAULT}" CACHE PATH "Install directory" FORCE) + endif() endif() set(NETGEN_VERSION_MAJOR 6) @@ -68,43 +100,68 @@ if (ADDITIONAL_PATHS) set(CMAKE_PREFIX_PATH ${ADDITIONAL_PATHS}) endif (ADDITIONAL_PATHS) -if(APPLE) - set(CMAKE_INSTALL_PREFIX "${INSTALL_DIR}/Contents/Resources" CACHE INTERNAL "Prefix prepended to install directories" FORCE) -else(APPLE) - set(CMAKE_INSTALL_PREFIX "${INSTALL_DIR}" CACHE INTERNAL "Prefix prepended to install directories" FORCE) -endif(APPLE) - -####################################################################### -# use rpath -SET(CMAKE_SKIP_BUILD_RPATH FALSE) -SET(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE) -SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib") -SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) -LIST(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/lib" isSystemDir) -IF("${isSystemDir}" STREQUAL "-1") - SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib") -ENDIF("${isSystemDir}" STREQUAL "-1") - ####################################################################### # build options -add_definitions(-DUSE_TIMEOFDAY) - include_directories ("${PROJECT_SOURCE_DIR}/include") include_directories ("${PROJECT_SOURCE_DIR}/libsrc/include") include_directories ("${PROJECT_BINARY_DIR}") set(CMAKE_INCLUDE_CURRENT_DIR ON) -set(INCDIR include CACHE PATH "install directory for header files") if(APPLE) - set(ng_install_dir_bin ../MacOS) - set(ng_install_dir_lib ../MacOS) + set(NG_INSTALL_DIR_BIN_DEFAULT Contents/MacOS) + set(NG_INSTALL_DIR_LIB_DEFAULT Contents/MacOS) + set(NG_INSTALL_DIR_CMAKE_DEFAULT Contents/Resources/share/cmake) + set(NG_INSTALL_DIR_PYTHON_DEFAULT Contents/Resources/${PYTHON_PACKAGES_INSTALL_DIR}) + set(NG_INSTALL_DIR_RES_DEFAULT Contents/Resources/share) + set(NG_INSTALL_DIR_INCLUDE_DEFAULT Contents/Resources/include) + + set(NG_RPATH_TOKEN "@loader_path") else(APPLE) - set(ng_install_dir_bin bin) - set(ng_install_dir_lib lib) + set(NG_INSTALL_DIR_BIN_DEFAULT bin) + set(NG_INSTALL_DIR_LIB_DEFAULT lib) + set(NG_INSTALL_DIR_CMAKE_DEFAULT lib/cmake) + set(NG_INSTALL_DIR_PYTHON_DEFAULT ${PYTHON_PACKAGES_INSTALL_DIR}) + set(NG_INSTALL_DIR_RES_DEFAULT share) + set(NG_INSTALL_DIR_INCLUDE_DEFAULT include) + + set(NG_RPATH_TOKEN "\$ORIGIN") endif(APPLE) -set(ng_install_dir EXPORT netgen-targets RUNTIME DESTINATION ${ng_install_dir_bin} COMPONENT netgen LIBRARY DESTINATION ${ng_install_dir_lib} COMPONENT netgen_devel ARCHIVE DESTINATION ${ng_install_dir_lib} COMPONENT netgen_devel) -install(EXPORT netgen-targets DESTINATION share/cmake) + +set(NG_INSTALL_SUFFIX netgen CACHE STRING "Suffix appended to install directories (project name)") +set(NG_INSTALL_DIR_PYTHON ${NG_INSTALL_DIR_PYTHON_DEFAULT} CACHE STRING "Install directory for Python files") +set(NG_INSTALL_DIR_BIN ${NG_INSTALL_DIR_BIN_DEFAULT} CACHE STRING "Install directory for executables") +set(NG_INSTALL_DIR_LIB ${NG_INSTALL_DIR_LIB_DEFAULT} CACHE STRING "Install directory for libraries") +set(NG_INSTALL_DIR_INCLUDE ${NG_INSTALL_DIR_INCLUDE_DEFAULT} CACHE STRING "Install directory for header files") +set(NG_INSTALL_DIR_CMAKE ${NG_INSTALL_DIR_CMAKE_DEFAULT} CACHE STRING "Install directory for CMake files") +set(NG_INSTALL_DIR_RES ${NG_INSTALL_DIR_RES_DEFAULT} CACHE STRING "Install directory for resources") + +get_filename_component(NETGEN_CMAKE_DIR_ABSOLUTE ${NG_INSTALL_DIR_CMAKE} ABSOLUTE BASE_DIR ${CMAKE_INSTALL_PREFIX}) +get_filename_component(NETGEN_BINARY_DIR_ABSOLUTE ${NG_INSTALL_DIR_BIN} ABSOLUTE BASE_DIR ${CMAKE_INSTALL_PREFIX}) +get_filename_component(NETGEN_LIBRARY_DIR_ABSOLUTE ${NG_INSTALL_DIR_LIB} ABSOLUTE BASE_DIR ${CMAKE_INSTALL_PREFIX}) +get_filename_component(NETGEN_INCLUDE_DIR_ABSOLUTE ${NG_INSTALL_DIR_INCLUDE} ABSOLUTE BASE_DIR ${CMAKE_INSTALL_PREFIX}) +get_filename_component(NETGEN_PYTHON_DIR_ABSOLUTE ${NG_INSTALL_DIR_PYTHON} ABSOLUTE BASE_DIR ${CMAKE_INSTALL_PREFIX}) +get_filename_component(NETGEN_RESOURCE_DIR_ABSOLUTE ${NG_INSTALL_DIR_RES} ABSOLUTE BASE_DIR ${CMAKE_INSTALL_PREFIX}) + +file(RELATIVE_PATH NETGEN_DIR ${NETGEN_CMAKE_DIR_ABSOLUTE} ${CMAKE_INSTALL_PREFIX}) +file(RELATIVE_PATH NETGEN_BINARY_DIR ${NETGEN_CMAKE_DIR_ABSOLUTE} ${NETGEN_BINARY_DIR_ABSOLUTE}) +file(RELATIVE_PATH NETGEN_LIBRARY_DIR ${NETGEN_CMAKE_DIR_ABSOLUTE} ${NETGEN_LIBRARY_DIR_ABSOLUTE}) +file(RELATIVE_PATH NETGEN_INCLUDE_DIR ${NETGEN_CMAKE_DIR_ABSOLUTE} ${NETGEN_INCLUDE_DIR_ABSOLUTE}) +file(RELATIVE_PATH NETGEN_PYTHON_DIR ${NETGEN_CMAKE_DIR_ABSOLUTE} ${NETGEN_PYTHON_DIR_ABSOLUTE}) +file(RELATIVE_PATH NETGEN_RESOURCE_DIR ${NETGEN_CMAKE_DIR_ABSOLUTE} ${NETGEN_RESOURCE_DIR_ABSOLUTE}) + +file(RELATIVE_PATH NETGEN_RPATH ${NETGEN_BINARY_DIR_ABSOLUTE} ${NETGEN_LIBRARY_DIR_ABSOLUTE}) +file(RELATIVE_PATH NETGEN_PYTHON_RPATH_BIN ${NETGEN_PYTHON_DIR_ABSOLUTE} ${NETGEN_BINARY_DIR_ABSOLUTE}) +file(RELATIVE_PATH NETGEN_PYTHON_RPATH ${NETGEN_PYTHON_DIR_ABSOLUTE} ${NETGEN_LIBRARY_DIR_ABSOLUTE}) +if(WIN32) + set(NETGEN_PYTHON_RPATH ${NETGEN_PYTHON_RPATH_BIN}) +endif(WIN32) + +set(NG_INSTALL_DIR EXPORT netgen-targets RUNTIME DESTINATION ${NG_INSTALL_DIR_BIN} COMPONENT netgen LIBRARY DESTINATION ${NG_INSTALL_DIR_LIB} COMPONENT netgen_devel ARCHIVE DESTINATION ${NG_INSTALL_DIR_LIB} COMPONENT netgen_devel) +install(EXPORT netgen-targets DESTINATION ${NG_INSTALL_DIR_CMAKE} ) + +set(CMAKE_MACOSX_RPATH TRUE) +set(CMAKE_INSTALL_RPATH "${NG_RPATH_TOKEN};${NG_RPATH_TOKEN}/${NETGEN_RPATH}") include (CheckIncludeFiles) check_include_files (dlfcn.h HAVE_DLFCN_H) @@ -185,8 +242,8 @@ if (USE_PYTHON) include_directories(${PYBIND_INCLUDE_DIR}) include_directories(${PYTHON_INCLUDE_DIRS}) - install(DIRECTORY ${PYBIND_INCLUDE_DIR}/pybind11 DESTINATION ${INCDIR} COMPONENT netgen_devel) - install(FILES ${PYBIND_INCLUDE_DIR}/../LICENSE DESTINATION ${INCDIR}/pybind11 COMPONENT netgen_devel) + install(DIRECTORY ${PYBIND_INCLUDE_DIR}/pybind11 DESTINATION ${NG_INSTALL_DIR_INCLUDE} COMPONENT netgen_devel) + install(FILES ${PYBIND_INCLUDE_DIR}/../LICENSE DESTINATION ${NG_INSTALL_DIR_INCLUDE}/pybind11 COMPONENT netgen_devel) endif (USE_PYTHON) ####################################################################### @@ -222,10 +279,10 @@ endif (USE_MPEG) ####################################################################### if(INSTALL_PROFILES) file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/netgen.sh "#!/bin/sh\n") - file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/netgen.sh "export PATH=${INSTALL_DIR}/bin:$PATH\n") - file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/netgen.sh "export NETGENDIR=${INSTALL_DIR}/bin\n") - file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/netgen.sh "export PYTHONPATH=${INSTALL_DIR}/${PYTHON_PACKAGES_INSTALL_DIR}:.\n") - file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/netgen.sh "export LD_LIBRARY_PATH=${INSTALL_DIR}/lib:.\n") + file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/netgen.sh "export PATH=${CMAKE_INSTALL_PREFIX}/bin:$PATH\n") + file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/netgen.sh "export NETGENDIR=${CMAKE_INSTALL_PREFIX}/bin\n") + file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/netgen.sh "export PYTHONPATH=${CMAKE_INSTALL_PREFIX}/${PYTHON_PACKAGES_INSTALL_DIR}:.\n") + file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/netgen.sh "export LD_LIBRARY_PATH=${CMAKE_INSTALL_PREFIX}/lib:.\n") install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/netgen.sh DESTINATION /etc/profile.d COMPONENT netgen) string(ASCII 27 Esc) @@ -237,19 +294,19 @@ endif(INSTALL_PROFILES) ####################################################################### file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/fixup.cmake "\ include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/netgen_fixup.cmake) -set(APP ${INSTALL_DIR}) +set(APP ${CMAKE_INSTALL_PREFIX}) message(\${APP}) set(BU_CHMOD_BUNDLE_ITEMS ON) -file(GLOB libs ${CMAKE_INSTALL_PREFIX}/${ng_install_dir_lib}/*.dylib ${CMAKE_INSTALL_PREFIX}/${ng_install_dir_lib}/*.so) +file(GLOB libs ${CMAKE_INSTALL_PREFIX}/${NG_INSTALL_DIR_LIB}/*.dylib ${CMAKE_INSTALL_PREFIX}/${NG_INSTALL_DIR_LIB}/*.so) message(\"\${libs}\") -netgen_fixup_bundle( \${APP}/Contents/MacOS/netgen \"\${libs}\" ${CMAKE_INSTALL_PREFIX}/${ng_install_dir_lib} ) -execute_process(COMMAND ln -s /Applications ${INSTALL_DIR}/../Applications) +netgen_fixup_bundle( \${APP}/Contents/MacOS/netgen \"\${libs}\" ${CMAKE_INSTALL_PREFIX}/${NG_INSTALL_DIR_LIB} ) +execute_process(COMMAND ln -s /Applications ${CMAKE_INSTALL_PREFIX}/../Applications) set (bundle_filename \$ENV{NETGEN_BUNDLE_NAME}) if(NOT bundle_filename) set(bundle_filename netgen) endif(NOT bundle_filename) -execute_process(COMMAND hdiutil create -volname Netgen -srcfolder ${INSTALL_DIR} -ov -format UDZO \${bundle_filename}-${PACKAGE_VERSION}.dmg) +execute_process(COMMAND hdiutil create -volname Netgen -srcfolder ${CMAKE_INSTALL_PREFIX} -ov -format UDZO \${bundle_filename}-${PACKAGE_VERSION}.dmg) ") add_custom_target(bundle COMMAND ${CMAKE_COMMAND} "-P" "${CMAKE_CURRENT_BINARY_DIR}/fixup.cmake") ####################################################################### @@ -323,7 +380,7 @@ export PYTHONPATH=$Netgen_BUNDLE/Contents/Resources/${PYTHON_PACKAGES_INSTALL_DI cd $Netgen_MACOS $Netgen_MACOS/netgen ") - install(PROGRAMS ${mac_startup} DESTINATION ${ng_install_dir_bin}) + install(PROGRAMS ${mac_startup} DESTINATION ${NG_INSTALL_DIR_BIN}) set(mac_ngsuite ${CMAKE_CURRENT_BINARY_DIR}/ngsuite.sh) file(WRITE ${mac_ngsuite} "\ @@ -332,7 +389,7 @@ Netgen_BUNDLE=\"`echo \"$0\" | sed -e 's/\\/Contents\\/MacOS\\/Netgen1//'`\" Netgen_MACOS=\"$Netgen_BUNDLE/Contents/MacOS\" open -a /Applications/Utilities/Terminal.app $Netgen_MACOS/startup.sh ") - install(PROGRAMS ${mac_ngsuite} DESTINATION ../MacOS RENAME Netgen1) + install(PROGRAMS ${mac_ngsuite} DESTINATION ${NG_INSTALL_DIR_BIN} RENAME Netgen1) set(mac_plist ${CMAKE_CURRENT_BINARY_DIR}/Info.plist) file(WRITE ${mac_plist} " @@ -350,8 +407,8 @@ open -a /Applications/Utilities/Terminal.app $Netgen_MACOS/startup.sh ") - install(FILES ${mac_plist} DESTINATION ../) - install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/netgen.icns DESTINATION . RENAME Netgen.icns) + install(FILES ${mac_plist} DESTINATION ${NG_INSTALL_DIR_BIN}/../) + install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/netgen.icns DESTINATION ${NG_INSTALL_DIR_RES}/../ RENAME Netgen.icns) endif(APPLE) @@ -368,10 +425,14 @@ configure_file( add_custom_target(uninstall COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake) +####################################################################### +# Generate package config file +get_directory_property(NETGEN_COMPILE_DEFINITIONS COMPILE_DEFINITIONS) + configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/NetgenConfig.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/NetgenConfig.cmake @ONLY) -install(FILES ${CMAKE_CURRENT_BINARY_DIR}/NetgenConfig.cmake DESTINATION share/cmake) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/NetgenConfig.cmake DESTINATION ${NG_INSTALL_DIR_CMAKE}) ####################################################################### # Configure message diff --git a/cmake/NetgenConfig.cmake.in b/cmake/NetgenConfig.cmake.in index c72d40c3..9cfa7da7 100644 --- a/cmake/NetgenConfig.cmake.in +++ b/cmake/NetgenConfig.cmake.in @@ -1,7 +1,17 @@ set(PACKAGE_VERSION "@NETGEN_VERSION@") -set(NETGEN_DIR "@CMAKE_INSTALL_PREFIX@") -set(NETGEN_INCLUDE_DIR "@CMAKE_INSTALL_PREFIX@/@INCDIR@") +get_filename_component(NETGEN_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) + +set(NETGEN_DIR "${NETGEN_CMAKE_DIR}/@NETGEN_DIR@") + +set(NETGEN_COMPILE_DEFINITIONS "@NETGEN_COMPILE_DEFINITIONS@") + +set(NETGEN_INCLUDE_DIR "${NETGEN_CMAKE_DIR}/@NETGEN_INCLUDE_DIR@/include;${NETGEN_CMAKE_DIR}/@NETGEN_INCLUDE_DIR@") +set(NETGEN_BINARY_DIR "${NETGEN_CMAKE_DIR}/@NETGEN_BINARY_DIR@") +set(NETGEN_LIBRARY_DIR "${NETGEN_CMAKE_DIR}/@NETGEN_LIBRARY_DIR@") +set(NETGEN_PYTHON_DIR "${NETGEN_CMAKE_DIR}/@NETGEN_PYTHON_DIR@") +set(NETGEN_RESOURCE_DIR "${NETGEN_CMAKE_DIR}/@NETGEN_RESOURCE_DIR@") + set(NETGEN_SOURCE_DIR "@PROJECT_SOURCE_DIR@") set(NETGEN_CMAKE_THREAD_LIBS_INIT "@CMAKE_THREAD_LIBS_INIT@") @@ -14,7 +24,6 @@ set(NETGEN_METIS_LIBRARY "@METIS_LIBRARY@") set(NETGEN_MKL_LIBRARIES "@MKL_LIBRARIES@") set(NETGEN_MPI_CXX_INCLUDE_PATH "@MPI_CXX_INCLUDE_PATH@") set(NETGEN_MPI_CXX_LIBRARIES "@MPI_CXX_LIBRARIES@") -set(NETGEN_INCLUDE_DIRS "@CMAKE_INSTALL_PREFIX@/@INCDIR@;@CMAKE_INSTALL_PREFIX@/@INCDIR@/include") set(NETGEN_OCC_INCLUDE_DIR "@OCC_INCLUDE_DIR@") set(NETGEN_OCC_LIBRARIES_BIN "@OCC_LIBRARIES_BIN@") set(NETGEN_OCC_LIBRARIES "@OCC_LIBRARIES@") @@ -46,4 +55,4 @@ set(NETGEN_INSTALL_PROFILES @INSTALL_PROFILES@) set(NETGEN_USE_CCACHE @USE_CCACHE@) include(${CMAKE_CURRENT_LIST_DIR}/netgen-targets.cmake) -message(STATUS "Found Netgen: ${NETGEN_DIR}") +message(STATUS "Found Netgen: ${CMAKE_CURRENT_LIST_DIR}") diff --git a/cmake/SuperBuild.cmake b/cmake/SuperBuild.cmake index b802b6fa..91ede9e7 100644 --- a/cmake/SuperBuild.cmake +++ b/cmake/SuperBuild.cmake @@ -40,19 +40,10 @@ if(WIN32) endif(${CMAKE_SIZEOF_VOID_P} MATCHES 4) endif(WIN32) -####################################################################### -# find netgen -if(APPLE) - set(INSTALL_DIR /Applications/Netgen.app CACHE PATH "Install path") - set(CMAKE_INSTALL_PREFIX "${INSTALL_DIR}/Contents/Resources" CACHE INTERNAL "Prefix prepended to install directories" FORCE) -else(APPLE) - set(INSTALL_DIR /opt/netgen CACHE PATH "Install path") - set(CMAKE_INSTALL_PREFIX "${INSTALL_DIR}" CACHE INTERNAL "Prefix prepended to install directories" FORCE) -endif(APPLE) if(UNIX) message("Checking for write permissions in install directory...") - execute_process(COMMAND mkdir -p ${INSTALL_DIR}) - execute_process(COMMAND test -w ${INSTALL_DIR} RESULT_VARIABLE res) + execute_process(COMMAND mkdir -p ${CMAKE_INSTALL_PREFIX}) + execute_process(COMMAND test -w ${CMAKE_INSTALL_PREFIX} RESULT_VARIABLE res) if(res) message(WARNING "No write access at install directory, please set correct permissions") endif() @@ -94,7 +85,7 @@ if(USE_OCC AND WIN32 AND NOT OCC_INCLUDE_DIR) BUILD_IN_SOURCE 1 CONFIGURE_COMMAND "" BUILD_COMMAND "" - INSTALL_COMMAND ${CMAKE_COMMAND} -E copy_directory . ${INSTALL_DIR} + INSTALL_COMMAND ${CMAKE_COMMAND} -E copy_directory . ${CMAKE_INSTALL_PREFIX} LOG_DOWNLOAD 1 ) list(APPEND NETGEN_DEPENDENCIES win_download_occ) @@ -140,10 +131,11 @@ set_vars( NETGEN_CMAKE_ARGS USE_NATIVE_ARCH USE_OCC USE_MPEG - INSTALL_DIR + USE_INTERNAL_TCL INSTALL_PROFILES INTEL_MIC CMAKE_PREFIX_PATH + CMAKE_INSTALL_PREFIX ) # propagate all variables set on the command line using cmake -DFOO=BAR @@ -166,7 +158,7 @@ endif() ExternalProject_Add (netgen DEPENDS ${NETGEN_DEPENDENCIES} SOURCE_DIR ${PROJECT_SOURCE_DIR} - CMAKE_ARGS -DUSE_SUPERBUILD=OFF ${NETGEN_CMAKE_ARGS} -DCMAKE_PREFIX_PATH=${INSTALL_DIR} + CMAKE_ARGS -DUSE_SUPERBUILD=OFF ${NETGEN_CMAKE_ARGS} INSTALL_COMMAND "" BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/netgen BUILD_COMMAND ${NETGEN_BUILD_COMMAND} @@ -176,21 +168,21 @@ ExternalProject_Add (netgen # Check if the git submodules (i.e. pybind11) are up to date # in case, something is wrong, emit a warning but continue ExternalProject_Add_Step(netgen check_submodules - COMMAND cmake -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/check_submodules.cmake + COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/check_submodules.cmake DEPENDERS install # Steps on which this step depends ) # Due to 'ALWAYS 1', this step is always run which also forces a build of # the Netgen subproject ExternalProject_Add_Step(netgen check_submodules1 - COMMAND cmake -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/check_submodules.cmake + COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/check_submodules.cmake DEPENDEES configure # Steps on which this step depends DEPENDERS build # Steps that depend on this step ALWAYS 1 # No stamp file, step always runs ) -install(CODE "execute_process(COMMAND cmake --build . --target install --config ${CMAKE_BUILD_TYPE} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/netgen)") +install(CODE "execute_process(COMMAND ${CMAKE_COMMAND} --build . --target install --config ${CMAKE_BUILD_TYPE} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/netgen)") add_custom_target(test_netgen ${CMAKE_COMMAND} --build ${CMAKE_CURRENT_BINARY_DIR}/netgen diff --git a/cmake/external_projects/tcltk.cmake b/cmake/external_projects/tcltk.cmake index 65d06df0..6be407b3 100644 --- a/cmake/external_projects/tcltk.cmake +++ b/cmake/external_projects/tcltk.cmake @@ -61,7 +61,7 @@ elseif(WIN32) BUILD_IN_SOURCE 1 CONFIGURE_COMMAND "" BUILD_COMMAND "" - INSTALL_COMMAND ${CMAKE_COMMAND} -E copy_directory . ${INSTALL_DIR} + INSTALL_COMMAND ${CMAKE_COMMAND} -E copy_directory . ${CMAKE_INSTALL_PREFIX} LOG_DOWNLOAD 1 ) diff --git a/doc/CMakeLists.txt b/doc/CMakeLists.txt index d7563fdb..e45555c7 100644 --- a/doc/CMakeLists.txt +++ b/doc/CMakeLists.txt @@ -1 +1 @@ -INSTALL(FILES ng4.pdf DESTINATION doc COMPONENT netgen_doc) +INSTALL(FILES ng4.pdf DESTINATION ${NG_INSTALL_DIR_RES}/${NG_INSTALL_SUFFIX}/doc COMPONENT netgen_doc) diff --git a/libsrc/csg/CMakeLists.txt b/libsrc/csg/CMakeLists.txt index 510b0e09..224a48e4 100644 --- a/libsrc/csg/CMakeLists.txt +++ b/libsrc/csg/CMakeLists.txt @@ -14,7 +14,7 @@ endif(APPLE) if(NOT WIN32) target_link_libraries(csg mesh ${PYTHON_LIBRARIES}) target_link_libraries(csg ${PYTHON_LIBRARIES}) - install( TARGETS csg ${ng_install_dir}) + install( TARGETS csg ${NG_INSTALL_DIR}) endif(NOT WIN32) @@ -25,7 +25,7 @@ if(USE_GUI) if(APPLE) set_target_properties( csgvis PROPERTIES SUFFIX ".so") endif(APPLE) - install( TARGETS csgvis ${ng_install_dir}) + install( TARGETS csgvis ${NG_INSTALL_DIR}) endif(NOT WIN32) endif(USE_GUI) @@ -36,5 +36,5 @@ install(FILES polyhedra.hpp revolution.hpp singularref.hpp solid.hpp specpoin.hpp spline3d.hpp splinesurface.hpp surface.hpp triapprox.hpp vscsg.hpp - DESTINATION ${INCDIR}/csg COMPONENT netgen_devel + DESTINATION ${NG_INSTALL_DIR_INCLUDE}/csg COMPONENT netgen_devel ) diff --git a/libsrc/general/CMakeLists.txt b/libsrc/general/CMakeLists.txt index 811bc80d..5faf7c6c 100644 --- a/libsrc/general/CMakeLists.txt +++ b/libsrc/general/CMakeLists.txt @@ -8,7 +8,7 @@ add_library(gen OBJECT set_target_properties( gen PROPERTIES POSITION_INDEPENDENT_CODE ON ) -install( FILES ngexception.hpp DESTINATION ${INCDIR} COMPONENT netgen_devel ) +install( FILES ngexception.hpp DESTINATION ${NG_INSTALL_DIR_INCLUDE} COMPONENT netgen_devel ) install(FILES archive_base.hpp array.hpp autodiff.hpp autoptr.hpp bitarray.hpp @@ -17,5 +17,5 @@ install(FILES optmem.hpp parthreads.hpp profiler.hpp seti.hpp sort.hpp spbita2d.hpp stack.hpp symbolta.hpp table.hpp template.hpp gzstream.h - DESTINATION ${INCDIR}/general COMPONENT netgen_devel + DESTINATION ${NG_INSTALL_DIR_INCLUDE}/general COMPONENT netgen_devel ) diff --git a/libsrc/geom2d/CMakeLists.txt b/libsrc/geom2d/CMakeLists.txt index 332fe06f..299157af 100644 --- a/libsrc/geom2d/CMakeLists.txt +++ b/libsrc/geom2d/CMakeLists.txt @@ -6,19 +6,19 @@ endif(APPLE) if(NOT WIN32) target_link_libraries(geom2d mesh ${PYTHON_LIBRARIES}) - install( TARGETS geom2d ${ng_install_dir}) + install( TARGETS geom2d ${NG_INSTALL_DIR}) endif(NOT WIN32) if(USE_GUI) add_library(geom2dvis ${NG_LIB_TYPE} vsgeom2d.cpp) if(NOT WIN32) target_link_libraries(geom2dvis geom2d) - install( TARGETS geom2dvis ${ng_install_dir}) + install( TARGETS geom2dvis ${NG_INSTALL_DIR}) endif(NOT WIN32) endif(USE_GUI) install(FILES geom2dmesh.hpp geometry2d.hpp spline2d.hpp splinegeometry2.hpp vsgeom2d.hpp - DESTINATION ${INCDIR}/geom2d COMPONENT netgen_devel + DESTINATION ${NG_INSTALL_DIR_INCLUDE}/geom2d COMPONENT netgen_devel ) diff --git a/libsrc/gprim/CMakeLists.txt b/libsrc/gprim/CMakeLists.txt index 4bf13c68..3957476a 100644 --- a/libsrc/gprim/CMakeLists.txt +++ b/libsrc/gprim/CMakeLists.txt @@ -10,5 +10,5 @@ install(FILES adtree.hpp geom2d.hpp geom3d.hpp geomfuncs.hpp geomobjects2.hpp geomobjects.hpp geomops2.hpp geomops.hpp geomtest3d.hpp gprim.hpp splinegeometry.hpp spline.hpp transform3d.hpp - DESTINATION ${INCDIR}/gprim COMPONENT netgen_devel + DESTINATION ${NG_INSTALL_DIR_INCLUDE}/gprim COMPONENT netgen_devel ) diff --git a/libsrc/include/CMakeLists.txt b/libsrc/include/CMakeLists.txt index 1bd3dc2f..2be510cf 100644 --- a/libsrc/include/CMakeLists.txt +++ b/libsrc/include/CMakeLists.txt @@ -1,10 +1,10 @@ -install(FILES nginterface.h nginterface_v2.hpp DESTINATION ${INCDIR} COMPONENT netgen_devel) +install(FILES nginterface.h nginterface_v2.hpp DESTINATION ${NG_INSTALL_DIR_INCLUDE} COMPONENT netgen_devel) install(FILES acisgeom.hpp csg.hpp geometry2d.hpp gprim.hpp incopengl.hpp inctcl.hpp incvis.hpp linalg.hpp meshing.hpp myadt.hpp mydefs.hpp mystdlib.h nginterface_v2_impl.hpp occgeom.hpp ngsimd.hpp opti.hpp parallel.hpp parallelinterface.hpp stlgeom.hpp visual.hpp - DESTINATION ${INCDIR}/include COMPONENT netgen_devel + DESTINATION ${NG_INSTALL_DIR_INCLUDE}/include COMPONENT netgen_devel ) diff --git a/libsrc/interface/CMakeLists.txt b/libsrc/interface/CMakeLists.txt index 29213966..ef52c30b 100644 --- a/libsrc/interface/CMakeLists.txt +++ b/libsrc/interface/CMakeLists.txt @@ -12,10 +12,10 @@ if(NOT WIN32) if(USE_GUI) target_link_libraries(interface visual) endif(USE_GUI) - install( TARGETS interface ${ng_install_dir}) + install( TARGETS interface ${NG_INSTALL_DIR}) endif(NOT WIN32) install(FILES writeuser.hpp - DESTINATION ${INCDIR}/interface COMPONENT netgen_devel + DESTINATION ${NG_INSTALL_DIR_INCLUDE}/interface COMPONENT netgen_devel ) diff --git a/libsrc/linalg/CMakeLists.txt b/libsrc/linalg/CMakeLists.txt index e50fb5b5..a5a5a4f2 100644 --- a/libsrc/linalg/CMakeLists.txt +++ b/libsrc/linalg/CMakeLists.txt @@ -7,5 +7,5 @@ set_target_properties(la PROPERTIES POSITION_INDEPENDENT_CODE ON ) install(FILES densemat.hpp linalg.hpp opti.hpp polynomial.hpp vector.hpp - DESTINATION ${INCDIR}/linalg COMPONENT netgen_devel + DESTINATION ${NG_INSTALL_DIR_INCLUDE}/linalg COMPONENT netgen_devel ) diff --git a/libsrc/meshing/CMakeLists.txt b/libsrc/meshing/CMakeLists.txt index 959f2868..e9e6e211 100644 --- a/libsrc/meshing/CMakeLists.txt +++ b/libsrc/meshing/CMakeLists.txt @@ -21,6 +21,7 @@ add_library(mesh ${NG_LIB_TYPE} topology.cpp triarls.cpp validate.cpp bcfunctions.cpp parallelmesh.cpp paralleltop.cpp paralleltop.hpp basegeom.cpp python_mesh.cpp hexarls.cpp + ../../ng/onetcl.cpp ${mesh_object_libs} ) @@ -30,7 +31,7 @@ endif(APPLE) if(NOT WIN32) target_link_libraries( mesh ${ZLIB_LIBRARIES} ${MPI_CXX_LIBRARIES} ${PYTHON_LIBRARIES} ${METIS_LIBRARY}) - install( TARGETS mesh ${ng_install_dir}) + install( TARGETS mesh ${NG_INSTALL_DIR}) endif(NOT WIN32) install(FILES @@ -42,5 +43,5 @@ install(FILES localh.hpp meshclass.hpp meshfunc.hpp meshing2.hpp meshing3.hpp meshing.hpp meshtool.hpp meshtype.hpp msghandler.hpp paralleltop.hpp ruler2.hpp ruler3.hpp specials.hpp topology.hpp validate.hpp - DESTINATION ${INCDIR}/meshing COMPONENT netgen_devel + DESTINATION ${NG_INSTALL_DIR_INCLUDE}/meshing COMPONENT netgen_devel ) diff --git a/libsrc/meshing/python_mesh.cpp b/libsrc/meshing/python_mesh.cpp index b4c3f8d3..774aae17 100644 --- a/libsrc/meshing/python_mesh.cpp +++ b/libsrc/meshing/python_mesh.cpp @@ -11,6 +11,8 @@ using namespace netgen; +extern const char *ngscript[]; + namespace netgen { extern bool netgen_executable_started; @@ -51,6 +53,12 @@ static Transformation<3> global_trafo(Vec<3> (0,0,0)); DLL_HEADER void ExportNetgenMeshing(py::module &m) { m.attr("_netgen_executable_started") = py::cast(netgen::netgen_executable_started); + string script; + const char ** hcp = ngscript; + while (*hcp) + script += *hcp++; + + m.attr("_ngscript") = py::cast(script); py::class_(m, "NGDummyArgument") .def("__bool__", []( NGDummyArgument &self ) { return false; } ) diff --git a/libsrc/occ/CMakeLists.txt b/libsrc/occ/CMakeLists.txt index 8f7f7c32..831f2e6b 100644 --- a/libsrc/occ/CMakeLists.txt +++ b/libsrc/occ/CMakeLists.txt @@ -10,10 +10,10 @@ add_library(occvis ${NG_LIB_TYPE} vsocc.cpp) if(NOT WIN32) target_link_libraries( occ ${OCC_LIBRARIES} ${PYTHON_LIBRARIES}) target_link_libraries( occvis occ ) - install( TARGETS occ occvis ${ng_install_dir}) + install( TARGETS occ occvis ${NG_INSTALL_DIR}) endif(NOT WIN32) install(FILES occgeom.hpp occmeshsurf.hpp vsocc.hpp - DESTINATION ${INCDIR}/occ COMPONENT netgen_devel + DESTINATION ${NG_INSTALL_DIR_INCLUDE}/occ COMPONENT netgen_devel ) diff --git a/libsrc/stlgeom/CMakeLists.txt b/libsrc/stlgeom/CMakeLists.txt index d2072a1a..3620c496 100644 --- a/libsrc/stlgeom/CMakeLists.txt +++ b/libsrc/stlgeom/CMakeLists.txt @@ -6,7 +6,7 @@ add_library(stl ${NG_LIB_TYPE} if(NOT WIN32) target_link_libraries( stl mesh ${PYTHON_LIBRARIES}) target_link_libraries( stl ${PYTHON_LIBRARIES}) - install( TARGETS stl ${ng_install_dir}) + install( TARGETS stl ${NG_INSTALL_DIR}) endif(NOT WIN32) if(USE_GUI) @@ -15,12 +15,12 @@ if(USE_GUI) ) if(NOT WIN32) target_link_libraries( stlvis stl ) - install( TARGETS stlvis ${ng_install_dir}) + install( TARGETS stlvis ${NG_INSTALL_DIR}) endif(NOT WIN32) endif(USE_GUI) install(FILES meshstlsurface.hpp stlgeom.hpp stlline.hpp stltool.hpp stltopology.hpp vsstl.hpp - DESTINATION ${INCDIR}/stlgeom COMPONENT netgen_devel + DESTINATION ${NG_INSTALL_DIR_INCLUDE}/stlgeom COMPONENT netgen_devel ) diff --git a/libsrc/visualization/CMakeLists.txt b/libsrc/visualization/CMakeLists.txt index 273829a6..8f803d92 100644 --- a/libsrc/visualization/CMakeLists.txt +++ b/libsrc/visualization/CMakeLists.txt @@ -1,5 +1,5 @@ add_definitions(-DNGINTERFACE_EXPORTS) -install(FILES soldata.hpp DESTINATION ${INCDIR} COMPONENT netgen_devel ) +install(FILES soldata.hpp DESTINATION ${NG_INSTALL_DIR_INCLUDE} COMPONENT netgen_devel ) if(USE_GUI) set( LIB_VISUAL_SOURCES meshdoc.cpp mvdraw.cpp vsfieldlines.cpp vsmesh.cpp vssolution.cpp importsolution.cpp ) @@ -11,11 +11,11 @@ add_library(visual ${NG_LIB_TYPE} ${LIB_VISUAL_SOURCES}) if(NOT WIN32) target_link_libraries( visual ${PYTHON_LIBRARIES} ${MPI_CXX_LIBRARIES} ${OPENGL_LIBRARIES} ) - install( TARGETS visual ${ng_install_dir}) + install( TARGETS visual ${NG_INSTALL_DIR}) endif(NOT WIN32) install(FILES meshdoc.hpp mvdraw.hpp vispar.hpp visual.hpp vssolution.hpp - DESTINATION ${INCDIR}/visualization COMPONENT netgen_devel + DESTINATION ${NG_INSTALL_DIR_INCLUDE}/visualization COMPONENT netgen_devel ) diff --git a/ng/CMakeLists.txt b/ng/CMakeLists.txt index 9fca6c27..7c4a1f81 100644 --- a/ng/CMakeLists.txt +++ b/ng/CMakeLists.txt @@ -1,23 +1,28 @@ -set(gui_sources - gui.cpp ngpkg.cpp demoview.cpp parallelfunc.cpp - ../libsrc/stlgeom/stlpkg.cpp ../libsrc/visualization/visualpkg.cpp - ../libsrc/csg/csgpkg.cpp ../libsrc/geom2d/geom2dpkg.cpp - ../libsrc/occ/occpkg.cpp ../libsrc/occ/vsocc.cpp - ) +if(USE_INTERNAL_TCL) + add_definitions(-DINTERNAL_TCL_DEFAULT=1) +else() + add_definitions(-DINTERNAL_TCL_DEFAULT=0) +endif() -set(netgen_sources ngappinit.cpp onetcl.cpp ) +set(netgen_sources ngappinit.cpp onetcl.cpp) +if(WIN32) + # 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) if(USE_GUI) - if(WIN32) - # 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_library(gui SHARED ${gui_sources}) - add_executable(netgen ${netgen_sources}) + add_library(gui SHARED + gui.cpp ngpkg.cpp demoview.cpp parallelfunc.cpp + ../libsrc/stlgeom/stlpkg.cpp ../libsrc/visualization/visualpkg.cpp + ../libsrc/csg/csgpkg.cpp ../libsrc/geom2d/geom2dpkg.cpp + ../libsrc/occ/occpkg.cpp ../libsrc/occ/vsocc.cpp + ) + + add_executable(netgen ngappinit.cpp onetcl.cpp) target_link_libraries( gui PUBLIC nglib ${ZLIB_LIBRARIES} ${JPEG_LIBRARIES} ${FFMPEG_LIBRARIES} ${X11_X11_LIB} ${OCC_LIBRARIES} ) target_link_libraries( gui PRIVATE ${LIBTOGL}) @@ -38,8 +43,8 @@ if(USE_GUI) target_link_libraries( gui PUBLIC mesh stlvis stl geom2dvis interface geom2d csg stl visual csgvis ) endif(NOT WIN32) - install(TARGETS netgen ${ng_install_dir}) - install(TARGETS gui ${ng_install_dir}) + install(TARGETS netgen ${NG_INSTALL_DIR}) + install(TARGETS gui ${NG_INSTALL_DIR}) if(APPLE) set_target_properties(netgen PROPERTIES OUTPUT_NAME netgen) @@ -59,18 +64,20 @@ if(USE_PYTHON) set_target_properties( ngpy PROPERTIES SUFFIX ".pyd") set_target_properties( ngpy PROPERTIES OUTPUT_NAME "libngpy") endif() - install(TARGETS ngpy ${ng_install_dir}) + set_target_properties(ngpy PROPERTIES INSTALL_RPATH "${NG_RPATH_TOKEN}/../${NETGEN_PYTHON_RPATH}") + install(TARGETS ngpy DESTINATION ${NG_INSTALL_DIR_PYTHON}/${NG_INSTALL_SUFFIX}) endif(USE_PYTHON) if(USE_GUI) - install(FILES - dialog.tcl menustat.tcl ngicon.tcl ng.tcl - ngvisual.tcl sockets.tcl nghelp.tcl ngshell.tcl - ngtesting.tcl parameters.tcl variables.tcl csgeom.tcl stlgeom.tcl - occgeom.tcl acisgeom.tcl netgen.ocf - DESTINATION ${ng_install_dir_bin} COMPONENT netgen) + if(NOT USE_INTERNAL_TCL) + install(FILES + dialog.tcl menustat.tcl ngicon.tcl ng.tcl + ngvisual.tcl sockets.tcl nghelp.tcl ngshell.tcl + ngtesting.tcl parameters.tcl variables.tcl csgeom.tcl stlgeom.tcl + occgeom.tcl acisgeom.tcl netgen.ocf drawing.tcl + DESTINATION ${NG_INSTALL_DIR_BIN} COMPONENT netgen) + endif() add_subdirectory(Togl2.1) - install(FILES drawing.tcl DESTINATION ${ng_install_dir_bin} COMPONENT netgen) endif(USE_GUI) diff --git a/ng/Togl2.1/CMakeLists.txt b/ng/Togl2.1/CMakeLists.txt index 98ae1310..bcade1f7 100644 --- a/ng/Togl2.1/CMakeLists.txt +++ b/ng/Togl2.1/CMakeLists.txt @@ -7,7 +7,7 @@ endif(APPLE) if(WIN32) add_definitions("-DBUILD_togl -DUNICODE -D_UNICODE -DTOGL_USE_FONTS=0 -DSTDC_HEADERS -DSTDC_HEADER") add_library(togl SHARED togl.c toglProcAddr.c toglStubInit.c) - install(TARGETS togl DESTINATION ${ng_install_dir} COMPONENT netgen) + install(TARGETS togl DESTINATION ${NG_INSTALL_DIR} COMPONENT netgen) target_link_libraries(togl ${TCL_LIBRARY} ${TK_LIBRARY}) else(WIN32) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fomit-frame-pointer -Wno-implicit-int") diff --git a/ng/ng.tcl b/ng/ng.tcl index 18a870db..003b745c 100644 --- a/ng/ng.tcl +++ b/ng/ng.tcl @@ -1,7 +1,9 @@ catch {lappend auto_path $env(NETGENDIR) } catch {lappend auto_path $env(NETGENDIR)/../lib } -load libgui[info sharedlibextension] gui +if {[catch {Ng_GetCommandLineParameter batchmode} result ]} { + load libgui[info sharedlibextension] gui +} set batchmode [Ng_GetCommandLineParameter batchmode] if {$batchmode=="undefined"} { diff --git a/ng/ngappinit.cpp b/ng/ngappinit.cpp index 21589aaf..a83957a7 100644 --- a/ng/ngappinit.cpp +++ b/ng/ngappinit.cpp @@ -191,7 +191,7 @@ int main(int argc, char ** argv) // parse tcl-script int errcode; - bool internaltcl = false; + bool internaltcl = INTERNAL_TCL_DEFAULT; if (shellmode) internaltcl = false; diff --git a/ng/onetcl.cpp b/ng/onetcl.cpp index 5a9df978..53348262 100644 --- a/ng/onetcl.cpp +++ b/ng/onetcl.cpp @@ -1,7 +1,9 @@ const char * ngscript[] = {"" ,"catch {lappend auto_path $env(NETGENDIR) }\n" ,"catch {lappend auto_path $env(NETGENDIR)/../lib }\n" +,"if {[catch {Ng_GetCommandLineParameter batchmode} result ]} {\n" ,"load libgui[info sharedlibextension] gui\n" +,"}\n" ,"set batchmode [Ng_GetCommandLineParameter batchmode]\n" ,"if {$batchmode==\"undefined\"} {\n" ,"if {[catch {package require tkdnd } result ]} {\n" @@ -5971,4 +5973,5 @@ const char * ngscript[] = {"" ,"source startup.tcl }\n" ,"catch { source ${ngdir}/demoapp.tcl }\n" ,"catch { source ${ngdir}/dropsexp.tcl }\n" +, nullptr }; diff --git a/ng/onetcl.py b/ng/onetcl.py index f340684b..19f8f546 100644 --- a/ng/onetcl.py +++ b/ng/onetcl.py @@ -40,5 +40,6 @@ for line in tclfiles["ng.tcl"].split('\n'): s = ',"' + line.replace('\\', r'\\').replace('"', r'\"') + '\\n"\n' onetclcpp.write(s) -onetclcpp.write('};'+'\n'); +onetclcpp.write(', nullptr\n'); +onetclcpp.write('};\n'); onetclcpp.close(); diff --git a/nglib/CMakeLists.txt b/nglib/CMakeLists.txt index 4a1faee0..ae1bb70c 100644 --- a/nglib/CMakeLists.txt +++ b/nglib/CMakeLists.txt @@ -38,5 +38,5 @@ if(USE_PYTHON) target_link_libraries(nglib ${PYTHON_LIBRARIES}) endif(USE_PYTHON) -install(TARGETS nglib ${ng_install_dir}) -install(FILES nglib.h DESTINATION ${INCDIR}/include COMPONENT netgen_devel) +install(TARGETS nglib ${NG_INSTALL_DIR}) +install(FILES nglib.h DESTINATION ${NG_INSTALL_DIR_INCLUDE}/include COMPONENT netgen_devel) diff --git a/py_tutorials/CMakeLists.txt b/py_tutorials/CMakeLists.txt index 895911a4..bf67b11a 100644 --- a/py_tutorials/CMakeLists.txt +++ b/py_tutorials/CMakeLists.txt @@ -1,5 +1,5 @@ install( FILES shaft.geo mesh.py exportNeutral.py - DESTINATION share/netgen/py_tutorials + DESTINATION ${NG_INSTALL_DIR_RES}/${NG_INSTALL_SUFFIX}/py_tutorials COMPONENT netgen_tutorial ) diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index d35278f3..5f9c785a 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -1,5 +1,8 @@ -install(FILES __init__.py meshing.py csg.py geom2d.py stl.py gui.py - DESTINATION ${PYTHON_PACKAGES_INSTALL_DIR}/netgen +configure_file(__init__.py ${CMAKE_CURRENT_BINARY_DIR}/__init__.py @ONLY) + +install(FILES + ${CMAKE_CURRENT_BINARY_DIR}/__init__.py + meshing.py csg.py geom2d.py stl.py gui.py + DESTINATION ${NG_INSTALL_DIR_PYTHON}/${NG_INSTALL_SUFFIX} COMPONENT netgen ) - diff --git a/python/__init__.py b/python/__init__.py index ca1e91bd..e74d1a49 100644 --- a/python/__init__.py +++ b/python/__init__.py @@ -1,19 +1,13 @@ import os -from sys import path -from sys import platform as __platform +import sys -if __platform.startswith('linux'): - _netgen_bin_dir=os.path.realpath(os.path.join(os.path.dirname(__file__),'../../../../bin')) - _netgen_lib_dir=os.path.realpath(os.path.join(os.path.dirname(__file__),'../../../../lib')) -if __platform.startswith('win'): - _netgen_bin_dir=os.path.realpath(os.path.join(os.path.dirname(__file__) + '/../../../bin')) - _netgen_lib_dir=_netgen_bin_dir -if __platform.startswith('darwin'): - _netgen_bin_dir=os.path.realpath(os.path.join(os.path.dirname(__file__) + '/../../../../../MacOS')) - _netgen_lib_dir=_netgen_bin_dir +_netgen_bin_dir=os.path.realpath(os.path.join(os.path.dirname(__file__),'..','@NETGEN_PYTHON_RPATH_BIN@')) +_netgen_lib_dir=os.path.realpath(os.path.join(os.path.dirname(__file__),'..','@NETGEN_PYTHON_RPATH@')) -path.append(_netgen_lib_dir) -path.append(_netgen_bin_dir) +if sys.platform.startswith('win'): + os.environ['PATH'] += ';'+os.path.realpath(os.path.join(os.path.dirname(__file__),'../../../bin')) -import libngpy -del path +del sys +del os + +from . import libngpy diff --git a/python/csg.py b/python/csg.py index f0e7823c..1e58f1bb 100644 --- a/python/csg.py +++ b/python/csg.py @@ -1,8 +1,7 @@ -import libngpy -from libngpy._csg import * -from libngpy._meshing import MeshingParameters -from libngpy._meshing import Pnt -from libngpy._meshing import Vec +from netgen.libngpy._csg import * +from netgen.libngpy._meshing import MeshingParameters +from netgen.libngpy._meshing import Pnt +from netgen.libngpy._meshing import Vec try: diff --git a/python/geom2d.py b/python/geom2d.py index bb5a12f6..47baa952 100644 --- a/python/geom2d.py +++ b/python/geom2d.py @@ -1,5 +1,5 @@ -from libngpy._geom2d import * -from libngpy._meshing import * +from netgen.libngpy._geom2d import * +from netgen.libngpy._meshing import * tmp_generate_mesh = SplineGeometry.GenerateMesh diff --git a/python/gui.py b/python/gui.py index bf29a41e..fcd4872b 100644 --- a/python/gui.py +++ b/python/gui.py @@ -1,16 +1,15 @@ import netgen def StartGUI(): - import os from tkinter import Tk - from . import _netgen_lib_dir - from . import _netgen_bin_dir - global win win = Tk() - dir_path = os.path.dirname(os.path.realpath(__file__)) - win.tk.eval("source "+os.path.realpath(os.path.join(_netgen_bin_dir, 'ng.tcl')).replace('\\','/')) + win.tk.eval('lappend ::auto_path ' + netgen._netgen_lib_dir) + win.tk.eval('lappend ::auto_path ' + netgen._netgen_bin_dir) + # load with absolute path to avoid issues on MacOS + win.tk.eval('load '+netgen._netgen_lib_dir.replace('\\','/')+'/libgui[info sharedlibextension] gui') + win.tk.eval( netgen.libngpy._meshing._ngscript) if not netgen.libngpy._meshing._netgen_executable_started: StartGUI() diff --git a/python/meshing.py b/python/meshing.py index c9c8f511..f6ad65ce 100644 --- a/python/meshing.py +++ b/python/meshing.py @@ -1 +1 @@ -from libngpy._meshing import * +from netgen.libngpy._meshing import * diff --git a/python/stl.py b/python/stl.py index 9ef75a57..032f2b69 100644 --- a/python/stl.py +++ b/python/stl.py @@ -1,6 +1,5 @@ -import libngpy -from libngpy._stl import * -from libngpy._meshing import MeshingParameters +from netgen.libngpy._stl import * +from netgen.libngpy._meshing import MeshingParameters def stl_meshing_func (geom, **args): diff --git a/tests/docker_15.10 b/tests/docker_15.10 index a88f5673..b386f250 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 tk-dev tcl-dev cmake git g++ libglu1-mesa-dev ccache python3-pytest python3-numpy +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 python3-tk ADD . /root/src/netgen diff --git a/tests/docker_16.04 b/tests/docker_16.04 index a1fe001e..2195714b 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 tk-dev tcl-dev cmake git g++ libglu1-mesa-dev ccache python3-pytest python3-numpy +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 python3-tk ADD . /root/src/netgen diff --git a/tests/pytest/test_gui.py b/tests/pytest/test_gui.py new file mode 100644 index 00000000..6e32488f --- /dev/null +++ b/tests/pytest/test_gui.py @@ -0,0 +1,11 @@ +import netgen +import pytest + +def test_gui(): + try: + from tkinter import Tk + win = Tk() + except: + pytest.skip("can't create a window") + import netgen.gui + diff --git a/tutorials/CMakeLists.txt b/tutorials/CMakeLists.txt index 0fea9d39..a2e70a6d 100644 --- a/tutorials/CMakeLists.txt +++ b/tutorials/CMakeLists.txt @@ -7,6 +7,6 @@ install( FILES twobricks.geo twocubes.geo twocyl.geo boundarycondition.geo hinge.stl part1.stl frame.step screw.step squarehole.in2d squarecircle.in2d square.in2d - DESTINATION share/netgen + DESTINATION ${NG_INSTALL_DIR_RES}/${NG_INSTALL_SUFFIX} COMPONENT netgen_tutorial ) From cbf36efbd3462f8fb943000b2318c7d889c9757e Mon Sep 17 00:00:00 2001 From: Matthias Hochsteger Date: Tue, 30 May 2017 00:03:22 +0200 Subject: [PATCH 47/63] Fixes in NetgenConfig.cmake --- cmake/NetgenConfig.cmake.in | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/cmake/NetgenConfig.cmake.in b/cmake/NetgenConfig.cmake.in index 9cfa7da7..fb66c205 100644 --- a/cmake/NetgenConfig.cmake.in +++ b/cmake/NetgenConfig.cmake.in @@ -6,7 +6,7 @@ set(NETGEN_DIR "${NETGEN_CMAKE_DIR}/@NETGEN_DIR@") set(NETGEN_COMPILE_DEFINITIONS "@NETGEN_COMPILE_DEFINITIONS@") -set(NETGEN_INCLUDE_DIR "${NETGEN_CMAKE_DIR}/@NETGEN_INCLUDE_DIR@/include;${NETGEN_CMAKE_DIR}/@NETGEN_INCLUDE_DIR@") +set(NETGEN_INCLUDE_DIR "${NETGEN_CMAKE_DIR}/@NETGEN_INCLUDE_DIR@") set(NETGEN_BINARY_DIR "${NETGEN_CMAKE_DIR}/@NETGEN_BINARY_DIR@") set(NETGEN_LIBRARY_DIR "${NETGEN_CMAKE_DIR}/@NETGEN_LIBRARY_DIR@") set(NETGEN_PYTHON_DIR "${NETGEN_CMAKE_DIR}/@NETGEN_PYTHON_DIR@") @@ -14,6 +14,7 @@ set(NETGEN_RESOURCE_DIR "${NETGEN_CMAKE_DIR}/@NETGEN_RESOURCE_DIR@") set(NETGEN_SOURCE_DIR "@PROJECT_SOURCE_DIR@") +set(NETGEN_INCLUDE_DIRS "${NETGEN_CMAKE_DIR}/@NETGEN_INCLUDE_DIR@/include;${NETGEN_CMAKE_DIR}/@NETGEN_INCLUDE_DIR@") set(NETGEN_CMAKE_THREAD_LIBS_INIT "@CMAKE_THREAD_LIBS_INIT@") set(NETGEN_FFMPEG_LIBRARIES "@FFMPEG_LIBRARIES@") set(NETGEN_JPEG_INCLUDE_DIR "@JPEG_INCLUDE_DIR@") @@ -29,11 +30,9 @@ set(NETGEN_OCC_LIBRARIES_BIN "@OCC_LIBRARIES_BIN@") set(NETGEN_OCC_LIBRARIES "@OCC_LIBRARIES@") set(NETGEN_OCC_LIBRARY_DIR "@OCC_LIBRARY_DIR@") set(NETGEN_OPENGL_LIBRARIES "@OPENGL_LIBRARIES@") -set(NETGEN_PYBIND_INCLUDE_DIR "@CMAKE_INSTALL_PREFIX@/include") set(NETGEN_PYTHON_EXECUTABLE "@PYTHON_EXECUTABLE@") set(NETGEN_PYTHON_INCLUDE_DIRS "@PYTHON_INCLUDE_DIRS@") set(NETGEN_PYTHON_LIBRARIES "@PYTHON_LIBRARIES@") -set(NETGEN_PYTHON_PACKAGES_INSTALL_DIR "@PYTHON_PACKAGES_INSTALL_DIR@") set(NETGEN_TCL_INCLUDE_PATH "@TCL_INCLUDE_PATH@") set(NETGEN_TCL_LIBRARY "@TCL_LIBRARY@") set(NETGEN_TK_DND_LIBRARY "@TK_DND_LIBRARY@") @@ -54,5 +53,8 @@ set(NETGEN_INTEL_MIC @INTEL_MIC@) set(NETGEN_INSTALL_PROFILES @INSTALL_PROFILES@) set(NETGEN_USE_CCACHE @USE_CCACHE@) +set(NETGEN_PYTHON_RPATH "@NETGEN_PYTHON_RPATH@") +set(NETGEN_RPATH_TOKEN "@NG_RPATH_TOKEN@") + include(${CMAKE_CURRENT_LIST_DIR}/netgen-targets.cmake) message(STATUS "Found Netgen: ${CMAKE_CURRENT_LIST_DIR}") From 97f4c17d96fadf1c7f57c7a5b50571a197f1e51f Mon Sep 17 00:00:00 2001 From: Matthias Hochsteger Date: Tue, 30 May 2017 08:38:48 +0200 Subject: [PATCH 48/63] Fix default install dir for cmake files --- CMakeLists.txt | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 53b67bde..d0946816 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -108,10 +108,12 @@ include_directories ("${PROJECT_BINARY_DIR}") set(CMAKE_INCLUDE_CURRENT_DIR ON) +set(NG_INSTALL_SUFFIX netgen CACHE STRING "Suffix appended to install directories (project name)") + if(APPLE) set(NG_INSTALL_DIR_BIN_DEFAULT Contents/MacOS) set(NG_INSTALL_DIR_LIB_DEFAULT Contents/MacOS) - set(NG_INSTALL_DIR_CMAKE_DEFAULT Contents/Resources/share/cmake) + set(NG_INSTALL_DIR_CMAKE_DEFAULT Contents/Resources/CMake) set(NG_INSTALL_DIR_PYTHON_DEFAULT Contents/Resources/${PYTHON_PACKAGES_INSTALL_DIR}) set(NG_INSTALL_DIR_RES_DEFAULT Contents/Resources/share) set(NG_INSTALL_DIR_INCLUDE_DEFAULT Contents/Resources/include) @@ -120,7 +122,11 @@ if(APPLE) else(APPLE) set(NG_INSTALL_DIR_BIN_DEFAULT bin) set(NG_INSTALL_DIR_LIB_DEFAULT lib) - set(NG_INSTALL_DIR_CMAKE_DEFAULT lib/cmake) + if(WIN32) + set(NG_INSTALL_DIR_CMAKE_DEFAULT cmake) + else(WIN32) + set(NG_INSTALL_DIR_CMAKE_DEFAULT lib/cmake/${NG_INSTALL_SUFFIX}) + endif(WIN32) set(NG_INSTALL_DIR_PYTHON_DEFAULT ${PYTHON_PACKAGES_INSTALL_DIR}) set(NG_INSTALL_DIR_RES_DEFAULT share) set(NG_INSTALL_DIR_INCLUDE_DEFAULT include) @@ -128,7 +134,6 @@ else(APPLE) set(NG_RPATH_TOKEN "\$ORIGIN") endif(APPLE) -set(NG_INSTALL_SUFFIX netgen CACHE STRING "Suffix appended to install directories (project name)") set(NG_INSTALL_DIR_PYTHON ${NG_INSTALL_DIR_PYTHON_DEFAULT} CACHE STRING "Install directory for Python files") set(NG_INSTALL_DIR_BIN ${NG_INSTALL_DIR_BIN_DEFAULT} CACHE STRING "Install directory for executables") set(NG_INSTALL_DIR_LIB ${NG_INSTALL_DIR_LIB_DEFAULT} CACHE STRING "Install directory for libraries") From 76e6aaecb154c95637ed63ccb27d73006aa2ed0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20Sch=C3=B6berl?= Date: Wed, 31 May 2017 07:52:45 +0200 Subject: [PATCH 49/63] use size_t to avoid int-narrowing --- libsrc/include/nginterface_v2.hpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/libsrc/include/nginterface_v2.hpp b/libsrc/include/nginterface_v2.hpp index ca72a3f1..13d427f8 100644 --- a/libsrc/include/nginterface_v2.hpp +++ b/libsrc/include/nginterface_v2.hpp @@ -106,7 +106,7 @@ namespace netgen double * pt; public: Ng_Point (double * apt) : pt(apt) { ; } - double operator[] (int i) + double operator[] (size_t i) { return pt[i]; } operator const double * () { return pt; } }; @@ -122,11 +122,11 @@ namespace netgen class Ng_Elements { public: - int ne; + size_t ne; const int * ptr; - int Size() const { return ne; } - int operator[] (int i) const { return ptr[i]; } + size_t Size() const { return ne; } + int operator[] (size_t i) const { return ptr[i]; } }; @@ -146,8 +146,8 @@ namespace netgen public: const int * ptr; - int Size() const { return 2; } - int operator[] (int i) const { return ptr[i]-POINTINDEX_BASE; } + size_t Size() const { return 2; } + int operator[] (size_t i) const { return ptr[i]-POINTINDEX_BASE; } }; @@ -163,21 +163,21 @@ namespace netgen class Ng_Vertices { public: - int nv; + size_t nv; const int * ptr; - int Size() const { return nv; } - int operator[] (int i) const { return ptr[i]-POINTINDEX_BASE; } + size_t Size() const { return nv; } + int operator[] (size_t i) const { return ptr[i]-POINTINDEX_BASE; } }; class Ng_Edges { public: - int ned; + size_t ned; const int * ptr; - int Size() const { return ned; } - int operator[] (int i) const { return ptr[i]-1; } + size_t Size() const { return ned; } + int operator[] (size_t i) const { return ptr[i]-1; } }; From feb74d49c2afbf15707a2e78b836b1402c792432 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20Sch=C3=B6berl?= Date: Wed, 31 May 2017 07:53:24 +0200 Subject: [PATCH 50/63] use static class variable rather then static function variable --- libsrc/meshing/meshclass.cpp | 1 + libsrc/meshing/meshclass.hpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/libsrc/meshing/meshclass.cpp b/libsrc/meshing/meshclass.cpp index 356192fc..a40deef9 100644 --- a/libsrc/meshing/meshclass.cpp +++ b/libsrc/meshing/meshclass.cpp @@ -5768,6 +5768,7 @@ namespace netgen materials.Elem(domnr) = new string(mat); } + string Mesh :: defaultmat = "default"; const string & Mesh :: GetMaterial (int domnr) const { if (domnr <= materials.Size()) diff --git a/libsrc/meshing/meshclass.hpp b/libsrc/meshing/meshclass.hpp index 40d8ebb4..4cf9c605 100644 --- a/libsrc/meshing/meshclass.hpp +++ b/libsrc/meshing/meshclass.hpp @@ -593,9 +593,9 @@ namespace netgen DLL_HEADER void SetMaterial (int domnr, const string & mat); /// const string & GetMaterial (int domnr) const; + static string defaultmat; const string * GetMaterialPtr (int domnr) const // 1-based { - static string defaultmat = "default"; return domnr <= materials.Size() ? materials.Get(domnr) : &defaultmat; } From a22e36f182cb331d9c8d1d0b6479f67a9fe1c134 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20Sch=C3=B6berl?= Date: Wed, 31 May 2017 07:53:50 +0200 Subject: [PATCH 51/63] fix bug for debug output --- libsrc/meshing/topology.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libsrc/meshing/topology.cpp b/libsrc/meshing/topology.cpp index 9d7961d5..83ed7aed 100644 --- a/libsrc/meshing/topology.cpp +++ b/libsrc/meshing/topology.cpp @@ -1119,8 +1119,8 @@ namespace netgen (*testout) << "points = " << face2vert[i] << endl; (*testout) << "pos = "; for (int j = 0; j < 4; j++) - if (face2vert[i].I(j+1) >= 1) - (*testout) << mesh[(PointIndex)face2vert[i].I(j+1)] << " "; + if (face2vert[i].I(j+1) >= 1) + (*testout) << (*mesh)[(PointIndex)face2vert[i].I(j+1)] << " "; (*testout) << endl; FlatArray vertels = GetVertexElements (face2vert[i].I(1)); From 9324121953bb33e13b9050657b9ef63680fadfae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20Sch=C3=B6berl?= Date: Wed, 31 May 2017 07:54:12 +0200 Subject: [PATCH 52/63] smaller int-type for GetNV --- libsrc/meshing/meshtype.hpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libsrc/meshing/meshtype.hpp b/libsrc/meshing/meshtype.hpp index 129e1fce..6bca8233 100644 --- a/libsrc/meshing/meshtype.hpp +++ b/libsrc/meshing/meshtype.hpp @@ -680,7 +680,7 @@ namespace netgen /// int GetNP () const { return np; } /// - short int GetNV() const + uint8_t GetNV() const { __assume(typ >= TET && typ <= HEX); switch (typ) @@ -699,7 +699,8 @@ namespace netgen #ifdef DEBUG PrintSysError ("Element3d::GetNV not implemented for typ ", typ); #endif - return -1; + __assume(false); + return -1; } } From ed453a5fbc74673ba2ea08c1525e791e67b8cb20 Mon Sep 17 00:00:00 2001 From: Matthias Hochsteger Date: Wed, 31 May 2017 14:09:48 +0200 Subject: [PATCH 53/63] CMake - export install dir settings --- cmake/NetgenConfig.cmake.in | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/cmake/NetgenConfig.cmake.in b/cmake/NetgenConfig.cmake.in index fb66c205..71447d6e 100644 --- a/cmake/NetgenConfig.cmake.in +++ b/cmake/NetgenConfig.cmake.in @@ -56,5 +56,12 @@ set(NETGEN_USE_CCACHE @USE_CCACHE@) set(NETGEN_PYTHON_RPATH "@NETGEN_PYTHON_RPATH@") set(NETGEN_RPATH_TOKEN "@NG_RPATH_TOKEN@") +set(NETGEN_INSTALL_DIR_PYTHON @NG_INSTALL_DIR_PYTHON@) +set(NETGEN_INSTALL_DIR_BIN @NG_INSTALL_DIR_BIN@) +set(NETGEN_INSTALL_DIR_LIB @NG_INSTALL_DIR_LIB@) +set(NETGEN_INSTALL_DIR_INCLUDE @NG_INSTALL_DIR_INCLUDE@) +set(NETGEN_INSTALL_DIR_CMAKE @NG_INSTALL_DIR_CMAKE@) +set(NETGEN_INSTALL_DIR_RES @NG_INSTALL_DIR_RES@) + include(${CMAKE_CURRENT_LIST_DIR}/netgen-targets.cmake) message(STATUS "Found Netgen: ${CMAKE_CURRENT_LIST_DIR}") From 0c611c339cfc51cfca0f4de06556f030641b6a23 Mon Sep 17 00:00:00 2001 From: Matthias Hochsteger Date: Wed, 31 May 2017 19:38:17 +0200 Subject: [PATCH 54/63] Python opencascade interface (by Gerhard Kitzler) --- libsrc/occ/CMakeLists.txt | 2 +- libsrc/occ/occgenmesh.cpp | 13 +++++++ libsrc/occ/occgeom.cpp | 77 ++++++++++++++++++++++++++++++++++++++- libsrc/occ/occgeom.hpp | 2 +- libsrc/occ/python_occ.cpp | 56 ++++++++++++++++++++++++++++ ng/netgenpy.cpp | 3 ++ python/CMakeLists.txt | 2 +- python/NgOCC.py | 11 ++++++ 8 files changed, 161 insertions(+), 5 deletions(-) create mode 100644 libsrc/occ/python_occ.cpp create mode 100644 python/NgOCC.py diff --git a/libsrc/occ/CMakeLists.txt b/libsrc/occ/CMakeLists.txt index 831f2e6b..2f10e54e 100644 --- a/libsrc/occ/CMakeLists.txt +++ b/libsrc/occ/CMakeLists.txt @@ -2,7 +2,7 @@ add_definitions(-DNGINTERFACE_EXPORTS) add_library(occ ${NG_LIB_TYPE} Partition_Inter2d.cxx Partition_Inter3d.cxx Partition_Loop.cxx Partition_Loop2d.cxx Partition_Loop3d.cxx Partition_Spliter.cxx - occconstruction.cpp occgenmesh.cpp occgeom.cpp occmeshsurf.cpp + occconstruction.cpp occgenmesh.cpp occgeom.cpp occmeshsurf.cpp python_occ.cpp ) add_library(occvis ${NG_LIB_TYPE} vsocc.cpp) diff --git a/libsrc/occ/occgenmesh.cpp b/libsrc/occ/occgenmesh.cpp index 1530a31e..2ce29d7b 100644 --- a/libsrc/occ/occgenmesh.cpp +++ b/libsrc/occ/occgenmesh.cpp @@ -417,10 +417,14 @@ namespace netgen && (geom.face_colours->GetColor(face,XCAFDoc_ColorSurf,face_colour))) { mesh.GetFaceDescriptor(facenr).SetSurfColour(Vec3d(face_colour.Red(),face_colour.Green(),face_colour.Blue())); + mesh.GetFaceDescriptor(facenr).SetBCName(&geom.fnames[facenr-1]); + mesh.GetFaceDescriptor(facenr).SetBCProperty(facenr); } else { mesh.GetFaceDescriptor(facenr).SetSurfColour(Vec3d(0.0,1.0,0.0)); + mesh.GetFaceDescriptor(facenr).SetBCName(&geom.fnames[facenr-1]); + mesh.GetFaceDescriptor(facenr).SetBCProperty(facenr); } // ACHTUNG! STIMMT NICHT ALLGEMEIN (RG) @@ -974,6 +978,13 @@ namespace netgen NgProfiler::StopTimer (timer_opt2d); multithread.task = savetask; + + // Gerhard BEGIN + for(int i = 0; iGetNSeg(); i++) (*testout) << mesh->LineSegment(i) << endl; + for (int i = 0; i < mesh->GetNDomains(); i++) + mesh->SetMaterial (i+1, geom.snames[i]); return TCL_OK; } } diff --git a/libsrc/occ/occgeom.cpp b/libsrc/occ/occgeom.cpp index 3ffaf376..1d8e86d8 100644 --- a/libsrc/occ/occgeom.cpp +++ b/libsrc/occ/occgeom.cpp @@ -17,6 +17,10 @@ #include "Partition_Spliter.hxx" #include "BRepAlgoAPI_Fuse.hxx" +#include "XSControl_WorkSession.hxx" +#include "XSControl_TransferReader.hxx" +#include "StepRepr_RepresentationItem.hxx" + #ifndef _Standard_Version_HeaderFile #include #endif @@ -29,6 +33,44 @@ namespace netgen { +void STEP_GetEntityName(const TopoDS_Shape & theShape, STEPCAFControl_Reader * aReader, char * acName) +{ + const Handle(XSControl_WorkSession)& theSession = aReader->Reader().WS(); + const Handle(XSControl_TransferReader)& aTransferReader = + theSession->TransferReader(); + + Handle(Standard_Transient) anEntity = + aTransferReader->EntityFromShapeResult(theShape, 1); + + if (anEntity.IsNull()) { + // as just mapped + anEntity = aTransferReader->EntityFromShapeResult (theShape,-1); + } + + if (anEntity.IsNull()) { + // as anything + anEntity = aTransferReader->EntityFromShapeResult (theShape,4); + } + + if (anEntity.IsNull()) { + cout<<"Warning: XSInterVertex_STEPReader::ReadAttributes()\nentity not found"<Name()->ToCString()); + } +} + + void OCCGeometry :: PrintNrShapes () { TopExp_Explorer e; @@ -1169,7 +1211,7 @@ namespace netgen // Enable transfer of colours reader.SetColorMode(Standard_True); - + reader.SetNameMode(Standard_True); Standard_Integer stat = reader.ReadFile((char*)filename); if(stat != IFSelect_RetDone) @@ -1210,7 +1252,38 @@ namespace netgen occgeo->CalcBoundingBox(); PrintContents (occgeo); - + char * name = new char(50); + //string name; + STEP_GetEntityName(occgeo->shape,&reader,name); + occgeo->snames.Append(name); + TopExp_Explorer exp0,exp1; + + for (exp0.Init(occgeo->shape, TopAbs_FACE); exp0.More(); exp0.Next()) + { + TopoDS_Face face = TopoDS::Face(exp0.Current()); + STEP_GetEntityName(face,&reader,name); + occgeo->fnames.Append(name); + for (exp1.Init(face, TopAbs_EDGE); exp1.More(); exp1.Next()) + { + TopoDS_Edge edge = TopoDS::Edge(exp1.Current()); + STEP_GetEntityName(edge,&reader,name); + occgeo->enames.Append(name); + } + } + // Gerhard BEGIN +// cout << "Solid Names: "<snames.Size();i++) +// cout << occgeo->snames[i] << endl; +// cout << " " <fnames.Size();i++) +// cout << occgeo->fnames[i] << endl; +// cout << " " <enames.Size();i++) +// cout << occgeo->enames[i] << endl; +// cout << " " < fsingular, esingular, vsingular; Box<3> boundingbox; - + Array fnames, enames, snames; // Philippose - 29/01/2009 // OpenCascade XDE Support // XCAF Handle to make the face colours available to the rest of diff --git a/libsrc/occ/python_occ.cpp b/libsrc/occ/python_occ.cpp new file mode 100644 index 00000000..0cb2454a --- /dev/null +++ b/libsrc/occ/python_occ.cpp @@ -0,0 +1,56 @@ +#ifdef NG_PYTHON +#ifdef OCCGEOMETRY + +#include <../general/ngpython.hpp> + +#include +#include + +using namespace netgen; + +namespace netgen +{ + extern std::shared_ptr ng_geometry; +} + + +DLL_HEADER void ExportNgOCC(py::module &m) +{ + py::class_> (m, "OCCGeometry") + .def(py::init<>()) + ; + m.def("LoadOCCGeometry",FunctionPointer([] (const string & filename) + { + cout << "load OCC geometry"; + ifstream ist(filename); + OCCGeometry * instance = new OCCGeometry(); + instance = LoadOCC_STEP(filename.c_str()); + return shared_ptr(instance, NOOP_Deleter); + })); + m.def("GenerateMesh", FunctionPointer([] (shared_ptr geo, MeshingParameters ¶m) + { + auto mesh = make_shared(); + SetGlobalMesh(mesh); + mesh->SetGeometry(geo); + ng_geometry = geo; + try + { + geo->GenerateMesh(mesh,param); + } + catch (NgException ex) + { + cout << "Caught NgException: " << ex.What() << endl; + } + return mesh; + })) + ; +} + +PYBIND11_PLUGIN(libNgOCC) { + py::module m("NgOCC", "pybind NgOCC"); + ExportNgOCC(m); + return m.ptr(); +} + +#endif // OCCGEOMETRY +#endif // NG_PYTHON diff --git a/ng/netgenpy.cpp b/ng/netgenpy.cpp index e4ea7aac..e18e1f4d 100644 --- a/ng/netgenpy.cpp +++ b/ng/netgenpy.cpp @@ -17,6 +17,7 @@ void DLL_HEADER ExportCSGVis(py::module &m); void DLL_HEADER ExportGeom2d(py::module &m); void DLL_HEADER ExportSTL(py::module &m); void DLL_HEADER ExportSTLVis(py::module &m); +void DLL_HEADER ExportNgOCC(py::module &m); PYBIND11_PLUGIN(libngpy) { @@ -29,6 +30,8 @@ PYBIND11_PLUGIN(libngpy) ExportGeom2d(geom2d); py::module stl = ngpy.def_submodule("_stl", "pybind stl module"); ExportSTL(stl); + py::module NgOCC = ngpy.def_submodule("_NgOCC", "pybind NgOCC module"); + ExportNgOCC(NgOCC); #ifdef OPENGL py::module meshvis = ngpy.def_submodule("meshvis", "pybind meshvis module"); ExportMeshVis(meshvis); diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index 5f9c785a..72912b24 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -2,7 +2,7 @@ configure_file(__init__.py ${CMAKE_CURRENT_BINARY_DIR}/__init__.py @ONLY) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/__init__.py - meshing.py csg.py geom2d.py stl.py gui.py + meshing.py csg.py geom2d.py stl.py gui.py NgOCC.py DESTINATION ${NG_INSTALL_DIR_PYTHON}/${NG_INSTALL_SUFFIX} COMPONENT netgen ) diff --git a/python/NgOCC.py b/python/NgOCC.py new file mode 100644 index 00000000..118bc1e4 --- /dev/null +++ b/python/NgOCC.py @@ -0,0 +1,11 @@ +import libngpy +from libngpy._NgOCC import * +from libngpy._meshing import MeshingParameters + +def NgOCC_meshing_func (geom, **args): + if "mp" in args: + return GenerateMesh (geom, args["mp"]) + else: + return GenerateMesh (geom, MeshingParameters (**args)) + +OCCGeometry.GenerateMesh = NgOCC_meshing_func From c9ac332971091718e201e665181a54d1a04cac52 Mon Sep 17 00:00:00 2001 From: Matthias Hochsteger Date: Wed, 31 May 2017 19:57:42 +0200 Subject: [PATCH 55/63] Export OCC module only when configured with OCC --- ng/netgenpy.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ng/netgenpy.cpp b/ng/netgenpy.cpp index e18e1f4d..6cbeba60 100644 --- a/ng/netgenpy.cpp +++ b/ng/netgenpy.cpp @@ -17,7 +17,9 @@ void DLL_HEADER ExportCSGVis(py::module &m); void DLL_HEADER ExportGeom2d(py::module &m); void DLL_HEADER ExportSTL(py::module &m); void DLL_HEADER ExportSTLVis(py::module &m); +#ifdef OCCGEOMETRY void DLL_HEADER ExportNgOCC(py::module &m); +#endif // OCCGEOMETRY PYBIND11_PLUGIN(libngpy) { @@ -30,8 +32,10 @@ PYBIND11_PLUGIN(libngpy) ExportGeom2d(geom2d); py::module stl = ngpy.def_submodule("_stl", "pybind stl module"); ExportSTL(stl); +#ifdef OCCGEOMETRY py::module NgOCC = ngpy.def_submodule("_NgOCC", "pybind NgOCC module"); ExportNgOCC(NgOCC); +#endif // OCCGEOMETRY #ifdef OPENGL py::module meshvis = ngpy.def_submodule("meshvis", "pybind meshvis module"); ExportMeshVis(meshvis); From e8712aa8ae7c82afee793da8fd248cfc29a58c2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20Sch=C3=B6berl?= Date: Wed, 31 May 2017 23:44:50 +0200 Subject: [PATCH 56/63] export Mesh.SecondOrder --- libsrc/meshing/python_mesh.cpp | 17 +++++++++++++++++ py_tutorials/exportNeutral.py | 4 ++-- py_tutorials/mesh.py | 3 ++- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/libsrc/meshing/python_mesh.cpp b/libsrc/meshing/python_mesh.cpp index 774aae17..90037fd5 100644 --- a/libsrc/meshing/python_mesh.cpp +++ b/libsrc/meshing/python_mesh.cpp @@ -237,6 +237,14 @@ DLL_HEADER void ExportNetgenMeshing(py::module &m) li.append (py::cast(self[i])); return li; })) + .def_property_readonly("points", + FunctionPointer ([](const Element & self) -> py::list + { + py::list li; + for (int i = 0; i < self.GetNP(); i++) + li.append (py::cast(self[i])); + return li; + })) ; py::class_(m, "Element2D") @@ -601,6 +609,15 @@ DLL_HEADER void ExportNetgenMeshing(py::module &m) Refinement().Refine(self); })) + .def ("SecondOrder", FunctionPointer + ([](Mesh & self) + { + if (self.GetGeometry()) + self.GetGeometry()->GetRefinement().MakeSecondOrder(self); + else + Refinement().MakeSecondOrder(self); + })) + .def ("SetGeometry", FunctionPointer ([](Mesh & self, shared_ptr geo) { diff --git a/py_tutorials/exportNeutral.py b/py_tutorials/exportNeutral.py index ad58ea41..5ed1928f 100644 --- a/py_tutorials/exportNeutral.py +++ b/py_tutorials/exportNeutral.py @@ -17,8 +17,8 @@ def Export (mesh, filename): print (len(volels), file=f) for el in volels: print (el.index, end=" ", file=f) - for j in el.vertices: - print (j.nr, end=" ", file=f) + for p in el.points: + print (p.nr, end=" ", file=f) print(file=f) diff --git a/py_tutorials/mesh.py b/py_tutorials/mesh.py index 1337a23a..c4937395 100644 --- a/py_tutorials/mesh.py +++ b/py_tutorials/mesh.py @@ -8,7 +8,7 @@ param.maxh = 10 print (param) m1 = GenerateMesh (geo, param) - +m1.SecondOrder() import exportNeutral exportNeutral.Export (m1, "shaft.mesh") @@ -16,3 +16,4 @@ exportNeutral.Export (m1, "shaft.mesh") Save (m1, "mesh.vol", geo) + From cb3af7ab555a13ab87d96f47265365d17ca6cf04 Mon Sep 17 00:00:00 2001 From: Matthias Hochsteger Date: Thu, 1 Jun 2017 10:15:25 +0200 Subject: [PATCH 57/63] Remove config.h --- CMakeLists.txt | 7 +++++-- config.h.cmake | 2 -- libsrc/include/mystdlib.h | 5 ----- 3 files changed, 5 insertions(+), 9 deletions(-) delete mode 100644 config.h.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index d0946816..653cbbb4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -170,8 +170,11 @@ set(CMAKE_INSTALL_RPATH "${NG_RPATH_TOKEN};${NG_RPATH_TOKEN}/${NETGEN_RPATH}") include (CheckIncludeFiles) check_include_files (dlfcn.h HAVE_DLFCN_H) -configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h) -add_definitions(-DHAVE_CONFIG_H) +if(HAVE_DLFCN_H) + add_definitions(-DHAVE_DLFCN_H) +endif() +add_definitions(-DPACKAGE_VERSION="${NETGEN_VERSION}") + include_directories(BEFORE ${CMAKE_CURRENT_BINARY_DIR}) ####################################################################### diff --git a/config.h.cmake b/config.h.cmake deleted file mode 100644 index 7dfa079d..00000000 --- a/config.h.cmake +++ /dev/null @@ -1,2 +0,0 @@ -#cmakedefine HAVE_DLFCN_H 1 -#define PACKAGE_VERSION "${NETGEN_VERSION}" diff --git a/libsrc/include/mystdlib.h b/libsrc/include/mystdlib.h index 5cbaca61..b4a049a7 100644 --- a/libsrc/include/mystdlib.h +++ b/libsrc/include/mystdlib.h @@ -1,11 +1,6 @@ #ifndef FILE_MYSTDLIB #define FILE_MYSTDLIB -#ifdef HAVE_CONFIG_H -#include -#endif - - #include #include #include From 6e316bb3d0e93382a4720454972569313b380efa Mon Sep 17 00:00:00 2001 From: Christoph Wintersteiger Date: Thu, 1 Jun 2017 17:04:21 +0200 Subject: [PATCH 58/63] move comments to py_tutorial file and use it for the documentation --- py_tutorials/merge.py | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/py_tutorials/merge.py b/py_tutorials/merge.py index 931d095a..abacd38e 100644 --- a/py_tutorials/merge.py +++ b/py_tutorials/merge.py @@ -3,28 +3,35 @@ from netgen.csg import * from ngsolve import ngsglobals ngsglobals.msg_level = 2 - +# generate brick and mesh it geo1 = CSGeometry() geo1.Add (OrthoBrick( Pnt(0,0,0), Pnt(1,1,1) )) m1 = geo1.GenerateMesh (maxh=0.1) m1.Refine() -m1.Refine() - +# generate sphere and mesh it geo2 = CSGeometry() geo2.Add (Sphere (Pnt(0.5,0.5,0.5), 0.1)) m2 = geo2.GenerateMesh (maxh=0.05) m2.Refine() m2.Refine() -print ("********************") -print ("** start merging **") -print ("********************") +print ("***************************") +print ("** merging suface meshes **") +print ("***************************") +# create an empty mesh mesh = Mesh() -fd_outside = mesh.Add (FaceDescriptor(surfnr=1,domin=1)) -fd_inside = mesh.Add (FaceDescriptor(surfnr=2,domin=2,domout=1)) +# a face-descriptor stores properties associated with a set of surface elements +# bc .. boundary condition marker, +# domin/domout .. domain-number in front/back of surface elements (0 = void), +# surfnr .. number of the surface described by the face-descriptor + +fd_outside = mesh.Add (FaceDescriptor(bc=1,domin=1,surfnr=1)) +fd_inside = mesh.Add (FaceDescriptor(bc=2,domin=2,domout=1,surfnr=2)) +# copy all boundary points from first mesh to new mesh. +# pmap1 maps point-numbers from old to new mesh pmap1 = { } for e in m1.Elements2D(): @@ -32,11 +39,17 @@ for e in m1.Elements2D(): if (v not in pmap1): pmap1[v] = mesh.Add (m1[v]) + +# copy surface elements from first mesh to new mesh +# we have to map point-numbers: + for e in m1.Elements2D(): mesh.Add (Element2D (fd_outside, [pmap1[v] for v in e.vertices])) +# same for the second mesh: + pmap2 = { } for e in m2.Elements2D(): for v in e.vertices: From 7178cc1b7331a585222401ee5edfb86b2b542f35 Mon Sep 17 00:00:00 2001 From: Christoph Wintersteiger Date: Thu, 1 Jun 2017 17:08:07 +0200 Subject: [PATCH 59/63] fix MultiElementTransformation<1,3> for SIMD --- libsrc/interface/nginterface_v2.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libsrc/interface/nginterface_v2.cpp b/libsrc/interface/nginterface_v2.cpp index d95f71e1..550ce1a8 100644 --- a/libsrc/interface/nginterface_v2.cpp +++ b/libsrc/interface/nginterface_v2.cpp @@ -757,7 +757,7 @@ namespace netgen double hdxdxi[4][3]; for (int j = 0; j<4;j++) hxi[j][0] = ((double*)&(xi[0]))[j]; - MultiElementTransformation<1,3> (elnr, 4, &hxi[0][0], 1, &hx[0][0], 2, &hdxdxi[0][0],4); + MultiElementTransformation<1,3> (elnr, 4, &hxi[0][0], 1, &hx[0][0], 3, &hdxdxi[0][0],3); for(int j=0; j<4; j++) for(int k=0; k<3; k++) ((double*)&(x[k]))[j] = hx[j][k]; From 892b391ad3545e2f803d2ae5b396856d3643f1d8 Mon Sep 17 00:00:00 2001 From: Christoph Wintersteiger Date: Thu, 1 Jun 2017 17:09:02 +0200 Subject: [PATCH 60/63] add boundary condition and maxh to base of SplineSurface --- libsrc/csg/python_csg.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libsrc/csg/python_csg.cpp b/libsrc/csg/python_csg.cpp index 5c43e23e..c85480da 100644 --- a/libsrc/csg/python_csg.cpp +++ b/libsrc/csg/python_csg.cpp @@ -441,6 +441,9 @@ DLL_HEADER void ExportCSG(py::module &m) } spsol->AddSurfaces(self); int tlonr = self.SetTopLevelObject(spsol->GetSolid(), surf.get()); + self.GetTopLevelObject(tlonr) -> SetBCProp(surf->GetBase()->GetBCProperty()); + self.GetTopLevelObject(tlonr) -> SetBCName(surf->GetBase()->GetBCName()); + self.GetTopLevelObject(tlonr) -> SetMaxH(surf->GetBase()->GetMaxH()); for(auto p : surf->GetPoints()) self.AddUserPoint(p); self.AddSplineSurface(surf); From e68333ee00ef0a5665076a4b3fb6fd8c789f767e Mon Sep 17 00:00:00 2001 From: Matthias Hochsteger Date: Thu, 1 Jun 2017 17:28:11 +0200 Subject: [PATCH 61/63] Search for ngsolve.tcl in PATH (after NETGENDIR) --- ng/ng.tcl | 17 ++++++++++++++++- ng/onetcl.cpp | 15 ++++++++++++++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/ng/ng.tcl b/ng/ng.tcl index 003b745c..7343eae0 100644 --- a/ng/ng.tcl +++ b/ng/ng.tcl @@ -269,7 +269,22 @@ if { $stereo == "defined" } { } -catch { source ${ngdir}/ngsolve.tcl } +set ngsolve_loaded 0 +catch { + source ${ngdir}/ngsolve.tcl; + set ngsolve_loaded 1 +} + +# try to find ngsolve.tcl in PATH +set pathlist [split $::env(PATH) \ [expr {$::tcl_platform(platform) == "windows" ? ";" : ":"}]] +foreach dir $pathlist { + if { $ngsolve_loaded != 1 } { + catch { + source ${dir}/ngsolve.tcl + set ngsolve_loaded 1 + } + } +} set scriptfilename [Ng_GetCommandLineParameter script] diff --git a/ng/onetcl.cpp b/ng/onetcl.cpp index 53348262..4eec1ab2 100644 --- a/ng/onetcl.cpp +++ b/ng/onetcl.cpp @@ -5948,7 +5948,20 @@ const char * ngscript[] = {"" ,"Ng_SetVisParameters;\n" ,"redraw\n" ,"}\n" -,"catch { source ${ngdir}/ngsolve.tcl }\n" +,"set ngsolve_loaded 0\n" +,"catch {\n" +,"source ${ngdir}/ngsolve.tcl;\n" +,"set ngsolve_loaded 1\n" +,"}\n" +,"set pathlist [split $::env(PATH) \\ [expr {$::tcl_platform(platform) == \"windows\" ? \";\" : \":\"}]]\n" +,"foreach dir $pathlist {\n" +,"if { $ngsolve_loaded != 1 } {\n" +,"catch {\n" +,"source ${dir}/ngsolve.tcl\n" +,"set ngsolve_loaded 1\n" +,"}\n" +,"}\n" +,"}\n" ,"set scriptfilename [Ng_GetCommandLineParameter script]\n" ,"if { $scriptfilename != \"undefined\" } {\n" ,"if { [catch { source $scriptfilename } errstring] == 1 } {\n" From 41e62e58a433d5953faa42d01c30b8a4827ae8e3 Mon Sep 17 00:00:00 2001 From: Matthias Hochsteger Date: Fri, 2 Jun 2017 14:15:31 +0200 Subject: [PATCH 62/63] OCC: Set BC Names/Materials only when available --- libsrc/occ/occgenmesh.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/libsrc/occ/occgenmesh.cpp b/libsrc/occ/occgenmesh.cpp index 2ce29d7b..7a26bf1b 100644 --- a/libsrc/occ/occgenmesh.cpp +++ b/libsrc/occ/occgenmesh.cpp @@ -417,15 +417,15 @@ namespace netgen && (geom.face_colours->GetColor(face,XCAFDoc_ColorSurf,face_colour))) { mesh.GetFaceDescriptor(facenr).SetSurfColour(Vec3d(face_colour.Red(),face_colour.Green(),face_colour.Blue())); - mesh.GetFaceDescriptor(facenr).SetBCName(&geom.fnames[facenr-1]); - mesh.GetFaceDescriptor(facenr).SetBCProperty(facenr); } else { mesh.GetFaceDescriptor(facenr).SetSurfColour(Vec3d(0.0,1.0,0.0)); - mesh.GetFaceDescriptor(facenr).SetBCName(&geom.fnames[facenr-1]); - mesh.GetFaceDescriptor(facenr).SetBCProperty(facenr); } + + if(geom.fnames.Size()>=facenr) + mesh.GetFaceDescriptor(facenr).SetBCName(&geom.fnames[facenr-1]); + mesh.GetFaceDescriptor(facenr).SetBCProperty(facenr); // ACHTUNG! STIMMT NICHT ALLGEMEIN (RG) @@ -1471,7 +1471,8 @@ namespace netgen (*testout) << mesh->LineSegment(i) << endl; for (int i = 0; i < mesh->GetNDomains(); i++) - mesh->SetMaterial (i+1, geom.snames[i]); + if(geom.snames.Size()) + mesh->SetMaterial( i+1, geom.snames[i] ); return TCL_OK; } } From 08823c179d3c69741d6ca2e8ea4121defe4f22f2 Mon Sep 17 00:00:00 2001 From: Matthias Hochsteger Date: Fri, 2 Jun 2017 14:50:16 +0200 Subject: [PATCH 63/63] Fix CMake warning, normalize paths --- CMakeLists.txt | 2 +- cmake/NetgenConfig.cmake.in | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 653cbbb4..340a9fbd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -438,7 +438,7 @@ add_custom_target(uninstall get_directory_property(NETGEN_COMPILE_DEFINITIONS COMPILE_DEFINITIONS) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/NetgenConfig.cmake.in - ${CMAKE_CURRENT_BINARY_DIR}/NetgenConfig.cmake @ONLY) + ${CMAKE_CURRENT_BINARY_DIR}/NetgenConfig.cmake @ONLY ESCAPE_QUOTES) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/NetgenConfig.cmake DESTINATION ${NG_INSTALL_DIR_CMAKE}) diff --git a/cmake/NetgenConfig.cmake.in b/cmake/NetgenConfig.cmake.in index 71447d6e..57b90bc9 100644 --- a/cmake/NetgenConfig.cmake.in +++ b/cmake/NetgenConfig.cmake.in @@ -2,19 +2,19 @@ set(PACKAGE_VERSION "@NETGEN_VERSION@") get_filename_component(NETGEN_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) -set(NETGEN_DIR "${NETGEN_CMAKE_DIR}/@NETGEN_DIR@") +get_filename_component(NETGEN_DIR "${NETGEN_CMAKE_DIR}/@NETGEN_DIR@" ABSOLUTE) set(NETGEN_COMPILE_DEFINITIONS "@NETGEN_COMPILE_DEFINITIONS@") -set(NETGEN_INCLUDE_DIR "${NETGEN_CMAKE_DIR}/@NETGEN_INCLUDE_DIR@") -set(NETGEN_BINARY_DIR "${NETGEN_CMAKE_DIR}/@NETGEN_BINARY_DIR@") -set(NETGEN_LIBRARY_DIR "${NETGEN_CMAKE_DIR}/@NETGEN_LIBRARY_DIR@") -set(NETGEN_PYTHON_DIR "${NETGEN_CMAKE_DIR}/@NETGEN_PYTHON_DIR@") -set(NETGEN_RESOURCE_DIR "${NETGEN_CMAKE_DIR}/@NETGEN_RESOURCE_DIR@") +get_filename_component(NETGEN_INCLUDE_DIR "${NETGEN_CMAKE_DIR}/@NETGEN_INCLUDE_DIR@" ABSOLUTE) +get_filename_component(NETGEN_BINARY_DIR "${NETGEN_CMAKE_DIR}/@NETGEN_BINARY_DIR@" ABSOLUTE) +get_filename_component(NETGEN_LIBRARY_DIR "${NETGEN_CMAKE_DIR}/@NETGEN_LIBRARY_DIR@" ABSOLUTE) +get_filename_component(NETGEN_PYTHON_DIR "${NETGEN_CMAKE_DIR}/@NETGEN_PYTHON_DIR@" ABSOLUTE) +get_filename_component(NETGEN_RESOURCE_DIR "${NETGEN_CMAKE_DIR}/@NETGEN_RESOURCE_DIR@" ABSOLUTE) set(NETGEN_SOURCE_DIR "@PROJECT_SOURCE_DIR@") -set(NETGEN_INCLUDE_DIRS "${NETGEN_CMAKE_DIR}/@NETGEN_INCLUDE_DIR@/include;${NETGEN_CMAKE_DIR}/@NETGEN_INCLUDE_DIR@") +set(NETGEN_INCLUDE_DIRS "${NETGEN_INCLUDE_DIR}/include;${NETGEN_INCLUDE_DIR}") set(NETGEN_CMAKE_THREAD_LIBS_INIT "@CMAKE_THREAD_LIBS_INIT@") set(NETGEN_FFMPEG_LIBRARIES "@FFMPEG_LIBRARIES@") set(NETGEN_JPEG_INCLUDE_DIR "@JPEG_INCLUDE_DIR@")