Skip to content

Add 1D Higher Order Lagrange Functions (Cx and C0)#175

Merged
krcools merged 2 commits into
krcools:masterfrom
sbadrian:feature/higher_order_4
Nov 14, 2025
Merged

Add 1D Higher Order Lagrange Functions (Cx and C0)#175
krcools merged 2 commits into
krcools:masterfrom
sbadrian:feature/higher_order_4

Conversation

@sbadrian

@sbadrian sbadrian commented Nov 8, 2025

Copy link
Copy Markdown
Contributor

Polynomials are implemented hard-coded up to order 10 for maximal speed.

TODO: The Mie unit test should be adapted once
curvilinear meshes are available. So far, we only
confirm that higher-order functions do not break the performance. However, since the mesh is not refined the geometrical error starts to dominate quickly.

Polynomials are implemented hard-coded up to order 10
for maximal speed.

TODO: The Mie unit test should be adapted once
curvilinear meshes are available. So far, we only
confirm that higher-order functions do not break the
performance. However, since the mesh is not refined
the geometrical error starts to dominate quickly.
@sbadrian sbadrian force-pushed the feature/higher_order_4 branch from 6cc104b to b1dc8dc Compare November 8, 2025 15:41
Greatly improves the speed.

I expect further improvements are possible, but this was the
most significant type instability that I have found.
Comment thread src/bases/lagrange.jl
function lagrangec0_dirichlet(mesh; order=1)

verts = skeleton(mesh, 0)
detached = trues(numvertices(mesh))

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

skeleton(mesh, 0) gives the nodes (vertices that are acutally used in the cell definitions). So it is not necessarily true that numvertices(mesh) == length(skeleton(mesh,0)). The latter should be used here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you suggesting to replace detached = trues(numvertices(mesh)) by detached = trues(length(skeleton(mesh,0)))? I think it is correct the way it is, because the goal in the following is to filter out the detached vertices (I am following here the same recipe as at other places in lagrange.jl and I have verified that it works as desired).

Comment thread src/bases/lagrange.jl
notonbnd[v] = false
end

vertexlist = findall(notonbnd .& .!detached)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this can be expressed as:

setminus(skeleton(mesh,0), skeleton(boundary(mesh),0))

@sbadrian sbadrian Nov 14, 2025

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. In fact, the entire function could be replaced by

function lagrangec0_dirichlet(mesh; order=1)
    internalnodes = setminus(skeleton(mesh,0), skeleton(boundary(mesh),0)).cells
    internalnodes = sort!([node[1] for node in internalnodes])
    
    lagrangec0(mesh, vertexlist, Val{dimension(mesh)+1}; order=order)
end

Given that the same mechanism is used in the other lagrange functions, I could replace it everywhere in lagrange.jl.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's leave this all as is for now. I'll make a testitem for the case where I think the two behaviours might differ.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My currents view is to hide as much as possible the vertices and use the 0-skeleton instead. Sometimes meshes like gmsh add floating (=unused) vertices to the file and so the two concepts are not always interchangeable.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, definitely, but I think the function was written precisely in this way to filter out the unused vertices when finding the internal nodes.. I think though that the setminus approach you have proposed is indeed much more elegant and clearer. I think we just should do it consistently like this in lagrange.jl as otherwise one would wonder why there are different approaches are used.

Of course, this could be done in a separate PR as this is a general refactoring.

@krcools krcools left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dont you need implementations for interpolate in laglocal.jl?

@sbadrian

Copy link
Copy Markdown
Contributor Author

It seems that for the momintegral routines the interpolate routines are not needed (actually, where are they used?). I can add them though.

@krcools

krcools commented Nov 14, 2025

Copy link
Copy Markdown
Owner

For some quadrature strategies they are almost certainly required. I even though that the vertex reorderings that are sometimes needed for Sauter-Schwab quadrature to work rely on them. For non-conforming meshes and refined meshes they are also used in general.

I suggest we leave as is and implement the first time someone tries one of these more complicated scenarios.

@sbadrian

Copy link
Copy Markdown
Contributor Author

Sounds good to me. I think then the branch is ready to be merged.

@krcools krcools merged commit c96d69a into krcools:master Nov 14, 2025
3 checks passed
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

Successfully merging this pull request may close these issues.

2 participants