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

Add bi- and trilinear interpolation #1020

Merged
merged 3 commits into from
May 17, 2024
Merged

Add bi- and trilinear interpolation #1020

merged 3 commits into from
May 17, 2024

Conversation

pgrete
Copy link
Collaborator

@pgrete pgrete commented Mar 13, 2024

PR Summary

Add bi- and trilinear interpolation from Phoebus/Spiner.

PR Checklist

  • Code passes cpplint
  • New features are documented.
  • Adds a test for any bugs fixed. Adds tests for new features.
  • Code is formatted
  • Changes are summarized in CHANGELOG.md
  • Change is breaking (API, behavior, ...)
    • Change is additionally added to CHANGELOG.md in the breaking section
    • PR is marked as breaking
    • Short summary API changes at the top of the PR (plus optionally with an automated update/fix script)
  • CI has been triggered on Darwin for performance regression tests.
  • Docs build
  • (@lanl.gov employees) Update copyright on changed files

@pgrete
Copy link
Collaborator Author

pgrete commented Mar 13, 2024

@Yurlungur do you by chance already have a unit test stashed? I didn't find one in Phoebus and so I just want to double check before reinventing the wheel.

@pgrete pgrete added the enhancement New feature or request label Mar 13, 2024
@pgrete pgrete linked an issue Mar 13, 2024 that may be closed by this pull request
@Yurlungur
Copy link
Collaborator

@Yurlungur do you by chance already have a unit test stashed? I didn't find one in Phoebus and so I just want to double check before reinventing the wheel.

Unfortunately no... I don't think I was careful about unit testing this piece of code.

Copy link
Collaborator

@Yurlungur Yurlungur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 thanks for porting this over!

} // namespace Cent
} // namespace interpolation
} // namespace parthenon
#endif // UTILS_INTERPOLATION_HPP_
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing newline

}
} // namespace robust
} // namespace parthenon
#endif // UTILS_ROBUST_HPP_
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing newline

@Yurlungur
Copy link
Collaborator

Copy link
Collaborator

@lroberts36 lroberts36 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but see my comment about possibly removing class Interpolation. I am not sure what is actually being used though.

Comment on lines 93 to 118
class Linear : public Interpolation {
public:
KOKKOS_FUNCTION
Linear(const int n_support, const Real dx, const Real shift)
: Interpolation(n_support, dx, shift) {
PARTHENON_FAIL("Not written yet!");
}

KOKKOS_INLINE_FUNCTION
void GetIndicesAndWeights(const int i, int *idx, Real *wgt) const override {
idx[0] = std::floor(i + shift_);
idx[1] = idx[0] + 1;

wgt[0] = wgt[1] = 1. - wgt[0];

for (int nsup = 0; nsup < 2; nsup++) {
if (idx[nsup] < 0 || idx[nsup] >= n_support_) {
idx[nsup] = 0;
wgt[nsup] = 0.;
}
}
}

KOKKOS_INLINE_FUNCTION
int StencilSize() const override { return 2; }
};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like dead code given the PARTHENON_FAIL, should we just remove it (or possibly all that inherits from Interpolation and Interpolation)? To be fair, it is not really clear to me how this code is supposed to work without seeing an example.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Yurlungur what's your take at this (also in light of the following comment

// TODO(JMM): Is this interpolation::Do syntax reasonable? An
// alternative path would be a class called "LCInterp with all
// static functions. Then it could have an `operator()` which would
// be maybe nicer?
// TODO(JMM): Merge this w/ what Ben has done.
namespace Cent {
namespace Linear {

Did the current structure work out for you in Phoebus/Spiner or do you anticipate/suggest changes?
Shall this PR just provide the mininum with a potentially changing interface in the future or keep these abstraction given (expected) futures extensions?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have not needed one dimensional linear interpolation so I would remove this.

This minimal working code has worked for me in Phoebus, so I don't think there's a need to extend it or provide hooks. I would remove the dead code.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the dead code.

@Yurlungur
Copy link
Collaborator

@pgrete what's the status of this? I think it would be nice to have this merged in.

@pgrete
Copy link
Collaborator Author

pgrete commented May 9, 2024

I should be able to make the finishing touches next week. Otherwise, if you got some spare time and would like to see this earlier, feel free to go ahead.

@pgrete
Copy link
Collaborator Author

pgrete commented May 17, 2024

Pulling the trigger as discussed.

@pgrete pgrete enabled auto-merge (squash) May 17, 2024 08:52
@pgrete pgrete merged commit 25d5600 into develop May 17, 2024
49 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Interpolation in Parthenon
3 participants