Odd bugs with Constructive Solid Geometry 2D

  • mcmcclur
  • Offline
  • New Member
  • New Member
  • Professor of Mathematics at UNC - Asheville
More
3 years 11 months ago #3468 by mcmcclur
I've noticed some odd behavior when generating 2D meshes using Constructive Solid Geometry. Consider the following code, which should generate the intersection of two overlapping circles:
Code:
import netgen.gui from netgen.geom2d import CSG2d, Circle from ngsolve import Mesh geo = CSG2d() c0 = Circle(center=(0,0),radius=1, bc='a') c1 = Circle(center=(1,0),radius=1, bc='b') domain = c0 * c1 geo.Add(domain) mesh = Mesh(geo.GenerateMesh())

We instead get a single circle centered at at the origin. The same thing happens with a union. An intersection yields an empty mesh; it's like the two circles are the same. If we shift the center a small amount, the code works as expected.

I've done this using a conda install on my Macbook Pro as well as with an apt-get install on Ubuntu 20.04 LTS, both with the same result.
More
3 years 11 months ago #3476 by matthiash
Hello,

I cannot reproduce the issue with Netgen 6.2.2009-69-gea7f6c1e.
Which version are you running? If it's older than 6.2.2009, I suggest an update.

Best,
Matthias
The following user(s) said Thank You: mcmcclur
  • mcmcclur
  • Offline
  • New Member
  • New Member
  • Professor of Mathematics at UNC - Asheville
More
3 years 11 months ago #3478 by mcmcclur

matthiash wrote: I cannot reproduce the issue with Netgen 6.2.2009-69-gea7f6c1e.
Which version are you running? If it's older than 6.2.2009, I suggest an update.


Thanks for the response. I am running 6.2.2009 on both my Mac and on my Ubuntu server. I've converted a Jupyter notebook to a webpage so you can see my version and full code here:

marksmath.org/ProblematicMeshIllustration.html
  • mcmcclur
  • Offline
  • New Member
  • New Member
  • Professor of Mathematics at UNC - Asheville
More
3 years 11 months ago - 3 years 11 months ago #3479 by mcmcclur
Here's a similar problem. To produce this, I set up a virtual machine running Ubuntu 20.04 LTS on Digital Ocean. Python version is 3.8. I then logged in as root and followed almost exactly the Ubuntu instructions on this page. - thus:
Code:
apt-add-repository universe add-apt-repository ppa:ngsolve/ngsolve apt-get update apt-get install ngsolve

(Since I was root, I didn't need sudo.)

I then used my favorite, console based text editor to create a file named "ng_bad_script.py" with the following content:
Code:
#!/usr/bin/python3 from ngsolve import Mesh from netgen.geom2d import Solid2d, Circle, CSG2d dom = Solid2d([(0,0),(1,0),(1,1),(0.5,0.5)])-Circle((0.5,0.5),0.2) geo = CSG2d() geo.Add(dom) mesh = Mesh(geo.GenerateMesh())

If I run this script, meshing then fails:
Code:
root@netgen:~# python3 ng_bad_script.py importing NGSolve-6.2.2009 Generate Mesh from spline geometry Boundary mesh done, np = 30 CalcLocalH: 30 Points 0 Elements 0 Surface Elements Meshing domain 1 / 1 load internal triangle rules give up with qualclass 201 number of frontlines = 27 Surface meshing done Traceback (most recent call last): File "ng_script.py", line 9, in <module> mesh = Mesh(geo.GenerateMesh()) netgen.libngpy._meshing.NgException: meshing failed

The situation is worse if I delete the point (0.5,0.5) from the Solid2d object and store the program in "ng_really_bad_script.py", for then I enter an infinite loop:
Code:
root@netgen:~# python3 ng_really_bad_script.py importing NGSolve-6.2.2009 Generate Mesh from spline geometry Boundary mesh done, np = 30 CalcLocalH: 30 Points 0 Elements 0 Surface Elements Meshing domain 1 / 1 load internal triangle rules loclines.Size = 1 loclines.Size = 1 loclines.Size = 1 ... ...

Note that loclines.Size=1 printout repeats until I terminate.

Again, this is a totally fresh install and the exact same thing happens on my Mac with an Anaconda based installation.

To be clear, though, I'm generally quite impressed with the software and I'm looking forward to using it to generate examples for the PDE class that I'll be teaching this semester. Examples where the points are in generic position tend to work; thus, problems like the above tend to go away if the points are perturbed a bit.
Last edit: 3 years 11 months ago by mcmcclur.
More
3 years 11 months ago #3480 by matthiash
Thanks for the detailed information. I discovered the reason for this bug in the source code. I will let you know, when it's fixed.

Best,
Matthias
The following user(s) said Thank You: mcmcclur
More
3 years 11 months ago #3489 by matthiash
The issues are fixed on the master branch. Nightly builds will be available tomorrow.

Best,
Matthias
The following user(s) said Thank You: mcmcclur
Time to create page: 0.102 seconds