DOFVector.hh 39.4 KB
Newer Older
1
#include <list>
Thomas Witkowski's avatar
Thomas Witkowski committed
2
#include <algorithm>
3
#include <math.h>
4
5
6
7
8
9
10
11
12
13
14
15
16
17

#include "FixVec.h"
#include "Boundary.h"
#include "DOFAdmin.h"
#include "ElInfo.h"
#include "Error.h"
#include "FiniteElemSpace.h"
#include "Global.h"
#include "Mesh.h"
#include "Quadrature.h"
#include "AbstractFunction.h"
#include "BoundaryManager.h"
#include "ElementVector.h"
#include "Assembler.h"
18
#include "OpenMP.h"
19
#include "Operator.h"
20
#include "Parameters.h"
Thomas Witkowski's avatar
Thomas Witkowski committed
21
#include "Traverse.h"
22
23
24
25

namespace AMDiS {

  template<typename T>
26
  DOFVectorBase<T>::DOFVectorBase(const FiniteElemSpace *f, std::string n)
Thomas Witkowski's avatar
Thomas Witkowski committed
27
28
29
30
    : feSpace(f),
      name(n),
      elementVector(NULL),
      boundaryManager(NULL)
31
  {
Thomas Witkowski's avatar
Thomas Witkowski committed
32
    nBasFcts = feSpace->getBasisFcts()->getNumber();
Thomas Witkowski's avatar
Thomas Witkowski committed
33
    dim = feSpace->getMesh()->getDim();
34

35
    localIndices.resize(omp_get_overall_max_threads());
Thomas Witkowski's avatar
Thomas Witkowski committed
36
    localVectors.resize(omp_get_overall_max_threads());
37
    grdPhis.resize(omp_get_overall_max_threads());
Thomas Witkowski's avatar
Thomas Witkowski committed
38
    grdTmp.resize(omp_get_overall_max_threads());
39
    D2Phis.resize(omp_get_overall_max_threads());
40

41
    for (int i = 0; i < omp_get_overall_max_threads(); i++) {
Thomas Witkowski's avatar
Thomas Witkowski committed
42
43
      localIndices[i] = GET_MEMORY(DegreeOfFreedom, this->nBasFcts);
      localVectors[i] = GET_MEMORY(T, this->nBasFcts);
44
      grdPhis[i] = NEW DimVec<double>(dim, DEFAULT_VALUE, 0.0);
Thomas Witkowski's avatar
Thomas Witkowski committed
45
      grdTmp[i] = NEW DimVec<double>(dim, DEFAULT_VALUE, 0.0);
46
      D2Phis[i] = NEW DimMat<double>(dim, NO_INIT);
47
48
    }
  }
Thomas Witkowski's avatar
Thomas Witkowski committed
49
  
50
  template<typename T>
Thomas Witkowski's avatar
Thomas Witkowski committed
51
52
53
54
  DOFVectorBase<T>::~DOFVectorBase()
  {
    for (int i = 0; i < static_cast<int>(localIndices.size()); i++) {
      FREE_MEMORY(localIndices[i], DegreeOfFreedom, this->nBasFcts);
Thomas Witkowski's avatar
Thomas Witkowski committed
55
      FREE_MEMORY(localVectors[i], T, this->nBasFcts);
56
      DELETE grdPhis[i];
Thomas Witkowski's avatar
Thomas Witkowski committed
57
      DELETE grdTmp[i];
58
      DELETE D2Phis[i];
Thomas Witkowski's avatar
Thomas Witkowski committed
59
60
61
62
    }
  }
  
  template<typename T>
63
  DOFVector<T>::DOFVector(const FiniteElemSpace* f, std::string n)
64
    : DOFVectorBase<T>(f, n),
65
      coarsenOperation(NO_OPERATION)
66
67
68
69
70
  {
    init(f, n);
  } 

  template<typename T>
71
  void DOFVector<T>::init(const FiniteElemSpace* f, std::string n)
72
73
74
  {
    name = n;
    feSpace = f;
75
    if (feSpace && feSpace->getAdmin()) {
76
      (feSpace->getAdmin())->addDOFIndexed(this);
Thomas Witkowski's avatar
Thomas Witkowski committed
77
    }
Thomas Witkowski's avatar
Thomas Witkowski committed
78
    this->boundaryManager = NEW BoundaryManager(f);
79
80
81
82
83
  }

  template<typename T>
  DOFVector<T>::~DOFVector()
  {
84
    if (feSpace && feSpace->getAdmin()) {
85
86
87
88
89
90
      (feSpace->getAdmin())->removeDOFIndexed(this);
    }

    if (this->boundaryManager) {
      DELETE this->boundaryManager;
    }
91
92

    vec.clear();
93
94
95
96
97
98
99
100
101
102
103
  }

  template<typename T>
  DOFVector<T> * DOFVector<T>::traverseVector = NULL;

  template<typename T>
  FastQuadrature *DOFVector<T>::quad_fast = NULL;

  template<typename T>
  double DOFVector<T>::norm = 0.0;

Thomas Witkowski's avatar
Thomas Witkowski committed
104
105
106
107
108
109
110
111
112
113
114
115
116
117
  template<typename T>
  void DOFVectorBase<T>::addElementVector(T factor, 
					  const ElementVector &elVec, 
					  const BoundaryType *bound,
					  bool add)
  {
    FUNCNAME("DOFVector::addElementVector()");

    int n_row = elVec.getSize();

    for (DegreeOfFreedom i = 0; i < n_row; i++) {
      BoundaryCondition *condition = 
	bound ? this->getBoundaryManager()->getBoundaryCondition(bound[i]) : NULL;

Thomas Witkowski's avatar
Thomas Witkowski committed
118
      if (!(condition && condition->isDirichlet())) {
Thomas Witkowski's avatar
Thomas Witkowski committed
119
120
121
122
123
124
125
	DegreeOfFreedom irow = elVec.dofIndices[i];
	(*this)[irow] = (add ? (*this)[irow] : 0.0);
	(*this)[irow] += factor * elVec[i];
      }
    }
  }

126
127
128
129
130
  template<typename T>
  double DOFVector<T>::nrm2() const
  {
    FUNCNAME("DOFVector<T>::nrm2()");

131
132
133
    TEST_EXIT_DBG(feSpace)("feSpace is NULL\n");
    TEST_EXIT_DBG(feSpace->getAdmin())("admin is NULL\n");
    TEST_EXIT_DBG(static_cast<int>(vec.size()) >= feSpace->getAdmin()->getUsedSize())
134
      ("size = %d too small: admin->sizeUsed = %d\n", vec.size(),
135
136
137
       feSpace->getAdmin()->getUsedSize());
    
    double nrm = 0.0;
138
    Iterator vecIterator(dynamic_cast<DOFIndexed<T>*>(const_cast<DOFVector<T>*>(this)), USED_DOFS);
Thomas Witkowski's avatar
Thomas Witkowski committed
139
    for (vecIterator.reset(); !vecIterator.end(); ++vecIterator)
140
141
142
143
144
145
146
147
148
149
      nrm += (*vecIterator) * (*vecIterator);

    return(sqrt(nrm));
  }

