Massively Parallel Trotter-Suzuki Solver  1.6.2
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  string coordinate_system;
45 
46  // Computational topology
47  int halo_x, halo_y;
48  int start_x, start_y;
49  int end_x, end_y;
50  int inner_start_x, inner_start_y;
51  int inner_end_x, inner_end_y;
52  int mpi_coords[2], mpi_dims[2];
53 #ifdef HAVE_MPI
54  MPI_Comm cartcomm;
55 #endif
56 };
57 
64 class Lattice1D: public Lattice {
65 public:
74  Lattice1D(int dim, double length, bool periodic_x_axis = false, string coordinate_system = "cartesian");
75 };
76 
83 class Lattice2D: public Lattice {
84 public:
95  Lattice2D(int dim, double length,
96  bool periodic_x_axis = false, bool periodic_y_axis = false,
97  double angular_velocity = 0., string coordinate_system = "cartesian");
110  Lattice2D(int dim_x, double length_x, int dim_y, double length_y,
111  bool periodic_x_axis = false, bool periodic_y_axis = false,
112  double angular_velocity = 0., string coordinate_system = "cartesian");
113 private:
114  void init(int dim_x, double length_x, int dim_y, double length_y,
115  bool periodic_x_axis = false, bool periodic_y_axis = false,
116  double angular_velocity = 0., string coordinate_system = "cartesian");
117 };
118 
123 class State {
124 public:
125  double *p_real;
126  double *p_imag;
127  Lattice *grid;
129 
138  State(Lattice *grid, int angular_momentum = 0, double *p_real = 0, double *p_imag = 0);
139  State(const State &obj );
140  ~State();
141  void init_state(complex<double> (*ini_state)(double x) );
142  void init_state(complex<double> (*ini_state)(double x, double y) );
143  void loadtxt(char *file_name);
144 
145  void imprint(complex<double> (*function)(double x) );
146  void imprint(complex<double> (*function)(double x, double y) );
147  double *get_particle_density(double *density = 0 );
148  double *get_phase(double *phase = 0 );
149  double get_expected_value(string _operator);
150  double get_squared_norm(void);
151  double get_mean_x(void);
152  double get_mean_xx(void);
153  double get_mean_y(void);
154  double get_mean_yy(void);
155  double get_mean_px(void);
156  double get_mean_pxpx(void);
157  double get_mean_py(void);
158  double get_mean_pypy(void);
159  double get_mean_angular_momentum(void);
160 
161  void write_to_file(string fileprefix );
162  void write_particle_density(string fileprefix );
163  void write_phase(string fileprefix );
165 
166 protected:
167  bool self_init;
168  void calculate_expected_values(void);
169  double mean_X, mean_XX;
170  double mean_Y, mean_YY;
171  double mean_Px, mean_PxPx;
172  double mean_Py, mean_PyPy;
174  double norm2;
175 };
176 
182 class BesselState: public State {
183 public:
195  BesselState(Lattice1D *grid, int angular_momentum = 0, int zeros = 1, double norm = 1, double phase = 0, double *p_real = 0, double *p_imag = 0);
196 
209  BesselState(Lattice2D *grid, int angular_momentum = 0, int zeros = 1, int n_y = 0, double norm = 1, double phase = 0, double *p_real = 0, double *p_imag = 0);
210 
211 private:
213  int zeros, n_y;
214  double zero;
215  double normalization;
216  double norm, phase;
217  complex<double> bessel_state1D(double x);
218  complex<double> bessel_state2D(double x, double y);
219 };
220 
226 class ExponentialState: public State {
227 public:
238  ExponentialState(Lattice1D *grid, int n_x = 1, double norm = 1, double phase = 0, double *p_real = 0, double *p_imag = 0);
239 
251  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);
252 
253 private:
254  int n_x, n_y;
255  double norm, phase;
256  complex<double> exp_state(double x, double y);
257 };
258 
264 class GaussianState: public State {
265 public:
277  GaussianState(Lattice1D *grid, double omega_x, double mean_x = 0, double norm = 1, double phase = 0,
278  double *p_real = 0, double *p_imag = 0);
279 
293  GaussianState(Lattice2D *grid, double omega_x, double omega_y = -1., double mean_x = 0, double mean_y = 0, double norm = 1, double phase = 0,
294  double *p_real = 0, double *p_imag = 0);
295 
296 private:
297  double mean_x;
298  double mean_y;
299  double omega_x;
300  double omega_y;
301  double norm;
302  double phase;
303  complex<double> gauss_state(double x, double y);
304 };
305 
311 class SinusoidState: public State {
312 public:
323  SinusoidState(Lattice1D *grid, int n_x = 1, double norm = 1, double phase = 0, double *p_real = 0, double *p_imag = 0);
324 
336  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);
337 
338 private:
339  int n_x, n_y;
340  double norm, phase;
341  complex<double> sinusoid_state(double x, double y);
342 };
343 
347 class Potential {
348 public:
349  Lattice *grid;
350  double *matrix;
351 
358  Potential(Lattice *grid, char *filename);
365  Potential(Lattice *grid, double *external_pot = 0);
372  Potential(Lattice *grid, double (*potential_function)(double x, double y));
379  Potential(Lattice *grid, double (*potential_function)(double x, double y, double t), int t = 0);
380  virtual ~Potential();
381  virtual double get_value(int x);
382  virtual double get_value(int x, int y);
383  bool update(double t);
384  bool updated_potential_matrix;
385 protected:
387  double (*static_potential)(double x, double y);
388  double (*evolving_potential)(double x, double y, double t);
389  bool self_init;
390  bool is_static;
391 };
392 
399 public:
410  HarmonicPotential(Lattice2D *grid, double omegax, double omegay, double mass = 1., double mean_x = 0., double mean_y = 0.);
412  double get_value(int x, int y);
413 
414 private:
415  double omegax, omegay;
416  double mass;
417  double mean_x, mean_y;
418 };
419 
423 class Hamiltonian {
424 public:
426  double mass;
427  double coupling_a;
430  double rot_coord_x;
431  double rot_coord_y;
432  double azimuthal_potential(double x, int angular_momentum);
433 
446  Hamiltonian(Lattice *grid, Potential *potential = 0, double mass = 1., double coupling_a = 0., double LeeHuangYang_coupling_a = 0.,
447  double angular_velocity = 0.,
448  double rot_coord_x = 0, double rot_coord_y = 0);
449  ~Hamiltonian();
450 
451 protected:
452  bool self_init;
453  Lattice *grid;
454 };
455 
460 public:
461  double mass_b;
462  double coupling_ab;
463  double coupling_b;
464  //double LeeHuangYang_coupling_b; ///< Coupling constant of the Lee-Huang-Yang term of the second component.
465  double omega_r;
466  double omega_i;
468  double azimuthal_potential_b(double x, int angular_momentum);
469 
487  Hamiltonian2Component(Lattice *grid, Potential *potential = 0,
488  Potential *potential_b = 0,
489  double mass = 1., double mass_b = 1.,
490  double coupling_a = 0.,/* double LeeHuangYang_coupling_a = 0.,*/ double coupling_ab = 0.,
491  double coupling_b = 0.,/* double LeeHuangYang_coupling_b = 0.,*/
492  double omega_r = 0, double omega_i = 0,
493  double angular_velocity = 0.,
494  double rot_coord_x = 0,
495  double rot_coord_y = 0);
497 };
498 
502 class ITrotterKernel {
503 public:
504  virtual ~ITrotterKernel() {};
505  virtual void run_kernel() = 0;
506  virtual void run_kernel_on_halo() = 0;
507  virtual void wait_for_completion() = 0;
508  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;
509  virtual void normalization() = 0;
510  virtual void rabi_coupling(double var, double delta_t) = 0;
511  virtual double calculate_squared_norm(bool global = true) const = 0;
512  virtual bool runs_in_place() const = 0;
513  virtual string get_name() const = 0;
514  virtual void update_potential(double *_external_pot_real, double *_external_pot_imag, int which) = 0;
515  virtual void cpy_first_positive_to_first_negative() = 0;
516 
517  virtual void start_halo_exchange() = 0;
518  virtual void finish_halo_exchange() = 0;
519 
520 };
521 
525 class Solver {
526 public:
527  Lattice *grid;
532 
541  Solver(Lattice *grid, State *state, Hamiltonian *hamiltonian, double delta_t,
542  string kernel_type = "cpu");
553  Solver(Lattice *grid, State *state1, State *state2,
554  Hamiltonian2Component *hamiltonian,
555  double delta_t, string kernel_type = "cpu");
556  ~Solver();
557  void evolve(int iterations, bool imag_time = false);
558  void update_parameters();
559  double get_total_energy(void);
560  double get_squared_norm(size_t which = 3 );
561  double get_kinetic_energy(size_t which = 3 );
562  double get_potential_energy(size_t which = 3 );
563  double get_rotational_energy(size_t which = 3 );
564  double get_intra_species_energy(size_t which = 3 );
565  double get_LeeHuangYang_energy(void);
566  double get_inter_species_energy(void);
567  double get_rabi_energy(void);
568  void set_exp_potential(double *real, int real_length, double *imag,
569  int imag_length, int which);
570 private:
571  bool imag_time;
572  double **external_pot_real;
573  double **external_pot_imag;
574  double delta_t;
575  double norm2[2];
577  string kernel_type;
578  ITrotterKernel * kernel;
579  void initialize_exp_potential(double time_single_it, int which);
580  void init_kernel();
581  double total_energy;
582  double kinetic_energy[2];
584  double potential_energy[2];
586  double rotational_energy[2];
588  double intra_species_energy[2];
592  double rabi_energy;
595  void calculate_energy_expected_values(void);
596  bool is_python;
597 };
598 
599 double const_potential(double x);
600 double const_potential(double x, double y);
601 void map_lattice_to_coordinate_space(Lattice *grid, int x_in, double *x_out);
602 void map_lattice_to_coordinate_space(Lattice *grid, int x_in, int y_in, double *x_out, double *y_out);
603 #endif // __TROTTERSUZUKI_H
double coupling_b
Coupling constant of the intra-particles interaction of the second component.
Definition: trottersuzuki.h:463
double omega_y
Gaussian coefficient.
Definition: trottersuzuki.h:300
double LeeHuangYang_energy
LeeHuangYang energy term.
Definition: trottersuzuki.h:590
double tot_potential_energy
Total potential energy of the system.
Definition: trottersuzuki.h:585
double mean_y
Y coordinate of the gaussian function&#39;s center.
Definition: trottersuzuki.h:298
double mean_angular_momentum
Expected value of the L_z operator.
Definition: trottersuzuki.h:173
int n_y
First and second quantum number.
Definition: trottersuzuki.h:254
double phase
Norm and phase of the state.
Definition: trottersuzuki.h:255
double rot_coord_y
Y coordinate of the center of rotation.
Definition: trottersuzuki.h:431
double * p_imag
Imaginary part of the wave function.
Definition: trottersuzuki.h:126
double * p_real
Real part of the wave function.
Definition: trottersuzuki.h:125
This class defines the Hamiltonian of a single component system.
Definition: trottersuzuki.h:423
State * state
State of the first component.
Definition: trottersuzuki.h:528
double current_evolution_time
Amount of time evolved since the beginning of the evolution.
Definition: trottersuzuki.h:386
double tot_intra_species_energy
Total intra-particles interaction energy of the system.
Definition: trottersuzuki.h:589
This class defines a quantum state with gaussian like wave function.
Definition: trottersuzuki.h:264
double ** external_pot_real
Real part of the evolution operator regarding the external potential.
Definition: trottersuzuki.h:572
double current_evolution_time
Amount of time evolved since the beginning of the evolution.
Definition: trottersuzuki.h:531
double zero
radial coordinate of the last zero.
Definition: trottersuzuki.h:214
This class defines the external potential that is used for Hamiltonian class.
Definition: trottersuzuki.h:347
Potential * potential_b
External potential for the second component.
Definition: trottersuzuki.h:467
This class defines the 2D lattice structure over which the state and potential matrices are defined...
Definition: trottersuzuki.h:83
State * state_b
State of the second component.
Definition: trottersuzuki.h:529
double * matrix
Matrix storing the potential.
Definition: trottersuzuki.h:350
bool self_init
Whether the external potential matrix has been initialized from the Potential constructor or not...
Definition: trottersuzuki.h:389
double LeeHuangYang_coupling_a
Coupling constant of the Lee-Huang-Yang term.
Definition: trottersuzuki.h:428
double omega_i
Imaginary part of the Rabi coupling.
Definition: trottersuzuki.h:466
Lattice * grid
Object that defines the lattice structure.
Definition: trottersuzuki.h:127
Hamiltonian * hamiltonian
Hamiltonian of the system; either single component or two components.
Definition: trottersuzuki.h:530
Lattice * grid
Lattice object.
Definition: trottersuzuki.h:527
double norm
Norm of the state.
Definition: trottersuzuki.h:301
double mean_PxPx
Expected values of the P_x and P_x^2 operators.
Definition: trottersuzuki.h:171
bool expected_values_updated
Whether the expected values of the state object are updated with respect to the last evolution...
Definition: trottersuzuki.h:164
double coupling_ab
Coupling constant of the inter-particles interaction.
Definition: trottersuzuki.h:462
double delta_t
A single evolution iteration, evolves the state for this time.
Definition: trottersuzuki.h:574
This class defines a quantum state with Bessel function of the first kind, along the radial coordinat...
Definition: trottersuzuki.h:182
bool energy_expected_values_updated
Whether the expectation values are updated or not.
Definition: trottersuzuki.h:594
double tot_rotational_energy
Total Rotational energy of the system.
Definition: trottersuzuki.h:587
bool self_init
Whether the potential is initialized in the Hamiltonian constructor or not.
Definition: trottersuzuki.h:452
int n_y
First and second quantum number.
Definition: trottersuzuki.h:339
This class defines the quantum state.
Definition: trottersuzuki.h:123
ITrotterKernel * kernel
Pointer to the kernel object.
Definition: trottersuzuki.h:578
Lattice * grid
Object that defines the lattice structure.
Definition: trottersuzuki.h:349
double tot_kinetic_energy
Total kinetic energy of the system.
Definition: trottersuzuki.h:583
double phase
Norm and phase of the state.
Definition: trottersuzuki.h:340
double normalization
Variable used for the normalization of the state.
Definition: trottersuzuki.h:215
double ** external_pot_imag
Imaginary part of the evolution operator regarding the external potential.
Definition: trottersuzuki.h:573
double phase
Norm and phase of the state.
Definition: trottersuzuki.h:216
double mean_PyPy
Expected values of the P_y and P_y^2 operators.
Definition: trottersuzuki.h:172
double rot_coord_x
X coordinate of the center of rotation.
Definition: trottersuzuki.h:430
bool is_static
Whether the external potential is static or time-dependent.
Definition: trottersuzuki.h:390
int angular_momentum
Angular momentum when cylindrical coordinates are used.
Definition: trottersuzuki.h:128
bool single_component
Whether the system is single-component(true) or two-components(false).
Definition: trottersuzuki.h:576
This class defines the evolution tasks.
Definition: trottersuzuki.h:525
double mean_y
Minimum of the potential along x and y axis.
Definition: trottersuzuki.h:417
This class defines the external potential that is used for Hamiltonian class.
Definition: trottersuzuki.h:398
double mass
Mass of the particle.
Definition: trottersuzuki.h:426
string kernel_type
Which kernel are being used (cpu or gpu).
Definition: trottersuzuki.h:577
double omega_r
Real part of the Rabi coupling.
Definition: trottersuzuki.h:465
double mean_XX
Expected values of the X and X^2 operators.
Definition: trottersuzuki.h:169
bool imag_time
Whether the time of evolution is imaginary(true) or real(false).
Definition: trottersuzuki.h:571
int n_y
First and second quantum number.
Definition: trottersuzuki.h:213
This class defines the Hamiltonian of a two component system.
Definition: trottersuzuki.h:459
double angular_velocity
The frame of reference rotates with this angular velocity.
Definition: trottersuzuki.h:429
double omega_x
Gaussian coefficient.
Definition: trottersuzuki.h:299
double phase
Relative phase of the wave function.
Definition: trottersuzuki.h:302
double total_energy
Total energy of the system.
Definition: trottersuzuki.h:581
double inter_species_energy
Inter-particles interaction energy of the system.
Definition: trottersuzuki.h:591
double mean_YY
Expected values of the Y and Y^2 operators.
Definition: trottersuzuki.h:170
double mass_b
Mass of the second component.
Definition: trottersuzuki.h:461
bool has_parameters_changed
Keeps track whether the Hamiltonian parameters were changed.
Definition: trottersuzuki.h:593
double omegay
Frequencies along x and y axis.
Definition: trottersuzuki.h:415
This class defines the 1D lattice structure over which the state and potential are defined...
Definition: trottersuzuki.h:64
Lattice * grid
Lattice object.
Definition: trottersuzuki.h:453
double mass
Mass of the particle.
Definition: trottersuzuki.h:416
This class defines a quantum state with sinusoidal like wave function.
Definition: trottersuzuki.h:311
double mean_x
X coordinate of the gaussian function&#39;s center.
Definition: trottersuzuki.h:297
Potential * potential
Potential object.
Definition: trottersuzuki.h:425
bool self_init
Whether the p_real and p_imag matrices have been initialized from the State constructor or not...
Definition: trottersuzuki.h:167
double coupling_a
Coupling constant of intra-particle interaction.
Definition: trottersuzuki.h:427
int angular_momentum
Angular momentum.
Definition: trottersuzuki.h:212
This class defines a quantum state with exponential like wave function.
Definition: trottersuzuki.h:226
double rabi_energy
Rabi energy of the system.
Definition: trottersuzuki.h:592
double norm2
Squared norm of the state.
Definition: trottersuzuki.h:174