diff --git a/src/mesh/ItemArrayUtils.hpp b/src/mesh/ItemArrayUtils.hpp index 0d90f77af27add5f08982e2be535bd7b779837a9..cb8ee339b56a3f127b3f446b7ee28970b31aa143 100644 --- a/src/mesh/ItemArrayUtils.hpp +++ b/src/mesh/ItemArrayUtils.hpp @@ -165,7 +165,7 @@ max(const ItemArray<DataType, item_type, ConnectivityPtr>& item_array) void init(data_type& value) const { - value = std::numeric_limits<data_type>::min(); + value = std::numeric_limits<data_type>::lowest(); } PUGS_INLINE diff --git a/src/mesh/ItemValueUtils.hpp b/src/mesh/ItemValueUtils.hpp index e64f2e1bdc0bc1e934aac22258461947c1c0ffd3..031caa640dbc8617ca4514c513035975451f7939 100644 --- a/src/mesh/ItemValueUtils.hpp +++ b/src/mesh/ItemValueUtils.hpp @@ -156,7 +156,7 @@ max(const ItemValue<DataType, item_type, ConnectivityPtr>& item_value) void init(data_type& value) const { - value = std::numeric_limits<data_type>::min(); + value = std::numeric_limits<data_type>::lowest(); } PUGS_INLINE diff --git a/src/mesh/SubItemArrayPerItemUtils.hpp b/src/mesh/SubItemArrayPerItemUtils.hpp index aec08ef845cc80bafd20ec8fa1a3b9bcc94415de..70b835ae3d8ff75c0fad7c9cd1b13c6cfb8ad998 100644 --- a/src/mesh/SubItemArrayPerItemUtils.hpp +++ b/src/mesh/SubItemArrayPerItemUtils.hpp @@ -170,7 +170,7 @@ max(const SubItemArrayPerItem<DataType, ItemOfItem, ConnectivityPtr>& sub_item_a void init(data_type& value) const { - value = std::numeric_limits<data_type>::min(); + value = std::numeric_limits<data_type>::lowest(); } PUGS_INLINE diff --git a/src/mesh/SubItemValuePerItemUtils.hpp b/src/mesh/SubItemValuePerItemUtils.hpp index 575c39c5238877bb064883c54b7d08792547000b..cc0c941f7f23ee5592e861d2a82a23ca07b3d0e1 100644 --- a/src/mesh/SubItemValuePerItemUtils.hpp +++ b/src/mesh/SubItemValuePerItemUtils.hpp @@ -166,7 +166,7 @@ max(const SubItemValuePerItem<DataType, ItemOfItem, ConnectivityPtr>& sub_item_v void init(data_type& value) const { - value = std::numeric_limits<data_type>::min(); + value = std::numeric_limits<data_type>::lowest(); } PUGS_INLINE diff --git a/src/utils/Array.hpp b/src/utils/Array.hpp index 2f0146e2b9d08c231eaadee7e7f50eeea439ddaf..a08453ba766450909f3bcdf0f0fd678bdb06456c 100644 --- a/src/utils/Array.hpp +++ b/src/utils/Array.hpp @@ -355,7 +355,7 @@ max(const Array<DataType>& array) void init(data_type& value) const { - value = std::numeric_limits<data_type>::min(); + value = std::numeric_limits<data_type>::lowest(); } PUGS_INLINE diff --git a/tests/test_Array.cpp b/tests/test_Array.cpp index 4a447f70a9e99151027266602763b712d00525cf..28c018cced7ac2c4a2295b1824882a7dc5b492f8 100644 --- a/tests/test_Array.cpp +++ b/tests/test_Array.cpp @@ -324,6 +324,103 @@ TEST_CASE("Array", "[utils]") } } + SECTION("checking for floating Array min/max") + { + SECTION("Min") + { + Array<double> b(10); + b[0] = 13; + b[1] = 1; + b[2] = 8; + b[3] = -3; + b[4] = 23; + b[5] = -1; + b[6] = 13; + b[7] = 0; + b[8] = 12; + b[9] = 9; + + REQUIRE(min(b) == -3); + + b.fill(0); + REQUIRE(min(b) == 0); + + b[0] = -13; + b[1] = -1; + b[2] = -8; + b[3] = -3; + b[4] = -23; + b[5] = -1; + b[6] = -13; + b[7] = 0; + b[8] = -12; + b[9] = -9; + + REQUIRE(min(b) == -23); + + b[0] = 13; + b[1] = 1; + b[2] = 8; + b[3] = 3; + b[4] = 23; + b[5] = 1; + b[6] = 13; + b[7] = 0; + b[8] = 12; + b[9] = 9; + + REQUIRE(min(b) == 0); + + b[7] = 3; + REQUIRE(min(b) == 1); + } + + SECTION("Max") + { + Array<double> b(10); + b[0] = 13; + b[1] = 1; + b[2] = 8; + b[3] = -3; + b[4] = 23; + b[5] = -1; + b[6] = 13; + b[7] = 0; + b[8] = 12; + b[9] = 9; + + REQUIRE(max(b) == 23); + + b[0] = -13; + b[1] = -12; + b[2] = -8; + b[3] = -3; + b[4] = -23; + b[5] = -1; + b[6] = -13; + b[7] = -10; + b[8] = -12; + b[9] = -9; + + REQUIRE(max(b) == -1); + + b.fill(-13); + REQUIRE(max(b) == -13); + + b[0] = 13; + b[1] = 12; + b[2] = 8; + b[3] = 3; + b[4] = 23; + b[5] = 1; + b[6] = 13; + b[7] = 10; + b[8] = 12; + b[9] = 9; + REQUIRE(max(b) == 23); + } + } + SECTION("reproducible floating point sum") { auto direct_sum = [](auto array) { diff --git a/tests/test_ItemArrayUtils.cpp b/tests/test_ItemArrayUtils.cpp index 8d04842849ed469e1cf0c1e6e217d8e1da4f01f8..0237b90da16549c30fd8b581643caec3dc287ddd 100644 --- a/tests/test_ItemArrayUtils.cpp +++ b/tests/test_ItemArrayUtils.cpp @@ -1028,6 +1028,66 @@ TEST_CASE("ItemArrayUtils", "[mesh]") } } } + + SECTION("max for negative double values") + { + std::array mesh_list = MeshDataBaseForTests::get().all3DMeshes(); + + for (const auto& named_mesh : mesh_list) { + SECTION(named_mesh.name()) + { + auto mesh_3d_v = named_mesh.mesh(); + auto mesh_3d = mesh_3d_v->get<Mesh<3>>(); + + const Connectivity<3>& connectivity = mesh_3d->connectivity(); + + CellArray<double> cell_array{connectivity, 2}; + cell_array.fill(std::numeric_limits<double>::max()); + + auto cell_is_owned = connectivity.cellIsOwned(); + parallel_for( + mesh_3d->numberOfCells(), PUGS_LAMBDA(CellId cell_id) { + if (cell_is_owned[cell_id]) { + for (size_t i = 0; i < cell_array.sizeOfArrays(); ++i) { + cell_array[cell_id][i] = -parallel::rank() - 10 + i; + } + } + }); + + REQUIRE(max(cell_array) == -parallel::size() - 10); + } + } + } + + SECTION("max for negative integral values") + { + std::array mesh_list = MeshDataBaseForTests::get().all3DMeshes(); + + for (const auto& named_mesh : mesh_list) { + SECTION(named_mesh.name()) + { + auto mesh_3d_v = named_mesh.mesh(); + auto mesh_3d = mesh_3d_v->get<Mesh<3>>(); + + const Connectivity<3>& connectivity = mesh_3d->connectivity(); + + CellArray<int> cell_array{connectivity, 2}; + cell_array.fill(std::numeric_limits<int>::max()); + + auto cell_is_owned = connectivity.cellIsOwned(); + parallel_for( + mesh_3d->numberOfCells(), PUGS_LAMBDA(CellId cell_id) { + if (cell_is_owned[cell_id]) { + for (size_t i = 0; i < cell_array.sizeOfArrays(); ++i) { + cell_array[cell_id][i] = -2 * parallel::size() + parallel::rank() - 10 + i; + } + } + }); + + REQUIRE(max(cell_array) == -static_cast<int>(parallel::size() + 10)); + } + } + } } SECTION("sum") diff --git a/tests/test_ItemValueUtils.cpp b/tests/test_ItemValueUtils.cpp index f80819f2c619709584c6574dd185d5a0e2f512fb..149dcbfa6c7c6d7976b98f21b559a03016daf857 100644 --- a/tests/test_ItemValueUtils.cpp +++ b/tests/test_ItemValueUtils.cpp @@ -240,6 +240,34 @@ TEST_CASE("ItemValueUtils", "[mesh]") } } } + + SECTION("max of all negative values") + { + std::array mesh_list = MeshDataBaseForTests::get().all3DMeshes(); + + for (const auto& named_mesh : mesh_list) { + SECTION(named_mesh.name()) + { + auto mesh_3d_v = named_mesh.mesh(); + auto mesh_3d = mesh_3d_v->get<Mesh<3>>(); + + const Connectivity<3>& connectivity = mesh_3d->connectivity(); + + CellValue<float> cell_value{connectivity}; + cell_value.fill(std::numeric_limits<float>::max()); + + auto cell_is_owned = connectivity.cellIsOwned(); + parallel_for( + mesh_3d->numberOfCells(), PUGS_LAMBDA(CellId cell_id) { + if (cell_is_owned[cell_id]) { + cell_value[cell_id] = -2 * parallel::size() + parallel::rank() + 1; + } + }); + + REQUIRE(max(cell_value) == -parallel::size()); + } + } + } } SECTION("sum") diff --git a/tests/test_SubItemArrayPerItemUtils.cpp b/tests/test_SubItemArrayPerItemUtils.cpp index 1ff8bb17f7bf170c748cfa15aa3fc82f25f4a879..ce3bb6265fd3e48a13d0505e39ddfa312bf33e2f 100644 --- a/tests/test_SubItemArrayPerItemUtils.cpp +++ b/tests/test_SubItemArrayPerItemUtils.cpp @@ -283,6 +283,39 @@ TEST_CASE("SubItemArrayPerItemUtils", "[mesh]") } } } + + SECTION("max of only negative values") + { + std::array mesh_list = MeshDataBaseForTests::get().all3DMeshes(); + + for (const auto& named_mesh : mesh_list) { + SECTION(named_mesh.name()) + { + auto mesh_3d = named_mesh.mesh()->get<Mesh<3>>(); + + const Connectivity<3>& connectivity = mesh_3d->connectivity(); + + NodeArrayPerEdge<double> node_array_per_edge{connectivity, 3}; + node_array_per_edge.fill(std::numeric_limits<double>::max()); + + auto edge_is_owned = connectivity.edgeIsOwned(); + + parallel_for( + connectivity.numberOfEdges(), PUGS_LAMBDA(EdgeId edge_id) { + if (edge_is_owned[edge_id]) { + auto edge_table = node_array_per_edge.itemTable(edge_id); + for (size_t i = 0; i < edge_table.numberOfRows(); ++i) { + for (size_t j = 0; j < edge_table.numberOfColumns(); ++j) { + edge_table(i, j) = -10. - parallel::size() + parallel::rank() - i - j; + } + } + } + }); + + REQUIRE(max(node_array_per_edge) == -11.); + } + } + } } SECTION("sum") diff --git a/tests/test_SubItemValuePerItemUtils.cpp b/tests/test_SubItemValuePerItemUtils.cpp index 69214c1c933ba6abb0c93e094317901263e70eed..fd84ad62e9dcfb1f5dd379c8f469a5b5d7e04d0d 100644 --- a/tests/test_SubItemValuePerItemUtils.cpp +++ b/tests/test_SubItemValuePerItemUtils.cpp @@ -267,6 +267,36 @@ TEST_CASE("SubItemValuePerItemUtils", "[mesh]") } } } + + SECTION("max for all negative values") + { + std::array mesh_list = MeshDataBaseForTests::get().all2DMeshes(); + + for (const auto& named_mesh : mesh_list) { + SECTION(named_mesh.name()) + { + auto mesh_2d = named_mesh.mesh()->get<Mesh<2>>(); + + const Connectivity<2>& connectivity = mesh_2d->connectivity(); + + EdgeValuePerCell<double> edge_value_per_cell{connectivity}; + edge_value_per_cell.fill(std::numeric_limits<double>::max()); + + auto cell_is_owned = connectivity.cellIsOwned(); + parallel_for( + connectivity.numberOfCells(), PUGS_LAMBDA(CellId cell_id) { + if (cell_is_owned[cell_id]) { + auto cell_array = edge_value_per_cell.itemArray(cell_id); + for (size_t i = 0; i < cell_array.size(); ++i) { + cell_array[i] = -1. * parallel::size() - 10 + parallel::rank() - i; + } + } + }); + + REQUIRE(max(edge_value_per_cell) == -11); + } + } + } } SECTION("sum")