lululxvi / deepxde

A library for scientific machine learning and physics-informed learning
https://deepxde.readthedocs.io
GNU Lesser General Public License v2.1
2.59k stars 733 forks source link

Flow in heterogeneous porous media - non homegeneous domain #584

Open gaboperezayala opened 2 years ago

gaboperezayala commented 2 years ago

Dear Dr. Lu Lu, Thanks for this incredible tool DeepXDE. I am currently working on flow in heterogeneous porous media, I was able to solve the homogeneous part of the problem, but I'm facing a challenge in moving forward with the heterogeneous part.

The equation to solve in the homogeneous part is:

p_xx + p_yy = 0 in Ω = [0,1] x [0,1]

with the Dirichlet boundary conditions:

p = 10 on Ω = (x,Ly), x ε [0,1] p = 5 on Ω = (x,0), x ε [0,1]

and, with the Neumann boundary conditions:

u = 0 on ∂Ω = (0,y), y ε [0,1] u = 0 on ∂Ω = (Lx,y), y ε [0,1]

Now for the heterogeneous, the idea is to use XPINN schema to subdivide the domain into three different subdomains to solve the problem and stitch three subnets to get the solution for the entire domain. https://doi.org/10.4208/cicp.OA-2020-0164 Ameya D.Jagtap However, I haven't found a way to decompose the domain into three small subdomains. I'd really appreciate any starting point you could provide me to tackle the problem.

My code looks like so far: (for the homogeneous domain)

I have got this result

lululxvi commented 2 years ago

See FAQ "Q: How can I implement new ODEs/PDEs, e.g., compute derivatives, complicated PDEs?"

gaboperezayala commented 2 years ago

Dr Lu Lu, Thanks for your previos answer, I have review the FAQ, and the code from other user. However, I got stuck in a point where I don't know to continue. I'm got the same error as @troyrock in #278 issue.

below is the code:

the error: ... C:\ProgramData\Anaconda3\lib\site-packages\deepxde\data\pde.py in losses(self, targets, outputs, loss, model) 152 beg, end = bcs_start[i], bcs_start[i + 1] 153 # The same BC points are used for training and testing. --> 154 error = bc.error(self.train_x, model.net.inputs, outputs, beg, end) 155 losses.append(loss[len(error_f) + i](bkd.zeros_like(error), error)) 156 return losses

C:\ProgramData\Anaconda3\lib\site-packages\deepxde\icbc\boundary_conditions.py in error(self, X, inputs, outputs, beg, end) 148 149 def error(self, X, inputs, outputs, beg, end): --> 150 return self.func(inputs, outputs, X)[beg:end] 151 TypeError: 'function' object is not subscriptable

For sure the error is in the definition of boundary_top and boundary_bottom, but I still don't know how to fix it.

I'd really appreciate your help with this issue! Many thanks in advance!

lululxvi commented 2 years ago

dde.geometry.Rectangle([0,0],[3,3]) - dde.geometry.Rectangle([0,0],[1.5,3]) is just a rectangle from [1.5, 0] to [3,3]?

gaboperezayala commented 2 years ago

yes, is just a rectangle. The idea is just divide the domain in two or more subdomains, I have tried with just two rectangles so far

lululxvi commented 2 years ago
def pde_top(x,y, _):
    ...

bc_top = dde.OperatorBC(geom, pde_top, boundary_top)

Also, boundary_top is correct in terms of grammar, but is it what you need? Do you need points to be on_boundary? Maybe this is what you need:

def boundary_top(y, on_boundary):
    return top.inside(np.array([y]))[0]

Similarly for boundary_bottom.

gaboperezayala commented 2 years ago

Hello, Dr. Lu Lu thanks for the help you have provided to me!!

The script is now running. However, I'm not getting the results I was expecting. In my code below, I understand that I divided the domain into two different subdomains (top and bottom), using the OperatorBC I am solving pde_100 and pde_1 for each subdomain respectively. Besides, I am also considering Neuman and Dirichlet boundary conditions for the entire domain. If I am right, then I don't know why the solution is exactly like the homogenous case. When plotting pressure against x, I was expecting a change in the slope between the two subdomains.

Am I right with my analysis of the problem?

I really appreciate all your help, Many thanks!

lululxvi commented 2 years ago

For XPINN, you need multiple outputs and also interface losses.

