Hello everyone
I want to plot the u^2 vs dt. Can you help me in resolving this issue?
from fenics import *
import numpy as np
import matplotlib.pyplot as plt
import numpy as np
set_log_level(LogLevel.ERROR)
T = 1
nx= 4
nmax = 5
Dt = []
Tm = []
for j in range(nmax):
num_steps = 2**(j+1)
dt = T/num_steps
Dt.append(dt)
alpha = 3 # parameter alpha
beta = 1.2
mesh = UnitSquareMesh(nx, nx)
V = FunctionSpace(mesh, 'P', 1)
u_D = Expression('1 + x[0]*x[0] + alpha*x[1]*x[1] + beta*t', degree=2, alpha=alpha, beta=beta, t=0)
def boundary(x, on_boundary):
return on_boundary
bc = DirichletBC(V, u_D, boundary)
u_n = interpolate(u_D, V)
u = TrialFunction(V)
v = TestFunction(V)
f = Constant(beta - 2 - 2*alpha)
F = u*v*dx + dt*dot(grad(u), grad(v))*dx - (u_n + dt*f)*v*dx
a, L = lhs(F), rhs(F)
u = Function(V)
t = 0
for n in range(num_steps):
t += dt
u_D.t = t
solve(a == L, u, bc)
u_n.assign(u)
T_m = dot(u,u)
Tm.append(T_m)
plt.plot(Dt, Tm, 'o', label='Dt vs Tm', linestyle='solid')
plt.title('Curve between Dt vs Tm and Tc') # Title of the plot
plt.xlabel('Dt') # Label for the x-axis
plt.ylabel('Tm and Tc') # Label for the y-axis
plt.grid(True) # Enable grid
plt.legend() # Show legend with label 'X vs Y'
plt.show() # Display the plot