Views.h 18.8 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
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
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
/** \file Views.h */

#ifndef MY_VIEWS_H
#define MY_VIEWS_H

#include <stdexcept>
#include <boost/type_traits/is_base_of.hpp>
#include <boost/utility/enable_if.hpp>

#include "AMDiS.h"
#ifdef USE_BACKGROUNDMESH
  #include "BackgroundMesh.h"
#endif
#ifdef USE_KD_TREE
  #include "kdtree_nanoflann_dof.h"
#endif

using namespace AMDiS; 

/// Abstract-Function-Views
/// ________________________________________________________________________________________________

/// result = 0.5*(f(x)+1)
template<typename T>
struct PhaseView : AbstractFunction<T, WorldVector<double> > {
  PhaseView(AbstractFunction<T, WorldVector<double> > &fct_) : fct(fct_) {}
  PhaseView(AbstractFunction<T, WorldVector<double> > *fct_) : fct(*fct_) {}
  T operator()(const WorldVector<double>& x) const {
	  return std::max(0.0, std::min(1.0, 0.5*(fct(x)+1.0)));
  }
private:
  AbstractFunction<T, WorldVector<double> > fct;
};

/// result = 2*f(x)-1
template<typename T>
struct ChView : AbstractFunction<T, WorldVector<double> > {
  ChView(AbstractFunction<T, WorldVector<double> > &fct_) : fct(fct_) {}
  ChView(AbstractFunction<T, WorldVector<double> > *fct_) : fct(*fct_) {}
  T operator()(const WorldVector<double>& x) const {
	  return std::max(-1.0, std::min(1.0, 2.0*fct(x)-1.0));
  }
private:
  AbstractFunction<T, WorldVector<double> > fct;
};

template<typename T>
struct MultView : AbstractFunction<T, WorldVector<double> > {
  MultView(AbstractFunction<T, WorldVector<double> > &fct_, double factor_) : fct(fct_), factor(factor_) {}
  MultView(AbstractFunction<T, WorldVector<double> > *fct_, double factor_) : fct(*fct_), factor(factor_) {}
  T operator()(const WorldVector<double>& x) const {
    return factor*fct(x);
  }
private:
  AbstractFunction<T, WorldVector<double> > fct;
  double factor;
};

/// DOFVector-Views
/// ________________________________________________________________________________________________

template<typename T>
struct DOFView : public DOFVector<T> {
  typedef T result_type;
  
  DOFView(DOFVector<T> *vec_)
  : DOFVector<T>(vec_->getFeSpace(), "dof_view"), 
    vector(vec_)
  {
    nullify(value0);
  }
    
  DOFView(DOFVector<T> &vec_)
  : DOFVector<T>(vec_.getFeSpace(), "dof_view"), 
    vector(&vec_)
  {
    nullify(value0);
  }
  
  /// Returns \ref vec[i]
  inline const T& operator[](WorldVector<double> &x) const 
  {
    FUNCNAME("DOFVector<T>::operator[x]");
    DegreeOfFreedom idx = -1;
    WorldVector<double> x_ = coordsView(x);
    bool inside = vector->getDofIdxAtPoint(x_, idx);
    
    return (inside ? operator[](idx) : value0);
  } 

  /// Returns \ref vec[i]
  inline T& operator[](WorldVector<double> &x) 
  {
    FUNCNAME("DOFVector<T>::operator[x]");
    DegreeOfFreedom idx = -1;
    WorldVector<double> x_ = coordsView(x);
    bool inside = vector->getDofIdxAtPoint(x_, idx);

    return (inside ? operator[](idx) : value0);
  }
  
  inline T& operator[](DegreeOfFreedom idx)
  {
    DOFVector<T>::operator[](idx)= valueView(idx);
    return DOFVector<T>::operator[](idx);
  }
  
  inline const T& operator[](DegreeOfFreedom idx) const 
  {
    const T& swap(valueView(idx));
    T& swap2 = const_cast<T&>(DOFVector<T>::operator[](idx));
    swap2 = swap;
    return swap2;
  }
  
