From eced33afe9d66911636a43c6c52d3e55a4e9559d Mon Sep 17 00:00:00 2001 From: Valentin Kaisermayer Date: Tue, 7 Jun 2022 19:19:50 +0200 Subject: [PATCH 1/2] fixes docs --- src/Electrical/Analog/ideal_components.jl | 116 ++++++++-------------- src/Electrical/Analog/sensors.jl | 106 ++++++++------------ src/Electrical/Analog/sources.jl | 18 +++- src/Electrical/utils.jl | 38 ++++--- 4 files changed, 116 insertions(+), 162 deletions(-) diff --git a/src/Electrical/Analog/ideal_components.jl b/src/Electrical/Analog/ideal_components.jl index a3836affc..d3317d18b 100644 --- a/src/Electrical/Analog/ideal_components.jl +++ b/src/Electrical/Analog/ideal_components.jl @@ -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) @@ -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() @@ -47,18 +39,18 @@ function Resistor(;name, R) end """ - Conductor(;name, G) + Capacitor(; name, C) -Ideal linear electrical conductor. +Creates an ideal Capacitor. -# 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) @@ -72,27 +64,22 @@ function Conductor(;name, G) end """ -```julia -function Capacitor(; name, C) -``` + Capacitor(; name, C) + 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) @@ -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) @@ -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() diff --git a/src/Electrical/Analog/sensors.jl b/src/Electrical/Analog/sensors.jl index ec3fe3ae2..6b01b48d7 100644 --- a/src/Electrical/Analog/sensors.jl +++ b/src/Electrical/Analog/sensors.jl @@ -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() @@ -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() @@ -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() @@ -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() @@ -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() diff --git a/src/Electrical/Analog/sources.jl b/src/Electrical/Analog/sources.jl index 09318f3bc..ac00a4d70 100644 --- a/src/Electrical/Analog/sources.jl +++ b/src/Electrical/Analog/sources.jl @@ -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() @@ -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() diff --git a/src/Electrical/utils.jl b/src/Electrical/utils.jl index d6932cfd1..ed469dead 100644 --- a/src/Electrical/utils.jl +++ b/src/Electrical/utils.jl @@ -6,31 +6,31 @@ ODESystem(Equation[], t, sts, [], name=name, defaults=Dict(v=>1.0, i=>1.0)) end @doc """ -```julia -@connector function Pin(; name) -``` + Pin(; name) A pin in an analog circuit. -# States -- `v(t)`: [`V`] - The voltage at this pin -- `i(t)`: [`A`] - The current passing through this pin +# States: +- `v(t)`: [`V`] The voltage at this pin +- `i(t)`: [`A`] The current passing through this pin """ Pin """ -```julia OnePort(; name, v_start=0.0, i_start=0.0) -``` Component with two electrical pins `p` and `n` and current `i` from `p` to `n`. +# States: +- `v(t)`: [`V`] The voltage across component `p.v - n.v` +- `i(t)`: [`A`] The current passing through positive pin + # Parameters: -- `v_start`: [`V`] - Initial voltage across the component -- `i_start`: [`A`] - Initial current through the component +- `v_start`: [`V`] Initial voltage across the component +- `i_start`: [`A`] Initial current through the component + +# Connectors: +- `p` Positive pin +- `n` Negative pin """ function OnePort(;name, v_start=0.0, i_start=0.0) @named p = Pin() @@ -56,16 +56,14 @@ end ODESystem(Equation[], t, [val, v, i], [], defaults=Dict(val=>0, i=>0), name=name) end @doc """ -```julia -@connector function DigitalPin(; name) -``` + DigitalPin(; name) A pin in a digital circuit. -# States +# States: - `v(t)`: [`V`] The voltage at this pin - `i(t)`: [`A`] The current passing through this pin -- `val(t)`: The binary value of the pin at this point. A voltage from `0V` to `0.8V` is a binary value - of `0`. A voltage in the range `2.0V` to `5.0V` is `1`. Any other value is `X`. +- `val(t)`: The binary value of the pin at this point. A voltage from `0V` to `0.8V` is a binary value of `0`. +A voltage in the range `2.0V` to `5.0V` is `1`. Any other value is `X`. """ DigitalPin From 909f4a795afa5fc9a4a9afbea42c6258f4dc47a0 Mon Sep 17 00:00:00 2001 From: Valentin Kaisermayer Date: Tue, 7 Jun 2022 19:32:28 +0200 Subject: [PATCH 2/2] fix conductor --- src/Electrical/Analog/ideal_components.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Electrical/Analog/ideal_components.jl b/src/Electrical/Analog/ideal_components.jl index d3317d18b..8d49b3465 100644 --- a/src/Electrical/Analog/ideal_components.jl +++ b/src/Electrical/Analog/ideal_components.jl @@ -39,9 +39,9 @@ function Resistor(;name, R) end """ - Capacitor(; name, C) + Conductor(;name, G) -Creates an ideal Capacitor. +Creates an ideal conductor. # States: See [OnePort](@ref) @@ -67,7 +67,7 @@ end Capacitor(; name, C) -Creates an ideal Capacitor. +Creates an ideal capacitor. # States: - `v(t)`: [`V`]