Forum Message

 

 

We have moved the forum to https://forum.ngsolve.org . This is an archived version of the topics until 05/05/23. All the topics were moved to the new forum and conversations can be continued there. This forum is just kept as legacy to not invalidate old links. If you want to continue a conversation just look for the topic in the new forum.

Notice

The forum is in read only mode.

Possible to set boundary conditions on a geometry from an STL source?

More
6 years 3 months ago #315 by ddrake
Hi,
I have a CSG geometry defined in an STL file which includes a small detailed model of a sailplane inside a large bounding box. I'm able to load this geometry in Netgen.

I have been looking at I-Tutorial 4.2 on CSG geometries in 3D. In that tutorial, I can see how to set boundary and material labels for a CSG object such as a sphere, then add that object to the geometry before meshing. I would like to be able to do something similar with my geometry from the STL file, for example, to set one boundary label on the surface of the airplane and a different label on the surface of the bounding box.

When I look at the contents of the STL file, I see only a list of facet definitions. Is there some way to assign boundary labels to specific facets either in Netgen/Python or directly in the STL file? I may not be thinking about this problem the right way -- any suggestions would be most welcome! I'm attaching the STL file in case that is helpful...

Thanks!
Attachments:
More
6 years 3 months ago - 6 years 3 months ago #318 by christopher
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:
ngsolve.org/docu/latest/netgen_tutorials...ing_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:
Code:
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:
Code:
# 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
Code:
# 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
Code:
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:
Code:
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
Attachments:
Last edit: 6 years 3 months ago by christopher. Reason: Wrong grading factor
The following user(s) said Thank You: ddrake
More
5 years 8 months ago #738 by Username
Hi Christopher,

In my version 6.2.1806 is missing:
Code:
from ngsolve_mri.meshtools import max_surfnr, nr_bcs, nr_materials

Where can I find this missing part?
More
5 years 8 months ago #739 by christopher
Sorry that file was missing, I've attached it. Just put it in the same folder and change
Code:
from ngsolve_mri.meshtools import max_surfnr, nr_bcs, nr_materials
to
Code:
from .meshtools import max_surfnr, nr_bcs, nr_materials
Attachments:
The following user(s) said Thank You: Username
Time to create page: 0.109 seconds