Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change integration in DOS.density() to make careful integration over nonlinear meshes #67

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

aeantipov
Copy link

Hi all,

I was playing with DOS class and the HilbertTransform. To check that my dos is normalized I used DOS.density() method with mu as a big number.
Right now the integration is done in a following way ( in pytriqs/DOS/DOS.py)

de = self.eps[1]-self.eps[0]
dens = (sum(self.rho[0:ind]) - self.rho[0]/2.0 - self.rho[ind-1]/2.0) * de

A better solution is to write something like

dens = numpy.trapz( x = self.eps[0:ind], y = self.rho[0:ind] )

which I attach as a pull request.

@aeantipov
Copy link
Author

To check the results I used the following script ( A[0].eps is a logarithmic grid with several dense points ):

f=lambda x : exp(-x*x)/sqrt(pi)
G=DOS_from_function(lambda x : exp(-x*x)/sqrt(pi), xmin = -6, xmax = 6, Npts = len(A[0].eps))
val=[]
for eps in A[0].eps:
    val.append(f(eps))
G2 = DOS(eps = A[0].eps, rho = val)
print "Regular mesh     : ", G.density(10)
print "Logarithmic mesh : ", G2.density(10)

Before was:

Regular mesh    :  1.0
Logarithmic mesh :  68.0356596281

And with a patch I get

Regular mesh     :  1.0
Logarithmic mesh :  1.00002354885

@mferrero
Copy link
Member

Before pulling this in the main branch, I need to make sure the modification is OK with the rest of the framework. Here's the issue: the DOS object has mainly been created to be used with the Hilbert transform. Your correction will indeed cure the density() method when you use a non-linear mesh. However, if you were to try to compute a Hilbert transform, it would not work because a linear mesh is still expected. So I think that one should do the things right and go all the way by modifying the code so that also the Hilbert transforms works with non-linear meshes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants