/usr/include/deal.II/integrators/divergence.h is in libdeal.ii-dev 8.1.0-6ubuntu1.
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 | // ---------------------------------------------------------------------
// $Id: divergence.h 31932 2013-12-08 02:15:54Z heister $
//
// Copyright (C) 2010 - 2013 by the deal.II authors
//
// This file is part of the deal.II library.
//
// The deal.II library is free software; you can use it, redistribute
// it, and/or modify it under the terms of the GNU Lesser General
// Public License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
// The full text of the license can be found in the file LICENSE at
// the top level of the deal.II distribution.
//
// ---------------------------------------------------------------------
#ifndef __deal2__integrators_divergence_h
#define __deal2__integrators_divergence_h
#include <deal.II/base/config.h>
#include <deal.II/base/exceptions.h>
#include <deal.II/base/quadrature.h>
#include <deal.II/lac/full_matrix.h>
#include <deal.II/fe/mapping.h>
#include <deal.II/fe/fe_values.h>
#include <deal.II/meshworker/dof_info.h>
DEAL_II_NAMESPACE_OPEN
namespace LocalIntegrators
{
/**
* @brief Local integrators related to the divergence operator and its trace.
*
* @ingroup Integrators
* @author Guido Kanschat
* @date 2010
*/
namespace Divergence
{
/**
* Auxiliary function. Computes the grad-div-operator from a set of
* Hessians.
*
* @note The third tensor argument is not used in two dimensions and
* can for instance duplicate one of the previous.
*
* @author Guido Kanschat
* @date 2011
*/
template <int dim>
Tensor<1,dim>
grad_div(
const Tensor<2,dim> &h0,
const Tensor<2,dim> &h1,
const Tensor<2,dim> &h2)
{
Tensor<1,dim> result;
for (unsigned int d=0; d<dim; ++d)
{
result[d] += h0[d][0];
if (dim >=2) result[d] += h1[d][1];
if (dim >=3) result[d] += h2[d][2];
}
return result;
}
/**
* Cell matrix for divergence. The derivative is on the trial
* function.
* \f[
* \int_Z v\nabla \cdot \mathbf u \,dx
* \f]
* This is the strong divergence operator and the trial
* space should be at least <b>H</b><sup>div</sup>. The test functions
* may be discontinuous.
*
* @author Guido Kanschat
* @date 2011
*/
template <int dim>
void cell_matrix (
FullMatrix<double> &M,
const FEValuesBase<dim> &fe,
const FEValuesBase<dim> &fetest,
double factor = 1.)
{
unsigned int fecomp = fe.get_fe().n_components();
const unsigned int n_dofs = fe.dofs_per_cell;
const unsigned int t_dofs = fetest.dofs_per_cell;
AssertDimension(fecomp, dim);
AssertDimension(fetest.get_fe().n_components(), 1);
AssertDimension(M.m(), t_dofs);
AssertDimension(M.n(), n_dofs);
for (unsigned int k=0; k<fe.n_quadrature_points; ++k)
{
const double dx = fe.JxW(k) * factor;
for (unsigned int i=0; i<t_dofs; ++i)
{
const double vv = fetest.shape_value(i,k);
for (unsigned int d=0; d<dim; ++d)
for (unsigned int j=0; j<n_dofs; ++j)
{
const double du = fe.shape_grad_component(j,k,d)[d];
M(i,j) += dx * du * vv;
}
}
}
}
/**
* The residual of the divergence operator in strong form.
* \f[
* \int_Z v\nabla \cdot \mathbf u \,dx
* \f]
* This is the strong divergence operator and the trial
* space should be at least <b>H</b><sup>div</sup>. The test functions
* may be discontinuous.
*
* The function cell_matrix() is the Frechet derivative of this function with respect
* to the test functions.
*
* @author Guido Kanschat
* @date 2011
*/
template <int dim, typename number>
void cell_residual(
Vector<number> &result,
const FEValuesBase<dim> &fetest,
const VectorSlice<const std::vector<std::vector<Tensor<1,dim> > > > &input,
const double factor = 1.)
{
AssertDimension(fetest.get_fe().n_components(), 1);
AssertVectorVectorDimension(input, dim, fetest.n_quadrature_points);
const unsigned int t_dofs = fetest.dofs_per_cell;
Assert (result.size() == t_dofs, ExcDimensionMismatch(result.size(), t_dofs));
for (unsigned int k=0; k<fetest.n_quadrature_points; ++k)
{
const double dx = factor * fetest.JxW(k);
for (unsigned int i=0; i<t_dofs; ++i)
for (unsigned int d=0; d<dim; ++d)
result(i) += dx * input[d][k][d] * fetest.shape_value(i,k);
}
}
/**
* The residual of the divergence operator in weak form.
* \f[
* - \int_Z \nabla v \cdot \mathbf u \,dx
* \f]
* This is the weak divergence operator and the test
* space should be at least <b>H</b><sup>1</sup>. The trial functions
* may be discontinuous.
*
* @todo Verify: The function cell_matrix() is the Frechet derivative of this function with respect
* to the test functions.
*
* @author Guido Kanschat
* @date 2013
*/
template <int dim, typename number>
void cell_residual(
Vector<number> &result,
const FEValuesBase<dim> &fetest,
const VectorSlice<const std::vector<std::vector<double> > > &input,
const double factor = 1.)
{
AssertDimension(fetest.get_fe().n_components(), 1);
AssertVectorVectorDimension(input, dim, fetest.n_quadrature_points);
const unsigned int t_dofs = fetest.dofs_per_cell;
Assert (result.size() == t_dofs, ExcDimensionMismatch(result.size(), t_dofs));
for (unsigned int k=0; k<fetest.n_quadrature_points; ++k)
{
const double dx = factor * fetest.JxW(k);
for (unsigned int i=0; i<t_dofs; ++i)
for (unsigned int d=0; d<dim; ++d)
result(i) -= dx * input[d][k] * fetest.shape_grad(i,k)[d];
}
}
/**
* Cell matrix for gradient. The derivative is on the trial function.
* \f[
* \int_Z \nabla u \cdot \mathbf v\,dx
* \f]
*
* This is the strong gradient and the trial space should be at least
* in <i>H</i><sup>1</sup>. The test functions can be discontinuous.
*
* @author Guido Kanschat
* @date 2011
*/
template <int dim>
void gradient_matrix(
FullMatrix<double> &M,
const FEValuesBase<dim> &fe,
const FEValuesBase<dim> &fetest,
double factor = 1.)
{
unsigned int fecomp = fetest.get_fe().n_components();
const unsigned int t_dofs = fetest.dofs_per_cell;
const unsigned int n_dofs = fe.dofs_per_cell;
AssertDimension(fecomp, dim);
AssertDimension(fe.get_fe().n_components(), 1);
AssertDimension(M.m(), t_dofs);
AssertDimension(M.n(), n_dofs);
for (unsigned int k=0; k<fe.n_quadrature_points; ++k)
{
const double dx = fe.JxW(k) * factor;
for (unsigned int d=0; d<dim; ++d)
for (unsigned int i=0; i<t_dofs; ++i)
{
const double vv = fetest.shape_value_component(i,k,d);
for (unsigned int j=0; j<n_dofs; ++j)
{
const Tensor<1,dim> &Du = fe.shape_grad(j,k);
M(i,j) += dx * vv * Du[d];
}
}
}
}
/**
* The residual of the gradient operator in strong form.
* \f[
* \int_Z \mathbf v\cdot\nabla u \,dx
* \f]
* This is the strong gradient operator and the trial
* space should be at least <b>H</b><sup>1</sup>. The test functions
* may be discontinuous.
*
* The function gradient_matrix() is the Frechet derivative of this function with respect to the test functions.
*
* @author Guido Kanschat
* @date 2011
*/
template <int dim, typename number>
void gradient_residual(
Vector<number> &result,
const FEValuesBase<dim> &fetest,
const std::vector<Tensor<1,dim> > &input,
const double factor = 1.)
{
AssertDimension(fetest.get_fe().n_components(), dim);
AssertDimension(input.size(), fetest.n_quadrature_points);
const unsigned int t_dofs = fetest.dofs_per_cell;
Assert (result.size() == t_dofs, ExcDimensionMismatch(result.size(), t_dofs));
for (unsigned int k=0; k<fetest.n_quadrature_points; ++k)
{
const double dx = factor * fetest.JxW(k);
for (unsigned int i=0; i<t_dofs; ++i)
for (unsigned int d=0; d<dim; ++d)
result(i) += dx * input[k][d] * fetest.shape_value_component(i,k,d);
}
}
/**
* The residual of the gradient operator in weak form.
* \f[
* -\int_Z \nabla\cdot \mathbf v u \,dx
* \f]
* This is the weak gradient operator and the test
* space should be at least <b>H</b><sup>div</sup>. The trial functions
* may be discontinuous.
*
* @todo Verify: The function gradient_matrix() is the Frechet derivative of this function with respect to the test functions.
*
* @author Guido Kanschat
* @date 2013
*/
template <int dim, typename number>
void gradient_residual(
Vector<number> &result,
const FEValuesBase<dim> &fetest,
const std::vector<double> &input,
const double factor = 1.)
{
AssertDimension(fetest.get_fe().n_components(), dim);
AssertDimension(input.size(), fetest.n_quadrature_points);
const unsigned int t_dofs = fetest.dofs_per_cell;
Assert (result.size() == t_dofs, ExcDimensionMismatch(result.size(), t_dofs));
for (unsigned int k=0; k<fetest.n_quadrature_points; ++k)
{
const double dx = factor * fetest.JxW(k);
for (unsigned int i=0; i<t_dofs; ++i)
for (unsigned int d=0; d<dim; ++d)
result(i) -= dx * input[k] * fetest.shape_grad_component(i,k,d)[d];
}
}
/**
* The trace of the divergence operator, namely the product of the
* normal component of the vector valued trial space and the test
* space.
* @f[ \int_F (\mathbf u\cdot \mathbf n) v \,ds @f]
*
* @author Guido Kanschat
* @date 2011
*/
template<int dim>
void
u_dot_n_matrix (
FullMatrix<double> &M,
const FEValuesBase<dim> &fe,
const FEValuesBase<dim> &fetest,
double factor = 1.)
{
unsigned int fecomp = fe.get_fe().n_components();
const unsigned int n_dofs = fe.dofs_per_cell;
const unsigned int t_dofs = fetest.dofs_per_cell;
AssertDimension(fecomp, dim);
AssertDimension(fetest.get_fe().n_components(), 1);
AssertDimension(M.m(), t_dofs);
AssertDimension(M.n(), n_dofs);
for (unsigned int k=0; k<fe.n_quadrature_points; ++k)
{
const Tensor<1,dim> ndx = factor * fe.JxW(k) * fe.normal_vector(k);
for (unsigned int i=0; i<t_dofs; ++i)
for (unsigned int j=0; j<n_dofs; ++j)
for (unsigned int d=0; d<dim; ++d)
M(i,j) += ndx[d] * fe.shape_value_component(j,k,d)
* fetest.shape_value(i,k);
}
}
/**
* The trace of the divergence
* operator, namely the product
* of the normal component of the
* vector valued trial space and
* the test space.
* @f[
* \int_F (\mathbf u\cdot \mathbf n) v \,ds
* @f]
*
* @author Guido Kanschat
* @date 2011
*/
template<int dim, typename number>
void
u_dot_n_residual (
Vector<number> &result,
const FEValuesBase<dim> &fe,
const FEValuesBase<dim> &fetest,
const VectorSlice<const std::vector<std::vector<double> > > &data,
double factor = 1.)
{
unsigned int fecomp = fe.get_fe().n_components();
const unsigned int t_dofs = fetest.dofs_per_cell;
AssertDimension(fecomp, dim);
AssertDimension(fetest.get_fe().n_components(), 1);
AssertDimension(result.size(), t_dofs);
AssertVectorVectorDimension (data, dim, fe.n_quadrature_points);
for (unsigned int k=0; k<fe.n_quadrature_points; ++k)
{
const Tensor<1,dim> ndx = factor * fe.normal_vector(k) * fe.JxW(k);
for (unsigned int i=0; i<t_dofs; ++i)
for (unsigned int d=0; d<dim; ++d)
result(i) += ndx[d] * fetest.shape_value(i,k) * data[d][k];
}
}
/**
* The trace of the gradient
* operator, namely the product
* of the normal component of the
* vector valued test space and
* the trial space.
* @f[
* \int_F u (\mathbf v\cdot \mathbf n) \,ds
* @f]
*
* @author Guido Kanschat
* @date 2013
*/
template<int dim, typename number>
void
u_times_n_residual (
Vector<number> &result,
const FEValuesBase<dim> &fetest,
const std::vector<double> &data,
double factor = 1.)
{
const unsigned int t_dofs = fetest.dofs_per_cell;
AssertDimension(fetest.get_fe().n_components(), dim);
AssertDimension(result.size(), t_dofs);
AssertDimension(data.size(), fetest.n_quadrature_points);
for (unsigned int k=0; k<fetest.n_quadrature_points; ++k)
{
const Tensor<1,dim> ndx = factor * fetest.normal_vector(k) * fetest.JxW(k);
for (unsigned int i=0; i<t_dofs; ++i)
for (unsigned int d=0; d<dim; ++d)
result(i) += ndx[d] * fetest.shape_value_component(i,k,d) * data[k];
}
}
/**
* The trace of the divergence
* operator, namely the product
* of the jump of the normal component of the
* vector valued trial function and
* the mean value of the test function.
* @f[
* \int_F (\mathbf u_1\cdot \mathbf n_1 + \mathbf u_2 \cdot \mathbf n_2) \frac{v_1+v_2}{2} \,ds
* @f]
*
* @author Guido Kanschat
* @date 2011
*/
template<int dim>
void
u_dot_n_matrix (
FullMatrix<double> &M11,
FullMatrix<double> &M12,
FullMatrix<double> &M21,
FullMatrix<double> &M22,
const FEValuesBase<dim> &fe1,
const FEValuesBase<dim> &fe2,
const FEValuesBase<dim> &fetest1,
const FEValuesBase<dim> &fetest2,
double factor = 1.)
{
const unsigned int n_dofs = fe1.dofs_per_cell;
const unsigned int t_dofs = fetest1.dofs_per_cell;
AssertDimension(fe1.get_fe().n_components(), dim);
AssertDimension(fe2.get_fe().n_components(), dim);
AssertDimension(fetest1.get_fe().n_components(), 1);
AssertDimension(fetest2.get_fe().n_components(), 1);
AssertDimension(M11.m(), t_dofs);
AssertDimension(M11.n(), n_dofs);
AssertDimension(M12.m(), t_dofs);
AssertDimension(M12.n(), n_dofs);
AssertDimension(M21.m(), t_dofs);
AssertDimension(M21.n(), n_dofs);
AssertDimension(M22.m(), t_dofs);
AssertDimension(M22.n(), n_dofs);
for (unsigned int k=0; k<fe1.n_quadrature_points; ++k)
{
const double dx = factor * fe1.JxW(k);
for (unsigned int i=0; i<t_dofs; ++i)
for (unsigned int j=0; j<n_dofs; ++j)
for (unsigned int d=0; d<dim; ++d)
{
const double un1 = fe1.shape_value_component(j,k,d) * fe1.normal_vector(k)[d];
const double un2 =-fe2.shape_value_component(j,k,d) * fe1.normal_vector(k)[d];
const double v1 = fetest1.shape_value(i,k);
const double v2 = fetest2.shape_value(i,k);
M11(i,j) += .5 * dx * un1 * v1;
M12(i,j) += .5 * dx * un2 * v1;
M21(i,j) += .5 * dx * un1 * v2;
M22(i,j) += .5 * dx * un2 * v2;
}
}
}
/**
* The weak form of the grad-div operator penalizing volume changes
* @f[
* \int_Z \nabla\!\cdot\!u \nabla\!\cdot\!v \,dx
* @f]
*
* @author Guido Kanschat
* @date 2011
*/
template <int dim>
void grad_div_matrix (
FullMatrix<double> &M,
const FEValuesBase<dim> &fe,
double factor = 1.)
{
const unsigned int n_dofs = fe.dofs_per_cell;
AssertDimension(fe.get_fe().n_components(), dim);
AssertDimension(M.m(), n_dofs);
AssertDimension(M.n(), n_dofs);
for (unsigned int k=0; k<fe.n_quadrature_points; ++k)
{
const double dx = factor * fe.JxW(k);
for (unsigned int i=0; i<n_dofs; ++i)
for (unsigned int j=0; j<n_dofs; ++j)
{
double dv = 0.;
double du = 0.;
for (unsigned int d=0; d<dim; ++d)
{
dv += fe.shape_grad_component(i,k,d)[d];
du += fe.shape_grad_component(j,k,d)[d];
}
M(i,j) += dx * du * dv;
}
}
}
/**
* The jump of the normal component
* @f[
* \int_F
* (\mathbf u_1\cdot \mathbf n_1 + \mathbf u_2 \cdot \mathbf n_2)
* (\mathbf v_1\cdot \mathbf n_1 + \mathbf v_2 \cdot \mathbf n_2)
* \,ds
* @f]
*
* @author Guido Kanschat
* @date 2011
*/
template<int dim>
void
u_dot_n_jump_matrix (
FullMatrix<double> &M11,
FullMatrix<double> &M12,
FullMatrix<double> &M21,
FullMatrix<double> &M22,
const FEValuesBase<dim> &fe1,
const FEValuesBase<dim> &fe2,
double factor = 1.)
{
const unsigned int n_dofs = fe1.dofs_per_cell;
AssertDimension(fe1.get_fe().n_components(), dim);
AssertDimension(fe2.get_fe().n_components(), dim);
AssertDimension(M11.m(), n_dofs);
AssertDimension(M11.n(), n_dofs);
AssertDimension(M12.m(), n_dofs);
AssertDimension(M12.n(), n_dofs);
AssertDimension(M21.m(), n_dofs);
AssertDimension(M21.n(), n_dofs);
AssertDimension(M22.m(), n_dofs);
AssertDimension(M22.n(), n_dofs);
for (unsigned int k=0; k<fe1.n_quadrature_points; ++k)
{
const double dx = factor * fe1.JxW(k);
for (unsigned int i=0; i<n_dofs; ++i)
for (unsigned int j=0; j<n_dofs; ++j)
for (unsigned int d=0; d<dim; ++d)
{
const double un1 = fe1.shape_value_component(j,k,d) * fe1.normal_vector(k)[d];
const double un2 =-fe2.shape_value_component(j,k,d) * fe1.normal_vector(k)[d];
const double vn1 = fe1.shape_value_component(i,k,d) * fe1.normal_vector(k)[d];
const double vn2 =-fe2.shape_value_component(i,k,d) * fe1.normal_vector(k)[d];
M11(i,j) += dx * un1 * vn1;
M12(i,j) += dx * un2 * vn1;
M21(i,j) += dx * un1 * vn2;
M22(i,j) += dx * un2 * vn2;
}
}
}
/**
* The <i>L</i><sup>2</sup>-norm of the divergence over the
* quadrature set determined by the FEValuesBase object.
*
* The vector is expected to consist of dim vectors of length
* equal to the number of quadrature points. The number of
* components of the finite element has to be equal to the space
* dimension.
*
* @author Guido Kanschat
* @date 2013
*/
template <int dim>
double norm(const FEValuesBase<dim> &fe,
const VectorSlice<const std::vector<std::vector<Tensor<1,dim> > > > &Du)
{
unsigned int fecomp = fe.get_fe().n_components();
AssertDimension(fecomp, dim);
AssertVectorVectorDimension (Du, dim, fe.n_quadrature_points);
double result = 0;
for (unsigned int k=0; k<fe.n_quadrature_points; ++k)
{
double div = Du[0][k][0];
for (unsigned int d=1; d<dim; ++d)
div += Du[d][k][d];
result += div*div*fe.JxW(k);
}
return result;
}
}
}
DEAL_II_NAMESPACE_CLOSE
#endif
|