  template<typename T>
  double DOFVector<T>::squareNrm2() const
  {
    FUNCNAME("DOFVector<T>::nrm2()");

150
151
152
    TEST_EXIT_DBG(feSpace)("feSpace is NULL\n");
    TEST_EXIT_DBG(feSpace->getAdmin())("admin is NULL\n");
    TEST_EXIT_DBG(static_cast<int>(vec.size()) >= feSpace->getAdmin()->getUsedSize())
153
      ("size = %d too small: admin->sizeUsed = %d\n", vec.size(),
154
155
156
       feSpace->getAdmin()->getUsedSize());
    
    double nrm = 0.0;
157
    Iterator vecIterator(dynamic_cast<DOFIndexed<T>*>(const_cast<DOFVector<T>*>(this)), USED_DOFS);
Thomas Witkowski's avatar
Thomas Witkowski committed
158
    for (vecIterator.reset(); !vecIterator.end(); ++vecIterator)
159
160
161
162
163
164
165
166
      nrm += (*vecIterator) * (*vecIterator);

    return nrm;
  }

  template<typename T>
  T DOFVector<T>::asum() const
  {
167
    FUNCNAME("DOFVector<T>::asum()");
168

169
170
171
172
173
    TEST_EXIT_DBG(feSpace)("feSpace is NULL\n");
    TEST_EXIT_DBG(feSpace->getAdmin())("admin is NULL\n");
    TEST_EXIT_DBG(static_cast<int>(vec.size()) >= feSpace->getAdmin()->getUsedSize())
      ("size = %d too small: admin->sizeUsed = %d\n", vec.size(),
       feSpace->getAdmin()->getUsedSize());
174

175
    double nrm = 0.0;
176
    Iterator vecIterator(dynamic_cast<DOFIndexed<T>*>(const_cast<DOFVector<T>*>(this)), USED_DOFS);
Thomas Witkowski's avatar
Thomas Witkowski committed
177
    for (vecIterator.reset(); !vecIterator.end(); ++vecIterator)
178
179
180
181
182
183
184
185
      nrm += abs(*vecIterator);

    return(nrm);
  }

  template<typename T>
  T DOFVector<T>::sum() const
  {
186
    FUNCNAME("DOFVector<T>::sum()");
187

188
189
190
191
192
    TEST_EXIT_DBG(feSpace)("feSpace is NULL\n");
    TEST_EXIT_DBG(feSpace->getAdmin())("admin is NULL\n");
    TEST_EXIT_DBG(static_cast<int>(vec.size()) >= feSpace->getAdmin()->getUsedSize())
      ("size = %d too small: admin->sizeUsed = %d\n", vec.size(),
       feSpace->getAdmin()->getUsedSize());
193

194
    double nrm = 0.0;    
195
    Iterator vecIterator(dynamic_cast<DOFIndexed<T>*>(const_cast<DOFVector<T>*>(this)), USED_DOFS);
Thomas Witkowski's avatar
Thomas Witkowski committed
196
    for (vecIterator.reset(); !vecIterator.end(); ++vecIterator)
197
198
199
200
201
202
203
204
      nrm += *vecIterator;

    return(nrm);
  }

  template<typename T>
  void DOFVector<T>::set(T alpha)
  {
205
    FUNCNAME("DOFVector<T>::set()");
206

207
208
209
    TEST_EXIT_DBG(feSpace)("feSpace is NULL\n");
    TEST_EXIT_DBG(feSpace->getAdmin())("admin is NULL\n");
    TEST_EXIT_DBG(static_cast<int>(vec.size()) >= feSpace->getAdmin()->getUsedSize())
210
      ("size = %d too small: admin->sizeUsed = %d\n", vec.size(),
211
212
       feSpace->getAdmin()->getUsedSize());
    
213
    Iterator vecIterator(dynamic_cast<DOFIndexed<T>*>(this), USED_DOFS);
Thomas Witkowski's avatar
Thomas Witkowski committed
214
    for (vecIterator.reset(); !vecIterator.end(); ++vecIterator) {
215
      *vecIterator = alpha ; 
Thomas Witkowski's avatar
Thomas Witkowski committed
216
    }
217
218
219
220
221
222
  }


  template<typename T>
  void DOFVector<T>::copy(const DOFVector<T>& x)
  {
223
224
225
226
227
    FUNCNAME("DOFVector<T>::copy()");
    
    TEST_EXIT_DBG(feSpace && x.feSpace)
      ("feSpace is NULL: %8X, %8X\n", feSpace, x.feSpace);
    TEST_EXIT_DBG(feSpace->getAdmin() && (feSpace->getAdmin() == x.feSpace->getAdmin()))
228
229
      ("no admin or different admins: %8X, %8X\n",
       feSpace->getAdmin(), x.feSpace->getAdmin());
230
    TEST_EXIT_DBG(static_cast<int>(vec.size()) >= feSpace->getAdmin()->getUsedSize())
231
      ("size = %d too small: admin->sizeUsed = %d\n", vec.size(), 
232
233
       feSpace->getAdmin()->getUsedSize());
    TEST_EXIT_DBG(static_cast<int>(x.vec.size()) >= feSpace->getAdmin()->getUsedSize())
234
      ("x.size = %d too small: admin->sizeUsed = %d\n", x.vec.size(), 
235
236
       feSpace->getAdmin()->getUsedSize());
    
237
238
    Iterator vecIterator(dynamic_cast<DOFIndexed<T>*>(this), USED_DOFS);
    Iterator xIterator(dynamic_cast<DOFVector<T>*>(const_cast<DOFVector<T>*>(&x)), USED_DOFS);
239
240
241
242
243
    for (vecIterator.reset(), xIterator.reset();
	 !vecIterator.end();
	 ++vecIterator, ++xIterator) {
      
      *vecIterator = *xIterator; 
Thomas Witkowski's avatar
Thomas Witkowski committed
244
    }
245
246
247
248
249
250
  }


