Rheolef  7.1
an efficient C++ finite element environment
field_expr_variational_tag.h
Go to the documentation of this file.
1 #ifndef _RHEOLEF_FIELD_EXPR_VARIATIONAL_TAG_H
2 #define _RHEOLEF_FIELD_EXPR_VARIATIONAL_TAG_H
23 //
24 // in a variational formulation we define things like that:
25 // a(u,v) = integrate(expr...);
26 // where expr should be linear with respect to u and v
27 // => define tag: pair of compile-time booleans
28 // that expresses the linearity with respect to each variable
29 //
30 // vf_tag is used to determine at compile time when a binary
31 // variationnal expression as : u*u, u*v, f*v, v*v*u, etc...
32 // is linear which respect to u or v, where:
33 // trial u;
34 // test v;
35 //
36 // SUMLMARY:
37 // 1. concept
38 // 2. duality
39 // 3. unary operators and functions
40 // 4. binary operators and functions
41 //
42 #include "rheolef/compiler.h"
43 #include "rheolef/expression.h"
44 namespace rheolef { namespace details {
45 
46 // ----------------------------------------------------------
47 // 1. concept: a pair of compile-time booleans
48 // ----------------------------------------------------------
49 struct vf_tag_nonlinear {};
50 typedef std::pair <std::false_type,std::false_type> vf_tag_00;
51 typedef std::pair <std::false_type,std::true_type > vf_tag_01;
52 typedef std::pair <std::true_type, std::true_type > vf_tag_11;
53 typedef std::pair <std::true_type, std::false_type> vf_tag_10;
54 // ------------------------------------------------
55 // 2. duality
56 // ------------------------------------------------
57 // vf tag: 01 <--> 10 i.e. swap test and trial
58 template<class T> struct dual_vf_tag { typedef vf_tag_nonlinear type; };
59 template<> struct dual_vf_tag <vf_tag_01> { typedef vf_tag_10 type; };
60 template<> struct dual_vf_tag <vf_tag_10> { typedef vf_tag_01 type; };
61 template<> struct dual_vf_tag <vf_tag_00> { typedef vf_tag_00 type; };
62 template<> struct dual_vf_tag <vf_tag_11> { typedef vf_tag_11 type; };
63 // --------------------------------------------------------------------
64 // 3. unary operators and functions
65 // --------------------------------------------------------------------
66 // default is nonlinear with respect to each variable
67 template <class F, class T> struct uf_vf_tag { typedef vf_tag_nonlinear type; };
68 template<class Tag> struct uf_vf_tag <unary_plus, Tag> { typedef Tag type; };
69 template<class Tag> struct uf_vf_tag <negate, Tag> { typedef Tag type; };
70 // --------------------------------------------------------------------
71 // 4. binary operators and functions
72 // --------------------------------------------------------------------
73 // default is nonlinear with respect to each variable
74 template <class F, class T1, class T2> struct bf_vf_tag { typedef vf_tag_nonlinear type; };
75 
76 // plus/minus
77 template<class Tag> struct bf_vf_tag <plus, Tag,Tag> { typedef Tag type; };
78 template<class Tag> struct bf_vf_tag <minus,Tag,Tag> { typedef Tag type; };
79 
80 // multiplies
81 template<> struct bf_vf_tag <multiplies,vf_tag_00,vf_tag_00> { typedef vf_tag_00 type; };
82 
83 template<> struct bf_vf_tag <multiplies,vf_tag_00,vf_tag_01> { typedef vf_tag_01 type; };
84 template<> struct bf_vf_tag <multiplies,vf_tag_01,vf_tag_00> { typedef vf_tag_01 type; };
85 
86 template<> struct bf_vf_tag <multiplies,vf_tag_00,vf_tag_10> { typedef vf_tag_10 type; };
87 template<> struct bf_vf_tag <multiplies,vf_tag_10,vf_tag_00> { typedef vf_tag_10 type; };
88 
89 template<> struct bf_vf_tag <multiplies,vf_tag_01,vf_tag_10> { typedef vf_tag_11 type; };
90 template<> struct bf_vf_tag <multiplies,vf_tag_10,vf_tag_01> { typedef vf_tag_11 type; };
91 template<> struct bf_vf_tag <multiplies,vf_tag_00,vf_tag_11> { typedef vf_tag_11 type; };
92 template<> struct bf_vf_tag <multiplies,vf_tag_11,vf_tag_00> { typedef vf_tag_11 type; };
93 
94 }} // namespace rheolef::details
95 #endif // _RHEOLEF_FIELD_EXPR_VARIATIONAL_TAG_H
std::pair< std::false_type, std::false_type > vf_tag_00
std::pair< std::true_type, std::true_type > vf_tag_11
std::pair< std::false_type, std::true_type > vf_tag_01
std::pair< std::true_type, std::false_type > vf_tag_10
This file is part of Rheolef.