Hello everyone.
I am trying to solve a time-dependent 1D problem. The weak form with time discretization is these equations(shown below). I want to get a time-dependent result.
The code is below, I try to plot some values from the array that I use to store the function, such as theta_list[20]. However, they are all just plain lines that satisfied the initial condition and the boundary condition. I think it should change depend on time. Is there anything wrong with the equation or my code? Any advice will be appreciated!
from dolfin import *
import matplotlib.pyplot as plt
import matplotlib.animation as animation
# Define 1D mesh and space
mesh = IntervalMesh(10, 0, 1)
Element1 = FiniteElement("CG", mesh.ufl_cell(), 5)
Element2 = FiniteElement("CG", mesh.ufl_cell(), 5)
W_elem = MixedElement([Element1, Element2])
ME = FunctionSpace(mesh, W_elem)
V = FunctionSpace(mesh, Element1)
# Define functions
u_old = Function(ME)
u_new = Function(ME)
theta_old, vy_old = split(u_old)
theta_new, vy_new = split(u_new)
vy_mid = 0.5*vy_old + 0.5*vy_new
theta_mid = 0.5*theta_old + 0.5*theta_new
tf = TestFunction(ME)
q, v = split(tf)
f1 = 2 * cos(2 * theta_mid)
f2 = 2 * cos(2 * theta_new)
dt = 1.0
# Boundary condition
def boundary(x, on_boundary):
return on_boundary
bc = DirichletBC(ME, [Constant(1.57), Constant(0)], boundary)
#Initial Condition
class InitialConditions(UserExpression):
def eval(self, values, x):
values[0] = 1.57
values[1] = 0
def value_shape(self):
return (2,)
u_init = InitialConditions()
u_new.interpolate(u_init)
u_old.interpolate(u_init)
# Weak statement of the equations
F0 = (theta_new-theta_old)/dt*q*dx + theta_mid.dx(0)*q.dx(0)*dx - 0.5*(f1+1)*vy_mid.dx(0)*q*dx
F1 = (-vy_new.dx(0) * v.dx(0)) * dx + f2 * theta_new.dx(0) * v * dx
F = F0 + F1
t = 0.0
T = 50*dt
theta_list = []
vy_list = []
while t < T:
t += dt
u_old.vector()[:] = u_new.vector()
solve(F == 0, u_new, bc)
theta_list.append(u_new.split()[0])
vy_list.append(u_new.split()[1])
plot(vy_list[20])
plt.show()