From 2430b4032bcafd5de8c4940d229ab3c5a0c49897 Mon Sep 17 00:00:00 2001 From: Francesc Verdugo Date: Fri, 9 Feb 2024 16:22:49 +0100 Subject: [PATCH] Removing unnecessary code --- .../GalerkinToolkitExamples/src/example003.jl | 75 +------------------ 1 file changed, 1 insertion(+), 74 deletions(-) diff --git a/extensions/GalerkinToolkitExamples/src/example003.jl b/extensions/GalerkinToolkitExamples/src/example003.jl index 6bcc9848..ddae28ee 100644 --- a/extensions/GalerkinToolkitExamples/src/example003.jl +++ b/extensions/GalerkinToolkitExamples/src/example003.jl @@ -6,7 +6,7 @@ using StaticArrays using LinearAlgebra using SparseArrays using WriteVTK -using PartitionedArrays: JaggedArray, val_parameter, nzindex +using PartitionedArrays: JaggedArray, sparse_matrix, sparse_matrix! using TimerOutputs using NLsolve using Random @@ -696,77 +696,4 @@ function export_results(uh,params,state) nothing end -# TODO move this to partitioned arrays -struct FilteredCooVector{F,A,B,C,T} <: AbstractVector{T} - f::F - I::A - J::B - V::C - function FilteredCooVector(f::F,I::A,J::B,V::C) where {F,A,B,C} - T = eltype(C) - new{F,A,B,C,T}(f,I,J,V) - end -end -Base.size(a::FilteredCooVector) = size(a.V) -Base.IndexStyle(::Type{<:FilteredCooVector}) = IndexLinear() -Base.@propagate_inbounds function Base.getindex(a::FilteredCooVector,k::Int) - i = a.I[k] - j = a.J[k] - v = a.V[k] - if i < 1 || j < 1 - return a.f(v) - end - v -end - -function sparse_matrix(I,J,V,m,n;kwargs...) - sparse_matrix(sparse,I,J,V,m,n;kwargs...) -end -function sparse_matrix(f,I,J,V,m,n;reuse=Val(false),skip_out_of_bounds=true) - if !skip_out_of_bounds - I2 = I - J2 = J - V2 = V - elseif m*n == 0 - Ti = eltype(I) - T = eltype(V) - I2 = Ti[] - J2 = Ti[] - V2 = Tv[] - else - I2 = FilteredCooVector(one,I,J,I) - J2 = FilteredCooVector(one,I,J,J) - V2 = FilteredCooVector(zero,I,J,V) - end - A = f(I2,J2,V2,m,n) - if val_parameter(reuse) - K = precompute_nzindex(A,I,J) - return A,K - end - A -end - -function precompute_nzindex(A,I,J) - K = zeros(Int32,length(I)) - for (p,(i,j)) in enumerate(zip(I,J)) - if i < 1 || j < 1 - continue - end - K[p] = nzindex(A,i,j) - end - K -end - -function sparse_matrix!(A,V,K) - LinearAlgebra.fillstored!(A,0) - A_nz = nonzeros(A) - for (k,v) in zip(K,V) - if k < 1 - continue - end - A_nz[k] += v - end - A -end - end # module