Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix single-component sums specified in fabm.yaml #98

Merged
merged 1 commit into from
Nov 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading