1- # Copyright 2015, 2016, 2017, 2018, 2019, 2020, 2021 Martin Holters
1+ # Copyright 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2023 Martin Holters
22# See accompanying license file.
33
44export resistor, potentiometer, capacitor, inductor, transformer,
@@ -97,8 +97,12 @@ Magnetization"](http://dafx.de/paper-archive/2016/dafxpapers/08-DAFx-16_paper_10
9797Pins: `1` and `2` for primary winding, `3` and `4` for secondary winding, and so
9898on
9999"""
100- function transformer(::Type{Val{:JA}}; D=2.4e-2, A=4.54e-5, ns=[],
101- a=14.1, α=5e-5, c=0.55, k=17.8, Ms=2.75e5)
100+ transformer(::Type{Val{:JA}}; ns=[], α=5e-5, c=0.55, kwargs...) =
101+ _transformer_ja(ns, α, c, (; kwargs...))
102+ _transformer_ja(ns, α, c, kwargs::NamedTuple{<:Any, <:Tuple{Vararg{Real}}}) =
103+ __transformer_ja(; ns=ns, α=α, c=c, kwargs...)
104+ function __transformer_ja(; D=2.4e-2, A=4.54e-5, ns=[],
105+ a=14.1, α=5e-5, c=0.55, k=17.8, Ms=2.75e5)
102106 μ0 = 1.2566370614e-6
103107 nonlinear_eq = @inline function (q)
104108 coth_q1 = coth(q[1])
@@ -175,7 +179,8 @@ Pins: `+` and `-` with `v` being measured from `+` to `-`
175179"""
176180function voltagesource end
177181voltagesource(v; rs=0) = Element(mv=1, mi=-rs, u0=v, ports=[:+ => :-])
178- voltagesource(; rs=0) = Element(mv=1, mi=-rs, mu=1, ports=[:+ => :-])
182+ voltagesource(; rs=0) = _voltagesource(rs)
183+ _voltagesource(rs) = Element(mv=1, mi=-rs, mu=1, ports=[:+ => :-])
179184
180185"""
181186 currentsource(; gp=0)
@@ -190,7 +195,8 @@ Pins: `+` and `-` where `i` measures the current leaving source at the `+` pin
190195"""
191196function currentsource end
192197currentsource(i; gp=0) = Element(mv=gp, mi=-1, u0=i, ports=[:+ => :-])
193- currentsource(; gp=0) = Element(mv=gp, mi=-1, mu=1, ports=[:+ => :-])
198+ currentsource(; gp=0) = _currentsource(gp)
199+ _currentsource(gp) = Element(mv=gp, mi=-1, mu=1, ports=[:+ => :-])
194200
195201"""
196202 voltageprobe()
@@ -201,7 +207,8 @@ defaults to zero.
201207
202208Pins: `+` and `-` with the output voltage being measured from `+` to `-`
203209"""
204- voltageprobe(;gp=0) = Element(mv=-gp, mi=1, pv=1, ports=[:+ => :-])
210+ voltageprobe(;gp=0) = _voltageprobe(gp)
211+ _voltageprobe(gp) = Element(mv=-gp, mi=1, pv=1, ports=[:+ => :-])
205212
206213"""
207214 currentprobe()
@@ -213,7 +220,8 @@ defaults to zero.
213220Pins: `+` and `-` with the output current being the current entering the probe
214221at `+`
215222"""
216- currentprobe(;rs=0) = Element(mv=1, mi=-rs, pi=1, ports=[:+ => :-])
223+ currentprobe(;rs=0) = _currentprobe(rs)
224+ _currentprobe(rs=0) = Element(mv=1, mi=-rs, pi=1, ports=[:+ => :-])
217225
218226@doc raw"""
219227 diode(;is=1e-12, η = 1)
@@ -224,7 +232,8 @@ The reverse saturation current `is` has to be given in Ampere, the emission
224232coefficient `η` is unitless.
225233
226234Pins: `+` (anode) and `-` (cathode)
227- """ diode(;is::Real=1e-12, η::Real = 1) =
235+ """ diode(;is=1e-12, η = 1) = _diode(is, η)
236+ _diode(is::Real, η::Real) =
228237 Element(mv=[1;0], mi=[0;1], mq=[-1 0; 0 -1], ports=[:+ => :-], nonlinear_eq =
229238 @inline function(q)
230239 v, i = q
@@ -295,7 +304,9 @@ The parameters are set using named arguments:
295304| `rb` | Base terminal resistance
296305
297306Pins: `base`, `emitter`, `collector`
298- """ function bjt(typ; is=1e-12, η=1, isc=is, ise=is, ηc=η, ηe=η, βf=1000, βr=10,
307+ """ bjt(typ; kwargs...) = _bjt(typ, (; kwargs...))
308+ _bjt(typ, kwargs::NamedTuple{<:Any, <:Tuple{Vararg{Real}}}) = __bjt(typ; kwargs...)
309+ function __bjt(typ; is=1e-12, η=1, isc=is, ise=is, ηc=η, ηe=η, βf=1000, βr=10,
299310 ile=0, ilc=0, ηcl=ηc, ηel=ηe, vaf=Inf, var=Inf, ikf=Inf, ikr=Inf,
300311 re=0, rc=0, rb=0)
301312 local polarity
@@ -419,7 +430,10 @@ respectively. E.g. with `vt=(0.7, 0.1, 0.02)`, the $v_{GS}$-dpendent threshold
419430voltage $v_T = 0.7 + 0.1\cdot v_{GS} + 0.02\cdot v_{GS}^2$ will be used.
420431
421432Pins: `gate`, `source`, `drain`
422- """ function mosfet(typ; vt=0.7, α=2e-5, λ=0)
433+ """ mosfet(typ; kwargs...) = _mosfet(typ, (; kwargs...))
434+ _mosfet(typ, kwargs::NamedTuple{<:Any, <:Tuple{Vararg{Union{Real,Tuple{Vararg{Real}}}}}}) =
435+ __mosfet(typ; kwargs...)
436+ function __mosfet(typ; vt=0.7, α=2e-5, λ=0)
423437 if typ == :n
424438 polarity = 1
425439 elseif typ == :p
@@ -519,7 +533,7 @@ connected to a ground node and has to provide the current sourced on the other
519533output pin.
520534
521535Pins: `in+` and `in-` for input, `out+` and `out-` for output
522- """ function opamp(::Type{Val{:macak}}, gain, vomin, vomax)
536+ """ function opamp(::Type{Val{:macak}}, gain::Real , vomin::Real , vomax::Real )
523537 offset = 0.5 * (vomin + vomax)
524538 scale = 0.5 * (vomax - vomin)
525539 nonlinear_eq =
0 commit comments