2 #include "../include/ds.h"
3 #include "../include/operators.h"
5 /*----------------------------------------------------------------------------//
7 *-----------------------------------------------------------------------------*/
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");
17 int n[] = {xDim, yDim};
20 int inembed[] = {xDim,yDim};
21 int onembed[] = {xDim,yDim};
27 result = cufftPlanMany(plan_fft1d, rank, n, inembed, istride,
28 idist, onembed, ostride, odist,
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);
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");
49 // Along first dimension (z)
51 result = cufftPlan1d(plan_fft1d, xDim, CUFFT_Z2Z, yDim*zDim);
54 // Along second dimension (y)
55 // This one is a bit complicated because of how the data is aligned
59 int n[] = {xDim, yDim};
62 int inembed[] = {xDim, yDim};
63 int onembed[] = {xDim, yDim};
67 result = cufftPlanMany(plan_fft1d, rank, n, inembed, istride,
68 idist, onembed, ostride, odist,
70 //result = cufftPlan2d(plan_fft1d, xDim, yDim, CUFFT_Z2Z);
74 // Along third dimension (x)
77 int batch = xDim*yDim;
79 int n[] = {xDim, yDim, zDim};
82 int inembed[] = {xDim, yDim, zDim};
83 int onembed[] = {xDim, yDim, zDim};
84 int istride = xDim*yDim;
85 int ostride = xDim*yDim;
87 result = cufftPlanMany(plan_fft1d, rank, n, inembed, istride,
88 idist, onembed, ostride, odist,
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);
101 // Function to set functionPtrs without an unordered map
102 void set_fns(Grid &par){
104 // There are 3 different function distributions to keep in mind:
108 par.set_V_fn(par.Vfn);
111 par.set_A_fn(par.Afn);
114 par.set_wfc_fn(par.Wfcfn);
119 /*----------------------------------------------------------------------------//
121 *-----------------------------------------------------------------------------*/
123 // Function to store sobel_fft operators and stuff
124 void Grid::store(std::string id, cufftDoubleComplex *d2param){
128 // Function to store integer into Grid->param_int
129 void Grid::store(std::string id, int iparam){
130 param_int[id] = iparam;
133 // Function to store double into Grid->param_double
134 void Grid::store(std::string id, double dparam){
135 param_double[id] = dparam;
138 // Function to store double* into param_dstar
139 void Grid::store(std::string id, double *dsparam){
140 param_dstar[id] = dsparam;
143 // Function to store bool into param_bool
144 void Grid::store(std::string id, bool bparam){
145 param_bool[id] = bparam;
148 // Function to store string into data_dir
149 void Grid::store(std::string id, std::string sparam){
150 param_string[id] = sparam;
153 // Function to store asts into data_dir
154 void Grid::store(std::string id, EqnNode_gpu *ensparam){
155 param_ast[id] = ensparam;
158 // Function to store asts into data_dir
159 void Grid::store(std::string id, EqnNode astparam){
160 param_ast_cpu[id] = astparam;
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()){
175 bool Grid::is_dstar(std::string id){
176 auto it = param_dstar.find(id);
177 if (it != param_dstar.end()){
185 bool Grid::is_ast_gpu(std::string id){
186 auto it = param_ast.find(id);
187 if (it != param_ast.end()){
195 bool Grid::is_ast_cpu(std::string id){
196 auto it = param_ast_cpu.find(id);
197 if (it != param_ast_cpu.end()){
205 // Function to retrieve integer from Grid->param_int
206 int Grid::ival(std::string id){
207 return param_int[id];
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());
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());
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());
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());
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());
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());
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());
288 // Function for file writing (to replace fileIO::writeOutParam)
289 void Grid::write(std::string filename){
290 std::ofstream output;
291 output.open(filename);
293 //Needed to recognise Params.dat as .ini format for python post processing
294 output << "[Params]" <<"\n";
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';
302 for (auto item : param_int){
303 output << item.first << "=" << item.second << '\n';
304 std::cout << item.first << "=" << item.second << '\n';
310 // Function to print all available variables
311 void Grid::print_map(){
312 for (auto item : param_double){
313 std::cout << item.first << '\n';
315 for (auto item : param_dstar){
316 std::cout << item.first << '\n';
320 void Grid::set_A_fn(std::string id){
321 if (id == "rotation"){
322 Ax_fn = krotation_Ax;
323 Ay_fn = krotation_Ay;
326 else if (id == "ring_rotation"){
327 Ax_fn = kring_rotation_Ax;
328 Ay_fn = kring_rotation_Ay;
329 Az_fn = kring_rotation_Az;
331 else if (id == "constant"){
336 else if (id == "ring"){
341 else if (id == "test"){
346 else if (id == "file"){
353 void Grid::set_wfc_fn(std::string id){
354 if (id == "2d" || id == "3d"){
357 else if(id == "torus"){
362 void Grid::set_V_fn(std::string id){
366 else if (id == "torus"){