Eötvös Quantum Utilities  v4.9.146
Providing the Horsepowers in the Quantum Realm
dgetPartialInv_test.m
Go to the documentation of this file.
1 %======================================================================
2 % Test function for the MEX file dgetPartialInv.
3 % Copyright (C) 2009-2015 Peter Rakyta, Ph.D.
4 %
5 % This program is free software: you can redistribute it and/or modify
6 % it under the terms of the GNU General Public License as published by
7 % the Free Software Foundation, either version 3 of the License, or
8 % (at your option) any later version.
9 %
10 % This program is distributed in the hope that it will be useful,
11 % but WITHOUT ANY WARRANTY; without even the implied warranty of
12 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 % GNU General Public License for more details.
14 %
15 % You should have received a copy of the GNU General Public License
16 % along with this program. If not, see http://www.gnu.org/licenses/.
17 function dgetPartialInv_test()
18 
19  filename = mfilename('fullpath');
20  [directory, fncname] = fileparts( filename );
21  fncname = fncname(1:end-length('_test'));
22  filename = fullfile( directory, [fncname, '.', mexext] );
23 
24 
25 %% creating the test Hamiltonian
26 Opt = structures('Opt');
27 param = structures('param');
29 param.scatter.shape = structures('shape');
30 
31 param.scatter.epsilon = 0.5;
32 param.scatter.vargamma = -2;
33 Opt.Lattice_Type = 'Square';
34 param.scatter.shape.width = 100;
35 param.scatter.shape.height = 40;
36 
37 CreateH = CreateHamiltonians( Opt, param );
38 CreateH.CreateScatterH();
39 
40 Hscatter = CreateH.Read('Hscatter');
41 CreateH.Clear('Hscatter');
42 
43 display('***************************************************************************')
44 display(['The size of the test matrix is :', num2str(size(Hscatter,1)), 'x', num2str(size(Hscatter,1))])
45 
46 %% Calculeting the surface Green function
47 
48 % reordering the matrix coupling the surface sites to the right-lower corner of the matrix
49 M = CreateH.Read('M');
50 surface_sites = false(size(Hscatter,1),1);
51 surface_sites(1:M) = true;
52 surface_sites(end-M+1:end) = true;
53 
54 Hscatter = [ Hscatter(~surface_sites, ~surface_sites), Hscatter(~surface_sites, surface_sites);
55  Hscatter(surface_sites, ~surface_sites), Hscatter(surface_sites, surface_sites) ];
56 
57 % adding Complex Eenrgy
58 sizeH = size(Hscatter, 1);
59 Hscatter = sparse(1:sizeH, 1:sizeH, 0.23, sizeH, sizeH) - Hscatter;
60 
61 % Test using the mdivide method
62 display(' ')
63 display('Calculating the surface Green function with the mldivide operator:')
64 tic
65 evec = sparse( size(Hscatter,1)-2*M+1:size(Hscatter,1), 1:2*M, 1, size(Hscatter,1), 2*M);
66 G = Hscatter\evec;
67 G = G(end-2*M+1:end, :);
68 toc
69 
70 
71 % Test using the partialInv method
72 display(' ')
73 display('Calculating the surface Green function with the dgetPartialInv utility:')
74  try
75  tic
76  GpartialInv = dgetPartialInv( Hscatter, 2*M );
77  toc
78  catch err
79  warning([fncname, ' failed to run. Deleting the compiled MEX file.']);
80  delete(filename);
81  disp( err.identifier )
82  disp( err.message )
83  pause(3)
84  return
85  end
86 
87  error_num = norm( G-GpartialInv);
88  if error_num < 1e-10
89  display('***************************************************************************')
90  disp(['Test of ', fncname, ' passed.'])
91  else
92  warning(['Test of ', fncname, ' failed with an error ', num2str(error_num), '. Deleting the compiled MEX file.'])
93  delete(filename);
94  return
95  end
96 
97 
98 end
Lattice_Type
String describing the preprogrammed lattice type. See the documentation of lattice types for details.
Definition: structures.m:80
function test(arg1, arg2)
Brief description of the function.
Structure Opt contains the basic computational parameters used in EQuUs.
Definition: structures.m:60
function()
Structure param contains data structures describing the physical parameters of the scattering center ...
Definition: structures.m:45
scatter_param scatter
An instance of the structure scatter_param containing the physical parameters for the scattering regi...
Definition: structures.m:47
Structure sites contains data to identify the individual sites in a matrix.
Definition: structures.m:187
Class containing physical parameters of a scattering center defined on a square lattice.
function dgetPartialInv_test()
function structures(name)
A class to create and store Hamiltonian of the scattering region.