DOFVector.hh 40.3 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"
21
22
23
24

namespace AMDiS {

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

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

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

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

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

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

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

  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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
  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;

      if(!(condition && condition->isDirichlet())) {
	DegreeOfFreedom irow = elVec.dofIndices[i];
	(*this)[irow] = (add ? (*this)[irow] : 0.0);
	(*this)[irow] += factor * elVec[i];
      }
    }
  }

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

130
131
132
    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())
133
      ("size = %d too small: admin->sizeUsed = %d\n", vec.size(),
134
135
136
       feSpace->getAdmin()->getUsedSize());
    
    double nrm = 0.0;
137
138
139
140
141
142
143
144
145
146
147
148
    Iterator vecIterator(dynamic_cast<DOFIndexed<T>*>(const_cast<DOFVector<T>*>(this)), USED_DOFS);
    for(vecIterator.reset(); !vecIterator.end(); ++vecIterator)
      nrm += (*vecIterator) * (*vecIterator);

    return(sqrt(nrm));
  }

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

149
150
151
    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())
152
      ("size = %d too small: admin->sizeUsed = %d\n", vec.size(),
153
154
155
       feSpace->getAdmin()->getUsedSize());
    
    double nrm = 0.0;
156
157
158
159
160
161
162
163
164
165
    Iterator vecIterator(dynamic_cast<DOFIndexed<T>*>(const_cast<DOFVector<T>*>(this)), USED_DOFS);
    for(vecIterator.reset(); !vecIterator.end(); ++vecIterator)
      nrm += (*vecIterator) * (*vecIterator);

    return nrm;
  }

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

168
169
170
171
172
    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());
173

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

    return(nrm);
  }

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

187
188
189
190
191
    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());
192

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

    return(nrm);
  }

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

206
207
208
    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())
209
      ("size = %d too small: admin->sizeUsed = %d\n", vec.size(),
210
211
       feSpace->getAdmin()->getUsedSize());
    
212
213
214
215
216
217
218
219
220
221
    Iterator vecIterator(dynamic_cast<DOFIndexed<T>*>(this), USED_DOFS);
    for(vecIterator.reset(); !vecIterator.end(); ++vecIterator) {
      *vecIterator = alpha ; 
    };
  }


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


  template<typename T>
  T DOFVector<T>::min() const
  {
250
251
252
253
254
    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())
255
      ("size = %d too small: admin->sizeUsed = %d\n", vec.size(), 
256
257
258
       feSpace->getAdmin()->getUsedSize());

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

264
265
266
267
268
269
    return m;
  }

  template<typename T>
  T DOFVector<T>::max() const 
  {
270
271
272
273
274
    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())
275
      ("size = %d too small: admin->sizeUsed = %d\n", vec.size(), 
276
       feSpace->getAdmin()->getUsedSize());
277

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

