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

Bugfix in gradient of functions / bases on ExtendedFESpace #219

Merged
merged 1 commit into from
Mar 24, 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
11 changes: 7 additions & 4 deletions src/FESpaces/ExtendedFESpaces.jl
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ function _find_all_cell_all_void(j_to_cell_or_void)
all_cell, all_void
end

struct VoidBasis{T} <: Field end
struct VoidBasis{T,D} <: Field end

function field_cache(f::VoidBasis{T},x) where T
Q = length(x)
Expand All @@ -132,8 +132,10 @@ end
cache.array
end

function field_gradient(f::VoidBasis{T}) where T
VoidBasis{eltype(T)}()
function field_gradient(f::VoidBasis{T,D}) where {T,D}
x = zero(Point{D,eltype(T)})
G = gradient_type(T,x)
VoidBasis{G,D}()
end

"""
Expand Down Expand Up @@ -169,7 +171,8 @@ function get_cell_basis(f::ExtendedFESpace)
vi = testitem(cell_to_val)
Tv = field_return_type(vi,xi)
T = eltype(Tv)
void_to_val = Fill(VoidBasis{T}(),length(f.trian.void_to_oldcell))
D = n_components(eltype(xi))
void_to_val = Fill(VoidBasis{T,D}(),length(f.trian.void_to_oldcell))

array = ExtendedVector(
void_to_val,
Expand Down
13 changes: 8 additions & 5 deletions test/FESpacesTests/ExtendedFESpacesTests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module ExtendedFESpacesTests

using Test
using Gridap.Arrays
using Gridap.TensorValues
using Gridap.Algebra
using Gridap.ReferenceFEs
using Gridap.Geometry
Expand Down Expand Up @@ -61,7 +62,7 @@ quad_in = CellQuadrature(trian_in,2*order)

quad_Γ = CellQuadrature(trian_Γ,2*order)

reffes = [LagrangianRefFE(Float64,get_polytope(p),order) for p in get_reffes(trian_in)]
reffes = [LagrangianRefFE(VectorValue{2,Float64},get_polytope(p),order) for p in get_reffes(trian_in)]

V_in = DiscontinuousFESpace(reffes,trian_in)

Expand All @@ -72,7 +73,7 @@ test_single_field_fe_space(V)
U = TrialFESpace(V)
test_single_field_fe_space(U)

u(x) = x[1]+x[2]
u(x) = VectorValue(x[1]+x[2], x[1])

uh = interpolate(U,u)

Expand All @@ -81,17 +82,17 @@ uh_in = restrict(uh,trian_in)

uh_Γ = restrict(uh,trian_Γ)

t_in = AffineFETerm( (u,v) -> v*u, (v) -> v*4, trian_in, quad_in)
t_in = AffineFETerm( (u,v) -> v*u, (v) -> v*u, trian_in, quad_in)
op_in = AffineFEOperator(U,V,t_in)

quad = CellQuadrature(trian,2*order)

t_Ω = AffineFETerm( (u,v) -> v*u, (v) -> v*4, trian, quad)
t_Ω = AffineFETerm( (u,v) -> v*u, (v) -> v*u, trian, quad)
op_Ω = AffineFEOperator(U,V,t_Ω)

@test get_vector(op_in) ≈ get_vector(op_Ω)

t_Γ = AffineFETerm( (u,v) -> jump(v)*jump(u), (v) -> jump(v)*4, trian_Γ, quad_Γ)
t_Γ = AffineFETerm( (u,v) -> jump(v)*jump(u) + inner(jump(ε(v)),jump(ε(u))), (v) -> jump(v)*u, trian_Γ, quad_Γ)
op_Γ = AffineFEOperator(U,V,t_Γ)

q_in = get_coordinates(quad_in)
Expand All @@ -102,6 +103,8 @@ collect(evaluate(uh,q))

q_Γ = get_coordinates(quad_Γ)
collect(evaluate(jump(uh_Γ),q_Γ))
collect(evaluate(jump(∇(uh_Γ)),q_Γ))
collect(evaluate(jump(ε(uh_Γ)),q_Γ))

V = TestFESpace(model=model_in,valuetype=Float64,reffe=:Lagrangian,order=2,conformity=:H1)
@test isa(V,ExtendedFESpace)
Expand Down