Open Jagadeesh-23 opened 1 year ago
Dear sir, I have tried to implement the same in 2d currently. I am receiving some errors. Please correct me
import torch rhoc =4.005*(10(-3)) k= 0.05 v= 10 ff= 0.6 fr= 1.4 Q= 1652.4 af= 1.002 ar= 3.34 b= 1.67 c= 1.67 h= 20*(10*(-6)) alpha= 12.484 T_ref= 273.15 Rboltz =5.67(10(-14)) emiss= 0.3 t0 = 0.0 te= 2.0 eta= 0.9 v = 10. U= 15.3 I= 120 x0 = -10 y0 = 0 num_domain = 30000 num_boundary = 20000 num_initial = 20000 layer_size = [3] + [60] * 5 + [1] activation_func = "tanh" initializer = "Glorot uniform" lr = 1e-3
loss_weights = [10, 1, 1, 1, 1, 10] epochs = 10000 optimizer = "adam" batch_size= 256
def pde(x, T): x, y, t= x[:, 0:1], x[:, 1:2], x[:, 2:3] dT_x = dde.grad.jacobian(T, x, j=0) dT_xx = dde.grad.hessian(T, x, j=0) dT_y = dde.grad.jacobian(T, x, j=1) dT_yy = dde.grad.hessian(T, x, j=1) dT_t = dde.grad.jacobian(T, x, j=2)
r02= ((x- x0-vt)2/af2)+((y-y0)2/b2) qf= (6((3)*(1/3))ffetaUI/(afbc3.141591.7724))torch.exp(-3r02) qr= (6((3)*(1/3))fretaUI/(arbc3.141591.7724))torch.exp(-3r02) q = qf+qr return rhoc(dT_t)- k*(dT_xx+dT_yy)-q
def boundary_l(x, on_boundary): return on_boundary and np.isclose(x[0], -20) def boundary_r(x, on_boundary): return on_boundary and np.isclose(x[0], 20) def boundary_u(x, on_boundary): return on_boundary and np.isclose(x[1], 5)
def boundary_d(x, on_boundary): return on_boundary and np.isclose(x[1], -5)
def boundary_initial(x, on_initial): return on_initial and np.isclose(x[2], 0)
def func_left(x, T): x, y, t= x[:, 0:1], x[:, 1:2], x[:, 2:3] dT_x = dde.grad.jacobian(T, x, j=0) return kdT_x - h(T-T_ref) - Rboltzemiss(T4-T_ref4)
def func_right(x, T): x, y, t= x[:, 0:1], x[:, 1:2], x[:, 2:3] dT_x = dde.grad.jacobian(T, x, j=0) return -kdT_x - h(T-T_ref) - Rboltzemiss(T4-T_ref4) def func_top(x, T): x, y, t= x[:, 0:1], x[:, 1:2],x[:, 2:3] dT_y = dde.grad.jacobian(T, x, j=1) return -kdT_y - h(T-T_ref) - Rboltzemiss(T4-T_ref4) def func_down(x, T): x, y, t= x[:, 0:1], x[:, 1:2],x[:, 2:3] dT_y = dde.grad.jacobian(T, x, j=1) return kdT_y - h(T-T_ref) - Rboltzemiss(T4-T_ref4)
def initial(x): return np.ones((len(x),1), dtype=np.float32)*T_ref
lower_left= [-20, -5] upper_right= [20, 5] geom= dde.geometry.Rectangle(lower_left, upper_right) timedomain= dde.geometry.TimeDomain(t0, te) geomtime= dde.geometry.GeometryXTime(geom, timedomain)
bc_x_l= dde.NeumannBC(geomtime,func_left, boundary_l) bc_x_r= dde.NeumannBC(geomtime,func_right, boundary_r) bc_x_t= dde.NeumannBC(geomtime,func_top, boundary_u) bc_x_d= dde.NeumannBC(geomtime,func_down, boundary_d)
ic= dde.IC(geomtime, initial, boundary_initial)
data = dde.data.TimePDE( geomtime, pde, [bc_x_l, bc_x_r, bc_x_t, bc_x_d, ic], num_domain=num_domain, num_boundary=num_boundary, num_initial=num_initial)
net= dde.maps.FNN(layer_size, activation_func, initializer) net.apply_output_transform(lambda x, y, :abs(y))
model = dde.Model(data, net)
model.compile(optimizer, lr= lr, loss_weights= loss_weights)
checker= dde.callbacks.ModelCheckpoint('model/model1.ckpt', save_better_only= True, period= 1000) losshistory, trainstate= model.train(epochs= epochs, batch_size= batch_size, callbacks= [checker]) model.compile('L-BFGS-B') dde.optimizers.set_LBFGS_options(maxcor= 50) losshistory, trainstate= model.train(epochs= epochs, batch_size= batch_size) dde.saveplot(losshistory, trainstate, issave= True, isplot= True)
Below is the error i am receiving:
Compiling model... Building feed-forward neural network... 'build' took 0.088725 s
tf.layers.dense
is deprecated and will be removed in a future version. Please use tf.keras.layers.Dense
instead.
return tf.layers.dense(AttributeError Traceback (most recent call last)
10 frames /usr/local/lib/python3.10/dist-packages/deepxde/gradients.py in init(self, ys, xs) 20 21 if backend_name in ["tensorflow.compat.v1", "tensorflow", "pytorch", "paddle"]: ---> 22 self.dim_y = ys.shape[1] 23 elif backend_name == "jax": 24 # For backend jax, a tuple of a jax array and a callable is passed as one of
AttributeError: 'NoneType' object has no attribute 'shape'
Ur boundary condition definition is wrong I assume. Since Neumann is dT/dn= 0. U need to define those boundaries as RobinBC (dT/dn = Func(x,y)). If you want to define your boundaries by Jacobian, U need to use OperatorBC.
@lululxvi
dear sir,
I want to solve the above problem with these following pde, bc, and ic conditions
This is 3d heat conduction equation Here q is the total heat = q_source (On top surface) - (total_q_convection_loss+total_q_radiation_loss)
The output should be Temperature(T) at (x, y, z, t) The q_source is given as
x0, y0, z0 is initial coordinates of heat source
I want to apply initial boundary condition (x, y, z, 0) = 273.15k
i want to apply hard neumann boundary condition kT_n - h(T-T_ref) - Rboltz emiss(T^4-T_ref^4) on all the surfaces to incorporate the radiation and convection loss. n is surface normal
So my doubt is that we require T which is predicted by model to apply this boundary condition, as i have seen in many other problems where output (like T ) is not required(Not present) in the boundary condition, So could you please help in solving this problem
Thank you, waiting for your reply sir.