Ver código fonte

Cleaned the code and removed unused imports.

Ovidio Peña Rodríguez 4 anos atrás
pai
commit
df4a9c7dda
9 arquivos alterados com 63 adições e 96 exclusões
  1. 6 0
      requirements.txt
  2. 29 30
      setup.py
  3. 5 9
      src/farfield.cc
  4. 5 9
      src/nearfield.cc
  5. 3 8
      src/nmie-applied.cc
  6. 4 7
      src/nmie-impl.cc
  7. 3 10
      src/nmie-pybind11.cc
  8. 6 18
      src/nmie.cc
  9. 2 5
      src/shell-generator.cc

+ 6 - 0
requirements.txt

@@ -0,0 +1,6 @@
+scipy~=1.3.3
+numpy~=1.17.4
+matplotlib~=3.1.2
+PyYAML~=5.3.1
+pybind11~=2.4.3
+setuptools~=45.2.0

+ 29 - 30
setup.py

@@ -43,33 +43,32 @@ from setuptools.extension import Extension
 import numpy as np
 import pybind11 as pb
 
-setup(name = __mod__,
-      version = __version__,
-      description = __title__,
-      long_description="""The Python version of scattnlay, a computer implementation of the algorithm for the calculation of electromagnetic \
-radiation scattering by a multilayered sphere developed by Yang. It has been shown that the program is effective, \
-resulting in very accurate values of scattering efficiencies for a wide range of size parameters, which is a \
-considerable improvement over previous implementations of similar algorithms. For details see: \
-O. Pena, U. Pal, Comput. Phys. Commun. 180 (2009) 2348-2354.""",
-      author = __author__,
-      author_email = __email__,
-      maintainer = __author__,
-      maintainer_email = __email__,
-      keywords = ['Mie scattering', 'Multilayered sphere', 'Efficiency factors', 'Cross-sections'],
-      url = __url__,
-      download_url = __download_url__,
-      license = 'GPL',
-      platforms = 'any',
-      packages = ['scattnlay'],#, 'scattnlay_dp', 'scattnlay_mp'],
-      ext_modules = [Extension("scattnlay_dp",
-                               ["src/nmie.cc", "src/nmie-pybind11.cc", "src/pb11_wrapper.cc"],
-                               language = "c++",
-                               include_dirs = [np.get_include(), pb.get_include()],
-                               extra_compile_args=['-std=c++11']),
-                     Extension("scattnlay_mp",
-                               ["src/nmie.cc", "src/nmie-pybind11.cc", "src/pb11_wrapper.cc"],
-                               language = "c++",
-                               include_dirs = [np.get_include(), pb.get_include()],
-                               extra_compile_args=['-std=c++11', '-DMULTI_PRECISION=100'])]
-)
-
+setup(name=__mod__,
+      version=__version__,
+      description=__title__,
+      long_description="""The Python version of scattnlay, a computer implementation of the algorithm for the \
+calculation of electromagnetic radiation scattering by a multilayered sphere developed by Yang. It has been \
+shown that the program is effective, resulting in very accurate values of scattering efficiencies for a wide \
+range of size parameters, which is a considerable improvement over previous implementations of similar algorithms. \
+For details see: O. Pena, U. Pal, Comput. Phys. Commun. 180 (2009) 2348-2354.""",
+      author=__author__,
+      author_email=__email__,
+      maintainer=__author__,
+      maintainer_email=__email__,
+      keywords=['Mie scattering', 'Multilayered sphere', 'Efficiency factors', 'Cross-sections'],
+      url=__url__,
+      download_url=__download_url__,
+      license='GPL',
+      platforms='any',
+      packages=['scattnlay'],  # , 'scattnlay_dp', 'scattnlay_mp'],
+      ext_modules=[Extension("scattnlay_dp",
+                             ["src/nmie.cc", "src/nmie-pybind11.cc", "src/pb11_wrapper.cc"],
+                             language="c++",
+                             include_dirs=[np.get_include(), pb.get_include()],
+                             extra_compile_args=['-std=c++11']),
+                   Extension("scattnlay_mp",
+                             ["src/nmie.cc", "src/nmie-pybind11.cc", "src/pb11_wrapper.cc"],
+                             language="c++",
+                             include_dirs=[np.get_include(), pb.get_include()],
+                             extra_compile_args=['-std=c++11', '-DMULTI_PRECISION=100'])]
+      )

+ 5 - 9
src/farfield.cc

@@ -29,17 +29,13 @@
 //    along with this program.  If not, see <http://www.gnu.org/licenses/>.         //
 //**********************************************************************************//
 
-#include <algorithm>
 #include <complex>
-#include <functional>
 #include <iostream>
 #include <stdexcept>
 #include <string>
 #include <vector>
-#include <stdlib.h>
-#include <stdio.h>
-#include <time.h>
-#include <string.h>
+#include <cstdio>
+
 #include "nmie.hpp"
 
 const double PI=3.14159265358979323846;
