From 4b808de50b1070e4fabfae6c904fef17aef8bf64 Mon Sep 17 00:00:00 2001 From: Qi Zhang Date: Fri, 27 Sep 2019 02:58:22 -0400 Subject: [PATCH 1/5] Implement `fieldvalues` & `eltype` for `EquationOfState` --- src/Collections.jl | 64 ++++++++++++++++++----------------------- src/NonlinearFitting.jl | 2 +- 2 files changed, 29 insertions(+), 37 deletions(-) diff --git a/src/Collections.jl b/src/Collections.jl index 062fc38..b7b1b62 100644 --- a/src/Collections.jl +++ b/src/Collections.jl @@ -304,7 +304,7 @@ apply(form::EnergyForm, eos::EquationOfState) = v -> apply(form, eos, v) Return the energy of a `Murnaghan` equation of state on volume `v`. """ function apply(::EnergyForm, eos::Murnaghan, v::Real) - v0, b0, bp0, e0 = collect(eos) + v0, b0, bp0, e0 = fieldvalues(eos) x = bp0 - 1 y = (v0 / v)^bp0 @@ -316,7 +316,7 @@ end Return the energy of a `BirchMurnaghan2nd` equation of state on volume `v`. """ function apply(::EnergyForm, eos::BirchMurnaghan2nd, v::Real) - v0, b0, e0 = collect(eos) + v0, b0, e0 = fieldvalues(eos) f = (cbrt(v0 / v)^2 - 1) / 2 return e0 + 9 / 2 * b0 * v0 * f^2 @@ -327,7 +327,7 @@ end Return the energy of a `BirchMurnaghan3rd` equation of state on volume `v`. """ function apply(::EnergyForm, eos::BirchMurnaghan3rd, v::Real) - v0, b0, bp0, e0 = collect(eos) + v0, b0, bp0, e0 = fieldvalues(eos) eta = cbrt(v0 / v) xi = eta^2 - 1 @@ -339,7 +339,7 @@ end Return the energy of a `BirchMurnaghan4th` equation of state on volume `v`. """ function apply(::EnergyForm, eos::BirchMurnaghan4th, v::Real) - v0, b0, bp0, bpp0, e0 = collect(eos) + v0, b0, bp0, bpp0, e0 = fieldvalues(eos) f = (cbrt(v0 / v)^2 - 1) / 2 h = b0 * bpp0 + bp0^2 @@ -351,7 +351,7 @@ end Return the energy of a `PoirierTarantola2nd` equation of state on volume `v`. """ function apply(::EnergyForm, eos::PoirierTarantola2nd, v::Real) - v0, b0, e0 = collect(eos) + v0, b0, e0 = fieldvalues(eos) return e0 + b0 / 2 * v0 * log(v / v0)^(2 / 3) end @@ -361,7 +361,7 @@ end Return the energy of a `PoirierTarantola3rd` equation of state on volume `v`. """ function apply(::EnergyForm, eos::PoirierTarantola3rd, v::Real) - v0, b0, bp0, e0 = collect(eos) + v0, b0, bp0, e0 = fieldvalues(eos) x = cbrt(v / v0) xi = -3 * log(x) @@ -373,7 +373,7 @@ end Return the energy of a `PoirierTarantola4th` equation of state on volume `v`. """ function apply(::EnergyForm, eos::PoirierTarantola4th, v::Real) - v0, b0, bp0, bpp0, e0 = collect(eos) + v0, b0, bp0, bpp0, e0 = fieldvalues(eos) x = cbrt(v / v0) xi = log(x) @@ -386,7 +386,7 @@ end Return the energy of a `Vinet` equation of state on volume `v`. """ function apply(::EnergyForm, eos::Vinet, v::Real) - v0, b0, bp0, e0 = collect(eos) + v0, b0, bp0, e0 = fieldvalues(eos) x = cbrt(v / v0) xi = 3 / 2 * (bp0 - 1) @@ -398,7 +398,7 @@ end Return the energy of a `AntonSchmidt` equation of state on volume `v`. """ function apply(::EnergyForm, eos::AntonSchmidt, v::Real) - v0, β, n, e∞ = collect(eos) + v0, β, n, e∞ = fieldvalues(eos) x = v / v0 η = n + 1 @@ -442,7 +442,7 @@ apply(::PressureForm, eos::EquationOfState) = v -> apply(PressureForm(), eos, v) Return the pressure of a `Murnaghan` equation of state on volume `v`. """ function apply(::PressureForm, eos::Murnaghan, v::Real) - v0, b0, bp0 = collect(eos) + v0, b0, bp0 = fieldvalues(eos) return b0 / bp0 * ((v0 / v)^bp0 - 1) end @@ -452,7 +452,7 @@ end Return the pressure of a `BirchMurnaghan2nd` equation of state on volume `v`. """ function apply(::PressureForm, eos::BirchMurnaghan2nd, v::Real) - v0, b0 = collect(eos) + v0, b0 = fieldvalues(eos) f = ((v0 / v)^(2 / 3) - 1) / 2 return 3b0 * f * (1 + 2f)^(5 / 2) @@ -463,7 +463,7 @@ end Return the pressure of a `BirchMurnaghan3rd` equation of state on volume `v`. """ function apply(::PressureForm, eos::BirchMurnaghan3rd, v::Real) - v0, b0, bp0 = collect(eos) + v0, b0, bp0 = fieldvalues(eos) eta = (v0 / v)^(1 / 3) return 3 / 2 * b0 * (eta^7 - eta^5) * (1 + 3 / 4 * (bp0 - 4) * (eta^2 - 1)) @@ -474,7 +474,7 @@ end Return the pressure of a `BirchMurnaghan4th` equation of state on volume `v`. """ function apply(::PressureForm, eos::BirchMurnaghan4th, v::Real) - v0, b0, bp0, bpp0 = collect(eos) + v0, b0, bp0, bpp0 = fieldvalues(eos) f = ((v0 / v)^(2 / 3) - 1) / 2 h = b0 * bpp0 + bp0^2 @@ -486,7 +486,7 @@ end Return the pressure of a `PoirierTarantola2nd` equation of state on volume `v`. """ function apply(::PressureForm, eos::PoirierTarantola2nd, v::Real) - v0, b0 = collect(eos) + v0, b0 = fieldvalues(eos) x = (v / v0)^(1 / 3) return -b0 / x * log(x) @@ -497,7 +497,7 @@ end Return the pressure of a `PoirierTarantola3rd` equation of state on volume `v`. """ function apply(::PressureForm, eos::PoirierTarantola3rd, v::Real) - v0, b0, bp0 = collect(eos) + v0, b0, bp0 = fieldvalues(eos) x = v / v0 xi = log(x) @@ -509,7 +509,7 @@ end Return the pressure of a `PoirierTarantola4th` equation of state on volume `v`. """ function apply(::PressureForm, eos::PoirierTarantola4th, v::Real) - v0, b0, bp0, bpp0 = collect(eos) + v0, b0, bp0, bpp0 = fieldvalues(eos) x = (v / v0)^(1 / 3) xi = log(x) @@ -522,7 +522,7 @@ end Return the pressure of a `Vinet` equation of state on volume `v`. """ function apply(::PressureForm, eos::Vinet, v::Real) - v0, b0, bp0 = collect(eos) + v0, b0, bp0 = fieldvalues(eos) x = (v / v0)^(1 / 3) xi = 3 / 2 * (bp0 - 1) @@ -534,7 +534,7 @@ end Return the pressure of a `AntonSchmidt` equation of state on volume `v`. """ function apply(::PressureForm, eos::AntonSchmidt, v::Real) - v0, β, n = collect(eos) + v0, β, n = fieldvalues(eos) x = v / v0 return -β * x^n * log(x) @@ -545,7 +545,7 @@ end Return the pressure of a `BreenanStacey` equation of state on volume `v`. """ function apply(::PressureForm, eos::BreenanStacey, v::Real) - v0, b0, γ0 = collect(eos) + v0, b0, γ0 = fieldvalues(eos) x = v0 / v return b0 / 2 / γ0 * x^(4 / 3) * (exp(2γ0 * (1 - x)) - 1) @@ -588,7 +588,7 @@ apply(::BulkModulusForm, eos::EquationOfState) = v -> apply(BulkModulusForm(), e Return the bulk modulus of a `BirchMurnaghan2nd` equation of state on volume `v`. """ function apply(::BulkModulusForm, eos::BirchMurnaghan2nd, v::Real) - v0, b0 = collect(eos) + v0, b0 = fieldvalues(eos) f = ((v0 / v)^(2 / 3) - 1) / 2 return b0 * (7f + 1) * (2f + 1)^(5 / 2) @@ -599,7 +599,7 @@ end Return the bulk modulus of a `BirchMurnaghan3rd` equation of state on volume `v`. """ function apply(::BulkModulusForm, eos::BirchMurnaghan3rd, v::Real) - v0, b0, bp0 = collect(eos) + v0, b0, bp0 = fieldvalues(eos) f = ((v0 / v)^(2 / 3) - 1) / 2 return b0 / 2 * (2f + 1)^(5 / 2) * ((27 * f^2 + 6f) * (bp0 - 4) - 4f + 2) @@ -610,7 +610,7 @@ end Return the bulk modulus of a `BirchMurnaghan4th` equation of state on volume `v`. """ function apply(::BulkModulusForm, eos::BirchMurnaghan4th, v::Real) - v0, b0, bp0, bpp0 = collect(eos) + v0, b0, bp0, bpp0 = fieldvalues(eos) f = ((v0 / v)^(2 / 3) - 1) / 2 h = b0 * bpp0 + bp0^2 @@ -623,7 +623,7 @@ end Return the bulk modulus of a `PoirierTarantola2nd` equation of state on volume `v`. """ function apply(::BulkModulusForm, eos::PoirierTarantola2nd, v::Real) - v0, b0 = collect(eos) + v0, b0 = fieldvalues(eos) x = (v / v0)^(1 / 3) return b0 / x * (1 - log(x)) @@ -634,7 +634,7 @@ end Return the bulk modulus of a `PoirierTarantola3rd` equation of state on volume `v`. """ function apply(::BulkModulusForm, eos::PoirierTarantola3rd, v::Real) - v0, b0, bp0 = collect(eos) + v0, b0, bp0 = fieldvalues(eos) x = v / v0 xi = log(x) @@ -646,7 +646,7 @@ end Return the bulk modulus of a `PoirierTarantola4th` equation of state on volume `v`. """ function apply(::BulkModulusForm, eos::PoirierTarantola4th, v::Real) - v0, b0, bp0, bpp0 = collect(eos) + v0, b0, bp0, bpp0 = fieldvalues(eos) x = (v / v0)^(1 / 3) xi = log(x) @@ -660,7 +660,7 @@ end Return the bulk modulus of a `Vinet` equation of state on volume `v`. """ function apply(::BulkModulusForm, eos::Vinet, v::Real) - v0, b0, bp0 = collect(eos) + v0, b0, bp0 = fieldvalues(eos) x = (v / v0)^(1 / 3) xi = 3 / 2 * (bp0 - 1) @@ -672,7 +672,7 @@ end Return the bulk modulus of a `AntonSchmidt` equation of state on volume `v`. """ function apply(::BulkModulusForm, eos::AntonSchmidt, v::Real) - v0, β, n = collect(eos) + v0, β, n = fieldvalues(eos) x = v / v0 return β * x^n * (1 + n * log(x)) @@ -698,16 +698,8 @@ for E in nonabstract(EquationOfState) end) end -Base.iterate(eos::EquationOfState) = getfield(eos, 1), 2 -function Base.iterate(eos::EquationOfState, state::Integer) - state > length(eos) && return nothing - return getfield(eos, state), state + 1 -end # function Base.iterate -Base.length(eos::EquationOfState) = nfields(eos) -Base.size(eos::EquationOfState) = (length(eos),) +fieldvalues(eos::EquationOfState) = [getfield(eos, i) for i in 1:nfields(eos)] Base.eltype(::Type{<:EquationOfState{T}}) where {T} = T - -Base.isapprox(a::T, b::T; kwargs...) where {T<:EquationOfState} = isapprox(collect(a), collect(b); kwargs...) # Base.getindex(eos::PolynomialEquationOfState{T,N}, index::Int64) where {T,N} = getindex(eos.data, index) # =============================== Miscellaneous ============================== # diff --git a/src/NonlinearFitting.jl b/src/NonlinearFitting.jl index 260a434..75bf036 100644 --- a/src/NonlinearFitting.jl +++ b/src/NonlinearFitting.jl @@ -42,7 +42,7 @@ function lsqfit( T = promote_type(eltype(eos), eltype(xdata), eltype(ydata), Float64) P = Collections.similar_type(E, T) model(x, p) = map(apply(form, P(p...)), x) - fitted = curve_fit(model, T.(xdata), T.(ydata), T.(collect(eos)); kwargs...) + fitted = curve_fit(model, T.(xdata), T.(ydata), T.(Collections.fieldvalues(eos)); kwargs...) return debug ? fitted : P(fitted.param...) end # function lsqfit From 4c04ec011cfac8dab4e1a958008394096e5c25fa Mon Sep 17 00:00:00 2001 From: Qi Zhang Date: Fri, 27 Sep 2019 03:06:19 -0400 Subject: [PATCH 2/5] test: Fix `isapprox` in test/NonlinearFitting.jl when deprecating iteration interface, `isapprox` cannot be applied onto `EquationOfState`s --- test/NonlinearFitting.jl | 72 ++++++++++++++++++++-------------------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/test/NonlinearFitting.jl b/test/NonlinearFitting.jl index 9b4861f..1c6f01f 100644 --- a/test/NonlinearFitting.jl +++ b/test/NonlinearFitting.jl @@ -10,14 +10,14 @@ using EquationsOfState.NonlinearFitting 103.58772269057364, -144.45152457521132, -40.31992619868024, - ) + ) |> Collections.fieldvalues @test isapprox( lsqfit( EnergyForm(), BirchMurnaghan3rd(1, 2, 3.0, 0), [1, 2, 3, 4, 5], [5, 6, 9, 8, 7], - ), + ) |> Collections.fieldvalues, result; atol = 1e-5, ) @@ -27,7 +27,7 @@ using EquationsOfState.NonlinearFitting BirchMurnaghan3rd(1, 2, 3, 0), [1, 2, 3, 4, 5.0], [5, 6, 9, 8, 7], - ), + ) |> Collections.fieldvalues, result; atol = 1e-5, ) @@ -37,7 +37,7 @@ using EquationsOfState.NonlinearFitting BirchMurnaghan3rd(1, 2, 3.0, 0), [1, 2, 3, 4, 5], [5, 6, 9, 8, 7.0], - ), + ) |> Collections.fieldvalues, result; atol = 1e-5, ) @@ -47,7 +47,7 @@ using EquationsOfState.NonlinearFitting BirchMurnaghan3rd(1, 2, 3, 0), [1, 2, 3, 4, 5], [5, 6, 9, 8, 7], - ), + ) |> Collections.fieldvalues, result; atol = 1e-5, ) @@ -59,14 +59,14 @@ end 29.30861698140365, 12.689089871112746, 0.0, - ) + ) |> Collections.fieldvalues @test isapprox( lsqfit( PressureForm(), BirchMurnaghan3rd(1, 2, 3.0, 0), [1, 2, 3, 4, 5], [5, 6, 9, 8, 7], - ), + ) |> Collections.fieldvalues, result; atol = 1e-6, ) @@ -76,7 +76,7 @@ end BirchMurnaghan3rd(1, 2, 3, 0), [1, 2, 3, 4, 5.0], [5, 6, 9, 8, 7], - ), + ) |> Collections.fieldvalues, result; atol = 1e-6, ) @@ -86,7 +86,7 @@ end BirchMurnaghan3rd(1, 2, 3.0, 0), [1, 2, 3, 4, 5], [5, 6, 9, 8, 7.0], - ), + ) |> Collections.fieldvalues, result; atol = 1e-6, ) @@ -96,21 +96,21 @@ end BirchMurnaghan3rd(1, 2, 3, 0), [1, 2, 3, 4, 5], [5, 6, 9, 8, 7], - ), + ) |> Collections.fieldvalues, result; atol = 1e-6, ) end @testset "Test fitting bulk modulus with different element types" begin - result = BirchMurnaghan3rd(7.218928431312577, 5.007900469653902, 4.06037725509478, 0.0) + result = BirchMurnaghan3rd(7.218928431312577, 5.007900469653902, 4.06037725509478, 0.0) |> Collections.fieldvalues @test isapprox( lsqfit( BulkModulusForm(), BirchMurnaghan3rd(1, 2, 3.0, 0), [1, 2, 3, 4, 5], [5, 6, 9, 8, 7], - ), + ) |> Collections.fieldvalues, result; atol = 1e-5, ) @@ -120,7 +120,7 @@ end BirchMurnaghan3rd(1, 2, 3, 0), [1, 2, 3, 4, 5.0], [5, 6, 9, 8, 7], - ), + ) |> Collections.fieldvalues, result; atol = 1e-5, ) @@ -130,7 +130,7 @@ end BirchMurnaghan3rd(1, 2, 3.0, 0), [1, 2, 3, 4, 5], [5, 6, 9, 8, 7.0], - ), + ) |> Collections.fieldvalues, result; atol = 1e-5, ) @@ -140,7 +140,7 @@ end BirchMurnaghan3rd(1, 2, 3, 0), [1, 2, 3, 4, 5], [5, 6, 9, 8, 7], - ), + ) |> Collections.fieldvalues, result; atol = 1e-5, ) @@ -210,40 +210,40 @@ end -9.73155247952, ] @test isapprox( - lsqfit(EnergyForm(), BirchMurnaghan3rd(40, 0.5, 4, 0), volumes, energies), + lsqfit(EnergyForm(), BirchMurnaghan3rd(40, 0.5, 4, 0), volumes, energies) |> Collections.fieldvalues, BirchMurnaghan3rd( 40.98926572528106, 0.5369258245417454, 4.178644235500821, -10.842803908240892, - ), + ) |> Collections.fieldvalues, ) @test isapprox( - lsqfit(EnergyForm(), Murnaghan(41, 0.5, 4, 0), volumes, energies), + lsqfit(EnergyForm(), Murnaghan(41, 0.5, 4, 0), volumes, energies) |> Collections.fieldvalues, Murnaghan( 41.13757930387086, 0.5144967693786603, 3.9123862262572264, -10.836794514626673, - ), + ) |> Collections.fieldvalues, ) @test isapprox( - lsqfit(EnergyForm(), PoirierTarantola3rd(41, 0.5, 4, 0), volumes, energies), + lsqfit(EnergyForm(), PoirierTarantola3rd(41, 0.5, 4, 0), volumes, energies) |> Collections.fieldvalues, PoirierTarantola3rd( 40.86770643373908, 0.5667729960804602, 4.331688936974368, -10.851486685041658, - ), + ) |> Collections.fieldvalues, ) @test isapprox( - lsqfit(EnergyForm(), Vinet(41, 0.5, 4, 0), volumes, energies), + lsqfit(EnergyForm(), Vinet(41, 0.5, 4, 0), volumes, energies) |> Collections.fieldvalues, Vinet( 40.916875663779784, 0.5493839425156859, 4.3051929654936885, -10.846160810560756, - ), + ) |> Collections.fieldvalues, ) # 'deltafactor': {'b0': 0.5369258245611414, # 'b1': 4.178644231924639, @@ -331,13 +331,13 @@ end fitted_eos = lsqfit(EnergyForm(), Vinet(23, 0.5, 4, -2), mp153_volumes, mp153_energies) @test isapprox( - fitted_eos, + fitted_eos |> Collections.fieldvalues, Vinet( 22.95764559358769, 0.2257091141420788, 4.060543387224629, -1.5944292606251582, - ), + ) |> Collections.fieldvalues, ) @test isapprox( map(apply(EnergyForm(), fitted_eos), mp153_volumes), @@ -421,13 +421,13 @@ end fitted_eos = lsqfit(EnergyForm(), Vinet(20, 0.5, 4, -5), mp149_volumes, mp149_energies) @test isapprox( - fitted_eos, + fitted_eos |> Collections.fieldvalues, Vinet( 20.446696754873944, 0.5516638521306302, 4.324373909783161, -5.424963389876503, - ), + ) |> Collections.fieldvalues, ) @test isapprox( map(apply(EnergyForm(), fitted_eos), mp149_volumes), @@ -511,13 +511,13 @@ end fitted_eos = lsqfit(EnergyForm(), Vinet(17, 0.5, 4, -7), mp72_volumes, mp72_energies) @test isapprox( - fitted_eos, + fitted_eos |> Collections.fieldvalues, Vinet( 17.13223026131245, 0.7029766224730147, 3.6388077563621812, -7.897414959124461, - ), + ) |> Collections.fieldvalues, ) @test isapprox( map(apply(EnergyForm(), fitted_eos), mp72_volumes), @@ -597,26 +597,26 @@ end BirchMurnaghan3rd(224, 0.0006, 4, -323), volumes, energies, - ) ≈ BirchMurnaghan3rd(224.444565, 0.00062506191050572675, 3.740369, -323.417714) + ) |> Collections.fieldvalues ≈ BirchMurnaghan3rd(224.444565, 0.00062506191050572675, 3.740369, -323.417714) |> Collections.fieldvalues @test isapprox( lsqfit( EnergyForm(), BirchMurnaghan4th(224, 0.0006, 4, -5460, -323), volumes, energies, - ), + ) |> Collections.fieldvalues, BirchMurnaghan4th( 224.45756247137314, 0.0006229382259822287, 3.730991473426449, -5322.693307704408, -323.4177113158418, - ); + ) |> Collections.fieldvalues; atol = 1e-3, ) @test isapprox( - lsqfit(EnergyForm(), Murnaghan(224, 0.006, 4, -323), volumes, energies), - Murnaghan(224.501825, 0.00060479524074699499, 3.723835, -323.417686); + lsqfit(EnergyForm(), Murnaghan(224, 0.006, 4, -323), volumes, energies) |> Collections.fieldvalues, + Murnaghan(224.501825, 0.00060479524074699499, 3.723835, -323.417686) |> Collections.fieldvalues; atol = 1e-5, ) @test isapprox( @@ -625,8 +625,8 @@ end PoirierTarantola3rd(100, 0.0006, 3.7, -323), volumes, energies, - ), - PoirierTarantola3rd(224.509208, 0.000635892264159838, 3.690448, -323.41773); + ) |> Collections.fieldvalues, + PoirierTarantola3rd(224.509208, 0.000635892264159838, 3.690448, -323.41773) |> Collections.fieldvalues; atol = 1e-5, ) # @test lsqfit(EnergyForm(), PoirierTarantola4th(220, 0.0006, 3.7, -5500, -323), volumes, energies; lower = Float64[220, 0, 3, -6000, -400], upper = Float64[300, 0.01, 5, -5000, -300]) ≈ PoirierTarantola4th(224.430182, 0.0006232241765069493, 3.758360, -5493.859729817176, -323.417712) From 8b2a77a24802c8895011b927ec81cbb9f6b56095 Mon Sep 17 00:00:00 2001 From: Qi Zhang Date: Fri, 27 Sep 2019 03:07:44 -0400 Subject: [PATCH 3/5] Make a comment on `fieldvalues` --- src/Collections.jl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Collections.jl b/src/Collections.jl index b7b1b62..5ffcec1 100644 --- a/src/Collections.jl +++ b/src/Collections.jl @@ -698,7 +698,9 @@ for E in nonabstract(EquationOfState) end) end +# This is a helper function and should not be exported. fieldvalues(eos::EquationOfState) = [getfield(eos, i) for i in 1:nfields(eos)] + Base.eltype(::Type{<:EquationOfState{T}}) where {T} = T # Base.getindex(eos::PolynomialEquationOfState{T,N}, index::Int64) where {T,N} = getindex(eos.data, index) # =============================== Miscellaneous ============================== # From 2a8b2e532d8831a1919f49a46c3d4a1310512da5 Mon Sep 17 00:00:00 2001 From: Qi Zhang Date: Fri, 27 Sep 2019 03:31:14 -0400 Subject: [PATCH 4/5] Define `length` for `EquationOfState` --- src/Collections.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Collections.jl b/src/Collections.jl index 5ffcec1..3ef928c 100644 --- a/src/Collections.jl +++ b/src/Collections.jl @@ -702,6 +702,7 @@ end fieldvalues(eos::EquationOfState) = [getfield(eos, i) for i in 1:nfields(eos)] Base.eltype(::Type{<:EquationOfState{T}}) where {T} = T +Base.length(eos::EquationOfState) = nfields(eos) # Base.getindex(eos::PolynomialEquationOfState{T,N}, index::Int64) where {T,N} = getindex(eos.data, index) # =============================== Miscellaneous ============================== # From 921e68ff7a138f27328b3906b8b6890af0ebef12 Mon Sep 17 00:00:00 2001 From: Qi Zhang Date: Fri, 27 Sep 2019 03:34:14 -0400 Subject: [PATCH 5/5] Deprecate `length` for `EquationOfState` this cannot fix #31, an iteration interface still need to be defined. And once it is defined, the error emerges. --- src/Collections.jl | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Collections.jl b/src/Collections.jl index 3ef928c..5ffcec1 100644 --- a/src/Collections.jl +++ b/src/Collections.jl @@ -702,7 +702,6 @@ end fieldvalues(eos::EquationOfState) = [getfield(eos, i) for i in 1:nfields(eos)] Base.eltype(::Type{<:EquationOfState{T}}) where {T} = T -Base.length(eos::EquationOfState) = nfields(eos) # Base.getindex(eos::PolynomialEquationOfState{T,N}, index::Int64) where {T,N} = getindex(eos.data, index) # =============================== Miscellaneous ============================== #