Hi everyone,
I’m pretty new to fenics. I’ve been using fenics for 1d heat diffusion from one material into another. However, I also want the entire mesh to shrink in size with time, but I have no idea how to approach this problem. I’m not getting any errors because I don’t even know where to start with this, but here is some example code of my static heat diffusion:
from fenics import *
import numpy as np
tf = 20*10**-9 # final time
num_steps = 60 # number of time steps (60)
dt = tf / num_steps # time step size
tol = DOLFIN_EPS
degree = 1
# Define Thermodynamic Parameters
init_temp = 500
peak_temp = 20000
k_0 = 100
k_1 = 50
rho = 8000
c = 320
l = 2*10**-6 # Length of iron (m)
lw = 4*10**-6 # Length of window (m)
tot_l = l + lw
meshpoints = 300
my_mesh = IntervalMesh ( meshpoints,0,tot_l )
V = FunctionSpace(my_mesh, 'P', degree)
# Define boundary condition
u_D = Expression(str(peak_temp),degree=degree)
def boundary ( x ):
value = x[0] < tol
return value
bc = DirichletBC(V, u_D, boundary)
# Define initial value
u_0 = Expression(str(init_temp), degree=degree)
u_n = interpolate(u_0, V)
#u_n = project(u_D, V)
# Define variational problem
u = Function(V)
v = TestFunction(V)
tc = 'x[0] >= l+tol ? k_1 : k_0'
kappa = Expression(tc, degree=degree,
tol=tol, k_1=k_1, k_0=k_0, l=l)
# Solve
F = u*v*dx + kappa/(rho*c)*dt*dot(grad(u), grad(v))*dx - (u_n)*v*dx
# Time-stepping and plotting
inc = 0.01*10**-6
loc = l - inc
points = np.linspace(0,tot_l,meshpoints)
times = np.linspace(0,tf, num_steps)
time_line = []
num_loops = 1
t=0
for loop in range(num_loops):
t=0
u_n = interpolate(u_0, V)
F = u*v*dx + kappa/(rho*c)*dt*dot(grad(u), grad(v))*dx - (u_n)*v*dx
time_line = []
for n in range(num_steps):
# Update current time
t += dt
u_D.t = t
kappa.t = t
print(t)
# Compute solution
solve(F==0, u, bc)
# Plot solution
#u_line = [u(point) for point in points]
time_line.append(u(loc))
# Update previous solution
u_n.assign(u)