diff --git a/tests/test_fftfreq.cpp b/tests/test_fftfreq.cpp index 642ccb6..812f959 100644 --- a/tests/test_fftfreq.cpp +++ b/tests/test_fftfreq.cpp @@ -1,117 +1,118 @@ /* * SPDX-License-Indentifier: AGPL-3.0-or-later * * Copyright (©) 2016-2023 EPFL (École Polytechnique Fédérale de Lausanne), * Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) * Copyright (©) 2020-2023 Lucas Frérot * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published * by the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . * */ /* -------------------------------------------------------------------------- */ #include "fft_engine.hh" #include "grid.hh" #include "grid_hermitian.hh" #include "grid_view.hh" #include "mpi_interface.hh" #include "partitioner.hh" #include "test.hh" #include #include #include using namespace tamaas; namespace py = pybind11; /* -------------------------------------------------------------------------- */ TEST(TestFFTEngine, Frequencies1D) { mpi::sequential_guard guard{}; - std::array sizes = {{10}}; + std::array sizes{10}; - auto freq = FFTEngine::computeFrequencies(sizes); + auto freq{FFTEngine::computeFrequencies(sizes)}; - py::module fftfreq = py::module::import("fftfreq"); + py::module fftfreq{py::module::import("fftfreq")}; std::vector reference(freq.dataSize()); - py::array py_arg(reference.size(), reference.data(), py::none()); + py::array py_arg{static_cast(reference.size()), reference.data(), + py::none()}; fftfreq.attr("frequencies1D")(py_arg); EXPECT_TRUE(compare(reference, freq, AreFloatEqual())) << "Non hermitian frequencies are wrong"; - auto hfreq = FFTEngine::computeFrequencies(sizes); + auto hfreq{FFTEngine::computeFrequencies(sizes)}; std::iota(reference.begin(), reference.end(), 0); EXPECT_TRUE(compare(reference, hfreq, AreFloatEqual())) << "Hermitian frequencies are wrong"; } /* -------------------------------------------------------------------------- */ TEST(TestFFTEngine, Frequencies2D) { - std::array sizes = {{10, 10}}; + std::array sizes{10, 10}; auto global_sizes = Partitioner<2>::global_size(sizes); - auto freq = FFTEngine::computeFrequencies(sizes); - auto hfreq = FFTEngine::computeFrequencies(sizes); - auto gathered = Partitioner<2>::gather(freq); - auto hgathered = Partitioner<2>::gather(hfreq); + auto freq{FFTEngine::computeFrequencies(sizes)}; + auto hfreq{FFTEngine::computeFrequencies(sizes)}; + auto gathered{Partitioner<2>::gather(freq)}; + auto hgathered{Partitioner<2>::gather(hfreq)}; if (mpi::rank() != 0) return; - py::module fftfreq = py::module::import("fftfreq"); + py::module fftfreq{py::module::import("fftfreq")}; std::vector reference(gathered.dataSize()); - py::array py_arg({global_sizes[0], global_sizes[1], 2u}, reference.data(), - py::none()); + py::array py_arg{ + {global_sizes[0], global_sizes[1], 2u}, reference.data(), py::none()}; fftfreq.attr("frequencies2D")(py_arg); EXPECT_TRUE(compare(reference, gathered, AreFloatEqual())) << "Non hermitian frequencies are wrong"; fftfreq.attr("hfrequencies2D")(py_arg); EXPECT_TRUE(compare(reference, hgathered, AreFloatEqual())) << "Hermitian frequencies are wrong"; } /* -------------------------------------------------------------------------- */ TEST(TestFFTEngine, RealComponents) { mpi::sequential_guard guard; - auto even_even = FFTEngine::realCoefficients<2>({{10, 10}}); - auto even_odd = FFTEngine::realCoefficients<2>({{10, 11}}); - auto odd_even = FFTEngine::realCoefficients<2>({{11, 10}}); - auto odd_odd = FFTEngine::realCoefficients<2>({{11, 11}}); + auto even_even{FFTEngine::realCoefficients<2>({{10, 10}})}; + auto even_odd{FFTEngine::realCoefficients<2>({{10, 11}})}; + auto odd_even{FFTEngine::realCoefficients<2>({{11, 10}})}; + auto odd_odd{FFTEngine::realCoefficients<2>({{11, 11}})}; - std::vector even_even_ref{{0, 0, 5, 0, 0, 5, 5, 5}}; - std::vector even_odd_ref{{0, 0, 5, 0}}; - std::vector odd_even_ref{{0, 0, 0, 5}}; - std::vector odd_odd_ref{{0, 0}}; + std::vector even_even_ref{0, 0, 5, 0, 0, 5, 5, 5}; + std::vector even_odd_ref{0, 0, 5, 0}; + std::vector odd_even_ref{0, 0, 0, 5}; + std::vector odd_odd_ref{0, 0}; auto flatten = [](auto v) { std::vector flat; for (auto&& tuple : v) for (auto i : tuple) flat.push_back(i); return flat; }; compare(flatten(even_even), even_even_ref); compare(flatten(even_odd), even_odd_ref); compare(flatten(odd_even), odd_even_ref); compare(flatten(odd_odd), odd_odd_ref); } diff --git a/tests/test_integration.cpp b/tests/test_integration.cpp index 940742d..040e6da 100644 --- a/tests/test_integration.cpp +++ b/tests/test_integration.cpp @@ -1,176 +1,176 @@ /* * SPDX-License-Indentifier: AGPL-3.0-or-later * * Copyright (©) 2016-2023 EPFL (École Polytechnique Fédérale de Lausanne), * Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) * Copyright (©) 2020-2023 Lucas Frérot * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published * by the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . * */ /* -------------------------------------------------------------------------- */ #include "fft_engine.hh" #include "integration/accumulator.hh" #include "mpi_interface.hh" #include "partitioner.hh" #include "test.hh" #include #include #include /* -------------------------------------------------------------------------- */ using namespace tamaas; namespace ex = expolit; static Real tol = 1e-13; class AccumulatorTest : public ::testing::Test { protected: void SetUp() override { nodal_values.resize(n); for (auto&& grid : nodal_values) { grid.setNbComponents(6); grid.resize(Partitioner<2>::local_size({nh, nh})); grid = 1; } accumulator.makeUniformMesh(nodal_values.size(), size); wavevectors = FFTEngine::computeFrequencies({nh, nh}); } mpi::sequential_guard guard; UInt n = 10, nh = 10; Real size = 3; std::vector> nodal_values; Grid wavevectors; Accumulator> accumulator; }; TEST_F(AccumulatorTest, uniformMesh) { - auto& pos = this->accumulator.nodePositions(); + auto& pos{this->accumulator.nodePositions()}; std::vector sol(pos.size()); std::iota(sol.begin(), sol.end(), 0); std::transform(sol.begin(), sol.end(), sol.begin(), [&](auto& x) { return size * x / (sol.size() - 1); }); ASSERT_TRUE(compare(sol, pos, AreFloatEqual())) << "Uniform mesh fail"; } // Litteral type using Q = ex::Litteral; TEST_F(AccumulatorTest, forward) { ASSERT_TRUE(compare(this->nodal_values.front().sizes(), this->wavevectors.sizes(), std::equal_to())) << "Size mismatch between nodal value and wavevectors"; // Setup for layer checking std::vector layers_seen, layers_to_see(n); std::iota(layers_to_see.begin(), layers_to_see.end(), 0); // Setup for integral checking constexpr Q q; constexpr auto z = ex::Polynomial({0, 1}); constexpr auto g0 = ex::exp(q * z); constexpr auto g1 = q * z * ex::exp(q * z); for (auto&& tuple : accumulator.forward(this->nodal_values, this->wavevectors)) { auto&& l = std::get<0>(tuple); auto&& xl_ = std::get<1>(tuple); auto&& acc_g0 = std::get<2>(tuple); auto&& acc_g1 = std::get<3>(tuple); layers_seen.push_back(l); // fundamental mode auto testing = acc_g0(0, 0, 0); EXPECT_NEAR(testing.real(), xl_, tol) << "Fundamental mode G0 fail"; testing = acc_g1(0, 0, 0); EXPECT_NEAR(testing.real(), 0, tol) << "Fundamental mode G1 fail"; // other modes testing = acc_g0(1, 0, 0); EXPECT_NEAR(testing.real(), acc_g0(0, 1, 0).real(), tol) << "Symmetry fail"; EXPECT_NEAR(testing.imag(), acc_g0(0, 1, 0).imag(), tol) << "Symmetry fail"; testing = acc_g0(1, 1, 0); Real sqrt_two = std::sqrt(Real(2)); auto ref_value = ex::definite_integral( std::pair(0, xl_), ex::substitute(ex::Constant({sqrt_two}), g0)); EXPECT_NEAR(testing.real(), ref_value, tol) << "Integration of exp(qy)*ϕ(y) fail"; testing = acc_g1(1, 1, 0); ref_value = ex::definite_integral( std::pair(0, xl_), ex::substitute(ex::Constant({sqrt_two}), g1)); EXPECT_NEAR(testing.real(), ref_value, tol) << "Integration of qy*exp(qy)*ϕ(y) fail"; } EXPECT_TRUE(compare(layers_seen, layers_to_see)) << "Did not see correct layers"; } TEST_F(AccumulatorTest, backward) { ASSERT_TRUE(compare(this->nodal_values.front().sizes(), this->wavevectors.sizes(), std::equal_to())) << "Size mismatch between nodal value and wavevectors"; // Setup for layer checking std::vector layers_seen, layers_to_see(n); std::iota(layers_to_see.rbegin(), layers_to_see.rend(), 0); // Setup for integral checking constexpr Q q; constexpr auto z = ex::Polynomial({0, 1}); constexpr auto g0 = ex::exp(q * (z * (-1))); constexpr auto g1 = q * z * ex::exp(q * ((-1) * z)); for (auto&& tuple : accumulator.backward(nodal_values, wavevectors)) { auto&& l = std::get<0>(tuple); auto&& xl_ = std::get<1>(tuple); auto&& acc_g0 = std::get<2>(tuple); auto&& acc_g1 = std::get<3>(tuple); layers_seen.push_back(l); // fundamental mode auto testing = acc_g0(0, 0, 0); EXPECT_NEAR(testing.real(), size - xl_, tol) << "Fundamental mode G0 fail"; testing = acc_g1(0, 0, 0); EXPECT_NEAR(testing.real(), 0, tol) << "Fundamental mode G1 fail"; // other modes testing = acc_g0(1, 0, 0); EXPECT_NEAR(testing.real(), acc_g0(0, 1, 0).real(), tol) << "Symmetry fail"; EXPECT_NEAR(testing.imag(), acc_g0(0, 1, 0).imag(), tol) << "Symmetry fail"; testing = acc_g0(1, 1, 0); auto ref_value = ex::definite_integral( std::make_pair(xl_, size), ex::substitute(ex::Constant({std::sqrt(2)}), g0)); EXPECT_NEAR(testing.real(), ref_value, tol) << "Integration of exp(-qy)*ϕ(y) fail"; testing = acc_g1(1, 1, 0); ref_value = ex::definite_integral( std::make_pair(xl_, size), ex::substitute(ex::Constant({std::sqrt(2)}), g1)); EXPECT_NEAR(testing.real(), ref_value, tol) << "Integration of qy*exp(-qy)*ϕ(y) fail"; } EXPECT_TRUE(compare(layers_seen, layers_to_see)) << "Did not see correct layers"; } diff --git a/tests/test_loop.cpp b/tests/test_loop.cpp index 5f54596..611fc02 100644 --- a/tests/test_loop.cpp +++ b/tests/test_loop.cpp @@ -1,401 +1,401 @@ /* * SPDX-License-Indentifier: AGPL-3.0-or-later * * Copyright (©) 2016-2023 EPFL (École Polytechnique Fédérale de Lausanne), * Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) * Copyright (©) 2020-2023 Lucas Frérot * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published * by the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . * */ /* -------------------------------------------------------------------------- */ #include "grid.hh" #include "grid_view.hh" #include "loop.hh" #include "mpi_interface.hh" #include "static_types.hh" #include "test.hh" #include /* -------------------------------------------------------------------------- */ /* WARNING: here we cannot use lambdas for tests because GoogleTest declares */ /* test functions as private members of classes which is incompatible with */ /* cuda's extended lambdas. I know... it's f*cking stupid */ /* -------------------------------------------------------------------------- */ using namespace tamaas; template struct AddOneInplace { CUDA_LAMBDA void operator()(T& x) { x += 1; } }; // Testing loops on one grid TEST(TestLoops, OneArgument) { - Grid grid({20}, 1); - Grid solution({20}, 1); + Grid grid{{20}, 1}; + Grid solution{{20}, 1}; auto add_one = [](auto x) { return x + 1; }; std::iota(grid.begin(), grid.end(), 1); // Makeing solution std::transform(grid.begin(), grid.end(), solution.begin(), add_one); - auto add_one_inplace = AddOneInplace(); + AddOneInplace add_one_inplace; Loop::loop(add_one_inplace, grid); ASSERT_TRUE(compare(grid, solution, AreFloatEqual())) << "One argument loop failed"; } struct PrimalTest { CUDA_LAMBDA void operator()(Int& primal, Int& val) { val = (primal > 0) ? -1 : 1; } }; // Testing loops on two grids TEST(TestLoops, TwoArguments) { // Why no ints? - Grid grid({20, 20}, 1); - Grid primal({20, 20}, 1); - Grid solution({20, 20}, 1); + Grid grid{{20, 20}, 1}; + Grid primal{{20, 20}, 1}; + Grid solution{{20, 20}, 1}; primal(0, 0) = 1; primal(0, 1) = 1; primal(1, 0) = 1; primal(1, 1) = 1; std::transform(primal.begin(), primal.end(), solution.begin(), [](Int& primal) { return (primal > 0) ? -1 : 1; }); - auto primal_test = PrimalTest(); + PrimalTest primal_test; Loop::loop(primal_test, primal, grid); ASSERT_TRUE(compare(solution, grid)) << "Two argument loop failed"; } struct AssignUInt { CUDA_LAMBDA void operator()(UInt& x, UInt i) { x = i; } }; // Testing an enumeration TEST(TestLoops, Enumeration) { - Grid grid({100}, 1); - Grid solution({100}, 1); + Grid grid{{100}, 1}; + Grid solution{{100}, 1}; std::iota(solution.begin(), solution.end(), 0); - auto assign_uint = AssignUInt(); + AssignUInt assign_uint; Loop::loop(assign_uint, grid, Loop::range(100)); ASSERT_TRUE(compare(solution, grid)) << "Enumeration loop failed"; } /* -------------------------------------------------------------------------- */ struct Identity { CUDA_LAMBDA UInt operator()(UInt& x) const { return x; } }; // Testing one grid reductions TEST(TestReductions, OneArgument) { - Grid grid({6}, 1); + Grid grid{{6}, 1}; std::iota(grid.begin(), grid.end(), 1); - const auto id = Identity(); + const Identity id; // Sum reduction UInt sol = mpi::allreduce( std::accumulate(grid.begin(), grid.end(), 0, std::plus<>())); UInt red = Loop::reduce(id, grid); ASSERT_TRUE(sol == red) << "Addition reduction failed on one argument"; // Product reduction sol = mpi::allreduce( std::accumulate(grid.begin(), grid.end(), 1, std::multiplies<>())); red = Loop::reduce(id, grid); ASSERT_TRUE(sol == red) << "Multiplication reduction failed on one argument"; // Min reduction sol = mpi::allreduce( *std::min_element(grid.begin(), grid.end())); red = Loop::reduce(id, grid); ASSERT_TRUE(sol == red) << "Min reduction failed on one argument"; // Max reduction sol = mpi::allreduce( *std::max_element(grid.begin(), grid.end())); red = Loop::reduce(id, grid); ASSERT_TRUE(sol == red) << "Max reduction failed on one argument"; } struct AssignReduce { CUDA_LAMBDA UInt operator()(UInt& x, UInt i) { x = i; return x; } }; TEST(TestReductions, ReduceAndTransform) { UInt n = 20; - Grid grid({n}, 1), solution({n}, 1); + Grid grid{{n}, 1}, solution{{n}, 1}; std::iota(solution.begin(), solution.end(), 0); UInt sum_value = mpi::allreduce((n - 1) * n / 2); - auto assign_reduce = AssignReduce{}; + AssignReduce assign_reduce; UInt res = Loop::reduce(assign_reduce, grid, Loop::range(n)); EXPECT_EQ(res, sum_value) << "Reduction failed"; EXPECT_TRUE(compare(grid, solution)) << "Assign failed"; } struct PrimalReduce { CUDA_LAMBDA UInt operator()(UInt& p, UInt& val) { return (p > 0) ? val : 0; } }; TEST(TestReductions, TwoArguments) { - Grid grid({20}, 1); - Grid primal({20}, 1); + Grid grid{{20}, 1}; + Grid primal{{20}, 1}; grid = 1; primal(0) = 1; primal(1) = 1; - auto primal_reduce = PrimalReduce(); + PrimalReduce primal_reduce; // Reduce on values where primal > 0 UInt red = Loop::reduce(primal_reduce, primal, grid); ASSERT_TRUE(red == mpi::allreduce(UInt{2})) << "Two args reduction failed"; } /* -------------------------------------------------------------------------- */ TEST(TestRange, type_trait) { - Grid grid({1}, 1); + Grid grid{{1}, 1}; auto gridrange = range>(grid); static_assert(decltype(gridrange)::is_valid_container>::value, "is_valid_container Type trait is wrong"); static_assert( not decltype(gridrange)::is_valid_container&>::value, "is_valid_container Type trait is wrong"); static_assert(not Range, Real, 1>::is_valid_container::value, "is_valid_container Type trait is wrong"); } struct AssignOne { CUDA_LAMBDA void operator()(VectorProxy x) { x = 1; } CUDA_LAMBDA void operator()(UInt& x) { x = 1; } CUDA_LAMBDA void operator()(VectorProxy v) { v(2) = 1; } CUDA_LAMBDA void operator()(VectorProxy v) { v = 1; } }; TEST(TestRange, headless) { if (mpi::rank() != 0) GTEST_SKIP() << "Skipping because not root process"; - Grid grid({10}, 1), solution({10}, 1); + Grid grid{{10}, 1}, solution{{10}, 1}; std::fill(++solution.begin(), solution.end(), 1); auto gridrange = range>(grid).headless(); - auto assign_one = AssignOne{}; + AssignOne assign_one; Loop::loop(assign_one, gridrange); ASSERT_TRUE(compare(grid, solution)) << "Headless fail"; } template using WrapVector = VectorProxy; struct AddOneVector { CUDA_LAMBDA void operator()(WrapVector x) { x(0) += 1; } }; TEST(TestStridedLoops, VectorStride) { - Grid grid({10, 10}, 2); + Grid grid{{10, 10}, 2}; std::iota(grid.begin(), grid.end(), 1); - Grid solution({10, 10}, 2); + Grid solution{{10, 10}, 2}; solution = grid; std::for_each(solution.begin(), solution.end(), [](UInt& x) { if (x % 2 == 1) x += 1; }); - auto add_one_inplace = AddOneVector(); + AddOneVector add_one_inplace; Loop::loop(add_one_inplace, range>(grid)); ASSERT_TRUE(compare(solution, grid)) << "Static vector strided loop failed"; } template using WrapMatrix = MatrixProxy; struct SetOneMatrix { CUDA_LAMBDA void operator()(WrapMatrix x) { x(0, 0) = 1; x(1, 1) = 1; } }; TEST(TestStridedLoops, MatrixStride) { - Grid grid({10, 10}, 4); - Grid solution({10, 10}, 4); + Grid grid{{10, 10}, 4}; + Grid solution{{10, 10}, 4}; std::iota(solution.begin(), solution.end(), 0); std::for_each(solution.begin(), solution.end(), [](UInt& x) { if (x % 4 == 0 || x % 4 == 3) x = 1; else x = 0; }); - auto set_one = SetOneMatrix(); + SetOneMatrix set_one; Loop::loop(set_one, range>(grid)); ASSERT_TRUE(compare(solution, grid)) << "Static matrix strided loop failed"; } struct VectorReduction { CUDA_LAMBDA Vector operator()(const VectorProxy& v) const { return v; } }; struct BroadcastSet123 { CUDA_LAMBDA inline void operator()(VectorProxy v) const { v(0) = 1; v(1) = 2; v(2) = 3; } }; TEST(TestStridedReduction, VectorReduce) { - Grid grid({10, 10}, 3); + Grid grid{{10, 10}, 3}; - Loop::loop(BroadcastSet123(), range>(grid)); + Loop::loop(BroadcastSet123{}, range>(grid)); auto res = Loop::reduce(VectorReduction(), range>(grid)); auto reduce = [](UInt x) { return mpi::allreduce(x); }; ASSERT_EQ(res(0), reduce(100)); ASSERT_EQ(res(1), reduce(200)); ASSERT_EQ(res(2), reduce(300)); } struct ScalarReduce { CUDA_LAMBDA UInt operator()(UInt& x) { return x; } }; TEST(TestViewReduction, ScalarReduce) { - Grid grid({10, 10}, 3); - Loop::loop(BroadcastSet123(), range>(grid)); + Grid grid{{10, 10}, 3}; + Loop::loop(BroadcastSet123{}, range>(grid)); auto view = make_component_view(grid, 2); - auto scalar_reduce = ScalarReduce{}; + ScalarReduce scalar_reduce; UInt res = Loop::reduce(scalar_reduce, view); EXPECT_EQ(res, mpi::allreduce(UInt{300})) << "Reduce on component view fail"; } TEST(TestViewReduction, VectorReduce) { - Grid grid({10, 10}, 3); + Grid grid{{10, 10}, 3}; auto view2 = make_view(grid, 0); - Loop::loop(BroadcastSet123(), range>(view2)); + Loop::loop(BroadcastSet123{}, range>(view2)); - auto res2 = Loop::reduce(VectorReduction(), + auto res2 = Loop::reduce(VectorReduction{}, range>(view2)); auto reduce = [](UInt x) { return mpi::allreduce(x); }; EXPECT_EQ(res2(0), reduce(10)); EXPECT_EQ(res2(1), reduce(20)); EXPECT_EQ(res2(2), reduce(30)); } TEST(TestViewLoop, ScalarLoop) { - Grid grid({10, 10}, 3), solution({10, 10}, 3); + Grid grid{{10, 10}, 3}, solution{{10, 10}, 3}; auto view = make_component_view(grid, 2); - auto assign_one = AssignOne{}; + AssignOne assign_one; Loop::loop(assign_one, view); Loop::loop(assign_one, range>(solution)); ASSERT_TRUE(compare(grid, solution)) << "View loop fail"; } TEST(TestLoopChecks, Components) { - Grid grid({10, 10}, 3); + Grid grid{{10, 10}, 3}; - auto assign_one = AssignOne(); + AssignOne assign_one; EXPECT_THROW(Loop::loop(assign_one, range>(grid)), std::length_error) << "Broken check on number of components"; } struct CopyValues { CUDA_LAMBDA auto operator()(UInt& x, UInt& y) { x = y; } CUDA_LAMBDA auto operator()(VectorProxy x, VectorProxy y) { x(0) = y(0); } }; TEST(TestLoopChecks, LoopSize) { - Grid grid({10}, 2), other({10}, 1); + Grid grid{{10}, 2}, other{{10}, 1}; CopyValues func; EXPECT_THROW(Loop::loop(func, grid, other), std::length_error) << "Check on loop size without ranges fail"; other.resize({11}); EXPECT_THROW(Loop::loop(func, range>(grid), range>(other)), std::length_error) << "Check on loop size with ranges fail"; - Grid twod({10, 11}, 2); + Grid twod{{10, 11}, 2}; auto view = make_view(twod, 0); EXPECT_THROW(Loop::loop(func, grid, view), std::length_error) << "Check on loop size with view fail"; } struct ReduceAndTransform { CUDA_LAMBDA UInt operator()(VectorProxy x, UInt /*i*/) { x += 1; return x(0) + x(1); } }; TEST(TestReductions, ReduceAndTransformVector) { UInt n = 20; - Grid grid({n}, 2), solution({n}, 2); + Grid grid{{n}, 2}, solution{{n}, 2}; std::iota(solution.begin(), solution.end(), 1); std::iota(grid.begin(), grid.end(), 0); UInt sum_value = mpi::allreduce((2 * n + 1) * 2 * n / 2); - auto reduce_transform = ReduceAndTransform(); + ReduceAndTransform reduce_transform; UInt res = Loop::reduce( reduce_transform, range>(grid), Loop::range(n)); EXPECT_EQ(res, sum_value) << "Reduction failed"; EXPECT_TRUE(compare(grid, solution)) << "Assign failed"; } diff --git a/tests/test_rough_surface.cpp b/tests/test_rough_surface.cpp index a0bdef4..0922fa6 100644 --- a/tests/test_rough_surface.cpp +++ b/tests/test_rough_surface.cpp @@ -1,82 +1,81 @@ /* * SPDX-License-Indentifier: AGPL-3.0-or-later * * Copyright (©) 2016-2023 EPFL (École Polytechnique Fédérale de Lausanne), * Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) * Copyright (©) 2020-2023 Lucas Frérot * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published * by the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . * */ /* -------------------------------------------------------------------------- */ -#include "tamaas.hh" #include "isopowerlaw.hh" -#include "surface_generator_filter.hh" -#include "polonsky_keer_rey.hh" #include "model_factory.hh" +#include "polonsky_keer_rey.hh" +#include "surface_generator_filter.hh" +#include "tamaas.hh" /* -------------------------------------------------------------------------- */ using namespace tamaas; int main() { /// Surface parameters UInt grid_size = 512; const UInt k0 = 4, k1 = 4, k2 = 32; const Real hurst = 0.8; /// Surface generation (2D) SurfaceGeneratorFilter<2> sg; - sg.setSizes({{grid_size, grid_size}}); - sg.setRandomSeed(0); + sg.setSizes({grid_size, grid_size}); + sg.setRandomSeed(1); - auto iso = std::make_shared>(); + auto iso{std::make_unique>()}; iso->setQ0(k0); iso->setQ1(k1); iso->setQ2(k2); iso->setHurst(hurst); - sg.setSpectrum(iso); + sg.setSpectrum(std::move(iso)); std::cout << "Building rough surface with properties\n" - << " Q0 = " << k0 << '\n' - << " Q1 = " << k1 << '\n' - << " Q2 = " << k2 << '\n' - << " Hurst = " << hurst << '\n' - << " size = " << grid_size << 'x' << grid_size << std::endl; + << " Q0 = " << k0 << '\n' + << " Q1 = " << k1 << '\n' + << " Q2 = " << k2 << '\n' + << " Hurst = " << hurst << '\n' + << " size = " << grid_size << 'x' << grid_size << std::endl; /// Making surface - GridBase & grid = sg.buildSurface(); + auto& grid = sg.buildSurface(); std::cout << "Creating model" << std::endl; /// Model initialization - std::unique_ptr model{ModelFactory::createModel( - model_type::basic_2d, {1., 1.}, {grid_size, grid_size})}; + auto model{ModelFactory::createModel(model_type::basic_2d, {1., 1.}, + {grid_size, grid_size})}; Real load = 0.1; Real precision = 1e-12; std::cout << "Solving contact problem" << std::endl; /// Solve normal contact problem PolonskyKeerRey solver{*model, grid, precision, PolonskyKeerRey::pressure, PolonskyKeerRey::pressure}; solver.solve(load); std::cout << "Finished" << std::endl; - - return EXIT_SUCCESS; + return 0; } diff --git a/tests/test_static_types.cpp b/tests/test_static_types.cpp index 0165382..a5fc30c 100644 --- a/tests/test_static_types.cpp +++ b/tests/test_static_types.cpp @@ -1,107 +1,107 @@ /* * SPDX-License-Indentifier: AGPL-3.0-or-later * * Copyright (©) 2016-2023 EPFL (École Polytechnique Fédérale de Lausanne), * Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) * Copyright (©) 2020-2023 Lucas Frérot * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published * by the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . * */ /* -------------------------------------------------------------------------- */ #include "static_types.hh" #include "test.hh" using namespace tamaas; /* -------------------------------------------------------------------------- */ TEST(TestStaticTypes, GEMV) { - Matrix A({1, 2, 3, 4, 5, 6, 7, 8, 9}); + Matrix A{{1, 2, 3, 4, 5, 6, 7, 8, 9}}; UInt b_[] = {1, 2, 3}; - VectorProxy b(b_); + VectorProxy b{b_}; auto res = A * b; - std::vector solution = {14, 32, 50}; + std::vector solution{14, 32, 50}; ASSERT_TRUE(compare(res, solution)) << "Matrix multiplication fail"; } TEST(TestStaticTypes, Dot) { UInt a_[] = {2, 3}; UInt b_[] = {1, 5}; - VectorProxy a(a_[0]), b(b_[0]); + VectorProxy a{a_[0]}, b{b_[0]}; ASSERT_EQ(a.dot(b), 17) << "Dot product fail"; } TEST(TestStaticTypes, Norm) { Real a_[] = {3., 4.}; - VectorProxy a(a_[0]); + VectorProxy a{a_[0]}; ASSERT_DOUBLE_EQ(a.l2norm(), 5) << "L2 norm fail"; } TEST(TestStaticTypes, Symmetrization2D) { - Matrix A({1, 2, 3, 4}); - Vector Av({1, 4, std::sqrt(2) * 2.5}); + Matrix A{{1, 2, 3, 4}}; + Vector Av{{1, 4, std::sqrt(2) * 2.5}}; SymMatrix As; As.symmetrize(A); ASSERT_TRUE(compare(Av, As, AreFloatEqual())) << "Symmetrization fail"; - Matrix B, Bref({1, 2.5, 2.5, 4}); + Matrix B, Bref{{1, 2.5, 2.5, 4}}; B.fromSymmetric(As); ASSERT_TRUE(compare(Bref, B, AreFloatEqual())) << "Dense construction fail"; } TEST(TestStaticTypes, Symmetrization3D) { - Matrix A({1, 2, 3, 4, 5, 6, 7, 8, 9}); - Vector Av( - {1, 5, 9, std::sqrt(2) * 7, std::sqrt(2) * 5, std::sqrt(2) * 3}); + Matrix A{{1, 2, 3, 4, 5, 6, 7, 8, 9}}; + Vector Av{ + {1, 5, 9, std::sqrt(2) * 7, std::sqrt(2) * 5, std::sqrt(2) * 3}}; SymMatrix As; As.symmetrize(A); ASSERT_TRUE(compare(Av, As, AreFloatEqual())) << "Symmetrization fail"; - Matrix B, Bref({1, 3, 5, 3, 5, 7, 5, 7, 9}); + Matrix B, Bref{{1, 3, 5, 3, 5, 7, 5, 7, 9}}; B.fromSymmetric(As); ASSERT_TRUE(compare(Bref, B, AreFloatEqual())) << "Dense construction fail"; } TEST(TestStaticTypes, Invariants) { - SymMatrix Av( - {1, 5, 9, std::sqrt(2) * 7, std::sqrt(2) * 5, std::sqrt(2) * 4}); + SymMatrix Av{ + {1, 5, 9, std::sqrt(2) * 7, std::sqrt(2) * 5, std::sqrt(2) * 4}}; auto invar = invariants(Av); Matrix B; B.fromSymmetric(Av); auto B2 = B * B; Vector sol; sol(0) = B.trace(); sol(1) = 0.5 * (B.trace() * B.trace() - B2.trace()); sol(2) = 7; ASSERT_TRUE(compare(invar, sol, AreFloatEqual{1e-14})) << "Invariants fail"; } TEST(TestStaticTypes, Eigenvalues) { - SymMatrix Av({2, 3, 9, std::sqrt(2) * 4, 0, 0}); + SymMatrix Av{{2, 3, 9, std::sqrt(2) * 4, 0, 0}}; auto eigen = eigenvalues(Av); // invariants Vector sol; sol(0) = 1; sol(1) = 2; sol(2) = 11; ASSERT_TRUE(compare(eigen, sol, AreFloatEqual{1e-14})) << "Eigenvalues do not reproduce invariants"; }