From 6ccaa5da1869e1748dea2905fb19aaf783b95636 Mon Sep 17 00:00:00 2001 From: Giovanni La Mura <giovanni.lamura@inaf.it> Date: Thu, 28 Mar 2024 12:31:36 +0100 Subject: [PATCH] Build C1 objects from scatterer and geometry configurations --- src/include/Commons.h | 8 +++----- src/include/Configuration.h | 22 ++++++++-------------- src/libnptm/Commons.cpp | 30 +++++++++++++++++------------- src/libnptm/clu_subs.cpp | 4 ++++ src/libnptm/sph_subs.cpp | 4 ++++ src/libnptm/tra_subs.cpp | 4 ++++ src/sphere/sphere.cpp | 13 ++++--------- 7 files changed, 44 insertions(+), 41 deletions(-) diff --git a/src/include/Commons.h b/src/include/Commons.h index 90a911eb..01365824 100644 --- a/src/include/Commons.h +++ b/src/include/Commons.h @@ -99,12 +99,10 @@ public: /*! \brief C1 instance constructor. * - * \param ns: `int` Number of spheres. - * \param l_max: `int` Maximum order of field expansion. - * \param nshl: `int *` Array of number of layers in spheres. - * \param iog: `int *` Vector of spherical units ID numbers. + * \param gconf: `GeometryConfiguration *` Pointer to a geometry configuration object. + * \param sconf: `ScattererConfiguration *` Pointer to a scatterer configuration object. */ - C1(int ns, int l_max, int *nshl, int *iog); + C1(GeometryConfiguration *gconf, ScattererConfiguration *sconf); /*! \brief C1 instance constructor copying all contents from a preexisting template * diff --git a/src/include/Configuration.h b/src/include/Configuration.h index f64330bf..81254833 100644 --- a/src/include/Configuration.h +++ b/src/include/Configuration.h @@ -422,29 +422,23 @@ public: /*! \brief Get the ID of a configuration from the index of the sphere. * - * This is a specialized function to a configuration ID through the index of + * This is a specialized function to get a configuration ID through the index of * the sphere it applies to. * + * \param index: `int` Index of the sphere. * \return ID: `int` ID of the configuration to be applied. */ int get_iog(int index) { return iog_vec[index]; } - /*! \brief Get the address of the configuration ID vector. + /*! \brief Get the number of layers for a given configuration. * - * This is a specialized function to access the configuration ID vector. + * This is a specialized function to get the number of layers in a specific + * configuration. * - * \return ptr: `int *` Pointer to the configuration index vector. + * \param index: `int` Index of the configuration. + * \return nl: `int` The number of layers for the given configuration. */ - int *get_iog_vec() { return iog_vec; } - - /*! \brief Get the address of the layer number vector. - * - * This is a specialized function to access the vector of layer numbers for the - * different configurations. - * - * \return ptr: `int *` Pointer to the vector of layer numbers. - */ - int *get_nshl() { return nshl_vec; } + int get_nshl(int index) { return nshl_vec[index]; } /*! \brief Get the value of a parameter by name. * diff --git a/src/libnptm/Commons.cpp b/src/libnptm/Commons.cpp index b1049638..03e19e69 100644 --- a/src/libnptm/Commons.cpp +++ b/src/libnptm/Commons.cpp @@ -16,14 +16,18 @@ #include "../include/types.h" #endif +#ifndef INCLUDE_CONFIGURATION_H_ +#include "../include/Configuration.h" +#endif + #ifndef INCLUDE_COMMONS_H #include "../include/Commons.h" #endif -C1::C1(int ns, int l_max, int *_nshl, int *_iog) { - nlmmt = 2 * (l_max * (l_max + 2)); - nsph = ns; - lm = l_max; +C1::C1(GeometryConfiguration *gconf, ScattererConfiguration *sconf) { + lm = (int)gconf->get_param("l_max"); + nsph = (int)gconf->get_param("nsph"); + nlmmt = 2 * (lm * (lm + 2)); vec_rmi = new dcomplex[nsph * lm](); vec_rei = new dcomplex[nsph * lm](); @@ -36,23 +40,20 @@ C1::C1(int ns, int l_max, int *_nshl, int *_iog) { vec_w = new dcomplex[4 * nlmmt](); w = new dcomplex*[nlmmt]; for (int wi = 0; wi < nlmmt; wi++) w[wi] = &(vec_w[4 * wi]); - configurations = 0; - for (int ci = 1; ci <= nsph; ci++) { - if (_iog[ci - 1] >= ci) configurations++; - } + configurations = (int)sconf->get_param("configurations"); vint = new dcomplex[16](); vec_vints = new dcomplex[nsph * 16](); vints = new dcomplex*[nsph]; - rc = new double*[nsph]; - nshl = new int[nsph](); + rc = new double*[configurations]; + nshl = new int[configurations](); iog = new int[nsph](); int conf_index = 0; for (int vi = 0; vi < nsph; vi++) { vints[vi] = &(vec_vints[vi * 16]); - iog[vi] = _iog[vi]; + iog[vi] = sconf->get_iog(vi); if (iog[vi] >= vi + 1) { - nshl[conf_index] = _nshl[conf_index]; - rc[conf_index] = new double[_nshl[conf_index]](); + nshl[conf_index] = sconf->get_nshl(conf_index); + rc[conf_index] = new double[nshl[conf_index]](); conf_index++; } } @@ -68,6 +69,9 @@ C1::C1(int ns, int l_max, int *_nshl, int *_iog) { ryy = new double[nsph](); rzz = new double[nsph](); ros = new double[nsph](); + for (int ri = 0; ri < nsph; ri++) { + ros[ri] = sconf->get_radius(ri); + } sas = new dcomplex**[nsph]; for (int si = 0; si < nsph; si++) { diff --git a/src/libnptm/clu_subs.cpp b/src/libnptm/clu_subs.cpp index 2473d636..e6a24d5f 100644 --- a/src/libnptm/clu_subs.cpp +++ b/src/libnptm/clu_subs.cpp @@ -9,6 +9,10 @@ #include "../include/types.h" #endif +#ifndef INCLUDE_CONFIGURATION_H_ +#include "../include/Configuration.h" +#endif + #ifndef INCLUDE_COMMONS_H_ #include "../include/Commons.h" #endif diff --git a/src/libnptm/sph_subs.cpp b/src/libnptm/sph_subs.cpp index f3a7d54d..ec130527 100644 --- a/src/libnptm/sph_subs.cpp +++ b/src/libnptm/sph_subs.cpp @@ -8,6 +8,10 @@ #include "../include/types.h" #endif +#ifndef INCLUDE_CONFIGURATION_H_ +#include "../include/Configuration.h" +#endif + #ifndef INCLUDE_COMMONS_H_ #include "../include/Commons.h" #endif diff --git a/src/libnptm/tra_subs.cpp b/src/libnptm/tra_subs.cpp index 2591b8c3..74b8f1b6 100644 --- a/src/libnptm/tra_subs.cpp +++ b/src/libnptm/tra_subs.cpp @@ -11,6 +11,10 @@ #include "../include/types.h" #endif +#ifndef INCLUDE_CONFIGURATION_H_ +#include "../include/Configuration.h" +#endif + #ifndef INCLUDE_COMMONS_H_ #include "../include/Commons.h" #endif diff --git a/src/sphere/sphere.cpp b/src/sphere/sphere.cpp index 866368b5..c2c9c5e5 100644 --- a/src/sphere/sphere.cpp +++ b/src/sphere/sphere.cpp @@ -115,12 +115,7 @@ void sphere(string config_file, string data_file, string output_path) { double cfmp, cfsp, sfmp, sfsp; int jw; int l_max = gconf->get_param("l_max"); - int *iog_vec = sconf->get_iog_vec(); - int *nshl_vec = sconf->get_nshl(); - C1 *c1 = new C1(nsph, l_max, nshl_vec, iog_vec); - for (int i = 0; i < nsph; i++) { - c1->ros[i] = sconf->get_radius(i); - } + C1 *c1 = new C1(gconf, sconf); int npnt = (int)gconf->get_param("npnt"); int npntts = (int)gconf->get_param("npntts"); int in_pol = (int)gconf->get_param("in_pol"); @@ -262,7 +257,7 @@ void sphere(string config_file, string data_file, string output_path) { tppoan.write(reinterpret_cast<char *>(&nsph), sizeof(int)); for (int nsi = 0; nsi < nsph; nsi++) - tppoan.write(reinterpret_cast<char *>(&(iog_vec[nsi])), sizeof(int)); + tppoan.write(reinterpret_cast<char *>(&(c1->iog[nsi])), sizeof(int)); if (in_pol == 0) fprintf(output, " LIN\n"); else fprintf(output, " CIRC\n"); fprintf(output, " \n"); @@ -295,7 +290,7 @@ void sphere(string config_file, string data_file, string output_path) { tppoan.write(reinterpret_cast<char *>(&vk), sizeof(double)); for (int i132 = 0; i132 < nsph; i132++) { int i = i132 + 1; - int iogi = iog_vec[i132]; + int iogi = c1->iog[i132]; if (iogi != i) { for (int l123 = 0; l123 < l_max; l123++) { c1->rmi[l123][i132] = c1->rmi[l123][iogi - 1]; @@ -303,7 +298,7 @@ void sphere(string config_file, string data_file, string output_path) { } continue; // i132 } - int nsh = nshl_vec[i132]; + int nsh = c1->nshl[i132]; int ici = (nsh + 1) / 2; if (idfc == 0) { for (int ic = 0; ic < ici; ic++) -- GitLab