/usr/include/rheolef/field_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 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 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 | #ifndef _RHEOLEF_FIELD_VF_EXPR_H
#define _RHEOLEF_FIELD_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
///
/// =========================================================================
//
// field_vf_expr: used for expressions in variationnal formulations
//
#include "rheolef/field_evaluate.h"
#include "rheolef/field_nonlinear_expr_terminal.h"
#include "rheolef/test.h" // for grad_option_type
#include "rheolef/vf_tag.h"
#include <boost/functional.hpp>
namespace rheolef {
// ---------------------------------------------------------------------------
// wrapper
// ---------------------------------------------------------------------------
template<class RawExpr, class VfTag = typename RawExpr::vf_tag_type>
class field_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 VfTag vf_tag_type;
typedef typename details::dual_vf_tag<vf_tag_type>::type
vf_dual_tag_type;
typedef field_vf_expr<RawExpr,VfTag> self_type;
typedef field_vf_expr<typename RawExpr::dual_self_type,vf_dual_tag_type>
dual_self_type;
// alocators:
field_vf_expr (const RawExpr& raw_expr)
: _raw_expr(raw_expr) {}
field_vf_expr (const field_vf_expr<RawExpr>& x)
: _raw_expr(x._raw_expr) {}
// accessors:
static bool have_test_space() { return RawExpr::have_test_space(); }
const space_type& get_vf_space() const { return _raw_expr.get_vf_space(); }
static const space_constant::valued_type valued_hint = RawExpr::valued_hint;
space_constant::valued_type valued_tag() const { return _raw_expr.valued_tag(); }
size_type n_derivative() const { return _raw_expr.n_derivative(); }
// mutable modifiers:
void initialize (const geo_basic<float_type,memory_type>& dom, const quadrature<float_type>& quad, bool ignore_sys_coord) const {
_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 element_initialize_on_side (const geo_element& K, const side_information_type& sid) {
_raw_expr.element_initialize_on_side (K, sid);
}
template<class ValueType>
void basis_evaluate (const reference_element& hat_K, size_type q, std::vector<ValueType>& value) const {
_raw_expr.basis_evaluate (hat_K, q, value);
}
template<class ValueType>
void valued_check() const {
_raw_expr.valued_check<ValueType>();
}
protected:
// data:
RawExpr _raw_expr;
};
// ---------------------------------------------------------------------------
// grad, grad_s, D, etc
// ---------------------------------------------------------------------------
template<class Expr>
class field_vf_expr_grad {
public:
// typedefs:
typedef geo_element::size_type size_type;
typedef typename Expr::memory_type memory_type;
typedef typename scalar_traits<typename Expr::value_type>::type
scalar_type;
typedef typename space_constant::rank_up<typename Expr::value_type>::type
value_type;
typedef typename float_traits<scalar_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 field_vf_expr_grad<Expr> self_type;
typedef field_vf_expr_grad<typename Expr::dual_self_type>
dual_self_type;
// alocators:
field_vf_expr_grad (const Expr& expr, const details::grad_option_type& opt = details::grad_option_type())
: _expr(expr),
_opt(opt)
{
check_macro (opt.broken
|| get_vf_space().get_numbering().is_continuous()
|| get_vf_space().get_numbering().name() == "bubble",
"grad(.): unexpected " << get_vf_space().get_numbering().name()
<< " discontinuous approximation (HINT: consider grad_h(.))");
}
field_vf_expr_grad (const field_vf_expr_grad<Expr>& x)
: _expr(x._expr),
_opt(x._opt)
{}
// accessors:
const space_type& get_vf_space() const { return _expr.get_vf_space(); }
static const space_constant::valued_type valued_hint = space_constant::valued_tag_traits<value_type>::value;
space_constant::valued_type valued_tag() const {
space_constant::valued_type v = _expr.valued_tag();
switch (v) {
case space_constant::scalar: return space_constant::vector;
case space_constant::vector: return space_constant::unsymmetric_tensor;
case space_constant::tensor: return space_constant::tensor3;
default:
fatal_macro ("unexpected " << space_constant::valued_name(v) << "-valued argument for grad() operator");
return space_constant::last_valued;
}
}
size_type n_derivative() const { return _expr.n_derivative() + 1; }
// mutable modifiers:
void initialize (const geo_basic<float_type,memory_type>& dom, const quadrature<float_type>& quad, bool ignore_sys_coord) const {
_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);
}
void element_initialize_on_side (const geo_element& K, const side_information_type& sid) {
_expr.element_initialize_on_side (K, sid);
}
template<class ValueType>
void basis_evaluate (const reference_element& hat_K, size_type q, std::vector<ValueType>& value) const {
_expr.grad_basis_evaluate (hat_K, q, _opt, value);
}
template<class ValueType>
void valued_check() const {
typedef typename space_constant::rank_down<ValueType>::type A1; // may be defined when ValueType is
_expr.valued_check<A1>();
}
protected:
// data:
Expr _expr;
details::grad_option_type _opt;
};
// ---------------------------------------------------------------------------
// div, div_s
// ---------------------------------------------------------------------------
template<class Expr>
class field_vf_expr_div {
public:
// typedefs:
typedef geo_element::size_type size_type;
typedef typename Expr::memory_type memory_type;
typedef typename space_constant::rank_down<typename Expr::value_type>::type
value_type;
typedef typename scalar_traits<typename Expr::value_type>::type
scalar_type;
typedef typename float_traits<scalar_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 field_vf_expr_div<Expr> self_type;
typedef field_vf_expr_div<typename Expr::dual_self_type>
dual_self_type;
// alocators:
field_vf_expr_div (const Expr& expr, const details::grad_option_type& opt = details::grad_option_type())
: _expr(expr),
_opt(opt)
{
check_macro (opt.broken
|| get_vf_space().get_numbering().is_continuous()
|| get_vf_space().get_numbering().name() == "bubble",
"div(.): unexpected " << get_vf_space().get_numbering().name()
<< " discontinuous approximation (HINT: consider div_h(.))");
}
// accessors:
const space_type& get_vf_space() const { return _expr.get_vf_space(); }
static const space_constant::valued_type valued_hint = space_constant::valued_tag_traits<value_type>::value;
space_constant::valued_type valued_tag() const {
space_constant::valued_type v = _expr.valued_tag();
switch (v) {
case space_constant::vector: return space_constant::scalar;
case space_constant::tensor:
case space_constant::unsymmetric_tensor: return space_constant::vector;
default:
fatal_macro ("unexpected " << space_constant::valued_name(v) << "-valued argument for div() operator");
return space_constant::last_valued;
}
}
size_type n_derivative() const { return _expr.n_derivative() + 1; }
// mutable modifiers:
void initialize (const geo_basic<float_type,memory_type>& dom, const quadrature<float_type>& quad, bool ignore_sys_coord) const {
_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);
}
void element_initialize_on_side (const geo_element& K, const side_information_type& sid) {
_expr.element_initialize_on_side (K, sid);
}
template<class ValueType>
void basis_evaluate (const reference_element& hat_K, size_type q, std::vector<ValueType>& value) const {
_expr.div_basis_evaluate (hat_K, q, _opt, value);
}
template<class ValueType>
void valued_check() const {
_expr.template div_valued_check<ValueType>();
}
protected:
// data:
Expr _expr;
details::grad_option_type _opt;
};
// ---------------------------------------------------------------------------
// curl
// ---------------------------------------------------------------------------
template<class Expr>
class field_vf_expr_curl {
public:
// typedefs:
typedef geo_element::size_type size_type;
typedef typename Expr::memory_type memory_type;
typedef typename scalar_traits<typename Expr::value_type>::type
scalar_type;
// value_type = vctor when d=2 and Expr is scalar or when d=3
// = scalar when d=2 and Expr is vector
// thus is undeterminated at compile-time
typedef undeterminated_basic<scalar_type> value_type;
typedef typename float_traits<scalar_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 field_vf_expr_curl<Expr> self_type;
typedef field_vf_expr_curl<typename Expr::dual_self_type>
dual_self_type;
// alocators:
field_vf_expr_curl (const Expr& expr, const details::grad_option_type& opt = details::grad_option_type())
: _expr(expr),
_opt(opt)
{
check_macro (opt.broken
|| get_vf_space().get_numbering().is_continuous()
|| get_vf_space().get_numbering().name() == "bubble",
"curl(.): unexpected " << get_vf_space().get_numbering().name()
<< " discontinuous approximation (HINT: consider curl_h(.))");
}
// accessors:
const space_type& get_vf_space() const { return _expr.get_vf_space(); }
static const space_constant::valued_type valued_hint = space_constant::valued_tag_traits<value_type>::value;
space_constant::valued_type valued_tag() const {
space_constant::valued_type arg_v = _expr.valued_tag();
switch (arg_v) {
case space_constant::scalar: return space_constant::vector;
case space_constant::vector: {
size_type d = get_vf_space().get_geo().dimension();
return (d==2) ? space_constant::scalar : space_constant::vector;
}
default:
fatal_macro ("unexpected " << space_constant::valued_name(arg_v) << "-valued argument for curl() operator");
return space_constant::last_valued;
}
}
size_type n_derivative() const { return _expr.n_derivative() + 1; }
// mutable modifiers:
void initialize (const geo_basic<float_type,memory_type>& dom, const quadrature<float_type>& quad, bool ignore_sys_coord) const {
_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);
}
void element_initialize_on_side (const geo_element& K, const side_information_type& sid) {
_expr.element_initialize_on_side (K, sid);
}
template<class ValueType>
void basis_evaluate (const reference_element& hat_K, size_type q, std::vector<ValueType>& value) const {
_expr.curl_basis_evaluate (hat_K, q, _opt, value);
}
void _valued_check_internal(const scalar_type&) const {
_expr.valued_check<point_basic<scalar_type> >();
size_type d = get_vf_space().get_geo().dimension();
check_macro (d==2, "unexpected "<<d<<"D physical dimension for the scalar-valued curl() operator");
}
void _valued_check_internal(const point_basic<scalar_type>&) const {
size_type d = get_vf_space().get_geo().dimension();
check_macro (d==2 || d==3, "unexpected "<<d<<"D physical dimension for the vector-valued curl() operator");
if (d == 2) {
_expr.valued_check<scalar_type>();
} else {
_expr.valued_check<point_basic<scalar_type> >();
}
}
void _valued_check_internal(const tensor_basic<scalar_type>&) const {
fatal_macro ("unexpected tensor-valued result for the curl() operator");
}
template<class ValueType>
void valued_check() const {
_valued_check_internal(ValueType());
}
protected:
// data:
Expr _expr;
details::grad_option_type _opt;
};
// ---------------------------------------------------------------------------
// unary function call: (f expr)
// ex: -v, 2*v, v/3
// ---------------------------------------------------------------------------
template<class UnaryFunction, class Expr>
class field_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
value_type;
typedef typename scalar_traits<value_type>::type scalar_type;
typedef typename float_traits<scalar_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 field_vf_expr_uf<UnaryFunction,Expr> self_type;
typedef field_vf_expr_uf<UnaryFunction,typename Expr::dual_self_type>
dual_self_type;
// alocators:
field_vf_expr_uf (const UnaryFunction& f, const field_vf_expr<Expr>& expr)
: _f(f), _expr(expr) {}
field_vf_expr_uf (const field_vf_expr_uf<UnaryFunction,Expr>& x)
: _f(x._f), _expr(x._expr) {}
// accessors:
static bool have_test_space() { return true; } // check !
const space_type& get_vf_space() const { return _expr.get_vf_space(); }
static const space_constant::valued_type valued_hint = space_constant::valued_tag_traits<value_type>::value;
space_constant::valued_type valued_tag() const {
return details::generic_unary_traits<UnaryFunction>::valued_tag(_expr.valued_tag());
}
size_type n_derivative() const { return _expr.n_derivative(); }
// mutable modifiers:
void initialize (const geo_basic<float_type,memory_type>& dom, const quadrature<float_type>& quad, bool ignore_sys_coord) const {
_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);
}
void element_initialize_on_side (const geo_element& K, const side_information_type& sid) {
_expr.element_initialize_on_side (K, sid);
}
// -------------
// evaluate
// -------------
// evaluate when all arg types are determinated
template<class ValueType, class Arg, class Status>
struct evaluate_call_check {
void operator() (const self_type& obj, const reference_element& hat_K, size_type q, std::vector<ValueType>& value) const {
fatal_macro ("invalid type resolution: ValueType="<<typename_macro(ValueType)
<< ", Arg="<<typename_macro(Arg)
<< ", UnaryFunction="<<typename_macro(UnaryFunction)
);
}
};
template<class ValueType, class Arg>
struct evaluate_call_check<ValueType,Arg,mpl::true_> {
void operator() (const self_type& obj, const reference_element& hat_K, size_type q, std::vector<ValueType>& value) const {
std::vector<Arg> value1 (value.size());
obj._expr.basis_evaluate (hat_K, q, value1);
for (size_type loc_idof = 0, loc_ndof = value1.size(); loc_idof < loc_ndof; ++loc_idof) {
value[loc_idof] = obj._f (value1[loc_idof]);
}
}
};
template<class ValueType, class Arg>
void evaluate_call (const reference_element& hat_K, size_type q, std::vector<ValueType>& value) const {
// check if ValueType is a valid return_type for this function:
typedef typename scalar_traits<ValueType>::type S;
typedef undeterminated_basic<S> undet;
typedef typename details::generic_unary_traits<UnaryFunction>::template hint<Arg,undet>::result_type result_type;
// TODO: instead of is_equal, could have compatible scalars T1,T2 ?
typedef typename details::is_equal<ValueType,result_type>::type status_t;
evaluate_call_check<ValueType,Arg,status_t> eval;
eval (*this, hat_K, q, value);
}
// when arg is defined at compile time:
template<class This, class ValueType, class Arg, class Status>
struct evaluate_switch {
void operator() (const This& obj, const reference_element& hat_K, size_type q, std::vector<ValueType>& value) const {
obj.template evaluate_call<ValueType, Arg> (hat_K, q, value);
}
};
// when arg is undeterminated at compile time
template<class This, class ValueType, class Arg>
struct evaluate_switch<This, ValueType, Arg, mpl::true_> {
void operator() (const This& obj, const reference_element& hat_K, size_type q, std::vector<ValueType>& value) const {
typedef typename scalar_traits<Arg>::type T;
space_constant::valued_type arg_valued_tag = obj._expr.valued_tag();
switch (arg_valued_tag) {
case space_constant::scalar:
obj.template evaluate_call<ValueType, T> (hat_K, q, value); break;
case space_constant::vector:
obj.template evaluate_call<ValueType, point_basic<T> > (hat_K, q, value); break;
case space_constant::tensor:
case space_constant::unsymmetric_tensor:
obj.template evaluate_call<ValueType, tensor_basic<T> > (hat_K, q, value); break;
default: error_macro ("unexpected argument valued tag="<<arg_valued_tag);
}
}
};
template<class ValueType>
void basis_evaluate (const reference_element& hat_K, size_type q, std::vector<ValueType>& value) const {
typedef typename details::generic_unary_traits<UnaryFunction>::template hint<typename Expr::value_type,ValueType>::argument_type
A1;
typedef typename is_undeterminated<A1>::type status_t;
evaluate_switch <self_type, ValueType, A1, status_t> eval;
eval (*this, hat_K, q, value);
}
template<class ValueType>
void valued_check() const {
typedef typename details::generic_unary_traits<UnaryFunction>::template hint<typename Expr::value_type,ValueType>::argument_type
A1;
if (! is_undeterminated<A1>::value) _expr.valued_check<A1>();
}
protected:
// data:
UnaryFunction _f;
field_vf_expr<Expr> _expr;
};
// ---------------------------------------------------------------------------
// binary function call: (f expr1 expr2),
// ex: v+v, v-v
// ---------------------------------------------------------------------------
template<class BinaryFunction, class Expr1, class Expr2>
class field_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 field_vf_expr_bf<BinaryFunction,Expr1,Expr2> self_type;
typedef field_vf_expr_bf<BinaryFunction,typename Expr1::dual_self_type,typename Expr2::dual_self_type>
dual_self_type;
// alocators:
field_vf_expr_bf (const BinaryFunction& f,
const Expr1& expr1,
const Expr2& expr2)
: _f(f), _expr1(expr1), _expr2(expr2) {}
// accessors:
static bool have_test_space() { return true; }
const space_type& get_vf_space() const { return _expr1.get_vf_space(); }
static const space_constant::valued_type valued_hint = space_constant::valued_tag_traits<value_type>::value;
space_constant::valued_type valued_tag() const {
return details::generic_binary_traits<BinaryFunction>::valued_tag(_expr1.valued_tag(), _expr2.valued_tag());
}
size_type n_derivative() const { return _expr1.n_derivative() + _expr2.n_derivative(); }
// mutable modifiers:
// TODO: check that expr1 & expr2 have the same get_vf_space()
void 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);
}
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);
}
// evaluate when all arg types are determinated
template<class ValueType, class Arg1, class Arg2, class Status>
struct evaluate_call_check {
void operator() (const self_type& obj, const reference_element& hat_K, size_type q, std::vector<ValueType>& value) const {
fatal_macro ("invalid type resolution");
}
};
template<class ValueType, class Arg1, class Arg2>
struct evaluate_call_check<ValueType,Arg1,Arg2,mpl::true_> {
void operator() (const self_type& obj, const reference_element& hat_K, size_type q, std::vector<ValueType>& value) const {
std::vector<Arg1> value1 (value.size());
std::vector<Arg2> value2 (value.size());
obj._expr1.basis_evaluate (hat_K, q, value1);
obj._expr2.basis_evaluate (hat_K, q, value2);
for (size_type loc_idof = 0, loc_ndof = value1.size(); loc_idof < loc_ndof; ++loc_idof) {
value[loc_idof] = obj._f (value1[loc_idof], value2[loc_idof]);
}
}
};
template<class ValueType, class Arg1, class Arg2>
void evaluate_call (const reference_element& hat_K, size_type q, std::vector<ValueType>& value) const {
typedef typename details::generic_binary_traits<BinaryFunction>::template result_hint<Arg1,Arg2>::type result_type;
// TODO: instead of is_equal, could have compatible scalars T1,T2 ?
typedef typename details::is_equal<ValueType,result_type>::type status_t;
evaluate_call_check<ValueType,Arg1,Arg2,status_t> eval;
eval (*this, hat_K, q, value);
}
template<class This, class ValueType, class Arg1, class Arg2, class Undet1, class Undet2>
struct evaluate_switch {};
// when both args are defined at compile time:
template<class This, class ValueType, class Arg1, class Arg2>
struct evaluate_switch<This, ValueType, Arg1, Arg2, mpl::false_, mpl::false_> {
void operator() (const This& obj, const reference_element& hat_K, size_type q, std::vector<ValueType>& value) const {
obj.template evaluate_call<ValueType, Arg1, Arg2> (hat_K, q, value);
}
};
// when first arg is undeterminated
template<class This, class ValueType, class Arg1, class Arg2>
struct evaluate_switch<This, ValueType, Arg1, Arg2, mpl::true_, mpl::false_> {
void operator() (const This& obj, const reference_element& hat_K, size_type q, std::vector<ValueType>& value) const {
typedef typename scalar_traits<Arg1>::type T1;
space_constant::valued_type arg1_valued_tag = obj._expr1.valued_tag();
switch (arg1_valued_tag) {
case space_constant::scalar:
obj.template evaluate_call<ValueType, T1, Arg2> (hat_K, q, value); break;
case space_constant::vector:
obj.template evaluate_call<ValueType, point_basic<T1>, Arg2> (hat_K, q, value); break;
case space_constant::tensor:
case space_constant::unsymmetric_tensor:
obj.template evaluate_call<ValueType, tensor_basic<T1>, Arg2> (hat_K, q, value); break;
default: error_macro ("unexpected first argument valued tag="<<arg1_valued_tag);
}
}
};
// when second arg is undeterminated
template<class This, class ValueType, class Arg1, class Arg2>
struct evaluate_switch<This, ValueType, Arg1, Arg2, mpl::false_, mpl::true_> {
void operator() (const This& obj, const reference_element& hat_K, size_type q, std::vector<ValueType>& value) const {
typedef typename scalar_traits<Arg2>::type T2;
space_constant::valued_type arg2_valued_tag = obj._expr2.valued_tag();
switch (arg2_valued_tag) {
case space_constant::scalar:
obj.template evaluate_call<ValueType, Arg1, T2> (hat_K, q, value); break;
case space_constant::vector:
obj.template evaluate_call<ValueType, Arg1, point_basic<T2> > (hat_K, q, value); break;
case space_constant::tensor:
case space_constant::unsymmetric_tensor:
obj.template evaluate_call<ValueType, Arg1, tensor_basic<T2> > (hat_K, q, value); break;
default: error_macro ("unexpected second argument valued tag="<<arg2_valued_tag);
}
}
};
// when one arg or both are undefined at compile time:
// TODO: optimize when only one arg is undeterminated
template<class This, class ValueType, class Arg1, class Arg2>
struct evaluate_switch<This, ValueType, Arg1, Arg2, mpl::true_, mpl::true_> {
void operator() (const This& obj, const reference_element& hat_K, size_type q, std::vector<ValueType>& value) const {
typedef typename scalar_traits<Arg1>::type T1;
typedef typename scalar_traits<Arg2>::type T2;
space_constant::valued_type arg1_valued_tag = obj._expr1.valued_tag();
space_constant::valued_type arg2_valued_tag = obj._expr2.valued_tag();
switch (arg1_valued_tag) {
case space_constant::scalar: {
switch (arg2_valued_tag) {
case space_constant::scalar:
obj.template evaluate_call<ValueType, T1, T2> (hat_K, q, value); break;
case space_constant::vector:
obj.template evaluate_call<ValueType, T1, point_basic<T2> > (hat_K, q, value); break;
case space_constant::tensor:
case space_constant::unsymmetric_tensor:
obj.template evaluate_call<ValueType, T1, tensor_basic<T2> > (hat_K, q, value); break;
default: error_macro ("unexpected second argument valued tag="<<arg2_valued_tag);
}
break;
}
case space_constant::vector: {
switch (arg2_valued_tag) {
case space_constant::scalar:
obj.template evaluate_call<ValueType, point_basic<T1>, T2> (hat_K, q, value); break;
case space_constant::vector:
obj.template evaluate_call<ValueType, point_basic<T1>, point_basic<T2> > (hat_K, q, value); break;
case space_constant::tensor:
case space_constant::unsymmetric_tensor:
obj.template evaluate_call<ValueType, point_basic<T1>, tensor_basic<T2> > (hat_K, q, value); break;
default: error_macro ("unexpected second argument valued tag="<<arg2_valued_tag);
}
break;
}
case space_constant::tensor:
case space_constant::unsymmetric_tensor: {
switch (arg2_valued_tag) {
case space_constant::scalar:
obj.template evaluate_call<ValueType, tensor_basic<T1>, T2> (hat_K, q, value); break;
case space_constant::vector:
obj.template evaluate_call<ValueType, tensor_basic<T1>, point_basic<T2> > (hat_K, q, value); break;
case space_constant::tensor:
case space_constant::unsymmetric_tensor:
obj.template evaluate_call<ValueType, tensor_basic<T1>, tensor_basic<T2> > (hat_K, q, value); break;
default: error_macro ("unexpected second argument valued tag="<<arg2_valued_tag);
}
break;
}
default: error_macro ("unexpected first argument valued tag="<<arg1_valued_tag);
}
}
};
// main eval call:
template<class ValueType>
void basis_evaluate (const reference_element& hat_K, size_type q, std::vector<ValueType>& value) 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;
static const space_constant::valued_type first_argument_tag = space_constant::valued_tag_traits<A1>::value;
static const space_constant::valued_type second_argument_tag = space_constant::valued_tag_traits<A2>::value;
typedef field_vf_expr_bf<BinaryFunction, Expr1, Expr2> This;
typedef typename is_undeterminated<A1>::type undet_1;
typedef typename is_undeterminated<A2>::type undet_2;
evaluate_switch <This, ValueType, A1, A2, undet_1, undet_2> eval;
eval (*this, hat_K, q, value);
}
template<class ValueType>
void 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>();
}
protected:
// data:
BinaryFunction _f;
Expr1 _expr1;
Expr2 _expr2;
};
// ---------------------------------------------------------------------------
// helper
// ---------------------------------------------------------------------------
template<class This, class Arg1>
struct nl_switch {
typedef typename This::size_type size_type;
void element_initialize (const This& obj, const geo_element& K) const {
space_constant::valued_type nl_arg_valued_tag = obj._nl_expr.valued_tag();
switch (nl_arg_valued_tag) {
case space_constant::scalar:
obj._nl_expr.evaluate (K, obj._scalar_nl_value_quad); break;
case space_constant::vector:
obj._nl_expr.evaluate (K, obj._vector_nl_value_quad); break;
case space_constant::tensor:
case space_constant::unsymmetric_tensor:
obj._nl_expr.evaluate (K, obj._tensor_nl_value_quad); break;
case space_constant::tensor3:
obj._nl_expr.evaluate (K, obj._tensor3_nl_value_quad); break;
case space_constant::tensor4:
obj._nl_expr.evaluate (K, obj._tensor4_nl_value_quad); break;
default: error_macro ("unexpected first argument valued tag="<<nl_arg_valued_tag); // ICI
}
}
void element_initialize_on_side (const This& obj, const geo_element& K, const side_information_type& sid) const {
space_constant::valued_type nl_arg_valued_tag = obj._nl_expr.valued_tag();
switch (nl_arg_valued_tag) {
case space_constant::scalar:
obj._nl_expr.evaluate_on_side (K, sid, obj._scalar_nl_value_quad); break;
case space_constant::vector:
obj._nl_expr.evaluate_on_side (K, sid, obj._vector_nl_value_quad); break;
case space_constant::tensor:
case space_constant::unsymmetric_tensor:
obj._nl_expr.evaluate_on_side (K, sid, obj._tensor_nl_value_quad); break;
case space_constant::tensor3:
obj._nl_expr.evaluate_on_side (K, sid, obj._tensor3_nl_value_quad); break;
case space_constant::tensor4:
obj._nl_expr.evaluate_on_side (K, sid, obj._tensor4_nl_value_quad); break;
default: error_macro ("unexpected first argument valued tag="<<nl_arg_valued_tag);
}
}
Arg1 get_nl_value (const This& obj, size_type q) const {
// Arg1 may be solved at compile time for real evaluation
fatal_macro ("unexpected argument type="<<typename_macro(Arg1));
return Arg1();
}
};
template<class This> struct nl_switch<This,typename This::scalar_type> {
typedef typename This::size_type size_type;
typedef typename This::scalar_type scalar_type;
void element_initialize (const This& obj, const geo_element& K) const {
obj._nl_expr.evaluate (K, obj._scalar_nl_value_quad); }
void element_initialize_on_side (const This& obj, const geo_element& K, const side_information_type& sid) const {
obj._nl_expr.evaluate_on_side (K, sid, obj._scalar_nl_value_quad); }
const scalar_type& get_nl_value (const This& obj, size_type q) const {
return obj._scalar_nl_value_quad[q]; }
};
template<class This> struct nl_switch<This,point_basic<typename This::scalar_type> > {
typedef typename This::size_type size_type;
typedef typename This::scalar_type scalar_type;
void element_initialize (const This& obj, const geo_element& K) const {
obj._nl_expr.evaluate (K, obj._vector_nl_value_quad); }
void element_initialize_on_side (const This& obj, const geo_element& K, const side_information_type& sid) const {
obj._nl_expr.evaluate_on_side (K, sid, obj._vector_nl_value_quad); }
const point_basic<scalar_type>& get_nl_value (const This& obj, size_type q) const {
return obj._vector_nl_value_quad[q]; }
};
template<class This> struct nl_switch<This,tensor_basic<typename This::scalar_type> > {
typedef typename This::size_type size_type;
typedef typename This::scalar_type scalar_type;
void element_initialize (const This& obj, const geo_element& K) const {
obj._nl_expr.evaluate (K, obj._tensor_nl_value_quad); }
void element_initialize_on_side (const This& obj, const geo_element& K, const side_information_type& sid) const {
obj._nl_expr.evaluate_on_side (K, sid, obj._tensor_nl_value_quad); }
const tensor_basic<scalar_type>& get_nl_value (const This& obj, size_type q) const {
return obj._tensor_nl_value_quad[q]; }
};
template<class This> struct nl_switch<This,tensor3_basic<typename This::scalar_type> > {
typedef typename This::size_type size_type;
typedef typename This::scalar_type scalar_type;
void element_initialize (const This& obj, const geo_element& K) const {
obj._nl_expr.evaluate (K, obj._tensor3_nl_value_quad); }
void element_initialize_on_side (const This& obj, const geo_element& K, const side_information_type& sid) const {
obj._nl_expr.evaluate_on_side (K, sid, obj._tensor3_nl_value_quad); }
const tensor3_basic<scalar_type>& get_nl_value (const This& obj, size_type q) const {
return obj._tensor3_nl_value_quad[q]; }
};
template<class This> struct nl_switch<This,tensor4_basic<typename This::scalar_type> > {
typedef typename This::size_type size_type;
typedef typename This::scalar_type scalar_type;
void element_initialize (const This& obj, const geo_element& K) const {
obj._nl_expr.evaluate (K, obj._tensor4_nl_value_quad); }
void element_initialize_on_side (const This& obj, const geo_element& K, const side_information_type& sid) const {
obj._nl_expr.evaluate_on_side (K, sid, obj._tensor4_nl_value_quad); }
const tensor4_basic<scalar_type>& get_nl_value (const This& obj, size_type q) const {
return obj._tensor4_nl_value_quad[q]; }
};
// ---------------------------------------------------------------------------
// binary function call: (f nl_expr vf_expr)
// examples: f = operator*, operator/
// eta_h*v
// v/eta_h
// dot(v,normal())
// at any quadrature node xq, the compuation eta_h(xq) is performed
// and then we loop on the basis functions for v :
// eta_q = eta_h(xq);
// for i=0..nk-1
// value[i] = f (eta_q, v(xq)[i]);
// since we can swap the two args (see the details::swap_fun<f> class),
// we assume that the first argument is a field or a general field_nl_expr
// and that the second argument is a test of a general field_vf_expr
//
// Implementation note: this operation do not reduces to field_vf_expr_uf
// with a class-function that contains eta_h since :
// - the value of eta_h may be refreshed at each xq
// (this could be achieved by replacing std::binder1st with an adequate extension)
// - the valued category of eta_h is not always known at compile-time.
// It is known in dot(eta_h,v) but not with eta_h*v
// and the class-functions for field_vf_expr_uf may have Arg1 and Result determined.
// So we switch to a specific field_vf_expr_binded_bf that is abble to solve the
// valued type at run time. When it is possible, it is determined at compile-time.
// ---------------------------------------------------------------------------
template<class BinaryFunction, class NLExpr, class VFExpr>
class field_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 VFExpr::vf_tag_type vf_tag_type;
typedef typename details::dual_vf_tag<vf_tag_type>::type
vf_dual_tag_type;
typedef field_vf_expr_binded_bf<BinaryFunction,NLExpr,VFExpr> self_type;
typedef field_vf_expr_binded_bf<BinaryFunction,NLExpr,typename VFExpr::dual_self_type>
dual_self_type;
// alocators:
field_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(),
_tensor4_nl_value_quad()
{}
field_vf_expr_binded_bf (const field_vf_expr_binded_bf<BinaryFunction,NLExpr,VFExpr>& x)
: _f(x._f),
_nl_expr(x._nl_expr),
_vf_expr(x._vf_expr),
_scalar_nl_value_quad(x._scalar_nl_value_quad),
_vector_nl_value_quad(x._vector_nl_value_quad),
_tensor_nl_value_quad(x._tensor_nl_value_quad),
_tensor4_nl_value_quad(x._tensor4_nl_value_quad)
{}
// accessors:
static bool have_test_space() { return true; } // deduce & check !
const space_type& get_vf_space() const { return _vf_expr.get_vf_space(); }
static const space_constant::valued_type valued_hint = space_constant::valued_tag_traits<value_type>::value;
space_constant::valued_type valued_tag() const {
return details::generic_binary_traits<BinaryFunction>::valued_tag(_nl_expr.valued_tag(), _vf_expr.valued_tag());
}
size_type n_derivative() const { return _vf_expr.n_derivative(); }
// mutable modifiers:
void 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);
}
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 promote<
typename NLExpr::value_type
,typename details::generic_binary_traits<BinaryFunction>::template hint<
typename NLExpr::value_type
,typename VFExpr::value_type
,value_type>::first_argument_type
>::type
A1;
nl_switch<self_type,A1> nl_helper;
nl_helper.element_initialize (*this, K);
_vf_expr.element_initialize (K);
}
void element_initialize_on_side (const geo_element& K, const side_information_type& sid) {
typedef typename promote<
typename NLExpr::value_type
,typename details::generic_binary_traits<BinaryFunction>::template hint<
typename NLExpr::value_type
,typename VFExpr::value_type
,value_type>::first_argument_type
>::type
A1;
nl_switch<self_type,A1> nl_helper;
nl_helper.element_initialize_on_side (*this, K, sid);
_vf_expr.element_initialize_on_side (K, sid);
}
// ---------------------------------------------
// basis evaluate
// ---------------------------------------------
// evaluate when all arg types are determinated
template<class ValueType, class Arg1, class Arg2, class Status>
struct evaluate_call_check {
void operator() (const self_type& obj, const reference_element& hat_K, size_type q, std::vector<ValueType>& value) const {
fatal_macro ("invalid type resolution");
}
};
template<class ValueType, class Arg1, class Arg2>
struct evaluate_call_check<ValueType,Arg1,Arg2,mpl::true_> {
void operator() (const self_type& obj, const reference_element& hat_K, size_type q, std::vector<ValueType>& value) const {
nl_switch<self_type,Arg1> nl_helper;
const Arg1& value1 = nl_helper.get_nl_value (obj, q);
std::vector<Arg2> value2 (value.size());
obj._vf_expr.basis_evaluate (hat_K, q, value2);
for (size_type loc_idof = 0, loc_ndof = value.size(); loc_idof < loc_ndof; ++loc_idof) {
value[loc_idof] = obj._f (value1, value2[loc_idof]);
}
}
};
template<class ValueType, class Arg1, class Arg2>
void evaluate_call (const reference_element& hat_K, size_type q, std::vector<ValueType>& value) const {
typedef typename details::generic_binary_traits<BinaryFunction>::template result_hint<Arg1,Arg2>::type result_type;
// TODO: instead of is_equal, could have compatible scalars T1,T2 ?
typedef typename details::is_equal<ValueType,result_type>::type status_t;
evaluate_call_check<ValueType,Arg1,Arg2,status_t> eval;
eval (*this, hat_K, q, value);
}
template<class This, class ValueType, class Arg1, class Arg2, class Undet1, class Undet2>
struct evaluate_switch {};
// when both args are defined at compile time:
template<class This, class ValueType, class Arg1, class Arg2>
struct evaluate_switch<This, ValueType, Arg1, Arg2, mpl::false_, mpl::false_> {
void operator() (const This& obj, const reference_element& hat_K, size_type q, std::vector<ValueType>& value) const {
obj.template evaluate_call<ValueType, Arg1, Arg2> (hat_K, q, value);
}
};
// when first arg is undeterminated
template<class This, class ValueType, class Arg1, class Arg2>
struct evaluate_switch<This, ValueType, Arg1, Arg2, mpl::true_, mpl::false_> {
void operator() (const This& obj, const reference_element& hat_K, size_type q, std::vector<ValueType>& value) const {
typedef typename scalar_traits<Arg1>::type T1;
space_constant::valued_type arg1_valued_tag = obj._nl_expr.valued_tag();
switch (arg1_valued_tag) {
case space_constant::scalar:
obj.template evaluate_call<ValueType, T1, Arg2> (hat_K, q, value); break;
case space_constant::vector:
obj.template evaluate_call<ValueType, point_basic<T1>, Arg2> (hat_K, q, value); break;
case space_constant::tensor:
case space_constant::unsymmetric_tensor:
obj.template evaluate_call<ValueType, tensor_basic<T1>, Arg2> (hat_K, q, value); break;
case space_constant::tensor3:
obj.template evaluate_call<ValueType, tensor3_basic<T1>, Arg2> (hat_K, q, value); break;
case space_constant::tensor4:
obj.template evaluate_call<ValueType, tensor4_basic<T1>, Arg2> (hat_K, q, value); break;
default: error_macro ("unexpected first argument valued tag="<<arg1_valued_tag);
}
}
};
// when second arg is undeterminated
template<class This, class ValueType, class Arg1, class Arg2>
struct evaluate_switch<This, ValueType, Arg1, Arg2, mpl::false_, mpl::true_> {
void operator() (const This& obj, const reference_element& hat_K, size_type q, std::vector<ValueType>& value) const {
typedef typename scalar_traits<Arg2>::type T2;
space_constant::valued_type arg2_valued_tag = obj._vf_expr.valued_tag();
switch (arg2_valued_tag) {
case space_constant::scalar:
obj.template evaluate_call<ValueType, Arg1, T2> (hat_K, q, value); break;
case space_constant::vector:
obj.template evaluate_call<ValueType, Arg1, point_basic<T2> > (hat_K, q, value); break;
case space_constant::tensor:
case space_constant::unsymmetric_tensor:
obj.template evaluate_call<ValueType, Arg1, tensor_basic<T2> > (hat_K, q, value); break;
case space_constant::tensor3:
obj.template evaluate_call<ValueType, Arg1, tensor3_basic<T2> > (hat_K, q, value); break;
case space_constant::tensor4:
obj.template evaluate_call<ValueType, Arg1, tensor4_basic<T2> > (hat_K, q, value); break;
default: error_macro ("unexpected second argument valued tag="<<arg2_valued_tag);
}
}
};
// when one arg or both are undefined at compile time:
// TODO: optimize when only one arg is undeterminated
template<class This, class ValueType, class Arg1, class Arg2>
struct evaluate_switch<This, ValueType, Arg1, Arg2, mpl::true_, mpl::true_> {
void operator() (const This& obj, const reference_element& hat_K, size_type q, std::vector<ValueType>& value) const {
typedef typename scalar_traits<Arg1>::type T1;
typedef typename scalar_traits<Arg2>::type T2;
space_constant::valued_type arg1_valued_tag = obj._nl_expr.valued_tag();
space_constant::valued_type arg2_valued_tag = obj._vf_expr.valued_tag();
switch (arg1_valued_tag) {
case space_constant::scalar: {
switch (arg2_valued_tag) {
case space_constant::scalar:
obj.template evaluate_call<ValueType, T1, T2> (hat_K, q, value); break;
case space_constant::vector:
obj.template evaluate_call<ValueType, T1, point_basic<T2> > (hat_K, q, value); break;
case space_constant::tensor:
case space_constant::unsymmetric_tensor:
obj.template evaluate_call<ValueType, T1, tensor_basic<T2> > (hat_K, q, value); break;
case space_constant::tensor3:
obj.template evaluate_call<ValueType, T1, tensor3_basic<T2> > (hat_K, q, value); break;
case space_constant::tensor4:
obj.template evaluate_call<ValueType, T1, tensor4_basic<T2> > (hat_K, q, value); break;
default: error_macro ("unexpected second argument valued tag="<<arg2_valued_tag);
}
break;
}
case space_constant::vector: {
switch (arg2_valued_tag) {
case space_constant::scalar:
obj.template evaluate_call<ValueType, point_basic<T1>, T2> (hat_K, q, value); break;
case space_constant::vector:
obj.template evaluate_call<ValueType, point_basic<T1>, point_basic<T2> > (hat_K, q, value); break;
case space_constant::tensor:
case space_constant::unsymmetric_tensor:
obj.template evaluate_call<ValueType, point_basic<T1>, tensor_basic<T2> > (hat_K, q, value); break;
case space_constant::tensor3:
obj.template evaluate_call<ValueType, point_basic<T1>, tensor3_basic<T2> > (hat_K, q, value); break;
case space_constant::tensor4:
obj.template evaluate_call<ValueType, point_basic<T1>, tensor4_basic<T2> > (hat_K, q, value); break;
default: error_macro ("unexpected second argument valued tag="<<arg2_valued_tag);
}
break;
}
case space_constant::tensor:
case space_constant::unsymmetric_tensor: {
switch (arg2_valued_tag) {
case space_constant::scalar:
obj.template evaluate_call<ValueType, tensor_basic<T1>, T2> (hat_K, q, value); break;
case space_constant::vector:
obj.template evaluate_call<ValueType, tensor_basic<T1>, point_basic<T2> > (hat_K, q, value); break;
case space_constant::tensor:
case space_constant::unsymmetric_tensor:
obj.template evaluate_call<ValueType, tensor_basic<T1>, tensor_basic<T2> > (hat_K, q, value); break;
case space_constant::tensor3:
obj.template evaluate_call<ValueType, tensor_basic<T1>, tensor3_basic<T2> > (hat_K, q, value); break;
case space_constant::tensor4:
obj.template evaluate_call<ValueType, tensor_basic<T1>, tensor4_basic<T2> > (hat_K, q, value); break;
default: error_macro ("unexpected second argument valued tag="<<arg2_valued_tag);
}
break;
}
case space_constant::tensor3: {
switch (arg2_valued_tag) {
case space_constant::scalar:
obj.template evaluate_call<ValueType, tensor3_basic<T1>, T2> (hat_K, q, value); break;
case space_constant::vector:
obj.template evaluate_call<ValueType, tensor3_basic<T1>, point_basic<T2> > (hat_K, q, value); break;
case space_constant::tensor:
case space_constant::unsymmetric_tensor:
obj.template evaluate_call<ValueType, tensor3_basic<T1>, tensor_basic<T2> > (hat_K, q, value); break;
case space_constant::tensor3:
obj.template evaluate_call<ValueType, tensor3_basic<T1>, tensor3_basic<T2> > (hat_K, q, value); break;
case space_constant::tensor4:
obj.template evaluate_call<ValueType, tensor3_basic<T1>, tensor4_basic<T2> > (hat_K, q, value); break;
default: error_macro ("unexpected second argument valued tag="<<arg2_valued_tag);
}
break;
}
case space_constant::tensor4: {
switch (arg2_valued_tag) {
case space_constant::scalar:
obj.template evaluate_call<ValueType, tensor4_basic<T1>, T2> (hat_K, q, value); break;
case space_constant::vector:
obj.template evaluate_call<ValueType, tensor4_basic<T1>, point_basic<T2> > (hat_K, q, value); break;
case space_constant::tensor:
case space_constant::unsymmetric_tensor:
obj.template evaluate_call<ValueType, tensor4_basic<T1>, tensor_basic<T2> > (hat_K, q, value); break;
case space_constant::tensor3:
obj.template evaluate_call<ValueType, tensor4_basic<T1>, tensor3_basic<T2> > (hat_K, q, value); break;
case space_constant::tensor4:
obj.template evaluate_call<ValueType, tensor4_basic<T1>, tensor4_basic<T2> > (hat_K, q, value); break;
default: error_macro ("unexpected second argument valued tag="<<arg2_valued_tag);
}
break;
}
default: error_macro ("unexpected first argument valued tag="<<arg1_valued_tag);
}
}
};
// main eval call:
template<class ValueType>
void basis_evaluate (const reference_element& hat_K, size_type q, std::vector<ValueType>& value) const {
typedef typename promote<
typename NLExpr::value_type
,typename details::generic_binary_traits<BinaryFunction>::template hint<
typename NLExpr::value_type
,typename VFExpr::value_type
,ValueType>::first_argument_type
>::type A1;
typedef typename promote<
typename VFExpr::value_type
,typename details::generic_binary_traits<BinaryFunction>::template hint<
typename NLExpr::value_type
,typename VFExpr::value_type
,ValueType>::second_argument_type
>::type A2;
static const space_constant::valued_type first_argument_tag = space_constant::valued_tag_traits<A1>::value;
static const space_constant::valued_type second_argument_tag = space_constant::valued_tag_traits<A2>::value;
typedef typename is_undeterminated<A1>::type undet_1;
typedef typename is_undeterminated<A2>::type undet_2;
evaluate_switch <self_type, ValueType, A1, A2, undet_1, undet_2> eval;
eval (*this, hat_K, q, value);
}
template<class ValueType>
void valued_check() const {
typedef typename promote<
typename NLExpr::value_type
,typename details::generic_binary_traits<BinaryFunction>::template hint<
typename NLExpr::value_type
,typename VFExpr::value_type
,ValueType>::first_argument_type
>::type A1;
typedef typename promote<
typename VFExpr::value_type
,typename details::generic_binary_traits<BinaryFunction>::template hint<
typename NLExpr::value_type
,typename VFExpr::value_type
,ValueType>::second_argument_type
>::type A2;
if (! is_undeterminated<A1>::value) _nl_expr.valued_check<A1>();
if (! is_undeterminated<A2>::value) _vf_expr.valued_check<A2>();
}
//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;
};
} // namespace rheolef
#endif // _RHEOLEF_FIELD_VF_EXPR_H
|