  inline const T evalAtPoint(WorldVector<double> &p, 
			      ElInfo *oldElInfo = NULL, 
			      T* valueReturn = NULL
			    ) const 
  {
    FUNCNAME("DOFVector<T>::operator[x]");
    
    WorldVector<double> x_ = coordsView(p);
    const FiniteElemSpace* feSpace = vector->getFeSpace();
    
    if (oldElInfo && feSpace->getMesh() == oldElInfo->getMesh()) {
      Mesh* mesh = feSpace->getMesh();
      DimVec<double> lambda(mesh->getDim(), NO_INIT);
      int k = oldElInfo->worldToCoord(x_, &lambda);
      if (k < 0) {
	std::vector<DegreeOfFreedom> localIndices;	// DOF-indices of all DOFs in trinangle
	mtl::dense_vector<double> uh; 		// evaluation of DOFVectors at QPs

	localIndices.resize(feSpace->getBasisFcts()->getNumber());
	uh.change_dim(mesh->getDim()+1);
	
	feSpace->getBasisFcts()->getLocalIndices(oldElInfo->getElement(), feSpace->getAdmin(), localIndices);
	for (int l = 0; l < feSpace->getBasisFcts()->getNumber(); l++)
	  uh[l] = (*vector)[localIndices[l]];
	T value = feSpace->getBasisFcts()->evalUh(lambda, uh);
	return value;
      }
    }
    
#ifdef USE_BACKGROUNDMESH
    using namespace experimental;
    bool use_backgroundmesh = false;
    Parameters::get("backgroundMesh->enabled",use_backgroundmesh);
    if (use_backgroundmesh) {
      Box* box = Box::provideBackgroundMesh(feSpace);
      int evaluation_accuracy = 0;
      Parameters::get("backgroundMesh->evaluation accuracy",evaluation_accuracy);
      T value = box->evalAtPoint(*vector, x_, evaluation_accuracy);
      return value;
    }
#endif
#ifdef USE_KD_TREE
    using namespace experimental;
    bool use_kdtree = false;
    Parameters::get("KD-Tree->enabled",use_kdtree);
    if (use_kdtree) {
      KD_Tree* tree = provideKDTree(feSpace);
      T value = tree->evalAtPoint(*vector, x_);
      return value;
    }
#endif
    DegreeOfFreedom idx = -1;
    T value = value0;    
    Mesh* mesh = feSpace->getMesh();
    
    ElInfo *elInfo = mesh->createNewElInfo();
    DimVec<double> lambda(mesh->getDim(), NO_INIT);

    bool inside = mesh->findElInfoAtPoint(x_, elInfo, lambda, (oldElInfo ? oldElInfo->getMacroElement() : NULL), NULL, NULL);
    
    if (inside) {      
      std::vector<DegreeOfFreedom> localIndices;
      mtl::dense_vector<T> uh; 	

      localIndices.resize(feSpace->getBasisFcts()->getNumber());
      uh.change_dim(feSpace->getBasisFcts()->getNumber());
    
      feSpace->getBasisFcts()->getLocalIndices(elInfo->getElement(), feSpace->getAdmin(), localIndices);
      for (int l = 0; l < feSpace->getBasisFcts()->getNumber(); l++)
	uh[l] = valueView(localIndices[l]);
      value = feSpace->getBasisFcts()->evalUh(lambda, uh);
    }
    if (valueReturn)
      *valueReturn = value;
    delete elInfo;
    
    return value;
  } 
  
protected:
  
  virtual inline T valueView(DegreeOfFreedom idx) const
  {
    return (*vector)[idx];
  }
  
  virtual inline WorldVector<double> coordsView(WorldVector<double> &x) const
  {
    return x;
  }
  
  void setDefaultValue(T& value0_)
  {
    value0 = value0_;
  };
  
  DOFVector<T> *vector;
  T value0;
};

