DOFVector.hh 38.7 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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <boost/numeric/mtl/mtl.hpp>
#include <boost/numeric/mtl/utility/tag.hpp>
#include <boost/numeric/mtl/utility/category.hpp>
#include <boost/numeric/linear_algebra/identity.hpp>


// Defining the interface for MTL4
namespace mtl {

  // Let MTL4 know that DOFVector it is a column vector
  namespace traits {
    template <typename T>
    struct category< AMDiS::DOFVector<T> > 
    {
      typedef tag::dense_col_vector type;
    };
  }

  namespace ashape {
    template <typename T>
    struct ashape< AMDiS::DOFVector<T> > 
    {
      typedef cvec<typename ashape<T>::type> type;
    };
  }

  // Modelling Collection and MutableCollection
  template <typename T>
  struct Collection< AMDiS::DOFVector<T> > 
  {
    typedef T               value_type;
    typedef const T&        const_reference;
    typedef std::size_t     size_type;
  };

  template <typename T>
  struct MutableCollection< AMDiS::DOFVector<T> > 
    : public Collection< AMDiS::DOFVector<T> > 
  {
    typedef T&              reference;
  };


} // namespace mtl



70
71
72
namespace AMDiS {

  template<typename T>
73
  DOFVectorBase<T>::DOFVectorBase(const FiniteElemSpace *f, std::string n)
Thomas Witkowski's avatar
Thomas Witkowski committed
74
75
    : feSpace(f),
      name(n),
76
      elementVector(NULL),
Thomas Witkowski's avatar
Thomas Witkowski committed
77
      boundaryManager(NULL)
78
  {
Thomas Witkowski's avatar
Thomas Witkowski committed
79
    nBasFcts = feSpace->getBasisFcts()->getNumber();
Thomas Witkowski's avatar
Thomas Witkowski committed
80
    dim = feSpace->getMesh()->getDim();
81

82
    localIndices.resize(omp_get_overall_max_threads());
Thomas Witkowski's avatar
Thomas Witkowski committed
83
    localVectors.resize(omp_get_overall_max_threads());
84
    grdPhis.resize(omp_get_overall_max_threads());
Thomas Witkowski's avatar
Thomas Witkowski committed
85
    grdTmp.resize(omp_get_overall_max_threads());
86
    D2Phis.resize(omp_get_overall_max_threads());
87

88
    for (int i = 0; i < omp_get_overall_max_threads(); i++) {
Thomas Witkowski's avatar
Thomas Witkowski committed
89
90
      localIndices[i] = GET_MEMORY(DegreeOfFreedom, this->nBasFcts);
      localVectors[i] = GET_MEMORY(T, this->nBasFcts);
91
      grdPhis[i] = NEW DimVec<double>(dim, DEFAULT_VALUE, 0.0);
Thomas Witkowski's avatar
Thomas Witkowski committed
92
      grdTmp[i] = NEW DimVec<double>(dim, DEFAULT_VALUE, 0.0);
93
      D2Phis[i] = NEW DimMat<double>(dim, NO_INIT);
94
    }
95
96

    elementVector = NEW ElementVector(this->nBasFcts);
97
  }
Thomas Witkowski's avatar
Thomas Witkowski committed
98
  
99
  template<typename T>
Thomas Witkowski's avatar
Thomas Witkowski committed
100
101
102
103
  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
104
      FREE_MEMORY(localVectors[i], T, this->nBasFcts);
105
      DELETE grdPhis[i];
Thomas Witkowski's avatar
Thomas Witkowski committed
106
      DELETE grdTmp[i];
107
      DELETE D2Phis[i];
Thomas Witkowski's avatar
Thomas Witkowski committed
108
109
110
111
    }
  }
  
  template<typename T>
112
  DOFVector<T>::DOFVector(const FiniteElemSpace* f, std::string n)
113
    : DOFVectorBase<T>(f, n),
114
      //elementVector(NULL), 
115
      coarsenOperation(NO_OPERATION)
116
117
  {
    init(f, n);
118
119
120
121

#ifdef HAVE_PARALLEL_AMDIS
    applicationOrdering = NULL;
#endif
122
123
124
  } 

  template<typename T>
125
  void DOFVector<T>::init(const FiniteElemSpace* f, std::string n)
