Closed jguterl closed 1 month ago
#%%
""" miscellaneous functions """
def rectangle_def(x, y, z, width, height):
# Create points for the rectangle corners
p1 = gmsh.model.occ.addPoint(x, y, z) # Bottom-left corner
p2 = gmsh.model.occ.addPoint(x + width, y, z) # Bottom-right corner
p3 = gmsh.model.occ.addPoint(x + width, y + height, z) # Top-right corner
p4 = gmsh.model.occ.addPoint(x, y + height, z) # Top-left corner
# Create lines for the rectangle edges
l1 = gmsh.model.occ.addLine(p1, p2) # Bottom edge
l2 = gmsh.model.occ.addLine(p2, p3) # Right edge
l3 = gmsh.model.occ.addLine(p3, p4) # Top edge
l4 = gmsh.model.occ.addLine(p4, p1) # Left edge# Define a rectangle in the XY plane
loop = gmsh.model.occ.addCurveLoop([l1, l2, l3, l4])
return loop, p1, p2, p3, p4, l1, l2, l3, l4
#%%
import gmsh
# Initialize GMSH
gmsh.initialize()
#%%
""" INPUT dots in structure """
N_dots = 1
Names = ["Dot_1","Dot_2"]
input_dict = {
Names[0]: {
"shape": "circle",
"x": 0,
"y": 0.8,
"radius": 0.05 # For cylinder
},
Names[1]: {
"shape": "rectangle",
"x": -0.5,
"y": -0.25,
"width": 1,
"height": 0.5
}
# Add more dots as needed
}
#%%
""" Plasma volume geometry """
# Cartesian coordinates of bottom plasma volume surface lower left corner
x_plasma_volume_ll = -2
y_plasma_volume_ll = -2
z_plasma_volume_ll = 0
# Width and height of plasma volume base surface
width = 4
height = 4
dz_plasma_volume = 4 # This variable is defined but not used in this surface creation
# Create a curve loop for plasma volume base
plasma_base_rectangle_loop, p1, p2, p3, p4, l1, l2, l3, l4 = \
rectangle_def(x_plasma_volume_ll, y_plasma_volume_ll, z_plasma_volume_ll, width, height)
# Create a curve loop for plasma_volume top
plasma_top_rectangle_loop, p5, p6, p7, p8, l5, l6, l7, l8 = rectangle_def(x_plasma_volume_ll, y_plasma_volume_ll, \
z_plasma_volume_ll + dz_plasma_volume, width, height)
# Create vertical lines connecting bottom and top
l9 = gmsh.model.occ.addLine(p1, p5)
l10 = gmsh.model.occ.addLine(p2, p6)
l11 = gmsh.model.occ.addLine(p3, p7)
l12 = gmsh.model.occ.addLine(p4, p8)
# list of surfaces IDs enclosing the plasma volume
volumes_surfaces = []
# Create surfaces for the sides (lateral surfaces)
plasma_side1 = gmsh.model.occ.addPlaneSurface([gmsh.model.occ.addCurveLoop([l1, l10, -l5, -l9])]) # minus when instead of going for extremity A to B you go from B to A close a loop
plasma_side2 = gmsh.model.occ.addPlaneSurface([gmsh.model.occ.addCurveLoop([l2, l11, -l6, -l10])])
plasma_side3 = gmsh.model.occ.addPlaneSurface([gmsh.model.occ.addCurveLoop([l3, l12, -l7, -l11])])
plasma_side4 = gmsh.model.occ.addPlaneSurface([gmsh.model.occ.addCurveLoop([l4, l9, -l8, -l12])])
# store surfaces enclosing volume in a variable
volumes_surfaces.append(plasma_side1)
volumes_surfaces.append(plasma_side2)
volumes_surfaces.append(plasma_side3)
volumes_surfaces.append(plasma_side4)
# Create the top surface
plasma_top = gmsh.model.occ.addPlaneSurface([gmsh.model.occ.addCurveLoop([l5, l6, l7, l8])])
# store surfaces enclosing volume in a variable
volumes_surfaces.append(plasma_top)
# Synchronize the GMSH model
gmsh.model.occ.synchronize()
#%%
""" DiMES geometry """
# Cartesian coordinates of the center of the DiMES disk
x_dimes = 0
y_dimes = 0
z_dimes = 1
# Radius of DiMES
r_dimes = 1
DiMES_circle = gmsh.model.occ.addCircle(x_dimes , y_dimes , 0 , r_dimes)
DiMES_circle_loop = gmsh.model.occ.addCurveLoop([DiMES_circle])
plasma_base = gmsh.model.occ.addPlaneSurface([plasma_base_rectangle_loop, DiMES_circle_loop])
# store surfaces enclosing volume in a variable
volumes_surfaces.append(plasma_base)
if z_dimes > 0:
DiMES_edge_surface = gmsh.model.occ.extrude([(1,DiMES_circle)], 0, 0, z_dimes)
# store surfaces enclosing volume in a variable
for tup in DiMES_edge_surface:
if tup[0] == 2:
DiMES_edge_surface_id = tup[1]
break
volumes_surfaces.append(DiMES_edge_surface_id)
#identify top_circle loop
DiMES_top_circle_loop = gmsh.model.occ.addCurveLoop([DiMES_edge_surface[0][1]])
else:
DiMES_top_circle_loop = DiMES_circle_loop
#%%
""" geometry Dots (coatings)"""
dot_loops = []
for nm in Names:
if input_dict[nm]["shape"] == "circle":
x = input_dict[nm]['x']
y = input_dict[nm]['y']
z = z_dimes
r = input_dict[nm]['radius']
dot_shape = gmsh.model.occ.addCircle(x, y, z, r)
dot_loop = gmsh.model.occ.addCurveLoop([dot_shape])
elif input_dict[nm]["shape"] == "rectangle":
x = input_dict[nm]['x']
y = input_dict[nm]['y']
z = z_dimes
width = input_dict[nm]['width']
height = input_dict[nm]['height']
dot_loop = rectangle_def(x, y, z, width, height)
dot_loop = dot_loop[0]
# store dots loops IDs
dot_loops.append(dot_loop)
# create dots surfaces
gmsh.model.occ.addPlaneSurface([dot_loop])
# store surfaces enclosing volume in a variable
volumes_surfaces.append(gmsh.model.occ.addPlaneSurface([dot_loop]))
# Generate DiMES top surface
gmsh.model.occ.synchronize()
DiMES_top_surface = gmsh.model.occ.addPlaneSurface([DiMES_top_circle_loop] + dot_loops)
# store surfaces enclosing volume in a variable
volumes_surfaces.append(DiMES_top_surface)
#%% generate the volume
plasma_volume = gmsh.model.occ.addVolume([gmsh.model.occ.addSurfaceLoop(volumes_surfaces)])
#%% Generate the mesh and visualize the result
# Final synchronization of the CAD model
gmsh.model.occ.synchronize()
gmsh.option.setNumber("Mesh.MeshSizeFromCurvature", 1)
gmsh.option.setNumber("Mesh.MinimumElementsPerTwoPi", 20)
# # Prevent very small elements in small dots
gmsh.option.setNumber("Mesh.MeshSizeMin", 0.05)
# Set maximum mesh characteristic length for the whole model
gmsh.option.setNumber("Mesh.CharacteristicLengthMax", 0.2)
gmsh.model.mesh.generate(2)
# Launch the GUI to see the results:
# Optionally, run the GUI to visualize
gmsh.fltk.run()
# Finalize GMSH
gmsh.finalize()
this code allows you to simulate DiMES in a plasma volume, only rectangles and circles are allowed as dots geometries. DiMES z location can be manually adjusted. Warning: the code doesn't tell you if your input is correct. Pay attention before simulating your geometry