GPUE  v1.0
GPU Gross-Pitaevskii Equation numerical solver for Bose-Einstein condensates
ds.cu
Go to the documentation of this file.
1 
2 #include "../include/ds.h"
3 #include "../include/operators.h"
4 
5 /*----------------------------------------------------------------------------//
6 * AUX
7 *-----------------------------------------------------------------------------*/
8 
9 // I didn't know where to place these functions for now, so the'll be here
10 void generate_plan_other2d(cufftHandle *plan_fft1d, Grid &par){
11  // We need a number of propertied for this fft / transform
12  int xDim = par.ival("xDim");
13  int yDim = par.ival("yDim");
14 
15  int batch = yDim;
16  int rank = 1;
17  int n[] = {xDim, yDim};
18  int idist = 1;
19  int odist = 1;
20  int inembed[] = {xDim,yDim};
21  int onembed[] = {xDim,yDim};
22  int istride = yDim;
23  int ostride = yDim;
24 
25  cufftResult result;
26 
27  result = cufftPlanMany(plan_fft1d, rank, n, inembed, istride,
28  idist, onembed, ostride, odist,
29  CUFFT_Z2Z, batch);
30 
31  if(result != CUFFT_SUCCESS){
32  printf("Result:=%d\n",result);
33  printf("Error: Could not execute cufftPlanfft1d(%s ,%d ,%d ).\n",
34  "plan_1d", (unsigned int)xDim, (unsigned int)yDim);
35  exit(1);
36  }
37 
38 }
39 
40 // other plan for 3d case
41 // Note that we have 3 cases to deal with here: x, y, and z
42 void generate_plan_other3d(cufftHandle *plan_fft1d, Grid &par, int axis){
43  int xDim = par.ival("xDim");
44  int yDim = par.ival("yDim");
45  int zDim = par.ival("zDim");
46 
47  cufftResult result;
48 
49  // Along first dimension (z)
50  if (axis == 0){
51  result = cufftPlan1d(plan_fft1d, xDim, CUFFT_Z2Z, yDim*zDim);
52  }
53 
54  // Along second dimension (y)
55  // This one is a bit complicated because of how the data is aligned
56  else if (axis == 1){
57  int batch = yDim;
58  int rank = 1;
59  int n[] = {xDim, yDim};
60  int idist = 1;
61  int odist = 1;
62  int inembed[] = {xDim, yDim};
63  int onembed[] = {xDim, yDim};
64  int istride = yDim;
65  int ostride = yDim;
66 
67  result = cufftPlanMany(plan_fft1d, rank, n, inembed, istride,
68  idist, onembed, ostride, odist,
69  CUFFT_Z2Z, batch);
70  //result = cufftPlan2d(plan_fft1d, xDim, yDim, CUFFT_Z2Z);
71 
72  }
73 
74  // Along third dimension (x)
75  else if (axis == 2){
76 
77  int batch = xDim*yDim;
78  int rank = 1;
79  int n[] = {xDim, yDim, zDim};
80  int idist = 1;
81  int odist = 1;
82  int inembed[] = {xDim, yDim, zDim};
83  int onembed[] = {xDim, yDim, zDim};
84  int istride = xDim*yDim;
85  int ostride = xDim*yDim;
86 
87  result = cufftPlanMany(plan_fft1d, rank, n, inembed, istride,
88  idist, onembed, ostride, odist,
89  CUFFT_Z2Z, batch);
90  }
91 
92  if(result != CUFFT_SUCCESS){
93  printf("Result:=%d\n",result);
94  printf("Error: Could not execute cufftPlan3d(%s ,%d ,%d ).\n",
95  "plan_1d", (unsigned int)xDim, (unsigned int)yDim);
96  exit(1);
97  }
98 
99 }
100 
101 // Function to set functionPtrs without an unordered map
102 void set_fns(Grid &par){
103 
104  // There are 3 different function distributions to keep in mind:
105  // Vfn, Afn, wfcfn
106 
107  // Vfn
108  par.set_V_fn(par.Vfn);
109 
110  // Afn
111  par.set_A_fn(par.Afn);
112 
113  // Wfcfn
114  par.set_wfc_fn(par.Wfcfn);
115 
116 }
117 
118 
119 /*----------------------------------------------------------------------------//
120 * GRID
121 *-----------------------------------------------------------------------------*/
122 
123 // Function to store sobel_fft operators and stuff
124 void Grid::store(std::string id, cufftDoubleComplex *d2param){
125  sobel[id] = d2param;
126 }
127 
128 // Function to store integer into Grid->param_int
129 void Grid::store(std::string id, int iparam){
130  param_int[id] = iparam;
131 }
132 
133 // Function to store double into Grid->param_double
134 void Grid::store(std::string id, double dparam){
135  param_double[id] = dparam;
136 }
137 
138 // Function to store double* into param_dstar
139 void Grid::store(std::string id, double *dsparam){
140  param_dstar[id] = dsparam;
141 }
142 
143 // Function to store bool into param_bool
144 void Grid::store(std::string id, bool bparam){
145  param_bool[id] = bparam;
146 }
147 
148 // Function to store string into data_dir
149 void Grid::store(std::string id, std::string sparam){
150  param_string[id] = sparam;
151 }
152 
153 // Function to store asts into data_dir
154 void Grid::store(std::string id, EqnNode_gpu *ensparam){
155  param_ast[id] = ensparam;
156 }
157 
158 // Function to store asts into data_dir
159 void Grid::store(std::string id, EqnNode astparam){
160  param_ast_cpu[id] = astparam;
161 }
162 
163 // Two boolean functions to check whether a string exists in
164 // param_double or param_dstar
165 bool Grid::is_double(std::string id){
166  auto it = param_double.find(id);
167  if (it != param_double.end()){
168  return true;
169  }
170  else {
171  return false;
172  }
173 }
174 
175 bool Grid::is_dstar(std::string id){
176  auto it = param_dstar.find(id);
177  if (it != param_dstar.end()){
178  return true;
179  }
180  else {
181  return false;
182  }
183 }
184 
185 bool Grid::is_ast_gpu(std::string id){
186  auto it = param_ast.find(id);
187  if (it != param_ast.end()){
188  return true;
189  }
190  else {
191  return false;
192  }
193 }
194 
195 bool Grid::is_ast_cpu(std::string id){
196  auto it = param_ast_cpu.find(id);
197  if (it != param_ast_cpu.end()){
198  return true;
199  }
200  else {
201  return false;
202  }
203 }
204 
205 // Function to retrieve integer from Grid->param_int
206 int Grid::ival(std::string id){
207  return param_int[id];
208 }
209 
210 // Function to retrieve double from Grid->param_double
211 double Grid::dval(std::string id){
212  auto it = param_double.find(id);
213  if (it == param_double.end()){
214  std::cout << "ERROR: could not find string " << id
215  << " in Grid::param_double." << '\n';
216  assert(it != param_double.end());
217  }
218  return it->second;
219 }
220 
221 // Function to retrieve double star values from param_dstar
222 double *Grid::dsval(std::string id){
223  auto it = param_dstar.find(id);
224  if (it == param_dstar.end()){
225  std::cout << "ERROR: could not find string " << id
226  << " in Grid::param_dstar." << '\n';
227  assert(it != param_dstar.end());
228  }
229  return it->second;
230 }
231 
232 // Function to retrieve bool values from param_bool
233 bool Grid::bval(std::string id){
234  auto it = param_bool.find(id);
235  if (it == param_bool.end()){
236  std::cout << "ERROR: could not find string " << id
237  << " in Grid::param_bool." << '\n';
238  assert(it != param_bool.end());
239  }
240  return it->second;
241 }
242 
243 // Function to retrieve string from data_dir
244 std::string Grid::sval(std::string id){
245  auto it = param_string.find(id);
246  if (it == param_string.end()){
247  std::cout << "ERROR: could not find string " << id
248  << " in Grid::param_string." << '\n';
249  assert(it != param_string.end());
250  }
251  return it->second;
252 }
253 
254 // Function to call back the sobel operators
255 cufftDoubleComplex *Grid::cufftDoubleComplexval(std::string id){
256  auto it = sobel.find(id);
257  if (it == sobel.end()){
258  std::cout << "ERROR: could not find string " << id
259  << " in Grid::sobel." << '\n';
260  assert(it != sobel.end());
261  }
262  return it->second;
263 }
264 
265 // Function to call back the ast's
266 EqnNode_gpu *Grid::astval(std::string id){
267  auto it = param_ast.find(id);
268  if (it == param_ast.end()){
269  std::cout << "ERROR: could not find string " << id
270  << " in Grid::param_ast." << '\n';
271  assert(it != param_ast.end());
272  }
273  return it->second;
274 }
275 
276 // Function to call back the ast's
277 EqnNode Grid::ast_cpuval(std::string id){
278  auto it = param_ast_cpu.find(id);
279  if (it == param_ast_cpu.end()){
280  std::cout << "ERROR: could not find string " << id
281  << " in Grid::param_ast_cpu." << '\n';
282  assert(it != param_ast_cpu.end());
283  }
284  return it->second;
285 }
286 
287 
288 // Function for file writing (to replace fileIO::writeOutParam)
289 void Grid::write(std::string filename){
290  std::ofstream output;
291  output.open(filename);
292 
293  //Needed to recognise Params.dat as .ini format for python post processing
294  output << "[Params]" <<"\n";
295 
296  // We simply iterate through the int and double param maps
297  for (auto item : param_double){
298  output << item.first << "=" << item.second << '\n';
299  std::cout << item.first << "=" << item.second << '\n';
300  }
301 
302  for (auto item : param_int){
303  output << item.first << "=" << item.second << '\n';
304  std::cout << item.first << "=" << item.second << '\n';
305  }
306 
307  output.close();
308 }
309 
310 // Function to print all available variables
311 void Grid::print_map(){
312  for (auto item : param_double){
313  std::cout << item.first << '\n';
314  }
315  for (auto item : param_dstar){
316  std::cout << item.first << '\n';
317  }
318 }
319 
320 void Grid::set_A_fn(std::string id){
321  if (id == "rotation"){
322  Ax_fn = krotation_Ax;
323  Ay_fn = krotation_Ay;
324  Az_fn = kconstant_A;
325  }
326  else if (id == "ring_rotation"){
327  Ax_fn = kring_rotation_Ax;
328  Ay_fn = kring_rotation_Ay;
329  Az_fn = kring_rotation_Az;
330  }
331  else if (id == "constant"){
332  Ax_fn = kconstant_A;
333  Ay_fn = kconstant_A;
334  Az_fn = kconstant_A;
335  }
336  else if (id == "ring"){
337  Ax_fn = kconstant_A;
338  Ay_fn = kconstant_A;
339  Az_fn = kring_Az;
340  }
341  else if (id == "test"){
342  Ax_fn = ktest_Ax;
343  Ay_fn = ktest_Ay;
344  Az_fn = kconstant_A;
345  }
346  else if (id == "file"){
347  Ax_fn = nullptr;
348  Ay_fn = nullptr;
349  Az_fn = nullptr;
350  }
351 }
352 
353 void Grid::set_wfc_fn(std::string id){
354  if (id == "2d" || id == "3d"){
355  wfc_fn = kstd_wfc;
356  }
357  else if(id == "torus"){
358  wfc_fn = ktorus_wfc;
359  }
360 }
361 
362 void Grid::set_V_fn(std::string id){
363  if (id == "2d"){
364  V_fn = kharmonic_V;
365  }
366  else if (id == "torus"){
367  V_fn = ktorus_V;
368  }
369  else if(id == "3d"){
370  V_fn = kharmonic_V;
371  }
372 }
373