test6 Program

Uses

  • program~~test6~~UsesGraph program~test6 test6 forunittest forunittest program~test6->forunittest module~fordiff fordiff program~test6->module~fordiff module~mod_func6 mod_func6 program~test6->module~mod_func6 kinds kinds module~fordiff->kinds module~mod_func6->kinds

Calls

program~~test6~~CallsGraph program~test6 test6 check check program~test6->check interface~derivative fordiff::derivative program~test6->interface~derivative proc~complex_step_derivative_t0_t0 fordiff::complex_step_derivative_T0_T0 interface~derivative->proc~complex_step_derivative_t0_t0 proc~complex_step_derivative_t0_t1 fordiff::complex_step_derivative_T0_T1 interface~derivative->proc~complex_step_derivative_t0_t1 proc~complex_step_derivative_t1_t1 fordiff::complex_step_derivative_T1_T1 interface~derivative->proc~complex_step_derivative_t1_t1 proc~finite_difference_t0_t0 fordiff::finite_difference_T0_T0 interface~derivative->proc~finite_difference_t0_t0 proc~finite_difference_t0_t1 fordiff::finite_difference_T0_T1 interface~derivative->proc~finite_difference_t0_t1 proc~finite_difference_t1_t1 fordiff::finite_difference_T1_T1 interface~derivative->proc~finite_difference_t1_t1 proc~finite_difference_backward_t0_t0 fordiff::finite_difference_backward_T0_T0 proc~finite_difference_t0_t0->proc~finite_difference_backward_t0_t0 proc~finite_difference_central_t0_t0 fordiff::finite_difference_central_T0_T0 proc~finite_difference_t0_t0->proc~finite_difference_central_t0_t0 proc~finite_difference_forward_t0_t0 fordiff::finite_difference_forward_T0_T0 proc~finite_difference_t0_t0->proc~finite_difference_forward_t0_t0 proc~finite_difference_backward_t0_t1 fordiff::finite_difference_backward_T0_T1 proc~finite_difference_t0_t1->proc~finite_difference_backward_t0_t1 proc~finite_difference_central_t0_t1 fordiff::finite_difference_central_T0_T1 proc~finite_difference_t0_t1->proc~finite_difference_central_t0_t1 proc~finite_difference_forward_t0_t1 fordiff::finite_difference_forward_T0_T1 proc~finite_difference_t0_t1->proc~finite_difference_forward_t0_t1 proc~finite_difference_backward_t1_t1 fordiff::finite_difference_backward_T1_T1 proc~finite_difference_t1_t1->proc~finite_difference_backward_t1_t1 proc~finite_difference_central_t1_t1 fordiff::finite_difference_central_T1_T1 proc~finite_difference_t1_t1->proc~finite_difference_central_t1_t1 proc~finite_difference_forward_t1_t1 fordiff::finite_difference_forward_T1_T1 proc~finite_difference_t1_t1->proc~finite_difference_forward_t1_t1

Variables

Type Attributes Name Initial
real(kind=rk), dimension(:,:), allocatable :: dfdx_f
real(kind=rk), dimension(:,:), allocatable :: dfdx_b
real(kind=rk), dimension(:,:), allocatable :: dfdx_c
real(kind=rk), dimension(:,:), allocatable :: expected_dfdx
integer :: i
type(unit_test) :: ut

Source Code

program test6

   use fordiff
   use mod_func6
   use forunittest

   implicit none

   real(rk), dimension(:,:), allocatable :: dfdx_f, dfdx_b, dfdx_c, expected_dfdx
   integer                               :: i
   type(unit_test) :: ut

   ! compute derivative using forward, backward and central difference
   dfdx_f = derivative(f=func6, x=[1.0_rk, -1.0_rk], h=1e-5_rk, method='forward')
   dfdx_b = derivative(f=func6, x=[1.0_rk, -1.0_rk], h=1e-5_rk, method='backward')
   dfdx_c = derivative(f=func6, x=[1.0_rk, -1.0_rk], h=1e-5_rk, method='central')

   ! compute reference derivative
   allocate(expected_dfdx(size(dfdx_f,1), size(dfdx_f,2)))
   expected_dfdx(1,1) = 2.0_rk*(1.0_rk)
   expected_dfdx(1,2) = (-1.0_rk)
   expected_dfdx(2,1) = 3.0_rk*(1.0_rk)**2
   expected_dfdx(2,2) = 1.5_rk*(-1.0_rk)**2
   expected_dfdx(3,1) = 4.0_rk*(1.0_rk)**3
   expected_dfdx(3,2) = 2.0_rk*(-1.0_rk)**3   

   ! check if derivative is correct
   call ut%check(dfdx_f, expected_dfdx, 1.0e-2_rk, 'test6.1' )
   call ut%check(dfdx_b, expected_dfdx, 1.0e-2_rk, 'test6.1' )
   call ut%check(dfdx_c, expected_dfdx, 1.0e-2_rk, 'test6.1' )

   deallocate(dfdx_f, dfdx_b, dfdx_c, expected_dfdx)

end program test6