lululxvi / deepxde

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

Issue with IC when simulating the free vibration of a simply supported euler beam #153

Closed DavidBraun97 closed 3 years ago

DavidBraun97 commented 3 years ago

Dear Mr. @lululxvi ,

First of all I would like to thank you for sharing deepxde with the community. Its a wonderful toolbox for Physics Informed ML.

I am currently trying to simulate the free vibration (q(x) = 0) of a simply supported euler beam. image That is the problem is as follows: image with the IC: image In my particular choice I have chosen the IC to be: image

So far the output after 25000 epochs of adam with lr=1e-3 and subsequent BFGS optimization the results is as follows: image It appears that the general structure of the solution is learned correctly. However, when taking a closer look the magnitude of the NN output appears to be off. See for instance the predicted deflection at t=0, i.e. at IC: image Considering above result, the model does not correctly learn the IC. In fact there seems to be an issue of scaling. Above results are the outcome of the following training routine: ####################################### model.compile("adam", lr=1e-3, loss_weights=[1e-3,1,1,500,100]) losshistory, train_state = model.train(epochs=25000) ..... model.compile("L-BFGS-B", loss_weights=[1e-3,1,1,500,100]) losshistory, train_state = model.train() #######################################

So far I do not know where the cause for this error in magnitude lies in. I think that I implemented the problem correctly. For illustration, please find the problem definition below:

####################################### from future import absolute_import from future import division from future import print_function import numpy as np import deepxde as dde from deepxde.backend import tf import matplotlib.pyplot as plt from scipy.interpolate import griddata from plotly.subplots import make_subplots import plotly.graph_objects as go

def dydt(x,y): dy_dt = tf.gradients(y, x)[0][:, 1:2] return dy_dt def dydxx(x,y): dy_dx = tf.gradients(y, x)[0][:, :1] dy_xx = tf.gradients(dy_dx, x)[0][:, :1] return dy_xx

def pde(x, y): dy_xt = tf.gradients(y, x)[0] dy_x,dy_t = dy_xt[:, :1], dy_xt[:, 1:]

dy_xx = tf.gradients(dy_x, x)[0][:, :1] dy_tt = tf.gradients(dy_t, x)[0][:, 1:]

dy_xxx = tf.gradients(dy_xx, x)[0][:, :1] dy_xxxx = tf.gradients(dy_xxx, x)[0][:, :1]

return dy_xxxx + dy_tt

def boundaryinitial(x, ): return np.isclose(x[-1], 0)

def func(x): x, t = x[:, :1], x[:, 1:] return np.sin(3 np.pi x) np.cos(9(np.pi*2)t)

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

bcs = [ dde.DirichletBC(geomtime, lambda x: 0,lambda _, on_boundary: onboundary),
dde.OperatorBC(geomtime, lambda x, y,
: dydxx(x,y), lambda _, on_boundary: on_boundary)
]

ics = [ dde.IC(geomtime, lambda x: np.sin(3 np.pi x), lambda _, on_initial: oninitial), dde.OperatorBC(geomtime, lambda x,y,: dydt(x,y), lambda _, on_initial: on_initial) ]

data = dde.data.TimePDE( geomtime, pde, bcs + ics, num_domain=3000, num_boundary=600, num_initial=900, solution=func, num_test=100, train_distribution="uniform", ) layer_size = [2] + [100]*3+ [1] last activation = "tanh" initializer = "Glorot uniform" net = dde.maps.FNN(layer_size, activation,initializer)

model = dde.Model(data, net) #######################################

It would be very kind of you if you (or anybody else out there) could give me some feedback on my implementation. Maybe someone has an idea where things go wrong. Besides that, I am not 100% sure if my PDE,BC and IC are correctly defined.

I am very thankful for any feedback! Thanks again for your great contribution @lululxvi.

Cheers, David

lululxvi commented 3 years ago

IC should be

dde.IC(geomtime, lambda x: np.sin(3* np.pi * x[:, 0:1]), lambda _, on_initial: on_initial)

x is (x, t).

DavidBraun97 commented 3 years ago

Thank you very much @lululxvi ! This helped a lot.

I am closing the issue now. Cheers.