BioDynaMo  v1.05.119-a4ff3934
continuum_interface.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 
15 #include "continuum_interface.h"
16 #include "core/param/param.h"
17 #include "core/scheduler.h"
18 #include "core/simulation.h"
19 
20 namespace bdm {
21 
23  if (time_step_ != std::numeric_limits<real_t>::max()) {
24  // Update the total time to simulate
25  time_to_simulate_ += dt;
26  // Compute the number of time steps to simulate
27  auto n_steps = static_cast<int>(std::floor(time_to_simulate_ / time_step_));
28  // Treat numerical instabilities. E.g. if time_to_simulate_ = 0.19999999999
29  // and time_step_ = 0.1, n_steps = 1, but we want n_steps = 2.
30  double left_over = time_to_simulate_ - (n_steps + 1) * time_step_;
31  double absolute_tolerance = 0;
32  if (sizeof(real_t) == 8) {
33  // for double precision
34  absolute_tolerance = 1e-10;
35  } else {
36  // for single precision
37  absolute_tolerance = 1e-8;
38  }
39  if (left_over < 0 && left_over > -absolute_tolerance) {
40  n_steps++;
41  }
42  // Simulate for the appropriate number of time steps
43  for (int i = 0; i < n_steps; i++) {
45  }
46  // Update the total simulated time
47  simulated_time_ += n_steps * time_step_;
48  // Keep track of time that has not been simulated yet
49  time_to_simulate_ -= n_steps * time_step_;
50  } else {
51  // If time_step_ is not set, we simply forward the time step to the Step
52  // method.
53  Step(dt);
54  simulated_time_ += dt;
55  }
56 }
57 
59 
61  if (time_step_ != std::numeric_limits<real_t>::max()) {
62  return time_step_;
63  } else {
64  auto* scheduler = Simulation::GetActive()->GetScheduler();
65  auto* op = scheduler->GetOps("continuum")[0];
67  op->frequency_;
68  }
69 }
70 } // namespace bdm
bdm
Definition: agent.cc:39
bdm::Continuum::Step
virtual void Step(real_t dt)=0
bdm::real_t
double real_t
Definition: real_t.h:21
scheduler.h
bdm::Continuum::time_to_simulate_
real_t time_to_simulate_
Time that the continuum (still) has to integrate.
Definition: continuum_interface.h:123
bdm::Simulation::GetScheduler
Scheduler * GetScheduler()
Definition: simulation.cc:262
bdm::Continuum::simulated_time_
real_t simulated_time_
Passed simulation time for the continuum.
Definition: continuum_interface.h:120
continuum_interface.h
bdm::Continuum::IntegrateTimeAsynchronously
void IntegrateTimeAsynchronously(real_t dt)
Definition: continuum_interface.cc:22
bdm::Continuum::GetTimeStep
real_t GetTimeStep() const
Returns the time step for the continuum.
Definition: continuum_interface.cc:60
bdm::Continuum::SetTimeStep
void SetTimeStep(real_t dt)
Definition: continuum_interface.cc:58
bdm::Param::simulation_time_step
real_t simulation_time_step
Definition: param.h:185
bdm::Continuum::time_step_
real_t time_step_
Definition: continuum_interface.h:117
bdm::Scheduler::GetOps
std::vector< Operation * > GetOps(const std::string &name)
Definition: scheduler.cc:218
simulation.h
bdm::Simulation::GetParam
const Param * GetParam() const
Returns the simulation parameters.
Definition: simulation.cc:254
param.h
bdm::Simulation::GetActive
static Simulation * GetActive()
This function returns the currently active Simulation simulation.
Definition: simulation.cc:68