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
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']))
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
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
)
43 particles
= [Particle(orig_xy
[i
], tmatrix
) for i
in np
.ndindex(orig_xy
.shape
[:-1])]
45 ss
= ScatteringSystem(particles
, sym
)
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')
55 mm_iri
= ss
.modeproblem_matrix_packed(k
, iri
)
57 U
, S
, Vh
= np
.linalg
.svd(mm_iri
)
59 print(iri
, ss
.irrep_names
[iri
], S
[-1])
60 starti
= max(0,len(S
) - np
.searchsorted(S
[::-1], sv_threshold
, side
='left')-1)
62 S
=S
[starti
:], omega
=omega
, Vh
= Vh
[starti
:], iri
=iri
, Nx
= Nx
, Ny
= Ny
)
65 Path(touchpath
).touch()
66 # Don't forget to conjugate Vh before transforming it to the full vector!