cholla
grid3D.h
Go to the documentation of this file.
1 
4 #ifndef GRID3D_H
5 #define GRID3D_H
6 
7 #ifdef MPI_CHOLLA
8 #include"mpi_routines.h"
9 #endif /*MPI_CHOLLA*/
10 
11 #include<stdio.h>
12 #include"global.h"
13 
14 #ifdef HDF5
15 #include<hdf5.h>
16 #endif
17 
18 #ifdef GRAVITY
19 #include"gravity/grav3D.h"
20 #endif
21 
22 #ifdef PARTICLES
23 #include "particles/particles_3D.h"
24 #endif
25 
26 #ifdef COSMOLOGY
27 #include"cosmology/cosmology.h"
28 #endif
29 
30 #ifdef COOLING_GRACKLE
31 #include "cooling/cool_grackle.h"
32 #endif
33 
34 #ifdef CPU_TIME
35 #include "timing_functions.h"
36 #endif
37 
38 struct Rotation
39 {
42  int nx;
43 
46  int nz;
47 
50  int nx_min;
51 
54  int nx_max;
55 
58  int nz_min;
59 
62  int nz_max;
63 
66  Real delta;
67 
70  Real theta;
71 
74  Real phi;
75 
78  Real Lx;
79 
82  Real Lz;
83 
86  int i_delta;
87 
90  Real n_delta;
91 
94  Real ddelta_dt;
95 
99 };
100 
101 struct Header
102 {
105  int n_cells;
106 
109  int n_ghost;
110 
113  int nx;
114 
117  int ny;
118 
121  int nz;
122 
125  int nx_real;
126 
129  int ny_real;
130 
133  int nz_real;
134 
136  /* \brief Global domain x-direction minimum */
137  Real xbound;
138 
140  /* \brief Global domain y-direction minimum */
141  Real ybound;
142 
144  /* \brief Global domain z-direction minimum */
145  Real zbound;
146 
148  /* \brief Local domain length in x-direction */
149  Real domlen_x;
150 
152  /* \brief Local domain length in y-direction */
153  Real domlen_y;
154 
156  /* \brief Local domain length in z-direction */
157  Real domlen_z;
158 
160  /* \brief Local domain x-direction minimum */
161  Real xblocal;
162 
164  /* \brief Local domain y-direction minimum */
165  Real yblocal;
166 
168  /* \brief Local domain z-direction minimum */
169  Real zblocal;
170 
172  /* \brief Global domain length in x-direction */
173  Real xdglobal;
174 
176  /* \brief Global domain length in y-direction */
177  Real ydglobal;
178 
180  /* \brief Global domain length in z-direction */
181  Real zdglobal;
182 
185  Real dx;
186 
189  Real dy;
190 
193  Real dz;
194 
197  Real t;
198 
201  Real dt;
202 
203  #ifdef AVERAGE_SLOW_CELLS
204  Real min_dt_slow;
205  #endif
206 
209  Real t_wall;
210 
213  int n_step;
214 
217  int n_fields;
218 
219  // Values for lower limit for density and temperature
220  Real density_floor;
221  Real temperature_floor;
222 
223  Real Ekin_avrg;
224 
225  //Flag to indicate when to transfer the Conserved boundaries
226  bool TRANSFER_HYDRO_BOUNDARIES;
227 
228  #ifdef GRAVITY
229 
231  int n_ghost_potential_offset;
232  #endif
233 
234  #ifdef COSMOLOGY
235  bool OUTPUT_SCALE_FACOR;
236  #endif
237 
241  bool Output_Initial;
242 
246 
247 
248 };
249 
252 class Grid3D
253 {
254  public:
255 
259 
262  int gflag;
263 
266  struct Header H;
267 
270  struct Rotation R;
271 
274  Real *buffer0;
275 
278  Real *buffer1;
279 
280  #ifdef GRAVITY
281  // Object that contains data for gravity
282  Grav3D Grav;
283  #endif
284 
285  #ifdef PARTICLES
286  // Object that contains data for particles
287  Particles_3D Particles;
288  #endif
289 
290  #ifdef COSMOLOGY
291  // Object that contains data for cosmology
292  Cosmology Cosmo;
293  #endif
294 
295  #ifdef COOLING_GRACKLE
296  // Object that contains data for Grackle cooling
297  Cool_GK Cool;
298  #endif
299 
300  #ifdef CPU_TIME
301  Time Timer;
302  #endif
303 
304  struct Conserved
305  {
308  Real *density;
309 
312  Real *momentum_x;
313 
316  Real *momentum_y;
317 
320  Real *momentum_z;
321 
324  Real *Energy;
325 
326  #ifdef DE
327 
330  Real *GasEnergy;
331  #endif
332 
333  #ifdef SCALAR
334 
336  Real *scalar;
337  #endif
338 
341  Real *Grav_potential;
342 
343 
344  } C;
345 
346 
349  Grid3D(void);
350 
353  void Initialize(struct parameters *P);
354 
357  void AllocateMemory(void);
358 
361  void Set_Initial_Conditions(parameters P);
362 
365  void Get_Position(long i, long j, long k, Real *xpos, Real *ypos, Real *zpos);
366 
369  void Set_Domain_Properties(struct parameters P);
370 
373  void set_dt(Real dti);
374 
375  #ifdef GRAVITY
376 
378  void set_dt_Gravity();
379  #endif
380 
383  Real calc_dti_CPU_1D();
384 
387  Real calc_dti_CPU_2D();
388 
391  Real calc_dti_CPU_3D_function( int g_start, int g_end );
392 
395  Real calc_dti_CPU_3D();
396 
399  Real calc_dti_CPU();
400 
403  Real Update_Grid(void);
404 
407  Real Update_Hydro_Grid(void);
408 
409  void Update_Time();
410 
413  void Write_Header_Binary(FILE *fp);
414 
417  void Write_Grid_Binary(FILE *fp);
418 
419 #ifdef HDF5
420 
422  void Write_Header_HDF5(hid_t file_id);
423 
426  void Write_Grid_HDF5(hid_t file_id);
427 
430  void Write_Projection_HDF5(hid_t file_id);
431 
434  void Write_Header_Rotated_HDF5(hid_t file_id);
435 
438  void Write_Rotated_Projection_HDF5(hid_t file_id);
439 
442  void Write_Slices_HDF5(hid_t file_id);
443 
444 #endif
445 
448  void Read_Grid(struct parameters P);
449 
452  void Read_Grid_Binary(FILE *fp);
453 
454 #ifdef HDF5
455 
457  void Read_Grid_HDF5(hid_t file_id, struct parameters P);
458 #endif
459 
462  void Reset(void);
463 
466  void FreeMemory(void);
467 
470  void Constant(Real rho, Real vx, Real vy, Real vz, Real P);
471 
474  void Sound_Wave(Real rho, Real vx, Real vy, Real vz, Real P, Real A);
475 
478  void Square_Wave(Real rho, Real vx, Real vy, Real vz, Real P, Real A);
479 
482  void Riemann(Real rho_l, Real v_l, Real P_l, Real rho_r, Real v_r, Real P_r, Real diaph);
483 
486  void Shu_Osher();
487 
490  void Blast_1D();
491 
494  void KH();
495 
498  void KH_res_ind();
499 
502  void Rayleigh_Taylor();
503 
506  void Gresho();
507 
510  void Implosion_2D();
511 
514  void Explosion_2D();
515 
518  void Noh_2D();
519 
522  void Noh_3D();
523 
526  void Disk_2D();
527 
530  void Disk_3D(parameters P);
531 
534  void Set_Boundary_Conditions(parameters P);
535 
538  void Set_Boundary_Conditions_Grid( parameters P);
539 
542  int Check_Custom_Boundary(int *flags, struct parameters P);
543 
546  void Set_Boundaries(int dir, int flags[]);
547 
550  void Set_Boundary_Extents(int dir, int *imin, int *imax);
551 
555  int Set_Boundary_Mapping(int ig, int jg, int kg, int flags[], Real *a);
556 
560  int Find_Index(int ig, int nx, int flag, int face, Real *a);
561 
564  void Custom_Boundary(char bcnd[MAXLEN]);
565 
569  void Noh_Boundary();
570 
573  void Spherical_Overpressure_3D();
574 
577  void Spherical_Overdensity_3D();
578 
579  void Uniform_Grid();
580 
581  void Zeldovich_Pancake( struct parameters P );
582 
583 
584 #ifdef MPI_CHOLLA
585  void Set_Boundaries_MPI(struct parameters P);
586  void Set_Boundaries_MPI_SLAB(int *flags, struct parameters P);
587  void Set_Boundaries_MPI_BLOCK(int *flags, struct parameters P);
588  void Set_Edge_Boundaries(int dir, int *flags);
589  void Set_Edge_Boundary_Extents(int dir, int edge, int *imin, int *imax);
590  void Load_and_Send_MPI_Comm_Buffers(int dir, int *flags);
591  void Load_and_Send_MPI_Comm_Buffers_SLAB(int *flags);
592  void Load_and_Send_MPI_Comm_Buffers_BLOCK(int dir, int *flags);
593  void Wait_and_Unload_MPI_Comm_Buffers_SLAB(int *flags);
594  void Wait_and_Unload_MPI_Comm_Buffers_BLOCK(int dir, int *flags);
595  void Unload_MPI_Comm_Buffers(int index);
596  void Unload_MPI_Comm_Buffers_SLAB(int index);
597  void Unload_MPI_Comm_Buffers_BLOCK(int index);
598  int Load_Hydro_Buffer_X0();
599  int Load_Hydro_Buffer_X1();
600  int Load_Hydro_Buffer_Y0();
601  int Load_Hydro_Buffer_Y1();
602  int Load_Hydro_Buffer_Z0();
603  int Load_Hydro_Buffer_Z1();
604 #endif /*MPI_CHOLLA*/
605 
606  #ifdef GRAVITY
607  void Initialize_Gravity( struct parameters *P );
608  void Compute_Gravitational_Potential( struct parameters *P );
609  void Copy_Hydro_Density_to_Gravity_Function( int g_start, int g_end);
610  void Copy_Hydro_Density_to_Gravity();
611  void Extrapolate_Grav_Potential_Function( int g_start, int g_end );
612  void Extrapolate_Grav_Potential();
613  void Copy_Potential_Boundaries( int direction, int side );
614  int Load_Gravity_Potential_To_Buffer( int direction, int side, Real *buffer, int buffer_start );
615  void Unload_Gravity_Potential_from_Buffer( int direction, int side, Real *buffer, int buffer_start );
616  #endif//GRAVITY
617 
618  #ifdef PARTICLES
619  void Initialize_Particles( struct parameters *P );
620  void Initialize_Uniform_Particles();
621  void Copy_Particles_Density_function( int g_start, int g_end );
622  void Copy_Particles_Density();
623  void Copy_Particles_Density_to_Gravity(struct parameters P);
624  void Copy_Particles_Density_Boundaries( int direction, int side );
625  void Transfer_Particles_Boundaries( struct parameters P );
626  Real Update_Grid_and_Particles_KDK( struct parameters P );
627  void Set_Particles_Boundary( int dir, int side);
628  #ifdef MPI_CHOLLA
629  int Load_Particles_Density_Boundary_to_Buffer( int direction, int side, Real *buffer );
630  void Unload_Particles_Density_Boundary_From_Buffer( int direction, int side, Real *buffer );
631  void Load_and_Send_Particles_X0( int ireq_n_particles, int ireq_particles_transfer );
632  void Load_and_Send_Particles_X1( int ireq_n_particles, int ireq_particles_transfer );
633  void Load_and_Send_Particles_Y0( int ireq_n_particles, int ireq_particles_transfer );
634  void Load_and_Send_Particles_Y1( int ireq_n_particles, int ireq_particles_transfer );
635  void Load_and_Send_Particles_Z0( int ireq_n_particles, int ireq_particles_transfer );
636  void Load_and_Send_Particles_Z1( int ireq_n_particles, int ireq_particles_transfer );
637  void Unload_Particles_from_Buffer_X0( int *flags );
638  void Unload_Particles_from_Buffer_X1( int *flags );
639  void Unload_Particles_from_Buffer_Y0( int *flags );
640  void Unload_Particles_from_Buffer_Y1( int *flags );
641  void Unload_Particles_from_Buffer_Z0( int *flags );
642  void Unload_Particles_from_Buffer_Z1( int *flags );
643  void Wait_NTransfer_and_Request_Recv_Particles_Transfer_BLOCK(int dir, int *flags);
644  void Load_NTtransfer_and_Request_Receive_Particles_Transfer(int index, int *ireq_particles_transfer);
645  void Wait_and_Unload_MPI_Comm_Particles_Buffers_BLOCK(int dir, int *flags);
646  void Unload_Particles_From_Buffers_BLOCK(int index, int *flags );
647  void Finish_Particles_Transfer();
648  #endif//MPI_CHOLLA
649  void Transfer_Particles_Density_Boundaries( struct parameters P );
650  // void Transfer_Particles_Boundaries( struct parameters P );
651  void WriteData_Particles( struct parameters P, int nfile);
652  void OutputData_Particles( struct parameters P, int nfile);
653  void Load_Particles_Data( struct parameters P);
654  #ifdef HDF5
655  void Write_Particles_Header_HDF5( hid_t file_id);
656  void Write_Particles_Data_HDF5( hid_t file_id);
657  void Load_Particles_Data_HDF5(hid_t file_id, int nfile);
658  #endif//HDF5
659  void Get_Gravity_Field_Particles_function( int g_start, int g_end );
660  void Get_Gravity_Field_Particles();
661  void Get_Gravity_CIC_function( part_int_t p_start, part_int_t p_end );
662  void Get_Gravity_CIC();
663  void Advance_Particles_KDK_Step1( );
664  void Advance_Particles_KDK_Step2( );
665  void Advance_Particles_KDK_Step1_function( part_int_t p_start, part_int_t p_end );
666  void Advance_Particles_KDK_Step2_function( part_int_t p_start, part_int_t p_end );
667  void Get_Particles_Acceleration();
668  void Advance_Particles( int N_KDK_step );
669  Real Calc_Particles_dt_function( part_int_t p_start, part_int_t p_end );
670  Real Calc_Particles_dt();
671  #ifdef PARTICLES_GPU
672  Real Calc_Particles_dt_GPU();
673  void Advance_Particles_KDK_Step1_GPU();
674  void Advance_Particles_KDK_Step2_GPU();
675  void Set_Particles_Boundary_GPU( int dir, int side);
676  #endif//PARTICLES_GPU
677  #endif//PARTICLES
678 
679  #ifdef COSMOLOGY
680  void Initialize_Cosmology( struct parameters *P );
681  void Change_DM_Frame_System( bool forward );
682  void Change_GAS_Frame_System( bool forward );
683  void Change_Cosmological_Frame_Sytem( bool forward );
684  void Advance_Particles_KDK_Cosmo_Step1_function( part_int_t p_start, part_int_t p_end );
685  void Advance_Particles_KDK_Cosmo_Step2_function( part_int_t p_start, part_int_t p_end );
686  Real Calc_Particles_dt_Cosmo_function( part_int_t p_start, part_int_t p_end );
687  Real Calc_Particles_dt_Cosmo();
688  #ifdef PARTICLES_GPU
689  void Advance_Particles_KDK_Cosmo_Step1_GPU();
690  void Advance_Particles_KDK_Cosmo_Step2_GPU();
691  #endif//PARTICLES_GPU
692  #endif//COSMOLOGY
693 
694  #ifdef COOLING_GRACKLE
695  void Initialize_Grackle( struct parameters *P );
696  void Allocate_Memory_Grackle();
697  void Initialize_Fields_Grackle();
698  void Copy_Fields_To_Grackle_function( int g_start, int g_end );
699  void Copy_Fields_To_Grackle();
700  void Update_Internal_Energy_function( int g_start, int g_end );
701  void Update_Internal_Energy();
702  void Do_Cooling_Step_Grackle();
703  #endif
704 
705 
706 };
707 
708 
709 
710 #endif //GRID3D_H
int nz_min
Bottom most point in the projected image for this subvolume.
Definition: grid3D.h:58
Definition: grid3D.h:38
Real t
Simulation time.
Definition: grid3D.h:197
Real t_wall
Wall time.
Definition: grid3D.h:209
Real phi
Rotation angle about y axis in simulation frame.
Definition: grid3D.h:74
Real dy
y-width of cells
Definition: grid3D.h:189
Definition: grid3D.h:101
Definition: global.h:154
int i_delta
number of output projection for delta rotation
Definition: grid3D.h:86
int nx_real
Number of real cells in the x-dimension.
Definition: grid3D.h:125
int nx
Number of pixels in x-dir of rotated, projected image.
Definition: grid3D.h:42
Real dt
Length of the current timestep.
Definition: grid3D.h:201
int flag_delta
output mode for box rotation
Definition: grid3D.h:98
Real * momentum_x
Array containing the momentum in the x direction of each cell in the grid.
Definition: grid3D.h:312
Real theta
Rotation angle about x axis in simulation frame.
Definition: grid3D.h:70
int flag_init
Initialization flag.
Definition: grid3D.h:258
bool Output_Complete_Data
Flag set to true when all the data will be written to file (Restart File )
Definition: grid3D.h:245
Real ddelta_dt
rate of delta rotation
Definition: grid3D.h:94
Real delta
Rotation angle about z axis in simulation frame.
Definition: grid3D.h:66
Real * momentum_z
Array containing the momentum in the z direction of each cell in the grid.
Definition: grid3D.h:320
Definition: grav3D.h:27
int n_fields
Number of fields (conserved variables, scalars, etc.)
Definition: grid3D.h:217
Real * density
Array containing the density of each cell in the grid.
Definition: grid3D.h:308
Real * Energy
Array containing the total Energy of each cell in the grid.
Definition: grid3D.h:324
int gflag
Flag that determines which buffer contains updated conserved variables.
Definition: grid3D.h:262
bool Output_Now
Flag set to true when data has to be written to file.
Definition: grid3D.h:240
int n_ghost
Number of ghost cells on each side of the grid.
Definition: grid3D.h:109
Real * buffer0
Buffer to hold conserved variable arrays.
Definition: grid3D.h:274
Real dz
z-width of cells
Definition: grid3D.h:193
int nz_max
Top most point in the projected image for this subvolume.
Definition: grid3D.h:62
Class to create a the gravity object.
Definition: grid3D.h:252
int nx
Total number of cells in the x-dimension.
Definition: grid3D.h:113
Real n_delta
total number of output projection for delta rotation
Definition: grid3D.h:90
int nz
Number of pixels in z-dir of rotated, projected image.
Definition: grid3D.h:46
int n_step
Number of timesteps taken.
Definition: grid3D.h:213
Real Lx
Physical x-dir size of projected image.
Definition: grid3D.h:78
int nz
Total number of cells in the z-dimension.
Definition: grid3D.h:121
Definition: grid3D.h:304
Real * buffer1
Buffer to hold conserved variable arrays.
Definition: grid3D.h:278
int nx_max
Right most point in the projected image for this subvolume.
Definition: grid3D.h:54
int ny
Total number of cells in the y-dimension.
Definition: grid3D.h:117
int n_cells
Total number of cells in the grid (including ghost cells)
Definition: grid3D.h:105
Real Lz
Physical z-dir size of projected image.
Definition: grid3D.h:82
int nx_min
Left most point in the projected image for this subvolume.
Definition: grid3D.h:50
Real dx
x-width of cells
Definition: grid3D.h:185
Real * momentum_y
Array containing the momentum in the y direction of each cell in the grid.
Definition: grid3D.h:316