123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- from __future__ import division
- import numpy as np
- cimport numpy as np
- cdef extern from "<vector>" namespace "std":
- cdef cppclass vector[T]:
- cppclass iterator:
- T operator*()
- iterator operator++()
- bint operator==(iterator)
- bint operator!=(iterator)
- vector()
- void push_back(T&)
- T& operator[](int)
- T& at(int)
- iterator begin()
- iterator end()
- cdef inline double *npy2c(np.ndarray a):
- assert a.dtype == np.float64
- if not (<object>a).flags["C_CONTIGUOUS"]:
- a = a.copy('C')
-
- return <double *>(a.data)
- cdef extern from "py_nmie.h":
- cdef int nMie(int L, int pl, vector[double] x, vector[complex] m, int nTheta, vector[double] Theta, int n_max, double *Qext, double *Qsca, double *Qabs, double *Qbk, double *Qpr, double *g, double *Albedo, double S1r[], double S1i[], double S2r[], double S2i[])
- cdef int nField(int L, int pl, vector[double] x, vector[complex] m, int n_max, int nCoords, vector[double] Xp, vector[double] Yp, vector[double] Zp, double Er[], double Ei[], double Hr[], double Hi[])
- def scattnlay(np.ndarray[np.float64_t, ndim = 2] x, np.ndarray[np.complex128_t, ndim = 2] m, np.ndarray[np.float64_t, ndim = 1] theta = np.zeros(0, dtype = np.float64), np.int_t pl = -1, np.int_t n_max = -1):
- cdef Py_ssize_t i
- cdef np.ndarray[np.int_t, ndim = 1] terms = np.zeros(x.shape[0], dtype = np.int)
- cdef np.ndarray[np.float64_t, ndim = 1] Qext = np.zeros(x.shape[0], dtype = np.float64)
- cdef np.ndarray[np.float64_t, ndim = 1] Qabs = np.zeros(x.shape[0], dtype = np.float64)
- cdef np.ndarray[np.float64_t, ndim = 1] Qsca = np.zeros(x.shape[0], dtype = np.float64)
- cdef np.ndarray[np.float64_t, ndim = 1] Qbk = np.zeros(x.shape[0], dtype = np.float64)
- cdef np.ndarray[np.float64_t, ndim = 1] Qpr = np.zeros(x.shape[0], dtype = np.float64)
- cdef np.ndarray[np.float64_t, ndim = 1] g = np.zeros(x.shape[0], dtype = np.float64)
- cdef np.ndarray[np.float64_t, ndim = 1] Albedo = np.zeros(x.shape[0], dtype = np.float64)
- cdef np.ndarray[np.complex128_t, ndim = 2] S1 = np.zeros((x.shape[0], theta.shape[0]), dtype = np.complex128)
- cdef np.ndarray[np.complex128_t, ndim = 2] S2 = np.zeros((x.shape[0], theta.shape[0]), dtype = np.complex128)
- cdef np.ndarray[np.float64_t, ndim = 1] S1r
- cdef np.ndarray[np.float64_t, ndim = 1] S1i
- cdef np.ndarray[np.float64_t, ndim = 1] S2r
- cdef np.ndarray[np.float64_t, ndim = 1] S2i
- for i in range(x.shape[0]):
- S1r = np.zeros(theta.shape[0], dtype = np.float64)
- S1i = np.zeros(theta.shape[0], dtype = np.float64)
- S2r = np.zeros(theta.shape[0], dtype = np.float64)
- S2i = np.zeros(theta.shape[0], dtype = np.float64)
- terms[i] = nMie(x.shape[1], pl, x[i].copy('C'), m[i].copy('C'), theta.shape[0], theta.copy('C'), n_max, &Qext[i], &Qsca[i], &Qabs[i], &Qbk[i], &Qpr[i], &g[i], &Albedo[i], npy2c(S1r), npy2c(S1i), npy2c(S2r), npy2c(S2i))
- S1[i] = S1r.copy('C') + 1.0j*S1i.copy('C')
- S2[i] = S2r.copy('C') + 1.0j*S2i.copy('C')
- return terms, Qext, Qsca, Qabs, Qbk, Qpr, g, Albedo, S1, S2
- def fieldnlay(np.ndarray[np.float64_t, ndim = 2] x, np.ndarray[np.complex128_t, ndim = 2] m, np.ndarray[np.float64_t, ndim = 2] coords = np.zeros((0, 3), dtype = np.float64), np.int_t pl = 0, np.int_t n_max = 0):
- cdef Py_ssize_t i
- cdef np.ndarray[np.int_t, ndim = 1] terms = np.zeros(x.shape[0], dtype = np.int)
- cdef np.ndarray[np.complex128_t, ndim = 2] E = np.zeros((x.shape[0], coords.shape[0]), dtype = np.complex128)
- cdef np.ndarray[np.complex128_t, ndim = 2] H = np.zeros((x.shape[0], coords.shape[0]), dtype = np.complex128)
- cdef np.ndarray[np.float64_t, ndim = 1] Er
- cdef np.ndarray[np.float64_t, ndim = 1] Ei
- cdef np.ndarray[np.float64_t, ndim = 1] Hr
- cdef np.ndarray[np.float64_t, ndim = 1] Hi
- for i in range(x.shape[0]):
- Er = np.zeros(coords.shape[0], dtype = np.float64)
- Ei = np.zeros(coords.shape[0], dtype = np.float64)
- Hr = np.zeros(coords.shape[0], dtype = np.float64)
- Hi = np.zeros(coords.shape[0], dtype = np.float64)
- terms[i] = nField(x.shape[1], pl, x[i].copy('C'), m[i].copy('C'), n_max, coords.shape[0], coords[:, 0].copy('C'), coords[:, 1].copy('C'), coords[:, 2].copy('C'), npy2c(Er), npy2c(Ei), npy2c(Hr), npy2c(Hi))
- E[i] = Er.copy('C') + 1.0j*Ei.copy('C')
- H[i] = Hr.copy('C') + 1.0j*Hi.copy('C')
- return terms, E, H
|