As stated here by @dokken for function spaces,sub(i)
and collapse()
gives you a function space over the ith element of the mixed element, which can be seen in your case as the “mixed element” between CG1 spaces (one per component). For an already defined fem.Function
, you could do the same (see this link) to access its components if available. By using uh.x.array[1::3]
you have to be aware of the dof ordering on FEniCS.
Regarding your second question, since you now have uh
, you could obtain the stress by using an interpolation into a DG0 space. I would do the following
Tensorplot_space = fem.FunctionSpace(
mesh_domain, ("DG", 0, (3, 3)))
sig_h = fem.Function(Tensorplot_space)
sig = fem.Expression(ufl.as_ufl(sigma(uh)),
Tensorplot_space.element.interpolation_points())
sig_h.interpolate(sig)
sig_h.name = "$\sigma$"
write_file.write_function(sig_h, step)
Maybe there is a better (faster) way of doing that.
Cheers.