Skip to content

Commit

Permalink
rename get_main_equation to find_main_equation + doc string
Browse files Browse the repository at this point in the history
  • Loading branch information
bbejanov committed Jul 11, 2023
1 parent 6048f84 commit bfe0a5a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
10 changes: 8 additions & 2 deletions src/model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1624,7 +1624,13 @@ function findequations(model::Model, sym::Symbol; verbose=true)
return sym_eqs
end

function get_main_equation(model::Model, var::Symbol)
"""
find_main_equation(model, var)
Return the name of the first equation that contains `var[t]`. Return `nothing`
if there's no such equation.
"""
function find_main_equation(model::Model, var::Symbol)
for (eqn_name, eqn) in pairs(model.equations)
for (t, sym) in eqn.tsrefs
if t[1].name == var && t[2] == 0
Expand All @@ -1634,7 +1640,7 @@ function get_main_equation(model::Model, var::Symbol)
end
return nothing
end
export get_main_equation
export find_main_equation

"""
prettyprint_equation(m::Model, eq::Equation; target::Symbol, eq_symbols::Vector{Any}=[])
Expand Down
8 changes: 4 additions & 4 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1449,13 +1449,13 @@ m2_for_sattelite_tests = nothing

@testset "Model find" begin
m = E3.newmodel()
findequations(m, :cr)
@test length(findequations(m, :cr)) == 1
@test length(findequations(m, :pinf)) == 3
findequations(m, :cr; verbose=false)
@test length(findequations(m, :cr; verbose=false)) == 1
@test length(findequations(m, :pinf; verbose=false)) == 3

@test get_main_equation(m, :rate) == :_EQ2

@test findequations(S1.model, :a) == [:_EQ1, :_SSEQ1]
@test findequations(S1.model, :a; verbose=false) == [:_EQ1, :_SSEQ1]

end

Expand Down

0 comments on commit bfe0a5a

Please sign in to comment.