@@ -17,7 +17,7 @@ module cobylb_mod
1717!
1818! Started: July 2021
1919!
20- ! Last Modified: Tue 12 Aug 2025 04:58:06 PM CST
20+ ! Last Modified: Tue 16 Sep 2025 12:36:40 PM CST
2121!- -------------------------------------------------------------------------------------------------!
2222
2323implicit none
@@ -42,7 +42,7 @@ subroutine cobylb(calcfc, iprint, maxfilt, maxfun, amat, bvec, ctol, cweight, et
4242use , non_intrinsic :: checkexit_mod, only : checkexit
4343use , non_intrinsic :: consts_mod, only : RP, IK, ZERO, ONE, HALF, TENTH, EPS, REALMAX, DEBUGGING, MIN_MAXFILT
4444use , non_intrinsic :: debug_mod, only : assert
45- use , non_intrinsic :: evaluate_mod, only : evaluate
45+ use , non_intrinsic :: evaluate_mod, only : evaluate, moderatec
4646use , non_intrinsic :: history_mod, only : savehist, rangehist
4747use , non_intrinsic :: infnan_mod, only : is_nan, is_posinf, is_finite
4848use , non_intrinsic :: infos_mod, only : INFO_DFT, MAXTR_REACHED, SMALL_TR_RADIUS, DAMAGING_ROUNDING, CALLBACK_TERMINATE
@@ -393,8 +393,10 @@ subroutine cobylb(calcfc, iprint, maxfilt, maxfun, amat, bvec, ctol, cweight, et
393393 cstrv = cval(j)
394394 else
395395 ! Evaluate the objective and constraints at X, taking care of possible Inf/NaN values.
396- constr(1 :m_lcon) = matprod(x, amat) - bvec
397- call evaluate(calcfc, x, f, constr(m_lcon + 1 :m))
396+ constr(1 :m_lcon) = moderatec(matprod(x, amat) - bvec) ! Linear constraints
397+ call evaluate(calcfc, x, f, constr(m_lcon + 1 :m)) ! Nonlinear constraints
398+ ! Note that EVALUATE moderates the nonlinear constraint values. Thus we also moderate the
399+ ! linear constraint values here to make CSTRV consistent.
398400 cstrv = maximum([ZERO, constr])
399401 nf = nf + 1_IK
400402 ! Save X, F, CONSTR, CSTRV into the history.
@@ -586,8 +588,10 @@ subroutine cobylb(calcfc, iprint, maxfilt, maxfun, amat, bvec, ctol, cweight, et
586588 cstrv = cval(j)
587589 else
588590 ! Evaluate the objective and constraints at X, taking care of possible Inf/NaN values.
589- constr(1 :m_lcon) = matprod(x, amat) - bvec
590- call evaluate(calcfc, x, f, constr(m_lcon + 1 :m))
591+ constr(1 :m_lcon) = moderatec(matprod(x, amat) - bvec) ! Linear constraints
592+ call evaluate(calcfc, x, f, constr(m_lcon + 1 :m)) ! Nonlinear constraints
593+ ! Note that EVALUATE moderates the nonlinear constraint values. Thus we also moderate the
594+ ! linear constraint values here to make CSTRV consistent.
591595 cstrv = maximum([ZERO, constr])
592596 nf = nf + 1_IK
593597 ! Save X, F, CONSTR, CSTRV into the history.
@@ -652,8 +656,10 @@ subroutine cobylb(calcfc, iprint, maxfilt, maxfun, amat, bvec, ctol, cweight, et
652656! Ensure that D has not been updated after SHORTD == TRUE occurred, or the code below is incorrect.
653657x = sim(:, n + 1 ) + d
654658if (info == SMALL_TR_RADIUS .and. shortd .and. norm(x - sim(:, n + 1 )) > 1.0E-3_RP * rhoend .and. nf < maxfun) then
655- constr(1 :m_lcon) = matprod(x, amat) - bvec
656- call evaluate(calcfc, x, f, constr(m_lcon + 1 :m))
659+ constr(1 :m_lcon) = moderatec(matprod(x, amat) - bvec) ! Linear constraints
660+ call evaluate(calcfc, x, f, constr(m_lcon + 1 :m)) ! Nonlinear constraints
661+ ! Note that EVALUATE moderates the nonlinear constraint values. Thus we also moderate the linear
662+ ! constraint values here to make CSTRV consistent.
657663 cstrv = maximum([ZERO, constr])
658664 nf = nf + 1_IK
659665 ! Save X, F, CONSTR, CSTRV into the history.
0 commit comments