Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gridap distributed #249

Merged
merged 20 commits into from
May 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
d562ce1
Added algebra interfaces
fverdugo May 5, 2020
0b06cf3
Simplifying zero_initial_guess
fverdugo May 5, 2020
b684406
Writing operators and solvers in terms of the new algebra interface
fverdugo May 5, 2020
c61b1b5
Simplified API of zero_free_values
fverdugo May 5, 2020
e21242e
Moving to v0.10.0
fverdugo May 5, 2020
def8485
moving allocate_{vector,matrix,matrix_and_vector} to Gridap.Algebra
fverdugo May 5, 2020
a505c58
More work in Algebra interface
fverdugo May 5, 2020
0cd4a4a
Merge branch 'master' of https://github.com/gridap/Gridap.jl into Gri…
amartinhuertas May 6, 2020
d0c748c
Added AssemblyStrategy and changed test/trial in single field assembler
fverdugo May 6, 2020
cfb46ed
Added SparseMatrixAssembler interface
fverdugo May 6, 2020
9fcaca4
Refactored MultiFieldSparseMatrixAssembler
fverdugo May 6, 2020
5f4f63b
Simplified Assembler interface
fverdugo May 7, 2020
90f51db
Merge branch 'master' of github.com:gridap/Gridap.jl into GridapDistr…
fverdugo May 7, 2020
048f404
Moved inner to outer constructor in FEOperatorFromTerms
fverdugo May 7, 2020
1a101e8
Update NEWS.md
amartinhuertas May 12, 2020
996dc0d
Merge branch 'master' of github.com:gridap/Gridap.jl into GridapDistr…
fverdugo May 14, 2020
6159753
Updating FESpacesWithLinearConstraints to new interface
fverdugo May 14, 2020
5d38d2e
Extending TriangulationPortion to boundary case
fverdugo May 14, 2020
6c32cca
Extended TriangulationPortion to skeleton case
fverdugo May 14, 2020
1b6161f
Updated NEWS.md
fverdugo May 14, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,24 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- Extended support of `TriangulationPortion` to boundary and skeleton triangulations. Since PR ...
- Added `FESpaceWithLinearConstraints`. Since PR [#247](https://github.com/gridap/Gridap.jl/pull/247).
- Added inner constructor to `CartesianDiscreteModel` allowing to build a model that represents a subgrid of
a larger grid. Since PR [#245](https://github.com/gridap/Gridap.jl/pull/245).

### Changed

- The part associated with the imposition of constraints in the `FESpace` interface has changed slightly. Since PR [#247](https://github.com/gridap/Gridap.jl/pull/247).
- Simplified the signature of `zero_free_values(::FESpace)`. Since PR ...
- Major refactoring in the `Assembler` interface.
**Important change:** assembly-related functions take the data returned by functions like
`collect_cell_matrix` as it is. Example: the old user code `assemble_matrix(assembler,collect_cell_matrix(du,dv,terms)...)`
now is written simply as `assemble_matrix(assembler,collect_cell_matrix(du,dv,terms))`, i.e., the unpack of the last argument is not
used anymore. With new new assembler interface, it is also possible to customize the assembly process
via a so-called `AssemblerStrategy` object. Since PR ...
- Change the types of the sizes and partition fields of CartesianDescriptor to tuples instead of points.
Since PR [#246](https://github.com/gridap/Gridap.jl/pull/246).


## [0.9.2] - 2020-4-26

### Added
Expand Down
21 changes: 20 additions & 1 deletion src/Algebra/Algebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,19 @@ using Test

using Gridap.Helpers

import Base: convert, size, getindex, show, count, *
import LinearAlgebra: mul!
import SparseArrays: nnz, nonzeros, nzrange, findnz, rowvals

export allocate_vector
export allocate_matrix
export allocate_matrix_and_vector
export allocate_in_domain
export allocate_in_range
export add_entries!
export scale_entries!
export muladd!

export push_coo!
export is_entry_stored
export finalize_coo!
Expand Down Expand Up @@ -71,12 +84,18 @@ export get_vector
export SparseMatrixCSR
export SymSparseMatrixCSR

include("MethodsAbstractMatrices.jl")
include("AlgebraInterfaces.jl")

include("SparseMatrices.jl")

include("CompressedSparseMatrices.jl")

include("SparseMatrixCSC.jl")

include("SparseMatrixCSR.jl")

include("SymSparseMatrixCSR.jl")

include("NonlinearOperators.jl")

include("NonlinearSolvers.jl")
Expand Down
135 changes: 135 additions & 0 deletions src/Algebra/AlgebraInterfaces.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@

function allocate_matrix end
function allocate_matrix_and_vector end

"""
allocate_vector(::Type{V},indices) where V

Allocate a vector of type `V` indexable at the incides `indices`
"""
function allocate_vector(::Type{V},indices) where V
n = length(indices)
allocate_vector(V,n)
end

function allocate_vector(::Type{V},n::Integer) where V
T = eltype(V)
zeros(T,n)
end

"""
allocate_in_range(::Type{V},matrix) where V

Allocate a vector of type `V` in the range of matrix `matrix`.
"""
function allocate_in_range(::Type{V},matrix) where V
n = size(matrix,1)
allocate_vector(V,n)
end

"""
allocate_in_domain(::Type{V},matrix) where V

Allocate a vector of type `V` in the domain of matrix `matrix`.
"""
function allocate_in_domain(::Type{V},matrix) where V
n = size(matrix,2)
allocate_vector(V,n)
end

"""
fill_entries!(a,v)

Fill the entries of array `a` with the value `v`. Returns `a`.
"""
function fill_entries!(a,v)
fill!(a,v)
a
end

"""
copy_entries!(a,b)

Copy the entries of array `b` into array `a`. Returns `a`.
"""
function copy_entries!(a,b)
if a !== b
copyto!(a,b)
end
a
end

"""
add_entries!(a,b,combine=+)

Perform the operation `combine` element-wise in the entries of arrays `a` and `b`
and store the result in array `a`. Returns `a`.
"""
function add_entries!(a,b,combine=+)
@assert length(a) == length(b)
@inbounds for i in eachindex(a)
a[i] = combine(a[i],b[i])
end
a
end

"""
add_entry!(A,v,i,j,combine=+)

Add an entry given its position and the operation to perform.
"""
function add_entry!(A,v,i::Integer,j::Integer,combine=+)
aij = A[i,j]
A[i,j] = combine(aij,v)
end

"""
add_entry!(A,v,i,combine=+)

Add an entry given its position and the operation to perform.
"""
function add_entry!(A,v,i::Integer,combine=+)
ai = A[i]
A[i] = combine(ai,v)
end

"""
scale_entries!(a,v)

Scale the entries of array `a` with the value `v`. Returns `a`.
"""
function scale_entries!(a,b)
@inbounds for i in eachindex(a)
a[i] = b*a[i]
end
a
end

# Base.mul!

"""
muladd!(c,a,b)

Matrix multiply a*b and add to result to c. Returns c.
"""
function muladd!(c,a,b)
_muladd!(c,a,b)
c
end

@static if VERSION >= v"1.3"
function _muladd!(c,a,b)
mul!(c,a,b,1,1)
end
else
function _muladd!(c,a,b)
@assert length(c) == size(a,1)
@assert length(b) == size(a,2)
@inbounds for j in 1:size(a,2)
for i in 1:size(a,1)
c[i] += a[i,j]*b[j]
end
end
end
end

34 changes: 0 additions & 34 deletions src/Algebra/CompressedSparseMatrices.jl
Original file line number Diff line number Diff line change
@@ -1,34 +1,4 @@

# CompressedSparseMatrices implementation contains:
#
# - Data types:
# + `SparseMatrixCSR`:Compressed Sparse Row (CSR) sparse matrix implementation with Bi-based indexing.
# + `SymSparseMatrixCSR`: Symmetric Compressed Sparse Row sparse matrix implementation with Bi-based indexing.
#
# - Procedures:
# + `sparsecsr`: Analogous method to [`sparse`](@ref) function to build a SparseMatrixCSR.
# + `symsparsecsr`: Analogous method to [`sparse`](@ref) function to build a SymSparseMatrixCSR.
# + `colvals`: Analogous method to [`rowvals`](@ref) to return `colvals` array.
# + `hasrowmajororder`: Return `true` if matrix values are ordered by row.
# + `hascolmajororder`: Return `true` if matrix values are ordered by column.
# + `getptr`: Return the pointer array of a SparseMatrix (`rowptr` or `colptr` depending on the SparseMatrix type)
# + `getindices`: Return the indices array of a SparseMatrix (`rowval` or `colval` depending on the SparseMatrix type)
#
# - Overloaded procedures:
# + `*`: SparseMatrix-Vector product.
# + `mul!`: SparseMatrix-Vector product.
# + `nnz`: Return the number of stored (filled) elements in a sparse array.
# + `nonzeros`: Return `nzval` array.
# + `nzrange`: Return the range of indices for a particular row or column (Depending on the SparseMatrix type)
# + `findnz`: Return a tuple (I, J, V) where I and J are the row and column indices.
# + `rowvals`: Return row indices or raises an error (Depending on the SparseMatrix type)
# + `convert`: Type conversion
# + `count`: Count the number of elements in nonzeros(S) for which predicate pred returns true.

import Base: convert, size, getindex, show, count, *
import LinearAlgebra: mul!
import SparseArrays: nnz, nonzeros, nzrange, findnz, rowvals

"""
hasrowmajororder(::Type{AbstractSparseMatrix})

Expand Down Expand Up @@ -157,7 +127,3 @@ function fill_entries!(A::AbstractSparseMatrix{Tv,Ti},v::Number) where {Tv,Ti}
nonzeros(A) .= convert(Tv,v)
end


include("SparseMatrixCSC.jl")
include("SparseMatrixCSR.jl")
include("SymSparseMatrixCSR.jl")
25 changes: 14 additions & 11 deletions src/Algebra/LinearSolvers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ get_vector(op::AffineOperator) = op.vector

function residual!(b::AbstractVector,op::AffineOperator,x::AbstractVector)
mul!(b,op.matrix,x)
b .-= op.vector
add_entries!(b,op.vector,-)
b
end

Expand All @@ -33,13 +33,14 @@ function jacobian(op::AffineOperator,x::AbstractVector)
op.matrix
end

function zero_initial_guess(::Type{T},op::AffineOperator) where T
n = size(op.matrix,2)
zeros(T,n)
function zero_initial_guess(op::AffineOperator)
x = allocate_in_domain(typeof(op.vector),op.matrix)
fill_entries!(x,zero(eltype(x)))
x
end

function allocate_residual(op::AffineOperator,x::AbstractVector)
similar(x,eltype(x),length(op.vector))
allocate_in_range(typeof(op.vector),op.matrix)
end

function allocate_jacobian(op::AffineOperator,x::AbstractVector)
Expand Down Expand Up @@ -151,12 +152,12 @@ function solve!(x::AbstractVector,
ls::LinearSolver,
op::NonlinearOperator,
cache::Nothing)
x .= zero(eltype(x))
fill_entries!(x,zero(eltype(x)))
b = residual(op, x)
A = jacobian(op, x)
ss = symbolic_setup(ls, A)
ns = numerical_setup(ss,A)
broadcast!(*,b,b,-1)
scale_entries!(b,-1)
solve!(x,ns,b)
LinearSolverCache(A,b,ns)
end
Expand All @@ -165,13 +166,13 @@ function solve!(x::AbstractVector,
ls::LinearSolver,
op::NonlinearOperator,
cache)
x .= zero(eltype(x))
fill_entries!(x,zero(eltype(x)))
b = cache.b
A = cache.A
ns = cache.ns
residual!(b, op, x)
numerical_setup!(ns,A)
broadcast!(*,b,b,-1)
scale_entries!(b,-1)
solve!(x,ns,b)
cache
end
Expand Down Expand Up @@ -238,7 +239,8 @@ end
function solve!(
x::AbstractVector,ns::LUNumericalSetup,b::AbstractVector)
y = ns.factors\b # the allocation of y can be avoided
x .= y
copy_entries!(x,y)
x
end

"""
Expand All @@ -265,5 +267,6 @@ end

function solve!(
x::AbstractVector,ns::BackslashNumericalSetup,b::AbstractVector)
copyto!(x, ns.A\b)
copy_entries!(x, ns.A\b)
end

3 changes: 0 additions & 3 deletions src/Algebra/MethodsAbstractMatrices.jl

This file was deleted.

6 changes: 3 additions & 3 deletions src/Algebra/NLSolvers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ function _solve_nr!(x,A,b,dx,ns,nls,op)
for nliter in 1:nls.max_nliters

# Solve linearized problem
broadcast!(*,b,b,-1)
scale_entries!(b,-1)
solve!(dx,ns,b)
broadcast!(+,x,x,dx)
add_entries!(x,dx)

# Check convergence for the current residual
residual!(b, op, x)
Expand Down Expand Up @@ -157,7 +157,7 @@ function _nlsolve_with_updated_cache!(x,nls,op,cache)
end
r = nlsolve(df,x;linsolve=linsolve!,kwargs...)
cache.result = r
x[:] .= r.zero
copy_entries!(x,r.zero)
end

function _new_nlsolve_cache(x0,nls,op)
Expand Down
Loading