From 619a1f45b40bff8e5b7d4ce3af0726c6525b4f75 Mon Sep 17 00:00:00 2001 From: Lawrence Kidder Date: Wed, 30 Jun 2021 15:09:09 -0400 Subject: [PATCH 1/2] Fix segfault on my new desktop using clang 12 Add ASSERTS making sure a cached filter does not change its filtering parameters. Capture the parameters rather than capturing this. Pass the lambda directly to make_static_cache instead naming it. See Issue #3298 for more details. --- .../LinearOperators/ExponentialFilter.cpp | 27 ++++++++++++++----- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/src/NumericalAlgorithms/LinearOperators/ExponentialFilter.cpp b/src/NumericalAlgorithms/LinearOperators/ExponentialFilter.cpp index 42dde227815d..24d4028271a2 100644 --- a/src/NumericalAlgorithms/LinearOperators/ExponentialFilter.cpp +++ b/src/NumericalAlgorithms/LinearOperators/ExponentialFilter.cpp @@ -24,12 +24,19 @@ Exponential::Exponential(const double alpha, template const Matrix& Exponential::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, @@ -38,7 +45,13 @@ const Matrix& Exponential::filter_matrix(const Mesh<1>& mesh) const CacheEnumeration, CacheEnumeration>(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)); } From e6c716cd06b9e9c1f7f916997f6106b55afa7f5d Mon Sep 17 00:00:00 2001 From: Lawrence Kidder Date: Wed, 30 Jun 2021 15:35:22 -0400 Subject: [PATCH 2/2] Fix narrowing warning --- tests/Unit/IO/Test_H5.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Unit/IO/Test_H5.cpp b/tests/Unit/IO/Test_H5.cpp index 5137e85f00dd..b8573614dd1b 100644 --- a/tests/Unit/IO/Test_H5.cpp +++ b/tests/Unit/IO/Test_H5.cpp @@ -548,7 +548,7 @@ SPECTRE_TEST_CASE("Unit.IO.H5.ReadData", "[Unit][IO][H5]") { h5::write_data(group_id, std::vector{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{1.0 / 3.0}, {}, + h5::write_data(group_id, std::vector{1.0f / 3.0f}, {}, "scalar_dataset_float"); CHECK(h5::read_data<0, float>(group_id, "scalar_dataset_float") == static_cast(1.0 / 3.0));