@@ -130,9 +130,6 @@ function _make_cablepart!(workspace::FEMWorkspace, part::AbstractCablePart,
130130 material_id # Material ID from registry
131131 )
132132
133- # Calculate mesh size for this part
134- mesh_size = calc_mesh_size (part, workspace)
135-
136133 # Create physical name
137134 part_type = lowercase (string (nameof (typeof (part))))
138135 elementary_name = create_cable_elementary_name (
@@ -148,15 +145,39 @@ function _make_cablepart!(workspace::FEMWorkspace, part::AbstractCablePart,
148145 radius_in = to_nominal (part. radius_in)
149146 radius_ext = to_nominal (part. radius_ext)
150147
148+ # Calculate mesh size for this part
149+ if part isa AbstractConductorPart
150+ num_elements = workspace. problem_def. elements_per_length_conductor
151+ elseif part isa Insulator
152+ num_elements = workspace. problem_def. elements_per_length_insulator
153+ elseif part isa Semicon
154+ num_elements = workspace. problem_def. elements_per_length_semicon
155+ end
156+
157+ mesh_size_current = calc_mesh_size (radius_in, radius_ext, part. material_props, num_elements, workspace)
158+
159+ # Calculate mesh size for the next part
160+ num_layers = length (cabledef. cable. components[comp_idx]. conductor_group. layers)
161+ next_part = layer_idx < num_layers ? cabledef. cable. components[comp_idx]. conductor_group. layers[layer_idx+ 1 ] : nothing
162+
163+ if ! isnothing (next_part)
164+ next_radius_in = to_nominal (next_part. radius_in)
165+ next_radius_ext = to_nominal (next_part. radius_ext)
166+ mesh_size_next = calc_mesh_size (next_radius_in, next_radius_ext, next_part. material_props, num_elements, workspace)
167+ else
168+ mesh_size_next = mesh_size_current
169+ end
170+
171+ mesh_size = min (mesh_size_current, mesh_size_next)
172+ num_points_circumference = workspace. problem_def. points_per_circumference
173+
151174 # Create annular shape and assign marker
152175 if radius_in ≈ 0
153176 # Solid disk
154- marker = _get_disk_marker (x_center, y_center)
155- entity_tag = _draw_disk (x_center, y_center, radius_ext, mesh_size)
177+ _, _, marker = _draw_disk (x_center, y_center, radius_ext, mesh_size, num_points_circumference)
156178 else
157179 # Annular shape
158- marker = _get_annular_marker (x_center, y_center, radius_in, radius_ext)
159- entity_tag = _draw_annular (x_center, y_center, radius_in, radius_ext, mesh_size)
180+ _, _, marker = _draw_annular (x_center, y_center, radius_in, radius_ext, mesh_size, num_points_circumference)
160181 end
161182
162183 # Create entity data
@@ -219,34 +240,67 @@ function _make_cablepart!(workspace::FEMWorkspace, part::WireArray,
219240 material_id # Material ID from registry
220241 )
221242
222- # Calculate mesh size for this part
223- mesh_size = calc_mesh_size (part, workspace)
224-
225- #
226- # First handle the wires
227- #
243+ # -------- First handle the wires
228244
229245 # Create physical name
230246 part_type = lowercase (string (nameof (typeof (part))))
231247
232248 # Extract parameters
233249 radius_in = to_nominal (part. radius_in)
250+ radius_ext = to_nominal (part. radius_ext)
234251
235- radius_wire = to_nominal (part. radius_wire)
252+ TOL = 5e-6 # Shrink the radius to avoid overlapping boundaries, this must be greater than Gmsh geometry tolerance
253+ radius_wire = to_nominal (part. radius_wire) - TOL
236254 num_wires = part. num_wires
237- lay_radius = num_wires == 1 ? 0 : to_nominal (part. radius_in)
255+
256+
257+ # Calculate mesh size for this part
258+ num_elements = workspace. problem_def. elements_per_length_conductor
259+ mesh_size_current = calc_mesh_size (radius_in, radius_ext, part. material_props, num_elements, workspace)
260+
261+ # Calculate mesh size for the next part
262+ num_layers = length (cabledef. cable. components[comp_idx]. conductor_group. layers)
263+ next_part = layer_idx < num_layers ? cabledef. cable. components[comp_idx]. conductor_group. layers[layer_idx+ 1 ] : nothing
264+
265+ if ! isnothing (next_part)
266+ next_radius_in = to_nominal (next_part. radius_in)
267+ next_radius_ext = to_nominal (next_part. radius_ext)
268+ mesh_size_next = calc_mesh_size (next_radius_in, next_radius_ext, next_part. material_props, num_elements, workspace)
269+ else
270+ mesh_size_next = mesh_size_current
271+ end
272+
273+ mesh_size = min (mesh_size_current, mesh_size_next)
274+ num_points_circumference = workspace. problem_def. points_per_circumference
238275
239276 # Calculate wire positions
240- wire_positions = calc_wirearray_coords (num_wires, radius_wire, lay_radius, C= (x_center, y_center))
277+ function _calc_wirearray_coords (
278+ num_wires:: Number ,
279+ # radius_wire::Number,
280+ radius_in:: Number ,
281+ radius_ext:: Number ;
282+ C= (0.0 , 0.0 ),
283+ )
284+ wire_coords = [] # Global coordinates of all wires
285+ lay_radius = num_wires == 1 ? 0 : (radius_in + radius_ext) / 2
286+
287+ # Calculate the angle between each wire
288+ angle_step = 2 * π / num_wires
289+ for i in 0 : num_wires- 1
290+ angle = i * angle_step
291+ x = C[1 ] + lay_radius * cos (angle)
292+ y = C[2 ] + lay_radius * sin (angle)
293+ push! (wire_coords, (x, y)) # Add wire center
294+ end
295+ return wire_coords
296+ end
241297
298+ wire_positions = _calc_wirearray_coords (num_wires, radius_in, radius_ext, C= (x_center, y_center))
242299
243300 # Create wires
244301 for (wire_idx, (wx, wy)) in enumerate (wire_positions)
245- # Create wire marker
246- marker = _get_disk_marker (wx, wy)
247302
248- # Create wire disk
249- entity_tag = _draw_disk (wx, wy, radius_wire, mesh_size)
303+ _, _, marker = _draw_disk (wx, wy, radius_wire, mesh_size, num_points_circumference)
250304
251305 # Create wire name
252306 elementary_name = create_cable_elementary_name (
@@ -267,9 +321,24 @@ function _make_cablepart!(workspace::FEMWorkspace, part::WireArray,
267321 workspace. unassigned_entities[marker] = entity_data
268322 end
269323
270- #
271- # Then those nasty air gaps, the cause of this entire suffering
272- #
324+ # Handle WireArray outermost boundary
325+ mesh_size = (radius_ext - radius_in)
326+ if ! (next_part isa WireArray) && ! isnothing (next_part)
327+ # step_angle = 2 * pi / num_wires
328+ _add_mesh_points (
329+ radius_in= radius_ext,
330+ radius_ext= radius_ext,
331+ theta_0= 0 ,
332+ theta_1= 2 * pi ,
333+ mesh_size= mesh_size,
334+ num_points_ang= num_points_circumference,
335+ num_points_rad= 0 ,
336+ C= (x_center, y_center),
337+ theta_offset= 0 # step_angle / 2
338+ )
339+ end
340+
341+ # --------Then those nasty air gaps
273342
274343 # Air gaps will be determined from the boolean fragmentation operation and do not need to be drawn. Only the markers are needed.
275344 markers_air_gap = _get_air_gap_markers (num_wires, radius_wire, radius_in)
@@ -298,9 +367,6 @@ function _make_cablepart!(workspace::FEMWorkspace, part::WireArray,
298367 material_id # Material ID from registry
299368 )
300369
301- # Calculate mesh size for this part
302- mesh_size = calc_mesh_size (part, workspace)
303-
304370 for marker in markers_air_gap
305371 # elementary names are not assigned to the air gaps because they are not drawn and appear as a result of the boolean operation
306372 core_data = CoreEntityData (physical_group_tag_air_gap, " " , mesh_size)
0 commit comments