/usr/include/dune/pdelab/localoperator/dgnavierstokesvelvecfem.hh is in libdune-pdelab-dev 2.5.0~20170124g7cf9f47a-1.
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 | // -*- tab-width: 2; indent-tabs-mode: nil -*-
// vi: set et ts=2 sw=2 sts=2:
#ifndef DUNE_PDELAB_LOCALOPERATOR_DGNAVIERSTOKESVELVECFEM_HH
#define DUNE_PDELAB_LOCALOPERATOR_DGNAVIERSTOKESVELVECFEM_HH
#include <dune/common/exceptions.hh>
#include <dune/common/fvector.hh>
#include <dune/common/parametertree.hh>
#include <dune/geometry/quadraturerules.hh>
#include <dune/localfunctions/common/interfaceswitch.hh>
#include <dune/pdelab/localoperator/idefault.hh>
#include <dune/pdelab/localoperator/defaultimp.hh>
#include <dune/pdelab/localoperator/pattern.hh>
#include <dune/pdelab/localoperator/flags.hh>
#include <dune/pdelab/localoperator/dgnavierstokesparameter.hh>
#include <dune/pdelab/localoperator/navierstokesmass.hh>
#ifndef VBLOCK
#define VBLOCK 0
#endif
#define PBLOCK (- VBLOCK + 1)
namespace Dune {
namespace PDELab {
template<class Basis, class Dummy = void>
struct VectorBasisInterfaceSwitch {
//! export vector type of the local coordinates
using DomainLocal = typename Basis::Traits::DomainLocal;
//! export field type of the values
using RangeField = typename Basis::Traits::RangeField;
//! export dimension of the values
static const std::size_t dimRange = Basis::Traits::dimRange;
//! Compute global jacobian matrix for vector valued bases
template<typename Geometry>
static void jacobian(const Basis& basis, const Geometry& geometry,
const DomainLocal& xl,
std::vector<FieldMatrix<RangeField, dimRange,
Geometry::coorddimension> >& jac)
{
jac.resize(basis.size());
basis.evaluateJacobian(xl, jac);
}
};
//! Switch for uniform treatment of local and global basis classes
template<class Basis>
struct VectorBasisInterfaceSwitch<
Basis, typename std::enable_if<
Std::to_true_type<
std::integral_constant<
std::size_t,
Basis::Traits::dimDomain
>
>::value
>::type
>
{
//! export vector type of the local coordinates
using DomainLocal = typename Basis::Traits::DomainType;
//! export field type of the values
using RangeField = typename Basis::Traits::RangeFieldType;
//! export dimension of the values
static const std::size_t dimRange = Basis::Traits::dimRange;
//! Compute global jacobian matrix for vector valued bases
template<typename Geometry>
static void jacobian(const Basis& basis, const Geometry& geometry,
const DomainLocal& xl,
std::vector<FieldMatrix<RangeField, dimRange,
Geometry::coorddimension> >& jac)
{
jac.resize(basis.size());
std::vector<FieldMatrix<
RangeField, dimRange, Geometry::coorddimension> > ljac(basis.size());
basis.evaluateJacobian(xl, ljac);
const typename Geometry::JacobianInverseTransposed& geojac =
geometry.jacobianInverseTransposed(xl);
for(std::size_t i = 0; i < basis.size(); ++i)
for(std::size_t row=0; row < dimRange; ++row)
geojac.mv(ljac[i][row], jac[i][row]);
}
};
/** \brief A local operator for solving the Navier-Stokes equations
using a DG discretization and a vector-valued finite element map
for the velocity grid function space.
\tparam PRM Parameter class for this local operator.
*/
template<typename PRM>
class DGNavierStokesVelVecFEM :
public LocalOperatorDefaultFlags,
public FullSkeletonPattern, public FullVolumePattern,
public InstationaryLocalOperatorDefaultMethods<typename PRM::Traits::RangeField>
{
using BC = StokesBoundaryCondition;
using RF = typename PRM::Traits::RangeField;
using InstatBase = InstationaryLocalOperatorDefaultMethods<typename PRM::Traits::RangeField>;
using Real = typename InstatBase::RealType;
static const bool navier = PRM::assemble_navier;
static const bool full_tensor = PRM::assemble_full_tensor;
public :
// pattern assembly flags
enum { doPatternVolume = true };
enum { doPatternSkeleton = true };
// call the assembler for each face only once
enum { doSkeletonTwoSided = false };
// residual assembly flags
enum { doAlphaVolume = true };
enum { doAlphaSkeleton = true };
enum { doAlphaBoundary = true };
enum { doLambdaVolume = true };
/** \brief Constructor
\param [in] _prm Parameter class for this local operator
\param [in] _superintegration_order This number will be added to the order of
quadrature in every integration. It is
only needed, when one of the parameters (e.g
rho, mu) is not constant or the mappings from
the reference elements to the cells are
nonlinear. Boundary conditions are assumed to
have the same order as the corresponding
finite element.
*/
DGNavierStokesVelVecFEM (PRM& _prm, int _superintegration_order=0) :
prm(_prm), superintegration_order(_superintegration_order),
current_dt(1.0)
{}
// Store current dt
void preStep (Real , Real dt, int )
{
current_dt = dt;
}
// set time in parameter class
void setTime(Real t)
{
InstatBase::setTime(t);
prm.setTime(t);
}
// volume integral depending on test and ansatz functions
template<typename EG, typename LFSU, typename X, typename LFSV, typename R>
void alpha_volume (const EG& eg, const LFSU& lfsu, const X& x, const LFSV& lfsv, R& r) const
{
const unsigned int dim = EG::Geometry::mydimension;
// subspaces
using namespace Indices;
using LFSV_V = TypeTree::Child<LFSV,_0>;
const auto& lfsv_v = child(lfsv,_0);
const auto& lfsu_v = child(lfsu,_0);
using LFSV_P = TypeTree::Child<LFSV,_1>;
const auto& lfsv_p = child(lfsv,_1);
const auto& lfsu_p = child(lfsu,_1);
// domain and range field type
using FESwitch_V = FiniteElementInterfaceSwitch<typename LFSV_V::Traits::FiniteElementType >;
using BasisSwitch_V = BasisInterfaceSwitch<typename FESwitch_V::Basis >;
using VectorBasisSwitch_V = VectorBasisInterfaceSwitch<typename FESwitch_V::Basis >;
using FESwitch_P = FiniteElementInterfaceSwitch<typename LFSV_P::Traits::FiniteElementType >;
using BasisSwitch_P = BasisInterfaceSwitch<typename FESwitch_P::Basis >;
using RF = typename BasisSwitch_V::RangeField;
using Range_V = typename BasisSwitch_V::Range;
using Range_P = typename BasisSwitch_P::Range;
using size_type = typename LFSV::Traits::SizeType;
// Get geometry
auto geo = eg.geometry();
// Determine quadrature order
const int v_order = FESwitch_V::basis(lfsv_v.finiteElement()).order();
const int det_jac_order = geo.type().isSimplex() ? 0 : (dim-1);
const int jac_order = geo.type().isSimplex() ? 0 : 1;
const int qorder = 3*v_order - 1 + jac_order + det_jac_order + superintegration_order;
const RF incomp_scaling = prm.incompressibilityScaling(current_dt);
// loop over quadrature points
for (const auto& ip : quadratureRule(geo,qorder))
{
auto local = ip.position();
auto mu = prm.mu(eg,local);
auto rho = prm.rho(eg,local);
// compute u (if Navier term enabled)
std::vector<Range_V> phi_v(lfsv_v.size());
Range_V val_u(0.0);
if(navier) {
FESwitch_V::basis(lfsv_v.finiteElement()).evaluateFunction(local,phi_v);
for (size_type i=0; i<lfsu_v.size(); i++)
val_u.axpy(x(lfsu_v,i),phi_v[i]);
}
// values of pressure shape functions
std::vector<Range_P> phi_p(lfsv_p.size());
FESwitch_P::basis(lfsv_p.finiteElement()).evaluateFunction(local,phi_p);
// compute pressure value
Range_P val_p(0.0);
for (size_type i=0; i<lfsu_p.size(); i++)
val_p.axpy(x(lfsu_p,i),phi_p[i]);
// evaluate jacobian of velocity shape functions on reference element
std::vector<Dune::FieldMatrix<RF,dim,dim> > jac_phi_v(lfsu_v.size());
VectorBasisSwitch_V::jacobian
(FESwitch_V::basis(lfsv_v.finiteElement()), geo, local, jac_phi_v);
// compute divergence of test functions
std::vector<RF> div_phi_v(lfsv_v.size(),0.0);
for (size_type i=0; i<lfsv_v.size(); i++)
for (size_type d=0; d<dim; d++)
div_phi_v[i] += jac_phi_v[i][d][d];
// compute velocity jacobian and divergence
Dune::FieldMatrix<RF,dim,dim> jac_u(0.0);
RF div_u(0.0);
for (size_type i=0; i<lfsu_v.size(); i++){
jac_u.axpy(x(lfsu_v,i),jac_phi_v[i]);
div_u += x(lfsu_v,i) * div_phi_v[i];
}
auto detj = geo.integrationElement(ip.position());
auto weight = ip.weight() * detj;
for (size_type i=0; i<lfsv_v.size(); i++) {
//================================================//
// \int (mu*grad_u*grad_v)
//================================================//
RF dvdu(0);
contraction(jac_u,jac_phi_v[i],dvdu);
r.accumulate(lfsv_v, i, dvdu * mu * weight);
//================================================//
// \int -p \nabla\cdot v
//================================================//
r.accumulate(lfsv_v, i, - div_phi_v[i] * val_p * weight);
//================================================//
// \int \rho ((u\cdot\nabla ) u )\cdot v
//================================================//
if(navier) {
// compute (grad u) u (matrix-vector product)
Range_V nabla_u_u(0.0);
jac_u.mv(val_u,nabla_u_u);
r.accumulate(lfsv_v, i, rho * (nabla_u_u*phi_v[i]) * weight);
} // end navier
} // end i
for (size_type i=0; i<lfsv_p.size(); i++) {
//================================================//
// \int -q \nabla\cdot u
//================================================//
r.accumulate(lfsv_p, i, - div_u * phi_p[i] * incomp_scaling * weight);
}
} // end loop quadrature points
} // end alpha_volume
// jacobian of volume term
template<typename EG, typename LFSU, typename X, typename LFSV,
typename LocalMatrix>
void jacobian_volume (const EG& eg, const LFSU& lfsu, const X& x, const LFSV& lfsv,
LocalMatrix& mat) const
{
const unsigned int dim = EG::Geometry::mydimension;
// subspaces
using namespace Indices;
using LFSV_V = TypeTree::Child<LFSV,_0>;
const auto& lfsv_v = child(lfsv,_0);
const auto& lfsu_v = child(lfsu,_0);
using LFSV_P = TypeTree::Child<LFSV,_1>;
const auto& lfsv_p = child(lfsv,_1);
const auto& lfsu_p = child(lfsu,_1);
// domain and range field type
using FESwitch_V = FiniteElementInterfaceSwitch<typename LFSV_V::Traits::FiniteElementType >;
using BasisSwitch_V = BasisInterfaceSwitch<typename FESwitch_V::Basis >;
using VectorBasisSwitch_V = VectorBasisInterfaceSwitch<typename FESwitch_V::Basis >;
using FESwitch_P = FiniteElementInterfaceSwitch<typename LFSV_P::Traits::FiniteElementType >;
using BasisSwitch_P = BasisInterfaceSwitch<typename FESwitch_P::Basis >;
using RF = typename BasisSwitch_V::RangeField;
using Range_V = typename BasisSwitch_V::Range;
using Range_P = typename BasisSwitch_P::Range;
using size_type = typename LFSV::Traits::SizeType;
// Get geometry
auto geo = eg.geometry();
// Determine quadrature order
const int v_order = FESwitch_V::basis(lfsv_v.finiteElement()).order();
const int det_jac_order = geo.type().isSimplex() ? 0 : (dim-1);
const int jac_order = geo.type().isSimplex() ? 0 : 1;
const int qorder = 3*v_order - 1 + jac_order + det_jac_order + superintegration_order;
const RF incomp_scaling = prm.incompressibilityScaling(current_dt);
// loop over quadrature points
for (const auto& ip : quadratureRule(geo,qorder))
{
auto local = ip.position();
auto mu = prm.mu(eg,local);
auto rho = prm.rho(eg,local);
// compute u (if Navier term enabled)
std::vector<Range_V> phi_v(lfsv_v.size());
Range_V val_u(0.0);
if(navier) {
FESwitch_V::basis(lfsv_v.finiteElement()).evaluateFunction(local,phi_v);
for (size_type i=0; i<lfsu_v.size(); i++)
val_u.axpy(x(lfsu_v,i),phi_v[i]);
}
// values of pressure shape functions
std::vector<Range_P> phi_p(lfsv_p.size());
FESwitch_P::basis(lfsv_p.finiteElement()).evaluateFunction(local,phi_p);
// evaluate jacobian of velocity shape functions on reference element
std::vector<Dune::FieldMatrix<RF,dim,dim> > jac_phi_v(lfsu_v.size());
VectorBasisSwitch_V::jacobian
(FESwitch_V::basis(lfsv_v.finiteElement()), geo, local, jac_phi_v);
assert(lfsu_v.size() == lfsv_v.size());
// compute divergence of velocity shape functions
std::vector<RF> div_phi_v(lfsv_v.size(),0.0);
for (size_type i=0; i<lfsv_v.size(); i++)
for (size_type d=0; d<dim; d++)
div_phi_v[i] += jac_phi_v[i][d][d];
// compute velocity jacobian (if Navier term enabled)
Dune::FieldMatrix<RF,dim,dim> jac_u(0.0);
if(navier) {
for (size_type i=0; i<lfsu_v.size(); i++){
jac_u.axpy(x(lfsu_v,i),jac_phi_v[i]);
}
}
auto detj = geo.integrationElement(ip.position());
auto weight = ip.weight() * detj;
for(size_type i=0; i<lfsv_v.size(); i++) {
for(size_type j=0; j<lfsu_v.size(); j++) {
//================================================//
// \int (mu*grad_u*grad_v)
//================================================//
RF dvdu(0.0);
contraction(jac_phi_v[j],jac_phi_v[i],dvdu);
mat.accumulate(lfsv_v,i,lfsu_v,j, mu * dvdu * weight);
//================================================//
// \int \rho ((u\cdot\nabla ) u )\cdot v
//================================================//
if(navier) {
// compute (grad u) phi_v_j (matrix-vector product)
Range_V nabla_u_phi_v_j(0.0);
jac_u.mv(phi_v[j],nabla_u_phi_v_j);
// compute (grad phi_v_j) u (matrix-vector product)
Range_V nabla_phi_v_j_u(0.0);
jac_phi_v[j].mv(val_u,nabla_phi_v_j_u);
mat.accumulate(lfsv_v,i,lfsu_v,j, rho * ((nabla_u_phi_v_j*phi_v[i]) + (nabla_phi_v_j_u*phi_v[i])) * weight);
} // end navier
} // end j
for(size_type j=0; j<lfsv_p.size(); j++) {
//================================================//
// - p * div v
// - q * div u
//================================================//
mat.accumulate(lfsv_v,i,lfsu_p,j, -phi_p[j] * div_phi_v[i] * weight);
mat.accumulate(lfsv_p,j,lfsu_v,i, -phi_p[j] * div_phi_v[i] * incomp_scaling * weight);
}
} // end i
} // end loop quadrature points
} // end jacobian_volume
// skeleton term, each face is only visited ONCE
template<typename IG, typename LFSU, typename X, typename LFSV, typename R>
void alpha_skeleton (const IG& ig,
const LFSU& lfsu_s, const X& x_s, const LFSV& lfsv_s,
const LFSU& lfsu_n, const X& x_n, const LFSV& lfsv_n,
R& r_s, R& r_n) const
{
// dimensions
const unsigned int dim = IG::dimension;
const unsigned int dimw = IG::coorddimension;
// subspaces
using namespace Indices;
using LFSV_V = TypeTree::Child<LFSV,_0>;
const auto& lfsv_v_s = child(lfsv_s,_0);
const auto& lfsu_v_s = child(lfsu_s,_0);
const auto& lfsv_v_n = child(lfsv_n,_0);
const auto& lfsu_v_n = child(lfsu_n,_0);
using LFSV_P = TypeTree::Child<LFSV,_1>;
const auto& lfsv_p_s = child(lfsv_s,_1);
const auto& lfsu_p_s = child(lfsu_s,_1);
const auto& lfsv_p_n = child(lfsv_n,_1);
const auto& lfsu_p_n = child(lfsu_n,_1);
// domain and range field type
using FESwitch_V = FiniteElementInterfaceSwitch<typename LFSV_V::Traits::FiniteElementType >;
using BasisSwitch_V = BasisInterfaceSwitch<typename FESwitch_V::Basis >;
using VectorBasisSwitch_V = VectorBasisInterfaceSwitch<typename FESwitch_V::Basis >;
using FESwitch_P = FiniteElementInterfaceSwitch<typename LFSV_P::Traits::FiniteElementType >;
using BasisSwitch_P = BasisInterfaceSwitch<typename FESwitch_P::Basis >;
using DF = typename BasisSwitch_V::DomainField;
using RF = typename BasisSwitch_V::RangeField;
using Range_V = typename BasisSwitch_V::Range;
using Range_P = typename BasisSwitch_P::Range;
using size_type = typename LFSV::Traits::SizeType;
// References to inside and outside cells
const auto& cell_inside = ig.inside();
const auto& cell_outside = ig.outside();
// Get geometries
auto geo = ig.geometry();
auto geo_inside = cell_inside.geometry();
auto geo_outside = cell_outside.geometry();
// Get geometry of intersection in local coordinates of cell_inside and cell_outside
auto geo_in_inside = ig.geometryInInside();
auto geo_in_outside = ig.geometryInOutside();
// Determine quadrature order
const int v_order = FESwitch_V::basis(lfsv_v_s.finiteElement()).order();
const int det_jac_order = geo.type().isSimplex() ? 0 : (dim-2);
const int qorder = 2*v_order + det_jac_order + superintegration_order;
const int epsilon = prm.epsilonIPSymmetryFactor();
const RF incomp_scaling = prm.incompressibilityScaling(current_dt);
auto penalty_factor = prm.getFaceIP(geo,geo_inside,geo_outside);
// loop over quadrature points and integrate normal flux
for (const auto& ip : quadratureRule(geo,qorder))
{
// position of quadrature point in local coordinates of element
auto local_s = geo_in_inside.global(ip.position());
auto local_n = geo_in_outside.global(ip.position());
// values of velocity shape functions
std::vector<Range_V> phi_v_s(lfsv_v_s.size());
std::vector<Range_V> phi_v_n(lfsv_v_n.size());
FESwitch_V::basis(lfsv_v_s.finiteElement()).evaluateFunction(local_s,phi_v_s);
FESwitch_V::basis(lfsv_v_n.finiteElement()).evaluateFunction(local_n,phi_v_n);
// values of pressure shape functions
std::vector<Range_P> phi_p_s(lfsv_p_s.size());
std::vector<Range_P> phi_p_n(lfsv_p_n.size());
FESwitch_P::basis(lfsv_p_s.finiteElement()).evaluateFunction(local_s,phi_p_s);
FESwitch_P::basis(lfsv_p_n.finiteElement()).evaluateFunction(local_n,phi_p_n);
// compute pressure value
Range_P val_p_s(0.0);
Range_P val_p_n(0.0);
for (size_type i=0; i<lfsu_p_s.size(); i++)
val_p_s.axpy(x_s(lfsu_p_s,i),phi_p_s[i]);
for (size_type i=0; i<lfsu_p_n.size(); i++)
val_p_n.axpy(x_n(lfsu_p_n,i),phi_p_n[i]);
// evaluate jacobian of velocity shape functions on reference element
std::vector<Dune::FieldMatrix<RF,dim,dim> > jac_phi_v_s(lfsu_v_s.size());
std::vector<Dune::FieldMatrix<RF,dim,dim> > jac_phi_v_n(lfsu_v_n.size());
VectorBasisSwitch_V::jacobian
(FESwitch_V::basis(lfsv_v_s.finiteElement()), geo_inside, local_s, jac_phi_v_s);
VectorBasisSwitch_V::jacobian
(FESwitch_V::basis(lfsv_v_n.finiteElement()), geo_outside, local_n, jac_phi_v_n);
// compute velocity value, jacobian, and divergence
Range_V val_u_s(0.0);
Range_V val_u_n(0.0);
Dune::FieldMatrix<RF,dim,dim> jac_u_s(0.0);
Dune::FieldMatrix<RF,dim,dim> jac_u_n(0.0);
for (size_type i=0; i<lfsu_v_s.size(); i++){
val_u_s.axpy(x_s(lfsu_v_s,i),phi_v_s[i]);
jac_u_s.axpy(x_s(lfsu_v_s,i),jac_phi_v_s[i]);
}
for (size_type i=0; i<lfsu_v_n.size(); i++){
val_u_n.axpy(x_n(lfsu_v_n,i),phi_v_n[i]);
jac_u_n.axpy(x_n(lfsu_v_n,i),jac_phi_v_n[i]);
}
auto normal = ig.unitOuterNormal(ip.position());
auto weight = ip.weight()*geo.integrationElement(ip.position());
auto mu = prm.mu(ig,ip.position());
auto factor = mu * weight;
// compute jump in velocity
auto jump = val_u_s - val_u_n;
// compute mean in pressure
auto mean_p = 0.5*(val_p_s + val_p_n);
// compute flux of velocity jacobian
Dune::FieldVector<DF,dimw> flux_jac_u(0.0);
add_compute_flux(jac_u_s,normal,flux_jac_u);
add_compute_flux(jac_u_n,normal,flux_jac_u);
flux_jac_u *= 0.5;
// loop over test functions, same element
for (size_t i=0; i<lfsv_v_s.size(); i++) {
//================================================//
// diffusion term
//================================================//
r_s.accumulate(lfsv_v_s, i, -(flux_jac_u * phi_v_s[i]) * factor);
//================================================//
// (non-)symmetric IP term
//================================================//
Dune::FieldVector<DF,dimw> flux_jac_phi(0.0);
add_compute_flux(jac_phi_v_s[i],normal,flux_jac_phi);
r_s.accumulate(lfsv_v_s, i, epsilon * 0.5 * (flux_jac_phi * jump) * factor);
//================================================//
// standard IP term integral
//================================================//
r_s.accumulate(lfsv_v_s,i, penalty_factor * (jump*phi_v_s[i]) * factor);
//================================================//
// pressure-velocity-coupling in momentum equation
//================================================//
r_s.accumulate(lfsv_v_s,i, mean_p * (phi_v_s[i]*normal) * weight);
}
// loop over test functions, neighbour element
for (size_t i=0; i<lfsv_v_n.size(); i++) {
//================================================//
// diffusion term
//================================================//
r_n.accumulate(lfsv_v_n, i, (flux_jac_u * phi_v_n[i]) * factor);
//================================================//
// (non-)symmetric IP term
//================================================//
Dune::FieldVector<DF,dimw> flux_jac_phi(0.0);
add_compute_flux(jac_phi_v_n[i],normal,flux_jac_phi);
r_n.accumulate(lfsv_v_n, i, epsilon * 0.5 * (flux_jac_phi * jump) * factor);
//================================================//
// standard IP term integral
//================================================//
r_n.accumulate(lfsv_v_n,i, -penalty_factor * (jump*phi_v_n[i]) * factor);
//================================================//
// pressure-velocity-coupling in momentum equation
//================================================//
r_n.accumulate(lfsv_v_n,i, -mean_p * (phi_v_n[i]*normal) * weight);
}
//================================================//
// incompressibility constraint
//================================================//
for (size_t i=0; i<lfsv_p_s.size(); i++)
r_s.accumulate(lfsv_p_s,i, 0.5*phi_p_s[i] * (jump*normal) * incomp_scaling * weight);
for (size_t i=0; i<lfsv_p_n.size(); i++)
r_n.accumulate(lfsv_p_n,i, 0.5*phi_p_n[i] * (jump*normal) * incomp_scaling * weight);
} // end loop quadrature points
} // end alpha_skeleton
// jacobian of skeleton term, each face is only visited ONCE
template<typename IG, typename LFSU, typename X, typename LFSV,
typename LocalMatrix>
void jacobian_skeleton (const IG& ig,
const LFSU& lfsu_s, const X&, const LFSV& lfsv_s,
const LFSU& lfsu_n, const X&, const LFSV& lfsv_n,
LocalMatrix& mat_ss, LocalMatrix& mat_sn,
LocalMatrix& mat_ns, LocalMatrix& mat_nn) const
{
// dimensions
const unsigned int dim = IG::dimension;
const unsigned int dimw = IG::coorddimension;
// subspaces
using namespace Indices;
using LFSV_V = TypeTree::Child<LFSV,_0>;
const auto& lfsv_v_s = child(lfsv_s,_0);
const auto& lfsu_v_s = child(lfsu_s,_0);
const auto& lfsv_v_n = child(lfsv_n,_0);
const auto& lfsu_v_n = child(lfsu_n,_0);
using LFSV_P = TypeTree::Child<LFSV,_1>;
const auto& lfsv_p_s = child(lfsv_s,_1);
const auto& lfsu_p_s = child(lfsu_s,_1);
const auto& lfsv_p_n = child(lfsv_n,_1);
const auto& lfsu_p_n = child(lfsu_n,_1);
// domain and range field type
using FESwitch_V = FiniteElementInterfaceSwitch<typename LFSV_V::Traits::FiniteElementType >;
using BasisSwitch_V = BasisInterfaceSwitch<typename FESwitch_V::Basis >;
using VectorBasisSwitch_V = VectorBasisInterfaceSwitch<typename FESwitch_V::Basis >;
using FESwitch_P = FiniteElementInterfaceSwitch<typename LFSV_P::Traits::FiniteElementType >;
using BasisSwitch_P = BasisInterfaceSwitch<typename FESwitch_P::Basis >;
using DF = typename BasisSwitch_V::DomainField;
using RF = typename BasisSwitch_V::RangeField;
using Range_V = typename BasisSwitch_V::Range;
using Range_P = typename BasisSwitch_P::Range;
using size_type = typename LFSV::Traits::SizeType;
// References to inside and outside cells
auto const& cell_inside = ig.inside();
auto const& cell_outside = ig.outside();
// Get geometries
auto geo = ig.geometry();
auto geo_inside = cell_inside.geometry();
auto geo_outside = cell_outside.geometry();
// Get geometry of intersection in local coordinates of cell_inside and cell_outside
auto geo_in_inside = ig.geometryInInside();
auto geo_in_outside = ig.geometryInOutside();
// Determine quadrature order
const int v_order = FESwitch_V::basis(lfsv_v_s.finiteElement()).order();
const int det_jac_order = geo.type().isSimplex() ? 0 : (dim-2);
const int qorder = 2*v_order + det_jac_order + superintegration_order;
auto epsilon = prm.epsilonIPSymmetryFactor();
auto incomp_scaling = prm.incompressibilityScaling(current_dt);
auto penalty_factor = prm.getFaceIP(geo,geo_inside,geo_outside);
// loop over quadrature points and integrate normal flux
for (const auto& ip : quadratureRule(geo,qorder))
{
// position of quadrature point in local coordinates of element
auto local_s = geo_in_inside.global(ip.position());
auto local_n = geo_in_outside.global(ip.position());
// values of velocity shape functions
std::vector<Range_V> phi_v_s(lfsv_v_s.size());
std::vector<Range_V> phi_v_n(lfsv_v_n.size());
FESwitch_V::basis(lfsv_v_s.finiteElement()).evaluateFunction(local_s,phi_v_s);
FESwitch_V::basis(lfsv_v_n.finiteElement()).evaluateFunction(local_n,phi_v_n);
// values of pressure shape functions
std::vector<Range_P> phi_p_s(lfsv_p_s.size());
std::vector<Range_P> phi_p_n(lfsv_p_n.size());
FESwitch_P::basis(lfsv_p_s.finiteElement()).evaluateFunction(local_s,phi_p_s);
FESwitch_P::basis(lfsv_p_n.finiteElement()).evaluateFunction(local_n,phi_p_n);
// evaluate jacobian of velocity shape functions on reference element
std::vector<Dune::FieldMatrix<RF,dim,dim> > jac_phi_v_s(lfsu_v_s.size());
std::vector<Dune::FieldMatrix<RF,dim,dim> > jac_phi_v_n(lfsu_v_n.size());
VectorBasisSwitch_V::jacobian
(FESwitch_V::basis(lfsv_v_s.finiteElement()), geo_inside, local_s, jac_phi_v_s);
VectorBasisSwitch_V::jacobian
(FESwitch_V::basis(lfsv_v_n.finiteElement()), geo_outside, local_n, jac_phi_v_n);
auto normal = ig.unitOuterNormal(ip.position());
auto weight = ip.weight()*geo.integrationElement(ip.position());
auto mu = prm.mu(ig,ip.position());
auto factor = mu * weight;
//============================================
// loop over test functions, same element
//============================================
for(size_type i=0; i<lfsv_v_s.size(); i++) {
// compute flux
Dune::FieldVector<DF,dimw> flux_jac_phi_i(0.0);
add_compute_flux(jac_phi_v_s[i],normal,flux_jac_phi_i);
//============================================
// diffusion
// (non-)symmetric IP-Term
// standard IP integral
//============================================
for(size_type j=0; j<lfsu_v_s.size(); j++) {
Dune::FieldVector<DF,dimw> flux_jac_phi_j(0.0);
add_compute_flux(jac_phi_v_s[j],normal,flux_jac_phi_j);
mat_ss.accumulate(lfsv_v_s,i,lfsu_v_s,j, -0.5 * (flux_jac_phi_j*phi_v_s[i]) * factor);
mat_ss.accumulate(lfsv_v_s,i,lfsu_v_s,j, epsilon * 0.5 * (flux_jac_phi_i*phi_v_s[j]) * factor);
mat_ss.accumulate(lfsv_v_s,i,lfsu_v_s,j, penalty_factor * (phi_v_s[j]*phi_v_s[i]) * factor);
}
for(size_type j=0; j<lfsu_v_n.size(); j++) {
Dune::FieldVector<DF,dimw> flux_jac_phi_j(0.0);
add_compute_flux(jac_phi_v_n[j],normal,flux_jac_phi_j);
mat_sn.accumulate(lfsv_v_s,i,lfsu_v_n,j, -0.5 * (flux_jac_phi_j*phi_v_s[i]) * factor);
mat_sn.accumulate(lfsv_v_s,i,lfsu_v_n,j, -epsilon * 0.5 * (flux_jac_phi_i*phi_v_n[j]) * factor);
mat_sn.accumulate(lfsv_v_s,i,lfsu_v_n,j, -penalty_factor * (phi_v_n[j]*phi_v_s[i]) * factor);
}
//============================================
// pressure-velocity coupling in momentum equation
//============================================
for(size_type j=0; j<lfsu_p_s.size(); j++) {
mat_ss.accumulate(lfsv_v_s,i,lfsu_p_s,j, 0.5*phi_p_s[j] * (phi_v_s[i]*normal) * weight);
}
for(size_type j=0; j<lfsu_p_n.size(); j++) {
mat_sn.accumulate(lfsv_v_s,i,lfsu_p_n,j, 0.5*phi_p_n[j] * (phi_v_s[i]*normal) * weight);
}
} // end i (same)
//============================================
// loop over test functions, neighbour element
//============================================
for(size_type i=0; i<lfsv_v_n.size(); i++) {
// compute flux
Dune::FieldVector<DF,dimw> flux_jac_phi_i(0.0);
add_compute_flux(jac_phi_v_n[i],normal,flux_jac_phi_i);
//============================================
// diffusion
// (non-)symmetric IP-Term
// standard IP integral
//============================================
for(size_type j=0; j<lfsu_v_s.size(); j++) {
Dune::FieldVector<DF,dimw> flux_jac_phi_j(0.0);
add_compute_flux(jac_phi_v_s[j],normal,flux_jac_phi_j);
mat_ns.accumulate(lfsv_v_n,i,lfsu_v_s,j, 0.5 * (flux_jac_phi_j*phi_v_n[i]) * factor);
mat_ns.accumulate(lfsv_v_n,i,lfsu_v_s,j, epsilon * 0.5 * (flux_jac_phi_i*phi_v_s[j]) * factor);
mat_ns.accumulate(lfsv_v_n,i,lfsu_v_s,j, -penalty_factor * (phi_v_s[j]*phi_v_n[i]) * factor);
}
for(size_type j=0; j<lfsu_v_n.size(); j++) {
Dune::FieldVector<DF,dimw> flux_jac_phi_j(0.0);
add_compute_flux(jac_phi_v_n[j],normal,flux_jac_phi_j);
mat_nn.accumulate(lfsv_v_n,i,lfsu_v_n,j, 0.5 * (flux_jac_phi_j*phi_v_n[i]) * factor);
mat_nn.accumulate(lfsv_v_n,i,lfsu_v_n,j, -epsilon * 0.5 * (flux_jac_phi_i*phi_v_n[j]) * factor);
mat_nn.accumulate(lfsv_v_n,i,lfsu_v_n,j, penalty_factor * (phi_v_n[j]*phi_v_n[i]) * factor);
}
//============================================
// pressure-velocity coupling in momentum equation
//============================================
for(size_type j=0; j<lfsu_p_s.size(); j++) {
mat_ns.accumulate(lfsv_v_n,i,lfsu_p_s,j, -0.5*phi_p_s[j] * (phi_v_n[i]*normal) * weight);
}
for(size_type j=0; j<lfsu_p_n.size(); j++) {
mat_nn.accumulate(lfsv_v_n,i,lfsu_p_n,j, -0.5*phi_p_n[j] * (phi_v_n[i]*normal) * weight);
}
} // end i (neighbour)
//================================================//
// \int <q> [u] n
//================================================//
for(size_type i=0; i<lfsv_p_s.size(); i++) {
for(size_type j=0; j<lfsu_v_s.size(); j++)
mat_ss.accumulate(lfsv_p_s,i,lfsu_v_s,j, 0.5*phi_p_s[i] * (phi_v_s[j]*normal) * incomp_scaling * weight);
for(size_type j=0; j<lfsu_v_n.size(); j++)
mat_sn.accumulate(lfsv_p_s,i,lfsu_v_n,j, -0.5*phi_p_s[i] * (phi_v_n[j]*normal) * incomp_scaling * weight);
}
for(size_type i=0; i<lfsv_p_n.size(); i++) {
for(size_type j=0; j<lfsu_v_s.size(); j++)
mat_ns.accumulate(lfsv_p_n,i,lfsu_v_s,j, 0.5*phi_p_n[i] * (phi_v_s[j]*normal) * incomp_scaling * weight);
for(size_type j=0; j<lfsu_v_n.size(); j++)
mat_nn.accumulate(lfsv_p_n,i,lfsu_v_n,j, -0.5*phi_p_n[i] * (phi_v_n[j]*normal) * incomp_scaling * weight);
}
} // end loop quadrature points
} // end jacobian_skeleton
// boundary term
template<typename IG, typename LFSU, typename X, typename LFSV, typename R>
void alpha_boundary (const IG& ig,
const LFSU& lfsu, const X& x, const LFSV& lfsv,
R& r) const
{
// dimensions
const unsigned int dim = IG::dimension;
const unsigned int dimw = IG::coorddimension;
// subspaces
using namespace Indices;
using LFSV_V = TypeTree::Child<LFSV,_0>;
const auto& lfsv_v = child(lfsv,_0);
const auto& lfsu_v = child(lfsu,_0);
using LFSV_P = TypeTree::Child<LFSV,_1>;
const auto& lfsv_p = child(lfsv,_1);
const auto& lfsu_p = child(lfsu,_1);
// domain and range field type
using FESwitch_V = FiniteElementInterfaceSwitch<typename LFSV_V::Traits::FiniteElementType >;
using BasisSwitch_V = BasisInterfaceSwitch<typename FESwitch_V::Basis >;
using VectorBasisSwitch_V = VectorBasisInterfaceSwitch<typename FESwitch_V::Basis >;
using FESwitch_P = FiniteElementInterfaceSwitch<typename LFSV_P::Traits::FiniteElementType >;
using BasisSwitch_P = BasisInterfaceSwitch<typename FESwitch_P::Basis >;
using DF = typename BasisSwitch_V::DomainField;
using RF = typename BasisSwitch_V::RangeField;
using Range_V = typename BasisSwitch_V::Range;
using Range_P = typename BasisSwitch_P::Range;
using size_type = typename LFSV::Traits::SizeType;
// References to inside cell
const auto& cell_inside = ig.inside();
// Get geometries
auto geo = ig.geometry();
auto geo_inside = cell_inside.geometry();
// Get geometry of intersection in local coordinates of cell_inside
auto geo_in_inside = ig.geometryInInside();
// Determine quadrature order
const int v_order = FESwitch_V::basis(lfsv_v.finiteElement()).order();
const int det_jac_order = geo.type().isSimplex() ? 0 : (dim-1);
const int qorder = 2*v_order + det_jac_order + superintegration_order;
auto epsilon = prm.epsilonIPSymmetryFactor();
auto incomp_scaling = prm.incompressibilityScaling(current_dt);
auto penalty_factor = prm.getFaceIP(geo,geo_inside);
// loop over quadrature points and integrate normal flux
for (const auto& ip : quadratureRule(geo,qorder))
{
// position of quadrature point in local coordinates of element
auto local = geo_in_inside.global(ip.position());
// values of velocity shape functions
std::vector<Range_V> phi_v(lfsv_v.size());
FESwitch_V::basis(lfsv_v.finiteElement()).evaluateFunction(local,phi_v);
// values of pressure shape functions
std::vector<Range_P> phi_p(lfsv_p.size());
FESwitch_P::basis(lfsv_p.finiteElement()).evaluateFunction(local,phi_p);
// evaluate jacobian of basis functions on reference element
std::vector<Dune::FieldMatrix<RF,dim,dim> > jac_phi_v(lfsu_v.size());
VectorBasisSwitch_V::jacobian
(FESwitch_V::basis(lfsv_v.finiteElement()), geo_inside, local, jac_phi_v);
// compute pressure value
Range_P val_p(0.0);
for (size_type i=0; i<lfsu_p.size(); i++)
val_p.axpy(x(lfsu_p,i),phi_p[i]);
// compute u and velocity jacobian
Range_V val_u(0.0);
Dune::FieldMatrix<RF,dim,dim> jac_u(0.0);
for (size_type i=0; i<lfsu_v.size(); i++){
val_u.axpy(x(lfsu_v,i),phi_v[i]);
jac_u.axpy(x(lfsu_v,i),jac_phi_v[i]);
}
auto normal = ig.unitOuterNormal(ip.position());
auto weight = ip.weight()*geo.integrationElement(ip.position());
auto mu = prm.mu(ig,ip.position());
// evaluate boundary condition type
auto bctype(prm.bctype(ig,ip.position()));
if (bctype == BC::VelocityDirichlet) {
// compute jump relative to Dirichlet value
auto u0(prm.g(cell_inside,local));
auto jump = val_u - u0;
// compute flux of velocity jacobian
Dune::FieldVector<DF,dimw> flux_jac_u(0.0);
add_compute_flux(jac_u,normal,flux_jac_u);
for (size_t i=0; i<lfsv_v.size(); i++) {
//================================================//
// diffusion term
//================================================//
r.accumulate(lfsv_v,i, -mu * (flux_jac_u * phi_v[i]) * weight);
//================================================//
// (non-)symmetric IP term
//================================================//
Dune::FieldVector<DF,dimw> flux_jac_phi(0.0);
add_compute_flux(jac_phi_v[i],normal,flux_jac_phi);
r.accumulate(lfsv_v,i, mu * epsilon * (flux_jac_phi*jump) * weight);
//================================================//
// standard IP term integral
//================================================//
r.accumulate(lfsv_v,i, mu * (jump*phi_v[i]) * penalty_factor * weight);
//================================================//
// pressure-velocity-coupling in momentum equation
//================================================//
r.accumulate(lfsv_v,i, val_p * (phi_v[i]*normal) * weight);
} // end i
//================================================//
// incompressibility constraint
//================================================//
for(size_type i=0; i<lfsv_p.size(); i++) {
r.accumulate(lfsv_p,i, phi_p[i] * (jump*normal) * incomp_scaling * weight);
}
} // Velocity Dirichlet
if (bctype == BC::StressNeumann) {
auto stress(prm.j(ig,ip.position(),normal));
for(size_type i=0; i<lfsv_v.size(); i++) {
r.accumulate(lfsv_v,i, (stress*phi_v[i]) * weight);
}
} // Pressure Dirichlet
} // end loop quadrature points
} // end alpha_boundary
// jacobian of boundary term
template<typename IG, typename LFSU, typename X, typename LFSV,
typename LocalMatrix>
void jacobian_boundary (const IG& ig,
const LFSU& lfsu, const X& x, const LFSV& lfsv,
LocalMatrix& mat) const
{
// dimensions
const unsigned int dim = IG::dimension;
const unsigned int dimw = IG::coorddimension;
// subspaces
using namespace Indices;
using LFSV_V = TypeTree::Child<LFSV,_0>;
const auto& lfsv_v = child(lfsv,_0);
const auto& lfsu_v = child(lfsu,_0);
using LFSV_P = TypeTree::Child<LFSV,_1>;
const auto& lfsv_p = child(lfsv,_1);
const auto& lfsu_p = child(lfsu,_1);
// domain and range field type
using FESwitch_V = FiniteElementInterfaceSwitch<typename LFSV_V::Traits::FiniteElementType >;
using BasisSwitch_V = BasisInterfaceSwitch<typename FESwitch_V::Basis >;
using VectorBasisSwitch_V = VectorBasisInterfaceSwitch<typename FESwitch_V::Basis >;
using FESwitch_P = FiniteElementInterfaceSwitch<typename LFSV_P::Traits::FiniteElementType >;
using BasisSwitch_P = BasisInterfaceSwitch<typename FESwitch_P::Basis >;
using DF = typename BasisSwitch_V::DomainField;
using RF = typename BasisSwitch_V::RangeField;
using Range_V = typename BasisSwitch_V::Range;
using Range_P = typename BasisSwitch_P::Range;
using size_type = typename LFSV::Traits::SizeType;
// References to inside cell
const auto& cell_inside = ig.inside();
// Get geometries
auto geo = ig.geometry();
auto geo_inside = cell_inside.geometry();
// Get geometry of intersection in local coordinates of cell_inside
auto geo_in_inside = ig.geometryInInside();
// Determine quadrature order
const int v_order = FESwitch_V::basis(lfsv_v.finiteElement()).order();
const int det_jac_order = geo.type().isSimplex() ? 0 : (dim-1);
const int qorder = 2*v_order + det_jac_order + superintegration_order;
auto epsilon = prm.epsilonIPSymmetryFactor();
auto incomp_scaling = prm.incompressibilityScaling(current_dt);
auto penalty_factor = prm.getFaceIP(geo,geo_inside);
// loop over quadrature points and integrate normal flux
for (const auto& ip : quadratureRule(geo,qorder))
{
// position of quadrature point in local coordinates of element
auto local = geo_in_inside.global(ip.position());
// values of velocity shape functions
std::vector<Range_V> phi_v(lfsv_v.size());
FESwitch_V::basis(lfsv_v.finiteElement()).evaluateFunction(local,phi_v);
// values of pressure shape functions
std::vector<Range_P> phi_p(lfsv_p.size());
FESwitch_P::basis(lfsv_p.finiteElement()).evaluateFunction(local,phi_p);
// evaluate jacobian of basis functions on reference element
std::vector<Dune::FieldMatrix<RF,dim,dim> > jac_phi_v(lfsu_v.size());
VectorBasisSwitch_V::jacobian
(FESwitch_V::basis(lfsv_v.finiteElement()), geo_inside, local, jac_phi_v);
auto normal = ig.unitOuterNormal(ip.position());
auto weight = ip.weight()*geo.integrationElement(ip.position());
auto mu = prm.mu(ig,ip.position());
// evaluate boundary condition type
auto bctype(prm.bctype(ig,ip.position()));
if (bctype == BC::VelocityDirichlet) {
for(size_type i=0; i<lfsv_v.size(); i++) {
// compute flux
Dune::FieldVector<DF,dimw> flux_jac_phi_i(0.0);
add_compute_flux(jac_phi_v[i],normal,flux_jac_phi_i);
for(size_type j=0; j<lfsu_v.size(); j++) {
//================================================//
// diffusion term
// (non-)symmetric IP term
//================================================//
Dune::FieldVector<DF,dimw> flux_jac_phi_j(0.0);
add_compute_flux(jac_phi_v[j],normal,flux_jac_phi_j);
mat.accumulate(lfsv_v,i,lfsu_v,j, -mu * (flux_jac_phi_j*phi_v[i]) * weight);
mat.accumulate(lfsv_v,i,lfsu_v,j, mu * epsilon * (flux_jac_phi_i*phi_v[j]) *weight);
//================================================//
// standard IP term integral
//================================================//
mat.accumulate(lfsv_v,i,lfsu_v,j, mu * (phi_v[j]*phi_v[i]) * penalty_factor * weight);
}
//================================================//
// pressure-velocity-coupling in momentum equation
//================================================//
for(size_type j=0; j<lfsu_p.size(); j++) {
mat.accumulate(lfsv_v,i,lfsu_p,j, phi_p[j] * (phi_v[i]*normal) * weight);
}
} // end i
//================================================//
// incompressibility constraint
//================================================//
for(size_type i=0; i<lfsv_p.size(); i++) {
for(size_type j=0; j<lfsu_v.size(); j++) {
mat.accumulate(lfsv_p,i,lfsu_v,j, phi_p[i] * (phi_v[j]*normal) * incomp_scaling * weight);
}
}
} // Velocity Dirichlet
} // end loop quadrature points
} // end jacobian_boundary
// volume integral depending only on test functions,
// contains f on the right hand side
template<typename EG, typename LFSV, typename R>
void lambda_volume (const EG& eg, const LFSV& lfsv, R& r) const
{
const unsigned int dim = EG::Geometry::mydimension;
// subspaces
using namespace Indices;
using LFSV_V = TypeTree::Child<LFSV,_0>;
const auto& lfsv_v = child(lfsv,_0);
// domain and range field type
using FESwitch_V = FiniteElementInterfaceSwitch<typename LFSV_V::Traits::FiniteElementType >;
using BasisSwitch_V = BasisInterfaceSwitch<typename FESwitch_V::Basis >;
using Range_V = typename BasisSwitch_V::Range;
using size_type = typename LFSV::Traits::SizeType;
// Get cell
const auto& cell = eg.entity();
// Get geometries
auto geo = eg.geometry();
// Determine quadrature order
const int v_order = FESwitch_V::basis(lfsv_v.finiteElement()).order();
const int det_jac_order = geo.type().isSimplex() ? 0 : (dim-1);
const int qorder = 2*v_order + det_jac_order + superintegration_order;
// loop over quadrature points
for (const auto& ip : quadratureRule(geo,qorder))
{
auto local = ip.position();
//const Dune::FieldVector<DF,dimw> global = eg.geometry().global(local);
// values of velocity shape functions
std::vector<Range_V> phi_v(lfsv_v.size());
FESwitch_V::basis(lfsv_v.finiteElement()).evaluateFunction(local,phi_v);
auto weight = ip.weight() * geo.integrationElement(ip.position());
// evaluate source term
auto fval(prm.f(cell,local));
//================================================//
// \int (f*v)
//================================================//
for(size_type i=0; i<lfsv_v.size(); i++)
r.accumulate(lfsv_v,i, -(fval*phi_v[i]) * weight);
} // end loop quadrature points
} // end lambda_volume
private :
template<class M, class RF>
static void contraction(const M & a, const M & b, RF & v)
{
v = 0;
const int an = a.N();
const int am = a.M();
for(int r=0; r<an; ++r)
for(int c=0; c<am; ++c)
v += a[r][c] * b[r][c];
}
template<class DU, class R>
static void add_compute_flux(const DU & du, const R & n, R & result)
{
const int N = du.N();
const int M = du.M();
for(int r=0; r<N; ++r)
for(int c=0; c<M; ++c)
result[r] += du[r][c] * n[c];
}
PRM& prm;
const int superintegration_order;
Real current_dt;
}; // end class DGNavierStokesVelVecFEM
} // end namespace PDELab
} // end namespace Dune
#endif // DUNE_PDELAB_LOCALOPERATOR_DGNAVIERSTOKESVELVECFEM_HH
|