Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
161 changes: 86 additions & 75 deletions src/Magnetic/FluxTubes/basic.jl
Original file line number Diff line number Diff line change
@@ -1,40 +1,39 @@
"""
Ground(;name)
Ground(; name)

Zero magnetic potential.
"""
@component function Ground(; name)
@named port = PositiveMagneticPort()
eqs = [port.V_m ~ 0]
ODESystem(eqs, t, [], [], systems = [port], name = name)
@mtkmodel Ground begin
@components begin
port = PositiveMagneticPort()
end
@equations begin
port.V_m ~ 0
end
end

"""
Idle(;name)

Idle running branch.
"""
@component function Idle(; name)
@named two_port = TwoPort()
@unpack Phi = two_port
eqs = [
Phi ~ 0,
]
extend(ODESystem(eqs, t, [], [], systems = [], name = name), two_port)
@mtkmodel Idle begin
@extend (Phi,) = two_port = TwoPort()
@equations begin
Phi ~ 0
end
end

"""
Short(;name)

Short cut branch.
"""
@component function Short(; name)
@named two_port = TwoPort()
@unpack V_m = two_port
eqs = [
V_m ~ 0,
]
extend(ODESystem(eqs, t, [], [], systems = [], name = name), two_port)
@mtkmodel Short begin
@extend (V_m,) = two_port = TwoPort()
@equations begin
V_m ~ 0
end
end

"""
Expand All @@ -44,108 +43,120 @@ Crossing of two branches.

This is a simple crossing of two branches. The ports port_p1 and port_p2 are connected, as well as port_n1 and port_n2.
"""
@component function Crossing(; name)
@named port_p1 = PositiveMagneticPort()
@named port_p2 = PositiveMagneticPort()
@named port_n1 = NegativeMagneticPort()
@named port_n2 = NegativeMagneticPort()
eqs = [
connect(port_p1, port_p2),
connect(port_n1, port_n2),
]
ODESystem(eqs, t, [], [], systems = [port_p1, port_p2, port_n1, port_n2], name = name)
@mtkmodel Crossing begin
@components begin
port_p1 = PositiveMagneticPort()
port_p2 = PositiveMagneticPort()
port_n1 = NegativeMagneticPort()
port_n2 = NegativeMagneticPort()
end
@equations begin
connect(port_p1, port_p2)
connect(port_n1, port_n2)
end
end

"""
ConstantPermeance(;name, G_m=1.0)
ConstantPermeance(; name, G_m = 1.0)

Constant permeance.

# Parameters:

- `G_m`: [H] Magnetic permeance
"""
@component function ConstantPermeance(; name, G_m = 1.0)
@named two_port = TwoPort()
@unpack V_m, Phi = two_port
@parameters G_m = G_m
eqs = [
Phi ~ G_m * V_m,
]
extend(ODESystem(eqs, t, [], [G_m], name = name), two_port)
@mtkmodel ConstantPermeance begin
@extend V_m, Phi = two_port = TwoPort()
@parameters begin
G_m = 1.0, [description = "Magnetic permeance"]
end
@equations begin
Phi ~ G_m * V_m
end
end

"""
ConstantReluctance(;name, R_m=1.0)
ConstantReluctance(; name, R_m = 1.0)

Constant reluctance.

# Parameters:

- `R_m`: [H^-1] Magnetic reluctance
"""
@component function ConstantReluctance(; name, R_m = 1.0)
@named two_port = TwoPort()
@unpack V_m, Phi = two_port
@parameters R_m = R_m
eqs = [
V_m ~ Phi * R_m,
]
extend(ODESystem(eqs, t, [], [R_m], name = name), two_port)
@mtkmodel ConstantReluctance begin
@extend V_m, Phi = two_port = TwoPort(; Phi = 0.0)
@parameters begin
R_m = 1.0, [description = "Magnetic reluctance"]
end
@equations begin
V_m ~ Phi * R_m
end
end

