Skip to content

Commit

Permalink
fix single-component sums specified in fabm.yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
jornbr committed Nov 7, 2024
1 parent eee3520 commit c393da7
Showing 1 changed file with 23 additions and 20 deletions.
43 changes: 23 additions & 20 deletions src/builtin/sum.F90
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ subroutine request_coupling_to_component(parent, target_link, component)

if (associated(component%link)) then
call parent%request_coupling(target_link, component%link)
else
elseif (component%name /= '') then
call parent%request_coupling(target_link, component%name)
end if
end subroutine request_coupling_to_component
Expand Down Expand Up @@ -321,6 +321,17 @@ subroutine weighted_sum_initialize(self, configunit)

n = base_initialize(self)

allocate(self%id_terms(n))

component => self%first
do i = 1, n
write (temp,'(i0)') i
call self%register_dependency(self%id_terms(i), 'term' // trim(temp), self%units, 'term ' // trim(temp))
call request_coupling_to_component(self, self%id_terms(i)%link, component)
component%link => self%id_terms(i)%link
component => component%next
end do

if (n == 0) then
! No components at all - the result is a constant
call self%add_interior_variable('result', self%units, 'result', fill_value=self%offset, missing_value=self%missing_value, &
Expand Down Expand Up @@ -354,16 +365,6 @@ subroutine weighted_sum_initialize(self, configunit)
end if

self%active = .true.
allocate(self%id_terms(n))

component => self%first
do i = 1, n
write (temp,'(i0)') i
call self%register_dependency(self%id_terms(i), 'term' // trim(temp), self%units, 'term ' // trim(temp))
call request_coupling_to_component(self, self%id_terms(i)%link, component)
component%link => self%id_terms(i)%link
component => component%next
end do

call self%add_interior_variable('result', self%units, 'result', fill_value=0.0_rk, missing_value=self%missing_value, &
output=self%result_output, write_index=self%id_result%sum_index, link=self%id_result%link, source=source_do, &
Expand Down Expand Up @@ -442,6 +443,17 @@ subroutine horizontal_weighted_sum_initialize(self, configunit)

n = base_initialize(self)

allocate(self%id_terms(n))

component => self%first
do i = 1, n
write (temp,'(i0)') i
call self%register_dependency(self%id_terms(i), 'term' // trim(temp), self%units, 'term ' // trim(temp))
call request_coupling_to_component(self, self%id_terms(i)%link, component)
component%link => self%id_terms(i)%link
component => component%next
end do

if (n == 0) then
! No components - link to constant field with offset (typically 0)
call self%add_horizontal_variable('result', self%units, 'result', fill_value=self%offset, missing_value=self%missing_value, &
Expand Down Expand Up @@ -476,16 +488,7 @@ subroutine horizontal_weighted_sum_initialize(self, configunit)
end if

self%active = .true.
allocate(self%id_terms(n))

component => self%first
do i = 1, n
write (temp,'(i0)') i
call self%register_dependency(self%id_terms(i), 'term' // trim(temp), self%units, 'term ' // trim(temp))
call request_coupling_to_component(self, self%id_terms(i)%link, component)
component%link => self%id_terms(i)%link
component => component%next
end do
call self%add_horizontal_variable('result', self%units, 'result', missing_value=self%missing_value, fill_value=0.0_rk, output=self%result_output, &
write_index=self%id_result%horizontal_sum_index, link=self%id_result%link, source=source_do_horizontal, domain=self%domain)
self%result_link => self%id_result%link
Expand Down

0 comments on commit c393da7

Please sign in to comment.