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

Feature: numeric gradient determination on magnetic fieldmaps with only field values #48

Merged

Conversation

wdconinc
Copy link
Contributor

This introduces numeric gradient determination (for use with adiabatic trajectories) in magnetic fieldmaps that have only field values. The gradient calculation aims to reuse as many of the regular interpolation infrastructure as possible, using the same point sets, but will be one order less in the derivative dimension (nearest neighbor therefore has no gradient).

Due to slight overlap, this uses some of the functionality in #46 (the magnetic_gradient_numerical attribute), but either should be possible to merge first.

Implementation

KMagfieldMapVTK::GetValue, in particular the implementations in KLinearInterpolationMagfieldMapVTK and KCubicInterpolationMagfieldMapVTK, takes a boolean gradient that will return the gradient instead of the value.

For the linear interpolation, _trilinearInterpolate takes an int d[] argument which contains the derivatives in each dimension (only 0 and 1 supported, for zeroth and first derivative). So, int d[3] = {0, 0, 1} will result in the z derivative, and int d[3] = {0, 1, 1} (unused) would result in the yz double derivative. Depending on which derivative is requested, this is passed to the _bilinearInterpolate or _linearInterpolate stages, as appropriate. Ultimately, the linear interpolation kernel p[1] - p[0] is used for the derivative in the requested direction, where p[0] + x * (p[1] - p[0]) is used when only the value is requested.

For the cubic interpolation, a very similar approach results in a cubic interpolation convolution kernel for the derivative that is 0.5 * (p[2] - p[0]) + 2. * x * (2. * p[0] - 5. * p[1] + 4. * p[2] - p[3] + 3. * x * (3. * (p[1] - p[2]) + p[3] - p[0])).

Tests

I verified on a fieldmap with only field value that this reproduces the output of the numerical gradient calculation in the root_magfield_painter for both linear and cubic interpolation cases. Note #47, though.

@wdconinc
Copy link
Contributor Author

Just noticed there were merge conflicts here. Merged main into branch, and conflicts resolved.

@zykure
Copy link
Member

zykure commented Apr 13, 2021

Sorry for taking so long to get back on this! I looked at your code and ran some tests, and it looks fine to me. Thanks for this convenient addition to the field map feature.

@zykure zykure merged commit bce36dc into KATRIN-Experiment:master Apr 13, 2021
@wdconinc wdconinc deleted the feature-fieldmap-numeric-gradient branch April 14, 2021 02:59
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