C++ mpi module for stochmagnet_main Package
SMOMPI_LandauLifschitzSystem.hpp
1 #ifndef SMOMPI_LandauLifschitzSystem_HPP
2 #define SMOMPI_LandauLifschitzSystem_HPP
3 
4 //MPI header
5 #include "MPI_Run.h"
6 
7 template<class StochFImpl>
9  const tReal& dt,const tReal& bdt,const tReal& epsilon,
10  const tBoolean& incdWt,tReal* dWt,SM_RealField& H) {
11 
12 
13  //number of elements of H
14  tIndex nH=H.getElementsNumber();
15  if (nH==0) return;
16 
17  //MPI environment
18  //const MPI_Environment& mpiEnv=MPI_Run::GetEnvironment();
19 
20  //current id of the MPI core
21  //const tMPICoreId& coreId=mpiEnv.getCoreId();
22 
23  //number of MPI cores
24  //const tMPICoreId& coresNumber=mpiEnv.getCoresNumber();
25 
26  //number of particles of the network
27  tInteger nParticles=getNetwork().getParticlesNumber();
28 
29 
30 
31 
33  dt,bdt,epsilon,
34  incdWt,dWt,&H[0]);
35 
36 }
37 
38 //templated stochastic case without statistics computing
39 //=======================================================
40 template<class StochFImpl, class NoiseFImpl>
42  SM_MultiStochasticFunctions<StochFImpl>& stochasticFunctions,
43  const SM_NoiseRateFunction<NoiseFImpl>& noiseRateFunction) {
44  tString routineName="SM_LandauLifschitzSystem::stochasticRunWithSCStochasticFunctions<StochFI,NoiseI>(const tIndex&,StochFI&,const NoiseI&)";
46  //return value
47  tBoolean succeeds=true;
48 
49  //network of the system
50  const SM_Network& network=this->getNetwork();
51 
52  //material of the system
53  const SM_Material& material=this->getMaterial();
54 
55  //number of particles
56  const tInteger& nParticles=getNetwork().getParticlesNumber();
57 
58  //number of halo particles
59  const tInteger& nHaloParticles=getNetwork().getHaloParticlesNumber();
60 
61  //field array size & iterator on it
62  tIndex s=(nParticles+nHaloParticles)*SM_Constants::DIM;
63 
64  //get direction of magnetic moments
66  if (St.getSize()!=s) {
67  throw CORE_Exception("stochmagnet/landauLifschitz",
68  "SMOMPI_LandauLifschitzSystem::templatedStochasticRun()",
69  "atomic spin directions has bad size : "+std::to_string(St.getSize())+" ("+std::to_string(s)+")" );
70  }
71  //get the variation of the dierction of the magnetic moment
73 
74  //magnetic field
75  SM_RealField &Ht=this->getMagneticField();
76 
77  //time stepper
78  const SM_TimeStepper& timeStepper=this->getTimeStepper();
79 
80  //time step
81  const tReal& dt=timeStepper.getTimeStep();
82 
83  //square root of time step for Brownian perturbation
84  tReal Wdt=sqrt(dt);
85 
86 
87 
88  //index of time
89  tIndex& timeIndex=this->getTimeIndex();
90 
91  //current time
92  tReal &time=this->getTime();
93  time=dt;
94  time*=timeIndex;
95 
96  //LL Function
98 
99 
100  //epsilon depending on time
101  tReal& epsilon_t=this->getNoiseRate();
102 
103 
104 
105 
106  //brownian perturbation variable or field
107  tReal dWt=0;
108  tBoolean incDWt=(!isRealBrownianVariable());
109  tReal *iDWt=&dWt;
110  if (incDWt && (getBrownianField().getElementsNumber()>0) ) {
111  iDWt=&getBrownianField()[0];
112  }
113 
114  tIndex &iStep=getStepIndex();
115  iStep=0;
116  while (iStep<steppersNumber) {//loop on time
117 
118  //std::cout<<"preconditioning step: "<< iStep<<"/"<<steppersNumber<<" \r";
119 
120  //compute epsilon_t by casting of computeFunction method
121  epsilon_t=noiseRateFunction.computeFunction(time);
122 
123  //compute H
124  computeMagneticField(timeIndex,network,material,St,Ht);
125 
126  //H:=dt.H+epsilon_t . w(dt). N(0,1)
127  if (epsilon_t!=0) {
128  //H:=dt.H+epsilon_t . w(dt). N(0,1)
129  computeBrownianVariationMagneticFieldWithSCStochasticFunctions(stochasticFunctions,dt,Wdt,epsilon_t,
130  incDWt,iDWt,Ht);
131  } else {
132  //H:=dt.H
134  }
135 
136  //compute the landau lifchitz function Delta S_t=LL(St,dHt)
137  llFunction.computeFunction(nParticles,St,Ht,DeltaSt);
138 
139  //compute S at next time step
140  if (!computeMagneticMomentDirectionsAtNextTimeStep(dt,epsilon_t,DeltaSt,St)) {
141  //the algorithm diverges
142  //break the loop
143  succeeds=false;
144  break;
145  }
146  //next time step
147  time+=dt;//time at next time step
148  timeIndex++;//next time index
149  iStep++;
150  }
151 
152  //store the stochastix output at time
153 
154 
155 
156  CORE_Profiler::EndCallRoutine(routineName);
157  return succeeds;
158 }
159 
160 
161 //templated stochastic case with statistics computing
162 //=======================================================
163 template<class StochFImpl, class NoiseImpl,class StochOutputImpl>
165  SM_MultiStochasticFunctions<StochFImpl>& stochasticFunctions,
166  const SM_NoiseRateFunction<NoiseImpl>& noiseRateFunction,
167  SM_StochasticOutput<StochOutputImpl>& stochasticOutput) {
168  tString routineName="SM_LandauLifschitzSystem::stochasticRunWithSCStochasticFunctions<StochFI,NoiseI,StochoOutputI>(const tIndex&,StochI&,const NoiseI&,StochOutputI&)";
169  CORE_Profiler::StartCallRoutine(routineName);
170 
171  //number of drawn for stochastic output
172  tInteger nDrawnSteps=stochasticOutput.getDrawnStepsNumber();
173  if (nDrawnSteps==0) nDrawnSteps=steppersNumber+1;
174 
175  //return value
176  tBoolean succeeds=true;
177 
178  //network of the system
179  const SM_Network& network=this->getNetwork();
180 
181  //material of the system
182  const SM_Material& material=this->getMaterial();
183 
184  //number of particles
185  const tIndex& nParticles=network.getParticlesNumber();
186 
187  //number of halo particles
188  const tIndex& nHaloParticles=network.getHaloParticlesNumber();
189 
190  //field array size & iterator on it
191  tIndex s=(nParticles+nHaloParticles)*SM_Constants::DIM;
192 
193  //get direction of magnetic moments
195  if (St.getSize()!=s) {
196  throw CORE_Exception("stochmagnet/landauLifschitz",
197  "SM_LandauLifschitzSystem::templatedStochasticRun()",
198  "atomic spin directions has bad size : "+std::to_string(St.getSize())+" ("+std::to_string(s)+")");
199  }
200  //get the variation of the dierction of the magnetic moment
202 
203  //magnetic field
204  SM_RealField &Ht=this->getMagneticField();
205 
206 
207  //time stepper
208  const SM_TimeStepper& timeStepper=this->getTimeStepper();
209 
210  //time step
211  const tReal& dt=timeStepper.getTimeStep();
212 
213  //square root of time step for Brownian perturbation
214  tReal Wdt=sqrt(dt);
215 
216 
217 
218  //index of time
219  tIndex& timeIndex=this->getTimeIndex();
220 
221  //current time
222  tReal &time=this->getTime();
223  time=dt;
224  time*=timeIndex;
225 
226  //LL Function
227  const SM_LandauLifschitzFunction& llFunction=this->getLandauLifschitzFunction();
228 
229 
230  //epsilon depending on time
231  tReal& epsilon_t=this->getNoiseRate();
232 
233 
234  //drawn Step
235  tInteger iDrawnStep=0;
236 
237 
238  //brownian perturbation variable or field
239  tReal dWt=0;
240  tBoolean incDWt=(!isRealBrownianVariable());
241  tReal *iDWt=&dWt;
242  if (incDWt && (getBrownianField().getElementsNumber()>0)) iDWt=&getBrownianField()[0];
243 
244 
245  tIndex& iStep=getStepIndex();
246  iStep=0;
247  while (iStep<steppersNumber) {//loop on time
248 
249  //std::cout<<"statistic step: "<< iStep<<"/"<<steppersNumber<<" \r";
250  //step to save the stochastic output
251  iDrawnStep++;
252 
253 
254  //compute epsilon_t by casting of computeFunction method
255  epsilon_t=noiseRateFunction.computeSCFunction(time);
256 
257  //compute H
258  computeMagneticField(timeIndex,network,material,St,Ht);
259 
260  //store stochastic output each drawnStep
261  if (iDrawnStep==nDrawnSteps) {
262  stochasticOutput.store(*this);
263  iDrawnStep=0;
264  }
265 
266  //H:=dt.H+epsilon_t . w(dt). N(0,1)
267  if (epsilon_t!=0) {
268  //H:=dt.H+epsilon_t . w(dt). N(0,1)
269  computeBrownianVariationMagneticFieldWithSCStochasticFunctions(stochasticFunctions,dt,Wdt,epsilon_t,
270  incDWt,iDWt,Ht);
271  } else {
272  //H:=dt.H
274  }
275 
276  //compute the landau lifchitz function Delta S_t=LL(St,dHt)
277  llFunction.computeFunction(nParticles,St,Ht,DeltaSt);
278 
279  //compute S at next time step
280  if (!computeMagneticMomentDirectionsAtNextTimeStep(dt,epsilon_t,DeltaSt,St)) {
281  //the algorithm diverges
282  //break the loop
283  succeeds=false;
284  break;
285  }
286 
287  //next time step
288  time+=dt;//time at next time step
289  timeIndex++;//next time index
290  iStep++;
291  }
292 
293  //store the stochastix output at time
294 
295 
296  //built-in profiler
297  CORE_Profiler::EndCallRoutine(routineName);
298 
299  return succeeds;
300 }
301 
302 #endif
this class describes the exceptions raised for CORE package
Definition: CORE_Exception.h:17
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
virtual void computeVariationMagneticField(const tReal &dt, SM_RealField &H) const final
computes
Definition: SMOMPI_LandauLifschitzSystem.cpp:124
void computeBrownianVariationMagneticFieldWithSCStochasticFunctions(SM_MultiStochasticFunctions< StochFImpl > &stochFs, const tReal &dt, const tReal &bdt, const tReal &epsilon, const tBoolean &incdWt, tReal *dWt, SM_RealField &H)
add stochastic brownian field
Definition: SMOMPI_LandauLifschitzSystem.hpp:8
tBoolean stochasticRunWithSCStochasticFunctions(const tIndex &steppersNumber, SM_MultiStochasticFunctions< StochFImplement > &stochasticFunctions, const SM_NoiseRateFunction< NoiseFImplement > &noiseRateFunction)
compute the relaxation process by calling only virtual methods
static constexpr tDimension DIM
space dimension
Definition: SM_Constants.h:80
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
const tBoolean & isRealBrownianVariable() const
get if the brownian variable is a field or a real
Definition: SM_LandauLifschitzSystem.h:399
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 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
void computeBrownianVariationMagneticFieldSliceWithSCStochasticFunctions(SM_StochasticFunctions< StochFImpl > &randF, tIndex start, tIndex end, const tReal &dt, const tReal &bdt, const tReal &epsilon, const tBoolean &incdWt, tReal *dWt, tReal *H)
add stochastic brownian field for particle indices in [start,end[
Definition: SM_LandauLifschitzSystem.h:692
const SM_LandauLifschitzFunction & getLandauLifschitzFunction() const
get the Landau Lifschitz function return the Landau lifschitz function for reading
Definition: SM_LandauLifschitzSystem.h:423
const SM_RealField & getBrownianField() const
get the generated brownian variable for reading
Definition: SM_LandauLifschitzSystem.h:406
This class describes a materials defined by state attributes:
Definition: SM_Material.h:61
This class describes a multi stochastic functions based on same random number generator which impleme...
Definition: SM_MultiStochasticFunctions.h:26
This class is describes a network composed by.
Definition: SM_Network.h:66
const tInteger & getHaloParticlesNumber() const
return the halo particles number
Definition: SM_Network.h:355
const tInteger & getParticlesNumber() const
return the particles number
Definition: SM_Network.h:349
This class describes a templated noise rate function as static polymorphism.
Definition: SM_NoiseRateFunction.h:14
virtual tReal computeFunction(const tReal &t) const final
compute the noise rate function
Definition: SM_NoiseRateFunction.h:99
tReal computeSCFunction(const tReal &t) const
compute the noise rate function by static polymorphism
Definition: SM_NoiseRateFunction.h:91
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
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
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