GADGET-4
pm_nonperiodic.h
Go to the documentation of this file.
1 /*******************************************************************************
2  * \copyright This file is part of the GADGET4 N-body/SPH code developed
3  * \copyright by Volker Springel. Copyright (C) 2014-2020 by Volker Springel
4  * \copyright (vspringel@mpa-garching.mpg.de) and all contributing authors.
5  *******************************************************************************/
6 
12 #ifndef PM_NONPERIODIC_H
13 #define PM_NONPERIODIC_H
14 
15 #include "gadgetconfig.h"
16 
17 #include "../data/allvars.h"
18 #include "../data/dtypes.h"
19 #include "../data/intposconvert.h"
20 #include "../data/mymalloc.h"
21 #include "../data/simparticles.h"
22 #include "../domain/domain.h"
23 #include "../logs/timer.h"
24 #include "../mpi_utils/mpi_utils.h"
25 #include "../pm/pm_mpi_fft.h"
26 #include "../system/system.h"
27 #include "../time_integration/timestep.h"
28 
29 class pm_nonperiodic : public pm_mpi_fft
30 {
31  public:
32  pm_nonperiodic(MPI_Comm comm) : setcomm(comm), pm_mpi_fft(comm) {}
33 
34 #if defined(PMGRID) && (!defined(PERIODIC) || defined(PLACEHIGHRESREGION))
35 
36  private:
37 #if defined(LONG_X_BITS) || defined(LONG_Y_BITS) || defined(LONG_Z_BITS)
38 #error "LONG_X/Y/Z_BITS not supported for the non-periodic FFT gravity code"
39 #endif
40 
41 #if defined(GRAVITY_TALLBOX)
42 #error "GRAVITY_TALLBOX not supported for the non-periodic FFT gravity code"
43 #endif
44 
45 #if(HRPMGRID > 1024)
46  typedef long long large_array_offset; /* use a larger data type in this case so that we can always address all cells of the 3D grid
47  with a single index */
48 #else
49  typedef int large_array_offset;
50 #endif
51 
52 #ifdef NUMPART_PER_TASK_LARGE
53  typedef long long large_numpart_type; /* if there is a risk that the local particle number times 8 overflows a 32-bit integer, this
54  data type should be used */
55 #else
56  typedef int large_numpart_type;
57 #endif
58 
59  /* short-cut macros for accessing different 3D arrays */
60 
61  int NSource;
62 
63  fft_plan myplan;
68  size_t maxfftsize;
69 
80  fft_real *rhogrid, *forcegrid, *workspace;
81 
87  fft_complex *fft_of_rhogrid;
88 
89  fft_real *kernel[2];
90  fft_complex *fft_of_kernel[2];
91 
92  public:
93  simparticles *Sp;
94 
95  void pm_init_nonperiodic(simparticles *Sp_ptr);
96  void pm_init_regionsize(void);
97  int pmforce_nonperiodic(int grnr);
98  void pm_setup_nonperiodic_kernel(void);
99  void pmforce_nonperiodic_zoom_optimized_prepare_density(int grnr);
100 
101  private:
102 #ifdef PM_ZOOM_OPTIMIZED
103 
104  void pmforce_nonperiodic_zoom_optimized_readout_forces_or_potential(int grnr, int dim);
105 
112  struct part_slab_data
113  {
114  large_array_offset globalindex;
115  large_numpart_type partindex;
117  large_array_offset localindex;
119  };
120  part_slab_data *part;
122  size_t *localfield_sendcount, *localfield_first, *localfield_offset, *localfield_recvcount;
123  large_array_offset *localfield_globalindex, *import_globalindex;
124  fft_real *localfield_data, *import_data;
125  large_numpart_type num_on_grid;
126 
127  /* realize the comparison function as a functor, so that it can have an internal state (here the data array for which we sort indices
128  */
129  struct pm_nonperiodic_sortindex_comparator
130  {
131  private:
132  const part_slab_data *data;
133 
134  public:
135  pm_nonperiodic_sortindex_comparator(const part_slab_data *data_) : data(data_) {}
136 
137  bool operator()(const large_numpart_type &a, const large_numpart_type &b) const
138  {
139  return data[a].globalindex < data[b].globalindex;
140  }
141  };
142 
143 #else
144 
145  /*
146  * Here come the routines for a different communication algorithm that is better suited for a homogenuously loaded boxes.
147  */
148  struct partbuf
149  {
150  MyIntPosType IntPos[3];
151  MyFloat Mass;
152  };
153  partbuf *partin, *partout;
154 
155  size_t nimport, nexport;
156 
157  size_t *Sndpm_count, *Sndpm_offset;
158  size_t *Rcvpm_count, *Rcvpm_offset;
159 
160  void pmforce_nonperiodic_uniform_optimized_prepare_density(int grnr);
161  void pmforce_nonperiodic_uniform_optimized_readout_forces_or_potential(int grnr, int dim);
162 
163 #endif
164 
165 #endif
166 };
167 
168 #endif
pm_nonperiodic(MPI_Comm comm)
float MyFloat
Definition: dtypes.h:86
uint32_t MyIntPosType
Definition: dtypes.h:35