/// DOFVector-Views ... Value-Views
/// ________________________________________________________________________________________________

template<typename T> 
struct PhaseDOFView : public DOFView<T> {
  typedef T result_type;
  
  PhaseDOFView(DOFVector<T> &vec_) : DOFView<T>(&vec_) {}
  PhaseDOFView(DOFVector<T> *vec_) : DOFView<T>(vec_) {}
	
protected:
  
  inline T valueView(DegreeOfFreedom idx) const
  {
    return std::max(0.0, std::min(1.0, 0.5*((*DOFView<T>::vector)[idx]+1.0)));
  }
};


template<typename T> 
struct InvPhaseView : public DOFView<T> {
  typedef T result_type;

  InvPhaseView(DOFVector<T> &vec_) : DOFView<T>(&vec_) {}
  InvPhaseView(DOFVector<T> *vec_) : DOFView<T>(vec_) {}
 
protected:
  
  inline T valueView(DegreeOfFreedom idx) const
  {
    return -(*DOFView<T>::vector)[idx];
  }
};

/// DOFVector-Views ... Coord-Views
/// ________________________________________________________________________________________________

/// vec[x] := vec.evalAtPoint(R^(-1) * x)
template<typename T> 
struct RotateView : public DOFView<T> {
  typedef T result_type;

  RotateView(DOFVector<T> &vec_, WorldMatrix<double> R_) : DOFView<T>(&vec_), R(R_) {}
  RotateView(DOFVector<T> *vec_, WorldMatrix<double> R_) : DOFView<T>(vec_), R(R_) {}
  
  RotateView(DOFVector<T> &vec_, double alpha) : DOFView<T>(&vec_) {
    R.setDiag(1.0);
    R[0][0] = cos(alpha);  R[0][1] = -sin(alpha);
    R[1][0] = sin(alpha);  R[1][1] = cos(alpha);
  }
  RotateView(DOFVector<T> *vec_, double alpha) : DOFView<T>(vec_) {
    R.setDiag(1.0);
    R[0][0] = cos(alpha);  R[0][1] = -sin(alpha);
    R[1][0] = sin(alpha);  R[1][1] = cos(alpha);
  }
 
protected:
  
  inline WorldVector<double> coordsView(WorldVector<double> &x) const
  {
    WorldVector<double> x_;
    WorldMatrix<double> R_ = R;
    for (int i = 0; i < R_.getNumRows(); i++)
      for (int j = 0; j < i; j++)
	std::swap(R_[i][j], R_[j][i]);
    x_.multMatrixVec(R_, x);
    return x_;
  }
  
private:
  
  WorldMatrix<double> R;
};


/// vec[x] := vec.evalAtPoint(x ./ scale)
template<typename T> 
struct ScaleView : public DOFView<T> {
  typedef T result_type;

  ScaleView(DOFVector<T> &vec_, WorldVector<double> scale_) : DOFView<T>(&vec_), scale(scale_) {}
  ScaleView(DOFVector<T> *vec_, WorldVector<double> scale_) : DOFView<T>(vec_), scale(scale_) {}
 
  ScaleView(DOFVector<T> &vec_, double scale_) : DOFView<T>(&vec_) { scale.set(scale_); }
  ScaleView(DOFVector<T> *vec_, double scale_) : DOFView<T>(vec_) { scale.set(scale_); }
  
protected:
  
  inline WorldVector<double> coordsView(WorldVector<double> &x) const
  {
    WorldVector<double> x_;
    for (int i = 0; i < x_.getSize(); i++)
      x_[i] = x[i]/scale[i];
    return x_;
  }
  
private:
  
  WorldVector<double> scale;
};

/// vec[x] := vec.evalAtPoint(x - shift)
template<typename T> 
struct ShiftView : public DOFView<T> {
  typedef T result_type;

  ShiftView(DOFVector<T> &vec_, WorldVector<double> shift_) : DOFView<T>(&vec_), shift(shift_) {}
  ShiftView(DOFVector<T> *vec_, WorldVector<double> shift_) : DOFView<T>(vec_), shift(shift_) {}
  
