-
Notifications
You must be signed in to change notification settings - Fork 1
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
Tmfp #12
base: master
Are you sure you want to change the base?
Tmfp #12
Conversation
We are really calculating the inelastic imfp twice, which seems kind of pointless... but I suppose it fits in with the philosophy of cstool-is-a-library-not-an-application. Anyway, I do have a few points:
|
Also, just a general thing: why do we always use 129 values along the energy axis? If it's just an arbitrary choice, why not pick a round number? |
"dv1" is not really an acronym. The "1" is because it is a first attempt. The D is probably for Delft, and the V could perhaps mean "Version".
I have resolved all the comments on the code, please check this. I do not know why we always use 129 values along the energy axis. Maybe @kerimarat or @slokhorst know? |
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.
OK, I did a more line-by-line style review here. These are mostly style-related suggestions, but in some cases I suggest a significantly different program flow. Do as you wish though, these are just opinions.
tmprange[i] = 1/tcs | ||
for j, omega in enumerate(e_ran): | ||
if (omega < K/2 and omega < K-s.band_structure.fermi): | ||
if j==0: |
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.
This may be more of a personal opinion, but I would prefer omega_old = 0 if j==0 else e_ran[j-1]
here. These ternary operators tend to lead to excessively long lines, so one should be careful with them, but I think this is a case where it helps the code clarity.
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.
Same here.
s.elf_file.get_min_energy_interval()) | ||
tmprange[i] = 1/tcs | ||
for j, omega in enumerate(e_ran): | ||
if (omega < K/2 and omega < K-s.band_structure.fermi): |
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.
I would suggest the following:
if omega >= K/2 or omega >= K - s.band_structure.fermi:
break
and no else clause for the actual code. This pattern is pretty common.
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.
Again, this comment is mostly related to the code that comes after it.
tmprange = np.zeros(e_ran.shape) * units.m | ||
print("# Computing inelastic electron range.") | ||
for i, K in enumerate(e_ran): | ||
ran_energies[i] = K.to('eV') |
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 this? Does supplying data=e_ran.to('eV')
in line 217 not already do this?
if ( K >= s.band_structure.barrier): | ||
# make sure the tmfp is monotonously increasing for energies above | ||
# the vacuum potential barrier | ||
if (tmfp < tmfpmax): |
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.
Suggestion: tmfpmax = np.maximum(tmfp_max, tmfp)
instead of these four lines and change line 239 to ran_tmfp[i] = tmfp_max
.
So do not change the tmfp
variable, conceptually it will always hold the tmfp for the current kinetic energy. Meanwhile, tmfp_max
is the largest one you have found (bar anything below the vacuum barrier), and you make it clear that that's what you want to write to ran_tmfp
.
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.
"These four lines" relates to the line I commented on and the three lines BELOW it. github doesn't allow for multiline comments, sorry for the confusion.
@@ -23,6 +24,12 @@ def integrant(theta): | |||
|
|||
return compute_tcs_icdf(integrant, 0*units('rad'), np.pi*units('rad'), P) | |||
|
|||
def compute_elastic_tcs(dcs, P): | |||
def integrant(theta): |
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.
I agree with you that we should be consistent in spelling "integrand" incorrectly.
@@ -6,6 +6,7 @@ | |||
from cstool.phonon import phonon_cs_fn | |||
from cstool.inelastic import inelastic_cs_fn | |||
from cstool.compile import compute_tcs_icdf | |||
from cstool.compile import compute_tcs |
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.
These two lines can be merged in one. Would make it more consistent with the other imports.
def compute_tcs(f, a, b, P, sampling=100000): | ||
x = np.linspace(a, b.to(a.units), sampling) * a.units | ||
y = f(x) | ||
cf = np.r_[0, np.cumsum((x[1:] - x[:-1]) * (y[:-1] + y[1:]) / 2.0)] |
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.
You are still storing all intermediate integration results here, while you only need the last. Actually, since this is simply an n-point trapezoid rule, you could just return np.trapz(y, x)
here -- shorter, intent is clear, and probably faster.
As for using 129 values, looking at the commit history it seems to have been introduced by @jhidding. |
The 129 energy values are just a random choice I think. In e-scatter, we use 1024 values, so I guess it would make sense to match that here. |
At least 1024 is a round number. That lets me sleep better than 129. As the lower energy bounds are different between cstool and e-scatter, there is no point in using 1024 here to "match" e-scatter. But I think we will all agree that cstool should provide at least the resolution that our simulator intends to use. Anyway, we're getting a bit off-topic here. |
Don't forget to fix #13 before/after merge |
Absolutely, thanks for creating that issue. If nobody else fixes it, I'll do it as soon as I get back. It's independent from the tmfp thing though. |
Historical reference: The 129 was probably chosen as (128 + 1), creating more or less round numbers, since the end-point of the interval is also included in the range. |
Merge branch tmfp to master in order to implement the calculation of the electron range used in Geant4.