-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #485 from gridap/diracs_deltas
Added DiracDelta
- Loading branch information
Showing
7 changed files
with
154 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
|
||
struct DiracDelta{D} <: GridapType | ||
Γ::Triangulation{D} | ||
dΓ::LebesgueMeasure | ||
end | ||
|
||
function DiracDelta{D}( | ||
model::DiscreteModel, | ||
face_to_bgface::AbstractVector{<:Integer}, | ||
degree::Integer) where D | ||
|
||
@assert 0 <= D && D < num_cell_dims(model) """\n | ||
Incorrect value of D=$D for building a DiracDelta{D} on a model with $(num_cell_dims(model)) cell dims. | ||
D should be in [0,$(num_cell_dims(model))). | ||
""" | ||
topo = get_grid_topology(model) | ||
bgface_grid = Grid(ReferenceFE{D},model) | ||
face_trian = RestrictedTriangulation(bgface_grid,face_to_bgface) | ||
cell_trian = Triangulation(model) | ||
bgface_to_lcell = Fill(1,num_faces(model,D)) | ||
glue = Geometry.FaceToCellGlue(topo,cell_trian,face_trian,face_to_bgface,bgface_to_lcell) | ||
Γ = BoundaryTriangulation(face_trian,cell_trian,glue) | ||
dΓ = LebesgueMeasure(Γ,degree) | ||
DiracDelta(Γ,dΓ) | ||
end | ||
|
||
function DiracDelta{D}( | ||
model::DiscreteModel, | ||
bgface_to_mask::AbstractVector{Bool}, | ||
degree::Integer) where D | ||
|
||
face_to_bgface = findall(bgface_to_mask) | ||
DiracDelta{D}(model,face_to_bgface,degree) | ||
end | ||
|
||
function DiracDelta{D}( | ||
model::DiscreteModel, | ||
labeling::FaceLabeling, | ||
degree::Integer;tags) where D | ||
|
||
@assert 0 <= D && D < num_cell_dims(model) """\n | ||
Incorrect value of D=$D for building a DiracDelta{D} on a model with $(num_cell_dims(model)) cell dims. | ||
D should be in [0,$(num_cell_dims(model))). | ||
""" | ||
face_to_mask = get_face_mask(labeling,tags,D) | ||
DiracDelta{D}(model,face_to_mask,degree) | ||
end | ||
|
||
function DiracDelta{D}(model::DiscreteModel,degree::Integer;tags) where D | ||
labeling = get_face_labeling(model) | ||
DiracDelta{D}(model,labeling,degree,tags=tags) | ||
end | ||
|
||
function DiracDelta{0}(model::DiscreteModel,labeling::FaceLabeling;tags) | ||
degree = 0 | ||
DiracDelta{0}(model,labeling,degree;tags=tags) | ||
end | ||
|
||
function DiracDelta{0}(model::DiscreteModel;tags) | ||
degree = 0 | ||
DiracDelta{0}(model,degree;tags=tags) | ||
end | ||
|
||
function (d::DiracDelta)(f::CellField) | ||
evaluate(d,f) | ||
end | ||
|
||
function evaluate!(cache,d::DiracDelta,f::CellField) | ||
∫(f)*d.dΓ | ||
end | ||
|
||
function get_triangulation(d::DiracDelta) | ||
d.Γ | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
module DiracDeltasTests | ||
|
||
using Test | ||
using Gridap.Helpers | ||
using Gridap.Arrays | ||
using Gridap.ReferenceFEs | ||
using Gridap.Geometry | ||
using Gridap.CellData | ||
|
||
domain = (0,1,0,1) | ||
cells = (30,30) | ||
model = CartesianDiscreteModel(domain,cells) | ||
|
||
Ω = Triangulation(model) | ||
|
||
vfun(x) = x[1] + 3*x[2] | ||
v = CellField(vfun,Ω) | ||
|
||
degree = 2 | ||
δ = DiracDelta{1}(model,degree,tags=5) | ||
@test sum(δ(v)) ≈ 0.5 | ||
|
||
#using Gridap.Visualization | ||
#writevtk(get_triangulation(δ),"trian_d") | ||
#writevtk(Ω,"trian") | ||
|
||
δ = DiracDelta{0}(model,tags=2) | ||
@test sum(δ(v)) ≈ 1 | ||
|
||
δ = DiracDelta{0}(model,tags=4) | ||
@test sum(δ(v)) ≈ 4 | ||
|
||
δ = DiracDelta{0}(model,tags=[2,4]) | ||
@test sum(δ(v)) ≈ 5 | ||
|
||
#using Gridap | ||
# | ||
#order = 2 | ||
#reffe = ReferenceFE(:Lagrangian,VectorValue{2,Float64},order) | ||
#V = FESpace(model,reffe,dirichlet_tags=[1,2,5]) | ||
# | ||
#dΩ = LebesgueMeasure(Ω,2*order) | ||
# | ||
#δ = DiracDelta{0}(model,tags=4) | ||
# | ||
#const E = 1 | ||
#const ν = 0.33 | ||
#const λ = (E*ν)/((1+ν)*(1-2*ν)) | ||
#const μ = E/(2*(1+ν)) | ||
#σ(ε) = λ*tr(ε)*one(ε) + 2*μ*ε | ||
# | ||
#a(u,v) = ∫( ε(v) ⊙ (σ∘ε(u)) )*dΩ | ||
#l(v) = δ( VectorValue(-1,0)⋅v ) | ||
# | ||
#op = AffineFEOperator(a,l,V,V) | ||
#uh = solve(op) | ||
# | ||
#writevtk(Ω,"results",cellfields=["uh"=>uh]) | ||
#writevtk(δ.Γ,"d",cellfields=["uh"=>uh]) | ||
|
||
end # module |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters