Hi,
I’m working on some finite elasticity codes and I’ve ran into a small quirk and would love some and explanation.
In particular I’m curious about how Dofs of subspaces of mixed elements are ordered and how they are different than those created. Also if there is any reliability in the ordering of dofs. And lastly is it possible to align dofs between two functions in different function spaces?
To better explain what I’m talking about here is the following findings I saw
I was following the hyperplasticity demo where the mesh is warped by a vector but the coloring is done by a separate scalar.
This is my first attempt to plot the function:
pyvista.set_jupyter_backend('client')
plotter = pyvista.Plotter()
V , V_dofs = ME.sub(0).collapse() #Vector element subspace of ME
u_n = fem.Function(V)
u_ex = Expression(w.sub(0),V.element.interpolation_points())
u_n.interpolate(u_ex)
topology, cells, geometry = plot.create_vtk_mesh(V)
function_grid = pyvista.UnstructuredGrid(topology, cells, geometry)
values = np.zeros((geometry.shape[0], 3))
values[:, :len(u_n)] = u_n.x.array.reshape(geometry.shape[0], len(u_n))
function_grid["u"] = values
function_grid.set_active_vectors("u")
warped = function_grid.warp_by_vector("u", factor=1)
warped.set_active_vectors("u")
# Add mesh to plotter and visualize
actor = plotter.add_mesh(warped, show_edges=True, lighting=False, clim=[0, 67.5])
# Compute magnitude of displacement to visualize in GIF
Vs = FunctionSpace(domain,("Lagrange", 2))
magnitude = fem.Function(Vs)
us = fem.Expression(u_n[1], Vs.element.interpolation_points())
magnitude.interpolate(us)
warped["mag"] = magnitude.x.array
#print(u_n.function_space.dofmap.list)
plotter.update_scalars(magnitude.x.array,render = False)
plotter.camera.position=[5,25,200]
plotter.camera.focal_point=[5,40,0]
plotter.render()
plotter.show()
Here is the result:
It seems that the dofs between the Magnitude function and the u_n function are not in the same order.
I then created this example:
pyvista.set_jupyter_backend('client')
plotter = pyvista.Plotter()
V = fem.VectorFunctionSpace(domain,("Lagrange",2)) #HERE IS THE FIX JUST CREATE A NEW FUNCTION SPACE
u_n = fem.Function(V)
u_ex = Expression(w.sub(0),V.element.interpolation_points())
u_n.interpolate(u_ex)
topology, cells, geometry = plot.create_vtk_mesh(V)
function_grid = pyvista.UnstructuredGrid(topology, cells, geometry)
values = np.zeros((geometry.shape[0], 3))
values[:, :len(u_n)] = u_n.x.array.reshape(geometry.shape[0], len(u_n))
function_grid["u"] = values
function_grid.set_active_vectors("u")
warped = function_grid.warp_by_vector("u", factor=1)
warped.set_active_vectors("u")
# Add mesh to plotter and visualize
actor = plotter.add_mesh(warped, show_edges=True, lighting=False, clim=[0, 67.5])
# Compute magnitude of displacement to visualize in GIF
Vs = FunctionSpace(domain,("Lagrange", 2))
magnitude = fem.Function(Vs)
us = fem.Expression(u_n[1], Vs.element.interpolation_points())
magnitude.interpolate(us)
warped["mag"] = magnitude.x.array
#print(u_n.function_space.dofmap.list)
plotter.update_scalars(magnitude.x.array,render = False)
plotter.camera.position=[5,25,200]
plotter.camera.focal_point=[5,40,0]
plotter.render()
plotter.show()
This function seems to work correctly.
As seen above it seems that creating a new vector subspace solves the previous issue above issue and the DOFS between the two subspaces align. I’m curious if this is coincidence or if DOF ordering is assured.
Also is there anyway to get the first example to work? Maybe by aligning the dofs between the subspace and the new element?
Thanks for your help.