~ubuntu-branches/ubuntu/saucy/deal.ii/saucy

« back to all changes in this revision

Viewing changes to lac/include/lac/block_vector.templates.h

  • Committer: Bazaar Package Importer
  • Author(s): Adam C. Powell, IV
  • Date: 2009-05-08 23:13:50 UTC
  • Revision ID: james.westby@ubuntu.com-20090508231350-rrh1ltgi0tifabwc
Tags: upstream-6.2.0
ImportĀ upstreamĀ versionĀ 6.2.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//---------------------------------------------------------------------------
 
2
//    $Id: block_vector.templates.h 18547 2009-04-03 13:04:41Z kronbichler $
 
3
//    Version: $Name$
 
4
//
 
5
//    Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 by the deal.II authors
 
6
//
 
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.
 
11
//
 
12
//---------------------------------------------------------------------------
 
13
#ifndef __deal2__block_vector_templates_h
 
14
#define __deal2__block_vector_templates_h
 
15
 
 
16
 
 
17
#include <base/config.h>
 
18
#include <lac/block_vector.h>
 
19
#include <lac/trilinos_block_vector.h>
 
20
#include <cmath>
 
21
#include <algorithm>
 
22
 
 
23
DEAL_II_NAMESPACE_OPEN
 
24
 
 
25
template <typename Number>
 
26
BlockVector<Number>::BlockVector (const unsigned int n_blocks,
 
27
                                  const unsigned int block_size)
 
28
{
 
29
  reinit (n_blocks, block_size);
 
30
}
 
31
 
 
32
 
 
33
 
 
34
template <typename Number>
 
35
BlockVector<Number>::BlockVector (const std::vector<unsigned int> &n)
 
36
{
 
37
  reinit (n, false);
 
38
}
 
39
 
 
40
 
 
41
template <typename Number>
 
42
BlockVector<Number>::BlockVector (const BlockVector<Number>& v)
 
43
                :
 
44
                BlockVectorBase<Vector<Number> > ()
 
45
{
 
46
  this->components.resize (v.n_blocks());
 
47
  this->block_indices = v.block_indices;
 
48
  
 
49
  for (unsigned int i=0; i<this->n_blocks(); ++i)
 
50
    this->components[i] = v.components[i];
 
51
}
 
52
 
 
53
 
 
54
#ifndef DEAL_II_EXPLICIT_CONSTRUCTOR_BUG    
 
55
 
 
56
template <typename Number>
 
57
template <typename OtherNumber>
 
58
BlockVector<Number>::BlockVector (const BlockVector<OtherNumber>& v)
 
59
{
 
60
  reinit (v, true);
 
61
  *this = v;
 
62
}
 
63
 
 
64
#endif
 
65
 
 
66
 
 
67
#ifdef DEAL_II_USE_TRILINOS
 
68
 
 
69
template <typename Number>
 
70
BlockVector<Number>::BlockVector (const TrilinosWrappers::BlockVector &v)
 
71
{
 
72
  this->block_indices = v.get_block_indices();
 
73
  this->components.resize(this->n_blocks());
 
74
 
 
75
  for (unsigned int i=0; i<this->n_blocks(); ++i)
 
76
    this->components[i] = v.block(i);
 
77
 
 
78
  BaseClass::collect_sizes();
 
79
}
 
80
 
 
81
#endif
 
82
 
 
83
 
 
84
template <typename Number>
 
85
void BlockVector<Number>::reinit (const unsigned int n_bl,
 
86
                                  const unsigned int bl_sz,
 
87
                                  const bool         fast)
 
88
{
 
89
  std::vector<unsigned int> n(n_bl, bl_sz);
 
90
  reinit(n, fast);
 
91
}
 
92
 
 
93
 
 
94
template <typename Number>
 
95
void BlockVector<Number>::reinit (const std::vector<unsigned int> &n,
 
96
                                  const bool                       fast)
 
97
{
 
98
  this->block_indices.reinit (n);
 
99
  if (this->components.size() != this->n_blocks())
 
100
    this->components.resize(this->n_blocks());
 
101
  
 
102
  for (unsigned int i=0; i<this->n_blocks(); ++i)
 
103
    this->components[i].reinit(n[i], fast);
 
104
}
 
105
 
 
106
 
 
107
template <typename Number>
 
108
template <typename Number2>
 
109
void BlockVector<Number>::reinit (const BlockVector<Number2>& v,
 
110
                                  const bool fast)
 
111
{
 
112
  this->block_indices = v.get_block_indices();
 
113
  if (this->components.size() != this->n_blocks())
 
114
    this->components.resize(this->n_blocks());
 
115
  
 
116
  for (unsigned int i=0;i<this->n_blocks();++i)
 
117
    this->block(i).reinit(v.block(i), fast);
 
118
}
 
119
 
 
120
 
 
121
template <typename Number>
 
122
BlockVector<Number>::~BlockVector ()
 
123
{}
 
124
 
 
125
 
 
126
#ifdef DEAL_II_USE_TRILINOS
 
127
template <typename Number>
 
128
inline
 
129
BlockVector<Number> &
 
130
BlockVector<Number>::operator = (const TrilinosWrappers::BlockVector &v)
 
131
{
 
132
  BaseClass::operator = (v);
 
133
  return *this;
 
134
}
 
135
#endif
 
136
 
 
137
 
 
138
template <typename Number>
 
139
void BlockVector<Number>::swap (BlockVector<Number> &v)
 
140
{
 
141
  Assert (this->n_blocks() == v.n_blocks(),
 
142
          ExcDimensionMismatch(this->n_blocks(), v.n_blocks()));
 
143
  
 
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);
 
147
}
 
148
 
 
149
 
 
150
 
 
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
 
156
{
 
157
  for (unsigned int i=0;i<this->n_blocks();++i)
 
158
    {
 
159
      if (across)
 
160
        out << 'C' << i << ':';
 
161
      else
 
162
        out << "Component " << i << std::endl;
 
163
      this->components[i].print(out, precision, scientific, across);
 
164
    }
 
165
}
 
166
 
 
167
 
 
168
 
 
169
template <typename Number>
 
170
void BlockVector<Number>::block_write (std::ostream &out) const
 
171
{
 
172
  for (unsigned int i=0;i<this->n_blocks();++i)
 
173
    this->components[i].block_write(out);
 
174
}
 
175
 
 
176
 
 
177
 
 
178
template <typename Number>
 
179
void BlockVector<Number>::block_read (std::istream &in)
 
180
{
 
181
  for (unsigned int i=0;i<this->n_blocks();++i)
 
182
    this->components[i].block_read(in);
 
183
}
 
184
 
 
185
 
 
186
 
 
187
DEAL_II_NAMESPACE_CLOSE
 
188
 
 
189
#endif