Reference documentation for deal.II version 8.1.0
block_vector.templates.h
1 // ---------------------------------------------------------------------
2 // @f$Id: block_vector.templates.h 30036 2013-07-18 16:55:32Z maier @f$
3 //
4 // Copyright (C) 1999 - 2013 by the deal.II authors
5 //
6 // This file is part of the deal.II library.
7 //
8 // The deal.II library is free software; you can use it, redistribute
9 // it, and/or modify it under the terms of the GNU Lesser General
10 // Public License as published by the Free Software Foundation; either
11 // version 2.1 of the License, or (at your option) any later version.
12 // The full text of the license can be found in the file LICENSE at
13 // the top level of the deal.II distribution.
14 //
15 // ---------------------------------------------------------------------
16 
17 #ifndef __deal2__block_vector_templates_h
18 #define __deal2__block_vector_templates_h
19 
20 
21 #include <deal.II/base/config.h>
22 #include <deal.II/lac/block_vector.h>
23 #include <deal.II/lac/trilinos_block_vector.h>
24 #include <cmath>
25 #include <algorithm>
26 
28 
29 template <typename Number>
30 BlockVector<Number>::BlockVector (const unsigned int n_blocks,
31  const size_type block_size)
32 {
33  reinit (n_blocks, block_size);
34 }
35 
36 
37 
38 template <typename Number>
39 BlockVector<Number>::BlockVector (const std::vector<size_type> &n)
40 {
41  reinit (n, false);
42 }
43 
44 
45 template <typename Number>
47 {
48  reinit (n, false);
49 }
50 
51 
52 template <typename Number>
54  :
55  BlockVectorBase<Vector<Number> > ()
56 {
57  this->components.resize (v.n_blocks());
58  this->block_indices = v.block_indices;
59 
60  for (size_type i=0; i<this->n_blocks(); ++i)
61  this->components[i] = v.components[i];
62 }
63 
64 
65 #ifndef DEAL_II_EXPLICIT_CONSTRUCTOR_BUG
66 
67 template <typename Number>
68 template <typename OtherNumber>
70 {
71  reinit (v, true);
72  *this = v;
73 }
74 
75 #endif
76 
77 
78 #ifdef DEAL_II_WITH_TRILINOS
79 
80 template <typename Number>
82 {
83  this->block_indices = v.get_block_indices();
84  this->components.resize(this->n_blocks());
85 
86  for (size_type i=0; i<this->n_blocks(); ++i)
87  this->components[i] = v.block(i);
88 
89  BaseClass::collect_sizes();
90 }
91 
92 #endif
93 
94 
95 template <typename Number>
96 void BlockVector<Number>::reinit (const unsigned int n_bl,
97  const size_type bl_sz,
98  const bool fast)
99 {
100  std::vector<size_type> n(n_bl, bl_sz);
101  reinit(n, fast);
102 }
103 
104 
105 template <typename Number>
106 void BlockVector<Number>::reinit (const std::vector<size_type> &n,
107  const bool fast)
108 {
109  this->block_indices.reinit (n);
110  if (this->components.size() != this->n_blocks())
111  this->components.resize(this->n_blocks());
112 
113  for (size_type i=0; i<this->n_blocks(); ++i)
114  this->components[i].reinit(n[i], fast);
115 }
116 
117 
118 template <typename Number>
120  const BlockIndices &n,
121  const bool fast)
122 {
123  this->block_indices = n;
124  if (this->components.size() != this->n_blocks())
125  this->components.resize(this->n_blocks());
126 
127  for (size_type i=0; i<this->n_blocks(); ++i)
128  this->components[i].reinit(n.block_size(i), fast);
129 }
130 
131 
132 template <typename Number>
133 template <typename Number2>
135  const bool fast)
136 {
137  this->block_indices = v.get_block_indices();
138  if (this->components.size() != this->n_blocks())
139  this->components.resize(this->n_blocks());
140 
141  for (size_type i=0; i<this->n_blocks(); ++i)
142  this->block(i).reinit(v.block(i), fast);
143 }
144 
145 
146 template <typename Number>
148 {}
149 
150 
151 #ifdef DEAL_II_WITH_TRILINOS
152 template <typename Number>
153 inline
156 {
157  BaseClass::operator = (v);
158  return *this;
159 }
160 #endif
161 
162 
163 template <typename Number>
165 {
166  Assert (this->n_blocks() == v.n_blocks(),
167  ExcDimensionMismatch(this->n_blocks(), v.n_blocks()));
168 
169  for (size_type i=0; i<this->n_blocks(); ++i)
170  ::swap (this->components[i], v.components[i]);
171  ::swap (this->block_indices, v.block_indices);
172 }
173 
174 
175 
176 template <typename Number>
177 void BlockVector<Number>::print (std::ostream &out,
178  const unsigned int precision,
179  const bool scientific,
180  const bool across) const
181 {
182  for (size_type i=0; i<this->n_blocks(); ++i)
183  {
184  if (across)
185  out << 'C' << i << ':';
186  else
187  out << "Component " << i << std::endl;
188  this->components[i].print(out, precision, scientific, across);
189  }
190 }
191 
192 
193 
194 template <typename Number>
195 void BlockVector<Number>::block_write (std::ostream &out) const
196 {
197  for (size_type i=0; i<this->n_blocks(); ++i)
198  this->components[i].block_write(out);
199 }
200 
201 
202 
203 template <typename Number>
204 void BlockVector<Number>::block_read (std::istream &in)
205 {
206  for (size_type i=0; i<this->n_blocks(); ++i)
207  this->components[i].block_read(in);
208 }
209 
210 
211 
212 DEAL_II_NAMESPACE_CLOSE
213 
214 #endif
BlockVector & operator=(const value_type s)
void swap(BlockVector &u, BlockVector &v)
void block_write(std::ostream &out) const
Auxiliary class aiding in the handling of block structures like in BlockVector or FESystem...
Definition: block_indices.h:55
void reinit(const unsigned int num_blocks, const size_type block_size=0, const bool fast=false)
#define Assert(cond, exc)
Definition: exceptions.h:299
const BlockIndices & get_block_indices() const
void reinit(const unsigned int n_blocks, const size_type n_elements_per_block)
std::vector< Vector< Number > > components
size_type block_size(const unsigned int i) const
void swap(BlockVector< Number > &v)
BlockVector(const unsigned int num_blocks=0, const size_type block_size=0)
::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
BlockType & block(const unsigned int i)
void print(const char *format=0) const
void block_read(std::istream &in)