From 404ea66f110bffd3e0ea5ccf614cc3c66a7bcd3c Mon Sep 17 00:00:00 2001 From: Jukka Aho Date: Sun, 23 Nov 2025 18:18:52 +0200 Subject: [PATCH] refactor(topology): Modernize segment topology implementation - Apply Vec constructor broadcasting: Vec{1,Float64}.((...)) - Convert edges() to return typed Edge{T} in SVector - Convert faces() to return typed Vertex{T} (endpoints in 1D) - Add vertices() method returning two Vertex{T} instances - Add cells() method returning single Cell{T} - Add entity count methods: nvertices(), nedges(), nfaces() - Clean up syntax with consistent formatting --- src/topology/segments.jl | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/src/topology/segments.jl b/src/topology/segments.jl index f92006c..80cd2c4 100644 --- a/src/topology/segments.jl +++ b/src/topology/segments.jl @@ -19,26 +19,38 @@ nnodes(::Segment{N}) where {N} = N dim(::Segment{N}) where {N} = 1 function reference_coordinates(::Segment{2}) - return SVector( - Vec{1,Float64}((-1.0,)), - Vec{1,Float64}((1.0,)) - ) + return SVector(Vec{1,Float64}.(( + (-1.0,), + (1.0,) + ))) end function reference_coordinates(::Segment{3}) - return SVector( - Vec{1,Float64}((-1.0,)), - Vec{1,Float64}((1.0,)), - Vec{1,Float64}((0.0,)) - ) + return SVector(Vec{1,Float64}.(( + (-1.0,), + (1.0,), + (0.0,) + ))) end -function edges(::Segment{N}) where {N} - return ((1, 2),) +function edges(::T) where {T<:Segment} + return SVector(Edge{T}((1, 2))) end -function faces(::Segment{N}) where {N} - return ((1,), (2,)) # Endpoints are "faces" in 1D +function faces(::T) where {T<:Segment} + return SVector(Vertex{T}(), Vertex{T}()) # Endpoints are "faces" in 1D end +function vertices(::T) where {T<:Segment} + return SVector(Vertex{T}(), Vertex{T}()) +end + +function cells(::T) where {T<:Segment} + return SVector(Cell{T}()) +end + +nvertices(::Segment) = 2 +nedges(::Segment) = 1 +nfaces(::Segment) = 2 # Two endpoints + export Seg2, Seg3