diff --git a/Project.toml b/Project.toml index 8644cb2..f67107c 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "ExtendableFEMBase" uuid = "12fb9182-3d4c-4424-8fd1-727a0899810c" authors = ["Christian Merdon "] -version = "0.3.3" +version = "0.4" [deps] DiffResults = "163ba53b-c6d8-5494-b064-1a9d43ac40c5" diff --git a/src/ExtendableFEMBase.jl b/src/ExtendableFEMBase.jl index 4f24ffc..677310f 100644 --- a/src/ExtendableFEMBase.jl +++ b/src/ExtendableFEMBase.jl @@ -80,6 +80,7 @@ export FEVectorBlock, FEVector export dot, norm, norms export FEMatrixBlock, FEMatrix, _addnz export fill!, addblock!, addblock_matmul!, lrmatmul, mul!, add!, apply_penalties! +export submatrix export show_entries export displace_mesh, displace_mesh! diff --git a/src/fematrix.jl b/src/fematrix.jl index a487c2c..aa2f46f 100644 --- a/src/fematrix.jl +++ b/src/fematrix.jl @@ -261,7 +261,7 @@ end function add!(AM::ExtendableSparseMatrix{Tv, Ti}, BM::ExtendableSparseMatrix{Tv, Ti}; kwargs...) where {Tv, Ti} add!(AM, BM.cscmatrix; kwargs...) end -function add!(AM::ExtendableSparseMatrix{Tv, Ti}, cscmat::SparseMatrixCSC{Tv, Ti}; factor = 1, transpose::Bool = false) where {Tv, Ti} +function add!(AM::ExtendableSparseMatrix{Tv, Ti}, cscmat::SparseMatrixCSC{Tv, Ti}; factor = 1, rowoffset = 0, coloffset = 0, transpose::Bool = false) where {Tv, Ti} rows::Array{Ti, 1} = rowvals(cscmat) valsB::Array{Tv, 1} = cscmat.nzval ncols::Int = size(cscmat, 2) @@ -270,14 +270,14 @@ function add!(AM::ExtendableSparseMatrix{Tv, Ti}, cscmat::SparseMatrixCSC{Tv, Ti for col ∈ 1:ncols for r in nzrange(cscmat, col) arow = rows[r] - _addnz(AM, col, arow, valsB[r], factor) + _addnz(AM, col + coloffset, arow + rowoffset, valsB[r], factor) end end else for col ∈ 1:ncols for r in nzrange(cscmat, col) arow = rows[r] - _addnz(AM, arow, col, valsB[r], factor) + _addnz(AM, arow + rowoffset, col + coloffset, valsB[r], factor) end end end @@ -547,7 +547,7 @@ function lrmatmul(a::AbstractVector{Tv}, B::ExtendableSparseMatrix{Tv, Ti}, b::A rows::Array{Ti, 1} = rowvals(cscmat) result = 0.0 for col ∈ 1:size(B, 2) - for r in nzrange(B.cscmatrix, col) + for r in nzrange(cscmat, col) result += valsB[r] * b[col] * factor * a[rows[r]] end end @@ -566,9 +566,31 @@ function ldrdmatmul(a1::AbstractVector{Tv}, a2::AbstractVector{Tv}, B::Extendabl rows::Array{Ti, 1} = rowvals(cscmat) result = 0.0 for col ∈ 1:size(B, 2) - for r in nzrange(B.cscmatrix, col) + for r in nzrange(cscmat, col) result += valsB[r] * (b1[col] - b2[col]) * factor * (a1[rows[r]] - a2[rows[r]]) end end return result end + + +function submatrix(A::ExtendableSparseMatrix{Tv,Ti}, srows, scols) where {Tv,Ti} + cscmat::SparseMatrixCSC{Tv, Ti} = A.cscmatrix + valsA::Array{Tv, 1} = cscmat.nzval + rows::Array{Ti, 1} = rowvals(cscmat) + result = 0.0 + S = ExtendableSparseMatrix{Tv,Ti}(length(srows), length(scols)) + @assert maximum(srows) <= size(A, 1) "rows exceeds rowcount of A" + @assert maximum(scols) <= size(A, 2) "cols exceeds colcount of A" + for col = 1 : length(scols) + scol = scols[col] + for r in nzrange(cscmat, scol) + j = findfirst(==(rows[r]), srows) + if j !== nothing + S[j, col] = A[rows[r], scol] + end + end + end + flush!(S) + return S +end \ No newline at end of file diff --git a/src/plots.jl b/src/plots.jl index 9bc694c..7d71bee 100644 --- a/src/plots.jl +++ b/src/plots.jl @@ -151,7 +151,7 @@ function unicode_scalarplot( end for c ∈ 1:length(components) if c == 1 - plt = lineplot(X, view(I[c][1]), ylim = ylim, xlabel = "x", name = title * "[$(components[c])]", height = resolution[2], width = resolution[1]) + plt = lineplot(X, view(I[c][1]), ylim = ylim, xlabel = "x", name = title * (length(components) == 1 ? "" : "[$(components[c])]"), height = resolution[2], width = resolution[1]) else lineplot!(plt, X, view(I[c][1]), name = title * "[$(components[c])]") end @@ -167,7 +167,7 @@ function unicode_scalarplot( yfact = (ey[2] - ey[1]) / (resolution[2] - 1), xoffset = ex[1], yoffset = ey[1], - title = title * "[$(components[c])]", + title = title * (length(components) == 1 ? "" : "[$(components[c])]"), colormap = colormap, ) for c ∈ 1:length(components) ] diff --git a/src/qpinfos.jl b/src/qpinfos.jl index 893c4c0..f29133f 100644 --- a/src/qpinfos.jl +++ b/src/qpinfos.jl @@ -3,7 +3,8 @@ mutable struct QPInfos{Ti, Tv, Ttime, Tx, Txref, TvG, TiG, PT} item::Ti cell::Ti region::Ti - volume::Tv + volume::TvG + normal::Vector{TvG} time::Ttime x::Vector{Tx} xref::Vector{Txref} @@ -12,7 +13,7 @@ mutable struct QPInfos{Ti, Tv, Ttime, Tx, Txref, TvG, TiG, PT} end function QPInfos(xgrid::ExtendableGrid{Tv, Ti}; time = 1.0, dim = size(xgrid[Coordinates], 1), T = Tv, x = ones(T, dim), params = [], kwargs...) where {Tv, Ti} - return QPInfos(Ti(1), Ti(1), Ti(1), Tv(1.0), time, x, ones(T, dim), xgrid, params) + return QPInfos{Ti, Tv, typeof(time), T, T, Tv, Ti, typeof(params)}(Ti(1), Ti(1), Ti(1), Tv(1.0), zeros(Tv, dim), time, x, ones(T, dim), xgrid, params) end