/usr/include/rheolef/form_expr_v2_variational.h is in librheolef-dev 6.7-1+b4.
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 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 | #ifndef _RHEOLEF_FORM_EXPR_V2_VARIATIONAL_H
#define _RHEOLEF_FORM_EXPR_V2_VARIATIONAL_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
///
/// =========================================================================
//
// variational expressions are used for form assembly
//
// author: Pierre.Saramito@imag.fr
//
// date: 23 september 2015
//
// Notes: use template expressions and SFINAE techniques
//
// SUMMARY:
// 1. concept
// 2. unary function
// 2.1. unary node
// 2.2. unary calls
// 3. binary operators +- between two variational forms
// 3.1. binary node
// 3.2. binary calls
// 4. binary operators * between two variational fields that returns a form
// 4.1. unary node
// 4.2. unary calls
// 5. binary operators */ between a variational form and a nonlinear expr
// 5.1. binary node
// 5.2. binary calls
// 6. binary operators */ between a variational form and a constant
//
#include "rheolef/field_expr_v2_variational.h"
#include <boost/numeric/ublas/matrix.hpp> // ublas::matrix
namespace rheolef {
namespace ublas = boost::numeric::ublas;
// -------------------------------------------------------------------
// 1. concept
// -------------------------------------------------------------------
namespace details {
// Define a trait type for detecting form expression valid arguments
template<class T> struct is_form_expr_v2_variational_arg : std::false_type {};
} // namespace details
// ---------------------------------------------------------------------------
// 2. unary function
// example: -(u*v), 2*(u*v), (u*v)/2
// ---------------------------------------------------------------------------
// 2.1. unary node
// ---------------------------------------------------------------------------
namespace details {
template<class UnaryFunction, class Expr>
class form_expr_v2_variational_unary {
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_expr_v2_variational_unary<UnaryFunction,Expr> self_type;
typedef form_expr_v2_variational_unary<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_expr_v2_variational_unary (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.template valued_check<A1>();
return true;
}
protected:
// data:
UnaryFunction _f;
Expr _expr;
};
template<class F, class Expr> struct is_form_expr_v2_variational_arg <form_expr_v2_variational_unary<F,Expr> > : std::true_type {};
} // namespace details
// ---------------------------------------------------------------------------
// 2.2. unary calls
// ---------------------------------------------------------------------------
#define _RHEOLEF_make_form_expr_v2_variational_unary(FUNCTION,FUNCTOR) \
template<class Expr> \
inline \
typename \
std::enable_if< \
details::is_form_expr_v2_variational_arg<Expr>::value \
,details::form_expr_v2_variational_unary< \
FUNCTOR \
,Expr \
> \
>::type \
FUNCTION (const Expr& expr) \
{ \
return details::form_expr_v2_variational_unary <FUNCTOR,Expr> (FUNCTOR(), expr); \
}
_RHEOLEF_make_form_expr_v2_variational_unary (operator+, details::unary_plus)
_RHEOLEF_make_form_expr_v2_variational_unary (operator-, details::negate)
#undef _RHEOLEF_make_form_expr_v2_variational_unary
// ---------------------------------------------------------------------------
// 3. binary operators +- between two variational forms
// ---------------------------------------------------------------------------
// 3.1. binary node
// ---------------------------------------------------------------------------
// example: operator+ between two forms as in
// (u*v) + dot(grad(u),grad(v))
namespace details {
template<class BinaryFunction, class Expr1, class Expr2>
class form_expr_v2_variational_binary {
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_expr_v2_variational_binary<BinaryFunction,Expr1,Expr2> self_type;
typedef form_expr_v2_variational_binary<BinaryFunction,typename Expr1::dual_self_type,
typename Expr2::dual_self_type>
dual_self_type;
typedef typename and_type<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_expr_v2_variational_binary (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.template valued_check<A1>();
if (! is_undeterminated<A2>::value) status &= _expr2.template valued_check<A2>();
return status;
}
protected:
// data:
BinaryFunction _f;
Expr1 _expr1;
Expr2 _expr2;
};
template<class F, class Expr1, class Expr2> struct is_form_expr_v2_variational_arg <form_expr_v2_variational_binary<F,Expr1,Expr2> > : std::true_type {};
} // namespace details
// ---------------------------------------------------------------------------
// 3.2. binary calls
// ---------------------------------------------------------------------------
#define _RHEOLEF_form_expr_v2_variational_binary(FUNCTION,FUNCTOR) \
template <class Expr1, class Expr2> \
inline \
typename \
std::enable_if< \
details::is_form_expr_v2_variational_arg <Expr1>::value \
&& details::is_form_expr_v2_variational_arg <Expr2>::value \
,details::form_expr_v2_variational_binary< \
FUNCTOR \
,Expr1 \
,Expr2 \
> \
>::type \
FUNCTION (const Expr1& expr1, const Expr2& expr2) \
{ \
return details::form_expr_v2_variational_binary \
<FUNCTOR, Expr1, Expr2> \
(FUNCTOR(), expr1, expr2); \
}
_RHEOLEF_form_expr_v2_variational_binary (operator+, details::plus)
_RHEOLEF_form_expr_v2_variational_binary (operator-, details::minus)
#undef _RHEOLEF_form_expr_v2_variational_binary
// ---------------------------------------------------------------------------
// 4. binary operators * between two variational fields that returns a form
// example: integrate(u*v)
// ---------------------------------------------------------------------------
// 4.1. binary node
// ---------------------------------------------------------------------------
namespace details {
template<class BinaryFunction, class Expr1, class Expr2>
class form_expr_v2_variational_binary_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_expr_v2_variational_binary_field<BinaryFunction,Expr1,Expr2> self_type;
typedef form_expr_v2_variational_binary_field<BinaryFunction,typename Expr1::dual_self_type,typename Expr2::dual_self_type>
dual_self_type;
typedef typename and_type<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_expr_v2_variational_binary_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.template valued_check<A1>();
if (! is_undeterminated<A2>::value) _expr2.template valued_check<A2>();
return true;
}
protected:
// data:
BinaryFunction _f;
Expr1 _expr1;
Expr2 _expr2;
};
template<class F, class Expr1, class Expr2> struct is_form_expr_v2_variational_arg <form_expr_v2_variational_binary_field<F,Expr1,Expr2> > : std::true_type {};
} // namespace details
// ---------------------------------------------------------------------------
// 4.2. binary calls
// ---------------------------------------------------------------------------
namespace details {
template<class Expr1, class Expr2, class Sfinae = void>
struct is_form_expr_v2_variational_binary_field : std::false_type {};
template <class Expr1, class Expr2>
struct is_form_expr_v2_variational_binary_field <
Expr1
,Expr2
,typename
std::enable_if<
is_field_expr_v2_variational_arg<Expr1>::value
&& is_field_expr_v2_variational_arg<Expr2>::value
>::type
>
: and_type<
is_field_expr_v2_variational_arg<Expr1>
,is_field_expr_v2_variational_arg<Expr2>
,std::is_same <
typename Expr1::vf_tag_type
,typename dual_vf_tag<typename Expr2::vf_tag_type>::type
>
>
{};
} // namespace details
#define _RHEOLEF_form_expr_v2_variational_binary_field(FUNCTION,FUNCTOR) \
template <class Expr1, class Expr2> \
inline \
typename \
std::enable_if< \
details::is_form_expr_v2_variational_binary_field <Expr1,Expr2>::value \
,details::form_expr_v2_variational_binary_field< \
FUNCTOR \
,Expr1 \
,Expr2 \
> \
>::type \
FUNCTION (const Expr1& expr1, const Expr2& expr2) \
{ \
return details::form_expr_v2_variational_binary_field \
<FUNCTOR, Expr1, Expr2> \
(FUNCTOR(), expr1, expr2); \
}
_RHEOLEF_form_expr_v2_variational_binary_field (operator*, details::multiplies)
_RHEOLEF_form_expr_v2_variational_binary_field (dot, details::dot_)
_RHEOLEF_form_expr_v2_variational_binary_field (ddot, details::ddot_)
#undef _RHEOLEF_form_expr_v2_variational_binary_field
// ---------------------------------------------------------------------------
// 5. binary operators */ between a variational form and a nonlinear expr
// ---------------------------------------------------------------------------
// 5.1. binary node
// ---------------------------------------------------------------------------
// example: integrate(eta_h*(u*v))
namespace details {
template<class BinaryFunction, class NLExpr, class VFExpr>
class form_expr_v2_variational_binary_binded {
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_expr_v2_variational_binary_binded <BinaryFunction,NLExpr,VFExpr> self_type;
typedef form_expr_v2_variational_binary_binded <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_expr_v2_variational_binary_binded (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.template valued_check<A1>();
if (! is_undeterminated<A2>::value) status &= _vf_expr.template 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;
};
template<class F, class Expr1, class Expr2> struct is_form_expr_v2_variational_arg <form_expr_v2_variational_binary_binded<F,Expr1,Expr2> > : std::true_type {};
} // namespace details
// ---------------------------------------------------------------------------
// 5.2. binary calls
// ---------------------------------------------------------------------------
namespace details {
template<class Expr1, class Expr2, class Sfinae = void>
struct is_form_expr_v2_variational_binary_multiplies_divides_left : std::false_type {};
template<class Expr1, class Expr2>
struct is_form_expr_v2_variational_binary_multiplies_divides_left <
Expr1
,Expr2
,typename
std::enable_if<
is_field_expr_v2_nonlinear_arg <Expr1>::value
&& is_form_expr_v2_variational_arg<Expr2>::value
>::type
>
: std::true_type
{};
template<class Expr1, class Expr2>
struct is_form_expr_v2_variational_binary_multiplies_divides_right
: is_form_expr_v2_variational_binary_multiplies_divides_left <Expr2,Expr1> {};
} // namespace details
#define _RHEOLEF_make_form_expr_v2_variational_binary_operator_multiplies_divides_left(FUNCTION,FUNCTOR) \
template<class Expr1, class Expr2> \
inline \
typename \
std::enable_if< \
details::is_form_expr_v2_variational_binary_multiplies_divides_left <Expr1,Expr2>::value \
,details::form_expr_v2_variational_binary_binded< \
FUNCTOR \
,typename details::field_expr_v2_nonlinear_terminal_wrapper_traits<Expr1>::type \
,Expr2 /* vf */ \
> \
>::type \
FUNCTION (const Expr1& expr1, const Expr2& expr2) \
{ \
typedef typename details::field_expr_v2_nonlinear_terminal_wrapper_traits<Expr1>::type wrap1_t; \
return details::form_expr_v2_variational_binary_binded \
<FUNCTOR, wrap1_t, Expr2> \
(FUNCTOR(), wrap1_t(expr1), expr2); \
}
#define _RHEOLEF_make_form_expr_v2_variational_binary_operator_multiplies_divides_right(FUNCTION,FUNCTOR) \
template<class Expr1, class Expr2> \
inline \
typename \
std::enable_if< \
details::is_form_expr_v2_variational_binary_multiplies_divides_right <Expr1,Expr2>::value \
,details::form_expr_v2_variational_binary_binded< \
details::swapper<FUNCTOR> \
, typename details::field_expr_v2_nonlinear_terminal_wrapper_traits<Expr2>::type \
,Expr1 /* vf */ \
> \
>::type \
FUNCTION (const Expr1& expr1, const Expr2& expr2) \
{ \
typedef typename details::field_expr_v2_nonlinear_terminal_wrapper_traits<Expr2>::type wrap2_t; \
return details::form_expr_v2_variational_binary_binded \
<details::swapper<FUNCTOR>, wrap2_t, Expr1> \
(details::swapper<FUNCTOR>(FUNCTOR()), wrap2_t(expr2), expr1); \
}
#define _RHEOLEF_make_form_expr_v2_variational_binary_operator_multiplies_divides(FUNCTION,FUNCTOR) \
_RHEOLEF_make_form_expr_v2_variational_binary_operator_multiplies_divides_left (FUNCTION,FUNCTOR) \
_RHEOLEF_make_form_expr_v2_variational_binary_operator_multiplies_divides_right (FUNCTION,FUNCTOR)
_RHEOLEF_make_form_expr_v2_variational_binary_operator_multiplies_divides (operator*, details::multiplies)
_RHEOLEF_make_form_expr_v2_variational_binary_operator_multiplies_divides_right (operator/, details::divides)
_RHEOLEF_make_form_expr_v2_variational_binary_operator_multiplies_divides (dot, details::dot_)
_RHEOLEF_make_form_expr_v2_variational_binary_operator_multiplies_divides (ddot, details::ddot_)
#undef _RHEOLEF_make_form_expr_v2_variational_binary_operator_multiplies_divides_left
#undef _RHEOLEF_make_form_expr_v2_variational_binary_operator_multiplies_divides_right
#undef _RHEOLEF_make_form_expr_v2_variational_binary_operator_multiplies_divides
// ---------------------------------------------------------------------------
// 6. binary operators */ between a variational form and a constant
// ---------------------------------------------------------------------------
namespace details {
template<class Expr1, class Expr2, class Sfinae = void>
struct is_form_expr_v2_variational_binary_multiplies_divides_constant_left : std::false_type {};
template<class Expr1, class Expr2>
struct is_form_expr_v2_variational_binary_multiplies_divides_constant_left <
Expr1
,Expr2
,typename
std::enable_if<
is_rheolef_arithmetic <Expr1>::value
&& is_form_expr_v2_variational_arg<Expr2>::value
>::type
>
: std::true_type
{};
template<class Expr1, class Expr2>
struct is_form_expr_v2_variational_binary_multiplies_divides_constant_right
: is_form_expr_v2_variational_binary_multiplies_divides_constant_left <Expr2,Expr1> {};
} // namespace details
#define _RHEOLEF_make_form_expr_v2_variational_binary_operator_multiplies_divides_constant_left(FUNCTION,FUNCTOR) \
template<class Expr1, class Expr2> \
inline \
typename \
std::enable_if< \
details::is_form_expr_v2_variational_binary_multiplies_divides_constant_left <Expr1,Expr2>::value \
,details::form_expr_v2_variational_unary< \
details::binder_first <FUNCTOR, Expr1> \
,Expr2 /* vf */ \
> \
>::type \
FUNCTION (const Expr1& expr1, const Expr2& expr2) \
{ \
return details::form_expr_v2_variational_unary \
<details::binder_first <FUNCTOR,Expr1>, Expr2> \
(details::binder_first <FUNCTOR,Expr1> (FUNCTOR(), expr1), expr2); \
}
#define _RHEOLEF_make_form_expr_v2_variational_binary_operator_multiplies_divides_constant_right(FUNCTION,FUNCTOR) \
template<class Expr1, class Expr2> \
inline \
typename \
std::enable_if< \
details::is_form_expr_v2_variational_binary_multiplies_divides_constant_right <Expr1,Expr2>::value \
,details::form_expr_v2_variational_unary< \
details::binder_second <FUNCTOR, Expr2> \
,Expr1 /* vf */ \
> \
>::type \
FUNCTION (const Expr1& expr1, const Expr2& expr2) \
{ \
return details::form_expr_v2_variational_unary \
<details::binder_second <FUNCTOR,Expr2>, Expr1> \
(details::binder_second <FUNCTOR,Expr2> (FUNCTOR(), expr2), expr1); \
}
#define _RHEOLEF_make_form_expr_v2_variational_binary_operator_multiplies_divides_constant(FUNCTION,FUNCTOR) \
_RHEOLEF_make_form_expr_v2_variational_binary_operator_multiplies_divides_constant_left (FUNCTION,FUNCTOR) \
_RHEOLEF_make_form_expr_v2_variational_binary_operator_multiplies_divides_constant_right (FUNCTION,FUNCTOR)
_RHEOLEF_make_form_expr_v2_variational_binary_operator_multiplies_divides_constant (operator*, details::multiplies)
_RHEOLEF_make_form_expr_v2_variational_binary_operator_multiplies_divides_constant_right (operator/, details::divides)
_RHEOLEF_make_form_expr_v2_variational_binary_operator_multiplies_divides_constant (dot, details::dot_)
_RHEOLEF_make_form_expr_v2_variational_binary_operator_multiplies_divides_constant (ddot, details::ddot_)
#undef _RHEOLEF_make_form_expr_v2_variational_binary_operator_multiplies_divides_constant_right
#undef _RHEOLEF_make_form_expr_v2_variational_binary_operator_multiplies_divides_constant_left
#undef _RHEOLEF_make_form_expr_v2_variational_binary_operator_multiplies_divides_constant
} // namespace rheolef
#endif // _RHEOLEF_FORM_EXPR_V2_VARIATIONAL_H
|