You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#XY = XYT[:,:][XYT[:,2]==time_end]
X = XY[:,0:1]
Y = XY[:,1:2]
X = X.reshape(101,101)
Y = Y.reshape(101,101)
dim = Y.shape[0]
Q_pre = global_filed[:,0:1] #稳定的热场
Q_pre = Q_pre.reshape(101,101)
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I want to compute a heat convection equation, as shown below
My code hardly converge and every training I will get different results. I don't konw why. There is my code.
`import deepxde as dde
import numpy as np
import torch
import matplotlib.pyplot as plt
from scipy.io import loadmat
data = loadmat(r"D:\MATLAB Document\RB对流\horizontal_convection_havegap_b\data\纯热对流\300000.mat")
data_domain1 = np.array(data['Calculated_value'][:,:])
XY = data_domain1[:, 0:2] # for printing
XYT = data_domain1[:, 0:3]
Q_accu = data_domain1[:, 3:4]
Ra=np.power(10,6)
Pr=1
alpha=1/torch.sqrt(torch.tensor(Ra*Pr))
spatial_domain=dde.geometry.Rectangle([0,0],[1,1])
time_domain=dde.geometry.TimeDomain(0,6000)
geomtime=dde.geometry.GeometryXTime(spatial_domain,time_domain)
def pde(x,y):
q=y[:,0:1]
dq_xx = dde.grad.hessian(y, x, i=0, j=0)
dq_yy = dde.grad.hessian(y, x, i=1, j=1)
dq_t=dde.grad.jacobian(y, x,i = 0,j = 2)
return dq_t-alpha*(dq_xx+dq_yy)
def boundary_left(x, on_boundary):
return on_boundary and dde.utils.isclose(x[0], 0.0)
def boundary_right(x, on_boundary):
return on_boundary and dde.utils.isclose(x[0], 1.0)
def boundary_bottom(x, on_boundary):
return on_boundary and dde.utils.isclose(x[1], 0.0)
def boundary_top(x, on_boundary):
return on_boundary and dde.utils.isclose(x[1], 1.0)
def func(x):
return np.cos(np.pi*x[:,0:1])
bc1=dde.icbc.NeumannBC(geomtime,lambda x:0, boundary_left)
bc2=dde.icbc.NeumannBC(geomtime,lambda x:0, boundary_right)
bc3=dde.icbc.NeumannBC(geomtime,lambda x:0, boundary_top)
bc4=dde.icbc.DirichletBC(geomtime,func, boundary_bottom)
bci=dde.icbc.IC(geomtime, lambda x:0.1,lambda _, on_initial:on_initial)
data=dde.data.TimePDE(geomtime,pde,
[bc1,bc2,bc3,bc4,bci],
num_domain=5000,
num_boundary=1000,
num_test=1000,
num_initial=500)
layer_size = [3] + [50] * 5 + [1]
activation = ("tanh")
initializer = "Glorot uniform"
net = dde.nn.FNN(layer_size, activation, initializer)
model = dde.Model(data, net)
model.compile("adam", lr=1e-4, loss_weights=[1, 10, 150, 10, 100, 1])# metrics=["l2 relative error"])
loss_history, train_state = model.train(iterations=20000, display_every=1000)
#dde.saveplot(loss_history, train_state, issave=True, isplot=True)
dde.saveplot(loss_history, train_state, issave=True, isplot=True)
global_loc = "global_filed.dat"
global_filed = model.predict(XYT)
data_global = np.hstack((XYT, global_filed[:,0:1]))
np.savetxt(global_loc, data_global)
f = model.predict(XYT, operator=pde)
print("Mean residual:", np.mean(np.absolute(f)))
print("L2 relative error:", dde.metrics.l2_relative_error(Q_accu, global_filed))
Plot and output results:
#XY = XYT[:,:][XYT[:,2]==time_end]
X = XY[:,0:1]
Y = XY[:,1:2]
X = X.reshape(101,101)
Y = Y.reshape(101,101)
dim = Y.shape[0]
Q_pre = global_filed[:,0:1] #稳定的热场
Q_pre = Q_pre.reshape(101,101)
numerical solution by spectral method
Q_accu = Q_accu.reshape(101,101)
plt.figure()
plt.subplot(2,1,1)
plt.contourf(X,Y,Q_accu, cmap=plt.cm.jet)
plt.title('Numerical Solutipon_q')
plt.colorbar()
plt.subplot(2,1,2)
plt.contourf(X,Y,Q_pre, cmap = plt.cm.jet)
plt.title('PINN_q')
plt.colorbar()
fig_loc = "comparison.jpg"
plt.savefig(fig_loc)
plt.show()`
results comparison
Beta Was this translation helpful? Give feedback.
All reactions