From c4d90c4fe95763054d6c876a116444775904d25a Mon Sep 17 00:00:00 2001
From: Giovanni La Mura <giovanni.lamura@inaf.it>
Date: Fri, 26 Apr 2024 15:57:41 +0200
Subject: [PATCH] Introduce a data structure for scattering angles

---
 src/include/Commons.h   | 102 ++++++++++++++++++++++++++++++++++++++++
 src/libnptm/Commons.cpp |  77 ++++++++++++++++++++++++++----
 2 files changed, 170 insertions(+), 9 deletions(-)

diff --git a/src/include/Commons.h b/src/include/Commons.h
index 04c29745..e4974553 100644
--- a/src/include/Commons.h
+++ b/src/include/Commons.h
@@ -385,4 +385,106 @@ public:
    */
   ~C9();
 };
+
+/*! \brief A data structure representing the angles to be evaluated in the problem.
+ *
+ */
+class ScatteringAngles {
+protected:
+  //! \brief Number of incident field azimuth angles.
+  int _nth;
+  //! \brief Number of scattered field azimuth angles.
+  int _nths;
+  //! \brief Number of incident field elevation angles.
+  int _nph;
+  //! \brief Number of scattered field elevation angles.
+  int _nphs;
+  //! \brief Number of incident field propagation angles.
+  int _nk;
+  //! \brief Number of scattered field propagation angles.
+  int _nks;
+  //! \brief Total number of field propagation angles.
+  int _nkks;
+  //! \brief First incident field azimuth angle.
+  double _th;
+  //! \brief Incident field azimuth angle increment.
+  double _thstp;
+  //! \brief Last incident field azimuth angle.
+  double _thlst;
+  //! \brief First scattered field azimuth angle.
+  double _ths;
+  //! \brief Scattered field azimuth angle increment.
+  double _thsstp;
+  //! \brief Last scattered field azimuth angle.
+  double _thslst;
+  //! \brief First incident field elevation angle.
+  double _ph;
+  //! \brief Incident field elevation angle increment.
+  double _phstp;
+  //! \brief Last incident field elevation angle.
+  double _phlst;
+  //! \brief First scattered field elevation angle.
+  double _phs;
+  //! \brief Scattered field elevation angle increment.
+  double _phsstp;
+  //! \brief Last scattered field elevation angle.
+  double _phslst;
+  //! \brief Azimuth scattering deflection.
+  double _thsca;
+
+public:
+  //! \brief Read only view of `_nth`.
+  const int& nth = _nth;
+  //! \brief Read only view of `_nths`.
+  const int& nths = _nths;
+  //! \brief Read only view of `_nph`.
+  const int& nph = _nph;
+  //! \brief Read only view of `_nphs`.
+  const int& nphs = _nphs;
+  //! \brief Read only view of `_nk`.
+  const int& nk = _nk;
+  //! \brief Read only view of `_nks`.
+  const int& nks = _nks;
+  //! \brief Read only view of `_nkks`.
+  const int& nkks = _nkks;
+  //! \brief Read only view of `_th`.
+  const double& th = _th;
+  //! \brief Read only view of `_thstp`.
+  const double& thstp = _thstp;
+  //! \brief Read only view of `_thlst`.
+  const double& thlst = _thlst;
+  //! \brief Read only view of `_ths`.
+  const double& ths = _ths;
+  //! \brief Read only view of `_thsstp`.
+  const double& thsstp = _thsstp;
+  //! \brief Read only view of `_thslst`.
+  const double& thslst = _thslst;
+  //! \brief Read only view of `_ph`.
+  const double& ph = _ph;
+  //! \brief Read only view of `_phstp`.
+  const double& phstp = _phstp;
+  //! \brief Read only view of `_phlst`.
+  const double& phlst = _phlst;
+  //! \brief Read only view of `_phs`.
+  const double& phs = _phs;
+  //! \brief Read only view of `_phsstp`.
+  const double& phsstp = _phsstp;
+  //! \brief Read only view of `_phslst`.
+  const double& phslst = _phslst;
+  //! \brief Read only view of `_thsca`.
+  const double& thsca = _thsca;
+
+  /*! \brief ScatteringAngles instance constructor.
+   *
+   * \param gconf: `GeometryConfiguration*` Pointer to a GeometryConfiguration object.
+   */
+  ScatteringAngles(GeometryConfiguration *gconf);
+  
+  /*! \brief ScatteringAngles copy constructor.
+   *
+   * \param rhs: `ScatteringAngles&` Reference to the ScatteringAngles object to be copied.
+   */
+  ScatteringAngles(const ScatteringAngles &rhs);
+};
+
 #endif
