From 31f6bb9a2549d73e4c4299008f2066a08c12e3e2 Mon Sep 17 00:00:00 2001 From: Giovanni La Mura <giovanni.lamura@inaf.it> Date: Tue, 20 Feb 2024 13:02:56 +0100 Subject: [PATCH] Introduce the trapping configuration class --- src/include/tfrfme.h | 115 ++++++++++++++++++++++++++++++++++++++++ src/libnptm/tfrfme.cpp | 69 ++++++++++++++++++++++++ src/trapping/cfrfme.cpp | 2 +- 3 files changed, 185 insertions(+), 1 deletion(-) create mode 100644 src/include/tfrfme.h create mode 100644 src/libnptm/tfrfme.cpp diff --git a/src/include/tfrfme.h b/src/include/tfrfme.h new file mode 100644 index 00000000..8bb9a7fc --- /dev/null +++ b/src/include/tfrfme.h @@ -0,0 +1,115 @@ +/*! \file tfrfme.h + * + * \brief Representation of the trapping configuration objects. + */ + +#ifndef INCLUDE_TFRFME_H_ +#define INCLUDE_TFRFME_H_ + +/*! \brief Class to represent the trapping configuration. + */ +class TFRFME { + private: + //! NLMMT = 2 * LM * (LM + 2) + int nlmmt; + //! NRVC = NXV * NYV * NZV + int nrvc; + + protected: + //! Field expansion mode identifier. + int lmode; + //! Maximim field expansion order; + int lm; + //! QUESTION: definition? + int nkv; + //! Number of computed X coordinates. + int nxv; + //! Number of computed Y coordinates. + int nyv; + //! Number of computed Z coordinates. + int nzv; + //! Wave number in scale units + double vk; + //! External medium refractive index + double exri; + //! QUESTION: definition? + double an; + //! QUESTION: definition? + double ff; + //! QUESTION: definition? + double tra; + //! QUESTION: definition? + double spd; + //! QUESTION: definition? + double frsh; + //! QUESTION: definition? + double exril; + //! Vector of computed x positions + double *xv; + //! Vector of computed y positions + double *yv; + //! Vector of computed z positions + double *zv; + //! QUESTION: definition? + complex<double> **wsum; + + public: + /*! \briesf Trapping configuration instance constructor. + */ + TFRFME( + int _lmode, int _lm, int _nkv, int _nxv, int _nyv, int _nzv +); + + /*! \briesf Trapping configuration instance destroyer. + */ + ~TFRFME(); + + /*! \briesf Load a trapping configuration instance from binary file. + * + * \param file_name: `string` Name of the file. + * \param format: `string` Format of the file (can be either "HDF5" + * or "LGEACY". Default is "LEGACY"). + * \return instance: `TFRFME *` Pointer to anewly created configuration + * instance. + */ + TFRFME* from_binary(std::string file_name, std::string format="LEGACY"); + + /*! \brief Get an element from the WSUM matrix. + * + * \param row: `int` Row index of the element to be read. + * \param col: `int` Column index of the element to be read. + * \return value: `complex<double>` The value of the requested element. + */ + std::complex<double> get_matrix_element(int row, int col); + + /*! \brief Get a configuration parameter. + * + * \param param_name: `string` Name of the parameter. + * \return value: `double` The value of the requested parameter. + */ + double get_param(std::string param_name); + + /*! \brief Set an element in the WSUM matrix. + * + * \param row: `int` Row index of the element to be read. + * \param col: `int` Column index of the element to be read. + * \param value: `complex<double>` The value to be placed in the matrix. + */ + void set_matrix_element(int row, int col, std::complex<double> value); + + /*! \brief Set a configuration parameter. + * + * \param param_name: `string` Name of the parameter. + * \param value: `double` Value to be stored as parameter. + */ + void set_param(std::string param_name, double value); + + /*! \briesf Write a trapping configuration instance to binary file. + * + * \param file_name: `string` Name of the file. + * \param format: `string` Format of the file (can be either "HDF5" + * or "LGEACY". Default is "LEGACY"). + */ + void write_binary(std::string file_name, std::string format="LEGACY"); +}; +#endif diff --git a/src/libnptm/tfrfme.cpp b/src/libnptm/tfrfme.cpp new file mode 100644 index 00000000..1dffdf06 --- /dev/null +++ b/src/libnptm/tfrfme.cpp @@ -0,0 +1,69 @@ +/*! \file tfrfme.cpp + * + * \brief Implementation of the trapping configuration objects. + */ + +#include<complex> +#include<string> + +#ifndef INCLUDE_TFRFME_H_ +#include "../include/tfrfme.cpp" +#endif + +using namespace std; + +TFRFME::TFRFME(int _lmode, int _lm, int _nkv, int _nxv, int _nyv, int _nzv) { + lmode = _lmode; + lm = _lm; + nkv = _nkv; + nxv = _nxv; + nyv = _nyv; + nzv = _nzv; + vk = 0.0; + exri = 0.0; + an = 0.0; + ff = 0.0; + tra = 0.0; + spd = 0.0; + frsh = 0.0; + exril = 0.0; + + // Array initialization + xv = new double[nxv](); + yv = new double[nyv](); + zv = new double[nzv](); + nlmmt = lm * (lm + 2) * 2; + nrvc = nxv * nyv * nzv; + wsum = new complex<double>*[nlmmt]; + for (int wi = 0; wi < nlmmt; wi++) wsum[wi] = new complex<double>[nrvc](); +} + +TFRFME::~TFRFME() { + delete[] xv; + delete[] yv; + delete[] zv; + for (int wi = nlmmt - 1; wi > -1; wi--) delete[] wsum[wi]; + delete[] wsum; +} + +TFRFME::TFRFME* from_binary(string file_name, string format) { + TFRFME *instance = NULL; + return instance; +} + +TFRFME::double get_param(string param_name) { + double value; + if (param_name.compare("exri") == 0) value = exri; + else if (param_name.compare("an") == 0) value = an; + else if (param_name.compare("ff") == 0) value = ff; + else if (param_name.compare("tra") == 0) value = tra; + else if (param_name.compare("spd") == 0) value = spd; + else if (param_name.compare("frsh") == 0) value = frsh; + else if (param_name.compare("exril") == 0) value = exril; + //TODO: add else clause with exception. + return value; +} + +TFRFME::void write_binary(string file_name, string format) { + return; +} diff --git a/src/trapping/cfrfme.cpp b/src/trapping/cfrfme.cpp index 5c1eae84..f4df0fe3 100644 --- a/src/trapping/cfrfme.cpp +++ b/src/trapping/cfrfme.cpp @@ -412,7 +412,7 @@ void frfme(string data_file, string output_path) { } // label 88 for (int ixyz = 0; ixyz < nrvc; ixyz++) { - for (int j = 0; j< jlml; j++) { + for (int j = 0; j < jlml; j++) { double vreal = wsum[j][ixyz].real(); double vimag = wsum[j][ixyz].imag(); tfrfme.write(reinterpret_cast<char *>(&vreal), sizeof(double)); -- GitLab