284
285
286
    return m;
  }

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

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

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

    ysize = y.getSize();

    typename DOFVector<T>::Iterator vecIterator(dynamic_cast<DOFIndexed<T>*>(&y), FREE_DOFS);
    for(vecIterator.reset();
	!vecIterator.end(); ++vecIterator) { 
      *vecIterator = 0;
    };

    if (transpose == NoTranspose) {
      typename DOFVector<T>::Iterator vecIterator(dynamic_cast<DOFIndexed<T>*>(&y), USED_DOFS); 
      DOFMatrix::Iterator rowIterator(const_cast<DOFMatrix*>(&a), USED_DOFS);
      for(vecIterator.reset(), rowIterator.reset();
	  !rowIterator.end();
	  ++rowIterator, ++vecIterator) { 
	sum = 0;
	row = &(a[rowIterator.getDOFIndex()]);
361
	for(std::vector<MatEntry>::iterator colIterator = rowIterator->begin();
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
	    colIterator != rowIterator->end();
	    colIterator++) {
	  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;
      };
    } else if (transpose == Transpose) {
      typename DOFVector<T>::Iterator vecIterator(dynamic_cast<DOFIndexed<T>*>(&y), USED_DOFS);
      for(vecIterator.reset();
	  !vecIterator.end(); 
	  ++vecIterator) {
	*vecIterator  *= beta ; 
      };
    
      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);
      for(xIterator.reset(), rowIterator.reset();
	  !rowIterator.end();
	  ++rowIterator, ++xIterator) { 
	ax = alpha * (*xIterator);
	row = &(a[rowIterator.getDOFIndex()]);
390
	for(std::vector<MatEntry>::iterator colIterator = rowIterator->begin();
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
	    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
  {
409
    FUNCNAME("DOFVector<T>::print()");
410
    const DOFAdmin *admin = NULL;
411
    const char *format;
412

413
414
    if (feSpace) 
      admin = feSpace->getAdmin();
415
416

    MSG("Vec `%s':\n", name.c_str());
417
    int j = 0;
418
419
420
421
422
423
424
425
426
427
428
429
    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);
      for(vecIterator.reset();
	  !vecIterator.end(); ++vecIterator) {
	if ((j % 3) == 0) {
430
431
	  if (j) 
	    Msg::print("\n");
432
	  MSG(format, "", vecIterator.getDOFIndex(), *vecIterator);
433
	} else 
434
435
	  Msg::print(format, " ", vecIterator.getDOFIndex(), *vecIterator);
	j++;
436
      }
437
      Msg::print("\n");
438
    } else {
439
440
	MSG("no DOFAdmin, print whole vector.\n");
    
441
442
443
444
445
446
	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 {
447
	    Msg::print(" (%d,%10.5e)",i,vec[i]);
448
	  }
449
450
451
452
453
454
455
	  j++;
	}
	Msg::print("\n");
      }
    return;
  }

456
457
458
459
460
461
462
463
464
  template<typename T>
  int DOFVector<T>::calcMemoryUsage() const
  {
    int result = 0;
    result += sizeof(DOFVector<T>);
    result += vec.size() * sizeof(T);

    return result;
  }
465
466
467
468
469
470
471
472
473

  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;

474
    for (int i = 0; i < numberOfBasFcts; i++)
475
476
477
478
479
480
481
482
      val += (*this)[dof_indices[i]]*(*phi->getPhi(i))(lambda);

    return val;
  }

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

485
486
487
    TEST_EXIT_DBG(fct)("no function to interpolate\n");

    interFct = fct;
488

489
490
491
492
493
    if (!this->getFESpace()) {
      MSG("no dof admin in vec %s, skipping interpolation\n",
	  this->getName().c_str());
      return;
    }
494

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

507
508
509
510
511
    if (!(fct)) {
      MSG("function that should be interpolated only pointer to NULL, ");
      Msg::print("skipping interpolation\n");
      return;
    }
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547

    traverseVector = this;
    this->getFESpace()->getMesh()->traverse(-1, 
					    Mesh::CALL_LEAF_EL |
					    Mesh::FILL_COORDS, 
					    interpolFct);

    return;
  }

  template<typename T>
  int DOFVector<T>::interpolFct(ElInfo* elinfo)
  {
    int i;
    const BasisFunction *basFct = traverseVector->getFESpace()->getBasisFcts();
    const DOFAdmin* admin = traverseVector->getFESpace()->getAdmin();
    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);

    int number = basFct->getNumber();
    for (i = 0; i < number; i++)
      (*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
548
    FUNCNAME("DOFVector::Int()");
549
550
551
  
    Mesh* mesh = feSpace->getMesh();

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

    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();
578
    uh_vec = traverseVector->getVecAtQPs(elinfo, NULL, quad_fast, NULL);
579
580

    int numPoints = quad_fast->getNumPoints();
581
582
583
    for (normT = iq = 0; iq < numPoints; iq++) {
      normT += quad_fast->getWeight(iq)*(uh_vec[iq]);
    }
584
585
586
587
588
589
590
591
    norm += det*normT;

    return 0;
  }

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

    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
