Multiple Cylinder issue

https://ngsolve.org/media/kunena/attachments/1425/test_coil.pyHello NGSolve Users,

I am trying to model a flat coil to simulate the magnetic field of it. As a first step, I am creating the geometry by adding up Cylinder objects to the desired shape.

FGeometry issue (picture attached):

When adding up the Cylinders by the “+” operator, it draws holes in the tubes, which are on the same axis like the inner tubes. As far as I understood from the docs, “+” should only “glue” overlapping points. Here it seems like it is also removing points on the same axis.

Second issue (code attached):

When trying to create the mesh, it stays at “Find points” forever. Am I doing something wrong with the GenerateMesh() command?

I would appreciate any help.

Thanks a lot and best regards!

Seems like the attachments did not work, here is the code:

from ngsolve import *
from ngsolve.solve import Draw, Redraw
from netgen.csg import *

Creating the coil geometry

Format of endpoints: end_point[i] = [xi1, yi1, zi1, xi2, yi2, zi2, r]

end_points = []

radius = 6

end_points.append([0, 0, 0, 198.179, 0, 0, radius])
end_points.append([198.179, 0, 0, 198.179 , 280, 0, radius])
end_points.append([198.179, 280, 0, -182.184, 280, 0, radius])
end_points.append([-182.184, 280, 0, -182.184, 20, 0, radius])
end_points.append([-182.184, 20, 0, 168.162, 20, 0, radius])
end_points.append([168.162, 20, 0, 168.162, 260, 0, radius])
end_points.append([168.162, 260, 0, -152.166, 260, 0, radius])

Create tubes from end_points vecotr

tubes = []

for end_point in end_points:

tubes.append(Cylinder(Pnt(end_point[0],end_point[1],end_point[2]), Pnt(end_point[3],end_point[4],end_point[5]), end_point[6]))

Join tubes to coil geometry

coil = tubes[0]

for i in range (1,len(tubes)):

coil = coil + tubes[i]

Create geometry

geo = CSGeometry()
geo.Add(coil)

Draw Geometry

geo.Draw()

Generate Mesh

mesh = geo.GenerateMesh()

Hello,

the command

Cylinder(p1,p2,radius)

defines an infinite cylinder, where the two points p1, p2 just define the axis. Thus you have to cut the cylinder with another object.

The visualization of the geometry might help to see what you defined, but it is not always accurate. Looks like it got confused by the intersection of the infinite cylinders.

The “+” operator leads to the union of objects.

Attached is a running version of you python file. Important is to cut the cylinders

Cylinder(p1,p2,radius)*Plane(p1,vec1)*Plane(p2,vec2)

where the vectors of the planes have to point outward.
When two objects have a common plane, it is advisable to use the same plane to cut them. You can use the following syntax:

Cylinder(p1,p2,radius)*Plane(p1,vec1)-Plane(p2,vec2)

where the cylinder is cut with the plane at p2, but using the “-” operator turns the vector vec2 performing the intersection. See also CSGeometry.

Best,
Christoph

Attachment: test_coil_2020-08-03.py

Dear Christoph,

thanks a lot for your detailed answer and the example code. Indeed I did not realize the necessity to cut the cylinders by the planes, which is clear now.

Thanks again and best regards!