Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

project_to_nodes in L2Projector projects to vertices #380

Closed
kimauth opened this issue Oct 7, 2021 · 2 comments
Closed

project_to_nodes in L2Projector projects to vertices #380

kimauth opened this issue Oct 7, 2021 · 2 comments

Comments

@kimauth
Copy link
Member

kimauth commented Oct 7, 2021

project_to_nodes in L2Projector projects to vertices

The project_to_nodes option in the L2-projection actually doesn't reorder values to the nodes of the Grid, but to the vertices of the elements. That is, for a QuadraticQuadrilateral, with a quadratic field on it, we will only get four values (one for each vertex) and all other values will be NaNs (as if the field didn't exist on these points).
I've been trying to fix this for a bit, but it seems that would require a general mapping of (geometric) nodes to dofs. Not sure that is worth the effort, considering that the L2Projection has some more flaws, like #330.

Thoughts on design of L2Projector
Perhaps it is a design error that the L2Projector creates it's own MixedDofHandler instead of taking in whichever one was used for the simulation. This would be easy to solve if the underlying dof handler knew the field dimensions properly (it always works with scalar fields). Solving #330 would also require to use a full MixedDofHandler with several FieldHandlers instead of the internally created one.

@kimauth
Copy link
Member Author

kimauth commented Jan 17, 2022

using Ferrite

dim = 2
grid = generate_grid(QuadraticQuadrilateral, (1,1))

ip = Lagrange{dim, RefCube, 2}()
qr = QuadratureRule{dim, RefCube}(3)
cv = CellScalarValues(qr, ip)

# generate some data for a hypothetic field, here f(x, y) = x*y
qp_values = Vector{Float64}[]
for cell in CellIterator(grid)
    reinit!(cv, cell)
    vals = Vector{Float64}(undef, getnquadpoints(cv))
    for qp in 1:getnquadpoints(cv)
        x = spatial_coordinate(cv, qp, getcoordinates(cell))
        vals[qp] = x[1]*x[2]
    end
    push!(qp_values, vals)
end

projector = L2Projector(ip, grid)
projected_vals_nodes = project(projector, qp_values, qr; project_to_nodes = true) # this is the default
projected_vals_dofs = project(projector, qp_values, qr; project_to_nodes = false)

# we can still save to vtk correctly when using project_to_nodes = false
vtk_grid("test", projector.dh) do vtk
    vtk_point_data(vtk, projector.dh, projected_vals_dofs)
end
julia> projected_vals_nodes
9-element Vector{Float64}:
   0.9999999999999998
 NaN
  -1.0
 NaN
 NaN
 NaN
  -1.0
 NaN
   1.0

julia> projected_vals_dofs
9-element Vector{Float64}:
  0.9999999999999998
 -1.0
  1.0
 -1.0
  6.123031769111881e-17
  7.31836466427715e-17
  1.3660947373317333e-17
  7.611099250848237e-17
 -2.0491421059976015e-17

@fredrikekre
Copy link
Member

Option removed in #699.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants