Skip to content

Commit b9703fc

Browse files
skip ci
1 parent 0257d60 commit b9703fc

25 files changed

Lines changed: 672 additions & 261 deletions

Project.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@ DisplayAs = "0b91fe84-8a4c-11e9-3e1d-67c38462b6d6"
1515
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
1616
EzXML = "8f5d6c58-4d21-5cfd-889c-e3ad7ee6a615"
1717
ForceImport = "9dda63f9-cce7-5873-89fa-eccbb2fffcde"
18+
GetDP = "dbfd83e6-7aba-450b-9c2b-93ccd973023a"
1819
Gmsh = "705231aa-382f-11e9-3f0c-b7cb4346fdeb"
1920
JSON3 = "0f8b85d8-7281-11e9-16c2-39a750bddbf1"
2021
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
2122
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
2223
LoggingExtras = "e6f89c97-d47a-5376-807f-9c37f3926c36"
24+
MacroTools = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09"
2325
Measurements = "eff96d63-e80a-5855-80a2-b1b0885c5ab7"
2426
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
2527
PkgTemplates = "14b8a8f1-9102-5b29-a752-f990bacb7fe1"
@@ -30,10 +32,9 @@ Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
3032
Serialization = "9e88b42a-f829-5b0c-bbe9-9e923198166b"
3133
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
3234
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
33-
GetDP = "dbfd83e6-7aba-450b-9c2b-93ccd973023a"
3435

3536
[sources]
36-
GetDP = {url = "https://github.com/Electa-Git/GetDP.jl", rev="main"}
37+
GetDP = {rev = "main", url = "https://github.com/Electa-Git/GetDP.jl"}
3738

3839
[compat]
3940
CSV = "0.10.15"
@@ -51,6 +52,7 @@ JSON3 = "1.14.2"
5152
LinearAlgebra = "1.11.0"
5253
Logging = "1.11.0"
5354
LoggingExtras = "1.1.0"
55+
MacroTools = "0.5.16"
5456
Measurements = "2.11.0"
5557
Pkg = "1.11.0"
5658
PkgTemplates = "0.7.56"

src/DataModel.jl

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,10 @@ using DataFrames
4444
using Colors
4545
using Plots
4646
using DisplayAs: DisplayAs
47-
import DataFrames: DataFrame
48-
import Base: get, delete!, length, setindex!, iterate, keys, values, haskey, getindex
49-
5047
using ..Utils
5148
using ..Materials
5249
using ..EarthProps
53-
import ..LineCableModels: add!, preview, save, _is_headless, _is_in_testset, _CLEANMETHODLIST
50+
import ..LineCableModels: _is_headless, _is_in_testset, _CLEANMETHODLIST
5451

5552
# To handle radius-related operations
5653
abstract type AbstractRadius end

