C++ mpi module for stochmagnet_main Package
SM_CubicAnisotropyOperator.h
1 #ifndef SM_CubicAnisotropyOperator_H
2 #define SM_CubicAnisotropyOperator_H
3 
4 //base classes
5 #include "SM_AnisotropyOperator.h"
6 
7 //network class
8 #include "SM_Network.h"
9 
10 
11 
31 class SM_CubicAnisotropyOperator : public SM_AnisotropyOperator<SM_CubicAnisotropyOperator> {
32 
33  //attributes
34 private :
35 
36 
37 
38 protected:
39  // CONSTRUCTORS
43 
44  // DESTRUCTORS
47  virtual ~SM_CubicAnisotropyOperator(void);
48 public :
49 
50  //Instance building
51  //=================
52 
56  inline static CORE_UniquePointer<SM_CubicAnisotropyOperator> New() {
57  return CORE_UniquePointer<SM_CubicAnisotropyOperator>(new SM_CubicAnisotropyOperator(),
59  }
60 
64  virtual CORE_UniquePointer<SM_SliceOperator> NewInstance() const override {
65  return New();
66  }
67 public:
68 
69  //MEMORY
70 
84  virtual tMemSize getMemorySize() const {
85  return sizeof(*this)+getContentsMemorySize();
86  }
87 
96  virtual tMemSize getContentsMemorySize() const {
98  return mem;
99  }
109  inline void computePhi(const tReal *U,const tReal* eU,
110  const tReal*S,const tReal *eS,
111  tReal& phi,tReal& W) const {
112  // OMP_CRITICAL(cout) {
113  // std::cout<<"U size:"<<(eU-U)<<" U={";
114  // const tReal *iU=U;
115  // while (iU!=eU) {
116  // std::cout<<(*iU)<<" ";
117  // iU++;
118  // }
119  // std::cout<<"}\n";
120  // }
121 
122  phi=0;
123  while (U!=eU) {
124 
125  //W=<S,Ud>
126  W=0;
127  while (S!=eS) {
128 
129  W+=(*S)*(*U);
130 
131  //next coordinate
132  S++;
133  U++;
134  }
135 
136 
137  //W=<S,Ud>^2
138  W*=W;
139  //W=<S,Ud>^4
140  W*=W;
141 
142  // \Phi_U(S)= \sum_{d=0}^{d=2} .<S,U_d>^4
143  phi+=W;
144 
145  //restore S pointer
147 
148 
149 
150  }//end loop on direction d
151 
152  // \Phi_U(S)= 0.5 \sum_{d=0}^{d=2} .<S,U_d>^4
153  phi*=0.5;
154 
155 
156  }
157 
168  inline void computePhiDerivatives(const tReal *U,const tReal* eU,
169  const tReal*S,const tReal *eS,
170  tReal& phi,std::array<tReal,SM_Constants::DIM>& gradPhi,
171  tReal& W,tReal& W3) const {
172 
173  //gradPhi=0;
174  memset(gradPhi.data(),0,sizeof(tReal)*SM_Constants::DIM);
175 
176  phi=0;
177  while (U!=eU) {//loop on anistropy direction
178  //W=<S,Ud>
179  W=0;
180  while (S!=eS) {
181  W+=(*S)*(*U);
182  //next coordinate
183  S++;
184  U++;
185  }
186 
187  //restore S pointer
189 
190  //restore U pointer
192 
193  //W3=<S,Ud>^3
194  W3=W;
195  W3*=W3;
196  W3*=W;
197 
198  //gradPhi+=2*Ud.<S,U_d>^3
199  for(auto& gradPhi_k:gradPhi) {
200  gradPhi_k+=2*W3*(*U);
201  U++;
202  }
203 
204  //W^4
205  W3*=W;
206 
207  //\Phi_U(S)= sum_{d=0}^{d=2} .<S,U_d>^4
208  phi+=W3;
209 
210  //next anisotropy direction
211 
212  }//end loop on direction
213  //\Phi_U(S)= - \frac{1}{2} \sum_{d=0}^{d=2} .<S,U_d>^4
214  phi*=0.5;
215 
216 
217 
218  }
219 
220 
221 
222 
223 };
224 
225 
226 #endif
class Free introduced for deleting a smart pointer
Definition: CORE_Object.h:113
This class is describes the general anisotropy operatoor.
Definition: SM_AnisotropyOperator.h:32
static constexpr tDimension DIM
space dimension
Definition: SM_Constants.h:80
This class is describes the uniaxial anisotropy.
Definition: SM_CubicAnisotropyOperator.h:31
virtual tMemSize getMemorySize() const
return the memory size of the class and the memory size of all its attributes/associations
Definition: SM_CubicAnisotropyOperator.h:84
void computePhi(const tReal *U, const tReal *eU, const tReal *S, const tReal *eS, tReal &phi, tReal &W) const
compute the function
Definition: SM_CubicAnisotropyOperator.h:109
virtual ~SM_CubicAnisotropyOperator(void)
destroy
Definition: SM_CubicAnisotropyOperator.cpp:7
virtual tMemSize getContentsMemorySize() const
return the memory size of the included associations
Definition: SM_CubicAnisotropyOperator.h:96
void computePhiDerivatives(const tReal *U, const tReal *eU, const tReal *S, const tReal *eS, tReal &phi, std::array< tReal, SM_Constants::DIM > &gradPhi, tReal &W, tReal &W3) const
compute the function
Definition: SM_CubicAnisotropyOperator.h:168
static CORE_UniquePointer< SM_CubicAnisotropyOperator > New()
build a new instance of the operator
Definition: SM_CubicAnisotropyOperator.h:56
SM_CubicAnisotropyOperator(void)
create a network class
Definition: SM_CubicAnisotropyOperator.cpp:3
virtual CORE_UniquePointer< SM_SliceOperator > NewInstance() const override
create a New instance of this
Definition: SM_CubicAnisotropyOperator.h:64
virtual tMemSize getContentsMemorySize() const
return nthe memory size of the included associations
Definition: SM_SliceOperator.h:97