1 /*!
2  * \file  include/TFEL/Math/ST2toST2/ST2toST2StensorProductExpr.hxx
3  * \brief
4  * \author Thomas Helfer
5  * \brief 05 juin 2014
6  * \copyright Copyright (C) 2006-2018 CEA/DEN, EDF R&D. All rights
7  * reserved.
8  * This project is publicly released under either the GNU GPL Licence
9  * or the CECILL-A licence. A copy of thoses licences are delivered
10  * with the sources of TFEL. CEA or EDF may also distribute this
11  * project under specific licensing conditions.
12  */
13 
14 #ifndef LIB_TFEL_MATH_ST2TOST2STENSORPRODUCTEXPR_HXX
15 #define LIB_TFEL_MATH_ST2TOST2STENSORPRODUCTEXPR_HXX
16 
17 #include"TFEL/Config/TFELConfig.hxx"
18 #include"TFEL/Math/ExpressionTemplates/Expr.hxx"
19 
20 #include"TFEL/Math/General/EmptyRunTimeProperties.hxx"
21 #include"TFEL/Math/Stensor/StensorConcept.hxx"
22 
23 
24 namespace tfel
25 {
26 
27   namespace math
28   {
29 
30     //! Empty structure used for partial specialisation of the
31     //! Expr class
32     template<unsigned short N>
33     struct ST2toST2StensorProductExpr
34     {}; // end of struct ST2toST2StensorProductExpr
35 
36     /*!
37      * Partial specialisation
38      */
39     template<typename StensorResultType>
40     struct Expr<StensorResultType,ST2toST2StensorProductExpr<1u> >
41       : public StensorConcept<Expr<StensorResultType,ST2toST2StensorProductExpr<1u> > >,
42 	public fsarray<StensorDimeToSize<StensorTraits<StensorResultType>::dime>::value,
43 		       typename StensorTraits<StensorResultType>::NumType>
44     {
45       //! a simple alias
46       typedef EmptyRunTimeProperties RunTimeProperties;
47       //! a simple alias
48       typedef typename StensorTraits<StensorResultType>::NumType value_type;
49       //! a simple check
50       TFEL_STATIC_ASSERT((StensorTraits<StensorResultType>::dime==1u));
51       /*!
52        * \param[in] a : first term of the product
53        * \param[in] b : second term of the product
54        */
55       template<typename ST2toST2Type,
56 	       typename StensorType>
57       TFEL_MATH_INLINE
Exprtfel::math::Expr58       Expr(const ST2toST2Type& a,
59 		  const StensorType&  b)
60       {
61 	//! a simple check
62 	TFEL_STATIC_ASSERT((tfel::meta::Implements<ST2toST2Type,ST2toST2Concept>::cond));
63 	//! a simple check
64 	TFEL_STATIC_ASSERT((tfel::meta::Implements<StensorType,tfel::math::StensorConcept>::cond));
65 	//! a simple check
66 	TFEL_STATIC_ASSERT((ST2toST2Traits<ST2toST2Type>::dime==1u));
67 	//! a simple check
68 	TFEL_STATIC_ASSERT((StensorTraits <StensorType>::dime==1u));
69 	this->v[0]=a(0,0)*b(0)+a(0,1)*b(1)+a(0,2)*b(2);
70 	this->v[1]=a(1,0)*b(0)+a(1,1)*b(1)+a(1,2)*b(2);
71 	this->v[2]=a(2,0)*b(0)+a(2,1)*b(1)+a(2,2)*b(2);
72       } // end of Expr
73       /*!
74        * \brief access operator
75        * \param[in] i : index
76        */
77       TFEL_MATH_INLINE const value_type&
operator ()tfel::math::Expr78       operator()(const unsigned short i) const
79       {
80 	return this->v[i];
81       } // end of operator()
82       /*!
83        * \brief access operator
84        * \param[in] i : index
85        */
86       TFEL_MATH_INLINE const value_type&
operator []tfel::math::Expr87       operator[](const unsigned short i) const
88       {
89 	return this->v[i];
90       } // end of operator[]
91       /*!
92        * \return the runtime properties
93        */
94       TFEL_MATH_INLINE RunTimeProperties
getRunTimePropertiestfel::math::Expr95       getRunTimeProperties() const
96       {
97 	return RunTimeProperties();
98       }
99     }; // end of struct Expr<StensorResultType,T2SST2toST2StensorProductExp>
100 
101     /*!
102      * Partial specialisation
103      */
104     template<typename StensorResultType>
105     struct Expr<StensorResultType,ST2toST2StensorProductExpr<2u> >
106       : public StensorConcept<Expr<StensorResultType,ST2toST2StensorProductExpr<2u> > >,
107 	public fsarray<StensorDimeToSize<StensorTraits<StensorResultType>::dime>::value,
108 		       typename StensorTraits<StensorResultType>::NumType>
109     {
110       //! a simple alias
111       typedef EmptyRunTimeProperties RunTimeProperties;
112       //! a simple alias
113       typedef typename StensorTraits<StensorResultType>::NumType value_type;
114       //! a simple check
115       TFEL_STATIC_ASSERT((StensorTraits<StensorResultType>::dime==2u));
116       /*!
117        * \param[in] a : first term of the product
118        * \param[in] b : second term of the product
119        */
120       template<typename ST2toST2Type,
121 	       typename StensorType>
122       TFEL_MATH_INLINE
Exprtfel::math::Expr123       Expr(const ST2toST2Type& a,
124 		  const StensorType&  b)
125       {
126 	//! a simple check
127 	TFEL_STATIC_ASSERT((tfel::meta::Implements<ST2toST2Type,ST2toST2Concept>::cond));
128 	//! a simple check
129 	TFEL_STATIC_ASSERT((tfel::meta::Implements<StensorType,tfel::math::StensorConcept>::cond));
130 	//! a simple check
131 	TFEL_STATIC_ASSERT((ST2toST2Traits<ST2toST2Type>::dime==2u));
132 	//! a simple check
133 	TFEL_STATIC_ASSERT((StensorTraits <StensorType>::dime==2u));
134 	this->v[0]=a(0,0)*b(0)+a(0,1)*b(1)+a(0,2)*b(2)+a(0,3)*b(3);
135 	this->v[1]=a(1,0)*b(0)+a(1,1)*b(1)+a(1,2)*b(2)+a(1,3)*b(3);
136 	this->v[2]=a(2,0)*b(0)+a(2,1)*b(1)+a(2,2)*b(2)+a(2,3)*b(3);
137 	this->v[3]=a(3,0)*b(0)+a(3,1)*b(1)+a(3,2)*b(2)+a(3,3)*b(3);
138       } // end of Expr
139       /*!
140        * \brief access operator
141        * \param[in] i : index
142        */
143       TFEL_MATH_INLINE const value_type&
operator ()tfel::math::Expr144       operator()(const unsigned short i) const
145       {
146 	return this->v[i];
147       } // end of operator()
148       /*!
149        * \brief access operator
150        * \param[in] i : index
151        */
152       TFEL_MATH_INLINE const value_type&
operator []tfel::math::Expr153       operator[](const unsigned short i) const
154       {
155 	return this->v[i];
156       } // end of operator[]
157       /*!
158        * \return the runtime properties
159        */
160       TFEL_MATH_INLINE RunTimeProperties
getRunTimePropertiestfel::math::Expr161       getRunTimeProperties() const
162       {
163 	return RunTimeProperties();
164       }
165     }; // end of struct Expr<StensorResultType,T2SST2toST2StensorProductExp>
166 
167     /*!
168      * Partial specialisation
169      */
170     template<typename StensorResultType>
171     struct Expr<StensorResultType,ST2toST2StensorProductExpr<3u> >
172       : public StensorConcept<Expr<StensorResultType,ST2toST2StensorProductExpr<3u> > >,
173 	public fsarray<StensorDimeToSize<StensorTraits<StensorResultType>::dime>::value,
174 		       typename StensorTraits<StensorResultType>::NumType>
175     {
176       //! a simple alias
177       typedef EmptyRunTimeProperties RunTimeProperties;
178       //! a simple alias
179       typedef typename StensorTraits<StensorResultType>::NumType value_type;
180       //! a simple check
181       TFEL_STATIC_ASSERT((StensorTraits<StensorResultType>::dime==3u));
182       /*!
183        * \param[in] a : first term of the product
184        * \param[in] b : second term of the product
185        */
186       template<typename ST2toST2Type,
187 	       typename StensorType>
188       TFEL_MATH_INLINE
Exprtfel::math::Expr189       Expr(const ST2toST2Type& a,
190 		  const StensorType&  b)
191       {
192 	//! a simple check
193 	TFEL_STATIC_ASSERT((tfel::meta::Implements<ST2toST2Type,ST2toST2Concept>::cond));
194 	//! a simple check
195 	TFEL_STATIC_ASSERT((tfel::meta::Implements<StensorType,tfel::math::StensorConcept>::cond));
196 	//! a simple check
197 	TFEL_STATIC_ASSERT((ST2toST2Traits<ST2toST2Type>::dime==3u));
198 	//! a simple check
199 	TFEL_STATIC_ASSERT((StensorTraits <StensorType>::dime==3u));
200 	this->v[0]=a(0,0)*b(0)+a(0,1)*b(1)+a(0,2)*b(2)+a(0,3)*b(3)+a(0,4)*b(4)+a(0,5)*b(5);
201 	this->v[1]=a(1,0)*b(0)+a(1,1)*b(1)+a(1,2)*b(2)+a(1,3)*b(3)+a(1,4)*b(4)+a(1,5)*b(5);
202 	this->v[2]=a(2,0)*b(0)+a(2,1)*b(1)+a(2,2)*b(2)+a(2,3)*b(3)+a(2,4)*b(4)+a(2,5)*b(5);
203 	this->v[3]=a(3,0)*b(0)+a(3,1)*b(1)+a(3,2)*b(2)+a(3,3)*b(3)+a(3,4)*b(4)+a(3,5)*b(5);
204 	this->v[4]=a(4,0)*b(0)+a(4,1)*b(1)+a(4,2)*b(2)+a(4,3)*b(3)+a(4,4)*b(4)+a(4,5)*b(5);
205 	this->v[5]=a(5,0)*b(0)+a(5,1)*b(1)+a(5,2)*b(2)+a(5,3)*b(3)+a(5,4)*b(4)+a(5,5)*b(5);
206       } // end of Expr
207       /*!
208        * \brief access operator
209        * \param[in] i : index
210        */
211       TFEL_MATH_INLINE const value_type&
operator ()tfel::math::Expr212       operator()(const unsigned short i) const
213       {
214 	return this->v[i];
215       } // end of operator()
216       /*!
217        * \brief access operator
218        * \param[in] i : index
219        */
220       TFEL_MATH_INLINE const value_type&
operator []tfel::math::Expr221       operator[](const unsigned short i) const
222       {
223 	return this->v[i];
224       } // end of operator[]
225       /*!
226        * \return the runtime properties
227        */
228       TFEL_MATH_INLINE RunTimeProperties
getRunTimePropertiestfel::math::Expr229       getRunTimeProperties() const
230       {
231 	return RunTimeProperties();
232       }
233     }; // end of struct Expr<StensorResultType,T2SST2toST2StensorProductExp>
234 
235   } // end of namespace math
236 
237 } // end of namespace tfel
238 
239 #endif /* LIB_TFEL_MATH_ST2TOST2STENSORPRODUCTEXPR_HXX */
240 
241