602
    Mesh* mesh = feSpace->getMesh();
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620

    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();
621
    uh_vec = traverseVector->getVecAtQPs(elinfo, NULL, quad_fast, NULL);
622
623

    int numPoints = quad_fast->getNumPoints();
624
625
626
    for (normT = iq = 0; iq < numPoints; iq++) {
      normT += quad_fast->getWeight(iq)*abs(uh_vec[iq]);
    }
627
628
629
630
631
632
633
634
635
    norm += det*normT;

    return 0;
  }


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

Thomas Witkowski's avatar
Thomas Witkowski committed
638
639
640
641
    if (!q) {
      int deg = 2 * feSpace->getBasisFcts()->getDegree();
      q = Quadrature::provideQuadrature(this->dim, deg);
    }
642
643
644
645
646
647
648

    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
649
650
    Mesh* mesh = feSpace->getMesh();
    mesh->traverse(-1, Mesh::CALL_LEAF_EL | Mesh::FILL_COORDS | Mesh::FILL_DET, L2Norm_fct);
651
652
653
654
655
656
657
658
659
660
661
662

    return norm;  
  }

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

    det = elinfo->getDet();
663
    uh_vec = traverseVector->getVecAtQPs(elinfo, NULL, quad_fast, NULL);
664
665

    int numPoints = quad_fast->getNumPoints();
666
667
668
    for (normT = iq = 0; iq < numPoints; iq++) {
      normT += quad_fast->getWeight(iq)*sqr(uh_vec[iq]);
    }
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
699
700
701
702
703
    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
704
    FUNCNAME("DOFVector::H1NormSquare()");
705

Thomas Witkowski's avatar
Thomas Witkowski committed
706
707
708
709
710
711
712
    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);
713
714

    norm = 0.0;
Thomas Witkowski's avatar
Thomas Witkowski committed
715
716
    traverseVector = const_cast<DOFVector<T>*>(this); 
    Mesh *mesh = feSpace->getMesh();
717
718
719
720
721
722
723
724
725
726

    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, 
727
					std::vector<DegreeOfFreedom> &newDOF)
728
  {
Thomas Witkowski's avatar
Thomas Witkowski committed
729
730
731
    for (int i = first; i <= last; i++) {
      if (newDOF[i] >= 0) {
	vec[newDOF[i]] = vec[i];
732
733
734
735
736
737
738
739
740
      }
    }
  }

  template<typename T>
  ElementVector* DOFVectorBase<T>::assemble(T factor, ElInfo *elInfo,
					    const BoundaryType *bound, 
					    Operator *op)
  {
741
    FUNCNAME("DOFVector::assemble()");
742

743
744
    if (!(op || this->operators.size())) 
      return NULL;
745
746
747
748

    Operator *operat = op ? op : this->operators[0];

    this->elementVector = 
749
      operat->getAssembler(omp_get_thread_num())->initElementVector(this->elementVector, elInfo);
750

751
    if (op) {
752
753
      op->getElementVector(elInfo, this->elementVector);
    } else {
754
755
      std::vector<Operator*>::iterator it;
      std::vector<double*>::iterator factorIt;
756
757
758
759
760
761
762
      for (it = this->operators.begin(), factorIt = this->operatorFactor.begin();	
	   it != this->operators.end(); 
	   ++it, ++factorIt) {
	(*it)->getElementVector(elInfo, 
				this->elementVector, 
				*factorIt ? **factorIt : 1.0);
      }
763
764
765
    }

    addElementVector(factor,
766
767
    		     *this->elementVector, 
    		     bound);
768
769
770
771
772
773
774
775

    return this->elementVector;
  }

  template<typename T>
  Flag DOFVectorBase<T>::getAssembleFlag()
  {
    Flag fillFlag(0);
776
    std::vector<Operator*>::iterator op;
777
778
779
780
781
782
783
    for(op = this->operators.begin(); op != this->operators.end(); ++op) {
      fillFlag |= (*op)->getFillFlag();
    }
    return fillFlag;
  }

  template<typename T>
