HI ,
I am solving heat equation u_t - u_xx -u_yy = 0 , with u(x,y, 0) = \delta(x)\delta(y), u = 0 on boundary
I tried this code and when I plot the solution I am getting flat surface but i think there should be peak in the solution.
from dolfin import *
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
nx = 64
# Define the mesh and function space
mesh = RectangleMesh(Point(-10, -20), Point(20, 30), nx, nx)
V = FunctionSpace(mesh, 'P', 1)
# Define the initial condition u(x,y,0) = Ξ΄(x)Ξ΄(y)
class Delta(UserExpression):
def __init__(self, **kwargs):
super().__init__(**kwargs)
def eval(self, values, x):
values[0] = 1.0 if abs(x[0]) < 1e-12 and abs(x[1]) < 1e-12 else 0.0
u0 = interpolate(Expression('0.0', degree=1), V)
# Define the boundary condition
def boundary(x, on_boundary):
return on_boundary
bc = DirichletBC(V, Constant(0.0), boundary)
# Define the variational problem
u = TrialFunction(V)
v = TestFunction(V)
f = Constant(0.0)
t = 0.0
T = 1.0
dt = 0.01
a = u*v*dx + dt*inner(grad(u), grad(v))*dx
L = u0*v*dx
# Time-stepping loop
while t < T:
t += dt
u = Function(V)
solve(a == L, u, bc)
u0.assign(u)
#plot comupted solution
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
# Define a 3D plot
fig = plt.figure()
ax = fig.gca(projection='3d')
# Extract the coordinates and values of the FEM solution
X = mesh.coordinates()[:, 0]
Y = mesh.coordinates()[:, 1]
Z = u.vector()[:]
# Plot the solution as a surface
ax.plot_trisurf(X, Y, Z, cmap=plt.cm.jet)
# Set the axis labels and title
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_zlabel('u')
# Show the plot
plt.show()