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 
143  public:
144  PPEXSIData(
145  MPI_Comm comm,
146  Int numProcRow,
147  Int numProcCol,
148  Int outputFileIndex );
149 
150  ~PPEXSIData();
151 
152  void LoadRealSymmetricMatrix(
153  Int nrows,
154  Int nnz,
155  Int nnzLocal,
156  Int numColLocal,
157  Int* colptrLocal,
158  Int* rowindLocal,
159  Real* HnzvalLocal,
160  Int isSIdentity,
161  Real* SnzvalLocal,
162  Int verbosity );
163 
164 
180  std::string ColPerm,
181  Int numProcSymbFact,
182  Int verbosity );
183 
199  std::string ColPerm,
200  Int numProcSymbFact,
201  Int verbosity );
202 
203 
204  void SelInvRealSymmetricMatrix(
205  double* AnzvalLocal,
206  Int verbosity,
207  double* AinvnzvalLocal );
208 
209  void SelInvComplexSymmetricMatrix(
210  double* AnzvalLocal,
211  Int verbosity,
212  double* AinvnzvalLocal );
213 
214 
244  const std::vector<Real>& shiftVec,
245  std::vector<Real>& inertiaVec,
246  Int verbosity );
247 
248 
275  Int numPole,
276  Real temperature,
277  Real gap,
278  Real deltaE,
279  Real mu,
280  Real numElectronExact,
281  Real numElectronTolerance,
282  Int verbosity,
283  Real& numElectron,
284  Real& numElectronDrvMu );
285 
286 
288  void DFTDriver(
289  Real numElectronExact,
290  Real temperature,
291  Real gap,
292  Real deltaE,
293  Int numPole,
294  Int isInertiaCount,
295  Int maxPEXSIIter,
296  Real muMin0,
297  Real muMax0,
298  Real mu0,
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:416
Interface with SuperLU_Dist (version 3.0 and later)
void DFTDriver(Real numElectronExact, Real temperature, Real gap, Real deltaE, Int numPole, Int isInertiaCount, Int maxPEXSIIter, Real muMin0, Real muMax0, Real mu0, 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:1508
const DistSparseMatrix< Real > & EnergyDensityRealMat() const
Energy density matrix.
Definition: ppexsi.hpp:333
Main class for parallel PEXSI.
Definition: ppexsi.hpp:66
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:915
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:761
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:307
Definition: SuperLUGrid.hpp:112
Definition: SuperLUGrid.hpp:102
Numerical vector.
Pole expansion subroutines.