BioDynaMo  v1.05.120-25dc9790
growth_division.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_GROWTH_DIVISION_H_
16 #define CORE_BEHAVIOR_GROWTH_DIVISION_H_
17 
18 #include "core/agent/cell.h"
20 #include "core/behavior/behavior.h"
21 #include "core/util/log.h"
22 #include "core/util/root.h"
23 
24 namespace bdm {
25 
28 class GrowthDivision : public Behavior {
30 
31  public:
33  GrowthDivision(real_t threshold, real_t growth_rate)
34  : threshold_(threshold), growth_rate_(growth_rate) {}
35 
36  virtual ~GrowthDivision() = default;
37 
38  void Initialize(const NewAgentEvent& event) override {
39  Base::Initialize(event);
40 
41  auto* other = event.existing_behavior;
42  if (auto* gd = dynamic_cast<GrowthDivision*>(other)) {
43  threshold_ = gd->threshold_;
44  growth_rate_ = gd->growth_rate_;
45  } else {
46  Log::Fatal("GrowthDivision::Initialize",
47  "event.existing_behavior was not of type GrowthDivision");
48  }
49  }
50 
53 
54  void Run(Agent* agent) override {
55  if (auto* cell = dynamic_cast<Cell*>(agent)) {
56  if (cell->GetDiameter() <= threshold_) {
57  cell->ChangeVolume(growth_rate_);
58  } else {
59  cell->Divide();
60  }
61  } else {
62  Log::Fatal("GrowthDivision::Run", "Agent is not a Cell");
63  }
64  }
65 
66  private:
69 };
70 
71 } // namespace bdm
72 
73 #endif // CORE_BEHAVIOR_GROWTH_DIVISION_H_
bdm::NewAgentEvent
Definition: new_agent_event.h:61
bdm::GrowthDivision::Initialize
void Initialize(const NewAgentEvent &event) override
Definition: growth_division.h:38
bdm
Definition: agent.cc:39
bdm::GrowthDivision::growth_rate_
real_t growth_rate_
Definition: growth_division.h:68
bdm::Behavior
Definition: behavior.h:29
bdm::GrowthDivision::~GrowthDivision
virtual ~GrowthDivision()=default
bdm::real_t
double real_t
Definition: real_t.h:21
bdm::GrowthDivision
Definition: growth_division.h:28
bdm::Behavior::AlwaysCopyToNew
void AlwaysCopyToNew()
Always copy this behavior to new agents.
Definition: behavior.h:63
bdm::GrowthDivision::GrowthDivision
GrowthDivision()
Definition: growth_division.h:32
bdm::Agent
Contains code required by all agents.
Definition: agent.h:79
cell_division_event.h
bdm::GrowthDivision::Run
void Run(Agent *agent) override
Definition: growth_division.h:54
root.h
bdm::Cell
Definition: cell.h:40
bdm::Log::Fatal
static void Fatal(const std::string &location, const Args &... parts)
Prints fatal error message.
Definition: log.h:115
log.h
behavior.h
bdm::GrowthDivision::BDM_BEHAVIOR_HEADER
BDM_BEHAVIOR_HEADER(GrowthDivision, Behavior, 1)
bdm::GrowthDivision::GrowthDivision
GrowthDivision(real_t threshold, real_t growth_rate)
Definition: growth_division.h:33
cell.h
bdm::GrowthDivision::threshold_
real_t threshold_
Definition: growth_division.h:67