functor.h 21.4 KB
Newer Older
Phillip Lino Rall's avatar
Phillip Lino Rall committed
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
/**********************************************************************************
 * Copyright 2010 Christoph Pflaum 
 *              Department Informatik Lehrstuhl 10 - Systemsimulation
 *              Friedrich-Alexander Universität Erlangen-Nürnberg
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 **********************************************************************************/
 
// ------------------------------------------------------------
//
// functor.h
//
// ------------------------------------------------------------

#ifndef FUNCTOR_H
#define FUNCTOR_H

/*************************************************************
 * Defines functor expression templates. Use
 * functor objects instead of function pointers.
 *
 * A functor class has to define a evaluate
 * function. No other requirements are imposed on
 * the functor class implementation.
 * Example for 3 arguments
 * (DTyp_Result = float,DTyp = double):
 *
 * class MyFunctor3
 * {
 * public:
 *      float evaluate(double x, double y, double z) const;
 * };
 * 
 * Furthermore, vector of variables is allowed in
 *     class FunctorVector
 * 
************************************************************/
#ifdef CPP11
#include <tuple>

#define Functor1 Functor

template<int ...> struct Functor_seq {};

template<int N, int ...S> struct Functor_gens : Functor_gens<N-1, N-1, S...> {};

template<int ...S> struct Functor_gens<0, S...>{ typedef Functor_seq<S...> type; };

template<typename... Args> inline void pass(Args&&...) {}

template <class DTyp_Result, class DTyp, class Func, typename ... A>
class Exp_Functor : public Expr< Exp_Functor<DTyp_Result, DTyp, Func, A...> > {
  std::tuple<const A&...> a_;
  Func& functor_;
  control_typ funCtrTyp_;

  template<elementTyp TYP_EL, int ...S>
    inline DTyp_Result
    Give_data_private(params_in, Functor_seq<S...>) const;

  template<int ...S>
    inline DTyp_Result
    Give_cell_hexahedra_private(params_in_cell, Functor_seq<S...>) const;

  template <elementTyp TYP_EL, int ...S>
    void
    Update_private ( int id, Functor_seq<S...> ) const;

  template <elementTyp TYP_EL>
    void
    Update_private ( const A&... a ) const
  {}

  template <elementTyp TYP_EL, typename Any>
  inline Any& Update_private ( int id, Any& any) const {
Phillip Lino Rall's avatar
Phillip Lino Rall committed
86
    any.template  Update<TYP_EL>(id);
Phillip Lino Rall's avatar
Phillip Lino Rall committed
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
    return any;
  }


public:
  inline Exp_Functor ( Func& functor, control_typ funCtrTyp, const A&... a )
                  : functor_ ( functor ), funCtrTyp_ ( funCtrTyp ), a_ ( a... ) {}

  stencil_typ Give_stencil_typ() const { return no_stencil; }
  control_typ Give_control_typ() const { return funCtrTyp_; }


  typedef DTyp_Result Result;

  template <elementTyp TYP_EL>
  inline DTyp_Result Give_data ( params_in ) const;

  inline DTyp_Result Give_cell_hexahedra ( params_in_cell ) const;

  template <elementTyp TYP_EL>
  void Update ( int id ) const;

  inline Blockgrid* Give_blockgrid() const { return std::get<1>(a_).Give_blockgrid(); };

  template <class VType>
  friend class Variable2D;

};


template <class DTyp_Result, class DTyp, class Func, typename... A>
template <elementTyp TYP_EL>
    inline void
    Exp_Functor<DTyp_Result, DTyp, Func, A...>::Update(int id) const
    {
       Update_private<TYP_EL>( id, typename Functor_gens<sizeof...(A)>::type() );
    }


template <class DTyp_Result, class DTyp, class Func, typename... A>
template <elementTyp TYP_EL, int ...S>
inline void
Exp_Functor<DTyp_Result, DTyp, Func, A...>::Update_private ( int id, Functor_seq<S...> ) const {
    Update_private<TYP_EL>( Update_private<TYP_EL>(id,std::get<S>(a_))... );
}

template <class DTyp_Result, class DTyp, class Func, typename... A>
template <elementTyp TYP_EL>
    inline DTyp_Result
    Exp_Functor<DTyp_Result, DTyp, Func, A...>::Give_data(params_in) const
    {
      return Give_data_private<TYP_EL>( params_out, typename Functor_gens<sizeof...(A)>::type() );
    }

