From d18d3b90dd0febfbfc076a22f7c44d04f0c3cc0b Mon Sep 17 00:00:00 2001 From: William Dawson Date: Tue, 1 Aug 2017 16:06:35 +0900 Subject: [PATCH] The examples were broken by the last update. I fixed them, and added reference output to premade matrix --- Examples/GraphTheory/main.f90 | 21 +++++----- Examples/HydrogenAtom/ReadMe.md | 2 +- Examples/HydrogenAtom/main.f90 | 26 +++++++------ Examples/HydrogenAtom/main.py | 4 +- Examples/HydrogenAtom/visualize.py | 2 +- Examples/OverlapMatrix/main.f90 | 10 ++--- Examples/OverlapMatrix/visualize.py | 2 +- Examples/PremadeMatrix/Density-Reference.mtx | 40 ++++++++++++++++++++ Examples/PremadeMatrix/ReadMe.md | 3 ++ Examples/PremadeMatrix/main.f90 | 14 +++---- Examples/PremadeMatrix/main.py | 5 ++- ReadMe.md | 3 +- 12 files changed, 90 insertions(+), 42 deletions(-) create mode 100644 Examples/PremadeMatrix/Density-Reference.mtx diff --git a/Examples/GraphTheory/main.f90 b/Examples/GraphTheory/main.f90 index 9b631345..189ab112 100644 --- a/Examples/GraphTheory/main.f90 +++ b/Examples/GraphTheory/main.f90 @@ -3,12 +3,13 @@ PROGRAM GraphTheory USE DataTypesModule, ONLY : ntreal USE DistributedSparseMatrixModule, ONLY : & - & WriteToMatrixMarket, DistributedSparseMatrix, ConstructEmpty, & + & WriteToMatrixMarket, DistributedSparseMatrix_t, & + & ConstructEmptyDistributedSparseMatrix, & & FillFromTripletList, DestructDistributedSparseMatrix, & & CopyDistributedSparseMatrix, FillDistributedIdentity, & & IncrementDistributedSparseMatrix USE InverseSolversModule, ONLY : Invert - USE IterativeSolversModule, ONLY : IterativeSolverParameters + USE IterativeSolversModule, ONLY : IterativeSolverParameters_t USE ProcessGridModule, ONLY : ConstructProcessGrid USE TripletListModule, ONLY : TripletList_t, ConstructTripletList, & & SetTripletAt, AppendToTripletList @@ -22,15 +23,15 @@ PROGRAM GraphTheory CHARACTER(len=80) :: output_file REAL(ntreal) :: threshold REAL(ntreal) :: attenuation - TYPE(IterativeSolverParameters) :: solver_parameters + TYPE(IterativeSolverParameters_t) :: solver_parameters !! MPI Variables INTEGER :: rank INTEGER :: total_processors INTEGER :: ierr INTEGER :: provided !! Matrices - TYPE(DistributedSparseMatrix) :: NetworkMat - TYPE(DistributedSparseMatrix) :: ResultMat + TYPE(DistributedSparseMatrix_t) :: NetworkMat + TYPE(DistributedSparseMatrix_t) :: ResultMat !! Local Part of the Matrix INTEGER :: number_of_local_nodes INTEGER, DIMENSION(:), ALLOCATABLE :: local_nodes @@ -75,14 +76,14 @@ PROGRAM GraphTheory & process_slices) !! Set Up The Solver Parameters. - solver_parameters = IterativeSolverParameters( & + solver_parameters = IterativeSolverParameters_t( & & be_verbose_in = .TRUE., threshold_in = threshold) CALL DivideUpWork !! Fill The Matrix - CALL ConstructEmpty(NetworkMat, number_of_nodes) - CALL ConstructEmpty(ResultMat, number_of_nodes) + CALL ConstructEmptyDistributedSparseMatrix(NetworkMat, number_of_nodes) + CALL ConstructEmptyDistributedSparseMatrix(ResultMat, number_of_nodes) CALL FillMatrix !! Solve @@ -196,10 +197,10 @@ SUBROUTINE FillMatrix END SUBROUTINE FillMatrix !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! SUBROUTINE SolveMatrix - TYPE(DistributedSparseMatrix) :: ResMat + TYPE(DistributedSparseMatrix_t) :: ResMat !! Compute attenuation*Identity - Matrix - CALL ConstructEmpty(ResMat, number_of_nodes) + CALL ConstructEmptyDistributedSparseMatrix(ResMat, number_of_nodes) CALL FillDistributedIdentity(ResMat) CALL IncrementDistributedSparseMatrix(NetworkMat, ResMat, & & alpha_in=REAL(-1.0*attenuation,NTREAL)) diff --git a/Examples/HydrogenAtom/ReadMe.md b/Examples/HydrogenAtom/ReadMe.md index 93a92d8b..895f88ac 100644 --- a/Examples/HydrogenAtom/ReadMe.md +++ b/Examples/HydrogenAtom/ReadMe.md @@ -16,7 +16,7 @@ There are three main points to this example. In a somewhat unconventional manner, we will do all this using the real space basis set. Of course, it is normally neither practical nor useful to compute -the density matrix in real space, however the equations in real space are +the full density matrix in real space, however the equations in real space are very simple and will allow us to demonstrate the concepts. We need to solve the following equation: diff --git a/Examples/HydrogenAtom/main.f90 b/Examples/HydrogenAtom/main.f90 index 185e55cc..1dafe920 100644 --- a/Examples/HydrogenAtom/main.f90 +++ b/Examples/HydrogenAtom/main.f90 @@ -4,10 +4,11 @@ PROGRAM HydrogenAtom USE DataTypesModule, ONLY : ntreal USE DensityMatrixSolversModule, ONLY : TRS2 USE DistributedSparseMatrixModule, ONLY : & - & WriteToMatrixMarket, DistributedSparseMatrix, ConstructEmpty, & + & WriteToMatrixMarket, DistributedSparseMatrix_t, & + & ConstructEmptyDistributedSparseMatrix, & & FillFromTripletList, CopyDistributedSparseMatrix, & & IncrementDistributedSparseMatrix, FillDistributedIdentity - USE IterativeSolversModule, ONLY : IterativeSolverParameters + USE IterativeSolversModule, ONLY : IterativeSolverParameters_t USE PermutationModule, ONLY : Permutation_t, ConstructRandomPermutation USE ProcessGridModule, ONLY : ConstructProcessGrid USE SquareRootSolversModule, ONLY : InverseSquareRoot @@ -21,7 +22,7 @@ PROGRAM HydrogenAtom CHARACTER(len=80) :: density_file_out INTEGER :: process_rows, process_columns, process_slices REAL(ntreal) :: threshold, convergence_threshold - TYPE(IterativeSolverParameters) :: solver_parameters + TYPE(IterativeSolverParameters_t) :: solver_parameters !! MPI Variables INTEGER :: rank INTEGER :: total_processors @@ -36,11 +37,11 @@ PROGRAM HydrogenAtom REAL(ntreal) :: grid_spacing REAL(ntreal), DIMENSION(:), ALLOCATABLE :: x_values !! Matrices - TYPE(DistributedSparseMatrix) :: KineticEnergy - TYPE(DistributedSparseMatrix) :: PotentialEnergy - TYPE(DistributedSparseMatrix) :: Hamiltonian - TYPE(DistributedSparseMatrix) :: Identity - TYPE(DistributedSparseMatrix) :: Density + TYPE(DistributedSparseMatrix_t) :: KineticEnergy + TYPE(DistributedSparseMatrix_t) :: PotentialEnergy + TYPE(DistributedSparseMatrix_t) :: Hamiltonian + TYPE(DistributedSparseMatrix_t) :: Identity + TYPE(DistributedSparseMatrix_t) :: Density !! Temporary Variables CHARACTER(len=80) :: argument CHARACTER(len=80) :: argument_value @@ -78,7 +79,7 @@ PROGRAM HydrogenAtom & process_slices) !! Set Up The Solver Parameters. - solver_parameters = IterativeSolverParameters( be_verbose_in=.TRUE., & + solver_parameters = IterativeSolverParameters_t( be_verbose_in=.TRUE., & & converge_diff_in=convergence_threshold, threshold_in=threshold) !! Divide The Work Amongst Processors. @@ -88,11 +89,11 @@ PROGRAM HydrogenAtom CALL ConstructLinearSpace() !! Construct The Kinetic Energy Operator. - CALL ConstructEmpty(KineticEnergy, grid_points) + CALL ConstructEmptyDistributedSparseMatrix(KineticEnergy, grid_points) CALL FillKineticEnergy() !! Construct The Potential Energy Operator. - CALL ConstructEmpty(PotentialEnergy, grid_points) + CALL ConstructEmptyDistributedSparseMatrix(PotentialEnergy, grid_points) CALL FillPotentialEnergy() !! Construct The Full Hamiltonian. @@ -100,7 +101,8 @@ PROGRAM HydrogenAtom CALL IncrementDistributedSparseMatrix(PotentialEnergy, Hamiltonian) !! Overlap Matrix is just the identity. - CALL ConstructEmpty(Identity,Hamiltonian%actual_matrix_dimension) + CALL ConstructEmptyDistributedSparseMatrix(Identity, & + & Hamiltonian%actual_matrix_dimension) CALL FillDistributedIdentity(Identity) !! Call the solver routine. diff --git a/Examples/HydrogenAtom/main.py b/Examples/HydrogenAtom/main.py index a3d6e3de..636ac0b9 100644 --- a/Examples/HydrogenAtom/main.py +++ b/Examples/HydrogenAtom/main.py @@ -117,8 +117,8 @@ # Call the solver routine. chemical_potential = 0 Density = nt.DistributedSparseMatrix(grid_points) - nt.DensityMatrixSolvers.TRS2(Hamiltonian, Identity, 2, - Density, chemical_potential, solver_parameters) + chemical_potential = nt.DensityMatrixSolvers.TRS2(Hamiltonian, Identity, 2, + Density, solver_parameters) # Print the density matrix to file. Density.WriteToMatrixMarket(density_file_out) diff --git a/Examples/HydrogenAtom/visualize.py b/Examples/HydrogenAtom/visualize.py index 25ef502e..d07a7576 100644 --- a/Examples/HydrogenAtom/visualize.py +++ b/Examples/HydrogenAtom/visualize.py @@ -2,7 +2,7 @@ import matplotlib.pyplot as plt import numpy -# A function that reads in matrix market-esque files produced by the library. +# A function that reads in matrix market files produced by the library. # @param file_name file to read. def ReadMM(file_name): matrix = numpy.zeros((0, 0)) diff --git a/Examples/OverlapMatrix/main.f90 b/Examples/OverlapMatrix/main.f90 index 92fa3d3b..a46b66ff 100644 --- a/Examples/OverlapMatrix/main.f90 +++ b/Examples/OverlapMatrix/main.f90 @@ -14,10 +14,10 @@ PROGRAM OverlapExample !! Parameters INTEGER :: process_rows, process_columns, process_slices REAL(ntreal) :: threshold, convergence_threshold - TYPE(IterativeSolverParameters) :: solver_parameters + TYPE(IterativeSolverParameters_t) :: solver_parameters INTEGER :: basis_functions !! Matrices - TYPE(DistributedSparseMatrix) :: Overlap, ISQOverlap + TYPE(DistributedSparseMatrix_t) :: Overlap, ISQOverlap TYPE(Permutation_t) :: permutation !! Triplet List TYPE(TripletList_t) :: triplet_list @@ -79,8 +79,8 @@ PROGRAM OverlapExample end_column = start_column + local_columns - 1 !! Build The Empty Matrices - CALL ConstructEmpty(Overlap, basis_functions) - CALL ConstructEmpty(ISQOverlap, basis_functions) + CALL ConstructEmptyDistributedSparseMatrix(Overlap, basis_functions) + CALL ConstructEmptyDistributedSparseMatrix(ISQOverlap, basis_functions) !! Compute The Overlap Matrix CALL StartTimer("Construct Triplet List") @@ -105,7 +105,7 @@ PROGRAM OverlapExample !! Set Up The Solver Parameters. CALL ConstructRandomPermutation(permutation, & & Overlap%logical_matrix_dimension) - solver_parameters = IterativeSolverParameters(& + solver_parameters = IterativeSolverParameters_t(& & converge_diff_in=convergence_threshold, threshold_in=threshold, & & BalancePermutation_in=permutation, be_verbose_in=.TRUE.) diff --git a/Examples/OverlapMatrix/visualize.py b/Examples/OverlapMatrix/visualize.py index 5b087cc8..7f4c9298 100644 --- a/Examples/OverlapMatrix/visualize.py +++ b/Examples/OverlapMatrix/visualize.py @@ -3,7 +3,7 @@ import numpy from matplotlib.colors import LogNorm -# A function that reads in matrix market-esque files produced by the library. +# A function that reads in matrix market files produced by the library. # @param file_name file to read. def ReadMM(file_name): matrix = numpy.zeros((0, 0)) diff --git a/Examples/PremadeMatrix/Density-Reference.mtx b/Examples/PremadeMatrix/Density-Reference.mtx new file mode 100644 index 00000000..e701a9e5 --- /dev/null +++ b/Examples/PremadeMatrix/Density-Reference.mtx @@ -0,0 +1,40 @@ +%%MatrixMarket matrix coordinate real general +% + 7 7 37 + 1 1 1.0549095967421220 + 2 1 -0.23302213379033082 + 3 1 3.7646419335116699E-002 + 4 1 3.7646419335116685E-002 + 6 1 -7.5642046773935134E-003 + 7 1 -7.5642046773937563E-003 + 1 2 -0.23302213783309644 + 2 2 1.0292641102917328 + 3 2 -0.20982918266288592 + 4 2 -0.20982918266288578 + 6 2 -4.3117326895678362E-002 + 7 2 -4.3117326895676926E-002 + 1 3 3.7646421361998791E-002 + 2 3 -0.20982921225444917 + 3 3 0.46883722812203843 + 4 3 6.8501651086330564E-002 + 6 3 0.37466965007376707 + 7 3 -3.1414239305686278E-002 + 1 4 3.7646421361998764E-002 + 2 4 -0.20982921225444895 + 3 4 6.8501651086330509E-002 + 4 4 0.46883722812204076 + 6 4 -3.1414239305686306E-002 + 7 4 0.37466965007376629 + 5 5 1.0000000000000000 + 1 6 -7.5642029235768070E-003 + 2 6 -4.3117329307985383E-002 + 3 6 0.37466966035658766 + 4 6 -3.1414332242094133E-002 + 6 6 0.32525138744266346 + 7 6 -8.6663457475723252E-002 + 1 7 -7.5642029235770195E-003 + 2 7 -4.3117329307984009E-002 + 3 7 -3.1414332242094126E-002 + 4 7 0.37466966035658689 + 6 7 -8.6663457475723182E-002 + 7 7 0.32525138744266113 diff --git a/Examples/PremadeMatrix/ReadMe.md b/Examples/PremadeMatrix/ReadMe.md index c8824b0a..f420e60f 100644 --- a/Examples/PremadeMatrix/ReadMe.md +++ b/Examples/PremadeMatrix/ReadMe.md @@ -106,3 +106,6 @@ computed by these routines. It is possible to write out a matrix either to either a text or binary format. Writing to text is slower, but is portable across systems. Writing to binary should probably only be used to store intermediate results. + +The output file can be compared to Density-Reference.mtx to verify its +correctness. diff --git a/Examples/PremadeMatrix/main.f90 b/Examples/PremadeMatrix/main.f90 index b4edeb92..a0556e39 100644 --- a/Examples/PremadeMatrix/main.f90 +++ b/Examples/PremadeMatrix/main.f90 @@ -4,8 +4,8 @@ PROGRAM PremadeMatrixProgram USE DataTypesModule, ONLY : ntreal USE DensityMatrixSolversModule, ONLY : TRS2 USE DistributedSparseMatrixModule, ONLY : ConstructFromMatrixMarket, & - & WriteToMatrixMarket, DistributedSparseMatrix - USE IterativeSolversModule, ONLY : IterativeSolverParameters + & WriteToMatrixMarket, DistributedSparseMatrix_t + USE IterativeSolversModule, ONLY : IterativeSolverParameters_t USE LoggingModule USE PermutationModule, ONLY : Permutation_t, ConstructRandomPermutation USE ProcessGridModule, ONLY : ConstructProcessGrid, IsRoot @@ -19,12 +19,12 @@ PROGRAM PremadeMatrixProgram INTEGER :: process_rows, process_columns, process_slices REAL(ntreal) :: threshold, convergence_threshold INTEGER :: number_of_electrons - TYPE(IterativeSolverParameters) :: solver_parameters + TYPE(IterativeSolverParameters_t) :: solver_parameters TYPE(Permutation_t) :: permutation !! Matrices - TYPE(DistributedSparseMatrix) :: Hamiltonian, Overlap - TYPE(DistributedSparseMatrix) :: ISQOverlap - TYPE(DistributedSparseMatrix) :: Density + TYPE(DistributedSparseMatrix_t) :: Hamiltonian, Overlap + TYPE(DistributedSparseMatrix_t) :: ISQOverlap + TYPE(DistributedSparseMatrix_t) :: Density !! Temporary Variables CHARACTER(len=80) :: argument CHARACTER(len=80) :: argument_value @@ -88,7 +88,7 @@ PROGRAM PremadeMatrixProgram !! Set Up The Solver Parameters. CALL ConstructRandomPermutation(permutation, & & Hamiltonian%logical_matrix_dimension) - solver_parameters = IterativeSolverParameters(& + solver_parameters = IterativeSolverParameters_t(& & converge_diff_in=convergence_threshold, threshold_in=threshold, & & BalancePermutation_in=permutation, be_verbose_in=.TRUE.) diff --git a/Examples/PremadeMatrix/main.py b/Examples/PremadeMatrix/main.py index 5581698a..341d13e1 100644 --- a/Examples/PremadeMatrix/main.py +++ b/Examples/PremadeMatrix/main.py @@ -56,8 +56,9 @@ # Call the solver routines. nt.SquareRootSolvers.InverseSquareRoot( Overlap, ISQOverlap, solver_parameters) - nt.DensityMatrixSolvers.TRS2(Hamiltonian, ISQOverlap, number_of_electrons, - Density, chemical_potential, solver_parameters) + chemical_potential = nt.DensityMatrixSolvers.TRS2(Hamiltonian, ISQOverlap, + number_of_electrons, + Density, solver_parameters) # Print the density matrix to file. Density.WriteToMatrixMarket(density_file_out) diff --git a/ReadMe.md b/ReadMe.md index 128ae089..84acc532 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -69,7 +69,8 @@ Getting Start With Examples -------------------------------------------------------------------------------- In the examples directory, there are a number of different example programs that use NTPoly. You can check the ReadMe.md file in each example directory to -learn how to build and run each example. +learn how to build and run each example. The simplest example is PremadeMatrix, +which includes sample output you can compare to. Feature Outline --------------------------------------------------------------------------------