BioDynaMo  v1.05.117-b1949764
Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes | List of all members
bdm::Agent Class Referenceabstract

Contains code required by all agents. More...

#include <agent.h>

Inheritance diagram for bdm::Agent:
[legend]
Collaboration diagram for bdm::Agent:
[legend]

Public Member Functions

 Agent ()
 
 Agent (TRootIOCtor *io_ctor)
 
 Agent (const Agent &other)
 
virtual ~Agent ()
 
virtual AgentNew () const =0
 Create a new instance of this object using the default constructor. More...
 
virtual AgentNewCopy () const =0
 Create a copy of this object. More...
 
virtual void Initialize (const NewAgentEvent &event)
 
virtual void Update (const NewAgentEvent &event)
 
void CreateNewAgents (const NewAgentEvent &event, const std::initializer_list< Agent * > &prototypes)
 
virtual const char * GetTypeName () const
 
virtual Shape GetShape () const =0
 
virtual std::set< std::string > GetRequiredVisDataMembers () const
 
virtual void RunDiscretization ()
 
void AssignNewUid ()
 
const AgentUidGetUid () const
 
SpinlockGetLock ()
 
virtual void CriticalRegion (std::vector< AgentPointer<>> *aptrs)
 
uint32_t GetBoxIdx () const
 
void SetBoxIdx (uint32_t idx)
 
void SetStaticnessNextTimestep (bool value) const
 
bool GetPropagateStaticness () const
 
void SetPropagateStaticness (bool value=true)
 
void PropagateStaticness (bool beginning=false)
 
void UpdateStaticness ()
 
bool IsStatic () const
 
template<typename TAgent = Agent>
AgentPointer< TAgent > GetAgentPtr () const
 Return agent pointer. More...
 
void AddBehavior (Behavior *behavior)
 Add a behavior to this agent. More...
 
void RemoveBehavior (const Behavior *behavior)
 
void RunBehaviors ()
 Execute all behaviorsq. More...
 
const InlineVector< Behavior *, 2 > & GetAllBehaviors () const
 Return all behaviors. More...
 
virtual Real3 CalculateDisplacement (const InteractionForce *force, real_t squared_radius, real_t dt)=0
 
virtual void ApplyDisplacement (const Real3 &displacement)=0
 
virtual const Real3GetPosition () const =0
 
virtual void SetPosition (const Real3 &pos)=0
 
virtual real_t GetDiameter () const =0
 
virtual void SetDiameter (real_t diameter)=0
 
virtual void RemoveFromSimulation ()
 
void * operator new (size_t size)
 
void operator delete (void *p)
 

Protected Member Functions

template<typename TFrom , typename TTo >
std::enable_if< std::is_base_of< TFrom, TTo >::value, TTo * >::type Cast (TFrom *agent) const
 
template<typename TFrom , typename TTo >
std::enable_if<!std::is_base_of< TFrom, TTo >::value, TTo * >::type Cast (TFrom *agent) const
 

Protected Attributes

AgentUid uid_
 unique id More...
 
uint32_t box_idx_ = std::numeric_limits<uint32_t>::max()
 Grid box index. More...
 
InlineVector< Behavior *, 2 > behaviors_
 collection of behaviors which define the internal behavior More...
 

Private Member Functions

void InitializeBehaviors (const NewAgentEvent &event)
 
void UpdateBehaviors (const NewAgentEvent &event)
 Function to invoke the Update method of the behavior or remove it from current. Forwards the call to Update to each behavior of the existing agent and removes behaviors if they are flagged. This function sets the attributes NewAgentEvent::existing_behavior and NewAgentEvent::new_behaviors to their correct value. More...
 

Private Attributes

Spinlock lock_
 
uint16_t run_behavior_loop_idx_ = 0
 
bool is_static_ = false
 If an agent is static, we should not compute the mechanical forces. More...
 
bool propagate_staticness_neighborhood_ = true
 
bool is_static_next_ts_ = false
 Flag to determine of an agent is static in the next timestep. More...
 

Detailed Description

Contains code required by all agents.

Definition at line 79 of file agent.h.

Constructor & Destructor Documentation

◆ Agent() [1/3]

bdm::Agent::Agent ( )

Definition at line 41 of file agent.cc.

◆ Agent() [2/3]

bdm::Agent::Agent ( TRootIOCtor *  io_ctor)
explicit

Definition at line 45 of file agent.cc.

◆ Agent() [3/3]

bdm::Agent::Agent ( const Agent other)

Definition at line 47 of file agent.cc.

◆ ~Agent()

bdm::Agent::~Agent ( )
virtual

Definition at line 59 of file agent.cc.

Member Function Documentation

◆ AddBehavior()

void bdm::Agent::AddBehavior ( Behavior behavior)

Add a behavior to this agent.

Definition at line 132 of file agent.cc.

◆ ApplyDisplacement()

virtual void bdm::Agent::ApplyDisplacement ( const Real3 displacement)
pure virtual

◆ AssignNewUid()

void bdm::Agent::AssignNewUid ( )

Definition at line 119 of file agent.cc.

◆ CalculateDisplacement()

