Skip to content

Commit 972afcc

Browse files
committed
Added DirichletSpace
1 parent b6a49ee commit 972afcc

File tree

5 files changed

+121
-0
lines changed

5 files changed

+121
-0
lines changed

src/Arrays/IdentityVectors.jl

+3
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,6 @@ function reindex(values::AbstractArray, indices::IdentityVector)
2626
values
2727
end
2828

29+
function reindex(a::AppliedArray,b::IdentityVector)
30+
a
31+
end

src/FESpaces/DirichletFESpaces.jl

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
2+
struct DirichletFESpace <: SingleFieldFESpace
3+
space::SingleFieldFESpace
4+
end
5+
6+
function num_free_dofs(f::DirichletFESpace)
7+
num_dirichlet_dofs(f.space)
8+
end
9+
10+
function zero_free_values(::Type{T},f::DirichletFESpace) where T
11+
zeros(T,num_free_dofs(f))
12+
end
13+
14+
function get_cell_dofs(f::DirichletFESpace)
15+
apply(elem(-),get_cell_dofs(f.space))
16+
end
17+
18+
function num_dirichlet_dofs(f::DirichletFESpace)
19+
num_free_dofs(f.space)
20+
end
21+
22+
function zero_dirichlet_values(f::DirichletFESpace)
23+
T = Float64
24+
zero_free_values(T,f.space)
25+
end
26+
27+
function num_dirichlet_tags(f::DirichletFESpace)
28+
1
29+
end
30+
31+
function get_dirichlet_dof_tag(f::DirichletFESpace)
32+
ones(Int8,num_dirichlet_dofs(f))
33+
end
34+
35+
function scatter_free_and_dirichlet_values(f::DirichletFESpace,fv,dv)
36+
scatter_free_and_dirichlet_values(f.space,dv,fv)
37+
end
38+
39+
function gather_free_and_dirichlet_values(f::DirichletFESpace,cv)
40+
dv, fv = gather_free_and_dirichlet_values(f.space,cv)
41+
(fv, dv)
42+
end
43+
44+
function TrialFESpace(f::DirichletFESpace)
45+
U = TrialFESpace(f.space)
46+
DirichletFESpace(U)
47+
end
48+
49+
function get_cell_basis(f::DirichletFESpace)
50+
get_cell_basis(f.space)
51+
end
52+
53+
function get_cell_dof_basis(f::DirichletFESpace)
54+
get_cell_dof_basis(f.space)
55+
end
56+
57+
function apply_constraints_matrix_cols(f::DirichletFESpace,cm,cids)
58+
apply_constraints_matrix_cols(f.space,cm,cids)
59+
end
60+
61+
function apply_constraints_matrix_rows(f::DirichletFESpace,cm,cids)
62+
apply_constraints_matrix_rows(f.space,cm,cids)
63+
end
64+
65+
function apply_constraints_vector(f::DirichletFESpace,cm,cids)
66+
apply_constraints_vector(f.space,cm,cids)
67+
end
68+

src/FESpaces/FESpaces.jl

+3
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ export FESpaceWithLastDofRemoved
157157
export ZeroMeanFESpace
158158
export CLagrangianFESpace
159159
export DivConformingFESpace
160+
export DirichletFESpace
160161

161162
export @law
162163
export operate
@@ -204,6 +205,8 @@ include("ZeroMeanFESpaces.jl")
204205

205206
include("CLagrangianFESpaces.jl")
206207

208+
include("DirichletFESpaces.jl")
209+
207210
include("FESpaceFactories.jl")
208211

209212
end # module
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
module DirichletFESpacesTests
2+
3+
using Test
4+
using Gridap.Algebra
5+
using Gridap.Geometry
6+
using Gridap.FESpaces
7+
8+
n = 2
9+
mesh = (n,n)
10+
domain = (0,1,0,1)
11+
order = 1
12+
dirichlet_tags = [1,3,4,6,7]
13+
model = CartesianDiscreteModel(domain, mesh)
14+
labels = get_face_labeling(model)
15+
add_tag_from_tags!(labels,"dirichlet",dirichlet_tags)
16+
17+
Vf = TestFESpace(
18+
reffe=:Lagrangian, order=order, valuetype=Float64,
19+
conformity=:H1, model=model, labels=labels, dirichlet_tags="dirichlet")
20+
21+
Vd = DirichletFESpace(Vf)
22+
test_single_field_fe_space(Vd,[],[],[],[])
23+
24+
Uf = TrialFESpace(Vf,1)
25+
26+
Ud = TrialFESpace(Vd)
27+
test_single_field_fe_space(Ud,[],[],[],[])
28+
29+
trian = Triangulation(model)
30+
degree = 2*order
31+
quad = CellQuadrature(trian,degree)
32+
33+
a(v,u) = v*u
34+
l(v) = v*0
35+
t_Ω = AffineFETerm(a,l,trian,quad)
36+
37+
op_ff = AffineFEOperator(Vf,Uf,t_Ω)
38+
op_fd = AffineFEOperator(Vf,Ud,t_Ω)
39+
op_df = AffineFEOperator(Vd,Uf,t_Ω)
40+
41+
xd = get_dirichlet_values(Uf)
42+
43+
@test maximum(abs.(get_vector(op_ff) + get_matrix(op_fd)*xd)) < 1.0e-10
44+
45+
end # module

test/FESpacesTests/runtests.jl

+2
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ using Test
4444

4545
@testset "CLagrangianFESpaces" begin include("CLagrangianFESpacesTests.jl") end
4646

47+
@testset "DirichletFESpaces" begin include("DirichletFESpacesTests.jl") end
48+
4749
@testset "FESpaceFactories" begin include("FESpaceFactoriesTests.jl") end
4850

4951
end # module

0 commit comments

Comments
 (0)