The eclipse rows (and, optionally, their partials, in the order of the rows' columns),
for the x already in the segments. The rows (segments) are done in parallel.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(eclipse_opt_data), | intent(inout) | :: | d | |||
| real(kind=wp), | intent(out), | dimension(:) | :: | ks | ||
| real(kind=wp), | intent(out), | optional, | dimension(:) | :: | jac | |
| logical, | intent(out), | optional | :: | ok |
false if a row couldn't be evaluated (see row_ks) |
|
| logical, | intent(in), | optional, | dimension(:) | :: | only |
evaluate only these rows (the others' |
subroutine eval_rows(d, ks, jac, ok, only) type(eclipse_opt_data),intent(inout) :: d real(wp),dimension(:),intent(out) :: ks real(wp),dimension(:),intent(out),optional :: jac logical,intent(out),optional :: ok !! false if a row couldn't be evaluated (see [[row_ks]]) logical,dimension(:),intent(in),optional :: only !! evaluate only these rows (the others' `ks` are 0, !! and their partials are not set) integer :: k, j, offset integer,dimension(:),allocatable :: first_nz !! index in `jac` of each row's first nonzero, minus 1 real(wp) :: t0, tf, dt, h, fp, fm real(wp),dimension(6) :: x0r, xp real(wp) :: tp0, tpf logical :: ok_k, all_ok allocate(first_nz(size(d%rows))) offset = 0 do k = 1, size(d%rows) first_nz(k) = offset offset = offset + d%rows(k)%ncol end do h = d%mission%eclipse_opt_fd_step all_ok = .true. !$OMP PARALLEL DO PRIVATE(k,j,t0,tf,dt,x0r,xp,tp0,tpf,fp,fm,ok_k) SCHEDULE(dynamic) do k = 1, size(d%rows) if (present(only)) then if (.not. only(k)) then ks(k) = zero cycle end if end if associate (row => d%rows(k), seg => d%mission%segs(d%rows(k)%iseg)) t0 = seg%data%t0 tf = seg%data%tf x0r = seg%data%x0_rotating ks(k) = row_ks(d%mission, seg, row, t0, tf, x0r, ok_k) if (.not. ok_k) all_ok = .false. if (present(jac)) then do j = 1, row%ncol dt = h * d%mission%xscale(row%col(j)) ! the unscaled change [days, km or km/s] call perturbed(row, j, t0, tf, x0r, +dt, tp0, tpf, xp) fp = row_ks(d%mission, seg, row, tp0, tpf, xp, ok_k) if (.not. ok_k) all_ok = .false. call perturbed(row, j, t0, tf, x0r, -dt, tp0, tpf, xp) fm = row_ks(d%mission, seg, row, tp0, tpf, xp, ok_k) if (.not. ok_k) all_ok = .false. jac(first_nz(k)+j) = (fp - fm) / (2.0_wp*h) end do end if end associate end do !$OMP END PARALLEL DO if (present(ok)) ok = all_ok contains pure subroutine perturbed(row, j, t0, tf, x0r, delta, tp0, tpf, xp) !! the segment's inputs with variable `j` of the row changed by `delta` !! (everything is passed in: an internal procedure would see the host's !! variables, not the OpenMP thread's private copies) type(eclipse_row),intent(in) :: row integer,intent(in) :: j real(wp),intent(in) :: t0, tf, delta real(wp),dimension(6),intent(in) :: x0r real(wp),intent(out) :: tp0, tpf real(wp),dimension(6),intent(out) :: xp tp0 = t0; tpf = tf; xp = x0r select case (row%kind(j)) case (0) tp0 = t0 + delta if (row%tf_with_t0) tpf = tf + delta case (1:6) xp(row%kind(j)) = x0r(row%kind(j)) + delta end select end subroutine perturbed end subroutine eval_rows