Excellent, thank you Joachim.
I have now moved on to a slightly more complex geometry with a steel cylinder passing through a foam box. Your solution works well on the outside of the box and on the ends of the cylinder, but there is something not quite right on the curved interface between the cylinder and the foam. As you can see from the output (link below), most of the curved surface is shown as steel, but some elements are shown as foam. Ideally, this should not happen, since the surface is part of the cylinder marked as steel, and the foam is defined as being everything inside the box that is not part of the cylinder. If this is just a visualization error, that is okay, but if some vertices on the cylinder are actually marked "foam", that is something I would want to fix. Is there any way I can confirm that all the vertices on the cylinder's curved surface are actually marked as steel, e.g. printing the material of all vertices on the cylinder surface?
Best regards,
Sindre
Link to output visualization: [url]
github.com/blakseth/images/blob/main/cyl...r_with_artifacts.PNG
[/url]
My code:
import ngsolve as ng
import netgen.csg as csg
from ngsolve.webgui import Draw
from ngsolve.comp import BoundaryFromVolumeCF
w,d,h = 2,2,1
r = 0.5
assert r < 0.5*w and r < 0.5*d
supp_maxh = 0.05
foam_maxh = 0.2
left = csg.Plane(csg.Pnt(0,0,0), csg.Vec(-1,0,0)).bc("sides")
right = csg.Plane(csg.Pnt(w,d,h), csg.Vec( 1,0,0)).bc("sides")
front = csg.Plane(csg.Pnt(0,0,0), csg.Vec(0,-1,0)).bc("sides")
back = csg.Plane(csg.Pnt(w,d,h), csg.Vec(0, 1,0)).bc("sides")
bot = csg.Plane(csg.Pnt(0,0,0), csg.Vec(0,0,-1)).bc("bot")
top = csg.Plane(csg.Pnt(w,d,h), csg.Vec(0,0, 1)).bc("top")
box = left * right * front * back * bot * top
inf_cyl = csg.Cylinder(csg.Pnt(w/2,d/2,0), csg.Pnt(w/2,d/2,1), r) # Defines a cylinder of infinite height with radius r and axis intersecting the given points.
supp = box*inf_cyl # The cylindrical support is the intersection of the box and the infinite cylinder.
foam = box - supp # The foam fills the part of the prism not occupied by the support.
supp.mat("steel")
foam.mat("foam")
geo = csg.CSGeometry()
geo.Add(supp)
geo.Add(foam)
mesh = ng.Mesh(geo.GenerateMesh(maxh=0.2))
mesh.Curve(3)
vol_cf = mesh.RegionCF(ng.VOL, {"steel":1, "foam":2})
bnd_cf = mesh.RegionCF(ng.BND, {"top":1, "bot":2, "sides"
})
Draw(bnd_cf, mesh)
Draw(BoundaryFromVolumeCF(vol_cf), mesh)