From 3ac988e41e03016835f124482ccbc1586797a2a2 Mon Sep 17 00:00:00 2001 From: ruoyunbai <56343340+ruoyunbai@users.noreply.github.com> Date: Mon, 3 Jul 2023 00:59:34 +0800 Subject: [PATCH 01/11] Create test_linear_elasticity.py test:equation/pde/linear_elasticity.py --- test/equation/test_linear_elasticity.py | 275 ++++++++++++++++++++++++ 1 file changed, 275 insertions(+) create mode 100644 test/equation/test_linear_elasticity.py diff --git a/test/equation/test_linear_elasticity.py b/test/equation/test_linear_elasticity.py new file mode 100644 index 000000000..06067e7f8 --- /dev/null +++ b/test/equation/test_linear_elasticity.py @@ -0,0 +1,275 @@ +import paddle +import pytest +from paddle import nn +from ppsci.equation import LinearElasticity + +def stress_disp_xx_expected_result(u,v,w,x,y,z,lambda_,mu,dim,sigma_xx): + stress_disp_xx = ( + lambda_ * (jacobian(u, x) + jacobian(v, y)) + + 2 * mu * jacobian(u, x) + - sigma_xx + ) + if dim == 3: + stress_disp_xx += lambda_ * jacobian(w, z) + return stress_disp_xx + + +def stress_disp_yy_expected_result(u,v,w,x,y,z,lambda_,mu,dim,sigma_yy): + stress_disp_yy = ( + lambda_ * (jacobian(u, x) + jacobian(v, y)) + + 2 * mu * jacobian(v, y) + - sigma_yy + ) + if dim == 3: + stress_disp_yy += lambda_ * jacobian(w, z) + return stress_disp_yy + + + +def stress_disp_zz_expected_result(u,v,w,x,y,z,lambda_,mu,sigma_zz): + stress_disp_zz = ( + lambda_ * (jacobian(u, x) + jacobian(v, y) + jacobian(w, z)) + + 2 * mu * jacobian(w, z) + - sigma_zz + ) + return stress_disp_zz + + +def stress_disp_xy_expected_result(u,v,x,y,mu,sigma_xy): + stress_disp_xy = mu * (jacobian(u, y) + jacobian(v, x)) - sigma_xy + return stress_disp_xy + + + +def stress_disp_xz_expected_result(u,w,x,z,mu,sigma_xz): + stress_disp_xz = mu * (jacobian(u, z) + jacobian(w, x)) - sigma_xz + return stress_disp_xz + + +def stress_disp_yz_expected_result(v,w,y,z,mu,sigma_yz): + stress_disp_yz = mu * (jacobian(v, z) + jacobian(w, y)) - sigma_yz + return stress_disp_yz + + +def equilibrium_x_expected_result(u,x,y,z,t,rho,dim,time,sigma_xx,sigma_xy,sigma_xz=None): + equilibrium_x = -jacobian(sigma_xx, x) - jacobian(sigma_xy, y) + if dim == 3: + equilibrium_x -= jacobian(sigma_xz, z) + if time: + equilibrium_x += rho * hessian(u, t) + return equilibrium_x + + +def equilibrium_y_expected_result(v,x,y,z,t,rho,dim,time,sigma_yy,sigma_xy,sigma_yz=None): + equilibrium_y = -jacobian(sigma_xy, x) - jacobian(sigma_yy, y) + if dim == 3: + equilibrium_y -= jacobian(sigma_yz, z) + if time: + equilibrium_y += rho * hessian(v, t) + return equilibrium_y + +def equilibrium_z_expected_result(w,x,y,z,t,rho,time,sigma_xz,sigma_yz,sigma_zz): + equilibrium_z = ( + -jacobian(sigma_xz, x) + - jacobian(sigma_yz, y) + - jacobian(sigma_zz, z) + ) + if time: + equilibrium_z += rho * hessian(w, t) + return equilibrium_z + +def traction_x_expected_result(normal_x, normal_y, sigma_xx, sigma_xy, normal_z=None, sigma_xz=None): + traction_x = normal_x * sigma_xx + normal_y * sigma_xy + if normal_z is not None and sigma_xz is not None: + traction_x += normal_z * sigma_xz + return traction_x + +def traction_y_expected_result(normal_x, normal_y, sigma_xy, sigma_yy, normal_z=None, sigma_yz=None): + traction_y = normal_x * sigma_xy + normal_y * sigma_yy + if normal_z is not None and sigma_yz is not None: + traction_y += normal_z * sigma_yz + return traction_y + +def traction_z_expected_result(normal_x, normal_y, normal_z, sigma_xz, sigma_yz, sigma_zz): + traction_z = normal_x * sigma_xz + normal_y * sigma_yz + normal_z * sigma_zz + return traction_z + +def jacobian(y: paddle.Tensor, x: paddle.Tensor) -> paddle.Tensor: + return paddle.grad(y, x, create_graph=True, allow_unused=True)[0] + +def hessian(y: paddle.Tensor, x: paddle.Tensor) -> paddle.Tensor: + return jacobian(jacobian(y, x), x) +def navier_x_expected_result(u, v, w, x, y, z, t, lambda_, mu, rho, dim, time): + duxvywz = jacobian(u, x) + jacobian(v, y) + duxxuyyuzz = hessian(u, x) + hessian(u, y) + if dim == 3: + duxvywz += jacobian(w, z) + duxxuyyuzz += hessian(u, z) + navier_x = ( + -(lambda_ + mu) * jacobian(duxvywz, x) - mu * duxxuyyuzz + ) + if time: + navier_x += rho * hessian(u, t) + return navier_x +def navier_y_expected_result(u, v, w, x, y, z, t, lambda_, mu, rho, dim, time): + duxvywz = jacobian(u, x) + jacobian(v, y) + dvxxvyyvzz = hessian(v, x) + hessian(v, y) + if dim == 3: + duxvywz += jacobian(w, z) + dvxxvyyvzz += hessian(v, z) + navier_y = ( + -(lambda_ + mu) * jacobian(duxvywz, y) - mu * dvxxvyyvzz + ) + if time: + navier_y += rho * hessian(v, t) + return navier_y + +def navier_z_expected_result(u, v, w, x, y, z, t, lambda_, mu, rho,time): + duxvywz = jacobian(u, x) + jacobian(v, y) + jacobian(w, z) + dwxxvyyvzz = hessian(w, x) + hessian(w, y) + hessian(w, z) + navier_z = ( + -(lambda_ + mu) * jacobian(duxvywz, z) + - mu * dwxxvyyvzz + ) + if time: + navier_z += rho * hessian(w, t) + return navier_z + +@pytest.mark.parametrize( + "E, nu, lambda_, mu, rho, dim, time", + [ + (1e4, 0.3, None, None, 1, 2, False), + (1e4, 0.3, None, None, 1, 2, True), + (1e4, 0.3, None, None, 1, 3, False), + (1e4, 0.3, None, None, 1, 3, True), + ], +) +def test_linear_elasticity(E, nu, lambda_, mu, rho, dim, time): + batch_size = 13 + x = paddle.randn([batch_size, 1]) + y = paddle.randn([batch_size, 1]) + z = paddle.randn([batch_size, 1]) if dim == 3 else None + t = paddle.randn([batch_size, 1]) if time else None + normal_x = paddle.randn([batch_size, 1]) + normal_y = paddle.randn([batch_size, 1]) + normal_z = paddle.randn([batch_size, 1]) if dim == 3 else None + + + x.stop_gradient = False + y.stop_gradient=False + if dim == 3: + z.stop_gradient=False + if time: + t.stop_gradient=False + + + lambda_ = (E * nu) / ((1 + nu) * (1 - 2 * nu)) + mu = E / (2 * (1 + nu)) + + + input_data = paddle.concat([x, y], axis=1) + if dim == 3: + input_data = paddle.concat([input_data, z], axis=1) + if time: + input_data = paddle.concat([input_data, t], axis=1) + + + model = nn.Sequential( + nn.Linear(input_data.shape[1], 9 if dim == 3 else 5), + nn.Tanh(), + ) + + + # generate output through the model + output = model(input_data) + + + # 提取输出中的u, v, w, sigma_xx, sigma_xy, sigma_xz, sigma_yy, sigma_yz, sigma_zz + u, v = output[:, 0:1], output[:, 1:2] + if dim == 3: + w = output[:, 2:3] + sigma_xx, sigma_xy, sigma_xz, sigma_yy, sigma_yz, sigma_zz = ( + output[:, 3:4], output[:, 4:5], output[:, 5:6], output[:, 6:7], output[:, 7:8], output[:, 8:9] + ) + else: + w = None + sigma_xx, sigma_xy, sigma_yy = ( + output[:, 2:3], output[:, 3:4], output[:, 4:5] + ) + sigma_xz, sigma_yz, sigma_zz = None, None, None + + expected_stress_disp_xx = stress_disp_xx_expected_result(u,v,w,x,y,z,lambda_,mu,dim,sigma_xx) + expected_stress_disp_yy = stress_disp_yy_expected_result(u,v,w,x,y,z,lambda_,mu,dim,sigma_yy) + expected_stress_disp_xy = stress_disp_xy_expected_result(u,v,x,y,mu,sigma_xy) + expected_equilibrium_x=equilibrium_x_expected_result(u, x, y, z, t, rho, dim, time,sigma_xx,sigma_xy,sigma_xz) + expected_equilibrium_y=equilibrium_y_expected_result(v, x, y, z, t, rho, dim, time,sigma_yy,sigma_xy,sigma_yz) + expected_traction_x = traction_x_expected_result(normal_x, normal_y, sigma_xx, sigma_xy, normal_z, sigma_xz) + expected_traction_y = traction_y_expected_result(normal_x, normal_y, sigma_xy, sigma_yy, normal_z, sigma_yz) + expected_navier_x = navier_x_expected_result(u, v, w, x, y, z, t, lambda_, mu, rho, dim, time) + expected_navier_y=navier_y_expected_result(u, v, w, x, y, z, t, lambda_, mu, rho, dim, time) + if dim == 3: + expected_stress_disp_zz = stress_disp_zz_expected_result(u,v,w,x,y,z,lambda_,mu,sigma_zz) + expected_stress_disp_xz = stress_disp_xz_expected_result(u,w,x,z,mu,sigma_xz) + expected_stress_disp_yz = stress_disp_yz_expected_result(v,w,y,z,mu,sigma_yz) + expected_equilibrium_z=equilibrium_z_expected_result(w, x, y, z, t, rho, time,sigma_xz,sigma_yz,sigma_zz) + expected_navier_z = navier_z_expected_result(u, v, w, x, y, z, t, lambda_, mu, rho,time) + expected_traction_z = traction_z_expected_result(normal_x, normal_y, normal_z, sigma_xz, sigma_yz, sigma_zz) + + + linear_elasticity = LinearElasticity(E=E, nu=nu, lambda_=lambda_, mu=mu, rho=rho, dim=dim, time=time) + data_dict = { + "x": x, + "y": y, + "u": u, + "v": v, + "z": z, + "w": w, + "t": t, + "sigma_xx": sigma_xx, + "sigma_xy": sigma_xy, + "sigma_xz": sigma_xz, + "sigma_yy": sigma_yy, + "sigma_yz": sigma_yz, + "sigma_zz": sigma_zz, + "normal_x": normal_x, + "normal_y": normal_y, + "normal_z": normal_z, + } + test_stress_disp_xx = linear_elasticity.equations["stress_disp_xx"](data_dict) + test_stress_disp_yy = linear_elasticity.equations["stress_disp_yy"](data_dict) + test_stress_disp_xy = linear_elasticity.equations["stress_disp_xy"](data_dict) + test_equilibrium_x = linear_elasticity.equations["equilibrium_x"](data_dict) + test_equilibrium_y = linear_elasticity.equations["equilibrium_y"](data_dict) + test_navier_x = linear_elasticity.equations["navier_x"](data_dict) + test_navier_y = linear_elasticity.equations["navier_y"](data_dict) + test_traction_x = linear_elasticity.equations["traction_x"](data_dict) + test_traction_y = linear_elasticity.equations["traction_y"](data_dict) + if dim == 3: + test_stress_zz=linear_elasticity.equations["stress_disp_zz"](data_dict) + test_stress_xz=linear_elasticity.equations["stress_disp_xz"](data_dict) + test_stress_yz=linear_elasticity.equations["stress_disp_yz"](data_dict) + test_equilibrium_z = linear_elasticity.equations["equilibrium_z"](data_dict) + test_navier_z = linear_elasticity.equations["navier_z"](data_dict) + test_traction_z = linear_elasticity.equations["traction_z"](data_dict) + + assert paddle.allclose(expected_stress_disp_xx, test_stress_disp_xx) + assert paddle.allclose(expected_stress_disp_yy, test_stress_disp_yy) + assert paddle.allclose(expected_stress_disp_xy, test_stress_disp_xy) + assert paddle.allclose(expected_equilibrium_x, test_equilibrium_x) + assert paddle.allclose(expected_equilibrium_y, test_equilibrium_y) + assert paddle.allclose(expected_navier_x, test_navier_x) + assert paddle.allclose(expected_navier_y, test_navier_y) + assert paddle.allclose(expected_traction_x, test_traction_x) + assert paddle.allclose(expected_traction_y, test_traction_y) + if dim==3: + assert paddle.allclose(expected_stress_disp_zz, test_stress_zz) + assert paddle.allclose(expected_stress_disp_xz, test_stress_xz) + assert paddle.allclose(expected_stress_disp_yz, test_stress_yz) + assert paddle.allclose(expected_equilibrium_z, test_equilibrium_z) + assert paddle.allclose(expected_traction_z, test_traction_z) + assert paddle.allclose(expected_navier_z, test_navier_z) + +if __name__ == "__main__": + pytest.main() + +# test_linear_elasticity_navier_y(1e4, 0.3, None, None, 1, 2, True) From 49ddb065e9f3af11a143cbee685ce717bf89c01d Mon Sep 17 00:00:00 2001 From: ruoyunbai <56343340+ruoyunbai@users.noreply.github.com> Date: Mon, 3 Jul 2023 01:16:12 +0800 Subject: [PATCH 02/11] Update test_linear_elasticity.py --- test/equation/test_linear_elasticity.py | 222 ++++++++++++++---------- 1 file changed, 130 insertions(+), 92 deletions(-) diff --git a/test/equation/test_linear_elasticity.py b/test/equation/test_linear_elasticity.py index 06067e7f8..d26dfefe2 100644 --- a/test/equation/test_linear_elasticity.py +++ b/test/equation/test_linear_elasticity.py @@ -1,32 +1,29 @@ import paddle import pytest from paddle import nn + from ppsci.equation import LinearElasticity -def stress_disp_xx_expected_result(u,v,w,x,y,z,lambda_,mu,dim,sigma_xx): + +def stress_disp_xx_expected_result(u, v, w, x, y, z, lambda_, mu, dim, sigma_xx): stress_disp_xx = ( - lambda_ * (jacobian(u, x) + jacobian(v, y)) - + 2 * mu * jacobian(u, x) - - sigma_xx + lambda_ * (jacobian(u, x) + jacobian(v, y)) + 2 * mu * jacobian(u, x) - sigma_xx ) if dim == 3: stress_disp_xx += lambda_ * jacobian(w, z) return stress_disp_xx -def stress_disp_yy_expected_result(u,v,w,x,y,z,lambda_,mu,dim,sigma_yy): +def stress_disp_yy_expected_result(u, v, w, x, y, z, lambda_, mu, dim, sigma_yy): stress_disp_yy = ( - lambda_ * (jacobian(u, x) + jacobian(v, y)) - + 2 * mu * jacobian(v, y) - - sigma_yy + lambda_ * (jacobian(u, x) + jacobian(v, y)) + 2 * mu * jacobian(v, y) - sigma_yy ) if dim == 3: stress_disp_yy += lambda_ * jacobian(w, z) return stress_disp_yy - -def stress_disp_zz_expected_result(u,v,w,x,y,z,lambda_,mu,sigma_zz): +def stress_disp_zz_expected_result(u, v, w, x, y, z, lambda_, mu, sigma_zz): stress_disp_zz = ( lambda_ * (jacobian(u, x) + jacobian(v, y) + jacobian(w, z)) + 2 * mu * jacobian(w, z) @@ -35,23 +32,24 @@ def stress_disp_zz_expected_result(u,v,w,x,y,z,lambda_,mu,sigma_zz): return stress_disp_zz -def stress_disp_xy_expected_result(u,v,x,y,mu,sigma_xy): +def stress_disp_xy_expected_result(u, v, x, y, mu, sigma_xy): stress_disp_xy = mu * (jacobian(u, y) + jacobian(v, x)) - sigma_xy return stress_disp_xy - -def stress_disp_xz_expected_result(u,w,x,z,mu,sigma_xz): +def stress_disp_xz_expected_result(u, w, x, z, mu, sigma_xz): stress_disp_xz = mu * (jacobian(u, z) + jacobian(w, x)) - sigma_xz return stress_disp_xz -def stress_disp_yz_expected_result(v,w,y,z,mu,sigma_yz): +def stress_disp_yz_expected_result(v, w, y, z, mu, sigma_yz): stress_disp_yz = mu * (jacobian(v, z) + jacobian(w, y)) - sigma_yz return stress_disp_yz -def equilibrium_x_expected_result(u,x,y,z,t,rho,dim,time,sigma_xx,sigma_xy,sigma_xz=None): +def equilibrium_x_expected_result( + u, x, y, z, t, rho, dim, time, sigma_xx, sigma_xy, sigma_xz=None +): equilibrium_x = -jacobian(sigma_xx, x) - jacobian(sigma_xy, y) if dim == 3: equilibrium_x -= jacobian(sigma_xz, z) @@ -60,7 +58,9 @@ def equilibrium_x_expected_result(u,x,y,z,t,rho,dim,time,sigma_xx,sigma_xy,sigma return equilibrium_x -def equilibrium_y_expected_result(v,x,y,z,t,rho,dim,time,sigma_yy,sigma_xy,sigma_yz=None): +def equilibrium_y_expected_result( + v, x, y, z, t, rho, dim, time, sigma_yy, sigma_xy, sigma_yz=None +): equilibrium_y = -jacobian(sigma_xy, x) - jacobian(sigma_yy, y) if dim == 3: equilibrium_y -= jacobian(sigma_yz, z) @@ -68,73 +68,84 @@ def equilibrium_y_expected_result(v,x,y,z,t,rho,dim,time,sigma_yy,sigma_xy,sigma equilibrium_y += rho * hessian(v, t) return equilibrium_y -def equilibrium_z_expected_result(w,x,y,z,t,rho,time,sigma_xz,sigma_yz,sigma_zz): + +def equilibrium_z_expected_result( + w, x, y, z, t, rho, time, sigma_xz, sigma_yz, sigma_zz +): equilibrium_z = ( - -jacobian(sigma_xz, x) - - jacobian(sigma_yz, y) - - jacobian(sigma_zz, z) + -jacobian(sigma_xz, x) - jacobian(sigma_yz, y) - jacobian(sigma_zz, z) ) if time: equilibrium_z += rho * hessian(w, t) return equilibrium_z -def traction_x_expected_result(normal_x, normal_y, sigma_xx, sigma_xy, normal_z=None, sigma_xz=None): + +def traction_x_expected_result( + normal_x, normal_y, sigma_xx, sigma_xy, normal_z=None, sigma_xz=None +): traction_x = normal_x * sigma_xx + normal_y * sigma_xy if normal_z is not None and sigma_xz is not None: traction_x += normal_z * sigma_xz return traction_x -def traction_y_expected_result(normal_x, normal_y, sigma_xy, sigma_yy, normal_z=None, sigma_yz=None): + +def traction_y_expected_result( + normal_x, normal_y, sigma_xy, sigma_yy, normal_z=None, sigma_yz=None +): traction_y = normal_x * sigma_xy + normal_y * sigma_yy if normal_z is not None and sigma_yz is not None: traction_y += normal_z * sigma_yz return traction_y -def traction_z_expected_result(normal_x, normal_y, normal_z, sigma_xz, sigma_yz, sigma_zz): + +def traction_z_expected_result( + normal_x, normal_y, normal_z, sigma_xz, sigma_yz, sigma_zz +): traction_z = normal_x * sigma_xz + normal_y * sigma_yz + normal_z * sigma_zz return traction_z + def jacobian(y: paddle.Tensor, x: paddle.Tensor) -> paddle.Tensor: return paddle.grad(y, x, create_graph=True, allow_unused=True)[0] + def hessian(y: paddle.Tensor, x: paddle.Tensor) -> paddle.Tensor: return jacobian(jacobian(y, x), x) + + def navier_x_expected_result(u, v, w, x, y, z, t, lambda_, mu, rho, dim, time): - duxvywz = jacobian(u, x) + jacobian(v, y) - duxxuyyuzz = hessian(u, x) + hessian(u, y) - if dim == 3: - duxvywz += jacobian(w, z) - duxxuyyuzz += hessian(u, z) - navier_x = ( - -(lambda_ + mu) * jacobian(duxvywz, x) - mu * duxxuyyuzz - ) - if time: - navier_x += rho * hessian(u, t) - return navier_x + duxvywz = jacobian(u, x) + jacobian(v, y) + duxxuyyuzz = hessian(u, x) + hessian(u, y) + if dim == 3: + duxvywz += jacobian(w, z) + duxxuyyuzz += hessian(u, z) + navier_x = -(lambda_ + mu) * jacobian(duxvywz, x) - mu * duxxuyyuzz + if time: + navier_x += rho * hessian(u, t) + return navier_x + + def navier_y_expected_result(u, v, w, x, y, z, t, lambda_, mu, rho, dim, time): duxvywz = jacobian(u, x) + jacobian(v, y) dvxxvyyvzz = hessian(v, x) + hessian(v, y) if dim == 3: duxvywz += jacobian(w, z) dvxxvyyvzz += hessian(v, z) - navier_y = ( - -(lambda_ + mu) * jacobian(duxvywz, y) - mu * dvxxvyyvzz - ) + navier_y = -(lambda_ + mu) * jacobian(duxvywz, y) - mu * dvxxvyyvzz if time: navier_y += rho * hessian(v, t) return navier_y -def navier_z_expected_result(u, v, w, x, y, z, t, lambda_, mu, rho,time): + +def navier_z_expected_result(u, v, w, x, y, z, t, lambda_, mu, rho, time): duxvywz = jacobian(u, x) + jacobian(v, y) + jacobian(w, z) dwxxvyyvzz = hessian(w, x) + hessian(w, y) + hessian(w, z) - navier_z = ( - -(lambda_ + mu) * jacobian(duxvywz, z) - - mu * dwxxvyyvzz - ) + navier_z = -(lambda_ + mu) * jacobian(duxvywz, z) - mu * dwxxvyyvzz if time: navier_z += rho * hessian(w, t) return navier_z + @pytest.mark.parametrize( "E, nu, lambda_, mu, rho, dim, time", [ @@ -153,87 +164,113 @@ def test_linear_elasticity(E, nu, lambda_, mu, rho, dim, time): normal_x = paddle.randn([batch_size, 1]) normal_y = paddle.randn([batch_size, 1]) normal_z = paddle.randn([batch_size, 1]) if dim == 3 else None - x.stop_gradient = False - y.stop_gradient=False + y.stop_gradient = False if dim == 3: - z.stop_gradient=False + z.stop_gradient = False if time: - t.stop_gradient=False - + t.stop_gradient = False lambda_ = (E * nu) / ((1 + nu) * (1 - 2 * nu)) mu = E / (2 * (1 + nu)) - input_data = paddle.concat([x, y], axis=1) if dim == 3: input_data = paddle.concat([input_data, z], axis=1) if time: input_data = paddle.concat([input_data, t], axis=1) - model = nn.Sequential( nn.Linear(input_data.shape[1], 9 if dim == 3 else 5), nn.Tanh(), ) - # generate output through the model output = model(input_data) - # 提取输出中的u, v, w, sigma_xx, sigma_xy, sigma_xz, sigma_yy, sigma_yz, sigma_zz u, v = output[:, 0:1], output[:, 1:2] if dim == 3: w = output[:, 2:3] sigma_xx, sigma_xy, sigma_xz, sigma_yy, sigma_yz, sigma_zz = ( - output[:, 3:4], output[:, 4:5], output[:, 5:6], output[:, 6:7], output[:, 7:8], output[:, 8:9] + output[:, 3:4], + output[:, 4:5], + output[:, 5:6], + output[:, 6:7], + output[:, 7:8], + output[:, 8:9], ) else: w = None - sigma_xx, sigma_xy, sigma_yy = ( - output[:, 2:3], output[:, 3:4], output[:, 4:5] - ) + sigma_xx, sigma_xy, sigma_yy = (output[:, 2:3], output[:, 3:4], output[:, 4:5]) sigma_xz, sigma_yz, sigma_zz = None, None, None - expected_stress_disp_xx = stress_disp_xx_expected_result(u,v,w,x,y,z,lambda_,mu,dim,sigma_xx) - expected_stress_disp_yy = stress_disp_yy_expected_result(u,v,w,x,y,z,lambda_,mu,dim,sigma_yy) - expected_stress_disp_xy = stress_disp_xy_expected_result(u,v,x,y,mu,sigma_xy) - expected_equilibrium_x=equilibrium_x_expected_result(u, x, y, z, t, rho, dim, time,sigma_xx,sigma_xy,sigma_xz) - expected_equilibrium_y=equilibrium_y_expected_result(v, x, y, z, t, rho, dim, time,sigma_yy,sigma_xy,sigma_yz) - expected_traction_x = traction_x_expected_result(normal_x, normal_y, sigma_xx, sigma_xy, normal_z, sigma_xz) - expected_traction_y = traction_y_expected_result(normal_x, normal_y, sigma_xy, sigma_yy, normal_z, sigma_yz) - expected_navier_x = navier_x_expected_result(u, v, w, x, y, z, t, lambda_, mu, rho, dim, time) - expected_navier_y=navier_y_expected_result(u, v, w, x, y, z, t, lambda_, mu, rho, dim, time) + expected_stress_disp_xx = stress_disp_xx_expected_result( + u, v, w, x, y, z, lambda_, mu, dim, sigma_xx + ) + expected_stress_disp_yy = stress_disp_yy_expected_result( + u, v, w, x, y, z, lambda_, mu, dim, sigma_yy + ) + expected_stress_disp_xy = stress_disp_xy_expected_result(u, v, x, y, mu, sigma_xy) + expected_equilibrium_x = equilibrium_x_expected_result( + u, x, y, z, t, rho, dim, time, sigma_xx, sigma_xy, sigma_xz + ) + expected_equilibrium_y = equilibrium_y_expected_result( + v, x, y, z, t, rho, dim, time, sigma_yy, sigma_xy, sigma_yz + ) + expected_traction_x = traction_x_expected_result( + normal_x, normal_y, sigma_xx, sigma_xy, normal_z, sigma_xz + ) + expected_traction_y = traction_y_expected_result( + normal_x, normal_y, sigma_xy, sigma_yy, normal_z, sigma_yz + ) + expected_navier_x = navier_x_expected_result( + u, v, w, x, y, z, t, lambda_, mu, rho, dim, time + ) + expected_navier_y = navier_y_expected_result( + u, v, w, x, y, z, t, lambda_, mu, rho, dim, time + ) if dim == 3: - expected_stress_disp_zz = stress_disp_zz_expected_result(u,v,w,x,y,z,lambda_,mu,sigma_zz) - expected_stress_disp_xz = stress_disp_xz_expected_result(u,w,x,z,mu,sigma_xz) - expected_stress_disp_yz = stress_disp_yz_expected_result(v,w,y,z,mu,sigma_yz) - expected_equilibrium_z=equilibrium_z_expected_result(w, x, y, z, t, rho, time,sigma_xz,sigma_yz,sigma_zz) - expected_navier_z = navier_z_expected_result(u, v, w, x, y, z, t, lambda_, mu, rho,time) - expected_traction_z = traction_z_expected_result(normal_x, normal_y, normal_z, sigma_xz, sigma_yz, sigma_zz) - + expected_stress_disp_zz = stress_disp_zz_expected_result( + u, v, w, x, y, z, lambda_, mu, sigma_zz + ) + expected_stress_disp_xz = stress_disp_xz_expected_result( + u, w, x, z, mu, sigma_xz + ) + expected_stress_disp_yz = stress_disp_yz_expected_result( + v, w, y, z, mu, sigma_yz + ) + expected_equilibrium_z = equilibrium_z_expected_result( + w, x, y, z, t, rho, time, sigma_xz, sigma_yz, sigma_zz + ) + expected_navier_z = navier_z_expected_result( + u, v, w, x, y, z, t, lambda_, mu, rho, time + ) + expected_traction_z = traction_z_expected_result( + normal_x, normal_y, normal_z, sigma_xz, sigma_yz, sigma_zz + ) - linear_elasticity = LinearElasticity(E=E, nu=nu, lambda_=lambda_, mu=mu, rho=rho, dim=dim, time=time) + linear_elasticity = LinearElasticity( + E=E, nu=nu, lambda_=lambda_, mu=mu, rho=rho, dim=dim, time=time + ) data_dict = { - "x": x, - "y": y, - "u": u, - "v": v, - "z": z, - "w": w, - "t": t, - "sigma_xx": sigma_xx, - "sigma_xy": sigma_xy, - "sigma_xz": sigma_xz, - "sigma_yy": sigma_yy, - "sigma_yz": sigma_yz, - "sigma_zz": sigma_zz, - "normal_x": normal_x, - "normal_y": normal_y, - "normal_z": normal_z, + "x": x, + "y": y, + "u": u, + "v": v, + "z": z, + "w": w, + "t": t, + "sigma_xx": sigma_xx, + "sigma_xy": sigma_xy, + "sigma_xz": sigma_xz, + "sigma_yy": sigma_yy, + "sigma_yz": sigma_yz, + "sigma_zz": sigma_zz, + "normal_x": normal_x, + "normal_y": normal_y, + "normal_z": normal_z, } test_stress_disp_xx = linear_elasticity.equations["stress_disp_xx"](data_dict) test_stress_disp_yy = linear_elasticity.equations["stress_disp_yy"](data_dict) @@ -245,9 +282,9 @@ def test_linear_elasticity(E, nu, lambda_, mu, rho, dim, time): test_traction_x = linear_elasticity.equations["traction_x"](data_dict) test_traction_y = linear_elasticity.equations["traction_y"](data_dict) if dim == 3: - test_stress_zz=linear_elasticity.equations["stress_disp_zz"](data_dict) - test_stress_xz=linear_elasticity.equations["stress_disp_xz"](data_dict) - test_stress_yz=linear_elasticity.equations["stress_disp_yz"](data_dict) + test_stress_zz = linear_elasticity.equations["stress_disp_zz"](data_dict) + test_stress_xz = linear_elasticity.equations["stress_disp_xz"](data_dict) + test_stress_yz = linear_elasticity.equations["stress_disp_yz"](data_dict) test_equilibrium_z = linear_elasticity.equations["equilibrium_z"](data_dict) test_navier_z = linear_elasticity.equations["navier_z"](data_dict) test_traction_z = linear_elasticity.equations["traction_z"](data_dict) @@ -261,7 +298,7 @@ def test_linear_elasticity(E, nu, lambda_, mu, rho, dim, time): assert paddle.allclose(expected_navier_y, test_navier_y) assert paddle.allclose(expected_traction_x, test_traction_x) assert paddle.allclose(expected_traction_y, test_traction_y) - if dim==3: + if dim == 3: assert paddle.allclose(expected_stress_disp_zz, test_stress_zz) assert paddle.allclose(expected_stress_disp_xz, test_stress_xz) assert paddle.allclose(expected_stress_disp_yz, test_stress_yz) @@ -269,6 +306,7 @@ def test_linear_elasticity(E, nu, lambda_, mu, rho, dim, time): assert paddle.allclose(expected_traction_z, test_traction_z) assert paddle.allclose(expected_navier_z, test_navier_z) + if __name__ == "__main__": pytest.main() From 0b961494d30be4e6c4a458f16696c6c12205d252 Mon Sep 17 00:00:00 2001 From: ruoyunbai <56343340+ruoyunbai@users.noreply.github.com> Date: Tue, 4 Jul 2023 14:22:12 +0800 Subject: [PATCH 03/11] =?UTF-8?q?fix:=E4=BF=AE=E6=AD=A3=E4=BA=86review?= =?UTF-8?q?=E6=8F=90=E5=87=BA=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/equation/test_linear_elasticity.py | 53 +++++++++++++------------ 1 file changed, 28 insertions(+), 25 deletions(-) diff --git a/test/equation/test_linear_elasticity.py b/test/equation/test_linear_elasticity.py index d26dfefe2..7ed6cddd2 100644 --- a/test/equation/test_linear_elasticity.py +++ b/test/equation/test_linear_elasticity.py @@ -2,7 +2,15 @@ import pytest from paddle import nn -from ppsci.equation import LinearElasticity +from ppsci import equation + + +def jacobian(y: paddle.Tensor, x: paddle.Tensor) -> paddle.Tensor: + return paddle.grad(y, x, create_graph=True)[0] + + +def hessian(y: paddle.Tensor, x: paddle.Tensor) -> paddle.Tensor: + return jacobian(jacobian(y, x), x) def stress_disp_xx_expected_result(u, v, w, x, y, z, lambda_, mu, dim, sigma_xx): @@ -105,14 +113,6 @@ def traction_z_expected_result( return traction_z -def jacobian(y: paddle.Tensor, x: paddle.Tensor) -> paddle.Tensor: - return paddle.grad(y, x, create_graph=True, allow_unused=True)[0] - - -def hessian(y: paddle.Tensor, x: paddle.Tensor) -> paddle.Tensor: - return jacobian(jacobian(y, x), x) - - def navier_x_expected_result(u, v, w, x, y, z, t, lambda_, mu, rho, dim, time): duxvywz = jacobian(u, x) + jacobian(v, y) duxxuyyuzz = hessian(u, x) + hessian(u, y) @@ -153,6 +153,10 @@ def navier_z_expected_result(u, v, w, x, y, z, t, lambda_, mu, rho, time): (1e4, 0.3, None, None, 1, 2, True), (1e4, 0.3, None, None, 1, 3, False), (1e4, 0.3, None, None, 1, 3, True), + (None, None, 1e3, 1e3, 1, 2, False), + (None, None, 1e3, 1e3, 1, 2, True), + (None, None, 1e3, 1e3, 1, 3, False), + (None, None, 1e3, 1e3, 1, 3, True), ], ) def test_linear_elasticity(E, nu, lambda_, mu, rho, dim, time): @@ -172,8 +176,12 @@ def test_linear_elasticity(E, nu, lambda_, mu, rho, dim, time): if time: t.stop_gradient = False - lambda_ = (E * nu) / ((1 + nu) * (1 - 2 * nu)) - mu = E / (2 * (1 + nu)) + if lambda_ == None or mu == None: + lambda_ = (E * nu) / ((1 + nu) * (1 - 2 * nu)) + mu = E / (2 * (1 + nu)) + else: + nu = lambda_ / (2 * mu + 2 * lambda_) + E = 2 * mu * (1 + nu) input_data = paddle.concat([x, y], axis=1) if dim == 3: @@ -190,20 +198,14 @@ def test_linear_elasticity(E, nu, lambda_, mu, rho, dim, time): output = model(input_data) # 提取输出中的u, v, w, sigma_xx, sigma_xy, sigma_xz, sigma_yy, sigma_yz, sigma_zz - u, v = output[:, 0:1], output[:, 1:2] + u, v, *other_outputs = paddle.split(output, num_or_sections=output.shape[1], axis=1) + if dim == 3: - w = output[:, 2:3] - sigma_xx, sigma_xy, sigma_xz, sigma_yy, sigma_yz, sigma_zz = ( - output[:, 3:4], - output[:, 4:5], - output[:, 5:6], - output[:, 6:7], - output[:, 7:8], - output[:, 8:9], - ) + w = other_outputs[0] + sigma_xx, sigma_xy, sigma_xz, sigma_yy, sigma_yz, sigma_zz = other_outputs[1:] else: w = None - sigma_xx, sigma_xy, sigma_yy = (output[:, 2:3], output[:, 3:4], output[:, 4:5]) + sigma_xx, sigma_xy, sigma_yy = other_outputs[0:3] sigma_xz, sigma_yz, sigma_zz = None, None, None expected_stress_disp_xx = stress_disp_xx_expected_result( @@ -251,9 +253,12 @@ def test_linear_elasticity(E, nu, lambda_, mu, rho, dim, time): normal_x, normal_y, normal_z, sigma_xz, sigma_yz, sigma_zz ) - linear_elasticity = LinearElasticity( + linear_elasticity = equation.LinearElasticity( E=E, nu=nu, lambda_=lambda_, mu=mu, rho=rho, dim=dim, time=time ) + # linear_elasticity = equation.LinearElasticity( + # E=E, nu=nu, lambda_=lambda_, mu=mu, rho=rho, dim=dim, time=time + # ) data_dict = { "x": x, "y": y, @@ -309,5 +314,3 @@ def test_linear_elasticity(E, nu, lambda_, mu, rho, dim, time): if __name__ == "__main__": pytest.main() - -# test_linear_elasticity_navier_y(1e4, 0.3, None, None, 1, 2, True) From 236a5f954f57c6514d73783a9ec40e064d89ecd3 Mon Sep 17 00:00:00 2001 From: ruoyunbai <56343340+ruoyunbai@users.noreply.github.com> Date: Tue, 4 Jul 2023 14:27:35 +0800 Subject: [PATCH 04/11] fix:code style --- test/equation/test_linear_elasticity.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/equation/test_linear_elasticity.py b/test/equation/test_linear_elasticity.py index 7ed6cddd2..7c14b730c 100644 --- a/test/equation/test_linear_elasticity.py +++ b/test/equation/test_linear_elasticity.py @@ -176,7 +176,7 @@ def test_linear_elasticity(E, nu, lambda_, mu, rho, dim, time): if time: t.stop_gradient = False - if lambda_ == None or mu == None: + if lambda_ is None or mu is None: lambda_ = (E * nu) / ((1 + nu) * (1 - 2 * nu)) mu = E / (2 * (1 + nu)) else: From 3ef9c5ebd9f69b6e085da75c393e1cae2546ea83 Mon Sep 17 00:00:00 2001 From: ruoyunbai <19376215@buaa.edu.cn> Date: Wed, 5 Jul 2023 03:33:55 +0800 Subject: [PATCH 05/11] =?UTF-8?q?fix:=E5=88=A0=E9=99=A4=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/equation/test_linear_elasticity.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/test/equation/test_linear_elasticity.py b/test/equation/test_linear_elasticity.py index 7c14b730c..ea609e1ad 100644 --- a/test/equation/test_linear_elasticity.py +++ b/test/equation/test_linear_elasticity.py @@ -256,9 +256,7 @@ def test_linear_elasticity(E, nu, lambda_, mu, rho, dim, time): linear_elasticity = equation.LinearElasticity( E=E, nu=nu, lambda_=lambda_, mu=mu, rho=rho, dim=dim, time=time ) - # linear_elasticity = equation.LinearElasticity( - # E=E, nu=nu, lambda_=lambda_, mu=mu, rho=rho, dim=dim, time=time - # ) + data_dict = { "x": x, "y": y, From 0665d6016062db159237962ee8d8d9f5d95d944b Mon Sep 17 00:00:00 2001 From: ruoyunbai <19376215@buaa.edu.cn> Date: Wed, 5 Jul 2023 23:17:01 +0800 Subject: [PATCH 06/11] fix:code style --- test/equation/test_linear_elasticity.py | 113 ++++++++++++++---------- 1 file changed, 68 insertions(+), 45 deletions(-) diff --git a/test/equation/test_linear_elasticity.py b/test/equation/test_linear_elasticity.py index ea609e1ad..ccc422d5d 100644 --- a/test/equation/test_linear_elasticity.py +++ b/test/equation/test_linear_elasticity.py @@ -149,10 +149,6 @@ def navier_z_expected_result(u, v, w, x, y, z, t, lambda_, mu, rho, time): @pytest.mark.parametrize( "E, nu, lambda_, mu, rho, dim, time", [ - (1e4, 0.3, None, None, 1, 2, False), - (1e4, 0.3, None, None, 1, 2, True), - (1e4, 0.3, None, None, 1, 3, False), - (1e4, 0.3, None, None, 1, 3, True), (None, None, 1e3, 1e3, 1, 2, False), (None, None, 1e3, 1e3, 1, 2, True), (None, None, 1e3, 1e3, 1, 3, False), @@ -176,13 +172,6 @@ def test_linear_elasticity(E, nu, lambda_, mu, rho, dim, time): if time: t.stop_gradient = False - if lambda_ is None or mu is None: - lambda_ = (E * nu) / ((1 + nu) * (1 - 2 * nu)) - mu = E / (2 * (1 + nu)) - else: - nu = lambda_ / (2 * mu + 2 * lambda_) - E = 2 * mu * (1 + nu) - input_data = paddle.concat([x, y], axis=1) if dim == 3: input_data = paddle.concat([input_data, z], axis=1) @@ -194,10 +183,8 @@ def test_linear_elasticity(E, nu, lambda_, mu, rho, dim, time): nn.Tanh(), ) - # generate output through the model output = model(input_data) - # 提取输出中的u, v, w, sigma_xx, sigma_xy, sigma_xz, sigma_yy, sigma_yz, sigma_zz u, v, *other_outputs = paddle.split(output, num_or_sections=output.shape[1], axis=1) if dim == 3: @@ -254,7 +241,7 @@ def test_linear_elasticity(E, nu, lambda_, mu, rho, dim, time): ) linear_elasticity = equation.LinearElasticity( - E=E, nu=nu, lambda_=lambda_, mu=mu, rho=rho, dim=dim, time=time + E=None, nu=None, lambda_=lambda_, mu=mu, rho=rho, dim=dim, time=time ) data_dict = { @@ -275,39 +262,75 @@ def test_linear_elasticity(E, nu, lambda_, mu, rho, dim, time): "normal_y": normal_y, "normal_z": normal_z, } - test_stress_disp_xx = linear_elasticity.equations["stress_disp_xx"](data_dict) - test_stress_disp_yy = linear_elasticity.equations["stress_disp_yy"](data_dict) - test_stress_disp_xy = linear_elasticity.equations["stress_disp_xy"](data_dict) - test_equilibrium_x = linear_elasticity.equations["equilibrium_x"](data_dict) - test_equilibrium_y = linear_elasticity.equations["equilibrium_y"](data_dict) - test_navier_x = linear_elasticity.equations["navier_x"](data_dict) - test_navier_y = linear_elasticity.equations["navier_y"](data_dict) - test_traction_x = linear_elasticity.equations["traction_x"](data_dict) - test_traction_y = linear_elasticity.equations["traction_y"](data_dict) + + test_output_names = [ + "stress_disp_xx", + "stress_disp_yy", + "stress_disp_xy", + "equilibrium_x", + "equilibrium_y", + "navier_x", + "navier_y", + "traction_x", + "traction_y", + ] + test_output = {} + for name in test_output_names: + test_output[name] = linear_elasticity.equations[name](data_dict) + test_output_names = [ + "stress_disp_xx", + "stress_disp_yy", + "stress_disp_xy", + "equilibrium_x", + "equilibrium_y", + "navier_x", + "navier_y", + "traction_x", + "traction_y", + ] + if dim == 3: - test_stress_zz = linear_elasticity.equations["stress_disp_zz"](data_dict) - test_stress_xz = linear_elasticity.equations["stress_disp_xz"](data_dict) - test_stress_yz = linear_elasticity.equations["stress_disp_yz"](data_dict) - test_equilibrium_z = linear_elasticity.equations["equilibrium_z"](data_dict) - test_navier_z = linear_elasticity.equations["navier_z"](data_dict) - test_traction_z = linear_elasticity.equations["traction_z"](data_dict) - - assert paddle.allclose(expected_stress_disp_xx, test_stress_disp_xx) - assert paddle.allclose(expected_stress_disp_yy, test_stress_disp_yy) - assert paddle.allclose(expected_stress_disp_xy, test_stress_disp_xy) - assert paddle.allclose(expected_equilibrium_x, test_equilibrium_x) - assert paddle.allclose(expected_equilibrium_y, test_equilibrium_y) - assert paddle.allclose(expected_navier_x, test_navier_x) - assert paddle.allclose(expected_navier_y, test_navier_y) - assert paddle.allclose(expected_traction_x, test_traction_x) - assert paddle.allclose(expected_traction_y, test_traction_y) + test_output_names.extend( + [ + "stress_disp_zz", + "stress_disp_xz", + "stress_disp_yz", + "equilibrium_z", + "navier_z", + "traction_z", + ] + ) + + test_output = {} + for name in test_output_names: + test_output[name] = linear_elasticity.equations[name](data_dict) + + expected_output = { + "stress_disp_xx": expected_stress_disp_xx, + "stress_disp_yy": expected_stress_disp_yy, + "stress_disp_xy": expected_stress_disp_xy, + "equilibrium_x": expected_equilibrium_x, + "equilibrium_y": expected_equilibrium_y, + "navier_x": expected_navier_x, + "navier_y": expected_navier_y, + "traction_x": expected_traction_x, + "traction_y": expected_traction_y, + } + if dim == 3: - assert paddle.allclose(expected_stress_disp_zz, test_stress_zz) - assert paddle.allclose(expected_stress_disp_xz, test_stress_xz) - assert paddle.allclose(expected_stress_disp_yz, test_stress_yz) - assert paddle.allclose(expected_equilibrium_z, test_equilibrium_z) - assert paddle.allclose(expected_traction_z, test_traction_z) - assert paddle.allclose(expected_navier_z, test_navier_z) + expected_output.update( + { + "stress_disp_zz": expected_stress_disp_zz, + "stress_disp_xz": expected_stress_disp_xz, + "stress_disp_yz": expected_stress_disp_yz, + "equilibrium_z": expected_equilibrium_z, + "navier_z": expected_navier_z, + "traction_z": expected_traction_z, + } + ) + + for name in test_output_names: + assert paddle.allclose(expected_output[name], test_output[name]) if __name__ == "__main__": From 83d63e748ce3d4383d07d55123bc99603af68c54 Mon Sep 17 00:00:00 2001 From: ruoyunbai <19376215@buaa.edu.cn> Date: Thu, 6 Jul 2023 13:47:44 +0800 Subject: [PATCH 07/11] =?UTF-8?q?fix:=E9=87=8D=E5=A4=8D=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/equation/test_linear_elasticity.py | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/test/equation/test_linear_elasticity.py b/test/equation/test_linear_elasticity.py index ccc422d5d..b1c019afd 100644 --- a/test/equation/test_linear_elasticity.py +++ b/test/equation/test_linear_elasticity.py @@ -241,7 +241,7 @@ def test_linear_elasticity(E, nu, lambda_, mu, rho, dim, time): ) linear_elasticity = equation.LinearElasticity( - E=None, nu=None, lambda_=lambda_, mu=mu, rho=rho, dim=dim, time=time + E=E, nu=nu, lambda_=lambda_, mu=mu, rho=rho, dim=dim, time=time ) data_dict = { @@ -274,20 +274,6 @@ def test_linear_elasticity(E, nu, lambda_, mu, rho, dim, time): "traction_x", "traction_y", ] - test_output = {} - for name in test_output_names: - test_output[name] = linear_elasticity.equations[name](data_dict) - test_output_names = [ - "stress_disp_xx", - "stress_disp_yy", - "stress_disp_xy", - "equilibrium_x", - "equilibrium_y", - "navier_x", - "navier_y", - "traction_x", - "traction_y", - ] if dim == 3: test_output_names.extend( From 37defc83d994e00c00c06dee7915af26b496ff53 Mon Sep 17 00:00:00 2001 From: ruoyunbai <56343340+ruoyunbai@users.noreply.github.com> Date: Thu, 6 Jul 2023 20:55:36 +0800 Subject: [PATCH 08/11] Update test_linear_elasticity.py --- test/equation/test_linear_elasticity.py | 1 - 1 file changed, 1 deletion(-) diff --git a/test/equation/test_linear_elasticity.py b/test/equation/test_linear_elasticity.py index b1c019afd..e35323044 100644 --- a/test/equation/test_linear_elasticity.py +++ b/test/equation/test_linear_elasticity.py @@ -302,7 +302,6 @@ def test_linear_elasticity(E, nu, lambda_, mu, rho, dim, time): "traction_x": expected_traction_x, "traction_y": expected_traction_y, } - if dim == 3: expected_output.update( { From 2104ccde43597edf77e67648a25b8e070948077c Mon Sep 17 00:00:00 2001 From: ruoyunbai <19376215@buaa.edu.cn> Date: Fri, 7 Jul 2023 14:41:35 +0800 Subject: [PATCH 09/11] =?UTF-8?q?time=E6=8E=92=E5=9C=A8dim=E4=B9=8B?= =?UTF-8?q?=E5=89=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/equation/test_linear_elasticity.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/equation/test_linear_elasticity.py b/test/equation/test_linear_elasticity.py index b1c019afd..01f612eb6 100644 --- a/test/equation/test_linear_elasticity.py +++ b/test/equation/test_linear_elasticity.py @@ -167,16 +167,16 @@ def test_linear_elasticity(E, nu, lambda_, mu, rho, dim, time): x.stop_gradient = False y.stop_gradient = False - if dim == 3: - z.stop_gradient = False if time: t.stop_gradient = False + if dim == 3: + z.stop_gradient = False input_data = paddle.concat([x, y], axis=1) - if dim == 3: - input_data = paddle.concat([input_data, z], axis=1) if time: input_data = paddle.concat([input_data, t], axis=1) + if dim == 3: + input_data = paddle.concat([input_data, z], axis=1) model = nn.Sequential( nn.Linear(input_data.shape[1], 9 if dim == 3 else 5), From 01235705026e022db869c82bcddb3a4ce1ef3bb3 Mon Sep 17 00:00:00 2001 From: gongwenxin <19376215@buaa.edu.cn> Date: Sun, 9 Jul 2023 15:38:24 +0800 Subject: [PATCH 10/11] fix:t front --- test/equation/test_linear_elasticity.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/equation/test_linear_elasticity.py b/test/equation/test_linear_elasticity.py index 78dadf71a..8909ef2a3 100644 --- a/test/equation/test_linear_elasticity.py +++ b/test/equation/test_linear_elasticity.py @@ -174,7 +174,7 @@ def test_linear_elasticity(E, nu, lambda_, mu, rho, dim, time): input_data = paddle.concat([x, y], axis=1) if time: - input_data = paddle.concat([input_data, t], axis=1) + input_data = paddle.concat([ t,input_data], axis=1) if dim == 3: input_data = paddle.concat([input_data, z], axis=1) From 519216c6c0bf8d3e251f277cad03998e194875bb Mon Sep 17 00:00:00 2001 From: gongwenxin <19376215@buaa.edu.cn> Date: Sun, 9 Jul 2023 15:53:50 +0800 Subject: [PATCH 11/11] style --- test/equation/test_linear_elasticity.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/equation/test_linear_elasticity.py b/test/equation/test_linear_elasticity.py index 8909ef2a3..ee4bfa922 100644 --- a/test/equation/test_linear_elasticity.py +++ b/test/equation/test_linear_elasticity.py @@ -174,7 +174,7 @@ def test_linear_elasticity(E, nu, lambda_, mu, rho, dim, time): input_data = paddle.concat([x, y], axis=1) if time: - input_data = paddle.concat([ t,input_data], axis=1) + input_data = paddle.concat([t, input_data], axis=1) if dim == 3: input_data = paddle.concat([input_data, z], axis=1)