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
Hello everyone,
I'm new in using deepxde and I'm trying to solve Mass transfer and darcy equations :
and I'm solving these equations as an inverse problem.
however, the error is high
my code is available below. any help would be appraciated.
`import deepxde as dde
import numpy as np
import matplotlib.pyplot as plt
from numpy import ma
from matplotlib import ticker, cm
from scipy.io import loadmat
import re
u = dde.Variable(0.0) #x-dirextion velocity
v = dde.Variable(0.0) #y-direction velocity
kappa = 1e-9 #diffusivity
perm = 1e-13 #permeability`
Load training data
def load_training_data(num):
data = loadmat("your_results_file.mat")
C_star = data["concentration"] # 1681 N x 201 T
P_star = data["pressure"] # 1681 N x 201 T
t_star = data["t"] # 201 T x 1
t_star = np.transpose(t_star)
X_star = data["x_star"] # 2 x 1681 N
X_star = np.transpose(X_star)
N = X_star.shape[0]
T = t_star.shape[0]
# Rearrange Data
XX = np.tile(X_star[:, 0:1], (1, T)) # N x T
YY = np.tile(X_star[:, 1:2], (1, T)) # N x T
TT = np.tile(t_star, (1, N)).T # N x T
CC = C_star # N x T
PP = P_star # N x T
x = XX.flatten()[:, None] # NT x 1
y = YY.flatten()[:, None] # NT x 1
t = TT.flatten()[:, None] # NT x 1
c = CC.flatten()[:, None] # NT x 1
p = PP.flatten()[:, None] # NT x 1
data_domain = np.column_stack((x, y, t, c, p))
idx = np.random.choice(data_domain.shape[0], num, replace=False)
x_train = data_domain[idx, 0:1]
y_train = data_domain[idx, 1:2]
t_train = data_domain[idx, 2:3]
c_train = data_domain[idx, 3:4]
p_train = data_domain[idx, 4:5]
return [x_train, y_train, t_train, c_train, p_train]
def pde(x, y):
# Extract variables
c = y[:, 0:1]
p = y[:, 1:2]
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.
-
Hello everyone,



I'm new in using deepxde and I'm trying to solve Mass transfer and darcy equations :
and I'm solving these equations as an inverse problem.
however, the error is high
my code is available below. any help would be appraciated.
`import deepxde as dde
import numpy as np
import matplotlib.pyplot as plt
from numpy import ma
from matplotlib import ticker, cm
from scipy.io import loadmat
import re
u = dde.Variable(0.0) #x-dirextion velocity
v = dde.Variable(0.0) #y-direction velocity
kappa = 1e-9 #diffusivity
perm = 1e-13 #permeability`
Load training data
def load_training_data(num):
data = loadmat("your_results_file.mat")
C_star = data["concentration"] # 1681 N x 201 T
P_star = data["pressure"] # 1681 N x 201 T
t_star = data["t"] # 201 T x 1
t_star = np.transpose(t_star)
X_star = data["x_star"] # 2 x 1681 N
X_star = np.transpose(X_star)
N = X_star.shape[0]
T = t_star.shape[0]
# Rearrange Data
XX = np.tile(X_star[:, 0:1], (1, T)) # N x T
YY = np.tile(X_star[:, 1:2], (1, T)) # N x T
TT = np.tile(t_star, (1, N)).T # N x T
CC = C_star # N x T
PP = P_star # N x T
x = XX.flatten()[:, None] # NT x 1
y = YY.flatten()[:, None] # NT x 1
t = TT.flatten()[:, None] # NT x 1
c = CC.flatten()[:, None] # NT x 1
p = PP.flatten()[:, None] # NT x 1
data_domain = np.column_stack((x, y, t, c, p))
idx = np.random.choice(data_domain.shape[0], num, replace=False)
x_train = data_domain[idx, 0:1]
y_train = data_domain[idx, 1:2]
t_train = data_domain[idx, 2:3]
c_train = data_domain[idx, 3:4]
p_train = data_domain[idx, 4:5]
return [x_train, y_train, t_train, c_train, p_train]
def pde(x, y):
# Extract variables
c = y[:, 0:1]
p = y[:, 1:2]
Spatial domain:
space_domain = dde.geometry.Rectangle([0,0],[10,10])
Time domain
time_domain = dde.geometry.TimeDomain(0, 200)
Spatio-temporal domain
geomtime = dde.geometry.GeometryXTime(space_domain, time_domain)
Get the training data: num
[ob_x, ob_y, ob_t, ob_c, ob_p] = load_training_data(num=1681)
ob_xyt = np.hstack((ob_x, ob_y, ob_t))
observe_c = dde.icbc.PointSetBC(ob_xyt, ob_c, component=0)
observe_p = dde.icbc.PointSetBC(ob_xyt, ob_p, component=1)
Training datasets and Loss
data = dde.data.TimePDE(
geomtime,
pde,
[observe_c, observe_p],
num_domain=10000,
num_boundary=0,
num_initial=2000,
anchors=ob_xyt,
)
Neural Network setup
layer_size = [3] + [50] * 6 + [2]
activation = "tanh"
initializer = "Glorot uniform"
net = dde.nn.FNN(layer_size, activation, initializer)
model = dde.Model(data, net)
callbacks for storing results
fnamevar = "variables.dat"
variable = dde.callbacks.VariableValue([u, v], period=100, filename=fnamevar)
Compile, train and save model
model.compile("adam", lr=1e-3, external_trainable_variables=[u, v])
loss_history, train_state = model.train(
iterations=5000, callbacks=[variable], display_every=1000, disregard_previous_best=True
)
dde.saveplot(loss_history, train_state, issave=True, isplot=True)
model.compile("adam", lr=1e-4, external_trainable_variables=[u, v])
loss_history, train_state = model.train(
iterations=30000, callbacks=[variable], display_every=1000, disregard_previous_best=True
)
dde.saveplot(loss_history, train_state, issave=True, isplot=True)
Plot Variables:
reopen saved data using callbacks in fnamevar
lines = open(fnamevar, "r").readlines()
read output data in fnamevar
Chat = np.array(
[
np.fromstring(
min(re.findall(re.escape("[") + "(.*?)" + re.escape("]"), line), key=len),
sep=",",
)
for line in lines
]
)
l, c = Chat.shape
plt.semilogy(range(0, l * 100, 100), Chat[:, 0], "r-")
plt.semilogy(range(0, l * 100, 100), Chat[:, 1], "k-")
plt.semilogy(range(0, l * 100, 100), np.ones(Chat[:, 0].shape) * u_true, "r--")
plt.semilogy(range(0, l * 100, 100), np.ones(Chat[:, 1].shape) * v_true, "k--")
plt.legend(["C1hat", "C2hat", "True C1", "True C2"], loc="right")
plt.xlabel("Epochs")
plt.title("Variables")
plt.show()
for t in range(0, 50):
X = space_domain.random_points(500000)
xyt_pred = np.hstack((X, t * np.ones((500000, 1))))
pred = model.predict(xyt_pred)
x_pred, y_pred, t_pred = xyt_pred[:, 0], xyt_pred[:, 1], xyt_pred[:, 2]
c_pred, p_pred = pred[:, 0], pred[:, 1]
Beta Was this translation helpful? Give feedback.
All reactions