C++ main module for stochmagnet Package  1.0
SM_LandauLifschitzFunction.h
Go to the documentation of this file.
1 #ifndef SM_LandauLifschitzFunction_H
2 #define SM_LandauLifschitzFunction_H
3 
4 //inherit class header
5 #include "SM_Object.h"
6 
7 //field heaer
8 #include "SM_Field.h"
9 
10 
27 
28  // ATTRIBUTES
29 
30 public:
31 
32 
33 
34 private:
35 
36 
37  //alpha parameter
39 
40  //beta parameter
42 
43  //normalized mu
45 
46 public:
47  // METHODS
48 
49  // CONSTRUCTORS
50 
54  mAlpha=-1;
55  mBeta=2;
56  mIsMuNormalized=false;
57  }
58 
59 
60 
61  // DESTRUCTORS
62 
63 
67  }
68 
69 
70 public:
71 
72 
73  //MEMORY
74 
88  virtual tMemSize getMemorySize() const {
89  return sizeof(*this)+getContentsMemorySize();
90  }
91 
92 
93 
94  // SET methods
95 
99  inline void copy(const SM_LandauLifschitzFunction& LL) {
100  mAlpha=LL.getAlpha();
101  mBeta=LL.getBeta();
103  }
107  inline void setAlpha(const tReal& v) {
108  mAlpha=v;
109  }
113  inline void setBeta(const tReal& v) {
114  mBeta=v;
115  }
116 
120  inline void setIsMuNormalized(const tBoolean& v) {
121  mIsMuNormalized=v;
122  }
123 
124  // GET methods
125  // ============
126 
130  inline const tReal& getAlpha() const {
131  return mAlpha;
132  }
133 
137  inline const tReal& getBeta() const {
138  return mBeta;
139  }
140 
144  inline tBoolean isMuNormalized() const {
145  return mIsMuNormalized;
146  }
147 
148 
149 public:
150  // OTHERS methods
161  inline void computeFunction(const SM_RealField& Mu,const SM_RealField& B,SM_RealField& F) const {
162  const tIndex& N=Mu.getElementsNumber();
163  if (N!=B.getElementsNumber()) {
164  throw SM_Exception("stochMagnet","SM_LandauLifschitzFunction::computeFunction(Mu,B,F)",
165  "incompatible size between Mu & B");
166  }
167 
168  //set the output field dimension
169  F.setElementsNumber(N);
170  computeFunction(N,Mu.getDimension(),&Mu[0],&B[0],&F[0]);
171  }
184  inline void computeFunction(const tIndex& nParticles,const tDimension& dim,
185  const tReal *mu,const tReal *B,tReal *F) const {
186  if (mIsMuNormalized) computeNLLFunction(nParticles,dim,mu, B,F);
187  else computeLLFunction(nParticles,dim,mu, B,F);
188  }
189 
190 private:
203  inline void computeLLFunction(const tIndex& nParticles,const tDimension& dim,
204  const tReal *mu,const tReal *B,tReal *F) const {
205 
206  ASSERT_IN(dim==3);
207 
208  //iterator on point
209  tIndex p;
210 
211  //sMuB=<Mu,B>
212  //sMuMu=<Mu,Mu>
213  tReal sMuB,sMuMu;
214  //iterator on mu
215  const tReal *iMu=mu;
216  //iterator on B
217  const tReal *iB=B;
218  //iterator on F
219  tReal *iF=F;
220 
221  for (p=0;p<nParticles;p++) {//loop on point
222 
223 
224  // A = alpha( mu \wedge B + beta ( <\mu,B> \mu - <\mu,\mu> B ) )
225  const tReal& mu0=(*iMu);iMu++;
226  const tReal& mu1=(*iMu);iMu++;
227  const tReal& mu2=(*iMu);iMu++;
228 
229  const tReal& B0=(*iB);iB++;
230  const tReal& B1=(*iB);iB++;
231  const tReal& B2=(*iB);iB++;
232 
233  sMuB=mu0*B0+mu1*B1+mu2*B2;
234  sMuMu=mu0*mu0+mu1*mu1+mu2*mu2;
235  (*iF)= mAlpha*((mu1 * B2 - mu2 * B1) + mBeta * (mu0 * sMuB - B0 * sMuMu));iF++;
236  (*iF)= mAlpha*((mu2 * B0 - mu0 * B2) + mBeta * (mu1 * sMuB - B1 * sMuMu));iF++;
237  (*iF)= mAlpha*((mu0 * B1 - mu1 * B0) + mBeta * (mu2 * sMuB - B2 * sMuMu));iF++;
238 
239 
240  }
241 
242 
243 
244  }
257  inline void computeNLLFunction(const tIndex& nParticles,const tDimension& dim,
258  const tReal *mu,const tReal *B,tReal *F) const {
259 
260  ASSERT_IN(dim==3);
261 
262  //iterator on point
263  tIndex p;
264 
265  //sMuB=<Mu,B>
266  //sMuMu=<Mu,Mu>
267  tReal sMuB;
268  //iterator on mu
269  const tReal *iMu=mu;
270  //iterator on B
271  const tReal *iB=B;
272  //iterator on F
273  tReal *iF=F;
274 
275  for (p=0;p<nParticles;p++) {//loop on point
276 
277 
278  // A = alpha( mu \wedge B + beta ( <\mu,B> \mu - <\mu,\mu> B ) )
279  const tReal& mu0=(*iMu);iMu++;
280  const tReal& mu1=(*iMu);iMu++;
281  const tReal& mu2=(*iMu);iMu++;
282 
283  const tReal& B0=(*iB);iB++;
284  const tReal& B1=(*iB);iB++;
285  const tReal& B2=(*iB);iB++;
286 
287  sMuB=mu0*B0+mu1*B1+mu2*B2;
288  //sMuMu=mu0*mu0+mu1*mu1+mu2*mu2;
289  //sMuMu=1
290  (*iF)= mAlpha*((mu1 * B2 - mu2 * B1) + mBeta * (mu0 * sMuB - B0 ));iF++;
291  (*iF)= mAlpha*((mu2 * B0 - mu0 * B2) + mBeta * (mu1 * sMuB - B1 ));iF++;
292  (*iF)= mAlpha*((mu0 * B1 - mu1 * B0) + mBeta * (mu2 * sMuB - B2 ));iF++;
293 
294 
295  }
296 
297 
298 
299  }
300 
301 public:
302 
306  virtual tString toString() const override {
307  return (mIsMuNormalized)?
308  "F(M,B)="+std::to_string(mAlpha)+".( M ^ B + "+std::to_string(mBeta)+"<M,B>M - B )\n":
309  "F(M,B)="+std::to_string(mAlpha)+".( M ^ B + "+std::to_string(mBeta)+"<M,B>M - |M|^2 B )\n";
310  }
311 
312 
313 };
314 
315 #endif
tUCInt tDimension
Definition: CORE_StdPtrField.h:567
K getDimension() const
get the dimension of the field
Definition: CORE_Field.h:143
tIndex getElementsNumber() const
return the number values of the container
Definition: CORE_Field.h:118
void setElementsNumber(const tInteger &n)
set the number of element of the container
Definition: CORE_Field.h:112
virtual tMemSize getContentsMemorySize() const
return nthe memory size of the included associations
Definition: CORE_Object.h:259
this class describes the exceptions raised for SM package
Definition: SM_Exception.h:14
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
void setAlpha(const tReal &v)
set the alpha parameter
Definition: SM_LandauLifschitzFunction.h:107
virtual ~SM_LandauLifschitzFunction(void)
destroy
Definition: SM_LandauLifschitzFunction.h:66
tReal mAlpha
Definition: SM_LandauLifschitzFunction.h:38
virtual tString toString() const override
turn the class into a string
Definition: SM_LandauLifschitzFunction.h:306
void copy(const SM_LandauLifschitzFunction &LL)
copy the LL function
Definition: SM_LandauLifschitzFunction.h:99
virtual tMemSize getMemorySize() const
return the memory size of the class and the memory size of all its attributes/associations
Definition: SM_LandauLifschitzFunction.h:88
void setBeta(const tReal &v)
set the beta parameter
Definition: SM_LandauLifschitzFunction.h:113
tReal mBeta
Definition: SM_LandauLifschitzFunction.h:41
SM_LandauLifschitzFunction(void)
create
Definition: SM_LandauLifschitzFunction.h:53
void computeFunction(const tIndex &nParticles, const tDimension &dim, const tReal *mu, const tReal *B, tReal *F) const
compute the magnetic function
Definition: SM_LandauLifschitzFunction.h:184
tBoolean isMuNormalized() const
return true if M is supposed to be normalized
Definition: SM_LandauLifschitzFunction.h:144
void setIsMuNormalized(const tBoolean &v)
set true if M is supposed to be normalized
Definition: SM_LandauLifschitzFunction.h:120
void computeNLLFunction(const tIndex &nParticles, const tDimension &dim, const tReal *mu, const tReal *B, tReal *F) const
compute the normalized magnetic function
Definition: SM_LandauLifschitzFunction.h:257
const tReal & getAlpha() const
get the alpha parameter
Definition: SM_LandauLifschitzFunction.h:130
const tReal & getBeta() const
get the beta parameter
Definition: SM_LandauLifschitzFunction.h:137
tBoolean mIsMuNormalized
Definition: SM_LandauLifschitzFunction.h:44
void computeLLFunction(const tIndex &nParticles, const tDimension &dim, const tReal *mu, const tReal *B, tReal *F) const
compute the magnetic function
Definition: SM_LandauLifschitzFunction.h:203
This class is a base class for Stoch Microm package.
Definition: SM_Object.h:19
#define ASSERT_IN(a)
Definition: functions.h:601
#define tIndex
Definition: types.h:157
#define tString
Definition: types.h:147
#define tMemSize
Definition: types.h:166
#define tBoolean
Definition: types.h:151
#define tReal
Definition: types.h:137