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 "pexsi/environment.hpp"
50 #include "pexsi/sparse_matrix.hpp"
51 #include "pexsi/NumVec.hpp"
52 #include "pexsi/utility.hpp"
53 #include "pexsi/pole.hpp"
54 #include "pexsi/mpi_interf.hpp"
55 #include "pexsi/SuperLUGrid.hpp"
57 #include "pexsi/pselinv.hpp"
58 //#include "pexsi/ngchol_interf.hpp"
59 //#include "pexsi/c_pexsi_interface.h"
60 
61 namespace PEXSI{
62 
67  class PPEXSIData{
68  private:
69  // *********************************************************************
70  // Computational variables
71  // *********************************************************************
72 
73  std::vector<Complex> zshift_; // Complex shift for the pole expansion
74  std::vector<Complex> zweightRho_; // Complex weight for the pole expansion for density
75  std::vector<Complex> zweightRhoDrvMu_; // Complex weight for the pole expansion for derivative of the Fermi-Dirac with respect to the chemical potential
76  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)
77  std::vector<Complex> zweightHelmholtz_; // Complex shift for the pole expansion for Helmholtz free energy
78  std::vector<Complex> zweightForce_; // Complex weight for the pole expansion for force
79 
80  // Outer layer communicator. Also used for distributing the
81  // DistSparseMatrix. Each DistSparseMatrix is replicated in the row
82  // (numPoleGroup) direction of gridPole.
83  const GridType* gridPole_;
84  const GridType* gridSelInv_; // Inner layer communicator for SelInv
85 
86  // Inner layer communicator for SuperLU factorization
87  const SuperLUGrid<Real>* gridSuperLUReal_;
88  const SuperLUGrid<Complex>* gridSuperLUComplex_;
89 
90 
91  DistSparseMatrix<Real> HRealMat_;
92  DistSparseMatrix<Real> SRealMat_;
93 
94  DistSparseMatrix<Real> shiftRealMat_;
95  DistSparseMatrix<Complex> shiftComplexMat_;
96 
97  DistSparseMatrix<Real> shiftInvRealMat_;
98  DistSparseMatrix<Complex> shiftInvComplexMat_;
99 
100  DistSparseMatrix<Real> rhoRealMat_; // Density matrix
101  DistSparseMatrix<Real> rhoDrvMuRealMat_; // Derivative of the Fermi-Dirac with respect to mu
102  DistSparseMatrix<Real> rhoDrvTRealMat_; // Derivative of the Fermi-Dirac with respect to T
103  DistSparseMatrix<Real> freeEnergyDensityRealMat_; // Helmholtz free energy density matrix
104  DistSparseMatrix<Real> energyDensityRealMat_; // Energy density matrix for computing the Pulay force
105 
106  // SuperLUMatrix and PMatrix structures These structures are saved
107  // to avoid repetitive symbolic factorization process, and saved in
108  // pointer form because of the constructors.
109  SuperLUMatrix<Real>* luRealMat_;
110  SuperLUMatrix<Complex>* luComplexMat_;
111 
112  SuperLUOptions luOpt_;
113 
114  PMatrix<Real>* PMRealMat_;
115  PMatrix<Complex>* PMComplexMat_;
116 
117  // Whether the matrices have been loaded into HRealMat_ and
118  // SRealMat_
119  bool isMatrixLoaded_;
120  // Whether the matrices (luMat and PMat) have obtained symbolic
121  // information
122  bool isRealSymmetricSymbolicFactorized_;
123  bool isComplexSymmetricSymbolicFactorized_;
124  // Supernode partition for the real matrix
125  SuperNodeType superReal_;
126  // Supernode partition for the complex matrix
127  SuperNodeType superComplex_;
128 
129  // Saves all the indices of diagonal elements in H, so that
130  // H.nzvalLocal(diagIdxLocal_[j]) are diagonal elements for all j.
131  // This is manly used when S is implicitly given as an identity matrix.
132  std::vector<Int> diagIdxLocal_;
133 
134  // Energy computed from Tr[H*DM]
135  Real totalEnergyH_;
136  // Energy computed from Tr[S*EDM]
137  Real totalEnergyS_;
138  // Free energy
139  Real totalFreeEnergy_;
140 
141 
142  // *********************************************************************
143  // Saved variables for nonlinear iterations
144  // *********************************************************************
145 
146  public:
147  PPEXSIData(
148  MPI_Comm comm,
149  Int numProcRow,
150  Int numProcCol,
151  Int outputFileIndex );
152 
153  ~PPEXSIData();
154 
155  void LoadRealSymmetricMatrix(
156  Int nrows,
157  Int nnz,
158  Int nnzLocal,
159  Int numColLocal,
160  Int* colptrLocal,
161  Int* rowindLocal,
162  Real* HnzvalLocal,
163  Int isSIdentity,
164  Real* SnzvalLocal,
165  Int verbosity );
166 
167 
168 
184  std::string ColPerm,
185  Int numProcSymbFact,
186  Int verbosity );
187 
188 
204  std::string ColPerm,
205  Int numProcSymbFact,
206  Int verbosity );
207 
208  void SelInvRealSymmetricMatrix(
209  double* AnzvalLocal,
210  Int verbosity,
211  double* AinvnzvalLocal );
212 
213  void SelInvComplexSymmetricMatrix(
214  double* AnzvalLocal,
215  Int verbosity,
216  double* AinvnzvalLocal );
217 
247  const std::vector<Real>& shiftVec,
248  std::vector<Real>& inertiaVec,
249  Int verbosity );
250 
251 
278  Int numPole,
279  Real temperature,
280  Real gap,
281  Real deltaE,
282  Real mu,
283  Real numElectronExact,
284  Real numElectronTolerance,
285  Int verbosity,
286  Real& numElectron,
287  Real& numElectronDrvMu );
288 
289 
291  void DFTDriver(
292  Real numElectronExact,
293  Real temperature,
294  Real gap,
295  Real deltaE,
296  Int numPole,
297  Int isInertiaCount,
298  Int maxPEXSIIter,
299  Real muMin0,
300  Real muMax0,
301  Real mu0,
302  Real muInertiaTolerance,
303  Real muInertiaExpansion,
304  Real muPEXSISafeGuard,
305  Real numElectronPEXSITolerance,
306  Int matrixType,
307  Int isSymbolicFactorize,
308  Int ordering,
309  Int numProcSymbFact,
310  Int verbosity,
311  Real& muPEXSI,
312  Real& numElectronPEXSI,
313  Real& muMinInertia,
314  Real& muMaxInertia,
315  Int& numTotalInertiaIter,
316  Int& numTotalPEXSIIter );
317 
318 
319  // *********************************************************************
320  // Access data
321  // *********************************************************************
322 
323  const GridType* GridPole() const {return gridPole_;}
324 
329  const DistSparseMatrix<Real>& RhoRealMat() const {return rhoRealMat_;}
330 
336  const DistSparseMatrix<Real>& EnergyDensityRealMat() const {return energyDensityRealMat_;}
337 
346  const DistSparseMatrix<Real>& FreeEnergyDensityRealMat() const {return freeEnergyDensityRealMat_;}
347 
348  Real TotalEnergyH() const {return totalEnergyH_;}
349 
350  Real TotalEnergyS() const {return totalEnergyS_;}
351 
352  Real TotalFreeEnergy() const {return totalFreeEnergy_;}
353 
354 
355  }; // PPEXSIData
356 
357 
358 } // namespace PEXSI
359 #endif // _PPEXSI_HPP_
Environmental variables.
A thin interface for passing parameters to set the SuperLU options.
Definition: superlu_dist_internal.hpp:62
const DistSparseMatrix< Real > & FreeEnergyDensityRealMat() const
Total Helmholtz free energy matrix (band energy part only).
Definition: ppexsi.hpp:346
SuperNodeType describes mapping between supernode and column, the permutation information, and potentially the elimination tree (not implemented here).
Definition: pselinv.hpp:143
void SymbolicFactorizeComplexSymmetricMatrix(std::string ColPerm, Int numProcSymbFact, Int verbosity)
Symbolically factorize the loaded matrices for complex arithmetic factorization and selected inversio...
Definition: ppexsi.cpp:408
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:1512
const DistSparseMatrix< Real > & EnergyDensityRealMat() const
Energy density matrix.
Definition: ppexsi.hpp:336
Main class for parallel PEXSI.
Definition: ppexsi.hpp:67
Main file for parallel selected inversion.
SuperLU processor grid.
Definition: SuperLUMatrix.hpp:206
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:910
Definition: SuperLUMatrix.hpp:337
Sparse matrix and Distributed sparse matrix in compressed column format.
GridType is the PSelInv way of defining the grid.
Definition: pselinv.hpp:106
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:750
const DistSparseMatrix< Real > & RhoRealMat() const
Density matrix.
Definition: ppexsi.hpp:329
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:298
Definition: SuperLUGrid.hpp:124
Definition: SuperLUGrid.hpp:111
Numerical vector.
Pole expansion subroutines.