示例#1
0
文件: test.go 项目: ominux/negf_mtj
func testRightSplit(n int) {
	fmt.Println("Initializing Sparse matrix structure\n")
	tmp := cmplxSparse.New()

	matrixSize := int(2 * (n + n + 4))
	fmt.Println("Making sparse ", matrixSize, "x", matrixSize, " Hamiltonian tridiagonal matrix for band split test (right)\n")
	cmplxSparse.MakeHamTriDiag(n+n+4, tmp)

	fmt.Println("Adding splitting of 1.25 along +z direction\n")
	tmp2 := cmplxSparse.AddBandSplitRightFM(0, 0, 0.1, 1.25, n, tmp)
	fmt.Println("Accessing matrix elements (m,n):")

	for idx0 := 0; idx0 < matrixSize; idx0++ {
		for idx1 := 0; idx1 < matrixSize; idx1++ {
			test := cmplxSparse.AccessMatrix(idx0, idx1, tmp2)
			fmt.Printf("%f  ", test)
		}
		fmt.Printf("\n")
	}
	fmt.Println("\n")

	fmt.Println("Adding splitting of 0.75 along (1,1,1) direction\n")
	tmp2 = cmplxSparse.AddBandSplitRightFM(1.0, 1.0, 1.0, 0.75, n, tmp)
	fmt.Println("Accessing matrix elements (m,n):")

	for idx0 := 0; idx0 < matrixSize; idx0++ {
		for idx1 := 0; idx1 < matrixSize; idx1++ {
			test := cmplxSparse.AccessMatrix(idx0, idx1, tmp2)
			fmt.Printf("%f  ", test)
		}
		fmt.Printf("\n")
	}
	fmt.Println("\n")
}
示例#2
0
文件: test.go 项目: ominux/negf_mtj
func testScaleMatrix(n int) {
	fmt.Println("Initializing Sparse matrix structure\n")
	tmp := cmplxSparse.New()

	matrixSize := int(2 * n)
	fmt.Println("Making sparse ", matrixSize, "x", matrixSize, " Hamiltonian tridiagonal matrix\n")
	cmplxSparse.MakeHamTriDiag(n, tmp)

	fmt.Println("Scaling matrix by factor of 5+1*im\n")
	cmplxSparse.ScaleSparseMatrix(complex(5, 1), tmp)
	fmt.Println("Accessing matrix elements (m,n):")

	for idx0 := 0; idx0 < matrixSize; idx0++ {
		for idx1 := 0; idx1 < matrixSize; idx1++ {
			test := cmplxSparse.AccessMatrix(idx0, idx1, tmp)
			fmt.Printf("%f  ", test)
		}
		fmt.Printf("\n")
	}

	fmt.Printf("\n")
	fmt.Println("Scaling matrix by factor of 1/5\n")
	cmplxSparse.ScaleSparseMatrix(complex128(0.2), tmp)
	for idx0 := 0; idx0 < matrixSize; idx0++ {
		for idx1 := 0; idx1 < matrixSize; idx1++ {
			test := cmplxSparse.AccessMatrix(idx0, idx1, tmp)
			fmt.Printf("%f  ", test)
		}
		fmt.Printf("\n")
	}
	fmt.Println("\n")

}
示例#3
0
func testDiagSolver(n int) {
	fmt.Println("Initializing Sparse matrix structure\n")
	tmp := cmplxSparse.New()

	matrixSize := int(2 * n)
	fmt.Println("Making sparse ", matrixSize, "x", matrixSize, " Hamiltonian tridiagonal matrix\n")
	cmplxSparse.MakeHamTriDiag(n, tmp)
	for idx0 := 0; idx0 < matrixSize; idx0++ {
		tmp.Data[idx0][2] -= complex(0.0, 5.0)
	}
	fmt.Println("Accessing matrix elements of Hamiltonian (m,n):")

	for idx0 := 0; idx0 < matrixSize; idx0++ {
		for idx1 := 0; idx1 < matrixSize; idx1++ {
			test := cmplxSparse.AccessMatrix(idx0, idx1, tmp)
			fmt.Printf("%f  ", test)
		}
		fmt.Printf("\n")
	}
	fmt.Printf("\n")

	tmp0 := cmplxSparse.SparseCopy(tmp)
	cmplxSparse.SparseDiagLU(tmp0)
	fmt.Println("Accessing matrix elements of LU (m,n):")
	for idx0 := 0; idx0 < matrixSize; idx0++ {
		for idx1 := 0; idx1 < matrixSize; idx1++ {
			test := cmplxSparse.AccessMatrix(idx0, idx1, tmp0)
			fmt.Printf("%f  ", test)
		}
		fmt.Printf("\n")
	}
	fmt.Printf("\n")

	InvBuffer := make([][]complex128, matrixSize)
	for idx0 := range InvBuffer {
		InvBuffer[idx0] = make([]complex128, matrixSize)
		for idx1 := range InvBuffer[idx0] {
			InvBuffer[idx0][idx1] = 0.0 + 0.0i
		}
	}

	for idx0 := range InvBuffer {
		InvBuffer[idx0][idx0] = 1.0 + 0.0i
		BufferMatrix := cmplxSparse.SparseDiagLinearSolver(tmp0, InvBuffer[idx0])
		InvBuffer[idx0] = BufferMatrix
	}

	fmt.Println("Accessing matrix elements of inverse (m,n):")

	for idx0 := range InvBuffer {
		for idx1 := range InvBuffer[idx0] {
			fmt.Printf("%.15g  ", InvBuffer[idx0][idx1])
		}
		fmt.Printf("\n")
	}
}
示例#4
0
文件: test.go 项目: ominux/negf_mtj
func testHamTri(n int) {
	fmt.Println("Initializing Sparse matrix structure\n")
	tmp := cmplxSparse.New()

	matrixSize := int(2 * n)
	fmt.Println("Making sparse ", matrixSize, "x", matrixSize, " Hamiltonian tridiagonal matrix\n")
	cmplxSparse.MakeHamTriDiag(n, tmp)

	fmt.Println("Accessing matrix elements (m,n):")

	for idx0 := 0; idx0 < matrixSize; idx0++ {
		for idx1 := 0; idx1 < matrixSize; idx1++ {
			test := cmplxSparse.AccessMatrix(idx0, idx1, tmp)
			fmt.Printf("%f  ", test)
		}
		fmt.Printf("\n")
	}
	fmt.Println("\n")
}
示例#5
0
文件: test.go 项目: ominux/negf_mtj
func testIdentity() {
	fmt.Println("Initializing Sparse matrix structure\n")
	tmp := cmplxSparse.New()

	fmt.Println("Making sparse 5x5 identity matrix\n")
	matrixSize := int(5)
	cmplxSparse.MakeIdentity(matrixSize, tmp)

	fmt.Println("Accessing matrix elements (m,n):")

	for idx0 := 0; idx0 < matrixSize; idx0++ {
		for idx1 := 0; idx1 < matrixSize; idx1++ {
			test := cmplxSparse.AccessMatrix(idx0, idx1, tmp)
			fmt.Printf("%f  ", test)
		}
		fmt.Printf("\n")
	}
	fmt.Println("\n")
}
示例#6
0
文件: test.go 项目: ominux/negf_mtj
func testRangeScale(A complex128, startIdx, endIdx, diagIdx, n int) {
	fmt.Println("Initializing Sparse matrix structure\n")
	tmp := cmplxSparse.New()

	matrixSize := int(2 * n)
	fmt.Println("Making sparse ", matrixSize, "x", matrixSize, " Hamiltonian tridiagonal matrix for range scale test\n")
	cmplxSparse.MakeHamTriDiag(n, tmp)

	fmt.Println("Scaling index ", startIdx, " to ", endIdx, " on the ", diagIdx, " diagonal of matrix by ", A)
	cmplxSparse.ScaleRangeSparseMatrix(startIdx, endIdx, diagIdx, A, tmp)
	fmt.Println("Accessing matrix elements (m,n):")

	for idx0 := 0; idx0 < matrixSize; idx0++ {
		for idx1 := 0; idx1 < matrixSize; idx1++ {
			test := cmplxSparse.AccessMatrix(idx0, idx1, tmp)
			fmt.Printf("%f  ", test)
		}
		fmt.Printf("\n")
	}
	fmt.Println("\n")
}
示例#7
0
文件: test.go 项目: ominux/negf_mtj
func testVoltage(n int) {
	fmt.Println("Initializing Sparse matrix structure\n")
	tmp := cmplxSparse.New()

	matrixSize := int(2 * n)
	fmt.Println("Making sparse ", matrixSize, "x", matrixSize, " Hamiltonian tridiagonal matrix for voltage profile test\n")
	cmplxSparse.MakeHamTriDiag(n, tmp)

	fmt.Println("Adding applied potential profile of 0.3 \n")
	tmp2 := cmplxSparse.AddVoltagePotential(1, n-4, 0.30, tmp)
	fmt.Println("Accessing matrix elements (m,n):")

	for idx0 := 0; idx0 < matrixSize; idx0++ {
		for idx1 := 0; idx1 < matrixSize; idx1++ {
			test := cmplxSparse.AccessMatrix(idx0, idx1, tmp2)
			fmt.Printf("%f  ", test)
		}
		fmt.Printf("\n")
	}
	fmt.Println("\n")

}
示例#8
0
func testLU(n int) {
	fmt.Println("Initializing Sparse matrix structure\n")
	tmp := cmplxSparse.New()

	matrixSize := int(2 * n)
	fmt.Println("Making sparse ", matrixSize, "x", matrixSize, " Hamiltonian tridiagonal matrix\n")
	cmplxSparse.MakeHamTriDiag(n, tmp)
	for idx0 := 0; idx0 < matrixSize; idx0++ {
		tmp.Data[idx0][2] -= complex(0.0, 5.0)
	}

	LU_mat := cmplxSparse.SparseCopy(tmp)
	cmplxSparse.SparseDiagLU(LU_mat)
	fmt.Println("Accessing matrix elements (m,n):")

	for idx0 := 0; idx0 < matrixSize; idx0++ {
		for idx1 := 0; idx1 < matrixSize; idx1++ {
			test := cmplxSparse.AccessMatrix(idx0, idx1, LU_mat)
			fmt.Printf("%f  ", test)
		}
		fmt.Printf("\n")
	}
	fmt.Println("\n")
}