Coupled PINN

Hi. I wanted to solve two different heat diffusion equations(coupled) and solve them. For this I need 2 seperate domains for equations and I want to solve them in parallel in 2 independent Neural Networks. How can I solve this problem? especially since there is an Interface condition here.

why do you want to use PINNs to solve this?

Just define two OptimizationProblems with NeuralPDE and then add an additional_loss term for the boundary handling. It is rather straightforward really from the two parts if you give it a go. What did you try?

1 Like

It’s for my Master’s degree thesis.

I have tried it. But there are two Optimization problems which must be run in parallel. I don’t know how to run them in parallel. I have seen the examples on NeuralPDE, but none of them were solved in parallel. One thing that I was trying to do but I failed was that I made two different PDESystems as inner systems and wanted to connect them by another PDESystem like what is done by ODE in Lorenz Equations. Unfortunately, it doesn’t work the same (Expectedly) but I don’t understand why it’s made possible to define inner systems in PDESystems while they can’t be connected.
Many Thanks

Define a new OptimizationProblem which calls both of the cost functions.

1 Like

You realize that a PINN is going to be an absurdly inefficient way to solve a diffusion equation, right? Standard PDE solvers are really good at this, since people have spent decades optimizing solution methods for Poisson equations…


Unfortunately, my supervisor insists on solving it by PINN and I can’t argue with him. There are more efficient and less time consuming methods ofcourse but it’s already late for the change of direction.

Thanks. The problem I’m having right now is that I want them to be run in parallel in res line;

res1 = Optimization.solve(prob1 ,Adam(0.001); callback = callback, maxiters=1000)
res2 = Optimization.solve(prob2 ,Adam(0.001); callback = callback, maxiters=1000)

Since there are two problems which should be solved in parallel, I don’t want them to run separately. Do I need Parallel computing to run them together?
For defining a new OptimizationProblem I don’t have any clue what to do.

newf(x,p) = prob1.f(x,p) + prob2.f(x,p)?

Here is my code. I still haven’t defined the additional Interface boundary condition.

using NeuralPDE, Flux, ModelingToolkit, DiffEqFlux
using  Cuba, CUDA, QuasiMonteCarlo, IfElse, Optimization
@parameters t x 
@variables T1(..) T2(..) 
# First order derivatives
Dt = Differential(t)
Dx = Differential(x)
# Second order derivatives
Dxx = Differential(x)^2
#First Prob implementation
domain1 = [ t ∈ IntervalDomain(0,10),
            x ∈ IntervalDomain(0.0,0.02)]
ρ1 = 2719
k1 = 202.4
cp1 = 871
q1 = 10^7
bc1 =[T1(0,x) ~ 300,
    Dx(T1(t,0)) ~ 0,
eq1 = ρ1*cp1*Dt(T1(t,x)) ~ k1*Dxx(T1(t,x))+ q1
n1 = 25
chain1 = Flux.Chain(Flux.Dense(2,n1,Flux.relu),
initθ1 = DiffEqFlux.initial_params(chain1) |> gpu
strategy = NeuralPDE.QuasiRandomTraining(100; #points
                                         sampling_alg = UniformSample(),
                                         resampling = false,
                                         minibatch = 8)
discretization1 = PhysicsInformedNN(chain1,
                                   init_params = initθ1)
@named pde_system1 = PDESystem(eqs = eq1,bcs = bc1,domain = domain1,ivs=[t,x],dvs = T1(t,x))
prob1 = NeuralPDE.discretize(pde_system1,discretization1)
#Second prob implementation
domain2 = [ t ∈ IntervalDomain(0,10),
            x ∈ IntervalDomain(0.02,0.04)]
bc2 =[T2(0,x) ~ 300,
    Dx(T2(t,0.04)) ~ 0,
ρ2 = 8978
k2 = 387.6
cp2 = 381
eq2 = ρ2*cp2*Dt(T2(t,x))~ k2*Dxx(T2(t,x))
n2 = 20
chain2= Flux.Chain(Flux.Dense(2,n2,Flux.relu),
initθ2 = DiffEqFlux.initial_params(chain2) |> gpu
discretization2 = PhysicsInformedNN(chain2,
                                   init_params = initθ2)
@named pde_system2 = PDESystem(eqs = eq2,bcs = bc2,domain = domain2,ivs=[t,x],dvs = T2(t,x))
prob2 = NeuralPDE.discretize(pde_system2,discretization2)
callback = function (p,l)
    println("Current loss is: $l")/
    return false
res = Optimization.solve(prob?? ,Adam(0.001); callback = callback, maxiters=1000)

I know there are a few things wrong with this code, especially they can’t be coupled because of how I defined the BCs. But I just want to know how can I run these two in parallel? I can’t use the cost function until the res line runs to achieve T1 and T2.

You can’t just make up syntax :sweat_smile: . See the documentation.

Define the third optimization problem using the first two…

What is made up? :sweat_smile:. The PDESystem Syntax is like this. I have seen it on Modelingtoolkit.jl.

At the same time, I know what U are saying and I don’t. How can I make a new prob using the first two when I don’t have any other relationship to define a new problem?
Thanks for your time.

The only solution I have on my mind is that when I define problems, I define a new loss function which calls both problems loss functions then make a new problem. Do U know if it is possible to do so with symbolic_discretize or not?

Not right now.

No, those values are not keyword arguments. They are positional in all of the docs.

You know the relationship because you just built it.

That’s what I am describing.

No, just do it as I showed.

1 Like

Thanks. :heart:

I apologize for asking so many questions. After defining the new loss function like what U mentioned
for defining new optimization problem surely, I need to define u0 from the init parameters produced. Since there are two different init parameters, Is it logical for me to vcat them? Or should I do something else?

f_ = OptimizationFunction(newf, Optimization.AutoZygote())
prob = Optimization.OptimizationProblem(f_, u0??)


yes, and then you slice them in newf.

1 Like

What is the purpose of slicing them in newf? Can’t I just give the problem f_ and u0? newf is my new loss function which is the sum of the prob1 and prob2 loss functions.

yes but you want to give different coefficients (u0 parts) to prob1.f and prob2.f? That’s the reason for concatenating u0?

1 Like