diff --git a/NEWS.md b/NEWS.md index c261ebe87..469a0e12a 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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 diff --git a/src/Arrays/Apply.jl b/src/Arrays/Apply.jl index dba83dbb6..7f13c0804 100644 --- a/src/Arrays/Apply.jl +++ b/src/Arrays/Apply.jl @@ -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...) diff --git a/src/FESpaces/ExtendedFESpaces.jl b/src/FESpaces/ExtendedFESpaces.jl index fa7302023..6f62a77e5 100644 --- a/src/FESpaces/ExtendedFESpaces.jl +++ b/src/FESpaces/ExtendedFESpaces.jl @@ -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 @@ -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) diff --git a/src/FESpaces/FESpaces.jl b/src/FESpaces/FESpaces.jl index c833adc69..7fe81ebd7 100644 --- a/src/FESpaces/FESpaces.jl +++ b/src/FESpaces/FESpaces.jl @@ -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 @@ -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 diff --git a/src/Visualization/PrintOpTrees.jl b/src/Visualization/PrintOpTrees.jl index 5cd299fdf..666f6fa18 100644 --- a/src/Visualization/PrintOpTrees.jl +++ b/src/Visualization/PrintOpTrees.jl @@ -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 diff --git a/test/FESpacesTests/ExtendedFESpacesTests.jl b/test/FESpacesTests/ExtendedFESpacesTests.jl index 77ba8b4f9..1cbb968e0 100644 --- a/test/FESpacesTests/ExtendedFESpacesTests.jl +++ b/test/FESpacesTests/ExtendedFESpacesTests.jl @@ -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