Skip to content

Commit 6f4e513

Browse files
committed
activated support for MTExtendableSparseMatrix and npartitions argument in FEMatrix constructor
1 parent 945f0d4 commit 6f4e513

File tree

3 files changed

+26
-21
lines changed

3 files changed

+26
-21
lines changed

Project.toml

Lines changed: 3 additions & 3 deletions
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]>"]
4-
version = "0.6.1"
4+
version = "0.7"
55

66
[deps]
77
DiffResults = "163ba53b-c6d8-5494-b064-1a9d43ac40c5"
@@ -20,8 +20,8 @@ UnicodePlots = "b8865327-cd53-5732-bb35-84acbb429228"
2020
[compat]
2121
DiffResults = "1"
2222
DocStringExtensions = "0.8,0.9"
23-
ExtendableGrids = "1.8"
24-
ExtendableSparse = "^1.4"
23+
ExtendableGrids = "1.9.2"
24+
ExtendableSparse = "1.5.1"
2525
ForwardDiff = "^0.10.35"
2626
LinearAlgebra = "1.9"
2727
Term = "2"

src/ExtendableFEMBase.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ using ExtendableGrids: ExtendableGrids, AT_NODES, AbstractElementGeometry,
3838
reference_domain, simplexgrid, subgrid, unique,
3939
update_trafo!
4040
using ExtendableSparse: ExtendableSparse, ExtendableSparseMatrix, flush!,
41+
AbstractExtendableSparseMatrixCSC, ExtendableSparseMatrixCSC, MTExtendableSparseMatrixCSC,
4142
rawupdateindex!
4243
using ForwardDiff: ForwardDiff, DiffResults
4344
using LinearAlgebra: LinearAlgebra, convert, det, diagm, dot, eigen, ldiv!, lu,

src/fematrix.jl

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,16 @@ function Base.copy(FEV::FEMatrix{TvM, TiM, TvG, TiG, nbrow, nbcol, nbtotal}) whe
6060
end
6161

6262
#Add value to matrix if it is nonzero
63-
@inline function _addnz(ESM::ExtendableSparseMatrix, i, j, v::Tv, fac) where Tv
63+
@inline function _addnz(ESM::AbstractExtendableSparseMatrixCSC, i, j, v::Tv, fac, part = 1) where Tv
6464
if v != zero(Tv)
65-
rawupdateindex!(ESM, +, v * fac, i, j)
65+
rawupdateindex!(ESM, +, v * fac, i, j, part)
6666
end
6767
end
6868

6969
#Add value to matrix if it is nonzero
70-
@inline function _addnz(FEB::FEMatrixBlock, i, j, v::Tv, fac) where Tv
70+
@inline function _addnz(FEB::FEMatrixBlock, i, j, v::Tv, fac, part = 1) where Tv
7171
if v != zero(Tv)
72-
rawupdateindex!(FEB.entries, +, v * fac, FEB.offset + i, FEB.offsetY + j)
72+
rawupdateindex!(FEB.entries, +, v * fac, FEB.offset + i, FEB.offsetY + j, part)
7373
end
7474
end
7575

