From b12fc991e5309d237357f91c582c067286ee4492 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ne=C4=8Dada?= Date: Sun, 22 Aug 2021 19:01:38 +0300 Subject: [PATCH] Custom python T-matrix generator test. --- .../custom_tmatrix/custom_tmatrices_simple.py | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100755 examples/api/custom_tmatrix/custom_tmatrices_simple.py diff --git a/examples/api/custom_tmatrix/custom_tmatrices_simple.py b/examples/api/custom_tmatrix/custom_tmatrices_simple.py new file mode 100755 index 0000000..b6f3d50 --- /dev/null +++ b/examples/api/custom_tmatrix/custom_tmatrices_simple.py @@ -0,0 +1,36 @@ +#!/usr/bin/env python3 +from qpms import TMatrixGenerator, BaseSpec, eV, hbar +import numpy as np +import sys + +errors = 0 + +def tmg_diagonal_fun(tmatrix, omega): + ''' + Example of a python function used as a custom T-matrix generator + + It receives a CTMatrix argument with pre-filled BaseSpec + (in tmatrix.spec) and angular frequency. + + It has to fill in the T-matrix elements tmatrix[...] + (a numpy array of shape (len(tmatrix.spec),len(tmatrix.spec))) + and return zero (on success) or other integral value on error. + + Note that this in justa an example of using the API, + not supposed to be anything physical. + ''' + l = tmatrix.spec.l() + tmatrix[...] = np.diag(1./l**2) + return 0 + +# Wrap the function as an actual TMatrixGenerator +tmg_diagonal = TMatrixGenerator(tmg_diagonal_fun) + +bspec = BaseSpec(lMax=2) + +tmatrix = tmg_diagonal(bspec, (2.0+.01j) * eV/hbar) + +errors += np.sum(tmatrix[...] != np.diag(1./bspec.l()**2)) + +sys.exit(errors) +