  template<typename T>
  T DOFVector<T>::min() const
  {
251
252
253
254
255
    FUNCNAME("DOFVector<T>::min()");
    
    TEST_EXIT_DBG(feSpace && feSpace->getAdmin())
      ("pointer is NULL: %8X, %8X\n", this, feSpace->getAdmin());
    TEST_EXIT_DBG((static_cast<int>(vec.size())) >= feSpace->getAdmin()->getUsedSize())
256
      ("size = %d too small: admin->sizeUsed = %d\n", vec.size(), 
257
258
259
       feSpace->getAdmin()->getUsedSize());

    T m;    
260
    Iterator vecIterator(const_cast<DOFIndexed<T>*>(dynamic_cast<const DOFIndexed<T>*>(this)), USED_DOFS);
261
    for (vecIterator.reset(), m = *vecIterator; !vecIterator.end(); ++vecIterator) {
262
      m = std::min(m, *vecIterator);
263
264
    }

265
266
267
268
269
270
    return m;
  }

  template<typename T>
  T DOFVector<T>::max() const 
  {
271
272
273
274
275
    FUNCNAME("DOFVector<T>::max()");
    
    TEST_EXIT_DBG(feSpace && feSpace->getAdmin())
      ("pointer is NULL: %8X, %8X\n", this, feSpace->getAdmin());
    TEST_EXIT_DBG((static_cast<int>(vec.size())) >= feSpace->getAdmin()->getUsedSize())
276
      ("size = %d too small: admin->sizeUsed = %d\n", vec.size(), 
277
       feSpace->getAdmin()->getUsedSize());
278

279
    T m;    
280
    Iterator vecIterator(const_cast<DOFIndexed<T>*>(dynamic_cast<const DOFIndexed<T>*>(this)), USED_DOFS);
281
    for (vecIterator.reset(), m = *vecIterator; !vecIterator.end(); ++vecIterator) {
282
      m = std::max(m, *vecIterator);
283
284
    }

285
286
287
    return m;
  }

Thomas Witkowski's avatar
Thomas Witkowski committed
288
289
290
291
292
293
  template<typename T>
  T DOFVector<T>::absMax() const
  {
    return std::max(abs(max()), abs(min()));
  }

294
295
296
297
298
  template<typename T>
  void gemv(MatrixTranspose transpose, T alpha,
	    const DOFMatrix& a, const DOFVector<T>& x,
	    T beta, DOFVector<T>& y)
  {
299
300
301
302
    FUNCNAME("DOFVector<T>::gemv()");

    int j, jcol, ysize;
    T sum, ax;
303
    const DOFMatrix::MatrixRow *row;
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
    
    TEST_EXIT_DBG(a.getRowFESpace() && 
		  a.getColFESpace() && 
		  x.getFESpace() && 
		  y.getFESpace())
      ("feSpace is NULL: %8X, %8X, %8X, %8X\n", 
       a.getRowFESpace(), a.getColFESpace(), x.getFESpace(), y.getFESpace());
    TEST_EXIT_DBG(a.getRowFESpace()->getAdmin() && 
		  a.getColFESpace()->getAdmin() && 
		  (((transpose == NoTranspose) && 
		    (a.getColFESpace()->getAdmin() == x.getFESpace()->getAdmin()) && 
		    (a.getRowFESpace()->getAdmin() == y.getFESpace()->getAdmin()))||
		   ((transpose == Transpose) && 
		    (a.getRowFESpace()->getAdmin() == x.getFESpace()->getAdmin()) && 
		    (a.getColFESpace()->getAdmin() == y.getFESpace()->getAdmin()))))
319
320
321
      ("no admin or different admins: %8X, %8X, %8X, %8X\n",
       a.getRowFESpace()->getAdmin(), a.getColFESpace()->getAdmin(), 
       x.getFESpace()->getAdmin(), y.getFESpace()->getAdmin());
322
    
323
    if (transpose == NoTranspose) {
324
      TEST_EXIT_DBG(static_cast<int>(x.getSize()) >= a.getColFESpace()->getAdmin()->getUsedSize())
325
	("x.size = %d too small: admin->sizeUsed = %d\n",
326
327
	 x.getSize(), a.getColFESpace()->getAdmin()->getUsedSize());
      TEST_EXIT_DBG(static_cast<int>(y.getSize()) >= a.getRowFESpace()->getAdmin()->getUsedSize())
328
	("y.size = %d too small: admin->sizeUsed = %d\n",
329
330
	 y.getSize(), a.getRowFESpace()->getAdmin()->getUsedSize());
      TEST_EXIT_DBG(static_cast<int>( a.getSize()) >= a.getRowFESpace()->getAdmin()->getUsedSize())
331
	("a.size = %d too small: admin->sizeUsed = %d\n",
332
	a.getSize(), a.getRowFESpace()->getAdmin()->getUsedSize());
333
334
    }
    else  if (transpose == Transpose) {
335
      TEST_EXIT_DBG(static_cast<int>(x.getSize()) >= a.getRowFESpace()->getAdmin()->getUsedSize())
336
	("x.size = %d too small: admin->sizeUsed = %d\n",
337
338
	 x.getSize(), a.getRowFESpace()->getAdmin()->getUsedSize());
      TEST_EXIT_DBG(static_cast<int>(y.getSize()) >= a.getColFESpace()->getAdmin()->getUsedSize())
339
	("y.size = %d too small: admin->sizeUsed = %d\n",
340
341
	 y.getSize(), a.getColFESpace()->getAdmin()->getUsedSize());
      TEST_EXIT_DBG(static_cast<int>( a.getSize()) >= a.getRowFESpace()->getAdmin()->getUsedSize())
342
	("a.size = %d too small: admin->sizeUsed = %d\n",
343
	a.getSize(), a.getRowFESpace()->getAdmin()->getUsedSize());
344
345
346
347
348
    }

    ysize = y.getSize();

    typename DOFVector<T>::Iterator vecIterator(dynamic_cast<DOFIndexed<T>*>(&y), FREE_DOFS);
Thomas Witkowski's avatar
Thomas Witkowski committed
349
    for (vecIterator.reset(); !vecIterator.end(); ++vecIterator) { 
350
      *vecIterator = 0;
Thomas Witkowski's avatar
Thomas Witkowski committed
351
    }
352
353
354
355

    if (transpose == NoTranspose) {
      typename DOFVector<T>::Iterator vecIterator(dynamic_cast<DOFIndexed<T>*>(&y), USED_DOFS); 
      DOFMatrix::Iterator rowIterator(const_cast<DOFMatrix*>(&a), USED_DOFS);
Thomas Witkowski's avatar
Thomas Witkowski committed
356
357
      for (vecIterator.reset(), rowIterator.reset(); !rowIterator.end();
	   ++rowIterator, ++vecIterator) { 
358
359
	sum = 0;
	row = &(a[rowIterator.getDOFIndex()]);
Thomas Witkowski's avatar
Thomas Witkowski committed
360
361
362
	for (std::vector<MatEntry>::iterator colIterator = rowIterator->begin();
	     colIterator != rowIterator->end();
	     colIterator++) {
363
364
365
366
367
368
369
370
371
372
	  jcol = colIterator->col;
	  if (jcol >= 0) { // entry used? 
	    sum += (static_cast<T>(colIterator->entry)) * x[jcol];
	  } else {
	    if (jcol == DOFMatrix::NO_MORE_ENTRIES)
	      break;
	  }
	}
	*vecIterator *= beta;
	*vecIterator += alpha * sum;
Thomas Witkowski's avatar
Thomas Witkowski committed
373
      }
374
375
    } else if (transpose == Transpose) {
      typename DOFVector<T>::Iterator vecIterator(dynamic_cast<DOFIndexed<T>*>(&y), USED_DOFS);
Thomas Witkowski's avatar
Thomas Witkowski committed
376
      for (vecIterator.reset(); !vecIterator.end(); ++vecIterator) {
377
	*vecIterator  *= beta ; 
Thomas Witkowski's avatar
Thomas Witkowski committed
378
      }
379
380
381
    
      typename DOFVector<T>::Iterator xIterator(dynamic_cast<DOFIndexed<T>*>(const_cast<DOFVector<T>*>(&x)), USED_DOFS);
      DOFMatrix::Iterator rowIterator(const_cast<DOFMatrix*>(&a), USED_DOFS);
Thomas Witkowski's avatar
Thomas Witkowski committed
382
383
      for (xIterator.reset(), rowIterator.reset(); !rowIterator.end();
	   ++rowIterator, ++xIterator) { 
384
385
	ax = alpha * (*xIterator);
	row = &(a[rowIterator.getDOFIndex()]);
Thomas Witkowski's avatar
Thomas Witkowski committed
386
	for (std::vector<MatEntry>::iterator colIterator = rowIterator->begin();
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
	    colIterator != rowIterator->end();
	    colIterator++) {
	  jcol = colIterator->col;
	  if (jcol >= 0) // entry used?
	    y[jcol] += ax * (static_cast<T>(colIterator->entry));
	  else 
	    if (jcol == DOFMatrix::NO_MORE_ENTRIES) break;
	}
      }
    }
    else {
      ERROR_EXIT("transpose=%d\n", transpose);
    }
  }

