C++ mpi module for stochmagnet_main Package
SM_ZeemanOperator.h
1 #ifndef SM_ZeemanOperator_H
2 #define SM_ZeemanOperator_H
3 
4 #include "SM_Operator.h"
5 
6 #include "SM_Field.h"
7 
27 
28  //attributes
29 private :
30 
31  //super class type
33 
34  //association
35 
36  //nTimeSteps x nParticles x dim
37  //Hext(t,i,k)=mHext[k+dim*(i+P*t)]
38 
39  //nTimeSteps=1 for permanent Hext
40  //nParticles=1 for constant field
41  tIndex mTimeStepsNumber;
42  tIndex mParticlesNumber;
43 
44  //external field
45  std::valarray<tReal> mHext;
46 
47 
48 protected:
49  // CONSTRUCTORS
53  this->setName("Zeeman");
54  mTimeStepsNumber=1;
55  mParticlesNumber=1;
56  }
57 
58  // DESTRUCTORS
61  virtual ~SM_ZeemanOperator(void) {
62  }
63 
64 public :
65 
66 
67  //MEMORY
68 
82  virtual tMemSize getMemorySize() const {
83  return sizeof(*this)+getContentsMemorySize();
84  }
93  virtual tMemSize getContentsMemorySize() const {
94  tMemSize mem=SuperClass::getContentsMemorySize();
95  mem+=mHext.size()*sizeof(tReal);
96  return mem;
97  }
98  //Instance building
99  //=================
100 
101 
105  inline static CORE_UniquePointer<SM_ZeemanOperator> New() {
106  return CORE_UniquePointer<SM_ZeemanOperator>(new SM_ZeemanOperator(),
108  }
109 
110 
114  virtual CORE_UniquePointer<SM_SliceOperator> NewInstance() const override {
115  return New();
116  }
117 
118 protected:
122  inline void setParticlesNumber(const tIndex& p) {
123  mParticlesNumber=p;
124  }
128  inline void setTimeStepsNumber(const tIndex& n) {
129  mTimeStepsNumber=n;
130  }
131 
132 public:
136  virtual void copy(const SM_SliceOperator& op) {
137  SuperClass::copy(op);
138  const SM_ZeemanOperator *zop=dynamic_cast<const SM_ZeemanOperator*>(&op);
139  if (zop!=null) {
140  mParticlesNumber=zop->getParticlesNumber();
141  mTimeStepsNumber=zop->getTimeStepsNumber();
142  mHext=zop->getHext();
143  }
144  }
145 
149  inline const tIndex& getParticlesNumber() const {return mParticlesNumber;}
150 
154  inline const tIndex& getTimeStepsNumber() const {return mTimeStepsNumber;}
155 
156 
161  inline const tReal* getHextAtTimeIndex(const tIndex& timeIndex) const {
162  return &mHext[(timeIndex%mTimeStepsNumber)*mParticlesNumber*SM_Constants::DIM];
163  }
168  inline tReal* getHextAtTimeIndex(const tIndex& timeIndex) {
169  return &mHext[(timeIndex%mTimeStepsNumber)*mParticlesNumber*SM_Constants::DIM];
170  }
174  inline const tReal* getHextValues() const {
175  return &mHext[0];
176  }
180  inline tReal* getHexValues() {
181  return &mHext[0];
182  }
183 protected:
187  inline const std::valarray<tReal>& getHext() const {
188  return mHext;
189  }
193  inline std::valarray<tReal>& getHext() {
194  return mHext;
195  }
196 public:
200  inline void setHext(std::initializer_list<tReal>&& values) {
201  mHext=values;
202  }
203 
207  inline void setHext(const std::vector<tReal>& values) {
208  mHext.resize(values.size());
209  tReal *Vi=&mHext[0];
210  for_each(values.begin(),values.end(),
211  [&](const auto &v) {
212  (*Vi)=v;
213  Vi++;
214  });
215  }
216 
220  inline void setHext(const std::array<tReal,SM_Constants::DIM>& values) {
221 
222  std::valarray<tReal>& Hext=getHext();
223  Hext.resize(SM_Constants::DIM);
224  memcpy(&Hext[0],values.data(),SM_Constants::DIM*sizeof(tReal));
225  }
226 
230  virtual void adimensionize(const tReal& cH) override {
231  //begin iterator on Hext
232  tReal *iHext=&mHext[0];
233 
234  //end iterator on Hext
235  const tReal *eHext=iHext;
236  eHext+=mHext.size();
237 
238  //dim factor
239  tReal invCH=1.;
240  invCH/=cH;
241 
242 
243  while (iHext!=eHext) {
244  (*iHext)*=invCH;
245  iHext++;
246  }
247  }
252  virtual void discretize(const SM_Network& network, const SM_Material& material) override {
255  }
256 
257 
258  //magnetics fields
259  //================
260 
261 
262 
263 
279  virtual void computeMagneticFieldSlice(const tIndex& timeIndex,
280  const SM_Network& network,
281  const SM_Material& material,
282  const tIndex& startIndex,
283  const tIndex& endIndex,
284  const tReal *S,
285  const tBoolean& alpha,
286  const tIndex& nH,
287  tReal *H) const;
288  //spin energy
289  //===========
290 
299  virtual tReal computeSpinEnergy(const tIndex& i,
300  const tIndex& timeIndex,
301  const SM_Network& network,
302  const SM_Material& material,
303  const SM_RealField& S) const override {
304  //begin iterator on direction of magnetic moment of spin i
305  const tReal *Si=&S[0];Si+=i*SM_Constants::DIM;
306  //end iterator on direction of magnetic moment of spin i
307  const tReal *eSi=Si;eSi+=SM_Constants::DIM;
308  //energi of the spin i
309  tReal Ei;
310  //compute spin energy
311  ComputeSpinEnergy(material.getAtomicSpinMoment()/material.getAdimensionizedDerivativeEnergyFactor(),//Mu_s=\tilde mu_s. Mu_B or only \tilde mu_s
312  &getHextAtTimeIndex(timeIndex)[i*SM_Constants::DIM],//Hext
313  Si,eSi,//S at i
314  Ei);
315  return Ei;
316  }
317 
325  inline static void ComputeSpinEnergy(const tReal& mu_s,
326  const tReal *Hext,
327  const tReal *iS,const tReal *eSi,
328  tReal& E) {
329  ComputeUnscaledSpinEnergy(Hext,iS,eSi,E);
330  E*=mu_s;
331  E*=-1;
332  }
333 
334 protected:
341  inline static void ComputeUnscaledSpinEnergy(const tReal *Hext,
342  const tReal *iS,const tReal *eS,
343  tReal& E) {
344 
345  E=0;
346  while (iS!=eS) {//loop on particles in [start,end[
347 
348  //E= \sum_{i=0}^{i=P-1} < H_{ext}(P_i),S_i>
349  E+=(*Hext)*(*iS);
350 
351  //iterator at next values
352  Hext++;
353  iS++;
354  }//end loop on particles
355  }
356 
357 
358  //total energy
359  //============
360 public:
361 
372  virtual tReal computeEnergySlice(const tIndex& timeIndex,
373  const SM_Network& network,
374  const SM_Material& material,
375  const tIndex& startIndex,
376  const tIndex& endIndex,
377  const tReal *S) const;
378 
379 
380 
381 
382  //string representation
383  //=====================
384 
387  virtual tString toString() const override {
388  tString ret=SuperClass::toString();
389  ret+=" Hext:"+functions_array::toString(getHext())+"\n";
390  return ret;
391  }
392 
393 };
394 
395 
396 #endif
class Free introduced for deleting a smart pointer
Definition: CORE_Object.h:113
static constexpr tDimension DIM
space dimension
Definition: SM_Constants.h:80
This class describes a materials defined by state attributes:
Definition: SM_Material.h:61
const tReal & getAtomicSpinMoment() const
get the atomic spin moment in unit of Bohr magneton
Definition: SM_Material.h:242
const tReal & getAdimensionizedDerivativeEnergyFactor() const
get the characteristic dipolar energy factor
Definition: SM_Material.h:401
This class is describes a network composed by.
Definition: SM_Network.h:66
const tInteger & getParticlesNumber() const
return the particles number
Definition: SM_Network.h:349
This class is describes an operator operating on slice of particles of a network SM_Network.
Definition: SM_SliceOperator.h:32
virtual tString toString() const override
return string representaton of the operator
Definition: SM_SliceOperator.h:227
virtual void copy(const SM_SliceOperator &op)
copy
Definition: SM_SliceOperator.h:129
void setName(const tString &name)
set the name
Definition: SM_SliceOperator.h:112
virtual tMemSize getContentsMemorySize() const
return nthe memory size of the included associations
Definition: SM_SliceOperator.h:97
This class is describes a Zeeman operator interface.
Definition: SM_ZeemanOperator.h:26
static void ComputeUnscaledSpinEnergy(const tReal *Hext, const tReal *iS, const tReal *eS, tReal &E)
compute the unscaled spin energy
Definition: SM_ZeemanOperator.h:341
const std::valarray< tReal > & getHext() const
return Hext as an array
Definition: SM_ZeemanOperator.h:187
tReal * getHexValues()
return Hext
Definition: SM_ZeemanOperator.h:180
static CORE_UniquePointer< SM_ZeemanOperator > New()
build a new instance of the operator
Definition: SM_ZeemanOperator.h:105
virtual void discretize(const SM_Network &network, const SM_Material &material) override
discretize the operator on the network
Definition: SM_ZeemanOperator.h:252
const tIndex & getTimeStepsNumber() const
return the number of time steps for the zeeman operatpr
Definition: SM_ZeemanOperator.h:154
virtual tMemSize getMemorySize() const
return the memory size of the class and the memory size of all its attributes/associations
Definition: SM_ZeemanOperator.h:82
SM_ZeemanOperator(void)
create a zeeman operator interface
Definition: SM_ZeemanOperator.h:52
virtual void adimensionize(const tReal &cH) override
adimensionize the operator
Definition: SM_ZeemanOperator.h:230
const tReal * getHextAtTimeIndex(const tIndex &timeIndex) const
return Hext at time step index t
Definition: SM_ZeemanOperator.h:161
virtual void computeMagneticFieldSlice(const tIndex &timeIndex, const SM_Network &network, const SM_Material &material, const tIndex &startIndex, const tIndex &endIndex, const tReal *S, const tBoolean &alpha, const tIndex &nH, tReal *H) const
compute the anisotropy magnetic field by virtual method
Definition: SM_ZeemanOperator.cpp:5
void setHext(const std::array< tReal, SM_Constants::DIM > &values)
set the Hext value
Definition: SM_ZeemanOperator.h:220
const tReal * getHextValues() const
return Hext at time 0
Definition: SM_ZeemanOperator.h:174
void setParticlesNumber(const tIndex &p)
set zeeman particlules number
Definition: SM_ZeemanOperator.h:122
virtual CORE_UniquePointer< SM_SliceOperator > NewInstance() const override
create a New instance of this
Definition: SM_ZeemanOperator.h:114
virtual tString toString() const override
return the string representation of the class
Definition: SM_ZeemanOperator.h:387
std::valarray< tReal > & getHext()
return Hext as an array
Definition: SM_ZeemanOperator.h:193
const tIndex & getParticlesNumber() const
return the number of particles for the zeeman operatpr
Definition: SM_ZeemanOperator.h:149
virtual tMemSize getContentsMemorySize() const
return nthe memory size of the included associations
Definition: SM_ZeemanOperator.h:93
virtual ~SM_ZeemanOperator(void)
destroy
Definition: SM_ZeemanOperator.h:61
void setHext(std::initializer_list< tReal > &&values)
set the Hext value
Definition: SM_ZeemanOperator.h:200
virtual tReal computeEnergySlice(const tIndex &timeIndex, const SM_Network &network, const SM_Material &material, const tIndex &startIndex, const tIndex &endIndex, const tReal *S) const
compute the energy at time t by virtual method for all particles in [startIndex,endIndex[
Definition: SM_ZeemanOperator.cpp:56
virtual void copy(const SM_SliceOperator &op)
copy
Definition: SM_ZeemanOperator.h:136
void setHext(const std::vector< tReal > &values)
set the Hext value
Definition: SM_ZeemanOperator.h:207
static void ComputeSpinEnergy(const tReal &mu_s, const tReal *Hext, const tReal *iS, const tReal *eSi, tReal &E)
compute spin energy
Definition: SM_ZeemanOperator.h:325
virtual tReal computeSpinEnergy(const tIndex &i, const tIndex &timeIndex, const SM_Network &network, const SM_Material &material, const SM_RealField &S) const override
compute the spin energy by virtual method
Definition: SM_ZeemanOperator.h:299
tReal * getHextAtTimeIndex(const tIndex &timeIndex)
return Hext at time step index t
Definition: SM_ZeemanOperator.h:168
void setTimeStepsNumber(const tIndex &n)
set zeeman time steps
Definition: SM_ZeemanOperator.h:128