C++ main module for stochmagnet Package  1.0
SM_ZeemanOperator.h
Go to the documentation of this file.
1 #ifndef SM_ZeemanOperator_H
2 #define SM_ZeemanOperator_H
3 
4 #include "SM_TemplatedOperator.h"
5 
6 #include "SM_Field.h"
7 
27 class SM_ZeemanOperator : public SM_TemplatedOperator<SM_ZeemanOperator> {
28 
29  //attributes
30 private :
31 
32 
33 
34  //association
35 
36  //nTimeSteps x nParticles x dim
37  //Bext(t,i,k)=mBext[k+dim*(i+P*t)]
38  //nTimeStep=1 for permanent Bext
39  //nParticles=1 for constant field
40 
44  std::valarray<tReal> mBext;
45 
46 
47 protected:
48  // CONSTRUCTORS
54  mDimension=3;
55  setName("Zeeman");
56  }
57 
58  // DESTRUCTORS
61  virtual ~SM_ZeemanOperator(void) {
62  }
63 
64 public :
65 
66  //Instance building
67  //=================
74  }
75 
79  virtual CORE_UniquePointer<SM_Operator> NewInstance() const override {
80  return New();
81  }
82 
83  //MEMORY
84 
98  virtual tMemSize getMemorySize() const {
99  return sizeof(*this)+getContentsMemorySize();
100  }
109  virtual tMemSize getContentsMemorySize() const {
111  mem+=mBext.size()*sizeof(tReal);
112  return mem;
113  }
114 
115 protected:
119  inline void setZeemanParticlesNumber(const tIndex& p) {
121  }
125  inline void setZeemanTimeStepsNumber(const tIndex& n) {
127  }
128 
129 public:
133  virtual void copy(const SM_Operator& op) {
134  SM_Operator::copy(op);
135  const SM_ZeemanOperator *zop=dynamic_cast<const SM_ZeemanOperator *>(&op);
136  if (zop!=null) {
140  mBext=zop->getBextAsArray();
141  }
142  }
143 
148 
156  inline const tDimension& getZeemanDimension() const {return mDimension;}
157 
161  virtual void discretize(const SM_System& system) override;
162 
167  inline const tReal* getBext(const tIndex& t) const {
169  }
174  inline tReal* getBext(const tIndex& t) {
176  }
180  inline const tReal* getBext() const {
181  return &mBext[0];
182  }
186  inline tReal* getBext() {
187  return &mBext[0];
188  }
189 protected:
193  inline const std::valarray<tReal>& getBextAsArray() const {
194  return mBext;
195  }
199  inline std::valarray<tReal>& getBextAsArray() {
200  return mBext;
201  }
202 public:
206  inline void setBext(std::initializer_list<tReal>&& values) {
207  mBext=values;
208  }
209 
213  inline void setBext(const std::vector<tReal>& values) {
214  mBext.resize(values.size());
215  tReal *Vi=&mBext[0];
216  for_each(values.begin(),values.end(),
217  [&](const auto &v) {
218  (*Vi)=v;
219  Vi++;
220  });
221  }
222 
223 
231  virtual void computeMagneticField(const tIndex& t,
232  const SM_Network& network,
233  const tReal *mu,
234  tReal *B) const override {
235  return computeTemplatedMagneticField(t,network,mu,B);
236  }
244  virtual void computeMagneticFieldAndEnergy(const tIndex& t,
245  const SM_Network& network,
246  const tReal *mu,
247  tReal *B,
248  tReal& E) const override{
249  return computeTemplatedMagneticFieldAndEnergy(t,network,mu,B,E);
250  }
251 
259  inline void computeTemplatedMagneticField(const tIndex& t,
260  const SM_Network& network,
261  const tReal *mu,
262  tReal *B) const {
263  tReal E=0;
264  computeTemplatedMagneticFieldAndEnergy(t,network,mu,B,E);
265 
266  }
276  const SM_Network& network,
277  const tReal *mu,
278  tReal *B,
279  tReal& E) const {
280  //get the number of particles of the network
281  const tIndex& nParticles=network.getParticlesNumber();
282 
283  //get the dimension of the netwok
284  const tDimension& dim=network.getDimension();
285 
286  //iterator on dimension
287  tDimension d;
288 
289 
290 
291  //Bext values at time t=0
292  const tReal *Bext_i,*Bext_id;
293  tBoolean incBext=(mZeemanParticlesNumber>1);
294 
295  //iterator on B
296  tReal *Bi_d=B;
297 
298  //iterator on Mu
299  const tReal *mu_id=mu;
300  //energy of the operator
301  E=0;
302  //Bext at particule i
303  Bext_i=getBext(t);
304 
305  for (tIndex i=0;i<nParticles;i++) {
306 
307  //Bext at coordinate d
308  Bext_id=Bext_i;
309 
310  for (d=0;d<dim;d++) {
311 
312  //zeeman magnetic field contribution to total field
313  (*Bi_d)+=(*Bext_id);
314 
315  //energy of the operator
316  E-=(*Bext_id)*(*mu_id);
317 
318  //next coordinate
319  Bext_id++;//Bext value at next coordinate
320  Bi_d++;//B value at next coordinate
321  mu_id++;//mu value at next coordinate
322  }
323 
324  //Bext at next perticles
325  Bext_i+=incBext;
326 
327  }
328 
329 
330  }
331 
332 
339  virtual tReal computeEnergy(const SM_Network& network,
340  const tReal *mu,
341  const tReal *H) const override {
342  //get the size of the network
343  tIndex i,N=network.getParticlesNumber()*network.getDimension();
344  tReal E=0;
345  const tReal *mu_i=mu;
346  const tReal *H_i=H;
347  for (i=0;i<N;i++) {
348  E-=(*mu_i)*(*H_i);
349  mu_i++;
350  H_i++;
351  }
352  return E;
353  }
354 
361  virtual tReal computeEnergy(const tIndex& t,
362  const SM_Network& network,
363  const tReal *mu) const override{
364  return computeTemplatedEnergy(t,network,mu);
365  }
374  const SM_Network& network,
375  const tReal *mu) const {
376 
377  //get the number of particles of the network
378  const tIndex& nParticles=network.getParticlesNumber();
379 
380  //get the dimension of the netwok
381  const tDimension& dim=network.getDimension();
382 
383  //iterator on dimension
384  tDimension d;
385 
386  //Bext values uniform on all points
387  const tReal *Bext_id,*Bext_i=getBext(t);
388  tBoolean incBext=(mZeemanParticlesNumber>1);
389 
390  //magnetic moment at point i
391  const tReal *Mui_d=mu;
392  //energy E=-\sum_i <Bext,Mu_i>
393  tReal E=0;
394  for (tIndex i=0;i<nParticles;i++) { //loop on particles
395  //external field
396  Bext_id=Bext_i;
397  for (d=0;d<dim;d++) {//loopon dimension
398  E-=(*Bext_id)*(*Mui_d);
399 
400  Bext_id++;
401  Mui_d++;
402  }
403 
404  //BNext at next partiule
405  Bext_i+=incBext;
406  }
407 
408  return E;
409  }//end method
410 
411 };
412 
413 
414 #endif
tUCInt tDimension
Definition: CORE_StdPtrField.h:567
class Free introduced for deleting a smart pointer
Definition: CORE_Object.h:94
This class is describes a a network.
Definition: SM_Network.h:18
tDimension getDimension() const
return the dimension
Definition: SM_Network.h:133
tInteger getParticlesNumber() const
return the particles number
Definition: SM_Network.h:146
This class is describes an operator.
Definition: SM_Operator.h:18
void setName(const tString &name)
set the name
Definition: SM_Operator.h:95
virtual tMemSize getContentsMemorySize() const
return nthe memory size of the included associations
Definition: SM_Operator.h:80
virtual void copy(const SM_Operator &op)
copy
Definition: SM_Operator.h:112
This class is a simulation of one trajectory class for Stoch Microm package.
Definition: SM_System.h:51
This class is describes an implmentation of operator with the class I.
Definition: SM_TemplatedOperator.h:18
This class is describes a Zeeman operator interface.
Definition: SM_ZeemanOperator.h:27
void setZeemanParticlesNumber(const tIndex &p)
set zeeman particlules number
Definition: SM_ZeemanOperator.h:119
virtual void discretize(const SM_System &system) override
discretize the operator : do nothing by default
Definition: SM_ZeemanOperator.cpp:5
tReal * getBext(const tIndex &t)
return Bext at time step index t
Definition: SM_ZeemanOperator.h:174
void setBext(std::initializer_list< tReal > &&values)
set the Bext value
Definition: SM_ZeemanOperator.h:206
tDimension mDimension
Definition: SM_ZeemanOperator.h:43
virtual void computeMagneticFieldAndEnergy(const tIndex &t, const SM_Network &network, const tReal *mu, tReal *B, tReal &E) const override
compute the magnetic field at time t by virtual method
Definition: SM_ZeemanOperator.h:244
static CORE_UniquePointer< SM_ZeemanOperator > New()
build a new instance of the operator
Definition: SM_ZeemanOperator.h:71
const tIndex & getZeemanTimeStepsNumber() const
return the number of time steps for the zeeman operatpr
Definition: SM_ZeemanOperator.h:152
virtual tReal computeEnergy(const SM_Network &network, const tReal *mu, const tReal *H) const override
compute the energy
Definition: SM_ZeemanOperator.h:339
virtual tReal computeEnergy(const tIndex &t, const SM_Network &network, const tReal *mu) const override
compute the energy
Definition: SM_ZeemanOperator.h:361
tIndex mZeemanParticlesNumber
Definition: SM_ZeemanOperator.h:42
const tIndex & getZeemanParticlesNumber() const
return the number of particles for the zeeman operatpr
Definition: SM_ZeemanOperator.h:147
void computeTemplatedMagneticField(const tIndex &t, const SM_Network &network, const tReal *mu, tReal *B) const
compute the magnetic field
Definition: SM_ZeemanOperator.h:259
virtual tMemSize getMemorySize() const
return the memory size of the class and the memory size of all its attributes/associations
Definition: SM_ZeemanOperator.h:98
virtual void copy(const SM_Operator &op)
copy
Definition: SM_ZeemanOperator.h:133
SM_ZeemanOperator(void)
create a zeeman operator interface
Definition: SM_ZeemanOperator.h:51
const std::valarray< tReal > & getBextAsArray() const
return Bext as an array
Definition: SM_ZeemanOperator.h:193
virtual void computeMagneticField(const tIndex &t, const SM_Network &network, const tReal *mu, tReal *B) const override
compute the magnetic field at time t by virtual method
Definition: SM_ZeemanOperator.h:231
void computeTemplatedMagneticFieldAndEnergy(const tIndex &t, const SM_Network &network, const tReal *mu, tReal *B, tReal &E) const
compute the magnetic field
Definition: SM_ZeemanOperator.h:275
const tReal * getBext() const
return Bext at time 0
Definition: SM_ZeemanOperator.h:180
tReal * getBext()
return Bext
Definition: SM_ZeemanOperator.h:186
virtual CORE_UniquePointer< SM_Operator > NewInstance() const override
create a New instance of this @retrun an unique pointer to the instance
Definition: SM_ZeemanOperator.h:79
std::valarray< tReal > mBext
Definition: SM_ZeemanOperator.h:44
std::valarray< tReal > & getBextAsArray()
return Bext as an array
Definition: SM_ZeemanOperator.h:199
const tDimension & getZeemanDimension() const
return the dimension of the zeeman operatpr
Definition: SM_ZeemanOperator.h:156
const tReal * getBext(const tIndex &t) const
return Bext at time step index t
Definition: SM_ZeemanOperator.h:167
virtual tMemSize getContentsMemorySize() const
return nthe memory size of the included associations
Definition: SM_ZeemanOperator.h:109
virtual ~SM_ZeemanOperator(void)
destroy
Definition: SM_ZeemanOperator.h:61
void setZeemanTimeStepsNumber(const tIndex &n)
set zeeman time steps
Definition: SM_ZeemanOperator.h:125
void setBext(const std::vector< tReal > &values)
set the Bext value
Definition: SM_ZeemanOperator.h:213
tReal computeTemplatedEnergy(const tIndex &t, const SM_Network &network, const tReal *mu) const
compute the energy
Definition: SM_ZeemanOperator.h:373
tIndex mZeemanTimeStepsNumber
Definition: SM_ZeemanOperator.h:41
typename std::unique_ptr< T, CORE_Object::Delete > CORE_UniquePointer
Definition: sp.h:8
#define tIndex
Definition: types.h:157
#define tMemSize
Definition: types.h:166
#define tBoolean
Definition: types.h:151
#define tReal
Definition: types.h:137