Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jchristopherson committed Sep 21, 2023
1 parent ab60694 commit 289040b
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 0 deletions.
80 changes: 80 additions & 0 deletions test/friction_model_tests.f90
Original file line number Diff line number Diff line change
Expand Up @@ -134,5 +134,85 @@ function test_maxwell() result(rst)
end if
end function

! ------------------------------------------------------------------------------
function test_gmsm() result(rst)
! Arguments
logical :: rst

! Local Variables
logical :: check
integer(int32) :: i, j
type(generalized_maxwell_slip_model) :: mdl
real(real64) :: f, nrm, c, x, v, muc, mus, bv, s0, alpha, vs
real(real64) :: dzdt(3), z(3), f_ans, g, a1, a2, s
real(real64) :: args(9)

! Initialization
rst = .true.
call mdl%initialize(3)
call random_number(nrm)
call random_number(c)
call random_number(x)
call random_number(v)
call random_number(muc)
call random_number(mus)
call random_number(bv)
call random_number(s0)
call random_number(alpha)
call random_number(vs)
call random_number(args)
call random_number(z)

! Ensure sum(vi) = 1
args(3) = 1.0d0 - (args(6) + args(9))

! Define the model
j = 0
do i = 1, size(args), 3
j = j + 1
check = mdl%set_element_stiffness(j, args(i))
check = mdl%set_element_damping(j, args(i+1))
check = mdl%set_element_scaling(j, args(i+2))
end do
mdl%attraction_coefficient = c
mdl%coulomb_coefficient = muc
mdl%shape_parameter = alpha
mdl%static_coefficient = mus
mdl%stiffness = s0
mdl%stribeck_velocity = vs
mdl%viscous_damping = bv

! Compute the solution
a1 = mdl%coulomb_coefficient * nrm / mdl%stiffness
a2 = nrm * (mdl%static_coefficient - mdl%coulomb_coefficient) / &
mdl%stiffness
s = abs(v) / mdl%stribeck_velocity
g = a1 + a2 / (1.0d0 + s**mdl%shape_parameter)
f_ans = 0.0d0
do i = 1, 3
if (abs(z(i)) < g) then
dzdt(i) = v
else
dzdt(i) = sign(1.0d0, v) * mdl%get_element_scaling(i) * &
mdl%attraction_coefficient * &
(1.0d0 - z(i) / (mdl%get_element_scaling(i) * g))
end if
f_ans = f_ans + mdl%get_element_stiffness(i) * z(i) + &
mdl%get_element_damping(i) * dzdt(i)
end do
f_ans = f_ans + mdl%viscous_damping * v

! Test
f = mdl%evaluate(0.0d0, x, v, nrm, z)
if (.not.assert(f, f_ans)) then
rst = .false.
print *, "TEST FAILED: test_gmsm -1"
end if
if (.not.mdl%has_internal_state()) then
rst = .false.
print *, "TEST FAILED: test_gmsm -2"
end if
end function

! ------------------------------------------------------------------------------
end module
3 changes: 3 additions & 0 deletions test/friction_test.f90
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ program test

check = test_maxwell()
if (.not.check) flag = 3

check = test_gmsm()
if (.not.check) flag = 4

! End
stop flag
Expand Down

0 comments on commit 289040b

Please sign in to comment.