deepxde icon indicating copy to clipboard operation
deepxde copied to clipboard

How to solve inverse problem with parameters in the boundary condition?

Open qgs17 opened this issue 1 year ago • 6 comments

Dear Dr.Lulu and developers, I want to solve for a parameter inversely based on some data. This parameter is not in the differential equation but is expressed in the boundary conditions.Can DeepXDE solve this problem?

Part of my code is below:

C1 = dde.Variable(0.1) #The parameter to be solved

def pde(x,y):
    dy_xx = dde.grad.hessian(y,x)
    return dy_xx - y/L**2

def boundary(x, on_boundary):
    return on_boundary and dde.utils.isclose(x[0], 0)

bc = dde.icbc.NeumannBC(geom, lambda x: C1/(2*D), boundary) # C1 is embeded in this boundary condition


external_trainable_variables = [C1]
variable = dde.callbacks.VariableValue(
    external_trainable_variables, period=500, filename="variables.dat"
)


model.compile("adam", lr=0.001, external_trainable_variables=external_trainable_variables)

losshistory, train_state = model.train(iterations=10000, callbacks=[variable])

error info: RuntimeError: Trying to backward through the graph a second time (or directly access saved tensors after they have already been freed). Saved intermediate values of the graph are freed when you call .backward() or autograd.grad(). Specify retain_graph=True if you need to backward through the graph a second time or if you need to access saved tensors after calling backward.

qgs17 avatar Jan 03 '24 13:01 qgs17

The parameter should be in the PDE. You can first solve the PDE without BC, and then use the PDE solution at boundary to compute C1.

lululxvi avatar Jan 21 '24 20:01 lululxvi

@lululxvi Actually the parameter does not have to be in the PDE, I solved an example where the unknown parameter is in the set of a BC.

tsarikahin avatar Jan 26 '24 14:01 tsarikahin

@tsarikahin This is interesting and good to know. Could you show me a simple demo about how you do it?

lululxvi avatar Feb 15 '24 17:02 lululxvi

@lululxvi We generated a repository (namely pinns_for_comp_mech) based on DeepXDE with a focus on computational mechanics. Here's an example of the Lame problem in elasticity. We define inlet pressure (pressure_inlet_predicted) as a tensor Variable (line 60) and use that in the boundary condition function (line 67 and line 97).

FIY: @maxdanwitz

tsarikahin avatar Feb 16 '24 14:02 tsarikahin

Here is the outcome. Pressure (defined in BC), Youngs modulus (defined in PDE) and Poissons (defined in PDE) ratio are set as variables and calculated by solving the inverse problem.

image

tsarikahin avatar Feb 16 '24 14:02 tsarikahin

@tsarikahin Could you explain how the predicted values align if we examine the data more closely, particularly ~30,000 iterations and beyond? I am also solving an inverse problem with a trainable parameter in my boundary conditions. Despite the predicted values being reasonably close, I'm not observing the perfect overlap of the two lines that typically occurs with conventional numerical methods. image

jdellag avatar Mar 12 '24 22:03 jdellag