deepxde icon indicating copy to clipboard operation
deepxde copied to clipboard

How to put higher order boundary conditions while solving 4th order time dependent pde (1d)

Open divyanshjnv1 opened this issue 1 year ago • 1 comments

Dear all, I am trying to solve Cahn hilliard eqn (a 4th order time dependent pde) but im not able to figure out syntax to put 2nd and 3rd order boundary conditions . 1- Do i need to put all 4 BCs for 4th order eqn or less BCs may work . 2- And please look , is my pde is defined correctly ? (specially 'f_prime' term)

reference eqn is uploaded , code what i have written is also added, please help.

import deepxde as dde
import numpy as np

from deepxde.backend import tf
import tensorflow as tf
import matplotlib.pyplot as plt

def dy_xx(x, y):
return dde.grad.hessian(y, x, i=0, j=0)

def dy_xxx(x, y):
return dde.grad.jacobian(dy_xx(x, y), x, i=0, j=0)

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

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

def pde(x, y):
M, kappa = 1.0, 1.0
f_prime = 2y - 3y**3 # First derivative of f w.r.t. c

dy_t = dde.grad.jacobian(y, x, i=0, j=1)        # 1st derivative of c
dy_xx = dde.grad.hessian(y, x, i=0, j=0)        # 2nd derivative of c
dy_xxx = dde.grad.jacobian(dy_xx, x, i=0, j=0)  # 3rd derivative of c
dy_xxxx = dde.grad.hessian(dy_xx, x, i=0, j=0)  # 4th derivative of c

d2f_prime_dx2 = dde.grad.hessian(f_prime, x, i=0, j=0)  # 2nd derivative of f_prime

return dy_t - M * (d2f_prime_dx2 - kappa * dy_xxxx)
def func(x):
return 0.5*(1 + np.tanh(0.5* x [:,0:1]))

geom = dde.geometry.Interval(-1, 1)
timedomain = dde.geometry.TimeDomain(0, 1)
geomtime = dde.geometry.GeometryXTime(geom, timedomain)

bc = dde.icbc.DirichletBC(geomtime, func, lambda _, on_boundary: on_boundary)
bc3 = dde.icbc.OperatorBC(geom, lambda x, y, _: dy_xx , boundary_r)
bc4 = dde.icbc.OperatorBC(geom, lambda x, y, _: dy_xxx, boundary_r)

ic = dde.icbc.IC(geomtime, func, lambda _, on_initial: on_initial)
data = dde.data.TimePDE(
geomtime,
pde,
[bc,bc3,bc4, ic],
num_domain=40,
num_boundary=20,
num_initial=10,
solution=func,
num_test=10000,
)

layer_size = [2] + [32] * 3 + [1]
activation = "tanh"
initializer = "Glorot uniform"
net = dde.nn.FNN(layer_size, activation, initializer)

model = dde.Model(data, net)

model.compile("adam", lr=0.001, metrics=["l2 relative error"])
losshistory, train_state = model.train(iterations=10000)

dde.saveplot(losshistory, train_state, issave=True, isplot=True)```

Thanks.
![WhatsApp Image 2023-11-17 at 1 36 39 AM](https://github.com/lululxvi/deepxde/assets/150776995/9a70a180-9012-4bde-a5b5-262ddc039400)

divyanshjnv1 avatar Nov 17 '23 13:11 divyanshjnv1

Can you please use markdown code block to write the code? Here is some help.

praksharma avatar Dec 05 '23 17:12 praksharma