  template<typename T>
  void DOFVector<T>::print() const
  {
405
    FUNCNAME("DOFVector<T>::print()");
406
    const DOFAdmin *admin = NULL;
407
    const char *format;
408

409
410
    if (feSpace) 
      admin = feSpace->getAdmin();
411
412

    MSG("Vec `%s':\n", name.c_str());
413
    int j = 0;
414
415
416
417
418
419
420
421
422
    if (admin) {
      if (admin->getUsedSize() > 100)
	format = "%s(%3d,%10.5le)";
      else if (admin->getUsedSize() > 10)
	format = "%s(%2d,%10.5le)";
      else
	format = "%s(%1d,%10.5le)";

      Iterator vecIterator(dynamic_cast<DOFIndexed<T>*>(const_cast<DOFVector<T>*>(this)), USED_DOFS);
Thomas Witkowski's avatar
Thomas Witkowski committed
423
      for (vecIterator.reset(); !vecIterator.end(); ++vecIterator) {
424
	if ((j % 3) == 0) {
425
426
	  if (j) 
	    Msg::print("\n");
427
	  MSG(format, "", vecIterator.getDOFIndex(), *vecIterator);
Thomas Witkowski's avatar
Thomas Witkowski committed
428
	} else {
429
	  Msg::print(format, " ", vecIterator.getDOFIndex(), *vecIterator);
Thomas Witkowski's avatar
Thomas Witkowski committed
430
	}
431
	j++;
432
      }
433
      Msg::print("\n");
434
    } else {
435
436
	MSG("no DOFAdmin, print whole vector.\n");
    
437
438
439
440
441
442
	for (int i = 0; i < static_cast<int>( vec.size()); i++) {
	  if ((j % 3) == 0) {
	    if (j) 
	      Msg::print("\n");
	    MSG("(%d,%10.5e)",i,vec[i]);
	  } else {
443
	    Msg::print(" (%d,%10.5e)",i,vec[i]);
444
	  }
445
446
447
448
449
450
451
	  j++;
	}
	Msg::print("\n");
      }
    return;
  }

452
453
454
455
456
457
458
459
460
  template<typename T>
  int DOFVector<T>::calcMemoryUsage() const
  {
    int result = 0;
    result += sizeof(DOFVector<T>);
    result += vec.size() * sizeof(T);

    return result;
  }
461
462
463
464
465
466
467
468
469

  template<typename T>
  T DOFVectorBase<T>::evalUh(const DimVec<double>& lambda, 
			     DegreeOfFreedom* dof_indices)
  {
    BasisFunction* phi = const_cast<BasisFunction*>(this->getFESpace()->getBasisFcts());
    int numberOfBasFcts = phi->getNumber();
    T val = 0.0;

470
    for (int i = 0; i < numberOfBasFcts; i++)
471
472
473
474
475
476
477
478
      val += (*this)[dof_indices[i]]*(*phi->getPhi(i))(lambda);

    return val;
  }

  template<typename T>
  void DOFVector<T>::interpol(AbstractFunction<T, WorldVector<double> > *fct)
  {
479
    FUNCNAME("DOFVector<T>::interpol()");
480

481
482
483
    TEST_EXIT_DBG(fct)("no function to interpolate\n");

    interFct = fct;
484

485
486
487
488
489
    if (!this->getFESpace()) {
      MSG("no dof admin in vec %s, skipping interpolation\n",
	  this->getName().c_str());
      return;
    }
490

491
492
493
494
495
    if (!(this->getFESpace()->getAdmin())) {
      MSG("no dof admin in feSpace %s, skipping interpolation\n", 
	  this->getFESpace()->getName().c_str());
      return;
    }
496
  
497
498
499
500
501
    if (!(this->getFESpace()->getBasisFcts())) {
      MSG("no basis functions in admin of vec %s, skipping interpolation\n",
	  this->getName().c_str());
      return;
    }
502

503
504
505
506
507
    if (!(fct)) {
      MSG("function that should be interpolated only pointer to NULL, ");
      Msg::print("skipping interpolation\n");
      return;
    }
508
509
510

    traverseVector = this;

Thomas Witkowski's avatar
Thomas Witkowski committed
511
512
513
514
515
516
517
    TraverseStack stack;
    ElInfo *elInfo = stack.traverseFirst(this->getFESpace()->getMesh(), -1,
					 Mesh::CALL_LEAF_EL | Mesh::FILL_COORDS);
    while (elInfo) {
      interpolFct(elInfo);
      elInfo = stack.traverseNext(elInfo);
    }
518
519
520
521
522
523
524
  }

