Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes issue #234 using same inputs #369

Merged
merged 7 commits into from
Mar 14, 2025

Conversation

matthew-kapp
Copy link
Contributor

@matthew-kapp matthew-kapp commented Mar 7, 2025

Checklist

  • Appropriate tests were added
  • Any code changes were done in a way that does not break public API
  • All documentation related to code changes were updated
  • The new code follows the
    contributor guidelines, in particular the SciML Style Guide and
    COLPRAC.
  • Any new documentation only uses public API

Additional context

using OrdinaryDiffEq, ModelingToolkit
using ModelingToolkitStandardLibrary.Thermal
using ModelingToolkit: t_nounits as t

@mtkmodel TestModel begin
    
    @components begin
        temp = FixedTemperature(T=300)
        heatflow = FixedHeatFlow(Q_flow=-1.0)
        wall = ThermalResistor(R=1)
    end

    @equations begin
        connect(temp.port, wall.port_a)
        connect(wall.port_b, heatflow.port)
    end

end

@mtkbuild test_model = TestModel()
for eq in observed(test_model)
    println(eq)
end
prob = ODEProblem(test_model, Pair[], (0, 10.0))
sol = solve(prob)

Output before:

temp₊port₊T(t) ~ temp₊T
heatflow₊port₊Q_flow(t) ~ wall₊Q_flow(t)
wall₊port_a₊Q_flow(t) ~ wall₊Q_flow(t)
wall₊port_b₊Q_flow(t) ~ -wall₊Q_flow(t)
temp₊port₊Q_flow(t) ~ -wall₊Q_flow(t)
wall₊port_a₊T(t) ~ temp₊port₊T(t)
heatflow₊port₊T(t) ~ (-heatflow₊port₊Q_flow(t) + heatflow₊Q_flow*(-1 + heatflow₊T_ref*heatflow₊alpha)) / (heatflow₊Q_flow*heatflow₊alpha)
wall₊dT(t) ~ temp₊port₊T(t) - heatflow₊port₊T(t)
wall₊port_b₊T(t) ~ heatflow₊port₊T(t)
retcode: InitialFailure
Interpolation: 3rd order Hermite
t: 1-element Vector{Float64}:
 0.0
u: 1-element Vector{Vector{Float64}}:
 [NaN]

Output after:

temp₊port₊T(t) ~ temp₊T
heatflow₊port₊T(t) ~ -wall₊dT(t) + temp₊port₊T(t)
wall₊port_a₊T(t) ~ temp₊port₊T(t)
heatflow₊port₊Q_flow(t) ~ ifelse(heatflow₊alpha == 0.0, -heatflow₊Q_flow, heatflow₊Q_flow*(-1 + (heatflow₊T_ref - heatflow₊port₊T(t))*heatflow₊alpha))
wall₊port_b₊T(t) ~ heatflow₊port₊T(t)
wall₊Q_flow(t) ~ heatflow₊port₊Q_flow(t)
wall₊port_a₊Q_flow(t) ~ wall₊Q_flow(t)
wall₊port_b₊Q_flow(t) ~ -wall₊Q_flow(t)
temp₊port₊Q_flow(t) ~ -wall₊Q_flow(t)
retcode: Success
Interpolation: 3rd order Hermite
t: 9-element Vector{Float64}:
  0.0
  1.0e-6
  1.1e-5
  0.00011099999999999999
  ⋮
  0.11111099999999996
  1.1111109999999995
 10.0
u: 9-element Vector{Vector{Float64}}:
 [1.0]
 [1.0]
 [1.0]
 [1.0]
 ⋮
 [1.0]
 [1.0]
 [1.0]

This MWE has been added as a test, which passes

@matthew-kapp matthew-kapp changed the title Fixes issue #364 Fixes issue #234 using same inputs Mar 7, 2025
@ChrisRackauckas ChrisRackauckas requested a review from ven-k March 7, 2025 15:21
@matthew-kapp
Copy link
Contributor Author

@ven-k there's now additional tests failing. I'll need to debug first.

@matthew-kapp
Copy link
Contributor Author

@ven-k all tests pass again

Update based on documentation build fix
Copy link
Member

@ven-k ven-k left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not strictly necessary, but I would suggest merging first two commits as they don't stand independently.
In future PRs I'd suggest "Update with rebase" option instead of merging main (for cleaner git history).

I have the foll. question, otherwise this looks good.

Project.toml Outdated
@@ -30,7 +30,7 @@ PreallocationTools = "0.4.23"
SafeTestsets = "0.1"
SciMLStructures = "1.4.2"
SymbolicIndexingInterface = "0.3.28"
Symbolics = "6.14"
Symbolics = "=6.29.2"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this pinned to a version?
If at all this is only to set a lower bound, it would be better to not add =. These tend to constraint package resolutions while using with other packages.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @ven-k good point. As mentioned in Issue #371 the latest version causes tests to fail. So does it make sense for Symbolics to first be fixed or how to deal with this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Symbolics 6.30 is yanked from the registry now. The pin can be removed.

@matthew-kapp
Copy link
Contributor Author

@ven-k all done

Copy link
Member

@ven-k ven-k left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The failing unit-tests are unrelated to this PR.

(Note that formatter failure is related)

@ChrisRackauckas ChrisRackauckas merged commit 8f9ab6a into SciML:main Mar 14, 2025
6 of 12 checks passed
@matthew-kapp matthew-kapp deleted the Tdep-thermal branch March 14, 2025 15:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants