BioDynaMo  v1.05.159-3be850bb
default_ops.cc
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 
25 
26 namespace bdm {
27 
28 BDM_REGISTER_OP(BoundSpace, "bound space", kCpu);
29 
31 
32 // By default run load balancing only in the first iteration.
34  std::numeric_limits<uint32_t>::max());
35 
36 BDM_REGISTER_OP(MechanicalForcesOp, "mechanical forces", kCpu);
37 
38 #ifdef USE_CUDA
39 BDM_REGISTER_OP(MechanicalForcesOpCuda, "mechanical forces", kCuda);
40 #endif
41 
42 BDM_REGISTER_OP(DividingCellOp, "DividingCellOp", kCpu);
43 
44 #if defined(USE_OPENCL) && !defined(__ROOTCLING__)
45 BDM_REGISTER_OP(MechanicalForcesOpOpenCL, "mechanical forces", kOpenCl);
46 #endif
47 
50 
51  void SetUp() override {
53  }
54 
55  void operator()(Agent* agent) override {
56  if (!detect_static_) {
57  return;
58  }
59  agent->UpdateStaticness();
60  }
61 
62  bool detect_static_ = false;
63 };
64 
65 BDM_REGISTER_OP(UpdateStaticnessOp, "update staticness", kCpu);
66 
69 
70  void operator()(Agent* agent) override { agent->PropagateStaticness(); }
71 };
72 
73 BDM_REGISTER_OP(PropagateStaticnessAgentOp, "propagate staticness agentop",
74  kCpu);
75 
76 struct BehaviorOp : public AgentOperationImpl {
78 
79  void operator()(Agent* agent) override { agent->RunBehaviors(); }
80 };
81 
83 
86 
87  void operator()(Agent* agent) override { agent->RunDiscretization(); }
88 };
89 
91 
94 
95  void operator()() override {
96  auto* sim = Simulation::GetActive();
97  const auto& all_exec_ctxts = sim->GetAllExecCtxts();
98  all_exec_ctxts[0]->SetupIterationAll(all_exec_ctxts);
99  sim->GetEnvironment()->Update();
100  }
101 };
102 
103 BDM_REGISTER_OP(SetUpIterationOp, "set up iteration", kCpu);
104 
107 
108  void operator()() override {
109  auto* sim = Simulation::GetActive();
110  const auto& all_exec_ctxts = sim->GetAllExecCtxts();
111  all_exec_ctxts[0]->TearDownIterationAll(all_exec_ctxts);
112  }
113 };
114 
115 BDM_REGISTER_OP(TearDownIterationOp, "tear down iteration", kCpu);
116 
119 
120  void operator()() override {
122  }
123 };
124 
125 BDM_REGISTER_OP(UpdateTimeSeriesOp, "update time series", kCpu);
126 
129 
130  void operator()() override {
131  auto* sim = Simulation::GetActive();
132  sim->GetEnvironment()->ForcedUpdate();
133  }
134 };
135 
136 BDM_REGISTER_OP(UpdateEnvironmentOp, "update environment", kCpu);
137 
139 
142 
143  void operator()() override {
144  if (!Simulation::GetActive()->GetParam()->detect_static_agents) {
145  return;
146  }
147  auto function = L2F(
148  [](Agent* agent, AgentHandle) { agent->PropagateStaticness(true); });
150  auto* param = Simulation::GetActive()->GetParam();
151  rm->ForEachAgentParallel(param->scheduling_batch_size, function);
152  }
153 };
154 
155 BDM_REGISTER_OP(PropagateStaticnessOp, "propagate staticness", kCpu);
156 
157 } // namespace bdm
Contains code required by all agents.
Definition: agent.h:79
void UpdateStaticness()
Definition: agent.cc:111
void PropagateStaticness(bool beginning=false)
Definition: agent.cc:77
void RunBehaviors()
Execute all behaviorsq.
Definition: agent.cc:146
virtual void RunDiscretization()
Definition: agent.cc:117
A class that sets up diffusion grids of the substances in this simulation.
Definition: continuum_op.h:35
Defines the 3D physical interactions between physical objects.
ResourceManager * GetResourceManager()
Returns the ResourceManager instance.
Definition: simulation.cc:244
experimental::TimeSeries * GetTimeSeries()
Definition: simulation.cc:287
static Simulation * GetActive()
This function returns the currently active Simulation simulation.
Definition: simulation.cc:68
const Param * GetParam() const
Returns the simulation parameters.
Definition: simulation.cc:254
void Update()
Adds a new data point to all time series with a collector.
Definition: time_series.cc:368
Definition: agent.cc:39
LambdaFunctor< decltype(&TLambda::operator())> L2F(const TLambda &l)
Definition: functor.h:110
@ kOpenCl
Definition: operation.h:31
@ kCpu
Definition: operation.h:31
@ kCuda
Definition: operation.h:31
BDM_REGISTER_OP(BoundSpace, "bound space", kCpu)
BDM_REGISTER_OP_WITH_FREQ(LoadBalancingOp, "load balancing", kCpu, std::numeric_limits< uint32_t >::max())
Interface for implementing an operation.
Definition: operation.h:76
void operator()(Agent *agent) override
Definition: default_ops.cc:79
BDM_OP_HEADER(BehaviorOp)
void operator()(Agent *agent) override
Definition: default_ops.cc:87
BDM_OP_HEADER(DiscretizationOp)
Defines the 3D physical interactions between physical objects.
Defines the 3D physical interactions between physical objects.
bool detect_static_agents
Definition: param.h:470
BDM_OP_HEADER(PropagateStaticnessAgentOp)
void operator()(Agent *agent) override
Definition: default_ops.cc:70
BDM_OP_HEADER(PropagateStaticnessOp)
void operator()() override
Definition: default_ops.cc:143
void operator()() override
Definition: default_ops.cc:95
BDM_OP_HEADER(SetUpIterationOp)
Interface for implementing an operation that should run on a GPU.
Definition: operation.h:86
BDM_OP_HEADER(TearDownIterationOp)
void operator()() override
Definition: default_ops.cc:108
void operator()() override
Definition: default_ops.cc:130
BDM_OP_HEADER(UpdateEnvironmentOp)
void operator()(Agent *agent) override
Definition: default_ops.cc:55
void SetUp() override
Definition: default_ops.cc:51
BDM_OP_HEADER(UpdateStaticnessOp)
BDM_OP_HEADER(UpdateTimeSeriesOp)
void operator()() override
Definition: default_ops.cc:120