fix: Change node and element IDs to UInt (Issue #267)

Gmsh returns node and element IDs as UInt64, so we should use unsigned
integers consistently throughout JuliaFEM to avoid unnecessary conversions.

Changes:
- Point.id: Int → UInt
- Element.id: Int → UInt
- Element.connectivity: Vector{Int} → Vector{UInt}
- Element constructors: Accept Integer (converts to UInt internally)
- Default element_id: -1 → 0 (UInt has no negative values)

Benefits:
- Direct compatibility with Gmsh.jl (no Int/UInt conversions)
- Semantically correct (node/element IDs are never negative)
- Slightly more efficient (no sign checks)

Tests: All 156 tests passing

Closes #267
This commit is contained in:
Jukka Aho
2025-11-09 03:17:34 +02:00
parent 52ebe682e9
commit 06e8276268
2 changed files with 10 additions and 8 deletions
+1 -1
View File
@@ -6,7 +6,7 @@ const Node = Vector{Float64}
abstract type AbstractPoint end
mutable struct Point{P<:AbstractPoint}
id :: Int
id :: UInt # Changed from Int to match Gmsh (Issue #267)
weight :: Float64
coords :: Tuple{Vararg{Float64}}
fields :: Dict{String, AbstractField}
+9 -7
View File
@@ -27,8 +27,8 @@ Abstract supertype for all elements.
abstract type AbstractElement{M<:AbstractFieldSet,B<:AbstractBasis} end
mutable struct Element{M,B} <: AbstractElement{M,B}
id::Int
connectivity::Vector{Int}
id::UInt # Changed from Int to match Gmsh (Issue #267)
connectivity::Vector{UInt} # Changed from Vector{Int} to match Gmsh
integration_points::Vector{IP}
dfields::Dict{Symbol,AbstractField}
sfields::M
@@ -71,22 +71,24 @@ and connectivity contains node numbers where element is connected.
element = Element(Tri3, (1, 2, 3))
```
"""
function Element(::Type{T}, connectivity::NTuple{N,Int}) where {N,T<:AbstractBasis}
function Element(::Type{T}, connectivity::NTuple{N,<:Integer}) where {N,T<:AbstractBasis}
return Element(T, DefaultFieldSet, connectivity)
end
function Element(::Type{T}, ::Type{M}, connectivity::NTuple{N,Int}) where {N,M<:AbstractFieldSet,T<:AbstractBasis}
element_id = -1
function Element(::Type{T}, ::Type{M}, connectivity::NTuple{N,<:Integer}) where {N,M<:AbstractFieldSet,T<:AbstractBasis}
element_id = UInt(0) # Changed from -1, UInt has no negative values
topology = T()
integration_points = Point{IntegrationPoint}[]
dfields = Dict{Symbol,AbstractField}()
sfields = M{N}()
element = Element(element_id, collect(connectivity), integration_points,
# Convert connectivity to UInt
connectivity_uint = UInt.(collect(connectivity))
element = Element(element_id, connectivity_uint, integration_points,
dfields, sfields, topology)
return element
end
function Element(::Type{T}, connectivity::Vector{Int}) where T<:AbstractBasis
function Element(::Type{T}, connectivity::Vector{<:Integer}) where T<:AbstractBasis
return Element(T, (connectivity...,))
end