====== Implementation ====== ===== DMRG ===== In this section the implementation of the relevant Java classes of the applet is explained. Though the applet just implements a spin-\(\frac{1}{2}\)-chain, all classes will have a variable number of local parameters. ==== Matrix ==== {{:wiki:1000px-matrice.svg.png?200|Anordnung der Matrixelemente ((Author: HB, Lizenz: Creative Common by-sa, Source: http://commons.wikimedia.org/wiki/File:Matrice.svg?uselang=de))}} The class "Matrix" implements the basic routines for matrices as two-dimensional arrays and furthermore is the wrapper for the following jlapack-functions ((Anderson, E. ; Bai, Z. ; Bischof, C. ; Blackford, S. ; Demmel, J. ; Dongarra, J. ; Du Croz, J. ; Greenbaum, A. ; Hammarling, S. ; McKenney, A. ; Sorensen, D.: LAPACK Users’ Guide. Third. Philadelphia, PA : Society for Industrial and Applied Mathematics, 1999. – ISBN 0-89871-447-8 (paperback) ))((Doolin, David M. ; Dongarra, Jack ; Seymour, Keith: JLAPACK - compiling LAPACK Fortran to Java. In: Sci. Program. 7 (1999), April, S. 111–138. – URL http://portal.acm.org/citation.cfm?id=1239860.1239868. – ISSN 1058-9244)): * **DGEMM** - matrixmultiplication (//mult//), matrixaddition (//add//), matrixsubtraction (//sub//) and transpose (//trans//) * **DGESVD** - Single value decomposition (//svd//) * **DSYEV** - exact diagonalisation (//Eigen//) Furthermore it is possible to merge matrices vertically or horizontally (//merge//). The files to split the matrices again (//split//), will be saved within the class, but note: It will just split the last merge. ==== MatrixMatrix ==== The class is the implementation for matrices of matrices, as needed for the MPO for the \(\hat W^{\left[i\right]}\) (See [[de:matrix_product_states#Hamilton-Operator|here]]). There is no implementation for the SVD or exact diagonalization for this class (This does not make sense). ==== Mps ==== In this class the MPS are implemented. It includes three two-dimensional arrays for the M-, A- or B-matrices and for the R- and L-matrices. There are two different constructors for the MPS, one fills the matrices with random values, the other one constructs a MPS from a given quantum state. This state has to be given via an one-dimension array, that contains the coefficients of the quantum state. Both constructors will give back a left-normalized state and also create the R-matrices. Therefore the Hamiltonian must also be given as an MPO. public void BuildR(Mpo H, int N) { Matrix Eins = new Matrix(1,1); Eins.SetContent(0,0,1); for (int a=0; athis.N-2) for (int m=0; m One also has to give the MPO for every "Sweep-Step" as the L- and R-matrices have to be updated. public Matrix DoLeftSweepStep(int j, Mpo op) { Matrix AAllStates = new Matrix(this.A[j][0]); for (int k=1; k=0;i--) this.A[j][i]=vt.split(); for (int i=0; i The [[de:matrix_product_states#Skalarprodukt|scalar product]] is also implemented in this class: public double ScalarProd(Mps b) { if (this.N != b.N) return 0.0; Matrix out = new Matrix(); Matrix pre_out = new Matrix(); pre_out = this.A[0][0].trans().mult(b.A[0][0]); for (int s=1; s ==== Mpo ==== This class implement the Mpo by using a three dimensional matrix-matrix-array. There are two different constructors: One constructor needs all $\hat W^{\left[i\right]}$ for every site, the other one just needs one $\hat W^{\left[i\right]}$ and takes this one for all sites (The special matrices for the last and first site will be created from the related row and column). The application of a Mpo on a Mps - as described in [[de:matrix_product_states#MPO-Anwendung|here]] - is given by the function //mult//: public Mps mult(Mps b) { Mps out = new Mps(this.N, b.d*this.W[0][0][0].GetSize()[1], b.d_max*this.W[this.N/2][0][0].GetSize()[1], this.states); for (int l=0; l ==== Dmrg ==== The class "Dmrg" contains the Hamiltonian as a Mpo and the wavefunction as a Mps and implements the [[de:variational_groundstate_search|DMRG-algorithm]] and is also the interface to the gui. The four main function are: * **DoNextStep** This function is the only one that can be used outside the class (with the constructor). It will automatically do a DMRG step in the correct direction. * **DoRightStep** Here a complete right-sweep-step is implemented. At first we have to setup the effective Hamiltonian [[de:variational_groundstate_search#Optimierung eines Platzes|$H_{\text{Eff}}$]]. Then we have to solve the eigenvalue problem. Finally we have to update the new MPS-matrix with the values from the eigenvector and right-normalize the matrix. At last we save all the results for the gui. public void DoRightStep(int N) { Matrix H = this.BuildHeff(N); double[] EigenValue = H.Eigen(); Matrix[] M = new Matrix[this.state.states]; for (int i=0; i * **DoLeftStep** This function is implemented analogously to the function DoRightStep, but going right and left-normalizing. * **BuildHeff** In order to create $H_{\text{Eff}}$, we will setup an auxiliary object $LWR^{[\sigma][\sigma^\prime][a_l][a_{l-1}]}$. The construction follows the calculation described [[de:variational_groundstate_search#Effektive Berechnung von|here]]. Finally we will sort all values into $H_{\text{Eff}}$. public Matrix BuildHeff(int N) { int Size = this.state.states*this.state.A[N][0].GetSize()[0]*this.state.A[N][0].GetSize()[1]; Matrix H = new Matrix(Size, Size); Matrix[][][][] LWR = new Matrix[this.state.states][this.state.states][this.state.A[N][0].GetSize()[0]][this.state.A[N][0].GetSize()[1]]; for (int i=0; i ===== Applet ===== Here we describe all classe and libraries needed for the gui. ==== DmrgCollector ==== This class is derived from the jchart2D-class "ADataCollector" and adds data to the single charts. In order to have parallel usage of the applet to the computation, this class implements the interface "Runnable" ((See: http://download.oracle.com/javase/1.5.0/docs/api/java/lang/Runnable.html)). This ensures that the class is executed in a single thread. The complete computation will be started by the function "collectData". At first it will be tested if the sweep-limit is fulfilled: // Max number of sweeps reached? ==> Stop if (this.visuRef.DmrgRef.CurrentSweep == this.visuRef.Sweeps) this.visuRef.stopData(); Then the sweep will be executed and the new energy will be added to the energy-chart: // create new data int y = this.visuRef.DmrgRef.DoNextStep(); Then the trace of the density matrix will be updated: // Update trace of dm this.visuRef.getDmTrace().removeAllPoints(); for (int i = 0; i Next the expectation values will be calculated. Here we use the Operator-class, which just supports single-site-operators: // Aktualisieren der Erwartungswerte für Sx und Sz for (int i=0; i Finally we will calculate the entanglement entropy. //Calc entanglement entropy double enen = 0.0; for (int i = 0; i ==== visu ==== The class //visu// contains the //main//-function and the complete gui. All objects will be initiated and the control parameters are saved within this class. Graphs are displayed using the JChart2D library ((See: http://jchart2d.sourceforge.net/)). ©: This site was created by Piet Dargel and Thomas Köhler