C++ main module for stochmagnet Package  1.0
SM_System.h
Go to the documentation of this file.
1 #ifndef SM_System_H
2 #define SM_System_H
3 
4 //base class
5 #include "SM_Object.h"
6 
7 //landau lifschtz function
9 
10 //stochastic function
11 #include "SM_StochasticFunction.h"
12 
13 //network
14 #include "SM_Network.h"
15 
16 //time
17 #include "SM_TimeStepper.h"
18 
19 //operator
20 #include "SM_Operator.h"
21 //noise header
22 #include "SM_NoiseRateFunction.h"
25 
26 //array manipulating
27 #include <valarray>
28 
51 class SM_System : public SM_Object {
52 
53  //attributes
54 private :
55 
56 
57  //associations
58 
59 
60  //the landau lishitz function
62 
63  //network
65 
66  //time stepper
68 
69  //operators
70  std::map<tString,CORE_UniquePointer<SM_Operator>> mOperators;
71 
72 
73  //total magnetic field of the system
75 
76  //initial mu of size mParticlesNumber x mDimension
78 
79  //the noise rate function
81 
82 
83 
84 
85 
86 protected:
87  // CONSTRUCTORS
90  SM_System(void) {
91 
92 
93 
94  tReal alpha=-1;
95  tReal beta=2;
96 
97  mLLFunction.setAlpha(alpha);
98  mLLFunction.setBeta(beta);
99 
100  mMu0={0,1,0};
101  }
102 
103  // DESTRUCTORS
106  virtual ~SM_System(void) {
107  }
108 
109 
110 public :
111 
112 
113  //MEMORY
114 
128  virtual tMemSize getMemorySize() const {
129  return sizeof(*this)+getContentsMemorySize();
130  }
131 
140  virtual tMemSize getContentsMemorySize() const {
145  mem+=mB.getContentsMemorySize();
147  mem+=(mNoiseRateFunction.get()==null)?0:mNoiseRateFunction->getMemorySize();
148  std::for_each(mOperators.cbegin(),mOperators.cend(),
149  [&](const auto& op) {
150  mem+=op.first.size();
151  mem+=op.second->getMemorySize();
152  });
153  return mem;
154  }
155 
156  //SET & GET methods
157 
158 
159  //Network data
160  //=============
161 public:
165  inline const SM_Network& getNetwork() const {
166  return mNetwork;
167  }
171  inline SM_Network& getNetwork() {
172  return mNetwork;
173  }
174 
175  //time stepper data
176  //=================
180  inline const SM_TimeStepper& getTimeStepper() const {
181  return mTimeStepper;
182  }
187  return mTimeStepper;
188  }
189 
190  //magnetic moment data
191  //====================
192 
193 public:
194 
198  inline void setInitialMagneticMoment(const std::valarray<tReal>& mu0) {
199  mMu0=mu0;
200  mMu0.normalize();
201  }
202 
206  inline void setInitialMagneticMoment(const SM_RealField& mu0) {
207  mMu0=mu0;
208  mMu0.normalize();
209  }
210 
215  inline void setInitialMagneticMoment(const tIndex& N,const std::array<tReal,3>& mu0) {
217  mMu0.initialize(mu0);
218  }
219 
220 
224  inline const SM_RealField& getInitialMagneticMoment() const {
225  return mMu0;
226  }
227 
228 
229 
230 
231  //stochastic function
232  //===================
233 
238  mNoiseRateFunction=std::move(f);
239  }
240 
241 
246  return *mNoiseRateFunction.get();
247  }
252  return *mNoiseRateFunction.get();
253  }
254 
255 
256  //Landau lifschtz function
257  //========================
258 
263  return mLLFunction;
264 
265  }
270  return mLLFunction;
271 
272  }
273 
274  //operators
275  //==========
276 
281  if (op.get()!=null) mOperators[op->getName()]=std::move(op);
282  }
283 
287  inline const SM_Operator* getOperator(const tString& name) const {
288  auto op=mOperators.find(name);
289  if (op!=mOperators.end()) {
290  return op->second.get();
291  }
292  return null;
293  }
294 
298  inline void copyOperators(const SM_System& system) {
299  const std::map<tString,CORE_UniquePointer<SM_Operator>>& operators=system.getOperators();
301  for_each(operators.begin(),operators.end(),
302  [&](const auto& op) {
303  cop=op.second->NewInstance();
304  cop->copy(*op.second.get());
305  mOperators[op.first]=std::move(cop);
306  });
307  }
311  const std::map<tString,CORE_UniquePointer<SM_Operator>>& getOperators() const {
312  return mOperators;
313  }
317  inline tIndex getOperatorsNumber() const {
318  return mOperators.size();
319  }
323  virtual void getOperatorNames(std::vector<tString>& names) const {
324  names.clear();
325  for(const auto& op : mOperators) {
326  names.push_back(op.first);
327  }
328 
329  }
330 
331 
332 
333  public:
334 
335 
336 
337 
338  public:
339 
340  //simulation methods
341  //===================
342  protected:
346  return mB;
347  }
348 
349  public:
354  virtual void discretize() {
355 
356  //get the network data
357  const SM_Network& network=getNetwork();
358 
359  //discretize magnetic field
361 
362  //discretize the operators on the network
363  for(auto& op : mOperators) {
364  op.second->discretize(*this);
365  }
366 
367  }
368 
369 
377  tBoolean makeRelaxation(const SM_StochasticFunction* randomFunction,tReal *mu,tReal *Es);
378 
379 
380  protected:
387  inline void computeMagneticField(const tIndex& t,
388  const SM_Network& network,
389  const tReal *mu,
390  tReal *B) const {
391 
392  tIndex N=network.getParticlesNumber()*network.getDimension();
393 
394  // B=0
395  memset(B,0,sizeof(tReal)*N);
396 
397  //B+=Bop
398  for(const auto& op : mOperators) {
399  op.second->computeMagneticField(t,network,mu,B);
400  }
401  }
410  const SM_Network& network,
411  const tReal *mu,
412  tReal *B,
413  tReal *Es) const {
414 
415  tIndex N=network.getParticlesNumber()*network.getDimension();
416 
417  // B=0
418  memset(B,0,sizeof(tReal)*N);
419 
420  //B+=Bop
421  tReal &Et=(*Es);Es++;//total energy
422  Et=0;//initialize total energy
423  tReal *Es_p=Es;//energy of the operator op
424  for(const auto& op : mOperators) {
425  op.second->computeMagneticFieldAndEnergy(t,network,mu,B,*Es_p);
426  Et+=(*Es_p);//operator's energy contribution
427  Es_p++;//energy of next operator
428  }
429  }
442  virtual tBoolean computeMuAtNextTimeStep(const tReal& dt,const tReal& epsilon_t,
443  const tIndex& nParticles,const tDimension& dim,
444  const tReal* mu_t,
445  tReal *mu_tpdt) const=0;
446 
447  public:
451  virtual tString toString() const override;
452  };
453 #endif
tUCInt tDimension
Definition: CORE_StdPtrField.h:567
virtual tMemSize getContentsMemorySize() const override
return the memory size of the included associations
Definition: CORE_Field.h:93
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
void normalize()
normalize all the elements of the field return false if the method is not compatible with the floatin...
Definition: CORE_StdPtrField.h:403
void initialize(const Q &v)
initailize all the values with v
Definition: CORE_StdPtrField.h:178
This class describes a landau lifschitz function of the form :
Definition: SM_LandauLifschitzFunction.h:26
void setAlpha(const tReal &v)
set the alpha parameter
Definition: SM_LandauLifschitzFunction.h:107
void setBeta(const tReal &v)
set the beta parameter
Definition: SM_LandauLifschitzFunction.h:113
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
virtual tMemSize getContentsMemorySize() const
return the memory size of the included associations
Definition: SM_Network.h:106
This class describes a noise rate function.
Definition: SM_NoiseRateFunction.h:13
This class is a base class for Stoch Microm package.
Definition: SM_Object.h:19
This class is describes an operator.
Definition: SM_Operator.h:18
This class describes a stochastic function interface to generate random numbers.
Definition: SM_StochasticFunction.h:15
This class is a simulation of one trajectory class for Stoch Microm package.
Definition: SM_System.h:51
tIndex getOperatorsNumber() const
get the operator with name
Definition: SM_System.h:317
SM_TimeStepper mTimeStepper
Definition: SM_System.h:67
virtual void discretize()
discretize the system
Definition: SM_System.h:354
SM_LandauLifschitzFunction mLLFunction
Definition: SM_System.h:61
tBoolean makeRelaxation(const SM_StochasticFunction *randomFunction, tReal *mu, tReal *Es)
compute the relaxation process by calling only virtual methods
Definition: SM_System.cpp:3
SM_System(void)
create a class
Definition: SM_System.h:90
SM_Network & getNetwork()
get the network
Definition: SM_System.h:171
const std::map< tString, CORE_UniquePointer< SM_Operator > > & getOperators() const
get the operators
Definition: SM_System.h:311
CORE_UniquePointer< SM_NoiseRateFunction > mNoiseRateFunction
Definition: SM_System.h:80
const SM_LandauLifschitzFunction & getLandauLifschitzFunction() const
get the Landau Lifschitz function return the Landau lifschitz function for reading
Definition: SM_System.h:262
const SM_NoiseRateFunction & getNoiseRateFunction() const
get the noise rate function
Definition: SM_System.h:251
SM_RealField & getMagneticField()
get the magnetic field
Definition: SM_System.h:345
void setInitialMagneticMoment(const std::valarray< tReal > &mu0)
set the initial Magnetic Moment by moving
Definition: SM_System.h:198
const SM_RealField & getInitialMagneticMoment() const
set the initial Magnetic Moment
Definition: SM_System.h:224
SM_RealField mB
Definition: SM_System.h:74
void copyOperators(const SM_System &system)
copy the operator
Definition: SM_System.h:298
void setInitialMagneticMoment(const tIndex &N, const std::array< tReal, 3 > &mu0)
set the initial Magnetic Moment by copy
Definition: SM_System.h:215
std::map< tString, CORE_UniquePointer< SM_Operator > > mOperators
Definition: SM_System.h:70
SM_NoiseRateFunction & getNoiseRateFunction()
get the noise rate function
Definition: SM_System.h:245
void addOperator(CORE_UniquePointer< SM_Operator > op)
add operator
Definition: SM_System.h:280
SM_TimeStepper & getTimeStepper()
get the time stepper
Definition: SM_System.h:186
SM_Network mNetwork
Definition: SM_System.h:64
void setNoiseRateFunction(CORE_UniquePointer< SM_NoiseRateFunction > &f)
gst the noise rate function
Definition: SM_System.h:237
const SM_Network & getNetwork() const
get the network
Definition: SM_System.h:165
virtual tMemSize getContentsMemorySize() const
return the memory size of the included associations
Definition: SM_System.h:140
void setInitialMagneticMoment(const SM_RealField &mu0)
set the initial Magnetic Moment by moving
Definition: SM_System.h:206
virtual void getOperatorNames(std::vector< tString > &names) const
get the operator names
Definition: SM_System.h:323
virtual tString toString() const override
turn the class into a string representation
Definition: SM_System.cpp:126
const SM_Operator * getOperator(const tString &name) const
get the operator with name
Definition: SM_System.h:287
virtual tBoolean computeMuAtNextTimeStep(const tReal &dt, const tReal &epsilon_t, const tIndex &nParticles, const tDimension &dim, const tReal *mu_t, tReal *mu_tpdt) const =0
compute mu at time step
virtual ~SM_System(void)
destroy the class
Definition: SM_System.h:106
const SM_TimeStepper & getTimeStepper() const
get the time stepper
Definition: SM_System.h:180
virtual tMemSize getMemorySize() const
return the memory size of the class and the memory size of all its attributes/associations
Definition: SM_System.h:128
void computeMagneticField(const tIndex &t, const SM_Network &network, const tReal *mu, tReal *B) const
compute the magnetic field at time step index t by calling the virtual method SM_Operator::computeMag...
Definition: SM_System.h:387
SM_LandauLifschitzFunction & getLandauLifschitzFunction()
get the Landau Lifschitz function
Definition: SM_System.h:269
void computeMagneticFieldAndEnergies(const tIndex &t, const SM_Network &network, const tReal *mu, tReal *B, tReal *Es) const
compute the magnetic field by calling the virtual method SM_Operator::computeMagneticField()
Definition: SM_System.h:409
SM_RealField mMu0
Definition: SM_System.h:77
This class is describes a time stepper.
Definition: SM_TimeStepper.h:13
typename std::unique_ptr< T, CORE_Object::Delete > CORE_UniquePointer
Definition: sp.h:8
#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