/********************************************************************************** * 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 Exp2D_Functor2D1; template class Exp2D_Functor2D1 : public Expr2D< Exp2D_Functor2D1 > { 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 inline DTyp_Result Give_data ( params2D_in ) const; inline DTyp_Result Give_cell_hexahedra ( params2D_in_cell ) const; template void Update ( int id ) const; }; template template inline void Exp2D_Functor2D1::Update ( int id ) const { a_.template Update ( id ); } template template inline DTyp_Result Exp2D_Functor2D1::Give_data ( params2D_in ) const { return functor_->evaluate ( a_.template Give_data ( params2D_out ) ); } template inline DTyp_Result Exp2D_Functor2D1::Give_cell_hexahedra ( params2D_in_cell ) const { return functor_->evaluate ( a_.Give_cell_hexahedra ( params2D_out_cell ) ); } /** \addtogroup ExpressionTemplates2D **/ /* @{ */ template class Functor2D1 { public: Functor2D1 ( Func* functor, control_typ funCtrTyp = thread_save ) : functor_ ( functor ), funCtrTyp_ ( funCtrTyp ) {}; template inline Exp2D_Functor2D1 operator() ( const Expr2D& a ) const { return Exp2D_Functor2D1 ( a, functor_, funCtrTyp_ ); } private: Func* functor_; control_typ funCtrTyp_; }; /* @} */ // 2 arguments template class Exp2D_Functor2D2 : public Expr2D > { 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 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 void Update ( int id ) const; Blockgrid2D* Give_blockgrid() const { return a_.Give_blockgrid(); }; }; template template inline void Exp2D_Functor2D2::Update ( int id ) const { a_.template Update ( id ); b_.template Update ( id ); } template template inline DTyp_Result Exp2D_Functor2D2::Give_data ( params2D_in ) const { return functor_->evaluate ( a_.template Give_data ( params2D_out ), b_.template Give_data ( params2D_out ) ); } template inline DTyp_Result Exp2D_Functor2D2::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 inline DTyp_Result Exp2D_Functor2D2::Give_cell_rectangle ( params2D_in_cell ) const { return functor_->evaluate ( a_.Give_cell_rectangle ( params2D_out_cell ), b_.Give_cell_rectangle ( params2D_out_cell ) ); } /** \addtogroup ExpressionTemplates2D **/ /* @{ */ template class Functor2D2 { public: Functor2D2 ( Func* functor, control_typ funCtrTyp = thread_save) : functor_ ( functor ), funCtrTyp_ ( funCtrTyp ) {}; template inline Exp2D_Functor2D2 operator() ( const Expr2D& a, const Expr2D& b ) const { return Exp2D_Functor2D2 ( 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 Exp2D_Functor2D3 : public Expr2D > { 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 inline DTyp_Result Give_data ( params2D_in ) const; inline DTyp_Result Give_cell_hexahedra ( params2D_in_cell ) const; template void Update ( int id ) const { a_.template Update ( id ); b_.template Update ( id ); c_.template Update ( id ); } }; template < class A, class B, class C, class DTyp_Result, class DTyp, class Func > template inline DTyp_Result Exp2D_Functor2D3::Give_data ( params2D_in ) const { return functor_->evaluate ( a_.template Give_data ( params2D_out ), b_.template Give_data ( params2D_out ), c_.template Give_data ( params2D_out ) ); } template < class A, class B, class C, class DTyp_Result, class DTyp, class Func > inline DTyp_Result Exp2D_Functor2D3::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 ) ); } /** \addtogroup ExpressionTemplates2D **/ /* @{ */ template class Functor2D3 { public: Functor2D3 ( Func* functor, control_typ funCtrTyp = thread_save) : functor_ ( functor ), funCtrTyp_ ( funCtrTyp ) {}; template inline Exp2D_Functor2D3 operator() ( const Expr2D& a, const Expr2D& b, const Expr2D& c ) const { return Exp2D_Functor2D3 ( a, b, c, functor_, funCtrTyp_ ); } private: Func* functor_; control_typ funCtrTyp_; }; /* @} */ // 4 arguments template class Exp2D_Functor2D4 : public Expr2D > { 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 inline DTyp_Result Give_data ( params2D_in ) const; inline DTyp_Result Give_cell_hexahedra ( params2D_in_cell ) const; template void Update ( int id ) const { a_.template Update ( id ); b_.template Update ( id ); c_.template Update ( id ); d_.template Update ( id ); } }; template < class A, class B, class C, class D, class DTyp_Result, class DTyp, class Func > template inline DTyp_Result Exp2D_Functor2D4::Give_data ( params2D_in ) const { return functor_->evaluate ( a_.template Give_data ( params2D_out ), b_.template Give_data ( params2D_out ), c_.template Give_data ( params2D_out ), d_.template Give_data ( params2D_out ) ); } template < class A, class B, class C, class D, class DTyp_Result, class DTyp, class Func > inline DTyp_Result Exp2D_Functor2D4::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 ) ); } /** \addtogroup ExpressionTemplates2D **/ /* @{ */ template class Functor2D4 { public: //Functor2D4 ( Func* functor ) : functor_ ( functor ) {}; Functor2D4 ( Func* functor, control_typ funCtrTyp = thread_save ) : functor_ ( functor ), funCtrTyp_ ( funCtrTyp ) { }; template inline Exp2D_Functor2D4 operator() ( const Expr2D& a, const Expr2D& b, const Expr2D& c, const Expr2D& d ) const { return Exp2D_Functor2D4 ( a, b, c, d, functor_ , funCtrTyp_ ); } private: Func* functor_; control_typ funCtrTyp_; }; /* @} */ #endif /* FUNCTOR_H */