  void setShift(WorldVector<double> &shift_) { shift = shift_; }
  
protected:
  
  inline WorldVector<double> coordsView(WorldVector<double> &x) const
  {
    WorldVector<double> x_;
    for (int i = 0; i < x_.getSize(); i++)
      x_[i] = x[i]-shift[i];
    return x_;
  }
  
private:
  
  WorldVector<double> shift;
};

/// evalAtPoint for several Data-Structures
/// ________________________________________________________________________________________________

// DOFVector can be accessed by locating the elInfo and than using barycentric coordinates
// The default value, if p outside of geometry, is 0.0
template<typename T>
inline T evalAtPoint(const DOFVector<T> &obj, WorldVector<double> &p, ElInfo* oldElInfo = NULL)
{
  const FiniteElemSpace* feSpace = obj.getFeSpace();
  Mesh* mesh = feSpace->getMesh();
  
  if (oldElInfo && feSpace->getMesh() == oldElInfo->getMesh()) {
    DimVec<double> lambda(mesh->getDim(), NO_INIT);
    oldElInfo->worldToCoord(p, &lambda);
    
    std::vector<DegreeOfFreedom> localIndices;	// DOF-indices of all DOFs in trinangle
    mtl::dense_vector<T> uh; 		// evaluation of DOFVectors at QPs

    localIndices.resize(feSpace->getBasisFcts()->getNumber());
    uh.change_dim(mesh->getDim()+1);
    
    feSpace->getBasisFcts()->getLocalIndices(oldElInfo->getElement(), feSpace->getAdmin(), localIndices);
    for (int l = 0; l < feSpace->getBasisFcts()->getNumber(); l++)
      uh[l] = obj[localIndices[l]];
    T value = feSpace->getBasisFcts()->evalUh(lambda, uh);
    return value;
  }
    
#ifdef USE_BACKGROUNDMESH
  using namespace experimental;
  bool use_backgroundmesh = false;
  Parameters::get("backgroundMesh->enabled",use_backgroundmesh);
  if (use_backgroundmesh) {
    Box* box = Box::provideBackgroundMesh(feSpace);
    int evaluation_accuracy = 0;
    Parameters::get("backgroundMesh->evaluation accuracy",evaluation_accuracy);
    T value = box->evalAtPoint(obj, p, evaluation_accuracy);
    return value;
  }
#endif
#ifdef USE_KD_TREE
    using namespace experimental;
    bool use_kdtree = false;
    Parameters::get("KD-Tree->enabled",use_kdtree);
    if (use_kdtree) {
      KD_Tree* tree = provideKDTree(feSpace);
      T value = tree->evalAtPoint(obj, p);
      return value;
    }
#endif   
  T value; nullify(value);
  
  ElInfo *elInfo = mesh->createNewElInfo();
  DimVec<double> lambda(mesh->getDim(), NO_INIT);

  std::vector<DegreeOfFreedom> localIndices;	// DOF-indices of all DOFs in trinangle
  mtl::dense_vector<T> uh; 	

  localIndices.resize(feSpace->getBasisFcts()->getNumber());
  uh.change_dim(feSpace->getBasisFcts()->getNumber());

  bool inside = mesh->findElInfoAtPoint(p, elInfo, lambda, NULL, NULL, NULL);
  
  if (inside) {
    feSpace->getBasisFcts()->getLocalIndices(elInfo->getElement(), obj.getFeSpace()->getAdmin(), localIndices);
    for (int l = 0; l < feSpace->getBasisFcts()->getNumber(); l++)
      uh[l] = obj[localIndices[l]];
    value = feSpace->getBasisFcts()->evalUh(lambda, uh);
  }
  delete elInfo;
  return value;
};

// DOFView can be accessed by own method
template<typename T >
inline T evalAtPoint(const DOFView<T> &obj, WorldVector<double> &p, ElInfo* elInfo = NULL)
{
  return obj.evalAtPoint(p, elInfo);
};

