Skip to content

Commit 672e3d9

Browse files
Merge pull request #872 from janmodderman/ConstantFE
Fix of ConstantFESpace + tests + export
2 parents 7fee059 + 3b9dac9 commit 672e3d9

File tree

6 files changed

+80
-73
lines changed

6 files changed

+80
-73
lines changed

NEWS.md

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1919
- Using broadcasting through in `ODESolver` vector operations. Since PR [#860](https://github.com/gridap/Gridap.jl/pull/860)
2020
- Fixes to `array_cache(a::Table)`: Now does not use the `zero(T,N)` function, but instead creates new empty vector using the general allocator `Vector{T}(undef,N)`. This allows `Table` to work with complex composite types which don't have an easy `zero(T)` function defined. Since PR [#838](https://github.com/gridap/Gridap.jl/pull/838).
2121
- Added `get_metadata` to all the instances of `ReferenceFE`. This makes the abstract type more consistent, which is necessary for the new type `FineToCoarseReferenceFE`. Since PR [#838](https://github.com/gridap/Gridap.jl/pull/838).
22+
- `ConstantFESpace` is now properly exported. Since PR [#872](https://github.com/gridap/Gridap.jl/pull/872).
2223

2324
## [0.17.16] - 2022-12-22
2425

src/Exports.jl

+1
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ using Gridap.CellData: ∫; export ∫
172172
@publish FESpaces FESolver
173173
@publish FESpaces SparseMatrixAssembler
174174
@publish FESpaces FiniteElements
175+
@publish FESpaces ConstantFESpace
175176

176177
@publish MultiField MultiFieldFESpace
177178
@publish MultiField num_fields

src/FESpaces/ConstantFESpaces.jl

+72-72
Original file line numberDiff line numberDiff line change
@@ -1,96 +1,96 @@
11

22
"""
3-
struct ConstantFESpace <: SingleFieldFESpace
4-
# private fields
5-
end
3+
struct ConstantFESpace <: SingleFieldFESpace
4+
# private fields
5+
end
66
"""
77
struct ConstantFESpace{V,T,A,B,C} <: SingleFieldFESpace
8-
model::DiscreteModel
9-
cell_basis::A
10-
cell_dof_basis::B
11-
cell_dof_ids::C
12-
function ConstantFESpace(model;
13-
vector_type::Type{V}=Vector{Float64},
14-
field_type::Type{T}=Float64) where {V,T}
15-
function setup_cell_reffe(model::DiscreteModel,
16-
reffe::Tuple{<:Gridap.FESpaces.ReferenceFEName,Any,Any}; kwargs...)
17-
basis, reffe_args,reffe_kwargs = reffe
18-
cell_reffe = ReferenceFE(model,basis,reffe_args...;reffe_kwargs...)
19-
end
20-
reffe=ReferenceFE(lagrangian,T,0)
21-
cell_reffe = setup_cell_reffe(model,reffe)
22-
cell_basis_array=lazy_map(get_shapefuns,cell_reffe)
23-
24-
cell_basis=Gridap.FESpaces.SingleFieldFEBasis(
25-
cell_basis_array,
26-
Triangulation(model),
27-
Gridap.FESpaces.TestBasis(),
28-
ReferenceDomain())
29-
30-
cell_dof_basis_array=lazy_map(get_dof_basis,cell_reffe)
31-
cell_dof_basis=Gridap.CellData.CellDof(cell_dof_basis_array,Triangulation(model),ReferenceDomain())
32-
33-
cell_dof_ids=Fill(Int32[1],num_cells(model))
34-
A=typeof(cell_basis)
35-
B=typeof(cell_dof_basis)
36-
C=typeof(cell_dof_ids)
37-
new{V,T,A,B,C}(model,
38-
cell_basis,
39-
cell_dof_basis,
40-
cell_dof_ids)
41-
end
8+
model::DiscreteModel
9+
cell_basis::A
10+
cell_dof_basis::B
11+
cell_dof_ids::C
12+
function ConstantFESpace(model;
13+
vector_type::Type{V}=Vector{Float64},
14+
field_type::Type{T}=Float64) where {V,T}
15+
function setup_cell_reffe(model::DiscreteModel,
16+
reffe::Tuple{<:ReferenceFEName,Any,Any}; kwargs...)
17+
basis, reffe_args,reffe_kwargs = reffe
18+
cell_reffe = ReferenceFE(model,basis,reffe_args...;reffe_kwargs...)
19+
end
20+
reffe=ReferenceFE(lagrangian,T,0)
21+
cell_reffe = setup_cell_reffe(model,reffe)
22+
cell_basis_array=lazy_map(get_shapefuns,cell_reffe)
23+
24+
cell_basis=SingleFieldFEBasis(
25+
cell_basis_array,
26+
Triangulation(model),
27+
TestBasis(),
28+
ReferenceDomain())
29+
30+
cell_dof_basis_array=lazy_map(get_dof_basis,cell_reffe)
31+
cell_dof_basis=CellDof(cell_dof_basis_array,Triangulation(model),ReferenceDomain())
32+
33+
cell_dof_ids=Fill(Int32[1],num_cells(model))
34+
A=typeof(cell_basis)
35+
B=typeof(cell_dof_basis)
36+
C=typeof(cell_dof_ids)
37+
new{V,T,A,B,C}(model,
38+
cell_basis,
39+
cell_dof_basis,
40+
cell_dof_ids)
41+
end
4242
end
4343

4444
# Genuine functions
45-
function Gridap.FESpaces.TrialFESpace(f::ConstantFESpace)
46-
f
45+
function TrialFESpace(f::ConstantFESpace)
46+
f
4747
end
4848

4949
# Delegated functions
50-
Gridap.FESpaces.get_triangulation(f::ConstantFESpace) = Triangulation(f.model)
50+
get_triangulation(f::ConstantFESpace) = Triangulation(f.model)
5151

52-
Gridap.FESpaces.ConstraintStyle(::Type{<:ConstantFESpace}) = UnConstrained()
52+
ConstraintStyle(::Type{<:ConstantFESpace}) = UnConstrained()
5353

54-
Gridap.FESpaces.get_dirichlet_dof_values(f::ConstantFESpace{V}) where V = eltype(V)[]
54+
get_dirichlet_dof_values(f::ConstantFESpace{V}) where V = eltype(V)[]
5555

56-
Gridap.FESpaces.get_fe_basis(f::ConstantFESpace) = f.cell_basis
56+
get_fe_basis(f::ConstantFESpace) = f.cell_basis
5757

58-
Gridap.FESpaces.get_fe_dof_basis(f::ConstantFESpace) = f.cell_dof_basis
58+
get_fe_dof_basis(f::ConstantFESpace) = f.cell_dof_basis
5959

60-
Gridap.FESpaces.get_free_dof_ids(f::ConstantFESpace) = Base.OneTo(length(f.cell_dof_ids[1]))
60+
get_free_dof_ids(f::ConstantFESpace) = Base.OneTo(length(f.cell_dof_ids[1]))
6161

62-
Gridap.FESpaces.get_vector_type(f::ConstantFESpace{V}) where V = V
62+
get_vector_type(f::ConstantFESpace{V}) where V = V
6363

64-
Gridap.FESpaces.get_cell_dof_ids(f::ConstantFESpace) = f.cell_dof_ids
64+
get_cell_dof_ids(f::ConstantFESpace) = f.cell_dof_ids
6565

66-
Gridap.FESpaces.get_dirichlet_dof_ids(f::ConstantFESpace) = Base.OneTo(0)
66+
get_dirichlet_dof_ids(f::ConstantFESpace) = Base.OneTo(0)
6767

68-
Gridap.FESpaces.num_dirichlet_tags(f::ConstantFESpace) = 0
68+
num_dirichlet_tags(f::ConstantFESpace) = 0
6969

70-
Gridap.FESpaces.get_dirichlet_dof_tag(f::ConstantFESpace) = Int8[]
70+
get_dirichlet_dof_tag(f::ConstantFESpace) = Int8[]
7171

72-
function Gridap.FESpaces.scatter_free_and_dirichlet_values(f::ConstantFESpace,fv,dv)
73-
cell_dof_ids = get_cell_dof_ids(f)
74-
lazy_map(Broadcasting(Gridap.Arrays.PosNegReindex(fv,dv)),cell_dof_ids)
72+
function scatter_free_and_dirichlet_values(f::ConstantFESpace,fv,dv)
73+
cell_dof_ids = get_cell_dof_ids(f)
74+
lazy_map(Broadcasting(PosNegReindex(fv,dv)),cell_dof_ids)
7575
end
7676

77-
function Gridap.FESpaces.gather_free_and_dirichlet_values(free_vals,
78-
dirichlet_vals,
79-
f::ConstantFESpace,
80-
cell_vals)
81-
cell_dofs = get_cell_dof_ids(f)
82-
cache_vals = array_cache(cv)
83-
cache_dofs = array_cache(cell_dofs)
84-
cells = 1:length(cell_vals)
85-
86-
Gridap.FESpaces._free_and_dirichlet_values_fill!(
87-
free_vals,
88-
dirichlet_vals,
89-
cache_vals,
90-
cache_dofs,
91-
cv,
92-
cell_dofs,
93-
cells)
94-
95-
(free_vals,dirichlet_vals)
77+
function gather_free_and_dirichlet_values!(free_vals,
78+
dirichlet_vals,
79+
f::ConstantFESpace,
80+
cell_vals)
81+
cell_dofs = get_cell_dof_ids(f)
82+
cache_vals = array_cache(cell_vals)
83+
cache_dofs = array_cache(cell_dofs)
84+
cells = 1:length(cell_vals)
85+
86+
_free_and_dirichlet_values_fill!(
87+
free_vals,
88+
dirichlet_vals,
89+
cache_vals,
90+
cache_dofs,
91+
cell_vals,
92+
cell_dofs,
93+
cells)
94+
95+
(free_vals,dirichlet_vals)
9696
end

src/FESpaces/FESpaces.jl

+4
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,8 @@ export GridWithFEMap
208208
export add_mesh_displacement!
209209
export update_coordinates!
210210

211+
export ConstantFESpace
212+
211213
include("FESpaceInterface.jl")
212214

213215
include("SingleFieldFESpaces.jl")
@@ -256,6 +258,8 @@ include("FESpacesWithLinearConstraints.jl")
256258

257259
include("DiscreteModelWithFEMaps.jl")
258260

261+
include("ConstantFESpaces.jl")
262+
259263
export get_free_values
260264
function get_free_values(args...)
261265
@unreachable "get_free_values has been removed. Use get_free_dof_values instead."

test/FESpacesTests/ConstantFESpaceTests.jl

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
module ConstantFESpacesTests
33

44
using Gridap
5-
using GridapBiotElasticity
65
using Test
76

87
domain = (0,1,0,1)

test/FESpacesTests/runtests_2.jl

+2
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,6 @@ using Test
2626

2727
@testset "DiscreteModelWithFEMapsTests" begin include("DiscreteModelWithFEMapsTests.jl") end
2828

29+
@testset "ConstantFESpaceTests" begin include("ConstantFESpaceTests.jl") end
30+
2931
end # module

0 commit comments

Comments
 (0)