BioDynaMo  v1.05.159-3be850bb
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_
GaussianBand(real_t mean, real_t sigma, uint8_t axis, real_t scaling=1.0)
The constructor.
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...
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...
PoissonBand(real_t lambda, uint8_t axis)
The constructor.
real_t operator()(real_t x, real_t y, real_t z)
Uniform(real_t min, real_t max, real_t value, uint8_t axis)
Definition: agent.cc:39
double real_t
Definition: real_t.h:21