Skip to content

Commit 4131bad

Browse files
authored
Merge branch 'master' into add_missing_multifield_sparsematrixassemblerconstructor
2 parents f4c46b2 + e9321cc commit 4131bad

12 files changed

+96
-218
lines changed

NEWS.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,21 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88

99
### Added
1010
- Added missing SparseMatrixAssembler constructor for MultiFieldFESpaces. Since PR [#320](https://github.com/gridap/Gridap.jl/pull/320/).
11+
- kw-argument `space` to `LagrangianRefFE` constructor in order to select the type of underlying polynomial space, i.e., `:Q`, `:S`, or `:P`. Since PR [#321](https://github.com/gridap/Gridap.jl/pull/321).
1112

1213
### Changed
1314
- The meaning of `inward/outward` has slightly changed for `SkeletonCellBasis` objects. Now, by accessing to these properties a `ReducedSkeletonCellBasis` is returned, which allows to use the result in a more flexible way (in particular, the result can be used in a similar way than the result of `jump` or `mean`). Since PR [#317](https://github.com/gridap/Gridap.jl/pull/317).
14-
- Major refactoring in `ReferenceFEs` module. Since PR [#319](https://github.com/gridap/Gridap.jl/pull/319). In particular:
15+
- Major refactoring in `ReferenceFEs` module. Since PR [#319](https://github.com/gridap/Gridap.jl/pull/319) and [#321](https://github.com/gridap/Gridap.jl/pull/321). In particular:
1516
- `NodalReferenceFE` has been replaced by a new abstract type `LagrangianRefFE`.
1617
- `GenericNodalCartesianRefFE` has been replaced by `GenericLagrangianRefFE`.
17-
- `DiscRefFE` replaced by `PDiscRefFE`.
1818

1919
### Removed
2020
- Removals associated with the `ReferenceFEs` refactoring in PR [#319](https://github.com/gridap/Gridap.jl/pull/319):
2121
- Removed `QDiscRefFE` constructor. Use a standard `LagrangianRefFE` and `L2Conformity` instead.
22+
- Removed `PDiscRefFE` constructor. Use `LagrangianRefFE` constructor with the kw-argument `space=:P`.
23+
- Removed `CDLagrangianRefFE` constructor. Use a standard `LagrangianRefFE` and `CDConformity` instead.
2224
- Removed fields `face_own_dofs` and `face_own_dof_permutations` from `GenericRefFE`.
25+
- Removed struct `DiscRefFE`.
2326

2427
### Fixed
2528
- Replaced `+=` by `add_entry!`. Since PR [#316](https://github.com/gridap/Gridap.jl/pull/316).

src/FESpaces/FESpaceFactories.jl

+1-71
Original file line numberDiff line numberDiff line change
@@ -248,9 +248,7 @@ function _setup_lagrange_spaces(kwargs)
248248
end
249249
else
250250
if reffe == :PLagrangian
251-
_reffes = [PDiscRefFE(T,p,order) for p in polytopes]
252-
elseif reffe == :QLagrangian
253-
_reffes = [QDiscRefFE(T,p,order) for p in polytopes]
251+
_reffes = [LagrangianRefFE(T,p,order;space=:P) for p in polytopes]
254252
else
255253
@unreachable "Not possible to use a $reffe reffe on polytopes $(polytopes...)"
256254
end
@@ -287,74 +285,6 @@ function _setup_lagrange_spaces(kwargs)
287285

288286
end
289287

290-
#function _setup_lagrange_spaces(kwargs)
291-
#
292-
# reffe = _get_kwarg(:reffe,kwargs)
293-
# model = _get_kwarg(:model,kwargs)
294-
# labels = _get_kwarg(:labels,kwargs,nothing)
295-
# conformity = _get_kwarg(:conformity,kwargs,true)
296-
# diritags = _get_kwarg(:dirichlet_tags,kwargs,Int[])
297-
# dirimasks = _get_kwarg(:dirichlet_masks,kwargs,nothing)
298-
# order = _get_kwarg(:order,kwargs)
299-
#
300-
# polytopes = get_polytopes(model)
301-
# trian = get_triangulation(model)
302-
#
303-
# T = _get_kwarg(:valuetype,kwargs,nothing)
304-
# if T == nothing
305-
# @unreachable "valuetype is a mandatory keyword argument in FESpace constructor for Lagrangian reference FEs"
306-
# end
307-
#
308-
# if _is_reffe_lagrangian_compatible_with_polytopes(reffe,polytopes)
309-
#
310-
# if reffe == :SLagrangian
311-
# _reffes = [SerendipityRefFE(T,p,order) for p in polytopes]
312-
# else
313-
# _reffes = [LagrangianRefFE(T,p,order) for p in polytopes]
314-
# end
315-
#
316-
# if conformity in [false, :L2]
317-
#
318-
# s = "Strong dirichlet conditions cannot be imposed in discontinuous spaces for the moment"
319-
# @notimplementedif diritags != Int[] s
320-
# @notimplementedif dirimasks != nothing s
321-
#
322-
# return DiscontinuousFESpace(_reffes,trian)
323-
#
324-
# elseif conformity in [true, :default, :H1, :C0]
325-
# if labels == nothing
326-
# return GradConformingFESpace(_reffes,model,diritags,dirimasks)
327-
# else
328-
# return GradConformingFESpace(_reffes,model,labels,diritags,dirimasks)
329-
# end
330-
#
331-
# else
332-
# s = "Conformity $conformity not implemented for $reffe reference FE on polytopes $(polytopes...)"
333-
# @unreachable s
334-
#
335-
# end
336-
#
337-
# elseif reffe == :PLagrangian
338-
#
339-
# if conformity in [false, :L2]
340-
#
341-
# _reffes = [PDiscRefFE(T,p,order) for p in polytopes]
342-
# return DiscontinuousFESpace(_reffes,trian)
343-
#
344-
# else
345-
#
346-
# @unreachable "Conformity $conformity not possible for $reffe reference FE on $(polytopes...)"
347-
#
348-
# end
349-
#
350-
# else
351-
#
352-
# @notimplemented "Reference element $reffe not implemented on $(polytopes...)"
353-
#
354-
# end
355-
#
356-
#end
357-
358288
function _get_kwarg(kwarg,kwargs)
359289
try
360290
return kwargs[kwarg]

src/ReferenceFEs/CDLagrangianRefFEs.jl

+3-11
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,12 @@ end
1515

1616
# Constructors
1717

18-
function LagrangianRefFE(::Type{T},p::ExtrusionPolytope{D},order::Int,cont) where {T,D}
19-
CDLagrangianRefFE(T,p,order,cont)
20-
end
21-
22-
function LagrangianRefFE(::Type{T},p::ExtrusionPolytope{D},orders,cont) where {T,D}
23-
CDLagrangianRefFE(T,p,orders,cont)
24-
end
25-
26-
function CDLagrangianRefFE(::Type{T},p::ExtrusionPolytope{D},order::Int,cont) where {T,D}
18+
function _CDLagrangianRefFE(::Type{T},p::ExtrusionPolytope{D},order::Int,cont) where {T,D}
2719
orders = tfill(order,Val{D}())
28-
CDLagrangianRefFE(T,p,orders,cont)
20+
_CDLagrangianRefFE(T,p,orders,cont)
2921
end
3022

31-
function CDLagrangianRefFE(::Type{T},p::ExtrusionPolytope{D},orders,cont) where {T,D}
23+
function _CDLagrangianRefFE(::Type{T},p::ExtrusionPolytope{D},orders,cont) where {T,D}
3224
cond(c,o) = ( o > 0 || c == DISC )
3325
@assert all([cond(c,o) for (c,o) in zip(cont,orders)])
3426
_cd_lagrangian_ref_fe(T,p,orders,cont)

src/ReferenceFEs/CLagrangianRefFEs.jl

+21-39
Original file line numberDiff line numberDiff line change
@@ -201,12 +201,26 @@ new polytope types increasing customization possibilities.
201201
- [`compute_own_nodes_permutations(p::Polytope, interior_nodes)`](@ref)
202202
- [`compute_lagrangian_reffaces(::Type{T},p::Polytope,orders) where T`](@ref)
203203
"""
204-
function LagrangianRefFE(::Type{T},p::Polytope{D},orders) where {T,D}
205-
if any(orders.==0) && !all(orders.==0)
206-
cont = map(i -> i == 0 ? DISC : CONT,orders)
207-
return _cd_lagrangian_ref_fe(T,p,orders,cont)
204+
function LagrangianRefFE(::Type{T},p::Polytope{D},orders;space::Symbol=_default_space(p)) where {T,D}
205+
if space == :P && is_n_cube(p)
206+
return _PDiscRefFE(T,p,orders)
207+
elseif space == :S && is_n_cube(p)
208+
SerendipityRefFE(T,p,orders)
208209
else
209-
return _lagrangian_ref_fe(T,p,orders)
210+
if any(orders.==0) && !all(orders.==0)
211+
cont = map(i -> i == 0 ? DISC : CONT,orders)
212+
return _cd_lagrangian_ref_fe(T,p,orders,cont)
213+
else
214+
return _lagrangian_ref_fe(T,p,orders)
215+
end
216+
end
217+
end
218+
219+
function _default_space(p)
220+
if is_n_cube(p)
221+
:Q
222+
else
223+
:P
210224
end
211225
end
212226

@@ -320,43 +334,11 @@ function _generate_face_nodes_aux(
320334
face_fnode_to_node
321335
end
322336

323-
#function _find_own_dof_permutaions(node_perms,node_and_comp_to_dof,nfacenodeids,nfacedofsids)
324-
# dof_perms = Vector{Int}[]
325-
# T = eltype(node_and_comp_to_dof)
326-
# ncomps = num_components(T)
327-
# idof_to_dof = nfacedofsids[end]
328-
# inode_to_node = nfacenodeids[end]
329-
# for inode_to_pinode in node_perms
330-
# ninodes = length(inode_to_pinode)
331-
# nidofs = ncomps*ninodes
332-
# idof_to_pidof = fill(INVALID_PERM,nidofs)
333-
# for (inode,ipnode) in enumerate(inode_to_pinode)
334-
# if ipnode == INVALID_PERM
335-
# continue
336-
# end
337-
# node = inode_to_node[inode]
338-
# pnode = inode_to_node[ipnode]
339-
# comp_to_pdof = node_and_comp_to_dof[pnode]
340-
# comp_to_dof = node_and_comp_to_dof[node]
341-
# for comp in 1:ncomps
342-
# dof = comp_to_dof[comp]
343-
# pdof = comp_to_pdof[comp]
344-
# idof = findfirst(i->i==dof,idof_to_dof)
345-
# ipdof = findfirst(i->i==pdof,idof_to_dof)
346-
# idof_to_pidof[idof] = ipdof
347-
# end
348-
# end
349-
# push!(dof_perms,idof_to_pidof)
350-
# end
351-
# dof_perms
352-
#end
353-
354-
355337
# Constructors taking Int
356338

357-
function LagrangianRefFE(::Type{T},p::Polytope{D},order::Int) where {T,D}
339+
function LagrangianRefFE(::Type{T},p::Polytope{D},order::Int;space::Symbol=_default_space(p)) where {T,D}
358340
orders = tfill(order,Val{D}())
359-
LagrangianRefFE(T,p,orders)
341+
LagrangianRefFE(T,p,orders;space=space)
360342
end
361343

362344
function MonomialBasis(::Type{T},p::Polytope{D},order::Int) where {D,T}

src/ReferenceFEs/PDiscRefFEs.jl

+21-30
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,29 @@
1-
"""
2-
struct PDiscRefFE{D} <: LagrangianRefFE{D}
3-
# Private fields
4-
end
5-
"""
6-
struct PDiscRefFE{D} <: LagrangianRefFE{D}
7-
reffe::LagrangianRefFE{D}
8-
polytope::Polytope{D}
1+
2+
function _PDiscRefFE(::Type{T},p::Polytope,orders) where T
3+
order = first(orders)
4+
@notimplementedif any( orders .!= order ) "Anisotropic serentopity FEs not allowed"
5+
_PDiscRefFE(T,p,order)
96
end
107

11-
function PDiscRefFE(::Type{T},p::Polytope,order::Integer) where T
8+
function _PDiscRefFE(::Type{T},p::Polytope,order::Integer) where T
129
D = num_cell_dims(p)
1310
extrusion = tfill(TET_AXIS,Val{D}())
1411
simplex = ExtrusionPolytope(extrusion)
1512
reffe = LagrangianRefFE(T,simplex,order)
16-
PDiscRefFE{D}(reffe,p)
13+
metadata = nothing
14+
face_nodes = [Int[] for face in 1:num_faces(p)]
15+
face_nodes[end] = collect(1:num_nodes(reffe))
16+
dofs = get_dof_basis(reffe)
17+
face_dofs = _generate_face_own_dofs(face_nodes,dofs.node_and_comp_to_dof)
18+
19+
reffe = GenericRefFE(
20+
num_dofs(reffe),
21+
p,
22+
get_prebasis(reffe),
23+
get_dof_basis(reffe),
24+
L2Conformity(),
25+
metadata,
26+
face_dofs)
27+
GenericLagrangianRefFE(reffe,face_nodes)
1728
end
1829

19-
# LagrangianRefFE
20-
21-
get_face_nodes(reffe::PDiscRefFE) = get_face_own_nodes(reffe)
22-
23-
# Reffe
24-
25-
num_dofs(reffe::PDiscRefFE) = num_dofs(reffe.reffe)
26-
27-
get_polytope(reffe::PDiscRefFE) = reffe.polytope
28-
29-
get_prebasis(reffe::PDiscRefFE) = get_prebasis(reffe.reffe)
30-
31-
get_dof_basis(reffe::PDiscRefFE) = get_dof_basis(reffe.reffe)
32-
33-
get_default_conformity(reffe::PDiscRefFE) = L2Conformity()
34-
35-
get_face_dofs(reffe::PDiscRefFE) = get_face_own_dofs(reffe)
36-
37-
get_shapefuns(reffe::PDiscRefFE) = get_shapefuns(reffe.reffe)
38-

src/ReferenceFEs/ReferenceFEs.jl

-2
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,8 @@ export DivConformity
154154
export CDConformity
155155

156156
export SerendipityRefFE
157-
export PDiscRefFE
158157
export RaviartThomasRefFE
159158
export NedelecRefFE
160-
export CDLagrangianRefFE
161159

162160
include("Polytopes.jl")
163161

test/FESpacesTests/CDLagrangianFESpacesTests.jl

+11-53
Original file line numberDiff line numberDiff line change
@@ -16,93 +16,51 @@ orders = (2,1)
1616
order = 2*max(orders...)
1717

1818
T = VectorValue{2,Float64}
19-
reffe = CDLagrangianRefFE(T,QUAD,orders,(DISC,CONT))
20-
V = FESpace(model=model,reffe=reffe)#),dirichlet_tags = [1,6])
19+
reffe = LagrangianRefFE(T,QUAD,orders)
20+
V = FESpace(model=model,reffe=reffe,conformity=CDConformity((DISC,CONT)))#),dirichlet_tags = [1,6])
2121
test_single_field_fe_space(V)
2222

2323
u(x) = x
2424

2525
U = TrialFESpace(V,u)
2626
uh = interpolate(U,u)
27-
2827
e = u - uh
29-
3028
trian = Triangulation(model)
3129
quad = CellQuadrature(trian,order)
32-
3330
el2 = sqrt(sum(integrate(inner(e,e),trian,quad)))
3431
@test el2 < 1.0e-10
3532

36-
reffe = CDLagrangianRefFE(Float64,QUAD,(2,2),(CONT,DISC))
37-
38-
quad9 = LagrangianRefFE(T,QUAD,2)
39-
V = FESpace(model=model,reffe=quad9,conformity=CDConformity((CONT,DISC)))
40-
33+
reffe = LagrangianRefFE(T,QUAD,2)
34+
V = FESpace(model=model,reffe=reffe,conformity=CDConformity((CONT,DISC)))
4135
U = TrialFESpace(V,u)
4236
uh = interpolate(U,u)
4337
e = u - uh
44-
4538
el2 = sqrt(sum(integrate(inner(e,e),trian,quad)))
4639
@test el2 < 1.0e-10
4740

48-
cdquad9 = CDLagrangianRefFE(T,QUAD,2,(CONT,DISC))
49-
V = FESpace(model=model,reffe=cdquad9)
50-
41+
reffe = LagrangianRefFE(T,QUAD,(2,1))
42+
V = FESpace(model=model,reffe=reffe,conformity=CDConformity((DISC,CONT)))
5143
U = TrialFESpace(V,u)
5244
uh = interpolate(U,u)
5345
e = u - uh
54-
5546
el2 = sqrt(sum(integrate(inner(e,e),trian,quad)))
5647
@test el2 < 1.0e-10
5748

58-
cdquad9 = CDLagrangianRefFE(T,QUAD,2,(CONT,DISC))
59-
V = FESpace(model=model,reffe=cdquad9,conformity=CDConformity((CONT,DISC)))
60-
61-
U = TrialFESpace(V,u)
62-
uh = interpolate(U,u)
63-
e = u - uh
64-
65-
el2 = sqrt(sum(integrate(inner(e,e),trian,quad)))
66-
@test el2 < 1.0e-10
67-
68-
cdquad9 = CDLagrangianRefFE(T,QUAD,2,(CONT,DISC))
69-
V = FESpace(model=model,reffe=cdquad9,conformity=CDConformity((DISC,CONT)))
70-
71-
U = TrialFESpace(V,u)
72-
uh = interpolate(U,u)
73-
e = u - uh
74-
75-
el2 = sqrt(sum(integrate(inner(e,e),trian,quad)))
76-
@test el2 < 1.0e-10
77-
78-
cdquad9 = LagrangianRefFE(T,QUAD,2,(CONT,DISC))
79-
V = FESpace(model=model,reffe=cdquad9,conformity=CDConformity((DISC,CONT)))
80-
81-
U = TrialFESpace(V,u)
82-
uh = interpolate(U,u)
83-
e = u - uh
84-
85-
el2 = sqrt(sum(integrate(inner(e,e),trian,quad)))
86-
@test el2 < 1.0e-10
87-
88-
cdquad9 = LagrangianRefFE(T,QUAD,(2,1))
89-
V = FESpace(model=model,reffe=cdquad9,conformity=CDConformity((DISC,CONT)))
90-
49+
reffe = LagrangianRefFE(T,QUAD,(2,0))
50+
V = FESpace(model=model,reffe=reffe,conformity=CDConformity((CONT,DISC)))
51+
u(x) = VectorValue(x[1],0.0)
9152
U = TrialFESpace(V,u)
9253
uh = interpolate(U,u)
9354
e = u - uh
94-
9555
el2 = sqrt(sum(integrate(inner(e,e),trian,quad)))
9656
@test el2 < 1.0e-10
9757

98-
cdquad9 = LagrangianRefFE(T,QUAD,(2,0))
99-
V = FESpace(model=model,reffe=cdquad9,conformity=CDConformity((CONT,DISC)))
100-
58+
reffe = LagrangianRefFE(T,QUAD,(2,0))
59+
V = FESpace(model=model,reffe=reffe,conformity=CDConformity((DISC,DISC)))
10160
u(x) = VectorValue(x[1],0.0)
10261
U = TrialFESpace(V,u)
10362
uh = interpolate(U,u)
10463
e = u - uh
105-
10664
el2 = sqrt(sum(integrate(inner(e,e),trian,quad)))
10765
@test el2 < 1.0e-10
10866

test/FESpacesTests/DiscontinuousFESpacesTests.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ uh = FEFunction(V,rand(num_free_dofs(V)))
3131
#
3232
#writevtk(trian,"trian",nsubcells=40,cellfields=["fh"=>fh, "uh"=>uh])
3333

34-
reffes = [PDiscRefFE(Float64,p,order) for p in polytopes]
34+
reffes = [LagrangianRefFE(Float64,p,order,space=:P) for p in polytopes]
3535
V = DiscontinuousFESpace(reffes,trian)
3636
test_single_field_fe_space(V)
3737

0 commit comments

Comments
 (0)