Skip to content

Commit

Permalink
Merge pull request #965 from gridap/clean-rk-solvers
Browse files Browse the repository at this point in the history
Refactoring of GridapODEs
  • Loading branch information
santiagobadia committed Mar 18, 2024
2 parents c53e6c2 + f578f90 commit 92f38a2
Show file tree
Hide file tree
Showing 105 changed files with 9,889 additions and 6,532 deletions.
57 changes: 0 additions & 57 deletions docs/ODEs.md

This file was deleted.

452 changes: 452 additions & 0 deletions docs/src/ODEs.md

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/Algebra/Algebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export allocate_in_domain
export allocate_in_range
export add_entries!
export muladd!
export axpy_entries!
export nz_counter
export nz_allocation
export create_from_nz
Expand Down
54 changes: 54 additions & 0 deletions src/Algebra/AlgebraInterfaces.jl
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,60 @@ else
end
end

"""
axpy_entries!(α::Number, A::T, B::T) where {T<: AbstractMatrix} -> T
Efficient implementation of axpy! for sparse matrices.
"""
function axpy_entries!::Number, A::T, B::T) where {T<:AbstractMatrix}
iszero(α) && return B

axpy!(α, A, B)
B
end

# For sparse matrices, it is surprisingly quicker to call `@. B += α * A` than
# `axpy!(α, A, B)`.` Calling axpy! on the nonzero values of A and B is the most
# efficient approach but this is only possible when A and B have the same
# sparsity pattern. The checks add some non-negligible overhead so we make them
# optional by adding a keyword.
const cannot_axpy_entries_msg = """
It is only possible to efficiently add two sparse matrices that have the same
sparsity pattern.
"""

function axpy_entries!(
α::Number, A::T, B::T;
check::Bool=true
) where {T<:SparseMatrixCSC}
iszero(α) && return B

if check
msg = cannot_axpy_entries_msg
@check rowvals(A) == rowvals(B) msg
@check all(nzrange(A, j) == nzrange(B, j) for j in axes(A, 2)) msg
end

axpy!(α, nonzeros(A), nonzeros(B))
B
end

function axpy_entries!(
α::Number, A::T, B::T;
check::Bool=true
) where {T<:Union{SparseMatrixCSR,SymSparseMatrixCSR}}
iszero(α) && return B

if check
msg = cannot_axpy_entries_msg
@check colvals(A) == colvals(B) msg
@check all(nzrange(A, j) == nzrange(B, j) for j in axes(A, 1)) msg
end

axpy!(α, nonzeros(A), nonzeros(B))
B
end

#
# Some API associated with assembly routines
#
Expand Down
12 changes: 10 additions & 2 deletions src/Arrays/Interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,16 @@ function testvalue(::Type{T}) where T<:AbstractArray{E,N} where {E,N}
similar(T,tfill(0,Val(N))...)
end

# When the jacobian of a residual is obtained through automatic differentiation,
# the return type is BlockArray{<:SubArray} and the behaviour of testvalue
# does not allow broadcasting operations between BlockArray{<:AbstractMatrix}
# and BlockArray{<:SubArray}. This function returns a matrix of size a
# P-dimensional array where each dimension has length 0, i.e., (0, ..., 0).
function testvalue(::Type{<:SubArray{T,P,AT}}) where {T,P,AT}
a = testvalue(AT)
return SubArray(a, ntuple(_ -> 0:-1, P))
end

function testvalue(::Type{T}) where T<:Transpose{E,A} where {E,A}
a = testvalue(A)
Transpose(a)
Expand Down Expand Up @@ -272,5 +282,3 @@ function test_array(
end
true
end


20 changes: 19 additions & 1 deletion src/Exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,25 @@ using Gridap.CellData: ∫; export ∫
@publish Visualization createpvd
@publish Visualization savepvd

include("ODEs/Exports.jl")
@publish ODEs ∂t
@publish ODEs ∂tt
@publish ODEs ForwardEuler
@publish ODEs ThetaMethod
@publish ODEs MidPoint
@publish ODEs BackwardEuler
@publish ODEs GeneralizedAlpha1
@publish ODEs ButcherTableau
@publish ODEs available_tableaus
@publish ODEs RungeKutta
# @publish ODEs GeneralizedAlpha2
# @publish ODEs Newmark
@publish ODEs TransientTrialFESpace
@publish ODEs TransientMultiFieldFESpace
@publish ODEs TransientFEOperator
@publish ODEs TransientIMEXFEOperator
@publish ODEs TransientSemilinearFEOperator
@publish ODEs TransientQuasilinearFEOperator
@publish ODEs TransientLinearFEOperator

# Deprecated / removed

Expand Down
1 change: 1 addition & 0 deletions src/MultiField/MultiFieldCellFields.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,4 @@ num_fields(a::MultiFieldCellField) = length(a.single_fields)
Base.getindex(a::MultiFieldCellField,i::Integer) = a.single_fields[i]
Base.iterate(a::MultiFieldCellField) = iterate(a.single_fields)
Base.iterate(a::MultiFieldCellField,state) = iterate(a.single_fields,state)
Base.length(a::MultiFieldCellField) = num_fields(a)
1 change: 1 addition & 0 deletions src/MultiField/MultiFieldFEFunctions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,4 @@ num_fields(m::MultiFieldFEFunction) = length(m.single_fe_functions)
Base.iterate(m::MultiFieldFEFunction) = iterate(m.single_fe_functions)
Base.iterate(m::MultiFieldFEFunction,state) = iterate(m.single_fe_functions,state)
Base.getindex(m::MultiFieldFEFunction,field_id::Integer) = m.single_fe_functions[field_id]
Base.length(m::MultiFieldFEFunction) = num_fields(m)
30 changes: 0 additions & 30 deletions src/ODEs/Exports.jl

This file was deleted.

Loading

0 comments on commit 92f38a2

Please sign in to comment.