PEXSI
 All Classes Namespaces Files Functions Variables Friends 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 */
46 #ifndef _PPEXSI_HPP_
47 #define _PPEXSI_HPP_
48 #include "environment.hpp"
49 #include "sparse_matrix_impl.hpp"
50 #include "numvec_impl.hpp"
51 #include "utility.hpp"
52 #include "pole.hpp"
53 #include "mpi_interf.hpp"
54 #include "superlu_dist_interf.hpp"
55 #include "pselinv.hpp"
56 #include "c_pexsi_interface.h"
57 
58 namespace PEXSI{
59 
64  class PPEXSIData{
65  private:
66  // *********************************************************************
67  // Computational variables
68  // *********************************************************************
69 
70  std::vector<Complex> zshift_; // Complex shift for the pole expansion
71  std::vector<Complex> zweightRho_; // Complex weight for the pole expansion for density
72  std::vector<Complex> zweightRhoDrvMu_; // Complex weight for the pole expansion for derivative of the Fermi-Dirac with respect to the chemical potential
73  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)
74  std::vector<Complex> zweightHelmholtz_; // Complex shift for the pole expansion for Helmholtz free energy
75  std::vector<Complex> zweightForce_; // Complex weight for the pole expansion for force
76 
77  const GridType* gridPole_; // Outer layer communicator. Also used for distributing the DistSparseMatrix. Each DistSparseMatrix is replicated in the row (numPoleGroup) direction of gridPole.
78  const GridType* gridSelInv_; // Inner layer communicator for SelInv
79  const SuperLUGrid* gridSuperLU_; // Inner layer communicator for SuperLU factorization
80 
81  SuperNodeType super_; // Supernode partition
82 
83  DistSparseMatrix<Real> rhoMat_; // Density matrix
84  DistSparseMatrix<Real> rhoDrvMuMat_; // Derivative of the Fermi-Dirac with respect to mu
85  DistSparseMatrix<Real> rhoDrvTMat_; // Derivative of the Fermi-Dirac with respect to T
86  DistSparseMatrix<Real> freeEnergyDensityMat_; // Helmholtz free energy density matrix
87  DistSparseMatrix<Real> energyDensityMat_; // Energy density matrix for computing the Pulay force
88 
89  // Saves all the indices of diagonal elements in H, so that
90  // H.nzvalLocal(diagIdxLocal_[j]) are diagonal elements for all j.
91  // This is manly used when S is implicitly given as an identity matrix.
92  std::vector<Int> diagIdxLocal_;
93 
94  // *********************************************************************
95  // Member functions
96  // *********************************************************************
99  Real CalculateChemicalPotentialNewtonFD(
100  const Int iter,
101  const Real numElectronExact,
102  const Real numElectronTolerance,
103  const std::vector<Real>& muList,
104  const std::vector<Real>& numElectronList );
105 
116  Real CalculateChemicalPotentialNewtonBisection(
117  const Real numElectronExact,
118  const Real numElectron,
119  const Real numElectronDrvMu,
120  const Real mu,
121  const Real muMin,
122  const Real muMax );
123 
124  public:
125  PPEXSIData( const PEXSI::GridType* g, Int nprow, Int npcol );
126  ~PPEXSIData();
127 
172  void Solve(
173  Int numPole,
174  Real temperature,
175  Real numElectronExact,
176  Real gap,
177  Real deltaE,
178  Real& mu,
179  Real& muMin,
180  Real& muMax,
181  const DistSparseMatrix<Real>& HMat,
182  const DistSparseMatrix<Real>& SMat,
183  Int muMaxIter,
184  Real numElectronTolerance,
185  std::string ColPerm,
186  Int numProcSymbFact,
187  bool isFreeEnergyDensityMatrix,
188  bool isEnergyDensityMatrix,
189  bool isDerivativeTMatrix,
190  std::vector<Real>& muList,
191  std::vector<Real>& numElectronList,
192  std::vector<Real>& numElectronDrvMuList,
193  bool& isConverged
194  );
195 
196 
197 
199  DistSparseMatrix<Real>& DensityMatrix () { return rhoMat_; }
200 
202  DistSparseMatrix<Real>& FreeEnergyDensityMatrix () { return freeEnergyDensityMat_; }
203 
206  DistSparseMatrix<Real>& EnergyDensityMatrix() { return energyDensityMat_; }
207 
214  Real CalculateNumElectron( const DistSparseMatrix<Real>& SMat );
215 
223 
232 
239  Real CalculateTotalEnergy( const DistSparseMatrix<Real>& HMat );
240 
252  Real CalculateFreeEnergy( const DistSparseMatrix<Real>& SMat );
253 
268  Real CalculateForce(
269  const DistSparseMatrix<Real>& HDerivativeMat,
270  const DistSparseMatrix<Real>& SDerivativeMat );
271 
272 
284  Real temperature,
285  Real mu,
286  const DistSparseMatrix<Real>& SMat );
287 
288 
317  const std::vector<Real>& shiftVec,
318  std::vector<Real>& inertiaVec,
319  const DistSparseMatrix<Real>& HMat,
320  const DistSparseMatrix<Real>& SMat,
321  std::string ColPerm,
322  Int numProcSymbFact );
323 
324 
328  const std::vector<Real>& shiftVec,
329  std::vector<Real>& inertiaVec,
330  const DistSparseMatrix<Real>& HMat,
331  const DistSparseMatrix<Real>& SMat,
332  std::string ColPerm,
333  Int numProcSymbFact );
334 
366  Int method,
367  const DistSparseMatrix<Real>& HMat,
368  const DistSparseMatrix<Real>& SMat,
369  const NumVec<Real>& v0,
370  Real tol,
371  Int maxNumIter,
372  Int& numIter,
373  Real& sigma );
374  }; // PPEXSIData
375 
376 
377 } // namespace PEXSI
378 #endif
DistSparseMatrix< Real > & FreeEnergyDensityMatrix()
DensityMatrix returns the free energy density matrix.
Definition: ppexsi.hpp:202
Environmental variables.
Real CalculateNumElectronDrvMu(const DistSparseMatrix< Real > &SMat)
CalculateNumElectronDrvMu computes the derivative of the number of electrons with respect to the chem...
Definition: ppexsi.cpp:939
DistSparseMatrix< Real > & EnergyDensityMatrix()
DensityMatrix returns the energy density matrix for computing the force.
Definition: ppexsi.hpp:206
Real CalculateForce(const DistSparseMatrix< Real > &HDerivativeMat, const DistSparseMatrix< Real > &SDerivativeMat)
CalculateFreeEnergy computes the force, including the Hellman-Feynman force and the Pulay force...
Definition: ppexsi.cpp:1077
DistSparseMatrix< Real > & DensityMatrix()
DensityMatrix returns the single particle density matrix.
Definition: ppexsi.hpp:199
SuperNodeType describes mapping between supernode and column, the permutation information, and potentially the elimination tree (not implemented here).
Definition: pselinv.hpp:121
void EstimateSpectralRadius(Int method, const DistSparseMatrix< Real > &HMat, const DistSparseMatrix< Real > &SMat, const NumVec< Real > &v0, Real tol, Int maxNumIter, Int &numIter, Real &sigma)
Estimate the spectral radius of the matrix stencil (H,S).
Definition: ppexsi.cpp:1364
Inteface with SuperLU_Dist (version 3.0 and later)
Implementation of Numerical Vector.
Main class for parallel PEXSI.
Definition: ppexsi.hpp:64
Main file for parallel selected inversion.
GridType is the PSelInv way of defining the grid.
Definition: pselinv.hpp:84
Interface with MPI to facilitate communication.
Various utility subroutines.
void Solve(Int numPole, Real temperature, Real numElectronExact, Real gap, Real deltaE, Real &mu, Real &muMin, Real &muMax, const DistSparseMatrix< Real > &HMat, const DistSparseMatrix< Real > &SMat, Int muMaxIter, Real numElectronTolerance, std::string ColPerm, Int numProcSymbFact, bool isFreeEnergyDensityMatrix, bool isEnergyDensityMatrix, bool isDerivativeTMatrix, std::vector< Real > &muList, std::vector< Real > &numElectronList, std::vector< Real > &numElectronDrvMuList, bool &isConverged)
Solve is the main subroutine for PPEXSI.
Definition: ppexsi.cpp:187
Real CalculateFreeEnergy(const DistSparseMatrix< Real > &SMat)
CalculateFreeEnergy computes the total Helmholtz free energy (band energy part only).
Definition: ppexsi.cpp:1038
Real EstimateZeroTemperatureChemicalPotential(Real temperature, Real mu, const DistSparseMatrix< Real > &SMat)
Estimate the chemical potential at zero temperature using quadratic approximation.
Definition: ppexsi.cpp:1117
Implementation of sparse matrices.
Interface subroutines of PEXSI that can be called by C.
Real CalculateTotalEnergy(const DistSparseMatrix< Real > &HMat)
CalculateTotalEnergy computes the total energy (band energy part only).
Definition: ppexsi.cpp:1012
A thin interface for the gridinfo_t strucutre in SuperLU.
Definition: superlu_dist_interf.hpp:64
void CalculateNegativeInertia(const std::vector< Real > &shiftVec, std::vector< Real > &inertiaVec, const DistSparseMatrix< Real > &HMat, const DistSparseMatrix< Real > &SMat, std::string ColPerm, Int numProcSymbFact)
Compute the negative inertia (the number of eigenvalues below a shift).
Definition: ppexsi.cpp:1147
Real CalculateNumElectronDrvT(const DistSparseMatrix< Real > &SMat)
CalculateNumElectronDrvT computes the derivative of the number of electrons with respect to the tempe...
Definition: ppexsi.cpp:976
Real CalculateNumElectron(const DistSparseMatrix< Real > &SMat)
CalculateNumElectron computes the number of electrons given the current density matrix.
Definition: ppexsi.cpp:902
Pole expansion subroutines.
void CalculateNegativeInertiaReal(const std::vector< Real > &shiftVec, std::vector< Real > &inertiaVec, const DistSparseMatrix< Real > &HMat, const DistSparseMatrix< Real > &SMat, std::string ColPerm, Int numProcSymbFact)
Compute the negative inertia (the number of eigenvalues below a shift) with real arithmetic which dir...
Definition: ppexsi_real.cpp:74