virtual Real3 bdm::Agent::CalculateDisplacement ( const InteractionForce force,
real_t  squared_radius,
real_t  dt 
)
pure virtual

◆ Cast() [1/2]

template<typename TFrom , typename TTo >
std::enable_if<std::is_base_of<TFrom, TTo>::value, TTo*>::type bdm::Agent::Cast ( TFrom *  agent) const
inlineprotected

Definition at line 278 of file agent.h.

◆ Cast() [2/2]

template<typename TFrom , typename TTo >
std::enable_if<!std::is_base_of<TFrom, TTo>::value, TTo*>::type bdm::Agent::Cast ( TFrom *  agent) const
inlineprotected

Definition at line 284 of file agent.h.

◆ CreateNewAgents()

void bdm::Agent::CreateNewAgents ( const NewAgentEvent event,
const std::initializer_list< Agent * > &  prototypes 
)
inline

This method creates a new agent for each entry in prototypes.
The prototypes list defines the type of the new agent. This function calls prototype->New() internally. New agents are automatically added to the execution context right after they are initialized. This function sets the attributes NewAgentEvent::existing_agent and NewAgentEvent::new_agents to their correct values. Lastly, this function calls this->Update(event)
The newly created and initialized agents can be found in event.new_agents.

Definition at line 121 of file agent.h.

◆ CriticalRegion()

virtual void bdm::Agent::CriticalRegion ( std::vector< AgentPointer<>> *  aptrs)
inlinevirtual

If the thread-safety mechanism is set to user-specified this function will be called before the operations are executed for this agent.
Subclasses define the critical region by adding the AgentPointers of all agents that must not be processed in parallel.
Don't forget to add the current agent.
Here an example from NeuronSoma.

void NeuronSoma::CriticalRegion(std::vector<AgentPointer<>>* aptrs) {
  aptrs->reserve(daughters_.size() + 1);
  aptrs->push_back(Agent::GetAgentPtr<>());
  for (auto& daughter : daughters_) {
    aptrs->push_back(daughter);
  }
}
See also
Param::thread_safety_mechanism
AgentPointer
NeuronSoma::CriticalRegion

Reimplemented in bdm::neuroscience::NeuriteElement, and bdm::neuroscience::NeuronSoma.

Definition at line 170 of file agent.h.

◆ GetAgentPtr()

template<typename TAgent = Agent>
AgentPointer<TAgent> bdm::Agent::GetAgentPtr ( ) const
inline

Return agent pointer.

Definition at line 208 of file agent.h.

◆ GetAllBehaviors()

const InlineVector< Behavior *, 2 > & bdm::Agent::GetAllBehaviors ( ) const

Return all behaviors.

Definition at line 154 of file agent.cc.

◆ GetBoxIdx()

uint32_t bdm::Agent::GetBoxIdx ( ) const

Definition at line 125 of file agent.cc.

◆ GetDiameter()

virtual real_t bdm::Agent::GetDiameter ( ) const
pure virtual

◆ GetLock()

Spinlock* bdm::Agent::GetLock ( )
inline

Definition at line 150 of file agent.h.

◆ GetPosition()

virtual const Real3& bdm::Agent::GetPosition ( ) const
pure virtual

◆ GetPropagateStaticness()

bool bdm::Agent::GetPropagateStaticness ( ) const
inline

Definition at line 180 of file agent.h.

◆ GetRequiredVisDataMembers()

virtual std::set<std::string> bdm::Agent::GetRequiredVisDataMembers ( ) const
inlinevirtual

Returns the data members that are required to visualize this simulation object.

Reimplemented in bdm::neuroscience::NeuriteElement.

Definition at line 140 of file agent.h.

◆ GetShape()

virtual Shape bdm::Agent::GetShape ( ) const
pure virtual

◆ GetTypeName()

virtual const char* bdm::Agent::GetTypeName ( ) const
inlinevirtual

Definition at line 134 of file agent.h.

◆ GetUid()

const AgentUid & bdm::Agent::GetUid ( ) const

Definition at line 123 of file agent.cc.

◆ Initialize()

void bdm::Agent::Initialize ( const NewAgentEvent event)
virtual

This method is called to initialize new agents that are created during a NewAgentEvent. Override this method to initialize attributes of your own Agent subclasses. NB: Don't forget to call the implementation of the base class first. Base::Initialize(event); Failing to do so will result in errors.

Reimplemented in bdm::Cell, bdm::neuroscience::NeuriteElement, and bdm::neuroscience::NeuronSoma.

Definition at line 65 of file agent.cc.

◆ InitializeBehaviors()

void bdm::Agent::InitializeBehaviors ( const NewAgentEvent event)
private

Function to copy behaviors from existing Agent to this one and to initialize them. This function sets the attributes NewAgentEvent::existing_behavior and NewAgentEvent::new_behaviors to their correct value.

Definition at line 163 of file agent.cc.

◆ IsStatic()

bool bdm::Agent::IsStatic ( ) const
inline

Definition at line 204 of file agent.h.

◆ New()

virtual Agent* bdm::Agent::New ( ) const
pure virtual

