rodluger / Limbdark.jl

Analytical transit light curves for limb darkened stars
MIT License
14 stars 4 forks source link

Conserving on computing square roots and divisions #51

Closed ericagol closed 5 years ago

ericagol commented 5 years ago

The s_2 function has several calculations that are already done in the main code; several of these involve divisions and square roots. I would like to conserve on computing these, and am wondering, @rodluger , if this is something you have done in starry. Some examples are:

k^2 = (1-(r-b)^2)/(4*b*r)
sqrt(1-r^2)
k_c = sqrt(1-k^2)
sqrt(1-(r-b)^2)

etc.

I could include all of these as variables in my Transit_Struct object, and just pass the object (which passes by reference/pointer) to the s_2 routine. Or I could pass the individual variables. But, I'm wondering if there is a more clever/elegant way to do this in which the two routines could share the variables and the computation.

rodluger commented 5 years ago

@ericagol In C++ my flux-computing routines are actually class methods, so they always have access to the class variables (which include the variables you listed up top). So I never have to explicitly "pass" any of these to the functions. I don't know if it works the same way in julia, but passing the struct by reference to each function should be totally fine speed-wise.

ericagol commented 5 years ago

I tried to implement this today, but there are some bugs occurring at boundary cases which I haven't tracked down yet. And, the speed improvement is not significant (although that could be due to bugs). This also makes the code a bit more difficult to read.

ericagol commented 5 years ago

I'm closing this for now; I can't seem to find the bug that's occurring, but the problem seems to be that df/dr and df/db become zero for small values of b. This does not occur when I use the original version of s_2, but what is strange is that s_2 seems to be computed correctly, as well as its gradients.