PEXSI
 All Classes Namespaces Files Functions Variables Typedefs Pages
ppexsi_old.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 _PEXSI_PPEXSI_HPP_
47 #define _PEXSI_PPEXSI_HPP_
48 #include "environment.hpp"
49 #include "sparse_matrix.hpp"
50 #include "NumVec.hpp"
51 #include "utility.hpp"
52 #include "pole.hpp"
53 #include "mpi_interf.hpp"
54 #include "SuperLUGrid.hpp"
55 //#include "SuperLUOptions.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  const GridType* gridPole_; // Outer layer communicator. Also used for distributing the DistSparseMatrix. Each DistSparseMatrix is replicated in the row (numPoleGroup) direction of gridPole.
80  const GridType* gridSelInv_; // Inner layer communicator for SelInv
81  const SuperLUGrid<Complex>* zGridSuperLU_; // Inner layer communicator for SuperLU factorization
82  const SuperLUGrid<Real>* dGridSuperLU_; // Inner layer communicator for SuperLU factorization
83 
84  SuperNodeType super_; // Supernode partition
85 
86  DistSparseMatrix<Real> rhoMat_; // Density matrix
87  DistSparseMatrix<Real> rhoDrvMuMat_; // Derivative of the Fermi-Dirac with respect to mu
88  DistSparseMatrix<Real> rhoDrvTMat_; // Derivative of the Fermi-Dirac with respect to T
89  DistSparseMatrix<Real> freeEnergyDensityMat_; // Helmholtz free energy density matrix
90  DistSparseMatrix<Real> energyDensityMat_; // Energy density matrix for computing the Pulay force
91 
92  // Saves all the indices of diagonal elements in H, so that
93  // H.nzvalLocal(diagIdxLocal_[j]) are diagonal elements for all j.
94  // This is manly used when S is implicitly given as an identity matrix.
95  std::vector<Int> diagIdxLocal_;
96 
97  // *********************************************************************
98  // Member functions
99  // *********************************************************************
102  Real CalculateChemicalPotentialNewtonFD(
103  const Int iter,
104  const Real numElectronExact,
105  const Real numElectronTolerance,
106  const std::vector<Real>& muList,
107  const std::vector<Real>& numElectronList );
108 
119  Real CalculateChemicalPotentialNewtonBisection(
120  const Real numElectronExact,
121  const Real numElectron,
122  const Real numElectronDrvMu,
123  const Real mu,
124  const Real muMin,
125  const Real muMax );
126 
127  public:
128  PPEXSIData( const PEXSI::GridType* g, Int nprow, Int npcol );
129  ~PPEXSIData();
130 
175  void Solve(
176  Int numPole,
177  Real temperature,
178  Real numElectronExact,
179  Real gap,
180  Real deltaE,
181  Real& mu,
182  Real& muMin,
183  Real& muMax,
184  const DistSparseMatrix<Real>& HMat,
185  const DistSparseMatrix<Real>& SMat,
186  Int muMaxIter,
187  Real numElectronTolerance,
188  std::string ColPerm,
189  Int numProcSymbFact,
190  bool isFreeEnergyDensityMatrix,
191  bool isEnergyDensityMatrix,
192  bool isDerivativeTMatrix,
193  std::vector<Real>& muList,
194  std::vector<Real>& numElectronList,
195  std::vector<Real>& numElectronDrvMuList,
196  bool& isConverged
197  );
198 
199 
200 
202  DistSparseMatrix<Real>& DensityMatrix () { return rhoMat_; }
203 
205  DistSparseMatrix<Real>& FreeEnergyDensityMatrix () { return freeEnergyDensityMat_; }
206 
209  DistSparseMatrix<Real>& EnergyDensityMatrix() { return energyDensityMat_; }
210 
217  Real CalculateNumElectron( const DistSparseMatrix<Real>& SMat );
218 
226 
235 
242  Real CalculateTotalEnergy( const DistSparseMatrix<Real>& HMat );
243 
255  Real CalculateFreeEnergy( const DistSparseMatrix<Real>& SMat );
256 
271  Real CalculateForce(
272  const DistSparseMatrix<Real>& HDerivativeMat,
273  const DistSparseMatrix<Real>& SDerivativeMat );
274 
275 
287  Real temperature,
288  Real mu,
289  const DistSparseMatrix<Real>& SMat );
290 
291 
320  const std::vector<Real>& shiftVec,
321  std::vector<Real>& inertiaVec,
322  const DistSparseMatrix<Real>& HMat,
323  const DistSparseMatrix<Real>& SMat,
324  std::string ColPerm,
325  Int numProcSymbFact );
326 
327 
331  const std::vector<Real>& shiftVec,
332  std::vector<Real>& inertiaVec,
333  const DistSparseMatrix<Real>& HMat,
334  const DistSparseMatrix<Real>& SMat,
335  std::string ColPerm,
336  Int numProcSymbFact );
337 
369  Int method,
370  const DistSparseMatrix<Real>& HMat,
371  const DistSparseMatrix<Real>& SMat,
372  const NumVec<Real>& v0,
373  Real tol,
374  Int maxNumIter,
375  Int& numIter,
376  Real& sigma );
377  }; // PPEXSIData
378 
379 
380 } // namespace PEXSI
381 
382 #endif //_PEXSI_PPEXSI_HPP_
DistSparseMatrix< Real > & FreeEnergyDensityMatrix()
DensityMatrix returns the free energy density matrix.
Definition: ppexsi_old.hpp:205
Environmental variables.
Real CalculateNumElectronDrvMu(const DistSparseMatrix< Real > &SMat)
CalculateNumElectronDrvMu computes the derivative of the number of electrons with respect to the chem...
Definition: ppexsi_old.cpp:946
DistSparseMatrix< Real > & EnergyDensityMatrix()
DensityMatrix returns the energy density matrix for computing the force.
Definition: ppexsi_old.hpp:209
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_old.cpp:1084
DistSparseMatrix< Real > & DensityMatrix()
DensityMatrix returns the single particle density matrix.
Definition: ppexsi_old.hpp:202
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_old.cpp:1371
Interface with SuperLU_Dist (version 3.0 and later)
Main file for parallel selected inversion.
SuperLU processor grid.
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
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_old.cpp:194
Real CalculateFreeEnergy(const DistSparseMatrix< Real > &SMat)
CalculateFreeEnergy computes the total Helmholtz free energy (band energy part only).
Definition: ppexsi_old.cpp:1045
Real EstimateZeroTemperatureChemicalPotential(Real temperature, Real mu, const DistSparseMatrix< Real > &SMat)
Estimate the chemical potential at zero temperature using quadratic approximation.
Definition: ppexsi_old.cpp:1124
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_old.cpp:1019
Numerical vector.
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_old.cpp:1154
Real CalculateNumElectronDrvT(const DistSparseMatrix< Real > &SMat)
CalculateNumElectronDrvT computes the derivative of the number of electrons with respect to the tempe...
Definition: ppexsi_old.cpp:983
Real CalculateNumElectron(const DistSparseMatrix< Real > &SMat)
CalculateNumElectron computes the number of electrons given the current density matrix.
Definition: ppexsi_old.cpp:909
Pole expansion subroutines.