C++ mpi module for stochmagnet_main Package
SM_Beam.h
1 #ifndef SM_Beam_H
2 #define SM_Beam_H
3 
4 //define the std::valarray object
5 #include <valarray>
6 //define the std::array object
7 #include <array>
8 
9 //base class
10 #include "SM_Object.h"
11 
12 //system class
13 #include "SM_System.h"
14 
15 //stochastic functions per threads
16 #include "SM_MultiStochasticFunctions.h"
17 
18 //stochastic output
19 #include "SM_StochasticOutput.h"
20 
21 
61 class SM_Beam : public SM_Object {
62 
63  //attributes
64 private :
65 
66 
67  //number of simulations
68  tIndex mBeamSize;
69  tIndex mBeginSimulationIndex;
70  tIndex mEndSimulationIndex;
71 
72  //associations
73  //============
74 
75  //system
76  CORE_UniquePointer<SM_System> mSystem;
77 
78  //stochastic functions per thread
79  CORE_UniquePointer<SM_MultiStochasticFunctionsInterface> mMultiStochasticFunctions;
80 
81 
82  tIndex mPreconditioningStepsNumber;
83  tIndex mStepsNumber;
84 
85 
86 protected:
87  // CONSTRUCTORS
90  SM_Beam(void) {
91  mBeamSize=1;
92  mPreconditioningStepsNumber=0;
93  mStepsNumber=1000;
94  mBeginSimulationIndex=0;
95  mEndSimulationIndex=mBeamSize;
96  }
97 
98  // DESTRUCTORS
101  virtual ~SM_Beam(void) {
102  }
103 
104 public :
105 
106  //MEMORY
107 
121  virtual tMemSize getMemorySize() const override {
122  return sizeof(*this)+getContentsMemorySize();
123  }
124 
133  virtual tMemSize getContentsMemorySize() const override {
134  tMemSize mem=SM_Object::getContentsMemorySize();
135  mem+=(mMultiStochasticFunctions.get()==null)?0:mMultiStochasticFunctions->getMemorySize();
136  mem+=(mSystem.get()==null)?0:mSystem->getMemorySize();
137  return mem;
138  }
139 
140 
141  //SET & GET methods
142 
143 
144  //data
145  //====
149  inline void setBeamSize(const tIndex& n) {
150  mBeamSize=n;
151  mBeginSimulationIndex=0;
152  mEndSimulationIndex=n;
153  }
158  inline void setBeamSize(const tIndex& s0,const tIndex& s1) {
159  mBeamSize=s1-s0;
160  mBeginSimulationIndex=s0;
161  mEndSimulationIndex=s1;
162  }
166  inline const tIndex& getBeamSize() const {
167  return mBeamSize;
168  }
174  inline const tIndex& getBeamSize(tIndex& s0,tIndex& s1) const {
175  s0= mBeginSimulationIndex;
176  s1= mEndSimulationIndex;
177  return mBeamSize;
178  }
179 
180 
181  //steps data
182  //=============
183 
187  inline void setPreconditioningStepsNumber(const tIndex& n) {
188  mPreconditioningStepsNumber=n;
189 
190  }
194  inline const tIndex& getPreconditioningStepsNumber() const {
195  return mPreconditioningStepsNumber;
196 
197  }
201  inline void setStepsNumber(const tIndex& n) {
202  mStepsNumber=n;
203  }
207  inline const tIndex& getStepsNumber() const {
208  return mStepsNumber;
209 
210  }
211  //Stochastic functions
212  //====================
213 
216  inline void resetStochasticFunctions() {
217  mMultiStochasticFunctions.reset();
218 
219  }
223  inline void setStochasticFunctions(CORE_UniquePointer<SM_MultiStochasticFunctionsInterface>& f) {
224  mMultiStochasticFunctions=std::move(f);
225 
226  }
227 
230  inline tBoolean hasStochasticFunctions() const {
231  return (mMultiStochasticFunctions.get()!=null);
232  }
237  return *mMultiStochasticFunctions.get();
238  }
243  return *mMultiStochasticFunctions.get();
244  }
245 
246 
247  //noise
248 
249 
250 
251  //System
252  //====
253 
257  inline void setSystem(CORE_UniquePointer<SM_System> system) {
258  mSystem=std::move(system);
259  }
260 
264  inline const SM_System& getSystem() const {
265  return *mSystem.get();
266  }
267 
271  inline SM_System& getSystem() {
272  return *mSystem.get();
273  }
274 
278  inline tBoolean hasSystem() const {
279  return (mSystem.get()!=null);
280  }
281 
282  // MAIN Method
283 public:
284 
285 
288  inline void normalize(const tBoolean& isAdimensionized) {
289  getSystem().normalize(isAdimensionized);
290  }
293  inline void discretize() {
294 
295  //discretize the system
296  getSystem().discretize();
297 
298  }
299 
300 
306  template<class System,class StochOutputImplement>
307  tBoolean run(SM_StochasticOutput<StochOutputImplement>& outputSData);
308 
309 
310 
311 
315  virtual tString toString() const override {
316  std::stringstream ret;
317  //print id
318  ret<<SM_Object::toString()<<"\n";
319  //print beam size
320  ret<<"beam size: "<<mBeamSize<<"\n";
321  ret<<"preconditioning steps number: "<<mPreconditioningStepsNumber<<"\n";
322  ret<<"steps number: "<<mStepsNumber<<"\n";
323 
324  ret<<"stochastic Function:";
325  if (mMultiStochasticFunctions.get()!=null)
326  ret<<mMultiStochasticFunctions->toString()<<"\n";
327  else
328  ret<<"null\n";
329 
330  ret<<"system:";
331  if (hasSystem())
332  ret<<getSystem().toString()<<"\n";
333  else
334  ret<<"null\n";
335  return ret.str();
336 
337  }
338 
339 };
340 
341 #include "SM_Beam.hpp"
342 
343 #endif
virtual tMemSize getContentsMemorySize() const
return nthe memory size of the included associations
Definition: CORE_Object.h:278
virtual tString toString() const
return the string representation of the object node
Definition: CORE_Object.h:333
This class defines a general stochastic beam of trajectories of system.
Definition: SM_Beam.h:61
const SM_System & getSystem() const
get the system
Definition: SM_Beam.h:264
SM_System & getSystem()
get the system
Definition: SM_Beam.h:271
SM_Beam(void)
create
Definition: SM_Beam.h:90
SM_MultiStochasticFunctionsInterface & getStochasticFunctions()
get the stochastic functions
Definition: SM_Beam.h:242
tBoolean run(SM_StochasticOutput< StochOutputImplement > &outputSData)
run the simulations
Definition: SM_Beam.hpp:6
virtual tString toString() const override
turn the class into a string representation
Definition: SM_Beam.h:315
const SM_MultiStochasticFunctionsInterface & getStochasticFunctions() const
get the stochastic functions
Definition: SM_Beam.h:236
tBoolean hasStochasticFunctions() const
return true if the beam has a stochastic function
Definition: SM_Beam.h:230
void setPreconditioningStepsNumber(const tIndex &n)
set the number of steps of preconditioning
Definition: SM_Beam.h:187
const tIndex & getBeamSize(tIndex &s0, tIndex &s1) const
get the beam size
Definition: SM_Beam.h:174
void setStepsNumber(const tIndex &n)
set the number of steps for loop
Definition: SM_Beam.h:201
void discretize()
discretize its system and its stochastic function
Definition: SM_Beam.h:293
void resetStochasticFunctions()
reset the stochastic functions
Definition: SM_Beam.h:216
void normalize(const tBoolean &isAdimensionized)
adimensionize the beam data
Definition: SM_Beam.h:288
virtual tMemSize getContentsMemorySize() const override
return the memory size of the included associations
Definition: SM_Beam.h:133
virtual tMemSize getMemorySize() const override
return the memory size of the class and the memory size of all its attributes/associations
Definition: SM_Beam.h:121
tBoolean hasSystem() const
return true if the system of the beam is not null
Definition: SM_Beam.h:278
const tIndex & getBeamSize() const
get the beam size
Definition: SM_Beam.h:166
void setSystem(CORE_UniquePointer< SM_System > system)
set the system
Definition: SM_Beam.h:257
virtual ~SM_Beam(void)
destroy
Definition: SM_Beam.h:101
void setBeamSize(const tIndex &s0, const tIndex &s1)
set the beam size
Definition: SM_Beam.h:158
void setBeamSize(const tIndex &n)
set the beam size
Definition: SM_Beam.h:149
const tIndex & getStepsNumber() const
get the number of steps for stochastic computation
Definition: SM_Beam.h:207
const tIndex & getPreconditioningStepsNumber() const
get the number of steps for precoditioning
Definition: SM_Beam.h:194
void setStochasticFunctions(CORE_UniquePointer< SM_MultiStochasticFunctionsInterface > &f)
set the stochastic functions
Definition: SM_Beam.h:223
This class describes a multi stochastic functions based on same random number generator which impleme...
Definition: SM_MultiStochasticFunctionsInterface.h:18
This class is a base class for Stoch Microm package.
Definition: SM_Object.h:36
this class implements the virtual methods of its base class SM_StochasticOutputComponent with templat...
Definition: SM_StochasticOutput.h:24
This class is a one simulation of a beam for Stoch Magnet package.
Definition: SM_System.h:53
virtual void discretize()
discretize the system
Definition: SM_System.h:546
virtual void normalize(const tBoolean &isAdimensionized)
normalize the system
Definition: SM_System.h:431
virtual tString toString() const override
turn the class into a string representation
Definition: SM_System.h:749