126
127
128
  {
    name = n;
    feSpace = f;
129
    if(feSpace && feSpace->getAdmin()) {
130
      (feSpace->getAdmin())->addDOFIndexed(this);
Thomas Witkowski's avatar
Thomas Witkowski committed
131
    }
Thomas Witkowski's avatar
Thomas Witkowski committed
132
    this->boundaryManager = NEW BoundaryManager(f);
133
134
135
136
137
  }

  template<typename T>
  DOFVector<T>::~DOFVector()
  {
138
    if(feSpace && feSpace->getAdmin()) {
139
140
141
142
143
144
      (feSpace->getAdmin())->removeDOFIndexed(this);
    }

    if (this->boundaryManager) {
      DELETE this->boundaryManager;
    }
145
146

    vec.clear();
147
148
149
150
151
152
153
154
155
156
157
  }

  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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
  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
172
      if (!(condition && condition->isDirichlet())) {
Thomas Witkowski's avatar
Thomas Witkowski committed
173
174
175
176
177
178
179
	DegreeOfFreedom irow = elVec.dofIndices[i];
	(*this)[irow] = (add ? (*this)[irow] : 0.0);
	(*this)[irow] += factor * elVec[i];
      }
    }
  }

180
181
182
183
184
  template<typename T>
  double DOFVector<T>::nrm2() const
  {
    FUNCNAME("DOFVector<T>::nrm2()");

185
186
187
    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())
188
      ("size = %d too small: admin->sizeUsed = %d\n", vec.size(),
189
190
191
       feSpace->getAdmin()->getUsedSize());
    
    double nrm = 0.0;
192
    Iterator vecIterator(dynamic_cast<DOFIndexed<T>*>(const_cast<DOFVector<T>*>(this)), USED_DOFS);
Thomas Witkowski's avatar
Thomas Witkowski committed
193
    for (vecIterator.reset(); !vecIterator.end(); ++vecIterator)
194
195
196
197
198
199
200
201
202
203
      nrm += (*vecIterator) * (*vecIterator);

    return(sqrt(nrm));
  }

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

204
205
206
    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())
207
      ("size = %d too small: admin->sizeUsed = %d\n", vec.size(),
208
209
210
       feSpace->getAdmin()->getUsedSize());
    
    double nrm = 0.0;
211
    Iterator vecIterator(dynamic_cast<DOFIndexed<T>*>(const_cast<DOFVector<T>*>(this)), USED_DOFS);
Thomas Witkowski's avatar
Thomas Witkowski committed
212
    for (vecIterator.reset(); !vecIterator.end(); ++vecIterator)
213
214
215
216
217
218
219
220
      nrm += (*vecIterator) * (*vecIterator);

    return nrm;
  }

  template<typename T>
  T DOFVector<T>::asum() const
  {
221
    FUNCNAME("DOFVector<T>::asum()");
222

223
224
225
226
227
    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());
228

229
    double nrm = 0.0;
230
    Iterator vecIterator(dynamic_cast<DOFIndexed<T>*>(const_cast<DOFVector<T>*>(this)), USED_DOFS);
Thomas Witkowski's avatar
Thomas Witkowski committed
231
    for (vecIterator.reset(); !vecIterator.end(); ++vecIterator)
232
233
234
235
236
237
238
239
      nrm += abs(*vecIterator);

    return(nrm);
  }

  template<typename T>
  T DOFVector<T>::sum() const
  {
240
    FUNCNAME("DOFVector<T>::sum()");
241

242
243
244
245
246
    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());
247

248
    double nrm = 0.0;    
249
    Iterator vecIterator(dynamic_cast<DOFIndexed<T>*>(const_cast<DOFVector<T>*>(this)), USED_DOFS);
Thomas Witkowski's avatar
Thomas Witkowski committed
250
    for (vecIterator.reset(); !vecIterator.end(); ++vecIterator)
251
252
253
254
255
256
257
258
      nrm += *vecIterator;

    return(nrm);
  }

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

261
262
263
    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())
264
      ("size = %d too small: admin->sizeUsed = %d\n", vec.size(),
265
266
       feSpace->getAdmin()->getUsedSize());
    
267
    Iterator vecIterator(dynamic_cast<DOFIndexed<T>*>(this), USED_DOFS);
Thomas Witkowski's avatar
Thomas Witkowski committed
268
    for (vecIterator.reset(); !vecIterator.end(); ++vecIterator) {
269
      *vecIterator = alpha ; 
Thomas Witkowski's avatar
Thomas Witkowski committed
270
    }
