Massively Parallel Trotter-Suzuki Solver  1.6.1
trottersuzuki.h
1 
18 #ifndef __TROTTERSUZUKI_H
19 #define __TROTTERSUZUKI_H
20 
21 #include <string>
22 #define _USE_MATH_DEFINES
23 #include <cfloat>
24 #include <complex>
25 #if HAVE_CONFIG_H
26 #include "config.h"
27 #endif
28 #ifdef HAVE_MPI
29 #include <mpi.h>
30 #endif
31 
32 using namespace std;
33 
34 class Lattice {
35 public:
36  int mpi_rank;
37  int mpi_procs;
38  double length_x, length_y;
39  double delta_x, delta_y;
40  int dim_x, dim_y;
41  int global_no_halo_dim_x, global_no_halo_dim_y;
42  int global_dim_x, global_dim_y;
43  int periods[2];
44 
45  // Computational topology
46  int halo_x, halo_y;
47  int start_x, start_y;
48  int end_x, end_y;
49  int inner_start_x, inner_start_y;
50  int inner_end_x, inner_end_y;
51  int mpi_coords[2], mpi_dims[2];
52 #ifdef HAVE_MPI
53  MPI_Comm cartcomm;
54 #endif
55 };
56 
63 class Lattice1D: public Lattice {
64 public:
73  Lattice1D(int dim, double length, bool periodic_x_axis = false);
74 };
75 
82 class Lattice2D: public Lattice {
83 public:
93  Lattice2D(int dim, double length,
94  bool periodic_x_axis = false, bool periodic_y_axis = false, double angular_velocity = 0.);
106  Lattice2D(int dim_x, double length_x, int dim_y, double length_y,
107  bool periodic_x_axis = false, bool periodic_y_axis = false, double angular_velocity = 0.);
108 private:
109  void init(int dim_x, double length_x, int dim_y, double length_y,
110  bool periodic_x_axis = false, bool periodic_y_axis = false, double angular_velocity = 0.);
111 };
112 
117 class State {
118 public:
119  double *p_real;
120  double *p_imag;
121  Lattice *grid;
122 
130  State(Lattice *grid, double *p_real = 0, double *p_imag = 0);
131  State(const State &obj );
132  ~State();
133  void init_state(complex<double> (*ini_state)(double x) );
134  void init_state(complex<double> (*ini_state)(double x, double y) );
135  void loadtxt(char *file_name);
136 
137  void imprint(complex<double> (*function)(double x) );
138  void imprint(complex<double> (*function)(double x, double y) );
139  double *get_particle_density(double *density = 0 );
140  double *get_phase(double *phase = 0 );
141  double get_squared_norm(void);
142  double get_mean_x(void);
143  double get_mean_xx(void);
144  double get_mean_y(void);
145  double get_mean_yy(void);
146  double get_mean_px(void);
147  double get_mean_pxpx(void);
148  double get_mean_py(void);
149  double get_mean_pypy(void);
150  double get_mean_angular_momentum(void);
151  void write_to_file(string fileprefix );
152  void write_particle_density(string fileprefix );
153  void write_phase(string fileprefix );
155 
156 protected:
157  bool self_init;
158  void calculate_expected_values(void);
159  double mean_X, mean_XX;
160  double mean_Y, mean_YY;
161  double mean_Px, mean_PxPx;
162  double mean_Py, mean_PyPy;
164  double norm2;
165 };
166 
172 class ExponentialState: public State {
173 public:
185  ExponentialState(Lattice2D *grid, int n_x = 1, int n_y = 1, double norm = 1, double phase = 0, double *p_real = 0, double *p_imag = 0);
186 
187 private:
188  int n_x, n_y;
189  double norm, phase;
190  complex<double> exp_state(double x, double y);
191 };
192 
198 class GaussianState: public State {
199 public:
213  GaussianState(Lattice2D *grid, double omega_x, double omega_y = -1., double mean_x = 0, double mean_y = 0, double norm = 1, double phase = 0,
214  double *p_real = 0, double *p_imag = 0);
215 
216 private:
217  double mean_x;
218  double mean_y;
219  double omega_x;
220  double omega_y;
221  double norm;
222  double phase;
223  complex<double> gauss_state(double x, double y);
224 };
225 
231 class SinusoidState: public State {
232 public:
244  SinusoidState(Lattice2D *grid, int n_x = 1, int n_y = 1, double norm = 1, double phase = 0, double *p_real = 0, double *p_imag = 0);
245 
246 private:
247  int n_x, n_y;
248  double norm, phase;
249  complex<double> sinusoid_state(double x, double y);
250 };
251 
255 class Potential {
256 public:
257  Lattice *grid;
258  double *matrix;
259 
266  Potential(Lattice *grid, char *filename);
273  Potential(Lattice *grid, double *external_pot = 0);
280  Potential(Lattice *grid, double (*potential_function)(double x, double y));
287  Potential(Lattice *grid, double (*potential_function)(double x, double y, double t), int t = 0);
288  virtual ~Potential();
289  virtual double get_value(int x);
290  virtual double get_value(int x, int y);
291  bool update(double t);
292  bool updated_potential_matrix;
293 protected:
295  double (*static_potential)(double x, double y);
296  double (*evolving_potential)(double x, double y, double t);
297  bool self_init;
298  bool is_static;
299 };
300 
307 public:
318  HarmonicPotential(Lattice2D *grid, double omegax, double omegay, double mass = 1., double mean_x = 0., double mean_y = 0.);
320  double get_value(int x, int y);
321 
322 private:
323  double omegax, omegay;
324  double mass;
325  double mean_x, mean_y;
326 };
327 
331 class Hamiltonian {
332 public:
334  double mass;
335  double coupling_a;
337  double rot_coord_x;
338  double rot_coord_y;
339 
351  Hamiltonian(Lattice *grid, Potential *potential = 0, double mass = 1., double coupling_a = 0.,
352  double angular_velocity = 0.,
353  double rot_coord_x = 0, double rot_coord_y = 0);
354  ~Hamiltonian();
355 
356 protected:
357  bool self_init;
358  Lattice *grid;
359 };
360 
365 public:
366  double mass_b;
367  double coupling_ab;
368  double coupling_b;
369  double omega_r;
370  double omega_i;
372 
390  Hamiltonian2Component(Lattice *grid, Potential *potential = 0,
391  Potential *potential_b = 0,
392  double mass = 1., double mass_b = 1.,
393  double coupling_a = 0., double coupling_ab = 0.,
394  double coupling_b = 0.,
395  double omega_r = 0, double omega_i = 0,
396  double angular_velocity = 0.,
397  double rot_coord_x = 0,
398  double rot_coord_y = 0);
400 };
401 
405 class ITrotterKernel {
406 public:
407  virtual ~ITrotterKernel() {};
408  virtual void run_kernel() = 0;
409  virtual void run_kernel_on_halo() = 0;
410  virtual void wait_for_completion() = 0;
411  virtual void get_sample(size_t dest_stride, size_t x, size_t y, size_t width, size_t height, double * dest_real, double * dest_imag, double * dest_real2 = 0, double * dest_imag2 = 0) const = 0;
412  virtual void normalization() = 0;
413  virtual void rabi_coupling(double var, double delta_t) = 0;
414  virtual double calculate_squared_norm(bool global = true) const = 0;
415  virtual bool runs_in_place() const = 0;
416  virtual string get_name() const = 0;
417  virtual void update_potential(double *_external_pot_real, double *_external_pot_imag, int which) = 0;
418 
419  virtual void start_halo_exchange() = 0;
420  virtual void finish_halo_exchange() = 0;
421 
422 };
423 
427 class Solver {
428 public:
429  Lattice *grid;
434 
443  Solver(Lattice *grid, State *state, Hamiltonian *hamiltonian, double delta_t,
444  string kernel_type = "cpu");
455  Solver(Lattice *grid, State *state1, State *state2,
456  Hamiltonian2Component *hamiltonian,
457  double delta_t, string kernel_type = "cpu");
458  ~Solver();
459  void evolve(int iterations, bool imag_time = false);
460  void update_parameters();
461  double get_total_energy(void);
462  double get_squared_norm(size_t which = 3 );
463  double get_kinetic_energy(size_t which = 3 );
464  double get_potential_energy(size_t which = 3 );
465  double get_rotational_energy(size_t which = 3 );
466  double get_intra_species_energy(size_t which = 3 );
467  double get_inter_species_energy(void);
468  double get_rabi_energy(void);
469  void set_exp_potential(double *real, int real_length, double *imag,
470  int imag_length, int which);
471 private:
472  bool imag_time;
473  double h_a[2];
474  double h_b[2];
475  double **external_pot_real;
476  double **external_pot_imag;
477  double delta_t;
478  double norm2[2];
480  string kernel_type;
481  ITrotterKernel * kernel;
482  void initialize_exp_potential(double time_single_it, int which);
483  void init_kernel();
484  double total_energy;
485  double kinetic_energy[2];
487  double potential_energy[2];
489  double rotational_energy[2];
491  double intra_species_energy[2];
494  double rabi_energy;
497  void calculate_energy_expected_values(void);
498  bool is_python;
499 };
500 
501 double const_potential(double x);
502 double const_potential(double x, double y);
503 void center_coordinates(Lattice *grid, int x_in, double *x_out);
504 void center_coordinates(Lattice *grid, int x_in, int y_in, double *x_out, double *y_out);
505 #endif // __TROTTERSUZUKI_H
double coupling_b
Coupling constant of the intra-particles interaction of the second component.
Definition: trottersuzuki.h:368
double omega_y
Gaussian coefficient.
Definition: trottersuzuki.h:220
double tot_potential_energy
Total potential energy of the system.
Definition: trottersuzuki.h:488
double mean_y
Y coordinate of the gaussian function&#39;s center.
Definition: trottersuzuki.h:218
double mean_angular_momentum
Expected value of the L_z operator.
Definition: trottersuzuki.h:163
int n_y
First and second quantum number.
Definition: trottersuzuki.h:188
double phase
Norm and phase of the state.
Definition: trottersuzuki.h:189
double rot_coord_y
Y coordinate of the center of rotation.
Definition: trottersuzuki.h:338
double * p_imag
Imaginary part of the wave function.
Definition: trottersuzuki.h:120
double * p_real
Real part of the wave function.
Definition: trottersuzuki.h:119
This class defines the Hamiltonian of a single component system.
Definition: trottersuzuki.h:331
State * state
State of the first component.
Definition: trottersuzuki.h:430
double current_evolution_time
Amount of time evolved since the beginning of the evolution.
Definition: trottersuzuki.h:294
double tot_intra_species_energy
Total intra-particles interaction energy of the system.
Definition: trottersuzuki.h:492
This class defines a quantum state with gaussian like wave function.
Definition: trottersuzuki.h:198
double ** external_pot_real
Real part of the evolution operator regarding the external potential.
Definition: trottersuzuki.h:475
double current_evolution_time
Amount of time evolved since the beginning of the evolution.
Definition: trottersuzuki.h:433
This class defines the external potential that is used for Hamiltonian class.
Definition: trottersuzuki.h:255
Potential * potential_b
External potential for the second component.
Definition: trottersuzuki.h:371
This class defines the 2D lattice structure over which the state and potential matrices are defined...
Definition: trottersuzuki.h:82
State * state_b
State of the second component.
Definition: trottersuzuki.h:431
double * matrix
Matrix storing the potential.
Definition: trottersuzuki.h:258
bool self_init
Whether the external potential matrix has been initialized from the Potential constructor or not...
Definition: trottersuzuki.h:297
double omega_i
Imaginary part of the Rabi coupling.
Definition: trottersuzuki.h:370
Lattice * grid
Object that defines the lattice structure.
Definition: trottersuzuki.h:121
Hamiltonian * hamiltonian
Hamiltonian of the system; either single component or two components.
Definition: trottersuzuki.h:432
Lattice * grid
Lattice object.
Definition: trottersuzuki.h:429
double norm
Norm of the state.
Definition: trottersuzuki.h:221
double mean_PxPx
Expected values of the P_x and P_x^2 operators.
Definition: trottersuzuki.h:161
bool expected_values_updated
Whether the expected values of the state object are updated with respect to the last evolution...
Definition: trottersuzuki.h:154
double coupling_ab
Coupling constant of the inter-particles interaction.
Definition: trottersuzuki.h:367
double delta_t
A single evolution iteration, evolves the state for this time.
Definition: trottersuzuki.h:477
bool energy_expected_values_updated
Whether the expectation values are updated or not.
Definition: trottersuzuki.h:496
double tot_rotational_energy
Total Rotational energy of the system.
Definition: trottersuzuki.h:490
bool self_init
Whether the potential is initialized in the Hamiltonian constructor or not.
Definition: trottersuzuki.h:357
int n_y
First and second quantum number.
Definition: trottersuzuki.h:247
This class defines the quantum state.
Definition: trottersuzuki.h:117
ITrotterKernel * kernel
Pointer to the kernel object.
Definition: trottersuzuki.h:481
Lattice * grid
Object that defines the lattice structure.
Definition: trottersuzuki.h:257
double tot_kinetic_energy
Total kinetic energy of the system.
Definition: trottersuzuki.h:486
double phase
Norm and phase of the state.
Definition: trottersuzuki.h:248
double ** external_pot_imag
Imaginary part of the evolution operator regarding the external potential.
Definition: trottersuzuki.h:476
double mean_PyPy
Expected values of the P_y and P_y^2 operators.
Definition: trottersuzuki.h:162
double rot_coord_x
X coordinate of the center of rotation.
Definition: trottersuzuki.h:337
bool is_static
Whether the external potential is static or time-dependent.
Definition: trottersuzuki.h:298
bool single_component
Whether the system is single-component(true) or two-components(false).
Definition: trottersuzuki.h:479
This class defines the evolution tasks.
Definition: trottersuzuki.h:427
double mean_y
Minimum of the potential along x and y axis.
Definition: trottersuzuki.h:325
This class defines the external potential that is used for Hamiltonian class.
Definition: trottersuzuki.h:306
double mass
Mass of the particle.
Definition: trottersuzuki.h:334
string kernel_type
Which kernel are being used (cpu or gpu).
Definition: trottersuzuki.h:480
double omega_r
Real part of the Rabi coupling.
Definition: trottersuzuki.h:369
double mean_XX
Expected values of the X and X^2 operators.
Definition: trottersuzuki.h:159
bool imag_time
Whether the time of evolution is imaginary(true) or real(false).
Definition: trottersuzuki.h:472
This class defines the Hamiltonian of a two component system.
Definition: trottersuzuki.h:364
double angular_velocity
The frame of reference rotates with this angular velocity.
Definition: trottersuzuki.h:336
double omega_x
Gaussian coefficient.
Definition: trottersuzuki.h:219
double phase
Relative phase of the wave function.
Definition: trottersuzuki.h:222
double total_energy
Total energy of the system.
Definition: trottersuzuki.h:484
double inter_species_energy
Inter-particles interaction energy of the system.
Definition: trottersuzuki.h:493
double mean_YY
Expected values of the Y and Y^2 operators.
Definition: trottersuzuki.h:160
double mass_b
Mass of the second component.
Definition: trottersuzuki.h:366
bool has_parameters_changed
Keeps track whether the Hamiltonian parameters were changed.
Definition: trottersuzuki.h:495
double omegay
Frequencies along x and y axis.
Definition: trottersuzuki.h:323
This class defines the 1D lattice structure over which the state and potential are defined...
Definition: trottersuzuki.h:63
Lattice * grid
Lattice object.
Definition: trottersuzuki.h:358
double mass
Mass of the particle.
Definition: trottersuzuki.h:324
This class defines a quantum state with sinusoidal like wave function.
Definition: trottersuzuki.h:231
double mean_x
X coordinate of the gaussian function&#39;s center.
Definition: trottersuzuki.h:217
Potential * potential
Potential object.
Definition: trottersuzuki.h:333
bool self_init
Whether the p_real and p_imag matrices have been initialized from the State constructor or not...
Definition: trottersuzuki.h:157
double coupling_a
Coupling constant of intra-particle interaction.
Definition: trottersuzuki.h:335
This class defines a quantum state with exponential like wave function.
Definition: trottersuzuki.h:172
double rabi_energy
Rabi energy of the system.
Definition: trottersuzuki.h:494
double norm2
Squared norm of the state.
Definition: trottersuzuki.h:164