BioDynaMo  v1.03.58-27764645
substance_initializers.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_SUBSTANCE_INITIALIZERS_H_
16 #define CORE_SUBSTANCE_INITIALIZERS_H_
17 
18 #include <stdexcept>
19 #include <vector>
20 
21 #include "Math/DistFunc.h"
22 
24 
25 namespace bdm {
26 
27 // -----------------------------------------------------------------------------
28 // A substance initializer is a function that can be used to initialize the
29 // concentration values of a particular substance in space.
30 // -----------------------------------------------------------------------------
31 
32 // Use this enum to express the axis you are interested in
33 enum Axis { kXAxis, kYAxis, kZAxis };
34 
37 class Uniform {
38  public:
39  Uniform(real_t min, real_t max, real_t value, uint8_t axis) {
40  min_ = min;
41  max_ = max;
42  value_ = value;
43  axis_ = axis;
44  }
45 
47  switch (axis_) {
48  case Axis::kXAxis: {
49  if (x >= min_ && x <= max_) {
50  return value_;
51  }
52  break;
53  }
54  case Axis::kYAxis: {
55  if (y >= min_ && y <= max_) {
56  return value_;
57  }
58  break;
59  }
60  case Axis::kZAxis: {
61  if (z >= min_ && z <= max_) {
62  return value_;
63  }
64  break;
65  }
66  default:
67  throw std::logic_error("You have chosen an non-existing axis!");
68  }
69  return 0;
70  }
71 
72  private:
76  uint8_t axis_;
77 };
78 
83 class GaussianBand {
84  public:
94  GaussianBand(real_t mean, real_t sigma, uint8_t axis, real_t scaling = 1.0) {
95  mean_ = mean;
96  sigma_ = sigma;
97  axis_ = axis;
98  scaling_ = scaling;
99  }
100 
109  switch (axis_) {
110  case Axis::kXAxis:
111  return scaling_ * ROOT::Math::normal_pdf(x, sigma_, mean_);
112  case Axis::kYAxis:
113  return scaling_ * ROOT::Math::normal_pdf(y, sigma_, mean_);
114  case Axis::kZAxis: {
115  return scaling_ * ROOT::Math::normal_pdf(z, sigma_, mean_);
116  }
117  default:
118  throw std::logic_error("You have chosen an non-existing axis!");
119  }
120  }
121 
122  private:
126  uint8_t axis_;
127 };
128 
133 class PoissonBand {
134  public:
141  PoissonBand(real_t lambda, uint8_t axis) {
142  lambda_ = lambda;
143  axis_ = axis;
144  }
145 
154  switch (axis_) {
155  case Axis::kXAxis:
156  return ROOT::Math::poisson_pdf(x, lambda_);
157  case Axis::kYAxis:
158  return ROOT::Math::poisson_pdf(y, lambda_);
159  case Axis::kZAxis:
160  return ROOT::Math::poisson_pdf(z, lambda_);
161  default:
162  throw std::logic_error("You have chosen an non-existing axis!");
163  }
164  }
165 
166  private:
168  uint8_t axis_;
169 };
170 
171 } // namespace bdm
172 
173 #endif // CORE_SUBSTANCE_INITIALIZERS_H_
bdm::Uniform::operator()
real_t operator()(real_t x, real_t y, real_t z)
Definition: substance_initializers.h:46
bdm::GaussianBand::operator()
real_t operator()(real_t x, real_t y, real_t z)
The model that we want to apply for substance initialization. The operator is called for the entire s...
Definition: substance_initializers.h:108
bdm::Uniform::Uniform
Uniform(real_t min, real_t max, real_t value, uint8_t axis)
Definition: substance_initializers.h:39
bdm::GaussianBand::mean_
real_t mean_
Definition: substance_initializers.h:124
bdm::kYAxis
@ kYAxis
Definition: substance_initializers.h:33
bdm::PoissonBand::PoissonBand
PoissonBand(real_t lambda, uint8_t axis)
The constructor.
Definition: substance_initializers.h:141
bdm
Definition: agent.cc:39
bdm::GaussianBand::axis_
uint8_t axis_
Definition: substance_initializers.h:126
bdm::real_t
double real_t
Definition: real_t.h:21
bdm::Uniform
Definition: substance_initializers.h:37
bdm::kZAxis
@ kZAxis
Definition: substance_initializers.h:33
bdm::GaussianBand::scaling_
real_t scaling_
Definition: substance_initializers.h:123
bdm::PoissonBand
Definition: substance_initializers.h:133
bdm::PoissonBand::lambda_
real_t lambda_
Definition: substance_initializers.h:167
diffusion_grid.h
bdm::GaussianBand::sigma_
real_t sigma_
Definition: substance_initializers.h:125
bdm::Uniform::axis_
uint8_t axis_
Definition: substance_initializers.h:76
bdm::Uniform::value_
real_t value_
Definition: substance_initializers.h:75
bdm::GaussianBand::GaussianBand
GaussianBand(real_t mean, real_t sigma, uint8_t axis, real_t scaling=1.0)
The constructor.
Definition: substance_initializers.h:94
bdm::Uniform::max_
real_t max_
Definition: substance_initializers.h:74
bdm::Uniform::min_
real_t min_
Definition: substance_initializers.h:73
bdm::Axis
Axis
Definition: substance_initializers.h:33
bdm::PoissonBand::axis_
uint8_t axis_
Definition: substance_initializers.h:168
bdm::PoissonBand::operator()
real_t operator()(real_t x, real_t y, real_t z)
The model that we want to apply for substance initialization. The operator is called for the entire s...
Definition: substance_initializers.h:153
bdm::GaussianBand
Definition: substance_initializers.h:83
bdm::kXAxis
@ kXAxis
Definition: substance_initializers.h:33