271
272
273
274
275
276
  }


  template<typename T>
  void DOFVector<T>::copy(const DOFVector<T>& x)
  {
277
278
279
280
281
    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()))
282
283
      ("no admin or different admins: %8X, %8X\n",
       feSpace->getAdmin(), x.feSpace->getAdmin());
284
    TEST_EXIT_DBG(static_cast<int>(vec.size()) >= feSpace->getAdmin()->getUsedSize())
285
      ("size = %d too small: admin->sizeUsed = %d\n", vec.size(), 
286
287
       feSpace->getAdmin()->getUsedSize());
    TEST_EXIT_DBG(static_cast<int>(x.vec.size()) >= feSpace->getAdmin()->getUsedSize())
288
      ("x.size = %d too small: admin->sizeUsed = %d\n", x.vec.size(), 
289
290
       feSpace->getAdmin()->getUsedSize());
    
291
292
    Iterator vecIterator(dynamic_cast<DOFIndexed<T>*>(this), USED_DOFS);
    Iterator xIterator(dynamic_cast<DOFVector<T>*>(const_cast<DOFVector<T>*>(&x)), USED_DOFS);
293
294
295
296
297
    for (vecIterator.reset(), xIterator.reset();
	 !vecIterator.end();
	 ++vecIterator, ++xIterator) {
      
      *vecIterator = *xIterator; 
Thomas Witkowski's avatar
Thomas Witkowski committed
298
    }
299
300
301
302
303
304
  }


  template<typename T>
  T DOFVector<T>::min() const
  {
305
306
307
308
309
    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())
310
      ("size = %d too small: admin->sizeUsed = %d\n", vec.size(), 
311
312
313
       feSpace->getAdmin()->getUsedSize());

    T m;    
314
    Iterator vecIterator(const_cast<DOFIndexed<T>*>(dynamic_cast<const DOFIndexed<T>*>(this)), USED_DOFS);
315
    for (vecIterator.reset(), m = *vecIterator; !vecIterator.end(); ++vecIterator) {
316
      m = std::min(m, *vecIterator);
317
318
    }

319
320
321
322
323
324
    return m;
  }

  template<typename T>
  T DOFVector<T>::max() const 
  {
325
326
327
328
329
    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())
330
      ("size = %d too small: admin->sizeUsed = %d\n", vec.size(), 
331
       feSpace->getAdmin()->getUsedSize());
332

333
    T m;    
334
    Iterator vecIterator(const_cast<DOFIndexed<T>*>(dynamic_cast<const DOFIndexed<T>*>(this)), USED_DOFS);
335
    for (vecIterator.reset(), m = *vecIterator; !vecIterator.end(); ++vecIterator) {
336
      m = std::max(m, *vecIterator);
337
338
    }

339
340
341
    return m;
  }

Thomas Witkowski's avatar
Thomas Witkowski committed
342
343
344
345
346
347
  template<typename T>
  T DOFVector<T>::absMax() const
  {
    return std::max(abs(max()), abs(min()));
  }

348
349
350
351
352
  template<typename T>
  void gemv(MatrixTranspose transpose, T alpha,
	    const DOFMatrix& a, const DOFVector<T>& x,
	    T beta, DOFVector<T>& y)
  {
353
354
355
356
    FUNCNAME("DOFVector<T>::gemv()");

    int j, jcol, ysize;
    T sum, ax;
357
    const DOFMatrix::MatrixRow *row;
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
    
    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()))))
373
374
375
      ("no admin or different admins: %8X, %8X, %8X, %8X\n",
       a.getRowFESpace()->getAdmin(), a.getColFESpace()->getAdmin(), 
       x.getFESpace()->getAdmin(), y.getFESpace()->getAdmin());
376
    
