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

PDESystem Internal System Compatibility #2299

Open
jbiffl opened this issue Oct 3, 2023 · 3 comments
Open

PDESystem Internal System Compatibility #2299

jbiffl opened this issue Oct 3, 2023 · 3 comments

Comments

@jbiffl
Copy link

jbiffl commented Oct 3, 2023

The definition for a PDESystem includes a field for internal systems, (PDESystem · ModelingToolkit.jl) but it looks like discretization of the PDESystem does not look at these systems, causing errors when discretization is attempted. From what I can tell, the equations, variables, and parameters from these internal systems are not pulled into the main PDESystem in the way that they are for ODESystems on system definition from eqs, ivs, dvs, etc.
ODESystem(eqs, t, vars, pars; systems = [sys])
vs
PDESystem(eqs, bcs, domains, [ivs], [dvs], pars; systems = [sys])

Currently, the only reference to PDESystem.systems that I can find is in Give PDESystem a systems field by xtalax · Pull Request #1588 · SciML/ModelingToolkit.jl · GitHub which seems related to visualization.

@ChrisRackauckas
Copy link
Member

@xtalax we should make sure it's supported or throw

@ts-tkd
Copy link

ts-tkd commented Jul 2, 2024

Any update on this? I'm trying to implement @ChrisRackauckas 's ADS Paper via MTK & the new (great work btw!) ModelingToolkitNeuralNets.NeuralNetworkBlock and I suspect I hit the same issue (code snippet below). I guess I'll have to discretize by hand for now ? Or did you find a workaround @jbiffl ?

Also: Happy to draft a PR if someone can provide me me with an overview of what needs to be changed (maybe @xtalax ? )

Example:

using OrdinaryDiffEq
using ModelingToolkit
using ModelingToolkitStandardLibrary.Blocks
using ModelingToolkitNeuralNets
using MethodOfLines
using DomainSets
using Lux

@parameters t, x
@variables c(..), q(..)
Dt = Differential(t)
Dx = Differential(x)
Dxx = Differential(x)^2

@named nn_in = RealInput(nin = 1)
@named nn_out = RealOutput(nout = 2)

#PDE, domains etc 
eq  = [Dt(c(t, x)) ~ Dx(c(t,x)) + Dxx(c(t, x)) - Dt(q(t,x)),
        Dt(q(t,x))  ~  nn_in.u[1],
        c ~ nn_out.u[1],
        q ~ nn_out.u[2]
    ]
bcs = [c(tstart, x) ~ 0.0,
        c(t, xstart) ~ 1.0 +   Dx(c(t, xstart)),
        Dx(c(t, xend)) ~ 0.0,
        
        q(tstart,x) ~ 3.0,
        Dx(q(t, xstart)) ~ 0.0,
        Dx(q(t, xend)) ~ 0.0
        ]

domains = [t ∈ Interval(tstart, tend),
           x ∈ Interval(xstart, xend)]
@named pdesys = PDESystem(eq, bcs, domains, [t, x], [c(t, x),q(t,x)], systems = [nn_in, nn_out])

#discretize, convert to ODE sys
dx = 0.3
order = 2
discretization = MOLFiniteDifference([x => dx], t)

ode_prob = discretize(pdesys,discretization)  ### fails

# from here on connect NN Block, optimize etc..

@ChrisRackauckas
Copy link
Member

I'm not sure how this issue is related to doing UDEs with MethodOfLines.jl (and this reply seems to be on the wrong repo?). It's something we need to work on but I wouldn't expect MOL to handle it right now.

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

No branches or pull requests

3 participants