diff --git a/src/libnptm/Commons.cpp b/src/libnptm/Commons.cpp
index 0dca548d..df0bbee9 100644
--- a/src/libnptm/Commons.cpp
+++ b/src/libnptm/Commons.cpp
@@ -2,15 +2,7 @@
 
 /*! \file Commons.cpp
  *
- * DEVELOPMENT NOTE:
- * The construction of common blocks requires some information
- * that is stored in configuration objects and is needed to compute
- * the allocation size of vectors and matrices. Currently, this
- * information is passed as arguments to the constructors of the
- * common blocks. A simpler and more logical way to operate would
- * be to design the constructors to take as arguments only pointers
- * to the configuration objects. These, on their turn, need to
- * expose methods to access the relevant data in read-only mode.
+ * \brief Implementation of the common data structures.
  */
 #ifndef INCLUDE_TYPES_H_
 #include "../include/types.h"
@@ -536,3 +528,70 @@ C9::~C9() {
   for (int si = sam_size_0 - 1; si > -1; si--) delete[] sam[si];
   delete[] sam;
 }
+
+ScatteringAngles::ScatteringAngles(GeometryConfiguration *gconf) {
+  int isam = (int)gconf->get_param("meridional_type");
+  _th = gconf->get_param("in_theta_start");
+  _thstp = gconf->get_param("in_theta_step");
+  _thlst = gconf->get_param("in_theta_end");
+  _ths = gconf->get_param("sc_theta_start");
+  _thsstp = gconf->get_param("sc_theta_step");
+  _thslst = gconf->get_param("sc_theta_end");
+  _ph = gconf->get_param("in_phi_start");
+  _phstp = gconf->get_param("in_phi_step");
+  _phlst = gconf->get_param("in_phi_end");
+  _phs = gconf->get_param("sc_phi_start");
+  _phsstp = gconf->get_param("sc_phi_step");
+  _phslst = gconf->get_param("sc_phi_end");
+  double small = 1.0e-3;
+  _nth = 0;
+  _nph = 0;
+  if (_thstp != 0.0) _nth = int((_thlst - _th) / _thstp + small);
+  _nth++;
+  if (_phstp != 0.0) _nph = int((_phlst - _ph) / _phstp + small);
+  _nph++;
+  _nths = 0;
+  _nphs = 0;
+  _thsca = 0.0;
+  if (isam > 1) {
+    _nths = 1;
+    _thsca = _ths - _th;
+  } else { // ISAM <= 1
+    if (_thsstp == 0.0) _nths = 0;
+    else _nths = int ((_thslst - _ths) / _thsstp + small);
+    _nths++;
+  }
+  if (isam >= 1) {
+    _nphs = 1;
+  } else {
+    if (_phsstp == 0.0) _nphs = 0;
+    else _nphs = int((_phslst - _phs) / _phsstp + small);
+    _nphs++;
+  }
+  _nk = nth * nph;
+  _nks = nths * nphs;
+  _nkks = nk * nks;
+}
+
+ScatteringAngles::ScatteringAngles(const ScatteringAngles &rhs) {
+  _th = rhs._th;
+  _thstp = rhs._thstp;
+  _thlst = rhs._thlst;
+  _ths = rhs._ths;
+  _thsstp = rhs._thsstp;
+  _thslst = rhs._thslst;
+  _ph = rhs._ph;
+  _phstp = rhs._phstp;
+  _phlst = rhs._phlst;
+  _phs = rhs._phs;
+  _phsstp = rhs._phsstp;
+  _phslst = rhs._phslst;
+  _nth = rhs._nth;
+  _nph = rhs._nph;
+  _nths = rhs._nths;
+  _nphs = rhs._nphs;
+  _thsca = rhs._thsca;
+  _nk = rhs._nk;
+  _nks = rhs._nks;
+  _nkks = rhs._nkks;
+}
-- 
GitLab