377
    if (transpose == NoTranspose) {
378
      TEST_EXIT_DBG(static_cast<int>(x.getSize()) >= a.getColFESpace()->getAdmin()->getUsedSize())
379
	("x.size = %d too small: admin->sizeUsed = %d\n",
380
381
	 x.getSize(), a.getColFESpace()->getAdmin()->getUsedSize());
      TEST_EXIT_DBG(static_cast<int>(y.getSize()) >= a.getRowFESpace()->getAdmin()->getUsedSize())
382
	("y.size = %d too small: admin->sizeUsed = %d\n",
383
384
	 y.getSize(), a.getRowFESpace()->getAdmin()->getUsedSize());
      TEST_EXIT_DBG(static_cast<int>( a.getSize()) >= a.getRowFESpace()->getAdmin()->getUsedSize())
385
	("a.size = %d too small: admin->sizeUsed = %d\n",
386
	a.getSize(), a.getRowFESpace()->getAdmin()->getUsedSize());
387
388
    }
    else  if (transpose == Transpose) {
389
      TEST_EXIT_DBG(static_cast<int>(x.getSize()) >= a.getRowFESpace()->getAdmin()->getUsedSize())
390
	("x.size = %d too small: admin->sizeUsed = %d\n",
391
392
	 x.getSize(), a.getRowFESpace()->getAdmin()->getUsedSize());
      TEST_EXIT_DBG(static_cast<int>(y.getSize()) >= a.getColFESpace()->getAdmin()->getUsedSize())
393
	("y.size = %d too small: admin->sizeUsed = %d\n",
394
395
	 y.getSize(), a.getColFESpace()->getAdmin()->getUsedSize());
      TEST_EXIT_DBG(static_cast<int>( a.getSize()) >= a.getRowFESpace()->getAdmin()->getUsedSize())
396
	("a.size = %d too small: admin->sizeUsed = %d\n",
397
	a.getSize(), a.getRowFESpace()->getAdmin()->getUsedSize());
398
399
    }

400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
    // Create MTL vector as wrapper of y
    mtl::vector::dense_vector<double>   yy(y.getSize(), &y[0]);
    DOFMatrix::base_matrix_type&        A= a.getBaseMatrix();

    if (transpose == NoTranspose) 
	yy= alpha*A*x + beta*yy;
    else if (transpose == Transpose)
	yy= alpha*trans(A)*x + beta*yy;
    else 
      ERROR_EXIT("transpose=%d\n", transpose);


#if 0

    //ysize = y.getSize();
415
416

    typename DOFVector<T>::Iterator vecIterator(dynamic_cast<DOFIndexed<T>*>(&y), FREE_DOFS);
Thomas Witkowski's avatar
Thomas Witkowski committed
417
    for (vecIterator.reset(); !vecIterator.end(); ++vecIterator) { 
418
      *vecIterator = 0;
Thomas Witkowski's avatar
Thomas Witkowski committed
419
    }
420
421
422
423

    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
424
425
      for (vecIterator.reset(), rowIterator.reset(); !rowIterator.end();
	   ++rowIterator, ++vecIterator) { 
426
427
	sum = 0;
	row = &(a[rowIterator.getDOFIndex()]);
Thomas Witkowski's avatar
Thomas Witkowski committed
428
429
430
	for (std::vector<MatEntry>::iterator colIterator = rowIterator->begin();
	     colIterator != rowIterator->end();
	     colIterator++) {
431
432
433
434
435
436
437
438
439
440
	  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
441
      }
442
443
    } else if (transpose == Transpose) {
      typename DOFVector<T>::Iterator vecIterator(dynamic_cast<DOFIndexed<T>*>(&y), USED_DOFS);
Thomas Witkowski's avatar
Thomas Witkowski committed
444
      for (vecIterator.reset(); !vecIterator.end(); ++vecIterator) {
445
	*vecIterator  *= beta ; 
Thomas Witkowski's avatar
Thomas Witkowski committed
446
      }
447
448
449
    
      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
450
451
      for (xIterator.reset(), rowIterator.reset(); !rowIterator.end();
	   ++rowIterator, ++xIterator) { 
452
453
	ax = alpha * (*xIterator);
	row = &(a[rowIterator.getDOFIndex()]);
Thomas Witkowski's avatar
Thomas Witkowski committed
454
	for (std::vector<MatEntry>::iterator colIterator = rowIterator->begin();
455
456
457
458
459
460
461
462
463
464
465
466
467
	    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);
    }
468
469
#endif

470
471
472
473
474
  }

  template<typename T>
  void DOFVector<T>::print() const
  {
475
    FUNCNAME("DOFVector<T>::print()");
476
    const DOFAdmin *admin = NULL;
477
    const char *format;
478

479
480
    if (feSpace) 
      admin = feSpace->getAdmin();
481
482

    MSG("Vec `%s':\n", name.c_str());
483
    int j = 0;
484
485
486
487
488
489
490
491
492
    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
493
      for (vecIterator.reset(); !vecIterator.end(); ++vecIterator) {
494
	if ((j % 3) == 0) {
495
496
	  if (j) 
	    Msg::print("\n");
497
	  MSG(format, "", vecIterator.getDOFIndex(), *vecIterator);
Thomas Witkowski's avatar
Thomas Witkowski committed
498
	} else {
499
	  Msg::print(format, " ", vecIterator.getDOFIndex(), *vecIterator);
Thomas Witkowski's avatar
Thomas Witkowski committed
500
	}
501
	j++;
502
      }
503
      Msg::print("\n");
504
    } else {
505
506
	MSG("no DOFAdmin, print whole vector.\n");
    
507
508
509
510
511
512
	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 {
513
	    Msg::print(" (%d,%10.5e)",i,vec[i]);
514
	  }
515
516
517
518
519
520
521
	  j++;
	}
	Msg::print("\n");
      }
    return;
  }

