Loading...
Searching...
No Matches
space_constant.h
Go to the documentation of this file.
#ifndef _RHEOLEF_SPACE_CONSTANT_H
#define _RHEOLEF_SPACE_CONSTANT_H
// constants
#include "rheolef/undeterminated.h"
#include "rheolef/field_expr_utilities.h"
#include <type_traits>
// ---------------------------------------------------------------------------
// utility
// ---------------------------------------------------------------------------
namespace rheolef { namespace details {
// is_equal : used by type resolution and by is_symmetric
template <class T1, class T2> struct is_equal : std::false_type {};
template <class T> struct is_equal<T,T> : std::true_type {};
// switch for a constant, or a pointer-to-function or a class-function:
template<class T> struct is_scalar : std::false_type {};
template<> struct is_scalar<int> : std::true_type {};
template<> struct is_scalar<const int> : std::true_type {};
template<> struct is_scalar<size_t> : std::true_type {};
template<> struct is_scalar<double> : std::true_type {};
#ifdef _RHEOLEF_HAVE_FLOAT128
template<> struct is_scalar<float128> : std::true_type {};
#endif // _RHEOLEF_HAVE_FLOAT128
template<class T> struct is_point : std::false_type {};
template<class T> struct is_point<point_basic<T> > : std::true_type {};
template<class T> struct is_tensor : std::false_type {};
template<class T> struct is_tensor<tensor_basic<T> > : std::true_type {};
template<class T> struct is_tensor3 : std::false_type {};
template<class T> struct is_tensor3<tensor3_basic<T> > : std::true_type {};
template<class T> struct is_tensor4 : std::false_type {};
template<class T> struct is_tensor4<tensor4_basic<T> > : std::true_type {};
} // namespace details
// ---------------------------------------------------------------------------
// argument promote, for template expression (binders, etc)
// ---------------------------------------------------------------------------
namespace details {
template <class T1, class T2, class Sfinae = void>
struct field_promote_first_argument: promote<T1,T2> {};
template <class T1, class T2, class Sfinae = void>
struct field_promote_second_argument: promote<T1,T2> {};
#define _RHEOLEF_field_promote_argument(tensor) \
template<class T1, class T2> \
struct field_promote_first_argument<tensor##_basic<T1>, T2, \
typename std::enable_if< \
is_rheolef_arithmetic<T1>::value \
&& is_rheolef_arithmetic<T2>::value \
>::type \
> { \
using type = tensor##_basic<typename promote<T1,T2>::type>; }; \
template <class T1, class T2> \
struct field_promote_first_argument<T1,tensor##_basic<T2>, \
typename std::enable_if< \
is_rheolef_arithmetic<T1>::value \
&& is_rheolef_arithmetic<T2>::value \
>::type \
> { \
using type = typename promote<T1,T2>::type; }; \
template <class T1, class T2> \
struct field_promote_second_argument<tensor##_basic<T1>, T2, \
typename std::enable_if< \
is_rheolef_arithmetic<T1>::value \
&& is_rheolef_arithmetic<T2>::value \
>::type \
> { \
using type = typename promote<T1,T2>::type; }; \
template <class T1, class T2> \
struct field_promote_second_argument<T1,tensor##_basic<T2>, \
typename std::enable_if< \
is_rheolef_arithmetic<T1>::value \
&& is_rheolef_arithmetic<T2>::value \
>::type \
> { \
using type = tensor##_basic<typename promote<T1,T2>::type>; };
_RHEOLEF_field_promote_argument(point)
_RHEOLEF_field_promote_argument(tensor)
_RHEOLEF_field_promote_argument(tensor3)
_RHEOLEF_field_promote_argument(tensor4)
#undef _RHEOLEF_field_promote_argument
} // namespace details
// -------------------------------------------------------------
// coordinate system helper
// -------------------------------------------------------------
namespace space_constant {
typedef size_t size_type;
typedef enum {
cartesian = 0,
axisymmetric_rz = 1,
axisymmetric_zr = 2,
last_coord_sys = 3
} coordinate_type;
coordinate_type coordinate_system (std::string sys_coord);
std::string coordinate_system_name (coordinate_type);
void check_coord_sys_and_dimension (coordinate_type, size_type d);
// -------------------------------------------------------------
// multi-component field support
// -------------------------------------------------------------
typedef enum {
scalar = 0,
vector = 1,
tensor = 2, // symmetric, D_ij
unsymmetric_tensor = 3,
tensor3 = 4, // unsymmetric, G_ijk
tensor4 = 5, // symmetric, A_ijkl
mixed = 6,
last_valued = 7
} valued_type;
const std::string& valued_name (valued_type tag);
valued_type valued_tag (const std::string& name);
size_type n_component (
valued_type valued_tag,
size_type d,
coordinate_type sys_coord);
size_type n_component (
const std::string& valued,
size_type d,
coordinate_type sys_coord);
// convert a type to the enum valued_tag:
// size_t tag = valued_tag_traits<T>::value;
template<class T> struct valued_tag_traits { static const valued_type value = scalar; };
template<class T> struct valued_tag_traits<point_basic<T> > { static const valued_type value = vector; };
template<class T> struct valued_tag_traits<tensor_basic<T> > { static const valued_type value = tensor; };
template<class T> struct valued_tag_traits<tensor3_basic<T> > { static const valued_type value = tensor3; };
template<class T> struct valued_tag_traits<tensor4_basic<T> > { static const valued_type value = tensor4; };
template<class T> struct valued_tag_traits<undeterminated_basic<T> > { static const valued_type value = last_valued; };
// convert an enum valued_tag to the type based on T:
// typedef typename valued_type_traits<tag,T>::type valued_t;
//
template<int Tag, class T> struct valued_type_traits { typedef undeterminated_basic<T> type; };
template<class T> struct valued_type_traits<scalar,T> { typedef T type; };
template<class T> struct valued_type_traits<vector,T> { typedef point_basic<T> type; };
template<class T> struct valued_type_traits<tensor,T> { typedef tensor_basic<T> type; };
template<class T> struct valued_type_traits<tensor3,T> { typedef tensor3_basic<T> type; };
template<class T> struct valued_type_traits<tensor4,T> { typedef tensor4_basic<T> type; };
template<class T> struct valued_type_traits<last_valued,T> { typedef undeterminated_basic<T> type; };
// tensorial up and down helpers (for grad(expr))
template<class T> struct rank_down { typedef undeterminated_basic<typename scalar_traits<T>::type> type; };
template<class T> struct rank_down<point_basic<T> > { typedef T type; };
template<class T> struct rank_down<tensor_basic<T> > { typedef point_basic<T> type; };
template<class T> struct rank_down<tensor3_basic<T> > { typedef tensor_basic<T> type; };
template<class T> struct rank_down<tensor4_basic<T> > { typedef tensor3_basic<T> type; };
template<class T> struct rank_up { typedef point_basic<typename scalar_traits<T>::type> type; };
template<class T> struct rank_up<point_basic<T> > { typedef tensor_basic<T> type; };
template<class T> struct rank_up<tensor_basic<T> > { typedef tensor3_basic<T> type; };
template<class T> struct rank_up<tensor3_basic<T> > { typedef tensor4_basic<T> type; };
template<class T> struct rank_up<undeterminated_basic<T> > { typedef undeterminated_basic<typename scalar_traits<T>::type> type; };
template<class T>
T contract_product (const T& a, const T& b) { return a*b; }
template<class T>
T contract_product (const point_basic<T>& a, const point_basic<T>& b) { return dot(a,b); }
template<class T>
T contract_product (const tensor_basic<T>& a, const tensor_basic<T>& b) { return ddot(a,b); }
// -------------------------------------------------------------
// 2-tensor support
// -------------------------------------------------------------
size_type tensor_index (
valued_type valued_tag,
coordinate_type sys_coord,
size_type i,
size_type j);
size_type tensor_index (
std::string valued,
std::string sys_coord,
size_type i,
size_type j);
std::pair<size_type,size_type>
tensor_subscript (
valued_type valued_tag,
coordinate_type sys_coord,
size_type i_comp);
std::string
tensor_subscript_name (
valued_type valued_tag,
coordinate_type sys_coord,
size_type i_comp);
std::pair<size_type,size_type>
tensor_subscript (
std::string valued,
std::string sys_coord,
size_type i_comp);
std::string
tensor_subscript_name (
std::string valued,
std::string sys_coord,
size_type i_comp);
// -------------------------------------------------------------
// 4-tensor support
// -------------------------------------------------------------
size_type
tensor4_index (
valued_type valued,
coordinate_type sys_coord,
size_type i,
size_type j,
size_type k,
size_type l);
size_type
tensor4_index (
std::string valued,
std::string sys_coord,
size_type i,
size_type j,
size_type k,
size_type l);
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);
std::string
tensor4_subscript_name (
valued_type valued,
coordinate_type sys_coord,
size_type i_comp);
std::pair<std::pair<size_type,size_type>, std::pair<size_type,size_type> >
tensor4_subscript (
std::string valued,
std::string sys_coord,
size_type i_comp);
std::string
tensor4_subscript_name (
std::string valued,
std::string sys_coord,
size_type i_comp);
// -------------------------------------------------------------
// field*field & field/field valued_type computed at run time
// -------------------------------------------------------------
valued_type multiplies_result_tag (valued_type tag1, valued_type tag2);
valued_type divides_result_tag (valued_type tag1, valued_type tag2);
} // namespace space_constant
// --------------------------------------------------------------------------
// utility to determine whether a template arg is a function or a constant
// --------------------------------------------------------------------------
namespace details {
// build a function that returns a constant
template<class T1, class T2>
struct f_constant {
T2 operator() (const T1& x) const { return c; }
f_constant (const T2& c0) : c(c0) {}
const T2 c;
};
template<class F> struct is_vector_function :
and_type <
std::is_class<F>
,is_point<typename F::result_type>
> {};
template<class T> struct is_vector_function<point_basic<T> (const point_basic<T>)>
: std::true_type {};
template<class E> class field_nonlinear_expr;
template<class E> struct is_expr : std::false_type {};
template<class E> struct is_expr<field_nonlinear_expr<E> > : std::true_type {};
template<class C>
struct is_constant :
or_type <
is_scalar<C>
,is_point<C>
> {};
template<class F>
struct is_function :
and_type <
or_type <
std::is_class<F>
,std::is_pointer<F>
,std::is_function<F>
>
,not_type <
or_type <
is_scalar<F>
,is_point<F>
,is_expr<F>
>
>
>
{};
template<class F>
struct result_type {
typedef typename function_traits<F>::result_type type;
};
template<class T, class R>
struct result_type<R(const point_basic<T>&)> {
typedef R type;
};
template<class T, class R>
struct result_type<R (*)(const point_basic<T>&)> {
typedef R type;
};
template<class Constant>
struct constant_promote { typedef Constant type; };
template<> struct constant_promote<int> { typedef Float type; };
template<> struct constant_promote<size_t> { typedef Float type; };
#ifdef _RHEOLEF_HAVE_FLOAT128
template<> struct constant_promote<double> { typedef Float type; };
#endif // _RHEOLEF_HAVE_FLOAT128
// constants in field expressions
template <class Value>
struct is_field_expr_v2_constant
: std::disjunction<
is_rheolef_arithmetic<Value>
,is_point<Value>
,is_tensor<Value>
,is_tensor3<Value>
,is_tensor4<Value>
>
{};
}} // namespace rheolef::details
#endif // _RHEOLEF_SPACE_CONSTITUTION_H
Float
see the Float page for the full documentation
point
see the point page for the full documentation
rheolef::details::field_nonlinear_expr
Definition space_constant.h:308
rheolef::point_basic
Definition point.h:86
rheolef::tensor3_basic
Definition tensor3.h:73
rheolef::tensor4_basic
Definition tensor4.h:80
rheolef::tensor_basic
Definition tensor.h:90
tensor3
see the tensor3 page for the full documentation
tensor4
see the tensor4 page for the full documentation
tensor
see the tensor page for the full documentation
T
Expr1::float_type T
Definition field_expr.h:230
rheolef::details
Definition compiler_eigen.h:39
rheolef::space_constant
Definition space_constant.cc:25
rheolef::space_constant::valued_type
valued_type
Definition space_constant.h:133
rheolef::space_constant::tensor
@ tensor
Definition space_constant.h:136
rheolef::space_constant::scalar
@ scalar
Definition space_constant.h:134
rheolef::space_constant::unsymmetric_tensor
@ unsymmetric_tensor
Definition space_constant.h:137
rheolef::space_constant::mixed
@ mixed
Definition space_constant.h:140
rheolef::space_constant::vector
@ vector
Definition space_constant.h:135
rheolef::space_constant::tensor3
@ tensor3
Definition space_constant.h:138
rheolef::space_constant::tensor4
@ tensor4
Definition space_constant.h:139
rheolef::space_constant::last_valued
@ last_valued
Definition space_constant.h:141
rheolef::space_constant::check_coord_sys_and_dimension
void check_coord_sys_and_dimension(coordinate_type i, size_type d)
Definition space_constant.cc:83
rheolef::space_constant::coordinate_system
coordinate_type coordinate_system(std::string sys_coord)
Definition space_constant.cc:75
rheolef::space_constant::coordinate_system_name
std::string coordinate_system_name(coordinate_type i)
Definition space_constant.cc:69
rheolef::space_constant::multiplies_result_tag
valued_type multiplies_result_tag(space_constant::valued_type tag1, space_constant::valued_type tag2)
Definition space_constant.cc:410
rheolef::space_constant::tensor4_index
size_type tensor4_index(valued_type valued, coordinate_type sys_coord, size_type i, size_type j, size_type k, size_type l)
Definition space_constant.cc:333
rheolef::space_constant::size_type
size_t size_type
Definition space_constant.h:117
rheolef::space_constant::contract_product
T contract_product(const T &a, const T &b)
Definition space_constant.h:191
rheolef::space_constant::tensor_subscript_name
std::string tensor_subscript_name(valued_type valued_tag, coordinate_type sys_coord, size_type i_comp)
Definition space_constant.cc:227
rheolef::space_constant::tensor_index
size_type tensor_index(valued_type valued_tag, coordinate_type sys_coord, size_type i, size_type j)
Definition space_constant.cc:181
rheolef::space_constant::divides_result_tag
valued_type divides_result_tag(space_constant::valued_type tag1, space_constant::valued_type tag2)
Definition space_constant.cc:421
rheolef::space_constant::tensor4_subscript
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)
Definition space_constant.cc:357
rheolef::space_constant::tensor4_subscript_name
std::string tensor4_subscript_name(valued_type valued, coordinate_type sys_coord, size_type i_comp)
Definition space_constant.cc:369
rheolef::space_constant::valued_name
const std::string & valued_name(valued_type valued_tag)
Definition space_constant.cc:43
rheolef::space_constant::n_component
size_type n_component(valued_type valued_tag, size_type d, coordinate_type sys_coord)
Definition space_constant.cc:136
rheolef::space_constant::coordinate_type
coordinate_type
Definition space_constant.h:119
rheolef::space_constant::last_coord_sys
@ last_coord_sys
Definition space_constant.h:123
rheolef::space_constant::cartesian
@ cartesian
Definition space_constant.h:120
rheolef::space_constant::axisymmetric_zr
@ axisymmetric_zr
Definition space_constant.h:122
rheolef::space_constant::axisymmetric_rz
@ axisymmetric_rz
Definition space_constant.h:121
rheolef::space_constant::tensor_subscript
std::pair< size_type, size_type > tensor_subscript(valued_type valued_tag, coordinate_type sys_coord, size_type i_comp)
Definition space_constant.cc:209
rheolef
This file is part of Rheolef.
Definition compiler_eigen.h:39
rheolef::ddot
T ddot(const tensor_basic< T > &a, const tensor_basic< T > &b)
ddot(x,y): see the expression page for the full documentation
Definition tensor.cc:278
rheolef::dot
rheolef::std::enable_if< details::is_vec_expr_v2_arg< Expr1 >::value &&details::is_vec_expr_v2_arg< Expr2 >::value, promote< Expr1::float_type, Expr2::float_type >::type > type dot const Expr1 expr1, const Expr2 expr2 dot(const Expr1 &expr1, const Expr2 &expr2)
Definition vec_expr_v2.h:415
rheolef::valued_tag
space_constant::valued_type valued_tag() const
Definition field_expr_recursive.h:620
d
size_t d
Definition neumann-laplace-lambda.cc:28
_RHEOLEF_field_promote_argument
#define _RHEOLEF_field_promote_argument(tensor)
Definition space_constant.h:71
rheolef::details::and_type
Definition field_expr_utilities.h:77
rheolef::details::constant_promote< int >::type
Float type
Definition space_constant.h:350
rheolef::details::constant_promote< size_t >::type
Float type
Definition space_constant.h:351
rheolef::details::constant_promote
Definition space_constant.h:349
rheolef::details::constant_promote::type
Constant type
Definition space_constant.h:349
rheolef::details::f_constant< point_basic< float_type >, Expr >::c
const Expr c
Definition space_constant.h:298
rheolef::details::f_constant::operator()
T2 operator()(const T1 &x) const
Definition space_constant.h:296
rheolef::details::f_constant::f_constant
f_constant(const T2 &c0)
Definition space_constant.h:297
rheolef::details::field_promote_first_argument
Definition space_constant.h:67
rheolef::details::field_promote_second_argument
Definition space_constant.h:69
rheolef::details::function_traits
Definition field_expr_utilities.h:184
rheolef::details::is_constant
Definition space_constant.h:317
rheolef::details::type
rheolef::details::is_equal
Definition space_constant.h:36
rheolef::details::is_expr
Definition space_constant.h:309
rheolef::details::is_field_expr_v2_constant
Definition space_constant.h:366
rheolef::details::is_function
Definition space_constant.h:335
rheolef::details::is_point
Definition space_constant.h:49
rheolef::details::is_scalar
Definition space_constant.h:40
rheolef::details::is_tensor3
Definition space_constant.h:55
rheolef::details::is_tensor4
Definition space_constant.h:58
rheolef::details::is_tensor
Definition space_constant.h:52
rheolef::details::is_vector_function
Definition space_constant.h:304
rheolef::details::or_type
Definition field_expr_utilities.h:54
rheolef::details::result_type< R(*)(const point_basic< T > &)>::type
R type
Definition space_constant.h:346
rheolef::details::result_type< R(const point_basic< T > &)>::type
R type
Definition space_constant.h:342
rheolef::details::result_type
Definition space_constant.h:337
rheolef::details::result_type::type
function_traits< F >::result_type type
Definition space_constant.h:338
rheolef::promote
Definition promote.h:29
rheolef::space_constant::rank_down< point_basic< T > >::type
T type
Definition space_constant.h:179
rheolef::space_constant::rank_down< tensor3_basic< T > >::type
tensor_basic< T > type
Definition space_constant.h:181
rheolef::space_constant::rank_down< tensor4_basic< T > >::type
tensor3_basic< T > type
Definition space_constant.h:182
rheolef::space_constant::rank_down< tensor_basic< T > >::type
point_basic< T > type
Definition space_constant.h:180
rheolef::space_constant::rank_down
Definition space_constant.h:178
rheolef::space_constant::rank_down::type
undeterminated_basic< typename scalar_traits< T >::type > type
Definition space_constant.h:178
rheolef::space_constant::rank_up< point_basic< T > >::type
tensor_basic< T > type
Definition space_constant.h:185
rheolef::space_constant::rank_up< tensor3_basic< T > >::type
tensor4_basic< T > type
Definition space_constant.h:187
rheolef::space_constant::rank_up< tensor_basic< T > >::type
tensor3_basic< T > type
Definition space_constant.h:186
rheolef::space_constant::rank_up< undeterminated_basic< T > >::type
undeterminated_basic< typename scalar_traits< T >::type > type
Definition space_constant.h:188
rheolef::space_constant::rank_up
Definition space_constant.h:184
rheolef::space_constant::rank_up::type
point_basic< typename scalar_traits< T >::type > type
Definition space_constant.h:184
rheolef::space_constant::valued_tag_traits< point_basic< T > >::value
static const valued_type value
Definition space_constant.h:160
rheolef::space_constant::valued_tag_traits< tensor3_basic< T > >::value
static const valued_type value
Definition space_constant.h:162
rheolef::space_constant::valued_tag_traits< tensor4_basic< T > >::value
static const valued_type value
Definition space_constant.h:163
rheolef::space_constant::valued_tag_traits< tensor_basic< T > >::value
static const valued_type value
Definition space_constant.h:161
rheolef::space_constant::valued_tag_traits< undeterminated_basic< T > >::value
static const valued_type value
Definition space_constant.h:164
rheolef::space_constant::valued_tag_traits
Definition space_constant.h:159
rheolef::space_constant::valued_tag_traits::value
static const valued_type value
Definition space_constant.h:159
rheolef::space_constant::valued_type_traits< last_valued, T >::type
undeterminated_basic< T > type
Definition space_constant.h:175
rheolef::space_constant::valued_type_traits< scalar, T >::type
T type
Definition space_constant.h:170
rheolef::space_constant::valued_type_traits< tensor3, T >::type
tensor3_basic< T > type
Definition space_constant.h:173
rheolef::space_constant::valued_type_traits< tensor4, T >::type
tensor4_basic< T > type
Definition space_constant.h:174
rheolef::space_constant::valued_type_traits< tensor, T >::type
tensor_basic< T > type
Definition space_constant.h:172
rheolef::space_constant::valued_type_traits< vector, T >::type
point_basic< T > type
Definition space_constant.h:171
rheolef::space_constant::valued_type_traits
Definition space_constant.h:169
rheolef::space_constant::valued_type_traits::type
undeterminated_basic< T > type
Definition space_constant.h:169
rheolef::undeterminated_basic
helper for generic field value_type: T, point_basic<T> or tensor_basic<T>
Definition undeterminated.h:32