gaboperezayala commented 2 years ago

Dr. Lu Lu, thanks very much for your reply. I wonder if it is doable using deepXDE, or do you recommend going back to TensorFlow?

lululxvi commented 2 years ago

Yes, it is doable. There are similar examples at FAQ "Q: How can I implement new ODEs/PDEs, e.g., compute derivatives, complicated PDEs?"

gaboperezayala commented 2 years ago

Dr. Lu Lu, thanks for your help and your answers to my questions! After your last comment I have come with this pice of code:

Now I understand that I need an output per each subdomain. However, I still don't fully understand the interface between the two subdomains. I was expecting to be able to stick them together using OperatorBC and the flux function I defined.

Do I need to set a condition inside the function pde to force the pde1 only for the top subdomain and pde2 only for the bottom subdomain? or How can I stick both solutions in only one?

gaboperezayala commented 2 years ago

Hello Dr. Lu Lu, Thanks again for your help! When dividing the domain into two subdomains, I got good results so far, as you can see in the next images.

operatorBC_8 operatorBC_8_2

However, when I try to change the geometry with the following code I get this error:

ValueError: all the input arrays must have same number of dimensions, but the array at index 0 has 2 dimension(s) and the array at index 1 has 1 dimension(s)

I have identified that the interface function is causing the error, but I haven't been able to fix it

the only difference is:

def interface(x,_):
    return np.isclose(x[0],2.0)

If I use 1.5 instead of 2.0, then the code runs, but that is not what I am looking for.

I'd really appreciate any help you can provide to me!!! I apologize if the question is too simple, Thanks again!

lululxvi commented 2 years ago

It could be that there is no training point of x=1.5. Try to add points with x=1.5 via anchors.

sashahexe commented 2 years ago

Dear @gaboperezayala,

I am also trying to solve a problem on multiple domains. WOuld be so kind to share your code with me?

Kind wishes, Alexandra

ach14012022 commented 2 years ago

Hello Dr. Lu Lu, Thanks again for your help! When dividing the domain into two subdomains, I got good results so far, as you can see in the next images.

operatorBC_8 operatorBC_8_2

However, when I try to change the geometry with the following code I get this error:

ValueError: all the input arrays must have same number of dimensions, but the array at index 0 has 2 dimension(s) and the array at index 1 has 1 dimension(s)

I have identified that the interface function is causing the error, but I haven't been able to fix it

the only difference is:

def interface(x,_):
    return np.isclose(x[0],2.0)

If I use 1.5 instead of 2.0, then the code runs, but that is not what I am looking for.

I'd really appreciate any help you can provide to me!!! I apologize if the question is too simple, Thanks again!

Dear Dr. Lu Lu, Thanks for this incredible tool DeepXDE. I am currently working on flow in heterogeneous porous media, I was able to solve the homogeneous part of the problem, but I'm facing a challenge in moving forward with the heterogeneous part.

The equation to solve in the homogeneous part is:

p_xx + p_yy = 0 in Ω = [0,1] x [0,1]

with the Dirichlet boundary conditions:

p = 10 on Ω = (x,Ly), x ε [0,1] p = 5 on Ω = (x,0), x ε [0,1]

and, with the Neumann boundary conditions:

u = 0 on ∂Ω = (0,y), y ε [0,1] u = 0 on ∂Ω = (Lx,y), y ε [0,1]

Now for the heterogeneous, the idea is to use XPINN schema to subdivide the domain into three different subdomains to solve the problem and stitch three subnets to get the solution for the entire domain. https://doi.org/10.4208/cicp.OA-2020-0164 Ameya D.Jagtap However, I haven't found a way to decompose the domain into three small subdomains. I'd really appreciate any starting point you could provide me to tackle the problem.

My code looks like so far: (for the homogeneous domain)

I have got this result

@gaboperezayala could you solve your problem?

fanzi66 commented 2 years ago

@gaboperezayala,hello, I have a question to ask you about the layered interface. I found that although different materials are defined in PDE, but they do not play a role in the results. I think it may be the reason for continuity boundary conditions. So I want to ask how this continuity boundary condition is added and provide ideas. Can you provide some ideas?

LucasMSpereira commented 1 year ago

Why is all the code from this discussion gone? I checked the FAQ. This seems to be the best reference for using XPINNs in deepxde... Is there another starting point?