Mechanics of Defect Evolution Library
Loading...
Searching...
No Matches
NoiseTraits.cpp
Go to the documentation of this file.
1/* This file is part of MoDELib, the Mechanics Of Defects Evolution Library.
2 *
3 *
4 * MoDELib is distributed without any warranty under the
5 * GNU General Public License (GPL) v2 <http://www.gnu.org/licenses/>.
6 */
7
8#ifndef model_NoiseTraits_cpp
9#define model_NoiseTraits_cpp
10
11#include <NoiseTraits.h>
12
13namespace model
14{
15
17 {
18 int num = 1;
19 if(*(char *)&num == 1)
20 {
21 return 1; //little endian
22 }
23 else
24 {
25 return 0; // big endian
26 }
27 }
28
29 float NoiseTraitsBase::ReverseFloat(const float& inFloat)
30 {
31 float retVal;
32 char *FloatToConvert = ( char* ) & inFloat;
33 char *returnFloat = ( char* ) & retVal;
34
35 // swap the bytes into a temporary buffer
36 returnFloat[0] = FloatToConvert[3];
37 returnFloat[1] = FloatToConvert[2];
38 returnFloat[2] = FloatToConvert[1];
39 returnFloat[3] = FloatToConvert[0];
40
41 return retVal;
42 }
43
44 double NoiseTraitsBase::ReverseDouble(const double& inDouble)
45 {
46 double retVal;
47 char *DoubleToConvert = ( char* ) & inDouble;
48 char *returnDouble = ( char* ) & retVal;
49
50 // swap the bytes into a temporary buffer
51 returnDouble[0] = DoubleToConvert[7];
52 returnDouble[1] = DoubleToConvert[6];
53 returnDouble[2] = DoubleToConvert[5];
54 returnDouble[3] = DoubleToConvert[4];
55 returnDouble[4] = DoubleToConvert[3];
56 returnDouble[5] = DoubleToConvert[2];
57 returnDouble[6] = DoubleToConvert[1];
58 returnDouble[7] = DoubleToConvert[0];
59
60 return retVal;
61 }
62
63template <int N>
64const typename NoiseTraits<N>::NoiseType& NoiseTraits<N>::fromMatrix(const Eigen::Matrix<REAL_SCALAR,1,N>& m)
65{
66 return m;
67}
68
69template <int N>
71{
72 return NoiseType::Zero();
73}
74
75template <int N>
77{
78 return (m.array()*m.array()).matrix();
79}
80
81
82//template struct NoiseTraits<1>;
83template struct NoiseTraits<2>;
84
85}
86#endif
87
static double ReverseDouble(const double &inDouble)
static float ReverseFloat(const float &inFloat)
static int LittleEndian()
static NoiseType squared(const NoiseType &m)
static NoiseType Zero()
static const NoiseType & fromMatrix(const Eigen::Matrix< REAL_SCALAR, 1, N > &m)
Eigen::Matrix< REAL_SCALAR, 1, N > NoiseType
Definition NoiseTraits.h:35
void t struct mesh * m