Hi,
It seems like your model is placed on the surface of your bounding box and not inside, there may be a mistake in the stl file. But anyhow I think it’s easier to mesh the stl model and the bounding CSG seperately and merge them afterwards. There is a (not fully up to date) documentation on how to do that here:
https://ngsolve.org/docu/latest/netgen_tutorials/working_with_meshes.html
When adding the facedescriptors you can give each of the surfaces a different number and a different name, so that they represent different boundary conditions.
Some new stuff that is not in that docu example:
You can mesh only surfaces (this saves quite some time) by:
import netgen.meshing as meshing
stlgeo.GenerateMesh(maxh=maxh,perfstepsend= meshing.MeshingStep.MESHSURFACE)
Then copy all the surface elements together into one mesh, set the maximum meshsize and name for each domain and generate the volume mesh:
# material numbers are 1 based
mesh.SetMaterial(1,"mat1")
mesh.SetMaterial(2,"mat2")
meshsize = [maxh[dom] for dom in mesh.GetMaterials()]
mesh.SetMaxHDomain(meshsize)
mesh.CalcLocalH(0.5)
mesh.GenerateVolumeMesh()
The 0.5 in CalcLocalH is a grading factor.
You can set names for the bc numbers with
# boundary condition numbers are 0 based! - yes this is a bit annoying... ;)
mesh.SetBCName(number,name)
I’ve attached a file that can be used to merge the surface meshes by calling
add_surfaces(mesh1,mesh2,outerdomain)
If you have any questions or if the code isn’t working (I use it in a bigger module, there may be something missing…) feel free to ask
PS:
To check if everything is set correctly I use a short snippet:
from ngsolve import *
from ngsolve.internal import *
boundaries = ["bc1",...]
materials = ["mat1",...]
fes = H1(mesh)
u = GridFunction(fes,"u")
viewoptions.clipping.enable = 1
Draw(u)
visoptions.clipsolution = "scal"
for bc in boundaries:
u.Set(CoefficientFunction(1),definedon=mesh.Boundaries(bc))
Redraw()
input(bc)
for mat in materials:
u.Set(CoefficientFunction(1),definedon=mesh.Materials(mat))
Redraw()
input(mat)
Best
Christopher
Attachment: merge_meshes.py