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

Generalization of FESpaceWithLastDofRemoved #396

Merged
merged 17 commits into from
Sep 11, 2020
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
534bc69
Added a new type extension of SingleFieldFESpace, named FESpaceWithDo…
amartinhuertas Aug 25, 2020
a5e00a1
Modified ZeroMeanFESpace such that it no longer depends on FESpaceWit…
amartinhuertas Aug 25, 2020
e020506
Merge branch 'master' of github.com:gridap/Gridap.jl into fe_space_wi…
amartinhuertas Aug 25, 2020
e67c140
Merge branch 'master' of github.com:gridap/Gridap.jl into fe_space_wi…
amartinhuertas Sep 2, 2020
4a9fa27
Generalized _compute_new_fixedval such that it takes the dof which is
amartinhuertas Sep 4, 2020
638fe89
Removed FESpaceWithLastDofRemoved
amartinhuertas Sep 5, 2020
b358318
Removed export from FESpaces.jl
amartinhuertas Sep 5, 2020
faa32a3
Renamed FESpaceWithDofPotentiallyRemoved.jl by FESpaceWithConstantFix…
amartinhuertas Sep 10, 2020
0da971d
Using Traits in order to control whether to fix or do not fix the
amartinhuertas Sep 10, 2020
01c1fa4
Added VectorWithEntryInserted and VectorWithEntryRemoved
amartinhuertas Sep 10, 2020
e4c7b87
Update NEWS.md
amartinhuertas Sep 10, 2020
9ea5851
Update NEWS.md
amartinhuertas Sep 10, 2020
d7f3bc6
Solved syntax error in FESpaceWithConstantFixed
amartinhuertas Sep 10, 2020
4412327
Merge branch 'vector_with_entry_inserted_and_removed' into fe_space_w…
amartinhuertas Sep 10, 2020
7cad067
Missing test files
amartinhuertas Sep 10, 2020
7ac6e1e
Bug-fix in function VectorWithEntryInserted(a::AbstractVector,index::…
amartinhuertas Sep 10, 2020
df737b8
Adapted FESpacesWithConstantFixed to new vectors developed
amartinhuertas Sep 10, 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
5 changes: 3 additions & 2 deletions src/FESpaces/FESpaces.jl
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,8 @@ export collect_cell_jacobian
export collect_cell_jacobian_and_residual
export collect_cell_residual

export FESpaceWithLastDofRemoved
export FESpaceWithConstantFixed

export ZeroMeanFESpace
export CLagrangianFESpace
export ConformingFESpace
Expand Down Expand Up @@ -252,7 +253,7 @@ include("FEOperatorsFromTerms.jl")

include("FESolvers.jl")

include("FESpacesWithLastDofRemoved.jl")
include("FESpacesWithConstantFixed.jl")

include("ZeroMeanFESpaces.jl")

Expand Down
186 changes: 186 additions & 0 deletions src/FESpaces/FESpacesWithConstantFixed.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
abstract type ConstantApproach end;
struct FixConstant <: ConstantApproach end;
struct DoNotFixConstant <: ConstantApproach end;

#"""
# struct FESpaceWithConstantFixed{CS,<:ConstantApproach} <: SingleFieldFESpace
# space::SingleFieldFESpace
# constraint_style::Val{CS}
# dof_to_fix::Int
# end
#"""
struct FESpaceWithConstantFixed{CS,CA<:ConstantApproach} <: SingleFieldFESpace
space::SingleFieldFESpace
constraint_style::Val{CS}
dof_to_fix::Int
@doc """
FESpaceWithConstantFixed(space::SingleFieldFESpace, fix_constant::Bool,
dof_to_fix::Int=num_free_dofs(space))
"""
function FESpaceWithConstantFixed(space::SingleFieldFESpace,
fix_constant::Bool,
dof_to_fix::Int=num_free_dofs(space))
cs = constraint_style(space)
CS = get_val_parameter(cs)
if (fix_constant && num_dirichlet_dofs(space)==0)
new{CS,FixConstant}(space,cs,dof_to_fix)
else
new{CS,DoNotFixConstant}(space,cs,dof_to_fix)
end
end
end

# Genuine functions
function num_free_dofs(f::FESpaceWithConstantFixed{CS,FixConstant}) where {CS}
num_free_dofs(f.space)-1
end

function num_free_dofs(f::FESpaceWithConstantFixed{CS,DoNotFixConstant}) where {CS}
num_free_dofs(f.space)
end

function zero_free_values(f::FESpaceWithConstantFixed)
zeros(num_free_dofs(f))
end

function get_cell_dofs(f::FESpaceWithConstantFixed{CS,FixConstant}) where {CS}
cell_dofs = get_cell_dofs(f.space)
CellDofsWithDofFixed(cell_dofs,f.dof_to_fix)
end

function get_cell_dofs(f::FESpaceWithConstantFixed{CS,DoNotFixConstant}) where {CS}
get_cell_dofs(f.space)
end


num_dirichlet_dofs(f::FESpaceWithConstantFixed{CS,FixConstant}) where {CS} = 1

num_dirichlet_dofs(f::FESpaceWithConstantFixed{CS,DoNotFixConstant}) where {CS} = 0

function zero_dirichlet_values(f::FESpaceWithConstantFixed)
T = Float64 # TODO
zeros(T,num_dirichlet_dofs(f))
end


num_dirichlet_tags(f::FESpaceWithConstantFixed{CS,FixConstant}) where {CS} = 1

num_dirichlet_tags(f::FESpaceWithConstantFixed{CS,DoNotFixConstant}) where {CS} = 0

get_dirichlet_dof_tag(f::FESpaceWithConstantFixed{CS,FixConstant}) where {CS} = Int8[1,]

get_dirichlet_dof_tag(f::FESpaceWithConstantFixed{CS,DoNotFixConstant}) where {CS} = Int8[]

function scatter_free_and_dirichlet_values(
f::FESpaceWithConstantFixed{CS,FixConstant},fv,dv) where {CS}
@assert length(dv) == 1
_dv = similar(dv,eltype(dv),0)
_fv = vcat(view(fv,1:f.dof_to_fix-1),
dv,
view(fv,f.dof_to_fix:length(fv))) # TODO lazy append
scatter_free_and_dirichlet_values(f.space,_fv,_dv)
end

function scatter_free_and_dirichlet_values(
f::FESpaceWithConstantFixed{CS,DoNotFixConstant},fv,dv) where {CS}
@assert length(dv) == 0
scatter_free_and_dirichlet_values(f.space,fv,dv)
end

function gather_free_and_dirichlet_values(
f::FESpaceWithConstantFixed{CS,FixConstant},cv) where {CS}
_fv, _dv = gather_free_and_dirichlet_values(f.space,cv)
@assert length(_dv) == 0
fv = vcat(view(_fv,1:f.dof_to_fix-1),
view(_fv,f.dof_to_fix+1:length(_fv))) # TODO: can we avoid
# allocating new memory?
dv = view(_fv,f.dof_to_fix:f.dof_to_fix)
(fv, dv)
end

function gather_free_and_dirichlet_values(
f::FESpaceWithConstantFixed{CS,DoNotFixConstant},cv) where {CS}
gather_free_and_dirichlet_values(f.space,cv)
end

function gather_free_and_dirichlet_values!(
fv,dv,f::FESpaceWithConstantFixed{CS,FixConstant},cv) where {CS}
_fv, _dv = gather_free_and_dirichlet_values(f.space,cv)
@assert length(_dv) == 0
fv .= vcat(view(_fv,1:f.dof_to_fix-1),
view(_fv,f.dof_to_fix+1:length(_fv))) # TODO: can we avoid
# allocating new memory?
dv .= view(_fv,f.dof_to_fix:f.dof_to_fix)
(fv, dv)
end

function gather_free_and_dirichlet_values!(
fv,dv,f::FESpaceWithConstantFixed{CS,DoNotFixConstant},cv) where {CS}
gather_free_and_dirichlet_values(f.space,cv)
end

function TrialFESpace(f::FESpaceWithConstantFixed{CS,CA}) where {CS,CA}
U = TrialFESpace(f.space)
FESpaceWithConstantFixed{CS,CA}(U,f.dof_to_fix)
end

# Delegated functions

function get_cell_basis(f::FESpaceWithConstantFixed)
get_cell_basis(f.space)
end

function get_cell_dof_basis(f::FESpaceWithConstantFixed)
get_cell_dof_basis(f.space)
end

get_cell_axes(t::FESpaceWithConstantFixed)= get_cell_axes(t.space)

get_cell_axes_with_constraints(t::FESpaceWithConstantFixed)= get_cell_axes_with_constraints(t.space)

CellData.CellField(t::FESpaceWithConstantFixed,cell_vals) = CellField(t.space,cell_vals)

constraint_style(::Type{<:FESpaceWithConstantFixed{CS}}) where CS = Val{CS}()

# Helpers

struct CellDofsWithDofFixed{A<:AbstractArray} <: AbstractVector{Vector{Int}}
cell_dofs::A
dof_to_fix::Int
end

Base.size(a::CellDofsWithDofFixed) = (length(a.cell_dofs),)

Base.IndexStyle(::Type{<:CellDofsWithDofFixed}) = IndexLinear()

function Base.getindex(a::CellDofsWithDofFixed,i::Integer)
cache = array_cache(a)
getindex!(cache,a,i)
end

function array_cache(a::CellDofsWithDofFixed)
@assert eltype(a.cell_dofs) == Vector{Int}
b = testitem(a.cell_dofs)
c = CachedArray(b)
cache = array_cache(a.cell_dofs)
(c, cache)
end

@inline function getindex!(d,a::CellDofsWithDofFixed,i::Integer)
c, cache = d
b = getindex!(cache,a.cell_dofs,i)
setsize!(c,size(b))
r = c.array
for j in 1:length(b)
bj = b[j]
if bj == a.dof_to_fix
rj = -1
elseif bj < a.dof_to_fix
rj = bj
else
rj = bj-1
end
r[j] = rj
end
r
end
140 changes: 0 additions & 140 deletions src/FESpaces/FESpacesWithLastDofRemoved.jl

This file was deleted.

Loading