Skip to content

Commit

Permalink
Merge pull request #3340 from kidder/fix_filter_segfault
Browse files Browse the repository at this point in the history
Fix  segfault in test for clang12
  • Loading branch information
kidder authored Jul 7, 2021
2 parents b716732 + e6c716c commit 5edec27
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
27 changes: 20 additions & 7 deletions src/NumericalAlgorithms/LinearOperators/ExponentialFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,19 @@ Exponential<FilterIndex>::Exponential(const double alpha,
template <size_t FilterIndex>
const Matrix& Exponential<FilterIndex>::filter_matrix(const Mesh<1>& mesh) const
noexcept {
const auto cache_function = [this](
const size_t extents, const Spectral::Basis basis,
const Spectral::Quadrature quadrature) noexcept {
return Spectral::filtering::exponential_filter(
Mesh<1>{extents, basis, quadrature}, alpha_, half_power_);
};
const static double cached_alpha = alpha_;

ASSERT(cached_alpha == alpha_, "Filter was cached with alpha = "
<< cached_alpha << ", but alpha is now "
<< alpha_
<< ".\nUse a different FilterIndex if you "
"need a filter with new parameters\n");
const static double cached_half_power = half_power_;
ASSERT(cached_half_power == half_power_,
"Filter was cached with half power = "
<< cached_half_power << ", but half power is now " << half_power_
<< ".\nUse a different FilterIndex if you need a filter with new "
"parameters\n");

const static auto cache = make_static_cache<
CacheRange<1_st,
Expand All @@ -38,7 +45,13 @@ const Matrix& Exponential<FilterIndex>::filter_matrix(const Mesh<1>& mesh) const
CacheEnumeration<Spectral::Basis, Spectral::Basis::Legendre,
Spectral::Basis::Chebyshev>,
CacheEnumeration<Spectral::Quadrature, Spectral::Quadrature::Gauss,
Spectral::Quadrature::GaussLobatto>>(cache_function);
Spectral::Quadrature::GaussLobatto>>(
[alpha = alpha_, half_power = half_power_](
const size_t extents, const Spectral::Basis basis,
const Spectral::Quadrature quadrature) noexcept {
return Spectral::filtering::exponential_filter(
Mesh<1>{extents, basis, quadrature}, alpha, half_power);
});
return cache(mesh.extents(0), mesh.basis(0), mesh.quadrature(0));
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/IO/Test_H5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ SPECTRE_TEST_CASE("Unit.IO.H5.ReadData", "[Unit][IO][H5]") {
h5::write_data(group_id, std::vector<double>{1.0 / 3.0}, {},
"scalar_dataset");
CHECK(h5::read_data<0, double>(group_id, "scalar_dataset") == 1.0 / 3.0);
h5::write_data(group_id, std::vector<float>{1.0 / 3.0}, {},
h5::write_data(group_id, std::vector<float>{1.0f / 3.0f}, {},
"scalar_dataset_float");
CHECK(h5::read_data<0, float>(group_id, "scalar_dataset_float") ==
static_cast<float>(1.0 / 3.0));
Expand Down

0 comments on commit 5edec27

Please sign in to comment.