PDEs with Dependent Variables on Heterogeneous Domains

A differential equation is said to have heterogeneous domains when its dependent variables depend on different independent variables:

\[u(x) + w(x, v) = \frac{\partial w(x, v)}{\partial w}\]

Here, we write an arbitrary heterogeneous system:

using ModelingToolkit, NeuralPDE, SciMLBase, Lux, Optimization, OptimizationOptimJL
using Optim: BFGS
import DomainSets: Interval

@parameters x y
@variables p(..) q(..) r(..) s(..)
Dx = Differential(x)
Dy = Differential(y)

# 2D PDE
eq = p(x) + q(y) + Dx(r(x, y)) + Dy(s(y, x)) ~ 0

# Initial and boundary conditions
bcs = [p(1) ~ 0.0f0, q(-1) ~ 0.0f0,
    r(x, -1) ~ 0.0f0, r(1, y) ~ 0.0f0,
    s(y, 1) ~ 0.0f0, s(-1, x) ~ 0.0f0]

# Space and time domains
domains = [x ∈ Interval(0.0, 1.0),
    y ∈ Interval(0.0, 1.0)]

numhid = 3
chains = [[Chain(Dense(1, numhid, σ), Dense(numhid, numhid, σ), Dense(numhid, 1))
           for i in 1:2]
          [Chain(Dense(2, numhid, σ), Dense(numhid, numhid, σ), Dense(numhid, 1))
           for i in 1:2]]
discretization = PhysicsInformedNN(chains, QuadratureTraining())

@named pde_system = PDESystem(eq, bcs, domains, [x, y], [p(x), q(y), r(x, y), s(y, x)])
prob = SciMLBase.discretize(pde_system, discretization)

callback = function (p, l)
    println("Current loss is: $l")
    return false
end

res = Optimization.solve(prob, BFGS(); maxiters = 100)
retcode: MaxIters
u: ComponentVector{Float64}(depvar = (p = (layer_1 = (weight = [-0.1417663715084098; -0.1172651286566307; 0.40496484477066197;;], bias = [0.21290800903230273, 0.499030268016696, -0.5172493882493249]), layer_2 = (weight = [0.38711678312167047 -0.4324253417181043 -0.42539098875461234; -0.3611074873002144 -0.9725883262410135 -0.6173719489947834; -0.1764856251196998 -0.8115964392656614 -0.04927668809461386], bias = [-0.5189161406787536, -0.5286282111898462, -0.5232933020698698]), layer_3 = (weight = [0.3180548349365402 -0.0075638494068908345 0.5659893758810923], bias = [-0.23816196851413235])), q = (layer_1 = (weight = [1.3839282361725764; -0.35510170744217756; -0.7602998957282417;;], bias = [-0.39396692235563097, -0.60265838511924, -0.2813325249421972]), layer_2 = (weight = [-0.32748046765616856 -0.8676084397154434 -0.9772063485876571; -0.14493793160819654 0.13253592216487875 -0.01196291524953099; -0.236422951044744 -0.952538574670448 -0.2982738699619369], bias = [0.369234429407375, -0.25474953212142204, -0.41578048100224985]), layer_3 = (weight = [0.16621408849717137 0.3309353572943782 -0.2430976401807947], bias = [-0.1405706569371678])), r = (layer_1 = (weight = [0.9421859927801838 0.1838885652550244; -0.9222572133356272 -0.3788511996205385; -0.6361352385513332 -0.689813309277169], bias = [0.39929489759035264, 0.06717617480004533, -0.6926403856917036]), layer_2 = (weight = [0.8136012857905643 -0.40380273119031224 0.328232029366049; 0.2444176812823327 -0.18185781204825313 -0.43453103743219246; -0.9038907370713161 0.05600009833066582 -0.09647267113588426], bias = [-0.036073468525001484, -0.0706919549202799, -0.37627843057592364]), layer_3 = (weight = [0.4469277525160592 0.0276186497311079 0.6393267419629782], bias = [-0.4579950657934387])), s = (layer_1 = (weight = [-0.3458570271679216 -1.008821772732383; 1.1252605195231073 -0.3931755342599497; -0.47622218359337976 -0.3786207667825976], bias = [0.04905305740145527, -0.2393485340950167, 0.5927435412639667]), layer_2 = (weight = [-0.779754086578392 -0.8224418134002631 0.028054351754833808; -0.4442833609091593 -0.51830904201 -0.00934085516615351; -0.6099719891265069 -0.32669238248922927 0.3593342797988876], bias = [-0.45052530239344885, -0.3854523742863372, -0.6806766912184626]), layer_3 = (weight = [0.6158570480361811 -0.5175417017860021 -0.43797105475497616], bias = [0.13827710080123745]))))