35 use lapack_interfaces,
only:
dgesv
36 use mpi_f08,
only: mpi_in_place, mpi_max, mpi_min
37 use comm,
only: neko_comm, pe_rank, mpi_real_precision
38 use math,
only: neko_eps
39 use profiler,
only: profiler_start_region, profiler_end_region
45 module subroutine mma_update_cpu(this, iter, x, df0dx, fval, dfdx)
53 class(mma_t),
intent(inout) :: this
54 integer,
intent(in) :: iter
55 real(kind=rp),
dimension(this%n),
intent(inout) :: x
56 real(kind=rp),
dimension(this%n),
intent(in) :: df0dx
57 real(kind=rp),
dimension(this%m),
intent(in) :: fval
58 real(kind=rp),
dimension(this%m, this%n),
intent(in) :: dfdx
60 if (.not. this%is_initialized)
then
61 call neko_error(
"The MMA object is not initialized.")
64 call profiler_start_region(
"MMA update")
67 call profiler_start_region(
"MMA gensub")
68 call mma_gensub_cpu(this, iter, x, df0dx, fval, dfdx)
69 call profiler_end_region(
"MMA gensub")
72 call profiler_start_region(
"MMA subsolve")
73 if (this%subsolver .eq.
"dip")
then
74 call mma_subsolve_dip_cpu(this, x)
75 else if (this%subsolver .eq.
"pdip")
then
76 call mma_subsolve_pdip_cpu(this, x)
78 call neko_error(
"Unrecognized subsolver for MMA in mma_cpu.")
80 call profiler_end_region(
"MMA subsolve")
82 call profiler_end_region(
"MMA update")
84 this%is_updated = .true.
85 end subroutine mma_update_cpu
88 module subroutine mma_kkt_cpu(this, x, df0dx, fval, dfdx)
108 class(mma_t),
intent(inout) :: this
109 real(kind=rp),
dimension(this%n),
intent(in) :: x
110 real(kind=rp),
dimension(this%n),
intent(in) :: df0dx
111 real(kind=rp),
dimension(this%m),
intent(in) :: fval
112 real(kind=rp),
dimension(this%m, this%n),
intent(in) :: dfdx
114 call profiler_start_region(
"MMA KKT computation")
116 if (this%subsolver .eq.
"dip")
then
117 call mma_dip_kkt_cpu(this, x, df0dx, fval, dfdx)
118 else if (this%subsolver .eq.
"pdip")
then
119 call mma_pdip_kkt_cpu(this, x, df0dx, fval, dfdx)
121 call neko_error(
"Unrecognized subsolver for MMA in mma_cpu.")
124 call profiler_end_region(
"MMA KKT computation")
125 end subroutine mma_kkt_cpu
129 module subroutine mma_pdip_kkt_cpu(this, x, df0dx, fval, dfdx)
149 class(mma_t),
intent(inout) :: this
150 real(kind=rp),
dimension(this%n),
intent(in) :: x
151 real(kind=rp),
dimension(this%n),
intent(in) :: df0dx
152 real(kind=rp),
dimension(this%m),
intent(in) :: fval
153 real(kind=rp),
dimension(this%m, this%n),
intent(in) :: dfdx
155 real(kind=rp) :: rez, rezeta
156 real(kind=rp),
dimension(this%m) :: rey, relambda, remu, res
157 real(kind=rp),
dimension(this%n) :: rex, rexsi, reeta
158 real(kind=rp),
dimension(3*this%n+4*this%m+2) :: residual
160 real(kind=rp),
dimension(4*this%m+2) :: residual_small
162 real(kind=rp) :: re_sq_norm
164 rex = df0dx + matmul(transpose(dfdx), this%lambda%x) &
165 - this%xsi%x + this%eta%x
166 rey = this%c%x + this%d%x*this%y%x - this%lambda%x - this%mu%x
167 rez = this%a0 - this%zeta - dot_product(this%lambda%x, this%a%x)
169 relambda = fval - this%a%x * this%z - this%y%x + this%s%x
170 rexsi = this%xsi%x * (x - this%xmin%x)
171 reeta = this%eta%x * (this%xmax%x - x)
172 remu = this%mu%x * this%y%x
173 rezeta = this%zeta * this%z
174 res = this%lambda%x * this%s%x
176 residual = [rex, rey, rez, relambda, rexsi, reeta, remu, rezeta, res]
177 residual_small = [rey, rez, relambda, remu, rezeta, res]
179 this%residumax = maxval(abs(residual))
180 re_sq_norm = norm2(rex)**2 + norm2(rexsi)**2 + norm2(reeta)**2
182 call mpi_allreduce(mpi_in_place, this%residumax, 1, &
183 mpi_real_precision, mpi_max, neko_comm, ierr)
185 call mpi_allreduce(mpi_in_place, re_sq_norm, 1, &
186 mpi_real_precision, mpi_sum, neko_comm, ierr)
188 this%residunorm = sqrt(norm2(residual_small)**2 + re_sq_norm)
189 end subroutine mma_pdip_kkt_cpu
193 module subroutine mma_dip_kkt_cpu(this, x, df0dx, fval, dfdx)
218 class(mma_t),
intent(inout) :: this
219 real(kind=rp),
dimension(this%n),
intent(in) :: x
220 real(kind=rp),
dimension(this%n),
intent(in) :: df0dx
221 real(kind=rp),
dimension(this%m),
intent(in) :: fval
222 real(kind=rp),
dimension(this%m, this%n),
intent(in) :: dfdx
224 real(kind=rp) :: rex, resi, xsi, eta, relambda
225 real(kind=rp) :: residual_max, residual_sq_norm
226 integer :: i, j, ierr
228 residual_max = 0.0_rp
229 residual_sq_norm = 0.0_rp
231 associate(xmin => this%xmin%x, xmax => this%xmax%x, &
232 lambda => this%lambda%x)
238 rex = rex + lambda(i) * dfdx(i, j)
243 if (x(j) .lt. xmin(j) + 1.0e-5_rp .and. rex .gt. 0.0_rp) xsi = rex
245 if (x(j) .gt. xmax(j) - 1.0e-5_rp .and. rex .lt. 0.0_rp) eta = -rex
246 rex = rex + (-xsi + eta)
248 residual_sq_norm = residual_sq_norm + rex**2
249 residual_max = max(abs(rex), residual_max)
250 resi = xsi * (x(j) - xmin(j))
251 residual_sq_norm = residual_sq_norm + resi**2
252 residual_max = max(abs(resi), residual_max)
253 resi = eta * (xmax(j) - x(j))
254 residual_sq_norm = residual_sq_norm + resi**2
255 residual_max = max(abs(resi), residual_max)
260 call mpi_allreduce(mpi_in_place, residual_sq_norm, 1, &
261 mpi_real_precision, mpi_sum, neko_comm, ierr)
262 call mpi_allreduce(mpi_in_place, residual_max, 1, &
263 mpi_real_precision, mpi_max, neko_comm, ierr)
268 relambda = relambda + this%lambda%x(i) * &
269 (this%a%x(i) * this%z + this%y%x(i) - fval(i))
272 this%residumax = max(abs(relambda), residual_max)
273 this%residunorm = sqrt(residual_sq_norm + relambda**2)
275 end subroutine mma_dip_kkt_cpu
281 subroutine mma_gensub_cpu(this, iter, x, df0dx, fval, dfdx)
287 class(mma_t),
intent(inout) :: this
288 real(kind=rp),
dimension(this%n),
intent(in) :: x
289 real(kind=rp),
dimension(this%n),
intent(in) :: df0dx
290 real(kind=rp),
dimension(this%m),
intent(in) :: fval
291 real(kind=rp),
dimension(this%m, this%n),
intent(in) :: dfdx
292 integer,
intent(in) :: iter
293 integer :: i, j, ierr
294 real(kind=rp),
dimension(this%n) :: xmin_eff, xmax_eff
295 real(kind=rp),
dimension(this%n) :: x_diff
296 real(kind=rp) :: asy_factor
298 xmin_eff = this%xmin%x
299 xmax_eff = this%xmax%x
300 if (this%move_limit .gt. 0.0_rp)
then
301 xmin_eff = max(xmin_eff, x - this%move_limit)
302 xmax_eff = min(xmax_eff, x + this%move_limit)
305 x_diff = max(xmax_eff - xmin_eff, 1.0e-5_rp)
309 associate(low => this%low%x, upp => this%upp%x, &
310 x_1 => this%xold1%x, x_2 => this%xold2%x)
312 if (iter .lt. 3)
then
314 low = x - this%asyinit * x_diff
315 upp = x + this%asyinit * x_diff
318 if ((x(j) - x_1(j)) * (x_1(j) - x_2(j)) .lt. 0.0_rp)
then
319 asy_factor = this%asydecr
320 else if ((x(j) - x_1(j)) * (x_1(j) - x_2(j)) .gt. 0.0_rp)
then
321 asy_factor = this%asyincr
326 low(j) = x(j) - asy_factor * (x_1(j) - low(j))
327 upp(j) = x(j) + asy_factor * (upp(j) - x_1(j))
333 low = max(low, x - 10.0_rp * x_diff)
334 low = min(low, x - 0.01_rp * x_diff)
336 upp = min(upp, x + 10.0_rp * x_diff)
337 upp = max(upp, x + 0.01_rp * x_diff)
351 associate(alpha => this%alpha%x, beta => this%beta%x, &
352 xmin => xmin_eff, xmax => xmax_eff, &
353 low => this%low%x, upp => this%upp%x, x => x)
355 alpha = max(xmin, low + 0.1_rp*(x - low))
356 beta = min(xmax, upp - 0.1_rp*(upp - x))
363 associate(p0j => this%p0j%x, q0j => this%q0j%x, &
364 pij => this%pij%x, qij => this%qij%x, &
365 low => this%low%x, upp => this%upp%x)
367 if (this%subsolver .eq.
"dip")
then
371 p0j = (upp - x)**2 * (max(df0dx, 0.0_rp) + 0.001_rp*abs(df0dx) &
372 + 0.5_rp*1.0e-6_rp/(upp - low))
373 q0j = (x - low)**2 * (max(-df0dx, 0.0_rp) + 0.001_rp*abs(df0dx) &
374 + 0.5_rp*1.0e-6_rp/(upp - low))
377 pij(i, j) = (upp(j) - x(j))**2 * max(dfdx(i, j), 0.0_rp)
378 qij(i, j) = (x(j) - low(j))**2 * max(-dfdx(i, j), 0.0_rp)
385 1.001_rp * max(df0dx, 0.0_rp) &
386 + 0.001_rp * max(-df0dx, 0.0_rp) &
387 + 0.00001_rp / max(x_diff, 0.00001_rp) &
391 0.001_rp * max(df0dx, 0.0_rp) &
392 + 1.001_rp * max(-df0dx, 0.0_rp) &
393 + 0.00001_rp / max(x_diff, 0.00001_rp)&
399 1.001_rp * max(dfdx(i, j), 0.0_rp) &
400 + 0.001_rp * max(-dfdx(i, j), 0.0_rp) &
401 + 0.00001_rp / max(x_diff(j), 0.00001_rp) &
402 ) * (upp(j) - x(j))**2
405 0.001_rp * max(dfdx(i, j), 0.0_rp) &
406 + 1.001_rp * max(-dfdx(i, j), 0.0_rp) &
407 + 0.00001_rp / max(x_diff(j), 0.00001_rp) &
408 ) * (x(j) - low(j))**2
418 associate(bi => this%bi%x, &
419 pij => this%pij%x, qij => this%qij%x, &
420 low => this%low%x, upp => this%upp%x)
426 + pij(i, j) / (upp(j) - x(j)) &
427 + qij(i, j) / (x(j) - low(j))
431 call mpi_allreduce(mpi_in_place, bi, this%m, &
432 mpi_real_precision, mpi_sum, neko_comm, ierr)
436 end subroutine mma_gensub_cpu
440 subroutine mma_subsolve_pdip_cpu(this, designx)
451 class(mma_t),
intent(inout) :: this
452 real(kind=rp),
dimension(this%n),
intent(inout) :: designx
455 integer :: i, j, k, iter, itto, ierr
456 real(kind=rp) :: epsi, residual_max, residual_norm, &
457 z, zeta, rez, rezeta, &
459 steg, zold, zetaold, new_residual
460 real(kind=rp),
dimension(this%m) :: y, lambda, s, mu, &
461 rey, relambda, remu, res, &
463 dy, dlambda, ds, dmu, &
464 yold, lambdaold, sold, muold
465 real(kind=rp),
dimension(this%n) :: x, xsi, eta, &
467 delx, diagx, dx, dxsi, deta, &
469 real(kind=rp),
dimension(4*this%m + 2) :: residual_small
470 real(kind=rp),
dimension(3*this%n + 4*this%m + 2) :: residual
471 real(kind=rp),
dimension(2*this%n + 4*this%m + 2) :: xx, dxx
473 real(kind=rp),
dimension(this%m, this%n) :: gg
474 real(kind=rp),
dimension(this%m+1) :: bb
475 real(kind=rp),
dimension(this%m+1, this%m+1) :: aa
476 real(kind=rp),
dimension(this%m * this%m) :: aa_buffer
481 integer,
dimension(this%m+1) :: ipiv
484 real(kind=rp) :: re_sq_norm
485 real(kind=rp) :: minimal_epsilon
492 x = 0.5_rp * (this%alpha%x + this%beta%x)
498 xsi = max(1.0_rp, 1.0_rp / (x - this%alpha%x))
499 eta = max(1.0_rp, 1.0_rp / (this%beta%x - x))
500 mu = max(1.0_rp, 0.5_rp * this%c%x)
505 minimal_epsilon = max(0.9_rp * this%epsimin, 1.0e-12_rp)
506 call mpi_allreduce(mpi_in_place, minimal_epsilon, 1, &
507 mpi_real_precision, mpi_min, neko_comm, ierr)
512 do while (epsi .gt. minimal_epsilon)
519 associate(p0j => this%p0j%x, q0j => this%q0j%x, &
520 pij => this%pij%x, qij => this%qij%x, &
521 low => this%low%x, upp => this%upp%x, &
522 alpha => this%alpha%x, beta => this%beta%x, &
523 c => this%c%x, d => this%d%x, &
524 a0 => this%a0, a => this%a%x)
526 rex = (p0j + matmul(transpose(pij), lambda)) / (upp - x)**2 &
527 - (q0j + matmul(transpose(qij), lambda)) / (x - low)**2 &
530 rey = c + d * y - lambda - mu
531 rez = a0 - zeta - dot_product(lambda, a)
537 relambda(i) = relambda(i) &
538 + pij(i, j) / (upp(j) - x(j)) &
539 + qij(i, j) / (x(j) - low(j))
549 call mpi_allreduce(mpi_in_place, relambda, this%m, &
550 mpi_real_precision, mpi_sum, neko_comm, ierr)
551 relambda = relambda - this%a%x*z - y + s - this%bi%x
553 rexsi = xsi * (x - this%alpha%x) - epsi
554 reeta = eta * (this%beta%x - x) - epsi
556 rezeta = zeta * z - epsi
557 res = lambda * s - epsi
560 residual = [rex, rey, rez, relambda, rexsi, reeta, remu, rezeta, res]
561 residual_small = [rey, rez, relambda, remu, rezeta, res]
563 residual_max = maxval(abs(residual))
564 re_sq_norm = norm2(rex)**2 + norm2(rexsi)**2 + norm2(reeta)**2
566 call mpi_allreduce(mpi_in_place, residual_max, 1, &
567 mpi_real_precision, mpi_max, neko_comm, ierr)
569 call mpi_allreduce(mpi_in_place, re_sq_norm, &
570 1, mpi_real_precision, mpi_sum, neko_comm, ierr)
572 residual_norm = sqrt(norm2(residual_small)**2 + re_sq_norm)
577 do iter = 1, this%max_iter
580 if (residual_max .lt. epsi)
exit
586 + this%pij%x(i,j) * lambda(i) / (this%upp%x(j) - x(j))**2 &
587 - this%qij%x(i,j) * lambda(i) / (x(j) - this%low%x(j))**2
592 + this%p0j%x / (this%upp%x - x)**2 &
593 - this%q0j%x / (x - this%low%x)**2 &
594 - epsi / (x - this%alpha%x) &
595 + epsi / (this%beta%x - x)
597 dely = this%c%x + this%d%x * y - lambda - epsi / y
598 delz = this%a0 - dot_product(lambda, this%a%x) - epsi / z
604 dellambda(i) = dellambda(i) &
605 + this%pij%x(i, j) / (this%upp%x(j) - x(j)) &
606 + this%qij%x(i, j) / (x(j) - this%low%x(j))
610 call mpi_allreduce(mpi_in_place, dellambda, this%m, &
611 mpi_real_precision, mpi_sum, neko_comm, ierr)
613 dellambda = dellambda - this%a%x*z - y - this%bi%x + epsi / lambda
616 gg(i,:) = this%pij%x(i,:) / (this%upp%x - x)**2 &
617 - this%qij%x(i,:) / (x - this%low%x)**2
621 (this%p0j%x + matmul(transpose(this%pij%x), lambda)) &
622 / (this%upp%x - x)**3 &
623 + (this%q0j%x + matmul(transpose(this%qij%x), lambda)) &
624 / (x - this%low%x)**3
626 diagx = 2.0_rp * diagx &
627 + xsi / (x - this%alpha%x) &
628 + eta / (this%beta%x - x)
642 bb(i) = bb(i) + gg(i, j) * (delx(j) / diagx(j))
646 call mpi_allreduce(mpi_in_place, bb, this%m, &
647 mpi_real_precision, mpi_sum, neko_comm, ierr)
649 bb(1:this%m) = dellambda + dely / (this%d%x + mu / y) - bb(1:this%m)
650 bb(this%m + 1) = delz
667 aa(i, j) = aa(i, j) &
668 + gg(i, k) * (1.0_rp / diagx(k)) * gg(j, k)
673 aa_buffer = reshape(aa(1:this%m, 1:this%m), [this%m * this%m])
675 call mpi_allreduce(mpi_in_place, aa_buffer, &
676 this%m*this%m, mpi_real_precision, mpi_sum, neko_comm, ierr)
678 aa(1:this%m, 1:this%m) = reshape(aa_buffer, [this%m, this%m])
682 aa(i, i) = aa(i, i) &
684 + 1.0_rp / (this%d%x(i) + mu(i) / y(i))
687 aa(1:this%m, this%m+1) = this%a%x
688 aa(this%m+1, 1:this%m) = this%a%x
689 aa(this%m+1, this%m+1) = - zeta/z
691 call dgesv(this%m + 1, 1, aa, this%m + 1, ipiv, bb, this%m + 1, info)
693 if (info .ne. 0)
then
694 call neko_error(
"DGESV failed to solve the linear system in " // &
695 "mma_subsolve_pdip.")
699 dlambda = bb(1:this%m)
703 dx = - delx / diagx - matmul(transpose(gg), dlambda) / diagx
704 dy = (-dely + dlambda) / (this%d%x + mu / y)
706 dxsi = -xsi + (epsi - dx * xsi) / (x - this%alpha%x)
707 deta = -eta + (epsi + dx * eta) / (this%beta%x - x)
708 dmu = -mu + (epsi - mu * dy) / y
709 dzeta = -zeta + (epsi - zeta * dz) / z
710 ds = -s + (epsi - dlambda * s) / lambda
712 dxx = [dy, dz, dlambda, dxsi, deta, dmu, dzeta, ds]
713 xx = [y, z, lambda, xsi, eta, mu, zeta, s]
715 steg = 1.0_rp / maxval([ &
717 -1.01_rp * dxx / xx, &
718 -1.01_rp * dx / (x - this%alpha%x), &
719 1.01_rp * dx / (this%beta%x - x) &
733 new_residual = 2.0_rp * residual_norm
736 call mpi_allreduce(mpi_in_place, steg, 1, &
737 mpi_real_precision, mpi_min, neko_comm, ierr)
738 call mpi_allreduce(mpi_in_place, new_residual, 1, &
739 mpi_real_precision, mpi_min, neko_comm, ierr)
744 do while ((new_residual .gt. residual_norm) .and. (itto .lt. 50))
752 lambda = lambdaold + steg*dlambda
753 xsi = xsiold + steg*dxsi
754 eta = etaold + steg*deta
755 mu = muold + steg*dmu
756 zeta = zetaold + steg*dzeta
761 rex = (this%p0j%x + matmul(transpose(this%pij%x), lambda)) &
762 / (this%upp%x - x)**2 &
763 - (this%q0j%x + matmul(transpose(this%qij%x), lambda)) &
764 / (x - this%low%x)**2 &
767 rey = this%c%x + this%d%x*y - lambda - mu
768 rez = this%a0 - zeta - dot_product(lambda, this%a%x)
774 relambda(i) = relambda(i) &
775 + this%pij%x(i, j) / (this%upp%x(j) - x(j)) &
776 + this%qij%x(i, j) / (x(j) - this%low%x(j))
780 call mpi_allreduce(mpi_in_place, relambda, this%m, &
781 mpi_real_precision, mpi_sum, neko_comm, ierr)
783 relambda = relambda - this%a%x*z - y + s - this%bi%x
785 rexsi = xsi * (x - this%alpha%x) - epsi
786 reeta = eta * (this%beta%x - x) - epsi
788 rezeta = zeta * z - epsi
789 res = lambda * s - epsi
792 re_sq_norm = norm2(rex)**2 + norm2(rexsi)**2 + norm2(reeta)**2
793 call mpi_allreduce(mpi_in_place, re_sq_norm, &
794 1, mpi_real_precision, mpi_sum, neko_comm, ierr)
796 residual_small = [rey, rez, relambda, remu, rezeta, res]
797 new_residual = sqrt(norm2(residual_small)**2 + re_sq_norm)
798 call mpi_allreduce(mpi_in_place, new_residual, 1, &
799 mpi_real_precision, mpi_min, neko_comm, ierr)
805 residual = [rex, rey, rez, relambda, rexsi, reeta, remu, rezeta, res]
808 residual_norm = new_residual
809 residual_max = maxval(abs(residual))
810 call mpi_allreduce(mpi_in_place, residual_max, 1, &
811 mpi_real_precision, mpi_max, neko_comm, ierr)
818 this%xold2%x = this%xold1%x
819 this%xold1%x = designx
825 this%lambda%x = lambda
832 end subroutine mma_subsolve_pdip_cpu
836 subroutine mma_subsolve_dip_cpu(this, designx)
874 class(mma_t),
intent(inout) :: this
875 real(kind=rp),
dimension(this%n),
intent(inout) :: designx
878 integer :: i, j, k, iter, ierr
879 real(kind=rp) :: epsi, residual_max, z, steg
880 real(kind=rp),
dimension(this%m) :: y, lambda, mu, &
881 relambda, remu, dlambda, dmu, gradlambda
882 real(kind=rp),
dimension(this%n) :: x, pjlambda, qjlambda
888 real(kind=rp),
dimension(this%n) :: ljjxinv
889 real(kind=rp),
dimension(this%m,this%n) :: hijx
890 real(kind=rp),
dimension(this%m,this%m) :: hess
891 real(kind=rp) :: hesstrace
897 integer,
dimension(this%m+1) :: ipiv
900 real(kind=rp) :: minimal_epsilon
911 lambda = max(1.0_rp, 0.5_rp * this%c%x)
919 minimal_epsilon = this%epsimin
920 call mpi_allreduce(mpi_in_place, minimal_epsilon, 1, &
921 mpi_real_precision, mpi_min, neko_comm, ierr)
925 residual_max = 1.0_rp
930 do while (epsi .gt. minimal_epsilon)
937 associate(p0j => this%p0j%x, q0j => this%q0j%x, &
938 pij => this%pij%x, qij => this%qij%x, &
939 low => this%low%x, upp => this%upp%x, &
940 alpha => this%alpha%x, beta => this%beta%x, &
941 c => this%c%x, d => this%d%x, &
942 a0 => this%a0, a => this%a%x, &
950 y = max(0.0_rp, lambda - c)
955 z = max(0.0_rp, 10.0_rp * (dot_product(lambda, a) - a0))
961 pjlambda = (p0j + matmul(transpose(pij), lambda))
962 qjlambda = (q0j + matmul(transpose(qij), lambda))
963 x = (sqrt(pjlambda) * low + sqrt(qjlambda) * upp) / &
964 (sqrt(pjlambda) + sqrt(qjlambda))
967 x = merge(alpha, x, x .lt. alpha)
968 x = merge(beta, x, x .gt. beta)
973 do iter = 1, this%max_iter
976 if (.not. (residual_max .gt. 0.9_rp * epsi))
exit
980 gradlambda = matmul(pij, 1.0_rp / (upp - x)) + &
981 matmul(qij, 1.0_rp/(x - low))
984 call mpi_allreduce(mpi_in_place, gradlambda, this%m, &
985 mpi_real_precision, mpi_sum, neko_comm, ierr)
986 gradlambda = gradlambda - bi - y - a * z
989 gradlambda = - gradlambda - epsi / lambda
995 ljjxinv= - 1.0_rp / ( (2.0_rp * pjlambda/(upp - x)**3) + &
996 (2.0_rp * qjlambda/(x - low)**3))
1000 ljjxinv = merge(0.0_rp, ljjxinv, x - alpha < neko_eps)
1001 ljjxinv = merge(0.0_rp, ljjxinv, beta - x < neko_eps)
1004 hijx(i,:) = pij(i,:) / (upp - x)**2 &
1005 - qij(i,:) / (x - low)**2
1016 hess(i, j) = hess(i, j) &
1017 + hijx(i, k) * (ljjxinv(k)) * hijx(j, k)
1022 call mpi_allreduce(mpi_in_place, hess, &
1023 this%m * this%m, mpi_real_precision, mpi_sum, neko_comm, ierr)
1029 if (dot_product(lambda, a) .gt. 0.0_rp)
then
1032 hess(i, j) = hess(i, j) - 10.0_rp * a(i) * a(j)
1040 if (y(i) .gt. 0.0_rp)
then
1041 hess(i, i) = hess(i, i) - 1.0_rp
1044 hess(i, i) = hess(i, i) - mu(i) / lambda(i)
1051 hesstrace = hesstrace + hess(i, i)
1054 hess(i,i) = hess(i, i) - &
1055 max(-1.0e-4_rp*hesstrace/this%m, 1.0e-7_rp)
1058 call dgesv(this%m , 1, hess, this%m , ipiv, &
1059 gradlambda, this%m, info)
1061 if (info .ne. 0)
then
1062 call neko_error(
"DGESV failed to solve the linear system in " // &
1063 "mma_subsolve_dip.")
1065 dlambda = gradlambda
1068 dmu = -mu + epsi / lambda - dlambda * mu / lambda
1074 steg = merge(-1.01_rp * dlambda(i) / lambda(i), steg, &
1075 steg < -1.01_rp * dlambda(i) / lambda(i))
1076 steg = merge(-1.01_rp * dmu(i) / mu(i), &
1077 steg, steg < -1.01_rp * dmu(i) / mu(i))
1080 steg = 1.0_rp / steg
1082 lambda = lambda + steg*dlambda
1091 y = max(0.0_rp, lambda - c)
1097 z = max(0.0_rp, 10.0_rp * (dot_product(lambda, a) - a0))
1103 pjlambda = (p0j + matmul(transpose(pij), lambda))
1104 qjlambda = (q0j + matmul(transpose(qij), lambda))
1105 x = (sqrt(pjlambda) * low + sqrt(qjlambda) * upp) / &
1106 (sqrt(pjlambda) + sqrt(qjlambda))
1109 x = merge(alpha, x, x .lt. alpha)
1110 x = merge(beta, x, x .gt. beta)
1113 relambda = matmul(pij, 1.0_rp / (upp - x)) + &
1114 matmul(qij, 1.0_rp / (x - low))
1116 call mpi_allreduce(mpi_in_place, relambda, this%m, &
1117 mpi_real_precision, mpi_sum, neko_comm, ierr)
1118 relambda = relambda - bi - y - a * z + mu
1121 remu = mu * lambda - epsi
1123 residual_max = maxval(abs([relambda, remu]))
1124 call mpi_allreduce(mpi_in_place, residual_max, 1, &
1125 mpi_real_precision, mpi_max, neko_comm, ierr)
1129 epsi = 0.1_rp * epsi
1133 this%xold2%x = this%xold1%x
1134 this%xold1%x = designx
1141 this%lambda%x = lambda
1143 end subroutine mma_subsolve_dip_cpu
1145end submodule mma_cpu