522
523
524
525
526
527
528
529
530
  template<typename T>
  int DOFVector<T>::calcMemoryUsage() const
  {
    int result = 0;
    result += sizeof(DOFVector<T>);
    result += vec.size() * sizeof(T);

    return result;
  }
531
532
533
534
535
536
537
538
539

  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;

540
    for (int i = 0; i < numberOfBasFcts; i++)
541
542
543
544
545
546
547
548
      val += (*this)[dof_indices[i]]*(*phi->getPhi(i))(lambda);

    return val;
  }

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

551
552
553
    TEST_EXIT_DBG(fct)("no function to interpolate\n");

    interFct = fct;
554

555
556
557
558
559
    if (!this->getFESpace()) {
      MSG("no dof admin in vec %s, skipping interpolation\n",
	  this->getName().c_str());
      return;
    }
560

561
562
563
564
565
    if (!(this->getFESpace()->getAdmin())) {
      MSG("no dof admin in feSpace %s, skipping interpolation\n", 
	  this->getFESpace()->getName().c_str());
      return;
    }
566
  
567
568
569
570
571
    if (!(this->getFESpace()->getBasisFcts())) {
      MSG("no basis functions in admin of vec %s, skipping interpolation\n",
	  this->getName().c_str());
      return;
    }
572

573
574
575
576
577
    if (!(fct)) {
      MSG("function that should be interpolated only pointer to NULL, ");
      Msg::print("skipping interpolation\n");
      return;
    }
578
579
580

    traverseVector = this;

Thomas Witkowski's avatar
Thomas Witkowski committed
581
582
583
584
585
586
587
    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);
    }
588
589
590
591
592
593
594
  }

  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
595
596
597
598
599
600
601
    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);
602
603

    int number = basFct->getNumber();
Thomas Witkowski's avatar
Thomas Witkowski committed
604
    for (int i = 0; i < number; i++)
605
606
607
608
609
610
611
612
      (*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
613
    FUNCNAME("DOFVector::Int()");
614
615
616
  
    Mesh* mesh = feSpace->getMesh();

Thomas Witkowski's avatar
Thomas Witkowski committed
617
618
619
620
    if (!q) {
      int deg = 2 * feSpace->getBasisFcts()->getDegree();
      q = Quadrature::provideQuadrature(this->dim, deg);
    }
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642

    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();
643
    uh_vec = traverseVector->getVecAtQPs(elinfo, NULL, quad_fast, NULL);
644
645

    int numPoints = quad_fast->getNumPoints();
646
647
648
    for (normT = iq = 0; iq < numPoints; iq++) {
      normT += quad_fast->getWeight(iq)*(uh_vec[iq]);
    }
649
650
651
652
653
654
655
656
    norm += det*normT;

    return 0;
  }

  template<typename T>
  double DOFVector<T>::L1Norm(Quadrature* q) const
  {
Thomas Witkowski's avatar
Thomas Witkowski committed
657
    FUNCNAME("DOFVector::L1Norm()");
658
  
Thomas Witkowski's avatar
Thomas Witkowski committed
659
660
661
662
    if (!q) {
      int deg = 2 * feSpace->getBasisFcts()->getDegree();
      q = Quadrature::provideQuadrature(this->dim, deg);
    }
663
664
665
666

    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
667
    Mesh* mesh = feSpace->getMesh();
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685

    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();
686
    uh_vec = traverseVector->getVecAtQPs(elinfo, NULL, quad_fast, NULL);
687
688

    int numPoints = quad_fast->getNumPoints();
689
690
691
    for (normT = iq = 0; iq < numPoints; iq++) {
      normT += quad_fast->getWeight(iq)*abs(uh_vec[iq]);
    }
692
693
694
695
696
697
698
699
700
    norm += det*normT;

    return 0;
  }


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

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

    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
