C++ mpi module for stochmagnet_main Package
SM_LandauLifschitzFunction.h
1 #ifndef SM_LandauLifschitzFunction_H
2 #define SM_LandauLifschitzFunction_H
3 
4 //inherit class header
5 #include "SM_Object.h"
6 
7 //constants value
8 #include "SM_Constants.h"
9 //field heaer
10 #include "SM_Field.h"
11 
31 
32  // ATTRIBUTES
33 
34 public:
35 
36 
37 
38 private:
39 
40  using LambdaF = std::function<void(const tReal&,const tReal& ,tReal&)>;
41  LambdaF mAlphaF;
42 
43  //gamma function
44  tReal mGamma;
45 
46 
47  //lambda parameter
48  tReal mLambda;
49 
50  //alpha parameter \f$ \alpha=\alpha(\gamma,\lambda)=-\frac{\gamma]{1+\lambda^2} \f$
51  tReal mAlpha;
52 
53 
54  //normalized mu
55  tBoolean mIsSNormalized;
56 
57 protected:
58  // METHODS
59 
60  // CONSTRUCTORS
61 
65 
66  mGamma=SM_Constants::GAMMA;
67  mLambda=0.1;
68 
69  mIsSNormalized=false;
70  mAlphaF=([](const tReal& gamma,const tReal& lambda,tReal& alpha) {
71  //alpha=lambda^2
72  alpha=lambda;
73  alpha*=alpha;
74  alpha+=1;
75  //alpha=gamma/(1+lambda^2)
76  alpha=gamma/alpha;
77  //alpha=-gamma/(1+lambda^2)
78  alpha*=-1;
79  });
80  //compute alpha
81  mAlphaF(mGamma,mLambda,mAlpha);
82 
83  }
84 
85 
86  // DESTRUCTORS
87 
88 
92  }
93 
94 
95 public:
96 
97 
98  //MEMORY
99 
113  virtual tMemSize getMemorySize() const {
114  return sizeof(*this)+getContentsMemorySize();
115  }
116 
117 
118 
119  // SET methods
120 
124  inline void copy(const SM_LandauLifschitzFunction& LL) {
125  mGamma=LL.getGamma();
126  mLambda=LL.getLambda();
127  mAlphaF(mGamma,mLambda,mAlpha);
128  mIsSNormalized=LL.isSNormalized();
129  }
130 
131 
132 
147  inline void setAlphaFunction(const LambdaF& L) {
148  mAlphaF=L;
149  }
153  inline void setGamma(const tReal& gamma) {
154  mGamma=gamma;
155  mAlphaF(mGamma,mLambda,mAlpha);
156  }
160  inline void setLambda(const tReal& v) {
161  mLambda=v;
162  mAlphaF(mGamma,mLambda,mAlpha);
163  }
164 
168  inline void setAlpha(const tReal& v) {
169  mAlpha=v;
170  }
171 public:
172 
173 
177  inline void setIsSNormalized(const tBoolean& v) {
178  mIsSNormalized=v;
179  }
180 
181  // GET methods
182  // ============
183 
187  inline const tReal& getGamma() const {
188  return mGamma;
189  }
190 
194  inline const tReal& getAlpha() const {
195  return mAlpha;
196  }
197 
201  inline const tReal& getLambda() const {
202  return mLambda;
203  }
204 
208  inline tBoolean isSNormalized() const {
209  return mIsSNormalized;
210  }
211 
212 
213 public:
214  // OTHERS methods
226  inline void computeFunction(const tIndex& nParticles,const SM_RealField& S,const SM_RealField& B,SM_RealField& F) const {
227 
228  tIndex nB=B.getElementsNumber();
229  if (nB>0) {
230  //set the output field dimension F=LL(S,B) size of F = size of B
231  if (F.getElementsNumber()!=B.getElementsNumber()) F.setElementsNumber(nB);
232 
233  computeFunction(nParticles,&S[0],B.getElementsNumber(),&B[0],&F[0]);
234  }
235  }
246  inline void computeFunction(const tIndex& nSParticles,const tReal *S,
247  const tIndex& nBParticles,const tReal *B,
248  tReal *F) const {
249  if (mIsSNormalized) computeNLLFunction(nSParticles,S,nBParticles,B,F);
250  else computeLLFunction(nSParticles,S,nBParticles,B,F);
251  }
252 
253 protected:
254 
265  virtual void computeLLFunction(const tIndex& nSParticles,const tReal *S,
266  const tIndex& nBParticles,const tReal *B,tReal *F) const=0;
267 
280  virtual void computeNLLFunction(const tIndex& nSParticles,const tReal *S,
281  const tIndex& nBParticles,const tReal *B,tReal *F) const=0;
282 
283 
284 
299  inline void computeSliceLLFunction(tIndex start,tIndex end,
300  const tIndex& nSParticles,const tReal *S,
301  const tIndex& nBParticles,const tReal *B,tReal *F) const {
302 
303  //particle index -> memory index
304  start*=SM_Constants::DIM;
305  end*=SM_Constants::DIM;
306 
307  //sSB=<S,B>
308  //sSS=<S,S>
309  tReal sSB,sSS;
310  //begin iterator on mu
311  const tReal *iS=S;iS+=start;
312  //end iterator on mu
313  const tReal *eS=S;eS+=end;
314 
315  //begin iterator on B
316  const tReal *iB=B;
317  if (nBParticles==nSParticles) iB+=start;
318 
319  //iterator on F
320  tReal *iF=F;
321  if (nBParticles==nSParticles) iF+=start;
322 
323  tReal S0,S1,S2,B0,B1,B2;
324  while (iS!=eS) {//loop on point
325 
326 
327  // A = alpha( S \wedge B + lambda ( <\S,B> \S - <\S,\S> B ) )
328  S0=(*iS);iS++;
329  S1=(*iS);iS++;
330  S2=(*iS);iS++;
331 
332  B0=(*iB);iB++;
333  B1=(*iB);iB++;
334  B2=(*iB);iB++;
335 
336  sSB=S0*B0+S1*B1+S2*B2;
337  sSS=S0*S0+S1*S1+S2*S2;
338  (*iF)= mAlpha*((S1 * B2 - S2 * B1) + mLambda * (S0 * sSB - B0 * sSS));iF++;
339  (*iF)= mAlpha*((S2 * B0 - S0 * B2) + mLambda * (S1 * sSB - B1 * sSS));iF++;
340  (*iF)= mAlpha*((S0 * B1 - S1 * B0) + mLambda * (S2 * sSB - B2 * sSS));iF++;
341 
342 #ifdef DEBUG
343  if (std::isnan(iF[-1]) || std::isnan(iF[-2]) || std::isnan(iF[-3])) {
344  throw CORE_Exception("stochmagnet/landauLifschitz",
345  "SM_LandauLifschitzFunction::computeSliceLLFunction("+std::to_string(start)+","+std::to_string(end)+",..)",
346  "nan detected : S=("+std::to_string(S0)+","+std::to_string(S1)+","+std::to_string(S2)+") B=("+std::to_string(B0)+","+std::to_string(B1)+","+std::to_string(B2)+") F=("+std::to_string(iF[-3])+","+std::to_string(iF[-2])+","+std::to_string(iF[-3])+")");
347  }
348 #endif
349 
350  }//end loop on values
351  }
352 
366  inline void computeSliceNLLFunction(tIndex start,tIndex end,
367  const tIndex& nSParticles,const tReal *S,
368  const tIndex& nBParticles,const tReal *B,tReal *F) const {
369 
370  //particle index -> memory index
371  start*=SM_Constants::DIM;
372  end*=SM_Constants::DIM;
373 
374 
375  //sSB=<S,B>
376  //sSS=<S,S>
377  tReal sSB;
378  //begin iterator on S
379  const tReal *iS=S;iS+=start;
380  //end iterator on S
381  const tReal *eS=S;eS+=end;
382  //begin iterator on B
383  const tReal *iB=B;
384  if (nBParticles==nSParticles) iB+=start;
385 
386  //iterator on F
387  tReal *iF=F;
388  if (nBParticles==nSParticles) iF+=start;
389 
390  tReal S0,S1,S2,B0,B1,B2;
391 
392  while (iS!=eS) {//loop on point
393 
394  // A = alpha( S \wedge B + lambda ( <\S,B> \S - <\S,\S> B ) )
395  S0=(*iS);iS++;
396  S1=(*iS);iS++;
397  S2=(*iS);iS++;
398 
399  B0=(*iB);iB++;
400  B1=(*iB);iB++;
401  B2=(*iB);iB++;
402 
403  sSB=S0*B0+S1*B1+S2*B2;
404  //sSS=S0*S0+S1*S1+S2*S2;
405  //sSS=1
406  (*iF)= mAlpha*((S1 * B2 - S2 * B1) + mLambda * (S0 * sSB - B0 ));iF++;
407  (*iF)= mAlpha*((S2 * B0 - S0 * B2) + mLambda * (S1 * sSB - B1 ));iF++;
408  (*iF)= mAlpha*((S0 * B1 - S1 * B0) + mLambda * (S2 * sSB - B2 ));iF++;
409 
410 #ifdef DEBUG
411  if (std::isnan(iF[-1]) || std::isnan(iF[-2]) || std::isnan(iF[-3])) {
412  throw CORE_Exception("stochmagnet/landauLifschitz",
413  "SM_LandauLifschitzFunction::computeSliceNLLFunction("+std::to_string(start)+","+std::to_string(end)+",..)",
414  "nan detected : S=("+std::to_string(S0)+","+std::to_string(S1)+","+std::to_string(S2)+") B=("+std::to_string(B0)+","+std::to_string(B1)+","+std::to_string(B2)+") F=("+std::to_string(iF[-3])+","+std::to_string(iF[-2])+","+std::to_string(iF[-3])+")");
415  }
416 #endif
417 
418  }//end loop on particle
419 
420  }
421 
422 
423 public:
424 
428  virtual tString toString() const override {
429  std::stringstream ret;
430  ret<<"LL gamma:"<<mGamma<<"\n";
431  ret<<"LL alpha:"<<mAlpha<<"\n";
432  ret<<"LL lambda:"<<mLambda<<"\n";
433  ret<<((mIsSNormalized)?
434  "LL(S,H)=alpha.( S ^ H + lambda.(<S,H>S - H )\n":
435  "LL(S,H)=alpha.( S ^ H + lambda.(<S,H>S - |S|^2 H )\n");
436  return ret.str();
437  }
438 
439 
440 };
441 
442 #endif
this class describes the exceptions raised for CORE package
Definition: CORE_Exception.h:17
tIndex getElementsNumber() const
return the number values of the container
Definition: CORE_Field.h:135
void setElementsNumber(const tInteger &n)
set the number of element of the container
Definition: CORE_Field.h:121
virtual tMemSize getContentsMemorySize() const
return nthe memory size of the included associations
Definition: CORE_Object.h:278
static constexpr tDimension DIM
space dimension
Definition: SM_Constants.h:80
static constexpr tReal GAMMA
gyroscopic precession :
Definition: SM_Constants.h:36
This class describes a landau lifschitz function of the form :
Definition: SM_LandauLifschitzFunction.h:30
void setAlpha(const tReal &v)
set the alpha parameter directly without setting setGamma()
Definition: SM_LandauLifschitzFunction.h:168
virtual ~SM_LandauLifschitzFunction(void)
destroy
Definition: SM_LandauLifschitzFunction.h:91
void computeSliceLLFunction(tIndex start, tIndex end, const tIndex &nSParticles, const tReal *S, const tIndex &nBParticles, const tReal *B, tReal *F) const
compute the magnetic function for particle indices in [start,end[
Definition: SM_LandauLifschitzFunction.h:299
virtual void computeLLFunction(const tIndex &nSParticles, const tReal *S, const tIndex &nBParticles, const tReal *B, tReal *F) const =0
compute the magnetic function
virtual tString toString() const override
turn the class into a string
Definition: SM_LandauLifschitzFunction.h:428
void copy(const SM_LandauLifschitzFunction &LL)
copy the LL function
Definition: SM_LandauLifschitzFunction.h:124
tBoolean isSNormalized() const
return true if M is supposed to be normalized
Definition: SM_LandauLifschitzFunction.h:208
void setAlphaFunction(const LambdaF &L)
set the alpha function
Definition: SM_LandauLifschitzFunction.h:147
virtual tMemSize getMemorySize() const
return the memory size of the class and the memory size of all its attributes/associations
Definition: SM_LandauLifschitzFunction.h:113
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
void computeSliceNLLFunction(tIndex start, tIndex end, const tIndex &nSParticles, const tReal *S, const tIndex &nBParticles, const tReal *B, tReal *F) const
compute the normalized magnetic function for particle indices in [start,end[
Definition: SM_LandauLifschitzFunction.h:366
void setLambda(const tReal &v)
set the lambda parameter
Definition: SM_LandauLifschitzFunction.h:160
void computeFunction(const tIndex &nSParticles, const tReal *S, const tIndex &nBParticles, const tReal *B, tReal *F) const
compute the magnetic function
Definition: SM_LandauLifschitzFunction.h:246
SM_LandauLifschitzFunction(void)
create
Definition: SM_LandauLifschitzFunction.h:64
void setGamma(const tReal &gamma)
set the alpha parameter
Definition: SM_LandauLifschitzFunction.h:153
const tReal & getLambda() const
get the lambda parameter
Definition: SM_LandauLifschitzFunction.h:201
const tReal & getGamma() const
get the gamma parameter
Definition: SM_LandauLifschitzFunction.h:187
const tReal & getAlpha() const
get the alpha parameter
Definition: SM_LandauLifschitzFunction.h:194
void setIsSNormalized(const tBoolean &v)
set true if M is supposed to be normalized
Definition: SM_LandauLifschitzFunction.h:177
virtual void computeNLLFunction(const tIndex &nSParticles, const tReal *S, const tIndex &nBParticles, const tReal *B, tReal *F) const =0
compute the normalized magnetic function
This class is a base class for Stoch Microm package.
Definition: SM_Object.h:36