diff --git a/src/QGradMonomialBases.jl b/src/QGradMonomialBases.jl index 1a7d5ee..70063e0 100644 --- a/src/QGradMonomialBases.jl +++ b/src/QGradMonomialBases.jl @@ -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 @@ -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 diff --git a/test/QGradMonomialBasesTests.jl b/test/QGradMonomialBasesTests.jl index 2c6b4ce..9329207 100644 --- a/test/QGradMonomialBasesTests.jl +++ b/test/QGradMonomialBasesTests.jl @@ -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), @@ -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)]