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 */
49 #ifndef _PPEXSI_HPP_
50 #define _PPEXSI_HPP_
51 #include "pexsi/environment.hpp"
52 #include "pexsi/sparse_matrix.hpp"
53 #include "pexsi/NumVec.hpp"
54 #include "pexsi/utility.hpp"
55 #include "pexsi/pole.hpp"
56 #include "pexsi/mpi_interf.hpp"
57 #include "pexsi/SuperLUGrid.hpp"
59 #include "pexsi/pselinv.hpp"
60 #include "pexsi/pselinv_unsym.hpp"
61 //#include "pexsi/ngchol_interf.hpp"
62 //#include "pexsi/c_pexsi_interface.h"
63 
64 namespace PEXSI{
65 
70  class PPEXSIData{
71  private:
72  // *********************************************************************
73  // Computational variables
74  // *********************************************************************
75 
76  std::vector<Complex> zshift_; // Complex shift for the pole expansion
77  std::vector<Complex> zweightRho_; // Complex weight for the pole expansion for density
78  std::vector<Complex> zweightRhoDrvMu_; // Complex weight for the pole expansion for derivative of the Fermi-Dirac with respect to the chemical potential
79  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)
80  std::vector<Complex> zweightHelmholtz_; // Complex shift for the pole expansion for Helmholtz free energy
81  std::vector<Complex> zweightForce_; // Complex weight for the pole expansion for force
82 
83  // Outer layer communicator. Also used for distributing the
84  // DistSparseMatrix. Each DistSparseMatrix is replicated in the row
85  // (numPoleGroup) direction of gridPole.
86  const GridType* gridPole_;
87  const GridType* gridSelInv_; // Inner layer communicator for SelInv
88 
89  // Inner layer communicator for SuperLU factorization
90  const SuperLUGrid<Real>* gridSuperLUReal_;
91  const SuperLUGrid<Complex>* gridSuperLUComplex_;
92 
93 
94  DistSparseMatrix<Real> HRealMat_;
95  DistSparseMatrix<Real> SRealMat_;
96 
97  DistSparseMatrix<Real> shiftRealMat_;
98  DistSparseMatrix<Complex> shiftComplexMat_;
99 
100  DistSparseMatrix<Real> shiftInvRealMat_;
101  DistSparseMatrix<Complex> shiftInvComplexMat_;
102 
103  DistSparseMatrix<Real> rhoRealMat_; // Density matrix
104  DistSparseMatrix<Real> rhoDrvMuRealMat_; // Derivative of the Fermi-Dirac with respect to mu
105  DistSparseMatrix<Real> rhoDrvTRealMat_; // Derivative of the Fermi-Dirac with respect to T
106  DistSparseMatrix<Real> freeEnergyDensityRealMat_; // Helmholtz free energy density matrix
107  DistSparseMatrix<Real> energyDensityRealMat_; // Energy density matrix for computing the Pulay force
108 
109  // SuperLUMatrix and PMatrix structures These structures are saved
110  // to avoid repetitive symbolic factorization process, and saved in
111  // pointer form because of the constructors.
112  SuperLUMatrix<Real>* luRealMat_;
113  SuperLUMatrix<Complex>* luComplexMat_;
114 
115  SuperLUOptions luOpt_;
116  PSelInvOptions selinvOpt_;
117 
118  PMatrix<Real>* PMRealMat_;
119  PMatrix<Complex>* PMComplexMat_;
120  PMatrixUnsym<Real>* PMRealUnsymMat_;
121  PMatrixUnsym<Complex>* PMComplexUnsymMat_;
122 
123  // Whether the matrices have been loaded into HRealMat_ and
124  // SRealMat_
125  bool isMatrixLoaded_;
126  // Whether the matrices (luMat and PMat) have obtained symbolic
127  // information
128  bool isRealSymmetricSymbolicFactorized_;
129  bool isComplexSymmetricSymbolicFactorized_;
130  bool isRealUnsymmetricSymbolicFactorized_;
131  bool isComplexUnsymmetricSymbolicFactorized_;
132  // Supernode partition for the real matrix
133  SuperNodeType superReal_;
134  // Supernode partition for the complex matrix
135  SuperNodeType superComplex_;
136 
137  // Saves all the indices of diagonal elements in H, so that
138  // H.nzvalLocal(diagIdxLocal_[j]) are diagonal elements for all j.
139  // This is manly used when S is implicitly given as an identity matrix.
140  std::vector<Int> diagIdxLocal_;
141 
142  // Energy computed from Tr[H*DM]
143  Real totalEnergyH_;
144  // Energy computed from Tr[S*EDM]
145  Real totalEnergyS_;
146  // Free energy
147  Real totalFreeEnergy_;
148 
149 
150  // *********************************************************************
151  // Saved variables for nonlinear iterations
152  // *********************************************************************
153 
154  public:
155  PPEXSIData(
156  MPI_Comm comm,
157  Int numProcRow,
158  Int numProcCol,
159  Int outputFileIndex );
160 
161  ~PPEXSIData();
162 
163  void LoadRealSymmetricMatrix(
164  Int nrows,
165  Int nnz,
166  Int nnzLocal,
167  Int numColLocal,
168  Int* colptrLocal,
169  Int* rowindLocal,
170  Real* HnzvalLocal,
171  Int isSIdentity,
172  Real* SnzvalLocal,
173  Int verbosity );
174 
175  void LoadRealUnsymmetricMatrix(
176  Int nrows,
177  Int nnz,
178  Int nnzLocal,
179  Int numColLocal,
180  Int* colptrLocal,
181  Int* rowindLocal,
182  Real* HnzvalLocal,
183  Int isSIdentity,
184  Real* SnzvalLocal,
185  Int verbosity );
186 
187 
188 
204  std::string ColPerm,
205  Int numProcSymbFact,
206  Int verbosity );
207 
226  std::string ColPerm,
227  std::string RowPerm,
228  Int numProcSymbFact,
229  Int Transpose,
230  double* AnzvalLocal,
231  Int verbosity );
232 
233 
249  std::string ColPerm,
250  Int numProcSymbFact,
251  Int verbosity );
252 
271  std::string ColPerm,
272  std::string RowPerm,
273  Int numProcSymbFact,
274  Int Transpose,
275  double* AnzvalLocal,
276  Int verbosity );
277 
278 
279 
280  void SelInvRealSymmetricMatrix(
281  double* AnzvalLocal,
282  Int verbosity,
283  double* AinvnzvalLocal );
284 
285  void SelInvRealUnsymmetricMatrix(
286  double* AnzvalLocal,
287  Int verbosity,
288  double* AinvnzvalLocal );
289 
290 
291  void SelInvComplexSymmetricMatrix(
292  double* AnzvalLocal,
293  Int verbosity,
294  double* AinvnzvalLocal );
295 
296  void SelInvComplexUnsymmetricMatrix(
297  double* AnzvalLocal,
298  Int verbosity,
299  double* AinvnzvalLocal );
300 
301 
302 
332  const std::vector<Real>& shiftVec,
333  std::vector<Real>& inertiaVec,
334  Int verbosity );
335 
336 
363  Int numPole,
364  Real temperature,
365  Real gap,
366  Real deltaE,
367  Real mu,
368  Real numElectronExact,
369  Real numElectronTolerance,
370  Int verbosity,
371  Real& numElectron,
372  Real& numElectronDrvMu );
373 
374 
376  void DFTDriver(
377  Real numElectronExact,
378  Real temperature,
379  Real gap,
380  Real deltaE,
381  Int numPole,
382  Int isInertiaCount,
383  Int maxPEXSIIter,
384  Real muMin0,
385  Real muMax0,
386  Real mu0,
387  Real muInertiaTolerance,
388  Real muInertiaExpansion,
389  Real muPEXSISafeGuard,
390  Real numElectronPEXSITolerance,
391  Int matrixType,
392  Int isSymbolicFactorize,
393  Int ordering,
394  Int numProcSymbFact,
395  Int verbosity,
396  Real& muPEXSI,
397  Real& numElectronPEXSI,
398  Real& muMinInertia,
399  Real& muMaxInertia,
400  Int& numTotalInertiaIter,
401  Int& numTotalPEXSIIter );
402 
403 
404 
437  Int numPole,
438  Real temperature,
439  Real gap,
440  Real deltaE,
441  Real numElectronExact,
442  Real numElectronTolerance,
443  Real muMinPEXSI,
444  Real muMaxPEXSI,
445  Int verbosity,
446  Real& mu,
447  Real& numElectron,
448  bool& isPEXSIConverged );
449 
452  void DFTDriver2(
453  Real numElectronExact,
454  Real temperature,
455  Real gap,
456  Real deltaE,
457  Int numPole,
458  Int isInertiaCount,
459  Real muMin0,
460  Real muMax0,
461  Real mu0,
462  Real muInertiaTolerance,
463  Real muInertiaExpansion,
464  Real numElectronPEXSITolerance,
465  Int matrixType,
466  Int isSymbolicFactorize,
467  Int ordering,
468  Int numProcSymbFact,
469  Int verbosity,
470  Real& muPEXSI,
471  Real& numElectronPEXSI,
472  Real& muMinInertia,
473  Real& muMaxInertia,
474  Int& numTotalInertiaIter );
475 
476 
477 
478 
479  // *********************************************************************
480  // Access data
481  // *********************************************************************
482 
483  const GridType* GridPole() const {return gridPole_;}
484 
489  const DistSparseMatrix<Real>& RhoRealMat() const {return rhoRealMat_;}
490 
496  const DistSparseMatrix<Real>& EnergyDensityRealMat() const {return energyDensityRealMat_;}
497 
506  const DistSparseMatrix<Real>& FreeEnergyDensityRealMat() const {return freeEnergyDensityRealMat_;}
507 
508  Real TotalEnergyH() const {return totalEnergyH_;}
509 
510  Real TotalEnergyS() const {return totalEnergyS_;}
511 
512  Real TotalFreeEnergy() const {return totalFreeEnergy_;}
513 
514 
515  }; // PPEXSIData
516 
517 
518 } // namespace PEXSI
519 #endif // _PPEXSI_HPP_
void DFTDriver2(Real numElectronExact, Real temperature, Real gap, Real deltaE, Int numPole, Int isInertiaCount, Real muMin0, Real muMax0, Real mu0, Real muInertiaTolerance, Real muInertiaExpansion, Real numElectronPEXSITolerance, Int matrixType, Int isSymbolicFactorize, Int ordering, Int numProcSymbFact, Int verbosity, Real &muPEXSI, Real &numElectronPEXSI, Real &muMinInertia, Real &muMaxInertia, Int &numTotalInertiaIter)
Updated main driver for DFT. This reuses the pole expansion and only performs one PEXSI iteration per...
Definition: ppexsi.cpp:2706
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:506
SuperNodeType describes mapping between supernode and column, the permutation information, and potentially the elimination tree (not implemented here).
Definition: pselinv.hpp:166
void SymbolicFactorizeComplexSymmetricMatrix(std::string ColPerm, Int numProcSymbFact, Int verbosity)
Symbolically factorize the loaded matrices for complex arithmetic factorization and selected inversio...
Definition: ppexsi.cpp:727
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:2198
const DistSparseMatrix< Real > & EnergyDensityRealMat() const
Energy density matrix.
Definition: ppexsi.hpp:496
Main class for parallel PEXSI.
Definition: ppexsi.hpp:70
Main file for parallel selected inversion on unsymmetric matrices.
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:1597
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:129
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:1437
const DistSparseMatrix< Real > & RhoRealMat() const
Density matrix.
Definition: ppexsi.hpp:489
Various utility subroutines.
void SymbolicFactorizeComplexUnsymmetricMatrix(std::string ColPerm, std::string RowPerm, Int numProcSymbFact, Int Transpose, double *AnzvalLocal, Int verbosity)
Symbolically factorize the loaded matrices for complex arithmetic factorization and selected inversio...
Definition: ppexsi.cpp:836
void SymbolicFactorizeRealSymmetricMatrix(std::string ColPerm, Int numProcSymbFact, Int verbosity)
Symbolically factorize the loaded matrices for real arithmetic factorization and selected inversion...
Definition: ppexsi.cpp:475
void CalculateFermiOperatorReal2(Int numPole, Real temperature, Real gap, Real deltaE, Real numElectronExact, Real numElectronTolerance, Real muMinPEXSI, Real muMaxPEXSI, Int verbosity, Real &mu, Real &numElectron, bool &isPEXSIConverged)
Compute the Fermi operator and derivied quantities.
Definition: ppexsi.cpp:3190
Definition: SuperLUGrid.hpp:124
Definition: SuperLUGrid.hpp:111
Numerical vector.
void SymbolicFactorizeRealUnsymmetricMatrix(std::string ColPerm, std::string RowPerm, Int numProcSymbFact, Int Transpose, double *AnzvalLocal, Int verbosity)
Symbolically factorize the loaded matrices for real arithmetic factorization and selected inversion...
Definition: ppexsi.cpp:588
A thin interface for passing parameters to set the PSelInv options.
Definition: pselinv.hpp:102
Pole expansion subroutines.