Hey everyone. I also did a very simple heat equation problem. However, When I plot all the solutions stored in the array. they are all the same and don’t vary. such as the plot of u_list[20] is same as u_list[40]. Any suggestions and advice will be appreciated!
from dolfin import *
import matplotlib.pyplot as plt
# Define 1D mesh and space
mesh = IntervalMesh(1000, 0, 1)
Element1 = FiniteElement("CG", mesh.ufl_cell(), 5)
E = FunctionSpace(mesh, Element1)
# Define functions
u_old = Function(E)
u_new = Function(E)
u_mid = 0.5*u_old + 0.5*u_new
q = TestFunction(E)
dt = 0.01
# Boundary condition
def boundary(x, on_boundary):
return on_boundary
bc = DirichletBC(E, Constant(0), boundary)
#Initial Condition
u_init = Expression('x[0]*x[0]', degree=1)
u_old.interpolate(u_init)
# Weak statement of the equations
F = (u_new - u_old)/dt*q*dx+u_mid.dx(0)*q.dx(0)*dx
t = 0.0
T = 50*dt
u_list = []
while t < T:
t += dt
solve(F == 0, u_new, bc)
u_old.vector()[:] = u_new.vector()
u_list.append(u_new)
plot(u_list[49])
plt.show()
Thank you very much for your reply. So it is mean that I only need to change u_new to another name such as u_2. Would you explain a bit more about copying? Like how can I copy it or what function I need to use. Sorry if the question is stupid I am pretty new to Fenics.