BioDynaMo
v1.05.120-25dc9790
|
Go to the documentation of this file.
15 #ifndef CORE_AGENT_AGENT_H_
16 #define CORE_AGENT_AGENT_H_
25 #include <type_traits>
26 #include <unordered_map>
52 #define BDM_AGENT_HEADER(class_name, base_class, class_version_id) \
54 using Base = base_class; \
56 explicit class_name(TRootIOCtor* io_ctor) {} \
59 Agent* New() const override { return new class_name(); } \
61 Agent* NewCopy() const override { return new class_name(*this); } \
63 const char* GetTypeName() const override { return #class_name; } \
67 Base* UpCast() { return static_cast<Base*>(this); } \
70 const Base* UpCast() const { return static_cast<const Base*>(this); } \
72 BDM_CLASS_DEF_OVERRIDE(class_name, class_version_id)
83 explicit Agent(TRootIOCtor* io_ctor);
122 const std::initializer_list<Agent*>& prototypes) {
124 event.existing_agent =
this;
125 for (
auto* p : prototypes) {
126 auto* new_agent = p->New();
127 new_agent->Initialize(event);
128 event.new_agents.push_back(new_agent);
141 return {
"position_",
"diameter_"};
207 template <
typename TAgent = Agent>
209 static_assert(!std::is_pointer<TAgent>::value,
210 "Cannot be of pointer type!");
215 const_cast<TAgent*
>(Cast<const Agent, const TAgent>(
this)));
251 void*
operator new(
size_t size) {
254 return mem_mgr->
New(size);
260 void operator delete(
void* p) {
273 uint32_t
box_idx_ = std::numeric_limits<uint32_t>::max();
277 template <
typename TFrom,
typename TTo>
278 typename std::enable_if<std::is_base_of<TFrom, TTo>::value, TTo*>::type
Cast(
279 TFrom* agent)
const {
280 return static_cast<TTo*
>(agent);
283 template <
typename TFrom,
typename TTo>
284 typename std::enable_if<!std::is_base_of<TFrom, TTo>::value, TTo*>::type
Cast(
285 TFrom* agent)
const {
286 return dynamic_cast<TTo*
>(agent);
323 #endif // CORE_AGENT_AGENT_H_
void SetStaticnessNextTimestep(bool value) const
virtual std::set< std::string > GetRequiredVisDataMembers() const
void InitializeBehaviors(const NewAgentEvent &event)
void RunBehaviors()
Execute all behaviorsq.
virtual void AddAgent(Agent *new_agent)=0
Adds the agent to the simulation (threadsafe, takes ownership). Note that we avoid the use of smart p...
void UpdateBehaviors(const NewAgentEvent &event)
Function to invoke the Update method of the behavior or remove it from current. Forwards the call to ...
virtual void RemoveFromSimulation()
void CreateNewAgents(const NewAgentEvent &event, const std::initializer_list< Agent * > &prototypes)
bool is_static_
If an agent is static, we should not compute the mechanical forces.
virtual void Initialize(const NewAgentEvent &event)
virtual Real3 CalculateDisplacement(const InteractionForce *force, real_t squared_radius, real_t dt)=0
const InlineVector< Behavior *, 2 > & GetAllBehaviors() const
Return all behaviors.
const AgentUid & GetUid() const
virtual void ApplyDisplacement(const Real3 &displacement)=0
virtual real_t GetDiameter() const =0
virtual const char * GetTypeName() const
virtual void SetDiameter(real_t diameter)=0
virtual Shape GetShape() const =0
virtual void SetPosition(const Real3 &pos)=0
void SetPropagateStaticness(bool value=true)
bool is_static_next_ts_
Flag to determine of an agent is static in the next timestep.
Contains code required by all agents.
uint16_t run_behavior_loop_idx_
void SetBoxIdx(uint32_t idx)
MemoryManager * GetMemoryManager()
#define BDM_CLASS_DEF(class_name, class_version_id)
Forward all calls to BDM_NULL_CLASS_DEF.
virtual void RunDiscretization()
AgentPointerMode gAgentPointerMode
virtual Agent * NewCopy() const =0
Create a copy of this object.
virtual Agent * New() const =0
Create a new instance of this object using the default constructor.
void AddBehavior(Behavior *behavior)
Add a behavior to this agent.
uint32_t GetBoxIdx() const
AgentPointer< TAgent > GetAgentPtr() const
Return agent pointer.
bool propagate_staticness_neighborhood_
bool GetPropagateStaticness() const
ExecutionContext * GetExecutionContext()
Returns a thread local execution context.
void * New(std::size_t size)
InlineVector< Behavior *, 2 > behaviors_
collection of behaviors which define the internal behavior
virtual void Update(const NewAgentEvent &event)
void RemoveBehavior(const Behavior *behavior)
std::enable_if<!std::is_base_of< TFrom, TTo >::value, TTo * >::type Cast(TFrom *agent) const
void PropagateStaticness(bool beginning=false)
std::enable_if< std::is_base_of< TFrom, TTo >::value, TTo * >::type Cast(TFrom *agent) const
virtual const Real3 & GetPosition() const =0
static Simulation * GetActive()
This function returns the currently active Simulation simulation.
uint32_t box_idx_
Grid box index.
virtual void CriticalRegion(std::vector< AgentPointer<>> *aptrs)