BioDynaMo  v1.05.159-3be850bb
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_
Contains code required by all agents.
Definition: agent.h:79
Move cells along the diffusion gradient (from low concentration to high)
Definition: chemotaxis.h:26
void Initialize(const NewAgentEvent &event) override
Definition: chemotaxis.h:41
Chemotaxis()=default
BDM_BEHAVIOR_HEADER(Chemotaxis, Behavior, 1)
void Run(Agent *agent) override
Definition: chemotaxis.h:48
Chemotaxis(const std::string &substance, real_t speed)
Definition: chemotaxis.h:31
DiffusionGrid * dgrid_
Definition: chemotaxis.h:57
Chemotaxis(DiffusionGrid *dgrid, real_t speed)
Definition: chemotaxis.h:36
virtual ~Chemotaxis()=default
Real3 GetGradient(const Real3 &position) const override
DiffusionGrid * GetDiffusionGrid(size_t substance_id) const
ResourceManager * GetResourceManager()
Returns the ResourceManager instance.
Definition: simulation.cc:244
static Simulation * GetActive()
This function returns the currently active Simulation simulation.
Definition: simulation.cc:68
Definition: agent.cc:39
double real_t
Definition: real_t.h:21
Behavior * existing_behavior