Skip to content

Commit

Permalink
Merge branch 'release-0.6.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
martinholters committed Feb 19, 2018
2 parents bd7faa6 + 4b4b02f commit 84277e7
Show file tree
Hide file tree
Showing 13 changed files with 90 additions and 45 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# ACME.jl - Analog Circuit Modeling and Emulation for Julia

[![Join the chat at https://gitter.im/HSU-ANT/ACME.jl](https://badges.gitter.im/HSU-ANT/ACME.jl.svg)](https://gitter.im/HSU-ANT/ACME.jl?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![Documentation](https://img.shields.io/badge/docs-v0.6.1-blue.svg)](https://hsu-ant.github.io/ACME.jl/v0.6.1)
[![Documentation](https://img.shields.io/badge/docs-v0.6.2-blue.svg)](https://hsu-ant.github.io/ACME.jl/v0.6.2)

ACME is a [Julia](http://julialang.org/) package for the simulation of
electrical circuits, focusing on audio effect circuits. It allows to
Expand Down Expand Up @@ -124,7 +124,7 @@ fail to run altogether.

## Moving on

There is some [documentation](https://hsu-ant.github.io/ACME.jl/v0.6.1)
There is some [documentation](https://hsu-ant.github.io/ACME.jl/v0.6.2)
available for how
to use ACME. Additionally, you can take a look at the examples that can be found
in the `examples` directory below `Pkg.dir("ACME")`.
Expand Down
8 changes: 5 additions & 3 deletions examples/birdie.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2016, 2017 Martin Holters
# Copyright 2016, 2017, 2018 Martin Holters
# See accompanying license file.

using ACME
Expand Down Expand Up @@ -30,5 +30,7 @@ function birdie(::Type{Circuit}; vol=nothing)
end
end

birdie{T<:DiscreteModel}(::Type{T}=DiscreteModel; vol=nothing, fs=44100) =
T(birdie(Circuit, vol=vol), 1//fs)
birdie(::Type{DiscreteModel}=DiscreteModel; vol=nothing, fs=44100, solver=nothing) =
solver === nothing ?
DiscreteModel(birdie(Circuit, vol=vol), 1//fs) :
DiscreteModel(birdie(Circuit, vol=vol), 1//fs, solver)
8 changes: 5 additions & 3 deletions examples/diodeclipper.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2015, 2016, 2017 Martin Holters
# Copyright 2015, 2016, 2017, 2018 Martin Holters
# See accompanying license file.

using ACME
Expand All @@ -14,5 +14,7 @@ function diodeclipper(::Type{Circuit})
end
end

diodeclipper{T<:DiscreteModel}(::Type{T}=DiscreteModel; fs=44100) =
T(diodeclipper(Circuit), 1//fs)
diodeclipper(::Type{DiscreteModel}=DiscreteModel; fs=44100, solver=nothing) =
solver === nothing ?
DiscreteModel(diodeclipper(Circuit), 1//fs) :
DiscreteModel(diodeclipper(Circuit), 1//fs, solver)
8 changes: 5 additions & 3 deletions examples/sallenkey.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2015, 2017 Martin Holters
# Copyright 2015, 2016, 2017, 2018 Martin Holters
# See accompanying license file.

using ACME
Expand All @@ -16,5 +16,7 @@ function sallenkey(::Type{Circuit})
end
end

sallenkey{T<:DiscreteModel}(::Type{T}=DiscreteModel; fs=44100) =
T(sallenkey(Circuit), 1//fs)
sallenkey(::Type{DiscreteModel}=DiscreteModel; fs=44100, solver=nothing) =
solver === nothing ?
DiscreteModel(sallenkey(Circuit), 1//fs) :
DiscreteModel(sallenkey(Circuit), 1//fs, solver)
8 changes: 5 additions & 3 deletions examples/superover.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2016, 2017 Martin Holters
# Copyright 2016, 2017, 2018 Martin Holters
# See accompanying license file.

using ACME
Expand Down Expand Up @@ -71,5 +71,7 @@ function superover(::Type{Circuit}; drive=nothing, tone=nothing, level=nothing,
return circ
end

superover{T<:DiscreteModel}(::Type{T}=DiscreteModel; drive=nothing, tone=nothing, level=nothing, sym::Bool=false, fs=44100) =
T(superover(Circuit, drive=drive, tone=tone, level=level, sym=sym), 1//fs)
superover(::Type{DiscreteModel}=DiscreteModel;drive=nothing, tone=nothing, level=nothing, sym::Bool=false, fs=44100, solver=nothing) =
solver === nothing ?
DiscreteModel(superover(Circuit, drive=drive, tone=tone, level=level, sym=sym), 1//fs) :
DiscreteModel(superover(Circuit, drive=drive, tone=tone, level=level, sym=sym), 1//fs, solver)
4 changes: 2 additions & 2 deletions src/ACME.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2015, 2016, 2017 Martin Holters
# Copyright 2015, 2016, 2017, 2018 Martin Holters
# See accompanying license file.

__precompile__()
Expand Down Expand Up @@ -768,7 +768,7 @@ function rank_factorize(a::SparseMatrixCSC)
return c, f
end

consecranges(lengths) = isempty(lengths) ? [] : range.(cumsum([1; lengths[1:end-1]]), lengths)
consecranges(lengths) = isempty(lengths) ? [] : ((s,l) -> (s:s+l-1)).(cumsum([1; lengths[1:end-1]]), lengths)

matsplit(v::AbstractVector, rowsizes) = [v[rs] for rs in consecranges(rowsizes)]
matsplit(m::AbstractMatrix, rowsizes, colsizes=[size(m,2)]) =
Expand Down
2 changes: 1 addition & 1 deletion src/circuit.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2015, 2016, 2017 Martin Holters
# Copyright 2015, 2016, 2017, 2018 Martin Holters
# See accompanying license file.

export Circuit, add!, connect!, disconnect!, @circuit
Expand Down
3 changes: 3 additions & 0 deletions src/compat.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright 2018 Martin Holters
# See accompanying license file.

using Compat

if VERSION v"0.6.0"
Expand Down
17 changes: 7 additions & 10 deletions src/elements.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2015, 2016, 2017 Martin Holters
# Copyright 2015, 2016, 2017, 2018 Martin Holters
# See accompanying license file.

export resistor, potentiometer, capacitor, inductor, transformer,
Expand Down Expand Up @@ -222,7 +222,7 @@ at `+`
"""
currentprobe(;rs=0) = Element(mv=1, mi=-rs, pi=1, pins=[:+; :-])

doc"""
@doc doc"""
diode(;is=1e-12, η = 1)
Creates a diode obeying Shockley's law
Expand All @@ -231,8 +231,7 @@ The reverse saturation current `is` has to be given in Ampere, the emission
coefficient `η` is unitless.
Pins: `+` (anode) and `-` (cathode)
"""
diode(;is::Real=1e-12, η::Real = 1) =
""" diode(;is::Real=1e-12, η::Real = 1) =
Element(mv=[1;0], mi=[0;1], mq=[-1 0; 0 -1], pins=[:+; :-], nonlinear_eq =
quote
let v = q[1], i = q[2], ex = exp(v*$(1 / (25e-3 * η)))
Expand All @@ -243,7 +242,7 @@ diode(;is::Real=1e-12, η::Real = 1) =
end
)

doc"""
@doc doc"""
bjt(typ; is=1e-12, η=1, isc=is, ise=is, ηc=η, ηe=η, βf=1000, βr=10,
ile=0, ilc=0, ηcl=ηc, ηel=ηe, vaf=Inf, var=Inf, ikf=Inf, ikr=Inf)
Expand Down Expand Up @@ -303,8 +302,7 @@ The parameters are set using named arguments:
| `rb` | Base terminal resistance
Pins: `base`, `emitter`, `collector`
"""
function bjt(typ; is=1e-12, η=1, isc=is, ise=is, ηc=η, ηe=η, βf=1000, βr=10,
""" function bjt(typ; is=1e-12, η=1, isc=is, ise=is, ηc=η, ηe=η, βf=1000, βr=10,
ile=0, ilc=0, ηcl=ηc, ηel=ηe, vaf=Inf, var=Inf, ikf=Inf, ikr=Inf,
re=0, rc=0, rb=0)
local polarity
Expand Down Expand Up @@ -455,7 +453,7 @@ Pins: `in+` and `in-` for input, `out+` and `out-` for output
opamp() = Element(mv=[0 0; 1 0], mi=[1 0; 0 0],
pins=["in+", "in-", "out+", "out-"])

doc"""
@doc doc"""
opamp(Val{:macak}, gain, vomin, vomax)
Creates a clipping operational amplifier where input and output voltage are
Expand All @@ -472,8 +470,7 @@ connected to a ground node and has to provide the current sourced on the other
output pin.
Pins: `in+` and `in-` for input, `out+` and `out-` for output
"""
function opamp(::Type{Val{:macak}}, gain, vomin, vomax)
""" function opamp(::Type{Val{:macak}}, gain, vomin, vomax)
offset = 0.5 * (vomin + vomax)
scale = 0.5 * (vomax - vomin)
nonlinear_eq =
Expand Down
2 changes: 1 addition & 1 deletion src/kdtree.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2016, 2017 Martin Holters
# Copyright 2016, 2017, 2018 Martin Holters
# See accompanying license file.

import Base.deleteat!
Expand Down
8 changes: 4 additions & 4 deletions src/solvers.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2016, 2017 Martin Holters
# Copyright 2016, 2017, 2018 Martin Holters
# See accompanying license file.

export SimpleSolver, HomotopySolver, CachingSolver
Expand Down Expand Up @@ -155,8 +155,8 @@ the last solution found (or another solution provided externally) using the
available Jacobians. Due to the missing global convergence, the `SimpleSolver`
is rarely useful as such.
"""
#mutable struct SimpleSolver{NLEQ<:ParametricNonLinEq}
@mutable_struct SimpleSolver{NLEQ<:ParametricNonLinEq} begin
#mutable struct SimpleSolver{NLEQ<:ParametricNonLinEq}
nleq::NLEQ
z::Vector{Float64}
linsolver::LinearSolver
Expand Down Expand Up @@ -257,8 +257,8 @@ can be combined with the `SimpleSolver` as `HomotopySolver{SimpleSolver}` to
obtain a useful Newton homtopy solver with generally good convergence
properties.
"""
#mutable struct HomotopySolver{BaseSolver}
@mutable_struct HomotopySolver{BaseSolver} begin
#mutable struct HomotopySolver{BaseSolver}
basesolver::BaseSolver
start_p::Vector{Float64}
pa::Vector{Float64}
Expand Down Expand Up @@ -332,8 +332,8 @@ See [M. Holters, U. Zölzer, "A k-d Tree Based Solution Cache for the Non-linear
Equation of Circuit Simulations"](http://www.eurasip.org/Proceedings/Eusipco/Eusipco2016/papers/1570255150.pdf)
for a more detailed discussion.
"""
#mutable struct CachingSolver{BaseSolver}
@mutable_struct CachingSolver{BaseSolver} begin
#mutable struct CachingSolver{BaseSolver}
basesolver::BaseSolver
ps_tree::KDTree{Vector{Float64}, Matrix{Float64}}
zs::Matrix{Float64}
Expand Down
34 changes: 34 additions & 0 deletions test/checklic.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Copyright 2018 Martin Holters
# See accompanying license file.
@static if VERSION < v"0.6"
ACMEdir = joinpath(dirname(@__FILE__), "..")
else
ACMEdir = joinpath(@__DIR__, "..")
end
println("Checking copyright headers...")
for dirname in ("src", "examples", "test")
dirname = joinpath(ACMEdir, dirname)
for name in readdir(dirname)
if endswith(name, ".jl")
name = joinpath(dirname, name)
years = sort!(unique(parse.([Int], readlines(`git log --format=%cd --date=format:%Y -- $name`))))
if isempty(years)
continue
end
println(name)
open(name, "r") do io
l = readline(io)
#println(l)
m = match(r"#\s*Copyright\s+(([0-9]+(,\s*)?)*)", l)
if m === nothing
error("Missing copyright header in $name")
end
headyears = parse.([Int], strip.(split(m.captures[1], ',')))
d = setdiff(years, headyears)
if !isempty(d)
error("Missing years in copyright header of $name: $d")
end
end
end
end
end
29 changes: 16 additions & 13 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Copyright 2015, 2016, 2017 Martin Holters
# Copyright 2015, 2016, 2017, 2018 Martin Holters
# See accompanying license file.

include("checklic.jl")

using ACME
using Compat
using Compat.Test
Expand All @@ -9,7 +11,9 @@ using ProgressMeter
if VERSION v"0.7.0-DEV.3389"
using SparseArrays
end

if VERSION < v"0.7.0-DEV.3986"
range(start; stop=error("missing stop"), length=error("missing length")) = linspace(start, stop, length)
end
@testset "topomat" begin
tv, ti = ACME.topomat(sparse([1 -1 1; -1 1 -1]))
@test tv*ti'==spzeros(2,1)
Expand Down Expand Up @@ -356,7 +360,7 @@ end
end
model = DiscreteModel(circ, 1)
N = 100
output = run!(model, [linspace(0, ib, N)'; linspace(1, -1, N÷2)' linspace(-1, 1, N÷2)'])
output = run!(model, [range(0, stop=ib, length=N)'; range(1, stop=-1, length=N÷2)' range(-1, stop=1, length=N÷2)'])
if typ == :pnp
output = -output
end
Expand Down Expand Up @@ -386,7 +390,7 @@ end
end
model = DiscreteModel(circ, 1)
N = 100
output = run!(model, [linspace(0, ib, N)'; linspace(1, -1, N÷2)' linspace(-1, 1, N÷2)'])
output = run!(model, [range(0, stop=ib, length=N)'; range(1, stop=-1, length=N÷2)' range(-1, stop=1, length=N÷2)'])
if typ == :pnp
output = -output
end
Expand Down Expand Up @@ -467,7 +471,7 @@ end

@testset "examples" begin
@testset "sallenkey" begin
include("../examples/sallenkey.jl")
include(joinpath(dirname(@__FILE__), "..", "examples", "sallenkey.jl"))
model=sallenkey()
println("Running sallenkey")
y = run!(model, sin.(2π*1000/44100*(0:44099)'); showprogress=false)
Expand All @@ -477,7 +481,7 @@ end
end

@testset "diodeclipper" begin
include("../examples/diodeclipper.jl")
include(joinpath(dirname(@__FILE__), "..", "examples", "diodeclipper.jl"))
model=diodeclipper()
println("Running diodeclipper")
@test ACME.np(model, 1) == 1
Expand All @@ -488,8 +492,7 @@ end

@test linearization_error!(model, 1e-3) < 1e-15

circ = diodeclipper(Circuit)
model = DiscreteModel(circ, 44100, ACME.HomotopySolver{ACME.SimpleSolver})
model = diodeclipper(solver=HomotopySolver{SimpleSolver})
runner = ModelRunner(model, false)
u = sin.(2π*1000/44100*(0:44099)')
y = run!(runner, u)
Expand All @@ -501,7 +504,7 @@ end
end

@testset "birdie" begin
include("../examples/birdie.jl")
include(joinpath(dirname(@__FILE__), "..", "examples", "birdie.jl"))
model=birdie(vol=0.8)
ACME.solve(model.solvers[1], [0.003, -0.0002])
@assert all(ACME.hasconverged, model.solvers)
Expand All @@ -517,13 +520,13 @@ end
model=birdie()
println("Running birdie with varying vol")
@test ACME.np(model, 1) == 3
y = run!(model, [sin.(2π*1000/44100*(0:44099)'); linspace(1,0,44100)']; showprogress=false)
y = run!(model, [sin.(2π*1000/44100*(0:44099)'); range(1, stop=0, length=44100)']; showprogress=false)
@test size(y) == (1,44100)
# TODO: further validate y
end

@testset "superover" begin
include("../examples/superover.jl")
include(joinpath(dirname(@__FILE__), "..", "examples", "superover.jl"))
model=superover(drive=1.0, tone=1.0, level=1.0)
println("Running superover with fixed potentiometer values")
@test ACME.np(model, 1) == 5
Expand Down Expand Up @@ -560,7 +563,7 @@ end
model=superover()
println("Running superover with varying potentiometer values")
@test ACME.np(model, 1) == 11
y = run!(model, [sin.(2π*1000/44100*(0:999)'); linspace(1,0,1000)'; linspace(0,1,1000)'; linspace(1,0,1000)']; showprogress=false)
y = run!(model, [sin.(2π*1000/44100*(0:999)'); range(1, stop=0, length=1000)'; range(0, stop=1, length=1000)'; range(1, stop=0, length=1000)']; showprogress=false)
@test size(y) == (1,1000)
# TODO: further validate y

Expand All @@ -574,7 +577,7 @@ end
@test ACME.np(model, 2) == 2
@test ACME.np(model, 3) == 2
@test ACME.np(model, 4) == 4
y = run!(model, [sin.(2π*1000/44100*(0:999)'); linspace(1,0,1000)'; linspace(0,1,1000)'; linspace(1,0,1000)']; showprogress=false)
y = run!(model, [sin.(2π*1000/44100*(0:999)'); range(1, stop=0, length=1000)'; range(0, stop=1, length=1000)'; range(1, stop=0, length=1000)']; showprogress=false)
@test size(y) == (1,1000)
# TODO: further validate y
end
Expand Down

0 comments on commit 84277e7

Please sign in to comment.