GPUE  v1.0
GPU Gross-Pitaevskii Equation numerical solver for Bose-Einstein condensates
ds.h
Go to the documentation of this file.
1 //##############################################################################
16  //#############################################################################
17 
18 #ifndef DS_H
19 #define DS_H
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <string>
23 #include <string.h>
24 #include <unordered_map>
25 #include <vector>
26 #include <fstream>
27 #include <cuda.h>
28 #include <cuda_runtime.h>
29 #include <cufft.h>
30 #include <typeinfo>
31 #include <cassert>
32 #include <iostream>
33 
34 /*----------------------------------------------------------------------------//
35 * CLASSES
36 *-----------------------------------------------------------------------------*/
37 
42 struct pos{
43  double x, y, z;
44 };
45 
50 typedef double (*fnPtr) (double, double);
51 
56 struct EqnNode{
57  double val = 0;
58  bool is_dynamic = false;
59  char var = '0';
60 
62 
63  int op_num;
64  bool has_op = false;
65 };
66 
71 struct EqnNode_gpu{
72  double val = 0;
73  bool is_dynamic = false;
74  char var = '0';
75 
76  int left = -1;
77  int right = -1;
78 
79  int op_num;
80 };
81 
86 class Grid{
87  // Here we keep our variable map (unordered for performance)
88  // and also grid information. Note that dx dy, and dz are in param_double
89  private:
90  typedef void (*functionPtrA)(double*, double*, double*,
91  double, double, double,
92  double, double, double,
93  double, double, double*);
94  typedef void (*functionPtrV)(double*, double*, double*, double*,
95  double*, double*, double*, double*);
96  typedef void (*functionPtrwfc)(double*, double*, double*,
97  double*, double, double*, double2*);
98  std::unordered_map<std::string, int> param_int;
99  std::unordered_map<std::string, double> param_double;
100  std::unordered_map<std::string, double*> param_dstar;
101  std::unordered_map<std::string, bool> param_bool;
102  std::unordered_map<std::string, cufftDoubleComplex*> sobel;
103  std::unordered_map<std::string, std::string> param_string;
104  std::unordered_map<std::string, EqnNode_gpu*> param_ast;
105  std::unordered_map<std::string, EqnNode> param_ast_cpu;
106 
107  // List of all strings for parsing into the appropriate param map
108  // 1 -> int, 2 -> double, 3 -> double*
109  std::unordered_map<std::string, int> id_list;
110 
111  // Here we keep the functions to store variables and access grid data
112  public:
113  dim3 grid, threads;
114 
115  // Map for function pointers and keys K and V
116  functionPtrV V_fn;
117  functionPtrA Ax_fn, Ay_fn, Az_fn;
118  functionPtrwfc wfc_fn;
119 
120  // placing grid parameters in public for now
121  double *x, *y, *z, *xp, *yp, *zp;
122 
123  // Function to store sobel_fft operators into the sobel map
124  void store(std::string id, cufftDoubleComplex* d2param);
125 
126  // Function to store integer into param_int
127  void store(std::string id, int iparam);
128 
129  // Function to store double into param_double
130  void store(std::string id, double dparam);
131 
132  // Function to store double* into param_dstar
133  void store(std::string id, double *dsparam);
134 
135  // Function to store bool into param_bool
136  void store(std::string id, bool bparam);
137 
138  // Function to store string into data_dir
139  void store(std::string id, std::string sparam);
140 
141  // Function to store asts into data_dir
142  void store(std::string id, EqnNode_gpu *ensparam);
143 
144  // Function to store asts into data_dir
145  void store(std::string id, EqnNode astparam);
146 
147  // Function to retrieve integer value from param_int
148  int ival(std::string id);
149 
150  // Function to retrieve double value from param_double
151  double dval(std::string id);
152 
153  // Function to retrieve double star values from param_dstar
154  double *dsval(std::string id);
155 
156  // Function to retrieve bool from param_bool
157  bool bval(std::string id);
158 
159  // Fucntion to retrieve string from data_dir
160  std::string sval(std::string id);
161 
162  // Function to call back the sobel operators
163  cufftDoubleComplex *cufftDoubleComplexval(std::string id);
164 
165  // Function to call back ast
166  EqnNode_gpu *astval(std::string id);
167 
168  // Function to call back ast
169  EqnNode ast_cpuval(std::string id);
170 
171  // Function for file writing
172  void write(std::string filename);
173 
174  // Two boolean functions to check whether a string exists in
175  // param_double or param_dstar
176  bool is_double(std::string id);
177  bool is_dstar(std::string id);
178  bool is_ast_gpu(std::string id);
179  bool is_ast_cpu(std::string id);
180 
181  // Function to print all available variables
182  void print_map();
183 
184  // function to set A functions
185  void set_A_fn(std::string id);
186 
187  // function to set V functions
188  void set_V_fn(std::string id);
189 
190  // function to set V functions
191  void set_wfc_fn(std::string id);
192 
193  // Key values for operators
194  // Note that Vector potential only have a single string for x, y, z
195  std::string Kfn, Vfn, Afn, Axfile, Ayfile, Azfile, Wfcfn;
196 };
197 typedef class Grid Grid;
198 
203 void generate_plan_other2d(cufftHandle *plan_fft1d, Grid &par);
204 
209 void generate_plan_other3d(cufftHandle *plan_fft1d, Grid &par, int axis);
210 
215 void set_fns(Grid &par);
216 
217 #endif
std::string Vfn
Definition: ds.h:195
void write(std::string filename)
bool is_double(std::string id)
double * zp
Definition: ds.h:121
int right
Definition: ds.h:77
EqnNode * left
Definition: ds.h:61
double dval(std::string id)
functionPtrA Ax_fn
Definition: ds.h:117
std::string Axfile
Definition: ds.h:195
dim3 threads
Definition: ds.h:113
bool is_ast_cpu(std::string id)
double x
Definition: ds.h:43
std::string Kfn
Definition: ds.h:195
int ival(std::string id)
void store(std::string id, cufftDoubleComplex *d2param)
void set_V_fn(std::string id)
int op_num
Definition: ds.h:79
char var
Definition: ds.h:59
void generate_plan_other3d(cufftHandle *plan_fft1d, Grid &par, int axis)
Generates CUFFT plan for 3D simulations.
EqnNode * right
Definition: ds.h:61
double val
Definition: ds.h:57
void set_fns(Grid &par)
Sets default functions for all fields (A, K, V)
bool is_dynamic
Definition: ds.h:58
char var
Definition: ds.h:74
double val
Definition: ds.h:72
std::string Azfile
Definition: ds.h:195
Struct to hold the node information for the AST on the CPU.
Definition: ds.h:56
cufftDoubleComplex * cufftDoubleComplexval(std::string id)
dim3 grid
Definition: ds.h:113
double(* fnPtr)(double, double)
function pointer type
Definition: ds.h:50
Struct to hold the node information for the AST on the GPU.
Definition: ds.h:71
void set_A_fn(std::string id)
bool is_dstar(std::string id)
functionPtrA Az_fn
Definition: ds.h:117
functionPtrA Ay_fn
Definition: ds.h:117
void generate_plan_other2d(cufftHandle *plan_fft1d, Grid &par)
Generates CUFFT plan for 2D simulations.
double * z
Definition: ds.h:121
double * xp
Definition: ds.h:121
bool has_op
Definition: ds.h:64
bool bval(std::string id)
EqnNode ast_cpuval(std::string id)
double y
Definition: ds.h:43
void set_wfc_fn(std::string id)
double * x
Definition: ds.h:121
Struct for an x, y, z position.
Definition: ds.h:42
std::string sval(std::string id)
% axis([1e4 1e7 5e-18 1e-10])
double * y
Definition: ds.h:121
std::string Wfcfn
Definition: ds.h:195
std::string Ayfile
Definition: ds.h:195
bool is_ast_gpu(std::string id)
functionPtrwfc wfc_fn
Definition: ds.h:118
functionPtrV V_fn
Definition: ds.h:116
Class to hold the variable map and grid information.
Definition: ds.h:86
int op_num
Definition: ds.h:63
def par
Definition: plot.py:237
EqnNode_gpu * astval(std::string id)
double * dsval(std::string id)
bool is_dynamic
Definition: ds.h:73
double * yp
Definition: ds.h:121
int left
Definition: ds.h:76
std::string Afn
Definition: ds.h:195
double z
Definition: ds.h:43
void print_map()