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  */
51 #ifndef _PPEXSI_HPP_
52 #define _PPEXSI_HPP_
53 #include "pexsi/environment.hpp"
54 #include "pexsi/sparse_matrix.hpp"
55 #include "pexsi/NumVec.hpp"
56 #include "pexsi/utility.hpp"
57 #include "pexsi/pole.hpp"
58 #include "pexsi/mpi_interf.hpp"
59 #include "pexsi/SuperLUGrid.hpp"
61 #include "pexsi/pselinv.hpp"
62 #include "pexsi/pselinv_unsym.hpp"
63 //#include "pexsi/ngchol_interf.hpp"
64 //#include "pexsi/c_pexsi_interface.h"
65 
66 #ifdef WITH_SYMPACK
67 #include <sympack.hpp>
68 #include "pexsi/sympack_interf.hpp"
69 #endif
70 
71 namespace PEXSI{
72 
77 class PPEXSIData{
78 private:
79  // *********************************************************************
80  // Computational variables
81  // *********************************************************************
82 
83  std::vector<Complex> zshift_; // Complex shift for the pole expansion
84  std::vector<Complex> zweightRho_; // Complex weight for the pole expansion for density
85  std::vector<Complex> zweightRhoDrvMu_; // Complex weight for the pole expansion for derivative of the Fermi-Dirac with respect to the chemical potential
86  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)
87  std::vector<Complex> zweightHelmholtz_; // Complex shift for the pole expansion for Helmholtz free energy
88  std::vector<Complex> zweightForce_; // Complex weight for the pole expansion for force
89 
90  // Outer layer communicator. Also used for distributing the
91  // DistSparseMatrix. Each DistSparseMatrix is replicated in the row
92  // (numPoleGroup) direction of gridPole.
93  const GridType* gridPole_;
94  const GridType* gridSelInv_; // Inner layer communicator for SelInv
95 
96  // Inner layer communicator for SuperLU factorization
97  const SuperLUGrid<Real>* gridSuperLUReal_;
98  const SuperLUGrid<Complex>* gridSuperLUComplex_;
99 
100  // Used for performing "CopyPattern"
101  DistSparseMatrix<Real> PatternMat_;
102 
103  DistSparseMatrix<Real> HRealMat_;
104  DistSparseMatrix<Real> SRealMat_;
105 
106 
107  DistSparseMatrix<Real> shiftRealMat_;
108  DistSparseMatrix<Complex> shiftComplexMat_;
109 
110  DistSparseMatrix<Real> shiftInvRealMat_;
111  DistSparseMatrix<Complex> shiftInvComplexMat_;
112 
113  DistSparseMatrix<Real> rhoRealMat_; // Density matrix
114  DistSparseMatrix<Real> rhoDrvMuRealMat_; // Derivative of the Fermi-Dirac with respect to mu
115  DistSparseMatrix<Real> rhoDrvTRealMat_; // Derivative of the Fermi-Dirac with respect to T
116  DistSparseMatrix<Real> freeEnergyDensityRealMat_; // Helmholtz free energy density matrix
117  DistSparseMatrix<Real> energyDensityRealMat_; // Energy density matrix for computing the Pulay force
118 
119 
120  // Below specifically for the case when H and S are Hermitian
121  DistSparseMatrix<Complex> HComplexMat_;
122  DistSparseMatrix<Complex> SComplexMat_;
123 
124  DistSparseMatrix<Complex> rhoComplexMat_; // Density matrix
125  DistSparseMatrix<Complex> rhoDrvMuComplexMat_; // Derivative of the Fermi-Dirac with respect to mu
126  DistSparseMatrix<Complex> rhoDrvTComplexMat_; // Derivative of the Fermi-Dirac with respect to T
127  DistSparseMatrix<Complex> freeEnergyDensityComplexMat_; // Helmholtz free energy density matrix
128  DistSparseMatrix<Complex> energyDensityComplexMat_; // Energy density matrix for computing the Pulay force
129 
130 
131  // SuperLUMatrix and PMatrix structures These structures are saved
132  // to avoid repetitive symbolic factorization process, and saved in
133  // pointer form because of the constructors.
134  SuperLUMatrix<Real>* luRealMat_;
135  SuperLUMatrix<Complex>* luComplexMat_;
136 
137 #ifdef WITH_SYMPACK
138  symPACK::symPACKMatrix<Real>* symPACKRealMat_;
139  symPACK::symPACKMatrix<Complex>* symPACKComplexMat_;
140  symPACK::symPACKOptions symPACKOpt_;
141 
142  // Used for performing "CopyPattern"
143  symPACK::DistSparseMatrix<Real> symmPatternMat_;
144 
145  symPACK::DistSparseMatrix<Real> symmHRealMat_;
146  symPACK::DistSparseMatrix<Real> symmSRealMat_;
147  // Below specifically for the case when H and S are Hermitian
148  symPACK::DistSparseMatrix<Complex> symmHComplexMat_;
149  symPACK::DistSparseMatrix<Complex> symmSComplexMat_;
150 
151  symPACK::DistSparseMatrix<Real> symmShiftRealMat_;
152  symPACK::DistSparseMatrix<Complex> symmShiftComplexMat_;
153 
154  symPACK::DistSparseMatrix<Real> symmShiftInvRealMat_;
155  symPACK::DistSparseMatrix<Complex> symmShiftInvComplexMat_;
156 #endif
157 
158  SuperLUOptions luOpt_;
159  FactorizationOptions factOpt_;
160  PSelInvOptions selinvOpt_;
161 
162  PMatrix<Real>* PMRealMat_;
163  PMatrix<Complex>* PMComplexMat_;
164  PMatrixUnsym<Real>* PMRealUnsymMat_;
165  PMatrixUnsym<Complex>* PMComplexUnsymMat_;
166 
167  // Whether the matrices have been loaded into HRealMat_ and
168  // SRealMat_
169  bool isMatrixLoaded_;
170  // Whether the matrices (luMat and PMat) have obtained symbolic
171  // information
172  bool isRealSymmetricSymbolicFactorized_;
173  bool isComplexSymmetricSymbolicFactorized_;
174  bool isRealUnsymmetricSymbolicFactorized_;
175  bool isComplexUnsymmetricSymbolicFactorized_;
176  // Supernode partition for the real matrix
177  SuperNodeType superReal_;
178  // Supernode partition for the complex matrix
179  SuperNodeType superComplex_;
180 
181  // Saves all the indices of diagonal elements in H, so that
182  // H.nzvalLocal(diagIdxLocal_[j]) are diagonal elements for all j.
183  // This is manly used when S is implicitly given as an identity matrix.
184  std::vector<Int> diagIdxLocal_;
185 
186  // Energy computed from Tr[H*DM]
187  Real totalEnergyH_;
188  // Energy computed from Tr[S*EDM]
189  Real totalEnergyS_;
190  // Free energy
191  Real totalFreeEnergy_;
192 
193 
194  // *********************************************************************
195  // Saved variables for nonlinear iterations
196  // *********************************************************************
197 
198 public:
199  PPEXSIData(
200  MPI_Comm comm,
201  Int numProcRow,
202  Int numProcCol,
203  Int outputFileIndex );
204 
205  ~PPEXSIData();
206 
207  void LoadRealMatrix(
208  Int nrows,
209  Int nnz,
210  Int nnzLocal,
211  Int numColLocal,
212  Int* colptrLocal,
213  Int* rowindLocal,
214  Real* HnzvalLocal,
215  Int isSIdentity,
216  Real* SnzvalLocal,
217  Int solver,
218  Int verbosity );
219 
220 
221  void LoadComplexMatrix(
222  Int nrows,
223  Int nnz,
224  Int nnzLocal,
225  Int numColLocal,
226  Int* colptrLocal,
227  Int* rowindLocal,
228  Complex* HnzvalLocal,
229  Int isSIdentity,
230  Complex* SnzvalLocal,
231  Int solver,
232  Int verbosity );
233 
234 
252  Int solver,
253  std::string ColPerm,
254  Int numProcSymbFact,
255  Int verbosity );
256 
277  Int solver,
278  std::string ColPerm,
279  std::string RowPerm,
280  Int numProcSymbFact,
281  Int Transpose,
282  double* AnzvalLocal,
283  Int verbosity );
284 
285 
289 
304  Int solver,
305  std::string ColPerm,
306  Int numProcSymbFact,
307  Int verbosity );
308 
329  Int solver,
330  std::string ColPerm,
331  std::string RowPerm,
332  Int numProcSymbFact,
333  Int Transpose,
334  double* AnzvalLocal,
335  Int verbosity );
336 
337 
338 
339  void SelInvRealSymmetricMatrix(
340  Int solver,
341  double* AnzvalLocal,
342  Int verbosity,
343  double* AinvnzvalLocal );
344 
345  void SelInvRealUnsymmetricMatrix(
346  Int solver,
347  double* AnzvalLocal,
348  Int verbosity,
349  double* AinvnzvalLocal );
350 
351 
352  void SelInvComplexSymmetricMatrix(
353  Int solver,
354  double* AnzvalLocal,
355  Int verbosity,
356  double* AinvnzvalLocal );
357 
358  void SelInvComplexUnsymmetricMatrix(
359  Int solver,
360  double* AnzvalLocal,
361  Int verbosity,
362  double* AinvnzvalLocal );
363 
364 
365 
395  const std::vector<Real>& shiftVec,
396  std::vector<Real>& inertiaVec,
397  Int solver,
398  Int verbosity );
399 
429  const std::vector<Real>& shiftVec,
430  std::vector<Real>& inertiaVec,
431  Int solver,
432  Int verbosity );
433 
434 
435 
462  Int numPole,
463  Real temperature,
464  Real gap,
465  Real deltaE,
466  Real mu,
467  Real numElectronExact,
468  Real numElectronTolerance,
469  Int solver,
470  Int verbosity,
471  Real& numElectron,
472  Real& numElectronDrvMu );
473 
474 
501  Int numPole,
502  Real temperature,
503  Real gap,
504  Real deltaE,
505  Real mu,
506  Real numElectronExact,
507  Real numElectronTolerance,
508  Int solver,
509  Int verbosity,
510  Real& numElectron,
511  Real& numElectronDrvMu );
512 
513 
514 
516  void DFTDriver(
517  Real numElectronExact,
518  Real temperature,
519  Real gap,
520  Real deltaE,
521  Int numPole,
522  Int isInertiaCount,
523  Int maxPEXSIIter,
524  Real muMin0,
525  Real muMax0,
526  Real mu0,
527  Real muInertiaTolerance,
528  Real muInertiaExpansion,
529  Real muPEXSISafeGuard,
530  Real numElectronPEXSITolerance,
531  Int matrixType,
532  Int isSymbolicFactorize,
533  Int solver,
534  Int ordering,
535  Int numProcSymbFact,
536  Int verbosity,
537  Real& muPEXSI,
538  Real& numElectronPEXSI,
539  Real& muMinInertia,
540  Real& muMaxInertia,
541  Int& numTotalInertiaIter,
542  Int& numTotalPEXSIIter );
543 
544 
545 
578  Int numPole,
579  Real temperature,
580  Real gap,
581  Real deltaE,
582  Real numElectronExact,
583  Real numElectronTolerance,
584  Real muMinPEXSI,
585  Real muMaxPEXSI,
586  Int solver,
587  Int verbosity,
588  Real& mu,
589  Real& numElectron,
590  bool& isPEXSIConverged );
591 
594  void DFTDriver2(
595  Real numElectronExact,
596  Real temperature,
597  Real gap,
598  Real deltaE,
599  Int numPole,
600  Int isInertiaCount,
601  Real muMin0,
602  Real muMax0,
603  Real mu0,
604  Real muInertiaTolerance,
605  Real muInertiaExpansion,
606  Real numElectronPEXSITolerance,
607  Int matrixType,
608  Int isSymbolicFactorize,
609  Int solver,
610  Int ordering,
611  Int numProcSymbFact,
612  Int verbosity,
613  Real& muPEXSI,
614  Real& numElectronPEXSI,
615  Real& muMinInertia,
616  Real& muMaxInertia,
617  Int& numTotalInertiaIter );
618 
619 
620 
621 
622  // *********************************************************************
623  // Access data
624  // *********************************************************************
625 
626  const GridType* GridPole() const {return gridPole_;}
627 
628 
633  const DistSparseMatrix<Real>& RhoRealMat() const {return rhoRealMat_;}
634  const DistSparseMatrix<Complex>& RhoComplexMat() const {return rhoComplexMat_;}
635 
641  const DistSparseMatrix<Real>& EnergyDensityRealMat() const {return energyDensityRealMat_;}
642  const DistSparseMatrix<Complex>& EnergyDensityComplexMat() const {return energyDensityComplexMat_;}
643 
652  const DistSparseMatrix<Real>& FreeEnergyDensityRealMat() const {return freeEnergyDensityRealMat_;}
653  const DistSparseMatrix<Complex>& FreeEnergyDensityComplexMat() const {return freeEnergyDensityComplexMat_;}
654 
655  Real TotalEnergyH() const {return totalEnergyH_;}
656 
657  Real TotalEnergyS() const {return totalEnergyS_;}
658 
659  Real TotalFreeEnergy() const {return totalFreeEnergy_;}
660 
661 
662 }; // PPEXSIData
663 
664 
665 } // namespace PEXSI
666 #endif // _PPEXSI_HPP_
Environmental variables.
A thin interface for passing parameters to set the Factorization options.
Definition: pselinv.hpp:115
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:652
void SymbolicFactorizeRealUnsymmetricMatrix(Int solver, 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:988
SuperNodeType describes mapping between supernode and column, the permutation information, and potentially the elimination tree (not implemented here).
Definition: pselinv.hpp:177
Interface with SuperLU_Dist (version 3.0 and later)
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 solver, 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:4238
const DistSparseMatrix< Real > & EnergyDensityRealMat() const
Energy density matrix.
Definition: ppexsi.hpp:641
void CalculateNegativeInertiaReal(const std::vector< Real > &shiftVec, std::vector< Real > &inertiaVec, Int solver, Int verbosity)
Compute the negative inertia (the number of eigenvalues below a shift) for real symmetric matrices...
Definition: ppexsi.cpp:2111
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 solver, 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:3759
Main class for parallel PEXSI.
Definition: ppexsi.hpp:77
Main file for parallel selected inversion on unsymmetric matrices.
Main file for parallel selected inversion.
SuperLU processor grid.
Definition: SuperLUMatrix.hpp:206
void CalculateNegativeInertiaComplex(const std::vector< Real > &shiftVec, std::vector< Real > &inertiaVec, Int solver, Int verbosity)
Compute the negative inertia (the number of eigenvalues below a shift) for complex Hermitian matrices...
Definition: ppexsi.cpp:2258
void CalculateFermiOperatorComplex(Int numPole, Real temperature, Real gap, Real deltaE, Real mu, Real numElectronExact, Real numElectronTolerance, Int solver, Int verbosity, Real &numElectron, Real &numElectronDrvMu)
Compute the Fermi operator for a given chemical potential for complex Hermitian matrices.
Definition: ppexsi.cpp:3051
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:140
Interface with MPI to facilitate communication.
const DistSparseMatrix< Real > & RhoRealMat() const
Density matrix.
Definition: ppexsi.hpp:633
Various utility subroutines.
void SymbolicFactorizeComplexUnsymmetricMatrix(Int solver, 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:1353
void SymbolicFactorizeRealSymmetricMatrix(Int solver, std::string ColPerm, Int numProcSymbFact, Int verbosity)
Symbolically factorize the loaded matrices for real arithmetic factorization and selected inversion...
Definition: ppexsi.cpp:785
Definition: SuperLUGrid.hpp:124
Definition: SuperLUGrid.hpp:111
Numerical vector.
A thin interface for passing parameters to set the PSelInv options.
Definition: pselinv.hpp:102
void SymbolicFactorizeComplexSymmetricMatrix(Int solver, std::string ColPerm, Int numProcSymbFact, Int verbosity)
Symbolically factorize the loaded matrices for complex arithmetic factorization and selected inversio...
Definition: ppexsi.cpp:1156
void CalculateFermiOperatorReal2(Int numPole, Real temperature, Real gap, Real deltaE, Real numElectronExact, Real numElectronTolerance, Real muMinPEXSI, Real muMaxPEXSI, Int solver, Int verbosity, Real &mu, Real &numElectron, bool &isPEXSIConverged)
Compute the Fermi operator and derivied quantities.
Definition: ppexsi.cpp:4693
void CalculateFermiOperatorReal(Int numPole, Real temperature, Real gap, Real deltaE, Real mu, Real numElectronExact, Real numElectronTolerance, Int solver, Int verbosity, Real &numElectron, Real &numElectronDrvMu)
Compute the Fermi operator for a given chemical potential for real symmetric matrices.
Definition: ppexsi.cpp:2405
Pole expansion subroutines.