#vectorheat
from __future__ import print_function
from dolfin import *
import numpy as np
from math import *
import os, sys
import matplotlib.pyplot as plt
import sympy as sp
from sympy import exp, sin, pi, cos
T = 1 # final time
num_steps = 10000 # number of time steps
dt = T / num_steps # time step size
# define symbol expressions of u,p,f using sympyw23
x,y,t = sp.symbols("x[0],x[1],t")
phsi=cos(t)*sin(4*pi*(x+y))*((4*y*(1-y))**4)
u1=sp.diff(phsi,y,1)
u2=-sp.diff(phsi,x,1)
f1=sp.diff(u1,t,1)-sp.diff(u1,x,2)-sp.diff(u1,y,2)
f2=sp.diff(u2,t,1)-sp.diff(u2,x,2)-sp.diff(u2,y,2)
# transform the expressions to ccode style
u1 = sp.printing.ccode(u1)
u2 = sp.printing.ccode(u2)
f1 = sp.printing.ccode(f1)
f2 = sp.printing.ccode(f2)
phsip = sp.printing.ccode(phsi)
class PeriodicBoundary(SubDomain):
# Left boundary is "target domain" G
def inside(self, x, on_boundary):
return bool(x[0] < DOLFIN_EPS and x[0] > -DOLFIN_EPS and on_boundary)
# Map right boundary (H) to left boundary (G)
def map(self, x, y):
y[0] = x[0] - 1
y[1] = x[1]
# Create mesh and define function spaces
mesh = UnitSquareMesh(32, 32)
P1 = FiniteElement("Lagrange", mesh.ufl_cell(), 1)
Q = FunctionSpace(mesh, P1, constrained_domain=PeriodicBoundary())
Mh= FunctionSpace(mesh, "RT", 1, constrained_domain=PeriodicBoundary())
# Define trial and test functions
u = TrialFunction(Mh)
v = TestFunction(Mh)
sigm =TrialFunction(Q)
sigmT =TestFunction(Q)
sigm_=Function(Q)
u_= Function(Mh)
f = Expression((f1,f2), degree=5, t=0)
u_e = Expression((u1,u2), degree=5,t=0)
u_n = interpolate(u_e, Mh)
k = Constant(dt)
# Define variational problem for step 0
a0=inner(sigm,sigmT)*dx
L0=inner(u_n,curl(sigmT))*dx
# Define variational problem for step 1
F1=inner((u-u_n)/k,v)*dx+inner(curl(sigm_),v)*dx+inner(div(u),div(v))*dx-inner(f,v)*dx
a1=lhs(F1)
L1=rhs(F1)
# Time-stepping
t = 0
for n in range(num_steps):
t += dt
solve(a0 == L0, sigm_)
f.t=t
solve(a1 == L1, u_)
u_e.t = t
error=errornorm(u_e, u_, "L2")
print('t = %.2f: error = %.3g' % (t, error))
u_n.assign(u_)
I want to solve the vector heat equation, the above is the code and the eqution is from the paper HIGH-ORDER METHODS FOR A PRESSURE POISSON EQUATION REFORMULATION OF THE NAVIER-STOKES EQUATIONS WITH ELECTRIC BOUNDARY CONDITIONS https://arxiv.org/abs/2002.09801. In this paper, the author is use Fenics, so I implement it and want to get the same results. But I meet some trouble. The equation and varitional form as

After run the code , take dt=0.001, T=0.01, and I get

So I really need someone help me.