From d632405b329be9fafd8a71772af230db59678ce5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ne=C4=8Dada?= Date: Fri, 9 Aug 2019 17:22:56 +0300 Subject: [PATCH] Generic T-matrix generator type Former-commit-id: 84c3a0a8a1cafe2f1c3ed05cf1528e5f80443b70 --- qpms/tmatrices.c | 28 +++++++++++++++++++++++++++ qpms/tmatrices.h | 49 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+) diff --git a/qpms/tmatrices.c b/qpms/tmatrices.c index 8dac691..6b27ad5 100644 --- a/qpms/tmatrices.c +++ b/qpms/tmatrices.c @@ -343,6 +343,13 @@ qpms_errno_t qpms_tmatrix_interpolator_eval_fill(qpms_tmatrix_t *t, return QPMS_SUCCESS; } +qpms_errno_t qpms_tmatrix_generator_interpolator(qpms_tmatrix_t *t, + complex double omega, const void *interp) +{ + return qpms_tmatrix_interpolator_eval_fill(t, + (const qpms_tmatrix_interpolator_t *) interp, omega); +} + double qpms_SU2eV(double e_SU) { return e_SU * SCUFF_OMEGAUNIT / (ELECTRONVOLT / HBAR); } @@ -567,6 +574,19 @@ qpms_errno_t qpms_tmatrix_spherical_fill(qpms_tmatrix_t *t, ///< T-matrix whose return QPMS_SUCCESS; } +qpms_errno_t qpms_tmatrix_generator_sphere(qpms_tmatrix_t *t, + complex double omega, const void *params) +{ + const qpms_tmatrix_generator_sphere_param_t *p = params; + qpms_epsmu_t out = p->outside.function(omega, p->outside.params); + qpms_epsmu_t in = p->inside.function(omega, p->inside.params); + return qpms_tmatrix_spherical_fill(t, + p->radius, + qpms_wavenumber(omega, in), + qpms_wavenumber(omega, out), + in.mu, out.mu); +} + /// Convenience function to calculate T-matrix of a non-magnetic spherical \ particle using the permittivity values, replacing existing T-matrix data. qpms_errno_t qpms_tmatrix_spherical_mu0_fill( @@ -769,3 +789,11 @@ qpms_errno_t qpms_tmatrix_axialsym_fill( return QPMS_SUCCESS; } +qpms_errno_t qpms_tmatrix_generator_axialsym(qpms_tmatrix_t *t, complex double omega, const void *param) { + const qpms_tmatrix_generator_axialsym_param_t *p = param; + return qpms_tmatrix_axialsym_fill(t, omega, + p->outside.function(omega, p->outside.params), + p->inside.function(omega, p->inside.params), + p->shape, + p->lMax_extend); +} diff --git a/qpms/tmatrices.h b/qpms/tmatrices.h index 1094a22..ab21a56 100644 --- a/qpms/tmatrices.h +++ b/qpms/tmatrices.h @@ -236,6 +236,19 @@ complex double *qpms_apply_tmatrix( const qpms_tmatrix_t *T ); +/// Generic T-matrix generator function that fills a pre-initialised qpms_tmatrix_t given a frequency. +/** Implemented by: + * qpms_tmatrix_generator_axialsym() + * qpms_tmatrix_generator_interpolator() + * qpms_tmatrix_generator_sphere() + */ +typedef struct qpms_tmatrix_generator_t { + qpms_errno_t (*function) (qpms_tmatrix_t *t, ///< T-matrix to fill. + complex double omega, ///< Angular frequency. + const void *params ///< Implementation dependent parameters. + ); + const void *params; ///< Parameter pointer passed to the function. +} qpms_tmatrix_generator_t; /* Fuck this, include the whole typedef struct gsl_spline gsl_spline; // Forward declaration for the interpolator struct @@ -277,6 +290,15 @@ qpms_tmatrix_interpolator_t *qpms_tmatrix_interpolator_create(size_t n, ///< Num //, bool copy_bspec ///< if true, copies its own copy of basis spec from the first T-matrix. /*, ...? */); + +/// qpms_tmatrix_interpolator for qpms_tmatrix_generator_t. +/** As in qpms_tmatrix_interpolator_eval(), the imaginary part of frequency is discarded! + */ +qpms_errno_t qpms_tmatrix_generator_interpolator(qpms_tmatrix_t *t, ///< T-matrix to fill. + complex double omega, ///< Angular frequency. + const void *interpolator ///< Parameter of type qpms_tmatrix_interpolator_t *. +); + /// Calculates the reflection Mie-Lorentz coefficients for a spherical particle. /** * This function is based on the previous python implementation mie_coefficients() from qpms_p.py, @@ -311,6 +333,19 @@ qpms_errno_t qpms_tmatrix_spherical_fill(qpms_tmatrix_t *t, ///< T-matrix whose complex double mu_e ///< Relative permeability of the surrounding medium. ); +/// Parameter structure for qpms_tmatrix_generator_sphere(). +typedef struct qpms_tmatrix_generator_sphere_param_t { + qpms_epsmu_generator_t outside; + qpms_epsmu_generator_t inside; + double radius; +} qpms_tmatrix_generator_sphere_param_t; + +/// T-matrix generator for spherical particles using Lorentz-Mie solution. +qpms_errno_t qpms_tmatrix_generator_sphere(qpms_tmatrix_t *t, + complex double omega, + const void *params ///< Of type qpms_tmatrix_generator_sphere_param_t. + ); + /// Creates a new T-matrix of a spherical particle using the Lorentz-Mie theory. static inline qpms_tmatrix_t *qpms_tmatrix_spherical( const qpms_vswf_set_spec_t *bspec, @@ -421,6 +456,20 @@ static inline qpms_tmatrix_t *qpms_tmatrix_axialsym( return t; } +/// Parameter structure for qpms_tmatrix_generator_axialsym. +typedef struct qpms_tmatrix_generator_axialsym_param_t { + qpms_epsmu_generator_t outside; + qpms_epsmu_generator_t inside; + qpms_arc_function_t shape; + qpms_l_t lMax_extend; +} qpms_tmatrix_generator_axialsym_param_t; + + +/// qpms_tmatrix_axialsym for qpms_tmatrix_generator_t +qpms_errno_t qpms_tmatrix_generator_axialsym(qpms_tmatrix_t *t, ///< T-matrix to fill. + complex double omega, ///< Angular frequency. + const void *params ///< Parameters of type qpms_tmatrix_generator_axialsym_param_t. +); #if 0