VPTissue Reference Manual
StandardNormal.h
Go to the documentation of this file.
1 #ifndef SIMPT_DEFAULT_MOVE_GEN_STANDARD_NORMAL_H_INCLUDED
2 #define SIMPT_DEFAULT_MOVE_GEN_STANDARD_NORMAL_H_INCLUDED
3 /*
4  * Copyright 2011-2016 Universiteit Antwerpen
5  *
6  * Licensed under the EUPL, Version 1.1 or as soon they will be approved by
7  * the European Commission - subsequent versions of the EUPL (the "Licence");
8  * You may not use this work except in compliance with the Licence.
9  * You may obtain a copy of the Licence at: http://ec.europa.eu/idabc/eupl5
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the Licence is distributed on an "AS IS" basis,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the Licence for the specific language governing
15  * permissions and limitations under the Licence.
16  */
22 #include "math/constants.h"
23 #include "math/RandomEngine.h"
24 #include "sim/CoreData.h"
25 
26 #include <trng/normal_dist.hpp>
27 #include <trng/uniform01_dist.hpp>
28 #include <array>
29 #include <cmath>
30 
31 namespace SimPT_Default {
32 namespace MoveGenerator {
33 
34 using namespace SimPT_Sim;
35 using namespace SimPT_Sim::Util;
36 
41 {
42 public:
45  {
46  assert( cd.Check() && "CoreData not ok.");
47  Initialize(cd);
48  }
49 
51  void Initialize(const CoreData& cd)
52  {
53  m_normal_generator = cd.m_random_engine->GetGenerator(trng::normal_dist<double>(0.0, 1.0));
54  m_uniform_generator = cd.m_random_engine->GetGenerator(trng::uniform01_dist<double>());
55  }
56 
58  std::array<double, 3> operator()()
59  {
60  // Angles range [0.0, pi], amplitudes [- very large, very large]
61  const double angle = m_uniform_generator() * pi();
62  const double ampli = m_normal_generator();
63  return std::array<double, 3>{{ ampli * std::sin(angle), ampli * std::cos(angle), 0.0 }};
64  }
65 
66 private:
67  std::function<double()> m_normal_generator;
68  std::function<double()> m_uniform_generator;
69 };
70 
71 } // namespace
72 } // namespace
73 
74 #endif // end_of_include_guard
Math constants.
Move Generator with normal distribution (no directional bias).
Core data with mesh, parameters, random engine and time data.
Definition: CoreData.h:38
Core data used during model execution.
Namespace for miscellaneous utilities.
Definition: PTreeFile.cpp:44
Interface of RandomEngine.
Namespace for components of the Default model group.
Namespace for the core simulator.
StandardNormal(const CoreData &cd)
Straight initialization.
void Initialize(const CoreData &cd)
Initialize or re-initialize.
std::array< double, 3 > operator()()
Generate a random move.
constexpr double pi()
Math constant pi.
Definition: constants.h:29
bool Check() const
Verify all pointers non-null.
Definition: CoreData.h:53