Преглед изворни кода

reduced the number of protected members

Konstantin Ladutenko пре 9 година
родитељ
комит
00b20150b1
4 измењених фајлова са 49 додато и 73 уклоњено
  1. 18 37
      src/nmie-applied.cc
  2. 0 3
      src/nmie-applied.h
  3. 15 21
      src/nmie.cc
  4. 16 12
      src/nmie.h

+ 18 - 37
src/nmie-applied.cc

@@ -140,7 +140,7 @@ namespace nmie {
   // ********************************************************************** //
   // ********************************************************************** //
   void MultiLayerMieApplied::AddTargetLayer(double width, std::complex<double> layer_index) {
-    isMieCalculated_ = false;
+    MarkUncalculated();
     if (width <= 0)
       throw std::invalid_argument("Layer width should be positive!");
     target_width_.push_back(width);
@@ -150,36 +150,27 @@ namespace nmie {
   // ********************************************************************** //
   // ********************************************************************** //
   void MultiLayerMieApplied::SetTargetPEC(double radius) {
-    isMieCalculated_ = false;
+    MarkUncalculated();
     if (target_width_.size() != 0 || target_index_.size() != 0)
       throw std::invalid_argument("Error! Define PEC target radius before any other layers!");
     // Add layer of any index...
     AddTargetLayer(radius, std::complex<double>(0.0, 0.0));
     // ... and mark it as PEC
-    SetPEC(0.0);
+    SetPECLayer(0);
   }
   // ********************************************************************** //
   // ********************************************************************** //
   // ********************************************************************** //
   void MultiLayerMieApplied::SetCoatingIndex(std::vector<std::complex<double> > index) {
-    isMieCalculated_ = false;
+    MarkUncalculated();
     coating_index_.clear();
     for (auto value : index) coating_index_.push_back(value);
   }  // end of void MultiLayerMieApplied::SetCoatingIndex(std::vector<complex> index);  
   // ********************************************************************** //
   // ********************************************************************** //
   // ********************************************************************** //
-  void MultiLayerMieApplied::SetAngles(const std::vector<double>& angles) {
-    isMieCalculated_ = false;
-    theta_ = angles;
-    // theta_.clear();
-    // for (auto value : angles) theta_.push_back(value);
-  }  // end of SetAngles()
-  // ********************************************************************** //
-  // ********************************************************************** //
-  // ********************************************************************** //
   void MultiLayerMieApplied::SetCoatingWidth(std::vector<double> width) {
-    isMieCalculated_ = false;
+    MarkUncalculated();
     coating_width_.clear();
     for (auto w : width)
       if (w <= 0)
@@ -191,7 +182,7 @@ namespace nmie {
   // ********************************************************************** //
   // ********************************************************************** //
   void MultiLayerMieApplied::SetWidthSP(const std::vector<double>& size_parameter) {
-    isMieCalculated_ = false;
+    MarkUncalculated();
     size_param_.clear();
     double prev_size_parameter = 0.0;
     for (auto layer_size_parameter : size_parameter) {
@@ -209,7 +200,7 @@ namespace nmie {
   // ********************************************************************** //
   // ********************************************************************** //
   void MultiLayerMieApplied::SetIndexSP(const std::vector< std::complex<double> >& index) {
-    isMieCalculated_ = false;
+    MarkUncalculated();
     //refractive_index_.clear();
     refractive_index_ = index;
     // for (auto value : index) refractive_index_.push_back(value);
@@ -230,17 +221,8 @@ namespace nmie {
   // ********************************************************************** //
   // ********************************************************************** //
   // ********************************************************************** //
-  void MultiLayerMieApplied::SetPEC(int layer_position) {
-    isMieCalculated_ = false;
-    if (layer_position < 0)
-      throw std::invalid_argument("Error! Layers are numbered from 0!");
-    PEC_layer_position_ = layer_position;
-  }
-  // ********************************************************************** //
-  // ********************************************************************** //
-  // ********************************************************************** //
   void MultiLayerMieApplied::GenerateSizeParameter() {
-    isMieCalculated_ = false;
+    MarkUncalculated();
     size_param_.clear();
     double radius = 0.0;
     for (auto width : target_width_) {
@@ -257,7 +239,7 @@ namespace nmie {
   // ********************************************************************** //
   // ********************************************************************** //
   void MultiLayerMieApplied::GenerateIndex() {
-    isMieCalculated_ = false;
+    MarkUncalculated();
     refractive_index_.clear();
     for (auto index : target_index_) refractive_index_.push_back(index);
     for (auto index : coating_index_) refractive_index_.push_back(index);
@@ -266,9 +248,7 @@ namespace nmie {
   // ********************************************************************** //
   // ********************************************************************** //
   double MultiLayerMieApplied::GetTotalRadius() {
-    if (!isMieCalculated_)
-      throw std::invalid_argument("You should run calculations before result request!");
-    if (total_radius_ == 0) GenerateSizeParameter();
+    if (!isMieCalculated())  GenerateSizeParameter();
     return total_radius_;      
   }  // end of double MultiLayerMieApplied::GetTotalRadius();
   // ********************************************************************** //
@@ -276,7 +256,7 @@ namespace nmie {
   // ********************************************************************** //
   std::vector< std::vector<double> >
   MultiLayerMieApplied::GetSpectra(double from_WL, double to_WL, int samples) {
-    if (!isMieCalculated_)
+    if (!isMieCalculated())
       throw std::invalid_argument("You should run calculations before result request!");
     std::vector< std::vector<double> > spectra;
     double step_WL = (to_WL - from_WL)/static_cast<double>(samples);
@@ -291,7 +271,8 @@ namespace nmie {
         continue;
       }
       //printf("%3.1f ",WL);
-      spectra.push_back(std::vector<double>({wavelength_, Qext_, Qsca_, Qabs_, Qbk_}));
+      spectra.push_back(std::vector<double>({wavelength_, GetQext(),
+	      GetQsca(), GetQabs(), GetQbk()}));
     }  // end of for each WL in spectra
     printf("Spectrum has %li fails\n",fails);
     wavelength_ = wavelength_backup;
@@ -301,7 +282,7 @@ namespace nmie {
   // ********************************************************************** //
   // ********************************************************************** //
   void MultiLayerMieApplied::ClearTarget() {
-    isMieCalculated_ = false;
+    MarkUncalculated();
     target_width_.clear();
     target_index_.clear();
   }
@@ -309,7 +290,7 @@ namespace nmie {
   // ********************************************************************** //
   // ********************************************************************** //
   void MultiLayerMieApplied::ClearCoating() {
-    isMieCalculated_ = false;
+    MarkUncalculated();
     coating_width_.clear();
     coating_index_.clear();
   }
@@ -317,7 +298,7 @@ namespace nmie {
   // ********************************************************************** //
   // ********************************************************************** //
   void MultiLayerMieApplied::ClearLayers() {
-    isMieCalculated_ = false;
+    MarkUncalculated();
     ClearTarget();
     ClearCoating();
   }
@@ -325,7 +306,7 @@ namespace nmie {
   // ********************************************************************** //
   // ********************************************************************** //
   void MultiLayerMieApplied::ClearAllDesign() {
-    isMieCalculated_ = false;
+    MarkUncalculated();
     ClearLayers();
     size_param_.clear();
     refractive_index_.clear();
@@ -445,7 +426,7 @@ c    MM + 1  and - 1, alternately
   // ********************************************************************** //
   // ********************************************************************** //
   void MultiLayerMieApplied::ConvertToSP() {
-    isMieCalculated_ = false;
+    MarkUncalculated();
     if (target_width_.size() + coating_width_.size() == 0)
       return;  // Nothing to convert, we suppose that SP was set directly
     GenerateSizeParameter();

+ 0 - 3
src/nmie-applied.h

@@ -80,10 +80,7 @@ namespace nmie {
 
     // Set common parameters
     void SetAnglesForPattern(double from_angle, double to_angle, int samples);
-    void SetAngles(const std::vector<double>& angles);
     std::vector<double> GetAngles();
-    void SetPEC(int layer_position = 0);  // By default set PEC layer to be the first one
-    
     
     void ClearTarget();
     void ClearCoating();

+ 15 - 21
src/nmie.cc

@@ -411,9 +411,7 @@ namespace nmie {
   // Modify scattering (theta) angles                                       //
   // ********************************************************************** //
   void MultiLayerMie::SetAngles(const std::vector<double>& angles) {
-    isExpCoeffsCalc_ = false;
-    isScaCoeffsCalc_ = false;
-    isMieCalculated_ = false;
+    MarkUncalculated();
     theta_ = angles;
   }
 
@@ -422,9 +420,7 @@ namespace nmie {
   // Modify size of all layers                                             //
   // ********************************************************************** //
   void MultiLayerMie::SetAllLayersSize(const std::vector<double>& layer_size) {
-    isExpCoeffsCalc_ = false;
-    isScaCoeffsCalc_ = false;
-    isMieCalculated_ = false;
+    MarkUncalculated();
     size_param_.clear();
     double prev_layer_size = 0.0;
     for (auto curr_layer_size : layer_size) {
@@ -443,9 +439,7 @@ namespace nmie {
   // Modify refractive index of all layers                                  //
   // ********************************************************************** //
   void MultiLayerMie::SetAllLayersIndex(const std::vector< std::complex<double> >& index) {
-    isExpCoeffsCalc_ = false;
-    isScaCoeffsCalc_ = false;
-    isMieCalculated_ = false;
+    MarkUncalculated();
     refractive_index_ = index;
   }
 
@@ -466,9 +460,7 @@ namespace nmie {
   // ********************************************************************** //
   // ********************************************************************** //
   void MultiLayerMie::SetPECLayer(int layer_position) {
-    isExpCoeffsCalc_ = false;
-    isScaCoeffsCalc_ = false;
-    isMieCalculated_ = false;
+    MarkUncalculated();
     if (layer_position < 0 && layer_position != -1)
       throw std::invalid_argument("Error! Layers are numbered from 0!");
     PEC_layer_position_ = layer_position;
@@ -479,9 +471,7 @@ namespace nmie {
   // Set maximun number of terms to be used                                 //
   // ********************************************************************** //
   void MultiLayerMie::SetMaxTerms(int nmax) {
-    isExpCoeffsCalc_ = false;
-    isScaCoeffsCalc_ = false;
-    isMieCalculated_ = false;
+    MarkUncalculated();
     nmax_preset_ = nmax;
   }
 
@@ -496,14 +486,20 @@ namespace nmie {
       return 0;
   }
 
-
   // ********************************************************************** //
-  // Clear layer information                                                //
+  // Mark uncalculated                                                      //
   // ********************************************************************** //
-  void MultiLayerMie::ClearLayers() {
+  void MultiLayerMie::MarkUncalculated() {
     isExpCoeffsCalc_ = false;
     isScaCoeffsCalc_ = false;
+
     isMieCalculated_ = false;
+  }
+  // ********************************************************************** //
+  // Clear layer information                                                //
+  // ********************************************************************** //
+  void MultiLayerMie::ClearLayers() {
+    MarkUncalculated();
     size_param_.clear();
     refractive_index_.clear();
   }
@@ -963,9 +959,7 @@ namespace nmie {
 
     const std::vector<double>& x = size_param_;
 
-    isExpCoeffsCalc_ = false;
-    isScaCoeffsCalc_ = false;
-    isMieCalculated_ = false;
+    MarkUncalculated();
 
     // Calculate scattering coefficients
     calcScattCoeffs();

+ 16 - 12
src/nmie.h

@@ -35,6 +35,12 @@
 #include <vector>
 
 namespace nmie {
+  //Used constants
+  const double PI_=3.14159265358979323846;
+  // light speed [m s-1]
+  const double cc_ = 2.99792458e8;
+  // assume non-magnetic (MU=MU0=const) [N A-2]
+  const double mu_ = 4.0*PI_*1.0e-7;
   int ScattCoeffs(const unsigned int L, const int pl, std::vector<double>& x, std::vector<std::complex<double> >& m, const int nmax, std::vector<std::complex<double> >& an, std::vector<std::complex<double> >& bn);
   int nMie(const unsigned int L, const int pl, std::vector<double>& x, std::vector<std::complex<double> >& m, const unsigned int nTheta, std::vector<double>& Theta, const int nmax, 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);
   int nMie(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);
@@ -86,8 +92,10 @@ namespace nmie {
     // Get maximun number of terms
     int GetMaxTerms() {return nmax_;};
 
+    bool isMieCalculated(){return isMieCalculated_;};
     // Clear layer information
     void ClearLayers();
+    void MarkUncalculated();
 
     // Applied units requests
     double GetSizeParameter();
@@ -98,8 +106,15 @@ namespace nmie {
 
     std::vector<std::vector< std::complex<double> > > GetFieldE(){return E_;};   // {X[], Y[], Z[]}
     std::vector<std::vector< std::complex<double> > > GetFieldH(){return H_;};
-//  private:
+
   protected:
+    // Size parameter for all layers
+    std::vector<double> size_param_;
+    // Refractive index for all layers
+    std::vector< std::complex<double> > refractive_index_;
+    // Scattering angles for scattering pattern in radians
+
+  private:
     void calcNstop();
     void calcNmax(unsigned int first_layer);
 
@@ -135,11 +150,6 @@ namespace nmie {
     bool isScaCoeffsCalc_ = false;
     bool isMieCalculated_ = false;
 
-    // Size parameter for all layers
-    std::vector<double> size_param_;
-    // Refractive index for all layers
-    std::vector< std::complex<double> > refractive_index_;
-    // Scattering angles for scattering pattern in radians
     std::vector<double> theta_;
     // Should be -1 if there is no PEC.
     int PEC_layer_position_ = -1;
@@ -156,12 +166,6 @@ namespace nmie {
     std::vector<std::vector< std::complex<double> > > E_, H_;  // {X[], Y[], Z[]}
     std::vector<std::complex<double> > S1_, S2_;
 
-    //Used constants
-    const double PI_=3.14159265358979323846;
-    // light speed [m s-1]
-    double const cc_ = 2.99792458e8;
-    // assume non-magnetic (MU=MU0=const) [N A-2]
-    double const mu_ = 4.0*PI_*1.0e-7;
 
     //Temporary variables
     std::vector<std::complex<double> > PsiZeta_;