Skip to content
Snippets Groups Projects
Unverified Commit c26b8d39 authored by Tobias Leibner's avatar Tobias Leibner Committed by GitHub
Browse files

Merge pull request #118 from dune-community/dailywork_tleibner

Fix color output, add blocked matrix test
parents 6f1512f0 2db472b3
No related branches found
No related tags found
No related merge requests found
...@@ -4,21 +4,21 @@ status = 1a3bcab04b011a5d6e44f9983cae6ff89fa695e8 bin (heads/master) ...@@ -4,21 +4,21 @@ status = 1a3bcab04b011a5d6e44f9983cae6ff89fa695e8 bin (heads/master)
20a673b9dad7e2e25bd97defa8849debb59d247c config.opts (heads/master) 20a673b9dad7e2e25bd97defa8849debb59d247c config.opts (heads/master)
8f2c5aba441417bf2c42f22272f538c68a89cc4a dune-alugrid (remotes/origin/releases/2.5) 8f2c5aba441417bf2c42f22272f538c68a89cc4a dune-alugrid (remotes/origin/releases/2.5)
707acf201d5a754c80f87cc4d71aa36bf29a6e3f dune-common (v2.5.1-9-g707acf20) 707acf201d5a754c80f87cc4d71aa36bf29a6e3f dune-common (v2.5.1-9-g707acf20)
+d00312da9c44822962cbf919813fe3735fd80547 dune-gdt (heads/dailywork_tleibner) +4c3b7f55e8fac69596b2098c8f4dc8ced8684227 dune-gdt (heads/entropy_flux_even_newer)
390a2c503783bbed778a8ff610f8c5ca09c238d0 dune-geometry (v2.5.1-5-g390a2c5) 390a2c503783bbed778a8ff610f8c5ca09c238d0 dune-geometry (v2.5.1-5-g390a2c5)
d7b20bbc5f6fdcfc312beb0ea5d16d39ea26904e dune-grid (v2.5.1-2-gd7b20bbc5) d7b20bbc5f6fdcfc312beb0ea5d16d39ea26904e dune-grid (v2.5.1-2-gd7b20bbc5)
9e29a333e8af02382d80b95335a784d5ce1ea2c8 dune-grid-glue (v2.4.0-70-g9e29a33) +e9d9a3336735090648637e044e279866bbea3597 dune-grid-glue (v2.4.0-60-ge9d9a33)
63df56a54f81eda308233a683eb329e77e69f0a9 dune-istl (v2.5.1rc1) 63df56a54f81eda308233a683eb329e77e69f0a9 dune-istl (v2.5.1rc1)
0d757d65e5d57134a7ecf304e35d063f4ccc7116 dune-localfunctions (v2.5.1rc1) 0d757d65e5d57134a7ecf304e35d063f4ccc7116 dune-localfunctions (v2.5.1rc1)
8a69fc68165780921bbba77da338b6932daf983c dune-pybindxi (v2.2.1-16-g8a69fc6) 8a69fc68165780921bbba77da338b6932daf983c dune-pybindxi (v2.2.1-16-g8a69fc6)
741e4f8e53bdd3e1b6e19d84eb22b6e3dc48526c dune-python (remotes/origin/releases/2.5) 741e4f8e53bdd3e1b6e19d84eb22b6e3dc48526c dune-python (remotes/origin/releases/2.5)
26cc8cb4161a3a51002ab2a81b8c81d2c951ee79 dune-testtools (remotes/origin/dune_xt) 26cc8cb4161a3a51002ab2a81b8c81d2c951ee79 dune-testtools (remotes/origin/p/renemilk/testname_listing_hack_no-skiptest)
0a74e7dd0b2115778a5d490dab08a2ed07fcaa1e dune-uggrid (v2.5.2) 0a74e7dd0b2115778a5d490dab08a2ed07fcaa1e dune-uggrid (v2.5.2)
+6db1dbdea1ae1b08fe4b17f7ee6edb3302ea68b7 dune-xt-common (heads/master) +956061671257741c385e51792428742eff3be1af dune-xt-common (heads/dailywork_tleibner)
b8cf8efc32e46511990b691afee55da3b7af15c8 dune-xt-data (heads/master) b8cf8efc32e46511990b691afee55da3b7af15c8 dune-xt-data (heads/master)
0c9df39934e23b950f357c912b4c800b86de683f dune-xt-functions (heads/master) 0c9df39934e23b950f357c912b4c800b86de683f dune-xt-functions (heads/dailywork_tleibner)
dd30fcd7d4485eb2a8158d5ddf01333f58502c40 dune-xt-grid (heads/master) dd30fcd7d4485eb2a8158d5ddf01333f58502c40 dune-xt-grid (heads/master)
7493329b647abe4cff8340172c60c37077b70568 dune-xt-la (heads/master) +3e70f4e5696d8393dba488783f19018a637ddbe9 dune-xt-la (heads/dailywork-tleibner)
09d0378f616b94d68bcdd9fc6114813181849ec0 scripts (heads/master) 09d0378f616b94d68bcdd9fc6114813181849ec0 scripts (heads/master)
commit = 3ff2591bb5a213889362ced1184570157631dd91 commit = 3ff2591bb5a213889362ced1184570157631dd91
...@@ -45,7 +45,7 @@ commit = 707acf201d5a754c80f87cc4d71aa36bf29a6e3f ...@@ -45,7 +45,7 @@ commit = 707acf201d5a754c80f87cc4d71aa36bf29a6e3f
[submodule.dune-gdt] [submodule.dune-gdt]
remote = git@github.com:dune-community/dune-gdt.git remote = git@github.com:dune-community/dune-gdt.git
status = 2424627f0ad5de7e4aaa5e7f48bc2a02414d95a1 .vcsetup (heads/master) status = 2424627f0ad5de7e4aaa5e7f48bc2a02414d95a1 .vcsetup (heads/master)
commit = d00312da9c44822962cbf919813fe3735fd80547 commit = 4c3b7f55e8fac69596b2098c8f4dc8ced8684227
[submodule.dune-geometry] [submodule.dune-geometry]
remote = git@github.com:dune-community/dune-geometry.git remote = git@github.com:dune-community/dune-geometry.git
...@@ -60,7 +60,7 @@ commit = d7b20bbc5f6fdcfc312beb0ea5d16d39ea26904e ...@@ -60,7 +60,7 @@ commit = d7b20bbc5f6fdcfc312beb0ea5d16d39ea26904e
[submodule.dune-grid-glue] [submodule.dune-grid-glue]
remote = https://github.com/dune-mirrors/dune-grid-glue.git remote = https://github.com/dune-mirrors/dune-grid-glue.git
status = status =
commit = 9e29a333e8af02382d80b95335a784d5ce1ea2c8 commit = e9d9a3336735090648637e044e279866bbea3597
[submodule.dune-istl] [submodule.dune-istl]
remote = https://github.com/dune-mirrors/dune-istl.git remote = https://github.com/dune-mirrors/dune-istl.git
...@@ -83,7 +83,7 @@ status = ...@@ -83,7 +83,7 @@ status =
commit = 741e4f8e53bdd3e1b6e19d84eb22b6e3dc48526c commit = 741e4f8e53bdd3e1b6e19d84eb22b6e3dc48526c
[submodule.dune-testtools] [submodule.dune-testtools]
remote = git@github.com:dune-community/dune-testtools.git remote = https://github.com/dune-mirrors/dune-testtools.git
status = status =
commit = 26cc8cb4161a3a51002ab2a81b8c81d2c951ee79 commit = 26cc8cb4161a3a51002ab2a81b8c81d2c951ee79
...@@ -95,16 +95,16 @@ commit = 0a74e7dd0b2115778a5d490dab08a2ed07fcaa1e ...@@ -95,16 +95,16 @@ commit = 0a74e7dd0b2115778a5d490dab08a2ed07fcaa1e
[submodule.dune-xt-common] [submodule.dune-xt-common]
remote = git@github.com:dune-community/dune-xt-common.git remote = git@github.com:dune-community/dune-xt-common.git
status = 2424627f0ad5de7e4aaa5e7f48bc2a02414d95a1 .vcsetup (heads/master) status = 2424627f0ad5de7e4aaa5e7f48bc2a02414d95a1 .vcsetup (heads/master)
commit = 6db1dbdea1ae1b08fe4b17f7ee6edb3302ea68b7 commit = 956061671257741c385e51792428742eff3be1af
[submodule.dune-xt-data] [submodule.dune-xt-data]
remote = git@github.com:dune-community/dune-xt-data remote = https://github.com/dune-community/dune-xt-data
status = 2424627f0ad5de7e4aaa5e7f48bc2a02414d95a1 .vcsetup (heads/master) status = -2424627f0ad5de7e4aaa5e7f48bc2a02414d95a1 .vcsetup
commit = b8cf8efc32e46511990b691afee55da3b7af15c8 commit = b8cf8efc32e46511990b691afee55da3b7af15c8
[submodule.dune-xt-functions] [submodule.dune-xt-functions]
remote = git@github.com:dune-community/dune-xt-functions.git remote = git@github.com:dune-community/dune-xt-functions.git
status = 2424627f0ad5de7e4aaa5e7f48bc2a02414d95a1 .vcsetup (heads/master) status = 2424627f0ad5de7e4aaa5e7f48bc2a02414d95a1 .vcsetup ((null))
commit = 0c9df39934e23b950f357c912b4c800b86de683f commit = 0c9df39934e23b950f357c912b4c800b86de683f
[submodule.dune-xt-grid] [submodule.dune-xt-grid]
...@@ -115,7 +115,7 @@ commit = dd30fcd7d4485eb2a8158d5ddf01333f58502c40 ...@@ -115,7 +115,7 @@ commit = dd30fcd7d4485eb2a8158d5ddf01333f58502c40
[submodule.dune-xt-la] [submodule.dune-xt-la]
remote = git@github.com:dune-community/dune-xt-la.git remote = git@github.com:dune-community/dune-xt-la.git
status = 2424627f0ad5de7e4aaa5e7f48bc2a02414d95a1 .vcsetup (heads/master) status = 2424627f0ad5de7e4aaa5e7f48bc2a02414d95a1 .vcsetup (heads/master)
commit = 7493329b647abe4cff8340172c60c37077b70568 commit = 3e70f4e5696d8393dba488783f19018a637ddbe9
[submodule.scripts] [submodule.scripts]
remote = https://github.com/wwu-numerik/scripts.git remote = https://github.com/wwu-numerik/scripts.git
......
...@@ -124,7 +124,7 @@ size_t template_color_chooser(size_t i) ...@@ -124,7 +124,7 @@ size_t template_color_chooser(size_t i)
bool terminal_supports_color() bool terminal_supports_color()
{ {
const char* const term = getenv("TERM"); const char* const term = getenv("TERM");
if (term == NULL) if (term == nullptr)
return false; return false;
else { else {
const auto term_str = std::string(term); const auto term_str = std::string(term);
...@@ -157,7 +157,7 @@ std::string highlight_template(std::string str, size_t maxlevel) ...@@ -157,7 +157,7 @@ std::string highlight_template(std::string str, size_t maxlevel)
i += dummy.size(); i += dummy.size();
} }
} }
str += "\033[38;5;0m"; str += "\033[0m";
return str; return str;
} // highlight_template } // highlight_template
...@@ -168,11 +168,13 @@ std::string highlight_string(std::string str, size_t colornr) ...@@ -168,11 +168,13 @@ std::string highlight_string(std::string str, size_t colornr)
std::string highlight_search_string(std::string str, std::string substr, size_t colornr) std::string highlight_search_string(std::string str, std::string substr, size_t colornr)
{ {
long index = long(str.find(substr, 0)); std::string dummy = "\033[38;5;" + std::to_string(colornr % 256) + "m";
std::string dummy2 = "\033[0m";
str.insert(0, dummy2);
while (index != long(std::string::npos)) { size_t index = str.find(substr, 0);
std::string dummy = "\033[38;5;" + std::to_string(colornr % 256) + "m";
std::string dummy2 = "\033[38;5;0m"; while (index != std::string::npos) {
str.insert(index, dummy); str.insert(index, dummy);
str.insert(index + substr.size() + dummy.size(), dummy2); str.insert(index + substr.size() + dummy.size(), dummy2);
index = str.find(substr, index + dummy.size() + substr.size() + dummy2.size()); index = str.find(substr, index + dummy.size() + substr.size() + dummy2.size());
......
...@@ -388,6 +388,12 @@ public: ...@@ -388,6 +388,12 @@ public:
{ {
} }
BlockedFieldMatrix(const size_t DXTC_DEBUG_ONLY(rows), const size_t DXTC_DEBUG_ONLY(cols), const K& val = K(0.))
: backend_(BlockType(val))
{
assert(rows == num_rows && cols == num_cols && "Requested shape has to match static shape!");
}
BlockedFieldMatrix(const MatrixType& other) BlockedFieldMatrix(const MatrixType& other)
{ {
*this = other; *this = other;
...@@ -418,23 +424,52 @@ public: ...@@ -418,23 +424,52 @@ public:
K get_entry(const size_t ii, const size_t jj) const K get_entry(const size_t ii, const size_t jj) const
{ {
assert(ii < num_rows && jj < num_cols); assert(ii < num_rows && jj < num_cols);
if (ii / block_rows != jj / block_cols) if (!in_pattern(ii, jj))
return K(0.); return K(0.);
return backend_[ii / block_rows][ii % block_rows][jj % block_cols]; return backend_[ii / block_rows][ii % block_rows][jj % block_cols];
} }
K& get_entry(const size_t jj, const size_t ll, const size_t mm) K& get_entry(const size_t jj, const size_t ll, const size_t mm)
{ {
assert(jj < num_blocks && ll < block_rows && mm < block_cols); assert(is_valid_entry(jj, ll, mm));
return backend_[jj][ll][mm]; return backend_[jj][ll][mm];
} }
const K& get_entry(const size_t jj, const size_t ll, const size_t mm) const const K& get_entry(const size_t jj, const size_t ll, const size_t mm) const
{ {
assert(jj < num_blocks && ll < block_rows && mm < block_cols); assert(is_valid_entry(jj, ll, mm));
return backend_[jj][ll][mm]; return backend_[jj][ll][mm];
} }
void set_entry(const size_t ii, const size_t jj, const K& val)
{
assert(ii < num_rows && jj < num_cols);
if (in_pattern(ii, jj))
backend_[ii / block_rows][ii % block_rows][jj % block_cols] = val;
else if (XT::Common::FloatCmp::ne(val, K(0)))
DUNE_THROW(Dune::MathError, "Tried to modify a value that is not in the pattern!");
}
void set_entry(const size_t jj, const size_t ll, const size_t mm, const K& val)
{
assert(is_valid_entry(jj, ll, mm));
backend_[jj][ll][mm] = val;
}
void add_to_entry(const size_t ii, const size_t jj, const K& val)
{
assert(ii < num_rows && jj < num_cols);
if (!in_pattern(ii, jj) && XT::Common::FloatCmp::ne(val, K(0)))
DUNE_THROW(Dune::MathError, "Tried to modify a value that is not in the pattern!");
backend_[ii / block_rows][ii % block_rows][jj % block_cols] += val;
}
void add_to_entry(const size_t jj, const size_t ll, const size_t mm, const K& val)
{
assert(is_valid_entry(jj, ll, mm));
backend_[jj][ll][mm] += val;
}
BlockType& block(const size_t jj) BlockType& block(const size_t jj)
{ {
assert(jj < num_blocks); assert(jj < num_blocks);
...@@ -504,6 +539,65 @@ public: ...@@ -504,6 +539,65 @@ public:
return ret; return ret;
} }
ThisType operator*(const ThisType& other) const
{
ThisType ret(*this);
ret.rightmultiply(other);
return ret;
}
ThisType& operator*=(const K& val)
{
for (size_t jj = 0; jj < num_blocks; ++jj)
block(jj) *= val;
return *this;
}
ThisType& operator+=(const ThisType& other)
{
for (size_t jj = 0; jj < num_blocks; ++jj)
block(jj) += other.block(jj);
return *this;
}
ThisType operator+(const ThisType& other) const
{
ThisType ret(*this);
ret += other;
return ret;
}
ThisType& operator-=(const ThisType& other)
{
for (size_t jj = 0; jj < num_blocks; ++jj)
block(jj) -= other.block(jj);
return *this;
}
ThisType operator-(const ThisType& other) const
{
ThisType ret(*this);
ret -= other;
return ret;
}
static bool in_pattern(const size_t ii, const size_t jj)
{
return (ii / block_rows == jj / block_cols);
}
static bool is_valid_entry(const size_t jj, const size_t ll, const size_t mm)
{
return (jj < num_blocks && ll < block_rows && mm < block_cols);
}
template <class CharType, class CharTraits>
friend std::basic_ostream<CharType, CharTraits>& operator<<(std::basic_ostream<CharType, CharTraits>& out,
const ThisType& mat)
{
return output_matrix(out, mat);
} // ... operator<<(...)
private: private:
FieldVector<BlockType, num_blocks> backend_; FieldVector<BlockType, num_blocks> backend_;
}; };
...@@ -530,6 +624,8 @@ struct MatrixAbstraction<Dune::XT::Common::FieldMatrix<K, N, M>> ...@@ -530,6 +624,8 @@ struct MatrixAbstraction<Dune::XT::Common::FieldMatrix<K, N, M>>
static const constexpr StorageLayout storage_layout = StorageLayout::dense_row_major; static const constexpr StorageLayout storage_layout = StorageLayout::dense_row_major;
static constexpr bool has_ostream = true;
template <class SparsityPatternType = FullPattern> template <class SparsityPatternType = FullPattern>
static inline MatrixType create(const size_t rows, static inline MatrixType create(const size_t rows,
const size_t cols, const size_t cols,
...@@ -585,6 +681,86 @@ struct MatrixAbstraction<Dune::XT::Common::FieldMatrix<K, N, M>> ...@@ -585,6 +681,86 @@ struct MatrixAbstraction<Dune::XT::Common::FieldMatrix<K, N, M>>
} }
}; };
template <class K, size_t num_blocks, size_t block_rows, size_t block_cols>
struct MatrixAbstraction<Dune::XT::Common::BlockedFieldMatrix<K, num_blocks, block_rows, block_cols>>
{
typedef Dune::XT::Common::BlockedFieldMatrix<K, num_blocks, block_rows, block_cols> MatrixType;
typedef typename Dune::FieldTraits<K>::field_type ScalarType;
typedef typename Dune::FieldTraits<K>::real_type RealType;
typedef ScalarType S;
typedef RealType R;
static const bool is_matrix = true;
static const bool has_static_size = true;
static const size_t static_rows = MatrixType::num_rows;
static const size_t static_cols = MatrixType::num_cols;
template <size_t rows = static_rows, size_t cols = static_cols, class FieldType = K>
using MatrixTypeTemplate = Dune::XT::Common::BlockedFieldMatrix<FieldType, rows / block_rows, block_rows, block_cols>;
static const constexpr StorageLayout storage_layout = StorageLayout::other;
static constexpr bool has_ostream = true;
template <class SparsityPatternType = FullPattern>
static inline MatrixType create(const size_t rows,
const size_t cols,
const ScalarType& val = suitable_default<ScalarType>::value(),
const SparsityPatternType& /*pattern*/ = SparsityPatternType())
{
return MatrixType(rows, cols, val);
}
template <class SparsityPatternType = FullPattern>
static inline std::unique_ptr<MatrixType> make_unique(const size_t rows,
const size_t cols,
const ScalarType& val = suitable_default<ScalarType>::value(),
const SparsityPatternType& /*pattern*/ = SparsityPatternType())
{
return std::make_unique<MatrixType>(rows, cols, val);
}
static constexpr size_t rows(const MatrixType& /*mat*/)
{
return static_rows;
}
static constexpr size_t cols(const MatrixType& /*mat*/)
{
return static_cols;
}
static inline void set_entry(MatrixType& mat, const size_t row, const size_t col, const ScalarType& val)
{
mat.set_entry(row, col, val);
}
static inline ScalarType get_entry(const MatrixType& mat, const size_t row, const size_t col)
{
return mat.get_entry(row, col);
}
static inline void add_to_entry(MatrixType& mat, const size_t row, const size_t col, const ScalarType& val)
{
mat.add_to_entry(row, col, val);
}
static inline ScalarType* data(MatrixType& /*mat*/)
{
DUNE_THROW(InvalidStateException, "Do not call me if storage layout is not dense!");
return nullptr;
}
static inline const ScalarType* data(const MatrixType& /*mat*/)
{
DUNE_THROW(InvalidStateException, "Do not call me if storage_layout is not dense!");
return nullptr;
}
};
template <class M> template <class M>
typename std::enable_if<is_matrix<M>::value && MatrixAbstraction<M>::has_static_size, typename std::enable_if<is_matrix<M>::value && MatrixAbstraction<M>::has_static_size,
......
...@@ -196,6 +196,18 @@ public: ...@@ -196,6 +196,18 @@ public:
{ {
} }
BlockedFieldVector(const std::initializer_list<K>& init_list)
{
assert(init_list.size() == static_size || init_list.size() == num_blocks);
if (init_list.size() == static_size) {
*this = VectorType(init_list);
} else {
size_t jj = 0;
for (const auto& block_init : init_list)
block(jj++) = block_init;
}
}
ThisType& operator=(const VectorType& other) ThisType& operator=(const VectorType& other)
{ {
for (size_t jj = 0; jj < num_blocks; ++jj) for (size_t jj = 0; jj < num_blocks; ++jj)
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#define DUNE_XT_COMMON_MATRIX_HH #define DUNE_XT_COMMON_MATRIX_HH
#include <memory> #include <memory>
#include <ostream>
#include <dune/common/dynmatrix.hh> #include <dune/common/dynmatrix.hh>
#include <dune/common/fmatrix.hh> #include <dune/common/fmatrix.hh>
...@@ -43,11 +44,12 @@ struct FullPattern ...@@ -43,11 +44,12 @@ struct FullPattern
template <class MatType> template <class MatType>
struct MatrixAbstraction struct MatrixAbstraction
{ {
typedef MatType MatrixType; using M = std::conditional_t<std::is_same<MatType, void>::value, int, MatType>; // avoid reference to void
typedef MatType ScalarType; typedef M MatrixType;
typedef MatType RealType; typedef typename Dune::FieldTraits<M>::field_type ScalarType;
typedef MatType S; typedef typename Dune::FieldTraits<M>::real_type RealType;
typedef MatType R; typedef ScalarType S;
typedef RealType R;
template <size_t rows = 0, size_t cols = 0, class FieldType = ScalarType> template <size_t rows = 0, size_t cols = 0, class FieldType = ScalarType>
using MatrixTypeTemplate = MatrixType; using MatrixTypeTemplate = MatrixType;
...@@ -62,6 +64,8 @@ struct MatrixAbstraction ...@@ -62,6 +64,8 @@ struct MatrixAbstraction
static const constexpr StorageLayout storage_layout = XT::Common::StorageLayout::other; static const constexpr StorageLayout storage_layout = XT::Common::StorageLayout::other;
static const bool has_ostream = false;
template <class SparsityPatternType = FullPattern> template <class SparsityPatternType = FullPattern>
static inline /*MatrixType*/ void create(const size_t /*rows*/, static inline /*MatrixType*/ void create(const size_t /*rows*/,
const size_t /*cols*/, const size_t /*cols*/,
...@@ -110,13 +114,14 @@ struct MatrixAbstraction ...@@ -110,13 +114,14 @@ struct MatrixAbstraction
static_assert(AlwaysFalse<MatType>::value, "Do not call me if is_matrix is false!"); static_assert(AlwaysFalse<MatType>::value, "Do not call me if is_matrix is false!");
} }
static inline ScalarType* data(typename std::remove_const<MatrixType>::type& /*mat*/) static inline ScalarType* data(std::remove_const_t<MatrixType>& /*mat*/)
{ {
static_assert(AlwaysFalse<MatType>::value, "Do not call me if storage_layout is not dense!"); static_assert(AlwaysFalse<MatType>::value, "Do not call me if storage_layout is not dense!");
return nullptr; return nullptr;
} }
static inline const ScalarType* data(const MatrixType& /*mat*/) template <bool is_mat = is_matrix>
static inline const std::enable_if_t<is_mat, ScalarType>* data(std::add_const_t<MatrixType>& /*vec*/)
{ {
static_assert(AlwaysFalse<MatType>::value, "Do not call me if storage_layout is not dense!"); static_assert(AlwaysFalse<MatType>::value, "Do not call me if storage_layout is not dense!");
return nullptr; return nullptr;
...@@ -144,6 +149,8 @@ struct MatrixAbstraction<Dune::DynamicMatrix<K>> ...@@ -144,6 +149,8 @@ struct MatrixAbstraction<Dune::DynamicMatrix<K>>
static const constexpr StorageLayout storage_layout = StorageLayout::other; static const constexpr StorageLayout storage_layout = StorageLayout::other;
static const bool has_ostream = true;
template <class SparsityPatternType = FullPattern> template <class SparsityPatternType = FullPattern>
static inline MatrixType create(const size_t rows, static inline MatrixType create(const size_t rows,
const size_t cols, const size_t cols,
...@@ -220,6 +227,8 @@ struct MatrixAbstraction<Dune::FieldMatrix<K, N, M>> ...@@ -220,6 +227,8 @@ struct MatrixAbstraction<Dune::FieldMatrix<K, N, M>>
static const constexpr StorageLayout storage_layout = StorageLayout::dense_row_major; static const constexpr StorageLayout storage_layout = StorageLayout::dense_row_major;
static const bool has_ostream = true;
template <class SparsityPatternType = FullPattern> template <class SparsityPatternType = FullPattern>
static inline MatrixType create(const size_t rows, static inline MatrixType create(const size_t rows,
const size_t cols, const size_t cols,
...@@ -460,6 +469,25 @@ transposed(const MatrixType& mat) ...@@ -460,6 +469,25 @@ transposed(const MatrixType& mat)
} }
template <class M, class CharType, class CharTraits>
std::basic_ostream<CharType, CharTraits>& output_matrix(std::basic_ostream<CharType, CharTraits>& out, const M& mat)
{
using Matrix = Dune::XT::Common::MatrixAbstraction<M>;
out << "[";
for (size_t ii = 0; ii < Matrix::rows(mat); ++ii) {
for (size_t jj = 0; jj < Matrix::cols(mat); ++jj) {
out << Matrix::get_entry(mat, ii, jj);
if (jj == Matrix::cols(mat) - 1 && ii < Matrix::rows(mat) - 1)
out << ";";
else if (jj < Matrix::cols(mat) - 1)
out << " ";
}
}
out << "]";
return out;
}
} // namespace Common } // namespace Common
} // namespace XT } // namespace XT
......
...@@ -52,7 +52,7 @@ void install_signal_handler(int signal, handler_type handler) ...@@ -52,7 +52,7 @@ void install_signal_handler(int signal, handler_type handler)
sigemptyset(&new_action.sa_mask); sigemptyset(&new_action.sa_mask);
new_action.sa_flags = 0; new_action.sa_flags = 0;
sigaction(signal, &new_action, NULL); sigaction(signal, &new_action, nullptr);
} // install_signal_handler } // install_signal_handler
} // namepsace Common } // namepsace Common
......
...@@ -21,30 +21,30 @@ GTEST_TEST(Color, All) ...@@ -21,30 +21,30 @@ GTEST_TEST(Color, All)
std::cout << "WARNING: This test will succeed although some of the color codes" << std::endl; std::cout << "WARNING: This test will succeed although some of the color codes" << std::endl;
std::cout << "are not supported by your terminal!" << std::endl; std::cout << "are not supported by your terminal!" << std::endl;
std::cout << "(Sometimes 'blink', 'reverse' or 'italic' are not supported.)" << std::endl; std::cout << "(Sometimes 'blink', 'reverse' or 'italic' are not supported.)" << std::endl;
std::cout << StreamModifiers::underline << "a simple 'hello world': " << StreamModifiers::endunderline std::cout << StreamModifiers::underline << "a simple 'hello world':" << StreamModifiers::endunderline << " "
<< "hello world" << std::endl; << "hello world" << std::endl;
std::cout << StreamModifiers::underline << "a colored 'hello world': " << StreamModifiers::endunderline std::cout << StreamModifiers::underline << "a colored 'hello world':" << StreamModifiers::endunderline << " "
<< highlight_string("hello world", 1) << std::endl; << highlight_string("hello world", 1) << std::endl;
std::cout << StreamModifiers::underline << "a colored 'hello world': " << StreamModifiers::endunderline std::cout << StreamModifiers::underline << "a colored 'hello world':" << StreamModifiers::endunderline << " "
<< Colors::bgreen << "hello world" << StreamModifiers::normal << std::endl; << Colors::bgreen << "hello world" << StreamModifiers::normal << std::endl;
std::cout << StreamModifiers::underline << "a blinking 'hello world': " << StreamModifiers::endunderline std::cout << StreamModifiers::underline << "a blinking 'hello world':" << StreamModifiers::endunderline << " "
<< StreamModifiers::blink << "hello world" << StreamModifiers::endblink << std::endl; << StreamModifiers::blink << "hello world" << StreamModifiers::endblink << std::endl;
std::cout << StreamModifiers::underline << "an italic 'hello world': " << StreamModifiers::endunderline std::cout << StreamModifiers::underline << "an italic 'hello world':" << StreamModifiers::endunderline << " "
<< StreamModifiers::italic << "hello world" << StreamModifiers::enditalic << std::endl; << StreamModifiers::italic << "hello world" << StreamModifiers::enditalic << std::endl;
std::cout << StreamModifiers::underline << "an underlined 'hello world': " << StreamModifiers::endunderline std::cout << StreamModifiers::underline << "an underlined 'hello world':" << StreamModifiers::endunderline << " "
<< StreamModifiers::underline << "hello world" << StreamModifiers::endunderline << std::endl; << StreamModifiers::underline << "hello world" << StreamModifiers::endunderline << std::endl;
std::cout << StreamModifiers::underline << "a reverse 'hello world': " << StreamModifiers::endunderline std::cout << StreamModifiers::underline << "a reverse 'hello world':" << StreamModifiers::endunderline << " "
<< StreamModifiers::reverse << "hello world" << StreamModifiers::endreverse << std::endl; << StreamModifiers::reverse << "hello world" << StreamModifiers::endreverse << std::endl;
std::cout << StreamModifiers::underline std::cout << StreamModifiers::underline
<< "a 'hello world' with highlighted substrings ('o'): " << StreamModifiers::endunderline << "a 'hello world' with highlighted substrings ('o'):" << StreamModifiers::endunderline << " "
<< highlight_search_string("hello world", "o", 3) << std::endl; << highlight_search_string("hello world", "o", 3) << std::endl;
std::cout << StreamModifiers::underline << "a highlighted 'hello world'-template: " << StreamModifiers::endunderline std::cout << StreamModifiers::underline << "a highlighted 'hello world'-template:" << StreamModifiers::endunderline
<< highlight_template("Hello< World, Hello< World, Hello< World< Hello, World > > > >") << std::endl; << " " << highlight_template("Hello< World, Hello< World, Hello< World< Hello, World > > > >") << std::endl;
std::cout << StreamModifiers::underline std::cout << StreamModifiers::underline
<< "a highlighted 'hello world'-template only showing two levels: " << StreamModifiers::endunderline << "a highlighted 'hello world'-template only showing two levels:" << StreamModifiers::endunderline << " "
<< highlight_template("Hello< World, Hello< World, Hello< World< Hello, World > > > >", 2) << std::endl; << highlight_template("Hello< World, Hello< World, Hello< World< Hello, World > > > >", 2) << std::endl;
std::cout << StreamModifiers::underline std::cout << StreamModifiers::underline
<< "colored 'hello world' for all available colors( 0 - 255): " << StreamModifiers::endunderline << "colored 'hello world' for all available colors( 0 - 255):" << StreamModifiers::endunderline << " "
<< std::endl; << std::endl;
for (size_t i = 0; i < 256; ++i) for (size_t i = 0; i < 256; ++i)
std::cout << highlight_string("hello world - ", i); std::cout << highlight_string("hello world - ", i);
......
...@@ -13,15 +13,20 @@ ...@@ -13,15 +13,20 @@
#include <dune/xt/common/matrix.hh> #include <dune/xt/common/matrix.hh>
#include <dune/xt/common/fmatrix.hh> #include <dune/xt/common/fmatrix.hh>
using MatrixTypes = ::testing::Types<std::tuple<Dune::FieldMatrix<int, 1, 1>, Int<1>, Int<1>>, using MatrixTypes =
std::tuple<Dune::FieldMatrix<int, 2, 3>, Int<2>, Int<3>>, ::testing::Types<std::tuple<Dune::FieldMatrix<int, 1, 1>, Int<1>, Int<1>>,
std::tuple<Dune::FieldMatrix<int, 3, 1>, Int<3>, Int<1>>, std::tuple<Dune::FieldMatrix<int, 2, 3>, Int<2>, Int<3>>,
std::tuple<Dune::XT::Common::FieldMatrix<int, 1, 1>, Int<1>, Int<1>>, std::tuple<Dune::FieldMatrix<int, 3, 1>, Int<3>, Int<1>>,
std::tuple<Dune::XT::Common::FieldMatrix<int, 2, 3>, Int<2>, Int<3>>, std::tuple<Dune::XT::Common::FieldMatrix<int, 1, 1>, Int<1>, Int<1>>,
std::tuple<Dune::XT::Common::FieldMatrix<int, 3, 1>, Int<3>, Int<1>>, std::tuple<Dune::XT::Common::FieldMatrix<int, 2, 3>, Int<2>, Int<3>>,
std::tuple<Dune::DynamicMatrix<int>, Int<1>, Int<1>>, std::tuple<Dune::XT::Common::FieldMatrix<int, 3, 1>, Int<3>, Int<1>>,
std::tuple<Dune::DynamicMatrix<int>, Int<2>, Int<3>>, std::tuple<Dune::XT::Common::BlockedFieldMatrix<int, 1, 1, 1>, Int<1>, Int<1>, Int<1>>,
std::tuple<Dune::DynamicMatrix<int>, Int<3>, Int<1>>>; std::tuple<Dune::XT::Common::BlockedFieldMatrix<int, 2, 2, 2>, Int<2>, Int<2>, Int<2>>,
std::tuple<Dune::XT::Common::BlockedFieldMatrix<int, 2, 2, 3>, Int<2>, Int<2>, Int<3>>,
std::tuple<Dune::XT::Common::BlockedFieldMatrix<int, 2, 3, 2>, Int<2>, Int<3>, Int<2>>,
std::tuple<Dune::DynamicMatrix<int>, Int<1>, Int<1>>,
std::tuple<Dune::DynamicMatrix<int>, Int<2>, Int<3>>,
std::tuple<Dune::DynamicMatrix<int>, Int<3>, Int<1>>>;
template <class Tuple> template <class Tuple>
...@@ -30,15 +35,33 @@ struct SerializeRowwiseTest : public ::testing::Test ...@@ -30,15 +35,33 @@ struct SerializeRowwiseTest : public ::testing::Test
using MatrixType = typename std::tuple_element<0, Tuple>::type; using MatrixType = typename std::tuple_element<0, Tuple>::type;
using M = Dune::XT::Common::MatrixAbstraction<MatrixType>; using M = Dune::XT::Common::MatrixAbstraction<MatrixType>;
using ScalarType = typename M::ScalarType; using ScalarType = typename M::ScalarType;
static const constexpr size_t rows = std::tuple_element<1, Tuple>::type::value; static constexpr bool is_block_matrix = std::tuple_size<Tuple>::value == 4;
static const constexpr size_t cols = std::tuple_element<2, Tuple>::type::value; static constexpr size_t num_blocks = std::tuple_element<1, Tuple>::type::value; // only for BlockedFieldMatrix
static constexpr size_t rows =
is_block_matrix ? std::tuple_element<1, Tuple>::type::value * std::tuple_element<2, Tuple>::type::value
: std::tuple_element<1, Tuple>::type::value;
static constexpr size_t cols = is_block_matrix
? std::tuple_element<1, Tuple>::type::value * std::tuple_element < is_block_matrix ? 3 : 2,
Tuple > ::type::value : std::tuple_element<2, Tuple>::type::value;
SerializeRowwiseTest() SerializeRowwiseTest()
: matrix_(M::create(rows, cols)) : matrix_(M::create(rows, cols))
{ {
for (size_t ii = 0; ii < rows; ++ii) if (is_block_matrix) {
for (size_t jj = 0; jj < cols; ++jj) const size_t block_rows = rows / num_blocks;
M::set_entry(matrix_, ii, jj, static_cast<ScalarType>(100 * ii + jj)); const size_t block_cols = cols / num_blocks;
for (size_t jj = 0; jj < num_blocks; ++jj)
for (size_t ll = 0; ll < block_rows; ++ll)
for (size_t mm = 0; mm < block_cols; ++mm) {
const size_t row = jj * block_rows + ll;
const size_t col = jj * block_cols + mm;
M::set_entry(matrix_, row, col, static_cast<ScalarType>(100 * row + col));
}
} else {
for (size_t ii = 0; ii < rows; ++ii)
for (size_t jj = 0; jj < cols; ++jj)
M::set_entry(matrix_, ii, jj, static_cast<ScalarType>(100 * ii + jj));
}
} }
template <class T> template <class T>
......
...@@ -109,9 +109,10 @@ struct HasSubscriptOperatorForVectorAbstraction ...@@ -109,9 +109,10 @@ struct HasSubscriptOperatorForVectorAbstraction
template <class VecType> template <class VecType>
struct VectorAbstraction struct VectorAbstraction
{ {
typedef VecType VectorType; using V = std::conditional_t<std::is_same<VecType, void>::value, int, VecType>; // avoid reference to void
typedef typename Dune::FieldTraits<VecType>::field_type ScalarType; typedef V VectorType;
typedef typename Dune::FieldTraits<VecType>::real_type RealType; typedef typename Dune::FieldTraits<V>::field_type ScalarType;
typedef typename Dune::FieldTraits<V>::real_type RealType;
typedef ScalarType S; typedef ScalarType S;
typedef RealType R; typedef RealType R;
...@@ -144,13 +145,15 @@ struct VectorAbstraction ...@@ -144,13 +145,15 @@ struct VectorAbstraction
static_assert(AlwaysFalse<VecType>::value, "Do not call me if is_vector is false!"); static_assert(AlwaysFalse<VecType>::value, "Do not call me if is_vector is false!");
} }
static inline ScalarType* data(typename std::remove_const<VectorType>::type& /*vec*/) static inline ScalarType* data(std::remove_const_t<VectorType>& /*vec*/)
{ {
static_assert(AlwaysFalse<VecType>::value, "Do not call me if is_contiguous is false!"); static_assert(AlwaysFalse<VecType>::value, "Do not call me if is_contiguous is false!");
return nullptr; return nullptr;
} }
static inline const ScalarType* data(const VectorType& /*vec*/) // using std::enable_if to avoid 'multiple overloads with same signature' for some strange VectorTypes
template <bool is_vec = is_vector>
static inline const std::enable_if_t<is_vec, ScalarType>* data(std::add_const_t<VectorType>& /*vec*/)
{ {
static_assert(AlwaysFalse<VecType>::value, "Do not call me if is_contiguous is false!"); static_assert(AlwaysFalse<VecType>::value, "Do not call me if is_contiguous is false!");
return nullptr; return nullptr;
...@@ -343,14 +346,9 @@ convert_to(const SourceType& source) ...@@ -343,14 +346,9 @@ convert_to(const SourceType& source)
} // ... convert_to(...) } // ... convert_to(...)
} // namespace Common
} // namespace XT
} // namespace Dune
template <class V, class CharType, class CharTraits> template <class V, class CharType, class CharTraits>
typename std::enable_if<Dune::XT::Common::is_vector<V>::value && !Dune::XT::Common::VectorAbstraction<V>::has_ostream, std::enable_if_t<Dune::XT::Common::is_vector<V>::value && !Dune::XT::Common::VectorAbstraction<V>::has_ostream,
std::basic_ostream<CharType, CharTraits>&>::type std::basic_ostream<CharType, CharTraits>&>
operator<<(std::basic_ostream<CharType, CharTraits>& out, const V& vec) operator<<(std::basic_ostream<CharType, CharTraits>& out, const V& vec)
{ {
using Vector = Dune::XT::Common::VectorAbstraction<V>; using Vector = Dune::XT::Common::VectorAbstraction<V>;
...@@ -368,6 +366,11 @@ operator<<(std::basic_ostream<CharType, CharTraits>& out, const V& vec) ...@@ -368,6 +366,11 @@ operator<<(std::basic_ostream<CharType, CharTraits>& out, const V& vec)
} // ... operator<<(...) } // ... operator<<(...)
} // namespace Common
} // namespace XT
} // namespace Dune
namespace std { namespace std {
...@@ -376,7 +379,7 @@ template <class V, class Alloc, class CharType, class CharTraits> ...@@ -376,7 +379,7 @@ template <class V, class Alloc, class CharType, class CharTraits>
std::basic_ostream<CharType, CharTraits>& operator<<(std::basic_ostream<CharType, CharTraits>& out, std::basic_ostream<CharType, CharTraits>& operator<<(std::basic_ostream<CharType, CharTraits>& out,
const std::vector<V, Alloc>& vec) const std::vector<V, Alloc>& vec)
{ {
::operator<<(out, vec); Dune::XT::Common::operator<<(out, vec);
return out; return out;
} // ... operator<<(...) } // ... operator<<(...)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment