Improving Accuracy of DeepXDE code #1779
Unanswered
SudharsunG
asked this question in
Q&A
Replies: 0 comments
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.
-
I have written a DeepXDE code that solves a fluid flow problem over a bump. This is my code. Even after many attempts, my code is predicting the velocity incorrectly. How can I improve its accuracy?
import deepxde as dde
import numpy as np
import pandas as pd
import tensorflow
from tensorflow.keras.layers import Dense
Load the data
file_path = "h20_domain.xlsx"
data = pd.read_excel(file_path)
Extract the first two columns as a NumPy array
x_points = data.iloc[:, 0].values
y_points = data.iloc[:, 1].values
points = np.column_stack((x_points, y_points))
domain = dde.geometry.pointcloud.PointCloud(points)
rho = 0.001
nu = 0.00002529
h =20
ur = 19.32679415
pr = 23.89611483
uur = 7.719305992
uvr = 0.575172886
vvr = 1.540227771
def pde(x, u):
u_vel, v_vel, p, uu, uv, vv = u[:, 0:1], u[:, 1:2], u[:, 2:3], u[:, 3:4], u[:, 4:5], u[:, 5:]
u_vel_x = dde.grad.jacobian(u, x, i=0, j=0)
u_vel_y = dde.grad.jacobian(u, x, i=0, j=1)
u_vel_xx = dde.grad.hessian(u, x, component=0, i=0, j=0)
u_vel_yy = dde.grad.hessian(u, x, component=0, i=1, j=1)
import pandas as pd
import numpy as np
import deepxde as dde
Load the Excel file with boundary points and output values
df = pd.read_excel('boundary_condition.xlsx')
Extract boundary points (x, y) and output values for each component
x_bc = df.iloc[:, 0].values
y_bc = df.iloc[:, 1].values
points_bc = np.column_stack((x_bc, y_bc))
values_component_0 = df.iloc[:, 2].values
values_component_1 = df.iloc[:, 3].values
values_component_2 = df.iloc[:, 4].values
values_component_3 = df.iloc[:, 5].values
values_component_4 = df.iloc[:, 6].values
values_component_5 = df.iloc[:, 7].values
Define the boundary conditions using PointSetBC for each component
boundary_condition_u = dde.icbc.PointSetBC(
points=points_bc, values=values_component_0, component=0
)
boundary_condition_v = dde.icbc.PointSetBC(
points=points_bc, values=values_component_1, component=1
)
boundary_condition_p = dde.icbc.PointSetBC(
points=points_bc, values=values_component_2, component=2
)
boundary_condition_uu = dde.icbc.PointSetBC(
points=points_bc, values=values_component_3, component=3
)
boundary_condition_uv = dde.icbc.PointSetBC(
points=points_bc, values=values_component_4, component=4
)
boundary_condition_vv = dde.icbc.PointSetBC(
points=points_bc, values=values_component_5, component=5
)
bc = [boundary_condition_u, boundary_condition_v, boundary_condition_p, boundary_condition_uu, boundary_condition_uv, boundary_condition_vv]
data = dde.data.PDE(
domain,
pde,
bc,
num_domain=93651,
num_test=50000,
)
net = dde.nn.FNN([2] + 8 * [20] + [6], "tanh", "Glorot normal")
model = dde.Model(data, net)
model.compile("adam", lr=1e-3)
model.train(iterations=50000)
model.compile("L-BFGS")
losshistory, train_state = model.train()
output = model.predict(points)
u_pred = output[:, 0]
df_actual = pd.read_excel('h20_actual.xlsx')
x_bc = df_actual.iloc[:, 0].values
y_bc = df_actual.iloc[:, 1].values
u_exact = df_actual.iloc[:, 2].values
l2_difference_u = dde.metrics.l2_relative_error(u_exact, u_pred)
print("l2_difference_u:", l2_difference_u)
Beta Was this translation helpful? Give feedback.
All reactions