BioDynaMo  v1.05.120-25dc9790
model_initializer.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 "core/model_initializer.h"
19 #include "core/util/log.h"
20 
21 namespace bdm {
22 
24  int substance_id, const std::string& substance_name, real_t diffusion_coeff,
25  real_t decay_constant, int resolution,
26  const std::vector<real_t>& binding_coefficients,
27  const std::vector<int>& binding_substances) {
28  auto* sim = Simulation::GetActive();
29  auto* param = sim->GetParam();
30  auto* rm = sim->GetResourceManager();
31  DiffusionGrid* dgrid = nullptr;
32  if (decay_constant < 0.) {
33  Log::Fatal("ModelInitializer::DefineSubstance",
34  "The decay constant must be > 0 (", decay_constant, ").");
35  }
36  if (param->diffusion_method == "euler") {
37  if (!binding_substances.empty()) {
38  if (binding_coefficients.size() != binding_substances.size()) {
39  Log::Fatal("ModelInitializer::DefineSubstance",
40  "The binding coefficients and substances have different",
41  " sizes (", binding_coefficients.size(), " vs ",
42  binding_substances.size(), ").");
43  }
44  for (auto binding_coeff : binding_coefficients) {
45  if (binding_coeff < 0.) {
46  Log::Fatal("ModelInitializer::DefineSubstance",
47  "The binding coefficients must be > 0 (", binding_coeff,
48  ").");
49  }
50  }
51 
52  dgrid = new EulerDepletionGrid(
53  substance_id, substance_name, diffusion_coeff, decay_constant,
54  resolution, binding_coefficients, binding_substances);
55  } else {
56  dgrid = new EulerGrid(substance_id, substance_name, diffusion_coeff,
57  decay_constant, resolution);
58  }
59  } else {
60  Log::Error("ModelInitializer::DefineSubstance", "Diffusion method '",
61  param->diffusion_method,
62  "' does not exist. Defaulting to 'euler'");
63  dgrid = new EulerGrid(substance_id, substance_name, diffusion_coeff,
64  decay_constant, resolution);
65  }
66 
67  rm->AddContinuum(dgrid);
68 }
69 
70 } // namespace bdm
bdm
Definition: agent.cc:39
bdm::real_t
double real_t
Definition: real_t.h:21
bdm::DiffusionGrid
Definition: diffusion_grid.h:90
model_initializer.h
euler_depletion_grid.h
diffusion_grid.h
bdm::EulerDepletionGrid
Continuum model for the 3D diffusion equation with exponential decay and substance depletion .
Definition: euler_depletion_grid.h:34
bdm::Log::Fatal
static void Fatal(const std::string &location, const Args &... parts)
Prints fatal error message.
Definition: log.h:115
bdm::Log::Error
static void Error(const std::string &location, const Args &... parts)
Prints error message.
Definition: log.h:79
log.h
euler_grid.h
bdm::ModelInitializer::DefineSubstance
static void DefineSubstance(int substance_id, const std::string &substance_name, real_t diffusion_coeff, real_t decay_constant, int resolution=10, const std::vector< real_t > &binding_coefficients={}, const std::vector< int > &binding_substances={})
Definition: model_initializer.cc:23
bdm::Simulation::GetActive
static Simulation * GetActive()
This function returns the currently active Simulation simulation.
Definition: simulation.cc:68
bdm::EulerGrid
Continuum model for the 3D heat equation with exponential decay .
Definition: euler_grid.h:43