Rheolef  7.1
an efficient C++ finite element environment
compose.h
Go to the documentation of this file.
1 #ifndef _RHEOLEF_COMPOSE_H
2 #define _RHEOLEF_COMPOSE_H
3 //
4 // This file is part of Rheolef.
5 //
6 // Copyright (C) 2000-2009 Pierre Saramito
7 //
8 // Rheolef is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
12 //
13 // Rheolef is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with Rheolef; if not, write to the Free Software
20 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 //
22 // ==========================================================================
23 // author: Pierre.Saramito@imag.fr
24 // date: 4 september 2015
25 
26 namespace rheolef {
78 } // namespace rheolef
79 
80 #include "rheolef/field_expr.h"
81 
82 namespace rheolef {
83 
84 // ---------------------------------------------------------------------------
85 // N-ary function call: (f expr1...exprN) , N >= 3 only
86 // ---------------------------------------------------------------------------
87 namespace details {
88 
89 template<class NaryFunctor, class... Exprs>
91 public:
92 // constants:
93 
94  static const size_t N = sizeof...(Exprs);
96 
97 // typedefs:
98 
101  using result_type = typename nary_functor_traits::result_type;
102 
107 #ifdef TODO
108  // TODO: extract first type Expr1 from Exprs (HOWTO extract ?) ;
109  // also, check that all args have the same memory model
110  typedef typename Expr1::memory_type memory_type;
111 #endif // TODO
112 
113 // alocators:
114 
115  field_expr_v2_nonlinear_node_nary (const NaryFunctor& f, const Exprs&... exprs)
116  : _f(f), _exprs(exprs...) {}
117 
118 // accessors:
119 
121 
123  return valued_hint; // when N >= 3 : return type should be solved at compile time
124 #ifdef TODO
125  // TODO: when N=1,2 : possible unsolved return type until run-time:
126  return details::generic_binary_traits<NaryFunctor>::valued_tag(_expr1.valued_tag(), _expr2.valued_tag());
127 #endif // TODO
128  }
129 
130 // initializers:
131 
132  template<size_t ...Is>
134  const piola_on_pointset<float_type>& pops,
135  const integrate_option& iopt,
136  index_list<Is...> ) const {
137  bool status_list[] = {(std::get<Is>(_exprs).initialize (pops, iopt), true)...};
138  }
139  template<size_t ...Is>
142  const piola_on_pointset<float_type>& pops,
143  const integrate_option& iopt,
144  index_list<Is...> ) const {
145  bool status_list[] = {(std::get<Is>(_exprs).initialize (Xh, pops, iopt), true)...};
146  }
147  void initialize (
148  const piola_on_pointset<float_type>& pops,
149  const integrate_option& iopt) const {
150  _initialize_internal (pops, iopt, IndexRange());
151  }
152  void initialize (
154  const piola_on_pointset<float_type>& pops,
155  const integrate_option& iopt) const {
156  _initialize_internal (Xh, pops, iopt, IndexRange());
157  }
158 
159 // evaluators:
160 
161  template<class Result, size_t ...Is>
163  const geo_basic<float_type,memory_type>& omega_K,
164  const geo_element& K,
165  Eigen::Matrix<Result,Eigen::Dynamic,1>& value,
166  index_list<Is...>) const
167  {
169  using vec_args_type
170  = std::tuple<
171  Eigen::Matrix<
172  typename std::decay<
173  typename traits::template arg<Is>::type
174  >::type
175  ,Eigen::Dynamic
176  ,1
177  >...
178  >;
179  vec_args_type value_i;
180  bool status_list[] = {(std::get<Is>(_exprs).evaluate (omega_K, K, std::get<Is>(value_i)), true)...};
181  size_type loc_nnod = std::get<0>(value_i).size();
182  static const int narg = sizeof...(Is);
183  size_type size_list[] = {std::get<Is>(value_i).size()...};
184  for (size_type iarg = 1; iarg < narg; ++iarg) {
185  check_macro(size_list[iarg] == loc_nnod, "invalid "<<iarg<<"-th arg-value size="<<size_list[iarg]
186  << " and 0-th arg-value size="<<loc_nnod);
187  }
188  value.resize (loc_nnod);
189  for (size_type loc_inod = 0; loc_inod < loc_nnod; ++loc_inod) {
190  value[loc_inod] = _f (std::get<Is>(value_i)[loc_inod]...);
191  }
192  }
193  template<class Result>
194  void evaluate (
195  const geo_basic<float_type,memory_type>& omega_K,
196  const geo_element& K,
197  Eigen::Matrix<Result,Eigen::Dynamic,1>& value) const
198  {
199  _evaluate_internal (omega_K, K, value, IndexRange());
200  }
201  template<class Result, size_t ...Is>
203  bool are_equivalent = (decay_is_same<Result,result_type>::value);
204  check_macro (are_equivalent,
205  "compose; incompatible function " << typename_macro(NaryFunctor)
206  << " return value " << typename_macro(result_type)
207  << " and expected value " << typename_macro(Result));
208  // check function argument type vs Exprs return types via recursive calls
209  bool status_list[] = { std::get<Is>(_exprs).template valued_check<
210  typename nary_functor_traits::template arg<Is>::decay_type>()... };
211  bool status = true;
212  for (bool status_i : status_list) { status &= status_i; }
213  return status;
214  }
215  template<class Result>
216  bool valued_check() const {
217  return _valued_check_internal (Result(), IndexRange());
218  }
219 protected:
220 // data:
221  NaryFunctor _f;
222  std::tuple<Exprs...> _exprs;
223 };
224 template<class F, class... Exprs> struct is_field_expr_v2_nonlinear_arg <field_expr_v2_nonlinear_node_nary<F,Exprs...> > : std::true_type {};
225 
226 } // namespace details
227 // ------------------------------------------------------
228 // compose(f,u1...uN)
229 // ------------------------------------------------------
230 // TODO: check that Function is a valid n-ary function or functor
231 // TODO: check that args are valid field_expr or field_constant
232 // details::and_type<details::is_field_expr_v2_nonlinear_arg<Exprs>...>::value
233 // TODO: when i-th arg is field_constant, use bind to support it
234 // TODO: possibly undetermined return type until run-time, when N=1,2
235 // TODO: then, unary-compose and binary-compose can be removed
236 template<class Function, class... Exprs>
237 inline
238 typename std::enable_if <
239  sizeof...(Exprs) >= 3,
243  >
244 >::type
246 compose (const Function& f, const Exprs&... exprs) {
251 }
252 
253 } // namespace rheolef
254 #endif // _RHEOLEF_COMPOSE_H
rheolef::details::field_expr_v2_nonlinear_node_nary::valued_hint
static const space_constant::valued_type valued_hint
Definition: compose.h:120
rheolef::geo_basic< float_type, memory_type >
rheo_default_memory_model
#define rheo_default_memory_model
Definition: distributed.h:113
check_macro
check_macro(expr1.have_homogeneous_space(Xh1), "dual(expr1,expr2); expr1 should have homogeneous space. HINT: use dual(interpolate(Xh, expr1),expr2)")
rheolef::Function
rheolef::std Function
rheolef::details::field_expr_v2_nonlinear_node_nary::_valued_check_internal
bool _valued_check_internal(Result, index_list< Is... >) const
Definition: compose.h:202
rheolef::details::field_expr_v2_nonlinear_node_nary::_initialize_internal
void _initialize_internal(const space_basic< float_type, memory_type > &Xh, const piola_on_pointset< float_type > &pops, const integrate_option &iopt, index_list< Is... >) const
Definition: compose.h:140
rheolef::details::field_expr_v2_nonlinear_node_nary::valued_check
bool valued_check() const
Definition: compose.h:216
rheolef::details::field_expr_v2_nonlinear_node_nary::N
static const size_t N
Definition: compose.h:94
rheolef::details::field_expr_v2_nonlinear_terminal_wrapper_traits::type
Expr type
Definition: field_expr_terminal.h:98
rheolef::value
rheolef::std value
rheolef::details::field_expr_v2_nonlinear_node_nary::evaluate
void evaluate(const geo_basic< float_type, memory_type > &omega_K, const geo_element &K, Eigen::Matrix< Result, Eigen::Dynamic, 1 > &value) const
Definition: compose.h:194
rheolef::_expr1
Expr1 _expr1
Definition: field_expr_recursive.h:933
rheolef::space_basic
the finite element space
Definition: space.h:352
rheolef::geo_element
see the geo_element page for the full documentation
Definition: geo_element.h:102
rheolef::details::field_expr_v2_nonlinear_node_nary::_initialize_internal
void _initialize_internal(const piola_on_pointset< float_type > &pops, const integrate_option &iopt, index_list< Is... >) const
Definition: compose.h:133
rheolef::details::field_expr_v2_nonlinear_node_nary
Definition: compose.h:90
rheolef::space_constant::valued_type
valued_type
Definition: space_constant.h:135
rheolef::details::field_expr_v2_nonlinear_node_nary::_exprs
std::tuple< Exprs... > _exprs
Definition: compose.h:222
rheolef::details::field_expr_v2_nonlinear_node_nary::size_type
geo_element::size_type size_type
Definition: compose.h:99
rheolef::integrate_option
see the integrate_option page for the full documentation
Definition: integrate_option.h:125
rheolef::details::field_expr_v2_nonlinear_node_nary::memory_type
rheo_default_memory_model memory_type
Definition: compose.h:106
rheolef::details::function_traits
Definition: field_expr_utilities.h:188
rheolef::geo_element::size_type
reference_element::size_type size_type
Definition: geo_element.h:125
rheolef::details::field_expr_v2_nonlinear_node_nary::value_type
result_type value_type
Definition: compose.h:103
rheolef::type
rheolef::std type
rheolef::details::field_expr_v2_nonlinear_node_nary::field_expr_v2_nonlinear_node_nary
field_expr_v2_nonlinear_node_nary(const NaryFunctor &f, const Exprs &... exprs)
Definition: compose.h:115
rheolef::details::field_expr_v2_nonlinear_node_nary::valued_tag
space_constant::valued_type valued_tag() const
Definition: compose.h:122
rheolef::piola_on_pointset< float_type >
rheolef
This file is part of Rheolef.
Definition: compiler_eigen.h:37
rheolef::float_traits::type
T type
Definition: Float.h:94
rheolef::details::field_expr_v2_nonlinear_node_nary::initialize
void initialize(const space_basic< float_type, memory_type > &Xh, const piola_on_pointset< float_type > &pops, const integrate_option &iopt) const
Definition: compose.h:152
rheolef::details::field_expr_v2_nonlinear_node_nary::scalar_type
scalar_traits< value_type >::type scalar_type
Definition: compose.h:104
rheolef::compose
details::field_expr_v2_nonlinear_node_nary< typename details::function_traits< Function >::functor_type,typename details::field_expr_v2_nonlinear_terminal_wrapper_traits< Exprs >::type... > ::type compose(const Function &f, const Exprs &... exprs)
see the compose page for the full documentation
Definition: compose.h:246
rheolef::scalar_traits::type
T type
Definition: point.h:324
rheolef::details::field_expr_v2_nonlinear_node_nary::_evaluate_internal
void _evaluate_internal(const geo_basic< float_type, memory_type > &omega_K, const geo_element &K, Eigen::Matrix< Result, Eigen::Dynamic, 1 > &value, index_list< Is... >) const
Definition: compose.h:162
rheolef::details::field_expr_v2_nonlinear_node_nary::result_type
typename nary_functor_traits::result_type result_type
Definition: compose.h:101
rheolef::_expr2
Expr2 _expr2
Definition: field_expr_recursive.h:934
rheolef::details::index_list
Definition: field_expr_utilities.h:115
rheolef::details::field_expr_v2_nonlinear_node_nary::float_type
float_traits< value_type >::type float_type
Definition: compose.h:105
rheolef::details::field_expr_v2_nonlinear_node_nary::initialize
void initialize(const piola_on_pointset< float_type > &pops, const integrate_option &iopt) const
Definition: compose.h:147
rheolef::details::field_expr_v2_nonlinear_node_nary::_f
NaryFunctor _f
Definition: compose.h:221
f
Definition: cavity_dg.h:29
rheolef::space_constant::valued_tag_traits
Definition: space_constant.h:161
rheolef::details::generic_binary_traits::valued_tag
static space_constant::valued_type valued_tag(space_constant::valued_type, space_constant::valued_type)
Definition: expression.h:421
rheolef::details::is_field_expr_v2_nonlinear_arg
Definition: field_expr_terminal.h:74
mkgeo_contraction.status
status
Definition: mkgeo_contraction.sh:290
rheolef::details::functor_traits
Definition: field_expr_utilities.h:146
rheolef::details::field_expr_v2_nonlinear_node_nary::IndexRange
range_builder< 0, N >::type IndexRange
Definition: compose.h:95
rheolef::details::range_builder
Definition: field_expr_utilities.h:120
rheolef::details::decay_is_same
Definition: field_expr_utilities.h:46