From 06031e665a1793b60afcea46b0b1242b83ab9c70 Mon Sep 17 00:00:00 2001 From: "mhochsteger@cerbsim.com" Date: Mon, 29 Nov 2021 11:03:50 +0100 Subject: [PATCH] set default bcname to valid string pointer, some occ tests --- libsrc/meshing/basegeom.cpp | 4 +--- libsrc/meshing/meshclass.cpp | 7 ++---- tests/pytest/test_occ.py | 43 ++++++++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 8 deletions(-) create mode 100644 tests/pytest/test_occ.py diff --git a/libsrc/meshing/basegeom.cpp b/libsrc/meshing/basegeom.cpp index 5dcecd1f..e8a2e352 100644 --- a/libsrc/meshing/basegeom.cpp +++ b/libsrc/meshing/basegeom.cpp @@ -626,11 +626,9 @@ namespace netgen for(auto k : Range(faces)) { auto & face = *faces[k]; - mesh.SetBCName(k, face.properties.GetName()); - // todo find attached solids FaceDescriptor fd(k+1, face.domin+1, face.domout+1, k+1); - fd.SetBCName(mesh.GetBCNamePtr(k)); mesh.AddFaceDescriptor(fd); + mesh.SetBCName(k, face.properties.GetName()); if(face.primary == &face) { if(MeshFace(mesh, mparam, k, glob2loc)) diff --git a/libsrc/meshing/meshclass.cpp b/libsrc/meshing/meshclass.cpp index efe51f4d..8748c36e 100644 --- a/libsrc/meshing/meshclass.cpp +++ b/libsrc/meshing/meshclass.cpp @@ -6887,14 +6887,11 @@ namespace netgen int oldsize = bcnames.Size(); bcnames.SetSize (bcnr+1); // keeps contents for (int i = oldsize; i <= bcnr; i++) - bcnames[i] = nullptr; + bcnames[i] = new string("default"); } if ( bcnames[bcnr] ) delete bcnames[bcnr]; - if ( abcname != "default" ) - bcnames[bcnr] = new string ( abcname ); - else - bcnames[bcnr] = nullptr; + bcnames[bcnr] = new string ( abcname ); for (auto & fd : facedecoding) if (fd.BCProperty() <= bcnames.Size()) diff --git a/tests/pytest/test_occ.py b/tests/pytest/test_occ.py new file mode 100644 index 00000000..510775cb --- /dev/null +++ b/tests/pytest/test_occ.py @@ -0,0 +1,43 @@ +import pytest +import math +from pytest import approx +from pytest_check import check + +def check_volume(shape, volume, dim=3): + from netgen.occ import OCCGeometry + geo = OCCGeometry(shape, dim=dim) + + m = geo.GenerateMesh() + assert len(m.Elements2D()) > 0 + assert len(m.Elements1D()) > 0 + if dim==3: + assert len(m.Elements3D()) > 0 + + ngs = pytest.importorskip("ngsolve") + mesh = ngs.Mesh(m) + mesh.Curve(5) + with check: assert ngs.Integrate(1.0, mesh) == approx(volume) + +def test_rect_with_two_holes(): + occ = pytest.importorskip("netgen.occ") + + face = occ.WorkPlane().Rectangle(7,4) \ + .Circle(2,2,1).Reverse() \ + .Circle(5,2,1).Reverse().Face() + check_volume(face, 7*4-2*math.pi, 2) + +def test_unit_square(): + occ = pytest.importorskip("netgen.occ") + check_volume(occ.unit_square.shape, 1, dim=2) + +def test_box_and_cyl(): + occ = pytest.importorskip("netgen.occ") + box = occ.Box(occ.Pnt(0,0,0), occ.Pnt(1,1,1)) + check_volume(box, 1) + r = 0.3 + h = 0.5 + vcyl = r*r*math.pi*h + cyl = occ.Cylinder(occ.Pnt(1,0.5,0.5), occ.X, r=r, h=h) + check_volume(cyl, vcyl) + fused = box+cyl + check_volume(fused, 1+vcyl)