diff --git a/test/PolynomialsTests/BernsteinBasesTests.jl b/test/PolynomialsTests/BernsteinBasesTests.jl index 17ffc99ec..1a06398f1 100644 --- a/test/PolynomialsTests/BernsteinBasesTests.jl +++ b/test/PolynomialsTests/BernsteinBasesTests.jl @@ -4,6 +4,8 @@ using Test using Gridap.TensorValues using Gridap.Fields using Gridap.Polynomials +using Gridap.Polynomials: binoms +using ForwardDiff @test isHierarchical(Bernstein) == false @@ -81,26 +83,41 @@ test_field_array(b,x[1],bx[1,:],grad=∇bx[1,:],gradgrad=Hbx[1,:]) # Order 3 +function bernstein(K,N) + b = binoms(Val(K)) + t -> b[N+1]*(t^N)*((1-t)^(K-N)) +end +_∇(b) = t -> ForwardDiff.derivative(b, t) +_H(b) = t -> ForwardDiff.derivative(y -> ForwardDiff.derivative(b, y), t) + order = 3 b = BernsteinBasis(Val(1),V,order) # x=x^1; x2 = x^2; x3 = x^3 # -x3+3x2-3x+1 3x3-6x2+3x -3x3+3x2 x3 -bx = [ 1.0 0.0 0.0 0.0 - 0.0 0.0 0.0 1.0 - .216 .432 .288 .064] +bx = [ bernstein(order,n)( xi[1]) for xi in x, n in 0:order] # -3x2+6x-3 9x2-12x+3 -9x2+6x 3x2 -∇bx = G[ -3. 3. 0. 0. - 0. 0. -3. 3. - -1.08 -.36 .96 .48] +∇bx = [ G(_∇(bernstein(order,n))(xi[1])) for xi in x, n in 0:order] # -6x+6 18x-12 -18x+6 6x -Hbx = H[ 6. -12. 6. 0. - 0. 6. -12. 6. - 3.6 -4.8 -1.2 2.4] +Hbx = [ H(_H(bernstein(order,n))(xi[1])) for xi in x, n in 0:order] + +test_field_array(b,x,bx,≈, grad=∇bx,gradgrad=Hbx) +test_field_array(b,x[1],bx[1,:],grad=∇bx[1,:],gradgrad=Hbx[1,:]) + + +# Order 4 + +order = 4 +b = BernsteinBasis(Val(1),V,order) + +bx = [ bernstein(order,n)( xi[1]) for xi in x, n in 0:order] +∇bx = [ G(_∇(bernstein(order,n))(xi[1])) for xi in x, n in 0:order] +Hbx = [ H(_H(bernstein(order,n))(xi[1])) for xi in x, n in 0:order] test_field_array(b,x,bx,≈, grad=∇bx,gradgrad=Hbx) test_field_array(b,x[1],bx[1,:],grad=∇bx[1,:],gradgrad=Hbx[1,:]) + end # module