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

Fix interpolate extended fe space #282

Merged
merged 2 commits into from
Jun 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 7 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ 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]

### Fixed

- Bug that showed up when interpolating a FE function defined on an
`ExtendedFESpace` onto a non-extended `FESpace`. Fixed via PR [#282](https://github.com/gridap/Gridap.jl/pull/282).

## [0.11.0] - 2020-6-16

### Added
Expand Down
4 changes: 2 additions & 2 deletions src/Arrays/Apply.jl
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,9 @@ function _array_cache(hash,a::AppliedArray)
cg = array_cache(hash,a.g)
gi = testitem(a.g)
fi = testitems(a.f...)
@notimplementedif any( map(isabstracttype,map(eltype,a.f)) )
@notimplementedif ! all( map(isconcretetype,map(eltype,a.f)) )
if ! (eltype(a.g)<:Function)
@notimplementedif isabstracttype(eltype(a.g))
@notimplementedif ! isconcretetype(eltype(a.g))
end
cf = array_caches(hash,a.f...)
cgi = kernel_cache(gi,fi...)
Expand Down
53 changes: 53 additions & 0 deletions src/FESpaces/ExtendedFESpaces.jl
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,27 @@ function evaluate_field_array(a::ExtendedVector,x::AbstractArray)
a.cell_to_oldcell)
end

function evaluate_dof_array(dofs::AbstractArray,fields::ExtendedVector)
_evaluate_dof_array_extended_fields(dofs,fields)
end

function evaluate_dof_array(dofs::AbstractArray{<:Dof},fields::ExtendedVector)
_evaluate_dof_array_extended_fields(dofs,fields)
end

function _evaluate_dof_array_extended_fields(dofs,fields)
dofs_void = reindex(dofs,fields.void_to_oldcell)
dofs_cell = reindex(dofs,fields.cell_to_oldcell)
r_void = evaluate_dof_array(dofs_void,fields.void_to_val)
r_cell = evaluate_dof_array(dofs_cell,fields.cell_to_val)
ExtendedVector(
r_void,
r_cell,
fields.oldcell_to_cell_or_void,
fields.void_to_oldcell,
fields.cell_to_oldcell)
end

function reindex(a::ExtendedVector,ptrs::AbstractArray)
_extended_reindex(a,ptrs)
end
Expand All @@ -81,6 +102,38 @@ function reindex(a::ExtendedVector,ptrs::SkeletonPair)
_extended_reindex(a,ptrs::SkeletonPair)
end

function apply(f::Fill,a::ExtendedVector...)
a_void, a_cell = _split_void_non_void(a...)
r_void = apply(f.value,a_void...)
r_cell = apply(f.value,a_cell...)
ExtendedVector(
r_void,
r_cell,
a[1].oldcell_to_cell_or_void,
a[1].void_to_oldcell,
a[1].cell_to_oldcell)
end

function apply(::Type{T},f::Fill,a::ExtendedVector...) where T
a_void, a_cell = _split_void_non_void(a...)
r_void = apply(T,f.value,a_void...)
r_cell = apply(T,f.value,a_cell...)
ExtendedVector(
r_void,
r_cell,
a[1].oldcell_to_cell_or_void,
a[1].void_to_oldcell,
a[1].cell_to_oldcell)
end

function _split_void_non_void(a::ExtendedVector...)
@notimplementedif ! all(map(i->i.void_to_oldcell===a[1].void_to_oldcell,a))
@notimplementedif ! all(map(i->i.cell_to_oldcell===a[1].cell_to_oldcell,a))
a_void = map(i->i.void_to_val,a)
a_cell = map(i->i.cell_to_val,a)
a_void, a_cell
end

#function reindex(a::ExtendedVector,trian::Triangulation)
# ptrs = get_cell_id(trian)
# _extended_reindex(a,ptrs)
Expand Down
2 changes: 2 additions & 0 deletions src/FESpaces/FESpaces.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import Gridap.Arrays: apply_kernel!
import Gridap.Arrays: kernel_return_type
import Gridap.Arrays: apply_kernel_for_cache!
import Gridap.Arrays: reindex
import Gridap.Arrays: apply
import Gridap.Geometry: get_cell_map
import Gridap.Geometry: get_cell_shapefuns
import Gridap.Geometry: get_reffes
Expand All @@ -57,6 +58,7 @@ import Gridap.Fields: evaluate
import Gridap.Fields: gradient
import Gridap.Fields: grad2curl
import Gridap.Fields: evaluate_field_array
import Gridap.ReferenceFEs: evaluate_dof_array
import Gridap.Fields: field_cache
import Gridap.Fields: evaluate_field!
import Gridap.Fields: field_gradient
Expand Down
6 changes: 6 additions & 0 deletions src/Visualization/PrintOpTrees.jl
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,9 @@ function get_children(n::TreeNode, a::Arrays.Table)
(similar_tree_node(n,a.data),similar_tree_node(n,a.ptrs))
end

function get_children(n::TreeNode, a::FESpaces.ExtendedVector)
(
similar_tree_node(n,a.void_to_val),
similar_tree_node(n,a.cell_to_val)
)
end
10 changes: 10 additions & 0 deletions test/FESpacesTests/ExtendedFESpacesTests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,14 @@ V = TestFESpace(triangulation=trian,valuetype=Float64,reffe=:Lagrangian,order=2,
#writevtk(trian,"trian",cellfields=["uh"=>uh])
#writevtk(trian_in,"trian_in",cellfields=["uh"=>uh_in])

V_in = TestFESpace(model=model_in,valuetype=Float64,reffe=:Lagrangian,order=2,conformity=:H1)
V = TestFESpace(model=model,valuetype=Float64,reffe=:Lagrangian,order=2,conformity=:H1)

vh_in = interpolate(V_in,x->x[1])
vh_in = interpolate(V_in,vh_in)
vh = interpolate(V,vh_in)

#using Gridap.Visualization
#writevtk(trian,"trian",cellfields=["vh"=>vh,"vh_in"=>vh_in])

end # module