784
785
  DOFVector<T>& DOFVector<T>::operator=(const DOFVector<T>& rhs )
  {
786
787
788
789
790
791
792
    feSpace = rhs.feSpace;
    vec = rhs.vec;
    this->elementVector = NULL;
    interFct = rhs.interFct;
    coarsenOperation = rhs.coarsenOperation;
    this->operators = rhs.operators;
    this->operatorFactor = rhs.operatorFactor;
793
    if (rhs.boundaryManager) {
794
795
      if (this->boundaryManager) 
	delete this->boundaryManager; 
796
      this->boundaryManager = new BoundaryManager(*rhs.boundaryManager);
797

798
      //    boundaryManager->setDOFVector(this);
799
    } else {
800
      this->boundaryManager=NULL;
801
802
    }

803
804
805
806
807
808
    return *this;
  }

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

811
812
    TEST_EXIT_DBG(x.getFESpace() && x.getFESpace()->getAdmin())
      ("pointer is NULL: %8X, %8X\n", x.getFESpace(), x.getFESpace()->getAdmin());
813
814

    typename DOFVector<T>::Iterator vecIterator(dynamic_cast<DOFIndexed<T>*>(&x), USED_DOFS);
815
    for (vecIterator.reset(); !vecIterator.end(); ++vecIterator) {
816
817
      (*vecIterator) *= scal; 
    };
818

819
820
821
822
823
824
825
    return x;
  }


  template<typename T>
  const DOFVector<T>& operator+=(DOFVector<T>& x, const DOFVector<T>& y)
  {
826
827
828
    FUNCNAME("DOFVector<T>::operator+=(DOFVector<T>& x, const DOFVector<T>& y)");
    
    TEST_EXIT_DBG(x.getFESpace() && y.getFESpace())
829
      ("feSpace is NULL: %8X, %8X\n", x.getFESpace(), y.getFESpace());
830
831
    TEST_EXIT_DBG(x.getFESpace()->getAdmin() &&
	      (x.getFESpace()->getAdmin() == y.getFESpace()->getAdmin()))
832
833
      ("no admin or different admins: %8X, %8X\n",
       x.getFESpace()->getAdmin(), y.getFESpace()->getAdmin());
834
835
    TEST_EXIT_DBG(x.getSize() == y.getSize())("different sizes\n");
    
836
837
    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);
838
839
840
841
842
843
    for (xIterator.reset(), yIterator.reset();
	 !xIterator.end();
	 ++xIterator, ++yIterator) {     
      *xIterator += *yIterator; 
    }

844
845
846
847
848
849
    return x;
  }

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

852
    TEST_EXIT_DBG(x.getFESpace() && y.getFESpace())
853
      ("feSpace is NULL: %8X, %8X\n", x.getFESpace(), y.getFESpace());
854
855
    TEST_EXIT_DBG(x.getFESpace()->getAdmin() &&
	      (x.getFESpace()->getAdmin() == y.getFESpace()->getAdmin()))
856
857
      ("no admin or different admins: %8X, %8X\n",
       x.getFESpace()->getAdmin(), y.getFESpace()->getAdmin());
858
859
    TEST_EXIT_DBG(x.getSize() == y.getSize())("different sizes\n");
    
860
861
    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);
862
863
864
865
866
    for (xIterator.reset(), yIterator.reset();
	 !xIterator.end();
	 ++xIterator, ++yIterator) {
      *xIterator -= *yIterator; 
    }
