Hello, I am trying to find forward solution of unsteady heat equation with time dependent boundary conditions for four edges of a square domain. I am getting error in solve function . Do you have any idea, please?
from fenics import *
from fenics_adjoint import *
from collections import OrderedDictmesh = RectangleMesh(Point(1,1), Point(2,2),5,5)
plot(mesh)T=1
dt = Constant(0.1)
t = float(dt)u_0 = Expression(’ x[0] * x[0] + x[1] * x[1] + sin(10t) ‘, t=0, degree=2)
f = Expression(’-6(x[0] + x[1]) + 10 * cos(10 * t)‘, t=0, degree=2)
kappa = Expression(’ x[0] + x[1]', degree=1)def boundary_L(x, on_boundary):
tol = 1E-14
return on_boundary and near(x[0], 1, tol)def boundary_R(x, on_boundary):
tol = 1E-14
return on_boundary and near(x[0], 2, tol)def boundary_B(x, on_boundary):
tol = 1E-14
return on_boundary and near(x[1], 1, tol)def boundary_T(x, on_boundary):
tol = 1E-14
return on_boundary and near(x[1], 2, tol)u_L= Expression(‘1 + x[1]*x[1] + s’, s=s, degree=2)
u_R= Expression(‘4 + x[1]*x[1] + s’, s=s, degree=2)
u_B= Expression('x[0]*x[0] + 1 + s ', s=s, degree=2)
u_T = Expression(‘x[0]*x[0] + 4 + s’, s=s, degree=2)V = FunctionSpace(mesh, “CG”, 1)
u = TrialFunction(V)
v = TestFunction(V)
kappa = interpolate(kappa, V)
F = ( (u - u_0) /dt * v +inner(kappa * grad(u), grad(v)) - f*v)*dx
u=Function(V)while t <= T:
s = sin(10*t) bc_L = DirichletBC(V, u_L, boundary_L) bc_R = DirichletBC(V, u_R, boundary_R) bc_B = DirichletBC(V, u_B, boundary_B) bc_T = DirichletBC(V, u_T, boundary_T) bcs = [bc_L, bc_R, bc_B, bc_T] solve(F==0, u, bcs) t += float(dt)
plot(u)