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…

3 Likes

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)?

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??)

Thanks

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
sym_prob1 = NeuralPDE.symbolic_discretize(pde_system1, discretization1)
sym_prob2 = NeuralPDE.symbolic_discretize(pde_system2, discretization2)
#loss definition
pde_loss_functions1 = sym_prob1.loss_functions.pde_loss_functions
bc_loss_functions1 = sym_prob1.loss_functions.bc_loss_functions
aprox_derivative_loss_functions1 = sym_prob1.loss_functions.bc_loss_functions
pde_loss_functions2 = sym_prob2.loss_functions.pde_loss_functions
bc_loss_functions2 = sym_prob2.loss_functions.bc_loss_functions
aprox_derivative_loss_functions2 = sym_prob2.loss_functions.bc_loss_functions
##
loss_functions1 =  [pde_loss_functions1;bc_loss_functions1;aprox_derivative_loss_functions1]
loss_functions2 =  [pde_loss_functions2;bc_loss_functions2;aprox_derivative_loss_functions2]
#Loss Functions
function loss_function1(θ,p)
    sum(map(l->l(θ) ,loss_functions1))
end
function loss_function2(θ,p)
    sum(map(l->l(θ) ,loss_functions2))
end
#newf
newf(θ,p)=loss_function1(θ,p)+loss_function2(θ,p)
#Optimization
f_ = OptimizationFunction(newf, Optimization.AutoZygote())
u0 = vcat(sym_prob1.flat_init_params,sym_prob2.flat_init_params)
prob = Optimization.OptimizationProblem(f_, u0)

Am I doing something wrong here in the definition of newf? since U are saying that I should produce prob1.f and prob2.f but I defined their loss functions like that.
thanks