867
868
869
870
871
872
    return x;
  }

  template<typename T>
  const DOFVector<T>& operator*=(DOFVector<T>& x, const DOFVector<T>& y)
  {
873
874
875
    FUNCNAME("DOFVector<T>::operator*=(DOFVector<T>& x, const DOFVector<T>& y)");
    
    TEST_EXIT_DBG(x.getFESpace() && y.getFESpace())
876
      ("feSpace is NULL: %8X, %8X\n", x.getFESpace(), y.getFESpace());
877
878
    TEST_EXIT_DBG(x.getFESpace()->getAdmin() &&
	      (x.getFESpace()->getAdmin() == y.getFESpace()->getAdmin()))
879
880
      ("no admin or different admins: %8X, %8X\n",
       x.getFESpace()->getAdmin(), y.getFESpace()->getAdmin());
881
882
    TEST_EXIT_DBG(x.getSize() == y.getSize())("different sizes\n");
    
883
884
    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);
885
886
887
888
889
    for (xIterator.reset(), yIterator.reset();
	 !xIterator.end();
	 ++xIterator, ++yIterator) {
      *xIterator *= *yIterator; 
    }
890
891
892
893
894
895
896
897
898

    return x;
  }

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

899
    TEST_EXIT_DBG(x.getFESpace() && y.getFESpace())
900
      ("feSpace is NULL: %8X, %8X\n", x.getFESpace(), y.getFESpace());
901
902
    TEST_EXIT_DBG(x.getFESpace()->getAdmin() && 
	      (x.getFESpace()->getAdmin() == y.getFESpace()->getAdmin()))
903
904
      ("no admin or different admins: %8X, %8X\n",
       x.getFESpace()->getAdmin(), y.getFESpace()->getAdmin());
905
    TEST_EXIT_DBG(x.getSize() == y.getSize())("different sizes\n");
906

907
    T dot = 0;    
908
909
910
911
    typename DOFVector<T>::Iterator xIterator(dynamic_cast<DOFIndexed<T>*>(&x), USED_DOFS);
    typename DOFVector<T>::Iterator yIterator(dynamic_cast<DOFIndexed<T>*>(&y), USED_DOFS);
    for (xIterator.reset(), yIterator.reset();
	 !xIterator.end();
912
913
914
	 ++xIterator, ++yIterator) {
      dot += (*xIterator) * (*yIterator);
    };
915
916
917
918
919
920
921
922
923
924
925
926
927

    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()");

928
    TEST_EXIT_DBG(a.getRowFESpace() && a.getColFESpace() && x.getFESpace() && result.getFESpace())
929
930
      ("getFESpace() is NULL: %8X, %8X, %8X, %8X\n", 
       a.getRowFESpace(), a.getColFESpace(), x.getFESpace(), result.getFESpace());
931
932
933
934
935
936
937
938
    
    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()))))
939
940
941
      ("no admin or different admins: %8X, %8X, %8X, %8X\n",
       a.getRowFESpace()->getAdmin(), a.getColFESpace()->getAdmin(), 
       x.getFESpace()->getAdmin(), result.getFESpace()->getAdmin());
942
    
