BioDynaMo  v1.05.120-25dc9790
Public Member Functions | Private Attributes | List of all members
bdm::experimental::Counter< TResult > Struct Template Reference

#include <reduce.h>

Inheritance diagram for bdm::experimental::Counter< TResult >:
[legend]
Collaboration diagram for bdm::experimental::Counter< TResult >:
[legend]

Public Member Functions

 Counter ()
 Required for IO. More...
 
 Counter (bool(*condition)(Agent *), TResult(*post_process)(TResult)=nullptr)
 
virtual ~Counter ()=default
 
void Reset () override
 Resets the internal state between calculations. More...
 
void operator() (Agent *agent) override
 
TResult GetResult () override
 
Reducer< TResult > * NewCopy () const override
 
- Public Member Functions inherited from bdm::experimental::Reducer< uint64_t >
 ~Reducer () override=default
 
virtual ReducerNewCopy () const=0
 
- Public Member Functions inherited from bdm::Functor< void, Agent * >
virtual ~Functor ()=default
 
virtual void operator() (TArgs... args)=0
 

Private Attributes

SharedData< uint64_t > tl_results_
 
bool(* condition_ )(Agent *) = nullptr
 
TResult(* post_process_ )(TResult) = nullptr
 

Detailed Description

template<typename TResult = uint64_t>
struct bdm::experimental::Counter< TResult >

Provides functions to count the number of agents for which the given condition is true.
The following code example demonstrates how to count all agents with diameter < 5.

auto diam_lt_5 = [](Agent* agent) {
return agent->GetDiameter() < 5;
};
Counter<> counter(diam_lt_5);
rm->ForEachAgentParallel(counter);
auto result = counter.GetResult();

The counting result can be post processed. Let's assume we want to divide the counting result by two:

auto diam_lt_5 = [](Agent* agent) {
return agent->GetDiameter() < 5;
};
auto post_process = [](uint64_t result) { return result / 2; };
Counter<> counter(diam_lt_5, post_process);
rm->ForEachAgentParallel(counter);
auto result = counter.GetResult();

The benefit in comparison with bdm::experimental::Count is that multiple counters can be combined and processed in one sweep over all agents.

See also
bdm::experimental::Reducer`

Definition at line 235 of file reduce.h.

Constructor & Destructor Documentation

◆ Counter() [1/2]

template<typename TResult = uint64_t>
bdm::experimental::Counter< TResult >::Counter ( )
inline

Required for IO.

Definition at line 238 of file reduce.h.

◆ Counter() [2/2]

template<typename TResult = uint64_t>
bdm::experimental::Counter< TResult >::Counter ( bool(*)(Agent *)  condition,
TResult(*)(TResult)  post_process = nullptr 
)
inline

Definition at line 240 of file reduce.h.

◆ ~Counter()

template<typename TResult = uint64_t>
virtual bdm::experimental::Counter< TResult >::~Counter ( )
virtualdefault

Member Function Documentation

◆ GetResult()

template<typename TResult = uint64_t>
TResult bdm::experimental::Counter< TResult >::GetResult ( )
inlineoverridevirtual

Implements bdm::experimental::Reducer< uint64_t >.

Definition at line 261 of file reduce.h.

◆ NewCopy()

template<typename TResult = uint64_t>
Reducer<TResult>* bdm::experimental::Counter< TResult >::NewCopy ( ) const
inlineoverride

Definition at line 270 of file reduce.h.

◆ operator()()

template<typename TResult = uint64_t>
void bdm::experimental::Counter< TResult >::operator() ( Agent agent)
inlineoverride

Definition at line 254 of file reduce.h.

◆ Reset()

template<typename TResult = uint64_t>
void bdm::experimental::Counter< TResult >::Reset ( )
inlineoverridevirtual

Resets the internal state between calculations.

Implements bdm::experimental::Reducer< uint64_t >.

Definition at line 247 of file reduce.h.

Member Data Documentation

◆ condition_

template<typename TResult = uint64_t>
bool(* bdm::experimental::Counter< TResult >::condition_) (Agent *) = nullptr
private

Definition at line 274 of file reduce.h.

◆ post_process_

template<typename TResult = uint64_t>
TResult(* bdm::experimental::Counter< TResult >::post_process_) (TResult) = nullptr
private

Definition at line 275 of file reduce.h.

◆ tl_results_

template<typename TResult = uint64_t>
SharedData<uint64_t> bdm::experimental::Counter< TResult >::tl_results_
private

Definition at line 273 of file reduce.h.


The documentation for this struct was generated from the following file: