 Tensor Network Theory Library  Beta release 1.2.1 A library of routines for performing TNT-based operations
create_nodes.c

A simple example of creating nodes representing onsite spin- $$\frac{1}{2}$$ operators and using them to make two-site operators.

The elements are then extracted and used to build a functional node, which then has the parameters set.

Note that the onsite spin- $$\frac{1}{2}$$ operators could equivalently been created using tntMpsCreateSpinOp() but are shown being created manually here for illustrative purposes.

/*
Authors: Sarah Al-Assam, Stephen Clark and Dieter Jaksch
Date: $LastChangedDate$
(c) University of Oxford 2016
*/
/* Include the header for the TNT library, including MPS functions */
#include "tntMps.h"
int main(int argc, char **argv)
{
tntComplexArray Sxv, Syv, Szv;
tntComplexArray twositeops;
tntNode Sx, Sy, Sz;
tntNode twosite;
tntComplex compval={1.2,-0.3};
/* Create matrices for single site spin operators */
Sxv = tntComplexArrayCreate("0 1; 1 0");
Syv = tntComplexArrayCreate("0 -1i; 1i 0");
Szv = tntComplexArrayCreateDiag("1 -1", 0);
/* Create nodes for sinle site operators */
Sx = tntNodeCreate(&Sxv, "DU", 2, 2);
Sy = tntNodeCreate(&Syv, "DU", 2, 2);
Sz = tntNodeCreate(&Szv, "DU", 2, 2);
/* Contract the nodes to form two-site operators */
/* After creating the two-site node extract the matrix of values */
twosite = tntNodeContract(Sx, Sx, NULL, "DU=EV");
twositeops = tntNodeGetMatrix(twosite, "DE", "UV");
tntNodeFree(&twosite);
twosite = tntNodeContract(Sy, Sy, NULL, "DU=EV");
twositeops = tntNodeGetMatrix(twosite, "DE", "UV");
tntNodeFree(&twosite);
twosite = tntNodeContract(Sz, Sz, NULL, "DU=EV");
twositeops = tntNodeGetMatrix(twosite, "DE", "UV");
tntNodeFree(&twosite);
/* Use the matrices to create a functional node */
twosite = tntNodeFuncCreate(twositeops, 3, "exp", "DEUV", 2, 2, 2, 2);
tntNodePrintAll(twosite);
/* Set the initial parameters */
tntNodeSetRealParam(twosite,1.1,0);
tntNodeSetCompParam(twosite,compval,1);
tntNodeSetRealParam(twosite,2.3,2);
tntNodeFree(&twosite);
tntComplexArrayFree(twositeops);
tntComplexArrayFree(twositeops+1);
tntComplexArrayFree(twositeops+2);
return 0;
}