Skip to content

Commit 14fa8a9

Browse files
fixed tags in boundary curves, skip ci
1 parent d6638ee commit 14fa8a9

5 files changed

Lines changed: 107 additions & 28 deletions

File tree

examples/tutorial3.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ opts = FEMOptions(
6666
force_remesh=true, # Force remeshing
6767
run_solver=true,
6868
overwrite_results=true,
69-
preview_geo=false, # Preview geometry
69+
preview_geo=true, # Preview geometry
7070
preview_mesh=false, # Preview the mesh
7171
base_path=joinpath(@__DIR__, "fem_output"),
7272
verbosity=2, # Verbose output

src/FEMTools/cable.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,10 @@ function _make_cablepart!(workspace::FEMWorkspace, part::AbstractCablePart,
174174
# Create annular shape and assign marker
175175
if radius_in 0
176176
# Solid disk
177-
_, _, marker = draw_disk(x_center, y_center, radius_ext, mesh_size, num_points_circumference)
177+
_, _, marker, _ = draw_disk(x_center, y_center, radius_ext, mesh_size, num_points_circumference)
178178
else
179179
# Annular shape
180-
_, _, marker = draw_annular(x_center, y_center, radius_in, radius_ext, mesh_size, num_points_circumference)
180+
_, _, marker, _ = draw_annular(x_center, y_center, radius_in, radius_ext, mesh_size, num_points_circumference)
181181
end
182182

183183
# Create entity data
@@ -303,7 +303,7 @@ function _make_cablepart!(workspace::FEMWorkspace, part::WireArray,
303303
# Create wires
304304
for (wire_idx, (wx, wy)) in enumerate(wire_positions)
305305

306-
_, _, marker = draw_disk(wx, wy, radius_wire, mesh_size, num_points_circumference)
306+
_, _, marker, _ = draw_disk(wx, wy, radius_wire, mesh_size, num_points_circumference)
307307

308308
# Create wire name
309309
elementary_name = create_cable_elementary_name(

src/FEMTools/drawing.jl

Lines changed: 64 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,23 @@ function draw_line(x1::Number, y1::Number, x2::Number, y2::Number, mesh_size::Nu
169169

170170
tag = gmsh.model.occ.add_line(mesh_points[1], mesh_points[end])
171171

172+
# Add midpoint markers between each pair of mesh points
173+
segment_markers = Vector{Vector{Float64}}()
174+
push!(segment_markers, marker)
175+
176+
if length(mesh_points) >= 2
177+
# Iterate through adjacent pairs of mesh points
178+
for i in 1:(num_points-1)
179+
t = (i - 0.5) / (num_points - 1) # Parametric coordinate (0.5 between points)
180+
mid_x = x1 + t * (x2 - x1)
181+
mid_y = y1 + t * (y2 - y1)
182+
# Create marker at midpoint
183+
mid_marker = [mid_x, mid_y, 0.0]
184+
push!(segment_markers, mid_marker)
185+
end
186+
end
172187

173-
174-
175-
return tag, mesh_points, marker
188+
return tag, mesh_points, segment_markers
176189
end
177190

178191
"""
@@ -211,13 +224,35 @@ function draw_disk(x::Number, y::Number, radius::Number, mesh_size::Number, num_
211224
theta_offset=0 #pi / 15
212225
)
213226

214-
# marker = [x, y + (radius / 2), 0.0]
227+
215228
marker = [x, y + 0.99 * radius, 0.0] # A very small offset inwards the circle
216229
marker_tag = gmsh.model.occ.add_point(marker[1], marker[2], marker[3], mesh_size)
217230
gmsh.model.set_entity_name(0, marker_tag, "marker_$(round(mesh_size, sigdigits=6))")
218231

232+
# Add midpoint markers between each pair of mesh points
233+
arc_markers = Vector{Vector{Float64}}()
234+
235+
if num_points >= 2
236+
# Calculate the angular step between mesh points
237+
theta_step = 2 * pi / num_points
238+
239+
# Add a midpoint marker for each arc segment
240+
for i in 1:num_points
241+
# Calculate midpoint theta (angle)
242+
theta_mid = (i - 0.5) * theta_step
243+
244+
# Calculate midpoint coordinates
245+
mid_x = x + radius * cos(theta_mid)
246+
mid_y = y + radius * sin(theta_mid)
247+
248+
# Create marker at the midpoint
249+
mid_marker = [mid_x, mid_y, 0.0]
250+
251+
push!(arc_markers, mid_marker)
252+
end
253+
end
219254

220-
return tag, mesh_points, marker
255+
return tag, mesh_points, marker, arc_markers
221256
end
222257

223258

@@ -284,12 +319,34 @@ function draw_annular(x::Number, y::Number, radius_in::Number, radius_ext::Numbe
284319
)
285320
end
286321

287-
# marker = [x, y + ((radius_in + radius_ext) / 2), 0.0]
288322
marker = [x, y + (radius_in + 0.99 * (radius_ext - radius_in)), 0.0]
289323
marker_tag = gmsh.model.occ.add_point(marker[1], marker[2], marker[3], mesh_size)
290324
gmsh.model.set_entity_name(0, marker_tag, "marker_$(round(mesh_size, sigdigits=6))")
291325

292-
return tag, mesh_points, marker
326+
# Add midpoint markers between each pair of mesh points
327+
arc_markers = Vector{Vector{Float64}}()
328+
329+
if num_points >= 2
330+
# Calculate the angular step between mesh points
331+
theta_step = 2 * pi / num_points
332+
333+
# Add a midpoint marker for each arc segment
334+
for i in 1:num_points
335+
# Calculate midpoint theta (angle)
336+
theta_mid = (i - 0.5) * theta_step
337+
338+
# Calculate midpoint coordinates
339+
mid_x = x + radius_ext * cos(theta_mid)
340+
mid_y = y + radius_ext * sin(theta_mid)
341+
342+
# Create marker at the midpoint
343+
mid_marker = [mid_x, mid_y, 0.0]
344+
345+
push!(arc_markers, mid_marker)
346+
end
347+
end
348+
349+
return tag, mesh_points, marker, arc_markers
293350
end
294351

295352

src/FEMTools/identification.jl

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ this operation.
3232
function process_fragments(workspace::FEMWorkspace)
3333

3434
# Get all entities
35-
surfaces = gmsh.model.getEntities(2)
36-
curves = gmsh.model.getEntities(1)
37-
points = gmsh.model.getEntities(0)
35+
surfaces = gmsh.model.get_entities(2)
36+
curves = gmsh.model.get_entities(1)
37+
points = gmsh.model.get_entities(0)
3838

3939
@debug "Initial counts: $(length(surfaces)) surfaces, $(length(curves)) curves, $(length(points)) points"
4040

@@ -46,8 +46,8 @@ function process_fragments(workspace::FEMWorkspace)
4646
end
4747

4848
# Get updated entities after first fragmentation
49-
updated_curves = gmsh.model.getEntities(1)
50-
updated_points = gmsh.model.getEntities(0)
49+
updated_curves = gmsh.model.get_entities(1)
50+
updated_points = gmsh.model.get_entities(0)
5151

5252
@debug "After fragmenting points onto curves: $(length(updated_curves)) curves, $(length(updated_points)) points"
5353

@@ -64,9 +64,9 @@ function process_fragments(workspace::FEMWorkspace)
6464
gmsh.model.occ.synchronize()
6565

6666
# Final counts
67-
final_surfaces = gmsh.model.getEntities(2)
68-
final_curves = gmsh.model.getEntities(1)
69-
final_points = gmsh.model.getEntities(0)
67+
final_surfaces = gmsh.model.get_entities(2)
68+
final_curves = gmsh.model.get_entities(1)
69+
final_points = gmsh.model.get_entities(0)
7070

7171
@info "Boolean fragmentation completed"
7272
@debug "Before: $(length(surfaces)) surfaces, $(length(curves)) curves, $(length(points)) points"
@@ -78,7 +78,7 @@ end
7878
function identify_by_marker(workspace::FEMWorkspace)
7979

8080
# Get all surfaces after fragmentation
81-
all_surfaces = gmsh.model.getEntities(2)
81+
all_surfaces = gmsh.model.get_entities(2)
8282

8383
# Track statistics
8484
total_entities = length(workspace.unassigned_entities)
@@ -96,7 +96,7 @@ function identify_by_marker(workspace::FEMWorkspace)
9696
for (dim, tag) in all_surfaces
9797
if !(entity_data isa CurveEntity)
9898
# Check if marker is inside this surface
99-
if gmsh.model.isInside(dim, tag, marker) == 1
99+
if gmsh.model.is_inside(dim, tag, marker) == 1
100100
# Found match - create FEMEntity and add to appropriate container
101101
fem_entity = FEMEntity(tag, entity_data)
102102

@@ -121,7 +121,7 @@ function identify_by_marker(workspace::FEMWorkspace)
121121
end
122122

123123
# Get all remaining curves after fragmentation
124-
all_curves = gmsh.model.getEntities(1)
124+
all_curves = gmsh.model.get_entities(1)
125125

126126
# Update keys to avoid modifying dict during iteration
127127
markers = collect(keys(workspace.unassigned_entities))
@@ -134,7 +134,7 @@ function identify_by_marker(workspace::FEMWorkspace)
134134

135135
for (dim, tag) in all_curves
136136
# Check if marker is inside this curve
137-
if gmsh.model.isInside(dim, tag, marker) == 1
137+
if gmsh.model.is_inside(dim, tag, marker) == 1
138138
# Found match - create FEMEntity and add to appropriate container
139139
fem_entity = FEMEntity(tag, entity_data)
140140

src/FEMTools/space.jl

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ function make_space_geometry(workspace::FEMWorkspace)
4040
# Create inner domain disk
4141
num_points_circumference = formulation.points_per_circumference
4242
@debug "Creating inner domain disk with radius $(domain_radius) m"
43-
_, _, air_region_marker = draw_disk(x_center, y_center, domain_radius, mesh_size_domain, num_points_circumference)
43+
_, _, air_region_marker, domain_boundary_markers = draw_disk(x_center, y_center, domain_radius, mesh_size_domain, num_points_circumference)
4444

4545
# Create outer domain annular region
4646
@debug "Creating outer domain annular region with radius $(domain_radius_inf) m"
47-
_, _, air_infshell_marker = draw_annular(x_center, y_center, domain_radius, domain_radius_inf, mesh_size_inf, num_points_circumference)
47+
_, _, air_infshell_marker, domain_infty_markers = draw_annular(x_center, y_center, domain_radius, domain_radius_inf, mesh_size_inf, num_points_circumference)
4848

4949
# Get earth model from workspace
5050
earth_props = workspace.problem_def.earth_props
@@ -153,12 +153,26 @@ function make_space_geometry(workspace::FEMWorkspace)
153153
earth_material
154154
)
155155

156-
# Add surfaces to the workspace
156+
# Add curves to the workspace
157157
workspace.unassigned_entities[air_boundary_marker] = air_boundary_entity
158158
workspace.unassigned_entities[air_infty_marker] = air_infty_entity
159159
workspace.unassigned_entities[earth_boundary_marker] = earth_boundary_entity
160160
workspace.unassigned_entities[earth_infty_marker] = earth_infty_entity
161161

162+
@debug "Domain boundary markers:"
163+
for point_marker in domain_boundary_markers
164+
target_entity = point_marker[2] > 0 ? air_boundary_entity : earth_boundary_entity
165+
workspace.unassigned_entities[point_marker] = target_entity
166+
@debug " Point $point_marker: ($(point_marker[1]), $(point_marker[2]), $(point_marker[3]))"
167+
end
168+
169+
@debug "Domain -> infinity markers:"
170+
for point_marker in domain_infty_markers
171+
target_entity = point_marker[2] > 0 ? air_infty_entity : earth_infty_entity
172+
workspace.unassigned_entities[point_marker] = target_entity
173+
@debug " Point $point_marker: ($(point_marker[1]), $(point_marker[2]), $(point_marker[3]))"
174+
end
175+
162176
# Add physical groups to the workspace
163177
register_physical_group!(workspace, air_region_tag, air_material)
164178
register_physical_group!(workspace, earth_region_tag, earth_material)
@@ -202,7 +216,7 @@ function make_space_geometry(workspace::FEMWorkspace)
202216
num_elements = formulation.elements_per_length_interfaces
203217
earth_interface_mesh_size = _calc_mesh_size(0, domain_radius, earth_material, num_elements, workspace)
204218

205-
_, _, earth_interface_marker = draw_line(-domain_radius_inf, 0.0, domain_radius_inf, 0.0, earth_interface_mesh_size, round(Int, domain_radius))
219+
_, _, earth_interface_markers = draw_line(-domain_radius_inf, 0.0, domain_radius_inf, 0.0, earth_interface_mesh_size, round(Int, domain_radius))
206220

207221
# Create physical tag for the earth interface
208222
interface_idx = 1 # Earth interface index
@@ -228,6 +242,7 @@ function make_space_geometry(workspace::FEMWorkspace)
228242
mesh_size_min = earth_interface_mesh_size / 100 #characteristic_len / workspace.formulation.elements_per_length_insulator
229243
mesh_size_max = earth_interface_mesh_size
230244
transition_mesh = collect(LinRange(mesh_size_min, mesh_size_max, n_regions))
245+
# TODO: Transition regions should be parametric and specified by the user in the formulation
231246
_, _, earth_transition_markers = draw_transition_region(cx, cy, transition_radii, transition_mesh, num_points_circumference)
232247

233248
# Register transition regions in the workspace
@@ -246,7 +261,14 @@ function make_space_geometry(workspace::FEMWorkspace)
246261
@info "Transition regions created"
247262

248263
# Add interface to the workspace
249-
workspace.unassigned_entities[earth_interface_marker] = earth_interface_entity
264+
@debug "Domain -> infinity markers:"
265+
for point_marker in earth_interface_markers
266+
workspace.unassigned_entities[point_marker] = earth_interface_entity
267+
@debug " Point $point_marker: ($(point_marker[1]), $(point_marker[2]), $(point_marker[3]))"
268+
end
269+
270+
271+
250272
@info "Earth interfaces created"
251273

252274
end

0 commit comments

Comments
 (0)