I am a beginner and I want to calculate The coupling problem of heat transfer and diffusion, where the diffusion coefficient is a function of temperature, by learning The FEniCS Tutorial II, I have written the following program, but there seem to be some problems, I think the program must have more than one problem, but I want to solve step by step, my program is as follows:
from fenics import *
import numpy as np
import matplotlib.pyplot as plt
# 定义已知表达式
kB = Constant(8.6e-5)
r = Constant(0.3)
Sext = Constant(0.0)
fai = Constant(1e24)
c_ini = Constant(0)
c_evi = Constant(1)
t_total = 10
num_steps = 500
dt = t_total / num_steps
def D(T):
return 4.17e-7*exp(-0.39/(kB*T))
def KrW(T):
return 3.2e-15*exp(-1.16/(kB*T))
def KrCuCrZr(T):
return 2.9e-14*exp(-1.92/(kB*T))
mesh = Mesh('10_10_10s_slab/mesh.xml.gz')
W = FunctionSpace(mesh, 'P', 1)
V = FunctionSpace(mesh, 'P', 1)
class BoundaryX0(SubDomain):
def inside(self, x, on_boundary):
return on_boundary and abs(x[0]-0.00)<DOLFIN_EPS
class BoundaryX1(SubDomain):
def inside(self, x, on_boundary):
return on_boundary and abs(x[0]-0.01)<DOLFIN_EPS
class BoundaryY0(SubDomain):
def inside(self, x, on_boundary):
return on_boundary and abs(x[1]-0.00)<DOLFIN_EPS
class BoundaryY1(SubDomain):
def inside(self, x, on_boundary):
return on_boundary and abs(x[1]-0.01)<DOLFIN_EPS
bx0 = BoundaryX0()
bx1 = BoundaryX1()
by0 = BoundaryY0()
by1 = BoundaryY1()
boundary_markers = MeshFunction('size_t', mesh, mesh.topology().dim()-1)
#boundary_markers.set_all(9999)
bx0.mark(boundary_markers, 0)
bx1.mark(boundary_markers, 1)
by0.mark(boundary_markers, 2)
by1.mark(boundary_markers, 3)
ds = Measure('ds', domain=mesh, subdomain_data=boundary_markers)
T = Function(W)
c = Function(V)
c_n = Function(V) # initial
v = TestFunction(V)
F = c*v*dx + dt*D(T)*dot(grad(c),grad(v))*dx - c_n*v*dx - dt*Sext*v*dx - dt*((1-r)*fai-KrW(T)*c**2)*ds(3) - dt*(KrCuCrZr(T)*c**2)*ds(2)
xdmffile_c = XDMFFile('10_10_10s_slab/diffusion.xdmf')
xdmffile_c.parameters["flush_output"] = True
xdmffile_c.parameters["functions_share_mesh"] = True
timeseries_T = TimeSeries('10_10_10s_slab/temperature_series')
progress = Progress('Time-stepping', num_steps)
t = 0
for n in range(num_steps):
t += dt
timeseries_T.retrieve(T.vector(), t)
solve(F == 0, c)
plot(c)
xdmffile_c.write(c, t)
c_n.assign(c)
set_log_level(LogLevel.PROGRESS)
progress += 1
set_log_level(LogLevel.ERROR)
When I run the above program, I get the following error:
ArityMismatch: Integrand arguments () differ from form arguments (Argument(FunctionSpace(Mesh(VectorElement(FiniteElement('Lagrange', triangle, 1), dim=2), 353), FiniteElement('Lagrange', triangle, 1)), 0, None),).