Tensor Network Theory Library  Beta release 1.2.1 A library of routines for performing TNT-based operations
tntMatCreateBasisOp.m
1 %======================================================================
2 %> @ingroup matscripts
3 %> Creates the tntSystem structure and initialises it with 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 %> @note If the tntSystem variable already exists and you want to add the
12 %> basisOp to it, use tntMatAppendBasisOp() instead.
13 %======================================================================
14
15 function tntSystem = tntMatCreateBasisOp(op,qnums)
16  d = size(op,1);
17 if (~isempty(qnums))
18  tensor.elems_type = 'blocks';
19  if (1 == size(qnums,1))
20  [qnumssorted,indmap] = sort(qnums); %qnumssorted(j) = qnums(i) j = indmap(i)
21  % find the number of blocks
22  numblocks = 1;
23  indblock = 0;
24  for j=1:d
25  if ((j > 1) && qnumssorted(j) ~= qnumssorted(j-1))
26  numblocks = numblocks + 1;
27  indblock = 1;
28  else
29  indblock = indblock+1;
30  end
31  tensor.elems.qn_tot(numblocks) = qnumssorted(j);
32  i = find(indmap==j);
33  tensor.elems.vals{numblocks}(indblock,indblock) = op(i,i);
34  tensor.elems.indmapr(1,i) = numblocks-1;
35  tensor.elems.indmapr(2,i) = indblock-1;
36  end
37  tensor.elems.indmapc = tensor.elems.indmapr;
38  else
39  tensor.elems.qn_tot = qnums;
40  tensor.elems.vals = num2cell(diag(op));
41  tensor.elems.indmapr = [0:(d -1);zeros(1,d)];
42  tensor.elems.indmapc = [0:(d-1);zeros(1,d)];
43  end
44  tensor.elems.rowlegs = 0;
45  tensor.elems.collegs = 1;
46  tensor.qn_info.qn_dir = [1,-1];
47  tensor.qn_info.qn_index = {qnums,qnums};
48 else
49  tensor.elems_type = 'values';
50  tensor.elems.vals = op;
51  tensor.qn_info.qn_dir = [0,0];
52  tensor.qn_info.qn_index = {[],[]};
53 end
54
55 tensor.dims = size(op);
56
57 tntSystem.basisOp.tensor = tensor;
58 tntSystem.basisOp.ids = 'DU';
59 tntSystem.basisOp.indices = {0,1};
60
61 end
62
63
64
65
66
67
function tntMatAppendBasisOp(in op, in qnums)
function tntMatCreateBasisOp(in op, in qnums)