Просмотр исходного кода

added early convergence stop to near-field evaluation

Konstantin Ladutenko 3 лет назад
Родитель
Сommit
b12c46673a
3 измененных файлов с 10 добавлено и 5 удалено
  1. 4 4
      src/nearfield.cc
  2. 5 0
      src/nmie-nearfield.hpp
  3. 1 1
      src/nmie.cc

+ 4 - 4
src/nearfield.cc

@@ -1,6 +1,6 @@
 //**********************************************************************************//
-//    Copyright (C) 2009-2018  Ovidio Pena <ovidio@bytesfall.com>                   //
-//    Copyright (C) 2013-2018  Konstantin Ladutenko <kostyfisik@gmail.com>          //
+//    Copyright (C) 2009-2022  Ovidio Pena <ovidio@bytesfall.com>                   //
+//    Copyright (C) 2013-2022  Konstantin Ladutenko <kostyfisik@gmail.com>          //
 //                                                                                  //
 //    This file is part of scattnlay                                                //
 //                                                                                  //
@@ -235,8 +235,8 @@ int main(int argc, char *argv[]) {
       }
     }
 
-    nmie::nField(L, -1, x, m, -1, nmie::Modes::kAll, nmie::Modes::kAll, total_points, Xp, Yp, Zp, E, H);
-
+    int nmax = nmie::nField(L, -1, x, m, -1, nmie::Modes::kAll, nmie::Modes::kAll, total_points, Xp, Yp, Zp, E, H);
+    printf("Number of multipoles used in Mie series nmax=%i\n", nmax);
     if (has_comment)
       printf("%6s\n", comment.c_str());
 

+ 5 - 0
src/nmie-nearfield.hpp

@@ -283,6 +283,11 @@ namespace nmie {
     std::vector< std::complex<evalType> > Ediff_prev = {{0.,0.},{0.,0.},{0.,0.}},
         Hdiff_prev = {{0.,0.},{0.,0.},{0.,0.}};
     for (unsigned int n = 0; n < nmax; n++) {
+      if ( isConvergedE[0] && isConvergedE[1] && isConvergedE[2]
+          && isConvergedH[0] && isConvergedH[1] && isConvergedH[2]) {
+        std::cout<<"Near-field early convergence at nmax = "<<n+1<<std::endl;
+        break;
+      }
       int n1 = n + 1;
       auto rn = static_cast<evalType>(n1);
 

+ 1 - 1
src/nmie.cc

@@ -380,7 +380,7 @@ namespace nmie {
   //   m: Array containing the relative refractive indexes of the layers [0..L-1]     //
   //   nmax: Maximum number of multipolar expansion terms to be used for the          //
   //         calculations. Only use it if you know what you are doing, otherwise      //
-  //         set this parameter to 0 (zero) and the function will calculate it.       //
+  //         set this parameter to -1 and the function will calculate it.             //
   //   ncoord: Number of coordinate points                                            //
   //   Coords: Array containing all coordinates where the complex electric and        //
   //           magnetic fields will be calculated                                     //