template <class DTyp_Result, class DTyp, class Func,typename... A>
    inline DTyp_Result
    Exp_Functor<DTyp_Result, DTyp, Func, A...>::Give_cell_hexahedra(params_in_cell) const
    {
      return Give_cell_hexahedra_private( params_out_cell, typename Functor_gens<sizeof...(A)>::type() );
    }



template <class DTyp_Result, class DTyp, class Func, typename... A>
template <elementTyp TYP_EL, int ...S>
inline DTyp_Result
Exp_Functor<DTyp_Result, DTyp, Func, A...>::Give_data_private ( params_in, Functor_seq<S...> ) const {
Phillip Lino Rall's avatar
Phillip Lino Rall committed
154
        return functor_.evaluate ( std::get<S>(a_).template Give_data<TYP_EL> ( params_out )... );
Phillip Lino Rall's avatar
Phillip Lino Rall committed
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
}

template <class DTyp_Result, class DTyp, class Func, typename... A>
template <int ...S>
inline DTyp_Result
Exp_Functor<DTyp_Result, DTyp, Func, A...>::Give_cell_hexahedra_private ( params_in_cell, Functor_seq<S...> ) const {
        return functor_.evaluate ( std::get<S>(a_).Give_cell_hexahedra ( params_out_cell )... );
}

template <class DTyp_Result, class DTyp, class Func>
class Functor {

        public:
                Functor ( Func& functor,  control_typ funCtrTyp = thread_save ) : functor_ ( functor ), funCtrTyp_ ( funCtrTyp ) {};

                template <typename... A>
                inline Exp_Functor<DTyp_Result, DTyp, Func, A...>
                operator() ( const A&... a ) const
                { return Exp_Functor<DTyp_Result, DTyp, Func, A...> ( functor_, funCtrTyp_, a... ); }

        private:
                Func& functor_;
                control_typ funCtrTyp_;
};

#endif


template <class A, class DTyp_Result, class DTyp, class Func>

class Exp_Functor1 : public Expr<Exp_Functor1<A, DTyp_Result, DTyp, Func> > {
                const A& a_;
                Func* functor_;
                control_typ funCtrTyp_;

        public:
                inline Exp_Functor1 ( const A& a, Func* functor, control_typ funCtrTyp )
                                : a_ ( a ), functor_ ( functor ), funCtrTyp_ ( funCtrTyp ) {}

Phillip Lino Rall's avatar
Phillip Lino Rall committed
194
195
                stencil_typ Give_stencil_typ() const { return a_.Give_stencil_typ();     }
		bool totalCalcNotPossible()    const { return a_.totalCalcNotPossible(); }                
Phillip Lino Rall's avatar
Phillip Lino Rall committed
196
197
198
199
200
201
202
203
204
205
                control_typ Give_control_typ() const { return funCtrTyp_; }


                typedef DTyp_Result Result;

                template <elementTyp TYP_EL>
                inline DTyp_Result Give_data ( params_in ) const;

                inline DTyp_Result Give_cell_hexahedra ( params_in_cell ) const;

Phillip Lino Rall's avatar
Phillip Lino Rall committed
206
207
		inline Result Give_fromTotal(int i) const;			
		
Phillip Lino Rall's avatar
Phillip Lino Rall committed
208
209
                template <elementTyp TYP_EL>
                void Update ( int id ) const {
Phillip Lino Rall's avatar
Phillip Lino Rall committed
210
                        a_.template  Update<TYP_EL> ( id );
Phillip Lino Rall's avatar
Phillip Lino Rall committed
211
212
213
214
215
216
217
                }
};

template <class A, class DTyp_Result, class DTyp, class Func>
template <elementTyp TYP_EL>
inline DTyp_Result
Exp_Functor1<A, DTyp_Result, DTyp, Func>::Give_data ( params_in ) const {
Phillip Lino Rall's avatar
Phillip Lino Rall committed
218
        return functor_->evaluate ( a_.template Give_data<TYP_EL> ( params_out ) );
Phillip Lino Rall's avatar
Phillip Lino Rall committed
219
220
221
222
223
224
225
226
}

template <class A, class DTyp_Result, class DTyp, class Func>
inline DTyp_Result
Exp_Functor1<A, DTyp_Result, DTyp, Func>::Give_cell_hexahedra ( params_in_cell ) const {
        return functor_->evaluate ( a_.Give_cell_hexahedra ( params_out_cell ) );
}