943
    if (transpose == NoTranspose) {
944
      TEST_EXIT_DBG(static_cast<int>(x.getSize()) >= a.getColFESpace()->getAdmin()->getUsedSize())
945
	("x.size = %d too small: admin->sizeUsed = %d\n",
946
947
	 x.getSize(), a.getColFESpace()->getAdmin()->getUsedSize());
      TEST_EXIT_DBG(static_cast<int>( result.getSize()) >= a.getRowFESpace()->getAdmin()->getUsedSize())
948
	("size = %d too small: admin->sizeUsed = %d\n",
949
950
	 result.getSize(), a.getRowFESpace()->getAdmin()->getUsedSize());
      TEST_EXIT_DBG(static_cast<int>( a.getSize()) >= a.getRowFESpace()->getAdmin()->getUsedSize())
951
	("a.size = %d too small: admin->sizeUsed = %d\n",
952
953
	 a.getSize(), a.getRowFESpace()->getAdmin()->getUsedSize());
      
954

Thomas Witkowski's avatar
Thomas Witkowski committed
955
956
957
958
959
960
961
962
963
      typename DOFVector<T>::Iterator vecIterator(dynamic_cast<DOFIndexed<T>*>(&result), USED_DOFS); 
      DOFMatrix::Iterator rowIterator(const_cast<DOFMatrix*>(&a), USED_DOFS);
      for(vecIterator.reset(), rowIterator.reset();
      	  !rowIterator.end();
      	  ++rowIterator, ++vecIterator) { 
      	
	double sum = 0;
      	if (!add) 
	  *vecIterator = 0.0;
964
      	for(std::vector<MatEntry>::iterator colIterator = rowIterator->begin();
Thomas Witkowski's avatar
Thomas Witkowski committed
965
966
967
968
969
970
971
972
973
974
975
976
      	    colIterator != rowIterator->end();
      	    colIterator++) {
      	  
	  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;
977
978
979
      }

    } else if (transpose == Transpose) {
980
      TEST_EXIT_DBG(static_cast<int>(x.getSize()) >= a.getRowFESpace()->getAdmin()->getUsedSize())
981
	("x.size = %d too small: admin->sizeUsed = %d\n",
982
983
	 x.getSize(), a.getRowFESpace()->getAdmin()->getUsedSize());
      TEST_EXIT_DBG(static_cast<int>( result.getSize()) >= a.getColFESpace()->getAdmin()->getUsedSize())
984
	("size = %d too small: admin->sizeUsed = %d\n",
985
986
	 result.getSize(), a.getColFESpace()->getAdmin()->getUsedSize());
      TEST_EXIT_DBG(static_cast<int>( a.getSize()) >= a.getRowFESpace()->getAdmin()->getUsedSize())
987
	("a.size = %d too small: admin->sizeUsed = %d\n",
988
989
	 a.getSize(), a.getRowFESpace()->getAdmin()->getUsedSize());
      
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
      if(!add) {
	typename DOFVector<T>::Iterator vecIterator(dynamic_cast<DOFIndexed<T>*>(&result), USED_DOFS);
	for(vecIterator.reset();
	    !vecIterator.end(); ++vecIterator) {
	  *vecIterator = 0; 
	};
      }

      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);
      for(xIterator.reset(), rowIterator.reset();
	  !rowIterator.end();
	  ++rowIterator, ++xIterator) { 
	T ax = (*xIterator);
1004
	for (std::vector<MatEntry>::iterator colIterator = rowIterator->begin();
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
	    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()");

1026
    TEST_EXIT_DBG(x.getFESpace() && y.getFESpace())
1027
1028
      ("feSpace is NULL: %8X, %8X\n", x.getFESpace(), y.getFESpace());

1029
1030
    TEST_EXIT_DBG(x.getFESpace()->getAdmin() && 
	      (x.getFESpace()->getAdmin() == y.getFESpace()->getAdmin()))
1031
1032
      ("no admin or different admins: %8X, %8X\n",
       x.getFESpace()->getAdmin(), y.getFESpace()->getAdmin());
1033
    TEST_EXIT_DBG(static_cast<int>(x.getSize()) >= x.getFESpace()->getAdmin()->getUsedSize())
1034
      ("size = %d too small: admin->size = %d\n", x.getSize(), 
1035
1036
       x.getFESpace()->getAdmin()->getUsedSize());
    TEST_EXIT_DBG(static_cast<int>(y.getSize()) >= x.getFESpace()->getAdmin()->getUsedSize())
1037
      ("y.size = %d too small: admin->size = %d\n", y.getSize(), 
1038
1039
       x.getFESpace()->getAdmin()->getUsedSize());
    
1040
1041
1042
1043
1044
1045
1046
    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);
    for (xIterator.reset(), yIterator.reset();
	 !xIterator.end();
	 ++xIterator, ++yIterator) {
      *yIterator += alpha * (*xIterator); 
    };
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
  }

  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()");

1078
    TEST_EXIT_DBG(x.getFESpace() && y.getFESpace())
1079
1080
      ("feSpace is NULL: %8X, %8X\n", x.getFESpace(), y.getFESpace());

1081
1082
    TEST_EXIT_DBG(x.getFESpace()->getAdmin() && 
	      (x.getFESpace()->getAdmin() == y.getFESpace()->getAdmin()))
1083
1084
      ("no admin or different admins: %8X, %8X\n",
       x.getFESpace()->getAdmin(), y.getFESpace()->getAdmin());
1085
    TEST_EXIT_DBG(static_cast<int>(x.getSize()) >= x.getFESpace()->getAdmin()->getUsedSize())
1086
      ("size = %d too small: admin->size = %d\n", x.getSize(), 
1087
1088
       x.getFESpace()->getAdmin()->getUsedSize());
    TEST_EXIT_DBG(static_cast<int>(y.getSize()) >= x.getFESpace()->getAdmin()->getUsedSize())
1089
      ("y.size = %d too small: admin->size = %d\n", y.getSize(), 
1090
1091
       x.getFESpace()->getAdmin()->getUsedSize());
    
1092
1093
1094
1095
1096
1097
1098
    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);
    for (xIterator.reset(), yIterator.reset();
	 !xIterator.end();
	 ++xIterator, ++yIterator) {
      *yIterator = alpha *(*yIterator)+ (*xIterator); 
    };