// intrinsic types can return values directly
template<typename T>
inline T evalAtPoint(T &obj, WorldVector<double> &p, ElInfo* elInfo = NULL)
{
  return obj;
};

// AbstractFunctions with argument-type = WorldVector can be accessed directly
template<typename T>
inline T evalAtPoint(AbstractFunction<T, WorldVector<double> > &obj, WorldVector<double> &p, ElInfo* elInfo = NULL)
{
  return obj(p);
};

/// Type-Traits for value_type of Data-Structures
/// ________________________________________________________________________________________________

template<typename T, typename enable=void> struct ValueType { typedef T type; };
template<typename T> struct ValueType<DOFVector<T> > { typedef T type; };
Praetorius, Simon's avatar
Praetorius, Simon committed
441
442
443
444
template<typename T> struct ValueType<std::vector<T> > { typedef T type; };
template<typename T> struct ValueType<std::list<T> > { typedef T type; };
template<typename T> struct ValueType<std::set<T> > { typedef T type; };
template<typename T> struct ValueType<mtl::dense_vector<T> > { typedef T type; };
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
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
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
template<typename Derived> struct ValueType<Derived, typename boost::enable_if<boost::is_base_of<DOFView<double>, Derived > >::type> { typedef double type; };
template<typename Derived> struct ValueType<Derived, typename boost::enable_if<boost::is_base_of<DOFView<WorldVector<double> >, Derived > >::type> { typedef WorldVector<double> type; };
template<typename Derived> struct ValueType<Derived, typename boost::enable_if<boost::is_base_of<AbstractFunction<double, WorldVector<double> >, Derived > >::type> { typedef double type; };
template<typename Derived> struct ValueType<Derived, typename boost::enable_if<boost::is_base_of<AbstractFunction<WorldVector<double>, WorldVector<double> >, Derived > >::type> { typedef WorldVector<double> type; };
  
/// transformDOF by coords (independent of mesh and feSpace)
/// ________________________________________________________________________________________________

// result = vec
template<typename TOut, typename Vector>
inline void interpol_coords(Vector &vec, DOFVector<TOut> &result)
{
  typedef typename ValueType<Vector>::type T;
  DOFVector<WorldVector<double> > coords(result.getFeSpace(), "coords");
  result.getFeSpace()->getMesh()->getDofIndexCoords(result.getFeSpace(), coords);

  DOFIterator<WorldVector<double> > it_coords(&coords, USED_DOFS);
  DOFIterator<TOut> it_result(&result, USED_DOFS);
  for (it_coords.reset(), it_result.reset(); !it_coords.end(); ++it_coords, ++it_result) {
    *it_result = evalAtPoint<T>(vec, *it_coords);
  }
};

// result = op(vec)
template<typename TOut, typename Vector>
inline void transformDOF_coords(Vector &vec,
  DOFVector<TOut> &result,
  AbstractFunction<TOut, typename ValueType<Vector>::type> *op)
{
  typedef typename ValueType<Vector>::type T;
  DOFVector<WorldVector<double> > coords(result.getFeSpace(), "coords");
  result.getFeSpace()->getMesh()->getDofIndexCoords(result.getFeSpace(), coords);

  DOFIterator<WorldVector<double> > it_coords(&coords, USED_DOFS);
  DOFIterator<TOut> it_result(&result, USED_DOFS);
  for (it_coords.reset(), it_result.reset(); !it_coords.end(); ++it_coords, ++it_result) {
    T value = evalAtPoint<T>(vec, *it_coords);
    *it_result = (*op)(value);
  }
};

