Skip to content

Commit

Permalink
QPInfos can store normal vector, submatrix function for ExtendableSpa…
Browse files Browse the repository at this point in the history
…rseMatrix, some small improvements
  • Loading branch information
chmerdon committed Jun 6, 2024
1 parent b4462bf commit 242e0f3
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "ExtendableFEMBase"
uuid = "12fb9182-3d4c-4424-8fd1-727a0899810c"
authors = ["Christian Merdon <[email protected]>"]
version = "0.3.3"
version = "0.4"

[deps]
DiffResults = "163ba53b-c6d8-5494-b064-1a9d43ac40c5"
Expand Down
1 change: 1 addition & 0 deletions src/ExtendableFEMBase.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down
32 changes: 27 additions & 5 deletions src/fematrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
4 changes: 2 additions & 2 deletions src/plots.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
]
Expand Down
5 changes: 3 additions & 2 deletions src/qpinfos.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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


Expand Down

2 comments on commit 242e0f3

@chmerdon
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/108395

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.4.0 -m "<description of version>" 242e0f397d5845a2fbdf09cad85d12215115601d
git push origin v0.4.0

Please sign in to comment.