1099
1100
1101
1102
1103
1104
1105
1106
1107
  }

  template<typename T>
  inline const DOFVector<T>& mult(double scal,
				  const DOFVector<T>& v,
				  DOFVector<T>& result)
  {
    typename DOFVector<T>::Iterator vIterator(dynamic_cast<DOFIndexed<T>*>(const_cast<DOFVector<T>*>(&v)), USED_DOFS);
    typename DOFVector<T>::Iterator rIterator(dynamic_cast<DOFIndexed<T>*>(&result), USED_DOFS);
1108
1109
1110
1111
1112
    for (vIterator.reset(), rIterator.reset();
	 !vIterator.end();
	 ++vIterator, ++rIterator) {
      *rIterator = scal * (*vIterator);
    };
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147

    return result;
  }

  template<typename T>
  inline const DOFVector<T>& add(const DOFVector<T>& v,
				 double scal,
				 DOFVector<T>& result)
  {
    typename DOFVector<T>::Iterator vIterator(dynamic_cast<DOFIndexed<T>*>(const_cast<DOFVector<T>*>(&v)), USED_DOFS);
    typename DOFVector<T>::Iterator rIterator(dynamic_cast<DOFIndexed<T>*>(&result), USED_DOFS);
    for(vIterator.reset(), rIterator.reset();
	!vIterator.end();
	++vIterator, ++rIterator) 
      {  
	*rIterator = (*vIterator) + scal;
      };
    return result;
  }

  template<typename T>
  inline const DOFVector<T>& add(const DOFVector<T>& v1,
				 const DOFVector<T>& v2,
				 DOFVector<T>& result)
  {
    typename DOFVector<T>::Iterator v1Iterator(dynamic_cast<DOFIndexed<T>*>(const_cast<DOFVector<T>*>(&v1)), USED_DOFS);
    typename DOFVector<T>::Iterator v2Iterator(dynamic_cast<DOFIndexed<T>*>(const_cast<DOFVector<T>*>(&v2)), USED_DOFS);
    typename DOFVector<T>::Iterator rIterator(dynamic_cast<DOFIndexed<T>*>(&result), USED_DOFS);
    for(v1Iterator.reset(), v2Iterator.reset(), rIterator.reset();
	!v1Iterator.end();
	++v1Iterator, ++v2Iterator, ++</