src/DataModel/BaseParams.jl

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ alpha_eq = $(FUNCTIONNAME)(alpha_conductor, R_conductor, alpha_new_part, R_new_p
8888
println(alpha_eq) # Output: 0.00396 (approximately)
8989
```
9090
"""
91-
@measurify function calc_equivalent_alpha(alpha1::T, R1::T, alpha2::T, R2::T) where {T<:REALTYPES}
91+
@measurify function calc_equivalent_alpha(alpha1::T, R1::T, alpha2::T, R2::T) where {T<:REALSCALAR}
9292
return (alpha1 * R2 + alpha2 * R1) / (R1 + R2)
9393
end
9494

@@ -135,7 +135,7 @@ println(Req) # Outputs: 3.3333333333333335
135135
136136
- [`calc_helical_params`](@ref)
137137
"""
138-
function calc_parallel_equivalent(Z1::T, Z2::T) where {T<:Union{REALTYPES,COMPLEXTYPES}}
138+
function calc_parallel_equivalent(Z1::T, Z2::T) where {T<:Union{REALSCALAR,COMPLEXSCALAR}}
139139
return 1 / (1 / Z1 + 1 / Z2)
140140
end
141141

@@ -188,7 +188,7 @@ mean_diam, pitch, overlength = $(FUNCTIONNAME)(radius_in, radius_ext, lay_ratio)
188188
# overlength > 1.0 [1/m]
189189
```
190190
"""
191-
function calc_helical_params(radius_in::T, radius_ext::T, lay_ratio::T) where {T<:REALTYPES}
191+
function calc_helical_params(radius_in::T, radius_ext::T, lay_ratio::T) where {T<:REALSCALAR}
192192
mean_diameter = 2 * (radius_in + (radius_ext - radius_in) / 2)
193193
pitch_length = lay_ratio * mean_diameter
194194
overlength = pitch_length != 0 ? sqrt(1 +* mean_diameter / pitch_length)^2) : 1
@@ -243,7 +243,7 @@ function calc_strip_resistance(
243243
alpha::T,
244244
T0::T,
245245
Top::T,
246-
) where {T<:REALTYPES}
246+
) where {T<:REALSCALAR}
247247

248248
cross_section = thickness * width
249249
return calc_temperature_correction(alpha, Top, T0) * rho / cross_section
@@ -276,7 +276,7 @@ where ``\\alpha`` is the temperature coefficient of the material resistivity, ``
276276
k = $(FUNCTIONNAME)(0.00393, 75.0, 20.0) # Expected output: 1.2158
277277
```
278278
"""
279-
function calc_temperature_correction(alpha::T, Top::T, T0::T=T₀) where {T<:REALTYPES}
279+
function calc_temperature_correction(alpha::T, Top::T, T0::T=T₀) where {T<:REALSCALAR}
280280
@assert abs(Top - T0) < ΔTmax """
281281
Temperature is outside the valid range for linear resistivity model:
282282
Top = $Top
@@ -333,7 +333,7 @@ function calc_tubular_resistance(
333333
alpha::T,
334334
T0::T,
335335
Top::T,
336-
) where {T<:REALTYPES}
336+
) where {T<:REALSCALAR}
337337
cross_section = π * (radius_ext^2 - radius_in^2)
338338
return calc_temperature_correction(alpha, Top, T0) * rho / cross_section
339339
end
@@ -372,7 +372,7 @@ L = $(FUNCTIONNAME)(radius_in, radius_ext, mu_r)
372372
373373
- [`calc_tubular_resistance`](@ref)
374374
"""
375-
function calc_tubular_inductance(radius_in::T, radius_ext::T, mu_r::T) where {T<:REALTYPES}
375+
function calc_tubular_inductance(radius_in::T, radius_ext::T, mu_r::T) where {T<:REALSCALAR}
376376
return mu_r * μ₀ / (2 * π) * log(radius_ext / radius_in)
377377
end
378378

@@ -412,7 +412,7 @@ function calc_wirearray_coords(
412412
radius_wire::T,
413413
radius_in::T;
414414
C=(0.0, 0.0),
415-
) where {T<:REALTYPES}
415+
) where {T<:REALSCALAR}
416416
wire_coords = [] # Global coordinates of all wires
417417
lay_radius = num_wires == 1 ? 0 : radius_in + radius_wire
418418

@@ -481,7 +481,7 @@ function calc_inductance_trifoil(
481481
S::T;
482482
rho_e::T=100.0,
483483
f::T=f₀,
484-
) where {T<:REALTYPES}
484+
) where {T<:REALSCALAR}
485485

