dune-pdelab  2.5-dev
localvector.hh
Go to the documentation of this file.
1 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=4 sw=2 sts=2:
3 #ifndef DUNE_PDELAB_GRIDFUNCTIONSPACE_LOCALVECTOR_HH
4 #define DUNE_PDELAB_GRIDFUNCTIONSPACE_LOCALVECTOR_HH
5 
6 #include <vector>
7 #include <algorithm>
8 #include <functional>
10 
16 namespace Dune {
17  namespace PDELab {
18 
24  template<typename C>
27  {
28  public:
29 
31  typedef C Container;
32 
34  typedef typename Container::BaseContainer BaseContainer;
35 
37  typedef typename Container::value_type value_type;
38 
40  typedef typename Container::weight_type weight_type;
41 
45 
49  {
51  }
52 
54  typedef typename Container::size_type size_type;
55 
57 
62  {
63  _modified = true;
64  return _weight;
65  }
66 
68 
73  {
74  _weight = weight;
75  }
76 
78  template<typename LFS>
79  void accumulate(const LFS& lfs, size_type n, value_type v)
80  {
81  _modified = true;
82  _container(lfs,n) += _weight * v;
83  }
84 
86 
90  template<typename LFS>
91  void rawAccumulate(const LFS& lfs, size_type n, value_type v)
92  {
93  _modified = true;
94  _container(lfs,n) += v;
95  }
96 
99  : _container(container)
100  , _weight(weight)
101  , _modified(false)
102  {}
103 
105  size_type size() const
106  {
107  return _container.size();
108  }
109 
111  bool modified() const
112  {
113  return _modified;
114  }
115 
117 
122  {
123  _modified = false;
124  }
125 
128  {
129  _modified = true;
130  return _container;
131  }
132 
134  const Container& container() const
135  {
136  return _container;
137  }
138 
141  {
142  _modified = true;
143  return _container.base();
144  }
145 
147  const BaseContainer& base() const
148  {
149  return _container.base();
150  }
151 
152  private:
153  C& _container;
154  weight_type _weight;
155  bool _modified;
156  };
157 
158 
160 
170  template<typename T, typename LFSFlavorTag = AnySpaceTag, typename W = T>
172  {
173  public:
174 
176  typedef std::vector<T> BaseContainer;
177 
179  typedef typename BaseContainer::value_type value_type;
180 
182  typedef typename BaseContainer::size_type size_type;
183 
185  typedef typename BaseContainer::reference reference;
186 
188  typedef typename BaseContainer::const_reference const_reference;
189 
191 
195  typedef W weight_type;
196 
199 
202  {
203  return WeightedAccumulationView(*this,weight);
204  }
205 
207 
212  template<typename LFS>
213  reference operator()(const LFS& lfs, size_type i)
214  {
215  return _container[lfs.localIndex(i)];
216  }
217 
219 
224  template<typename LFS>
225  const_reference operator()(const LFS& lfs, size_type i) const
226  {
227  return _container[lfs.localIndex(i)];
228  }
229 
232  {
233  std::fill(_container.begin(),_container.end(),v);
234  return *this;
235  }
236 
239  {
240  using namespace std::placeholders;
241  std::transform(
242  _container.begin(),
243  _container.end(),
244  _container.begin(),
245  std::bind(std::multiplies<value_type>(),v,_1)
246  );
247  return *this;
248  }
249 
251  size_type size() const
252  {
253  return _container.size();
254  }
255 
258  {
259  _container.resize(size);
260  }
261 
263  void assign(size_type size, const T& value)
264  {
265  _container.assign(size,value);
266  }
267 
270  {
271  return _container;
272  }
273 
275  const BaseContainer& base() const
276  {
277  return _container;
278  }
279 
282  {}
283 
285  explicit LocalVector(size_type n)
286  : _container(n)
287  {}
288 
291  : _container(n,v)
292  {}
293 
294  private:
295 
296  BaseContainer _container;
297 
298  };
299 
300 
301  template<typename C>
303  {
304  return c;
305  }
306 
307  template<typename T, typename Tag, typename W>
309  {
310  return c.base();
311  }
312 
313  template<typename C>
316  {
317  return c.base();
318  }
319 
320  template<typename C>
321  const C& accessBaseContainer(const C& c)
322  {
323  return c;
324  }
325 
326  template<typename T, typename Tag, typename W>
328  {
329  return c.base();
330  }
331 
332  template<typename C>
335  {
336  return c.base();
337  }
338 
343  } // end namespace PDELab
344 } // end namespace Dune
345 
346 #endif // DUNE_PDELAB_GRIDFUNCTIONSPACE_LOCALVECTOR_HH
Dune::PDELab::WeightedVectorAccumulationView::value_type
Container::value_type value_type
The value type of the entries.
Definition: localvector.hh:37
Dune::PDELab::WeightedVectorAccumulationView::modified
bool modified() const
Returns whether this view has been written to.
Definition: localvector.hh:111
Dune::PDELab::WeightedVectorAccumulationView::Container
C Container
The type of the underlying LocalVector.
Definition: localvector.hh:31
Dune::PDELab::WeightedVectorAccumulationView::weight_type
Container::weight_type weight_type
The type of the weight applied when accumulating contributions.
Definition: localvector.hh:40
Dune::PDELab::WeightedVectorAccumulationView::setWeight
void setWeight(weight_type weight)
Resets the weighting coefficient of the view.
Definition: localvector.hh:72
Dune::PDELab::LocalVector
A container for storing data associated with the degrees of freedom of a LocalFunctionSpace.
Definition: localvector.hh:171
Dune::PDELab::WeightedVectorAccumulationView::accumulate
void accumulate(const LFS &lfs, size_type n, value_type v)
Applies the current weight to v and adds the result to the n-th degree of freedom of the lfs.
Definition: localvector.hh:79
Dune::PDELab::LocalVector::operator=
LocalVector & operator=(const value_type &v)
Assigns v to all entries.
Definition: localvector.hh:231
Dune::PDELab::LocalVector::value_type
BaseContainer::value_type value_type
The value type of this container.
Definition: localvector.hh:179
Dune
For backward compatibility – Do not use this!
Definition: adaptivity.hh:28
Dune::PDELab::WeightedVectorAccumulationView::BaseContainer
Container::BaseContainer BaseContainer
The type of the storage container underlying the LocalVector.
Definition: localvector.hh:34
Dune::PDELab::LocalVector::LocalVector
LocalVector()
Default constructor.
Definition: localvector.hh:281
Dune::PDELab::WeightedVectorAccumulationView::weight
weight_type weight()
Returns the weight associated with this view.
Definition: localvector.hh:61
Dune::PDELab::LocalVector::operator()
reference operator()(const LFS &lfs, size_type i)
Access the value in this container associated with the i-th degree of freedom of the LocalFunctionSpa...
Definition: localvector.hh:213
Dune::PDELab::LocalVector::operator*=
LocalVector & operator*=(const value_type &v)
Multiplies all entries by v.
Definition: localvector.hh:238
Dune::PDELab::LocalVector::LocalVector
LocalVector(size_type n, const value_type &v)
Construct a LocalVector with size n and initialize all entries with v.
Definition: localvector.hh:290
localfunctionspacetags.hh
Dune::PDELab::WeightedVectorAccumulationView::weightedAccumulationView
WeightedAccumulationView weightedAccumulationView(weight_type weight)
Returns a WeighedAccumulationView with some weight in addition to this view's weight.
Definition: localvector.hh:48
Dune::PDELab::LocalVector::operator()
const_reference operator()(const LFS &lfs, size_type i) const
Access the value in this container associated with the i-th degree of freedom of the LocalFunctionSpa...
Definition: localvector.hh:225
Dune::PDELab::WeightedVectorAccumulationView::WeightedVectorAccumulationView
WeightedVectorAccumulationView(C &container, weight_type weight)
Constructor.
Definition: localvector.hh:98
Dune::PDELab::LocalVector::resize
void resize(size_type size)
Resize the container.
Definition: localvector.hh:257
Dune::PDELab::LocalVector::BaseContainer
std::vector< T > BaseContainer
The type of the underlying storage container.
Definition: localvector.hh:176
Dune::PDELab::LocalVector::weight_type
W weight_type
The weight type of this container.
Definition: localvector.hh:195
Dune::PDELab::WeightedVectorAccumulationView::size_type
Container::size_type size_type
The size_type of the underlying container.
Definition: localvector.hh:54
Dune::PDELab::LocalVector::weightedAccumulationView
WeightedAccumulationView weightedAccumulationView(weight_type weight)
Returns a WeighedAccumulationView of this container with the given weight.
Definition: localvector.hh:201
Dune::PDELab::WeightedVectorAccumulationView::container
Container & container()
Returns the container (of type LocalVector) that this view is based on.
Definition: localvector.hh:127
Dune::PDELab::WeightedVectorAccumulationView::container
const Container & container() const
Returns the container (of type LocalVector) that this view is based on (const version).
Definition: localvector.hh:134
Dune::PDELab::LocalVector::const_reference
BaseContainer::const_reference const_reference
The const reference type of this container.
Definition: localvector.hh:188
Dune::PDELab::WeightedVectorAccumulationView::WeightedAccumulationView
WeightedVectorAccumulationView WeightedAccumulationView
Export this type for uniform handling of the containers themselves and their views.
Definition: localvector.hh:44
Dune::PDELab::LocalVector::size_type
BaseContainer::size_type size_type
The size type of this container.
Definition: localvector.hh:182
Dune::PDELab::WeightedVectorAccumulationView::size
size_type size() const
Returns the size of the underlying container.
Definition: localvector.hh:105
Dune::PDELab::WeightedVectorAccumulationView
An accumulate-only view on a local vector that automatically takes into account an accumulation weigh...
Definition: localvector.hh:26
Dune::PDELab::WeightedVectorAccumulationView::rawAccumulate
void rawAccumulate(const LFS &lfs, size_type n, value_type v)
Adds v to the n-th degree of freedom of the lfs without applying the current weight.
Definition: localvector.hh:91
Dune::PDELab::accessBaseContainer
C & accessBaseContainer(C &c)
Definition: localvector.hh:302
Dune::PDELab::LocalVector::base
const BaseContainer & base() const
Returns the underlying, std::vector-like storage container (const version).
Definition: localvector.hh:275
Dune::PDELab::LocalVector::assign
void assign(size_type size, const T &value)
Resize the container to size and assign the passed value to all entries.
Definition: localvector.hh:263
Dune::PDELab::LocalVector::base
BaseContainer & base()
Returns the underlying, std::vector-like storage container.
Definition: localvector.hh:269
Dune::PDELab::LocalVector::reference
BaseContainer::reference reference
The reference type of this container.
Definition: localvector.hh:185
Dune::PDELab::LocalVector::LocalVector
LocalVector(size_type n)
Construct a LocalVector with size n.
Definition: localvector.hh:285
value
static const unsigned int value
Definition: gridfunctionspace/tags.hh:139
Dune::PDELab::LocalVector::WeightedAccumulationView
WeightedVectorAccumulationView< LocalVector > WeightedAccumulationView
An accumulate-only view of this container that automatically applies a weight to all contributions.
Definition: localvector.hh:198
Dune::PDELab::LocalVector::size
size_type size() const
The size of the container.
Definition: localvector.hh:251
Dune::PDELab::WeightedVectorAccumulationView::base
BaseContainer & base()
Returns the storage container of the underlying LocalVector.
Definition: localvector.hh:140
Dune::PDELab::WeightedVectorAccumulationView::base
const BaseContainer & base() const
Returns the storage container of the underlying LocalVector (const version).
Definition: localvector.hh:147
Dune::PDELab::WeightedVectorAccumulationView::resetModified
void resetModified()
Resets the modification state of the view to not modified.
Definition: localvector.hh:121