Skip to content

Commit 5ea170e

Browse files
authored
Make type of entries in FEVector(Block) a parameter (#43)
* typeof(entries) is now a parameter in FEVector(Block)
1 parent 972b7b7 commit 5ea170e

File tree

3 files changed

+20
-15
lines changed

3 files changed

+20
-15
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# CHANGES
22

3+
## v1.3.0
4+
- type of `entries` of `FEVectorBlock` and `FEVector` is now a template parameter
5+
36
## v1.2.0 June 25, 2025
47
- major documentation and docstring overhaul
58
- improved show functions and constructors for FEMatrix, FEVector

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "ExtendableFEMBase"
22
uuid = "12fb9182-3d4c-4424-8fd1-727a0899810c"
33
authors = ["Christian Merdon <[email protected]>", "Patrick Jaap <[email protected]>"]
4-
version = "1.2.0"
4+
version = "1.3.0"
55

66
[deps]
77
DiffResults = "163ba53b-c6d8-5494-b064-1a9d43ac40c5"

src/fevector.jl

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Each `FEVectorBlock` provides array-like access to the degrees of freedom (DOFs)
1616
- `T`: Value type of the vector entries (e.g., `Float64`).
1717
- `Tv`: Value type for the associated `FESpace`.
1818
- `Ti`: Integer type for the associated `FESpace`.
19+
- `TVector`: Type of the entries vector.
1920
- `FEType`: Type of the finite element.
2021
- `APT`: Assembly type for the finite element.
2122
@@ -24,21 +25,21 @@ Each `FEVectorBlock` provides array-like access to the degrees of freedom (DOFs)
2425
- `FES::FESpace{Tv, Ti, FEType, APT}`: The finite element space associated with this block.
2526
- `offset::Int`: Global offset (start index in the global vector).
2627
- `last_index::Int`: Global end index (inclusive).
27-
- `entries::Array{T, 1}`: Reference to the global coefficient array (shared with the parent `FEVector`).
28+
- `entries::TVector`: Reference to the global coefficient array (shared with the parent `FEVector`).
2829
2930
# Usage
3031
`FEVectorBlock` is typically created internally by `FEVector` constructors and provides efficient access to the coefficients for a particular FE space. Supports standard array operations (`getindex`, `setindex!`, `size`, `length`, etc.) and can be used for block-wise assembly, extraction, and manipulation.
3132
"""
32-
struct FEVectorBlock{T, Tv, Ti, FEType, APT} <: AbstractArray{T, 1}
33+
struct FEVectorBlock{T, Tv, Ti, TVector <: AbstractArray{T, 1}, FEType, APT} <: AbstractArray{T, 1}
3334
name::String
3435
FES::FESpace{Tv, Ti, FEType, APT}
3536
offset::Int
3637
last_index::Int
37-
entries::Array{T, 1} # shares with parent object
38+
entries::TVector # shares with parent object
3839
end
3940

40-
function Base.copy(FEB::FEVectorBlock{T, Tv, Ti, FEType, APT}, entries) where {T, Tv, Ti, FEType, APT}
41-
return FEVectorBlock{T, Tv, Ti, FEType, APT}(deepcopy(FEB.name), copy(FEB.FES), FEB.offset, FEB.last_index, entries)
41+
function Base.copy(FEB::FEVectorBlock{T, Tv, Ti, TVector, FEType, APT}, entries) where {T, Tv, Ti, TVector, FEType, APT}
42+
return FEVectorBlock{T, Tv, Ti, TVector, FEType, APT}(deepcopy(FEB.name), copy(FEB.FES), FEB.offset, FEB.last_index, entries)
4243
end
4344

4445
"""
@@ -69,22 +70,23 @@ An `FEVector` consists of a global coefficient array subdivided into multiple `F
6970
- `T`: Value type of the vector entries (e.g., `Float64`).
7071
- `Tv`: Value type for the associated `FESpace`.
7172
- `Ti`: Integer type for the associated `FESpace`.
73+
- `TVector`: Type of the `entries` vector
7274
7375
# Fields
7476
- `FEVectorBlocks::Array{FEVectorBlock{T, Tv, Ti}, 1}`: Array of blocks, each representing a segment of the global vector for a specific `FESpace`.
75-
- `entries::Array{T, 1}`: The global coefficient array, shared by all blocks.
77+
- `entries::TVector`: The global coefficient array, shared by all blocks.
7678
- `tags::Vector{Any}`: Optional tags for identifying or accessing blocks (e.g., by name or symbol).
7779
7880
"""
79-
struct FEVector{T, Tv, Ti} #<: AbstractVector{T}
80-
FEVectorBlocks::Array{FEVectorBlock{T, Tv, Ti}, 1}
81-
entries::Array{T, 1}
81+
struct FEVector{T, Tv, Ti, TVector <: AbstractArray{T, 1}} #<: AbstractVector{T}
82+
FEVectorBlocks::Array{FEVectorBlock{T, Tv, Ti, TVector}, 1}
83+
entries::TVector
8284
tags::Vector{Any}
8385
end
8486

85-
function Base.copy(FEV::FEVector{T, Tv, Ti}) where {T, Tv, Ti}
87+
function Base.copy(FEV::FEVector{T, Tv, Ti, TVector}) where {T, Tv, Ti, TVector}
8688
entries = deepcopy(FEV.entries)
87-
return FEVector{T, Tv, Ti}([copy(B, entries) for B in FEV.FEVectorBlocks], entries, [t for t in FEV.tags])
89+
return FEVector{T, Tv, Ti, TVector}([copy(B, entries) for B in FEV.FEVectorBlocks], entries, [t for t in FEV.tags])
8890
end
8991

9092
# overload stuff for AbstractArray{T,1} behaviour
@@ -254,10 +256,10 @@ function FEVector{T}(FES::Array{<:FESpace{Tv, Ti}, 1}; entries = nothing, name =
254256
Blocks = Array{FEVectorBlock{T, Tv, Ti}, 1}(undef, length(FES))
255257
offset = 0
256258
for j in 1:length(FES)
257-
Blocks[j] = FEVectorBlock{T, Tv, Ti, eltype(FES[j]), assemblytype(FES[j])}(names[j], FES[j], offset, offset + FES[j].ndofs, entries)
259+
Blocks[j] = FEVectorBlock{T, Tv, Ti, typeof(entries), eltype(FES[j]), assemblytype(FES[j])}(names[j], FES[j], offset, offset + FES[j].ndofs, entries)
258260
offset += FES[j].ndofs
259261
end
260-
return FEVector{T, Tv, Ti}(Blocks, entries, tags)
262+
return FEVector{T, Tv, Ti, typeof(entries)}(Blocks, entries, tags)
261263
end
262264

263265

@@ -296,7 +298,7 @@ Overloaded `append` function for `FEVector` that adds a FEVectorBlock at the end
296298
"""
297299
function Base.append!(FEF::FEVector{T}, FES::FESpace{Tv, Ti, FEType, APT}; name = "", tag = nothing) where {T, Tv, Ti, FEType, APT}
298300
append!(FEF.entries, zeros(T, FES.ndofs))
299-
newBlock = FEVectorBlock{T, Tv, Ti, FEType, APT}(name, FES, FEF.FEVectorBlocks[end].last_index, FEF.FEVectorBlocks[end].last_index + FES.ndofs, FEF.entries)
301+
newBlock = FEVectorBlock{T, Tv, Ti, typeof(FEF.entries), FEType, APT}(name, FES, FEF.FEVectorBlocks[end].last_index, FEF.FEVectorBlocks[end].last_index + FES.ndofs, FEF.entries)
300302
push!(FEF.FEVectorBlocks, newBlock)
301303
if tag !== nothing
302304
push!(FEF.tags, tag)

0 commit comments

Comments
 (0)