Skip to content

Commit db931bd

Browse files
Refactor FEMWorkspace to manage physical groups and update cable geometry functions to register physical groups
1 parent ecd97f4 commit db931bd

4 files changed

Lines changed: 39 additions & 5 deletions

File tree

src/FEMTools.jl

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -431,8 +431,8 @@ mutable struct FEMWorkspace
431431
unassigned_entities::Dict{Vector{Float64},AbstractEntityData}
432432
"Container for all material names used in the model."
433433
material_registry::Dict{String,Int}
434-
"ONELAB parameters."
435-
onelab_params::Dict{String,Any}
434+
"Container for unique physical groups."
435+
physical_groups::Dict{Int,Material}
436436
"Results storage."
437437
results::Dict{String,Any}
438438

@@ -474,7 +474,7 @@ mutable struct FEMWorkspace
474474
Vector{FEMEntity{<:AbstractEntityData}}(), #boundaries
475475
Dict{Vector{Float64},AbstractEntityData}(), #unassigned_entities
476476
Dict{String,Int}(), # Initialize empty material registry
477-
Dict{String,Any}(),
477+
Dict{Int,Material}(), # Maps physical group tags to materials
478478
Dict{String,Any}()
479479
)
480480

@@ -511,9 +511,13 @@ workspace = $(FUNCTIONNAME)(cable_system, problem_def, solver)
511511
function run_fem_model(cable_system::LineCableSystem,
512512
problem_def::FEMProblemDefinition,
513513
solver::FEMSolver;
514-
frequency::Float64=50.0)
514+
frequency::Float64=50.0, workspace::Union{FEMWorkspace,Nothing}=nothing)
515+
515516
# Create and initialize workspace
516-
workspace = FEMWorkspace(cable_system, problem_def, solver, frequency=frequency)
517+
if isnothing(workspace) || !isa(workspace, FEMWorkspace)
518+
workspace = FEMWorkspace(cable_system, problem_def, solver, frequency=frequency)
519+
end
520+
# workspace = FEMWorkspace(cable_system, problem_def, solver, frequency=frequency)
517521

518522
# Log start
519523
_log(workspace, 1, "Starting FEM simulation for cable system: $(cable_system.case_id)")

src/FEMTools/cable.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,9 @@ function _make_cablepart!(workspace::FEMWorkspace, part::AbstractCablePart,
187187
# Add to workspace in the unassigned container for subsequent processing
188188
workspace.unassigned_entities[marker] = entity_data
189189

190+
# Add physical groups to the workspace
191+
register_physical_group!(workspace, physical_group_tag, part.material_props)
192+
190193
end
191194

192195
"""
@@ -320,6 +323,8 @@ function _make_cablepart!(workspace::FEMWorkspace, part::WireArray,
320323
# Add to workspace
321324
workspace.unassigned_entities[marker] = entity_data
322325
end
326+
# Add physical groups to the workspace
327+
register_physical_group!(workspace, physical_group_tag, part.material_props)
323328

324329
# Handle WireArray outermost boundary
325330
mesh_size = (radius_ext - radius_in)
@@ -376,4 +381,7 @@ function _make_cablepart!(workspace::FEMWorkspace, part::WireArray,
376381
workspace.unassigned_entities[marker] = entity_data
377382
end
378383

384+
# Add physical groups to the workspace
385+
register_physical_group!(workspace, physical_group_tag_air_gap, air_material)
386+
379387
end

src/FEMTools/encoding.jl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,23 @@ function get_or_register_material_id(workspace::FEMWorkspace, material::Material
281281
return material_id
282282
end
283283

284+
function register_physical_group!(workspace::FEMWorkspace, physical_group_tag::Int, material::Material)
284285

286+
# Create physical_groups if it doesn't exist
287+
if !isdefined(workspace, :physical_groups)
288+
workspace.physical_groups = Dict{Int,Material}()
289+
end
290+
291+
# # Get material name using existing function that checks library first
292+
# material_name = get_material_name(material, workspace.problem_def.materials_db)
293+
294+
# Find or create the ID
295+
if !haskey(workspace.physical_groups, physical_group_tag)
296+
# New material - assign next available ID
297+
workspace.physical_groups[physical_group_tag] = material
298+
end
299+
300+
end
285301
"""
286302
$(TYPEDSIGNATURES)
287303

src/FEMTools/space.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,12 @@ function _make_space_geometry(workspace::FEMWorkspace)
159159
workspace.unassigned_entities[earth_boundary_marker] = earth_boundary_entity
160160
workspace.unassigned_entities[earth_infty_marker] = earth_infty_entity
161161

162+
# Add physical groups to the workspace
163+
register_physical_group!(workspace, air_region_tag, air_material)
164+
register_physical_group!(workspace, earth_region_tag, earth_material)
165+
register_physical_group!(workspace, air_infshell_tag, air_material)
166+
register_physical_group!(workspace, earth_infshell_tag, earth_material)
167+
162168
# Create domain surfaces
163169
air_region_entity = SurfaceEntity(
164170
CoreEntityData(air_region_tag, air_region_name, mesh_size_default),

0 commit comments

Comments
 (0)