Skip to content

Commit

Permalink
Added extra type parameter in QGradMonomialBasis
Browse files Browse the repository at this point in the history
  • Loading branch information
fverdugo committed Jul 22, 2019
1 parent 412f479 commit e33ac68
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 21 deletions.
27 changes: 13 additions & 14 deletions src/QGradMonomialBases.jl
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@

# Types and constructors

struct QGradMonomialBasis{P,G,D} <: TensorPolynomialBasis{P,P,G}
struct QGradMonomialBasis{P,V,G,D} <: TensorPolynomialBasis{P,V,G}
order::Int
terms::CartesianIndices{D}
perms::Matrix{Int}
end

function (::Type{QGradMonomialBasis{P}})(order::Int) where P
function (::Type{QGradMonomialBasis{P,V}})(order::Int) where {P,V}
D = _length(P)
G = _gradient_type(P,P)
@assert _length(V) == D
G = _gradient_type(V,P)
n1d = order+1
t = fill(n1d,D)
t[1] = order
terms = CartesianIndices(tuple(t...))
perms = _prepare_perms(D)
QGradMonomialBasis{P,G,D}(order,terms,perms)
QGradMonomialBasis{P,V,G,D}(order,terms,perms)
end

# Implementation of the interface

length(b::QGradMonomialBasis{P,G,D}) where {P,G,D} = D*b.order*(b.order+1)^(D-1)
length(b::QGradMonomialBasis{P,V,G,D}) where {P,V,G,D} = D*b.order*(b.order+1)^(D-1)

ndims(b::QGradMonomialBasis{P,G,D}) where {P,G,D} = D
ndims(b::QGradMonomialBasis{P,V,G,D}) where {P,V,G,D} = D

function ScratchData(b::QGradMonomialBasis{P}) where P
V = P
function ScratchData(b::QGradMonomialBasis{P,V}) where {P,V}
T = eltype(V)
dim = _length(P)
n1d = b.order+1
Expand All @@ -35,19 +35,18 @@ function ScratchData(b::QGradMonomialBasis{P}) where P
end

function evaluate!(
v::AbstractVector{P},
b::QGradMonomialBasis{P,G,D},
v::AbstractVector{V},
b::QGradMonomialBasis{P,V,G,D},
x::P,
cache::MonomialBasisCache) where {P,G,D}
cache::MonomialBasisCache) where {P,V,G,D}
_evaluate_nd_qgrad!(v,x,b.order,b.terms,b.perms,cache.c)
end

function gradient!(
v::AbstractVector{G},
b::QGradMonomialBasis{P,G,D},
b::QGradMonomialBasis{P,V,G,D},
x::P,
cache::MonomialBasisCache) where {P,G,D}
V = P
cache::MonomialBasisCache) where {P,V,G,D}
_gradient_nd_qgrad!(v,x,b.order,b.terms,b.perms,cache.c,cache.g,V)
end

Expand Down
16 changes: 9 additions & 7 deletions test/QGradMonomialBasesTests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ using Test
using TensorPolynomialBases
using TensorValues

P = VectorValue{3,Float64}
P = VectorValue{3}
V = VectorValue{3,Float64}
order = 1
basis = QGradMonomialBasis{P}(order)
basis = QGradMonomialBasis{P,V}(order)
G = gradient_type(basis)

x = VectorValue(2.0,3.0,5.0)
v = P[
x = VectorValue(2,3,5)
v = V[
(1.0, 0.0, 0.0), (0.0, 1.0, 0.0), (0.0, 0.0, 1.0),
(3.0, 0.0, 0.0), (0.0, 5.0, 0.0), (0.0, 0.0, 2.0),
(5.0, 0.0, 0.0), (0.0, 2.0, 0.0), (0.0, 0.0, 3.0),
Expand All @@ -30,14 +31,15 @@ g = G[
(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 3.0, 2.0, 0.0)]
test_polynomial_basis(basis,x,v,g)

P = VectorValue{2,Float64}
P = VectorValue{2}
V = VectorValue{2,Float64}
order = 2
basis = QGradMonomialBasis{P}(order)
basis = QGradMonomialBasis{P,V}(order)
G = gradient_type(basis)

x = VectorValue(2.0,3.0)

v = P[
v = V[
(1.0, 0.0), (0.0, 1.0), (2.0, 0.0), (0.0, 3.0),
(3.0, 0.0), (0.0, 2.0), (6.0, 0.0), (0.0, 6.0),
(9.0, 0.0), (0.0, 4.0), (18.0, 0.0), (0.0, 12.0)]
Expand Down

0 comments on commit e33ac68

Please sign in to comment.