  template<typename T>
  int DOFVector<T>::interpolFct(ElInfo* elinfo)
  {
    const BasisFunction *basFct = traverseVector->getFESpace()->getBasisFcts();
    const DOFAdmin* admin = traverseVector->getFESpace()->getAdmin();
Thomas Witkowski's avatar
Thomas Witkowski committed
525
526
527
528
529
530
531
    const DegreeOfFreedom *dof =  basFct->getLocalIndices(const_cast<Element *>(elinfo->getElement()),
							  admin, NULL);
    const T *inter_val = const_cast<BasisFunction*>(basFct)->interpol(elinfo, 
								      0, 
								      NULL,
								      traverseVector->interFct, 
								      NULL);
532
533

    int number = basFct->getNumber();
Thomas Witkowski's avatar
Thomas Witkowski committed
534
    for (int i = 0; i < number; i++)
535
536
537
538
539
540
541
542
      (*traverseVector)[dof[i]] = inter_val[i];

    return 0;
  }

  template<typename T>
  double DOFVector<T>::Int(Quadrature* q) const
  {
Thomas Witkowski's avatar
Thomas Witkowski committed
543
    FUNCNAME("DOFVector::Int()");
544
545
546
  
    Mesh* mesh = feSpace->getMesh();

Thomas Witkowski's avatar
Thomas Witkowski committed
547
548
549
550
    if (!q) {
      int deg = 2 * feSpace->getBasisFcts()->getDegree();
      q = Quadrature::provideQuadrature(this->dim, deg);
    }
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572

    quad_fast = FastQuadrature::provideFastQuadrature(feSpace->getBasisFcts(), *q, INIT_PHI);
    norm = 0.0;
    traverseVector = const_cast<DOFVector<T>*>(this);

    mesh->traverse(-1, 
		   Mesh::CALL_LEAF_EL|
		   Mesh::FILL_COORDS |
		   Mesh::FILL_DET, 
		   Int_fct);

    return norm;  
  }

  template<typename T>
  int DOFVector<T>::Int_fct(ElInfo *elinfo)
  {
    double det, normT;
    const T *uh_vec;
    int iq;

    det = elinfo->getDet();
573
    uh_vec = traverseVector->getVecAtQPs(elinfo, NULL, quad_fast, NULL);
574
575

    int numPoints = quad_fast->getNumPoints();
576
577
578
    for (normT = iq = 0; iq < numPoints; iq++) {
      normT += quad_fast->getWeight(iq)*(uh_vec[iq]);
    }
579
580
581
582
583
584
585
586
    norm += det*normT;

    return 0;
  }

  template<typename T>
  double DOFVector<T>::L1Norm(Quadrature* q) const
  {
Thomas Witkowski's avatar
Thomas Witkowski committed
587
    FUNCNAME("DOFVector::L1Norm()");
588
  
Thomas Witkowski's avatar
Thomas Witkowski committed
589
590
591
592
    if (!q) {
      int deg = 2 * feSpace->getBasisFcts()->getDegree();
      q = Quadrature::provideQuadrature(this->dim, deg);
    }
593
594
595
596

    quad_fast = FastQuadrature::provideFastQuadrature(feSpace->getBasisFcts(),*q,INIT_PHI);
    norm = 0.0;
    traverseVector = const_cast<DOFVector<T>*>(this);
Thomas Witkowski's avatar
Thomas Witkowski committed
597
    Mesh* mesh = feSpace->getMesh();
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615

    mesh->traverse(-1, 
		   Mesh::CALL_LEAF_EL|
		   Mesh::FILL_COORDS |
		   Mesh::FILL_DET, 
		   L1Norm_fct);

    return norm;  
  }

  template<typename T>
  int DOFVector<T>::L1Norm_fct(ElInfo *elinfo)
  {
    double det, normT;
    const T *uh_loc, *uh_vec;
    int iq;

    det = elinfo->getDet();
616
    uh_vec = traverseVector->getVecAtQPs(elinfo, NULL, quad_fast, NULL);
617
618

    int numPoints = quad_fast->getNumPoints();
619
620
621
    for (normT = iq = 0; iq < numPoints; iq++) {
      normT += quad_fast->getWeight(iq)*abs(uh_vec[iq]);
    }
622
623
624
625
626
627
628
629
630
    norm += det*normT;

    return 0;
  }


  template<typename T>
  double DOFVector<T>::L2NormSquare(Quadrature* q) const
  {
Thomas Witkowski's avatar
Thomas Witkowski committed
631
    FUNCNAME("DOFVector::L2NormSquare()");
632

Thomas Witkowski's avatar
Thomas Witkowski committed
633
634
635
636
    if (!q) {
      int deg = 2 * feSpace->getBasisFcts()->getDegree();
      q = Quadrature::provideQuadrature(this->dim, deg);
    }
637
638
639
640
641
642
643

    quad_fast = FastQuadrature::provideFastQuadrature(feSpace->getBasisFcts(), 
						      *q, 
						      INIT_PHI);

    norm = 0.0;
    traverseVector = const_cast<DOFVector<T>*>(this);
Thomas Witkowski's avatar
Thomas Witkowski committed
644
645
    Mesh* mesh = feSpace->getMesh();
    mesh->traverse(-1, Mesh::CALL_LEAF_EL | Mesh::FILL_COORDS | Mesh::FILL_DET, L2Norm_fct);
646
647
648
649
650
651
652
653
654
655
656
657

    return norm;  
  }

  template<typename T>
  int DOFVector<T>::L2Norm_fct(ElInfo *elinfo)
  {
    double det, normT;
    const T *uh_vec;
    int iq;

    det = elinfo->getDet();
658
    uh_vec = traverseVector->getVecAtQPs(elinfo, NULL, quad_fast, NULL);
659
660

    int numPoints = quad_fast->getNumPoints();
661
662
663
    for (normT = iq = 0; iq < numPoints; iq++) {
      normT += quad_fast->getWeight(iq)*sqr(uh_vec[iq]);
    }
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
    norm += det*normT;

    return 0;
  }

