C++ main module for stochmagnet Package  1.0
SM_Network.h
Go to the documentation of this file.
1 #ifndef SM_Network_H
2 #define SM_Network_H
3 
4 //define a real field
5 #include"SM_Field.h"
6 
7 //define the std::array object
8 #include <array>
9 
10 #include "SM_Object.h"
11 
18 class SM_Network : public SM_Object {
19 
20  //attributes
21 private :
22 
23 
24 
25 
26 
27 
28  //strength
30 
31 
32  //coordinates of points
34 
35  //neighbors number
36  std::valarray<tUInt> mNeighborsNumber;
37 
38  //list of the neighbors indices
39  std::valarray<tIndex> mNeighborsIndices;
40 
41  //list of js;
42  std::valarray<tReal> mJs;
43 
44  //association
45 
46 
47 
48 public:
49  // CONSTRUCTORS
52  SM_Network(void) {
53 
55 
56  mLambda=1;
57  mNeighborsNumber={0};
58  }
59 
60  // DESTRUCTORS
63  virtual ~SM_Network(void) {
64  }
65 
66 public :
67 
68  //Instance building
69  //=================
70 
76  }
77 
78 
79  //MEMORY
80 
94  virtual tMemSize getMemorySize() const {
95  return sizeof(*this)+getContentsMemorySize();
96  }
97 
106  virtual tMemSize getContentsMemorySize() const {
109  mem+=mNeighborsNumber.size()*sizeof(tUInt);
110  mem+=mNeighborsIndices.size()*sizeof(tIndex);
111  mem+=mJs.size()*sizeof(tReal);
112  return mem;
113  }
114 
115  //SET & GET methods
116 
120  void copy(const SM_Network& network) {
121  //strength
122  mLambda=network.getLambda();
127 
128 
129  }
130 
133  inline tDimension getDimension() const {
134  return mPoints.getDimension();
135  }
136 
140  inline void setParticlesNumber(const tInteger& nParticles) {
141  mPoints.setElementsNumber(nParticles);
142  }
146  inline tInteger getParticlesNumber() const {
147  return mPoints.getElementsNumber();
148  }
153  tIndex nAloneParticles=0;
154  std::for_each(std::begin(mNeighborsNumber),std::end(mNeighborsNumber),
155  [&nAloneParticles](const auto& i){nAloneParticles+=(i==0);});
156  return nAloneParticles;
157  }
158 
162  inline void setParticlesCoordinates(std::initializer_list<tReal>&& coords) {
163  mPoints=coords;
164  }
168  inline void setParticlesCoordinates(const std::initializer_list<tReal>& coords) {
169  mPoints=coords;
170  }
174  inline void setParticlesCoordinates(const SM_RealField& coords) {
175  mPoints=coords;
176  }
177 
181  inline const SM_RealField& getParticlesCoordinates() const {
182  return mPoints;
183  }
184 
189  return mPoints;
190  }
191 
195  inline void setLambda( const tReal& L) {
196  mLambda=L;
197  }
201  inline const tReal& getLambda() const {
202  return mLambda;
203  }
204 
210  inline void setNeighbors(std::valarray<tUInt>&& neighborsNumber,
211  std::valarray<tIndex>&& neighborsIndices,
212  std::valarray<tReal>&& Js) {
213  mNeighborsNumber=neighborsNumber;
214  mNeighborsIndices=neighborsIndices;
215  mJs=Js;
216  }
222  inline void setNeighbors(const std::valarray<tUInt>& neighborsNumber,
223  const std::vector<tIndex>& neighborsIndices,
224  const std::vector<tReal>& Js) {
225  //copy neighbors
226  mNeighborsNumber=neighborsNumber;
227 
228 
229  //copy vector neighborsIndices into array mNeighborsIndices
230  auto Ni=neighborsIndices.cbegin();
231  mNeighborsIndices.resize(neighborsIndices.size());
232  std::for_each(std::begin(mNeighborsIndices),std::end(mNeighborsIndices),[&Ni](tIndex& e){e=(*Ni);Ni++;} );
233 
234  //copy vector Js into array mJs
235  auto Ji=Js.cbegin();
236  mJs.resize(Js.size());
237  std::for_each(std::begin(mJs),std::end(mJs),[&Ji](tReal& e){e=(*Ji);Ji++;} );
238 
239  }
240 
241 
242 
246  inline tIndex getConnectionsNumber() const {
247  return mNeighborsIndices.size();
248  }
252  inline const std::valarray<tUInt>& getNeighborsNumber() const {
253  return mNeighborsNumber;
254  }
258  inline std::valarray<tUInt>& getNeighborsNumber() {
259  return mNeighborsNumber;
260  }
261 
262 
263  /* ! \brief get the neighbors indices
264  * @return the neighborsIndices as indices of neighbors for each particle of size mParticlesNumber x sum on i of neighborsNumber[i]
265  */
266  inline const std::valarray<tIndex>& getNeighborsIndices() const {
267  return mNeighborsIndices;
268  }
269 
270  /* ! \brief get the neighbors indices
271  * @return the neighborsIndices as indices of neighbors for each particle of size mParticlesNumber x sum on i of neighborsNumber[i]
272  */
273  inline std::valarray<tIndex>& getNeighborsIndices() {
274  return mNeighborsIndices;
275  }
276 
277 
278 
279 
283  inline const std::valarray<tReal>& getHeissenbergCoefficients() const {
284  return mJs;
285  }
286 
290  inline std::valarray<tReal>& getHeissenbergCoefficients() {
291  return mJs;
292  }
293 
294 
306  void create3DGrid(const tIndex& Nx,const tIndex Ny,const tIndex Nz,
307  const tReal & Hx,const tReal& Hy,const tReal &Hz,
308  const tReal& J,const tBoolean& hasSelfInteraction);
309 
310 public:
311 
315  virtual tString toString() const override;
316 };
317 
318 
319 #endif
tUCInt tDimension
Definition: CORE_StdPtrField.h:567
K getDimension() const
get the dimension of the field
Definition: CORE_Field.h:143
virtual tMemSize getContentsMemorySize() const override
return the memory size of the included associations
Definition: CORE_Field.h:93
void copy(const tIndex &n, const Q *vs)
initialize the field to the values of pointer of size n
Definition: CORE_Field.h:422
tIndex getElementsNumber() const
return the number values of the container
Definition: CORE_Field.h:118
void setElementsNumber(const tInteger &n)
set the number of element of the container
Definition: CORE_Field.h:112
class Free introduced for deleting a smart pointer
Definition: CORE_Object.h:94
virtual tMemSize getContentsMemorySize() const
return nthe memory size of the included associations
Definition: CORE_Object.h:259
This class is describes a a network.
Definition: SM_Network.h:18
virtual tMemSize getMemorySize() const
return the memory size of the class and the memory size of all its attributes/associations
Definition: SM_Network.h:94
std::valarray< tReal > mJs
Definition: SM_Network.h:42
tReal mLambda
Definition: SM_Network.h:29
std::valarray< tIndex > mNeighborsIndices
Definition: SM_Network.h:39
tDimension getDimension() const
return the dimension
Definition: SM_Network.h:133
tIndex getConnectionsNumber() const
get the number of connections
Definition: SM_Network.h:246
tIndex computeAloneParticlesNumber() const
return the particles number
Definition: SM_Network.h:152
const tReal & getLambda() const
get the lambda value
Definition: SM_Network.h:201
const std::valarray< tIndex > & getNeighborsIndices() const
Definition: SM_Network.h:266
void setNeighbors(std::valarray< tUInt > &&neighborsNumber, std::valarray< tIndex > &&neighborsIndices, std::valarray< tReal > &&Js)
set the neighbors by moving
Definition: SM_Network.h:210
void create3DGrid(const tIndex &Nx, const tIndex Ny, const tIndex Nz, const tReal &Hx, const tReal &Hy, const tReal &Hz, const tReal &J, const tBoolean &hasSelfInteraction)
create a grid 3D of size Nx x Ny x Nz with distance between particles is hx x hy x hz the interaction...
Definition: SM_Network.cpp:5
std::valarray< tIndex > & getNeighborsIndices()
Definition: SM_Network.h:273
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
void setParticlesCoordinates(std::initializer_list< tReal > &&coords)
void set particles 3D-coordinates
Definition: SM_Network.h:162
static CORE_UniquePointer< SM_Network > New()
build a new instance of a Network
Definition: SM_Network.h:74
void setParticlesCoordinates(const std::initializer_list< tReal > &coords)
void set particles 3D-coordinates
Definition: SM_Network.h:168
tInteger getParticlesNumber() const
return the particles number
Definition: SM_Network.h:146
void setNeighbors(const std::valarray< tUInt > &neighborsNumber, const std::vector< tIndex > &neighborsIndices, const std::vector< tReal > &Js)
set the neighbors by copy
Definition: SM_Network.h:222
const SM_RealField & getParticlesCoordinates() const
void get particles coordinates
Definition: SM_Network.h:181
std::valarray< tUInt > & getNeighborsNumber()
get the neighbors number
Definition: SM_Network.h:258
void setParticlesCoordinates(const SM_RealField &coords)
void set particles coordinates
Definition: SM_Network.h:174
SM_Network(void)
create a network class
Definition: SM_Network.h:52
virtual tMemSize getContentsMemorySize() const
return the memory size of the included associations
Definition: SM_Network.h:106
std::valarray< tReal > & getHeissenbergCoefficients()
get the Heissenberg coefficients
Definition: SM_Network.h:290
void setLambda(const tReal &L)
set the lambda value
Definition: SM_Network.h:195
virtual tString toString() const override
turn the class into a string representation
Definition: SM_Network.cpp:146
std::valarray< tUInt > mNeighborsNumber
Definition: SM_Network.h:36
void copy(const SM_Network &network)
copy the network
Definition: SM_Network.h:120
virtual ~SM_Network(void)
destroy
Definition: SM_Network.h:63
SM_RealField mPoints
Definition: SM_Network.h:33
SM_RealField & getParticlesCoordinates()
void get particles coordinates
Definition: SM_Network.h:188
void setParticlesNumber(const tInteger &nParticles)
set the particles number
Definition: SM_Network.h:140
This class is a base class for Stoch Microm package.
Definition: SM_Object.h:19
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 tString
Definition: types.h:147
#define tMemSize
Definition: types.h:166
#define tInteger
Definition: types.h:114
#define tBoolean
Definition: types.h:151
#define tReal
Definition: types.h:137