This page was generated from unit-4.2-csg/csg.ipynb.
4.2 Constructive Solid Geometry (CSG)¶
These geometries are bases on primitives (e.g. sphere, cylinder, plane) which are used to build solids by performing boolean operations. Netgen offers the following primitives
primitive |
csg syntax |
meaning |
---|---|---|
half-space |
Plane(Pnt a,Vec n) |
point p in plane, normal vector |
sphere |
Sphere(Pnt c,float r) |
sphere with center c and radius r |
cylinder |
Cylinder(Pnt a, Pnt b, float r) |
points a and b define the axes of a infinite cylinder of radius r |
brick |
OrthoBrick (Pnt a, Pnt b) |
axes parallel brick with minimal coordinates a and maximal coordinates b |
and the boolean operators
operator |
set operation |
---|---|
\(*\) |
intersection |
\(+\) |
union |
\(-\) |
intersection with complement |
[1]:
import netgen.gui
from ngsolve import Draw, Redraw # just for visualization
Using these primitives and operations, we can easily construct a cube. First we import the netgen.csg
module, create 6 plane and intersect them to get the solid cube
.
[2]:
from netgen.csg import *
left = Plane (Pnt(0,0,0), Vec(-1,0,0) )
right = Plane (Pnt(1,1,1), Vec( 1,0,0) )
front = Plane (Pnt(0,0,0), Vec(0,-1,0) )
back = Plane (Pnt(1,1,1), Vec(0, 1,0) )
bot = Plane (Pnt(0,0,0), Vec(0,0,-1) )
top = Plane (Pnt(1,1,1), Vec(0,0, 1) )
cube = left * right * front * back * bot * top
Then we create a CSGeometry
object and add the solid.
[3]:
geo = CSGeometry()
geo.Add (cube)
mesh = geo.GenerateMesh(maxh=0.25)
Redraw()
# mesh.Save("cube.vol")
Start Findpoints
main-solids: 1
Found points 8
Analyze spec points
Find edges
12 edges found
Check intersecting edges
CalcLocalH: 44 Points 0 Elements 0 Surface Elements
Start Findpoints
Analyze spec points
Find edges
12 edges found
Check intersecting edges
Start Findpoints
Analyze spec points
Find edges
12 edges found
Check intersecting edges
Surface 1 / 6
load internal triangle rules
Surface meshing done
0 illegal triangles
Optimize Surface
Edgeswapping, topological
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
36 elements, 55 points
Surface 2 / 6
Surface meshing done
0 illegal triangles
Optimize Surface
Edgeswapping, topological
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
38 elements, 67 points
Surface 3 / 6
Surface meshing done
0 illegal triangles
Optimize Surface
Edgeswapping, topological
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
36 elements, 78 points
Surface 4 / 6
Surface meshing done
0 illegal triangles
Optimize Surface
Edgeswapping, topological
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
34 elements, 88 points
Surface 5 / 6
Surface meshing done
0 illegal triangles
Optimize Surface
Edgeswapping, topological
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
36 elements, 99 points
Surface 6 / 6
Surface meshing done
0 illegal triangles
Optimize Surface
Edgeswapping, topological
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
42 elements, 113 points
SplitSeparateFaces
Check subdomain 1 / 1
Meshing subdomain 1 of 1
Use internal rules
Delaunay meshing
number of points: 108
blockfill local h
number of points: 161
Points: 161
Elements: 872
Tree data entries per element: 1.6055
Tree nodes per element: 0.0309633
SwapImprove
SwapImprove
SwapImprove
SwapImprove
0 degenerated elements removed
Remove intersecting
Remove outer
161 points, 612 elements
start tetmeshing
Use internal rules
Success !
161 points, 612 elements
Remove Illegal Elements
Volume Optimization
CombineImprove
ImproveMesh
SplitImprove
ImproveMesh
SwapImprove
SwapImprove2
ImproveMesh
CombineImprove
ImproveMesh
SplitImprove
ImproveMesh
SwapImprove
SwapImprove2
ImproveMesh
CombineImprove
ImproveMesh
SplitImprove
ImproveMesh
SwapImprove
SwapImprove2
ImproveMesh
[4]:
from netgen.csg import *
cube = OrthoBrick( Pnt(0,0,0), Pnt(1,1,1) )
hole = Cylinder ( Pnt(0.5, 0.5, 0), Pnt(0.5, 0.5, 1), 0.2)
geo = CSGeometry()
geo.Add (cube-hole.maxh(0.05))
mesh = geo.GenerateMesh(maxh=0.1)
Redraw()
Start Findpoints
main-solids: 1
Found points 16
Analyze spec points
Find edges
14 edges found
Check intersecting edges
CalcLocalH: 166 Points 0 Elements 0 Surface Elements
Start Findpoints
Analyze spec points
Find edges
14 edges found
Check intersecting edges
Start Findpoints
Analyze spec points
Find edges
14 edges found
Check intersecting edges
Surface 1 / 7
Surface meshing done
0 illegal triangles
Optimize Surface
Edgeswapping, topological
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
285 elements, 276 points
Surface 2 / 7
Surface meshing done
0 illegal triangles
Optimize Surface
Edgeswapping, topological
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
234 elements, 374 points
Surface 3 / 7
Surface meshing done
0 illegal triangles
Optimize Surface
Edgeswapping, topological
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
246 elements, 478 points
Surface 4 / 7
Surface meshing done
0 illegal triangles
Optimize Surface
Edgeswapping, topological
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
248 elements, 583 points
Surface 5 / 7
Surface meshing done
0 illegal triangles
Optimize Surface
Edgeswapping, topological
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
289 elements, 695 points
Surface 6 / 7
Surface meshing done
0 illegal triangles
Optimize Surface
Edgeswapping, topological
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
252 elements, 802 points
Surface 7 / 7
Surface meshing done
0 illegal triangles
Optimize Surface
Edgeswapping, topological
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
1148 elements, 1351 points
SplitSeparateFaces
Check subdomain 1 / 1
Meshing subdomain 1 of 1
Use internal rules
Delaunay meshing
number of points: 1342
blockfill local h
number of points: 3009
Points: 3009
Elements: 20511
Tree data entries per element: 1.51626
Tree nodes per element: 0.0302764
SwapImprove
SwapImprove
SwapImprove
SwapImprove
1 degenerated elements removed
Remove intersecting
Remove outer
3005 points, 14997 elements
start tetmeshing
Use internal rules
Success !
3019 points, 15129 elements
Remove Illegal Elements
Volume Optimization
CombineImprove
ImproveMesh
SplitImprove
ImproveMesh
SwapImprove
SwapImprove2
ImproveMesh
CombineImprove
ImproveMesh
SplitImprove
ImproveMesh
SwapImprove
SwapImprove2
ImproveMesh
CombineImprove
ImproveMesh
SplitImprove
ImproveMesh
SwapImprove
SwapImprove2
ImproveMesh
Setting properties of solids¶
A solid has members which we can set to define the desired properties.
[5]:
sphere = Sphere(Pnt(0,0,0),1)
Now we can set a boundary name and a maximal mesh size on the surface of this sphere
[6]:
sphere.bc("sphere").maxh(0.25)
[6]:
<netgen.libngpy._csg.Solid at 0x7faeb4e1eeb0>
and define a material for the volume
[7]:
sphere.mat("iron")
[7]:
<netgen.libngpy._csg.Solid at 0x7faeb4e1eeb0>
In case we want to visualize the geometry we can define the color (using rgb values) and transparency of the solid.
[8]:
sphere.col([1,0,0])#.transp()
[8]:
<netgen.libngpy._csg.Solid at 0x7faeb4e1eeb0>
[9]:
geo = CSGeometry()
geo.Add(sphere)
geo.Draw()
Calc Triangle Approximation
Object 0 has 882 triangles
[10]:
ngmesh = geo.GenerateMesh()
print(type(ngmesh))
Redraw()
Start Findpoints
main-solids: 1
Found points 0
Analyze spec points
Find edges
0 edges found
Check intersecting edges
CalcLocalH: 2 Points 0 Elements 0 Surface Elements
Start Findpoints
main-solids: 1
Found points 0
Analyze spec points
Find edges
0 edges found
Check intersecting edges
Start Findpoints
main-solids: 1
Found points 0
Analyze spec points
Find edges
0 edges found
Check intersecting edges
Surface 1 / 1
Surface meshing done
0 illegal triangles
Optimize Surface
Edgeswapping, topological
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
414 elements, 209 points
SplitSeparateFaces
Check subdomain 1 / 1
Meshing subdomain 1 of 1
Use internal rules
Delaunay meshing
number of points: 209
blockfill local h
number of points: 240
Points: 240
Elements: 1211
Tree data entries per element: 1.56895
Tree nodes per element: 0.0305533
SwapImprove
SwapImprove
SwapImprove
SwapImprove
0 degenerated elements removed
Remove intersecting
Remove outer
240 points, 737 elements
start tetmeshing
Use internal rules
Success !
240 points, 737 elements
Remove Illegal Elements
Volume Optimization
CombineImprove
ImproveMesh
SplitImprove
ImproveMesh
SwapImprove
SwapImprove2
ImproveMesh
CombineImprove
ImproveMesh
SplitImprove
ImproveMesh
SwapImprove
SwapImprove2
ImproveMesh
CombineImprove
ImproveMesh
SplitImprove
ImproveMesh
SwapImprove
SwapImprove2
ImproveMesh
<class 'netgen.libngpy._meshing.Mesh'>
To improve the approximation of curved geometries it is possible to use curved elements. This can be done within NGSolve
. Thus we have to convert the Netgen
mesh to a NGSolve
mesh before curving it.
[11]:
from ngsolve.comp import Mesh
mesh = Mesh(ngmesh)
print(type(mesh))
Redraw()
Update mesh topology
<class 'ngsolve.comp.Mesh'>
Update clusters
[12]:
mesh.Curve(3)
Draw(mesh)
Curve elements, order = 3
Update clusters
Curving edges
Curving faces
Setting the mesh size¶
There are the following options to set the mesh size:
globally as argument
maxh
ofGenerateMesh
to the surface of one solid (
maxh
property as above mentioned)for the volume of a solid as optional argument when adding it to the geometry
Add(...,bc)
restrict the mesh size for one point using
RestrictH
use
CloseSurfaces
to generate anisotropic meshes
Global mesh size¶
The global mesh size can be set with the named argument maxh
. The following two versions are equivalent since all arguments of the of the GenerateMesh
function are parsed to the MeshingParameters
if no named argument mp
is given.
[13]:
unit_cube.GenerateMesh(maxh=0.4)
Start Findpoints
main-solids: 1
Found points 8
Analyze spec points
Find edges
12 edges found
Check intersecting edges
CalcLocalH: 32 Points 0 Elements 0 Surface Elements
Start Findpoints
Analyze spec points
Find edges
12 edges found
Check intersecting edges
Start Findpoints
Analyze spec points
Find edges
12 edges found
Check intersecting edges
Surface 1 / 6
Surface meshing done
0 illegal triangles
Optimize Surface
Edgeswapping, topological
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
18 elements, 36 points
Surface 2 / 6
Surface meshing done
0 illegal triangles
Optimize Surface
Edgeswapping, topological
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
18 elements, 40 points
Surface 3 / 6
Surface meshing done
0 illegal triangles
Optimize Surface
Edgeswapping, topological
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
18 elements, 44 points
Surface 4 / 6
Surface meshing done
0 illegal triangles
Optimize Surface
Edgeswapping, topological
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
18 elements, 48 points
Surface 5 / 6
Surface meshing done
0 illegal triangles
Optimize Surface
Edgeswapping, topological
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
18 elements, 52 points
Surface 6 / 6
Surface meshing done
0 illegal triangles
Optimize Surface
Edgeswapping, topological
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
18 elements, 56 points
SplitSeparateFaces
Check subdomain 1 / 1
Meshing subdomain 1 of 1
Use internal rules
Delaunay meshing
number of points: 52
blockfill local h
number of points: 61
Points: 61
Elements: 302
Tree data entries per element: 1.3245
Tree nodes per element: 0.0231788
SwapImprove
SwapImprove
SwapImprove
SwapImprove
0 degenerated elements removed
Remove intersecting
Remove outer
61 points, 166 elements
start tetmeshing
Use internal rules
Success !
61 points, 166 elements
Remove Illegal Elements
Volume Optimization
CombineImprove
ImproveMesh
SplitImprove
ImproveMesh
SwapImprove
SwapImprove2
ImproveMesh
CombineImprove
ImproveMesh
SplitImprove
ImproveMesh
SwapImprove
SwapImprove2
ImproveMesh
CombineImprove
ImproveMesh
SplitImprove
ImproveMesh
SwapImprove
SwapImprove2
ImproveMesh
[13]:
<netgen.libngpy._meshing.Mesh at 0x7faeb60ea870>
[14]:
from netgen.meshing import MeshingParameters
mp = MeshingParameters(maxh=0.4)
unit_cube.GenerateMesh(mp = mp)
Start Findpoints
main-solids: 1
Found points 8
Analyze spec points
Find edges
12 edges found
Check intersecting edges
CalcLocalH: 32 Points 0 Elements 0 Surface Elements
Start Findpoints
Analyze spec points
Find edges
12 edges found
Check intersecting edges
Start Findpoints
Analyze spec points
Find edges
12 edges found
Check intersecting edges
Surface 1 / 6
Surface meshing done
0 illegal triangles
Optimize Surface
Edgeswapping, topological
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
18 elements, 36 points
Surface 2 / 6
Surface meshing done
0 illegal triangles
Optimize Surface
Edgeswapping, topological
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
18 elements, 40 points
Surface 3 / 6
Surface meshing done
0 illegal triangles
Optimize Surface
Edgeswapping, topological
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
18 elements, 44 points
Surface 4 / 6
Surface meshing done
0 illegal triangles
Optimize Surface
Edgeswapping, topological
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
18 elements, 48 points
Surface 5 / 6
Surface meshing done
0 illegal triangles
Optimize Surface
Edgeswapping, topological
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
18 elements, 52 points
Surface 6 / 6
Surface meshing done
0 illegal triangles
Optimize Surface
Edgeswapping, topological
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
18 elements, 56 points
SplitSeparateFaces
Check subdomain 1 / 1
Meshing subdomain 1 of 1
Use internal rules
Delaunay meshing
number of points: 52
blockfill local h
number of points: 61
Points: 61
Elements: 302
Tree data entries per element: 1.3245
Tree nodes per element: 0.0231788
SwapImprove
SwapImprove
SwapImprove
SwapImprove
0 degenerated elements removed
Remove intersecting
Remove outer
61 points, 166 elements
start tetmeshing
Use internal rules
Success !
61 points, 166 elements
Remove Illegal Elements
Volume Optimization
CombineImprove
ImproveMesh
SplitImprove
ImproveMesh
SwapImprove
SwapImprove2
ImproveMesh
CombineImprove
ImproveMesh
SplitImprove
ImproveMesh
SwapImprove
SwapImprove2
ImproveMesh
CombineImprove
ImproveMesh
SplitImprove
ImproveMesh
SwapImprove
SwapImprove2
ImproveMesh
[14]:
<netgen.libngpy._meshing.Mesh at 0x7faeb4e303b0>
Mesh size for one solid¶
To set the mesh size for one domain of the mesh we have to add the desired maxh
as argument when adding the solid to the geometry
[15]:
geo = CSGeometry()
brick = OrthoBrick(Pnt(-2,-2,-2),Pnt(2,2,2))
sphere = Sphere(Pnt(0,0,0),1)
geo.Add(brick-sphere)
geo.Add(sphere,maxh=0.1)
ngmesh = geo.GenerateMesh(maxh=0.4)
Start Findpoints
main-solids: 2
Found points 8
Analyze spec points
Find edges
12 edges found
Check intersecting edges
CalcLocalH: 118 Points 0 Elements 0 Surface Elements
Start Findpoints
Analyze spec points
Find edges
12 edges found
Check intersecting edges
Start Findpoints
Analyze spec points
Find edges
12 edges found
Check intersecting edges
Surface 1 / 7
Surface meshing done
0 illegal triangles
Optimize Surface
Edgeswapping, topological
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
226 elements, 212 points
Surface 2 / 7
Surface meshing done
0 illegal triangles
Optimize Surface
Edgeswapping, topological
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
244 elements, 315 points
Surface 3 / 7
Surface meshing done
0 illegal triangles
Optimize Surface
Edgeswapping, topological
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
236 elements, 414 points
Surface 4 / 7
Surface meshing done
0 illegal triangles
Optimize Surface
Edgeswapping, topological
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
248 elements, 519 points
Surface 5 / 7
Surface meshing done
0 illegal triangles
Optimize Surface
Edgeswapping, topological
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
242 elements, 621 points
Surface 6 / 7
Surface meshing done
0 illegal triangles
Optimize Surface
Edgeswapping, topological
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
248 elements, 726 points
Surface 7 / 7
Surface meshing done
0 illegal triangles
Optimize Surface
Edgeswapping, topological
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
2722 elements, 2087 points
SplitSeparateFaces
Check subdomain 1 / 2
Check subdomain 2 / 2
Meshing subdomain 1 of 2
Use internal rules
Delaunay meshing
number of points: 2066
blockfill local h
number of points: 5722
Points: 5722
Elements: 35074
Tree data entries per element: 1.51679
Tree nodes per element: 0.0303074
SwapImprove
SwapImprove
SwapImprove
SwapImprove
9 degenerated elements removed
Remove intersecting
Remove outer
5652 points, 29391 elements
start tetmeshing
Use internal rules
Success !
5750 points, 30496 elements
Meshing subdomain 2 of 2
Use internal rules
Delaunay meshing
number of points: 5750
blockfill local h
number of points: 9755
Points: 5363
Elements: 31246
Tree data entries per element: 1.5682
Tree nodes per element: 0.031332
SwapImprove
SwapImprove
SwapImprove
SwapImprove
0 degenerated elements removed
Remove intersecting
Remove outer
9749 points, 58739 elements
start tetmeshing
Use internal rules
Success !
9749 points, 58739 elements
Remove Illegal Elements
Volume Optimization
CombineImprove
ImproveMesh
SplitImprove
ImproveMesh
SwapImprove
SwapImprove2
ImproveMesh
CombineImprove
ImproveMesh
SplitImprove
ImproveMesh
SwapImprove
SwapImprove2
ImproveMesh
CombineImprove
ImproveMesh
SplitImprove
ImproveMesh
SwapImprove
SwapImprove2
ImproveMesh
Mesh size on a surface¶
If we want to refine just on a surface we define it as property of the solid.
[16]:
geo = CSGeometry()
brick = OrthoBrick(Pnt(-2,-2,-2),Pnt(2,2,2))
sphere = Sphere(Pnt(0,0,0),1)
geo.Add(brick-sphere)
geo.Add(sphere.maxh(0.1))
ngmesh = geo.GenerateMesh()
Start Findpoints
main-solids: 2
Found points 8
Analyze spec points
Find edges
12 edges found
Check intersecting edges
CalcLocalH: 10 Points 0 Elements 0 Surface Elements
Start Findpoints
Analyze spec points
Find edges
12 edges found
Check intersecting edges
Start Findpoints
Analyze spec points
Find edges
12 edges found
Check intersecting edges
Surface 1 / 7
Surface meshing done
0 illegal triangles
Optimize Surface
Edgeswapping, topological
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
13 elements, 30 points
Surface 2 / 7
Surface meshing done
0 illegal triangles
Optimize Surface
Edgeswapping, topological
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
19 elements, 36 points
Surface 3 / 7
Surface meshing done
0 illegal triangles
Optimize Surface
Edgeswapping, topological
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
13 elements, 39 points
Surface 4 / 7
Surface meshing done
0 illegal triangles
Optimize Surface
Edgeswapping, topological
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
16 elements, 43 points
Surface 5 / 7
Surface meshing done
0 illegal triangles
Optimize Surface
Edgeswapping, topological
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
28 elements, 52 points
Surface 6 / 7
Surface meshing done
0 illegal triangles
Optimize Surface
Edgeswapping, topological
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
13 elements, 55 points
Surface 7 / 7
Surface meshing done
0 illegal triangles
Optimize Surface
Edgeswapping, topological
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
2722 elements, 1416 points
SplitSeparateFaces
Check subdomain 1 / 2
Check subdomain 2 / 2
Meshing subdomain 1 of 2
Use internal rules
Delaunay meshing
number of points: 1408
blockfill local h
number of points: 4971
Points: 4971
Elements: 30900
Tree data entries per element: 1.54045
Tree nodes per element: 0.0307767
SwapImprove
SwapImprove
SwapImprove
SwapImprove
10 degenerated elements removed
Remove intersecting
Remove outer
4897 points, 26492 elements
start tetmeshing
Use internal rules
Success !
4983 points, 27661 elements
Meshing subdomain 2 of 2
Use internal rules
Delaunay meshing
number of points: 4983
blockfill local h
number of points: 6425
Points: 2800
Elements: 16601
Tree data entries per element: 1.53003
Tree nodes per element: 0.0305403
SwapImprove
SwapImprove
SwapImprove
SwapImprove
3 degenerated elements removed
Remove intersecting
Remove outer
6407 points, 40950 elements
start tetmeshing
Use internal rules
ImproveMesh
CombineImprove
ImproveMesh
SwapImprove
SwapImprove2
ImproveMesh
CombineImprove
ImproveMesh
SwapImprove
SwapImprove2
ImproveMesh
CombineImprove
ImproveMesh
SwapImprove
SwapImprove2
ImproveMesh
CombineImprove
ImproveMesh
Call remove problem
Elements before Remove: 34914
Elements after Remove: 34820
start tetmeshing
Use internal rules
Success !
5595 points, 34927 elements
Remove Illegal Elements
Volume Optimization
CombineImprove
ImproveMesh
SplitImprove
ImproveMesh
SwapImprove
SwapImprove2
ImproveMesh
CombineImprove
ImproveMesh
SplitImprove
ImproveMesh
SwapImprove
SwapImprove2
ImproveMesh
CombineImprove
ImproveMesh
SplitImprove
ImproveMesh
SwapImprove
SwapImprove2
ImproveMesh
Mesh size in points¶
This can be done with the MeshingParameters
. Using RestrictH
we can define the mesh size in an arbitrary point.
[17]:
geo = CSGeometry()
brick = OrthoBrick(Pnt(-2,-2,-2),Pnt(2,2,2))
sphere = Sphere(Pnt(0,0,0),1)
mp = MeshingParameters(maxh=0.4)
mp.RestrictH (x=0, y=0, z=1, h=0.025)
geo.Add(brick-sphere)
geo.Add(sphere)
ngmesh = geo.GenerateMesh(mp = mp)
Start Findpoints
main-solids: 2
Found points 8
Analyze spec points
Find edges
12 edges found
Check intersecting edges
CalcLocalH: 118 Points 0 Elements 0 Surface Elements
Start Findpoints
Analyze spec points
Find edges
12 edges found
Check intersecting edges
Start Findpoints
Analyze spec points
Find edges
12 edges found
Check intersecting edges
Surface 1 / 7
Surface meshing done
0 illegal triangles
Optimize Surface
Edgeswapping, topological
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
226 elements, 212 points
Surface 2 / 7
Surface meshing done
0 illegal triangles
Optimize Surface
Edgeswapping, topological
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
244 elements, 315 points
Surface 3 / 7
Surface meshing done
0 illegal triangles
Optimize Surface
Edgeswapping, topological
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
236 elements, 414 points
Surface 4 / 7
Surface meshing done
0 illegal triangles
Optimize Surface
Edgeswapping, topological
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
248 elements, 519 points
Surface 5 / 7
Surface meshing done
0 illegal triangles
Optimize Surface
Edgeswapping, topological
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
242 elements, 621 points
Surface 6 / 7
Surface meshing done
0 illegal triangles
Optimize Surface
Edgeswapping, topological
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
248 elements, 726 points
Surface 7 / 7
Surface meshing done
0 illegal triangles
Optimize Surface
Edgeswapping, topological
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
296 elements, 874 points
SplitSeparateFaces
Check subdomain 1 / 2
Check subdomain 2 / 2
Meshing subdomain 1 of 2
Use internal rules
Delaunay meshing
number of points: 857
blockfill local h
number of points: 1533
Points: 1533
Elements: 8608
Tree data entries per element: 1.85874
Tree nodes per element: 0.0370586
SwapImprove
SwapImprove
SwapImprove
SwapImprove
0 degenerated elements removed
Remove intersecting
Remove outer
1533 points, 6796 elements
start tetmeshing
Use internal rules
Success !
1533 points, 6796 elements
Meshing subdomain 2 of 2
Use internal rules
Delaunay meshing
number of points: 1533
blockfill local h
number of points: 1622
Points: 238
Elements: 1279
Tree data entries per element: 1.48554
Tree nodes per element: 0.0289289
SwapImprove
SwapImprove
SwapImprove
SwapImprove
1 degenerated elements removed
Remove intersecting
Remove outer
1618 points, 7590 elements
start tetmeshing
Use internal rules
Success !
1649 points, 7871 elements
Remove Illegal Elements
Volume Optimization
CombineImprove
ImproveMesh
SplitImprove
ImproveMesh
SwapImprove
SwapImprove2
ImproveMesh
CombineImprove
ImproveMesh
SplitImprove
ImproveMesh
SwapImprove
SwapImprove2
ImproveMesh
CombineImprove
ImproveMesh
SplitImprove
ImproveMesh
SwapImprove
SwapImprove2
ImproveMesh
Anisotropic meshes¶
If the geometry contains thin layers we can use CloseSurfaces
to avoid elements with small angles.
[18]:
from netgen.csg import *
geo = CSGeometry()
box = OrthoBrick(Pnt(0,0,0),Pnt(1,1,1))
top = Plane(Pnt(0,0,0.52),Vec(0,0,1))
bot = Plane(Pnt(0,0,0.48),Vec(0,0,-1))
plate = box * top * bot
geo.Add((box-top).mat("air"))
geo.Add(plate.mat("plate"))
geo.Add((box-bot).mat("air"))
slices = [2**(-i) for i in reversed(range(1,6))]
# define the close surfaces
geo.CloseSurfaces(bot,top)#,slices)
nmesh = geo.GenerateMesh(maxh=0.3)
# refine the mesh between the close surfaces
# ZRefinement(nmesh,geo)
surface ids1 = 0: 21
surface ids2 = 0: 13
Start Findpoints
main-solids: 3
Found points 16
Analyze spec points
Find edges
28 edges found
Find Identifications
Check intersecting edges
CalcLocalH: 56 Points 0 Elements 0 Surface Elements
Start Findpoints
Analyze spec points
Find edges
28 edges found
Find Identifications
Check intersecting edges
Start Findpoints
Analyze spec points
Find edges
28 edges found
Find Identifications
Check intersecting edges
Surface 1 / 16
Surface meshing done
0 illegal triangles
Optimize Surface
Edgeswapping, topological
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
14 elements, 70 points
Surface 2 / 16
Surface meshing done
0 illegal triangles
Optimize Surface
Edgeswapping, topological
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
14 elements, 72 points
Surface 3 / 16
Surface meshing done
0 illegal triangles
Optimize Surface
Edgeswapping, topological
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
11 elements, 73 points
Surface 4 / 16
Surface meshing done
0 illegal triangles
Optimize Surface
Edgeswapping, topological
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
9 elements, 73 points
Surface 5 / 16
Surface meshing done
0 illegal triangles
Optimize Surface
Edgeswapping, topological
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
22 elements, 79 points
Surface 6 / 16
Surface meshing done
0 illegal triangles
Optimize Surface
Edgeswapping, topological
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
13 elements, 81 points
Surface 7 / 16
Surface meshing done
0 illegal triangles
Optimize Surface
Edgeswapping, topological
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
13 elements, 83 points
Surface 8 / 16
insert quad layer of 4 elements at face 8
Surface meshing done
0 illegal triangles
4 elements, 83 points
Surface 9 / 16
Surface meshing done
0 illegal triangles
Optimize Surface
Edgeswapping, topological
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
24 elements, 88 points
Surface 10 / 16
Surface meshing done
0 illegal triangles
Optimize Surface
Edgeswapping, topological
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
14 elements, 90 points
Surface 12 / 16
insert quad layer of 4 elements at face 12
Surface meshing done
0 illegal triangles
4 elements, 90 points
Surface 13 / 16
Surface meshing done
0 illegal triangles
Optimize Surface
Edgeswapping, topological
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
14 elements, 92 points
Surface 14 / 16
insert quad layer of 4 elements at face 14
Surface meshing done
0 illegal triangles
4 elements, 92 points
Surface 15 / 16
insert quad layer of 4 elements at face 15
Surface meshing done
0 illegal triangles
4 elements, 92 points
Surface 16 / 16
Surface meshing done
0 illegal triangles
Optimize Surface
Edgeswapping, topological
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
30 elements, 100 points
Surface 11
22 elements, 102 points
SplitSeparateFaces
Check subdomain 1 / 3
Check subdomain 2 / 3
Check subdomain 3 / 3
Meshing subdomain 1 of 3
Use internal rules
Delaunay meshing
number of points: 102
blockfill local h
number of points: 102
Points: 56
Elements: 252
Tree data entries per element: 1.5873
Tree nodes per element: 0.0277778
SwapImprove
SwapImprove
SwapImprove
SwapImprove
0 degenerated elements removed
Remove intersecting
Remove outer
102 points, 108 elements
start tetmeshing
Use internal rules
Success !
102 points, 108 elements
Meshing subdomain 2 of 3
Use internal rules
102 points, 130 elements
Meshing subdomain 3 of 3
Use internal rules
Delaunay meshing
number of points: 102
blockfill local h
number of points: 104
Points: 48
Elements: 224
Tree data entries per element: 1.33929
Tree nodes per element: 0.0223214
SwapImprove
SwapImprove
SwapImprove
SwapImprove
0 degenerated elements removed
Remove intersecting
Remove outer
104 points, 232 elements
start tetmeshing
Use internal rules
Success !
104 points, 232 elements
Remove Illegal Elements
Volume Optimization
CombineImprove
ImproveMesh
SplitImprove
ImproveMesh
SwapImprove
SwapImprove2
ImproveMesh
CombineImprove
ImproveMesh
SplitImprove
ImproveMesh
SwapImprove
SwapImprove2
ImproveMesh
CombineImprove
ImproveMesh
SplitImprove
ImproveMesh
SwapImprove
SwapImprove2
ImproveMesh
Setting boundary conditions¶
Boundary condition on the surface of a solid¶
Setting a boundary condition on the whole surface of solid can be achieved by adding it as property to the solid.
[19]:
brick = OrthoBrick(Pnt(-2,-2,-2),Pnt(2,2,2)).bc('outer')
sphere = Sphere(Pnt(0,0,0),1).bc('sphere')
Modify boundary between two solids¶
This can be done by adding the named argument bcmod
when adding the solid to the geometry. Here we change the boundary condition on the surface between the halfsphere
and the already added box
.
[20]:
halfsphere = sphere * Plane(Pnt(0,0,0),Vec(1,0,0)).bc('plane')
box = brick-sphere
geo = CSGeometry()
geo.Add(box.col([1,0,0]).transp())
geo.Add(halfsphere.col([0,0,1]),bcmod=[(box,"halfsphere")])
geo.Draw()
Calc Triangle Approximation
Object 0 has 1842 triangles
Object 1 has 1473 triangles
[21]:
ngmesh = geo.GenerateMesh()
mesh = Mesh(ngmesh)
mesh.GetBoundaries()
Start Findpoints
main-solids: 2
Found points 12
Analyze spec points
Find edges
13 edges found
Check intersecting edges
CalcLocalH: 21 Points 0 Elements 0 Surface Elements
Start Findpoints
Analyze spec points
Find edges
13 edges found
Check intersecting edges
Start Findpoints
Analyze spec points
Find edges
13 edges found
Check intersecting edges
Surface 1 / 9
Surface meshing done
0 illegal triangles
Optimize Surface
Edgeswapping, topological
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
22 elements, 51 points
Surface 2 / 9
Surface meshing done
0 illegal triangles
Optimize Surface
Edgeswapping, topological
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
22 elements, 57 points
Surface 3 / 9
Surface meshing done
0 illegal triangles
Optimize Surface
Edgeswapping, topological
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
24 elements, 64 points
Surface 4 / 9
Surface meshing done
0 illegal triangles
Optimize Surface
Edgeswapping, topological
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
20 elements, 69 points
Surface 5 / 9
Surface meshing done
0 illegal triangles
Optimize Surface
Edgeswapping, topological
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
24 elements, 76 points
Surface 6 / 9
Surface meshing done
0 illegal triangles
Optimize Surface
Edgeswapping, topological
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
22 elements, 82 points
Surface 7 / 9
Surface meshing done
0 illegal triangles
Optimize Surface
Edgeswapping, topological
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
59 elements, 106 points
Surface 8 / 9
Surface meshing done
0 illegal triangles
Optimize Surface
Edgeswapping, topological
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
69 elements, 135 points
Surface 9 / 9
Surface meshing done
0 illegal triangles
Optimize Surface
Edgeswapping, topological
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
Edgeswapping, metric
Smoothing
Combine improve
Smoothing
27 elements, 143 points
SplitSeparateFaces
Check subdomain 1 / 2
Check subdomain 2 / 2
Meshing subdomain 1 of 2
Use internal rules
Delaunay meshing
number of points: 140
blockfill local h
number of points: 166
Points: 158
Elements: 849
Tree data entries per element: 1.649
Tree nodes per element: 0.0318021
SwapImprove
SwapImprove
SwapImprove
SwapImprove
0 degenerated elements removed
Remove intersecting
Remove outer
166 points, 565 elements
start tetmeshing
Use internal rules
Success !
166 points, 565 elements
Meshing subdomain 2 of 2
Use internal rules
Delaunay meshing
number of points: 166
blockfill local h
number of points: 167
Points: 51
Elements: 237
Tree data entries per element: 1.26582
Tree nodes per element: 0.021097
SwapImprove
SwapImprove
SwapImprove
SwapImprove
0 degenerated elements removed
Remove intersecting
Remove outer
167 points, 674 elements
start tetmeshing
Use internal rules
Success !
167 points, 674 elements
Remove Illegal Elements
Volume Optimization
CombineImprove
ImproveMesh
SplitImprove
ImproveMesh
SwapImprove
SwapImprove2
ImproveMesh
CombineImprove
ImproveMesh
SplitImprove
ImproveMesh
SwapImprove
SwapImprove2
ImproveMesh
CombineImprove
ImproveMesh
SplitImprove
ImproveMesh
SwapImprove
SwapImprove2
ImproveMesh
[21]:
('outer',
'outer',
'outer',
'outer',
'outer',
'outer',
'sphere',
'halfsphere',
'plane')
Update mesh topology
Update clusters
[ ]: