test4 Program

Uses

  • program~~test4~~UsesGraph program~test4 test4 forunittest forunittest program~test4->forunittest module~fordiff fordiff program~test4->module~fordiff module~mod_func4 mod_func4 program~test4->module~mod_func4 kinds kinds module~fordiff->kinds module~mod_func4->kinds

Calls

program~~test4~~CallsGraph program~test4 test4 check check program~test4->check interface~derivative fordiff::derivative program~test4->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) :: dfdx_f
real(kind=rk) :: dfdx_b
real(kind=rk) :: dfdx_c
real(kind=rk) :: expected_dfdx
type(unit_test) :: ut

Source Code

program test4

   use fordiff
   use mod_func4
   use forunittest

   implicit none

   real(rk) :: dfdx_f, dfdx_b, dfdx_c, expected_dfdx
   type(unit_test) :: ut

   ! compute derivative using forward mode
   dfdx_f = derivative(f=func4, x=1.0_rk, h=1e-5_rk, method='forward')
   
   ! compute derivative using backward mode
   dfdx_b = derivative(f=func4, x=1.0_rk, h=1e-5_rk, method='backward')

   ! compute derivative using central mode
   dfdx_c = derivative(f=func4, x=1.0_rk, h=1e-5_rk, method='central')

   ! compute derivative analytically
   expected_dfdx = 2.0_rk*(1.0_rk) + 2.0_rk

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

end program test4