Skip to content
Snippets Groups Projects
Commit 94b47e42 authored by Stéphane Del Pino's avatar Stéphane Del Pino
Browse files

Support for output of ItemValue and ItemArray on ostream

- Beware that this only prints values on the printing processor in
parallel (rank 0 processor by now).

- Could also have added SubItem{Value,Array}PerItem outputs and
DiscreteFunctionP0, but it remains unclear to me if this development
is really relevant, due to the parallel defect of this
functionality. In the case of DiscreteFunctionP0, one can use the
DiscreteFunctionP0::cellValues() function to print values.
parent ab37cf64
No related branches found
No related tags found
1 merge request!130Support for output of ItemValue and ItemArray on ostream
...@@ -171,6 +171,13 @@ class ItemArray ...@@ -171,6 +171,13 @@ class ItemArray
return *this; 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> template <typename DataType2, typename ConnectivityPtr2>
PUGS_INLINE PUGS_INLINE
ItemArray(const ItemArray<DataType2, item_type, ConnectivityPtr2>& array_per_item) noexcept ItemArray(const ItemArray<DataType2, item_type, ConnectivityPtr2>& array_per_item) noexcept
......
...@@ -159,6 +159,13 @@ class ItemValue ...@@ -159,6 +159,13 @@ class ItemValue
return *this; 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> template <typename DataType2, typename ConnectivityPtr2>
PUGS_INLINE PUGS_INLINE
ItemValue(const ItemValue<DataType2, item_type, ConnectivityPtr2>& value_per_item) noexcept ItemValue(const ItemValue<DataType2, item_type, ConnectivityPtr2>& value_per_item) noexcept
......
...@@ -271,6 +271,27 @@ TEST_CASE("ItemArray", "[mesh]") ...@@ -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 #ifndef NDEBUG
SECTION("error") SECTION("error")
{ {
......
...@@ -218,6 +218,25 @@ TEST_CASE("ItemValue", "[mesh]") ...@@ -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 #ifndef NDEBUG
SECTION("error") SECTION("error")
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment