functor2D.h 11.6 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
/**********************************************************************************
 * 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
//
// ------------------------------------------------------------
#include "extemp2D.h"

#ifndef Functor2D_H
#define Functor2D_H

// 1 argument
template <class A, class DTyp_Result, class DTyp, class Func>
class Exp2D_Functor2D1;

template <class A, class DTyp_Result, class DTyp, class Func>
class Exp2D_Functor2D1 : public Expr2D< Exp2D_Functor2D1<A, DTyp_Result, DTyp, Func> > {
		const A& a_;
		Func* functor_;
		control_typ funCtrTyp_;
		
	public:
		inline Exp2D_Functor2D1 ( const A& a, Func* functor, control_typ funCtrTyp )
				: a_ ( a ), 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 ( params2D_in ) const;
		
		inline DTyp_Result Give_cell_hexahedra ( params2D_in_cell ) const;
		
		template <elementTyp TYP_EL>
		void Update ( int id ) const;
};

template <class A, class DTyp_Result, class DTyp, class Func>
template <elementTyp TYP_EL>
inline void
Exp2D_Functor2D1<A, DTyp_Result, DTyp, Func>::Update ( int id ) const {
  a_.template Update<TYP_EL> ( id );
}

template <class A, class DTyp_Result, class DTyp, class Func>
template <elementTyp TYP_EL>
inline DTyp_Result
Exp2D_Functor2D1<A, DTyp_Result, DTyp, Func>::Give_data ( params2D_in ) const {
	return functor_->evaluate ( a_.template Give_data<TYP_EL> ( params2D_out ) );
}

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

Christoph Pflaum's avatar
Christoph Pflaum committed
78
79
/** \addtogroup ExpressionTemplates2D **/
/* @{ */  
Phillip Lino Rall's avatar
Phillip Lino Rall committed
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
template <class DTyp_Result, class DTyp, class Func>
class Functor2D1 {

	public:
		Functor2D1 ( Func* functor,  control_typ funCtrTyp = thread_save ) : functor_ ( functor ), funCtrTyp_ ( funCtrTyp ) {};
		
		template <class A>
		inline Exp2D_Functor2D1<A, DTyp_Result, DTyp, Func>
		operator() ( const Expr2D<A>& a ) const
		{ return Exp2D_Functor2D1<A, DTyp_Result, DTyp, Func> ( a, functor_, funCtrTyp_ ); }
		
	private:
		Func* functor_;
		control_typ funCtrTyp_;
};
Christoph Pflaum's avatar
Christoph Pflaum committed
95
/* @} */
Phillip Lino Rall's avatar
Phillip Lino Rall committed
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

//  2 arguments

template <class A, class B, class DTyp_Result, class DTyp, class Func>
class Exp2D_Functor2D2
			: public Expr2D<Exp2D_Functor2D2<A, B, DTyp_Result, DTyp, Func> > {
		const A& a_;
		const B& b_;
		Func* functor_;
		control_typ funCtrTyp_;
		
	public:
		inline Exp2D_Functor2D2 ( const A& a, const B& b, Func* functor, control_typ funCtrTyp ) :
				a_ ( a ), b_ ( b ), 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 ( params2D_in ) const;
		
		inline DTyp_Result Give_cell_hexahedra(params2D_in_cell) const;
		
		inline DTyp_Result Give_cell_rectangle(params2D_in_cell) const;		
		
		template <elementTyp TYP_EL>
		void Update ( int id ) const;
		
		Blockgrid2D* Give_blockgrid() const { return a_.Give_blockgrid(); };
};



template <class A, class B, class DTyp_Result, class DTyp, class Func>
template <elementTyp TYP_EL>
inline void
Exp2D_Functor2D2<A,B, DTyp_Result, DTyp, Func>::Update ( int id ) const {
  a_.template Update<TYP_EL> ( id );
  b_.template Update<TYP_EL> ( id );
}