Phillip Lino Rall's avatar
Phillip Lino Rall committed
227
228
229
230
231
232
template <class A, class DTyp_Result, class DTyp, class Func>
inline DTyp_Result
Exp_Functor1<A, DTyp_Result, DTyp, Func>::Give_fromTotal(int i) const {
        return functor_->evaluate ( a_.Give_fromTotal(i) );
}

Phillip Lino Rall's avatar
Phillip Lino Rall committed
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
template <class DTyp_Result, class DTyp, class Func>
class Functor1 {
        public:
                Functor1 ( Func& functor,  control_typ funCtrTyp = thread_save ) : functor_ ( &functor ), funCtrTyp_ ( funCtrTyp ) {};
                Functor1 ( Func* functor,  control_typ funCtrTyp = thread_save ) : functor_ ( functor ), funCtrTyp_ ( funCtrTyp ) {};

                template <class A>
                inline Exp_Functor1<A, DTyp_Result, DTyp, Func>
                operator() ( const Expr<A>& a ) const
                { return Exp_Functor1<A, DTyp_Result, DTyp, Func> ( a, functor_, funCtrTyp_ ); }

        private:
                Func* functor_;
                control_typ funCtrTyp_;
};


//  2 arguments

template <class A, class B, class DTyp_Result, class DTyp, class Func>

class Exp_Functor2
                        : public Expr<Exp_Functor2<A, B, DTyp_Result, DTyp, Func> > {
                const A& a_;
                const B& b_;
                Func* functor_;
                control_typ funCtrTyp_;

        public:
                inline Exp_Functor2 ( const A& a, const B& b, Func* functor, control_typ funCtrTyp ) :
                                a_ ( a ), b_ ( b ), functor_ ( functor ), funCtrTyp_ ( funCtrTyp ) {}

Phillip Lino Rall's avatar
Phillip Lino Rall committed
265
266
267
268
269
270
271
272
273
		stencil_typ Give_stencil_typ() const {
			if(a_.Give_stencil_typ() == yes_stencil ) return yes_stencil;
			return b_.Give_stencil_typ();
		};		
		
		bool totalCalcNotPossible() const {
			if(a_.totalCalcNotPossible()) return true;
			return b_.totalCalcNotPossible();
		};	
Phillip Lino Rall's avatar
Phillip Lino Rall committed
274
275
276
277
278
279
280
281
282
                control_typ Give_control_typ() const { return funCtrTyp_; }

                typedef DTyp_Result Result;

                template <elementTyp TYP_EL>
                inline DTyp_Result Give_data ( params_in ) const;

                inline DTyp_Result Give_cell_hexahedra ( params_in_cell ) const;

Phillip Lino Rall's avatar
Phillip Lino Rall committed
283
284
		inline Result Give_fromTotal(int i) const;			
		
Phillip Lino Rall's avatar
Phillip Lino Rall committed
285
286
                template <elementTyp TYP_EL>
                void Update ( int id ) const {
Phillip Lino Rall's avatar
Phillip Lino Rall committed
287
                        a_.template  Update<TYP_EL> ( id );
Phillip Lino Rall's avatar
Phillip Lino Rall committed
288
289
290
291
292
293
294
                }
};

template <class A, class B, class DTyp_Result, class DTyp, class Func>
template <elementTyp TYP_EL>
inline DTyp_Result
Exp_Functor2<A, B, DTyp_Result, DTyp, Func>::Give_data ( params_in ) const {
Phillip Lino Rall's avatar
Phillip Lino Rall committed
295
296
        return functor_->evaluate ( a_.template Give_data<TYP_EL> ( params_out ),
                                    b_.template Give_data<TYP_EL> ( params_out ) );
Phillip Lino Rall's avatar
Phillip Lino Rall committed
297
298
299
300
301
302
303
304
305
}

template <class A, class B, class DTyp_Result, class DTyp, class Func>
inline DTyp_Result
Exp_Functor2<A, B, DTyp_Result, DTyp, Func>::Give_cell_hexahedra ( params_in_cell ) const {
        return functor_->evalute ( a_.Give_cell_hexahedra ( params_out_cell ),
                                   b_.Give_cell_hexahedra ( params_out_cell ) );
}

Phillip Lino Rall's avatar
Phillip Lino Rall committed
306

