Skip to content

Commit

Permalink
Generalized calc_x code for AbstractArrays
Browse files Browse the repository at this point in the history
Bump version to v1.0.2
  • Loading branch information
MarcBerliner committed May 22, 2023
1 parent 4ce7b93 commit c0edac5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "PETLION"
uuid = "5e0a28e4-193c-47fa-bbb8-9c901cc1ac2c"
authors = ["Marc D. Berliner", "Richard D. Braatz"]
version = "1.0.1"
version = "1.0.2"

[deps]
BSON = "fbb218c0-5317-5bc6-957e-2ee96dd4b1f0"
Expand Down
16 changes: 8 additions & 8 deletions src/physics_equations/scalar_residual.jl
Original file line number Diff line number Diff line change
Expand Up @@ -75,21 +75,21 @@ end
for state in keys(states_total)
if state :T # temperature is handled separately
is_scalar = isempty(states_total[state].sections)
str = "calc_$state(Y::Vector{<:Number}, p::AbstractModel) = " * (is_scalar ? "@inbounds Y[p.ind.$state[1]]" : "@inbounds @views Y[p.ind.$state]")
str = "calc_$state(Y::AbstractVector{<:Number}, p::AbstractModel) = " * (is_scalar ? "@inbounds Y[p.ind.$state[1]]" : "@inbounds @views Y[p.ind.$state]")
str = remove_module_name(str)
eval(Meta.parse(str))
end
end
@inline calc_T(Y::Vector{<:Number}, p::AbstractModelTemp{true}) = @inbounds @views Y[p.ind.T]
@inline calc_T(::Vector{<:Number}, p::AbstractModelTemp{false}) = repeat([p.θ[:T₀]], p.N.a+p.N.p+p.N.s+p.N.n+p.N.z)
@inline calc_T(Y::AbstractVector{<:Number}, p::AbstractModelTemp{true}) = @inbounds @views Y[p.ind.T]
@inline calc_T(::AbstractVector{<:Number}, p::AbstractModelTemp{false}) = repeat([p.θ[:T₀]], p.N.a+p.N.p+p.N.s+p.N.n+p.N.z)

@inline calc_V(Y::Vector{<:Number}, p::AbstractModel) = @inbounds Y[p.ind.Φ_s[1]] - Y[p.ind.Φ_s[end]]
@inline calc_P(Y::Vector{<:Number}, p::AbstractModel) = calc_I(Y,p)*p.θ[:I1C]*calc_V(Y,p)
@inline calc_V(Y::AbstractVector{<:Number}, p::AbstractModel) = @inbounds Y[p.ind.Φ_s[1]] - Y[p.ind.Φ_s[end]]
@inline calc_P(Y::AbstractVector{<:Number}, p::AbstractModel) = calc_I(Y,p)*p.θ[:I1C]*calc_V(Y,p)
@inline calc_T_avg(Y, p) = temperature_weighting(calc_T(Y,p),p)
@inline calc_K_eff(Y::Vector{<:Number}, p::AbstractModelTemp{true}) = @inbounds @views p.numerics.K_eff(Y[p.ind.c_e.p], Y[p.ind.c_e.s], Y[p.ind.c_e.n], Y[p.ind.T.p], Y[p.ind.T.s], Y[p.ind.T.n], p)
@inline calc_K_eff(Y::Vector{<:Number}, p::AbstractModelTemp{false}) = @inbounds @views p.numerics.K_eff(Y[p.ind.c_e.p], Y[p.ind.c_e.s], Y[p.ind.c_e.n], repeat([p.θ[:T₀]], p.N.p), repeat([p.θ[:T₀]], p.N.s), repeat([p.θ[:T₀]], p.N.n), p)
@inline calc_K_eff(Y::AbstractVector{<:Number}, p::AbstractModelTemp{true}) = @inbounds @views p.numerics.K_eff(Y[p.ind.c_e.p], Y[p.ind.c_e.s], Y[p.ind.c_e.n], Y[p.ind.T.p], Y[p.ind.T.s], Y[p.ind.T.n], p)
@inline calc_K_eff(Y::AbstractVector{<:Number}, p::AbstractModelTemp{false}) = @inbounds @views p.numerics.K_eff(Y[p.ind.c_e.p], Y[p.ind.c_e.s], Y[p.ind.c_e.n], repeat([p.θ[:T₀]], p.N.p), repeat([p.θ[:T₀]], p.N.s), repeat([p.θ[:T₀]], p.N.n), p)

@inline calc_η_plating(Y::Vector{<:Number},p::AbstractModel) = @inbounds Y[p.ind.Φ_s.n[1]] - Y[p.ind.Φ_e.n[1]]
@inline calc_η_plating(Y::AbstractVector{<:Number},p::AbstractModel) = @inbounds Y[p.ind.Φ_s.n[1]] - Y[p.ind.Φ_e.n[1]]
@inline calc_η_plating(t,Y,YP,p) = calc_η_plating(Y,p)

@inline function calc_SOC(Y::AbstractVector{Float64}, p::model)
Expand Down

0 comments on commit c0edac5

Please sign in to comment.