| 1 |
// ------------------------------------------------------------------------ |
| 2 |
// |
| 3 |
// SPDX-License-Identifier: LGPL-2.1-or-later |
| 4 |
// Copyright (C) 2012 - 2024 by the deal.II authors |
| 5 |
// |
| 6 |
// This file is part of the deal.II library. |
| 7 |
// |
| 8 |
// Part of the source code is dual licensed under Apache-2.0 WITH |
| 9 |
// LLVM-exception OR LGPL-2.1-or-later. Detailed license information |
| 10 |
// governing the source code and code contributions can be found in |
| 11 |
// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II. |
| 12 |
// |
| 13 |
// ------------------------------------------------------------------------ |
| 14 |
|
| 15 |
#ifndef dealii_integrators_advection_h |
| 16 |
#define dealii_integrators_advection_h |
| 17 |
|
| 18 |
|
| 19 |
#include <deal.II/base/config.h> |
| 20 |
|
| 21 |
#include <deal.II/base/exceptions.h> |
| 22 |
#include <deal.II/base/quadrature.h> |
| 23 |
|
| 24 |
#include <deal.II/fe/fe_values.h> |
| 25 |
#include <deal.II/fe/mapping.h> |
| 26 |
|
| 27 |
#include <deal.II/lac/full_matrix.h> |
| 28 |
|
| 29 |
#include <deal.II/meshworker/dof_info.h> |
| 30 |
|
| 31 |
DEAL_II_NAMESPACE_OPEN |
| 32 |
|
| 33 |
namespace LocalIntegrators |
| 34 |
{ |
| 35 |
/** |
| 36 |
* @brief Local integrators related to advection along a vector field and |
| 37 |
* its DG formulations |
| 38 |
* |
| 39 |
* All advection operators depend on an advection velocity denoted by |
| 40 |
* <b>w</b> in the formulas below. It is denoted as <tt>velocity</tt> in the |
| 41 |
* parameter lists. |
| 42 |
* |
| 43 |
* The functions cell_matrix() and both upwind_value_matrix() are taking the |
| 44 |
* equation in weak form, that is, the directional derivative is on the test |
| 45 |
* function. |
| 46 |
* |
| 47 |
* @ingroup Integrators |
| 48 |
*/ |
| 49 |
namespace Advection |
| 50 |
{ |
| 51 |
/** |
| 52 |
* Advection along the direction <b>w</b> in weak form with derivative on |
| 53 |
* the test function \f[ m_{ij} = \int_Z u_j\,(\mathbf w \cdot \nabla) v_i |
| 54 |
* \, dx. \f] |
| 55 |
* |
| 56 |
* The FiniteElement in <tt>fe</tt> may be scalar or vector valued. In the |
| 57 |
* latter case, the advection operator is applied to each component |
| 58 |
* separately. |
| 59 |
* |
| 60 |
* @param M: The advection matrix obtained as result |
| 61 |
* @param fe: The FEValues object describing the local trial function |
| 62 |
* space. #update_values and #update_gradients, and #update_JxW_values |
| 63 |
* must be set. |
| 64 |
* @param fetest: The FEValues object describing the local test function |
| 65 |
* space. #update_values and #update_gradients must be set. |
| 66 |
* @param velocity: The advection velocity, a vector of dimension |
| 67 |
* <tt>dim</tt>. Each component may either contain a vector of length one, |
| 68 |
* in which case a constant velocity is assumed, or a vector with as many |
| 69 |
* entries as quadrature points if the velocity is not constant. |
| 70 |
* @param factor is an optional multiplication factor for the result. |
| 71 |
*/ |
| 72 |
template <int dim> |
| 73 |
DEAL_II_DEPRECATED void |
| 74 |
cell_matrix(FullMatrix<double> &M, |
| 75 |
const FEValuesBase<dim> &fe, |
| 76 |
const FEValuesBase<dim> &fetest, |
| 77 |
const ArrayView<const std::vector<double>> &velocity, |
| 78 |
const double factor = 1.) |
| 79 |
{ |
| 80 |
const unsigned int n_dofs = fe.dofs_per_cell; |
| 81 |
const unsigned int t_dofs = fetest.dofs_per_cell; |
| 82 |
const unsigned int n_components = fe.get_fe().n_components(); |
| 83 |
|
| 84 |
AssertDimension(velocity.size(), dim); |
| 85 |
// If the size of the |
| 86 |
// velocity vectors is one, |
| 87 |
// then do not increment |
| 88 |
// between quadrature points. |
| 89 |
const unsigned int v_increment = (velocity[0].size() == 1) ? 0 : 1; |
| 90 |
|
| 91 |
if (v_increment == 1) |
| 92 |
{ |
| 93 |
AssertVectorVectorDimension(velocity, dim, fe.n_quadrature_points); |
| 94 |
} |
| 95 |
|
| 96 |
AssertDimension(M.n(), n_dofs); |
| 97 |
AssertDimension(M.m(), t_dofs); |
| 98 |
|
| 99 |
for (unsigned k = 0; k < fe.n_quadrature_points; ++k) |
| 100 |
{ |
| 101 |
const double dx = factor * fe.JxW(k); |
| 102 |
const unsigned int vindex = k * v_increment; |
| 103 |
|
| 104 |
for (unsigned j = 0; j < n_dofs; ++j) |
| 105 |
for (unsigned i = 0; i < t_dofs; ++i) |
| 106 |
for (unsigned int c = 0; c < n_components; ++c) |
| 107 |
{ |
| 108 |
double wgradv = |
| 109 |
velocity[0][vindex] * fe.shape_grad_component(i, k, c)[0]; |
| 110 |
for (unsigned int d = 1; d < dim; ++d) |
| 111 |
wgradv += |
| 112 |
velocity[d][vindex] * fe.shape_grad_component(i, k, c)[d]; |
| 113 |
M(i, j) -= dx * wgradv * fe.shape_value_component(j, k, c); |
| 114 |
} |
| 115 |
} |
| 116 |
} |
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
/** |
| 121 |
* Scalar advection residual operator in strong form |
| 122 |
* |
| 123 |
* \f[ r_i = \int_Z (\mathbf w \cdot \nabla)u\, v_i \, dx. \f] |
| 124 |
* |
| 125 |
* \warning This is not the residual consistent with cell_matrix(), but |
| 126 |
* with its transpose. |
| 127 |
*/ |
| 128 |
template <int dim> |
| 129 |
DEAL_II_DEPRECATED inline void |
| 130 |
cell_residual(Vector<double> &result, |
| 131 |
const FEValuesBase<dim> &fe, |
| 132 |
const std::vector<Tensor<1, dim>> &input, |
| 133 |
const ArrayView<const std::vector<double>> &velocity, |
| 134 |
double factor = 1.) |
| 135 |
{ |
| 136 |
const unsigned int nq = fe.n_quadrature_points; |
| 137 |
const unsigned int n_dofs = fe.dofs_per_cell; |
| 138 |
Assert(input.size() == nq, ExcDimensionMismatch(input.size(), nq)); |
| 139 |
Assert(result.size() == n_dofs, |
| 140 |
ExcDimensionMismatch(result.size(), n_dofs)); |
| 141 |
|
| 142 |
AssertDimension(velocity.size(), dim); |
| 143 |
const unsigned int v_increment = (velocity[0].size() == 1) ? 0 : 1; |
| 144 |
if (v_increment == 1) |
| 145 |
{ |
| 146 |
AssertVectorVectorDimension(velocity, dim, fe.n_quadrature_points); |
| 147 |
} |
| 148 |
|
| 149 |
for (unsigned k = 0; k < nq; ++k) |
| 150 |
{ |
| 151 |
const double dx = factor * fe.JxW(k); |
| 152 |
for (unsigned i = 0; i < n_dofs; ++i) |
| 153 |
for (unsigned int d = 0; d < dim; ++d) |
| 154 |
result(i) += dx * input[k][d] * fe.shape_value(i, k) * |
| 155 |
velocity[d][k * v_increment]; |
| 156 |
} |
| 157 |
} |
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
/** |
| 162 |
* Vector-valued advection residual operator in strong form |
| 163 |
* |
| 164 |
* |
| 165 |
* \f[ r_i = \int_Z \bigl((\mathbf w \cdot \nabla) \mathbf u\bigr) |
| 166 |
* \cdot\mathbf v_i \, dx. \f] |
| 167 |
* |
| 168 |
* \warning This is not the residual consistent with cell_matrix(), but |
| 169 |
* with its transpose. |
| 170 |
*/ |
| 171 |
template <int dim> |
| 172 |
DEAL_II_DEPRECATED inline void |
| 173 |
cell_residual(Vector<double> &result, |
| 174 |
const FEValuesBase<dim> &fe, |
| 175 |
const ArrayView<const std::vector<Tensor<1, dim>>> &input, |
| 176 |
const ArrayView<const std::vector<double>> &velocity, |
| 177 |
double factor = 1.) |
| 178 |
{ |
| 179 |
const unsigned int nq = fe.n_quadrature_points; |
| 180 |
const unsigned int n_dofs = fe.dofs_per_cell; |
| 181 |
const unsigned int n_comp = fe.get_fe().n_components(); |
| 182 |
|
| 183 |
AssertVectorVectorDimension(input, n_comp, fe.n_quadrature_points); |
| 184 |
Assert(result.size() == n_dofs, |
| 185 |
ExcDimensionMismatch(result.size(), n_dofs)); |
| 186 |
|
| 187 |
AssertDimension(velocity.size(), dim); |
| 188 |
const unsigned int v_increment = (velocity[0].size() == 1) ? 0 : 1; |
| 189 |
if (v_increment == 1) |
| 190 |
{ |
| 191 |
AssertVectorVectorDimension(velocity, dim, fe.n_quadrature_points); |
| 192 |
} |
| 193 |
|
| 194 |
for (unsigned k = 0; k < nq; ++k) |
| 195 |
{ |
| 196 |
const double dx = factor * fe.JxW(k); |
| 197 |
for (unsigned i = 0; i < n_dofs; ++i) |
| 198 |
for (unsigned int c = 0; c < n_comp; ++c) |
| 199 |
for (unsigned int d = 0; d < dim; ++d) |
| 200 |
result(i) += dx * input[c][k][d] * |
| 201 |
fe.shape_value_component(i, k, c) * |
| 202 |
velocity[d][k * v_increment]; |
| 203 |
} |
| 204 |
} |
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
/** |
| 209 |
* Scalar advection residual operator in weak form |
| 210 |
* |
| 211 |
* \f[ r_i = \int_Z (\mathbf w \cdot \nabla)v\, u_i \, dx. \f] |
| 212 |
*/ |
| 213 |
template <int dim> |
| 214 |
DEAL_II_DEPRECATED inline void |
| 215 |
cell_residual(Vector<double> &result, |
| 216 |
const FEValuesBase<dim> &fe, |
| 217 |
const std::vector<double> &input, |
| 218 |
const ArrayView<const std::vector<double>> &velocity, |
| 219 |
double factor = 1.) |
| 220 |
{ |
| 221 |
const unsigned int nq = fe.n_quadrature_points; |
| 222 |
const unsigned int n_dofs = fe.dofs_per_cell; |
| 223 |
Assert(input.size() == nq, ExcDimensionMismatch(input.size(), nq)); |
| 224 |
Assert(result.size() == n_dofs, |
| 225 |
ExcDimensionMismatch(result.size(), n_dofs)); |
| 226 |
|
| 227 |
AssertDimension(velocity.size(), dim); |
| 228 |
const unsigned int v_increment = (velocity[0].size() == 1) ? 0 : 1; |
| 229 |
if (v_increment == 1) |
| 230 |
{ |
| 231 |
AssertVectorVectorDimension(velocity, dim, fe.n_quadrature_points); |
| 232 |
} |
| 233 |
|
| 234 |
for (unsigned k = 0; k < nq; ++k) |
| 235 |
{ |
| 236 |
const double dx = factor * fe.JxW(k); |
| 237 |
for (unsigned i = 0; i < n_dofs; ++i) |
| 238 |
for (unsigned int d = 0; d < dim; ++d) |
| 239 |
result(i) -= dx * input[k] * fe.shape_grad(i, k)[d] * |
| 240 |
velocity[d][k * v_increment]; |
| 241 |
} |
| 242 |
} |
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
/** |
| 247 |
* Vector-valued advection residual operator in weak form |
| 248 |
* |
| 249 |
* |
| 250 |
* \f[ r_i = \int_Z \bigl((\mathbf w \cdot \nabla) \mathbf v\bigr) |
| 251 |
* \cdot\mathbf u_i \, dx. \f] |
| 252 |
*/ |
| 253 |
template <int dim> |
| 254 |
DEAL_II_DEPRECATED inline void |
| 255 |
cell_residual(Vector<double> &result, |
| 256 |
const FEValuesBase<dim> &fe, |
| 257 |
const ArrayView<const std::vector<double>> &input, |
| 258 |
const ArrayView<const std::vector<double>> &velocity, |
| 259 |
double factor = 1.) |
| 260 |
{ |
| 261 |
const unsigned int nq = fe.n_quadrature_points; |
| 262 |
const unsigned int n_dofs = fe.dofs_per_cell; |
| 263 |
const unsigned int n_comp = fe.get_fe().n_components(); |
| 264 |
|
| 265 |
AssertVectorVectorDimension(input, n_comp, fe.n_quadrature_points); |
| 266 |
Assert(result.size() == n_dofs, |
| 267 |
ExcDimensionMismatch(result.size(), n_dofs)); |
| 268 |
|
| 269 |
AssertDimension(velocity.size(), dim); |
| 270 |
const unsigned int v_increment = (velocity[0].size() == 1) ? 0 : 1; |
| 271 |
if (v_increment == 1) |
| 272 |
{ |
| 273 |
AssertVectorVectorDimension(velocity, dim, fe.n_quadrature_points); |
| 274 |
} |
| 275 |
|
| 276 |
for (unsigned k = 0; k < nq; ++k) |
| 277 |
{ |
| 278 |
const double dx = factor * fe.JxW(k); |
| 279 |
for (unsigned i = 0; i < n_dofs; ++i) |
| 280 |
for (unsigned int c = 0; c < n_comp; ++c) |
| 281 |
for (unsigned int d = 0; d < dim; ++d) |
| 282 |
result(i) -= dx * input[c][k] * |
| 283 |
fe.shape_grad_component(i, k, c)[d] * |
| 284 |
velocity[d][k * v_increment]; |
| 285 |
} |
| 286 |
} |
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
/** |
| 291 |
* Upwind flux at the boundary for weak advection operator. This is the |
| 292 |
* value of the trial function at the outflow boundary and zero else: |
| 293 |
* @f[ |
| 294 |
* a_{ij} = \int_{\partial\Omega} |
| 295 |
* [\mathbf w\cdot\mathbf n]_+ |
| 296 |
* u_i v_j \, ds |
| 297 |
* @f] |
| 298 |
* |
| 299 |
* The <tt>velocity</tt> is provided as an ArrayView, having <tt>dim</tt> |
| 300 |
* vectors, one for each velocity component. Each of the vectors must |
| 301 |
* either have only a single entry, if the advection velocity is constant, |
| 302 |
* or have an entry for each quadrature point. |
| 303 |
* |
| 304 |
* The finite element can have several components, in which case each |
| 305 |
* component is advected by the same velocity. |
| 306 |
*/ |
| 307 |
template <int dim> |
| 308 |
DEAL_II_DEPRECATED void |
| 309 |
upwind_value_matrix(FullMatrix<double> &M, |
| 310 |
const FEValuesBase<dim> &fe, |
| 311 |
const FEValuesBase<dim> &fetest, |
| 312 |
const ArrayView<const std::vector<double>> &velocity, |
| 313 |
double factor = 1.) |
| 314 |
{ |
| 315 |
const unsigned int n_dofs = fe.dofs_per_cell; |
| 316 |
const unsigned int t_dofs = fetest.dofs_per_cell; |
| 317 |
unsigned int n_components = fe.get_fe().n_components(); |
| 318 |
AssertDimension(M.m(), n_dofs); |
| 319 |
AssertDimension(M.n(), n_dofs); |
| 320 |
|
| 321 |
AssertDimension(velocity.size(), dim); |
| 322 |
const unsigned int v_increment = (velocity[0].size() == 1) ? 0 : 1; |
| 323 |
if (v_increment == 1) |
| 324 |
{ |
| 325 |
AssertVectorVectorDimension(velocity, dim, fe.n_quadrature_points); |
| 326 |
} |
| 327 |
|
| 328 |
for (unsigned k = 0; k < fe.n_quadrature_points; ++k) |
| 329 |
{ |
| 330 |
const double dx = factor * fe.JxW(k); |
| 331 |
|
| 332 |
double nv = 0.; |
| 333 |
for (unsigned int d = 0; d < dim; ++d) |
| 334 |
nv += fe.normal_vector(k)[d] * velocity[d][k * v_increment]; |
| 335 |
|
| 336 |
if (nv > 0) |
| 337 |
{ |
| 338 |
for (unsigned i = 0; i < t_dofs; ++i) |
| 339 |
for (unsigned j = 0; j < n_dofs; ++j) |
| 340 |
{ |
| 341 |
if (fe.get_fe().is_primitive()) |
| 342 |
M(i, j) += |
| 343 |
dx * nv * fe.shape_value(i, k) * fe.shape_value(j, k); |
| 344 |
else |
| 345 |
for (unsigned int c = 0; c < n_components; ++c) |
| 346 |
M(i, j) += dx * nv * |
| 347 |
fetest.shape_value_component(i, k, c) * |
| 348 |
fe.shape_value_component(j, k, c); |
| 349 |
} |
| 350 |
} |
| 351 |
} |
| 352 |
} |
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
/** |
| 357 |
* Scalar case: Residual for upwind flux at the boundary for weak |
| 358 |
* advection operator. This is the value of the trial function at the |
| 359 |
* outflow boundary and the value of the incoming boundary condition on |
| 360 |
* the inflow boundary: |
| 361 |
* @f[ |
| 362 |
* a_{ij} = \int_{\partial\Omega} |
| 363 |
* (\mathbf w\cdot\mathbf n) |
| 364 |
* \widehat u v_j \, ds |
| 365 |
* @f] |
| 366 |
* |
| 367 |
* Here, the numerical flux $\widehat u$ is the upwind value at the face, |
| 368 |
* namely the finite element function whose values are given in the |
| 369 |
* argument `input` on the outflow boundary. On the inflow boundary, it is |
| 370 |
* the inhomogeneous boundary value in the argument `data`. |
| 371 |
* |
| 372 |
* The <tt>velocity</tt> is provided as an ArrayView, having <tt>dim</tt> |
| 373 |
* vectors, one for each velocity component. Each of the vectors must |
| 374 |
* either have only a single entry, if the advection velocity is constant, |
| 375 |
* or have an entry for each quadrature point. |
| 376 |
* |
| 377 |
* The finite element can have several components, in which case each |
| 378 |
* component is advected by the same velocity. |
| 379 |
*/ |
| 380 |
template <int dim> |
| 381 |
DEAL_II_DEPRECATED inline void |
| 382 |
upwind_value_residual(Vector<double> &result, |
| 383 |
const FEValuesBase<dim> &fe, |
| 384 |
const std::vector<double> &input, |
| 385 |
const std::vector<double> &data, |
| 386 |
const ArrayView<const std::vector<double>> &velocity, |
| 387 |
double factor = 1.) |
| 388 |
{ |
| 389 |
const unsigned int n_dofs = fe.dofs_per_cell; |
| 390 |
|
| 391 |
AssertDimension(input.size(), fe.n_quadrature_points); |
| 392 |
AssertDimension(data.size(), fe.n_quadrature_points); |
| 393 |
|
| 394 |
AssertDimension(velocity.size(), dim); |
| 395 |
const unsigned int v_increment = (velocity[0].size() == 1) ? 0 : 1; |
| 396 |
if (v_increment == 1) |
| 397 |
{ |
| 398 |
AssertVectorVectorDimension(velocity, dim, fe.n_quadrature_points); |
| 399 |
} |
| 400 |
|
| 401 |
|
| 402 |
for (unsigned k = 0; k < fe.n_quadrature_points; ++k) |
| 403 |
{ |
| 404 |
const double dx = factor * fe.JxW(k); |
| 405 |
|
| 406 |
double nv = 0.; |
| 407 |
for (unsigned int d = 0; d < dim; ++d) |
| 408 |
nv += fe.normal_vector(k)[d] * velocity[d][k * v_increment]; |
| 409 |
|
| 410 |
// Always use the upwind value |
| 411 |
const double val = (nv > 0.) ? input[k] : -data[k]; |
| 412 |
|
| 413 |
for (unsigned i = 0; i < n_dofs; ++i) |
| 414 |
{ |
| 415 |
const double v = fe.shape_value(i, k); |
| 416 |
result(i) += dx * nv * val * v; |
| 417 |
} |
| 418 |
} |
| 419 |
} |
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
/** |
| 424 |
* Vector-valued case: Residual for upwind flux at the boundary for weak |
| 425 |
* advection operator. This is the value of the trial function at the |
| 426 |
* outflow boundary and the value of the incoming boundary condition on |
| 427 |
* the inflow boundary: |
| 428 |
* @f[ |
| 429 |
* a_{ij} = \int_{\partial\Omega} |
| 430 |
* (\mathbf w\cdot\mathbf n) |
| 431 |
* \widehat u v_j \, ds |
| 432 |
* @f] |
| 433 |
* |
| 434 |
* Here, the numerical flux $\widehat u$ is the upwind value at the face, |
| 435 |
* namely the finite element function whose values are given in the |
| 436 |
* argument `input` on the outflow boundary. On the inflow boundary, it is |
| 437 |
* the inhomogeneous boundary value in the argument `data`. |
| 438 |
* |
| 439 |
* The <tt>velocity</tt> is provided as an ArrayView, having <tt>dim</tt> |
| 440 |
* vectors, one for each velocity component. Each of the vectors must |
| 441 |
* either have only a single entry, if the advection velocity is constant, |
| 442 |
* or have an entry for each quadrature point. |
| 443 |
* |
| 444 |
* The finite element can have several components, in which case each |
| 445 |
* component is advected by the same velocity. |
| 446 |
*/ |
| 447 |
template <int dim> |
| 448 |
DEAL_II_DEPRECATED inline void |
| 449 |
upwind_value_residual(Vector<double> &result, |
| 450 |
const FEValuesBase<dim> &fe, |
| 451 |
const ArrayView<const std::vector<double>> &input, |
| 452 |
const ArrayView<const std::vector<double>> &data, |
| 453 |
const ArrayView<const std::vector<double>> &velocity, |
| 454 |
double factor = 1.) |
| 455 |
{ |
| 456 |
const unsigned int n_dofs = fe.dofs_per_cell; |
| 457 |
const unsigned int n_comp = fe.get_fe().n_components(); |
| 458 |
|
| 459 |
AssertVectorVectorDimension(input, n_comp, fe.n_quadrature_points); |
| 460 |
AssertVectorVectorDimension(data, n_comp, fe.n_quadrature_points); |
| 461 |
|
| 462 |
AssertDimension(velocity.size(), dim); |
| 463 |
const unsigned int v_increment = (velocity[0].size() == 1) ? 0 : 1; |
| 464 |
if (v_increment == 1) |
| 465 |
{ |
| 466 |
AssertVectorVectorDimension(velocity, dim, fe.n_quadrature_points); |
| 467 |
} |
| 468 |
|
| 469 |
|
| 470 |
for (unsigned k = 0; k < fe.n_quadrature_points; ++k) |
| 471 |
{ |
| 472 |
const double dx = factor * fe.JxW(k); |
| 473 |
|
| 474 |
double nv = 0.; |
| 475 |
for (unsigned int d = 0; d < dim; ++d) |
| 476 |
nv += fe.normal_vector(k)[d] * velocity[d][k * v_increment]; |
| 477 |
|
| 478 |
std::vector<double> val(n_comp); |
| 479 |
|
| 480 |
for (unsigned int d = 0; d < n_comp; ++d) |
| 481 |
{ |
| 482 |
val[d] = (nv > 0.) ? input[d][k] : -data[d][k]; |
| 483 |
for (unsigned i = 0; i < n_dofs; ++i) |
| 484 |
{ |
| 485 |
const double v = fe.shape_value_component(i, k, d); |
| 486 |
result(i) += dx * nv * val[d] * v; |
| 487 |
} |
| 488 |
} |
| 489 |
} |
| 490 |
} |
| 491 |
|
| 492 |
|
| 493 |
|
| 494 |
/** |
| 495 |
* Upwind flux in the interior for weak advection operator. Matrix entries |
| 496 |
* correspond to the upwind value of the trial function, multiplied by the |
| 497 |
* jump of the test functions |
| 498 |
* @f[ |
| 499 |
* a_{ij} = \int_F \left|\mathbf w |
| 500 |
* \cdot \mathbf n\right| |
| 501 |
* u^\uparrow |
| 502 |
* (v^\uparrow-v^\downarrow) |
| 503 |
* \,ds |
| 504 |
* @f] |
| 505 |
* |
| 506 |
* The <tt>velocity</tt> is provided as an ArrayView, having <tt>dim</tt> |
| 507 |
* vectors, one for each velocity component. Each of the vectors must |
| 508 |
* either have only a single entry, if the advection velocity is constant, |
| 509 |
* or have an entry for each quadrature point. |
| 510 |
* |
| 511 |
* The finite element can have several components, in which case each |
| 512 |
* component is advected the same way. |
| 513 |
*/ |
| 514 |
template <int dim> |
| 515 |
DEAL_II_DEPRECATED void |
| 516 |
upwind_value_matrix(FullMatrix<double> &M11, |
| 517 |
FullMatrix<double> &M12, |
| 518 |
FullMatrix<double> &M21, |
| 519 |
FullMatrix<double> &M22, |
| 520 |
const FEValuesBase<dim> &fe1, |
| 521 |
const FEValuesBase<dim> &fe2, |
| 522 |
const FEValuesBase<dim> &fetest1, |
| 523 |
const FEValuesBase<dim> &fetest2, |
| 524 |
const ArrayView<const std::vector<double>> &velocity, |
| 525 |
const double factor = 1.) |
| 526 |
{ |
| 527 |
const unsigned int n1 = fe1.dofs_per_cell; |
| 528 |
// Multiply the quadrature point |
| 529 |
// index below with this factor to |
| 530 |
// have simpler data for constant |
| 531 |
// velocities. |
| 532 |
AssertDimension(velocity.size(), dim); |
| 533 |
const unsigned int v_increment = (velocity[0].size() == 1) ? 0 : 1; |
| 534 |
if (v_increment == 1) |
| 535 |
{ |
| 536 |
AssertVectorVectorDimension(velocity, dim, fe1.n_quadrature_points); |
| 537 |
} |
| 538 |
|
| 539 |
for (unsigned k = 0; k < fe1.n_quadrature_points; ++k) |
| 540 |
{ |
| 541 |
double nbeta = fe1.normal_vector(k)[0] * velocity[0][k * v_increment]; |
| 542 |
for (unsigned int d = 1; d < dim; ++d) |
| 543 |
nbeta += fe1.normal_vector(k)[d] * velocity[d][k * v_increment]; |
| 544 |
const double dx_nbeta = factor * std::abs(nbeta) * fe1.JxW(k); |
| 545 |
FullMatrix<double> &M1 = nbeta > 0. ? M11 : M22; |
| 546 |
FullMatrix<double> &M2 = nbeta > 0. ? M21 : M12; |
| 547 |
const FEValuesBase<dim> &fe = nbeta > 0. ? fe1 : fe2; |
| 548 |
const FEValuesBase<dim> &fetest = nbeta > 0. ? fetest1 : fetest2; |
| 549 |
const FEValuesBase<dim> &fetestn = nbeta > 0. ? fetest2 : fetest1; |
| 550 |
for (unsigned i = 0; i < n1; ++i) |
| 551 |
for (unsigned j = 0; j < n1; ++j) |
| 552 |
{ |
| 553 |
if (fe1.get_fe().is_primitive()) |
| 554 |
{ |
| 555 |
M1(i, j) += dx_nbeta * fe.shape_value(j, k) * |
| 556 |
fetest.shape_value(i, k); |
| 557 |
M2(i, j) -= dx_nbeta * fe.shape_value(j, k) * |
| 558 |
fetestn.shape_value(i, k); |
| 559 |
} |
| 560 |
else |
| 561 |
{ |
| 562 |
for (unsigned int d = 0; d < fe1.get_fe().n_components(); |
| 563 |
++d) |
| 564 |
{ |
| 565 |
M1(i, j) += dx_nbeta * |
| 566 |
fe.shape_value_component(j, k, d) * |
| 567 |
fetest.shape_value_component(i, k, d); |
| 568 |
M2(i, j) -= dx_nbeta * |
| 569 |
fe.shape_value_component(j, k, d) * |
| 570 |
fetestn.shape_value_component(i, k, d); |
| 571 |
} |
| 572 |
} |
| 573 |
} |
| 574 |
} |
| 575 |
} |
| 576 |
|
| 577 |
|
| 578 |
|
| 579 |
/** |
| 580 |
* Scalar case: Upwind flux in the interior for weak advection operator. |
| 581 |
* Matrix entries correspond to the upwind value of the trial function, |
| 582 |
* multiplied by the jump of the test functions |
| 583 |
* @f[ |
| 584 |
* a_{ij} = \int_F \left|\mathbf w |
| 585 |
* \cdot \mathbf n\right| |
| 586 |
* u^\uparrow |
| 587 |
* (v^\uparrow-v^\downarrow) |
| 588 |
* \,ds |
| 589 |
* @f] |
| 590 |
* |
| 591 |
* The <tt>velocity</tt> is provided as an ArrayView, having <tt>dim</tt> |
| 592 |
* vectors, one for each velocity component. Each of the vectors must |
| 593 |
* either have only a single entry, if the advection velocity is constant, |
| 594 |
* or have an entry for each quadrature point. |
| 595 |
* |
| 596 |
* The finite element can have several components, in which case each |
| 597 |
* component is advected the same way. |
| 598 |
*/ |
| 599 |
template <int dim> |
| 600 |
DEAL_II_DEPRECATED void |
| 601 |
upwind_face_residual(Vector<double> &result1, |
| 602 |
Vector<double> &result2, |
| 603 |
const FEValuesBase<dim> &fe1, |
| 604 |
const FEValuesBase<dim> &fe2, |
| 605 |
const std::vector<double> &input1, |
| 606 |
const std::vector<double> &input2, |
| 607 |
const ArrayView<const std::vector<double>> &velocity, |
| 608 |
const double factor = 1.) |
| 609 |
{ |
| 610 |
Assert(fe1.get_fe().n_components() == 1, |
| 611 |
ExcDimensionMismatch(fe1.get_fe().n_components(), 1)); |
| 612 |
Assert(fe2.get_fe().n_components() == 1, |
| 613 |
ExcDimensionMismatch(fe2.get_fe().n_components(), 1)); |
| 614 |
|
| 615 |
const unsigned int n1 = fe1.dofs_per_cell; |
| 616 |
// Multiply the quadrature point |
| 617 |
// index below with this factor to |
| 618 |
// have simpler data for constant |
| 619 |
// velocities. |
| 620 |
AssertDimension(velocity.size(), dim); |
| 621 |
const unsigned int v_increment = (velocity[0].size() == 1) ? 0 : 1; |
| 622 |
if (v_increment == 1) |
| 623 |
{ |
| 624 |
AssertVectorVectorDimension(velocity, dim, fe1.n_quadrature_points); |
| 625 |
} |
| 626 |
|
| 627 |
for (unsigned k = 0; k < fe1.n_quadrature_points; ++k) |
| 628 |
{ |
| 629 |
double nbeta = fe1.normal_vector(k)[0] * velocity[0][k * v_increment]; |
| 630 |
for (unsigned int d = 1; d < dim; ++d) |
| 631 |
nbeta += fe1.normal_vector(k)[d] * velocity[d][k * v_increment]; |
| 632 |
const double dx_nbeta = factor * nbeta * fe1.JxW(k); |
| 633 |
|
| 634 |
for (unsigned i = 0; i < n1; ++i) |
| 635 |
{ |
| 636 |
const double v1 = fe1.shape_value(i, k); |
| 637 |
const double v2 = fe2.shape_value(i, k); |
| 638 |
const double u1 = input1[k]; |
| 639 |
const double u2 = input2[k]; |
| 640 |
if (nbeta > 0) |
| 641 |
{ |
| 642 |
result1(i) += dx_nbeta * u1 * v1; |
| 643 |
result2(i) -= dx_nbeta * u1 * v2; |
| 644 |
} |
| 645 |
else |
| 646 |
{ |
| 647 |
result1(i) += dx_nbeta * u2 * v1; |
| 648 |
result2(i) -= dx_nbeta * u2 * v2; |
| 649 |
} |
| 650 |
} |
| 651 |
} |
| 652 |
} |
| 653 |
|
| 654 |
|
| 655 |
|
| 656 |
/** |
| 657 |
* Vector-valued case: Upwind flux in the interior for weak advection |
| 658 |
* operator. Matrix entries correspond to the upwind value of the trial |
| 659 |
* function, multiplied by the jump of the test functions |
| 660 |
* @f[ |
| 661 |
* a_{ij} = \int_F \left|\mathbf w |
| 662 |
* \cdot \mathbf n\right| |
| 663 |
* u^\uparrow |
| 664 |
* (v^\uparrow-v^\downarrow) |
| 665 |
* \,ds |
| 666 |
* @f] |
| 667 |
* |
| 668 |
* The <tt>velocity</tt> is provided as an ArrayView, having <tt>dim</tt> |
| 669 |
* vectors, one for each velocity component. Each of the vectors must |
| 670 |
* either have only a single entry, if the advection velocity is constant, |
| 671 |
* or have an entry for each quadrature point. |
| 672 |
* |
| 673 |
* The finite element can have several components, in which case each |
| 674 |
* component is advected the same way. |
| 675 |
*/ |
| 676 |
template <int dim> |
| 677 |
DEAL_II_DEPRECATED void |
| 678 |
upwind_face_residual(Vector<double> &result1, |
| 679 |
Vector<double> &result2, |
| 680 |
const FEValuesBase<dim> &fe1, |
| 681 |
const FEValuesBase<dim> &fe2, |
| 682 |
const ArrayView<const std::vector<double>> &input1, |
| 683 |
const ArrayView<const std::vector<double>> &input2, |
| 684 |
const ArrayView<const std::vector<double>> &velocity, |
| 685 |
const double factor = 1.) |
| 686 |
{ |
| 687 |
const unsigned int n_comp = fe1.get_fe().n_components(); |
| 688 |
const unsigned int n1 = fe1.dofs_per_cell; |
| 689 |
AssertVectorVectorDimension(input1, n_comp, fe1.n_quadrature_points); |
| 690 |
AssertVectorVectorDimension(input2, n_comp, fe2.n_quadrature_points); |
| 691 |
|
| 692 |
// Multiply the quadrature point |
| 693 |
// index below with this factor to |
| 694 |
// have simpler data for constant |
| 695 |
// velocities. |
| 696 |
AssertDimension(velocity.size(), dim); |
| 697 |
const unsigned int v_increment = (velocity[0].size() == 1) ? 0 : 1; |
| 698 |
if (v_increment == 1) |
| 699 |
{ |
| 700 |
AssertVectorVectorDimension(velocity, dim, fe1.n_quadrature_points); |
| 701 |
} |
| 702 |
|
| 703 |
for (unsigned k = 0; k < fe1.n_quadrature_points; ++k) |
| 704 |
{ |
| 705 |
double nbeta = fe1.normal_vector(k)[0] * velocity[0][k * v_increment]; |
| 706 |
for (unsigned int d = 1; d < dim; ++d) |
| 707 |
nbeta += fe1.normal_vector(k)[d] * velocity[d][k * v_increment]; |
| 708 |
const double dx_nbeta = factor * nbeta * fe1.JxW(k); |
| 709 |
|
| 710 |
for (unsigned i = 0; i < n1; ++i) |
| 711 |
for (unsigned int d = 0; d < n_comp; ++d) |
| 712 |
{ |
| 713 |
const double v1 = fe1.shape_value_component(i, k, d); |
| 714 |
const double v2 = fe2.shape_value_component(i, k, d); |
| 715 |
const double u1 = input1[d][k]; |
| 716 |
const double u2 = input2[d][k]; |
| 717 |
if (nbeta > 0) |
| 718 |
{ |
| 719 |
result1(i) += dx_nbeta * u1 * v1; |
| 720 |
result2(i) -= dx_nbeta * u1 * v2; |
| 721 |
} |
| 722 |
else |
| 723 |
{ |
| 724 |
result1(i) += dx_nbeta * u2 * v1; |
| 725 |
result2(i) -= dx_nbeta * u2 * v2; |
| 726 |
} |
| 727 |
} |
| 728 |
} |
| 729 |
} |
| 730 |
|
| 731 |
} // namespace Advection |
| 732 |
} // namespace LocalIntegrators |
| 733 |
|
| 734 |
|
| 735 |
DEAL_II_NAMESPACE_CLOSE |
| 736 |
|
| 737 |
#endif |