  template<typename T>
  int DOFVector<T>::H1Norm_fct(ElInfo *elinfo)
  {
    double norm2, normT;
    const WorldVector<T> *grduh_vec;
    int iq, j;

    double det = elinfo->getDet();

    grduh_vec = traverseVector->getGrdAtQPs(elinfo, NULL, quad_fast, NULL);

    int dimOfWorld = Global::getGeo(WORLD);

    int numPoints = quad_fast->getNumPoints();
    for (normT = iq = 0; iq < numPoints; iq++)
      {
	for (norm2 = j = 0; j < dimOfWorld; j++)
	  norm2 += sqr(grduh_vec[iq][j]);

	normT += quad_fast->getWeight(iq)*norm2;
      }
    norm += det*normT;

    return 0;
  }


  template<typename T>
  double DOFVector<T>::H1NormSquare(Quadrature *q) const
  {
Thomas Witkowski's avatar
Thomas Witkowski committed
699
    FUNCNAME("DOFVector::H1NormSquare()");
700

Thomas Witkowski's avatar
Thomas Witkowski committed
701
702
703
704
705
706
707
    if (!q) {
      int deg = 2 * feSpace->getBasisFcts()->getDegree() - 2;
      q = Quadrature::provideQuadrature(this->dim, deg);
    }

    quad_fast = FastQuadrature::provideFastQuadrature(feSpace->getBasisFcts(), 
						      *q, INIT_GRD_PHI);
708
709

    norm = 0.0;
Thomas Witkowski's avatar
Thomas Witkowski committed
710
711
    traverseVector = const_cast<DOFVector<T>*>(this); 
    Mesh *mesh = feSpace->getMesh();
712
713
714
715
716
717
718
719
720
721

    mesh->traverse(-1, Mesh::CALL_LEAF_EL | Mesh::FILL_COORDS | 
		   Mesh::FILL_DET | Mesh::FILL_GRD_LAMBDA,
		   H1Norm_fct);

    return norm;
  }

  template<typename T>
  void DOFVector<T>::compressDOFIndexed(int first, int last, 
722
					std::vector<DegreeOfFreedom> &newDOF)
723
  {
Thomas Witkowski's avatar
Thomas Witkowski committed
724
725
726
    for (int i = first; i <= last; i++) {
      if (newDOF[i] >= 0) {
	vec[newDOF[i]] = vec[i];
727
728
729
730
731
732
733
734
      }
    }
  }

  template<typename T>
  Flag DOFVectorBase<T>::getAssembleFlag()
  {
    Flag fillFlag(0);
735
    std::vector<Operator*>::iterator op;
Thomas Witkowski's avatar
Thomas Witkowski committed
736
    for (op = this->operators.begin(); op != this->operators.end(); ++op) {
737
738
739
740
741
742
      fillFlag |= (*op)->getFillFlag();
    }
    return fillFlag;
  }

  template<typename T>
743
744
  DOFVector<T>& DOFVector<T>::operator=(const DOFVector<T>& rhs )
  {
745
746
747
748
749
750
751
    feSpace = rhs.feSpace;
    vec = rhs.vec;
    this->elementVector = NULL;
    interFct = rhs.interFct;
    coarsenOperation = rhs.coarsenOperation;
    this->operators = rhs.operators;
    this->operatorFactor = rhs.operatorFactor;
752
    if (rhs.boundaryManager) {
753
754
      if (this->boundaryManager) 
	delete this->boundaryManager; 
755
      this->boundaryManager = new BoundaryManager(*rhs.boundaryManager);
756

757
      //    boundaryManager->setDOFVector(this);
758
    } else {
759
      this->boundaryManager=NULL;
760
761
    }

762
763
764
765
766
767
    return *this;
  }

  template<typename T>
  const DOFVector<T>& operator*=(DOFVector<T>& x, T scal)
  {
768
    FUNCNAME("DOFVector<T>::operator*=(DOFVector<T>& x, T scal)");
769

770
771
    TEST_EXIT_DBG(x.getFESpace() && x.getFESpace()->getAdmin())
      ("pointer is NULL: %8X, %8X\n", x.getFESpace(), x.getFESpace()->getAdmin());
772
773

    typename DOFVector<T>::Iterator vecIterator(dynamic_cast<DOFIndexed<T>*>(&x), USED_DOFS);
774
    for (vecIterator.reset(); !vecIterator.end(); ++vecIterator) {
775
      (*vecIterator) *= scal; 
Thomas Witkowski's avatar
Thomas Witkowski committed
776
    }
777

778
779
780
781
782
783
784
    return x;
  }


  template<typename T>
  const DOFVector<T>& operator+=(DOFVector<T>& x, const DOFVector<T>& y)
  {
785
786
787
    FUNCNAME("DOFVector<T>::operator+=(DOFVector<T>& x, const DOFVector<T>& y)");
    
    TEST_EXIT_DBG(x.getFESpace() && y.getFESpace())
788
      ("feSpace is NULL: %8X, %8X\n", x.getFESpace(), y.getFESpace());
789
790
    TEST_EXIT_DBG(x.getFESpace()->getAdmin() &&
	      (x.getFESpace()->getAdmin() == y.getFESpace()->getAdmin()))
791
792
      ("no admin or different admins: %8X, %8X\n",
       x.getFESpace()->getAdmin(), y.getFESpace()->getAdmin());
793
794
    TEST_EXIT_DBG(x.getSize() == y.getSize())("different sizes\n");
    
795
796
    typename DOFVector<T>::Iterator xIterator(dynamic_cast<DOFIndexed<T>*>(&x), USED_DOFS);
    typename DOFVector<T>::Iterator yIterator(dynamic_cast<DOFIndexed<T>*>(const_cast<DOFVector<T>*>(&y)), USED_DOFS);
797
798
799
800
801
802
    for (xIterator.reset(), yIterator.reset();
	 !xIterator.end();
	 ++xIterator, ++yIterator) {     
      *xIterator += *yIterator; 
    }

803
804
805
806
807
808
    return x;
  }

