1
//---------------------------------------------------------------------------
2
// $Id: block_vector.templates.h 18547 2009-04-03 13:04:41Z kronbichler $
5
// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 by the deal.II authors
7
// This file is subject to QPL and may not be distributed
8
// without copyright and license information. Please refer
9
// to the file deal.II/doc/license.html for the text and
10
// further information on this license.
12
//---------------------------------------------------------------------------
13
#ifndef __deal2__block_vector_templates_h
14
#define __deal2__block_vector_templates_h
17
#include <base/config.h>
18
#include <lac/block_vector.h>
19
#include <lac/trilinos_block_vector.h>
23
DEAL_II_NAMESPACE_OPEN
25
template <typename Number>
26
BlockVector<Number>::BlockVector (const unsigned int n_blocks,
27
const unsigned int block_size)
29
reinit (n_blocks, block_size);
34
template <typename Number>
35
BlockVector<Number>::BlockVector (const std::vector<unsigned int> &n)
41
template <typename Number>
42
BlockVector<Number>::BlockVector (const BlockVector<Number>& v)
44
BlockVectorBase<Vector<Number> > ()
46
this->components.resize (v.n_blocks());
47
this->block_indices = v.block_indices;
49
for (unsigned int i=0; i<this->n_blocks(); ++i)
50
this->components[i] = v.components[i];
54
#ifndef DEAL_II_EXPLICIT_CONSTRUCTOR_BUG
56
template <typename Number>
57
template <typename OtherNumber>
58
BlockVector<Number>::BlockVector (const BlockVector<OtherNumber>& v)
67
#ifdef DEAL_II_USE_TRILINOS
69
template <typename Number>
70
BlockVector<Number>::BlockVector (const TrilinosWrappers::BlockVector &v)
72
this->block_indices = v.get_block_indices();
73
this->components.resize(this->n_blocks());
75
for (unsigned int i=0; i<this->n_blocks(); ++i)
76
this->components[i] = v.block(i);
78
BaseClass::collect_sizes();
84
template <typename Number>
85
void BlockVector<Number>::reinit (const unsigned int n_bl,
86
const unsigned int bl_sz,
89
std::vector<unsigned int> n(n_bl, bl_sz);
94
template <typename Number>
95
void BlockVector<Number>::reinit (const std::vector<unsigned int> &n,
98
this->block_indices.reinit (n);
99
if (this->components.size() != this->n_blocks())
100
this->components.resize(this->n_blocks());
102
for (unsigned int i=0; i<this->n_blocks(); ++i)
103
this->components[i].reinit(n[i], fast);
107
template <typename Number>
108
template <typename Number2>
109
void BlockVector<Number>::reinit (const BlockVector<Number2>& v,
112
this->block_indices = v.get_block_indices();
113
if (this->components.size() != this->n_blocks())
114
this->components.resize(this->n_blocks());
116
for (unsigned int i=0;i<this->n_blocks();++i)
117
this->block(i).reinit(v.block(i), fast);
121
template <typename Number>
122
BlockVector<Number>::~BlockVector ()
126
#ifdef DEAL_II_USE_TRILINOS
127
template <typename Number>
129
BlockVector<Number> &
130
BlockVector<Number>::operator = (const TrilinosWrappers::BlockVector &v)
132
BaseClass::operator = (v);
138
template <typename Number>
139
void BlockVector<Number>::swap (BlockVector<Number> &v)
141
Assert (this->n_blocks() == v.n_blocks(),
142
ExcDimensionMismatch(this->n_blocks(), v.n_blocks()));
144
for (unsigned int i=0; i<this->n_blocks(); ++i)
145
dealii::swap (this->components[i], v.components[i]);
146
dealii::swap (this->block_indices, v.block_indices);
151
template <typename Number>
152
void BlockVector<Number>::print (std::ostream &out,
153
const unsigned int precision,
154
const bool scientific,
155
const bool across) const
157
for (unsigned int i=0;i<this->n_blocks();++i)
160
out << 'C' << i << ':';
162
out << "Component " << i << std::endl;
163
this->components[i].print(out, precision, scientific, across);
169
template <typename Number>
170
void BlockVector<Number>::block_write (std::ostream &out) const
172
for (unsigned int i=0;i<this->n_blocks();++i)
173
this->components[i].block_write(out);
178
template <typename Number>
179
void BlockVector<Number>::block_read (std::istream &in)
181
for (unsigned int i=0;i<this->n_blocks();++i)
182
this->components[i].block_read(in);
187
DEAL_II_NAMESPACE_CLOSE