714
715
    Mesh* mesh = feSpace->getMesh();
    mesh->traverse(-1, Mesh::CALL_LEAF_EL | Mesh::FILL_COORDS | Mesh::FILL_DET, L2Norm_fct);
716
717
718
719
720
721
722
723
724
725
726
727

    return norm;  
  }

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

    det = elinfo->getDet();
728
    uh_vec = traverseVector->getVecAtQPs(elinfo, NULL, quad_fast, NULL);
729
730

    int numPoints = quad_fast->getNumPoints();
731
732
733
    for (normT = iq = 0; iq < numPoints; iq++) {
      normT += quad_fast->getWeight(iq)*sqr(uh_vec[iq]);
    }
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
    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
769
    FUNCNAME("DOFVector::H1NormSquare()");
770

Thomas Witkowski's avatar
Thomas Witkowski committed
771
772
773
774
775
776
777
    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);
778
779

    norm = 0.0;
Thomas Witkowski's avatar
Thomas Witkowski committed
780
781
    traverseVector = const_cast<DOFVector<T>*>(this); 
    Mesh *mesh = feSpace->getMesh();
782
783
784
785
786
787
788
789
790
791

    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, 
792
					std::vector<DegreeOfFreedom> &newDOF)
793
  {
Thomas Witkowski's avatar
Thomas Witkowski committed
794
795
    for (int i = first; i <= last; i++)
      if (newDOF[i] >= 0)
Thomas Witkowski's avatar
Thomas Witkowski committed
796
	vec[newDOF[i]] = vec[i];
797
798
799
800
801
802
  }

  template<typename T>
  Flag DOFVectorBase<T>::getAssembleFlag()
  {
    Flag fillFlag(0);
Thomas Witkowski's avatar
Thomas Witkowski committed
803
804
805
    
    for (std::vector<Operator*>::iterator op = this->operators.begin(); 
	 op != this->operators.end(); ++op) {
806
807
      fillFlag |= (*op)->getFillFlag();
    }
Thomas Witkowski's avatar
Thomas Witkowski committed
808

809
810
811
    return fillFlag;
  }

Thomas Witkowski's avatar
Thomas Witkowski committed
812
813
814
815
816
817
818
819
820
821
  template<typename T>
  void DOFVectorBase<T>::finishAssembling()
  {
    // call the operatos cleanup procedures
    for (std::vector<Operator*>::iterator it = this->operators.begin();
	 it != this->operators.end(); ++it) {     
      (*it)->finishAssembling();
    }
  }

822
  template<typename T>
823
824
  DOFVector<T>& DOFVector<T>::operator=(const DOFVector<T>& rhs )
  {
825
    feSpace = rhs.feSpace;
826
    DOFVectorBase<T>::feSpace = rhs.feSpace;
827
    this->nBasFcts = rhs.nBasFcts;
828
    vec = rhs.vec;
829
    this->elementVector = new ElementVector(this->nBasFcts);
830
831
832
833
    interFct = rhs.interFct;
    coarsenOperation = rhs.coarsenOperation;
    this->operators = rhs.operators;
    this->operatorFactor = rhs.operatorFactor;
834
    if (rhs.boundaryManager) {
835
836
      if (this->boundaryManager) 
	delete this->boundaryManager; 
837
      this->boundaryManager = new BoundaryManager(*rhs.boundaryManager);
838

839
      //    boundaryManager->setDOFVector(this);
840
    } else {
841
      this->boundaryManager = NULL;
842
843
    }

844
845
846
847
848
849
    return *this;
  }

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

852
853
    TEST_EXIT_DBG(x.getFESpace() && x.getFESpace()->getAdmin())
      ("pointer is NULL: %8X, %8X\n", x.getFESpace(), x.getFESpace()->getAdmin());
854
855

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

