1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275
|
#ifndef _RHEOLEF_FIELD_EXPR_H
#define _RHEOLEF_FIELD_EXPR_H
///
/// This file is part of Rheolef.
///
/// Copyright (C) 2000-2009 Pierre Saramito <Pierre.Saramito@imag.fr>
///
/// Rheolef is free software; you can redistribute it and/or modify
/// it under the terms of the GNU General Public License as published by
/// the Free Software Foundation; either version 2 of the License, or
/// (at your option) any later version.
///
/// Rheolef is distributed in the hope that it will be useful,
/// but WITHOUT ANY WARRANTY; without even the implied warranty of
/// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
/// GNU General Public License for more details.
///
/// You should have received a copy of the GNU General Public License
/// along with Rheolef; if not, write to the Free Software
/// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
///
/// =========================================================================
//
// field assignement from expresions, e.g.
//
// field xh = expr;
//
// author: Pierre.Saramito@imag.fr
//
// date: 13 september 2015
//
// Notes:
// check at compile time that the expression is affine
// check at run time that it is also homogneous in terms of approximation space
//
// 1. field assignments
// 1.1. field assignment members
// 1.2. computed assignment
// 2. misc
// 2.1. duality product
// 2.2. form d = diag (expr)
// 2.3. output a linear expession
#include "rheolef/field_expr_recursive.h"
namespace rheolef {
// -------------------------------------------
// 1. field assignments
// -------------------------------------------
// 1.1. field assignment members
// -------------------------------------------
// 1.1.1 field
// -------------------------------------------
#ifdef TO_CLEAN
// uh = expr;
template<class T, class M>
template<class Expr>
inline
typename std::enable_if<
details::is_field_expr_affine_homogeneous<Expr>::value
&& ! details::is_field_expr_v2_constant <Expr>::value
&& ! details::is_field <Expr>::value
,field_basic<T, M>&
>::type
field_basic<T,M>::operator= (const Expr& expr)
{
space_basic<T,M> Xh;
check_macro (expr.have_homogeneous_space (Xh),
"field = expr; expr should have homogeneous space. HINT: use field = interpolate(Xh, expr)");
if (get_space().name() != Xh.name()) {
resize (Xh);
}
details::assign_with_operator (begin_dof(), end_dof(), expr.begin_dof(), details::assign_op());
return *this;
}
// field uh = expr;
template<class T, class M>
template<class Expr, class Sfinae>
inline
field_basic<T,M>::field_basic (const Expr& expr)
: _V (),
_u (),
_b (),
_dis_dof_indexes_requires_update(true),
_dis_dof_assembly_requires_update(false)
{
operator= (expr);
}
#endif // TO_CLEAN
// ---------------------------------------------------------------------------
// 1.2. computed assignment
// ---------------------------------------------------------------------------
// uh -+= expr
// uh [i_comp] -+= expr; // note: requires a move &&
// uh [domain] -+= expr;
#define _RHEOLEF_field_expr_v2_op_assign_field(OP, FUNCTOR) \
template<class T, class M, class Expr> \
inline \
typename std::enable_if< \
details::is_field_expr_affine_homogeneous<Expr>::value, \
field_basic<T,M>& \
>::type \
operator OP (field_basic<T,M>& uh, const Expr& expr) \
{ \
space_basic<T,M> Xh; \
check_macro (expr.have_homogeneous_space (Xh), \
"field [domain] " << #OP << " expr; expr should have homogeneous space. " \
<< "HINT: use field [domain] " << #OP << " interpolate(Xh, expr)"); \
check_macro (uh.get_space().name() == Xh.name(), "field " << #OP << " field_expression : incompatible spaces " \
<< uh.get_space().name() << " and " << Xh.name()); \
details::assign_with_operator (uh.begin_dof(), uh.end_dof(), expr.begin_dof(), FUNCTOR()); \
return uh; \
}
#define _RHEOLEF_field_expr_v2_op_assign_auxil(OP, FUNCTOR, NAME, IDX) \
template<class FieldWdof, class FieldRdof> \
inline \
typename std::enable_if< \
details::is_field_expr_affine_homogeneous<FieldRdof>::value, \
NAME<FieldWdof>& \
>::type \
operator OP (NAME<FieldWdof>&& uh, const FieldRdof& expr) \
{ \
using space_type = typename FieldWdof::space_type; \
space_type Xh; \
check_macro (expr.have_homogeneous_space (Xh), \
"field [" << #IDX << "] " << #OP << " expr; expr should have homogeneous space. " \
<< "HINT: use field [" << #IDX << "] " << #OP << " interpolate(Xh, expr)"); \
check_macro (uh.get_space().name() == Xh.name(), "field [" << #IDX << "] " << #OP << " field_expression : incompatible spaces " \
<< uh.get_space().name() << " and " << Xh.name()); \
details::assign_with_operator (uh.begin_dof(), uh.end_dof(), expr.begin_dof(), FUNCTOR()); \
return uh; \
}
#define _RHEOLEF_field_expr_v2_op_assign(OP, FUNCTOR) \
_RHEOLEF_field_expr_v2_op_assign_field(OP, FUNCTOR) \
_RHEOLEF_field_expr_v2_op_assign_auxil(OP, FUNCTOR, details::field_wdof_sliced, "i_comp") \
_RHEOLEF_field_expr_v2_op_assign_auxil(OP, FUNCTOR, details::field_wdof_indirect, "domain")
_RHEOLEF_field_expr_v2_op_assign (+=, details::plus_assign)
_RHEOLEF_field_expr_v2_op_assign (-=, details::minus_assign)
#undef _RHEOLEF_field_expr_v2_op_assign_field
#undef _RHEOLEF_field_expr_v2_op_assign_auxil
#undef _RHEOLEF_field_expr_v2_op_assign
// uh -+*/= c
// uh [i_comp] -+*/= c; // requires a move &&
// uh [domain] -+*/= c; // TODO
#define _RHEOLEF_field_expr_v2_op_assign_constant_field(OP, FUNCTOR) \
template<class T, class M, class Expr> \
inline \
typename std::enable_if< \
details::is_field_expr_v2_constant<Expr>::value \
,field_basic<T,M>& \
>::type \
operator OP (field_basic<T,M>& uh, const Expr& expr) \
{ \
details::assign_with_operator (uh.begin_dof(), uh.end_dof(), details::iterator_on_constant<Expr>(expr), FUNCTOR()); \
return uh; \
}
#define _RHEOLEF_field_expr_v2_op_assign_constant_auxil(OP, FUNCTOR, NAME, IDX) \
template<class FieldWdof, class Expr> \
inline \
typename std::enable_if< \
details::is_field_expr_v2_constant<Expr>::value \
,NAME<FieldWdof>& \
>::type \
operator OP (NAME<FieldWdof>&& uh, const Expr& expr) \
{ \
details::assign_with_operator (uh.begin_dof(), uh.end_dof(), details::iterator_on_constant<Expr>(expr), FUNCTOR()); \
return uh; \
}
#define _RHEOLEF_field_expr_v2_op_assign_constant(OP, FUNCTOR) \
_RHEOLEF_field_expr_v2_op_assign_constant_field(OP, FUNCTOR) \
_RHEOLEF_field_expr_v2_op_assign_constant_auxil(OP, FUNCTOR, details::field_wdof_sliced, "i_comp") \
_RHEOLEF_field_expr_v2_op_assign_constant_auxil(OP, FUNCTOR, details::field_wdof_indirect, "domain")
_RHEOLEF_field_expr_v2_op_assign_constant (+=, details::plus_assign)
_RHEOLEF_field_expr_v2_op_assign_constant (-=, details::minus_assign)
_RHEOLEF_field_expr_v2_op_assign_constant (*=, details::multiplies_assign)
_RHEOLEF_field_expr_v2_op_assign_constant (/=, details::divides_assign)
#undef _RHEOLEF_field_expr_v2_op_assign_constant_field
#undef _RHEOLEF_field_expr_v2_op_assign_constant_auxil
#undef _RHEOLEF_field_expr_v2_op_assign_constant_auxil_old
#undef _RHEOLEF_field_expr_v2_op_assign_constant
// ---------------------------------------------------------------------------
// 2. misc
// ---------------------------------------------------------------------------
// 2.1. duality product
// ---------------------------------------------------------------------------
// dual (uh,vh)
template <class Expr1, class Expr2>
inline
typename
std::enable_if<
details::is_field_expr_affine_homogeneous<Expr1>::value &&
details::is_field_expr_affine_homogeneous<Expr2>::value,
typename promote<
typename Expr1::float_type,
typename Expr2::float_type>::type
>::type
dual (const Expr1& expr1, const Expr2& expr2)
{
typedef typename Expr1::float_type T;
typedef typename Expr1::memory_type M;
space_basic<T,M> Xh1, Xh2;
check_macro (expr1.have_homogeneous_space (Xh1),
"dual(expr1,expr2); expr1 should have homogeneous space. HINT: use dual(interpolate(Xh, expr1),expr2)");
check_macro (expr2.have_homogeneous_space (Xh2),
"dual(expr1,expr2); expr2 should have homogeneous space. HINT: use dual(expr1,interpolate(Xh, expr2))");
check_macro (Xh1.name() == Xh2.name(),
"dual(expr1,expr2); incompatible \""<<Xh1.name()<<"\" and \""<<Xh2.name()<<" spaces for expr1 and expr2");
return dis_inner_product (expr1.begin_dof(), expr2.begin_dof(), Xh1.ndof(), Xh1.ownership().comm(), M());
}
// dual (c,uh)
template <class Expr1, class Expr2>
inline
typename
std::enable_if<
details::is_field_expr_v2_constant <Expr1>::value &&
details::is_field_expr_affine_homogeneous<Expr2>::value
,typename Expr2::float_type
>::type
dual (const Expr1& expr1, const Expr2& expr2)
{
typedef typename Expr2::float_type T;
typedef typename Expr2::memory_type M;
space_basic<T,M> Xh2;
check_macro (expr2.have_homogeneous_space (Xh2),
"dual(cte,expr2); expr2 should have homogeneous space. HINT: use dual(cte,interpolate(Xh, expr2))");
return expr1*dis_accumulate (expr2.begin_dof(), Xh2.ndof(), Xh2.ownership().comm(), M());
}
// dual (uh,c)
template <class Expr1, class Expr2>
inline
typename
std::enable_if<
details::is_field_expr_affine_homogeneous<Expr1>::value &&
details::is_field_expr_v2_constant <Expr2>::value
,typename Expr1::float_type
>::type
dual (const Expr1& expr1, const Expr2& expr2)
{
typedef typename Expr1::float_type T;
typedef typename Expr1::memory_type M;
space_basic<T,M> Xh1;
check_macro (expr1.have_homogeneous_space (Xh1),
"dual(expr1,cte); expr1 should have homogeneous space. HINT: use dual(interpolate(Xh, expr1),cte)");
return dis_accumulate (expr1.begin_dof(), Xh1.ndof(), Xh1.ownership().comm(), M())*expr2;
}
// ---------------------------------------------------------------------------
// 2.2. form d = diag (expr)
// ---------------------------------------------------------------------------
template<class Expr>
inline
typename
std::enable_if<
details::has_field_rdof_interface<Expr>::value
&& ! details::is_field<Expr>::value
,form_basic <typename Expr::value_type, typename Expr::memory_type>
>::type
diag (const Expr& expr)
{
typedef typename Expr::value_type T;
typedef typename Expr::memory_type M;
return diag (field_basic<T,M>(expr));
}
} // namespace rheolef
#endif // _RHEOLEF_FIELD_EXPR_H
|