C++ main module for stochmagnet Package  1.0
SM_HeissenbergOperator.h
Go to the documentation of this file.
1 #ifndef SM_HeissenbergOperator_H
2 #define SM_HeissenbergOperator_H
3 
4 //base classes
5 #include "SM_TemplatedOperator.h"
6 
7 //network class
8 #include "SM_Network.h"
9 
27 class SM_HeissenbergOperator : public SM_TemplatedOperator<SM_HeissenbergOperator> {
28 
29  //attributes
30 private :
31 
32 
33  //association
34 
35 
36 
37 protected:
38  // CONSTRUCTORS
42  setName("Heissenberg");
43  }
44 
45  // DESTRUCTORS
48  virtual ~SM_HeissenbergOperator(void) {
49  }
50 
51 public :
52 
53  //Instance building
54  //=================
55 
61  }
62 
66  virtual CORE_UniquePointer<SM_Operator> NewInstance() const override {
67  return New();
68  }
69 public:
70 
71  //MEMORY
72 
86  virtual tMemSize getMemorySize() const {
87  return sizeof(*this)+getContentsMemorySize();
88  }
89 
90 
98  virtual void computeMagneticField(const tIndex& t,
99  const SM_Network& network,
100  const tReal *mu,
101  tReal *B) const override {
102  return computeTemplatedMagneticField(t,network,mu,B);
103  }
111  virtual void computeMagneticFieldAndEnergy(const tIndex& t,
112  const SM_Network& network,
113  const tReal *mu,
114  tReal *B,
115  tReal& E) const override{
116  return computeTemplatedMagneticFieldAndEnergy(t,network,mu,B,E);
117  }
125  inline void computeTemplatedMagneticField(const tIndex& t,
126  const SM_Network& network,
127  const tReal *mu,
128  tReal *B) const {
129 
130  tReal E=0;
131  computeTemplatedMagneticFieldAndEnergy(t,network,mu,B,E);
132  }
133 
142  const SM_Network& network,
143  const tReal *mu,
144  tReal *H,
145  tReal& E) const {
146  //get the number of particles of the network
147  const tIndex& nParticles=network.getParticlesNumber();
148 
149  //get the dimension of the netwok
150  const tDimension& dim=network.getDimension();
151 
152  //strength of the network
153  const tReal& lambda=network.getLambda();
154  tReal iLambda2x2=2./(lambda*lambda);
155 
156  //iterator on particles
157  tIndex i,j;
158 
159  //iterator on dimension
160  tDimension d;
161 
162  //Bid at first particles
163  tReal *Hi=H;
164  tReal *Hi_d=null;
165 
166  //d-coordinate of magnetic moment at particle j
167  const tReal *Muj_d;
168 
169  //d-coordinate of magnetic moment at particle i
170  const tReal *Mui=mu,*Mui_d=null;
171 
172 
173  const tUInt *nNeighbors_i=&network.getNeighborsNumber()[0];//number of neighbor of the particle 0
174  const tIndex *iNeighbors=&network.getNeighborsIndices()[0];//first index of the neighbor of the particle 0
175 
176  const tReal *iJ=&network.getHeissenbergCoefficients()[0];//value of the exchange of the neighbor of particles i
177 
178  tUInt iN;//iterator on neighbor particles
179 
180  //for (i=0;i<nParticles;i++) std::cout<<"\t mu["<<i<<"]=("<<mu[i*dim]<<","<<mu[i*dim+1]<<","<<mu[i*dim+2]<<")\n";
181 
182  //Energy
183 
184  E=0;
185 
186  tReal Hex_id;//d-coordinate of Hexchange at particle Pi
187  for (i=0;i<nParticles;i++) {//loop on particles
188 
189  //loop on the neighbors of the particle i
190 
191 
192  for (iN=0;iN<(*nNeighbors_i);iN++) {
193 
194 
195  //mu at j of the neighbor particles
196  j=(*iNeighbors);
197 
198 
199  //d-coordinate of u at point P_j
200  Muj_d=&mu[j*dim];
201 
202  //Hi +=\sum_j (2.Jij/\lambda^2). mu_j
203  Hi_d=Hi;
204  Mui_d=Mui;
205  for (d=0;d<dim;d++) {
206 
207  //Hexc =\sum_j (2.Jij/\lambda^2). mu_j
208  Hex_id=(*Muj_d)*(*iJ)*iLambda2x2;
209 
210  //add to d-coordinate of B at particle P_i
211  (*Hi_d)+=Hex_id;
212 
213  //E=-0.5<H,mu>
214  E-=0.5*Hex_id*(*Mui_d);
215 
216 
217  //next coordinate
218  Hi_d++; //next coordinate of H at particle Pi
219  Muj_d++;//next coordinate of Mu at particle Pj
220  Mui_d++;//next coordinate of Mu at particle Pi
221  }
222 
223 
224 
225  //next neighbor particle
226  iNeighbors++;
227  iJ++;
228 
229  }//end loop on neighbors
230 
231 
232  //neighbors number of next particle
233  nNeighbors_i++;
234 
235  //H at next particle
236  Hi+=dim;
237  //Mu at next particle
238  Mui+=dim;
239 
240 
241  }//end loop on particles
242 
243  }//end method
250  virtual tReal computeEnergy(const tIndex &t,
251  const SM_Network& network,
252  const tReal *mu) const override{
253  return computeTemplatedEnergy(t,network,mu);
254  }
263  const SM_Network& network,
264  const tReal *mu) const {
265 
266  //get the number of particles of the network
267  const tIndex& nParticles=network.getParticlesNumber();
268 
269  //get the dimension of the netwok
270  const tDimension& dim=network.getDimension();
271 
272  //strength of the network
273  const tReal& lambda=network.getLambda();
274  tReal iLambda2=1./(lambda*lambda);
275 
276  //iterator on particles
277  tIndex i,j;
278 
279  //iterator on dimension
280  tDimension d;
281 
282  //Mu at particle i
283  const tReal *Mui=mu,*Mui_d;
284 
285  //Mu at particle j
286  const tReal *Muj_d;
287 
288  //neighbors
289  const tUInt *nNeighbors_i=&network.getNeighborsNumber()[0];//number of neighbor of the particle 0
290  const tIndex *iNeighbors=&network.getNeighborsIndices()[0];//first index of the neighbor of the particle 0
291 
292  const tReal *iJ=&network.getHeissenbergCoefficients()[0];//value of the exchange of the neighbor of particles i
293 
294 
295  tUInt iN;//iterator on neighbor particles
296 
297 
298  //energy
299  tReal E=0;
300 
301  for (i=0;i<nParticles;i++) {//loop on particles
302 
303  //loop on the neighbors of the particle i
304 
305  for (iN=0;iN<(*nNeighbors_i);iN++) {
306 
307  //index of the neighbor particle
308  j=(*iNeighbors);
309 
310  //mu at j
311  Muj_d=&mu[j*dim];
312 
313  //E -=(1/\lambda^2) \sum_j (Jij/\lambda^2). <mu_j,mu_i>
314  Mui_d=Mui;
315  for (d=0;d<dim;d++) {
316  E-=(*Muj_d)*(*Mui_d)*(*iJ)*iLambda2;
317  Mui_d++;
318  Muj_d++;
319  }
320 
321  //next neighbor particle
322  iNeighbors++;
323  //next J of neihbor relation
324  iJ++;
325 
326  }//end loop on neighbors
327 
328 
329  //neighbors number of next particle i
330  nNeighbors_i++;
331 
332  //magnetic moment at next particle i
333  Mui+=dim;
334 
335 
336  }//end loop on particles i
337 
338 
339 
340  return E;
341  }//end method
342 
343 
344 };
345 
346 
347 #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 the exchange operator.
Definition: SM_HeissenbergOperator.h:27
tReal computeTemplatedEnergy(const tIndex &t, const SM_Network &network, const tReal *mu) const
compute the energy
Definition: SM_HeissenbergOperator.h:262
void computeTemplatedMagneticField(const tIndex &t, const SM_Network &network, const tReal *mu, tReal *B) const
compute the magnetic field
Definition: SM_HeissenbergOperator.h:125
virtual tMemSize getMemorySize() const
return the memory size of the class and the memory size of all its attributes/associations
Definition: SM_HeissenbergOperator.h:86
void computeTemplatedMagneticFieldAndEnergy(const tIndex &t, const SM_Network &network, const tReal *mu, tReal *H, tReal &E) const
compute the magnetic field and energy
Definition: SM_HeissenbergOperator.h:141
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_HeissenbergOperator.h:111
virtual tReal computeEnergy(const tIndex &t, const SM_Network &network, const tReal *mu) const override
compute the energy at time t
Definition: SM_HeissenbergOperator.h:250
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_HeissenbergOperator.h:98
SM_HeissenbergOperator(void)
create a network class
Definition: SM_HeissenbergOperator.h:41
static CORE_UniquePointer< SM_HeissenbergOperator > New()
build a new instance of the operator
Definition: SM_HeissenbergOperator.h:59
virtual CORE_UniquePointer< SM_Operator > NewInstance() const override
create a New instance of this @retrun an unique pointer to the instance
Definition: SM_HeissenbergOperator.h:66
virtual ~SM_HeissenbergOperator(void)
destroy
Definition: SM_HeissenbergOperator.h:48
This class is describes a a network.
Definition: SM_Network.h:18
tDimension getDimension() const
return the dimension
Definition: SM_Network.h:133
const tReal & getLambda() const
get the lambda value
Definition: SM_Network.h:201
const std::valarray< tIndex > & getNeighborsIndices() const
Definition: SM_Network.h:266
const std::valarray< tUInt > & getNeighborsNumber() const
get the neighbors number
Definition: SM_Network.h:252
const std::valarray< tReal > & getHeissenbergCoefficients() const
get the Heissenberg coefficients
Definition: SM_Network.h:283
tInteger getParticlesNumber() const
return the particles number
Definition: SM_Network.h:146
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
This class is describes an implmentation of operator with the class I.
Definition: SM_TemplatedOperator.h:18
typename std::unique_ptr< T, CORE_Object::Delete > CORE_UniquePointer
Definition: sp.h:8
#define tUInt
Definition: types.h:44
#define tIndex
Definition: types.h:157
#define tMemSize
Definition: types.h:166
#define tReal
Definition: types.h:137