Skip to content

Commit

Permalink
Constructing FE Spaces from FaceLabels different from the ones in the…
Browse files Browse the repository at this point in the history
… model
  • Loading branch information
fverdugo committed Sep 10, 2019
1 parent 3708474 commit e9dfac4
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 19 deletions.
23 changes: 18 additions & 5 deletions src/FESpaces/CLagrangianFESpaces.jl
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,26 @@ function CLagrangianFESpace(
end

function CLagrangianFESpace(
::Type{T},model::DiscreteModel,order,diritags=Int[],dirimasks=nothing) where T
::Type{T},
model::DiscreteModel,
order::Integer,
diritags=Int[],
dirimasks=nothing) where T
CLagrangianFESpace(T,model,FaceLabels(model),order,diritags,dirimasks)
end

function CLagrangianFESpace(
::Type{T},
model::DiscreteModel,
facelabels::FaceLabels,
order::Integer,
diritags=Int[],
dirimasks=nothing) where T

_diri_tags = _setup_tags(model,diritags)
_diri_tags = _setup_tags(facelabels,diritags)
_diri_masks = _setup_masks(T,_diri_tags,dirimasks)

grid, node_to_label, tag_to_labels = _setup_grid(model,order)
grid, node_to_label, tag_to_labels = _setup_grid(model,facelabels,order)

CLagrangianFESpace(
T,grid,node_to_label,tag_to_labels,_diri_tags,_diri_masks)
Expand Down Expand Up @@ -443,9 +457,8 @@ function _same_order(order,co::ConstantCellValue)
order == co.value
end

function _setup_grid(model,order)
function _setup_grid(model,facelabels,order)

facelabels = FaceLabels(model)
_grid = Grid(model)

