NanoMagMC  v0.2
Monte Carlo Simulation Software for Atomistic Models of Magnetic Materials
field_type.hpp
Go to the documentation of this file.
1 #ifndef _FIELD
2 #define _FIELD
3 
4 #include <vector>
5 #include <string>
6 
7 #define XTENSOR_USE_XSIMD
8 #include <xtensor/xfixed.hpp>
9 
10 namespace particle{ namespace field {
14  class field_type
15  {
16  private:
17  std::vector<xt::xtensorf<double, xt::xshape<4> > > spins;
18  std::vector<xt::xtensorf<int, xt::xshape<4> > > locs;
19  std::vector<std::vector<int> > neighbours;
20  std::vector<std::vector<int> > adj;
21  std::vector<std::vector<int> > neigh_choice;
22 
23  std::vector<xt::xtensorf<int, xt::xshape<4> > > loc_diffs;
24  std::vector<double> J_diffs;
25  std::vector<xt::xtensorf<double, xt::xshape<4> > > D_vecs;
26 
27  bool J_on;
28  bool D_on;
29  bool ising;
30  bool periodic;
31  int d;
32  int edgesize;
33  xt::xtensorf<double, xt::xshape<4>> upspin;
34  xt::xtensorf<double, xt::xshape<4>> downspin;
35  xt::xtensorf<double, xt::xshape<4>> testspin;
36  xt::xtensorf<int, xt::xshape<4>> blankloc;
37 
38  public:
43 
56  field_type(bool ising_in,
57  bool periodic_in,
58  int d_in,
59  int edgesize_in,
60  double J_mod,
61  double D_mod,
62  std::string J_filename);
63 
68 
72  void set_default_spins();
73 
80  xt::xtensorf<double, xt::xshape<4>>& access(int index) {return spins[index];}
81 
89  std::vector<int>& get_neigh(int index) {return neighbours[index];}
90 
98  std::vector<int>& get_adj(int index) {return adj[index];}
99 
107  double& get_J(int i, int j) {return J_diffs[neigh_choice[i][j]];}
108 
116  xt::xtensorf<double, xt::xshape<4>>& get_D_vec(int i, int j)
117  {return D_vecs[neigh_choice[i][j]];}
118 
126  xt::xtensorf<int, xt::xshape<4>>& get_loc(int index)
127  {return locs[index];}
128 
134  void add_spin(xt::xtensorf<int, xt::xshape<4>>& loc);
135 
139  void set_neigh();
140 
146  unsigned int get_size() {return spins.size();}
147 
153  int get_dim() {return d;}
154 
160  int get_edge() {return edgesize;}
161 
167  void set_rand(int index) {spins[index] = testspin;}
168 
174  void set_up(int index) {spins[index] = upspin;}
175 
181  void set_down(int index) {spins[index] = downspin;}
182 
188  void set_spin(int index, xt::xtensorf<double, xt::xshape<4> >& in)
189  {spins[index] = in;}
190 
194  void gen_rand();
195 
201  xt::xtensorf<double, xt::xshape<4>>& get_rand() {return testspin;}
202 
206  void all_rand();
207 
211  void all_zero();
212 
222  void print_setup(const std::string filename,
223  const std::string groupname,
224  const int Tmax,
225  const int Hmax);
226 
233  void print(std::string filename, std::string arrname);
234 
240  void send_data(int dest_rank);
241 
247  void recv_data(int src_rank);
248 
252  bool use_J() {return J_on;}
253 
257  bool use_D() {return D_on;}
258  };
259 }}
260 
261 #endif
void set_spin(int index, xt::xtensorf< double, xt::xshape< 4 > > &in)
Definition: field_type.hpp:188
void print_setup(const std::string filename, const std::string groupname, const int Tmax, const int Hmax)
void set_neigh()
Determine the neighbours of the spins.
int get_edge()
Definition: field_type.hpp:160
~field_type()
Destructor.
Definition: field_type.hpp:67
void all_rand()
Set all spins to a random state.
int get_dim()
Definition: field_type.hpp:153
xt::xtensorf< int, xt::xshape< 4 > > & get_loc(int index)
Definition: field_type.hpp:126
Definition: field_type.hpp:10
xt::xtensorf< double, xt::xshape< 4 > > & get_D_vec(int i, int j)
Definition: field_type.hpp:116
void set_rand(int index)
Definition: field_type.hpp:167
Base class for fields.
Definition: field_type.hpp:14
void print(std::string filename, std::string arrname)
double & get_J(int i, int j)
Definition: field_type.hpp:107
void set_down(int index)
Definition: field_type.hpp:181
void set_up(int index)
Definition: field_type.hpp:174
void add_spin(xt::xtensorf< int, xt::xshape< 4 >> &loc)
bool use_J()
Are the exchanges on?
Definition: field_type.hpp:252
xt::xtensorf< double, xt::xshape< 4 > > & access(int index)
Definition: field_type.hpp:80
xt::xtensorf< double, xt::xshape< 4 > > & get_rand()
Definition: field_type.hpp:201
void recv_data(int src_rank)
std::vector< int > & get_adj(int index)
Definition: field_type.hpp:98
void gen_rand()
Generate a random spin state.
bool use_D()
Are the dmis on?
Definition: field_type.hpp:257
void send_data(int dest_rank)
field_type()
Default constructor.
Definition: field_type.hpp:42
void all_zero()
Set all spins to a zero state.
void set_default_spins()
Set default spins.
std::vector< int > & get_neigh(int index)
Definition: field_type.hpp:89
unsigned int get_size()
Definition: field_type.hpp:146