C++ mpi module for stochmagnet_main Package
SM_Field.h
1 #ifndef SM_Field_H
2 #define SM_Field_H
3 
4 
5 //base class header
6 #include "CORE_Field.h"
7 
8 //runner header
9 #include "CORE_Run.h"
10 
11 //io header
12 #include "CORE_IO.h"
13 
14 //SM_Object header
15 #include "SM_Object.h"
16 
17 //file stream header
18 #include <fstream>
19 //set precision header
20 #include<iomanip>
21 
22 //field header
23 #include "CORE_StdPtrField.h"
24 
25 //stochastic functions
26 #include "SM_MultiStochasticFunctions.h"
27 
28 //constants header
29 #include "SM_Constants.h"
30 
31 //openmp header
32 //#include "openMP.h"
33 
42 template<typename T,typename K,tUCInt D>
43 class SM_Field : public CORE_StdPtrField<T,K,D> {
44 
45  // ATTRIBUTES
46 private :
47  typedef SM_Field<T,K,D> Self;
48 
49 public:
50  // METHODS
51 
52  // CONSTRUCTORS
53 
57 
58  }
59 
63  SM_Field(std::initializer_list<T>&& values) {
64  this->copy(values);
65  }
66 
67 
68 
69  // DESTRUCTORS
70 
71 
74  virtual ~SM_Field(void) {
75  }
76 
77 private:
78 
79 
80 
81 public:
82  // New class pointer
83  //==================
84 
88  inline static CORE_UniquePointer<Self> New() {
89  return CORE_UniquePointer<Self>(new Self(),CORE_Object::Delete());
90  }
91 
92 
93  //MEMORY
94 
108  virtual tMemSize getMemorySize() const {
109  return sizeof(*this)+this->getContentsMemorySize();
110  }
111 
112 
113  //assignement operator
118  Self& operator=(const T& v) {
119  this->initialize(v);
120  return (*this);
121  }
122 
127  Self& operator=(const std::initializer_list<T>& cpy) {
128  this->copy(cpy);
129  return (*this);
130  }
135  Self& operator=(std::initializer_list<T>&& cpy) {
136  this->copy(cpy);
137  return (*this);
138  }
143  Self& operator=(const std::valarray<T>& cpy) {
144  this->copy(cpy);
145  return (*this);
146  }
151  Self& operator=(const std::array<T,D>& cpy) {
152  this->copy(cpy);
153  return (*this);
154  }
155 
160  Self& operator=(const Self& cpy) {
161  this->copy(cpy);
162  return (*this);
163  }
168  Self& operator=(Self&& cpy) {
169  this->copy(cpy);
170  return (*this);
171  }
172 
173 
174 
175  //mathematical operators
176  //=======================
177 
183  template<class R>
184  requires functions_type::isRealType<R>
185  inline void addStochasticNoise(const R& epsilon,
187 
188  tIndex n=this->getSize();
189  T *Vs=this->getValues();
190  //random function for the thread 0
192 
193  //for each element of the array add a random number
194  T *iV=Vs;
195  const T *iVe=Vs;iVe+=n;
196 
197  while (iV!=iVe) {
198  (*iV)+=epsilon*f.normalRandom();
199  iV++;
200  }
201  }
202 
208  template<class R,class StochF>
209  inline void addscStochasticNoise(const R& epsilon,
211 
212  tIndex n=this->getSize();
213  T *Vs=this->getValues();
214 
215 
216  //random function for the thread 0
217  StochF& f=fs[0];
218 
219  //for each element of the array add a random number
220  T *iV=Vs;
221  const T *iVe=Vs;iVe+=n;
222 
223  while (iV!=iVe) {
224  (*iV)+=epsilon*f.scNormalRandom();
225  iV++;
226  }
227 
228  }
229 
230 
231 
232 
233 
234 public:
235  // OTHERS methods
236 
237 
238 
239 private:
240 
241 
242 
243 };
244 
245 
246 
248 
249 #endif
virtual tMemSize getContentsMemorySize() const override
return the memory size of the included associations
Definition: CORE_Field.h:102
void copy(const tIndex &n, const Q *vs)
initialize the field to the values of pointer of size n
Definition: CORE_Field.h:447
const T * getValues() const
get the values of the array for reading
Definition: CORE_Field.h:323
tIndex getSize() const
return the number values of the container
Definition: CORE_Field.h:161
class Free introduced for deleting a smart pointer
Definition: CORE_Object.h:113
this class describes a standart arithmetic array type implemented with a CORE_StdPtrArray object
Definition: CORE_StdPtrField.h:17
void initialize(const Q &v)
initailize all the values with v
Definition: CORE_StdPtrField.h:192
This class describes a field with a T type with index of type K of size D.
Definition: SM_Field.h:43
Self & operator=(const std::array< T, D > &cpy)
copy operator
Definition: SM_Field.h:151
virtual ~SM_Field(void)
destroy the interface
Definition: SM_Field.h:74
static CORE_UniquePointer< Self > New()
build a new instance of a SM_Field
Definition: SM_Field.h:88
Self & operator=(const T &v)
copy operator
Definition: SM_Field.h:118
void addscStochasticNoise(const R &epsilon, SM_MultiStochasticFunctions< StochF > &fs)
add a stochastic noise the the field by static casting method
Definition: SM_Field.h:209
virtual tMemSize getMemorySize() const
return the memory size of the class and the memory size of all its attributes/associations
Definition: SM_Field.h:108
Self & operator=(const std::valarray< T > &cpy)
copy operator
Definition: SM_Field.h:143
Self & operator=(std::initializer_list< T > &&cpy)
copy operator
Definition: SM_Field.h:135
Self & operator=(const std::initializer_list< T > &cpy)
copy operator
Definition: SM_Field.h:127
requires functions_type::isRealType< R > void addStochasticNoise(const R &epsilon, SM_MultiStochasticFunctionsInterface &fs)
add a stochastic noise the the field
Definition: SM_Field.h:185
SM_Field()
create a field of dim D and size 1
Definition: SM_Field.h:56
Self & operator=(Self &&cpy)
copy operator
Definition: SM_Field.h:168
SM_Field(std::initializer_list< T > &&values)
create a field of dim 3 and size values.size()/3 initialized with values list values
Definition: SM_Field.h:63
Self & operator=(const Self &cpy)
copy operator
Definition: SM_Field.h:160
This class describes a multi stochastic functions based on same random number generator which impleme...
Definition: SM_MultiStochasticFunctionsInterface.h:18
This class describes a multi stochastic functions based on same random number generator which impleme...
Definition: SM_MultiStochasticFunctions.h:26
This class describes a stochastic functions based on same random number generator which implement ran...
Definition: SM_StochasticFunctionsInterface.h:18
virtual tReal normalRandom()=0
compute a normal random number