Phillip Lino Rall's avatar
Phillip Lino Rall committed
307
308
309
310
311
312
313
314
315
template <class A, class B, class DTyp_Result, class DTyp, class Func>
inline DTyp_Result
Exp_Functor2<A, B, DTyp_Result, DTyp, Func>::Give_fromTotal(int i) const {
        return functor_->evalute ( a_.Give_fromTotal(i),
                                   b_.Give_fromTotal(i) );
}


template <class DTyp_Result, class DTyp, class Func>
Phillip Lino Rall's avatar
Phillip Lino Rall committed
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
class Functor2 {

        public:
                Functor2 ( Func& functor, control_typ funCtrTyp = thread_save) : functor_ ( &functor ), funCtrTyp_ ( funCtrTyp )  {};
                Functor2 ( Func* functor, control_typ funCtrTyp = thread_save) : functor_ ( functor ), funCtrTyp_ ( funCtrTyp )  {};

                template <class A, class B>
                inline Exp_Functor2<A, B, DTyp_Result, DTyp, Func>
                operator() ( const Expr<A>& a, const Expr<B>& b ) const
                { return Exp_Functor2<A, B, DTyp_Result, DTyp, Func> ( a, b, functor_, funCtrTyp_ ); }

        private:
                Func* functor_;
                control_typ funCtrTyp_;
};


// 3 arguments

template < class A, class B, class C,

class DTyp_Result, class DTyp, class Func >

class Exp_Functor3
                        : public Expr<Exp_Functor3<A, B, C, DTyp_Result, DTyp, Func> > {
                const A& a_;
                const B& b_;
                const C& c_;
                Func* functor_;
                control_typ funCtrTyp_;

        public:
                inline Exp_Functor3 ( const A& a,
                                      const B& b,
                                      const C& c,
                                      Func* functor,
                                      control_typ funCtrTyp ) :
                                a_ ( a ), b_ ( b ), c_ ( c ), functor_ ( functor ), funCtrTyp_ ( funCtrTyp ) {}

Phillip Lino Rall's avatar
Phillip Lino Rall committed
355
356
357
358
359
360
361
362
363
364
365
		stencil_typ Give_stencil_typ() const {
			if(a_.Give_stencil_typ() == yes_stencil ) return yes_stencil;
			if(b_.Give_stencil_typ() == yes_stencil ) return yes_stencil;			
			return c_.Give_stencil_typ();
		};		
		
		bool totalCalcNotPossible() const {
			if(a_.totalCalcNotPossible()) return true;
			if(b_.totalCalcNotPossible()) return true;			
			return c_.totalCalcNotPossible();
		};
Phillip Lino Rall's avatar
Phillip Lino Rall committed
366
367
368
369
370
371
372
373
374
                control_typ Give_control_typ() const { return funCtrTyp_; }

                typedef DTyp_Result Result;

                template <elementTyp TYP_EL>
                inline DTyp_Result Give_data ( params_in ) const;

                inline DTyp_Result Give_cell_hexahedra ( params_in_cell ) const;

Phillip Lino Rall's avatar
Phillip Lino Rall committed
375
376
		inline Result Give_fromTotal(int i) const;	
		
Phillip Lino Rall's avatar
Phillip Lino Rall committed
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
                template <elementTyp TYP_EL>
                void Update ( int id ) const {
                        a_.template Update<TYP_EL> ( id );
                }
};


template < class A, class B, class C,

class DTyp_Result, class DTyp, class Func >
template <elementTyp TYP_EL>
inline DTyp_Result
Exp_Functor3<A, B, C, DTyp_Result, DTyp, Func>::Give_data ( params_in ) const {
        return functor_->evaluate ( a_.template Give_data<TYP_EL> ( params_out ),
                                    b_.template Give_data<TYP_EL> ( params_out ),
                                    c_.template Give_data<TYP_EL> ( params_out ) );
}

template < class A, class B, class C,
class DTyp_Result, class DTyp, class Func >
inline DTyp_Result
Phillip Lino Rall's avatar
Phillip Lino Rall committed
398
Exp_Functor3<A, B, C, DTyp_Result, DTyp, Func>::Give_cell_hexahedra ( params_in_cell ) const {
Phillip Lino Rall's avatar
Phillip Lino Rall committed
399
400
401
402
403
404
405
406
407
408
409
410
411
412
        return functor_->evaluate ( a_.Give_cell_hexahedra ( params_out_cell ),
                                    b_.Give_cell_hexahedra ( params_out_cell ),
                                    c_.Give_cell_hexahedra ( params_out_cell ) );

}


