From 1f6ab5ce0c30da79fa3db90188add72ef5eef84d Mon Sep 17 00:00:00 2001 From: David Sagan Date: Wed, 27 Sep 2023 00:32:23 -0400 Subject: [PATCH] Fix bookkeeping when gen grad field scale is changed. --- bmad/code/attribute_bookkeeper.f90 | 1 + bmad/code/lattice_bookkeeper.f90 | 3 ++- bmad/modules/bookkeeper_mod.f90 | 40 ++++++++++++++++++++++++------ tao/version/tao_version_mod.f90 | 2 +- 4 files changed, 37 insertions(+), 9 deletions(-) diff --git a/bmad/code/attribute_bookkeeper.f90 b/bmad/code/attribute_bookkeeper.f90 index 1d71881612..8e0310950a 100644 --- a/bmad/code/attribute_bookkeeper.f90 +++ b/bmad/code/attribute_bookkeeper.f90 @@ -87,6 +87,7 @@ subroutine attribute_bookkeeper (ele, force_bookkeeping) if (ele%bookkeeping_state%attributes /= stale$ .and. .not. logic_option(.false., force_bookkeeping)) return else + call attributes_need_bookkeeping(ele) if (ele%bookkeeping_state%attributes /= stale$ .and. .not. logic_option(.false., force_bookkeeping)) return if (ele%lord_status /= not_a_lord$) then diff --git a/bmad/code/lattice_bookkeeper.f90 b/bmad/code/lattice_bookkeeper.f90 index de14a01463..136522a2a1 100644 --- a/bmad/code/lattice_bookkeeper.f90 +++ b/bmad/code/lattice_bookkeeper.f90 @@ -37,6 +37,7 @@ subroutine lattice_bookkeeper (lat, err_flag) type (branch_struct), pointer :: branch type (bookkeeping_state_struct), pointer :: stat +real(rp) dval(num_ele_attrib$) integer i, j logical, optional :: err_flag @@ -58,7 +59,7 @@ subroutine lattice_bookkeeper (lat, err_flag) branch => lat%branch(i) do j = 0, branch%n_ele_max call set_ele_status_stale (branch%ele(j), all_groups$, .false.) - call attributes_need_bookkeeping(branch%ele(j)) + call attributes_need_bookkeeping(branch%ele(j), dval) enddo enddo endif diff --git a/bmad/modules/bookkeeper_mod.f90 b/bmad/modules/bookkeeper_mod.f90 index d3e4a3392a..1326938419 100644 --- a/bmad/modules/bookkeeper_mod.f90 +++ b/bmad/modules/bookkeeper_mod.f90 @@ -1901,16 +1901,42 @@ subroutine attributes_need_bookkeeping (ele, dval) enddo endif +if (associated(ele%cartesian_map)) then + do i = 1, size(ele%cartesian_map) + ele%value(check_sum$) = ele%value(check_sum$) + ele%cartesian_map(i)%field_scale + enddo +endif + +if (associated(ele%cylindrical_map)) then + do i = 1, size(ele%cylindrical_map) + ele%value(check_sum$) = ele%value(check_sum$) + ele%cylindrical_map(i)%field_scale + enddo +endif + +if (associated(ele%gen_grad_map)) then + do i = 1, size(ele%gen_grad_map) + ele%value(check_sum$) = ele%value(check_sum$) + ele%gen_grad_map(i)%field_scale + enddo +endif + +if (associated(ele%grid_field)) then + do i = 1, size(ele%grid_field) + ele%value(check_sum$) = ele%value(check_sum$) + ele%grid_field(i)%field_scale + enddo +endif + ! -dv = abs(ele%value - ele%old_value) -dv(x1_limit$:y2_limit$) = 0 ! Limit changes do not need bookkeeping -if (present(dval)) dval = dv +if (present(dval)) then + dv = abs(ele%value - ele%old_value) + dv(x1_limit$:y2_limit$) = 0 ! Limit changes do not need bookkeeping + dval = dv -if (all(dv == 0) .and. ele%key /= capillary$) then - ele%bookkeeping_state%attributes = ok$ -else - ele%bookkeeping_state%attributes = stale$ + if (all(dv == 0) .and. ele%key /= capillary$) then + ele%bookkeeping_state%attributes = ok$ + else + ele%bookkeeping_state%attributes = stale$ + endif endif end subroutine attributes_need_bookkeeping diff --git a/tao/version/tao_version_mod.f90 b/tao/version/tao_version_mod.f90 index b800ce0431..a66884bf0f 100644 --- a/tao/version/tao_version_mod.f90 +++ b/tao/version/tao_version_mod.f90 @@ -6,5 +6,5 @@ !- module tao_version_mod -character(*), parameter :: tao_version_date = "2023/09/26 02:26:30" +character(*), parameter :: tao_version_date = "2023/09/26 22:48:47" end module