Tensor Network Theory Library  Beta release 1.2.1 A library of routines for performing TNT-based operations
tntMatAppendBasisOp.m
1 %======================================================================
2 %> @ingroup matscripts
3 %> Creates the basis operator structure, where the basis operator has been provided as a matrix.
4 %> If there is a global physical symmetry (e.g. total number of bosons are being conserved), then the associated quantum numbers should be provided. Otherwise simply pass an empty array.
5 %> In this case the basis operator should be diagonal
6 %>
7 %> @param op Matrix representing the basis operator
8 %> @param qnums Quantum numbers for a physical leg of the operator
9 %>
10 %> @retval sx A struct
11 %======================================================================
12
13 function basisOp = tntMatAppendBasisOp(op,qnums)
14  d = size(op,1);
15 if (~isempty(qnums))
16  tensor.elems_type = 'blocks';
17  if (1 == size(qnums,1))
18  [qnumssorted,indmap] = sort(qnums); %qnumssorted(j) = qnums(i) j = indmap(i)
19  % find the number of blocks
20  numblocks = 1;
21  indblock = 0;
22  for j=1:d
23  if ((j > 1) && qnumssorted(j) ~= qnumssorted(j-1))
24  numblocks = numblocks + 1;
25  indblock = 1;
26  else
27  indblock = indblock+1;
28  end
29  tensor.elems.qn_tot(numblocks) = qnumssorted(j);
30  i = find(indmap==j);
31  tensor.elems.vals{numblocks}(indblock,indblock) = op(i,i);
32  tensor.elems.indmapr(1,i) = numblocks-1;
33  tensor.elems.indmapr(2,i) = indblock-1;
34  end
35  tensor.elems.indmapc = tensor.elems.indmapr;
36  else
37  tensor.elems.qn_tot = qnums;
38  tensor.elems.vals = num2cell(diag(op));
39  tensor.elems.indmapr = [0:(d -1);zeros(1,d)];
40  tensor.elems.indmapc = [0:(d-1);zeros(1,d)];
41  end
42  tensor.elems.rowlegs = 0;
43  tensor.elems.collegs = 1;
44  tensor.qn_info.qn_dir = [1,-1];
45  tensor.qn_info.qn_index = {qnums,qnums};
46 else
47  tensor.elems_type = 'values';
48  tensor.elems.vals = op;
49  tensor.qn_info.qn_dir = [0,0];
50  tensor.qn_info.qn_index = {[],[]};
51 end
52
53 tensor.dims = size(op);
54
55 basisOp.tensor = tensor;
56 basisOp.ids = 'DU';
57 basisOp.indices = {0,1};
58
59 end
60
61
62
63
64
65
function tntMatAppendBasisOp(in op, in qnums)