diff --git a/src/mesh/ItemArray.hpp b/src/mesh/ItemArray.hpp index 3bd7de633659e81eb8fc178f275ee76a449048cf..0033bb24eb99e3e50739ac25a954cca808665746 100644 --- a/src/mesh/ItemArray.hpp +++ b/src/mesh/ItemArray.hpp @@ -171,6 +171,13 @@ class ItemArray return *this; } + friend std::ostream& + operator<<(std::ostream& os, const ItemArray& item_array) + { + os << item_array.m_values; + return os; + } + template <typename DataType2, typename ConnectivityPtr2> PUGS_INLINE ItemArray(const ItemArray<DataType2, item_type, ConnectivityPtr2>& array_per_item) noexcept diff --git a/src/mesh/ItemValue.hpp b/src/mesh/ItemValue.hpp index 981ebcc196d4d637d9e775231fe14edc8a70a2f2..1b888e704c530d693660fc9ced3138affe740b10 100644 --- a/src/mesh/ItemValue.hpp +++ b/src/mesh/ItemValue.hpp @@ -159,6 +159,13 @@ class ItemValue return *this; } + friend std::ostream& + operator<<(std::ostream& os, const ItemValue& item_value) + { + os << item_value.m_values; + return os; + } + template <typename DataType2, typename ConnectivityPtr2> PUGS_INLINE ItemValue(const ItemValue<DataType2, item_type, ConnectivityPtr2>& value_per_item) noexcept diff --git a/tests/test_ItemArray.cpp b/tests/test_ItemArray.cpp index 9b3b95fded76400eb5953d4a3d70f50481dadde8..cf59acf9097d36874ba81804f8862f2623e383bd 100644 --- a/tests/test_ItemArray.cpp +++ b/tests/test_ItemArray.cpp @@ -271,6 +271,27 @@ TEST_CASE("ItemArray", "[mesh]") } } + SECTION("output") + { + auto mesh = MeshDataBaseForTests::get().unordered1DMesh(); + + Table<int> table{mesh->numberOfCells(), 3}; + for (size_t i = 0; i < table.numberOfRows(); ++i) { + for (size_t j = 0; j < table.numberOfColumns(); ++j) { + table(i, j) = 2 * i + 1 + 3 * j; + } + } + + CellArray<int> cell_array{mesh->connectivity(), 3}; + cell_array = table; + + std::ostringstream table_ost; + table_ost << table; + std::ostringstream cell_array_ost; + cell_array_ost << cell_array; + REQUIRE(table_ost.str() == cell_array_ost.str()); + } + #ifndef NDEBUG SECTION("error") { diff --git a/tests/test_ItemValue.cpp b/tests/test_ItemValue.cpp index 5ec3fdb892eb5474b80381a250d1f2dc487574de..fcea4247018a69bb15855b03e45cb5f8df6e9bd6 100644 --- a/tests/test_ItemValue.cpp +++ b/tests/test_ItemValue.cpp @@ -218,6 +218,25 @@ TEST_CASE("ItemValue", "[mesh]") } } + SECTION("output") + { + auto mesh = MeshDataBaseForTests::get().unordered1DMesh(); + + Array<int> array{mesh->numberOfCells()}; + for (size_t i = 0; i < array.size(); ++i) { + array[i] = 2 * i + 1; + } + + CellValue<int> cell_value{mesh->connectivity()}; + cell_value = array; + + std::ostringstream array_ost; + array_ost << array; + std::ostringstream cell_value_ost; + cell_value_ost << cell_value; + REQUIRE(array_ost.str() == cell_value_ost.str()); + } + #ifndef NDEBUG SECTION("error") {