Skip to content

Electrical formatting changes #64

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 7, 2022
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
116 changes: 43 additions & 73 deletions src/Electrical/Analog/ideal_components.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
"""
```julia
function Ground(; name)
```
Ground(; name)

Ground node with the potential of zero and connector `g`. Every circuit must have one ground
node.

# Connectors
# Connectors:
- `g`
"""
function Ground(;name)
Expand All @@ -16,25 +14,19 @@ function Ground(;name)
end

"""
```julia
function Resistor(; name, R)
```
Resistor(; name, R)

Creates an ideal Resistor following Ohm's Law.

# States
- `v(t)`: [`V`]
The voltage across the resistor, given by `p.i * R`
# States:
See [OnePort](@ref)

# Connectors
- `p`
Positive pin
- `n`
Negative pin
# Connectors:
- `p` Positive pin
- `n` Negative pin

# Parameters:
- `R`: [`Ω`]
Resistance
- `R`: [`Ω`] Resistance
"""
function Resistor(;name, R)
@named oneport = OnePort()
Expand All @@ -49,16 +41,16 @@ end
"""
Conductor(;name, G)

Ideal linear electrical conductor.
Creates an ideal conductor.

# States
- see [`OnePort`](@ref)
# States:
See [OnePort](@ref)

# Connectors
# Connectors:
- `p` Positive pin
- `n` Negative pin

# Parameters:
# Parameters:
- `G`: [`S`] Conductance
"""
function Conductor(;name, G)
Expand All @@ -72,27 +64,22 @@ function Conductor(;name, G)
end

"""
```julia
function Capacitor(; name, C)
```
Capacitor(; name, C)


Creates an ideal Capacitor.
Creates an ideal capacitor.

# States
# States:
- `v(t)`: [`V`]
The voltage across the capacitor, given by `D(v) ~ p.i / C`

# Connectors
- `p`
Positive pin
- `n`
Negative pin
# Connectors:
- `p` Positive pin
- `n` Negative pin

# Parameters:
- `C`: [`F`]
Capacitance
- `v_start`: [`V`]
Initial voltage of capacitor
- `C`: [`F`] Capacitance
- `v_start`: [`V`] Initial voltage of capacitor
"""
function Capacitor(;name, C, v_start=0.0)
@named oneport = OnePort(;v_start=v_start)
Expand All @@ -105,27 +92,20 @@ function Capacitor(;name, C, v_start=0.0)
end

"""
```julia
function Inductor(; name, L)
```
Inductor(; name, L)

Creates an ideal Inductor.

# States
- `v(t)`: [`V`]
The voltage across the inductor, given by `D(p.i) ~ v / L`
# States:
See [OnePort](@ref)

# Connectors
- `p`
Positive pin
- `n`
Negative pin
# Connectors:
- `p` Positive pin
- `n` Negative pin

# Parameters:
- `L`: [`H`]
Inductance
- `i_start`: [`A`]
Initial current through inductor
- `L`: [`H`] Inductance
- `i_start`: [`A`] Initial current through inductor
"""
function Inductor(;name, L, i_start=0.0)
@named oneport = OnePort(;i_start=i_start)
Expand All @@ -138,33 +118,23 @@ function Inductor(;name, L, i_start=0.0)
end

"""
```julia
function IdealOpAmp(; name)
```
IdealOpAmp(; name)

Ideal operational amplifier (norator-nullator pair).
The ideal OpAmp is a two-port. The left port is fixed to `v1 = 0` and `i1 = 0` (nullator).
At the right port both any voltage `v2` and any current `i2` are possible (norator).

# States
- `v1(t)`: [`V`]
Voltage of left port
- `v2(t)`: [`V`]
Voltage of right port
- `i1(t)`: [`A`]
Current of left port
- `i2(t)`: [`A`]
Current of right port

# Connectors
- `p1`
Positive pin (left port)
- `p2`
Positive pin (right port)
- `n1`
Negative pin (left port)
- `n2`
Negative pin (right port)
# States:
- `v1(t)`: [`V`] Voltage of left port
- `v2(t)`: [`V`] Voltage of right port
- `i1(t)`: [`A`] Current of left port
- `i2(t)`: [`A`] Current of right port

# Connectors:
- `p1` Positive pin (left port)
- `p2` Positive pin (right port)
- `n1` Negative pin (left port)
- `n2` Negative pin (right port)
"""
function IdealOpAmp(;name)
@named p1 = Pin()
Expand Down
106 changes: 39 additions & 67 deletions src/Electrical/Analog/sensors.jl
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
"""
```julia
function CurrentSensor(; name)
```
CurrentSensor(; name)

Creates a circuit component that measures the current flowing through it. Analogous to
an ideal ammeter.

# States
- `i(t)`: [`A`]
Current through the sensor
# States:
- `i(t)`: [`A`] Current through the sensor

# Connectors
- `p`
Positive pin
- `n`
Negative pin
# Connectors:
- `p` Positive pin
- `n` Negative pin
"""
function CurrentSensor(; name)
@named p = Pin()
Expand All @@ -29,19 +24,15 @@ function CurrentSensor(; name)
end