"""
ElectroMagneticConverter(;name, N, Phi_start=0.0)
ElectroMagneticConverter(; name, N, Phi)

Ideal electromagnetic energy conversion.

The electromagnetic energy conversion is given by Ampere's law and Faraday's law respectively
V_m = N * i
N * dΦ/dt = -v

Initial magnetic flux flowing into the port_p can be set with `Phi` ([Wb])

# Parameters:

- `N`: Number of turns
- `Phi_start`: [Wb] Initial magnetic flux flowing into the port_p
"""
@component function ElectroMagneticConverter(; name, N, Phi_start = 0.0)
@named port_p = PositiveMagneticPort()
@named port_n = NegativeMagneticPort()
@named p = Pin()
@named n = Pin()

sts = @variables v(t) i(t) V_m(t) Phi(t)=Phi_start
pars = @parameters N = N
eqs = [v ~ p.v - n.v
@mtkmodel ElectroMagneticConverter begin
@parameters begin
N, [description = "Number of turns"]
end
@variables begin
v(t)
i(t)
Phi
end
@extend V_m, Phi = two_port = TwoPort(; Phi = Phi)
@components begin
p = Pin()
n = Pin()
end
@equations begin
v ~ p.v - n.v
0 ~ p.i + n.i
i ~ p.i
V_m ~ port_p.V_m - port_n.V_m
0 ~ port_p.Phi + port_n.Phi
Phi ~ port_p.Phi
#converter equations:
#converter equations:
V_m ~ i * N # Ampere's law
D(Phi) ~ -v / N]
ODESystem(eqs, t, sts, pars, systems = [port_p, port_n, p, n], name = name)
D(Phi) ~ -v / N
end
end

"""
EddyCurrent(;name, rho=0.098e-6, l=1, A=1, Phi_start=0.0)
EddyCurrent(;name, Phi, rho = 0.098e-6, l = 1, A = 1)

For modelling of eddy current in a conductive magnetic flux tube.
Initial magnetic flux flowing into the port_p can be set with `Phi` ([`Wb`])

# Parameters:

- `rho`: [ohm * m] Resistivity of flux tube material (default: Iron at 20degC)
- `l`: [m] Average length of eddy current path
- `A`: [m^2] Cross sectional area of eddy current path
- `Phi_start`: [Wb] Initial magnetic flux flowing into the port_p
"""
@component function EddyCurrent(; name, rho = 0.098e-6, l = 1, A = 1, Phi_start = 0.0)
@named two_port = TwoPort(Phi_start = Phi_start)
@unpack V_m, Phi = two_port
@parameters R = rho * l / A # Electrical resistance of eddy current path
eqs = [
D(Phi) ~ V_m * R,
]
extend(ODESystem(eqs, t, [], [R], name = name), two_port)
"""
@mtkmodel EddyCurrent begin
@variables begin
Phi
end
@parameters begin
rho = 0.098e-6, [description = "Resistivity of flux tube material"]
l = 1, [description = "Average length of eddy current path"]
A = 1, [description = "Cross sectional area of eddy current path"]
R = rho * l / A # Electrical resistance of eddy current path
end
@extend (V_m, Phi) = two_port = TwoPort(; Phi = Phi)
@equations begin
D(Phi) ~ V_m * R
end
end
50 changes: 34 additions & 16 deletions src/Magnetic/FluxTubes/sources.jl
Original file line number Diff line number Diff line change
@@ -1,35 +1,53 @@
"""
ConstantMagneticPotentialDifference(; name, V_m = 0.0)

Constant magnetomotive force.

Parameters:

- `V_m`: [A] Magnetic potential difference
"""
@component function ConstantMagneticPotentialDifference(; name, V_m = 1.0)
port_p = PositiveMagneticPort()
port_n = NegativeMagneticPort()
@parameters V_m = V_m
@variables Phi(t)
eqs = [V_m ~ port_p.V_m - port_n.V_m
@mtkmodel ConstantMagneticPotentialDifference begin
@components begin
port_p = PositiveMagneticPort()
port_n = NegativeMagneticPort()
end
@parameters begin
V_m = 0.0, [description = "Magnetic potential difference"]
end
@variables begin
Phi(t)
end
@equations begin
V_m ~ port_p.V_m - port_n.V_m
Phi ~ port_p.Phi
0 ~ port_p.Phi + port_n.Phi]
ODESystem(eqs, t, [Phi], [V_m], systems = [port_p, port_n], name = name)
0 ~ port_p.Phi + port_n.Phi
end
end

"""
ConstantMagneticFlux(; name, Phi = 0.0)