@@ -205,7 +205,7 @@ FEMatrix{TvM,TiM}(FESX, FESY; name = "auto")
205205
206206
Creates an FEMatrix with blocks coressponding to the ndofs of FESX (rows) and FESY (columns).
207207
"""
208-
function FEMatrix{TvM, TiM}(FESX::Array{<:FESpace{TvG, TiG}, 1}, FESY::Array{<:FESpace{TvG, TiG}, 1}; entries = nothing, name = nothing, tags = nothing, tagsX = tags, tagsY = tagsX, kwargs...) where {TvM, TiM, TvG, TiG}
208+
function FEMatrix{TvM, TiM}(FESX::Array{<:FESpace{TvG, TiG}, 1}, FESY::Array{<:FESpace{TvG, TiG}, 1}; entries = nothing, name = nothing, tags = nothing, tagsX = tags, tagsY = tagsX, npartitions = 1, kwargs...) where {TvM, TiM, TvG, TiG}
209209
ndofsX, ndofsY = 0, 0
210210
for j 1:length(FESX)
211211
ndofsX += FESX[j].ndofs
@@ -214,7 +214,11 @@ function FEMatrix{TvM, TiM}(FESX::Array{<:FESpace{TvG, TiG}, 1}, FESY::Array{<:F
214214
ndofsY += FESY[j].ndofs
215215
end
216216
if entries === nothing
217-
entries = ExtendableSparseMatrix{TvM, TiM}(ndofsX, ndofsY)
217+
if npartitions == 1
218+
entries = ExtendableSparseMatrixCSC{TvM, TiM}(ndofsX, ndofsY)
219+
elseif npartitions > 1
220+
entries = MTExtendableSparseMatrixCSC{TvM, TiM}(ndofsX, ndofsY, npartitions)
221+
end
218222
else
219223
@assert size(entries) == (ndofsX, ndofsY) "size of given entries not matching number of dofs in given FE space(s)"
220224
end
@@ -284,10 +288,10 @@ Adds FEMatrix/ExtendableSparseMatrix/CSCMatrix B to FEMatrix A.
284288
function add!(A::FEMatrix{Tv, Ti}, B::FEMatrix{Tv, Ti}; kwargs...) where {Tv, Ti}
285289
add!(A.entries, B.entries; kwargs...)
286290
end
287-
function add!(AM::ExtendableSparseMatrix{Tv, Ti}, BM::ExtendableSparseMatrix{Tv, Ti}; kwargs...) where {Tv, Ti}
291+
function add!(AM::AbstractExtendableSparseMatrixCSC{Tv, Ti}, BM::AbstractExtendableSparseMatrixCSC{Tv, Ti}; kwargs...) where {Tv, Ti}
288292
add!(AM, BM.cscmatrix; kwargs...)
289293
end
290-
function add!(AM::ExtendableSparseMatrix{Tv, Ti}, cscmat::SparseMatrixCSC{Tv, Ti}; factor = 1, rowoffset = 0, coloffset = 0, transpose::Bool = false) where {Tv, Ti}
294+
function add!(AM::AbstractExtendableSparseMatrixCSC{Tv, Ti}, cscmat::SparseMatrixCSC{Tv, Ti}; factor = 1, rowoffset = 0, coloffset = 0, transpose::Bool = false) where {Tv, Ti}
291295
rows::Array{Ti, 1} = rowvals(cscmat)
292296
valsB::Array{Tv, 1} = cscmat.nzval
293297
ncols::Int = size(cscmat, 2)
@@ -318,8 +322,8 @@ $(TYPEDSIGNATURES)
318322
Adds FEMatrixBlock B to FEMatrixBlock A.
319323
"""
320324
function addblock!(A::FEMatrixBlock{Tv, Ti}, B::FEMatrixBlock{Tv, Ti}; factor = 1, transpose::Bool = false) where {Tv, Ti}
321-
AM::ExtendableSparseMatrix{Tv, Ti} = A.entries
322-
BM::ExtendableSparseMatrix{Tv, Ti} = B.entries
325+
AM::AbstractExtendableSparseMatrixCSC{Tv, Ti} = A.entries
326+
BM::AbstractExtendableSparseMatrixCSC{Tv, Ti} = B.entries
323327
cscmat::SparseMatrixCSC{Tv, Ti} = BM.cscmatrix
324328
rows::Array{Ti, 1} = rowvals(cscmat)
325329
valsB::Array{Tv, 1} = cscmat.nzval
@@ -357,7 +361,7 @@ $(TYPEDSIGNATURES)
357361
358362
Adds ExtendableSparseMatrix B to FEMatrixBlock A.
359363
"""
360-
function addblock!(A::FEMatrixBlock{Tv}, B::ExtendableSparseMatrix{Tv, Ti}; factor = 1, transpose::Bool = false) where {Tv, Ti <: Integer}
364+
function addblock!(A::FEMatrixBlock{Tv}, B::AbstractExtendableSparseMatrixCSC{Tv, Ti}; factor = 1, transpose::Bool = false) where {Tv, Ti <: Integer}
361365
addblock!(A, B.cscmatrix; factor = factor, transpose = transpose)
362366
end
363367

@@ -368,7 +372,7 @@ $(TYPEDSIGNATURES)
368372
Adds SparseMatrixCSC B to FEMatrixBlock A.
369373
"""
370374
function addblock!(A::FEMatrixBlock{Tv}, cscmat::SparseArrays.SparseMatrixCSC{Tv, Ti}; factor = 1, transpose::Bool = false) where {Tv, Ti <: Integer}
371-
AM::ExtendableSparseMatrix{Tv, Int64} = A.entries
375+
AM::AbstractExtendableSparseMatrixCSC{Tv, Int64} = A.entries
372376
rows::Array{Int, 1} = rowvals(cscmat)
373377
valsB::Array{Tv, 1} = cscmat.nzval
374378
arow::Int = 0
@@ -396,7 +400,7 @@ function addblock!(A::FEMatrixBlock{Tv}, cscmat::SparseArrays.SparseMatrixCSC{Tv
396400
return nothing
397401
end
398402

399-
function apply_penalties!(A::ExtendableSparseMatrix, fixed_dofs, penalty)
403+
function apply_penalties!(A::AbstractExtendableSparseMatrixCSC, fixed_dofs, penalty)
400404
for dof in fixed_dofs
401405
A[dof, dof] = penalty
402406
end
@@ -410,7 +414,7 @@ $(TYPEDSIGNATURES)
410414
Adds matrix-matrix product B times C to FEMatrixBlock A.
411415
"""
412416
function addblock_matmul!(A::FEMatrixBlock{Tv}, cscmatB::SparseMatrixCSC{Tv, Ti}, cscmatC::SparseMatrixCSC{Tv, Ti}; factor = 1, transposed::Bool = false) where {Tv, Ti}
413-
AM::ExtendableSparseMatrix{Tv, Int64} = A.entries
417+
AM::AbstractExtendableSparseMatrixCSC{Tv, Int64} = A.entries
414418
rowsB::Array{Ti, 1} = rowvals(cscmatB)
415419
rowsC::Array{Ti, 1} = rowvals(cscmatC)
416420
valsB::Array{Tv, 1} = cscmatB.nzval
@@ -529,7 +533,7 @@ $(TYPEDSIGNATURES)
529533
530534
Adds matrix-vector product B times b to FEVectorBlock a.
531535
"""
532-
function addblock_matmul!(a::FEVectorBlock{Tv}, B::ExtendableSparseMatrix{Tv, Ti}, b::FEVectorBlock{Tv}; factor = 1) where {Tv, Ti <: Integer}
536+
function addblock_matmul!(a::FEVectorBlock{Tv}, B::AbstractExtendableSparseMatrixCSC{Tv, Ti}, b::FEVectorBlock{Tv}; factor = 1) where {Tv, Ti <: Integer}
533537
cscmat::SparseMatrixCSC{Tv, Ti} = B.cscmatrix
534538
rows::Array{Ti, 1} = rowvals(cscmat)
535539
valsB::Array{Tv, 1} = cscmat.nzval
@@ -567,7 +571,7 @@ $(TYPEDSIGNATURES)
567571
568572
Computes vector'-matrix-vector product a'*B*b.
569573
"""
570-
function lrmatmul(a::AbstractVector{Tv}, B::ExtendableSparseMatrix{Tv, Ti}, b::AbstractVector{Tv}; factor = 1) where {Tv, Ti <: Integer}
574+
function lrmatmul(a::AbstractVector{Tv}, B::AbstractExtendableSparseMatrixCSC{Tv, Ti}, b::AbstractVector{Tv}; factor = 1) where {Tv, Ti <: Integer}
571575
cscmat::SparseMatrixCSC{Tv, Ti} = B.cscmatrix
572576
valsB::Array{Tv, 1} = cscmat.nzval
573577
rows::Array{Ti, 1} = rowvals(cscmat)
@@ -586,7 +590,7 @@ $(TYPEDSIGNATURES)
586590
587591
Computes vector'-matrix-vector product (a1-a2)'*B*(b1-b2).
588592
"""
589-
function ldrdmatmul(a1::AbstractVector{Tv}, a2::AbstractVector{Tv}, B::ExtendableSparseMatrix{Tv, Ti}, b1::AbstractVector{Tv}, b2::AbstractVector{Tv}; factor = 1) where {Tv, Ti <: Integer}
593+
function ldrdmatmul(a1::AbstractVector{Tv}, a2::AbstractVector{Tv}, B::AbstractExtendableSparseMatrixCSC{Tv, Ti}, b1::AbstractVector{Tv}, b2::AbstractVector{Tv}; factor = 1) where {Tv, Ti <: Integer}
590594
cscmat::SparseMatrixCSC{Tv, Ti} = B.cscmatrix
591595
valsB::Array{Tv, 1} = cscmat.nzval
592596
rows::Array{Ti, 1} = rowvals(cscmat)
@@ -600,7 +604,7 @@ function ldrdmatmul(a1::AbstractVector{Tv}, a2::AbstractVector{Tv}, B::Extendabl
600604
end
601605

602606

603-
function submatrix(A::ExtendableSparseMatrix{Tv,Ti}, srows, scols) where {Tv,Ti}
607+
function submatrix(A::AbstractExtendableSparseMatrixCSC{Tv,Ti}, srows, scols) where {Tv,Ti}
604608
cscmat::SparseMatrixCSC{Tv, Ti} = A.cscmatrix
605609
valsA::Array{Tv, 1} = cscmat.nzval
606610
rows::Array{Ti, 1} = rowvals(cscmat)

0 commit comments

Comments
 (0)