  template<typename T>
  const DOFVector<T>& operator-=(DOFVector<T>& x, const DOFVector<T>& y)
  {
809
    FUNCNAME("DOFVector<T>::operator-=(DOFVector<T>& x, const DOFVector<T>& y)");
810

811
    TEST_EXIT_DBG(x.getFESpace() && y.getFESpace())
812
      ("feSpace is NULL: %8X, %8X\n", x.getFESpace(), y.getFESpace());
813
814
    TEST_EXIT_DBG(x.getFESpace()->getAdmin() &&
	      (x.getFESpace()->getAdmin() == y.getFESpace()->getAdmin()))
815
816
      ("no admin or different admins: %8X, %8X\n",
       x.getFESpace()->getAdmin(), y.getFESpace()->getAdmin());
817
818
    TEST_EXIT_DBG(x.getSize() == y.getSize())("different sizes\n");
    
819
820
    typename DOFVector<T>::Iterator xIterator(dynamic_cast<DOFIndexed<T>*>(&x), USED_DOFS);
    typename DOFVector<T>::Iterator yIterator(dynamic_cast<DOFIndexed<T>*>(const_cast<DOFVector<T>*>(&y)), USED_DOFS);
821
822
823
824
825
    for (xIterator.reset(), yIterator.reset();
	 !xIterator.end();
	 ++xIterator, ++yIterator) {
      *xIterator -= *yIterator; 
    }
826
827
828
829
830
831
    return x;
  }

  template<typename T>
  const DOFVector<T>& operator*=(DOFVector<T>& x, const DOFVector<T>& y)
  {
832
833
834
    FUNCNAME("DOFVector<T>::operator*=(DOFVector<T>& x, const DOFVector<T>& y)");
    
    TEST_EXIT_DBG(x.getFESpace() && y.getFESpace())
835
      ("feSpace is NULL: %8X, %8X\n", x.getFESpace(), y.getFESpace());
836
837
    TEST_EXIT_DBG(x.getFESpace()->getAdmin() &&
	      (x.getFESpace()->getAdmin() == y.getFESpace()->getAdmin()))
838
839
      ("no admin or different admins: %8X, %8X\n",
       x.getFESpace()->getAdmin(), y.getFESpace()->getAdmin());
840
841
    TEST_EXIT_DBG(x.getSize() == y.getSize())("different sizes\n");
    
842
843
    typename DOFVector<T>::Iterator xIterator(dynamic_cast<DOFIndexed<T>*>(&x), USED_DOFS);
    typename DOFVector<T>::Iterator yIterator(dynamic_cast<DOFIndexed<T>*>(const_cast<DOFVector<T>*>(&y)), USED_DOFS);
844
845
846
847
848
    for (xIterator.reset(), yIterator.reset();
	 !xIterator.end();
	 ++xIterator, ++yIterator) {
      *xIterator *= *yIterator; 
    }
849
850
851
852
853
854
855
856
857

    return x;
  }

  template<typename T>
  T operator*(DOFVector<T>& x, DOFVector<T>& y)
  {
    FUNCNAME("DOFVector<T>::operator*(DOFVector<T>& x, DOFVector<T>& y)");

858
    TEST_EXIT_DBG(x.getFESpace() && y.getFESpace())
859
      ("feSpace is NULL: %8X, %8X\n", x.getFESpace(), y.getFESpace());
860
861
    TEST_EXIT_DBG(x.getFESpace()->getAdmin() && 
	      (x.getFESpace()->getAdmin() == y.getFESpace()->getAdmin()))
862
863
      ("no admin or different admins: %8X, %8X\n",
       x.getFESpace()->getAdmin(), y.getFESpace()->getAdmin());
864
    TEST_EXIT_DBG(x.getSize() == y.getSize())("different sizes\n");
865

866
    T dot = 0;    
867
868
    typename DOFVector<T>::Iterator xIterator(dynamic_cast<DOFIndexed<T>*>(&x), USED_DOFS);
    typename DOFVector<T>::Iterator yIterator(dynamic_cast<DOFIndexed<T>*>(&y), USED_DOFS);
Thomas Witkowski's avatar
Thomas Witkowski committed
869
    for (xIterator.reset(), yIterator.reset(); !xIterator.end(); 
870
871
	 ++xIterator, ++yIterator) {
      dot += (*xIterator) * (*yIterator);
Thomas Witkowski's avatar
Thomas Witkowski committed
872
    }
873
874
875
876
877
878
879
880
881
882
883
884
885

    return(dot);
  }