template <class A, class B, class DTyp_Result, class DTyp, class Func>
template <elementTyp TYP_EL>
inline DTyp_Result
Exp2D_Functor2D2<A, B, DTyp_Result, DTyp, Func>::Give_data ( params2D_in ) const {
	return functor_->evaluate ( a_.template Give_data<TYP_EL> ( params2D_out ),
	                            b_.template Give_data<TYP_EL> ( params2D_out ) );
}

template <class A, class B, class DTyp_Result, class DTyp, class Func>
inline DTyp_Result
Exp2D_Functor2D2<A, B, DTyp_Result, DTyp, Func>::Give_cell_hexahedra ( params2D_in_cell ) const {
	return functor_->evaluate ( a_.Give_cell_hexahedra ( params2D_out_cell ),
	                           b_.Give_cell_hexahedra ( params2D_out_cell ) );
}

template <class A, class B, class DTyp_Result, class DTyp, class Func>
inline DTyp_Result
Exp2D_Functor2D2<A, B, DTyp_Result, DTyp, Func>::Give_cell_rectangle ( params2D_in_cell ) const {
	return functor_->evaluate ( a_.Give_cell_rectangle ( params2D_out_cell ),
	                           b_.Give_cell_rectangle ( params2D_out_cell ) );
}

Christoph Pflaum's avatar
Christoph Pflaum committed
161
162
/** \addtogroup ExpressionTemplates2D **/
/* @{ */   
Phillip Lino Rall's avatar
Phillip Lino Rall committed
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
template <class DTyp_Result, class DTyp, class Func>
class Functor2D2 {

	public:
		Functor2D2 ( Func* functor, control_typ funCtrTyp = thread_save) : functor_ ( functor ), funCtrTyp_ ( funCtrTyp )  {};
		
		template <class A, class B>
		inline Exp2D_Functor2D2<A, B, DTyp_Result, DTyp, Func>
		operator() ( const Expr2D<A>& a, const Expr2D<B>& b ) const
		{ return Exp2D_Functor2D2<A, B, DTyp_Result, DTyp, Func> ( a, b, functor_, funCtrTyp_ ); }
		
	private:
		Func* functor_;
		control_typ funCtrTyp_;
};
Christoph Pflaum's avatar
Christoph Pflaum committed
178
/* @} */
Phillip Lino Rall's avatar
Phillip Lino Rall committed
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

// 3 arguments

template < class A, class B, class C,

class DTyp_Result, class DTyp, class Func >