860
861
862
863
864
865
866
    return x;
  }


  template<typename T>
  const DOFVector<T>& operator+=(DOFVector<T>& x, const DOFVector<T>& y)
  {
867
868
869
    FUNCNAME("DOFVector<T>::operator+=(DOFVector<T>& x, const DOFVector<T>& y)");
    
    TEST_EXIT_DBG(x.getFESpace() && y.getFESpace())
870
      ("feSpace is NULL: %8X, %8X\n", x.getFESpace(), y.getFESpace());
871
872
    TEST_EXIT_DBG(x.getFESpace()->getAdmin() &&
	      (x.getFESpace()->getAdmin() == y.getFESpace()->getAdmin()))
873
874
      ("no admin or different admins: %8X, %8X\n",
       x.getFESpace()->getAdmin(), y.getFESpace()->getAdmin());
875
876
    TEST_EXIT_DBG(x.getSize() == y.getSize())("different sizes\n");
    
877
878
    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);
879
880
881
882
883
884
    for (xIterator.reset(), yIterator.reset();
	 !xIterator.end();
	 ++xIterator, ++yIterator) {     
      *xIterator += *yIterator; 
    }

885
886
887
888
889
890
    return x;
  }

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

893
    TEST_EXIT_DBG(x.getFESpace() && y.getFESpace())
894
      ("feSpace is NULL: %8X, %8X\n", x.getFESpace(), y.getFESpace());
895
896
    TEST_EXIT_DBG(x.getFESpace()->getAdmin() &&
	      (x.getFESpace()->getAdmin() == y.getFESpace()->getAdmin()))
897
898
      ("no admin or different admins: %8X, %8X\n",
       x.getFESpace()->getAdmin(), y.getFESpace()->getAdmin());
899
900
    TEST_EXIT_DBG(x.getSize() == y.getSize())("different sizes\n");
    
901
902
    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);
903
904
905
906
907
    for (xIterator.reset(), yIterator.reset();
	 !xIterator.end();
	 ++xIterator, ++yIterator) {
      *xIterator -= *yIterator; 
    }
908
909
910
911
912
913
    return x;
  }

  template<typename T>
  const DOFVector<T>& operator*=(DOFVector<T>& x, const DOFVector<T>& y)
  {
914
915
916
    FUNCNAME("DOFVector<T>::operator*=(DOFVector<T>& x, const DOFVector<T>& y)");
    
    TEST_EXIT_DBG(x.getFESpace() && y.getFESpace())
917
      ("feSpace is NULL: %8X, %8X\n", x.getFESpace(), y.getFESpace());
918
919
    TEST_EXIT_DBG(x.getFESpace()->getAdmin() &&
	      (x.getFESpace()->getAdmin() == y.getFESpace()->getAdmin()))
920
921
      ("no admin or different admins: %8X, %8X\n",
       x.getFESpace()->getAdmin(), y.getFESpace()->getAdmin());
922
923
    TEST_EXIT_DBG(x.getSize() == y.getSize())("different sizes\n");
    
924
925
    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);
926
927
928
929
930
    for (xIterator.reset(), yIterator.reset();
	 !xIterator.end();
	 ++xIterator, ++yIterator) {
      *xIterator *= *yIterator; 
    }
