PEXSI
 All Classes Namespaces Files Functions Variables Typedefs Pages
ppexsi.hpp
Go to the documentation of this file.
1 /*
2  Copyright (c) 2012 The Regents of the University of California,
3  through Lawrence Berkeley National Laboratory.
4 
5  Author: Lin Lin
6 
7  This file is part of PEXSI. All rights reserved.
8 
9  Redistribution and use in source and binary forms, with or without
10  modification, are permitted provided that the following conditions are met:
11 
12  (1) Redistributions of source code must retain the above copyright notice, this
13  list of conditions and the following disclaimer.
14  (2) Redistributions in binary form must reproduce the above copyright notice,
15  this list of conditions and the following disclaimer in the documentation
16  and/or other materials provided with the distribution.
17  (3) Neither the name of the University of California, Lawrence Berkeley
18  National Laboratory, U.S. Dept. of Energy nor the names of its contributors may
19  be used to endorse or promote products derived from this software without
20  specific prior written permission.
21 
22  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
23  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
26  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
27  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
29  ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 
33  You are under no obligation whatsoever to provide any bug fixes, patches, or
34  upgrades to the features, functionality or performance of the source code
35  ("Enhancements") to anyone; however, if you choose to make your Enhancements
36  available either publicly, or directly to Lawrence Berkeley National
37  Laboratory, without imposing a separate written license agreement for such
38  Enhancements, then you hereby grant the following license: a non-exclusive,
39  royalty-free perpetual license to install, use, modify, prepare derivative
40  works, incorporate into other computer software, distribute, and sublicense
41  such enhancements or derivative works thereof, in binary and source code form.
42 */
47 #ifndef _PPEXSI_HPP_
48 #define _PPEXSI_HPP_
49 #include "environment.hpp"
50 #include "sparse_matrix.hpp"
51 #include "NumVec.hpp"
52 #include "utility.hpp"
53 #include "pole.hpp"
54 #include "mpi_interf.hpp"
55 #include "SuperLUGrid.hpp"
56 #include "superlu_dist_interf.hpp"
57 #include "pselinv.hpp"
58 //#include "c_pexsi_interface.h"
59 
60 namespace PEXSI{
61 
66  class PPEXSIData{
67  private:
68  // *********************************************************************
69  // Computational variables
70  // *********************************************************************
71 
72  std::vector<Complex> zshift_; // Complex shift for the pole expansion
73  std::vector<Complex> zweightRho_; // Complex weight for the pole expansion for density
74  std::vector<Complex> zweightRhoDrvMu_; // Complex weight for the pole expansion for derivative of the Fermi-Dirac with respect to the chemical potential
75  std::vector<Complex> zweightRhoDrvT_; // Complex weight for the pole expansion for derivative of the Fermi-Dirac with respect to the temperature T (1/beta, in au)
76  std::vector<Complex> zweightHelmholtz_; // Complex shift for the pole expansion for Helmholtz free energy
77  std::vector<Complex> zweightForce_; // Complex weight for the pole expansion for force
78 
79  // Outer layer communicator. Also used for distributing the
80  // DistSparseMatrix. Each DistSparseMatrix is replicated in the row
81  // (numPoleGroup) direction of gridPole.
82  const GridType* gridPole_;
83  const GridType* gridSelInv_; // Inner layer communicator for SelInv
84 
85  // Inner layer communicator for SuperLU factorization
86  const SuperLUGrid<Real>* gridSuperLUReal_;
87  const SuperLUGrid<Complex>* gridSuperLUComplex_;
88 
89 
90  DistSparseMatrix<Real> HRealMat_;
91  DistSparseMatrix<Real> SRealMat_;
92 
93  DistSparseMatrix<Real> shiftRealMat_;
94  DistSparseMatrix<Complex> shiftComplexMat_;
95 
96  DistSparseMatrix<Real> shiftInvRealMat_;
97  DistSparseMatrix<Complex> shiftInvComplexMat_;
98 
99  DistSparseMatrix<Real> rhoRealMat_; // Density matrix
100  DistSparseMatrix<Real> rhoDrvMuRealMat_; // Derivative of the Fermi-Dirac with respect to mu
101  DistSparseMatrix<Real> rhoDrvTRealMat_; // Derivative of the Fermi-Dirac with respect to T
102  DistSparseMatrix<Real> freeEnergyDensityRealMat_; // Helmholtz free energy density matrix
103  DistSparseMatrix<Real> energyDensityRealMat_; // Energy density matrix for computing the Pulay force
104 
105  // SuperLUMatrix and PMatrix structures These structures are saved
106  // to avoid repetitive symbolic factorization process, and saved in
107  // pointer form because of the constructors.
108  SuperLUMatrix<Real>* luRealMat_;
109  SuperLUMatrix<Complex>* luComplexMat_;
110 
111  PMatrix<Real>* PMRealMat_;
112  PMatrix<Complex>* PMComplexMat_;
113 
114  // Whether the matrices have been loaded into HRealMat_ and
115  // SRealMat_
116  bool isMatrixLoaded_;
117  // Whether the matrices (luMat and PMat) have obtained symbolic
118  // information
119  bool isRealSymmetricSymbolicFactorized_;
120  bool isComplexSymmetricSymbolicFactorized_;
121  // Supernode partition for the real matrix
122  SuperNodeType superReal_;
123  // Supernode partition for the complex matrix
124  SuperNodeType superComplex_;
125 
126  // Saves all the indices of diagonal elements in H, so that
127  // H.nzvalLocal(diagIdxLocal_[j]) are diagonal elements for all j.
128  // This is manly used when S is implicitly given as an identity matrix.
129  std::vector<Int> diagIdxLocal_;
130 
131  // Energy computed from Tr[H*DM]
132  Real totalEnergyH_;
133  // Energy computed from Tr[S*EDM]
134  Real totalEnergyS_;
135  // Free energy
136  Real totalFreeEnergy_;
137 
138 
139  // *********************************************************************
140  // Saved variables for nonlinear iterations
141  // *********************************************************************
142  Real muPEXSISave_;
143 
144  public:
145  PPEXSIData(
146  MPI_Comm comm,
147  Int numProcRow,
148  Int numProcCol,
149  Int outputFileIndex );
150 
151  ~PPEXSIData();
152 
153  void LoadRealSymmetricMatrix(
154  Int nrows,
155  Int nnz,
156  Int nnzLocal,
157  Int numColLocal,
158  Int* colptrLocal,
159  Int* rowindLocal,
160  Real* HnzvalLocal,
161  Int isSIdentity,
162  Real* SnzvalLocal,
163  Int verbosity );
164 
165 
181  std::string ColPerm,
182  Int numProcSymbFact,
183  Int verbosity );
184 
200  std::string ColPerm,
201  Int numProcSymbFact,
202  Int verbosity );
203 
204 
205  void SelInvRealSymmetricMatrix(
206  double* AnzvalLocal,
207  Int verbosity,
208  double* AinvnzvalLocal );
209 
210  void SelInvComplexSymmetricMatrix(
211  double* AnzvalLocal,
212  Int verbosity,
213  double* AinvnzvalLocal );
214 
215 
245  const std::vector<Real>& shiftVec,
246  std::vector<Real>& inertiaVec,
247  Int verbosity );
248 
249 
276  Int numPole,
277  Real temperature,
278  Real gap,
279  Real deltaE,
280  Real mu,
281  Real numElectronExact,
282  Real numElectronTolerance,
283  Int verbosity,
284  Real& numElectron,
285  Real& numElectronDrvMu );
286 
287 
289  void DFTDriver(
290  Real numElectronExact,
291  Real temperature,
292  Real gap,
293  Real deltaE,
294  Int numPole,
295  Int isInertiaCount,
296  Int maxPEXSIIter,
297  Real muMin0,
298  Real muMax0,
299  Real muInertiaTolerance,
300  Real muInertiaExpansion,
301  Real muPEXSISafeGuard,
302  Real numElectronPEXSITolerance,
303  Int matrixType,
304  Int isSymbolicFactorize,
305  Int ordering,
306  Int numProcSymbFact,
307  Int verbosity,
308  Real& muPEXSI,
309  Real& numElectronPEXSI,
310  Real& muMinInertia,
311  Real& muMaxInertia,
312  Int& numTotalInertiaIter,
313  Int& numTotalPEXSIIter );
314 
315 
316  // *********************************************************************
317  // Access data
318  // *********************************************************************
319 
320  const GridType* GridPole() const {return gridPole_;}
321 
326  const DistSparseMatrix<Real>& RhoRealMat() const {return rhoRealMat_;}
327 
333  const DistSparseMatrix<Real>& EnergyDensityRealMat() const {return energyDensityRealMat_;}
334 
343  const DistSparseMatrix<Real>& FreeEnergyDensityRealMat() const {return freeEnergyDensityRealMat_;}
344 
345  Real TotalEnergyH() const {return totalEnergyH_;}
346 
347  Real TotalEnergyS() const {return totalEnergyS_;}
348 
349  Real TotalFreeEnergy() const {return totalFreeEnergy_;}
350 
351 
352  }; // PPEXSIData
353 
354 
355 } // namespace PEXSI
356 #endif // _PPEXSI_HPP_
Environmental variables.
const DistSparseMatrix< Real > & FreeEnergyDensityRealMat() const
Total Helmholtz free energy matrix (band energy part only).
Definition: ppexsi.hpp:343
SuperNodeType describes mapping between supernode and column, the permutation information, and potentially the elimination tree (not implemented here).
Definition: pselinv.hpp:122
void SymbolicFactorizeComplexSymmetricMatrix(std::string ColPerm, Int numProcSymbFact, Int verbosity)
Symbolically factorize the loaded matrices for complex arithmetic factorization and selected inversio...
Definition: ppexsi.cpp:403
Interface with SuperLU_Dist (version 3.0 and later)
const DistSparseMatrix< Real > & EnergyDensityRealMat() const
Energy density matrix.
Definition: ppexsi.hpp:333
Main class for parallel PEXSI.
Definition: ppexsi.hpp:66
void DFTDriver(Real numElectronExact, Real temperature, Real gap, Real deltaE, Int numPole, Int isInertiaCount, Int maxPEXSIIter, Real muMin0, Real muMax0, Real muInertiaTolerance, Real muInertiaExpansion, Real muPEXSISafeGuard, Real numElectronPEXSITolerance, Int matrixType, Int isSymbolicFactorize, Int ordering, Int numProcSymbFact, Int verbosity, Real &muPEXSI, Real &numElectronPEXSI, Real &muMinInertia, Real &muMaxInertia, Int &numTotalInertiaIter, Int &numTotalPEXSIIter)
Main driver for solving KSDFT.
Definition: ppexsi.cpp:1493
Main file for parallel selected inversion.
SuperLU processor grid.
Definition: SuperLUMatrix.hpp:235
void CalculateFermiOperatorReal(Int numPole, Real temperature, Real gap, Real deltaE, Real mu, Real numElectronExact, Real numElectronTolerance, Int verbosity, Real &numElectron, Real &numElectronDrvMu)
Compute the Fermi operator for a given chemical potential for real symmetric matrices.
Definition: ppexsi.cpp:902
Definition: SuperLUMatrix.hpp:363
Sparse matrix and Distributed sparse matrix in compressed column format.
GridType is the PSelInv way of defining the grid.
Definition: pselinv.hpp:85
Interface with MPI to facilitate communication.
void CalculateNegativeInertiaReal(const std::vector< Real > &shiftVec, std::vector< Real > &inertiaVec, Int verbosity)
Compute the negative inertia (the number of eigenvalues below a shift) for real symmetric matrices...
Definition: ppexsi.cpp:748
const DistSparseMatrix< Real > & RhoRealMat() const
Density matrix.
Definition: ppexsi.hpp:326
Various utility subroutines.
void SymbolicFactorizeRealSymmetricMatrix(std::string ColPerm, Int numProcSymbFact, Int verbosity)
Symbolically factorize the loaded matrices for real arithmetic factorization and selected inversion...
Definition: ppexsi.cpp:294
Definition: SuperLUGrid.hpp:112
Definition: SuperLUGrid.hpp:102
Numerical vector.
Pole expansion subroutines.