| 1 |
// ------------------------------------------------------------------------ |
| 2 |
// |
| 3 |
// SPDX-License-Identifier: LGPL-2.1-or-later |
| 4 |
// Copyright (C) 2009 - 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 |
|
| 16 |
#ifndef dealii_mesh_worker_integration_info_h |
| 17 |
#define dealii_mesh_worker_integration_info_h |
| 18 |
|
| 19 |
#include <deal.II/base/config.h> |
| 20 |
|
| 21 |
#include <deal.II/base/quadrature_lib.h> |
| 22 |
|
| 23 |
#include <deal.II/dofs/block_info.h> |
| 24 |
|
| 25 |
#include <deal.II/fe/fe_values.h> |
| 26 |
|
| 27 |
#include <deal.II/meshworker/dof_info.h> |
| 28 |
#include <deal.II/meshworker/local_results.h> |
| 29 |
#include <deal.II/meshworker/vector_selector.h> |
| 30 |
|
| 31 |
#include <memory> |
| 32 |
|
| 33 |
DEAL_II_NAMESPACE_OPEN |
| 34 |
|
| 35 |
namespace MeshWorker |
| 36 |
{ |
| 37 |
/** |
| 38 |
* Class for objects handed to local integration functions. |
| 39 |
* |
| 40 |
* Objects of this class contain one or more objects of type FEValues, |
| 41 |
* FEFaceValues or FESubfaceValues to be used in local integration. They are |
| 42 |
* stored in an array of pointers to the base classes FEValuesBase. The |
| 43 |
* template parameter VectorType allows the use of different data types for |
| 44 |
* the global system. |
| 45 |
* |
| 46 |
* Additionally, this function contains space to store the values of finite |
| 47 |
* element functions stored in #global_data in the quadrature points. These |
| 48 |
* vectors are initialized automatically on each cell or face. In order to |
| 49 |
* avoid initializing unused vectors, you can use initialize_selector() to |
| 50 |
* select the vectors by name that you actually want to use. |
| 51 |
* |
| 52 |
* <h3>Integration models</h3> |
| 53 |
* |
| 54 |
* This class supports two local integration models, corresponding to the |
| 55 |
* data models in the documentation of the Assembler namespace. One is the |
| 56 |
* standard model suggested by the use of FESystem. Namely, there is one |
| 57 |
* FEValuesBase object in this class, containing all shape functions of the |
| 58 |
* whole system, and having as many components as the system. Using this |
| 59 |
* model involves loops over all system shape functions. It requires to |
| 60 |
* identify the system components for each shape function and to select the |
| 61 |
* correct bilinear form, usually in an @p if or @p switch statement. |
| 62 |
* |
| 63 |
* The second integration model builds one FEValuesBase object per base |
| 64 |
* element of the system. The degrees of freedom on each cell are renumbered |
| 65 |
* by block, such that they represent the same block structure as the global |
| 66 |
* system. Objects performing the integration can then process each block |
| 67 |
* separately, which improves reusability of code considerably. |
| 68 |
* |
| 69 |
* @note As described in DoFInfo, the use of the local block model is |
| 70 |
* triggered by calling BlockInfo::initialize_local() before using |
| 71 |
* initialize() in this class. |
| 72 |
* |
| 73 |
* @ingroup MeshWorker |
| 74 |
*/ |
| 75 |
template <int dim, int spacedim = dim> |
| 76 |
class IntegrationInfo |
| 77 |
{ |
| 78 |
private: |
| 79 |
/// vector of FEValues objects |
| 80 |
std::vector<std::shared_ptr<FEValuesBase<dim, spacedim>>> fevalv; |
| 81 |
|
| 82 |
public: |
| 83 |
static constexpr unsigned int dimension = dim; |
| 84 |
static constexpr unsigned int space_dimension = spacedim; |
| 85 |
|
| 86 |
/** |
| 87 |
* Constructor. |
| 88 |
*/ |
| 89 |
IntegrationInfo(); |
| 90 |
|
| 91 |
/** |
| 92 |
* Copy constructor, creating a clone to be used by WorkStream::run(). |
| 93 |
*/ |
| 94 |
IntegrationInfo(const IntegrationInfo<dim, spacedim> &other); |
| 95 |
|
| 96 |
/** |
| 97 |
* Build all internal structures, in particular the FEValuesBase objects |
| 98 |
* and allocate space for data vectors. |
| 99 |
* |
| 100 |
* @param el is the finite element of the DoFHandler. |
| 101 |
* |
| 102 |
* @param mapping is the Mapping object used to map the mesh cells. |
| 103 |
* |
| 104 |
* @param quadrature is a Quadrature formula used in the constructor of |
| 105 |
* the FEVALUES objects. |
| 106 |
* |
| 107 |
* @param flags are the UpdateFlags used in the constructor of the |
| 108 |
* FEVALUES objects. |
| 109 |
* |
| 110 |
* @param local_block_info is an optional parameter for systems of PDE. If |
| 111 |
* it is provided with reasonable data, then the degrees of freedom on the |
| 112 |
* cells will be re-ordered to reflect the block structure of the system. |
| 113 |
*/ |
| 114 |
template <class FEVALUES> |
| 115 |
void |
| 116 |
initialize(const FiniteElement<dim, spacedim> &el, |
| 117 |
const Mapping<dim, spacedim> &mapping, |
| 118 |
const Quadrature<FEVALUES::integral_dimension> &quadrature, |
| 119 |
const UpdateFlags flags, |
| 120 |
const BlockInfo *local_block_info = nullptr); |
| 121 |
|
| 122 |
/** |
| 123 |
* Initialize the data vector and cache the selector. |
| 124 |
*/ |
| 125 |
void |
| 126 |
initialize_data(const std::shared_ptr<VectorDataBase<dim, spacedim>> &data); |
| 127 |
|
| 128 |
/** |
| 129 |
* Delete the data created by initialize(). |
| 130 |
*/ |
| 131 |
void |
| 132 |
clear(); |
| 133 |
|
| 134 |
/** |
| 135 |
* Return a reference to the FiniteElement that was used to initialize |
| 136 |
* this object. |
| 137 |
*/ |
| 138 |
const FiniteElement<dim, spacedim> & |
| 139 |
finite_element() const; |
| 140 |
|
| 141 |
/// This is true if we are assembling for multigrid |
| 142 |
bool multigrid; |
| 143 |
/// Access to finite element |
| 144 |
/** |
| 145 |
* This is the access function being used, if initialize() for a single |
| 146 |
* element was used (without the BlockInfo argument). It throws an |
| 147 |
* exception, if applied to a vector of elements. |
| 148 |
*/ |
| 149 |
const FEValuesBase<dim, spacedim> & |
| 150 |
fe_values() const; |
| 151 |
|
| 152 |
/// Access to finite elements |
| 153 |
/** |
| 154 |
* This access function must be used if the initialize() for a group of |
| 155 |
* elements was used (with a valid BlockInfo object). |
| 156 |
*/ |
| 157 |
const FEValuesBase<dim, spacedim> & |
| 158 |
fe_values(const unsigned int i) const; |
| 159 |
|
| 160 |
/** |
| 161 |
* The vector containing the values of finite element functions in the |
| 162 |
* quadrature points. |
| 163 |
* |
| 164 |
* There is one vector per selected finite element function, containing |
| 165 |
* one vector for each component, containing vectors with values for each |
| 166 |
* quadrature point. |
| 167 |
*/ |
| 168 |
std::vector<std::vector<std::vector<double>>> values; |
| 169 |
|
| 170 |
/** |
| 171 |
* The vector containing the derivatives of finite element functions in |
| 172 |
* the quadrature points. |
| 173 |
* |
| 174 |
* There is one vector per selected finite element function, containing |
| 175 |
* one vector for each component, containing vectors with values for each |
| 176 |
* quadrature point. |
| 177 |
*/ |
| 178 |
std::vector<std::vector<std::vector<Tensor<1, spacedim>>>> gradients; |
| 179 |
|
| 180 |
/** |
| 181 |
* The vector containing the second derivatives of finite element |
| 182 |
* functions in the quadrature points. |
| 183 |
* |
| 184 |
* There is one vector per selected finite element function, containing |
| 185 |
* one vector for each component, containing vectors with values for each |
| 186 |
* quadrature point. |
| 187 |
*/ |
| 188 |
std::vector<std::vector<std::vector<Tensor<2, spacedim>>>> hessians; |
| 189 |
|
| 190 |
/** |
| 191 |
* Reinitialize internal data structures for use on a cell. |
| 192 |
*/ |
| 193 |
template <typename number> |
| 194 |
void |
| 195 |
reinit(const DoFInfo<dim, spacedim, number> &i); |
| 196 |
|
| 197 |
/** |
| 198 |
* Use the finite element functions in #global_data and fill the vectors |
| 199 |
* #values, #gradients and #hessians. |
| 200 |
*/ |
| 201 |
template <typename number> |
| 202 |
void |
| 203 |
fill_local_data(const DoFInfo<dim, spacedim, number> &info, |
| 204 |
bool split_fevalues); |
| 205 |
|
| 206 |
/** |
| 207 |
* The global data vector used to compute function values in quadrature |
| 208 |
* points. |
| 209 |
*/ |
| 210 |
std::shared_ptr<VectorDataBase<dim, spacedim>> global_data; |
| 211 |
|
| 212 |
/** |
| 213 |
* The memory used by this object. |
| 214 |
*/ |
| 215 |
std::size_t |
| 216 |
memory_consumption() const; |
| 217 |
|
| 218 |
private: |
| 219 |
/** |
| 220 |
* The pointer to the (system) element used for initialization. |
| 221 |
*/ |
| 222 |
ObserverPointer<const FiniteElement<dim, spacedim>, |
| 223 |
IntegrationInfo<dim, spacedim>> |
| 224 |
fe_pointer; |
| 225 |
|
| 226 |
/** |
| 227 |
* Use the finite element functions in #global_data and fill the vectors |
| 228 |
* #values, #gradients and #hessians with values according to the |
| 229 |
* selector. |
| 230 |
*/ |
| 231 |
template <typename TYPE> |
| 232 |
void |
| 233 |
fill_local_data(std::vector<std::vector<std::vector<TYPE>>> &data, |
| 234 |
VectorSelector &selector, |
| 235 |
bool split_fevalues) const; |
| 236 |
/** |
| 237 |
* Cache the number of components of the system element. |
| 238 |
*/ |
| 239 |
unsigned int n_components; |
| 240 |
}; |
| 241 |
|
| 242 |
/** |
| 243 |
* The object holding the scratch data for integrating over cells and faces. |
| 244 |
* IntegrationInfoBox serves three main purposes: |
| 245 |
* |
| 246 |
* <ol> |
| 247 |
* <li> It provides the interface needed by MeshWorker::loop(), namely the |
| 248 |
* two functions post_cell() and post_faces(), as well as the data members |
| 249 |
* #cell, #boundary, #face, #subface, and #neighbor. |
| 250 |
* |
| 251 |
* <li> It contains all information needed to initialize the FEValues and |
| 252 |
* FEFaceValues objects in the IntegrationInfo data members. |
| 253 |
* |
| 254 |
* <li> It stores information on finite element vectors and whether their |
| 255 |
* data should be used to compute values or derivatives of functions at |
| 256 |
* quadrature points. |
| 257 |
* |
| 258 |
* <li> It makes educated guesses on quadrature rules and update flags, so |
| 259 |
* that minimal code has to be written when default parameters are |
| 260 |
* sufficient. |
| 261 |
* </ol> |
| 262 |
* |
| 263 |
* In order to allow for sufficient generality, a few steps have to be |
| 264 |
* undertaken to use this class. |
| 265 |
* |
| 266 |
* First, you should consider if you need values from any vectors in a |
| 267 |
* AnyData object. If so, fill the VectorSelector objects #cell_selector, |
| 268 |
* #boundary_selector and #face_selector with their names and the data type |
| 269 |
* (value, gradient, Hessian) to be extracted. |
| 270 |
* |
| 271 |
* Afterwards, you will need to consider UpdateFlags for FEValues objects. A |
| 272 |
* good start is initialize_update_flags(), which looks at the selectors |
| 273 |
* filled before and adds all the flags needed to get the selection. |
| 274 |
* Additional flags can be set with add_update_flags(). |
| 275 |
* |
| 276 |
* Finally, we need to choose quadrature formulas. In the simplest case, you |
| 277 |
* might be happy with the default settings, which are <i>n</i>-point Gauss |
| 278 |
* formulas. If only derivatives of the shape functions are used |
| 279 |
* (#update_values is not set) <i>n</i> equals the highest polynomial degree |
| 280 |
* in the FiniteElement, if #update_values is set, <i>n</i> is one higher |
| 281 |
* than this degree. If you choose to use Gauss formulas of other size, use |
| 282 |
* initialize_gauss_quadrature() with appropriate values. Otherwise, you can |
| 283 |
* fill the variables #cell_quadrature, #boundary_quadrature and |
| 284 |
* #face_quadrature directly. |
| 285 |
* |
| 286 |
* In order to save time, you can set the variables boundary_fluxes and |
| 287 |
* interior_fluxes of the base class to false, thus telling the |
| 288 |
* Meshworker::loop() not to loop over those faces. |
| 289 |
* |
| 290 |
* All the information in here is used to set up IntegrationInfo objects |
| 291 |
* correctly, typically in an IntegrationInfoBox. |
| 292 |
* |
| 293 |
* @ingroup MeshWorker |
| 294 |
*/ |
| 295 |
template <int dim, int spacedim = dim> |
| 296 |
class IntegrationInfoBox |
| 297 |
{ |
| 298 |
public: |
| 299 |
/** |
| 300 |
* The type of the @p info object for cells. |
| 301 |
*/ |
| 302 |
using CellInfo = IntegrationInfo<dim, spacedim>; |
| 303 |
|
| 304 |
/** |
| 305 |
* Default constructor. |
| 306 |
*/ |
| 307 |
IntegrationInfoBox(); |
| 308 |
|
| 309 |
/** |
| 310 |
* Initialize the IntegrationInfo objects contained. |
| 311 |
* |
| 312 |
* Before doing so, add update flags necessary to produce the data needed |
| 313 |
* and also set uninitialized quadrature rules to Gauss formulas, which |
| 314 |
* integrate polynomial bilinear forms exactly. |
| 315 |
*/ |
| 316 |
void |
| 317 |
initialize(const FiniteElement<dim, spacedim> &el, |
| 318 |
const Mapping<dim, spacedim> &mapping, |
| 319 |
const BlockInfo *block_info = nullptr); |
| 320 |
|
| 321 |
/** |
| 322 |
* Initialize the IntegrationInfo objects contained. |
| 323 |
* |
| 324 |
* Before doing so, add update flags necessary to produce the data needed |
| 325 |
* and also set uninitialized quadrature rules to Gauss formulas, which |
| 326 |
* integrate polynomial bilinear forms exactly. |
| 327 |
*/ |
| 328 |
template <typename VectorType> |
| 329 |
void |
| 330 |
initialize(const FiniteElement<dim, spacedim> &el, |
| 331 |
const Mapping<dim, spacedim> &mapping, |
| 332 |
const AnyData &data, |
| 333 |
const VectorType &dummy, |
| 334 |
const BlockInfo *block_info = nullptr); |
| 335 |
/** |
| 336 |
* Initialize the IntegrationInfo objects contained. |
| 337 |
* |
| 338 |
* Before doing so, add update flags necessary to produce the data needed |
| 339 |
* and also set uninitialized quadrature rules to Gauss formulas, which |
| 340 |
* integrate polynomial bilinear forms exactly. |
| 341 |
*/ |
| 342 |
template <typename VectorType> |
| 343 |
void |
| 344 |
initialize(const FiniteElement<dim, spacedim> &el, |
| 345 |
const Mapping<dim, spacedim> &mapping, |
| 346 |
const AnyData &data, |
| 347 |
const MGLevelObject<VectorType> &dummy, |
| 348 |
const BlockInfo *block_info = nullptr); |
| 349 |
/** |
| 350 |
* @name FEValues setup |
| 351 |
* @{ |
| 352 |
*/ |
| 353 |
|
| 354 |
/** |
| 355 |
* Call this function before initialize() in order to guess the update |
| 356 |
* flags needed, based on the data selected. |
| 357 |
* |
| 358 |
* When computing face fluxes, we normally can use the geometry |
| 359 |
* (integration weights and normal vectors) from the original cell and |
| 360 |
* thus can avoid updating these values on the neighboring cell. Set |
| 361 |
* <tt>neighbor_geometry</tt> to true in order to initialize these values |
| 362 |
* as well. |
| 363 |
*/ |
| 364 |
void |
| 365 |
initialize_update_flags(bool neighbor_geometry = false); |
| 366 |
|
| 367 |
/** |
| 368 |
* Add FEValues UpdateFlags for integration on all objects (cells, |
| 369 |
* boundary faces and all interior faces). |
| 370 |
*/ |
| 371 |
void |
| 372 |
add_update_flags_all(const UpdateFlags flags); |
| 373 |
|
| 374 |
/** |
| 375 |
* Add FEValues UpdateFlags for integration on cells. |
| 376 |
*/ |
| 377 |
void |
| 378 |
add_update_flags_cell(const UpdateFlags flags); |
| 379 |
|
| 380 |
/** |
| 381 |
* Add FEValues UpdateFlags for integration on boundary faces. |
| 382 |
*/ |
| 383 |
void |
| 384 |
add_update_flags_boundary(const UpdateFlags flags); |
| 385 |
|
| 386 |
/** |
| 387 |
* Add FEValues UpdateFlags for integration on interior faces. |
| 388 |
*/ |
| 389 |
void |
| 390 |
add_update_flags_face(const UpdateFlags flags); |
| 391 |
|
| 392 |
/** |
| 393 |
* Add additional update flags to the ones already set in this program. |
| 394 |
* The four boolean flags indicate whether the additional flags should be |
| 395 |
* set for cell, boundary, interelement face for the cell itself or |
| 396 |
* neighbor cell, or any combination thereof. |
| 397 |
*/ |
| 398 |
void |
| 399 |
add_update_flags(const UpdateFlags flags, |
| 400 |
const bool cell = true, |
| 401 |
const bool boundary = true, |
| 402 |
const bool face = true, |
| 403 |
const bool neighbor = true); |
| 404 |
|
| 405 |
/** |
| 406 |
* Assign n-point Gauss quadratures to each of the quadrature rules. Here, |
| 407 |
* a size of zero points means that no loop over these grid entities |
| 408 |
* should be performed. |
| 409 |
* |
| 410 |
* If the parameter <tt>force</tt> is true, then all quadrature sets are |
| 411 |
* filled with new quadrature rules. If it is false, then only empty rules |
| 412 |
* are changed. |
| 413 |
*/ |
| 414 |
void |
| 415 |
initialize_gauss_quadrature(unsigned int n_cell_points, |
| 416 |
unsigned int n_boundary_points, |
| 417 |
unsigned int n_face_points, |
| 418 |
const bool force = true); |
| 419 |
|
| 420 |
/** |
| 421 |
* The memory used by this object. |
| 422 |
*/ |
| 423 |
std::size_t |
| 424 |
memory_consumption() const; |
| 425 |
|
| 426 |
/** |
| 427 |
* The set of update flags for boundary cell integration. |
| 428 |
* |
| 429 |
* Defaults to #update_JxW_values. |
| 430 |
*/ |
| 431 |
UpdateFlags cell_flags; |
| 432 |
/** |
| 433 |
* The set of update flags for boundary face integration. |
| 434 |
* |
| 435 |
* Defaults to #update_JxW_values and #update_normal_vectors. |
| 436 |
*/ |
| 437 |
UpdateFlags boundary_flags; |
| 438 |
|
| 439 |
/** |
| 440 |
* The set of update flags for interior face integration. |
| 441 |
* |
| 442 |
* Defaults to #update_JxW_values and #update_normal_vectors. |
| 443 |
*/ |
| 444 |
UpdateFlags face_flags; |
| 445 |
|
| 446 |
/** |
| 447 |
* The set of update flags for interior face integration. |
| 448 |
* |
| 449 |
* Defaults to #update_default, since quadrature weights are taken from |
| 450 |
* the other cell. |
| 451 |
*/ |
| 452 |
UpdateFlags neighbor_flags; |
| 453 |
|
| 454 |
/** |
| 455 |
* The quadrature rule used on cells. |
| 456 |
*/ |
| 457 |
Quadrature<dim> cell_quadrature; |
| 458 |
|
| 459 |
/** |
| 460 |
* The quadrature rule used on boundary faces. |
| 461 |
*/ |
| 462 |
Quadrature<dim - 1> boundary_quadrature; |
| 463 |
|
| 464 |
/** |
| 465 |
* The quadrature rule used on interior faces. |
| 466 |
*/ |
| 467 |
Quadrature<dim - 1> face_quadrature; |
| 468 |
/** @} */ |
| 469 |
|
| 470 |
/** |
| 471 |
* @name Data vectors |
| 472 |
* @{ |
| 473 |
*/ |
| 474 |
|
| 475 |
/** |
| 476 |
* Initialize the VectorSelector objects #cell_selector, |
| 477 |
* #boundary_selector and #face_selector in order to save computational |
| 478 |
* effort. If no selectors are used, then values for all named vectors in |
| 479 |
* DoFInfo::global_data will be computed in all quadrature points. |
| 480 |
* |
| 481 |
* This function will also add UpdateFlags to the flags stored in this |
| 482 |
* class. |
| 483 |
*/ |
| 484 |
/** |
| 485 |
* Select the vectors from DoFInfo::global_data that should be computed in |
| 486 |
* the quadrature points on cells. |
| 487 |
*/ |
| 488 |
MeshWorker::VectorSelector cell_selector; |
| 489 |
|
| 490 |
/** |
| 491 |
* Select the vectors from DoFInfo::global_data that should be computed in |
| 492 |
* the quadrature points on boundary faces. |
| 493 |
*/ |
| 494 |
MeshWorker::VectorSelector boundary_selector; |
| 495 |
|
| 496 |
/** |
| 497 |
* Select the vectors from DoFInfo::global_data that should be computed in |
| 498 |
* the quadrature points on interior faces. |
| 499 |
*/ |
| 500 |
MeshWorker::VectorSelector face_selector; |
| 501 |
|
| 502 |
std::shared_ptr<MeshWorker::VectorDataBase<dim, spacedim>> cell_data; |
| 503 |
std::shared_ptr<MeshWorker::VectorDataBase<dim, spacedim>> boundary_data; |
| 504 |
std::shared_ptr<MeshWorker::VectorDataBase<dim, spacedim>> face_data; |
| 505 |
/** @} */ |
| 506 |
|
| 507 |
/** |
| 508 |
* @name Interface for MeshWorker::loop() |
| 509 |
* @{ |
| 510 |
*/ |
| 511 |
/** |
| 512 |
* A callback function which is called in the loop over all cells, after |
| 513 |
* the action on a cell has been performed and before the faces are dealt |
| 514 |
* with. |
| 515 |
* |
| 516 |
* In order for this function to have this effect, at least either of the |
| 517 |
* arguments <tt>boundary_worker</tt> or <tt>face_worker</tt> arguments of |
| 518 |
* loop() should be nonzero. Additionally, <tt>cells_first</tt> should be |
| 519 |
* true. If <tt>cells_first</tt> is false, this function is called before |
| 520 |
* any action on a cell is taken. |
| 521 |
* |
| 522 |
* And empty function in this class, but can be replaced in other classes |
| 523 |
* given to loop() instead. |
| 524 |
* |
| 525 |
* See loop() and cell_action() for more details of how this function can |
| 526 |
* be used. |
| 527 |
*/ |
| 528 |
template <class DOFINFO> |
| 529 |
void |
| 530 |
post_cell(const DoFInfoBox<dim, DOFINFO> &); |
| 531 |
|
| 532 |
/** |
| 533 |
* A callback function which is called in the loop over all cells, after |
| 534 |
* the action on the faces of a cell has been performed and before the |
| 535 |
* cell itself is dealt with (assumes <tt>cells_first</tt> is false). |
| 536 |
* |
| 537 |
* In order for this function to have a reasonable effect, at least either |
| 538 |
* of the arguments <tt>boundary_worker</tt> or <tt>face_worker</tt> |
| 539 |
* arguments of loop() should be nonzero. Additionally, |
| 540 |
* <tt>cells_first</tt> should be false. |
| 541 |
* |
| 542 |
* And empty function in this class, but can be replaced in other classes |
| 543 |
* given to loop() instead. |
| 544 |
* |
| 545 |
* See loop() and cell_action() for more details of how this function can |
| 546 |
* be used. |
| 547 |
*/ |
| 548 |
template <class DOFINFO> |
| 549 |
void |
| 550 |
post_faces(const DoFInfoBox<dim, DOFINFO> &); |
| 551 |
|
| 552 |
/** |
| 553 |
* The @p info object for a cell. |
| 554 |
*/ |
| 555 |
CellInfo cell; |
| 556 |
/** |
| 557 |
* The @p info object for a boundary face. |
| 558 |
*/ |
| 559 |
CellInfo boundary; |
| 560 |
/** |
| 561 |
* The @p info object for a regular interior face, seen from the first cell. |
| 562 |
*/ |
| 563 |
CellInfo face; |
| 564 |
/** |
| 565 |
* The @p info object for the refined side of an interior face seen from the |
| 566 |
* first cell. |
| 567 |
*/ |
| 568 |
CellInfo subface; |
| 569 |
/** |
| 570 |
* The @p info object for an interior face, seen from the other cell. |
| 571 |
*/ |
| 572 |
CellInfo neighbor; |
| 573 |
|
| 574 |
/** @} */ |
| 575 |
}; |
| 576 |
|
| 577 |
|
| 578 |
//----------------------------------------------------------------------// |
| 579 |
|
| 580 |
template <int dim, int sdim> |
| 581 |
inline IntegrationInfo<dim, sdim>::IntegrationInfo() |
| 582 |
: fevalv(0) |
| 583 |
, multigrid(false) |
| 584 |
, global_data(std::make_shared<VectorDataBase<dim, sdim>>()) |
| 585 |
, n_components(numbers::invalid_unsigned_int) |
| 586 |
{} |
| 587 |
|
| 588 |
#ifndef DOXYGEN |
| 589 |
template <int dim, int sdim> |
| 590 |
inline IntegrationInfo<dim, sdim>::IntegrationInfo( |
| 591 |
const IntegrationInfo<dim, sdim> &other) |
| 592 |
: multigrid(other.multigrid) |
| 593 |
, values(other.values) |
| 594 |
, gradients(other.gradients) |
| 595 |
, hessians(other.hessians) |
| 596 |
, global_data(other.global_data) |
| 597 |
, fe_pointer(other.fe_pointer) |
| 598 |
, n_components(other.n_components) |
| 599 |
{ |
| 600 |
fevalv.resize(other.fevalv.size()); |
| 601 |
for (unsigned int i = 0; i < other.fevalv.size(); ++i) |
| 602 |
{ |
| 603 |
const FEValuesBase<dim, sdim> &p = *other.fevalv[i]; |
| 604 |
const FEValues<dim, sdim> *pc = |
| 605 |
dynamic_cast<const FEValues<dim, sdim> *>(&p); |
| 606 |
const FEFaceValues<dim, sdim> *pf = |
| 607 |
dynamic_cast<const FEFaceValues<dim, sdim> *>(&p); |
| 608 |
const FESubfaceValues<dim, sdim> *ps = |
| 609 |
dynamic_cast<const FESubfaceValues<dim, sdim> *>(&p); |
| 610 |
|
| 611 |
if (pc != nullptr) |
| 612 |
fevalv[i] = |
| 613 |
std::make_shared<FEValues<dim, sdim>>(pc->get_mapping(), |
| 614 |
pc->get_fe(), |
| 615 |
pc->get_quadrature(), |
| 616 |
pc->get_update_flags()); |
| 617 |
else if (pf != nullptr) |
| 618 |
fevalv[i] = |
| 619 |
std::make_shared<FEFaceValues<dim, sdim>>(pf->get_mapping(), |
| 620 |
pf->get_fe(), |
| 621 |
pf->get_quadrature(), |
| 622 |
pf->get_update_flags()); |
| 623 |
else if (ps != nullptr) |
| 624 |
fevalv[i] = std::make_shared<FESubfaceValues<dim, sdim>>( |
| 625 |
ps->get_mapping(), |
| 626 |
ps->get_fe(), |
| 627 |
ps->get_quadrature(), |
| 628 |
ps->get_update_flags()); |
| 629 |
else |
| 630 |
DEAL_II_ASSERT_UNREACHABLE(); |
| 631 |
} |
| 632 |
} |
| 633 |
#endif |
| 634 |
|
| 635 |
|
| 636 |
|
| 637 |
template <int dim, int sdim> |
| 638 |
template <class FEVALUES> |
| 639 |
inline void |
| 640 |
IntegrationInfo<dim, sdim>::initialize( |
| 641 |
const FiniteElement<dim, sdim> &el, |
| 642 |
const Mapping<dim, sdim> &mapping, |
| 643 |
const Quadrature<FEVALUES::integral_dimension> &quadrature, |
| 644 |
const UpdateFlags flags, |
| 645 |
const BlockInfo *block_info) |
| 646 |
{ |
| 647 |
fe_pointer = ⪙ |
| 648 |
if (block_info == nullptr || block_info->local().size() == 0) |
| 649 |
{ |
| 650 |
fevalv.resize(1); |
| 651 |
fevalv[0] = std::make_shared<FEVALUES>(mapping, el, quadrature, flags); |
| 652 |
} |
| 653 |
else |
| 654 |
{ |
| 655 |
fevalv.resize(el.n_base_elements()); |
| 656 |
for (unsigned int i = 0; i < fevalv.size(); ++i) |
| 657 |
fevalv[i] = std::make_shared<FEVALUES>(mapping, |
| 658 |
el.base_element(i), |
| 659 |
quadrature, |
| 660 |
flags); |
| 661 |
} |
| 662 |
n_components = el.n_components(); |
| 663 |
} |
| 664 |
|
| 665 |
|
| 666 |
template <int dim, int spacedim> |
| 667 |
inline const FiniteElement<dim, spacedim> & |
| 668 |
IntegrationInfo<dim, spacedim>::finite_element() const |
| 669 |
{ |
| 670 |
Assert(fe_pointer != nullptr, ExcNotInitialized()); |
| 671 |
return *fe_pointer; |
| 672 |
} |
| 673 |
|
| 674 |
template <int dim, int spacedim> |
| 675 |
inline const FEValuesBase<dim, spacedim> & |
| 676 |
IntegrationInfo<dim, spacedim>::fe_values() const |
| 677 |
{ |
| 678 |
AssertDimension(fevalv.size(), 1); |
| 679 |
return *fevalv[0]; |
| 680 |
} |
| 681 |
|
| 682 |
|
| 683 |
template <int dim, int spacedim> |
| 684 |
inline const FEValuesBase<dim, spacedim> & |
| 685 |
IntegrationInfo<dim, spacedim>::fe_values(unsigned int i) const |
| 686 |
{ |
| 687 |
AssertIndexRange(i, fevalv.size()); |
| 688 |
return *fevalv[i]; |
| 689 |
} |
| 690 |
|
| 691 |
|
| 692 |
template <int dim, int spacedim> |
| 693 |
template <typename number> |
| 694 |
inline void |
| 695 |
IntegrationInfo<dim, spacedim>::reinit( |
| 696 |
const DoFInfo<dim, spacedim, number> &info) |
| 697 |
{ |
| 698 |
for (unsigned int i = 0; i < fevalv.size(); ++i) |
| 699 |
{ |
| 700 |
FEValuesBase<dim, spacedim> &febase = *fevalv[i]; |
| 701 |
if (info.sub_number != numbers::invalid_unsigned_int) |
| 702 |
{ |
| 703 |
// This is a subface |
| 704 |
FESubfaceValues<dim, spacedim> &fe = |
| 705 |
dynamic_cast<FESubfaceValues<dim, spacedim> &>(febase); |
| 706 |
fe.reinit(info.cell, info.face_number, info.sub_number); |
| 707 |
} |
| 708 |
else if (info.face_number != numbers::invalid_unsigned_int) |
| 709 |
{ |
| 710 |
// This is a face |
| 711 |
FEFaceValues<dim, spacedim> &fe = |
| 712 |
dynamic_cast<FEFaceValues<dim, spacedim> &>(febase); |
| 713 |
fe.reinit(info.cell, info.face_number); |
| 714 |
} |
| 715 |
else |
| 716 |
{ |
| 717 |
// This is a cell |
| 718 |
FEValues<dim, spacedim> &fe = |
| 719 |
dynamic_cast<FEValues<dim, spacedim> &>(febase); |
| 720 |
fe.reinit(info.cell); |
| 721 |
} |
| 722 |
} |
| 723 |
|
| 724 |
const bool split_fevalues = info.block_info != nullptr; |
| 725 |
if (!global_data->empty()) |
| 726 |
fill_local_data(info, split_fevalues); |
| 727 |
} |
| 728 |
|
| 729 |
|
| 730 |
|
| 731 |
//----------------------------------------------------------------------// |
| 732 |
|
| 733 |
template <int dim, int sdim> |
| 734 |
inline void |
| 735 |
IntegrationInfoBox<dim, sdim>::initialize_gauss_quadrature(unsigned int cp, |
| 736 |
unsigned int bp, |
| 737 |
unsigned int fp, |
| 738 |
bool force) |
| 739 |
{ |
| 740 |
if (force || cell_quadrature.empty()) |
| 741 |
cell_quadrature = QGauss<dim>(cp); |
| 742 |
if (force || boundary_quadrature.empty()) |
| 743 |
boundary_quadrature = QGauss<dim - 1>(bp); |
| 744 |
if (force || face_quadrature.empty()) |
| 745 |
face_quadrature = QGauss<dim - 1>(fp); |
| 746 |
} |
| 747 |
|
| 748 |
|
| 749 |
template <int dim, int sdim> |
| 750 |
inline void |
| 751 |
IntegrationInfoBox<dim, sdim>::add_update_flags_all(const UpdateFlags flags) |
| 752 |
{ |
| 753 |
add_update_flags(flags, true, true, true, true); |
| 754 |
} |
| 755 |
|
| 756 |
|
| 757 |
template <int dim, int sdim> |
| 758 |
inline void |
| 759 |
IntegrationInfoBox<dim, sdim>::add_update_flags_cell(const UpdateFlags flags) |
| 760 |
{ |
| 761 |
add_update_flags(flags, true, false, false, false); |
| 762 |
} |
| 763 |
|
| 764 |
|
| 765 |
template <int dim, int sdim> |
| 766 |
inline void |
| 767 |
IntegrationInfoBox<dim, sdim>::add_update_flags_boundary( |
| 768 |
const UpdateFlags flags) |
| 769 |
{ |
| 770 |
add_update_flags(flags, false, true, false, false); |
| 771 |
} |
| 772 |
|
| 773 |
|
| 774 |
template <int dim, int sdim> |
| 775 |
inline void |
| 776 |
IntegrationInfoBox<dim, sdim>::add_update_flags_face(const UpdateFlags flags) |
| 777 |
{ |
| 778 |
add_update_flags(flags, false, false, true, true); |
| 779 |
} |
| 780 |
|
| 781 |
|
| 782 |
#ifndef DOXYGEN |
| 783 |
template <int dim, int sdim> |
| 784 |
inline void |
| 785 |
IntegrationInfoBox<dim, sdim>::initialize(const FiniteElement<dim, sdim> &el, |
| 786 |
const Mapping<dim, sdim> &mapping, |
| 787 |
const BlockInfo *block_info) |
| 788 |
{ |
| 789 |
initialize_update_flags(); |
| 790 |
initialize_gauss_quadrature((cell_flags & update_values) ? |
| 791 |
(el.tensor_degree() + 1) : |
| 792 |
el.tensor_degree(), |
| 793 |
(boundary_flags & update_values) ? |
| 794 |
(el.tensor_degree() + 1) : |
| 795 |
el.tensor_degree(), |
| 796 |
(face_flags & update_values) ? |
| 797 |
(el.tensor_degree() + 1) : |
| 798 |
el.tensor_degree(), |
| 799 |
false); |
| 800 |
|
| 801 |
cell.template initialize<FEValues<dim, sdim>>( |
| 802 |
el, mapping, cell_quadrature, cell_flags, block_info); |
| 803 |
boundary.template initialize<FEFaceValues<dim, sdim>>( |
| 804 |
el, mapping, boundary_quadrature, boundary_flags, block_info); |
| 805 |
face.template initialize<FEFaceValues<dim, sdim>>( |
| 806 |
el, mapping, face_quadrature, face_flags, block_info); |
| 807 |
subface.template initialize<FESubfaceValues<dim, sdim>>( |
| 808 |
el, mapping, face_quadrature, face_flags, block_info); |
| 809 |
neighbor.template initialize<FEFaceValues<dim, sdim>>( |
| 810 |
el, mapping, face_quadrature, neighbor_flags, block_info); |
| 811 |
} |
| 812 |
#endif |
| 813 |
|
| 814 |
|
| 815 |
template <int dim, int sdim> |
| 816 |
template <typename VectorType> |
| 817 |
void |
| 818 |
IntegrationInfoBox<dim, sdim>::initialize(const FiniteElement<dim, sdim> &el, |
| 819 |
const Mapping<dim, sdim> &mapping, |
| 820 |
const AnyData &data, |
| 821 |
const VectorType &, |
| 822 |
const BlockInfo *block_info) |
| 823 |
{ |
| 824 |
initialize(el, mapping, block_info); |
| 825 |
std::shared_ptr<VectorData<VectorType, dim, sdim>> p; |
| 826 |
VectorDataBase<dim, sdim> *pp; |
| 827 |
|
| 828 |
p = std::make_shared<VectorData<VectorType, dim, sdim>>(cell_selector); |
| 829 |
// Public member function of parent class was not found without |
| 830 |
// explicit cast |
| 831 |
pp = &*p; |
| 832 |
pp->initialize(data); |
| 833 |
cell_data = p; |
| 834 |
cell.initialize_data(p); |
| 835 |
|
| 836 |
p = std::make_shared<VectorData<VectorType, dim, sdim>>(boundary_selector); |
| 837 |
pp = &*p; |
| 838 |
pp->initialize(data); |
| 839 |
boundary_data = p; |
| 840 |
boundary.initialize_data(p); |
| 841 |
|
| 842 |
p = std::make_shared<VectorData<VectorType, dim, sdim>>(face_selector); |
| 843 |
pp = &*p; |
| 844 |
pp->initialize(data); |
| 845 |
face_data = p; |
| 846 |
face.initialize_data(p); |
| 847 |
subface.initialize_data(p); |
| 848 |
neighbor.initialize_data(p); |
| 849 |
} |
| 850 |
|
| 851 |
template <int dim, int sdim> |
| 852 |
template <typename VectorType> |
| 853 |
void |
| 854 |
IntegrationInfoBox<dim, sdim>::initialize(const FiniteElement<dim, sdim> &el, |
| 855 |
const Mapping<dim, sdim> &mapping, |
| 856 |
const AnyData &data, |
| 857 |
const MGLevelObject<VectorType> &, |
| 858 |
const BlockInfo *block_info) |
| 859 |
{ |
| 860 |
initialize(el, mapping, block_info); |
| 861 |
std::shared_ptr<MGVectorData<VectorType, dim, sdim>> p; |
| 862 |
VectorDataBase<dim, sdim> *pp; |
| 863 |
|
| 864 |
p = std::make_shared<MGVectorData<VectorType, dim, sdim>>(cell_selector); |
| 865 |
// Public member function of parent class was not found without |
| 866 |
// explicit cast |
| 867 |
pp = &*p; |
| 868 |
pp->initialize(data); |
| 869 |
cell_data = p; |
| 870 |
cell.initialize_data(p); |
| 871 |
|
| 872 |
p = |
| 873 |
std::make_shared<MGVectorData<VectorType, dim, sdim>>(boundary_selector); |
| 874 |
pp = &*p; |
| 875 |
pp->initialize(data); |
| 876 |
boundary_data = p; |
| 877 |
boundary.initialize_data(p); |
| 878 |
|
| 879 |
p = std::make_shared<MGVectorData<VectorType, dim, sdim>>(face_selector); |
| 880 |
pp = &*p; |
| 881 |
pp->initialize(data); |
| 882 |
face_data = p; |
| 883 |
face.initialize_data(p); |
| 884 |
subface.initialize_data(p); |
| 885 |
neighbor.initialize_data(p); |
| 886 |
} |
| 887 |
|
| 888 |
template <int dim, int sdim> |
| 889 |
template <class DOFINFO> |
| 890 |
void |
| 891 |
IntegrationInfoBox<dim, sdim>::post_cell(const DoFInfoBox<dim, DOFINFO> &) |
| 892 |
{} |
| 893 |
|
| 894 |
|
| 895 |
template <int dim, int sdim> |
| 896 |
template <class DOFINFO> |
| 897 |
void |
| 898 |
IntegrationInfoBox<dim, sdim>::post_faces(const DoFInfoBox<dim, DOFINFO> &) |
| 899 |
{} |
| 900 |
|
| 901 |
|
| 902 |
} // namespace MeshWorker |
| 903 |
|
| 904 |
DEAL_II_NAMESPACE_CLOSE |
| 905 |
|
| 906 |
#endif |