@@ -84,7 +80,7 @@ int main(int argc, char *argv[]) {
 
     int mode = -1;
     double tmp_mr;
-    for (auto arg : args) {
+    for (const auto& arg : args) {
       // For each arg in args list we detect the change of the current
       // read mode or read the arg. The reading args algorithm works
       // as a finite-state machine.
@@ -130,7 +126,7 @@ int main(int argc, char *argv[]) {
       }
 
       if (mode == read_mi) {
-        m.push_back(std::complex<double>( tmp_mr,std::stod(arg) ));
+        m.emplace_back( tmp_mr,std::stod(arg) );
         mode = read_x;
         continue;
       }
@@ -164,7 +160,7 @@ int main(int argc, char *argv[]) {
 
     if ( (x.size() != m.size()) || (L != x.size()) )
       throw std::invalid_argument(std::string("Broken structure!\n") + error_msg);
-    if ( (0 == m.size()) || ( 0 == x.size()) )
+    if ( (m.empty()) || ( x.empty()) )
       throw std::invalid_argument(std::string("Empty structure!\n") + error_msg);
 
     if (nt < 0) {

+ 5 - 9
src/nearfield.cc

@@ -29,17 +29,13 @@
 //    along with this program.  If not, see <http://www.gnu.org/licenses/>.         //
 //**********************************************************************************//
 
-#include <algorithm>
 #include <complex>
-#include <functional>
 #include <iostream>
 #include <stdexcept>
 #include <string>
 #include <vector>
-#include <stdlib.h>
-#include <stdio.h>
-#include <time.h>
-#include <string.h>
+#include <cstdio>
+
 #include "nmie.hpp"
 
 const double PI=3.14159265358979323846;
@@ -84,7 +80,7 @@ int main(int argc, char *argv[]) {
 
     int mode = -1;
     double tmp_mr;
-    for (auto arg : args) {
+    for (const auto& arg : args) {
       // For each arg in args list we detect the change of the current
       // read mode or read the arg. The reading args algorithm works
       // as a finite-state machine.
@@ -130,7 +126,7 @@ int main(int argc, char *argv[]) {
       }
 
       if (mode == read_mi) {
-        m.push_back(std::complex<double>( tmp_mr,std::stod(arg) ));
+        m.emplace_back( tmp_mr,std::stod(arg) );
         mode = read_x;
         continue;
       }
@@ -211,7 +207,7 @@ int main(int argc, char *argv[]) {
 
     if ( (x.size() != m.size()) || (L != x.size()) )
       throw std::invalid_argument(std::string("Broken structure!\n") + error_msg);
-    if ( (0 == m.size()) || ( 0 == x.size()) )
+    if ( (m.empty()) || ( x.empty()) )
       throw std::invalid_argument(std::string("Empty structure!\n") + error_msg);
 
     if (nx == 1)

+ 3 - 8
src/nmie-applied.cc

@@ -31,15 +31,12 @@
 //    @brief  Wrapper class around nMie function for ease of use                    //
 //                                                                                  //
 //**********************************************************************************//
+#include <stdexcept>
+#include <vector>
+
 #include "nmie-applied.hpp"
 #include "nmie-applied-impl.hpp"
 #include "nmie-precision.hpp"
-#include <array>
-#include <algorithm>
-#include <cstdio>
-#include <cstdlib>
-#include <stdexcept>
-#include <vector>
 
 namespace nmie {  
   //**********************************************************************************//
@@ -102,9 +99,7 @@ namespace nmie {
       // Will catch if  ml_mie fails or other errors.
       std::cerr << "Invalid argument: " << ia.what() << std::endl;
       throw std::invalid_argument(ia);
-      return -1;
     }
-    return 0;
   }
   int nMieApplied(const unsigned int L, std::vector<double>& x, std::vector<std::complex<double> >& m, const unsigned int nTheta, std::vector<double>& Theta, double *Qext, double *Qsca, double *Qabs, double *Qbk, double *Qpr, double *g, double *Albedo, std::vector<std::complex<double> >& S1, std::vector<std::complex<double> >& S2) {
     return nmie::nMieApplied(L, -1, x, m, nTheta, Theta, -1, Qext, Qsca, Qabs, Qbk, Qpr, g, Albedo, S1, S2);

+ 4 - 7
src/nmie-impl.cc

@@ -47,17 +47,14 @@
 //                                                                                  //
 // Hereinafter all equations numbers refer to [2]                                   //
 //**********************************************************************************//
-#include "nmie.hpp"
-#include "nmie-precision.hpp"
-#include <array>
-#include <algorithm>
-#include <cstdio>
-#include <cstdlib>
 #include <iostream>
 #include <iomanip>
 #include <stdexcept>
 #include <vector>
 
+#include "nmie.hpp"
+#include "nmie-precision.hpp"
+
 namespace nmie {
   //helper functions
 
@@ -1018,7 +1015,7 @@ namespace nmie {
 
     for (int n = nmax_ - 2; n >= 0; n--) {
       int n1 = n + 1;
-      FloatType rn = static_cast<FloatType>(n1);
+      auto rn = static_cast<FloatType>(n1);
 
       // using BH 4.12 and 4.50
       calcSpherHarm(Rho*ml, Theta, Phi, Psi[n1], D1n[n1], Pi[n], Tau[n], rn, M1o1n, M1e1n, N1o1n, N1e1n);

+ 3 - 10
src/nmie-pybind11.cc

@@ -28,18 +28,11 @@
 //    You should have received a copy of the GNU General Public License             //
 //    along with this program.  If not, see <http://www.gnu.org/licenses/>.         //
 //**********************************************************************************//
-#include "nmie.hpp"
-#include "nmie-precision.hpp"
-#include <array>
-#include <tuple>
-#include <algorithm>
 #include <cstdio>
-#include <cstdlib>
-#include <stdexcept>
-#include <iostream>
-#include <iomanip>
 #include <vector>
 
+#include "nmie.hpp"
+
 #include <pybind11/pybind11.h>
 #include <pybind11/numpy.h>
 #include <pybind11/complex.h>
@@ -51,7 +44,7 @@ namespace py = pybind11;
 py::array_t< std::complex<double>> VectorComplex2Py(const std::vector<std::complex<double> > &c_x) {
   auto py_x = py::array_t< std::complex<double>>(c_x.size());
   auto py_x_buffer = py_x.request();
-  std::complex<double> *py_x_ptr = (std::complex<double> *) py_x_buffer.ptr;
+  auto *py_x_ptr = (std::complex<double> *) py_x_buffer.ptr;
   std::memcpy(py_x_ptr, c_x.data(), c_x.size()*sizeof(std::complex<double>));
   return py_x;
 }

+ 6 - 18
src/nmie.cc

@@ -45,18 +45,14 @@
 //                                                                                  //
 // Hereinafter all equations numbers refer to [2]                                   //
 //**********************************************************************************//
-#include "nmie.hpp"
-#include "nmie-precision.hpp"
-#include "nmie-impl.cc"
-#include <array>
-#include <algorithm>
-#include <cstdio>
-#include <cstdlib>
 #include <stdexcept>
 #include <iostream>
-#include <iomanip>
 #include <vector>
 
+#include "nmie.hpp"
+#include "nmie-precision.hpp"
+#include "nmie-impl.cc"
+
 namespace nmie {
   
   //**********************************************************************************//
@@ -100,9 +96,7 @@ namespace nmie {
       // Will catch if  ml_mie fails or other errors.
       std::cerr << "Invalid argument: " << ia.what() << std::endl;
       throw std::invalid_argument(ia);
-      return -1;
     }
-    return 0;
   }
 
   //**********************************************************************************//
@@ -152,9 +146,7 @@ namespace nmie {
       // Will catch if  ml_mie fails or other errors.
       std::cerr << "Invalid argument: " << ia.what() << std::endl;
       throw std::invalid_argument(ia);
-      return -1;
     }
-    return 0;
   }
 
   //**********************************************************************************//
@@ -226,9 +218,7 @@ namespace nmie {
       // Will catch if  ml_mie fails or other errors.
       std::cerr << "Invalid argument: " << ia.what() << std::endl;
       throw std::invalid_argument(ia);
-      return -1;
     }
-    return 0;
   }
 
 
@@ -370,10 +360,10 @@ namespace nmie {
     if (Xp_vec.size() != ncoord || Yp_vec.size() != ncoord || Zp_vec.size() != ncoord
         || E.size() != ncoord || H.size() != ncoord)
       throw std::invalid_argument("Declared number of coords do not fit Xp, Yp, Zp, E, or H!");
-    for (auto f:E)
+    for (const auto& f:E)
       if (f.size() != 3)
         throw std::invalid_argument("Field E is not 3D!");
-    for (auto f:H)
+    for (const auto& f:H)
       if (f.size() != 3)
         throw std::invalid_argument("Field H is not 3D!");
     try {
@@ -393,8 +383,6 @@ namespace nmie {
       // Will catch if  ml_mie fails or other errors.
       std::cerr << "Invalid argument: " << ia.what() << std::endl;
       throw std::invalid_argument(ia);
-      return - 1;
     }
-    return 0;
   }
 }  // end of namespace nmie

+ 2 - 5
src/shell-generator.cc

@@ -30,18 +30,15 @@
 //**********************************************************************************//
 //   @brief  Generates points for integration on sphere surface
 
-#include <algorithm>
 #include <cmath>
 #include <complex>
-#include <cstdio>
-#include <fstream>
 #include <iostream>
 #include <set>
-#include <sstream>
 #include <stdexcept>
-#include <string>
 #include <vector>
+
 #include "shell-generator.hpp"
+
 namespace shell_generator {
   template<class T> inline T pow2(const T value) {return value*value;}
   // ********************************************************************** //