Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding support to DiracDelta for generic points in the domain #837

Merged
merged 17 commits into from
Oct 17, 2022
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `lastindex` for `MultiValue`s for consistent usage of `[end]` as per `length`. Since PR [#834](https://github.com/gridap/Gridap.jl/pull/834)
- BDM (Brezzi-Douglas-Marini) ReferenceFEs in PR [#823](https://github.com/gridap/Gridap.jl/pull/823)
- Implemented `ConstantFESpace`. This space allows, e.g., to impose the mean value of the pressure via an additional unknown/equation (a Lagrange multiplier). Since PR [#836](https://github.com/gridap/Gridap.jl/pull/836)

- Added support to construct `DiracDelta` at generic `Point`(s) in the domain. Since PR [#837](https://github.com/gridap/Gridap.jl/pull/837)
## [0.17.14] - 2022-07-29

### Added
Expand Down
37 changes: 35 additions & 2 deletions src/CellData/DiracDeltas.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
abstract type DiracDeltaSupportType <: GridapType end
struct IsGridEntity <: DiracDeltaSupportType end
struct NotGridEntity <: DiracDeltaSupportType end

struct DiracDelta{D} <: GridapType
struct DiracDelta{D,S<:DiracDeltaSupportType} <: GridapType
Γ::Triangulation{D}
dΓ::Measure
end
Expand All @@ -24,7 +27,7 @@ function DiracDelta{D}(
trian = BodyFittedTriangulation(model,face_grid,face_to_bgface)
Γ = BoundaryTriangulation(trian,glue)
dΓ = Measure(Γ,degree)
DiracDelta(Γ,dΓ)
DiracDelta{D,IsGridEntity}(Γ,dΓ)
end

function DiracDelta{D}(
Expand Down Expand Up @@ -76,3 +79,33 @@ end
function get_triangulation(d::DiracDelta)
d.Γ
end

# For handling DiracDelta at a generic Point in the domain #

function DiracDelta(x::Point{D,T}, model::DiscreteModel{D}) where {D,T}
trian = Triangulation(model)
cache1 = _point_to_cell_cache(KDTreeSearch(),trian)
cell = _point_to_cell!(cache1, x)
point_grid = UnstructuredGrid([x])
point_model = UnstructuredDiscreteModel(point_grid)
point_trian = Triangulation(point_model)
dx = Measure(point_trian,1)
DiracDelta{0,NotGridEntity}(point_trian,dx)
end

function DiracDelta(v::Vector{Point{D,T}},model::DiscreteModel{D}) where {D,T}
trian = Triangulation(model)
cache1 = _point_to_cell_cache(KDTreeSearch(),trian)
cell = map(x -> _point_to_cell!(cache1, x), v)
point_grid = UnstructuredGrid(v)
point_model = UnstructuredDiscreteModel(point_grid)
point_trian = Triangulation(point_model)
dx = Measure(point_trian,1)
DiracDelta{0,NotGridEntity}(point_trian,dx)
end

function evaluate!(cache,d::DiracDelta{0,NotGridEntity},f::CellField)
amartinhuertas marked this conversation as resolved.
Show resolved Hide resolved
d_f = lazy_map(f,d.Γ.grid.node_coordinates)
dc = DomainContribution()
add_contribution!(dc, d.Γ, d_f)
end
16 changes: 16 additions & 0 deletions test/CellDataTests/DiracDeltasTests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,22 @@ degree = 2
δ = DiracDelta{0}(model,tags=[2,4])
@test sum(δ(v)) ≈ 5

# Tests for DiracDelta at a generic Point in the domain #

p = VectorValue(0.2,0.3)
amartinhuertas marked this conversation as resolved.
Show resolved Hide resolved
δ = DiracDelta(p,model)
@test sum(δ(v)) == v(p)
amartinhuertas marked this conversation as resolved.
Show resolved Hide resolved

pvec = [p,π*p]
δ = DiracDelta(pvec,model)
@test sum(δ(v)) == sum(v(pvec))
amartinhuertas marked this conversation as resolved.
Show resolved Hide resolved

# below passes but cannot use FESpace and FEFunction here
amartinhuertas marked this conversation as resolved.
Show resolved Hide resolved
# reffe = ReferenceFE(lagrangian,Float64,3)
# V = FESpace(model,reffe,conformity=:L2)
# uh = FEFunction(V,rand(num_free_dofs(V)))
# @test sum(d(uh)) == uh(p)

#using Gridap
amartinhuertas marked this conversation as resolved.
Show resolved Hide resolved
#
#order = 2
Expand Down
3 changes: 3 additions & 0 deletions test/TensorValuesTests/IndexingTests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ v = VectorValue{4}(a)
@test size(v) == (4,)
@test length(v) == 4
@test lastindex(v) == length(v)
@test v[end] == a[end]
amartinhuertas marked this conversation as resolved.
Show resolved Hide resolved

for (k,i) in enumerate(eachindex(v))
@test v[i] == a[k]
Expand All @@ -24,6 +25,7 @@ t = TensorValue{2}(a)
@test size(t) == (2,2)
@test length(t) == 4
@test lastindex(t) == length(t)
@test t[end] == a[end]

for (k,i) in enumerate(eachindex(t))
@test t[i] == a[k]
Expand All @@ -43,6 +45,7 @@ t = TensorValue(convert(SMatrix{2,2,Int},s))
@test size(s) == (2,2)
@test length(s) == 4
@test lastindex(s) == length(s)
@test s[end] == 22

for (k,i) in enumerate(eachindex(t))
@test s[i] == t[k]
Expand Down