template < class A, class B, class C,
class DTyp_Result, class DTyp, class Func >
inline DTyp_Result
Exp_Functor3<A, B, C, DTyp_Result, DTyp, Func>::Give_fromTotal(int i) const {
        return functor_->evaluate ( a_.Give_fromTotal(i),
                                    b_.Give_fromTotal(i),
                                    c_.Give_fromTotal(i) );
Phillip Lino Rall's avatar
Phillip Lino Rall committed
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
441
442
443
444
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

}


template <class DTyp_Result, class DTyp, class Func>

class Functor3 {

        public:
                Functor3 ( Func& functor, control_typ funCtrTyp = thread_save) : functor_ ( &functor ), funCtrTyp_ ( funCtrTyp ) {};
                Functor3 ( Func* functor, control_typ funCtrTyp = thread_save) : functor_ ( functor ), funCtrTyp_ ( funCtrTyp ) {};

                template <class A, class B, class C>
                inline Exp_Functor3<A, B, C, DTyp_Result, DTyp, Func>
                operator() ( const Expr<A>& a,
                             const Expr<B>& b,
                             const Expr<C>& c ) const
                { return Exp_Functor3<A, B, C, DTyp_Result, DTyp, Func> ( a, b, c, functor_, funCtrTyp_ ); }


        private:
                Func* functor_;
                control_typ funCtrTyp_;
};


// 4 arguments

template <class A, class B, class C, class D, class DTyp_Result, class DTyp, class Func>

class Exp_Functor4
                        : public Expr<Exp_Functor4<A, B, C, D, DTyp_Result, DTyp, Func> > {
                const A& a_;
                const B& b_;
                const C& c_;
                const D& d_;
                const control_typ funCtrTyp_;
                Func* functor_;

        public:
                inline Exp_Functor4 ( const A& a,
                                      const B& b,
                                      const C& c,
                                      const D& d,
                                      Func* functor,
                                      control_typ funCtrTyp ) :
                                a_ ( a ), b_ ( b ), c_ ( c ), d_ ( d ), functor_ ( functor ), funCtrTyp_ ( funCtrTyp ) {}

                stencil_typ Give_stencil_typ() const { return no_stencil; }

                control_typ Give_control_typ() const { return funCtrTyp_; }

                typedef DTyp_Result Result;

                template <elementTyp TYP_EL>
                inline DTyp_Result Give_data ( params_in ) const;

                inline DTyp_Result Give_cell_hexahedra ( params_in_cell ) const;


                template <elementTyp TYP_EL>
                void Update ( int id ) const {
Phillip Lino Rall's avatar
Phillip Lino Rall committed
475
                        a_.template  Update<TYP_EL> ( id );
Phillip Lino Rall's avatar
Phillip Lino Rall committed
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
                }
};


template < class A, class B, class C, class D,

class DTyp_Result, class DTyp, class Func >
template <elementTyp TYP_EL>
inline DTyp_Result
Exp_Functor4<A, B, C, D, DTyp_Result, DTyp, Func>::Give_data ( params_in ) const {
        return functor_->evaluate ( a_.template Give_data<TYP_EL> ( params_out ),
                                    b_.template Give_data<TYP_EL> ( params_out ),
                                    c_.template Give_data<TYP_EL> ( params_out ),
                                    d_.template Give_data<TYP_EL> ( params_out ) );
}

template < class A, class B, class C, class D,

class DTyp_Result, class DTyp, class Func >
inline DTyp_Result
Exp_Functor4<A, B, C, D, DTyp_Result, DTyp, Func>::Give_cell_hexahedra ( params_in_cell ) const {
497
498
499
500
        return functor_->evaluate ( a_.template Give_cell_hexahedra ( params_out_cell ),
                                    b_.template Give_cell_hexahedra ( params_out_cell ),
                                    c_.template Give_cell_hexahedra ( params_out_cell ),
                                    d_.template Give_cell_hexahedra ( params_out_cell ) );
Phillip Lino Rall's avatar
Phillip Lino Rall committed
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
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
}




template <class DTyp_Result, class DTyp, class Func>

class Functor4 {

        public:
                Functor4 ( Func* functor, control_typ funCtrTyp = thread_save ) : functor_ ( functor ), funCtrTyp_ ( funCtrTyp ) {

                };

                Functor4 ( Func& functor, control_typ funCtrTyp = thread_save ) : functor_ ( &functor ), funCtrTyp_ ( funCtrTyp ) {

                };

