subVector.hh

Go to the documentation of this file.
1 
6 #ifndef subvector_hh
7 #define subvector_hh
8 
9 #include "vector.hh"
10 #include "space/spaceSet.hh"
11 #include "toolbox/set.hh"
12 
13 namespace concepts {
14 
15  // ************************************************************* SubVector **
16 
27  template<class F>
28  class SubVector : public Function<F> {
29  public:
31  SubVector(Vector<F>& f, const Set<IndexRange>& indices);
32  SubVector(const Vector<F>& f, const Set<IndexRange>& indices);
33 
34  virtual ~SubVector() {}
35 
36  virtual Function<F>& operator=(const Function<F>& fnc);
37 
38  /* Assignement operator from different number type
39 
40  This is extra, because virtual member templates don't exist.
41 
42  The compiler checks, if the assigment is possible, e.g.
43  Cmplx = Real, possible
44  Real = Cmplx, not possible
45  */
46  template<class H>
47  Function<F>& operator=(const Function<H>& fnc);
48 
51 
52  virtual F& operator()(uint i) {
53  conceptsAssert3(i < this->dim_, Assertion(), "i = " << i << ", n = " << this->dim_);
55  return (*v_)(indices_[i]); }
56  virtual F operator()(uint i) const {
57  conceptsAssert3(i < this->dim_, Assertion(), "i = " << i << ", n = " << this->dim_);
58  if (v_)
59  return (*v_)(indices_[i]);
60  return (*vc_)(indices_[i]);
61  }
62 
64  virtual Function<F>& operator+=(const Function<F>& fnc);
65  virtual Function<F>& operator+=(F c);
66 
68  virtual Function<F>& operator-=(const Function<F>& fnc);
69  virtual Function<F>& operator-=(F c);
70 
71  virtual Function<F>& operator*=(F sc);
72 
73  virtual Function<F>& add(const Function<F>& fnc, F sc);
74 
76  uint n() const { return this->dim_; }
77  protected:
78  virtual std::ostream& info(std::ostream& os) const;
79  private:
83  const Vector<F>* vc_;
86  };
87 
88  template<class F>
89  template<class H>
92  uint j = 0;
93  for (Set<IndexRange>::index_iterator i = indices_.index_begin();
94  i != indices_.index_end(); )
95  (*v_)(i++) = fnc(j++);
96  return *this;
97  }
98 
99 } // namespace concepts
100 
101 #endif // subvector_hh
Vector< F > * v_
Vector.
Definition: subVector.hh:81
SubVector< F > & operator=(F c)
Assignement operator.
virtual Function< F > & operator+=(const Function< F > &fnc)
Addition operator.
A sub vector, defined by another vector and an index set.
Definition: subVector.hh:28
uint n() const
Elements in the vector.
Definition: subVector.hh:76
Abstract class for a function.
Definition: basis.hh:21
virtual Function< F > & operator=(const Function< F > &fnc)
Assignment operator.
Set with operations, output operator, and method of the particular element types.
Definition: traces.hh:18
#define conceptsAssert(cond, exc)
Assert that a certain condition is fulfilled.
Definition: exceptions.hh:394
virtual Function< F > & operator+=(F c)
Addition operator.
Exception class for assertions.
Definition: exceptions.hh:258
virtual ~SubVector()
Definition: subVector.hh:34
uint dim_
Dimension of the function (or of the space the function is defined)
Definition: basis.hh:57
SubVector(Vector< F > &f, const Set< IndexRange > &indices)
Constructor.
virtual std::ostream & info(std::ostream &os) const
Returns information in an output stream.
virtual Function< F > & operator-=(F c)
Subtraction operator.
virtual F & operator()(uint i)
Index operator.
Definition: subVector.hh:52
const Vector< F > * vc_
Constant vector.
Definition: subVector.hh:83
virtual F operator()(uint i) const
Index operator.
Definition: subVector.hh:56
virtual Function< F > & operator-=(const Function< F > &fnc)
Subtraction operator.
virtual Function< F > & operator*=(F sc)
Scaling operator.
virtual Function< F > & add(const Function< F > &fnc, F sc)
Adds a times fnc to this function.
#define conceptsAssert3(cond, exc, msg)
Assert that a certain condition is fulfilled.
Definition: exceptions.hh:442
SubVector(const Vector< F > &f, const Set< IndexRange > &indices)
const Set< IndexRange > indices_
Index sets of sub vector.
Definition: subVector.hh:85
Basic namespace for Concepts-2.
Definition: pml_formula.h:16
Page URL: http://wiki.math.ethz.ch/bin/view/Concepts/WebHome
21 August 2020
© 2020 Eidgenössische Technische Hochschule Zürich