/usr/include/rheolef/form_vf_expr.h is in librheolef-dev 6.6-1build2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 | #ifndef _RHEOLEF_FORM_VF_EXPR_H
#define _RHEOLEF_FORM_VF_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
///
/// =========================================================================
//
// form_vf_expr: used for expressions in variationnal formulations
//
#include "rheolef/vf_tag.h"
#include <boost/numeric/ublas/matrix.hpp> // ublas::matrix
namespace rheolef {
namespace ublas = boost::numeric::ublas;
// ---------------------------------------------------------------------------
// wrapper
// ---------------------------------------------------------------------------
template<class RawExpr>
class form_vf_expr {
public:
// typedefs:
typedef typename RawExpr::size_type size_type;
typedef typename RawExpr::memory_type memory_type;
typedef typename RawExpr::value_type value_type;
typedef typename RawExpr::scalar_type scalar_type;
typedef typename RawExpr::float_type float_type;
typedef typename RawExpr::space_type space_type;
typedef typename RawExpr::vf_tag_type vf_tag_type;
typedef typename RawExpr::vf_dual_tag_type vf_dual_tag_type;
typedef form_vf_expr<RawExpr> self_type;
typedef form_vf_expr<typename RawExpr::dual_self_type>
dual_self_type;
typedef typename RawExpr::maybe_symmetric maybe_symmetric;
static const space_constant::valued_type valued_hint = space_constant::valued_tag_traits<value_type>::value;
// alocators:
form_vf_expr (const RawExpr& raw_expr)
: _raw_expr(raw_expr) {}
// accessors:
const space_type& get_test_space() const { return _raw_expr.get_test_space(); }
const space_type& get_trial_space() const { return _raw_expr.get_trial_space(); }
size_type n_derivative() const { return _raw_expr.n_derivative(); }
// mutable modifiers:
bool initialize (const geo_basic<float_type,memory_type>& dom, const quadrature<float_type>& quad, bool ignore_sys_coord) const {
return _raw_expr.initialize (dom, quad, ignore_sys_coord);
}
void initialize (const band_basic<float_type,memory_type>& gh, const quadrature<float_type>& quad, bool ignore_sys_coord) const {
_raw_expr.initialize (gh, quad, ignore_sys_coord);
}
void element_initialize (const geo_element& K) const {
_raw_expr.element_initialize (K);
}
void basis_evaluate (const reference_element& hat_K, size_type q, ublas::matrix<scalar_type>& value) const {
_raw_expr.basis_evaluate (hat_K, q, value);
}
template<class ValueType>
bool valued_check() const {
static const bool status = details::is_equal<ValueType,scalar_type>::value;
check_macro (status, "unexpected result_type");
return _raw_expr.valued_check<ValueType>();
}
protected:
// data:
RawExpr _raw_expr;
};
// ---------------------------------------------------------------------------
// binary function call: (f field_expr1 field_expr2) -> form_expr
// example: integrate(u*v)
// ---------------------------------------------------------------------------
template<class BinaryFunction, class Expr1, class Expr2>
class form_vf_expr_bf_field {
public:
// typedefs:
typedef geo_element::size_type size_type;
typedef typename promote_memory<typename Expr1::memory_type,typename Expr2::memory_type>::type
memory_type;
typedef typename details::generic_binary_traits<BinaryFunction>::template result_hint<
typename Expr1::value_type
,typename Expr2::value_type>::type result_hint;
typedef typename details::generic_binary_traits<BinaryFunction>::template hint<
typename Expr1::value_type
,typename Expr2::value_type
,result_hint>::result_type value_type;
typedef typename scalar_traits<value_type>::type scalar_type;
typedef typename float_traits<value_type>::type float_type;
typedef space_basic<scalar_type,memory_type> space_type; // TODO: deduce from Exprs
typedef typename details::bf_vf_tag<BinaryFunction,
typename Expr1::vf_tag_type,
typename Expr2::vf_tag_type>::type vf_tag_type;
typedef typename details::dual_vf_tag<vf_tag_type>::type
vf_dual_tag_type;
typedef form_vf_expr_bf_field<BinaryFunction,Expr1,Expr2> self_type;
typedef form_vf_expr_bf_field<BinaryFunction,typename Expr1::dual_self_type,typename Expr2::dual_self_type>
dual_self_type;
typedef typename mpl::and_<typename details::generic_binary_traits<BinaryFunction>::is_symmetric::type,
typename details::is_equal<
Expr1,
typename Expr2::dual_self_type>::type>::type
maybe_symmetric;
static const space_constant::valued_type valued_hint = space_constant::valued_tag_traits<value_type>::value;
// alocators:
form_vf_expr_bf_field (const BinaryFunction& f,
const Expr1& expr1,
const Expr2& expr2)
: _f(f), _expr1(expr1), _expr2(expr2) {}
// accessors:
const space_type& get_test_space() const {
return (details::is_equal<typename Expr1::vf_tag_type, details::vf_tag_01>::value) ?
_expr1.get_vf_space() : _expr2.get_vf_space();
}
const space_type& get_trial_space() const {
return (details::is_equal<typename Expr1::vf_tag_type, details::vf_tag_10>::value) ?
_expr1.get_vf_space() : _expr2.get_vf_space();
}
size_type n_derivative() const { return _expr1.n_derivative() + _expr2.n_derivative(); }
// mutable modifiers:
bool initialize (const geo_basic<float_type,memory_type>& dom, const quadrature<float_type>& quad, bool ignore_sys_coord) const {
_expr1.initialize (dom, quad, ignore_sys_coord);
_expr2.initialize (dom, quad, ignore_sys_coord);
return true;
}
void initialize (const band_basic<float_type,memory_type>& gh, const quadrature<float_type>& quad, bool ignore_sys_coord) const {
_expr1.initialize (gh, quad, ignore_sys_coord);
_expr2.initialize (gh, quad, ignore_sys_coord);
}
void element_initialize (const geo_element& K) const {
_expr1.element_initialize (K);
_expr2.element_initialize (K);
}
template<class ValueType, class Arg1, class Arg2>
void evaluate_call (const reference_element& hat_K, size_type q, ublas::matrix<ValueType>& value) const {
if (details::is_equal<typename Expr2::vf_tag_type, details::vf_tag_01>::value) {
// expr1 is trial and expr2 is test
std::vector<Arg2> v_test (value.size1()); _expr2.basis_evaluate (hat_K, q, v_test);
std::vector<Arg1> u_trial (value.size2()); _expr1.basis_evaluate (hat_K, q, u_trial);
for (size_type i = 0, ni = value.size1(); i < ni; ++i) {
for (size_type j = 0, nj = value.size2(); j < nj; ++j) {
value(i,j) = _f (u_trial[j], v_test[i]);
}}
} else {
// expr2 is trial and expr1 is test
std::vector<Arg2> v_test (value.size1()); _expr1.basis_evaluate (hat_K, q, v_test);
std::vector<Arg1> u_trial (value.size2()); _expr2.basis_evaluate (hat_K, q, u_trial);
for (size_type i = 0, ni = value.size1(); i < ni; ++i) {
for (size_type j = 0, nj = value.size2(); j < nj; ++j) {
value(i,j) = _f (u_trial[j], v_test[i]);
}}
}
}
// when both args are defined at compile time:
template<class This, class ValueType,
class Arg1, space_constant::valued_type Arg1Tag,
class Arg2, space_constant::valued_type Arg2Tag>
struct evaluate_switch {
void operator() (const This& obj, const reference_element& hat_K, size_type q, ublas::matrix<ValueType>& value) const {
obj.template evaluate_call<ValueType, Arg1, Arg2> (hat_K, q, value);
}
};
template<class ValueType>
void basis_evaluate (const reference_element& hat_K, size_type q, ublas::matrix<ValueType>& value) const {
typedef typename details::generic_binary_traits<BinaryFunction>::template hint<
typename Expr1::value_type
,typename Expr2::value_type
,ValueType>::first_argument_type first_argument_type;
typedef typename details::generic_binary_traits<BinaryFunction>::template hint<
typename Expr1::value_type
,typename Expr2::value_type
,ValueType>::second_argument_type second_argument_type;
static const space_constant::valued_type first_argument_tag = space_constant::valued_tag_traits<first_argument_type>::value;
static const space_constant::valued_type second_argument_tag = space_constant::valued_tag_traits<second_argument_type>::value;
evaluate_switch <self_type, ValueType,
first_argument_type, first_argument_tag,
second_argument_type, second_argument_tag> eval;
eval (*this, hat_K, q, value);
}
template<class ValueType>
bool valued_check() const {
typedef typename details::generic_binary_traits<BinaryFunction>::template hint<
typename Expr1::value_type
,typename Expr2::value_type
,ValueType>::first_argument_type A1;
typedef typename details::generic_binary_traits<BinaryFunction>::template hint<
typename Expr1::value_type
,typename Expr2::value_type
,ValueType>::second_argument_type A2;
if (! is_undeterminated<A1>::value) _expr1.valued_check<A1>();
if (! is_undeterminated<A2>::value) _expr2.valued_check<A2>();
return true;
}
protected:
// data:
BinaryFunction _f;
Expr1 _expr1;
Expr2 _expr2;
};
// ---------------------------------------------------------------------------
// unary function call: (f form_expr) -> form_expr
// example: -(u*v), 2*(u*v), (u*v)/2
// ---------------------------------------------------------------------------
template<class UnaryFunction, class Expr>
class form_vf_expr_uf {
public:
// typedefs:
typedef geo_element::size_type size_type;
typedef typename Expr::memory_type memory_type;
typedef typename details::generic_unary_traits<UnaryFunction>::template result_hint<
typename Expr::value_type>::type result_hint;
typedef typename details::generic_unary_traits<UnaryFunction>::template hint<
typename Expr::value_type
,result_hint>::result_type value_type;
typedef typename scalar_traits<value_type>::type scalar_type;
typedef typename float_traits<value_type>::type float_type;
typedef space_basic<scalar_type,memory_type> space_type;
typedef typename Expr::vf_tag_type vf_tag_type;
typedef typename details::dual_vf_tag<vf_tag_type>::type
vf_dual_tag_type;
typedef form_vf_expr_uf<UnaryFunction,Expr> self_type;
typedef form_vf_expr_uf<UnaryFunction, typename Expr::dual_self_type>
dual_self_type;
typedef typename Expr::maybe_symmetric::type maybe_symmetric;
static const space_constant::valued_type valued_hint = space_constant::valued_tag_traits<value_type>::value;
// alocators:
form_vf_expr_uf (const UnaryFunction& f, const Expr& expr)
: _f(f), _expr(expr) {}
// accessors:
const space_type& get_trial_space() const { return _expr.get_trial_space(); }
const space_type& get_test_space() const { return _expr.get_test_space(); }
size_type n_derivative() const { return _expr.n_derivative(); }
// mutable modifiers:
bool initialize (const geo_basic<float_type,memory_type>& dom, const quadrature<float_type>& quad, bool ignore_sys_coord) const {
return _expr.initialize (dom, quad, ignore_sys_coord);
}
void initialize (const band_basic<float_type,memory_type>& gh, const quadrature<float_type>& quad, bool ignore_sys_coord) const {
_expr.initialize (gh, quad, ignore_sys_coord);
}
void element_initialize (const geo_element& K) const {
_expr.element_initialize (K);
}
template<class ValueType>
void basis_evaluate (const reference_element& hat_K, size_type q, ublas::matrix<ValueType>& value) const {
// ValueType is float_type in general: elementary matrix
typedef ValueType A1;
ublas::matrix<A1> value1 (value.size1(), value.size2());
_expr.basis_evaluate (hat_K, q, value1);
for (size_type i = 0, ni = value.size1(); i < ni; ++i) {
for (size_type j = 0, nj = value.size2(); j < nj; ++j) {
value(i,j) = _f (value1(i,j));
}}
}
template<class ValueType>
bool valued_check() const {
typedef ValueType A1;
if (! is_undeterminated<A1>::value) return _expr.valued_check<A1>();
return true;
}
protected:
// data:
UnaryFunction _f;
Expr _expr;
};
// ---------------------------------------------------------------------------
// binary function call: (f form_expr1 form_expr2) -> form_expr
// example: operator+ between two forms as in
// (u*v) + dot(grad(u),grad(v))
// ---------------------------------------------------------------------------
template<class BinaryFunction, class Expr1, class Expr2>
class form_vf_expr_bf {
public:
// typedefs:
typedef geo_element::size_type size_type;
typedef typename promote_memory<typename Expr1::memory_type,typename Expr2::memory_type>::type
memory_type;
typedef typename details::generic_binary_traits<BinaryFunction>::template result_hint<
typename Expr1::value_type
,typename Expr2::value_type>::type result_hint;
typedef typename details::generic_binary_traits<BinaryFunction>::template hint<
typename Expr1::value_type
,typename Expr2::value_type
,result_hint>::result_type value_type;
typedef typename scalar_traits<value_type>::type scalar_type;
typedef typename float_traits<value_type>::type float_type;
typedef space_basic<scalar_type,memory_type> space_type; // TODO: deduce from Exprs
typedef typename details::bf_vf_tag<BinaryFunction,
typename Expr1::vf_tag_type,
typename Expr2::vf_tag_type>::type vf_tag_type;
typedef typename details::dual_vf_tag<vf_tag_type>::type
vf_dual_tag_type;
typedef form_vf_expr_bf<BinaryFunction,Expr1,Expr2> self_type;
typedef form_vf_expr_bf<BinaryFunction,typename Expr1::dual_self_type,
typename Expr2::dual_self_type>
dual_self_type;
typedef typename mpl::and_<typename Expr1::maybe_symmetric::type,
typename Expr2::maybe_symmetric::type>::type
maybe_symmetric;
static const space_constant::valued_type valued_hint = space_constant::valued_tag_traits<value_type>::value;
// alocators:
form_vf_expr_bf (const BinaryFunction& f,
const Expr1& expr1,
const Expr2& expr2)
: _f(f), _expr1(expr1), _expr2(expr2) {}
// accessors:
const space_type& get_trial_space() const { return _expr1.get_trial_space(); }
const space_type& get_test_space() const { return _expr1.get_test_space(); }
size_type n_derivative() const { return std::max(_expr1.n_derivative(), _expr2.n_derivative()); }
// mutable modifiers:
// TODO: at init, check that exp1 & expr2 has the same test & trial spaces
bool initialize (const geo_basic<float_type,memory_type>& dom, const quadrature<float_type>& quad, bool ignore_sys_coord) const {
return _expr1.initialize (dom, quad, ignore_sys_coord) &&
_expr2.initialize (dom, quad, ignore_sys_coord);
}
void initialize (const band_basic<float_type,memory_type>& gh, const quadrature<float_type>& quad, bool ignore_sys_coord) const {
_expr1.initialize (gh, quad, ignore_sys_coord);
_expr2.initialize (gh, quad, ignore_sys_coord);
}
void element_initialize (const geo_element& K) const {
_expr1.element_initialize (K);
_expr2.element_initialize (K);
}
// ValueType is float_type in general: elementary matrix
template<class ValueType>
void basis_evaluate (const reference_element& hat_K, size_type q, ublas::matrix<ValueType>& value) const {
// for f=operator+ => sum of two elementary matrix of the same type
// TODO: otherwise ValueType1 and 2 could be obtained from the hint<> helper
typedef ValueType A1;
typedef ValueType A2;
ublas::matrix<A1> value1 (value.size1(), value.size2());
ublas::matrix<A2> value2 (value.size1(), value.size2());
_expr1.basis_evaluate (hat_K, q, value1);
_expr2.basis_evaluate (hat_K, q, value2);
for (size_type i = 0, ni = value.size1(); i < ni; ++i) {
for (size_type j = 0, nj = value.size2(); j < nj; ++j) {
value(i,j) = _f (value1(i,j), value2(i,j));
}}
}
template<class ValueType>
bool valued_check() const {
typedef ValueType A1;
typedef ValueType A2;
bool status = true;
if (! is_undeterminated<A1>::value) status &= _expr1.valued_check<A1>();
if (! is_undeterminated<A2>::value) status &= _expr2.valued_check<A2>();
return status;
}
protected:
// data:
BinaryFunction _f;
Expr1 _expr1;
Expr2 _expr2;
};
// ---------------------------------------------------------------------------
// binary function call: (f nl_field_expr vf_form_expr) -> form_expr
// example: integrate(eta_h*(u*v))
// ---------------------------------------------------------------------------
template<class BinaryFunction, class NLExpr, class VFExpr>
class form_vf_expr_binded_bf {
public:
// typedefs:
typedef geo_element::size_type size_type;
typedef typename promote_memory<typename NLExpr::memory_type,typename VFExpr::memory_type>::type
memory_type;
typedef typename details::generic_binary_traits<BinaryFunction>::template result_hint<
typename NLExpr::value_type
,typename VFExpr::value_type>::type result_hint;
typedef typename details::generic_binary_traits<BinaryFunction>::template hint<
typename NLExpr::value_type
,typename VFExpr::value_type
,result_hint>::result_type value_type;
typedef typename scalar_traits<value_type>::type scalar_type;
typedef typename float_traits<value_type>::type float_type;
typedef space_basic<scalar_type,memory_type> space_type; // TODO: deduce from Exprs
typedef typename details::bf_vf_tag<BinaryFunction,
details::vf_tag_00,
typename VFExpr::vf_tag_type>::type vf_tag_type;
typedef typename details::dual_vf_tag<vf_tag_type>::type
vf_dual_tag_type;
typedef form_vf_expr_binded_bf<BinaryFunction,NLExpr,VFExpr> self_type;
typedef form_vf_expr_binded_bf<BinaryFunction,NLExpr,typename VFExpr::dual_self_type>
dual_self_type;
typedef typename VFExpr::maybe_symmetric::type maybe_symmetric;
// TODO: symmetry: works only when eta_h is scalar
// TODO: problem when ddot(eta_h,otimes(u,v)) when eta_h is unsymmetric tensor
// and "unsymmetric tensor" is not known at compile time
static const space_constant::valued_type valued_hint = space_constant::valued_tag_traits<value_type>::value;
// alocators:
form_vf_expr_binded_bf (const BinaryFunction& f,
const NLExpr& nl_expr,
const VFExpr& vf_expr)
: _f(f),
_nl_expr(nl_expr),
_vf_expr(vf_expr),
_scalar_nl_value_quad(),
_vector_nl_value_quad(),
_tensor_nl_value_quad(),
_tensor3_nl_value_quad(),
_tensor4_nl_value_quad()
{}
// accessors:
const space_type& get_trial_space() const { return _vf_expr.get_trial_space(); }
const space_type& get_test_space() const { return _vf_expr.get_test_space(); }
size_type n_derivative() const { return _vf_expr.n_derivative(); }
// mutable modifiers:
bool initialize (const geo_basic<float_type,memory_type>& dom, const quadrature<float_type>& quad, bool ignore_sys_coord) const {
_nl_expr.initialize (dom, quad);
_vf_expr.initialize (dom, quad, ignore_sys_coord);
return true;
}
void initialize (const band_basic<float_type,memory_type>& gh, const quadrature<float_type>& quad, bool ignore_sys_coord) const {
_nl_expr.initialize (gh.level_set(), quad);
_vf_expr.initialize (gh, quad, ignore_sys_coord);
}
// ---------------------------------------------
// element initialize: evaluate nl_expr
// ---------------------------------------------
void element_initialize (const geo_element& K) const {
typedef typename details::generic_binary_traits<BinaryFunction>::template hint<
typename NLExpr::value_type
,typename VFExpr::value_type
,value_type>::first_argument_type first_argument_type;
nl_switch<self_type,first_argument_type> nl_helper;
nl_helper.element_initialize (*this, K);
_vf_expr.element_initialize (K);
}
template<class ValueType>
void basis_evaluate (const reference_element& hat_K, size_type q, ublas::matrix<ValueType>& value) const {
typedef ValueType Arg1; // TODO: switch
typedef ValueType Arg2; // TODO: switch ; is float_type in general, as elementary matrix
nl_switch<self_type,Arg1> nl_helper;
const Arg1& value1 = nl_helper.get_nl_value (*this, q);
ublas::matrix<Arg2> value2 (value.size1(), value.size2());
_vf_expr.basis_evaluate (hat_K, q, value2);
for (size_type i = 0, ni = value.size1(); i < ni; ++i) {
for (size_type j = 0, nj = value.size2(); j < nj; ++j) {
value(i,j) = _f (value1, value2(i,j));
}}
}
template<class ValueType>
bool valued_check() const {
typedef ValueType A1;
typedef ValueType A2;
bool status = true;
if (! is_undeterminated<A1>::value) status &= _nl_expr.valued_check<A1>();
if (! is_undeterminated<A2>::value) status &= _vf_expr.valued_check<A2>();
return status;
}
//protected:
// data:
BinaryFunction _f;
NLExpr _nl_expr;
VFExpr _vf_expr;
mutable std::vector<scalar_type> _scalar_nl_value_quad;
mutable std::vector<point_basic<scalar_type> > _vector_nl_value_quad;
mutable std::vector<tensor_basic<scalar_type> > _tensor_nl_value_quad;
mutable std::vector<tensor3_basic<scalar_type> > _tensor3_nl_value_quad;
mutable std::vector<tensor4_basic<scalar_type> > _tensor4_nl_value_quad;
};
#ifndef TODO
#endif // TODO
} // namespace rheolef
#endif // _RHEOLEF_FIELD_VF_EXPR_H
|