7 module subroutine vfh_set_fcn(this, fcn, nfcn, nvar)
8 class(vecfcn_helper),
intent(inout) :: this
9 procedure(vecfcn),
intent(in),
pointer :: fcn
10 integer(int32),
intent(in) :: nfcn, nvar
17 module subroutine vfh_set_jac(this, jac)
18 class(vecfcn_helper),
intent(inout) :: this
19 procedure(jacobianfcn),
intent(in),
pointer :: jac
24 module function vfh_is_fcn_defined(this) result(x)
25 class(vecfcn_helper),
intent(in) :: this
27 x =
associated(this%m_fcn)
31 module function vfh_is_jac_defined(this) result(x)
32 class(vecfcn_helper),
intent(in) :: this
34 x =
associated(this%m_jac)
38 module subroutine vfh_fcn(this, x, f)
39 class(vecfcn_helper),
intent(in) :: this
40 real(real64),
intent(in),
dimension(:) :: x
41 real(real64),
intent(out),
dimension(:) :: f
42 if (this%is_fcn_defined())
then
48 module subroutine vfh_jac_fcn(this, x, jac, fv, work, olwork, err)
50 class(vecfcn_helper),
intent(in) :: this
51 real(real64),
intent(inout),
dimension(:) :: x
52 real(real64),
intent(out),
dimension(:,:) :: jac
53 real(real64),
intent(in),
dimension(:),
optional,
target :: fv
54 real(real64),
intent(out),
dimension(:),
optional,
target :: work
55 integer(int32),
intent(out),
optional :: olwork, err
58 real(real64),
parameter :: zero = 0.0d0
61 integer(int32) :: j, m, n, lwork, flag
62 real(real64) :: eps, epsmch, h, temp
63 real(real64),
pointer,
dimension(:) :: fptr, f1ptr
64 real(real64),
allocatable,
target,
dimension(:) :: wrk
67 if (
present(err)) err = 0
70 m = this%get_equation_count()
71 n = this%get_variable_count()
75 if (
size(x) /= n)
then
77 else if (
size(jac, 1) /= m .or.
size(jac, 2) /= n)
then
82 if (
present(err)) err = flag
87 if (.not.this%is_fcn_defined())
return
88 if (
associated(this%m_jac))
then
90 if (
present(olwork))
then
96 call this%m_jac(x, jac)
105 if (
present(olwork))
then
113 if (
present(work))
then
114 if (
size(work) < lwork)
then
116 if (
present(err)) err = 5
120 if (
present(fv))
then
121 if (
size(fv) < m)
then
123 if (
present(err)) err = 4
128 fptr => work(m+1:2*m)
129 call this%fcn(x, fptr)
132 allocate(wrk(lwork), stat = flag)
135 if (
present(err)) err = -1
139 if (
present(fv))
then
143 call this%fcn(x, fptr)
148 epsmch = epsilon(epsmch)
155 if (h == zero) h = eps
157 call this%fcn(x, f1ptr)
159 jac(:,j) = (f1ptr - fptr) / h
165 module function vfh_get_nfcn(this) result(n)
166 class(vecfcn_helper),
intent(in) :: this
172 module function vfh_get_nvar(this) result(n)
173 class(vecfcn_helper),
intent(in) :: this