@@ -8,49 +8,49 @@ for all subsequent computational steps.
88# Fields
99$(TYPEDFIELDS)
1010"""
11- @kwdef struct CoaxialWorkspace{T <: REALSCALAR , U <: Vector{<:REALSCALAR} }
12- " Vector of frequency values [Hz]."
13- freq:: Vector{T}
14- " Vector of horizontal positions [m]."
15- horz:: Vector{T}
16- " Vector of vertical positions [m]."
17- vert:: Vector{T}
18- " Vector of internal conductor radii [m]."
19- r_in:: Vector{T}
20- " Vector of external conductor radii [m]."
21- r_ext:: Vector{T}
22- " Vector of internal insulator radii [m]."
23- r_ins_in:: Vector{T}
24- " Vector of external insulator radii [m]."
25- r_ins_ext:: Vector{T}
26- " Vector of conductor resistivities [Ω·m]."
27- rho_cond:: Vector{T}
28- " Vector of conductor relative permeabilities."
29- mu_cond:: Vector{T}
30- " Vector of conductor relative permittivities."
31- eps_cond:: Vector{T}
32- " Vector of insulator resistivities [Ω·m]."
33- rho_ins:: Vector{T}
34- " Vector of insulator relative permeabilities."
35- mu_ins:: Vector{T}
36- " Vector of insulator relative permittivities."
37- eps_ins:: Vector{T}
38- " Vector of insulator loss tangents."
39- tan_ins:: Vector{T}
40- " Vector of phase mapping indices."
41- phase_map:: Vector{Int}
42- " Vector of cable mapping indices."
43- cable_map:: Vector{Int}
44- " Effective earth parameters as a vector of NamedTuples."
45- earth:: Vector{NamedTuple{(:rho_g, :eps_g, :mu_g), Tuple{U, U, U }}}
46- " Operating temperature [°C]."
47- temp:: T
48- " Number of frequency samples."
49- n_frequencies:: Int
50- " Number of phases in the system."
51- n_phases:: Int
52- " Number of cables in the system."
53- n_cables:: Int
11+ @kwdef struct CoaxialWorkspace{T<: REALSCALAR }
12+ " Vector of frequency values [Hz]."
13+ freq:: Vector{T}
14+ " Vector of horizontal positions [m]."
15+ horz:: Vector{T}
16+ " Vector of vertical positions [m]."
17+ vert:: Vector{T}
18+ " Vector of internal conductor radii [m]."
19+ r_in:: Vector{T}
20+ " Vector of external conductor radii [m]."
21+ r_ext:: Vector{T}
22+ " Vector of internal insulator radii [m]."
23+ r_ins_in:: Vector{T}
24+ " Vector of external insulator radii [m]."
25+ r_ins_ext:: Vector{T}
26+ " Vector of conductor resistivities [Ω·m]."
27+ rho_cond:: Vector{T}
28+ " Vector of conductor relative permeabilities."
29+ mu_cond:: Vector{T}
30+ " Vector of conductor relative permittivities."
31+ eps_cond:: Vector{T}
32+ " Vector of insulator resistivities [Ω·m]."
33+ rho_ins:: Vector{T}
34+ " Vector of insulator relative permeabilities."
35+ mu_ins:: Vector{T}
36+ " Vector of insulator relative permittivities."
37+ eps_ins:: Vector{T}
38+ " Vector of insulator loss tangents."
39+ tan_ins:: Vector{T}
40+ " Vector of phase mapping indices."
41+ phase_map:: Vector{Int}
42+ " Vector of cable mapping indices."
43+ cable_map:: Vector{Int}
44+ " Effective earth parameters as a vector of NamedTuples."
45+ earth:: Vector {NamedTuple{(:rho_g , :eps_g , :mu_g ),Tuple{Vector{T},Vector{T},Vector{T} }}}
46+ " Operating temperature [°C]."
47+ temp:: T
48+ " Number of frequency samples."
49+ n_frequencies:: Int
50+ " Number of phases in the system."
51+ n_phases:: Int
52+ " Number of cables in the system."
53+ n_cables:: Int
5454end
5555
5656"""
@@ -59,90 +59,87 @@ $(TYPEDSIGNATURES)
5959Initializes and populates the [`CoaxialWorkspace`](@ref) by normalizing a
6060[`LineParametersProblem`](@ref) into flat, type-stable arrays.
6161"""
62- function init_workspace (problem:: LineParametersProblem , formulation:: CoaxialFormulation )
63-
64- opts = formulation. options
65- # set_logger!(opts.verbosity, opts.logfile)
66-
67- system = problem. system
68- n_frequencies = length (problem. frequencies)
69- n_components = sum (length (cable. design_data. components) for cable in system. cables)
70-
71- # Determine the common numeric type for all calculations
72- T = _find_common_type (problem)
73-
74- # Pre-allocate 1D arrays
75- freq = Vector {T} (undef, n_frequencies)
76- horz = Vector {T} (undef, n_components)
77- vert = Vector {T} (undef, n_components)
78- r_in = Vector {T} (undef, n_components)
79- r_ext = Vector {T} (undef, n_components)
80- r_ins_in = Vector {T} (undef, n_components)
81- r_ins_ext = Vector {T} (undef, n_components)
82- rho_cond = Vector {T} (undef, n_components)
83- mu_cond = Vector {T} (undef, n_components)
84- eps_cond = Vector {T} (undef, n_components)
85- rho_ins = Vector {T} (undef, n_components)
86- mu_ins = Vector {T} (undef, n_components)
87- eps_ins = Vector {T} (undef, n_components)
88- tan_ins = Vector {T} (undef, n_components) # Loss tangent for insulator
89- phase_map = Vector {Int} (undef, n_components)
90- cable_map = Vector {Int} (undef, n_components)
91-
92- # Fill arrays, ensuring type promotion
93- freq .= T .(problem. frequencies)
94-
95- idx = 0
96- for (cable_idx, cable) in enumerate (system. cables)
97- for (comp_idx, component) in enumerate (cable. design_data. components)
98- idx += 1
99- # Geometric properties
100- horz[idx] = T (cable. horz)
101- vert[idx] = T (cable. vert)
102- r_in[idx] = T (component. conductor_group. radius_in)
103- r_ext[idx] = T (component. conductor_group. radius_ext)
104- r_ins_in[idx] = T (component. insulator_group. radius_in)
105- r_ins_ext[idx] = T (component. insulator_group. radius_ext)
106-
107- # Material properties
108- rho_cond[idx] = T (component. conductor_props. rho)
109- mu_cond[idx] = T (component. conductor_props. mu_r)
110- eps_cond[idx] = T (component. conductor_props. eps_r)
111- rho_ins[idx] = T (component. insulator_props. rho)
112- mu_ins[idx] = T (component. insulator_props. mu_r)
113- eps_ins[idx] = T (component. insulator_props. eps_r)
114-
115- # Calculate loss factor from resistivity
116- ω = 2 * π * f₀ # Using default frequency
117- C_eq = T (component. insulator_group. shunt_capacitance)
118- G_eq = T (component. insulator_group. shunt_conductance)
119- tan_ins[idx] = G_eq / (ω * C_eq)
120-
121- # Mapping
122- phase_map[idx] = cable. conn[comp_idx]
123- cable_map[idx] = cable_idx
124- end
125- end
126-
127- earth = _get_earth_data (
128- formulation. equivalent_earth,
129- problem. earth_props,
130- problem. frequencies,
131- T,
132- )
133-
134- temp = T (problem. temperature)
135-
136- # Construct and return the CoaxialWorkspace struct
137- return CoaxialWorkspace (
138- freq = freq,
139- horz = horz, vert = vert,
140- r_in = r_in, r_ext = r_ext,
141- r_ins_in = r_ins_in, r_ins_ext = r_ins_ext,
142- rho_cond = rho_cond, mu_cond = mu_cond, eps_cond = eps_cond,
143- rho_ins = rho_ins, mu_ins = mu_ins, eps_ins = eps_ins, tan_ins = tan_ins,
144- phase_map = phase_map, cable_map = cable_map, earth = earth,
145- temp = temp, n_frequencies = n_frequencies, n_phases = n_components,
146- n_cables = system. num_cables,
147- )
62+ function init_workspace (problem:: LineParametersProblem{T} , formulation:: CoaxialFormulation ) where {T}
63+
64+ opts = formulation. options
65+ # set_logger!(opts.verbosity, opts.logfile)
66+
67+ system = problem. system
68+ n_frequencies = length (problem. frequencies)
69+ n_components = sum (length (cable. design_data. components) for cable in system. cables)
70+
71+ # Pre-allocate 1D arrays
72+ freq = Vector {T} (undef, n_frequencies)
73+ horz = Vector {T} (undef, n_components)
74+ vert = Vector {T} (undef, n_components)
75+ r_in = Vector {T} (undef, n_components)
76+ r_ext = Vector {T} (undef, n_components)
77+ r_ins_in = Vector {T} (undef, n_components)
78+ r_ins_ext = Vector {T} (undef, n_components)
79+ rho_cond = Vector {T} (undef, n_components)
80+ mu_cond = Vector {T} (undef, n_components)
81+ eps_cond = Vector {T} (undef, n_components)
82+ rho_ins = Vector {T} (undef, n_components)
83+ mu_ins = Vector {T} (undef, n_components)
84+ eps_ins = Vector {T} (undef, n_components)
85+ tan_ins = Vector {T} (undef, n_components) # Loss tangent for insulator
86+ phase_map = Vector {Int} (undef, n_components)
87+ cable_map = Vector {Int} (undef, n_components)
88+
89+ # Fill arrays, ensuring type promotion
90+ freq .= problem. frequencies
91+
92+ idx = 0
93+ for (cable_idx, cable) in enumerate (system. cables)
94+ for (comp_idx, component) in enumerate (cable. design_data. components)
95+ idx += 1
96+ # Geometric properties
97+ horz[idx] = T (cable. horz)
98+ vert[idx] = T (cable. vert)
99+ r_in[idx] = T (component. conductor_group. radius_in)
100+ r_ext[idx] = T (component. conductor_group. radius_ext)
101+ r_ins_in[idx] = T (component. insulator_group. radius_in)
102+ r_ins_ext[idx] = T (component. insulator_group. radius_ext)
103+
104+ # Material properties
105+ rho_cond[idx] = T (component. conductor_props. rho)
106+ mu_cond[idx] = T (component. conductor_props. mu_r)
107+ eps_cond[idx] = T (component. conductor_props. eps_r)
108+ rho_ins[idx] = T (component. insulator_props. rho)
109+ mu_ins[idx] = T (component. insulator_props. mu_r)
110+ eps_ins[idx] = T (component. insulator_props. eps_r)
111+
112+ # Calculate loss factor from resistivity
113+ ω = 2 * π * f₀ # Using default frequency
114+ C_eq = T (component. insulator_group. shunt_capacitance)
115+ G_eq = T (component. insulator_group. shunt_conductance)
116+ tan_ins[idx] = G_eq / (ω * C_eq)
117+
118+ # Mapping
119+ phase_map[idx] = cable. conn[comp_idx]
120+ cable_map[idx] = cable_idx
121+ end
122+ end
123+
124+ earth = _get_earth_data (
125+ formulation. equivalent_earth,
126+ problem. earth_props,
127+ problem. frequencies,
128+ T,
129+ )
130+
131+ temp = T (problem. temperature)
132+
133+ # Construct and return the CoaxialWorkspace struct
134+ return CoaxialWorkspace {T} (
135+ freq= freq,
136+ horz= horz, vert= vert,
137+ r_in= r_in, r_ext= r_ext,
138+ r_ins_in= r_ins_in, r_ins_ext= r_ins_ext,
139+ rho_cond= rho_cond, mu_cond= mu_cond, eps_cond= eps_cond,
140+ rho_ins= rho_ins, mu_ins= mu_ins, eps_ins= eps_ins, tan_ins= tan_ins,
141+ phase_map= phase_map, cable_map= cable_map, earth= earth,
142+ temp= temp, n_frequencies= n_frequencies, n_phases= n_components,
143+ n_cables= system. num_cables,
144+ )
148145end
0 commit comments