Skip to content

energies: adding energies to PDESystems #2256

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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ModelingToolkit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ $(DocStringExtensions.README)
"""
module ModelingToolkit
using PrecompileTools, Reexport
@recompile_invalidations begin
@recompile_invalidations begin
using DocStringExtensions
using Compat
using AbstractTrees
Expand Down
1 change: 1 addition & 0 deletions src/systems/abstractsystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ function complete(sys::AbstractSystem)
end

for prop in [:eqs
:energies
:tag
:noiseeqs
:iv
Expand Down
9 changes: 7 additions & 2 deletions src/systems/pde/pdesystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ domains = [t ∈ (0.0,1.0),
struct PDESystem <: ModelingToolkit.AbstractMultivariateSystem
"The equations which define the PDE"
eqs::Any
"The energy functions"
energies::Any
"The boundary conditions"
bcs::Any
"The domain for the independent variables."
Expand Down Expand Up @@ -85,7 +87,7 @@ struct PDESystem <: ModelingToolkit.AbstractMultivariateSystem
gui_metadata: metadata for MTK GUI.
"""
gui_metadata::Union{Nothing, GUIMetadata}
@add_kwonly function PDESystem(eqs, bcs, domain, ivs, dvs,
@add_kwonly function PDESystem(eqs, energies, bcs, domain, ivs, dvs,
Copy link
Member

Choose a reason for hiding this comment

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

Please include a default value, and make it an optional argument so as to not break all other pdesystems written to date

Copy link
Author

Choose a reason for hiding this comment

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

Hi @xtalax, I tested that this won't break a pdesystem without energies. But I think a default value would be a good idea for all of the fields eqs, energies and bcs. Would you agree to add a default value (empty vector) to these three fields?

Copy link
Member

Choose a reason for hiding this comment

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

A PDE without eqs is undefined so I'm ok with this erroring. Default for bcs and energies is sensible though. Please remember to add test cases for this and also the energy free case in test/pde.jl

Copy link
Author

Choose a reason for hiding this comment

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

Imho a PDE without eqs is actually well-defined as well. It just means that there are no relations in the jet bundle. For example, you could just solve for a given boundary condition and low energy or even just for low energy solutions or solutions only satisfying the boundary conditions. If all three of eqs, bcs and energies are empty, the semantics should be that any function defined on the domain is returned - the neural network with randomly initialized weights.

I'll add defaults for bcs and energies and tests for now. Please note that this PR only makes sense if SciML/NeuralPDE.jl#734 is accepted as well.

ps = SciMLBase.NullParameters();
defaults = Dict(),
systems = [],
Expand All @@ -101,6 +103,7 @@ struct PDESystem <: ModelingToolkit.AbstractMultivariateSystem
end

eqs = eqs isa Vector ? eqs : [eqs]
energies = energies isa Vector ? energies : [energies]

if !isnothing(analytic)
analytic = analytic isa Vector ? analytic : [analytic]
Expand All @@ -123,7 +126,8 @@ struct PDESystem <: ModelingToolkit.AbstractMultivariateSystem
analytic_func = analytic_func isa Dict ? analytic_func : analytic_func |> Dict
end

new(eqs, bcs, domain, ivs, dvs, ps, defaults, connector_type, systems, analytic,
new(eqs, energies, bcs, domain, ivs, dvs, ps, defaults, connector_type, systems,
analytic,
analytic_func, name, metadata, gui_metadata)
end
end
Expand All @@ -149,6 +153,7 @@ function Base.show(io::IO, ::MIME"text/plain", sys::PDESystem)
println(io, summary(sys))
println(io, "Equations: ", get_eqs(sys))
println(io, "Boundary Conditions: ", get_bcs(sys))
println(io, "Energies: ", get_energies(sys))
println(io, "Domain: ", get_domain(sys))
println(io, "Dependent Variables: ", get_dvs(sys))
println(io, "Independent Variables: ", get_ivs(sys))
Expand Down