BioDynaMo  v1.05.120-25dc9790
euler_depletion_grid.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 
16 #include "core/resource_manager.h"
17 #include "core/simulation.h"
18 
19 namespace bdm {
20 
22  auto* sim = Simulation::GetActive();
23  const auto* rm = sim->GetResourceManager();
24 
25  // The explicit scheme computes the new concentarion c2 based on c1. Efficient
26  // updates are ensured by swapping pointers at each step. Here, however, we
27  // want to continue to use c1 for the next step. Thus, we swap pointers here
28  // (and again after the depletion). This is necessary because ApplyDepletion
29  // is called after the diffusion of the EulerGrid (swaps pointer at the end).
30  std::swap(c1_, c2_);
31 
32  for (size_t s = 0; s < binding_substances_.size(); s++) {
33  if (binding_coefficients_[s] == 0.0) {
34  // If the binding coefficient is zero, we do not need to apply the
35  // depletion.
36  continue;
37  }
38 
39  size_t depleting_boxes =
40  rm->GetDiffusionGrid(binding_substances_[s])->GetNumBoxes();
41 
42  if (depleting_boxes != GetNumBoxes()) {
43  Log::Fatal(
44  "EulerDepletionGrid::ApplyDepletion()",
45  "The number of voxels of the depleting diffusion grid ",
46  rm->GetDiffusionGrid(binding_substances_[s])->GetContinuumName(),
47  " differs from that of the depleted one (", GetContinuumName(),
48  "). Check the resolution.");
49  } else {
50  auto* depleting_concentration =
51  rm->GetDiffusionGrid(binding_substances_[s])->GetAllConcentrations();
52 #pragma omp parallel for simd
53  for (size_t c = 0; c < total_num_boxes_; c++) {
54  c2_[c] -=
55  c1_[c] * binding_coefficients_[s] * depleting_concentration[c] * dt;
56  }
57  }
58  }
59  // See comment above.
60  std::swap(c1_, c2_);
61 }
62 
64  // Update concentration without depletion (c1 is modified)
66 
67  ApplyDepletion(dt);
68 }
69 
71  // Update concentration without depletion (c1 is modified)
73 
74  ApplyDepletion(dt);
75 }
76 
78  // Update concentration without depletion (c1 is modified)
80 
81  ApplyDepletion(dt);
82 }
83 
85  // Update concentration without depletion (c1 is modified)
87 
88  ApplyDepletion(dt);
89 }
90 
92  // Update concentration without depletion (c1 is modified)
94 
95  ApplyDepletion(dt);
96 }
97 
98 } // namespace bdm
bdm::EulerDepletionGrid::DiffuseWithOpenEdge
void DiffuseWithOpenEdge(real_t dt) override
Definition: euler_depletion_grid.cc:70
bdm::EulerDepletionGrid::binding_substances_
std::vector< int > binding_substances_
Vector of binding substances.
Definition: euler_depletion_grid.h:96
bdm::EulerGrid::DiffuseWithDirichlet
void DiffuseWithDirichlet(real_t dt) override
Definition: euler_grid.cc:157
bdm
Definition: agent.cc:39
bdm::EulerDepletionGrid::binding_coefficients_
std::vector< real_t > binding_coefficients_
Definition: euler_depletion_grid.h:94
bdm::DiffusionGrid::GetNumBoxes
size_t GetNumBoxes() const
Definition: diffusion_grid.h:268
bdm::real_t
double real_t
Definition: real_t.h:21
bdm::DiffusionGrid::c1_
ParallelResizeVector< real_t > c1_
The array of concentration values.
Definition: diffusion_grid.h:382
bdm::EulerDepletionGrid::DiffuseWithNeumann
void DiffuseWithNeumann(real_t dt) override
Definition: euler_depletion_grid.cc:84
bdm::DiffusionGrid::total_num_boxes_
size_t total_num_boxes_
The total number of boxes in the diffusion grid.
Definition: diffusion_grid.h:400
bdm::EulerDepletionGrid::DiffuseWithClosedEdge
void DiffuseWithClosedEdge(real_t dt) override
Definition: euler_depletion_grid.cc:63
bdm::Continuum::GetContinuumName
const std::string & GetContinuumName() const
Returns the name of the continuum.
Definition: continuum_interface.h:93
bdm::EulerDepletionGrid::ApplyDepletion
void ApplyDepletion(real_t dt)
Depletes the substance according to binding_substances_ and binding_coefficients_....
Definition: euler_depletion_grid.cc:21
bdm::EulerGrid::DiffuseWithOpenEdge
void DiffuseWithOpenEdge(real_t dt) override
Definition: euler_grid.cc:69
euler_depletion_grid.h
bdm::EulerGrid::DiffuseWithNeumann
void DiffuseWithNeumann(real_t dt) override
Definition: euler_grid.cc:213
bdm::EulerDepletionGrid::DiffuseWithPeriodic
void DiffuseWithPeriodic(real_t dt) override
Definition: euler_depletion_grid.cc:91
bdm::Log::Fatal
static void Fatal(const std::string &location, const Args &... parts)
Prints fatal error message.
Definition: log.h:115
bdm::EulerDepletionGrid::DiffuseWithDirichlet
void DiffuseWithDirichlet(real_t dt) override
Definition: euler_depletion_grid.cc:77
bdm::EulerGrid::DiffuseWithPeriodic
void DiffuseWithPeriodic(real_t dt) override
Definition: euler_grid.cc:304
simulation.h
resource_manager.h
bdm::Simulation::GetActive
static Simulation * GetActive()
This function returns the currently active Simulation simulation.
Definition: simulation.cc:68
bdm::EulerGrid::DiffuseWithClosedEdge
void DiffuseWithClosedEdge(real_t dt) override
Definition: euler_grid.cc:21
bdm::DiffusionGrid::c2_
ParallelResizeVector< real_t > c2_
An extra concentration data buffer for faster value updating.
Definition: diffusion_grid.h:384