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:
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
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
meshsize = [maxh[dom] for dom in mesh.GetMaterials()]
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... ;)
I’ve attached a file that can be used to merge the surface meshes by calling
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
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
visoptions.clipsolution = "scal"
for bc in boundaries:
for mat in materials: