C++ main module for stochmagnet Package  1.0
SM_Field.h
Go to the documentation of this file.
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 //file stream header
12 #include <fstream>
13 //set precision header
14 #include<iomanip>
15 
16 //stochastic function
18 
19 //field header
20 #include "CORE_StdPtrField.h"
21 
30 template<typename T,typename K>
31 class SM_Field : public CORE_StdPtrField<T,K,3> {
32 
33  // ATTRIBUTES
34 private :
35  typedef SM_Field<T,K> Self;
36 
37 public:
38  // METHODS
39 
40  // CONSTRUCTORS
41 
45 
46  }
47 
51  SM_Field(std::initializer_list<T>&& values) {
52  copy(values);
53  }
54 
55 
56 
57  // DESTRUCTORS
58 
59 
62  virtual ~SM_Field(void) {
63  }
64 
65 private:
66 
67 
68 
69 public:
70  // New class pointer
71  //==================
72 
76  inline static CORE_UniquePointer<Self> New() {
78  }
79 
80 
81  //MEMORY
82 
96  virtual tMemSize getMemorySize() const {
97  return sizeof(*this)+this->getContentsMemorySize();
98  }
99 
100 
101  //assignement operator
106  Self& operator=(const T& v) {
107  this->initialize(v);
108  return (*this);
109  }
110 
115  Self& operator=(const std::initializer_list<T>& cpy) {
116  this->copy(cpy);
117  return (*this);
118  }
123  Self& operator=(std::initializer_list<T>&& cpy) {
124  this->copy(cpy);
125  return (*this);
126  }
131  Self& operator=(const std::valarray<T>& cpy) {
132  this->copy(cpy);
133  return (*this);
134  }
135 
140  Self& operator=(const Self& cpy) {
141  this->copy(cpy);
142  return (*this);
143  }
148  Self& operator=(Self&& cpy) {
149  this->copy(cpy);
150  return (*this);
151  }
152 
153 
154 
155  //mathematical operators
156  //=======================
157 
163  template<class R>
164  requires core_functions::isRealType<R>
165  inline void addStochasticNoise(const R& epsilon,
167  //for each element of the array add a random number
168  T *iV=this->getValues();
169  const T *iVe=iV+this->getSize();
170  while (iV!=iVe) {
171  (*iV)+=epsilon*f.random();
172  iV++;
173  }
174 
175  }
176 
182  template<class R,class I>
183  inline void addTemplatedStochasticNoise(const R& epsilon,
185  //for each element of the array add a random number
186  T *iV=this->getValues();
187  const T *iVe=iV+this->getSize();
188  while (iV!=iVe) {
189  (*iV)+=epsilon*f.templatedRandom();
190  iV++;
191  }
192  }
193 
194 
195 
196 
197 
198 
199 public:
200  // OTHERS methods
201 
202 
203 
204 private:
205 
206 
207 
208 };
209 
210 
212 
213 #endif
SM_Field< tReal, tDimension > SM_RealField
Definition: SM_Field.h:211
virtual tMemSize getContentsMemorySize() const override
return the memory size of the included associations
Definition: CORE_Field.h:93
void copy(const tIndex &n, const Q *vs)
initialize the field to the values of pointer of size n
Definition: CORE_Field.h:422
const T * getValues() const
get the values of the array for reading
Definition: CORE_Field.h:298
tIndex getSize() const
return the number values of the container
Definition: CORE_Field.h:135
class Free introduced for deleting a smart pointer
Definition: CORE_Object.h:94
this class describes a standart arithmetic array type implemented with a std::valarray object
Definition: CORE_StdPtrField.h:14
void initialize(const Q &v)
initailize all the values with v
Definition: CORE_StdPtrField.h:178
This class describes a field with a floating point type.
Definition: SM_Field.h:31
SM_Field< T, K > Self
Definition: SM_Field.h:35
virtual ~SM_Field(void)
destroy the interface
Definition: SM_Field.h:62
void addTemplatedStochasticNoise(const R &epsilon, SM_TemplatedStochasticFunction< I > &f)
add a stochastic noise the the field
Definition: SM_Field.h:183
Self & operator=(const T &v)
copy operator
Definition: SM_Field.h:106
virtual tMemSize getMemorySize() const
return the memory size of the class and the memory size of all its attributes/associations
Definition: SM_Field.h:96
Self & operator=(const std::valarray< T > &cpy)
copy operator
Definition: SM_Field.h:131
static CORE_UniquePointer< Self > New()
build a new instance of a SM_Field
Definition: SM_Field.h:76
Self & operator=(std::initializer_list< T > &&cpy)
copy operator
Definition: SM_Field.h:123
Self & operator=(Self &&cpy)
copy operator
Definition: SM_Field.h:148
Self & operator=(const std::initializer_list< T > &cpy)
copy operator
Definition: SM_Field.h:115
requires core_functions::isRealType< R > void addStochasticNoise(const R &epsilon, SM_StochasticFunction &f)
add a stochastic noise the the field
Definition: SM_Field.h:165
Self & operator=(const Self &cpy)
copy operator
Definition: SM_Field.h:140
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:51
SM_Field()
create a field of dim 3 and size 1
Definition: SM_Field.h:44
This class describes a stochastic function interface to generate random numbers.
Definition: SM_StochasticFunction.h:15
virtual tReal random() const =0
compute a random number
This class describes a templated stochastic function to generate random numbers.
Definition: SM_TemplatedStochasticFunction.h:15
tReal templatedRandom() const
compute a random number
Definition: SM_TemplatedStochasticFunction.h:64
typename std::unique_ptr< T, CORE_Object::Delete > CORE_UniquePointer
Definition: sp.h:8
#define tMemSize
Definition: types.h:166