Dune Core Modules (2.3.1)

fassign.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_ASSIGN_HH
4#define DUNE_ASSIGN_HH
5
9
10namespace Dune {
11
24 namespace {
25
31 struct Zero {
32 explicit Zero (int) {};
34 operator double () { return 0.0; }
36 operator int () { return 0; }
37 } zero(0);
38
44 struct NextRow {
45 explicit NextRow (int) {};
46 } nextRow(0);
47 } // end empty namespace
48
69 template <class T, int s>
71 {
72 private:
74 int c;
75 bool temporary;
77 public:
79 fvector_assigner(fvector_assigner & a) : v(a.v), c(a.c), temporary(false)
80 {}
85 fvector_assigner(FieldVector<T,s> & _v, bool t) : v(_v), c(0), temporary(t)
86 {};
92 {
93 if (!temporary && c!=s)
94 DUNE_THROW(MathError, "Trying to assign " << c <<
95 " entries to a FieldVector of size " << s);
96 }
98 fvector_assigner & append (const T & t)
99 {
100 v[c++] = t;
101 return *this;
102 }
106 {
108 while (c!=s) v[c++] = 0;
109 return *this;
110 }
116 {
117 return append(t);
118 }
124 {
125 return append(z);
126 }
127 };
128
135 template <class T, class K, int s>
136 fvector_assigner<T,s> operator <<= (FieldVector<T,s> & v, const K & t)
137 {
138 return fvector_assigner<T,s>(v,true).append(t);
139 }
140
146 template <class T, int s>
147 fvector_assigner<T,s> operator <<= (FieldVector<T,s> & v, Zero z)
148 {
149 return fvector_assigner<T,s>(v,true).append(z);
150 }
151
172 template <class T, int n, int m>
174 {
175 private:
177 int c;
178 int r;
179 bool temporary;
180 bool thrown;
181
182 void end_row()
183 {
184 if (!temporary && c!=m && !thrown) {
185 thrown=true;
186 DUNE_THROW(MathError, "Trying to assign " << c <<
187 " entries to a FieldMatrix row of size " << m);
188 }
189 c=0;
190 }
191 public:
193 fmatrix_assigner(fmatrix_assigner & a) : A(a.A), c(a.c), r(a.r), temporary(false), thrown(a.thrown)
194 {}
199 fmatrix_assigner(FieldMatrix<T,n,m> & _A, bool t) : A(_A), c(0), r(0), temporary(t),
200 thrown(false)
201 {};
207 {
208 end_row();
209 if (!temporary && r!=n-1 && !thrown) {
210 thrown=true;
211 DUNE_THROW(MathError, "Trying to assign " << r <<
212 " rows to a FieldMatrix of size " << n << " x " << m);
213 }
214 }
216 fmatrix_assigner & append (const T & t)
217 {
218 // Check whether we have passed the last row
219 if(r>=m) {
220 thrown=true;
221 DUNE_THROW(MathError, "Trying to assign more than " << m <<
222 " rows to a FieldMatrix of size " << n << " x " << m);
223 }
224 A[r][c++] = t;
225 return *this;
226 }
230 {
232 while (c!=m) A[r][c++] = 0;
233 return *this;
234 }
238 {
240 end_row();
241 r++;
242 return *this;
243 }
249 {
250 return append(t);
251 }
257 {
258 return append(z);
259 }
266 {
267 return append(nr);
268 }
269 };
270
277 template <class T, class K, int n, int m>
278 fmatrix_assigner<T,n,m> operator <<= (FieldMatrix<T,n,m> & v, const K & t)
279 {
280 return fmatrix_assigner<T,n,m>(v,true).append(t);
281 }
282
288 template <class T, int n, int m>
289 fmatrix_assigner<T,n,m> operator <<= (FieldMatrix<T,n,m> & v, Zero z)
290 {
291 return fmatrix_assigner<T,n,m>(v,true).append(z);
292 }
293
294} // end namespace Dune
295
296#endif // DUNE_ASSIGN_HH
Default exception class for mathematical errors.
Definition: exceptions.hh:267
fmatrix assignment operator
Definition: fassign.hh:174
fvector assignment operator
Definition: fassign.hh:71
Implements a matrix constructed from a given type representing a field and compile-time given number ...
Implements a vector constructed from a given type representing a field and a compile-time given size.
fvector_assigner(fvector_assigner &a)
Copy Constructor.
Definition: fassign.hh:79
fmatrix_assigner & append(NextRow nr)
move to next row of the matrix
Definition: fassign.hh:237
fmatrix_assigner & append(Zero z)
append zeros to this matrix
Definition: fassign.hh:229
fmatrix_assigner & append(const T &t)
append data to this matrix
Definition: fassign.hh:216
fvector_assigner & append(Zero z)
append zeros to this vector
Definition: fassign.hh:105
~fmatrix_assigner()
Destructor checks for complete initialization of the matrix. The check is skipped,...
Definition: fassign.hh:206
fvector_assigner(FieldVector< T, s > &_v, bool t)
Constructor from vector and temporary flag.
Definition: fassign.hh:85
fmatrix_assigner(fmatrix_assigner &a)
Copy Constructor.
Definition: fassign.hh:193
~fvector_assigner()
Destructor checks for complete initialization of the vector. The check is skipped,...
Definition: fassign.hh:91
fmatrix_assigner & operator,(const T &t)
append data to this matrix the overloaded comma operator is used to assign a comma separated list of ...
Definition: fassign.hh:248
fvector_assigner & operator,(const T &t)
append data to this vector the overloaded comma operator is used to assign a comma separated list of ...
Definition: fassign.hh:115
fvector_assigner< T, s > operator<<=(FieldVector< T, s > &v, const K &t)
fvector assignment operator
Definition: fassign.hh:136
fmatrix_assigner(FieldMatrix< T, n, m > &_A, bool t)
Constructor from matrix and temporary flag.
Definition: fassign.hh:199
fvector_assigner & append(const T &t)
append data to this vector
Definition: fassign.hh:98
#define DUNE_THROW(E, m)
Definition: exceptions.hh:244
Dune namespace.
Definition: alignment.hh:14
Definition of the DUNE_UNUSED macro for the case that config.h is not available.
#define DUNE_UNUSED_PARAMETER(parm)
A macro to mark intentional unused function parameters with.
Definition: unused.hh:18
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Jul 15, 22:36, 2024)