Skip to content

consistent usage of cell indexing type (Ti instead of Int)#123

Merged
chmerdon merged 12 commits into
masterfrom
chmerdon/cell_numbertype
May 20, 2026
Merged

consistent usage of cell indexing type (Ti instead of Int)#123
chmerdon merged 12 commits into
masterfrom
chmerdon/cell_numbertype

Conversation

@chmerdon
Copy link
Copy Markdown
Member

@chmerdon chmerdon commented May 7, 2026

in downstream packages like ExtendableFEMBase there is always confusion about with which index type a cell should be identified, sometimes it is the Ti type of the grid, sometimes it is just Int. This is mainly caused by the update_trafo functions of the l2gtransformer in ExtendableGrids, which enforces the cell index to be of type Int, although in the grid storages cells are indexed with the the type Ti.

With this PR all functions in ExtendableGrids now use the Ti type consistently. Unfortunately, this might cause some downstream assembly loops to crash and requires an update there as well. However, I think this should be done to avoid confusion in future and probably, when fixed there as well, this will also remove some allocations, e.g. in lazy_interpolate! of ExtendableFEMBase.

Update: Instead of enforcing Ti everywhere, type annotations have been removed to allow for Ti (and not enforce Int anymore)

@chmerdon chmerdon changed the title change cell type from fixed Int to grid Ti type change cell indexing type from fixed Int to grid Ti type May 7, 2026
@chmerdon chmerdon changed the title change cell indexing type from fixed Int to grid Ti type consistent usage of cell indexing type (Ti instead of Int) May 7, 2026
@pjaap
Copy link
Copy Markdown
Member

pjaap commented May 19, 2026

I think the following approach may solve the breaking-version problem:

function update_trafo!(T::L2GTransformer{<:Real, Ti, <:Edge1D, Cartesian1D}, item::Int, use_typestable_api::Val{false} = Val(false)) where {Ti <: Integer}
    Base.depwarn("use the type-stable API: typeof(item) must match the L2GTransformer Ti type", :update_trafo!, force = true)
    return update_trafo!(T, Ti(item), Val(true))
end


function update_trafo!(T::L2GTransformer{<:Real, Ti, <:Edge1D, Cartesian1D}, item::Ti, use_typestable_api::Val{true}) where {Ti}
    if T.citem != item
        T.citem = item
        T.b[1] = T.Coords[1, T.Nodes[1, item]]
        T.A[1, 1] = T.Coords[1, T.Nodes[2, item]] - T.b[1]
        T.det = T.ItemVolumes[item]
    end
    return nothing
end

Here for one function.

The old call is preserved but labeled as deprecated. It then calls the new signature with an explicit type conversion of the item. Maybe I miss something, so please review this idea.

@pjaap
Copy link
Copy Markdown
Member

pjaap commented May 19, 2026

I applied this to all update_trafo! methods for testing

@chmerdon
Copy link
Copy Markdown
Member Author

As suggested by @j-fu I removed the type annotations for the item arguments... hence downstream code should still work and no depwarns are needed. Internally (citem of L2GTransformer and CellFinder algorithms) still only Ti is used and CellFinder now always returns a value of type Ti. There seem to be no downstream issues, so not breaking?

Comment thread src/cellfinder.jl Outdated
else
@debug "could not find point in any cell and ended up at boundary of domain (maybe x lies outside of the domain ?)"
return 0
return Ti(0)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It is maybe cleaner to annotate the function with ::Ti instead of casting every return statement? The result is the same in the end.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

... and it ensures the return value type. For future changes.

Comment thread src/cellfinder.jl Outdated
@debug "gFindBruteForce did not find any cell that contains x = $x (make sure that x is inside the domain, or try reducing $eps)"

return 0
return Ti(0)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

same idea for this function with ::Ti

@j-fu
Copy link
Copy Markdown
Member

j-fu commented May 20, 2026

LGTM

@chmerdon chmerdon merged commit 125ef77 into master May 20, 2026
11 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.

3 participants