rheolef  7.0
space_constant.h
Go to the documentation of this file.
1 #ifndef _RHEOLEF_SPACE_CONSTANT_H
2 #define _RHEOLEF_SPACE_CONSTANT_H
3 
4 #include "rheolef/distributed.h"
5 #include "rheolef/undeterminated.h"
6 #include "rheolef/field_expr_v2_utilities.h"
7 #include <type_traits>
8 
9 
10 namespace rheolef {
11 
12 namespace details {
13 
14 template <class T1, class T2> struct is_equal : std::false_type {};
15 template <class T> struct is_equal<T,T> : std::true_type {};
16 
17 template<class T> struct is_scalar : std::false_type {};
18 template<> struct is_scalar<int> : std::true_type {};
19 template<> struct is_scalar<const int> : std::true_type {};
20 template<> struct is_scalar<size_t> : std::true_type {};
21 template<> struct is_scalar<Float> : std::true_type {};
22 
23 template<class T> struct is_point : std::false_type {};
24 template<class T> struct is_point<point_basic<T> > : std::true_type {};
25 
26 template<class T> struct is_tensor : std::false_type {};
27 template<class T> struct is_tensor<tensor_basic<T> > : std::true_type {};
28 
29 template<class T> struct is_tensor3 : std::false_type {};
30 template<class T> struct is_tensor3<tensor3_basic<T> > : std::true_type {};
31 
32 template<class T> struct is_tensor4 : std::false_type {};
33 template<class T> struct is_tensor4<tensor4_basic<T> > : std::true_type {};
34 
35 template <class ValueType>
37 : or_type<
38  is_rheolef_arithmetic<ValueType>
39  ,is_point<ValueType>
40  ,is_tensor<ValueType>
41  ,is_tensor3<ValueType>
42  ,is_tensor4<ValueType>
43  >
44 {};
45 
46 } // namespace details
47 namespace details {
48 template <class T1, class T2, class Sfinae = void>
50 template <class T1, class T2, class Sfinae = void>
52 
53 #define _RHEOLEF_field_promote_argument(tensor) \
54 template<class T1, class T2> \
55 struct field_promote_first_argument<tensor##_basic<T1>, T2, \
56  typename std::enable_if< \
57  is_rheolef_arithmetic<T1>::value \
58  && is_rheolef_arithmetic<T2>::value \
59  >::type \
60 > { \
61  using type = tensor##_basic<typename promote<T1,T2>::type>; }; \
62 template <class T1, class T2> \
63 struct field_promote_first_argument<T1,tensor##_basic<T2>, \
64  typename std::enable_if< \
65  is_rheolef_arithmetic<T1>::value \
66  && is_rheolef_arithmetic<T2>::value \
67  >::type \
68 > { \
69  using type = typename promote<T1,T2>::type; }; \
70 template <class T1, class T2> \
71 struct field_promote_second_argument<tensor##_basic<T1>, T2, \
72  typename std::enable_if< \
73  is_rheolef_arithmetic<T1>::value \
74  && is_rheolef_arithmetic<T2>::value \
75  >::type \
76 > { \
77  using type = typename promote<T1,T2>::type; }; \
78 template <class T1, class T2> \
79 struct field_promote_second_argument<T1,tensor##_basic<T2>, \
80  typename std::enable_if< \
81  is_rheolef_arithmetic<T1>::value \
82  && is_rheolef_arithmetic<T2>::value \
83  >::type \
84 > { \
85  using type = tensor##_basic<typename promote<T1,T2>::type>; };
86 
91 #undef _RHEOLEF_field_promote_argument
92 
93 } // namespace details
94 namespace space_constant {
95 
96 typedef size_t size_type;
97 
98 typedef enum {
99  cartesian = 0,
104 
105 coordinate_type coordinate_system (std::string sys_coord);
108 
109 typedef enum {
110  scalar = 0,
111  vector = 1,
112  tensor = 2, // symmetric, D_ij
114  tensor3 = 4, // unsymmetric, G_ijk
115  tensor4 = 5, // symmetric, A_ijkl
116  mixed = 6,
118 } valued_type;
119 
120 const std::string& valued_name (valued_type tag);
121 valued_type valued_tag (const std::string& name);
122 
123 size_type n_component (
125  size_type d,
126  coordinate_type sys_coord);
127 
128 size_type n_component (
129  const std::string& valued,
130  size_type d,
131  coordinate_type sys_coord);
132 
133 // size_t tag = valued_tag_traits<T>::value;
134 template<class T> struct valued_tag_traits { static const valued_type value = scalar; };
135 template<class T> struct valued_tag_traits<point_basic<T> > { static const valued_type value = vector; };
136 template<class T> struct valued_tag_traits<tensor_basic<T> > { static const valued_type value = tensor; };
137 template<class T> struct valued_tag_traits<tensor3_basic<T> > { static const valued_type value = tensor3; };
138 template<class T> struct valued_tag_traits<tensor4_basic<T> > { static const valued_type value = tensor4; };
139 template<class T> struct valued_tag_traits<undeterminated_basic<T> > { static const valued_type value = last_valued; };
140 
141 // typedef typename valued_type_traits<tag,T>::type valued_t;
142 template<int Tag, class T> struct valued_type_traits { typedef undeterminated_basic<T> type; };
143 template<class T> struct valued_type_traits<scalar,T> { typedef T type; };
144 template<class T> struct valued_type_traits<vector,T> { typedef point_basic<T> type; };
145 template<class T> struct valued_type_traits<tensor,T> { typedef tensor_basic<T> type; };
146 template<class T> struct valued_type_traits<tensor3,T> { typedef tensor3_basic<T> type; };
147 template<class T> struct valued_type_traits<tensor4,T> { typedef tensor4_basic<T> type; };
148 template<class T> struct valued_type_traits<last_valued,T> { typedef undeterminated_basic<T> type; };
149 
151 template<class T> struct rank_down<point_basic<T> > { typedef T type; };
152 template<class T> struct rank_down<tensor_basic<T> > { typedef point_basic<T> type; };
153 template<class T> struct rank_down<tensor3_basic<T> > { typedef tensor_basic<T> type; };
154 template<class T> struct rank_down<tensor4_basic<T> > { typedef tensor3_basic<T> type; };
155 
156 template<class T> struct rank_up { typedef point_basic<typename scalar_traits<T>::type> type; };
157 template<class T> struct rank_up<point_basic<T> > { typedef tensor_basic<T> type; };
158 template<class T> struct rank_up<tensor_basic<T> > { typedef tensor3_basic<T> type; };
159 template<class T> struct rank_up<tensor3_basic<T> > { typedef tensor4_basic<T> type; };
161 
162 template<class T>
163 T contract_product (const T& a, const T& b) { return a*b; }
164 template<class T>
165 T contract_product (const point_basic<T>& a, const point_basic<T>& b) { return dot(a,b); }
166 template<class T>
167 T contract_product (const tensor_basic<T>& a, const tensor_basic<T>& b) { return ddot(a,b); }
168 
169 size_type tensor_index (
171  coordinate_type sys_coord,
172  size_type i,
173  size_type j);
174 
175 size_type tensor_index (
176  std::string valued,
177  std::string sys_coord,
178  size_type i,
179  size_type j);
180 
181 std::pair<size_type,size_type>
183  valued_type valued_tag,
184  coordinate_type sys_coord,
185  size_type i_comp);
186 
187 std::string
189  valued_type valued_tag,
190  coordinate_type sys_coord,
191  size_type i_comp);
192 
193 std::pair<size_type,size_type>
195  std::string valued,
196  std::string sys_coord,
197  size_type i_comp);
198 
199 std::string
201  std::string valued,
202  std::string sys_coord,
203  size_type i_comp);
204 
205 size_type
207  valued_type valued,
208  coordinate_type sys_coord,
209  size_type i,
210  size_type j,
211  size_type k,
212  size_type l);
213 
214 size_type
216  std::string valued,
217  std::string sys_coord,
218  size_type i,
219  size_type j,
220  size_type k,
221  size_type l);
222 
223 std::pair<std::pair<size_type,size_type>, std::pair<size_type,size_type> >
225  valued_type valued,
226  coordinate_type sys_coord,
227  size_type i_comp);
228 
229 std::string
231  valued_type valued,
232  coordinate_type sys_coord,
233  size_type i_comp);
234 
235 std::pair<std::pair<size_type,size_type>, std::pair<size_type,size_type> >
237  std::string valued,
238  std::string sys_coord,
239  size_type i_comp);
240 
241 std::string
243  std::string valued,
244  std::string sys_coord,
245  size_type i_comp);
246 
247 // field*field & field/field valued_type computed at run time
250 
251 
252 } // namespace space_constant
253 namespace details {
254  template<class T1, class T2>
255  struct f_constant {
256  T2 operator() (const T1& x) const { return c; }
257  f_constant (const T2& c0) : c(c0) {}
258  const T2 c;
259  };
260  template<class F> struct is_vector_function :
261  and_type <
262  std::is_class<F>
263  ,is_point<typename F::result_type>
264  > {};
265  template<class T> struct is_vector_function<point_basic<T> (const point_basic<T>)>
266  : std::true_type {};
267 
268  template<class E> class field_nonlinear_expr;
269  template<class E> struct is_expr : std::false_type {};
270  template<class E> struct is_expr<field_nonlinear_expr<E> > : std::true_type {};
271 
272  template<class C>
273  struct is_constant :
274  or_type <
275  is_scalar<C>
276  ,is_point<C>
277  > {};
278 
279  template<class F>
280  struct is_function :
281  and_type <
282  or_type <
283  std::is_class<F>
284  ,std::is_pointer<F>
285  ,std::is_function<F>
286  >
287  ,not_type <
288  or_type <
289  is_scalar<F>
290  ,is_point<F>
291  ,is_expr<F>
292  >
293  >
294  >
295  {};
296  template<class F>
297  struct result_type {
299  };
300  template<class T, class R>
301  struct result_type<R(const point_basic<T>&)> {
302  typedef R type;
303  };
304  template<class T, class R>
305  struct result_type<R (*)(const point_basic<T>&)> {
306  typedef R type;
307  };
308  template<class Constant>
309  struct constant_promote { typedef Constant type; };
310  template<> struct constant_promote<int> { typedef Float type; };
311  template<> struct constant_promote<size_t> { typedef Float type; };
312 
313 } // namespace details
314 } // namespace rheolef
315 #endif // _RHEOLEF_SPACE_CONSTITUTION_H
point_basic< typename scalar_traits< T >::type > type
function_traits< F >::result_type type
valued_type multiplies_result_tag(space_constant::valued_type tag1, space_constant::valued_type tag2)
tensor_basic< Float > tensor
Definition: tensor.h:85
tensor3_basic< Float > tensor3
Definition: tensor3.h:55
valued_type divides_result_tag(space_constant::valued_type tag1, space_constant::valued_type tag2)
point - vertex of a mesh
Definition: point.h:22
coordinate_type coordinate_system(std::string sys_coord)
rheolef::details::is_vec dot
space_constant::valued_type valued_tag() const
irheostream, orheostream - large data streams
Definition: compiler.h:7
undeterminated_basic< typename scalar_traits< T >::type > type
size_type tensor4_index(valued_type valued, coordinate_type sys_coord, size_type i, size_type j, size_type k, size_type l)
undeterminated_basic< typename scalar_traits< T >::type > type
void check_coord_sys_and_dimension(coordinate_type i, size_type d)
const std::string & valued_name(valued_type valued_tag)
double Float
Definition: compiler.h:160
size_t d
std::string tensor4_subscript_name(valued_type valued, coordinate_type sys_coord, size_type i_comp)
T ddot(const tensor_basic< T > &a, const tensor_basic< T > &b)
Definition: tensor.cc:211
#define _RHEOLEF_field_promote_argument(tensor)
rheolef::std value
T contract_product(const tensor_basic< T > &a, const tensor_basic< T > &b)
std::pair< std::pair< size_type, size_type >, std::pair< size_type, size_type > > tensor4_subscript(valued_type valued, coordinate_type sys_coord, size_type i_comp)
point_basic< Float > point
Definition: point.h:122
std::pair< size_type, size_type > tensor_subscript(valued_type valued_tag, coordinate_type sys_coord, size_type i_comp)
size_type tensor_index(valued_type valued_tag, coordinate_type sys_coord, size_type i, size_type j)
tensor4_basic< Float > tensor4
Definition: tensor4.h:61
size_type n_component(valued_type valued_tag, size_type d, coordinate_type sys_coord)
std::string coordinate_system_name(coordinate_type i)
std::string tensor_subscript_name(valued_type valued_tag, coordinate_type sys_coord, size_type i_comp)