Skip to content

Commit fb4febe

Browse files
committed
src/util/aggregator_types.F90: Add incremental averaging method for computing mean aggregations
1 parent d37196a commit fb4febe

1 file changed

Lines changed: 24 additions & 2 deletions

File tree

src/util/aggregator_types.F90

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,8 @@ subroutine aggregator_set_method(this, method)
158158
character(len=*), intent(in) :: method
159159

160160
if (method == "mean") then
161-
this%accumulate => sum_accumulate
162-
this%normalise => mean_normalise
161+
this%accumulate => mean_accumulate
162+
this%normalise => other_normalise
163163
this%reset => other_reset
164164
elseif (method == "sum") then
165165
this%accumulate => sum_accumulate
@@ -183,6 +183,28 @@ subroutine aggregator_set_method(this, method)
183183

184184
end subroutine aggregator_set_method
185185

186+
subroutine mean_accumulate(this)
187+
class(aggregator_t), intent(inout) :: this
188+
189+
select type (this)
190+
type is (aggregator_real32_1d_t)
191+
this%storage = this%storage + (this%source_data - this%storage) / (this%counter + 1)
192+
type is (aggregator_real32_2d_t)
193+
this%storage = this%storage + (this%source_data - this%storage) / (this%counter + 1)
194+
type is (aggregator_real32_3d_t)
195+
this%storage = this%storage + (this%source_data - this%storage) / (this%counter + 1)
196+
type is (aggregator_real64_1d_t)
197+
this%storage = this%storage + (this%source_data - this%storage) / (this%counter + 1)
198+
type is (aggregator_real64_2d_t)
199+
this%storage = this%storage + (this%source_data - this%storage) / (this%counter + 1)
200+
type is (aggregator_real64_3d_t)
201+
this%storage = this%storage + (this%source_data - this%storage) / (this%counter + 1)
202+
end select
203+
204+
this%counter = this%counter + 1
205+
206+
end subroutine mean_accumulate
207+
186208
subroutine sum_accumulate(this)
187209
class(aggregator_t), intent(inout) :: this
188210

0 commit comments

Comments
 (0)