Skip to content

Commit

Permalink
fix Bernstein test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Antoinemarteau committed Jan 6, 2025
1 parent 9555fe9 commit 6b07a81
Showing 1 changed file with 26 additions and 9 deletions.
35 changes: 26 additions & 9 deletions test/PolynomialsTests/BernsteinBasesTests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

0 comments on commit 6b07a81

Please sign in to comment.