BioDynaMo  v1.05.120-25dc9790
continuum_op.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_OPERATION_DIFFUSION_OP_H_
16 #define CORE_OPERATION_DIFFUSION_OP_H_
17 
18 #include <string>
19 #include <utility>
20 #include <vector>
21 
27 #include "core/param/param.h"
28 #include "core/resource_manager.h"
29 #include "core/simulation.h"
30 #include "core/util/log.h"
31 
32 namespace bdm {
33 
37 
38  public:
39  void operator()() override {
40  // Get active simulation and related pointers
41  auto* sim = Simulation::GetActive();
42  const auto* rm = sim->GetResourceManager();
43  const auto* env = sim->GetEnvironment();
44  const auto* param = sim->GetParam();
45 
46  // Compute the passed time to update the diffusion grid accordingly.
47  real_t current_time = sim->GetScheduler()->GetSimulatedTime();
48  delta_t_ = current_time - last_time_run_;
49  last_time_run_ = current_time;
50 
51  // Avoid computation if delta_t_ is zero
52  if (delta_t_ == 0.0) {
53  return;
54  }
55 
56  rm->ForEachContinuum([this, &env, &param](Continuum* cm) {
57  // Update the diffusion grid dimension if the environment dimensions
58  // have changed. If the space is bound, we do not need to update the
59  // dimensions, because these should not be changing anyway
60  if (env->HasGrown() &&
61  param->bound_space == Param::BoundSpaceMode::kOpen) {
62  cm->Update();
63  }
65  auto* dgrid = dynamic_cast<DiffusionGrid*>(cm);
66  if (dgrid && param->calculate_gradients) {
67  dgrid->CalculateGradient();
68  }
69  });
70  }
71 
72  private:
78 };
79 
80 } // namespace bdm
81 
82 #endif // CORE_OPERATION_DIFFUSION_OP_H_
inline_vector.h
bdm::ContinuumOp::operator()
void operator()() override
Definition: continuum_op.h:39
bdm
Definition: agent.cc:39
operation.h
bdm::ContinuumOp::delta_t_
real_t delta_t_
Definition: continuum_op.h:77
bdm::real_t
double real_t
Definition: real_t.h:21
bdm::DiffusionGrid
Definition: diffusion_grid.h:90
bdm::Continuum
Continuum class to interface with BioDynaMo for hybrid simulations.
Definition: continuum_interface.h:52
operation_registry.h
bdm::Continuum::IntegrateTimeAsynchronously
void IntegrateTimeAsynchronously(real_t dt)
Definition: continuum_interface.cc:22
diffusion_grid.h
log.h
bdm::ContinuumOp
A class that sets up diffusion grids of the substances in this simulation.
Definition: continuum_op.h:35
environment.h
simulation.h
bdm::ContinuumOp::BDM_OP_HEADER
BDM_OP_HEADER(ContinuumOp)
bdm::ContinuumOp::last_time_run_
real_t last_time_run_
Last time when the operation was executed.
Definition: continuum_op.h:74
resource_manager.h
param.h
bdm::Simulation::GetActive
static Simulation * GetActive()
This function returns the currently active Simulation simulation.
Definition: simulation.cc:68
bdm::StandaloneOperationImpl
Interface for implementing an operation that should run on a GPU.
Definition: operation.h:86