From 3f40be278fd9fb48450f8fb1952ec0d3fc0af730 Mon Sep 17 00:00:00 2001
From: Chichi Lalescu <clalesc1@jhu.edu>
Date: Thu, 24 Dec 2015 14:12:38 +0100
Subject: [PATCH] put dx, dy, dz and bounds in rFFTW_interpolator

---
 bfps/cpp/rFFTW_interpolator.cpp | 38 +++++++++++++++++++++++++++++++++
 bfps/cpp/rFFTW_interpolator.hpp |  7 ++++++
 bfps/cpp/rFFTW_particles.cpp    |  8 +------
 tox_plain.ini                   |  2 +-
 4 files changed, 47 insertions(+), 8 deletions(-)

diff --git a/bfps/cpp/rFFTW_interpolator.cpp b/bfps/cpp/rFFTW_interpolator.cpp
index 6f1a49bc..5e95d742 100644
--- a/bfps/cpp/rFFTW_interpolator.cpp
+++ b/bfps/cpp/rFFTW_interpolator.cpp
@@ -26,6 +26,7 @@
 
 #define NDEBUG
 
+#include <cmath>
 #include "rFFTW_interpolator.hpp"
 
 template <class rnumber, int interp_neighbours>
@@ -47,6 +48,41 @@ rFFTW_interpolator<rnumber, interp_neighbours>::rFFTW_interpolator(
         this->f1 = (rnumber*)((void*)fftw_alloc_real(this->field_size));
     }
     this->temp = this->f1;
+
+    // compute dx, dy, dz;
+    this->dx = 4*acos(0) / (fs->dkx*fs->rd->sizes[2]);
+    this->dy = 4*acos(0) / (fs->dky*fs->rd->sizes[1]);
+    this->dz = 4*acos(0) / (fs->dkz*fs->rd->sizes[0]);
+
+    // compute lower and upper bounds
+    this->lbound = new double[nprocs];
+    this->ubound = new double[nprocs];
+    double *tbound = new double[nprocs];
+    std::fill_n(tbound, nprocs, 0.0);
+    tbound[this->descriptor->myrank] = fs->rd->starts[0]*this->dz;
+    MPI_Allreduce(
+            tbound,
+            this->lbound,
+            nprocs,
+            MPI_DOUBLE,
+            MPI_SUM,
+            this->descriptor->comm);
+    std::fill_n(tbound, this->descriptor->nprocs, 0.0);
+    tbound[this->descriptor->myrank] = (fs->rd->starts[0] + fs->rd->subsizes[0])*this->dz;
+    MPI_Allreduce(
+            tbound,
+            this->ubound,
+            nprocs,
+            MPI_DOUBLE,
+            MPI_SUM,
+            this->descriptor->comm);
+    delete[] tbound;
+    //for (int r = 0; r<nprocs; r++)
+    //    DEBUG_MSG(
+    //            "lbound[%d] = %lg, ubound[%d] = %lg\n",
+    //            r, this->lbound[r],
+    //            r, this->ubound[r]
+    //            );
 }
 
 template <class rnumber, int interp_neighbours>
@@ -62,6 +98,8 @@ rFFTW_interpolator<rnumber, interp_neighbours>::~rFFTW_interpolator()
         fftw_free((double*)((void*)this->f0));
         fftw_free((double*)((void*)this->f1));
     }
+    delete[] this->lbound;
+    delete[] this->ubound;
 }
 
 template <class rnumber, int interp_neighbours>
diff --git a/bfps/cpp/rFFTW_interpolator.hpp b/bfps/cpp/rFFTW_interpolator.hpp
index 7a32e758..ea7776b3 100644
--- a/bfps/cpp/rFFTW_interpolator.hpp
+++ b/bfps/cpp/rFFTW_interpolator.hpp
@@ -49,6 +49,13 @@ class rFFTW_interpolator
         field_descriptor<rnumber> *descriptor;
         rnumber *f0, *f1, *temp;
 
+        /* physical parameters of field */
+        double dx, dy, dz;
+
+        /* precomputed boundaries of process's domain */
+        double *lbound;
+        double *ubound;
+
         rFFTW_interpolator(
                 fluid_solver_base<rnumber> *FSOLVER,
                 base_polynomial_values BETA_POLYS);
diff --git a/bfps/cpp/rFFTW_particles.cpp b/bfps/cpp/rFFTW_particles.cpp
index 20f0eef5..42a308f2 100644
--- a/bfps/cpp/rFFTW_particles.cpp
+++ b/bfps/cpp/rFFTW_particles.cpp
@@ -24,7 +24,7 @@
 
 
 
-//#define NDEBUG
+#define NDEBUG
 
 #include <cmath>
 #include <cassert>
@@ -105,12 +105,6 @@ rFFTW_particles<particle_type, rnumber, interp_neighbours>::rFFTW_particles(
             MPI_SUM,
             this->comm);
     delete[] tbound;
-    //for (int r = 0; r<nprocs; r++)
-    //    DEBUG_MSG(
-    //            "lbound[%d] = %lg, ubound[%d] = %lg\n",
-    //            r, this->lbound[r],
-    //            r, this->ubound[r]
-    //            );
 }
 
 template <int particle_type, class rnumber, int interp_neighbours>
diff --git a/tox_plain.ini b/tox_plain.ini
index 1aad5555..21413b95 100644
--- a/tox_plain.ini
+++ b/tox_plain.ini
@@ -1,5 +1,5 @@
 [tox]
-envlist = py27
+envlist = py34
 [testenv]
 sitepackages = True
 #deps = matplotlib
-- 
GitLab