Skip to content

Commit

Permalink
Merge pull request #963 from gridap/allocate-vectors
Browse files Browse the repository at this point in the history
Changing behaviour for `allocate_vector`
  • Loading branch information
JordiManyer authored Dec 7, 2023
2 parents 68db8cb + 5438ce0 commit 5d369ef
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 15 deletions.
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased

### Changed

- Changed how `allocate_vector` works. Now it only allocates, instead of allocating+initialising to zero. Since PR[#963](https://github.com/gridap/Gridap.jl/pull/963).

## [0.17.21] - 2023-12-04

### Added
Expand Down
5 changes: 2 additions & 3 deletions src/Algebra/AlgebraInterfaces.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ function allocate_vector(::Type{V},indices) where V
end

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

function allocate_vector(::Type{<:BlockVector{T,VV}},indices::BlockedUnitRange) where {T,VV}
Expand Down Expand Up @@ -86,7 +85,7 @@ end
Allocate a vector in the domain of matrix `matrix`.
"""
function allocate_in_domain(matrix::AbstractMatrix{T}) where T
allocate_in_range(Vector{T},matrix)
allocate_in_domain(Vector{T},matrix)
end

function allocate_in_domain(matrix::BlockMatrix{T}) where T
Expand Down
4 changes: 3 additions & 1 deletion src/FESpaces/FESpaceInterface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ num_free_dofs(f::FESpace) = length(get_free_dof_ids(f))
"""
function zero_free_values(f::FESpace)
V = get_vector_type(f)
allocate_vector(V,num_free_dofs(f))
free_values = allocate_vector(V,get_free_dof_ids(f))
fill!(free_values,zero(eltype(V)))
return free_values
end

function get_vector_type(fs::FESpace)
Expand Down
4 changes: 3 additions & 1 deletion src/FESpaces/SingleFieldFESpaces.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ num_dirichlet_dofs(f::SingleFieldFESpace) = length(get_dirichlet_dof_ids(f))
"""
function zero_dirichlet_values(f::SingleFieldFESpace)
V = get_vector_type(f)
allocate_vector(V,num_dirichlet_dofs(f))
dir_values = allocate_vector(V,num_dirichlet_dofs(f))
fill!(dir_values,zero(eltype(V)))
return dir_values
end

"""
Expand Down
2 changes: 0 additions & 2 deletions src/FESpaces/UnconstrainedFESpaces.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ end

ConstraintStyle(::Type{<:UnconstrainedFESpace}) = UnConstrained()
get_free_dof_ids(f::UnconstrainedFESpace) = Base.OneTo(f.nfree)
zero_free_values(f::UnconstrainedFESpace) = allocate_vector(f.vector_type,num_free_dofs(f))
get_fe_basis(f::UnconstrainedFESpace) = f.fe_basis
get_fe_dof_basis(f::UnconstrainedFESpace) = f.fe_dof_basis
get_cell_dof_ids(f::UnconstrainedFESpace) = f.cell_dofs_ids
Expand All @@ -61,7 +60,6 @@ get_cell_is_dirichlet(f::UnconstrainedFESpace) = f.cell_is_dirichlet

get_dirichlet_dof_ids(f::UnconstrainedFESpace) = Base.OneTo(f.ndirichlet)
num_dirichlet_tags(f::UnconstrainedFESpace) = f.ntags
zero_dirichlet_values(f::UnconstrainedFESpace) = allocate_vector(f.vector_type,num_dirichlet_dofs(f))
get_dirichlet_dof_tag(f::UnconstrainedFESpace) = f.dirichlet_dof_tag

function scatter_free_and_dirichlet_values(f::UnconstrainedFESpace,free_values,dirichlet_values)
Expand Down
7 changes: 0 additions & 7 deletions src/MultiField/MultiFieldFESpaces.jl
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,6 @@ function FESpaces.get_free_dof_ids(f::MultiFieldFESpace,::BlockMultiFieldStyle{N
return BlockArrays.blockedrange(block_num_dofs)
end

function FESpaces.zero_free_values(f::MultiFieldFESpace{<:BlockMultiFieldStyle{NB,SB,P}}) where {NB,SB,P}
block_ranges = get_block_ranges(NB,SB,P)
block_num_dofs = map(range->sum(map(num_free_dofs,f.spaces[range])),block_ranges)
block_vtypes = map(range->get_vector_type(first(f.spaces[range])),block_ranges)
return mortar(map(allocate_vector,block_vtypes,block_num_dofs))
end

FESpaces.get_dof_value_type(f::MultiFieldFESpace{MS,CS,V}) where {MS,CS,V} = eltype(V)

FESpaces.get_vector_type(f::MultiFieldFESpace) = f.vector_type
Expand Down
4 changes: 3 additions & 1 deletion src/ODEs/TransientFETools/TransientFESpaces.jl
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,9 @@ function zero_free_values(f::TransientMultiFieldTrialFESpace{<:BlockMultiFieldSt
block_ranges = get_block_ranges(NB,SB,P)
block_num_dofs = map(range->sum(map(num_free_dofs,f.spaces[range])),block_ranges)
block_vtypes = map(range->get_vector_type(first(f.spaces[range])),block_ranges)
return mortar(map(allocate_vector,block_vtypes,block_num_dofs))
values = mortar(map(allocate_vector,block_vtypes,block_num_dofs))
fill!(values,zero(eltype(values)))
return values
end

get_dof_value_type(f::TransientMultiFieldTrialFESpace{MS,CS,V}) where {MS,CS,V} = eltype(V)
Expand Down

0 comments on commit 5d369ef

Please sign in to comment.