From adda364eaaaa587e5e48a9513922c145cf07aed7 Mon Sep 17 00:00:00 2001 From: Julius Zimmermann Date: Mon, 11 Apr 2022 17:52:35 +0200 Subject: [PATCH 1/5] UNV interface with D notation for exponent --- libsrc/interface/readuser.cpp | 46 ++++++++++++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 4 deletions(-) diff --git a/libsrc/interface/readuser.cpp b/libsrc/interface/readuser.cpp index 763aad4b..5f17fb29 100644 --- a/libsrc/interface/readuser.cpp +++ b/libsrc/interface/readuser.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include "writeuser.hpp" @@ -80,6 +81,10 @@ namespace netgen { char reco[100]; // int invert; + // read files that are stored with D instead of E as exponent prefix + // such files are for example exported by GMSH + bool Dnotation; + bool DnotationSet = false; ifstream in(filename); @@ -105,20 +110,47 @@ namespace netgen while (1) { int pi, hi; - Point<3> p; + Point<3> p; + string p1tmp, p2tmp, p3tmp; in >> pi; if (pi == -1) break; in >> hi >> hi >> hi; - in >> p(0) >> p(1) >> p(2); - - mesh.AddPoint (p); + if (DnotationSet == false) { + in >> p1tmp >> p2tmp >> p3tmp; + if (p1tmp.find("D") != std::string::npos){ + DnotationSet = true; + Dnotation = true; + cout << "Attention: in your UNV file, D is used as an exponent prefix instead of E" << endl; + std::replace( p1tmp.begin(), p1tmp.end(), 'D', 'E'); + std::replace( p2tmp.begin(), p2tmp.end(), 'D', 'E'); + std::replace( p3tmp.begin(), p3tmp.end(), 'D', 'E'); + } + p(0) = std::stod(p1tmp); + p(1) = std::stod(p2tmp); + p(2) = std::stod(p3tmp); + } + else if (Dnotation == true) { + in >> p1tmp >> p2tmp >> p3tmp; + std::replace( p1tmp.begin(), p1tmp.end(), 'D', 'E'); + std::replace( p2tmp.begin(), p2tmp.end(), 'D', 'E'); + std::replace( p3tmp.begin(), p3tmp.end(), 'D', 'E'); + p(0) = std::stod(p1tmp); + p(1) = std::stod(p2tmp); + p(2) = std::stod(p3tmp); + } + else{ + in >> p(0) >> p(1) >> p(2); + } + mesh.AddPoint(p); } cout << "read " << mesh.GetNP() << " points" << endl; Point3d pmin, pmax; + cout << "Get Box" << endl; mesh.GetBox (pmin, pmax); + cout << "Pmin: " << pmin << " Pmax: " << pmax << endl; if(fabs(pmin.Z() - pmax.Z()) < 1e-10 * Dist(pmin, pmax)) { cout << "Set Dimension to 2." << endl; @@ -382,11 +414,17 @@ namespace netgen } + cout << "Finalize mesh" << endl; Point3d pmin, pmax; + cout << "ComputeNVertices" << endl; mesh.ComputeNVertices(); + cout << "RebuildSurfaceElementLists" << endl; mesh.RebuildSurfaceElementLists(); + cout << "GetBox" << endl; mesh.GetBox (pmin, pmax); + cout << "UpdateTopology" << endl; mesh.UpdateTopology(); + cout << "increment bccounter" << endl; if(dim == 3) bccounter++; cout << "bounding-box = " << pmin << "-" << pmax << endl; cout << "Created " << bccounter << " boundaries." << endl; From 718c876fa74fa641b39fe7e17eabe5faecef7224 Mon Sep 17 00:00:00 2001 From: Julius Zimmermann Date: Wed, 20 Apr 2022 00:08:54 +0200 Subject: [PATCH 2/5] correct computation of shapes --- libsrc/occ/python_occ_shapes.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/libsrc/occ/python_occ_shapes.cpp b/libsrc/occ/python_occ_shapes.cpp index 315e7f3d..6f5125e3 100644 --- a/libsrc/occ/python_occ_shapes.cpp +++ b/libsrc/occ/python_occ_shapes.cpp @@ -717,6 +717,14 @@ DLL_HEADER void ExportNgOCCShapes(py::module &m) { case TopAbs_FACE: BRepGProp::SurfaceProperties (shape, props); break; + case TopAbs_SHELL: + BRepGProp::SurfaceProperties (shape, props); break; + case TopAbs_SOLID: + BRepGProp::VolumeProperties (shape, props); break; + case TopAbs_COMPOUND: + BRepGProp::VolumeProperties (shape, props); break; + case TopAbs_COMPSOLID: + BRepGProp::VolumeProperties (shape, props); break; default: BRepGProp::LinearProperties(shape, props); // throw Exception("Properties implemented only for FACE"); @@ -744,6 +752,14 @@ DLL_HEADER void ExportNgOCCShapes(py::module &m) { case TopAbs_FACE: BRepGProp::SurfaceProperties (shape, props); break; + case TopAbs_SHELL: + BRepGProp::SurfaceProperties (shape, props); break; + case TopAbs_SOLID: + BRepGProp::VolumeProperties (shape, props); break; + case TopAbs_COMPOUND: + BRepGProp::VolumeProperties (shape, props); break; + case TopAbs_COMPSOLID: + BRepGProp::VolumeProperties (shape, props); break; default: BRepGProp::LinearProperties(shape, props); } From ae28716366e7b3674744bcbb0ad0afed1c6f5924 Mon Sep 17 00:00:00 2001 From: Julius Zimmermann Date: Wed, 20 Apr 2022 14:49:22 +0200 Subject: [PATCH 3/5] add cone --- libsrc/occ/python_occ_shapes.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libsrc/occ/python_occ_shapes.cpp b/libsrc/occ/python_occ_shapes.cpp index 315e7f3d..345d53ee 100644 --- a/libsrc/occ/python_occ_shapes.cpp +++ b/libsrc/occ/python_occ_shapes.cpp @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include @@ -1802,6 +1803,11 @@ DLL_HEADER void ExportNgOCCShapes(py::module &m) }, py::arg("axis"), py::arg("r"), py::arg("h"), "create cylinder given by axis, radius and height"); + m.def("Cone", [] (gp_Ax2 ax, double r1, double r2, double h, double angle) { + return BRepPrimAPI_MakeCone (ax, r1, r2, h, angle).Solid(); + }, py::arg("axis"), py::arg("r1"), py::arg("r2"), py::arg("h"), py::arg("angle"), + "create cone given by axis, radius at bottom (z=0) r1, radius at top (z=h) r2, height and angle"); + m.def("Box", [] (gp_Pnt cp1, gp_Pnt cp2) { return BRepPrimAPI_MakeBox (cp1, cp2).Solid(); }, py::arg("p1"), py::arg("p2"), From 267959967d8f877682bfcc284581279d49d4f892 Mon Sep 17 00:00:00 2001 From: Julius Zimmermann Date: Thu, 21 Apr 2022 10:25:57 +0200 Subject: [PATCH 4/5] add message level and check notation of unv file only for first line --- libsrc/interface/readuser.cpp | 87 ++++++++++++++++++----------------- 1 file changed, 46 insertions(+), 41 deletions(-) diff --git a/libsrc/interface/readuser.cpp b/libsrc/interface/readuser.cpp index 5f17fb29..c3aac4ae 100644 --- a/libsrc/interface/readuser.cpp +++ b/libsrc/interface/readuser.cpp @@ -29,7 +29,7 @@ namespace netgen if ( ext == ".surf" ) { - cout << "Surface file" << endl; + cout << IM(3) << "Surface file" << endl; ifstream in (filename); @@ -73,7 +73,7 @@ namespace netgen } - cout << "points: " << np << " faces: " << nbe << endl; + cout << IM(3) << "points: " << np << " faces: " << nbe << endl; } @@ -105,7 +105,7 @@ namespace netgen else if (strcmp (reco, "2411") == 0) { - cout << "nodes found" << endl; + cout << IM(3) << "nodes found" << endl; while (1) { @@ -118,25 +118,30 @@ namespace netgen break; in >> hi >> hi >> hi; + // check if D in first line if (DnotationSet == false) { in >> p1tmp >> p2tmp >> p3tmp; if (p1tmp.find("D") != std::string::npos){ - DnotationSet = true; Dnotation = true; - cout << "Attention: in your UNV file, D is used as an exponent prefix instead of E" << endl; - std::replace( p1tmp.begin(), p1tmp.end(), 'D', 'E'); - std::replace( p2tmp.begin(), p2tmp.end(), 'D', 'E'); - std::replace( p3tmp.begin(), p3tmp.end(), 'D', 'E'); + cout << IM(3) << "Attention: in your UNV file, D is used as an exponent prefix instead of E" << endl; + std::replace(p1tmp.begin(), p1tmp.end(), 'D', 'E'); + std::replace(p2tmp.begin(), p2tmp.end(), 'D', 'E'); + std::replace(p3tmp.begin(), p3tmp.end(), 'D', 'E'); } p(0) = std::stod(p1tmp); p(1) = std::stod(p2tmp); p(2) = std::stod(p3tmp); + mesh.AddPoint(p); + + DnotationSet = true; + continue; } - else if (Dnotation == true) { + + if (Dnotation == true) { in >> p1tmp >> p2tmp >> p3tmp; - std::replace( p1tmp.begin(), p1tmp.end(), 'D', 'E'); - std::replace( p2tmp.begin(), p2tmp.end(), 'D', 'E'); - std::replace( p3tmp.begin(), p3tmp.end(), 'D', 'E'); + std::replace(p1tmp.begin(), p1tmp.end(), 'D', 'E'); + std::replace(p2tmp.begin(), p2tmp.end(), 'D', 'E'); + std::replace(p3tmp.begin(), p3tmp.end(), 'D', 'E'); p(0) = std::stod(p1tmp); p(1) = std::stod(p2tmp); p(2) = std::stod(p3tmp); @@ -146,14 +151,14 @@ namespace netgen } mesh.AddPoint(p); } - cout << "read " << mesh.GetNP() << " points" << endl; + cout << IM(3) << "read " << mesh.GetNP() << " points" << endl; Point3d pmin, pmax; - cout << "Get Box" << endl; + cout << IM(5) << "Get Box" << endl; mesh.GetBox (pmin, pmax); - cout << "Pmin: " << pmin << " Pmax: " << pmax << endl; + cout << IM(5) << "Pmin: " << pmin << " Pmax: " << pmax << endl; if(fabs(pmin.Z() - pmax.Z()) < 1e-10 * Dist(pmin, pmax)) { - cout << "Set Dimension to 2." << endl; + cout << IM(5) << "Set Dimension to 2." << endl; mesh.SetDimension(2); dim = 2 ; } @@ -162,7 +167,7 @@ namespace netgen else if (strcmp (reco, "2412") == 0) { - cout << "elements found" << endl; + cout << IM(3) << "elements found" << endl; while (1) { @@ -266,18 +271,18 @@ namespace netgen break; } default: - cout << "Do not know fe_id = " << fe_id << ", skipping it." << endl; + cout << IM(3) << "Do not know fe_id = " << fe_id << ", skipping it." << endl; break; } } - cout << mesh.GetNE() << " elements found" << endl; - cout << mesh.GetNSE() << " surface elements found" << endl; + cout << IM(3) << mesh.GetNE() << " elements found" << endl; + cout << IM(3) << mesh.GetNSE() << " surface elements found" << endl; } else if(strcmp (reco, "2467") == 0) { int matnr = 1; - cout << "Groups found" << endl; + cout << IM(3) << "Groups found" << endl; while(in.good()) { int len; @@ -288,7 +293,7 @@ namespace netgen for(int i=0; i < 7; i++) in >> len; in >> name; - cout << len << " element are in group " << name << endl; + cout << IM(3) << len << " element are in group " << name << endl; int hi, index; int fdnr, ednr; @@ -350,7 +355,7 @@ namespace netgen } default: { - cout << "Codim " << codim << " not implemented yet!" << endl; + cout << IM(3) << "Codim " << codim << " not implemented yet!" << endl; } } @@ -389,7 +394,7 @@ namespace netgen } else { - cout << "Do not know data field type " << reco << ", skipping it" << endl; + cout << IM(3) << "Do not know data field type " << reco << ", skipping it" << endl; while(in.good()) { in >> reco; @@ -414,22 +419,22 @@ namespace netgen } - cout << "Finalize mesh" << endl; + cout << IM(5) << "Finalize mesh" << endl; Point3d pmin, pmax; - cout << "ComputeNVertices" << endl; + cout << IM(5) << "ComputeNVertices" << endl; mesh.ComputeNVertices(); - cout << "RebuildSurfaceElementLists" << endl; + cout << IM(5) << "RebuildSurfaceElementLists" << endl; mesh.RebuildSurfaceElementLists(); - cout << "GetBox" << endl; + cout << IM(5) << "GetBox" << endl; mesh.GetBox (pmin, pmax); - cout << "UpdateTopology" << endl; + cout << IM(5) << "UpdateTopology" << endl; mesh.UpdateTopology(); - cout << "increment bccounter" << endl; + cout << IM(5) << "increment bccounter" << endl; if(dim == 3) bccounter++; - cout << "bounding-box = " << pmin << "-" << pmax << endl; - cout << "Created " << bccounter << " boundaries." << endl; + cout << IM(5) << "bounding-box = " << pmin << "-" << pmax << endl; + cout << IM(5) << "Created " << bccounter << " boundaries." << endl; for(int i=0; i> buf; - cout << "buf = " << buf << endl; + cout << IM(5) << "buf = " << buf << endl; if (strcmp (buf, "points") == 0) { in >> np; - cout << "np = " << np << endl; + cout << IM(5) << "np = " << np << endl; } } while (in.good()); @@ -556,7 +561,7 @@ namespace netgen auto pktfile = filename; pktfile.replace_extension("pkt"); - cout << "pktfile = " << pktfile << endl; + cout << IM(3) << "pktfile = " << pktfile << endl; int np, nse, i; int bcprop; @@ -597,7 +602,7 @@ namespace netgen p3++; if (p1 < 1 || p1 > np || p2 < 1 || p2 > np || p3 < 1 || p3 > np) { - cout << "p1 = " << p1 << " p2 = " << p2 << " p3 = " << p3 << endl; + cout << IM(3) << "p1 = " << p1 << " p2 = " << p2 << " p3 = " << p3 << endl; } if (i > 110354) Swap (p2, p3); @@ -627,7 +632,7 @@ namespace netgen ifstream incyl ("ngusers/guenter/cylinder.surf"); int npcyl, nsecyl; incyl >> npcyl; - cout << "npcyl = " << npcyl << endl; + cout << IM(3) << "npcyl = " << npcyl << endl; for (i = 1; i <= npcyl; i++) { Point3d p(0,0,0); @@ -635,7 +640,7 @@ namespace netgen mesh.AddPoint (p); } incyl >> nsecyl; - cout << "nsecyl = " << nsecyl << endl; + cout << IM(3) << "nsecyl = " << nsecyl << endl; for (i = 1; i <= nsecyl; i++) { incyl >> p1 >> p2 >> p3; From 4df5ed15363257e9a07da48e253541efb70a7b79 Mon Sep 17 00:00:00 2001 From: Julius Zimmermann Date: Thu, 21 Apr 2022 10:26:27 +0200 Subject: [PATCH 5/5] denser syntax in occ file --- libsrc/occ/python_occ_shapes.cpp | 6 ------ 1 file changed, 6 deletions(-) diff --git a/libsrc/occ/python_occ_shapes.cpp b/libsrc/occ/python_occ_shapes.cpp index 2a563694..7f5ba84b 100644 --- a/libsrc/occ/python_occ_shapes.cpp +++ b/libsrc/occ/python_occ_shapes.cpp @@ -717,13 +717,10 @@ DLL_HEADER void ExportNgOCCShapes(py::module &m) switch (shape.ShapeType()) { case TopAbs_FACE: - BRepGProp::SurfaceProperties (shape, props); break; case TopAbs_SHELL: BRepGProp::SurfaceProperties (shape, props); break; case TopAbs_SOLID: - BRepGProp::VolumeProperties (shape, props); break; case TopAbs_COMPOUND: - BRepGProp::VolumeProperties (shape, props); break; case TopAbs_COMPSOLID: BRepGProp::VolumeProperties (shape, props); break; default: @@ -752,13 +749,10 @@ DLL_HEADER void ExportNgOCCShapes(py::module &m) switch (shape.ShapeType()) { case TopAbs_FACE: - BRepGProp::SurfaceProperties (shape, props); break; case TopAbs_SHELL: BRepGProp::SurfaceProperties (shape, props); break; case TopAbs_SOLID: - BRepGProp::VolumeProperties (shape, props); break; case TopAbs_COMPOUND: - BRepGProp::VolumeProperties (shape, props); break; case TopAbs_COMPSOLID: BRepGProp::VolumeProperties (shape, props); break; default: