Hi,
I’m facing a problem imposing initial conditions in a mixed function space. When I open the files in ParaView, the values of some components were mixed in some nodes. I noticed that, without the VectorElement with dimension 3 and the TensorElement, the interpolation is ok.
from ufl import VectorElement, FiniteElement, TensorElement, MixedElement
import dolfinx
from dolfinx import RectangleMesh, FunctionSpace, Function
from dolfinx.io import XDMFFile
from mpi4py import MPI
import numpy as np
# Mesh
mesh = RectangleMesh(
MPI.COMM_WORLD,
[np.array([0, 0, 0]), np.array([1, 1, 0])], [32, 32],
dolfinx.cpp.mesh.CellType.triangle, dolfinx.cpp.mesh.GhostMode.none)
# Define Function Space
V = VectorElement("Lagrange", mesh.ufl_cell(), 1)
Q = FiniteElement("Lagrange", mesh.ufl_cell(), 1)
S = VectorElement("Lagrange", mesh.ufl_cell(), 1, 3)
L = TensorElement("Lagrange", mesh.ufl_cell(), 1)
W = FunctionSpace(mesh, MixedElement([V, Q, S, L]))
# Define function
w = Function(W)
# Initial conditions
def w_init(x):
values = np.zeros((10, x.shape[1]))
values[0] = 1.0
values[1] = 2.0
values[2] = 3.0
values[3] = 4.0
values[4] = 5.0
values[5] = 6.0
values[6] = 7.0
values[7] = 8.0
values[8] = 9.0
values[9] = 10.0
return values
w.interpolate(w_init)
# Files
u_file = XDMFFile(MPI.COMM_WORLD, "test/velocity.xdmf", "w")
u_file.write_mesh(mesh)
u_file.write_function(w.split()[0])
p_file = XDMFFile(MPI.COMM_WORLD, "test/pressure.xdmf", "w")
p_file.write_mesh(mesh)
p_file.write_function(w.split()[1])
A11_file = XDMFFile(MPI.COMM_WORLD, "test/A11.xdmf", "w")
A11_file.write_mesh(mesh)
A11_file.write_function(w.split()[2].split()[0])
A12_file = XDMFFile(MPI.COMM_WORLD, "test/A12.xdmf", "w")
A12_file.write_mesh(mesh)
A12_file.write_function(w.split()[2].split()[1])
A22_file = XDMFFile(MPI.COMM_WORLD, "test/A22.xdmf", "w")
A22_file.write_mesh(mesh)
A22_file.write_function(w.split()[2].split()[2])
G11_file = XDMFFile(MPI.COMM_WORLD, "test/G11.xdmf", "w")
G11_file.write_mesh(mesh)
G11_file.write_function(w.split()[3].split()[0])
G12_file = XDMFFile(MPI.COMM_WORLD, "test/G12.xdmf", "w")
G12_file.write_mesh(mesh)
G12_file.write_function(w.split()[3].split()[1])
G21_file = XDMFFile(MPI.COMM_WORLD, "test/G21.xdmf", "w")
G21_file.write_mesh(mesh)
G21_file.write_function(w.split()[3].split()[2])
G22_file = XDMFFile(MPI.COMM_WORLD, "test/G22.xdmf", "w")
G22_file.write_mesh(mesh)
G22_file.write_function(w.split()[3].split()[3])
u_file.close()
p_file.close()
A11_file.close()
A12_file.close()
A22_file.close()
G11_file.close()
G12_file.close()
G21_file.close()
G22_file.close()
These are the components x and y of the file velocity.xdmf, which are supposed to be equal to 1.0 and 2.0, respectively.