Skip to content

Commit

Permalink
Merge pull request #653 from ConnorMallon/shape_derivative
Browse files Browse the repository at this point in the history
Shape derivative
  • Loading branch information
amartinhuertas authored Feb 27, 2022
2 parents 154ee18 + eb39b81 commit 36bc2a7
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 24 deletions.
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased

### Added
- Extra support for dual number propagation. Since PR [#653](https://github.com/gridap/Gridap.jl/pull/653)

## [0.17.8] - 2022-02-14

### Added
Expand Down
14 changes: 7 additions & 7 deletions src/CellData/CellFields.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
A single point or an array of points on the cells of a Triangulation
CellField objects can be evaluated efficiently at CellPoint instances.
"""
struct CellPoint{DS} <: CellDatum
cell_ref_point::AbstractArray{<:Union{Point,AbstractArray{<:Point}}}
cell_phys_point::AbstractArray{<:Union{Point,AbstractArray{<:Point}}}
trian::Triangulation
struct CellPoint{DS,A,B,C} <: CellDatum
cell_ref_point::A
cell_phys_point::B
trian::C
domain_style::DS
end

function CellPoint(
cell_ref_point::AbstractArray{<:Union{Point,AbstractArray{<:Point}}},
cell_ref_point::AbstractArray,
trian::Triangulation,
domain_style::ReferenceDomain)

Expand All @@ -20,7 +20,7 @@ function CellPoint(
end

function CellPoint(
cell_phys_point::AbstractArray{<:Union{Point,AbstractArray{<:Point}}},
cell_phys_point::AbstractArray,
trian::Triangulation,
domain_style::PhysicalDomain)
cell_map = get_cell_map(trian)
Expand All @@ -38,7 +38,7 @@ function get_data(f::CellPoint)
end

get_triangulation(f::CellPoint) = f.trian
DomainStyle(::Type{CellPoint{DS}}) where DS = DS()
DomainStyle(::Type{CellPoint{DS,A,B,C}}) where {DS,A,B,C} = DS()

function change_domain(a::CellPoint,::ReferenceDomain,::PhysicalDomain)
CellPoint(a.cell_ref_point,a.cell_phys_point,a.trian,PhysicalDomain())
Expand Down
1 change: 0 additions & 1 deletion src/Fields/AffineMaps.jl
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,3 @@ function lazy_map(::typeof(∇),a::LazyArray{<:Fill{typeof(affine_map)}})
gradients = a.args[1]
lazy_map(constant_field,gradients)
end

2 changes: 1 addition & 1 deletion src/Geometry/AppendedTriangulations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ function get_grid(t::AppendedTriangulation)
lazy_append(a,b)
end

function get_glue(t::AppendedTriangulation,::Val{D}) where D
function get_glue(t::AppendedTriangulation,::Val{D}) where D
a = get_glue(t.a,Val(D))
b = get_glue(t.b,Val(D))
if a==nothing || b==nothing
Expand Down
88 changes: 74 additions & 14 deletions src/Polynomials/MonomialBases.jl
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,17 @@ end
return_type(::MonomialBasis{D,T}) where {D,T} = T

# Field implementation

function return_cache(f::MonomialBasis{D,T},x::AbstractVector{<:Point}) where {D,T}
@assert D == length(eltype(x)) "Incorrect number of point components"
zT = zero(T)
zxi = zero(eltype(eltype(x)))
Tp = typeof( zT*zxi*zxi + zT*zxi*zxi )
np = length(x)
ndof = length(f.terms)*num_components(T)
n = 1 + _maximum(f.orders)
r = CachedArray(zeros(T,(np,ndof)))
v = CachedArray(zeros(T,(ndof,)))
c = CachedArray(zeros(eltype(T),(D,n)))
r = CachedArray(zeros(Tp,(np,ndof)))
v = CachedArray(zeros(Tp,(ndof,)))
c = CachedArray(zeros(eltype(Tp),(D,n)))
(r, v, c)
end

Expand All @@ -146,31 +148,54 @@ function evaluate!(cache,f::MonomialBasis{D,T},x::AbstractVector{<:Point}) where
r.array
end

function return_cache(
function _return_cache(
fg::FieldGradientArray{1,MonomialBasis{D,V}},
x::AbstractVector{<:Point}) where {D,V}
x::AbstractVector{<:Point},
::Type{T},
TisbitsType::Val{true}) where {D,V,T}

f = fg.fa
@assert D == length(eltype(x)) "Incorrect number of point components"
np = length(x)
ndof = length(f.terms)*num_components(V)
xi = testitem(x)
T = gradient_type(V,xi)
n = 1 + _maximum(f.orders)
r = CachedArray(zeros(T,(np,ndof)))
v = CachedArray(zeros(T,(ndof,)))
c = CachedArray(zeros(eltype(T),(D,n)))
g = CachedArray(zeros(eltype(T),(D,n)))
(r, v, c, g)
(r,v,c,g)
end

function evaluate!(
function _return_cache(
fg::FieldGradientArray{1,MonomialBasis{D,V}},
x::AbstractVector{<:Point},
::Type{T},
TisbitsType::Val{false}) where {D,V,T}

cache = _return_cache(fg,x,T,Val{true}())
z = CachedArray(zeros(eltype(T),D))
(cache...,z)
end

function return_cache(
fg::FieldGradientArray{1,MonomialBasis{D,V}},
x::AbstractVector{<:Point}) where {D,V}

xi = testitem(x)
T = gradient_type(V,xi)
TisbitsType = Val(isbits(T))
_return_cache(fg,x,T,TisbitsType)
end

function _evaluate!(
cache,
fg::FieldGradientArray{1,MonomialBasis{D,T}},
x::AbstractVector{<:Point}) where {D,T}
x::AbstractVector{<:Point},
TisbitsType::Val{true}) where {D,T}

f = fg.fa
r, v, c, g = cache
z = zero(Mutable(VectorValue{D,eltype(T)}))
np = length(x)
ndof = length(f.terms) * num_components(T)
n = 1 + _maximum(f.orders)
Expand All @@ -180,14 +205,49 @@ function evaluate!(
setsize!(g,(D,n))
for i in 1:np
@inbounds xi = x[i]
_gradient_nd!(v,xi,f.orders,f.terms,c,g,T)
_gradient_nd!(v,xi,f.orders,f.terms,c,g,z,T)
for j in 1:ndof
@inbounds r[i,j] = v[j]
end
end
r.array
end

function _evaluate!(
cache,
fg::FieldGradientArray{1,MonomialBasis{D,T}},
x::AbstractVector{<:Point},
TisbitsType::Val{false}) where {D,T}

f = fg.fa
r, v, c, g, z = cache
np = length(x)
ndof = length(f.terms) * num_components(T)
n = 1 + _maximum(f.orders)
setsize!(r,(np,ndof))
setsize!(v,(ndof,))
setsize!(c,(D,n))
setsize!(g,(D,n))
for i in 1:np
@inbounds xi = x[i]
_gradient_nd!(v,xi,f.orders,f.terms,c,g,z,T)
for j in 1:ndof
@inbounds r[i,j] = v[j]
end
end
r.array
end

function evaluate!(
cache,
fg::FieldGradientArray{1,MonomialBasis{D,T}},
x::AbstractVector{<:Point}) where {D,T}

r, v, c, g = cache
TisbitsType = Val(isbitstype(eltype(c)))
_evaluate!(cache,fg,x,TisbitsType)
end

function return_cache(
fg::FieldGradientArray{2,MonomialBasis{D,V}},
x::AbstractVector{<:Point}) where {D,V}
Expand Down Expand Up @@ -372,15 +432,15 @@ function _gradient_nd!(
terms::AbstractVector{CartesianIndex{D}},
c::AbstractMatrix{T},
g::AbstractMatrix{T},
z::AbstractVector{T},
::Type{V}) where {G,T,D,V}

dim = D
for d in 1:dim
_evaluate_1d!(c,x,orders[d],d)
_gradient_1d!(g,x,orders[d],d)
end

z = zero(Mutable(VectorValue{D,T}))

o = one(T)
k = 1

Expand Down
1 change: 0 additions & 1 deletion src/TensorValues/VectorValueTypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,3 @@ length(::VectorValue{D}) where {D} = length(VectorValue{D})

num_components(::Type{<:VectorValue{D}}) where {D} = length(VectorValue{D})
num_components(::VectorValue{D}) where {D} = num_components(VectorValue{D})

0 comments on commit 36bc2a7

Please sign in to comment.