C++ mpi module for stochmagnet_main Package
SM_LandauLifschitzSystem.hpp
1 
2 //deterministic case
3 //==================
4 
5 
11 template<class StochOutputI>
12 tBoolean SM_LandauLifschitzSystem::deterministicRun(const tIndex& steppersNumber,
13  SM_StochasticOutput<StochOutputI>& stochasticOutput) {
14  tString routineName="SM_LandauLifschitzSystem::deterministicRun<StochasticOutput>(const tIndex&,StochasticOutput&)";
16 
17  //std::cout<<"begin "<<routineName<<" \n";
18 
19  //number of drawn for stochastic output
20  const tInteger& nDrawnSteps=stochasticOutput.getDrawnStepsNumber();
21 
22  //return value
23  tBoolean succeeds=true;
24 
25  //network of the system
26  const SM_Network& network=this->getNetwork();
27 
28  //material of the system
29  const SM_Material& material=this->getMaterial();
30 
31  //number of particles
32  const tIndex& nParticles=network.getParticlesNumber();
33 
34 
35  //get direction of magnetic moments
37 
38  //std::cout<<"S at time index 0:"<<St<<"\n";
39 
40 #ifdef DEBUG
41  if (St.isNANContained()) {
42  throw CORE_Exception("stochmagnet/LL",
43  "SM_LLSystem::deterministicRun("+std::to_string(steppersNumber)+",...)",
44  "S0 is nan");
45  }
46  //std::cout<<"NAN debug verification done.\n";
47 #endif
48 
49  //get the variation of the direction of the magnetic moment
51 
52  //magnetic field
53  SM_RealField &Ht=this->getMagneticField();
54 
55 
56  //time stepper
57  const SM_TimeStepper& timeStepper=this->getTimeStepper();
58 
59  //time step
60  const tReal& dt=timeStepper.getTimeStep();
61 
62 
63  //index of time
64  tIndex& timeIndex=this->getTimeIndex();
65 
66  //current time
67  tReal &time=this->getTime();
68  time=dt;
69  time*=timeIndex;
70 
71 
72  //LL Function
74 
75 
76  //use relaxation mIsRelaxed=true
77  tBoolean isRelaxationReached=false;
78  tReal& relaxationValue=getRelaxationValue();
79  relaxationValue=0;
80 
81 
82  tInteger iDrawnStep=0;
83 
84  //do the loop until:
85  // time >targetTime
86  // or
87  // mIsRelaxed is true and isRelaxationReached is true
88 
89 
90  tIndex &iStep=getStepIndex();
91  iStep=0;
92  //std::cout<<" step="<<iStep<<" steppers number :"<<steppersNumber<<" mIsRelaxed="<<mIsRelaxed<<" isRelaxationReached:"<<isRelaxationReached<<"\n";
93  while ( (iStep<steppersNumber) && ( (!mIsRelaxed) || (!isRelaxationReached)) ) {//loop on time
94 
95  //progress bar
96  //std::cout<<iStep<<"/"<<steppersNumber<<" mIsRelaxed:"<<mIsRelaxed<<" isRelaxationReached:"<<isRelaxationReached<<" relaxation:"<<relaxationValue<<"\n";
97 
98  //step to save the stochastic output > 0
99  iDrawnStep++;
100 
101 
102 
103  //update state of operators
104  //std::cout<<"update operator for step "<<iStep<<"\n";
105  updateOperatorsState(timeIndex,network,material,St);
106 
107 
108  //compute H
109  //std::cout<<" compute Ht for step "<<iStep<<"\n";
110  computeMagneticField(timeIndex,network,material,St,Ht);
111 
112  //is relaxed
113  //std::cout<<"compute Net Torque for step "<<iStep<<"\n";
114  relaxationValue=computeNetTorque();
115  isRelaxationReached=(fabs(relaxationValue)<mRelaxationTolerance);
116  //std::cout<<iStep<<":\t"<<relaxationValue<<"\t"<<isRelaxationReached<<"\n";
117 
118  //store stochastic output each drawnStep
119  if (iDrawnStep==nDrawnSteps) {
120  //std::cout<<"SO.store() for step "<<iStep<<"\n";
121  stochasticOutput.store(*this);
122  iDrawnStep=0;
123  }
124 
125 
126  //H:=dt.H
127  //std::cout<<" compute dHt for step "<<iStep<<"\n";
129 
130 
131 
132  //compute the landau lifchitz function Delta S_t=LL(St,dHt)
133  //std::cout<<" compute LL(St,Ht) for step "<<iStep<<"\n";
134  llFunction.computeFunction(nParticles,St,Ht,DeltaSt);
135 
136  //compute S at next time step
137  //std::cout<<"begin "<<getIdentityString()<<"::computeNextS for step "<<iStep<<"\n";
138  if (!computeMagneticMomentDirectionsAtNextTimeStep(dt,0,DeltaSt,St)) {
139  //the algorithm diverges
140  //break the loop
141  succeeds=false;
142  break;
143  }
144  //std::cout<<"end "<<getIdentityString()<<"::computeNextS for step "<<iStep<<"\n";
145 
146 
147 
148  //next time step
149  time+=dt;//time at next time step
150  timeIndex++;
151  iStep++;
152 
153  }
154 
155  //store the stochastix stochasticOutput at last time
156 
157  //compute h
158  //computeMagneticField(timeIndex,network,material,St,Ht);
159 
160  CORE_Profiler::EndCallRoutine(routineName);
161 
162  return succeeds;
163 }
164 
165 
166 //stochastic case
167 //================
168 
169 template<class StochOutputImplement>
170 tBoolean SM_LandauLifschitzSystem::stochasticRun(const tIndex& steppersNumber,
171  SM_MultiStochasticFunctionsInterface& multiStochasticFunctions,
172  SM_StochasticOutput<StochOutputImplement>& stochasticOutput) {
173  tString routineName="SM_LandauLifschitzSystem::stochasticRun<StochasticOutput>(const tIndex&, SM_StochasticFunctions&,StochasticOutput&)";
174  CORE_Profiler::StartCallRoutine(routineName);
175 
176  //number of drawn for stochastic output
177  tInteger nDrawnSteps=stochasticOutput.getDrawnStepsNumber();
178  if (nDrawnSteps==0) nDrawnSteps=steppersNumber+1;
179 
180  //return value
181  tBoolean succeeds=true;
182 
183  //network of the system
184  const SM_Network& network=this->getNetwork();
185 
186  //material of the system
187  const SM_Material& material=this->getMaterial();
188 
189  //number of particles
190  const tIndex& nParticles=network.getParticlesNumber();
191 
192 
193  //get direction of magnetic moments
195 
196  //get the variation of the dierction of the magnetic moment
198 
199  //magnetic field
200  SM_RealField &Ht=this->getMagneticField();
201 
202 
203  //time stepper
204  const SM_TimeStepper& timeStepper=this->getTimeStepper();
205 
206  //time step
207  const tReal& dt=timeStepper.getTimeStep();
208 
209  //square root of time step for Brownian perturbation
210  tReal Wdt=sqrt(dt);
211 
212 
213 
214  //index of time
215  tIndex& timeIndex=this->getTimeIndex();
216 
217  //current time
218  tReal &time=this->getTime();
219  time=dt;
220  time*=timeIndex;
221 
222  //LL Function
223  const SM_LandauLifschitzFunction& llFunction=this->getLandauLifschitzFunction();
224 
225 
226  //get the noise rate function
228 
229  //epsilon depending on time
230  tReal& epsilon_t=this->getNoiseRate();
231 
232 
233  //drawn Step
234  tInteger iDrawnStep=0;
235 
236 
237  //brownian perturbation variable or field
238  tReal dWt=0;
239  tBoolean incDWt=(!mIsRealBrownianVariable);
240  tReal *iDWt=&dWt;
241 
242  //iterator on brownian field
243  if (incDWt && (mDeltaWt.getSize()>0)) iDWt=&mDeltaWt[0];
244 
245  tIndex& iStep=getStepIndex();
246  iStep=0;
247  while (iStep<steppersNumber) {//loop on time
248 
249  //progress bar
250  //std::cout<<"SM_LLSystem::stochasticRun(..) : "<<iStep<<"/"<<steppersNumber<<" \n";
251 
252  //step to save the stochastic output
253  iDrawnStep++;
254 
255 
256  //compute epsilon_t by casting of computeFunction method
257  epsilon_t=noiseRateFunction.computeFunction(time);
258 
259  //update state of operators
260  updateOperatorsState(timeIndex,network,material,St);
261 
262  //compute H
263  computeMagneticField(timeIndex,network,material,St,Ht);
264 
265  //store stochastic output each drawnStep
266  if (iDrawnStep==nDrawnSteps) {
267  //std::cout<<"begin storing Stoch Outputs "<<stochasticOutput.getIdentityString()<<"\n";
268  stochasticOutput.store(*this);
269  //std::cout<<"end storing Stoch Outputs\n";
270  iDrawnStep=0;
271  }
272 
273  //H:=dt.H+epsilon_t . w(dt). N(0,1)
274  //std::cout<<"compute dHt\n";
275  if (epsilon_t!=0) {
276  //H:=dt.H+epsilon_t . w(dt). N(0,1)
277  computeBrownianVariationMagneticField(multiStochasticFunctions,dt,Wdt,epsilon_t,
278  incDWt,iDWt,Ht);
279  } else {
280  //H:=dt.H
282  }
283 
284  //std::cout<<"compute DSt\n";
285  //compute the landau lifchitz function Delta S_t=LL(St,dHt)
286  llFunction.computeFunction(nParticles,St,Ht,DeltaSt);
287 
288 
289  //compute S at next time step
290  //std::cout<<"compute St+dt\n";
291  if (!computeMagneticMomentDirectionsAtNextTimeStep(dt,epsilon_t,DeltaSt,St)) {
292  //the algorithm diverges
293  //break the loop
294  succeeds=false;
295  break;
296  }
297 
298  //next time step
299  time+=dt;//time at next time step
300  timeIndex++;//next time index
301  iStep++;
302  }
303  //progress bar
304  //std::cout<<"end SM_LLSystem::stochasticRun(..)";
305  CORE_Profiler::EndCallRoutine(routineName);
306  return succeeds;
307 }
308 
309 
310 
311 //Random J connection
312 
313 //stochastic case
314 //================
315 
323 template<class StochOutputImpl>
324 tBoolean SM_LandauLifschitzSystem::stochasticJRun(const tIndex& steppersNumber,
325  SM_StochasticFunctionsInterface& stochasticFunctions,
326  SM_StochasticOutput<StochOutputImpl>& stochasticOutput,
327  const std::function<void(const tReal&,const tReal& ,const tReal&,tReal& )>& F) {
328  tString routineName="SM_LandauLifschitzSystem::stochasticJRun<StochasticOutput>(const tIndex&, SM_StochasticFunctions&,StochasticOutput&)";
329  CORE_Profiler::StartCallRoutine(routineName);
330 
331  //number of drawn for stochastic output
332  tInteger nDrawnSteps=stochasticOutput.getDrawnStepsNumber();
333  if (nDrawnSteps==0) nDrawnSteps=steppersNumber+1;
334 
335  //return value
336  tBoolean succeeds=true;
337 
338  //network of the system
339  SM_Network& network=this->getNetwork();
340 
341  //material of the system
342  const SM_Material& material=this->getMaterial();
343 
344  //adimensionized exhange factor
345  const tReal& J=material.getAdimensionizedExchangeEnergyFactor();
346 
347  //number of particles
348  const tIndex& nParticles=network.getParticlesNumber();
349 
350  //get direction of magnetic moments
352 
353  //get the variation of the dierction of the magnetic moment
355 
356  //magnetic field
357  SM_RealField &Ht=this->getMagneticField();
358 
359  //time stepper
360  const SM_TimeStepper& timeStepper=this->getTimeStepper();
361 
362  //time step
363  const tReal& dt=timeStepper.getTimeStep();
364 
365 
366  //index of time
367  tIndex& timeIndex=this->getTimeIndex();
368 
369  //current time
370  tReal &time=this->getTime();
371  time=dt;
372  time*=timeIndex;
373 
374  //LL Function
375  const SM_LandauLifschitzFunction& llFunction=this->getLandauLifschitzFunction();
376 
377  //stochastic noise
378  const tReal& epsilon=this->getStochasticNoise();
379 
380 
381  //drawn Step
382  tInteger iDrawnStep=0;
383 
384  tIndex& iStep=getStepIndex();
385  iStep=0;
386  while (iStep<steppersNumber) {//loop on time
387 
388  //step to save the stochastic output
389  iDrawnStep++;
390 
391 
392  //compute random J
393  network.updateConnectionValues(epsilon,stochasticFunctions,J,F);
394 
395  //update state of operators
396  updateOperatorsState(timeIndex,network,material,St);
397 
398  //compute H
399  computeMagneticField(timeIndex,network,material,St,Ht);
400 
401  //store stochastic output each drawnStep
402  if (iDrawnStep==nDrawnSteps) {
403  stochasticOutput.store(*this);
404  iDrawnStep=0;
405  }
406 
407  //H:=dt.H
409 
410 
411 
412  //compute the landau lifchitz function Delta S_t=LL(St,dHt)
413  llFunction.computeFunction(nParticles,St,Ht,DeltaSt);
414 
415 
416  //compute S at next time step
417  if (!computeMagneticMomentDirectionsAtNextTimeStep(dt,epsilon,DeltaSt,St)) {
418  //the algorithm diverges
419  //break the loop
420  succeeds=false;
421  break;
422  }
423 
424  //next time step
425  time+=dt;//time at next time step
426  timeIndex++;//next time index
427  iStep++;
428  }
429 
430  //store the stochastix output at time
431 
432  CORE_Profiler::EndCallRoutine(routineName);
433  return succeeds;
434 }
435 
436 
this class describes the exceptions raised for CORE package
Definition: CORE_Exception.h:17
tBoolean isNANContained() const
return true if one value is Not A Number
Definition: CORE_Field.h:782
tIndex getSize() const
return the number values of the container
Definition: CORE_Field.h:161
static void EndCallRoutine(const tString &routineName)
end calling routine
Definition: CORE_Profiler.h:91
static void StartCallRoutine(const tString &routineName)
start calling routine
Definition: CORE_Profiler.h:61
This class describes a landau lifschitz function of the form :
Definition: SM_LandauLifschitzFunction.h:30
void computeFunction(const tIndex &nParticles, const SM_RealField &S, const SM_RealField &B, SM_RealField &F) const
computes the magnetic function
Definition: SM_LandauLifschitzFunction.h:226
const SM_RealField & getMagneticField() const
get the magnetic field for writting
Definition: SM_LandauLifschitzSystem.h:474
const SM_RealField & getMagneticMomentDirectionsVariation() const
get the variation of the direction of the magnetic moments for writting
Definition: SM_LandauLifschitzSystem.h:480
SM_NoiseRateFunctionInterface & getNoiseRateFunction()
get the noise rate function
Definition: SM_LandauLifschitzSystem.h:278
tBoolean stochasticJRun(const tIndex &steppersNumber, SM_StochasticFunctionsInterface &stochasticFunctions, const std::function< void(const tReal &, const tReal &, const tReal &, tReal &)> &F)
compute the steppers number of system for reaching the relaxed state
Definition: SM_LandauLifschitzSystem.cpp:130
virtual void computeVariationMagneticField(const tReal &dt, SM_RealField &H) const =0
computes
tBoolean deterministicRun(const tIndex &steppersNumber, SM_StochasticOutput< StochOutputI > &stochasticOutput)
compute deterministic running of steppers number of the system with computing statistics
Definition: SM_LandauLifschitzSystem.hpp:12
const tIndex & getTimeIndex() const
get the time index
Definition: SM_LandauLifschitzSystem.h:221
virtual tBoolean computeMagneticMomentDirectionsAtNextTimeStep(const tReal &dt, const tReal &epsilon_t, const SM_RealField &deltaSt, SM_RealField &St)=0
compute direction of magnetic moments at next time
const tReal & getTime() const
get the time
Definition: SM_LandauLifschitzSystem.h:214
const tReal & getRelaxationValue() const
get the relaxation value to detect relaxation for reading
Definition: SM_LandauLifschitzSystem.h:332
virtual void computeBrownianVariationMagneticField(SM_MultiStochasticFunctionsInterface &stochFs, const tReal &dt, const tReal &bdt, const tReal &epsilon, const tBoolean &incdWt, tReal *dWt, SM_RealField &H)=0
add stochastic brownian field
const SM_TimeStepper & getTimeStepper() const
get the time stepper
Definition: SM_LandauLifschitzSystem.h:200
const tReal & getNoiseRate() const
get the noise rate
Definition: SM_LandauLifschitzSystem.h:251
tReal computeNetTorque() const
compute Net Torque
Definition: SM_LandauLifschitzSystem.h:347
const SM_LandauLifschitzFunction & getLandauLifschitzFunction() const
get the Landau Lifschitz function return the Landau lifschitz function for reading
Definition: SM_LandauLifschitzSystem.h:423
tBoolean stochasticRun(const tIndex &steppersNumber, SM_MultiStochasticFunctionsInterface &sfs)
compute the steppers number of system without stochastic output
Definition: SM_LandauLifschitzSystem.cpp:3
This class describes a materials defined by state attributes:
Definition: SM_Material.h:61
const tReal & getAdimensionizedExchangeEnergyFactor() const
get the characteristic exchange energy factor
Definition: SM_Material.h:375
This class describes a multi stochastic functions based on same random number generator which impleme...
Definition: SM_MultiStochasticFunctionsInterface.h:18
This class is describes a network composed by.
Definition: SM_Network.h:66
virtual void updateConnectionValues(const tReal &noiseRate, SM_StochasticFunctionsInterface &randomF, const tReal &J, const std::function< void(const tReal &, const tReal &, const tReal &, tReal &)> &F)=0
compute the connection values of the particles in [startInddex,endIndex[
const tInteger & getParticlesNumber() const
return the particles number
Definition: SM_Network.h:349
This class describes a noise rate function.
Definition: SM_NoiseRateFunctionInterface.h:13
virtual tReal computeFunction(const tReal &t) const =0
compute the noise rate function
This class describes a stochastic functions based on same random number generator which implement ran...
Definition: SM_StochasticFunctionsInterface.h:18
const tInteger & getDrawnStepsNumber() const
get the drawn number to compute the stochastic output
Definition: SM_StochasticOutputComponent.h:243
this class implements the virtual methods of its base class SM_StochasticOutputComponent with templat...
Definition: SM_StochasticOutput.h:24
tBoolean store(const SM_System &system)
store the stochastic data during the relation method of the system
Definition: SM_StochasticOutput.h:164
const SM_RealField & getMagneticMomentDirections() const
get the unit direction of spins at time
Definition: SM_System.h:267
void updateOperatorsState(const tIndex &timeIndex, const SM_Network &network, const SM_Material &material, const SM_RealField &S)
update the operators state before computeing magnetic field
Definition: SM_System.h:573
const SM_Network & getNetwork() const
get the network
Definition: SM_System.h:170
const SM_Material & getMaterial() const
get the material of the network
Definition: SM_System.h:193
const tReal & getStochasticNoise() const
get the stochastic noise without dimension
Definition: SM_System.h:385
void computeMagneticField(const tIndex &timeIndex, const SM_Network &network, const SM_Material &material, const SM_RealField &S, SM_RealField &H) const
compute the magnetic field at time step index t by calling the virtual method SM_Operator::computeMag...
Definition: SM_System.h:593
const tIndex & getStepIndex() const
get the step index
Definition: SM_System.h:415
This class is describes a time stepper.
Definition: SM_TimeStepper.h:13
const tReal & getTimeStep() const
return the time step
Definition: SM_TimeStepper.h:108