Skip to content

Commit 5d369ef

Browse files
authored
Merge pull request #963 from gridap/allocate-vectors
Changing behaviour for `allocate_vector`
2 parents 68db8cb + 5438ce0 commit 5d369ef

File tree

7 files changed

+17
-15
lines changed

7 files changed

+17
-15
lines changed

NEWS.md

+6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## Unreleased
9+
10+
### Changed
11+
12+
- 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).
13+
814
## [0.17.21] - 2023-12-04
915

1016
### Added

src/Algebra/AlgebraInterfaces.jl

+2-3
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ function allocate_vector(::Type{V},indices) where V
3737
end
3838

3939
function allocate_vector(::Type{V},n::Integer) where V
40-
T = eltype(V)
41-
zeros(T,n)
40+
V(undef,n)
4241
end
4342

4443
function allocate_vector(::Type{<:BlockVector{T,VV}},indices::BlockedUnitRange) where {T,VV}
@@ -86,7 +85,7 @@ end
8685
Allocate a vector in the domain of matrix `matrix`.
8786
"""
8887
function allocate_in_domain(matrix::AbstractMatrix{T}) where T
89-
allocate_in_range(Vector{T},matrix)
88+
allocate_in_domain(Vector{T},matrix)
9089
end
9190

9291
function allocate_in_domain(matrix::BlockMatrix{T}) where T

src/FESpaces/FESpaceInterface.jl

+3-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,9 @@ num_free_dofs(f::FESpace) = length(get_free_dof_ids(f))
8787
"""
8888
function zero_free_values(f::FESpace)
8989
V = get_vector_type(f)
90-
allocate_vector(V,num_free_dofs(f))
90+
free_values = allocate_vector(V,get_free_dof_ids(f))
91+
fill!(free_values,zero(eltype(V)))
92+
return free_values
9193
end
9294

9395
function get_vector_type(fs::FESpace)

src/FESpaces/SingleFieldFESpaces.jl

+3-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ num_dirichlet_dofs(f::SingleFieldFESpace) = length(get_dirichlet_dof_ids(f))
1616
"""
1717
function zero_dirichlet_values(f::SingleFieldFESpace)
1818
V = get_vector_type(f)
19-
allocate_vector(V,num_dirichlet_dofs(f))
19+
dir_values = allocate_vector(V,num_dirichlet_dofs(f))
20+
fill!(dir_values,zero(eltype(V)))
21+
return dir_values
2022
end
2123

2224
"""

src/FESpaces/UnconstrainedFESpaces.jl

-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ end
4848

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

6261
get_dirichlet_dof_ids(f::UnconstrainedFESpace) = Base.OneTo(f.ndirichlet)
6362
num_dirichlet_tags(f::UnconstrainedFESpace) = f.ntags
64-
zero_dirichlet_values(f::UnconstrainedFESpace) = allocate_vector(f.vector_type,num_dirichlet_dofs(f))
6563
get_dirichlet_dof_tag(f::UnconstrainedFESpace) = f.dirichlet_dof_tag
6664

6765
function scatter_free_and_dirichlet_values(f::UnconstrainedFESpace,free_values,dirichlet_values)

src/MultiField/MultiFieldFESpaces.jl

-7
Original file line numberDiff line numberDiff line change
@@ -137,13 +137,6 @@ function FESpaces.get_free_dof_ids(f::MultiFieldFESpace,::BlockMultiFieldStyle{N
137137
return BlockArrays.blockedrange(block_num_dofs)
138138
end
139139

140-
function FESpaces.zero_free_values(f::MultiFieldFESpace{<:BlockMultiFieldStyle{NB,SB,P}}) where {NB,SB,P}
141-
block_ranges = get_block_ranges(NB,SB,P)
142-
block_num_dofs = map(range->sum(map(num_free_dofs,f.spaces[range])),block_ranges)
143-
block_vtypes = map(range->get_vector_type(first(f.spaces[range])),block_ranges)
144-
return mortar(map(allocate_vector,block_vtypes,block_num_dofs))
145-
end
146-
147140
FESpaces.get_dof_value_type(f::MultiFieldFESpace{MS,CS,V}) where {MS,CS,V} = eltype(V)
148141

149142
FESpaces.get_vector_type(f::MultiFieldFESpace) = f.vector_type

src/ODEs/TransientFETools/TransientFESpaces.jl

+3-1
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,9 @@ function zero_free_values(f::TransientMultiFieldTrialFESpace{<:BlockMultiFieldSt
206206
block_ranges = get_block_ranges(NB,SB,P)
207207
block_num_dofs = map(range->sum(map(num_free_dofs,f.spaces[range])),block_ranges)
208208
block_vtypes = map(range->get_vector_type(first(f.spaces[range])),block_ranges)
209-
return mortar(map(allocate_vector,block_vtypes,block_num_dofs))
209+
values = mortar(map(allocate_vector,block_vtypes,block_num_dofs))
210+
fill!(values,zero(eltype(values)))
211+
return values
210212
end
211213

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

0 commit comments

Comments
 (0)