Tensor Network Theory Library  Beta release 1.2.1 A library of routines for performing TNT-based operations
tntMpsCreateTwoSiteOp.c
1 /*
2 Authors: Sarah Al-Assam, Stephen Clark and Dieter Jaksch
3 $LastChangedDate$
4 (c) University of Oxford 2014
5 */
6
12 /* Include internal header */
13 #include "tntMpsInternal.h"
14
39 tntNode tntMpsCreateTwoSiteOp(tntNodeArray *Lnodes,
40  tntNodeArray *Rnodes,
41  tntComplexArray *params)
42 {
43
44  tntNode Tterm, T; /* Nodes for building two-site operator */
45  tntNode tnA, tnB; /* Nodes used while contracting */
46  tntIntArray qnums_phys; /* Quantum numbers for the physical leg */
47  unsigned loop;
48
49  /* First deal with the nearest neighbour terms */
50  for (loop = 0; loop < Lnodes->sz; loop++) {
51
52  /* Copy over the nodes and add a leg to each one */
53  /* Left contribution */
54  tnA = tntNodeCopy(Lnodes->vals[loop],0);
55
56  /* Right contribution */
57  tnB = tntNodeCopy(Rnodes->vals[loop],0);
58
59  /* Contract them to form a two site operator */
60  Tterm = tntNodeContract(tnA, tnB, NULL, "DU=EV");
61
62  /* Scale by the parameter */
63  tntNodeScaleComplex(Tterm, params->vals[loop]);
64
65  /* Add to the total Hamiltonian, unless it is the first term */
66  if (0 == loop) {
67  T = Tterm;
68  } else {
70  /* Free the node for the current term */
71  tntNodeFree(&Tterm);
72  }
73  }
74
75  /* Now put the unitary in the blocks form */
76  if (tntSymmTypeGet()) {
77  /* Get the quantum numbers for the physical leg */
78  qnums_phys = tntNodeGetQN(tntSysBasisOpGet(), "D");
79
80  /* Set the quantum numbers for the unitary - upwards facing legs (U and V) are outgoing, downwards facing legs (D and E) are incoming. */
81  tntNodeSetQN(T,"U",&qnums_phys,TNT_QN_OUT);
82  tntNodeSetQN(T,"V",&qnums_phys,TNT_QN_OUT);
83  tntNodeSetQN(T,"D",&qnums_phys,TNT_QN_IN);
84  tntNodeSetQN(T,"E",&qnums_phys,TNT_QN_IN);
85  /* Note - this may require some elements of the unitary to be discarded - no check at the moment for this */
86
87  /* free the quantum numbers */
88  tntIntArrayFree(&qnums_phys);
89  }
90
91  return T;
92
93 }
tntNode tntNodeCopy(tntNode A)
Definition: tntNodeUtil.c:304
void tntNodeSetQN(tntNode A, tntLegLabel legA, tntIntArray *qvals, int legdir)
Definition: tntNodeQN.c:37
void tntNodeScaleComplex(tntNode A, tntComplex val)