From 5a9219a4f67d7ed3cb5a495e0d382d57d6abb22f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ne=C4=8Dada?= Date: Wed, 14 Aug 2019 11:04:42 +0300 Subject: [PATCH] Expose single vswf functions to cython. Former-commit-id: 7fd1183cdab2d6f60b446879a875dab4d673da73 --- qpms/__init__.py | 5 +++-- qpms/cybspec.pyx | 1 + qpms/cywaves.pyx | 20 ++++++++++++++++++++ qpms/qpms_c.pyx | 2 +- qpms/qpms_cdefs.pxd | 2 ++ qpms/vswf.h | 8 ++++---- setup.py | 6 +++++- 7 files changed, 36 insertions(+), 8 deletions(-) create mode 100644 qpms/cywaves.pyx diff --git a/qpms/__init__.py b/qpms/__init__.py index 5f73da3..00a1f0f 100644 --- a/qpms/__init__.py +++ b/qpms/__init__.py @@ -18,11 +18,12 @@ except ImportError as ex: raise ex from .qpms_p import * from .cyquaternions import CQuat, IRot3 -from .cybspec import VSWFNorm, BaseSpec +from .cybspec import VSWFNorm, BaseSpec, default_bspec from .cytmatrices import CTMatrix, TMatrixInterpolator, TMatrixGenerator from .cytranslations import trans_calculator from .cymaterials import MaterialInterpolator, EpsMu, LorentzDrudeModel, lorentz_drude, EpsMuGenerator -from .cycommon import dbgmsg_enable, dbgmsg_disable, dbgmsg_active, BesselType +from .cycommon import dbgmsg_enable, dbgmsg_disable, dbgmsg_active, BesselType, VSWFType +from .cywaves import vswf_single from .lattices2d import * from .hexpoints import * from .tmatrices import * diff --git a/qpms/cybspec.pyx b/qpms/cybspec.pyx index 2faf05b..7e6ad16 100644 --- a/qpms/cybspec.pyx +++ b/qpms/cybspec.pyx @@ -119,3 +119,4 @@ cdef class BaseSpec: def __get__(self): return VSWFNorm(self.s.norm) +default_bspec = BaseSpec(lMax=2) diff --git a/qpms/cywaves.pyx b/qpms/cywaves.pyx new file mode 100644 index 0000000..bd1877d --- /dev/null +++ b/qpms/cywaves.pyx @@ -0,0 +1,20 @@ +from qpms_cdefs cimport * + +from .cybspec cimport BaseSpec +from .cybspec import VSWFNorm, default_bspec +from .cycommon import VSWFType, BesselType + +def vswf_single(kr_csph, qpms_vswf_type_t t, qpms_l_t l, qpms_m_t m, + qpms_bessel_t btyp = QPMS_BESSEL_REGULAR, qpms_normalisation_t norm = default_bspec.norm): + cdef csph_t kr + kr.r, kr.theta, kr.phi = kr_csph + if t == QPMS_VSWF_ELECTRIC: + return qpms_vswf_single_el_csph(m, l, kr, btyp, norm) + elif t == QPMS_VSWF_MAGNETIC: + return qpms_vswf_single_mg_csph(m, l, kr, btyp, norm) + elif t == QPMS_VSWF_LONGITUDINAL: + raise NotImplementedError("Longitudinal single waves not yet implemented, sorry.") + else: + raise ValueError("Invalid wave type specified") + + diff --git a/qpms/qpms_c.pyx b/qpms/qpms_c.pyx index 58941cf..9660c1e 100644 --- a/qpms/qpms_c.pyx +++ b/qpms/qpms_c.pyx @@ -488,7 +488,7 @@ cdef class ScatteringMatrix: qpms_scatsys_scatter_solve(&f_view[0], &a_view[0], self.lu) return f -def pitau(double theta, qpms_l_t lMax, double csphase = 1): +def pitau(double theta, qpms_l_t lMax, double csphase = -1): if(abs(csphase) != 1): raise ValueError("csphase must be 1 or -1, is %g" % csphase) cdef size_t nelem = qpms_lMax2nelem(lMax) diff --git a/qpms/qpms_cdefs.pxd b/qpms/qpms_cdefs.pxd index fc7d7b6..9d7378a 100644 --- a/qpms/qpms_cdefs.pxd +++ b/qpms/qpms_cdefs.pxd @@ -160,6 +160,8 @@ cdef extern from "vswf.h": qpms_incfield_planewave_params_E E qpms_errno_t qpms_incfield_planewave(cdouble target, const qpms_vswf_set_spec_t *bspec, const cart3_t evalpoint, const void *args, bint add) + csphvec_t qpms_vswf_single_el_csph(qpms_m_t m, qpms_l_t n, csph_t kdlj, qpms_bessel_t btyp, qpms_normalisation_t norm) + csphvec_t qpms_vswf_single_mg_csph(qpms_m_t m, qpms_l_t n, csph_t kdlj, qpms_bessel_t btyp, qpms_normalisation_t norm) cdef extern from "indexing.h": qpms_y_t qpms_lMax2nelem(qpms_l_t lMax) diff --git a/qpms/vswf.h b/qpms/vswf.h index 334b001..90ac7a5 100644 --- a/qpms/vswf.h +++ b/qpms/vswf.h @@ -128,16 +128,16 @@ qpms_errno_t qpms_incfield_planewave( // ----------------------------------------------------------------------- /// Electric wave N. -csphvec_t qpms_vswf_single_el(int m, int n, sph_t kdlj, +csphvec_t qpms_vswf_single_el(qpms_m_t m, qpms_l_t n, sph_t kdlj, qpms_bessel_t btyp, qpms_normalisation_t norm); /// Magnetic wave M. -csphvec_t qpms_vswf_single_mg(int m, int n, sph_t kdlj, +csphvec_t qpms_vswf_single_mg(qpms_m_t m, qpms_l_t n, sph_t kdlj, qpms_bessel_t btyp, qpms_normalisation_t norm); /// Electric wave N, complex wave number version. -csphvec_t qpms_vswf_single_el_csph(int m, int n, csph_t kdlj, +csphvec_t qpms_vswf_single_el_csph(qpms_m_t m, qpms_l_t n, csph_t kdlj, qpms_bessel_t btyp, qpms_normalisation_t norm); /// Magnetic wave M, complex wave number version.. -csphvec_t qpms_vswf_single_mg_csph(int m, int n, csph_t kdlj, +csphvec_t qpms_vswf_single_mg_csph(qpms_m_t m, qpms_l_t n, csph_t kdlj, qpms_bessel_t btyp, qpms_normalisation_t norm); /// Set of electric and magnetic VSWF values in spherical coordinate basis. diff --git a/setup.py b/setup.py index 77a2a59..4ae09d2 100755 --- a/setup.py +++ b/setup.py @@ -92,6 +92,10 @@ cytmatrices = Extension('qpms.cytmatrices', #extra_link_args=['qpms/libqpms.a', 'amos/libamos.a'], libraries=['qpms', 'gsl', 'lapacke', 'blas', 'gslcblas', 'pthread',] ) +cywaves = Extension('qpms.cywaves', + sources = ['qpms/cywaves.pyx'], + libraries=['qpms', 'gsl', 'lapacke', 'blas', 'gslcblas', 'pthread',] + ) cytranslations = Extension('qpms.cytranslations', sources = ['qpms/cytranslations.pyx', 'qpms/translations_python.c', @@ -140,7 +144,7 @@ setup(name='qpms', #'quaternion','spherical_functions', 'scipy>=0.18.0', 'sympy>=1.2'], #dependency_links=['https://github.com/moble/quaternion/archive/v2.0.tar.gz','https://github.com/moble/spherical_functions/archive/master.zip'], - ext_modules=cythonize([qpms_c, cytranslations, cytmatrices, cycommon, cyquaternions, cybspec, cymaterials], include_path=['qpms', 'amos'], gdb_debug=True), + ext_modules=cythonize([qpms_c, cywaves, cytranslations, cytmatrices, cycommon, cyquaternions, cybspec, cymaterials], include_path=['qpms', 'amos'], gdb_debug=True), cmdclass = {'build_ext': build_ext}, zip_safe=False )