1 #ifndef DUNE_FEM_VECTOR_HH 2 #define DUNE_FEM_VECTOR_HH 4 #include <dune/common/math.hh> 5 #include <dune/common/typetraits.hh> 6 #include <dune/common/bartonnackmanifcheck.hh> 7 #include <dune/common/fvector.hh> 70 VectorType& operator= (
const ThisType &v );
73 VectorType &operator= (
const FieldType s );
76 const FieldType &operator[] (
unsigned int index )
const;
79 FieldType &operator[] (
unsigned int index );
90 VectorType &operator*= (
const FieldType s );
94 VectorType &addScaled (
const FieldType s,
108 void assign (
const FieldType s );
114 ConstIteratorType begin ()
const;
117 IteratorType begin ();
120 ConstIteratorType end ()
const;
126 unsigned int size ()
const;
129 using BaseType::asImp;
133 template<
class Vector >
137 static const bool v = Conversion< Vector, VectorInterfaceType >::exists;
141 template<
class V,
class W >
147 static_assert( (Conversion< FieldType, typename W::FieldType >::sameType),
148 "FieldType must be identical." );
153 template<
class Field,
class Vector >
172 template<
class Field,
class Vector >
193 const unsigned int size = this->size();
194 assert( size == v.
size() );
195 for(
unsigned int i = 0; i < size; ++i )
196 (*
this)[ i ] += v[ i ];
204 const unsigned int size = this->size();
205 assert( size == v.
size() );
206 for(
unsigned int i = 0; i < size; ++i )
207 (*
this)[ i ] -= v[ i ];
212 VectorType &operator*= (
const FieldType s )
214 const unsigned int size = this->size();
215 for(
unsigned int i = 0; i < size; ++i )
224 const unsigned int size = this->size();
225 assert( size == v.
size() );
226 for(
unsigned int i = 0; i < size; ++i )
227 (*
this)[ i ] += s * v[ i ];
235 const unsigned int size = this->size();
236 assert( size == v.
size() );
237 for(
unsigned int i = 0; i < size; ++i )
238 asImp()[ i ] = v[ i ];
244 const unsigned int size = this->size();
245 for(
unsigned int i = 0; i < size; ++i )
269 ConstIteratorType
end ()
const 280 using BaseType :: size;
283 using BaseType :: asImp;
291 template<
class FieldVectorImp >
294 template<
class Field,
int sz >
296 :
public VectorDefault< Field, FieldVectorAdapter< FieldVector< Field, sz > > >
306 using BaseType :: operator+=;
307 using BaseType :: operator-=;
308 using BaseType :: addScaled;
309 using BaseType :: assign;
335 : fieldVector_( other.fieldVector_ )
339 operator const FieldVectorType & ()
const 344 operator FieldVectorType & ()
356 ThisType &operator= (
const ThisType &v )
362 ThisType &operator= (
const FieldType &s )
367 const FieldType &operator[] (
unsigned int index )
const 369 return fieldVector_[ index ];
372 FieldType &operator[] (
unsigned int index )
374 return fieldVector_[ index ];
377 ThisType &operator+= (
const ThisType &v )
383 ThisType &operator+= (
const FieldVectorType &v )
389 ThisType &operator-= (
const ThisType &v )
395 ThisType &operator-= (
const FieldVectorType &v )
401 ThisType &operator*= (
const FieldType &s )
407 ThisType &
addScaled (
const FieldType &s,
const ThisType &other )
425 return FieldVectorType::dimension;
428 static const ThisType &
adapt (
const FieldVectorType &v )
430 return reinterpret_cast< const ThisType &
>( v );
433 static ThisType &
adapt ( FieldVectorType &v )
435 return reinterpret_cast< ThisType &
>( v );
442 template<
class FieldImp >
444 :
public VectorDefault< FieldImp, ArrayWrapperVector< FieldImp > >
455 using BaseType :: assign;
464 FieldType *
const fields )
472 FieldType *
const fields,
483 FieldType *
const fields,
500 inline ThisType &operator= (
const ThisType &v )
507 inline ThisType &operator= (
const FieldType s )
513 inline const FieldType &operator[] (
unsigned int index )
const 515 assert( index < size_ );
516 return fields_[ index ];
519 inline FieldType &operator[] (
unsigned int index )
521 assert( index < size_ );
522 return fields_[ index ];
525 inline unsigned int size ()
const 540 template<
class Field,
543 :
public VectorDefault< Field, DynamicVector< Field, ArrayAllocator > >
552 using BaseType :: assign;
595 inline ThisType &operator= (
const ThisType &v )
602 inline ThisType &operator= (
const FieldType s )
608 inline const FieldType &operator[] (
unsigned int index )
const 610 return fields_[ index ];
613 inline FieldType &operator[] (
unsigned int index )
615 return fields_[ index ];
640 inline void resize (
unsigned int newSize )
642 fields_.
resize( newSize );
645 inline void resize (
unsigned int newSize,
646 const FieldType defaultValue )
648 fields_.
resize( newSize, defaultValue );
651 inline unsigned int size ()
const 653 return fields_.
size();
662 template<
class FieldImp,
int sz >
664 :
public VectorDefault< FieldImp, StaticVector< FieldImp, sz > >
675 using BaseType :: assign;
678 FieldType fields_[ sz ];
714 inline ThisType &operator= (
const ThisType &v )
721 inline ThisType &operator= (
const FieldType s )
727 inline const FieldType &operator[] (
unsigned int index )
const 729 assert( index < sz );
730 return fields_[ index ];
733 inline FieldType &operator[] (
unsigned int index )
735 assert( index < sz );
736 return fields_[ index ];
739 inline unsigned int size ()
const 746 template<
class Vector1Type,
class Vector2Type >
748 :
public VectorDefault< typename ExtractCommonFieldType< Vector1Type, Vector2Type >::FieldType,
749 CombinedVector< Vector1Type, Vector2Type > >
766 const FieldType &operator[] (
unsigned int index )
const 768 const int index2 = index - vector1_.size();
770 return vector1_[ index ];
772 return vector2_[ index2 ];
775 FieldType &operator[] (
unsigned int index )
777 const int index2 = index - vector1_.size();
779 return vector1_[ index ];
781 return vector2_[ index2 ];
786 return vector1_.size() + vector2_.size();
799 namespace Capabilities
802 template<
class Field,
template<
class >
class ArrayAllocator >
804 :
public MetaBool< true >
817 #endif // #ifndef DUNE_FEM_VECTOR_HH implementation of VectorInterface using a C++ array embedded info the class to provide the fields ...
Definition: vector.hh:663
void clear()
initialize the vector to 0
Definition: vector.hh:250
FieldVector< FieldType, sz > FieldVectorType
Definition: vector.hh:304
V::FieldType FieldType
Definition: vector.hh:144
Field FieldType
Definition: vector.hh:156
FieldVectorAdapter()
Definition: vector.hh:315
ExtractCommonFieldType< Vector1Type, Vector2Type >::FieldType FieldType
Definition: vector.hh:754
IteratorType end()
obtain end iterator
Definition: vector.hh:275
VT::IteratorType IteratorType
Definition: vector.hh:31
unsigned int size() const
Definition: array.hh:617
Traits::VectorType VectorType
type of the implementation (Barton-Nackman)
Definition: vector.hh:52
DynamicVector(unsigned int size=0)
Constructor setting up a vector of a specified size.
Definition: vector.hh:559
BaseType::VectorInterfaceType VectorInterfaceType
Definition: vector.hh:182
IteratorType begin()
obtain begin iterator
Definition: vector.hh:263
unsigned int size() const
Returns the vector's size.
Definition: vector_inline.hh:144
unsigned int size() const
Definition: vector.hh:784
ThisType VectorInterfaceType
type of this interface
Definition: vector.hh:49
unsigned int size() const
Definition: vector.hh:739
void assign(const VectorInterface< T > &v)
copy another vector to this one
Definition: vector.hh:620
FieldVectorAdapter(const FieldType &s)
Definition: vector.hh:319
StaticVector(const FieldType s)
Constructor setting up a vector initialized to a constant value.
Definition: vector.hh:687
FieldImp FieldType
field type of vector
Definition: vector.hh:448
default implementation of VectorInterface
Definition: vector.hh:173
unsigned int size() const
Definition: vector.hh:525
ElementType * leakPointer()
Definition: array.hh:579
DynamicVector(const ThisType &v)
Copy constructor setting up a vector with the data of another one (of the same type) ...
Definition: vector.hh:580
FieldVectorAdapter(const VectorInterface< T > &v)
Definition: vector.hh:328
BaseType::VectorType VectorType
Definition: vector.hh:183
const FieldType * leakPointer() const
Definition: vector.hh:625
Field FieldType
field type of the vector
Definition: vector.hh:550
void reserve(unsigned int newSize)
Definition: array.hh:589
An implementation of VectorInterface wrapping a standard C++ array.
Definition: vector.hh:443
DynamicVector(const VectorInterface< T > &v)
Copy constructor setting up a vector with the data of another one.
Definition: vector.hh:573
StaticVector(const VectorInterface< T > &v)
Copy constructor setting up a vector with the data of another one.
Definition: vector.hh:694
const unsigned int size_
Definition: vector.hh:458
DynamicVector(unsigned int size, const FieldType s)
Constructor setting up a vector iniitialized with a constant value.
Definition: vector.hh:564
ThisType & addScaled(const FieldType &s, const ThisType &other)
Definition: vector.hh:407
Definition: vector.hh:154
ArrayDefaultIterator< const FieldType, const VectorType > ConstIteratorType
Definition: vector.hh:160
ArrayDefaultIterator< FieldType, VectorType > IteratorType
Definition: vector.hh:159
VectorInterface< typename Vector::Traits > VectorInterfaceType
Definition: vector.hh:136
BaseType::ConstIteratorType ConstIteratorType
Definition: vector.hh:185
Definition: vector.hh:747
FieldType * leakPointer()
Definition: vector.hh:630
FieldType *const fields_
Definition: vector.hh:459
CombinedVector(Vector1Type &v1, Vector2Type &v2)
Definition: vector.hh:761
void assign(const ThisType &other)
Definition: vector.hh:413
void assign(const FieldType s)
Initialize all fields of this vector with a scalar.
Definition: vector.hh:242
void assign(const FieldType &s)
Definition: vector.hh:418
void resize(unsigned int newSize, const FieldType defaultValue)
Definition: vector.hh:645
unsigned int size() const
Definition: vector.hh:651
Definition: vector.hh:295
VectorType & addScaled(const FieldType s, const VectorInterface< T > &v)
Add a multiple of another vector to this one.
Definition: vector.hh:222
FieldType value_type
Definition: vector.hh:56
Definition: coordinate.hh:4
StaticVector(const ThisType &v)
Copy constructor setting up a vector with the data of another one.
Definition: vector.hh:700
FieldVectorAdapter(const FieldVectorType &v)
Definition: vector.hh:323
Definition: vector.hh:134
Definition: vector.hh:142
VT::VectorType ArrayType
Definition: vector.hh:27
Field FieldType
Definition: vector.hh:302
void assign(const VectorInterface< T > &v)
copy another vector to this one
Definition: vector.hh:233
An abstract vector interface.
Definition: vector.hh:37
StaticVector()
Constructor setting up an uninitialized vector.
Definition: vector.hh:682
static const ThisType & adapt(const FieldVectorType &v)
Definition: vector.hh:428
unsigned int size() const
Definition: vector.hh:423
void resize(unsigned int newSize)
Definition: vector.hh:640
ConstIteratorType begin() const
obtain begin iterator
Definition: vector.hh:257
Traits::ConstIteratorType ConstIteratorType
type of constant iterator
Definition: vector.hh:59
Vector1Type & vector1_
Definition: vector.hh:790
VT::FieldType ElementType
Definition: vector.hh:28
ArrayWrapperVector(const unsigned int size, FieldType *const fields, const FieldType s)
Constructor setting up the vector and initializing the fields to a constant value.
Definition: vector.hh:471
ConstIteratorType end() const
obtain end iterator
Definition: vector.hh:269
ArrayWrapperVector(const unsigned int size, FieldType *const fields)
Constructor setting up the vector (without initializing the fields)
Definition: vector.hh:463
Vector VectorType
Definition: vector.hh:157
void assign(const ArrayInterface< T > &other)
copy another array to this one
Definition: array.hh:572
FieldImp FieldType
field type of vector
Definition: vector.hh:668
DynamicArray< FieldType, ArrayAllocator > fields_
Definition: vector.hh:555
BaseType::FieldType FieldType
Definition: vector.hh:180
Definition: vector.hh:292
BaseType::IteratorType IteratorType
Definition: vector.hh:186
FieldVectorAdapter(const ThisType &other)
Definition: vector.hh:334
abstract array interface
Definition: array.hh:23
static ThisType & adapt(FieldVectorType &v)
Definition: vector.hh:433
void reserve(unsigned int newSize)
Definition: vector.hh:635
void resize(unsigned int newSize)
Definition: array.hh:594
FieldVectorType fieldVector_
Definition: vector.hh:312
Vector2Type & vector2_
Definition: vector.hh:791
VT Traits
Definition: vector.hh:46
VT::ConstIteratorType ConstIteratorType
Definition: vector.hh:30
Traits::IteratorType IteratorType
type of iterator
Definition: vector.hh:62
A vector using a DynamicArray as storage.
Definition: vector.hh:542
ArrayWrapperVector(const unsigned int size, FieldType *const fields, const VectorInterface< T > &v)
Copy constructor setting up a vector with the data of another one.
Definition: vector.hh:482
Definition: arrayallocator.hh:112
Traits::FieldType FieldType
field type for the vector
Definition: vector.hh:55