Advection equation on super ellipse domain #729
kasahundirirsa
started this conversation in
General
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.
-
Hello GitHub Community this code can't work for the domain of super ellipse
import deepxde as dde
import matplotlib.pyplot as plt
import numpy as np
#from numpy import flot
def advection_eq_exact_solution(x, t):
"""Returns the exact solution for a given x and t (for sinusoidal initial conditions).
def gen_exact_solution():
"""Generates exact solution for the advection equation for the given values of x and t."""
# Number of points in each dimension:
x_dim, t_dim = (256, 201)
def gen_testdata():
"""Import and preprocess the dataset with the exact solution."""
# Load the data:
data = np.load("advection_eq_data.npz")
# Obtain the values for t, x, and the excat solution:
t, x, exact = data["t"], data["x"], data["usol"].T
# Process the data and flatten it out (like labels and features):
xx, tt = np.meshgrid(x, t)
X = np.vstack((np.ravel(xx), np.ravel(tt))).T
y = exact.flatten()[:, None]
return X, y
Problem parameters:
a = 0.4 # Thermal diffusivity
b = 1
c = 1
L = 1 # Length of the bar
n = 1 / 2 # Frequency of the sinusoidal initial conditions
Generate a dataset with the exact solution (if you dont have one):
gen_exact_solution()
def pde(x, y):
"""Expresses the PDE residual of the advection equation."""
dy_tt = dde.grad.jacobian(y, x, i=0, j=1)
dy_xx = dde.grad.hessian(y, x, i=0, j=0)
return dy_tt + a * dy_xx
Computational geometry:
geom = dde.geometry.Interval(0, L)
timedomain = dde.geometry.TimeDomain(0, 2 * np.pi)
geomtime = dde.geometry.GeometryXTime(geom, timedomain)
Initial and boundary conditions:
bc = dde.icbc.DirichletBC(geomtime, lambda x: (abs(b) * ((np.cos(x)) ** 2 / n)), lambda t: (abs(c) * ((np.sin(t)) ** 2 / n)))
ic = dde.icbc.IC(
geomtime,
lambda x: np.sin(n * np.pi * x[:, 0:1] / L),
lambda _, on_initial: on_initial,
)
Define the PDE problem and configurations of the network:
data = dde.data.TimePDE(
geomtime,
pde,
[bc, ic],
num_domain=2540,
num_boundary=80,
num_initial=160,
num_test=2540,
)
net = dde.nn.FNN([2] + [20] * 3 + [1], "tanh", "Glorot normal")
model = dde.Model(data, net)
Build and train the model:
model.compile("adam", lr=1e-3)
model.train(epochs=200)
model.compile("L-BFGS")
losshistory, train_state = model.train()
Plot/print the results
dde.saveplot(losshistory, train_state, issave=True, isplot=True)
X, y_true = gen_testdata()
y_pred = model.predict(X)
f = model.predict(X, operator=pde)
print("Mean residual:", np.mean(np.absolute(f)))
print("L2 relative error:", dde.metrics.l2_relative_error(y_true, y_pred))
np.savetxt("test.dat", np.hstack((X, y_true, y_pred)))
Beta Was this translation helpful? Give feedback.
All reactions