Rheolef  7.2
an efficient C++ finite element environment
 
Loading...
Searching...
No Matches
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
26namespace rheolef {
78} // namespace rheolef
79
80#include "rheolef/field_expr.h"
81
82namespace rheolef {
83
84// ---------------------------------------------------------------------------
85// N-ary function call: (f expr1...exprN) , N >= 3 only
86// ---------------------------------------------------------------------------
87namespace details {
88
89template<class NaryFunctor, class... Exprs>
91public:
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>
135 const integrate_option& iopt,
137 bool status_list[] = {(std::get<Is>(_exprs).initialize (pops, iopt), true)...};
138 }
139 template<size_t ...Is>
143 const integrate_option& iopt,
145 bool status_list[] = {(std::get<Is>(_exprs).initialize (Xh, pops, iopt), true)...};
146 }
149 const integrate_option& iopt) {
150 _initialize_internal (pops, iopt, IndexRange());
151 }
155 const integrate_option& iopt) {
156 _initialize_internal (Xh, pops, iopt, IndexRange());
157 }
158
159// evaluators:
160
161 template<class Result, size_t ...Is>
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 (
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 }
219protected:
220// data:
221 NaryFunctor _f;
222 std::tuple<Exprs...> _exprs;
223};
224template<class F, class... Exprs> struct is_field_expr_v2_nonlinear_arg <field_expr_v2_nonlinear_node_nary<F,Exprs...> > : std::true_type {};
225template<class F, class... Exprs> struct has_field_lazy_interface <field_expr_v2_nonlinear_node_nary<F,Exprs...> > : std::true_type {};
226
227} // namespace details
228// ------------------------------------------------------
229// compose(f,u1...uN)
230// ------------------------------------------------------
231// TODO: check that Function is a valid n-ary function or functor
232// TODO: check that args are valid field_expr or field_constant
233// details::and_type<details::is_field_expr_v2_nonlinear_arg<Exprs>...>::value
234// TODO: when i-th arg is field_constant, use bind to support it
235// TODO: possibly undetermined return type until run-time, when N=1,2
236// TODO: then, unary-compose and binary-compose can be removed
237template<class Function, class... Exprs>
238inline
239typename std::enable_if <
240 sizeof...(Exprs) >= 3,
244 >
245>::type
253
254} // namespace rheolef
255#endif // _RHEOLEF_COMPOSE_H
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
functor_traits< typename std::decay< NaryFunctor >::type > nary_functor_traits
Definition compose.h:100
void initialize(const piola_on_pointset< float_type > &pops, const integrate_option &iopt)
Definition compose.h:147
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... >)
Definition compose.h:140
typename nary_functor_traits::result_type result_type
Definition compose.h:101
static const space_constant::valued_type valued_hint
Definition compose.h:120
field_expr_v2_nonlinear_node_nary(const NaryFunctor &f, const Exprs &... exprs)
Definition compose.h:115
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
scalar_traits< value_type >::type scalar_type
Definition compose.h:104
void _initialize_internal(const piola_on_pointset< float_type > &pops, const integrate_option &iopt, index_list< Is... >)
Definition compose.h:133
bool _valued_check_internal(Result, index_list< Is... >) const
Definition compose.h:202
void initialize(const space_basic< float_type, memory_type > &Xh, const piola_on_pointset< float_type > &pops, const integrate_option &iopt)
Definition compose.h:152
float_traits< value_type >::type float_type
Definition compose.h:105
space_constant::valued_type valued_tag() const
Definition compose.h:122
generic mesh with rerefence counting
Definition geo.h:1089
see the geo_element page for the full documentation
reference_element::size_type size_type
see the integrate_option page for the full documentation
the finite element space
Definition space.h:382
#define rheo_default_memory_model
check_macro(expr1.have_homogeneous_space(Xh1), "dual(expr1,expr2); expr1 should have homogeneous space. HINT: use dual(interpolate(Xh, expr1),expr2)")
This file is part of Rheolef.
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:247
Definition cavity_dg.h:29
static space_constant::valued_type valued_tag(space_constant::valued_type, space_constant::valued_type)
Definition expression.h:422