C++ main module for stochmagnet Package  1.0
SM_Beam.hpp
Go to the documentation of this file.
1 #ifndef SM_Beam_HPP
2 #define SM_Beam_HPP
3 
6 
7 template<class SystemImpl,class NoiseImpl>
8 tIndex SM_Beam::templatedSimulate(SystemImpl& system,const NoiseImpl& noise) {
9 
10  //get the size of the beam
11  const tIndex & beamSize=getBeamSize();
12 
13  //iterator on trajectories
14  tIndex s;
15 
16  //the size of mu is mBeamSize x mTimeStepsNumber x mParticlesNumber x mDimension
17  //the value of the k-coordinates of the particle p at time t for the simulation s is at index:
18  //index=k+mDimension*(p+mParticlesNumber*(t+mTimeStepsNumber*(s)))
19 
20  //the mu by simulation
21  std::valarray<tReal>& mu=getMagneticMoment();
22 
23  //the energy of simulations
24  std::valarray<tReal>& Es=getEnergies();
25 
26  //mu Size for one trajectory
27  tIndex muSize=mu.size()/beamSize;
28 
29  //E Size for one trajectory
30  tIndex ESize=Es.size()/beamSize;
31 
32  //get the stochastic function
34 
35  //mu at simulation 0
36  tReal *mu_s=&mu[0];
37 
38  //Es at simulation 0
39  tReal *Es_s=&Es[0];
40 
41  //number of simulations without errors
42  tIndex nEffectiveSimulations=0;
43 
45  //Boost normal function
46 
47  for (s=0;s<beamSize;s++) {
48  if (system.makeTemplatedRelaxation(*dynamic_cast<const SMS_BoostNormalFunction*>(&sf),
49  noise,
50  mu_s,Es_s)) {
51  nEffectiveSimulations++;
52 
53  //next trajectory
54  mu_s+=muSize;
55  Es_s+=ESize;
56 
57  }
58 
59  }
60  } else {
61  // STD normal function
62  for (s=0;s<beamSize;s++) {
63  if (system.makeTemplatedRelaxation(*dynamic_cast<const SMS_STDNormalFunction*>(&sf),
64  noise,
65  mu_s,Es_s)) {
66  nEffectiveSimulations++;
67 
68  //next trajectory
69  mu_s+=muSize;
70  Es_s+=ESize;
71 
72  }
73 
74  }
75  }
76 
77  //main loop
78  return nEffectiveSimulations;
79 
80 }
81 #endif
tBoolean isInstanceOf() const
test if the clas T is an instance of this class
Definition: CORE_Object.h:271
This class implements a stochastic function with a normal law implemented from the boost library.
Definition: SMS_BoostNormalFunction.h:20
This class implements a stochastic function with a normal law implemented from the boost library.
Definition: SMS_STDNormalFunction.h:15
tIndex templatedSimulate()
simulate a beam by computing mu field by calling only templated methods
Definition: SM_Beam.h:313
const tIndex & getBeamSize() const
get the beam size
Definition: SM_Beam.h:166
const std::valarray< tReal > & getEnergies() const
return the Energy array
Definition: SM_Beam.h:218
const SM_StochasticFunction & getStochasticFunction() const
get the stochastic function
Definition: SM_Beam.h:179
const std::valarray< tReal > & getMagneticMoment() const
return the mu array
Definition: SM_Beam.h:206
This class describes a stochastic function interface to generate random numbers.
Definition: SM_StochasticFunction.h:15
#define tIndex
Definition: types.h:157
#define tReal
Definition: types.h:137