I am trying to refer to the Merge three-dimensional meshes example in NGSolve Documentation 4.3. I understand this example performs merging on Constructive Solid Geometry (CSG) objects.
However, if I want to generate a mesh for Open Cascade (OCC) Geometry instead of CSG, I need to use ngsolve.Mesh
for mesh generation. In this case, to perform a similar merging operation, I believe it is necessary to convert the ngsolve.Mesh
object back to a netgen.meshing.Mesh
object. Is my understanding correct?
If my understanding is correct, is it possible to generate a netgen.meshing.Mesh
from an ngsolve.Mesh
?
you get it from the ngsolve mesh by
netgen_mesh = mesh.ngmesh
although occ geom GenerateMesh creates a netgen mesh as well, so this example should be independent of the geometry kernel.
1 Like
an ngsolve.Mesh
is a wrapper around a netgen.meshing.Mesh
.
To create an ngsolve-mesh, we do
ngsolvemesh = ngsolve.Mesh(ngmesh)
to obtain the Netgen-mesh (as part of the ngsolve wrapped mesh) we do
ngsolvemesh.ngmesh
1 Like
Thank you.
I did almost the same thing in 2D with OCC.
However, combined_mesh.GenerateVolumeMesh()
does not work out.
I do not see any other method for 2D.
from netgen.occ import *
from netgen.meshing import *
from ngsolve.webgui import Draw
Al_w = 0.065
Al_h = 0.020
Al_z = -0.000
Al = MoveTo(0, Al_z).Rectangle(Al_w, Al_h).Face()
Al.bc('Al')
domain_a = 0.100
import ngsolve
mesh1 = ngsolve.Mesh(OCCGeometry(Al, dim=2).GenerateMesh(maxh=0.010)).ngmesh
circle = MoveTo(0, 0).Circle(domain_a).Face()
rectangle = MoveTo(-domain_a, -domain_a).Rectangle(domain_a, 2*domain_a).Face()
semicircle = circle-rectangle
semicircle.bc('Air')
shape = semicircle-Al
shape.edges.name = 'outer'
mesh2 = ngsolve.Mesh(OCCGeometry(shape,dim=2).GenerateMesh(maxh=0.010)).ngmesh
from netgen.meshing import Mesh
combined_mesh = Mesh()
pmap1 = {}
for el in mesh1.Elements2D():
for v in el.vertices:
if (v not in pmap1):
pmap1[v] = combined_mesh.Add(mesh1[v])
idx_dom = combined_mesh.AddRegion("mat", dim=2)
for e in mesh1.Elements2D():
combined_mesh.Add(Element2D (idx_dom, [pmap1[v] for v in e.vertices]))
pmap2 = {}
for el in mesh2.Elements1D():
for v in el.vertices:
if (v not in pmap2):
pmap2[v] = combined_mesh.Add(mesh2[v])
for e in mesh2.Elements1D():
combined_mesh.Add(Element1D([pmap2[v] for v in e.vertices]))
combined_mesh.GenerateVolumeMesh()
mesh = ngsolve.Mesh(combined_mesh)
Draw (mesh)