if _same_order(order,cellorders(_grid))
Expand Down
18 changes: 15 additions & 3 deletions src/FESpaces/ConformingFESpaces.jl
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,27 @@ function ConformingFESpace(
return ConformingFESpace(reffe, trian, graph, labels, ())
end

function ConformingFESpace(::Type{T},model::DiscreteModel{D},order,diri_tags) where {D,T}
function ConformingFESpace(
::Type{T}, model::DiscreteModel{D}, order::Integer, diri_tags) where {D,T}

labels = FaceLabels(model)
ConformingFESpace(T,model,labels,order,diri_tags)
end

function ConformingFESpace(
::Type{T},
model::DiscreteModel{D},
labels::FaceLabels,
order::Integer,
diri_tags) where {D,T}

grid = Grid(model,D)
trian = Triangulation(grid)
graph = GridGraph(model)
labels = FaceLabels(model)
orders = fill(order,D)
polytope = _polytope(celltypes(grid))
fe = LagrangianRefFE(T,polytope, orders)
_diri_tags = _setup_tags(model,diri_tags)
_diri_tags = _setup_tags(labels,diri_tags)
ConformingFESpace(fe,trian,graph,labels,_diri_tags)
end

Expand Down
20 changes: 17 additions & 3 deletions src/FESpaces/DLagrangianFESpaces.jl
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,26 @@ function DLagrangianFESpace(
end

function DLagrangianFESpace(
::Type{T},model::DiscreteModel,order,diritags=Int[],dirimasks=nothing) where T
::Type{T},
model::DiscreteModel,
order::Integer,
diritags=Int[],
dirimasks=nothing) where T
DLagrangianFESpace(T,model,FaceLabels(model),order,diritags,dirimasks)
end

function DLagrangianFESpace(
::Type{T},
model::DiscreteModel,
facelabels::FaceLabels,
order::Integer,
diritags=Int[],
dirimasks=nothing) where T

_diri_tags = _setup_tags(model,diritags)
_diri_tags = _setup_tags(facelabels,diritags)
_diri_masks = _setup_masks(T,_diri_tags,dirimasks)

grid, node_to_label, tag_to_labels = _setup_grid(model,order)
grid, node_to_label, tag_to_labels = _setup_grid(model,facelabels,order)

DLagrangianFESpace(
T,grid,node_to_label,tag_to_labels,_diri_tags,_diri_masks)
Expand Down
14 changes: 7 additions & 7 deletions src/Geometry/BoundaryGrids.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function Triangulation(grid::BoundaryGrid)
end

function BoundaryGrid(model::DiscreteModel,tags,icell::Int=1)
_tags = _setup_tags(model,tags)
_tags = _setup_tags(Facelabels(model),tags)
BoundaryGrid(model,_tags,icell)
end

Expand Down Expand Up @@ -96,16 +96,16 @@ function _cell_to_polytope(cell_to_extrussion::ConstantCellValue)
ConstantCellValue(poly,l)
end

_setup_tags(model,tags) = tags
_setup_tags(facelabels,tags) = tags

_setup_tags(model,tag::Integer) = [tag,]
_setup_tags(facelabels,tag::Integer) = [tag,]

function _setup_tags(model,name::String)
_setup_tags(model,[name,])
function _setup_tags(facelabels,name::String)
_setup_tags(facelabels,[name,])
end

function _setup_tags(model,names::Vector{String})
[ tag_from_name(model,s) for s in names ]
function _setup_tags(facelabels,names::Vector{String})
[ tag_from_name(facelabels,s) for s in names ]
end

end # module
3 changes: 3 additions & 0 deletions src/Geometry/FaceLabels.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module FaceLabelsModule

using Gridap
using Gridap.Helpers
using Gridap.CellValuesGallery

export FaceLabels
Expand Down Expand Up @@ -49,6 +50,7 @@ function tag_from_name(l::FaceLabels,name::String)
return tag
end
end
@unreachable
0
end

Expand All @@ -75,6 +77,7 @@ function _first_tag_on_face!(face_to_tag,face_to_label,tag_to_labels)
end

function add_tag_from_tags!(facelabels::FaceLabels, name::String, tags::Vector{Int})
@assert ! (name in facelabels.tag_to_name)
labels = Int[]
for tag in tags
for label in labels_on_tag(facelabels,tag)
Expand Down
12 changes: 12 additions & 0 deletions test/FESpacesTests/CLagrangianFESpacesTests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,16 @@ fespace = CLagrangianFESpace(T,model,order)
@test all(fespace.node_and_comp_to_dof .> 0)
@test fespace.ndiridofs == 0

labels = FaceLabels(model)
labels = FaceLabels(
labels.dim_to_nface_to_label,copy(labels.tag_to_labels),copy(labels.tag_to_name))
diritag = "diri_boundary"
add_tag_from_tags!(labels,diritag,diritags)
dirimask = [true,]
fespace = CLagrangianFESpace(T,model,labels,order,diritag,dirimask)





end # module
8 changes: 8 additions & 0 deletions test/FESpacesTests/DLagrangianFESpacesTests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,12 @@ fespace = DLagrangianFESpace(T,model,order)
@test fespace.dirimasks == Tuple{Bool}[]
@test fespace.ndiridofs == 0

labels = FaceLabels(model)
labels = FaceLabels(
labels.dim_to_nface_to_label,copy(labels.tag_to_labels),copy(labels.tag_to_name))
diritag = "diri_boundary"
add_tag_from_tags!(labels,diritag,diritags)
dirimask = [true,]
fespace = DLagrangianFESpace(T,model,labels,order,diritag,dirimask)

end # module
8 changes: 7 additions & 1 deletion test/FESpacesTests/FEOperatorsTestsMixin.jl
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,13 @@ gfun(x) = 1.0
# Construct the FEspace
order = 1
diritags = [1,2,3,4,5,6,7]
fespace = ConformingFESpace(Float64,model,order,diritags)
labels = FaceLabels(model)
# This next line is only for testing purposes
labels = FaceLabels(
labels.dim_to_nface_to_label,copy(labels.tag_to_labels),copy(labels.tag_to_name))
diritag = "diri_boundary"
add_tag_from_tags!(labels,diritag,diritags)
fespace = ConformingFESpace(Float64,model,labels,order,diritag)

# Define test and trial
V = TestFESpace(fespace)
Expand Down

0 comments on commit e9dfac4

Please sign in to comment.