Skip to content

Commit

Permalink
Fix advection coupling issue
Browse files Browse the repository at this point in the history
  • Loading branch information
ctessum committed Oct 27, 2024
1 parent 4968762 commit a6037a9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
3 changes: 1 addition & 2 deletions src/advection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ function advection(vars, di::DomainInfo)
eqs
end

function couple(c::CoupledSystem, _::Advection)::CoupledSystem
function couple2(c::CoupledSystem, _::Advection)::CoupledSystem
dom = domain(c)

# Add in a model component to allow the specification of the wind velocity.
Expand All @@ -79,7 +79,6 @@ function couple(c::CoupledSystem, _::Advection)::CoupledSystem
push!(c.pdefunctions, f)
c
end
couple(a::Advection, c::CoupledSystem)::CoupledSystem = couple(c, a)

struct ConstantWindCoupler
sys
Expand Down
12 changes: 6 additions & 6 deletions src/coupled_system.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Things that can be added to a `CoupledSystem`:
* [Callbacks](https://docs.sciml.ai/DiffEqDocs/stable/features/callback_functions/)
* Types `X` that implement a `EarthSciMLBase.init_callback(::X, sys::CoupledSystem, sys_mtk, obs_eqs, domain::DomainInfo)::DECallback` method
* Other `CoupledSystem`s
* Types `X` that implement a `EarthSciMLBase.couple(::X, ::CoupledSystem)` or `EarthSciMLBase.couple(::CoupledSystem, ::X)` method.
* Types `X` that implement a `EarthSciMLBase.couple2(::X, ::CoupledSystem)` or `EarthSciMLBase.couple2(::CoupledSystem, ::X)` method.
* `Tuple`s or `AbstractVector`s of any of the things above.
"""
mutable struct CoupledSystem
Expand Down Expand Up @@ -83,11 +83,11 @@ function couple(systems...)::CoupledSystem
push!(o.callbacks, sys)
elseif (sys isa Tuple) || (sys isa AbstractVector)
o = couple(o, sys...)
elseif hasmethod(init_callback, (typeof(sys), Any, Any, Any, Any))
elseif hasmethod(init_callback, (typeof(sys), CoupledSystem, Any, Any, DomainInfo))
push!(o.init_callbacks, sys)
elseif applicable(couple, o, sys)
o = couple(o, sys)
elseif applicable(couple, sys, o)
elseif hasmethod(couple2, (CoupledSystem, typeof(sys)))
o = couple2(o, sys)
elseif hasmethod(couple2, (typeof(sys), CoupledSystem))
o = couple(sys, o)
else
error("Cannot couple a $(typeof(sys)).")
Expand Down Expand Up @@ -219,7 +219,7 @@ end
"""
Types that implement an:
`init_callback(x, sys, obs_eqs, domain, u0, p)::DECallback`
`init_callback(x, sys::CoupledSystem, obs_eqs, domain::DomainInfo)::DECallback`
method can also be coupled into a `CoupledSystem`.
The `init_callback` function will be run before the simulator is run
Expand Down
6 changes: 3 additions & 3 deletions test/advection_test.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Main.EarthSciMLBase
using EarthSciMLBase
using Test
using DomainSets, MethodOfLines, ModelingToolkit, DifferentialEquations
using ModelingToolkit: t, D
Expand Down Expand Up @@ -46,7 +46,7 @@ using Dates, DomainSets
eq = equations(combined_mtk)
eqstr = string(eq)

@test occursin("- MeanWind₊v_x(t, x)*Differential(x)(examplesys₊y(t, x))", eqstr) ||
@test occursin("- MeanWind₊v_x(t, x)*Differential(x)(examplesys₊y(t, x))", eqstr) ||
occursin("- Differential(x)(examplesys₊y(t, x))*MeanWind₊v_x(t, x)", eqstr)

@test_broken begin # Test fails because PDEs don't currently work with units.
Expand Down Expand Up @@ -94,4 +94,4 @@ end
for term want_terms
@test any(occursin.((term,), have_eqs))
end
end
end

2 comments on commit a6037a9

@ctessum
Copy link
Member Author

Choose a reason for hiding this comment

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

@JuliaRegistrator register

Release notes:

  • Replace Simulator with ODEProblem.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request created: JuliaRegistries/General/118175

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.18.0 -m "<description of version>" a6037a9d5b07f5dd3634ae816d0c8f8334696474
git push origin v0.18.0

Please sign in to comment.