source icon indicating copy to clipboard operation
source copied to clipboard

Proposal: adaptive integration

Open MMoscheni opened this issue 2 years ago • 2 comments

Dear Raysect team,

we believe that a non-uniform/adaptive integration in InhomogeneousVolumeEmitter would be ideal to speed up the process.

The leading idea would be to allow the user to define a mathematical rule to arbitrarily space source samples along the ray direction. While the current uniform integration places samples at a constant distance step (deafult = 1 cm), an adaptive integration would allow to put more closely-spaced samples in regions of interest (e.g. close to the maximum emission), and more coarsely-spaced elsewhere (e.g. where the emission approaches its minimum / vanishes). This has been preliminarily proven to reduce the computational cost of more than a factor 10, with no associated decrease in the precision.

Quoting the wise strategy suggested by @vsnever (from this issue)

  • I think that instead of modifying the NumericalIntegrator class, it would be more correct to define a separate AdaptiveNumericalIntegrator(VolumeIntegrator) class.

  • Ideally, AdaptiveNumericalIntegrator should work with any InhomogeneousVolumeEmitter instant, and should not rely on special material methods such as step_function_3d(). Of course, the emission spectrum must be reduced to a single value in order to calculate the error required to correct the integration step. Some obvious options are the total intensity error and the maximum spectral intensity error. I think it would be nice to give the user the option to choose between several methods of spectrum reduction.

  • In NumericalIntegrator you have the loop while length_traveled < length:. The user expects that length_traveled is equal to length when integration stops, and here length_traveled can be greater than length by the value lower than step. This potentially creates the debugging hell for the user, not to mention that the end point of integration lies outside the bounding primitive.

What do you think? Thank you! Cheers, Matteo

MMoscheni avatar Jan 19 '23 09:01 MMoscheni

An expanded integration system, where materials inform the integrator what step size is appropriate is slated for version 1.0. However this is a breaking change and would require cherab's materials to be completely rewritten. The current design is unsatisfactory and not worth extending.

CnlPepper avatar Jan 29 '23 17:01 CnlPepper

See #357.

CnlPepper avatar Jan 29 '23 17:01 CnlPepper