"""
```julia
function PotentialSensor(; name)
```
PotentialSensor(; name)

Creates a circuit component which measures the potential at a pin.

# States
- `phi(t)`: [`V`]
The potential at this point
# States:
- `phi(t)`: [`V`] The measured potential at this point

# Connectors
- `p`
Pin at which potential is to be measured
# Connectors:
- `p` Pin at which potential is to be measured
"""
function PotentialSensor(; name)
@named p = Pin()
Expand All @@ -54,22 +45,16 @@ function PotentialSensor(; name)
end

"""
```julia
function VoltageSensor(; name)
```
VoltageSensor(; name)

Creates a circuit component that measures the voltage across it. Analogous to
an ideal voltmeter.
Creates a circuit component that measures the voltage across it. Analogous to an ideal voltmeter.

# States
- `v(t)`: [`V`]
The voltage across this component
# States:
- `v(t)`: [`V`] The voltage difference form positive to negative pin `p.v - n.v`

# Connectors
- `p`
Positive pin
- `n`
Negative pin
# Connectors:
- `p` Positive pin
- `n` Negative pin
"""
function VoltageSensor(; name)
@named p = Pin()
Expand All @@ -84,26 +69,21 @@ function VoltageSensor(; name)
end

"""
```julia
function PowerSensor(; name)
```
PowerSensor(; name)

Combines a [`VoltageSensor`](@ref) and a [`CurrentSensor`](@ref) to measure the power being
consumed by a circuit.

# States
- `power(t)`: [`W`]
The power being consumed, given by the product of voltage and current.

# Connectors
- `pc`
Corresponds to the `p` pin of the [`CurrentSensor`](@ref)
- `nc`
Corresponds to the `n` pin of the [`CurrentSensor`](@ref)
- `pv`
Corresponds to the `p` pin of the [`VoltageSensor`](@ref)
- `nv`
Corresponds to the `n` pin of the [`VoltageSensor`](@ref)
# States:
- `power(t)`: [`W`] The power being consumed, given by the product of voltage and current.
- See [VoltageSensor](@ref)
- See [CurrentSensor](@ref)

# Connectors:
- `pc` Corresponds to the `p` pin of the [`CurrentSensor`](@ref)
- `nc` Corresponds to the `n` pin of the [`CurrentSensor`](@ref)
- `pv` Corresponds to the `p` pin of the [`VoltageSensor`](@ref)
- `nv` Corresponds to the `n` pin of the [`VoltageSensor`](@ref)
"""
function PowerSensor(; name)
@named pc = Pin()
Expand All @@ -124,27 +104,19 @@ function PowerSensor(; name)
end

"""
```julia
function MultiSensor(; name)
```
MultiSensor(; name)

Combines a [`VoltageSensor`](@ref) and a [`CurrentSensor`](@ref).

# States
- `v(t)`: [`V`]
The voltage across the [`VoltageSensor`](@ref)
- `i(t)`: [`A`]
The current across the [`CurrentSensor`](@ref)

# Connectors
- `pc`
Corresponds to the `p` pin of the [`CurrentSensor`](@ref)
- `nc`
Corresponds to the `n` pin of the [`CurrentSensor`](@ref)
- `pv`
Corresponds to the `p` pin of the [`VoltageSensor`](@ref)
- `nv`
Corresponds to the `n` pin of the [`VoltageSensor`](@ref)
# States:
- `v(t)`: [`V`] The voltage across the [`VoltageSensor`](@ref)
- `i(t)`: [`A`] The current across the [`CurrentSensor`](@ref)

# Connectors:
- `pc` Corresponds to the `p` pin of the [`CurrentSensor`](@ref)
- `nc` Corresponds to the `n` pin of the [`CurrentSensor`](@ref)
- `pv` Corresponds to the `p` pin of the [`VoltageSensor`](@ref)
- `nv` Corresponds to the `n` pin of the [`VoltageSensor`](@ref)
"""
function MultiSensor(; name)
@named pc = Pin()
Expand Down
18 changes: 16 additions & 2 deletions src/Electrical/Analog/sources.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
"""
Voltage(;name)

Acts as voltage signal.
Acts as an ideal voltage source with no internal resistance.

# States:
See [OnePort](@ref)

# Connectors:
- `p` Positive pin
- `n` Negative pin
- `V` [RealInput](@ref) Input for the voltage control signal, i.e. `V ~ p.v - n.v`
"""
function Voltage(;name)
@named oneport = OnePort()
Expand All @@ -18,8 +25,15 @@ end
"""
Current(;name)

Acts as current signal.
Acts as an ideal current source with no internal resistance.

# States:
See [OnePort](@ref)

# Connectors:
- `p` Positive pin
- `n` Negative pin
- `I` [RealInput](@ref) Input for the current control signal, i.e. `I ~ p.i
"""
function Current(;name)
@named oneport = OnePort()
Expand Down
Loading