7 module function fnh_fcn(this, x) result(f)
8 class(fcnnvar_helper),
intent(in) :: this
9 real(real64),
intent(in),
dimension(:) :: x
11 if (
associated(this%m_fcn))
then
17 module function fnh_is_fcn_defined(this) result(x)
18 class(fcnnvar_helper),
intent(in) :: this
20 x =
associated(this%m_fcn)
24 module subroutine fnh_set_fcn(this, fcn, nvar)
25 class(fcnnvar_helper),
intent(inout) :: this
26 procedure(fcnnvar),
intent(in),
pointer :: fcn
27 integer(int32),
intent(in) :: nvar
33 module function fnh_get_nvar(this) result(n)
34 class(fcnnvar_helper),
intent(in) :: this
40 module subroutine fnh_set_grad(this, fcn)
41 class(fcnnvar_helper),
intent(inout) :: this
42 procedure(gradientfcn),
pointer,
intent(in) :: fcn
47 module function fnh_is_grad_defined(this) result(x)
48 class(fcnnvar_helper),
intent(in) :: this
50 x =
associated(this%m_grad)
54 module subroutine fnh_grad_fcn(this, x, g, fv, err)
56 class(fcnnvar_helper),
intent(in) :: this
57 real(real64),
intent(inout),
dimension(:) :: x
58 real(real64),
intent(out),
dimension(:) :: g
59 real(real64),
intent(in),
optional :: fv
60 integer(int32),
intent(out),
optional :: err
63 real(real64),
parameter :: zero = 0.0d0
66 integer(int32) :: j, n, flag
67 real(real64) :: eps, epsmch, h, temp, f, f1
70 if (
present(err)) err = 0
72 n = this%get_variable_count()
76 if (
size(x) /= n)
then
78 else if (
size(g) /= n)
then
83 if (
present(err)) err = flag
88 if (.not.this%is_fcn_defined())
return
89 if (this%is_gradient_defined())
then
91 call this%m_grad(x, g)
101 epsmch = epsilon(epsmch)
108 if (h == zero) h = eps