Fix reciprocal basis (transposition) in argproc.py
[qpms.git] / misc / 201903_finiterectlat_AaroBEC.py
blob7ccacce4f9b2ed2284c429356012a917752e1fa5
1 #!/usr/bin/env python
2 # coding: utf-8
3 from qpms import Particle, CTMatrix, BaseSpec, FinitePointGroup, ScatteringSystem, TMatrixInterpolator, eV, hbar, c, MaterialInterpolator, scatsystem_set_nthreads
4 from qpms.symmetries import point_group_info
5 import numpy as np
6 import os
7 import sys
8 from pathlib import Path
10 if 'SLURM_CPUS_PER_TASK' in os.environ:
11 scatsystem_set_nthreads(int(os.environ['SLURM_CPUS_PER_TASK']))
12 nm = 1e-9
14 rewrite_output = '--rewrite-output' in sys.argv
16 sym = FinitePointGroup(point_group_info['D2h'])
17 bspec = BaseSpec(lMax = 2)
18 tmfile = '/m/phys/project/qd/Marek/tmatrix-experiments/Cylinder/AaroBEC/cylinder_50nm_lMax4_longer.TMatrix'
19 #outputdatadir = '/home/necadam1/wrkdir/AaroBECfinite_new'
20 outputdatadir = '/u/46/necadam1/unix/project/AaroBECfinite_new'
21 os.makedirs(outputdatadir, exist_ok = True)
22 interp = TMatrixInterpolator(tmfile, bspec, symmetrise = sym, atol = 1e-8)
23 # There is only one t-matrix in the system for each frequency. We initialize the matrix with the lowest frequency data.
24 # Later, we can replace it using the tmatrix[...] = interp(freq) and s.update_tmatrices NOT YET; TODO
26 omega = float(sys.argv[3]) * eV/hbar
27 sv_threshold = float(sys.argv[4])
29 # Now place the particles and set background index.
30 px = 571*nm; py = 621*nm
31 n = 1.52
32 Nx = int(sys.argv[1])
33 Ny = int(sys.argv[2])
35 orig_x = (np.arange(Nx/2) + (0 if (Nx % 2) else .5)) * px
36 orig_y = (np.arange(Ny/2) + (0 if (Ny % 2) else .5)) * py
38 orig_xy = np.stack(np.meshgrid(orig_x, orig_y), axis = -1)
40 tmatrix = interp(omega)
41 #print(tmatrix.m)
43 particles = [Particle(orig_xy[i], tmatrix) for i in np.ndindex(orig_xy.shape[:-1])]
45 ss = ScatteringSystem(particles, sym)
47 k = n * omega / c
49 for iri in range(ss.nirreps):
50 destpath = os.path.join(outputdatadir, 'Nx%d_Ny%d_%geV_ir%d.npz'%(Nx, Ny, omega/eV*hbar, iri,))
51 touchpath = os.path.join(outputdatadir, 'Nx%d_Ny%d_%geV_ir%d.done'%(Nx, Ny, omega/eV*hbar, iri,))
52 if (os.path.isfile(destpath) or os.path.isfile(touchpath)) and not rewrite_output:
53 print(destpath, 'already exists, skipping')
54 continue
55 mm_iri = ss.modeproblem_matrix_packed(k, iri)
56 #print(mm_iri)
57 U, S, Vh = np.linalg.svd(mm_iri)
58 del U
59 print(iri, ss.irrep_names[iri], S[-1])
60 starti = max(0,len(S) - np.searchsorted(S[::-1], sv_threshold, side='left')-1)
61 np.savez(destpath,
62 S=S[starti:], omega=omega, Vh = Vh[starti:], iri=iri, Nx = Nx, Ny= Ny )
63 del S
64 del Vh
65 Path(touchpath).touch()
66 # Don't forget to conjugate Vh before transforming it to the full vector!