From 8370b41e78c5e369defc7b84c08982b7094ce27a Mon Sep 17 00:00:00 2001 From: longemen3000 Date: Sun, 25 Oct 2020 02:00:29 -0300 Subject: [PATCH] general cleaning, bump to 0.4.2 --- Project.toml | 2 +- src/spec.jl | 40 +++++++++++++++++----------------------- src/specs_model.jl | 4 ---- 3 files changed, 18 insertions(+), 28 deletions(-) diff --git a/Project.toml b/Project.toml index 505d39a..798be6e 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "ThermoState" uuid = "e7b6519d-fdf7-4a33-b544-2b37a9c1234a" authors = ["Andres Riedemann"] -version = "0.4.1" +version = "0.4.2" [deps] Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d" diff --git a/src/spec.jl b/src/spec.jl index 42ed1f2..dca05f8 100644 --- a/src/spec.jl +++ b/src/spec.jl @@ -218,13 +218,8 @@ end ThermodynamicState(st::Tuple) = ThermodynamicState(st,()) - Base.values(s::ThermodynamicState) = s.specs - - - - #reduce-based mass transform, to check properties _reduce_check_mass(x::Spec) = 0 @@ -311,20 +306,10 @@ _specs_C(tup::Tuple,kw::Int64)::Int64 = 1 _reduce_mass_spec_p(x::Spec) = 0 _reduce_mass_spec_p(x::Spec{PhaseFractions}) = length(value(x)) -function _specs_P(kwargs::NamedTuple,kw::Int64)::Int64 - if (kw == 0) +function _specs_P(kw::Int64)::Int64 + if iszero(kw) return 1 - elseif kw == 1 - return 2 - else - return 0 - end -end - -function _specs_P(tup::Tuple,kw::Int64)::Int64 - if (kw == 0) - return 1 - elseif kw == 1 + elseif isone(kw) return 2 else return 0 @@ -374,10 +359,19 @@ function spec_equal(x1::Spec{T1},x2::Spec{T2})::Bool where {T1,T2} return false end function spec_tuple_unique(a)::Bool - @inbounds for i = 1:length(a) - for j = (i+1):length(a) - if spec_equal(a[i],a[j]) - return false + len = length(a) + if len == 1 + return true + elseif len == 2 + return !spec_equal(a[1],a[2]) + elseif len == 3 + return !(spec_equal(a[1],a[2]) | spec_equal(a[3],a[2]) | spec_equal(a[3],a[2])) + else + @inbounds for i = 1:len + for j = (i+1):len + if spec_equal(a[i],a[j]) + return false + end end end end @@ -388,7 +382,7 @@ function check_spec(args) mass_basis = _specs_components(args) phase_basis = _specs_phase_basis(args) C = _specs_C(args,mass_basis) - P = _specs_P(args,phase_basis) + P = _specs_P(phase_basis) F = _specs_F(args,mass_basis,phase_basis) DF = C - P + 2 - F#behold, the gibbs phase rule! if DF<0 diff --git a/src/specs_model.jl b/src/specs_model.jl index b279a27..0c9e7d6 100644 --- a/src/specs_model.jl +++ b/src/specs_model.jl @@ -8,10 +8,6 @@ a basic thermodynamic model, used to extract thermodynamic specifications from a struct FromState <: ThermoModel end const URVec = AbstractVector{T} where T<:Number - - - - moles2(a::ThermodynamicState,mw) = moles3(amount_type(a),a,mw) mass2(a::ThermodynamicState,mw) = mass3(amount_type(a),a,mw) kg_per_mol2(a::ThermodynamicState,mw) = kg_per_mol3(amount_type(a),a,mw)