486486
ω = 2 * π * f
487487
C = μ₀ / (2π)
@@ -562,7 +562,7 @@ gmr = $(FUNCTIONNAME)(lay_rad, N, rad_wire, mu_r)
562562
println(gmr) # Expected output: 0.01187... [m]
563563
```
564564
"""
565-
function calc_wirearray_gmr(lay_rad::T, N::Int, rad_wire::T, mu_r::T) where {T<:REALTYPES}
565+
function calc_wirearray_gmr(lay_rad::T, N::Int, rad_wire::T, mu_r::T) where {T<:REALSCALAR}
566566
gmr_wire = rad_wire * exp(-mu_r / 4)
567567
log_gmr_array = log(gmr_wire * N * lay_rad^(N - 1)) / N
568568
return exp(log_gmr_array)
@@ -603,7 +603,7 @@ gmr = $(FUNCTIONNAME)(radius_ext, radius_in, mu_r)
603603
println(gmr) # Expected output: ~0.0135 [m]
604604
```
605605
"""
606-
function calc_tubular_gmr(radius_ext::T, radius_in::T, mu_r::T) where {T<:REALTYPES}
606+
function calc_tubular_gmr(radius_ext::T, radius_in::T, mu_r::T) where {T<:REALSCALAR}
607607
if radius_ext < radius_in
608608
throw(ArgumentError("Invalid parameters: radius_ext must be >= radius_in."))
609609
end
@@ -675,7 +675,7 @@ println(mu_r) # Expected output: ~1.5 [dimensionless]
675675
# See also
676676
- [`calc_tubular_gmr`](@ref)
677677
"""
678-
function calc_equivalent_mu(gmr::T, radius_ext::T, radius_in::T) where {T<:REALTYPES}
678+
function calc_equivalent_mu(gmr::T, radius_ext::T, radius_in::T) where {T<:REALSCALAR}
679679
if radius_ext < radius_in
680680
throw(ArgumentError("Invalid parameters: radius_ext must be >= radius_in."))
681681
end
@@ -723,7 +723,7 @@ capacitance = $(FUNCTIONNAME)(radius_in, radius_ext, epsr)
723723
println(capacitance) # Expected output: ~1.24e-10 [F/m]
724724
```
725725
"""
726-
function calc_shunt_capacitance(radius_in::T, radius_ext::T, epsr::T) where {T<:REALTYPES}
726+
function calc_shunt_capacitance(radius_in::T, radius_ext::T, epsr::T) where {T<:REALSCALAR}
727727
return 2 * π * ε₀ * epsr / log(radius_ext / radius_in)
728728
end
729729

@@ -757,7 +757,7 @@ g = $(FUNCTIONNAME)(radius_in, radius_ext, rho)
757757
println(g) # Expected output: 2.7169e-9 [S·m]
758758
```
759759
"""
760-
function calc_shunt_conductance(radius_in::T, radius_ext::T, rho::T) where {T<:REALTYPES}
760+
function calc_shunt_conductance(radius_in::T, radius_ext::T, rho::T) where {T<:REALSCALAR}
761761
return 2 * π * (1 / rho) / log(radius_ext / radius_in)
762762
end
763763

@@ -943,7 +943,7 @@ function calc_solenoid_correction(
943943
num_turns::T,
944944
radius_ext_con::T,
945945
radius_ext_ins::T,
946-
) where {T<:REALTYPES}
946+
) where {T<:REALSCALAR}
947947
if isnan(num_turns)
948948
return 1.0
949949
else
@@ -980,7 +980,7 @@ where ``S_{eff}`` is the effective cross-sectional area of the tubular conductor
980980
rho_eq = $(FUNCTIONNAME)(0.01, 0.02, 0.01) # Expected output: ~9.42e-4 [Ω·m]
981981
```
982982
"""
983-
function calc_equivalent_rho(R::T, radius_ext_con::T, radius_in_con::T) where {T<:REALTYPES}
983+
function calc_equivalent_rho(R::T, radius_ext_con::T, radius_in_con::T) where {T<:REALSCALAR}
984984
eff_conductor_area = π * (radius_ext_con^2 - radius_in_con^2)
985985
return R * eff_conductor_area
986986
end
@@ -1015,7 +1015,7 @@ eps_eq = $(FUNCTIONNAME)(1e-10, 0.01, 0.005) # Expected output: ~2.26 [dimensio
10151015
# See also
10161016
- [`ε₀`](@ref)
10171017
"""
1018-
function calc_equivalent_eps(C_eq::T, radius_ext::T, radius_in::T) where {T<:REALTYPES}
1018+
function calc_equivalent_eps(C_eq::T, radius_ext::T, radius_in::T) where {T<:REALSCALAR}
10191019
return (C_eq * log(radius_ext / radius_in)) / (2 * pi) / ε₀
10201020
end
10211021

@@ -1046,7 +1046,7 @@ where ``\\tan \\delta`` is the loss factor (tangent).
10461046
loss_factor = $(FUNCTIONNAME)(1e-8, 1e-10, 2π*50) # Expected output: ~0.0318 [dimensionless]
10471047
```
10481048
"""
1049-
function calc_equivalent_lossfact(G_eq::T, C_eq::T, ω::T) where {T<:REALTYPES}
1049+
function calc_equivalent_lossfact(G_eq::T, C_eq::T, ω::T) where {T<:REALSCALAR}
10501050
return G_eq /* C_eq)
10511051
end
10521052

@@ -1077,7 +1077,7 @@ Geq = 2.7169e-9
10771077
sigma_eq = $(FUNCTIONNAME)(G_eq, radius_in, radius_ext)
10781078
```
10791079
"""
1080-
function calc_sigma_lossfact(G_eq::T, radius_in::T, radius_ext::T) where {T<:REALTYPES}
1080+
function calc_sigma_lossfact(G_eq::T, radius_in::T, radius_ext::T) where {T<:REALSCALAR}
10811081
return G_eq * log(radius_ext / radius_in) / (2 * pi)
10821082
end
10831083

src/DataModel/cabledesign.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ $(FUNCTIONNAME)(design, component)
321321
- [`CableDesign`](@ref)
322322
- [`CableComponent`](@ref)
323323
"""
324-
function add!(
324+
function LineCableModels.add!(
325325
design::CableDesign,
326326
component::CableComponent,
327327
)
@@ -368,7 +368,7 @@ $(FUNCTIONNAME)(design, "shield", conductor_group, insulator_group)
368368
- [`CableDesign`](@ref)
369369
- [`CableComponent`](@ref)
370370
"""
371-
function add!(
371+
function LineCableModels.add!(
372372
design::CableDesign,
373373
component_id::String,
374374
conductor_group::ConductorGroup,
@@ -378,5 +378,5 @@ function add!(
378378
component = CableComponent(component_id, conductor_group, insulator_group)
379379

380380
# Call the main function
381-
return add!(design, component)
381+
return LineCableModels.add!(design, component)
382382
end

src/DataModel/cableslibrary.jl

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,13 @@ mutable struct CablesLibrary
4545
end
4646

4747
# Implement the AbstractDict interface
48-
length(lib::CablesLibrary) = length(lib.data)
49-
setindex!(lib::CablesLibrary, value::CableDesign, key::String) = (lib.data[key] = value)
50-
iterate(lib::CablesLibrary, state...) = iterate(lib.data, state...)
51-
keys(lib::CablesLibrary) = keys(lib.data)
52-
values(lib::CablesLibrary) = values(lib.data)
53-
haskey(lib::CablesLibrary, key::String) = haskey(lib.data, key)
54-
getindex(lib::CablesLibrary, key::String) = getindex(lib.data, key)
48+
Base.length(lib::CablesLibrary) = length(lib.data)
49+
Base.setindex!(lib::CablesLibrary, value::CableDesign, key::String) = (lib.data[key] = value)
50+
Base.iterate(lib::CablesLibrary, state...) = iterate(lib.data, state...)
51+
Base.keys(lib::CablesLibrary) = keys(lib.data)
52+
Base.values(lib::CablesLibrary) = values(lib.data)
53+
Base.haskey(lib::CablesLibrary, key::String) = haskey(lib.data, key)
54+
Base.getindex(lib::CablesLibrary, key::String) = getindex(lib.data, key)
5555

5656
"""
5757
Stores a cable design in a [`CablesLibrary`](@ref) object.
@@ -78,7 +78,7 @@ println(library) # Prints the updated dictionary containing the new cable design
7878
- [`CableDesign`](@ref)
7979
- [`delete!`](@ref)
8080
"""
81-
function add!(library::CablesLibrary, design::CableDesign)
81+
function LineCableModels.add!(library::CablesLibrary, design::CableDesign)
8282
library.data[design.cable_id] = design
8383
@info "Cable design with ID `$(design.cable_id)` added to the library."
8484
library
@@ -115,7 +115,7 @@ haskey(library, "example") # Returns false
115115
- [`CablesLibrary`](@ref)
116116
- [`add!`](@ref)
117117
"""
118-
function delete!(library::CablesLibrary, cable_id::String)
118+
function LineCableModels.delete!(library::CablesLibrary, cable_id::String)
119119
if haskey(library, cable_id)
120120
delete!(library.data, cable_id)
121121
@info "Cable design with ID `$cable_id` removed from the library."
@@ -162,12 +162,12 @@ println(missing_design === nothing) # Prints true
162162
- [`add!`](@ref)
163163
- [`delete!`](@ref)
164164
"""
165-
function get(library::CablesLibrary, cable_id::String, default=nothing)::Union{Nothing,CableDesign}
165+
function Base.get(library::CablesLibrary, cable_id::String, default=nothing)::Union{Nothing,CableDesign}
166166
if haskey(library, cable_id)
167167
@info "Cable design with ID `$cable_id` loaded from the library."
168168
return library[cable_id]
169169
else
170-
@error "Cable design with ID `$cable_id` not found in the library."
171-
throw(KeyError(cable_id))
170+
@warn "Cable design with ID `$cable_id` not found in the library."
171+
return default
172172
end
173173
end

src/DataModel/conductors.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ $(FUNCTIONNAME)(conductor, WireArray, 0.02, 0.002, 7, 15, material_props, temper
221221
- [`calc_parallel_equivalent`](@ref)
222222
- [`calc_equivalent_alpha`](@ref)
223223
"""
224-
function add!(
224+
function LineCableModels.add!(
225225
group::ConductorGroup,
226226
part_type::Type{T}, # The type of conductor part (WireArray, Strip, Tubular)
227227
args...; # Arguments specific to the part type

src/DataModel/dataframe.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ first(df, 5) # Show the first 5 rows of the DataFrame
3434
- [`CableDesign`](@ref)
3535
- [`add!`](@ref)
3636
"""
37-
function DataFrame(library::CablesLibrary)::DataFrame
37+
function DataFrames.DataFrame(library::CablesLibrary)::DataFrame
3838
ids = keys(library)
3939
nominal_data = [string(design.nominal_data) for design in values(library)]
4040
components = [
@@ -83,7 +83,7 @@ println(df)
8383
- [`LineCableSystem`](@ref)
8484
- [`CablePosition`](@ref)
8585
"""
86-
function DataFrame(system::LineCableSystem)::DataFrame
86+
function DataFrames.DataFrame(system::LineCableSystem)::DataFrame
8787
cable_ids = String[]
8888
horz_coords = Number[]
8989
vert_coords = Number[]
@@ -152,7 +152,7 @@ core_data = DataFrame(design, :baseparams, S=0.5, rho_e=150)
152152
- [`calc_inductance_trifoil`](@ref)
153153
- [`calc_shunt_capacitance`](@ref)
154154
"""
155-
function DataFrame(
155+
function DataFrames.DataFrame(
156156
design::CableDesign,
157157
format::Symbol=:baseparams;
158158
S::Union{Nothing,Number}=nothing,

src/DataModel/insulators.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ $(FUNCTIONNAME)(insulator_group, Semicon, 0.015, 0.018, material_props)
156156
- [`Semicon`](@ref)
157157
- [`calc_parallel_equivalent`](@ref)
158158
"""
159-
function add!(
159+
function LineCableModels.add!(
160160
group::InsulatorGroup,
161161
part_type::Type{T}, # The type of insulator part (Insulator, Semicon)
162162
args...; # Arguments specific to the part type

src/DataModel/linecablesystem.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ println(cable_system.num_cables) # Prints: 2
205205
- [`CablePosition`](@ref)
206206
- [`CableDesign`](@ref)
207207
"""
208-
function add!(
208+
function LineCableModels.add!(
209209
system::LineCableSystem,
210210
cable::CableDesign,
211211
horz::Number,

src/DataModel/preview.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ cable_plot = $(FUNCTIONNAME)(design) # Cable cross-section is displayed
187187
- [`Strip`](@ref)
188188
- [`Semicon`](@ref)
189189
"""
190-
function preview(
190+
function LineCableModels.preview(
191191
design::CableDesign;
192192
x_offset=0.0,
193193
y_offset=0.0,
@@ -373,7 +373,7 @@ $(FUNCTIONNAME)(system, earth_model=earth_params, zoom_factor=0.5)
373373
- [`EarthModel`](@ref)
374374
- [`CablePosition`](@ref)
375375
"""
376-
function preview(
376+
function LineCableModels.preview(
377377
system::LineCableSystem;
378378
earth_model=nothing,
379379
zoom_factor=0.25,
@@ -437,7 +437,7 @@ function preview(
437437
for cable_position in system.cables
438438
x_offset = to_nominal(cable_position.horz)
439439
y_offset = to_nominal(cable_position.vert)
440-
preview(
440+
LineCableModels.preview(
441441
cable_position.design_data; # Changed from cable_position.design_data
442442
x_offset,
443443
y_offset,
@@ -481,8 +481,8 @@ for interactive use when no backend is explicitly specified. This is particularl
481481
# Examples
482482
483483
```julia
484-
choose_proper_backend() # Auto-selects based on environment
485-
choose_proper_backend(pyplot) # Explicitly use PyPlot backend
484+
_resolve_backend() # Auto-selects based on environment
485+
_resolve_backend(pyplot) # Explicitly use PyPlot backend
486486
```
487487
"""
488488
function _resolve_backend(backend=nothing)

0 commit comments

Comments
 (0)