rheolef  6.6
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_functor.h"
7 
8 #include <boost/type_traits/is_class.hpp>
9 #include <boost/type_traits/is_function.hpp>
10 #include <boost/mpl/bool.hpp>
11 #include <boost/mpl/and.hpp>
12 #include <boost/mpl/or.hpp>
13 #include <boost/mpl/not.hpp>
14 
15 
16 namespace rheolef {
17 
18 namespace details {
19 
20 template <class T1, class T2> struct is_equal : mpl::false_ {};
21 template <class T> struct is_equal<T,T> : mpl::true_ {};
22 
23 template<class T> struct is_scalar : boost::mpl::false_ {};
24 template<> struct is_scalar<int> : boost::mpl::true_ {};
25 template<> struct is_scalar<const int> : boost::mpl::true_ {};
26 template<> struct is_scalar<size_t> : boost::mpl::true_ {};
27 template<> struct is_scalar<Float> : boost::mpl::true_ {};
28 
29 template<class T> struct is_point : boost::mpl::false_ {};
30 template<class T> struct is_point<point_basic<T> > : boost::mpl::true_ {};
31 
32 template<class T> struct is_tensor : boost::mpl::false_ {};
33 template<class T> struct is_tensor<tensor_basic<T> > : boost::mpl::true_ {};
34 
35 template<class T> struct is_tensor3 : boost::mpl::false_ {};
36 template<class T> struct is_tensor3<tensor3_basic<T> > : boost::mpl::true_ {};
37 
38 template<class T> struct is_tensor4 : boost::mpl::false_ {};
39 template<class T> struct is_tensor4<tensor4_basic<T> > : boost::mpl::true_ {};
40 
41 } // namespace details
42 
43 namespace space_constant {
44 
45 typedef size_t size_type;
46 
47 typedef enum {
48  cartesian = 0,
53 
54 coordinate_type coordinate_system (std::string sys_coord);
57 
58 typedef enum {
59  scalar = 0,
60  vector = 1,
61  tensor = 2, // symmetric, D_ij
63  tensor3 = 4, // unsymmetric, G_ijk
64  tensor4 = 5, // symmetric, A_ijkl
65  mixed = 6,
67 } valued_type;
68 
69 const std::string& valued_name (valued_type tag);
70 valued_type valued_tag (const std::string& name);
71 
72 size_type n_component (
74  size_type d,
75  coordinate_type sys_coord);
76 
77 size_type n_component (
78  const std::string& valued,
79  size_type d,
80  coordinate_type sys_coord);
81 
82 // size_t tag = valued_tag_traits<T>::value;
83 template<class T> struct valued_tag_traits { static const valued_type value = scalar; };
84 template<class T> struct valued_tag_traits<point_basic<T> > { static const valued_type value = vector; };
85 template<class T> struct valued_tag_traits<tensor_basic<T> > { static const valued_type value = tensor; };
86 template<class T> struct valued_tag_traits<tensor3_basic<T> > { static const valued_type value = tensor3; };
87 template<class T> struct valued_tag_traits<tensor4_basic<T> > { static const valued_type value = tensor4; };
88 template<class T> struct valued_tag_traits<undeterminated_basic<T> > { static const valued_type value = last_valued; };
89 
90 // typedef typename valued_type_traits<tag,T>::type valued_t;
91 template<int Tag, class T> struct valued_type_traits { typedef undeterminated_basic<T> type; };
92 template<class T> struct valued_type_traits<scalar,T> { typedef T type; };
93 template<class T> struct valued_type_traits<vector,T> { typedef point_basic<T> type; };
94 template<class T> struct valued_type_traits<tensor,T> { typedef tensor_basic<T> type; };
95 template<class T> struct valued_type_traits<tensor3,T> { typedef tensor3_basic<T> type; };
96 template<class T> struct valued_type_traits<tensor4,T> { typedef tensor4_basic<T> type; };
97 template<class T> struct valued_type_traits<last_valued,T> { typedef undeterminated_basic<T> type; };
98 
100 template<class T> struct rank_down<point_basic<T> > { typedef T type; };
101 template<class T> struct rank_down<tensor_basic<T> > { typedef point_basic<T> type; };
102 template<class T> struct rank_down<tensor3_basic<T> > { typedef tensor_basic<T> type; };
103 template<class T> struct rank_down<tensor4_basic<T> > { typedef tensor3_basic<T> type; };
104 
105 template<class T> struct rank_up { typedef point_basic<typename scalar_traits<T>::type> type; };
106 template<class T> struct rank_up<point_basic<T> > { typedef tensor_basic<T> type; };
107 template<class T> struct rank_up<tensor_basic<T> > { typedef tensor3_basic<T> type; };
108 template<class T> struct rank_up<tensor3_basic<T> > { typedef tensor4_basic<T> type; };
110 
111 template<class T>
112 T contract_product (const T& a, const T& b) { return a*b; }
113 template<class T>
114 T contract_product (const point_basic<T>& a, const point_basic<T>& b) { return dot(a,b); }
115 template<class T>
116 T contract_product (const tensor_basic<T>& a, const tensor_basic<T>& b) { return ddot(a,b); }
117 
118 size_type tensor_index (
120  coordinate_type sys_coord,
121  size_type i,
122  size_type j);
123 
124 size_type tensor_index (
125  std::string valued,
126  std::string sys_coord,
127  size_type i,
128  size_type j);
129 
130 std::pair<size_type,size_type>
133  coordinate_type sys_coord,
134  size_type i_comp);
135 
136 std::string
139  coordinate_type sys_coord,
140  size_type i_comp);
141 
142 std::pair<size_type,size_type>
144  std::string valued,
145  std::string sys_coord,
146  size_type i_comp);
147 
148 std::string
150  std::string valued,
151  std::string sys_coord,
152  size_type i_comp);
153 
154 size_type
156  valued_type valued,
157  coordinate_type sys_coord,
158  size_type i,
159  size_type j,
160  size_type k,
161  size_type l);
162 
163 size_type
165  std::string valued,
166  std::string sys_coord,
167  size_type i,
168  size_type j,
169  size_type k,
170  size_type l);
171 
172 std::pair<std::pair<size_type,size_type>, std::pair<size_type,size_type> >
174  valued_type valued,
175  coordinate_type sys_coord,
176  size_type i_comp);
177 
178 std::string
180  valued_type valued,
181  coordinate_type sys_coord,
182  size_type i_comp);
183 
184 std::pair<std::pair<size_type,size_type>, std::pair<size_type,size_type> >
186  std::string valued,
187  std::string sys_coord,
188  size_type i_comp);
189 
190 std::string
192  std::string valued,
193  std::string sys_coord,
194  size_type i_comp);
195 
196 // field*field & field/field valued_type computed at run time
199 
200 
201 } // namespace space_constant
202 namespace details {
203  template<class T1, class T2>
204  struct f_constant : field_functor<f_constant<T1,T2>,T2 > {
205  const T2& operator() (const T1& x) const { return c; }
206  f_constant (const T2& c0) : c(c0) {}
207  T2 c;
208  };
209  template<class F> struct is_vector_function :
210  boost::mpl::and_ <
211  boost::is_class<F>
212  ,is_point<typename F::result_type>
213  > {};
214  template<class T> struct is_vector_function<point_basic<T> (const point_basic<T>)>
215  : boost::mpl::true_ {};
216 
217  template<class E> class field_nonlinear_expr;
218  template<class E> struct is_expr : boost::mpl::false_ {};
219  template<class E> struct is_expr<field_nonlinear_expr<E> > : boost::mpl::true_ {};
220 
221  template<class C>
222  struct is_constant :
223  boost::mpl::or_ <
224  is_scalar<C>
225  ,is_point<C>
226  > {};
227 
228  template<class F>
229  struct is_function :
230  boost::mpl::and_ <
231  boost::mpl::or_ <
232  boost::is_class<F>
233  ,boost::is_pointer<F>
234  ,boost::is_function<F>
235  >
236  ,boost::mpl::not_ <
237  boost::mpl::or_ <
238  is_scalar<F>
239  ,is_point<F>
240  ,is_expr<F>
241  >
242  >
243  >
244  {};
245  template<class F>
246  struct result_type {
247  typedef typename F::result_type type;
248  };
249  template<class T, class R>
250  struct result_type<R(const point_basic<T>&)> {
251  typedef R type;
252  };
253  template<class T, class R>
254  struct result_type<R (*)(const point_basic<T>&)> {
255  typedef R type;
256  };
257  template<class Constant>
258  struct constant_promote { typedef Constant type; };
259  template<> struct constant_promote<int> { typedef Float type; };
260  template<> struct constant_promote<size_t> { typedef Float type; };
261 
262 } // namespace details
263 } // namespace rheolef
264 #endif // _RHEOLEF_SPACE_CONSTITUTION_H
point_basic< typename scalar_traits< T >::type > type
valued_type multiplies_result_tag(space_constant::valued_type tag1, space_constant::valued_type tag2)
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)
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)
field_functor - a functor wrapper suitable for field expressions
Definition: field_functor.h:59
const T2 & operator()(const T1 &x) const
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:177
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:200
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)
T contract_product(const T &a, const T &b)
valued_type valued_tag(const std::string &name)
T dot(const vec< T, M > &x, const int &y)
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)
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)