From ffb4bab36500d0ba0486a0d1f9508808923b8d8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ne=C4=8Dada?= Date: Mon, 4 Apr 2022 09:43:02 +0300 Subject: [PATCH] Dummy (zero) T-matrix generator --- qpms/cytmatrices.pyx | 16 ++++++++++++++++ qpms/qpms_cdefs.pxd | 1 + qpms/tmatrices.c | 6 ++++++ qpms/tmatrices.h | 12 +++++++++++- 4 files changed, 34 insertions(+), 1 deletion(-) diff --git a/qpms/cytmatrices.pyx b/qpms/cytmatrices.pyx index 91a22af..b447449 100644 --- a/qpms/cytmatrices.pyx +++ b/qpms/cytmatrices.pyx @@ -286,6 +286,10 @@ cdef class TMatrixGenerator: self.holder = what self.g.function = qpms_tmatrix_generator_interpolator self.g.params = (self.holder).rawpointer() + elif what == 0: + self.holder = 0 + self.g.function = qpms_tmatrix_generator_zero + self.g.params = 0 elif callable(what): warnings.warn("Custom python T-matrix generators are an experimental feature. Also expect it to be slow.") self.holder = what @@ -403,3 +407,15 @@ cdef class TMatrixGenerator: EpsMuGenerator(outside), EpsMuGenerator(inside), ArcFunction(__ArcCylinder(r, h)), *args, **kwargs)) + @staticmethod + def dummy(): + """Returns a dummy T-matrix generator (returns a zero T-matrix). + + Returns + ------- + tmgen_dummy : TMatrixGenerator + """ + return tmgen_dummy + +# pre-generate a dummy TMatrixGenerator (which returns zero T-matrix) +tmgen_dummy = TMatrixGenerator(0) diff --git a/qpms/qpms_cdefs.pxd b/qpms/qpms_cdefs.pxd index 42e6423..a368b40 100644 --- a/qpms/qpms_cdefs.pxd +++ b/qpms/qpms_cdefs.pxd @@ -496,6 +496,7 @@ cdef extern from "tmatrices.h": qpms_errno_t qpms_tmatrix_generator_interpolator(qpms_tmatrix_t *t, cdouble omega, const void *params) qpms_errno_t qpms_tmatrix_generator_sphere(qpms_tmatrix_t *t, cdouble omega, const void *params) qpms_errno_t qpms_tmatrix_generator_constant(qpms_tmatrix_t *t, cdouble omega, const void *params) + qpms_errno_t qpms_tmatrix_generator_zero(qpms_tmatrix_t *t, cdouble omega, const void *params) struct qpms_tmatrix_generator_sphere_param_t: qpms_epsmu_generator_t outside qpms_epsmu_generator_t inside diff --git a/qpms/tmatrices.c b/qpms/tmatrices.c index 5ae6beb..7ac501f 100644 --- a/qpms/tmatrices.c +++ b/qpms/tmatrices.c @@ -988,6 +988,12 @@ qpms_errno_t qpms_tmatrix_generator_constant(qpms_tmatrix_t *t, return QPMS_SUCCESS; } +qpms_errno_t qpms_tmatrix_generator_zero(qpms_tmatrix_t *t, + complex double omega_ignored, const void *params_ignored) { + memset(t->m, 0, SQ(t->spec->n)*sizeof(*(t->m))); + return QPMS_SUCCESS; +} + void qpms_tmatrix_operation_clear(qpms_tmatrix_operation_t *f) { switch(f->typ) { case QPMS_TMATRIX_OPERATION_NOOP: diff --git a/qpms/tmatrices.h b/qpms/tmatrices.h index 30361c9..ee95d05 100644 --- a/qpms/tmatrices.h +++ b/qpms/tmatrices.h @@ -258,6 +258,7 @@ _Complex double *qpms_apply_tmatrix( * qpms_tmatrix_generator_interpolator() * qpms_tmatrix_generator_sphere() * qpms_tmatrix_generator_constant() + * qpms_tmatrix_generator_zero() */ typedef struct qpms_tmatrix_generator_t { qpms_errno_t (*function) (qpms_tmatrix_t *t, ///< T-matrix to fill. @@ -279,11 +280,20 @@ qpms_tmatrix_t *qpms_tmatrix_init_from_generator( * the same base spec. */ qpms_errno_t qpms_tmatrix_generator_constant(qpms_tmatrix_t *t, - _Complex double omega, + _Complex double omega_ignored, /// Source T-matrix, real type is (const qpms_tmatrix_t*). const void *tmatrix_orig ); +/// Dummy implementation of qpms_tmatrix_generator_t, yielding a zero matrix. +/** + * This effectively represents a part of the background medium without + * any scatterer present. + */ +qpms_errno_t qpms_tmatrix_generator_zero(qpms_tmatrix_t *t, + _Complex double omega_ignored, + const void *params_ignored); + /* Fuck this, include the whole typedef struct gsl_spline gsl_spline; // Forward declaration for the interpolator struct typedef struct gsl_interp_type gsl_interp_type;