Hi! I’m trying to give a specific name to a field, but the method (or parameter) name
provided by Function
class just ignore the name string I provided, which results in some random name like f_20, f_117 etc. The MWE is as following:
from fenics import *
import os
mesh = RectangleMesh(Point(0, 0), Point(1.0, 1.0), 10, 10)
def initialize_temperature(Q):
T0 = Expression('0.5*(1.0-x[1]*x[1])+0.01*cos(pi*x[0]/length)*sin(pi*x[1]/height)', length = 1, height = 1, degree=1)
T0 = interpolate(T0, Q)
return T0, 0.0
V = VectorElement('Lagrange', mesh.ufl_cell(), 2)
Q = FiniteElement('Lagrange', mesh.ufl_cell(), 1)
W = FunctionSpace(mesh, MixedElement([V, Q]))
QT = FunctionSpace(mesh, "DG", 1)
T_n = Function(QT, name = "Temperature")
T_n, t = initialize_temperature(QT)
dirname = "result"
outputname = "convection"
xdmfpath = os.path.abspath(dirname)+"/"+outputname+".xdmf"
xdmf_field = XDMFFile(xdmfpath)
hdf5path = os.path.abspath(dirname)+"/"+outputname
field_series = TimeSeries(hdf5path)
#Here is probably the error
xdmf_field.write(T_n, t)
field_series.store(T_n.vector(), t)
xdmf_field.close()
short notes on this snippet, T_n
is a Function object with name “Temperature” I’d like to visualize in Paraview. If I debug this code, type T_n.name()
in terminal, it gives “Temperature”, which is right. But the command xdmf_field.write(T_n, t)
just ignores T_n
’s name and writes some arbitrary string in convection.xdmf, e.g. f_20. Paraview will just show that arbitrary string for that field.
I also found a method name
and rename
in class XDMFFile
, but I haven’t figured out how to use it. Any suggestion? Thanks!