-
Notifications
You must be signed in to change notification settings - Fork 26
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
Hilbert transform #157
Hilbert transform #157
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dear Dwaipayan,
Thanks for the pull request. I left some comments. When possible, please take a look.
Best,
Nakib
src/screening.f90
Outdated
@@ -127,6 +127,65 @@ subroutine calculate_Hilbert_weights(w_disc, w_cont, zeroplus, Hilbert_weights) | |||
end do | |||
end subroutine calculate_Hilbert_weights | |||
|
|||
subroutine hilbert_transform(Reeps_T, Omegas, spec_eps_T) | |||
!! EQ (4), R. Balito et. al. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add meaningful comment.
src/screening.f90
Outdated
@@ -127,6 +127,65 @@ subroutine calculate_Hilbert_weights(w_disc, w_cont, zeroplus, Hilbert_weights) | |||
end do | |||
end subroutine calculate_Hilbert_weights | |||
|
|||
subroutine hilbert_transform(Reeps_T, Omegas, spec_eps_T) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Write Hilbert instead of hilbert.
src/screening.f90
Outdated
real(r64) :: in1, in2, fin, bl !, domegas | ||
integer(i64) :: nx, kh, np |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use meaningful names for variables unless you are staying consistent with the notation used in the reference paper's equation(s).
src/screening.f90
Outdated
in1=0.0_r64 | ||
in2=0.0_r64 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use space on both sides of =
, here and elsewhere.
src/screening.f90
Outdated
in1=0.0_r64 | ||
in2=0.0_r64 | ||
do np=1,nx-1-kh | ||
bl = log(real(np+1.0_r64)/real(np)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add space around =
, +
, and -
, but not around *
and /
.
src/screening.f90
Outdated
in2=0.0_r64 | ||
do np=1,nx-1-kh | ||
bl = log(real(np+1.0_r64)/real(np)) | ||
if ( (kh+np).lt.nx) then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use <
instead of .lt.
.
src/screening.f90
Outdated
|
||
do np=1,kh-1 | ||
bl = log(real(np+1.0_r64)/real(np)) | ||
if ((kh-np).gt.1) then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use >
instead of .gt.
.
src/screening.f90
Outdated
if (kh.ge.2 .and. kh.le.(nx-1)) then | ||
fin = spec_eps_T(kh+1)-spec_eps_T(kh-1) | ||
else | ||
fin = 1e-12_r64 | ||
end if |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use proper indentation. For example, the else
and end if
should start at the same level of indentation as if
. In a decent editor (like emacs), selecting a region and pressing TAB fixes all indentation issues. Perhaps your editor is also decent like that...
src/screening.f90
Outdated
fin = 1e-12_r64 | ||
end if | ||
Reeps_T(kh) = (-1.0_r64/pi)*(fin+in1+in2) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this empty space.
src/screening.f90
Outdated
Reeps_T(kh) = (-1.0_r64/pi)*(fin+in1+in2) | ||
|
||
end do | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this empty space.
src/screening.f90
Outdated
in1=0.0_r64 | ||
in2=0.0_r64 | ||
do np=1,nx-1-kh | ||
bl = log(real(np+1.0_r64)/real(np)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you write np + 1.0_r64
, do you have to wrap further with real
? What does real
do? Does it respect the precision you are seeking? Also, does the np
in the denominator have to be wrapped by real
since writing the numerator as (np + 1.0_r64)
already makes it a r64
type number.
src/screening.f90
Outdated
in2=0.0_r64 | ||
do np=1,nx-1-kh | ||
bl = log(real(np+1.0_r64)/real(np)) | ||
if ( (kh+np).lt.nx) then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to add comments explaining the reasoning for these conditionals. You should do this unless it is absolutely obvious from the context.
src/screening.f90
Outdated
|
||
end do | ||
|
||
end subroutine hilbert_transform |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hilbert -> Hilbert
src/screening.f90
Outdated
end if | ||
end do | ||
|
||
if (kh.ge.2 .and. kh.le.(nx-1)) then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Write >=
and <=
instead of .ge.
and .le.
, respectively.
src/screening.f90
Outdated
in2=0.0_r64 | ||
do np=1,nx-1-kh | ||
bl = log(real(np+1.0_r64)/real(np)) | ||
if ( (kh+np).lt.nx) then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Write if((kh + np) < nx)
instead of if ( (kh+np).lt.nx)
. Fix similar issues elsewhere. There should not be randomly inserted spaces. We should try to stick to a consistent style.
src/screening.f90
Outdated
else | ||
!print *,"Hilbert transform: Boundary breached",kh+np,nx | ||
in1 = in1 - (1.0_r64-(np+1.0_r64)*bl)*spec_eps_T(kh+np) + & | ||
(1.0_r64-np*bl)*1e-12_r64 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this magic 1e-12_r64
? If it is supposed to be a small number, define above as a parameter
along with a reference to the equation where it appears. The same number appears below again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the changes. A few more minor comments.
Best,
Nakib
end do | ||
|
||
! To avoid edge error | ||
if (kh >= 2 .and. kh <= (nOmegas-1)) then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Space missing around -
. But I'll fix it after merging.
do nh = 1, kh - 1 | ||
bh = log((nh + 1.0_r64)/nh) | ||
! To avoid edge error in the lower limit | ||
if ((kh - nh) > 1) then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is there a space after if
? I don't think this done anywhere else in this code base.
! For outside the boundary | ||
diff = smalln | ||
end if | ||
Reeps_T(kh) = (-1.0_r64/pi)*(diff + sum1 + sum2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is sufficient to write -1.0_r64/pi*(...)
. The brackets are unnecessary. Fortran understands the usual order of arithmetic.
Implemented Hilbert transform using the numerical method from R. Balito et. al. Eq(4).