// result = binary_op(vec1, vec2)
template<typename TOut, typename Vector1, typename Vector2>
inline void transformDOF_coords(Vector1 &vec1, Vector2 &vec2,
  DOFVector<TOut> &result,
  BinaryAbstractFunction<TOut, typename ValueType<Vector1>::type, 
			       typename ValueType<Vector2>::type> *binary_op)
{
  typedef typename ValueType<Vector1>::type T1;
  typedef typename ValueType<Vector2>::type T2;
  DOFVector<WorldVector<double> > coords(result.getFeSpace(), "coords");
  result.getFeSpace()->getMesh()->getDofIndexCoords(result.getFeSpace(), coords);

  DOFIterator<WorldVector<double> > it_coords(&coords, USED_DOFS);
  DOFIterator<TOut> it_result(&result, USED_DOFS);
  for (it_coords.reset(), it_result.reset(); !it_coords.end(); ++it_coords, ++it_result) {
    T1 value1 = evalAtPoint<T1>(vec1, *it_coords);
    T2 value2 = evalAtPoint<T2>(vec2, *it_coords);
    
    *it_result = (*binary_op)(value1, value2);
  }
};

// result = tertiary_op(vec1, vec2, vec3)
template<typename TOut, typename Vector1, typename Vector2, typename Vector3>
inline void transformDOF_coords(Vector1 &vec1, Vector2 &vec2, Vector3 &vec3,
  DOFVector<TOut> &result,
  TertiaryAbstractFunction<TOut, typename ValueType<Vector1>::type, 
				 typename ValueType<Vector2>::type, 
				 typename ValueType<Vector3>::type> *tertiary_op)
{
  typedef typename ValueType<Vector1>::type T1;
  typedef typename ValueType<Vector2>::type T2;
  typedef typename ValueType<Vector3>::type T3;
  DOFVector<WorldVector<double> > coords(result.getFeSpace(), "coords");
  result.getFeSpace()->getMesh()->getDofIndexCoords(result.getFeSpace(), coords);

  DOFIterator<WorldVector<double> > it_coords(&coords, USED_DOFS);
  DOFIterator<TOut> it_result(&result, USED_DOFS);
  for (it_coords.reset(), it_result.reset(); !it_coords.end(); ++it_coords, ++it_result) {
    T1 value1 = evalAtPoint<T1>(vec1, *it_coords);
    T2 value2 = evalAtPoint<T2>(vec2, *it_coords);
    T3 value3 = evalAtPoint<T3>(vec3, *it_coords);

    *it_result = (*tertiary_op)(value1, value2, value3);
  }
};


// result = quart_op(vec1, vec2, vec3, vec4)
template<typename TOut, typename Vector1, typename Vector2, typename Vector3, typename Vector4>
inline void transformDOF_coords(Vector1 &vec1, Vector2 &vec2, Vector3 &vec3, Vector4 &vec4,
  DOFVector<TOut> &result,
  QuartAbstractFunction<TOut, typename ValueType<Vector1>::type, 
			      typename ValueType<Vector2>::type, 
			      typename ValueType<Vector3>::type, 
			      typename ValueType<Vector4>::type> *quart_op)
{
  typedef typename ValueType<Vector1>::type T1;
  typedef typename ValueType<Vector2>::type T2;
  typedef typename ValueType<Vector3>::type T3;
  typedef typename ValueType<Vector4>::type T4;
  DOFVector<WorldVector<double> > coords(result.getFeSpace(), "coords");
  result.getFeSpace()->getMesh()->getDofIndexCoords(result.getFeSpace(), coords);

  DOFIterator<WorldVector<double> > it_coords(&coords, USED_DOFS);
  DOFIterator<TOut> it_result(&result, USED_DOFS);
  for (it_coords.reset(), it_result.reset(); !it_coords.end(); ++it_coords, ++it_result) {
    T1 value1 = evalAtPoint<T1>(vec1, *it_coords);
    T2 value2 = evalAtPoint<T2>(vec2, *it_coords);
    T3 value3 = evalAtPoint<T3>(vec3, *it_coords);
    T4 value4 = evalAtPoint<T3>(vec4, *it_coords);

    *it_result = (*quart_op)(value1, value2, value3, value4);
  }
};

#endif // MY_VIEWS_H