                template <class A, class B, class C, class D>
                inline Exp_Functor4<A, B, C, D, DTyp_Result, DTyp, Func>
                operator() ( const Expr<A>& a,
                             const Expr<B>& b,
                             const Expr<C>& c,
                             const Expr<D>& d ) const {
                        return Exp_Functor4<A, B, C, D, DTyp_Result, DTyp, Func> ( a, b, c, d, functor_ ,
                                funCtrTyp_ );
                }


        private:
                Func* functor_;
                control_typ funCtrTyp_;
};

////////////////////////////////////////////////////////////////////////////////////////////////////
// list of arguments
////////////////////////////////////////////////////////////////////////////////////////////////////

////////////////
//  Anwendung
//  1. FunctorVector definieren:
//          FunctorVector  func(funcF);
//  2. Als Expression anwenden:
//        a = func()
////////////////


/*
template <class DTyp_Result, class DTyp, class Func>
class Exp_Functor_Vector : public Expr<Exp_Functor_Vector<DTyp_Result, DTyp, Func> > {
                int sizeVector;
		Func* functor;
		Variable<DTyp>* vecVar;
		const control_typ funCtrTyp;
	        DTyp* vectorCopy;
	public:
		inline Exp_Functor_Vector(int sizeVector_, 
					  const Variable<DTyp>* vecVar_, 
			                  Func* functor_, 
			                  const control_typ funCtrTyp_,
			                  DTyp* vectorCopy_) :	
		      sizeVector(sizeVector_), functor(functor_), 
		      vecVar(vecVar_),         funCtrTyp(funCtrTyp_), 
		      vectorCopy(vectorCopy_)  {	
		}
				
		stencil_typ Give_stencil_typ() const { return no_stencil; }		
		control_typ Give_control_typ() const { return funCtrTyp; }
		
		typedef DTyp_Result Result;
		
		
		template <elementTyp TYP_EL>
                inline DTyp_Result Give_data ( params_in ) const;
				
		inline DTyp_Result Give_cell_hexahedra ( params_in_cell ) const;
		
		
		template <elementTyp TYP_EL>
		void Update ( int id ) const {
Phillip Lino Rall's avatar
Phillip Lino Rall committed
581
			for(int i=0;i<sizeVector;++i) vecVar[i].template  Update<TYP_EL> ( id );
Phillip Lino Rall's avatar
Phillip Lino Rall committed
582
583
584
585
586
587
588
589
590
		}
		
};


template <class DTyp_Result, class DTyp, class Func>
template <elementTyp TYP_EL>
inline DTyp_Result
Exp_Functor_Vector<DTyp_Result, DTyp, Func>::Give_data ( params_in ) const {
Phillip Lino Rall's avatar
Phillip Lino Rall committed
591
        for(int i=0;i<sizeVector;++i) vectorCopy[i] = vecVar.template Give_data<TYP_EL>(params_out);
Phillip Lino Rall's avatar
Phillip Lino Rall committed
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
	return functor->evaluate( vectorCopy );
}

template <class DTyp_Result, class DTyp, class Func>
inline DTyp_Result
Exp_Functor_Vector<DTyp_Result, DTyp, Func>::Give_cell_hexahedra ( params_in_cell ) const {
       for(int i=0;i<sizeVector;++i) vectorCopy[i] = vecVar.Give_cell_hexahedra(params_out_cell);
       return functor->evaluate( vectorCopy );  
}




template <class DTyp_Result, class DTyp, class Func>
class FunctorVector {
  public:
     FunctorVector(Func* functor, int sizeVector_, control_typ funCtrTyp = thread_save ) 
        : functor_ ( functor ), funCtrTyp_ ( funCtrTyp ) {
	  sizeVector = sizeVector_;
	  vectorCopy = new DTyp[sizeVector];
     };
     ~FunctorVector() { delete[] vectorCopy; }
		
     inline Exp_Functor_Vector<DTyp_Result, DTyp, Func>
        operator() (const Variable<DTyp>* vecVar) const {
		    return Exp_Functor_Vector<DTyp_Result, DTyp, Func>(sizeVector, vecVar, functor_ , funCtrTyp_, vectorCopy);
	}

  private:
    Func* functor_;
    control_typ funCtrTyp_;
    DTyp* vectorCopy;
    int sizeVector;
};

*/



#endif /* FUNCTOR_H */