Create a new instance of this object using the default constructor.

◆ NewCopy()

virtual Agent* bdm::Agent::NewCopy ( ) const
pure virtual

Create a copy of this object.

◆ operator delete()

void bdm::Agent::operator delete ( void *  p)
inline

Definition at line 260 of file agent.h.

◆ operator new()

void* bdm::Agent::operator new ( size_t  size)
inline

Definition at line 251 of file agent.h.

◆ PropagateStaticness()

void bdm::Agent::PropagateStaticness ( bool  beginning = false)

If the agent is not static, a call to this method sets all neighbors to 'not static'.
This method will be called twice: 1) At the end of the iteration using an agent op (beginning=false).
2) At the beginning of the iteration as pre_scheduled op (beginning=true).
1 is faster because it can use cached neighbors, but it might miss some conditions. (Neighbors modifying an agent after PropagateStaticness has been called. Agent which is larger than the largest agent.) 2 is slower but able to process all conditions. Therefore, we use 1 whenever possible and 2 for the remaining conditions.

Definition at line 77 of file agent.cc.

◆ RemoveBehavior()

void bdm::Agent::RemoveBehavior ( const Behavior behavior)

Remove a behavior from this agent The parameter behavior will be deleted if the instance is stored in this agent and must not be used after the call to RemoveBehavior.

Definition at line 134 of file agent.cc.

◆ RemoveFromSimulation()

void bdm::Agent::RemoveFromSimulation ( )
virtual

Definition at line 159 of file agent.cc.

◆ RunBehaviors()

void bdm::Agent::RunBehaviors ( )

Execute all behaviorsq.

Definition at line 146 of file agent.cc.

◆ RunDiscretization()

void bdm::Agent::RunDiscretization ( )
virtual

Reimplemented in bdm::neuroscience::NeuriteElement.

Definition at line 117 of file agent.cc.

◆ SetBoxIdx()

void bdm::Agent::SetBoxIdx ( uint32_t  idx)

Definition at line 127 of file agent.cc.

◆ SetDiameter()

virtual void bdm::Agent::SetDiameter ( real_t  diameter)
pure virtual

◆ SetPosition()

virtual void bdm::Agent::SetPosition ( const Real3 pos)
pure virtual

◆ SetPropagateStaticness()

void bdm::Agent::SetPropagateStaticness ( bool  value = true)
inline

Definition at line 184 of file agent.h.

◆ SetStaticnessNextTimestep()

void bdm::Agent::SetStaticnessNextTimestep ( bool  value) const
inline

Definition at line 176 of file agent.h.

◆ Update()

void bdm::Agent::Update ( const NewAgentEvent event)
virtual

This method is called to update the existing agent at the end of a NewAgentEvent. Override this method to update attributes of your own Agent subclasses. NB: Don't forget to call the implementation of the base class first. Base::Update(event); Failing to do so will result in errors.

Reimplemented in bdm::neuroscience::NeuriteElement, and bdm::neuroscience::NeuronSoma.

Definition at line 71 of file agent.cc.

◆ UpdateBehaviors()

void bdm::Agent::UpdateBehaviors ( const NewAgentEvent event)
private

Function to invoke the Update method of the behavior or remove it from current. Forwards the call to Update to each behavior of the existing agent and removes behaviors if they are flagged. This function sets the attributes NewAgentEvent::existing_behavior and NewAgentEvent::new_behaviors to their correct value.

Definition at line 183 of file agent.cc.

◆ UpdateStaticness()

void bdm::Agent::UpdateStaticness ( )

Definition at line 111 of file agent.cc.

Member Data Documentation

◆ behaviors_

InlineVector<Behavior*, 2> bdm::Agent::behaviors_
protected

collection of behaviors which define the internal behavior

Definition at line 275 of file agent.h.

◆ box_idx_

uint32_t bdm::Agent::box_idx_ = std::numeric_limits<uint32_t>::max()
protected

Grid box index.

Definition at line 273 of file agent.h.

◆ is_static_

bool bdm::Agent::is_static_ = false
private

If an agent is static, we should not compute the mechanical forces.

Definition at line 297 of file agent.h.

◆ is_static_next_ts_

bool bdm::Agent::is_static_next_ts_ = false
mutableprivate

Flag to determine of an agent is static in the next timestep.

Definition at line 302 of file agent.h.

◆ lock_

Spinlock bdm::Agent::lock_
private

Definition at line 290 of file agent.h.

◆ propagate_staticness_neighborhood_

bool bdm::Agent::propagate_staticness_neighborhood_ = true
private

If an agent becomes non-static (i.e. it moved or grew), we should set this flag to true to also compute mechanical forces on the neighboring agents

Definition at line 300 of file agent.h.

◆ run_behavior_loop_idx_

uint16_t bdm::Agent::run_behavior_loop_idx_ = 0
private

Helper variable used to support removal of behaviors while RunBehaviors iterates over them.

Definition at line 294 of file agent.h.

◆ uid_

AgentUid bdm::Agent::uid_
protected

unique id

Definition at line 271 of file agent.h.


The documentation for this class was generated from the following files: