Replies: 1 comment 1 reply
-
|
You can try larger weight for IC. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Dear @lululxvi
I am working on training the diffusivity coefficient in a diffusion equation with variable diffusivity wherein after training I am seeing that the final composition profile matches very well whereas initial profile as well as PDE isn't satisfied to that extend whereby eventually the trained diffusivity isn't accurate.So my code is attached below as
`
import deepxde as dde
import numpy as np
import pandas as pd
import time
import matplotlib.pyplot as plt
import torch
#Exponential Constants in Diffusivity Function to be Determined in Inverse Problem
a = dde.Variable(1.0)
b = dde.Variable(1.0)
c = dde.Variable(1.0)
d0 = dde.Variable(10.0)
def get_derivative(x,y):
return dde.grad.jacobian(y, x, i=0, j=0)
def pde(x, y):
dy_t = dde.grad.jacobian(y, x, i=0, j=1)
dy_x = dde.grad.jacobian(y,x,i=0,j=0)
dy_xx = dde.grad.jacobian(d0 * torch.exp(a * y + b * y * y + c * y * y * y ) * dy_x,x,i=0,j=0)#Added variable Diffusivity in Fick's Second Law
return (dy_t-dy_xx)
def ZeroBC(x):
return np.zeros((len(x),1))
def step_function(x):
comp=np.zeros((len(x),1))
for i in range(len(x)):
if i <= len(x)/2.0:
comp[i] = 0.75
else:
comp[i] = 0.25
return comp
start = time.time()
#geom = dde.geometry.Interval(0, 0.0006)
geom = dde.geometry.Interval(0, 600)
#timedomain = dde.geometry.TimeDomain(0,360348.34834834834)
timedomain = dde.geometry.TimeDomain(0,99.996996996997)
geomtime = dde.geometry.GeometryXTime(geom, timedomain)
bc = dde.icbc.NeumannBC(geomtime, ZeroBC, lambda _, on_boundary: on_boundary)#Here we need to have Homogeneous Neumann BCs
ic = dde.icbc.IC(geomtime, step_function, lambda _, on_initial: on_initial)#Here the initial condition is applied
#Reading the Data
df = pd.read_fwf('/home/pushkar/jupy/jup_notebook/notebook/PINNs/BinaryAlloy/RawData_Scaled.txt',header=None)
df = df[0].str.split(' ', expand=True)
df.columns = ['Position','Time','Composition']
observe_x = np.vstack((df['Position'].to_numpy(),df['Time'].to_numpy())).T
observe_x = observe_x.astype(float)
comp_y = df['Composition'].to_numpy()
comp_y = comp_y.astype(float)
comp_y = comp_y.reshape((len(comp_y),1))
observe_y = dde.icbc.PointSetBC(observe_x,comp_y, component=0)
data = dde.data.TimePDE(
geomtime,
pde,
[bc,ic,observe_y],
num_domain=1000,
num_boundary=20,
num_initial=10,
anchors=observe_x,
num_test=10000
)
layer_size = [2] + [50] * 8 + [1]
activation = "tanh"
initializer = "Glorot uniform"
net = dde.nn.FNN(layer_size, activation, initializer)
model = dde.Model(data, net)
weights = [10] + [1,1,1]
model.compile(
"adam", lr=3e-4, external_trainable_variables=[a,b,c,d0],loss_weights = weights
)
variable = dde.callbacks.VariableValue([a,b,c,d0], period=1000,filename="Trained_Variable.dat")
losshistory, train_state = model.train(iterations=1000000,callbacks=[variable],model_save_path='DiffusionModel')
end = time.time()
print(f'Elapsed Time : {(end - start)/3600.0} hours')
dde.saveplot(losshistory, train_state, issave=True, isplot=True)
#Get the prediction from model and compare it with final composition
comp_NN = model.predict(observe_x)
plt.plot(observe_x[:,0:1],comp_NN,'r-',label='NNSol')
plt.plot(observe_x[:,0:1],comp_y,label='FDMSol')
plt.title('FinalCompositionComparison - FDM Vs NN')
plt.legend()
plt.savefig('ComparisionPlotDeepXDE.png')
plt.show()
f = model.predict(observe_x, operator=get_derivative)
np.savetxt(f"Derivative.dat",np.hstack((observe_x,f)))
`
Any headers on how I can fit the initial conditions as well as my PDE better will truly be helpful.
Thanks in Advance
Pushkar
Beta Was this translation helpful? Give feedback.
All reactions