BioDynaMo  v1.05.119-a4ff3934
chemotaxis.h
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------
2 //
3 // Copyright (C) 2021 CERN & University of Surrey for the benefit of the
4 // BioDynaMo collaboration. All Rights Reserved.
5 //
6 // Licensed under the Apache License, Version 2.0 (the "License");
7 // you may not use this file except in compliance with the License.
8 //
9 // See the LICENSE file distributed with this work for details.
10 // See the NOTICE file distributed with this work for additional information
11 // regarding copyright ownership.
12 //
13 // -----------------------------------------------------------------------------
14 
15 #ifndef CORE_BEHAVIOR_CHEMOTAXIS_H_
16 #define CORE_BEHAVIOR_CHEMOTAXIS_H_
17 
18 #include "core/agent/cell.h"
19 #include "core/behavior/behavior.h"
21 #include "core/resource_manager.h"
22 
23 namespace bdm {
24 
26 class Chemotaxis : public Behavior {
28 
29  public:
30  Chemotaxis() = default;
31  Chemotaxis(const std::string& substance, real_t speed) : speed_(speed) {
33  substance);
34  }
35 
36  explicit Chemotaxis(DiffusionGrid* dgrid, real_t speed)
37  : dgrid_(dgrid), speed_(speed) {}
38 
39  virtual ~Chemotaxis() = default;
40 
41  void Initialize(const NewAgentEvent& event) override {
42  Base::Initialize(event);
43  auto* other = bdm_static_cast<Chemotaxis*>(event.existing_behavior);
44  dgrid_ = other->dgrid_;
45  speed_ = other->speed_;
46  }
47 
48  void Run(Agent* agent) override {
49  auto* cell = bdm_static_cast<Cell*>(agent);
50  auto& position = cell->GetPosition();
51  Real3 gradient;
52  dgrid_->GetGradient(position, &gradient); // returns normalized gradient
53  cell->UpdatePosition(gradient * speed_);
54  }
55 
56  private:
57  DiffusionGrid* dgrid_ = nullptr;
59 };
60 
61 } // namespace bdm
62 
63 #endif // CORE_BEHAVIOR_CHEMOTAXIS_H_
bdm::NewAgentEvent
Definition: new_agent_event.h:61
bdm::Chemotaxis::Initialize
void Initialize(const NewAgentEvent &event) override
Definition: chemotaxis.h:41
bdm
Definition: agent.cc:39
bdm::NewAgentEvent::existing_behavior
Behavior * existing_behavior
Definition: new_agent_event.h:77
bdm::Behavior
Definition: behavior.h:29
bdm::ResourceManager::GetDiffusionGrid
DiffusionGrid * GetDiffusionGrid(size_t substance_id) const
Definition: resource_manager.h:167
bdm::Chemotaxis::BDM_BEHAVIOR_HEADER
BDM_BEHAVIOR_HEADER(Chemotaxis, Behavior, 1)
bdm::real_t
double real_t
Definition: real_t.h:21
bdm::DiffusionGrid
Definition: diffusion_grid.h:90
bdm::Agent
Contains code required by all agents.
Definition: agent.h:79
bdm::Chemotaxis::Chemotaxis
Chemotaxis(const std::string &substance, real_t speed)
Definition: chemotaxis.h:31
bdm::Chemotaxis::Chemotaxis
Chemotaxis(DiffusionGrid *dgrid, real_t speed)
Definition: chemotaxis.h:36
bdm::Chemotaxis
Move cells along the diffusion gradient (from low concentration to high)
Definition: chemotaxis.h:26
bdm::Chemotaxis::dgrid_
DiffusionGrid * dgrid_
Definition: chemotaxis.h:57
diffusion_grid.h
bdm::Simulation::GetResourceManager
ResourceManager * GetResourceManager()
Returns the ResourceManager instance.
Definition: simulation.cc:244
bdm::Chemotaxis::Run
void Run(Agent *agent) override
Definition: chemotaxis.h:48
bdm::Chemotaxis::speed_
real_t speed_
Definition: chemotaxis.h:58
bdm::Chemotaxis::Chemotaxis
Chemotaxis()=default
behavior.h
bdm::Chemotaxis::~Chemotaxis
virtual ~Chemotaxis()=default
bdm::MathArray< real_t, 3 >
resource_manager.h
bdm::Simulation::GetActive
static Simulation * GetActive()
This function returns the currently active Simulation simulation.
Definition: simulation.cc:68
bdm::DiffusionGrid::GetGradient
Real3 GetGradient(const Real3 &position) const override
Definition: diffusion_grid.h:196
cell.h