C++ main module for stochmagnet Package  1.0
SM_TemplatedSystem.hpp
Go to the documentation of this file.
1 #ifndef SM_TemplatedSystem_HPP
2 #define SM_TemplatedSystem_HPP
3 template<class SystemImpl>
4 template<class StochImpl,class NoiseImpl>
6  const SM_TemplatedNoiseRateFunction<NoiseImpl>& noiseRateFunction,
7  tReal *mu,tReal *E) {
8  //return value
9  tBoolean succeeds=true;
10 
11 
12  //network of the system
13  const SM_Network& network=this->getNetwork();
14 
15  //dimension of th enetwork
16  const tUSInt& dim=network.getDimension();
17 
18  //number of particles
19  const tIndex& nParticles=network.getParticlesNumber();
20 
21  //field array size & iterator on it
22  tIndex i,N=nParticles*dim;
23 
24  //time stepper
25  const SM_TimeStepper& timeStepper=this->getTimeStepper();
26 
27  //time step
28  const tReal& dt=timeStepper.getTimeStep();
29 
30  //maximum time steps number
31  const tIndex &nTimeSteps=timeStepper.getMaximumTimeStepsNumber();
32 
33  //magnetic moment at t=0
34  const SM_RealField & mu0=this->getInitialMagneticMoment();
35 
36 
37  //input assertions
38  ASSERT_IN(mu0.getElementsNumber()==nParticles);
39  ASSERT_IN(getMagneticField().getElementsNumber()==nParticles);
40 
41  //magnetic field B
42  tReal *B=&getMagneticField()[0];
43 
44  //current time
45  tReal time=0;
46 
47 
48  //noise rate
49  tReal epsilon_t;
50 
51 
52  //iterator on mu(t)
53  tReal *mu_t=mu;
54 
55  //initialize mu(t=0)=mu0
56  memcpy(mu_t,&mu0[0],N*sizeof(tReal));
57 
58  //mu at time t+dt
59  tReal *mu_tpdt=&mu[N];
60 
61  //iterator on E(t)
62  //size of E is (nOperators+1) x nTimesSteps
63  tIndex nE=getOperatorsNumber()+1;
64  tReal *E_t=E;
65 
66 
67  //initialize energy to 0
68  memset(E,0,nE*nTimeSteps*sizeof(tReal));
69 
70 
71  //LL Function
72  const SM_LandauLifschitzFunction& llFunction=getLandauLifschitzFunction();
73 
74  //iterator on B
75  tReal *Bi;
76 
77 
78 
79  for (tIndex iT=0;iT<nTimeSteps;iT++) {//loop on time
80 
81  //compute the noise rate by a templated function
82  epsilon_t=noiseRateFunction.computeTemplatedFunction(time);
83  //compute the noise rate by a virtual function
84  //epsilon_t=noiseRateFunction.computeFunction(time);
85 
86  //compute B
87  //std::cout<<"t="<<time<<" ";
88  //templated method implemntation:
89  computeTemplatedMagneticFieldAndEnergies(iT,network,mu_t,B,E_t);
90  //virtual method implementation:
91  //computeMagneticField(network,mu_t,B);
92 
93  //B=dt.B+epsilon_t . sqrt(dt). N(0,1)
94  Bi=B;
95  for (i=0;i<N;i++) {
96  (*Bi) =(*Bi)*dt+epsilon_t*sqrt(dt)*randomFunction.templatedRandom();//templated function called
97  //(*Bi) =(*Bi)*dt+epsilon_t*sqrt(dt)*randomFunction.random();//virtual function called
98  Bi++;
99  }
100 
101  //compute the landau lifchitz function mu_{t+dt}=LL(mu_t,B)
102  llFunction.computeFunction(nParticles,dim,mu_t,B,mu_tpdt);
103 
104  //compute mu at next time step
105  if (!computeTemplatedMuAtNextTimeStep(dt,epsilon_t,nParticles,dim,mu_t,mu_tpdt)) {
106  //the algorithm diverges
107  //break the loop
108  succeeds=false;
109  break;
110  }
111 
112  //next time step
113  time+=dt;//time at next time step
114  mu_t+=N;//mu at t+dt
115  mu_tpdt+=N;//mu at t+dt+dt
116  E_t+=nE;//energy at next time step
117  }
118 
119  return succeeds;
120 }
121 
122 
123 
124 #endif
tIndex getElementsNumber() const
return the number values of the container
Definition: CORE_Field.h:118
This class describes a landau lifschitz function of the form :
Definition: SM_LandauLifschitzFunction.h:26
void computeFunction(const SM_RealField &Mu, const SM_RealField &B, SM_RealField &F) const
computes the magnetic function
Definition: SM_LandauLifschitzFunction.h:161
This class is describes a a network.
Definition: SM_Network.h:18
tDimension getDimension() const
return the dimension
Definition: SM_Network.h:133
tInteger getParticlesNumber() const
return the particles number
Definition: SM_Network.h:146
This class describes a templated noise rate function as static polymorphism.
Definition: SM_TemplatedNoiseRateFunction.h:14
tReal computeTemplatedFunction(const tReal &t) const
compute the noise rate function by static polymorphism
Definition: SM_TemplatedNoiseRateFunction.h:91
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
tBoolean makeTemplatedRelaxation(const SM_TemplatedStochasticFunction< StochImpl > &randomFunction, tReal *mu, tReal *Es)
compute the relaxation process by calling only templated methods
Definition: SM_TemplatedSystem.h:124
This class is describes a time stepper.
Definition: SM_TimeStepper.h:13
const tReal & getTimeStep() const
return the time step
Definition: SM_TimeStepper.h:103
const tIndex & getMaximumTimeStepsNumber() const
return the time steps number
Definition: SM_TimeStepper.h:130
#define ASSERT_IN(a)
Definition: functions.h:601
#define tIndex
Definition: types.h:157
#define tUSInt
Definition: types.h:38
#define tBoolean
Definition: types.h:151
#define tReal
Definition: types.h:137