class Exp2D_Functor2D3
			: public Expr2D<Exp2D_Functor2D3<A, B, C, DTyp_Result, DTyp, Func> > {
		const A& a_;
		const B& b_;
		const C& c_;
		Func* functor_;
		control_typ funCtrTyp_;
		
	public:
		inline Exp2D_Functor2D3 ( const A& a,
		                      const B& b,
		                      const C& c,
		                      Func* functor,
		                      control_typ funCtrTyp ) :
				a_ ( a ), b_ ( b ), c_ ( c ), 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 ( params2D_in ) const;
		
		inline DTyp_Result Give_cell_hexahedra ( params2D_in_cell ) const;
		
		
		template <elementTyp TYP_EL>
		void Update ( int id ) const {
			a_.template Update<TYP_EL> ( id );
                        b_.template Update<TYP_EL> ( id );
                        c_.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
Exp2D_Functor2D3<A, B, C, DTyp_Result, DTyp, Func>::Give_data ( params2D_in ) const {
	return functor_->evaluate ( a_.template Give_data<TYP_EL> ( params2D_out ),
	                            b_.template Give_data<TYP_EL> ( params2D_out ),
	                            c_.template Give_data<TYP_EL> ( params2D_out ) );
}

template < class A, class B, class C,

class DTyp_Result, class DTyp, class Func >
inline DTyp_Result
Exp2D_Functor2D3<A, B, C, DTyp_Result, DTyp, Func>::Give_cell_hexahedra ( params2D_in_cell ) const {
	return functor_->evaluate ( a_.Give_cell_hexahedra ( params2D_out_cell ),
	                            b_.Give_cell_hexahedra ( params2D_out_cell ),
	                            c_.Give_cell_hexahedra ( params2D_out_cell ) );
	                            
}


Christoph Pflaum's avatar
Christoph Pflaum committed
245
246
/** \addtogroup ExpressionTemplates2D **/
/* @{ */   
Phillip Lino Rall's avatar
Phillip Lino Rall committed
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 Functor2D3 {

	public:
		Functor2D3 ( Func* functor, control_typ funCtrTyp = thread_save) : functor_ ( functor ), funCtrTyp_ ( funCtrTyp ) {};
		
		template <class A, class B, class C>
		inline Exp2D_Functor2D3<A, B, C, DTyp_Result, DTyp, Func>
		operator() ( const Expr2D<A>& a,
		             const Expr2D<B>& b,
		             const Expr2D<C>& c ) const
		{ return Exp2D_Functor2D3<A, B, C, DTyp_Result, DTyp, Func> ( a, b, c, functor_, funCtrTyp_ ); }
		
		
	private:
		Func* functor_;
		control_typ funCtrTyp_;
};
Christoph Pflaum's avatar
Christoph Pflaum committed
265
/* @} */
Phillip Lino Rall's avatar
Phillip Lino Rall committed
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

// 4 arguments

template <class A, class B, class C, class D, class DTyp_Result, class DTyp, class Func>
class Exp2D_Functor2D4
			: public Expr2D<Exp2D_Functor2D4<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 Exp2D_Functor2D4 ( 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 ( params2D_in ) const;
		
		inline DTyp_Result Give_cell_hexahedra ( params2D_in_cell ) const;
		
		
		template <elementTyp TYP_EL>
		void Update ( int id ) const {
			a_.template Update<TYP_EL> ( id );
                        b_.template Update<TYP_EL> ( id );
                        c_.template Update<TYP_EL> ( id );
                        d_.template Update<TYP_EL> ( id );
		}
};


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

template < class A, class B, class C, class D,
class DTyp_Result, class DTyp, class Func >
inline DTyp_Result
Exp2D_Functor2D4<A, B, C, D, DTyp_Result, DTyp, Func>::Give_cell_hexahedra ( params2D_in_cell ) const {
	return functor_->evaluate ( a_.Give_cell_hexahedra ( params2D_out_cell ),
	                            b_.Give_cell_hexahedra ( params2D_out_cell ),
	                            c_.Give_cell_hexahedra ( params2D_out_cell ),
	                            d_.Give_cell_hexahedra ( params2D_out_cell ) );
}



Christoph Pflaum's avatar
Christoph Pflaum committed
333
334
/** \addtogroup ExpressionTemplates2D **/
/* @{ */    
Phillip Lino Rall's avatar
Phillip Lino Rall committed
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
template <class DTyp_Result, class DTyp, class Func>
class Functor2D4 {

	public:
		//Functor2D4 ( Func* functor ) : functor_ ( functor ) {};
		
		Functor2D4 ( Func* functor, control_typ funCtrTyp = thread_save ) : functor_ ( functor ), funCtrTyp_ ( funCtrTyp ) {
		
		};
		
		template <class A, class B, class C, class D>
		inline Exp2D_Functor2D4<A, B, C, D, DTyp_Result, DTyp, Func>
		operator() ( const Expr2D<A>& a,
		             const Expr2D<B>& b,
		             const Expr2D<C>& c,
		             const Expr2D<D>& d ) const {
			return Exp2D_Functor2D4<A, B, C, D, DTyp_Result, DTyp, Func> ( a, b, c, d, functor_ ,
			        funCtrTyp_ );
		}
		
		
	private:
		Func* functor_;
		control_typ funCtrTyp_;
};
Christoph Pflaum's avatar
Christoph Pflaum committed
360
361
/* @} */

Phillip Lino Rall's avatar
Phillip Lino Rall committed
362
#endif /* FUNCTOR_H */