From 637e43f40aea4096bc88283f87d604a0c349bd72 Mon Sep 17 00:00:00 2001 From: Guido Kanschat Date: Wed, 8 Jul 2015 09:59:04 +0200 Subject: [PATCH] add string conversion for BlockIndices --- include/deal.II/lac/block_indices.h | 25 +++++++++++++++++++++++++ tests/lac/block_indices.cc | 2 +- tests/lac/block_indices.output | 4 ++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/include/deal.II/lac/block_indices.h b/include/deal.II/lac/block_indices.h index 41fafc8acf..60a6c04a89 100644 --- a/include/deal.II/lac/block_indices.h +++ b/include/deal.II/lac/block_indices.h @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -116,6 +117,13 @@ public: */ size_type block_size (const unsigned int i) const; + /** + * String representation of the block sizes. The output is of the + * form `[nb->b1,b2,b3|s]`, where `nb` is n_blocks(), `s` + * is total_size() and `b1` etc. are the values of block_size(). + */ + std::string to_string () const; + //@} /** @@ -422,6 +430,23 @@ BlockIndices::block_size (const unsigned int block) const +inline +std::string +BlockIndices::to_string () const +{ + std::string result = "[" + Utilities::int_to_string(n_blocks) + "->"; + for (unsigned int i=0; i0) + result += ','; + result += Utilities::int_to_string(block_size(i)); + } + result += "|" + Utilities::int_to_string(total_size()) + ']'; + return result; +} + + + inline BlockIndices::size_type BlockIndices::block_start (const unsigned int block) const diff --git a/tests/lac/block_indices.cc b/tests/lac/block_indices.cc index 092789ffc0..480a1f5e2d 100644 --- a/tests/lac/block_indices.cc +++ b/tests/lac/block_indices.cc @@ -31,7 +31,7 @@ void test (const BlockIndices &idx) for (unsigned i=0; i5 DEAL::empty: 0:[]->0 DEAL::sizes: 3:[0 0 0]->0 DEAL::start: 0 0 0 +DEAL::string: [3->0,0,0|0] DEAL:: DEAL:: DEAL::sizes: 3:[4 4 4]->12 DEAL::start: 0 4 8 +DEAL::string: [3->4,4,4|12] DEAL:: 0:0:0 1:0:1 2:0:2 3:0:3 4:1:0 5:1:1 6:1:2 7:1:3 8:2:0 9:2:1 10:2:2 11:2:3 DEAL:: 0:0:0 1:0:1 2:0:2 3:0:3 4:1:0 5:1:1 6:1:2 7:1:3 8:2:0 9:2:1 10:2:2 11:2:3 DEAL::push: 4:[4 4 4 2]->14 DEAL::push: 5:[4 4 4 2 5]->19 DEAL::sizes: 6:[4 4 4 2 5 4]->23 DEAL::start: 0 4 8 12 14 19 +DEAL::string: [6->4,4,4,2,5,4|23] DEAL:: 0:0:0 1:0:1 2:0:2 3:0:3 4:1:0 5:1:1 6:1:2 7:1:3 8:2:0 9:2:1 10:2:2 11:2:3 12:3:0 13:3:1 14:4:0 15:4:1 16:4:2 17:4:3 18:4:4 19:5:0 20:5:1 21:5:2 22:5:3 DEAL:: 0:0:0 1:0:1 2:0:2 3:0:3 4:1:0 5:1:1 6:1:2 7:1:3 8:2:0 9:2:1 10:2:2 11:2:3 12:3:0 13:3:1 14:4:0 15:4:1 16:4:2 17:4:3 18:4:4 19:5:0 20:5:1 21:5:2 22:5:3 DEAL::sizes: 4:[4 3 2 1]->10 DEAL::start: 0 4 7 9 +DEAL::string: [4->4,3,2,1|10] DEAL:: 0:0:0 1:0:1 2:0:2 3:0:3 4:1:0 5:1:1 6:1:2 7:2:0 8:2:1 9:3:0 DEAL:: 0:0:0 1:0:1 2:0:2 3:0:3 4:1:0 5:1:1 6:1:2 7:2:0 8:2:1 9:3:0 -- 2.39.5