931
932
933
934
935
936
937
938

    return x;
  }

  template<typename T>
  T operator*(DOFVector<T>& x, DOFVector<T>& y)
  {
    FUNCNAME("DOFVector<T>::operator*(DOFVector<T>& x, DOFVector<T>& y)");
939
940
    T dot;
    const DOFAdmin *admin = NULL;
941

942
    TEST_EXIT(x.getFESpace() && y.getFESpace())
943
      ("feSpace is NULL: %8X, %8X\n", x.getFESpace(), y.getFESpace());
944
    TEST_EXIT((admin = x.getFESpace()->getAdmin()) && (admin == y.getFESpace()->getAdmin()))
945
946
      ("no admin or different admins: %8X, %8X\n",
       x.getFESpace()->getAdmin(), y.getFESpace()->getAdmin());
947
948
949
    TEST_EXIT(x.getSize() == y.getSize())("different sizes\n");

    dot = 0;
950
951
952

    typename DOFVector<T>::Iterator xIterator(dynamic_cast<DOFIndexed<T>*>(&x), USED_DOFS);
    typename DOFVector<T>::Iterator yIterator(dynamic_cast<DOFIndexed<T>*>(&y), USED_DOFS);
953
954
955
956
957
958
    for (xIterator.reset(), yIterator.reset();
	 !xIterator.end();
	 ++xIterator, ++yIterator) 
      {
	dot += (*xIterator) * (*yIterator);
      };
959
960
961
962
963
964
965
966
967
968
969

    return(dot);
  }

  template<typename T>
  void mv(MatrixTranspose transpose,
	  const DOFMatrix &a, 
	  const DOFVector<T>&x,
	  DOFVector<T> &result,
	  bool add)
  {
970
971
972
    // Unfortunately needed
    using namespace mtl;

973
974
    FUNCNAME("DOFVector<T>::mv()");

975
    TEST_EXIT(a.getRowFESpace() && a.getColFESpace() && x.getFESpace() && result.getFESpace())
976
977
      ("getFESpace() is NULL: %8X, %8X, %8X, %8X\n", 
       a.getRowFESpace(), a.getColFESpace(), x.getFESpace(), result.getFESpace());
978
979
980
981
982
983
984
985
986

    const DOFAdmin *rowAdmin = a.getRowFESpace()->getAdmin();
    const DOFAdmin *colAdmin = a.getColFESpace()->getAdmin();

    TEST_EXIT((rowAdmin && colAdmin) && 
	      (((transpose == NoTranspose) && (colAdmin == x.getFESpace()->getAdmin()) && 
		(rowAdmin == result.getFESpace()->getAdmin()))||
	       ((transpose == Transpose) && (rowAdmin == x.getFESpace()->getAdmin()) && 
		(colAdmin == result.getFESpace()->getAdmin()))))
987
988
989
990
991
      ("no admin or different admins: %8X, %8X, %8X, %8X\n",
       a.getRowFESpace()->getAdmin(), a.getColFESpace()->getAdmin(), 
       x.getFESpace()->getAdmin(), result.getFESpace()->getAdmin());


992
993
994
995
996
    if (transpose == NoTranspose)
      mult(a.getBaseMatrix(), x, result);
    else if (transpose == Transpose)
      mult(trans(const_cast<DOFMatrix::base_matrix_type&>(a.getBaseMatrix())), x, result);
    else 
997
998
999
1000
1001
1002
1003
1004
1005
1006
      ERROR_EXIT("transpose = %d\n", transpose);
  }

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

1007
    TEST_EXIT(x.getFESpace() && y.getFESpace())
1008
1009
      ("feSpace is NULL: %8X, %8X\n", x.getFESpace(), y.getFESpace());

1010
1011
1012
    const DOFAdmin *admin = x.getFESpace()->getAdmin();

    TEST_EXIT((admin) && (admin == y.getFESpace()->getAdmin()))
1013
1014
      ("no admin or different admins: %8X, %8X\n",
       x.getFESpace()->getAdmin(), y.getFESpace()->getAdmin());
1015
    TEST_EXIT(static_cast<int>(x.getSize()) >= admin->getUsedSize())
1016
      ("size = %d too small: admin->size = %d\n", x.getSize(), 
1017
1018
       admin->getUsedSize());
    TEST_EXIT(static_cast<int>(y.getSize()) >= admin->getUsedSize())
1019
      ("y.size = %d too small: admin->size = %d\n", y.getSize(), 
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
       admin->getUsedSize());

      // This is the old implementation of the mv-multiplication. It have been changed
      // because of the OpenMP-parallelization:
//     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); 
//       };

      int i;
      int maxI = y.getSize();

#ifdef _OPENMP
#pragma omp parallel for schedule(dynamic, 25000) default(shared) private(i)
#endif
      for (i = 0; i < maxI; i++) {
	if (!admin->isDOFFree(i)) {
	  y[i] += alpha * x[i];
	}
      }
1044
1045
1046
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
  }

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

1075
    TEST_EXIT(x.getFESpace() && y.getFESpace())
1076
1077
      ("feSpace is NULL: %8X, %8X\n", x.getFESpace(), y.getFESpace());

1078
1079
1080
    const DOFAdmin *admin = x.getFESpace()->getAdmin();

    TEST_EXIT(admin && (admin == y.getFESpace()->getAdmin()))
1081
1082
      ("no admin or different admins: %8X, %8X\n",
       x.getFESpace()->getAdmin(), y.getFESpace()->getAdmin());
1083
    TEST_EXIT(static_cast<int>(x.getSize()) >= admin->getUsedSize())
1084
      ("size = %d too small: admin->size = %d\n", x.getSize(), 
1085
1086
       admin->getUsedSize());
    TEST_EXIT(static_cast<int>(y.getSize()) >= admin->getUsedSize())
1087
      ("y.size = %d too small: admin->size = %d\n", y.getSize(), 
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
       admin->getUsedSize());

    // This is the old im