Source of constant magnetic flux.

Parameters:

- `Phi`: [Wb] Magnetic flux
"""
@component function ConstantMagneticFlux(; name, Phi = 1.0)
port_p = PositiveMagneticPort()
port_n = NegativeMagneticPort()
@parameters Phi = Phi
@variables V_m(t)
eqs = [V_m ~ port_p.V_m - port_n.V_m
@mtkmodel ConstantMagneticFlux begin
@components begin
port_p = PositiveMagneticPort()
port_n = NegativeMagneticPort()
end
@parameters begin
Phi = 0.0, [description = "Magnetic flux"]
end
@variables begin
V_m(t)
end
@equations begin
V_m ~ port_p.V_m - port_n.V_m
Phi ~ port_p.Phi
0 ~ port_p.Phi + port_n.Phi]
ODESystem(eqs, t, [Phi], [V_m], systems = [port_p, port_n], name = name)
0 ~ port_p.Phi + port_n.Phi
end
end
33 changes: 19 additions & 14 deletions src/Magnetic/FluxTubes/utils.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
@connector function MagneticPort(; name, V_m_start = 0.0, Phi_start = 0.0)
@variables V_m(t) = V_m_start # [Wb] Magnetic potential at the port
@variables Phi(t)=Phi_start [connect = Flow] # [A] Magnetic flux flowing into the port"
ODESystem(Equation[], t, [V_m, Phi], []; name = name)
@connector MagneticPort begin
V_m(t), [description = "Magnetic potential at the port"]
Phi(t), [connect = Flow, description = "Magnetic flux flowing into the port"]
end
Base.@doc "Port for a Magnetic system." MagneticPort

Expand All @@ -16,21 +15,27 @@ Negative magnetic port
const NegativeMagneticPort = MagneticPort

"""
TwoPort(;name, V_m_start=0.0, Phi_start=0.0)
TwoPort(; name, V_m = 0.0, Phi = 0.0)

Partial component with magnetic potential difference between two magnetic ports p and n and magnetic flux Phi from p to n.

# Parameters:

- `V_m_start`: Initial magnetic potential difference between both ports
- `Phi_start`: Initial magnetic flux from port_p to port_n
- `V_m`: Initial magnetic potential difference between both ports
- `Phi`: Initial magnetic flux from port_p to port_n
"""
@component function TwoPort(; name, V_m_start = 0.0, Phi_start = 0.0)
@named port_p = PositiveMagneticPort()
@named port_n = NegativeMagneticPort()
@variables V_m(t)=V_m_start Phi(t)=Phi_start
eqs = [V_m ~ port_p.V_m - port_n.V_m
@mtkmodel TwoPort begin
@components begin
port_p = PositiveMagneticPort()
port_n = NegativeMagneticPort()
end
@variables begin
V_m(t) = 0.0
Phi(t) = 0.0
end
@equations begin
V_m ~ port_p.V_m - port_n.V_m
Phi ~ port_p.Phi
0 ~ port_p.Phi + port_n.Phi]
ODESystem(eqs, t, [V_m, Phi], [], systems = [port_p, port_n], name = name)
0 ~ port_p.Phi + port_n.Phi
end
end
2 changes: 1 addition & 1 deletion test/Magnetic/magnetic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ using OrdinaryDiffEq: ReturnCode.Success
@named voltage = Electrical.Voltage()
@named r = Electrical.Resistor(R = 7.5)
@named ground = Electrical.Ground()
@named coil = Magnetic.FluxTubes.ElectroMagneticConverter(N = 600)
@named coil = Magnetic.FluxTubes.ElectroMagneticConverter(N = 600, Phi = 0.0)
@named ground_m = Magnetic.FluxTubes.Ground()
@named r_mAirPar = Magnetic.FluxTubes.ConstantReluctance(R_m = a * b * l_air * mu_air)
@named r_mFe = Magnetic.FluxTubes.ConstantReluctance(R_m = a * b * l_Fe * mu_Fe)
Expand Down