  template<typename T>
  void mv(MatrixTranspose transpose,
	  const DOFMatrix &a, 
	  const DOFVector<T>&x,
	  DOFVector<T> &result,
	  bool add)
  {
    FUNCNAME("DOFVector<T>::mv()");

886
    TEST_EXIT_DBG(a.getRowFESpace() && a.getColFESpace() && x.getFESpace() && result.getFESpace())
887
888
      ("getFESpace() is NULL: %8X, %8X, %8X, %8X\n", 
       a.getRowFESpace(), a.getColFESpace(), x.getFESpace(), result.getFESpace());
889
890
891
892
893
894
895
896
    
    TEST_EXIT_DBG((a.getRowFESpace()->getAdmin() && a.getColFESpace()->getAdmin()) && 
	      (((transpose == NoTranspose) && 
		(a.getColFESpace()->getAdmin() == x.getFESpace()->getAdmin()) && 
		(a.getRowFESpace()->getAdmin() == result.getFESpace()->getAdmin())) ||
	       ((transpose == Transpose) && 
		(a.getRowFESpace()->getAdmin() == x.getFESpace()->getAdmin()) && 
		(a.getColFESpace()->getAdmin() == result.getFESpace()->getAdmin()))))
897
898
899
      ("no admin or different admins: %8X, %8X, %8X, %8X\n",
       a.getRowFESpace()->getAdmin(), a.getColFESpace()->getAdmin(), 
       x.getFESpace()->getAdmin(), result.getFESpace()->getAdmin());
900
    
901
    if (transpose == NoTranspose) {
902
      TEST_EXIT_DBG(static_cast<int>(x.getSize()) >= a.getColFESpace()->getAdmin()->getUsedSize())
903
	("x.size = %d too small: admin->sizeUsed = %d\n",
904
905
	 x.getSize(), a.getColFESpace()->getAdmin()->getUsedSize());
      TEST_EXIT_DBG(static_cast<int>( result.getSize()) >= a.getRowFESpace()->getAdmin()->getUsedSize())
906
	("size = %d too small: admin->sizeUsed = %d\n",
907
908
	 result.getSize(), a.getRowFESpace()->getAdmin()->getUsedSize());
      TEST_EXIT_DBG(static_cast<int>( a.getSize()) >= a.getRowFESpace()->getAdmin()->getUsedSize())
909
	("a.size = %d too small: admin->sizeUsed = %d\n",
910
911
	 a.getSize(), a.getRowFESpace()->getAdmin()->getUsedSize());
      
912

Thomas Witkowski's avatar
Thomas Witkowski committed
913
914
      typename DOFVector<T>::Iterator vecIterator(dynamic_cast<DOFIndexed<T>*>(&result), USED_DOFS); 
      DOFMatrix::Iterator rowIterator(const_cast<DOFMatrix*>(&a), USED_DOFS);
Thomas Witkowski's avatar
Thomas Witkowski committed
915
      for (vecIterator.reset(), rowIterator.reset(); !rowIterator.end();
Thomas Witkowski's avatar
Thomas Witkowski committed
916
917
918
919
920
      	  ++rowIterator, ++vecIterator) { 
      	
	double sum = 0;
      	if (!add) 
	  *vecIterator = 0.0;
Thomas Witkowski's avatar
Thomas Witkowski committed
921
922
923
      	for (std::vector<MatEntry>::iterator colIterator = rowIterator->begin();
	     colIterator != rowIterator->end();
	     colIterator++) {
Thomas Witkowski's avatar
Thomas Witkowski committed
924
925
926
927
928
929
930
931
932
933
      	  
	  int jcol = colIterator->col;
      	  if (jcol >= 0) { // entry used? 
      	    sum += (static_cast<double>(colIterator->entry)) * x[jcol];
      	  } else {
      	    if (jcol == DOFMatrix::NO_MORE_ENTRIES)
      	      break;
      	  }
      	}
      	*vecIterator += sum;
934
935
936
      }

    } else if (transpose == Transpose) {
937
      TEST_EXIT_DBG(static_cast<int>(x.getSize()) >= a.getRowFESpace()->getAdmin()->getUsedSize())
938
	("x.size = %d too small: admin->sizeUsed = %d\n",
939
940
	 x.getSize(), a.getRowFESpace()->getAdmin()->getUsedSize());
      TEST_EXIT_DBG(static_cast<int>( result.getSize()) >= a.getColFESpace()->getAdmin()->getUsedSize())
941
	("size = %d too small: admin->sizeUsed = %d\n",
942
943
	 result.getSize(), a.getColFESpace()->getAdmin()->getUsedSize());
      TEST_EXIT_DBG(static_cast<int>( a.getSize()) >= a.getRowFESpace()->getAdmin()->getUsedSize())
944
	("a.size = %d too small: admin->sizeUsed = %d\n",
945
946
	 a.getSize(), a.getRowFESpace()->getAdmin()->getUsedSize());
      
Thomas Witkowski's avatar
Thomas Witkowski committed
947
      if (!add) {
948
	typename DOFVector<T>::Iterator vecIterator(dynamic_cast<DOFIndexed<T>*>(&result), USED_DOFS);
Thomas Witkowski's avatar
Thomas Witkowski committed
949
	for (vecIterator.reset(); !vecIterator.end(); ++vecIterator) {
950
	  *vecIterator = 0; 
Thomas Witkowski's avatar
Thomas Witkowski committed
951
	}
952
953
954
955
      }

      typename DOFVector<T>::Iterator xIterator(const_cast<DOFIndexed<T>*>(dynamic_cast<const DOFIndexed<T>*>(&x)), USED_DOFS);
      DOFMatrix::Iterator rowIterator(const_cast<DOFMatrix*>(&a), USED_DOFS);
Thomas Witkowski's avatar
Thomas Witkowski committed
956
957
      for (xIterator.reset(), rowIterator.reset(); !rowIterator.end();
	   ++rowIterator, ++xIterator) { 
958
	T ax = (*xIterator);
959
	for (std::vector<MatEntry>::iterator colIterator = rowIterator->begin();
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
	    colIterator != rowIterator->end();
	    colIterator++) {
	  int jcol = colIterator->col;
	  if (jcol >= 0) // entry used?
	    result[jcol] += (static_cast<double>(colIterator->entry)) * ax;
	  else 
	    if (jcol == DOFMatrix::NO_MORE_ENTRIES) break;
	}
      }
    } else {
      ERROR_EXIT("transpose = %d\n", transpose);
    }
  }

  template<typename T>
  void axpy(double alpha, 
	    const DOFVector<T>& x, 
	    DOFVector<T>& y)
  {
    FUNCNAME("DOFVector<T>::axpy()");

981
    TEST_EXIT_DBG(x.getFESpace() && y.getFESpace())
982
983
      ("feSpace is NULL: %8X, %8X\n", x.getFESpace(), y.getFESpace());

984
985
    TEST_EXIT_DBG(x.getFESpace()->getAdmin() && 
	      (x.getFESpace()->getAdmin() == y.getFESpace()->getAdmin()))
986
987
      ("no admin or different admins: %8X, %8X\n",
       x.getFESpace()->getAdmin(), y.getFESpace()->getAdmin());
988
    TEST_EXIT_DBG(static_cast<int>(x.getSize()) >= x.getFESpace()->getAdmin()->getUsedSize())
989
      ("size = %d too small: admin->size = %d\n", x.getSize(), 
990
991
       x.getFESpace()->getAdmin()->getUsedSize());
    TEST_EXIT_DBG(static_cast<int>(y.getSize()) >= x.getFESpace()->getAdmin()->getUsedSize())
992
      ("y.size = %d too small: admin->size = %d\n", y.getSize(), 
993
994
       x.getFESpace()->getAdmin()->getUsedSize());
    
995
996
    typename DOFVector<T>::Iterator xIterator(dynamic_cast<DOFIndexed<T>*>(const_cast<DOFVector<T>*>(&x)), USED_DOFS);
    typename DOFVector<T>::Iterator yIterator(dynamic_cast<DOFIndexed<T>*>(&y), USED_DOFS);
Thomas Witkowski's avatar
Thomas Witkowski committed
997
    for (xIterator.reset(), yIterator.reset(); !xIterator.end();
998
999
	 ++xIterator, ++yIterator) {
      *yIterator += alpha * (*xIterator); 
Thomas Witkowski's avatar
Thomas Witkowski committed
1000
    }
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
  }

  template<typename T>
  const DOFVector<T>& operator*(const DOFVector<T>& v, double d)
  {
    static DOFVector<T> result;
    return mult(d, v, result);
  }

  template<typename T>
  const DOFVector<T>& operator*(double d, const DOFVector<T>& v)
  {
    static DOFVector<T> result;
    return mult(d, v, result);
  }

  template<typename T>
  const DOFVector<T>& operator+(const DOFVector<T> &v1 , const DOFVector<T> &v2)
  {
    static DOFVector<T> result;
    return add(v1, v2, result);
  }


  template<typename T>
  void xpay(double alpha, 
	    const DOFVector<T>& x, 
	    DOFVector<T>& y)
  {
    FUNCNAME("DOFVector<T>::xpay()");