KratosMultiphysics
KRATOS Multiphysics (Kratos) is a framework for building parallel, multi-disciplinary simulation software, aiming at modularity, extensibility, and high performance. Kratos is written in C++, and counts with an extensive Python interface.
random_initializer_utility.h
Go to the documentation of this file.
1 // | / |
2 // ' / __| _` | __| _ \ __|
3 // . \ | ( | | ( |\__ `
4 // _|\_\_| \__,_|\__|\___/ ____/
5 // Multi-Physics
6 //
7 // License: BSD License
8 // Kratos default license: kratos/license.txt
9 //
10 // Main authors: Vicente Mataix Ferrandiz
11 //
12 //
13 
14 #if !defined(KRATOS_RANDOM_UTILITY_INITIALIZER_H_INCLUDED )
15 #define KRATOS_RANDOM_UTILITY_INITIALIZER_H_INCLUDED
16 
17 // System includes
18 #include <random>
19 
20 // External includes
21 
22 // Project includes
23 #include "spaces/ublas_space.h"
24 
25 namespace Kratos
26 {
27 
30 
34 
38 
42 
46 
54 template<class TDataType>
56 {
57 public:
58 
61 
63 
65 
67 
69 
71 
73 
74  typedef std::size_t SizeType;
75 
79 
83 
84 
88 
95  static inline void NormalDestributionRandom(
96  VectorType& R,
97  const TDataType& MeanValue,
98  const TDataType& VarianceValue
99  )
100  {
101  // We create a random vector as seed of the method
102  unsigned int seed = 1; // Constant seed
103  std::default_random_engine generator(seed);
104 
105  std::normal_distribution<TDataType> normal_distribution(MeanValue, VarianceValue);
106 
107  for (SizeType i = 0; i < R.size(); ++i)
108  R[i] = normal_distribution(generator);
109  }
110 
111 
118  static inline void RandomInitialize(
119  const SparseMatrixType& K,
120  VectorType& R,
121  const bool Inverse = false
122  )
123  {
124  const TDataType threshold = std::numeric_limits<TDataType>::epsilon();
125  const TDataType normK = SparseSpaceType::TwoNorm(K);
126  const TDataType aux_value = (Inverse == false) ? normK : (normK > threshold) ? 1.0/normK : 1.0;
127  NormalDestributionRandom(R, aux_value, 0.25 * aux_value);
128  }
129 
133 
134 
138 
139 
143 
147 
148 private:
149 
152 
156 
160 
164 
168 
172 
176 
180 
182 
184 
185 }; /* Class RandomInitializeUtility */
186 
187 } // namespace Kratos.
188 
189 #endif // KRATOS_RANDOM_UTILITY_INITIALIZER_H_INCLUDED defined
Utility to initialize a random vector.
Definition: random_initializer_utility.h:56
UblasSpace< TDataType, CompressedMatrix, boost::numeric::ublas::vector< double > > SparseSpaceType
Definition: random_initializer_utility.h:62
static void RandomInitialize(const SparseMatrixType &K, VectorType &R, const bool Inverse=false)
This method initializes a vector using a normal distribution. The mean and the variance is taken from...
Definition: random_initializer_utility.h:118
static void NormalDestributionRandom(VectorType &R, const TDataType &MeanValue, const TDataType &VarianceValue)
This method initializes a vector using a normal normal distribution.
Definition: random_initializer_utility.h:95
SparseSpaceType::MatrixType SparseMatrixType
Definition: random_initializer_utility.h:66
LocalSpaceType::MatrixType DenseMatrixType
Definition: random_initializer_utility.h:70
LocalSpaceType::VectorType DenseVectorType
Definition: random_initializer_utility.h:72
std::size_t SizeType
Definition: random_initializer_utility.h:74
UblasSpace< TDataType, Matrix, Vector > LocalSpaceType
Definition: random_initializer_utility.h:64
SparseSpaceType::VectorType VectorType
Definition: random_initializer_utility.h:68
A class template for handling data types, matrices, and vectors in a Ublas space.
Definition: ublas_space.h:121
static TDataType TwoNorm(VectorType const &rX)
||rX||2
Definition: ublas_space.h:278
TMatrixType MatrixType
The matrix type considered.
Definition: ublas_space.h:133
TVectorType VectorType
The vector type considered.
Definition: ublas_space.h:136
int seed
Definition: GenerateWind.py:138
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
threshold
Definition: isotropic_damage_automatic_differentiation.py:135
R
Definition: isotropic_damage_automatic_differentiation.py:172
K
Definition: sensitivityMatrix.py:73
integer i
Definition: TensorModule.f:17