consistent usage of cell indexing type (Ti instead of Int)#123
Conversation
|
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 |
|
I applied this to all update_trafo! methods for testing |
…at gFindLocal nd gFindBruteForce always return Ti
|
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? |
| 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) |
There was a problem hiding this comment.
It is maybe cleaner to annotate the function with ::Ti instead of casting every return statement? The result is the same in the end.
There was a problem hiding this comment.
... and it ensures the return value type. For future changes.
| @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) |
There was a problem hiding this comment.
same idea for this function with ::Ti
|
LGTM |
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)