|
1 | 1 | # Copyright 2015, 2016, 2017, 2018, 2019 Martin Holters |
2 | 2 | # See accompanying license file. |
3 | 3 |
|
4 | | -VERSION < v"0.7.0-beta2.199" && __precompile__() |
5 | | - |
6 | 4 | module ACME |
7 | 5 |
|
8 | 6 | export DiscreteModel, run!, steadystate, steadystate!, linearize, ModelRunner |
9 | 7 |
|
10 | | -using Compat.SparseArrays: SparseMatrixCSC, dropzeros!, findnz, |
| 8 | +using SparseArrays: SparseMatrixCSC, blockdiag, dropzeros!, findnz, |
11 | 9 | nonzeros, sparse, spzeros |
12 | | -using Compat.LinearAlgebra: I, axpy! |
13 | | -import Compat.LinearAlgebra.BLAS |
| 10 | +using LinearAlgebra: BLAS, I, axpy!, lu, rmul! |
| 11 | +using Markdown: @doc_str |
14 | 12 |
|
15 | 13 | using ProgressMeter |
16 | 14 | using IterTools |
17 | | -using DataStructures |
| 15 | +using OrderedCollections: OrderedDict |
18 | 16 | using StaticArrays |
19 | 17 |
|
20 | | -include("compat.jl") |
21 | | - |
22 | 18 | include("kdtree.jl") |
23 | 19 | include("solvers.jl") |
24 | 20 |
|
@@ -60,7 +56,7 @@ mutable struct Element |
60 | 56 | :pxd => (:ny,:nx), :pq => (:ny,:nq) ) |
61 | 57 |
|
62 | 58 | elem = new() |
63 | | - for (key, val) in kwargs_pairs(args) |
| 59 | + for (key, val) in args |
64 | 60 | if haskey(mat_dims, key) |
65 | 61 | val = convert(SparseMatrixCSC{Real,Int}, hcat(val)) # turn val into a sparse matrix whatever it is |
66 | 62 | update_sizes(val, mat_dims[key]) |
@@ -448,14 +444,10 @@ np(model::DiscreteModel, subidx) = size(model.dqs[subidx], 1) |
448 | 444 | nu(model::DiscreteModel) = size(model.b, 2) |
449 | 445 | ny(model::DiscreteModel) = length(model.y0) |
450 | 446 | nn(model::DiscreteModel, subidx) = size(model.fqs[subidx], 2) |
451 | | -nn(model::DiscreteModel) = Compat.reduce(+, init=0, size(fq, 2) for fq in model.fqs) |
| 447 | +nn(model::DiscreteModel) = reduce(+, init=0, size(fq, 2) for fq in model.fqs) |
452 | 448 |
|
453 | 449 | function steadystate(model::DiscreteModel, u=zeros(nu(model))) |
454 | | - @static if VERSION < v"0.7.0-DEV.5211" |
455 | | - IA_LU = Compat.LinearAlgebra.lufact(I-model.a) |
456 | | - else |
457 | | - IA_LU = Compat.LinearAlgebra.lu(I-model.a) |
458 | | - end |
| 450 | + IA_LU = lu(I-model.a) |
459 | 451 | steady_z = zeros(nn(model)) |
460 | 452 | zoff = 1 |
461 | 453 | for idx in 1:length(model.solvers) |
@@ -511,8 +503,8 @@ function linearize(model::DiscreteModel, usteady::AbstractVector{Float64}=zeros( |
511 | 503 |
|
512 | 504 | zranges[idx] = zoff:zoff+length(zsub)-1 |
513 | 505 | fqdzdps = [model.fqprevs[idx][:,zranges[n]] * dzdps[n] for n in 1:idx-1] |
514 | | - dqlins[idx] = Compat.reduce(+, init=model.dqs[idx], fqdzdps .* dqlins[1:idx-1]) |
515 | | - eqlins[idx] = Compat.reduce(+, init=model.eqs[idx], fqdzdps .* eqlins[1:idx-1]) |
| 506 | + dqlins[idx] = reduce(+, init=model.dqs[idx], fqdzdps .* dqlins[1:idx-1]) |
| 507 | + eqlins[idx] = reduce(+, init=model.eqs[idx], fqdzdps .* eqlins[1:idx-1]) |
516 | 508 |
|
517 | 509 | x0 += model.c[:,zranges[idx]] * (zsub - dzdps[idx]*psteady) |
518 | 510 | a += model.c[:,zranges[idx]] * dzdps[idx] * dqlins[idx] |
@@ -706,7 +698,7 @@ function gensolve(a, b, x, h, thresh=0.1) |
706 | 698 | s = ait * h; |
707 | 699 | jnz, nz_vals = findnz(s') |
708 | 700 | nz_abs_vals = abs.(nz_vals) |
709 | | - max_abs_val = Compat.reduce(max, init=zero(eltype(s)), nz_abs_vals) |
| 701 | + max_abs_val = reduce(max, init=zero(eltype(s)), nz_abs_vals) |
710 | 702 | if max_abs_val ≤ tol # cosidered numerical zero |
711 | 703 | continue |
712 | 704 | end |
|
0 commit comments