| 1 |
// ------------------------------------------------------------------------ |
| 2 |
// |
| 3 |
// SPDX-License-Identifier: LGPL-2.1-or-later |
| 4 |
// Copyright (C) 1998 - 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_matrix_creator_h |
| 16 |
#define dealii_matrix_creator_h |
| 17 |
|
| 18 |
|
| 19 |
#include <deal.II/base/config.h> |
| 20 |
|
| 21 |
#include <deal.II/base/exceptions.h> |
| 22 |
#include <deal.II/base/function.h> |
| 23 |
|
| 24 |
#include <deal.II/lac/affine_constraints.h> |
| 25 |
|
| 26 |
#include <map> |
| 27 |
|
| 28 |
#ifdef DEAL_II_WITH_PETSC |
| 29 |
# include <petscsys.h> |
| 30 |
#endif |
| 31 |
|
| 32 |
DEAL_II_NAMESPACE_OPEN |
| 33 |
|
| 34 |
|
| 35 |
// forward declarations |
| 36 |
#ifndef DOXYGEN |
| 37 |
template <int dim> |
| 38 |
class Quadrature; |
| 39 |
|
| 40 |
|
| 41 |
template <typename number> |
| 42 |
class Vector; |
| 43 |
template <typename number> |
| 44 |
class SparseMatrix; |
| 45 |
|
| 46 |
template <int dim, int spacedim> |
| 47 |
class Mapping; |
| 48 |
template <int dim, int spacedim> |
| 49 |
DEAL_II_CXX20_REQUIRES((concepts::is_valid_dim_spacedim<dim, spacedim>)) |
| 50 |
class DoFHandler; |
| 51 |
|
| 52 |
namespace hp |
| 53 |
{ |
| 54 |
template <int> |
| 55 |
class QCollection; |
| 56 |
template <int, int> |
| 57 |
class MappingCollection; |
| 58 |
} // namespace hp |
| 59 |
|
| 60 |
#endif |
| 61 |
|
| 62 |
|
| 63 |
/** |
| 64 |
* This namespace provides functions that assemble certain standard matrices |
| 65 |
* for a given triangulation, using a given finite element, a given mapping |
| 66 |
* and a quadrature formula. |
| 67 |
* |
| 68 |
* |
| 69 |
* <h3>Conventions for all functions</h3> |
| 70 |
* |
| 71 |
* There exist two versions of almost all functions, one that takes an |
| 72 |
* explicit Mapping argument and one that does not. The second one generally |
| 73 |
* calls the first with an implicit $Q_1$ argument (i.e., with an argument of |
| 74 |
* kind MappingQ(1)). If your intend your code to use a different |
| 75 |
* mapping than a (bi-/tri-)linear one, then you need to call the functions |
| 76 |
* <b>with</b> mapping argument should be used. |
| 77 |
* |
| 78 |
* All functions take a matrix object to hold the matrix to be created. |
| 79 |
* The functions assume that the matrix is initialized with a sparsity pattern |
| 80 |
* (SparsityPattern) corresponding to the given degree of freedom handler, |
| 81 |
* i.e. the sparsity structure is already as needed. You can do this by |
| 82 |
* calling the DoFTools::make_sparsity_pattern() function. |
| 83 |
* |
| 84 |
* Furthermore it is assumed that no relevant data is in the matrix. Some |
| 85 |
* entries will be overwritten and some others will contain invalid data if |
| 86 |
* the matrix wasn't empty before. Therefore you may want to clear the matrix |
| 87 |
* before assemblage. |
| 88 |
* |
| 89 |
* By default, all created matrices are `raw': they are not condensed, i.e. |
| 90 |
* hanging nodes are not eliminated. The reason is that you may want to add |
| 91 |
* several matrices and could then condense afterwards only once, instead of |
| 92 |
* for every matrix. To actually do computations with these matrices, you have |
| 93 |
* to condense the matrix using the AffineConstraints::condense function; you |
| 94 |
* also have to condense the right hand side accordingly and distribute the |
| 95 |
* solution afterwards. Alternatively, you can give an optional argument |
| 96 |
* AffineConstraints that writes cell matrix (and vector) entries with |
| 97 |
* distribute_local_to_global into the global matrix and vector. This way, |
| 98 |
* adding several matrices from different sources is more complicated and |
| 99 |
* you should make sure that you do not mix different ways of applying |
| 100 |
* constraints. Particular caution is necessary when the given |
| 101 |
* AffineConstraints object contains inhomogeneous constraints: In that case, |
| 102 |
* the matrix assembled this way must be the only matrix (or you need to |
| 103 |
* assemble the <b>same</b> right hand side for <b>every</b> matrix you |
| 104 |
* generate and add together). |
| 105 |
* |
| 106 |
* If you want to use boundary conditions with the matrices generated by the |
| 107 |
* functions of this namespace in addition to the ones in a possible |
| 108 |
* AffineConstraints object, you have to use a function like |
| 109 |
* <tt>apply_boundary_values</tt> with the matrix, solution, and right hand |
| 110 |
* side. |
| 111 |
* |
| 112 |
* |
| 113 |
* <h3>Supported matrices</h3> |
| 114 |
* |
| 115 |
* At present there are functions to create the following matrices: |
| 116 |
* <ul> |
| 117 |
* <li> @p create_mass_matrix: create the matrix with entries $m_{ij} = |
| 118 |
* \int_\Omega \phi_i(x) \phi_j(x) dx$ by numerical quadrature. Here, the |
| 119 |
* $\phi_i$ are the basis functions of the finite element space given. |
| 120 |
* |
| 121 |
* A coefficient may be given to evaluate $m_{ij} = \int_\Omega a(x) \phi_i(x) |
| 122 |
* \phi_j(x) dx$ instead. |
| 123 |
* |
| 124 |
* <li> @p create_laplace_matrix: create the matrix with entries $a_{ij} = |
| 125 |
* \int_\Omega \nabla\phi_i(x) \nabla\phi_j(x) dx$ by numerical quadrature. |
| 126 |
* |
| 127 |
* Again, a coefficient may be given to evaluate $a_{ij} = \int_\Omega a(x) |
| 128 |
* \nabla\phi_i(x) \nabla\phi_j(x) dx$ instead. |
| 129 |
* </ul> |
| 130 |
* |
| 131 |
* Make sure that the order of the Quadrature formula given to these functions |
| 132 |
* is sufficiently high to compute the matrices with the required accuracy. |
| 133 |
* For the choice of this quadrature rule you need to take into account the |
| 134 |
* polynomial degree of the FiniteElement basis functions, the roughness of |
| 135 |
* the coefficient @p a, as well as the degree of the given @p Mapping (if |
| 136 |
* any). |
| 137 |
* |
| 138 |
* Note, that for vector-valued elements the @ref GlossMassMatrix "mass matrix" and the laplace |
| 139 |
* matrix is implemented in such a way that each component couples only with |
| 140 |
* itself, i.e. there is no coupling of shape functions belonging to different |
| 141 |
* components. If the degrees of freedom have been sorted according to their |
| 142 |
* vector component (e.g., using DoFRenumbering::component_wise()), then the |
| 143 |
* resulting matrices will be block diagonal. |
| 144 |
* |
| 145 |
* If the finite element for which the mass matrix or the Laplace matrix is to |
| 146 |
* be built has more than one component, the functions accept a single |
| 147 |
* coefficient as well as a vector valued coefficient function. For the latter |
| 148 |
* case, the number of components must coincide with the number of components |
| 149 |
* of the system finite element. |
| 150 |
* |
| 151 |
* |
| 152 |
* <h3>Matrices on the boundary</h3> |
| 153 |
* |
| 154 |
* The create_boundary_mass_matrix() creates the matrix with entries $m_{ij} = |
| 155 |
* \int_{\Gamma} \phi_i \phi_j dx$, where $\Gamma$ is the union of boundary |
| 156 |
* parts with indicators contained in a std::map<types::boundary_id, const |
| 157 |
* Function<spacedim,number>*> passed to the function (i.e. if you want to set |
| 158 |
* up the mass matrix for the parts of the boundary with indicators zero and 2, |
| 159 |
* you pass the function a map with key type types::boundary_id |
| 160 |
* as the parameter @p boundary_functions containing the keys zero and |
| 161 |
* 2). The size of the matrix is equal to the number of degrees of freedom |
| 162 |
* that have support on the boundary, i.e. it is <em>not</em> a matrix on all |
| 163 |
* degrees of freedom, but only a subset. (The $\phi_i$ in the formula are the |
| 164 |
* subset of basis functions which have at least part of their support on |
| 165 |
* $\Gamma$.) In order to determine which shape functions are to be |
| 166 |
* considered, and in order to determine in which order, the function takes a |
| 167 |
* @p dof_to_boundary_mapping; this object maps global DoF numbers to a |
| 168 |
* numbering of the degrees of freedom located on the boundary, and can be |
| 169 |
* obtained using the function DoFTools::map_dof_to_boundary_indices(). |
| 170 |
* |
| 171 |
* In order to work, the function needs a matrix of the correct size, built on |
| 172 |
* top of a corresponding sparsity pattern. Since we only work on a subset of |
| 173 |
* the degrees of freedom, we can't use the matrices and sparsity patterns |
| 174 |
* that are created for the entire set of degrees of freedom. Rather, you |
| 175 |
* should use the DoFHandler::make_boundary_sparsity_pattern() function to |
| 176 |
* create the correct sparsity pattern, and build a matrix on top of it. |
| 177 |
* |
| 178 |
* Note that at present there is no function that computes the mass matrix for |
| 179 |
* <em>all</em> shape functions, though such a function would be trivial to |
| 180 |
* implement. |
| 181 |
* |
| 182 |
* |
| 183 |
* <h3>Right hand sides</h3> |
| 184 |
* |
| 185 |
* In many cases, you will not only want to build the matrix, but also a right |
| 186 |
* hand side, which will give a vector with $f_i = \int_\Omega f(x) \phi_i(x) |
| 187 |
* dx$. For this purpose, each function exists in two versions, one only |
| 188 |
* building the matrix and one also building the right hand side vector. If |
| 189 |
* you want to create a right hand side vector without creating a matrix, you |
| 190 |
* can use the VectorTools::create_right_hand_side() function. The use of the |
| 191 |
* latter may be useful if you want to create many right hand side vectors. |
| 192 |
* |
| 193 |
* @ingroup numerics |
| 194 |
*/ |
| 195 |
namespace MatrixCreator |
| 196 |
{ |
| 197 |
/** |
| 198 |
* Assemble the @ref GlossMassMatrix "mass matrix". If no coefficient is given (i.e., if the |
| 199 |
* pointer to a function object is zero as it is by default), the |
| 200 |
* coefficient is taken as being constant and equal to one. |
| 201 |
* In case you want to specify @p constraints and use the default argument |
| 202 |
* for the coefficient you have to specify the (unused) coefficient argument |
| 203 |
* as <code>(const Function<spacedim,number> *const)nullptr</code>. |
| 204 |
* |
| 205 |
* If the library is configured to use multithreading, this function works |
| 206 |
* in parallel. |
| 207 |
* |
| 208 |
* The optional argument @p constraints allows to apply constraints on the |
| 209 |
* resulting matrix directly. Note, however, that this becomes difficult |
| 210 |
* when you have inhomogeneous constraints and later want to add several |
| 211 |
* such matrices, for example in time dependent settings such as the main |
| 212 |
* loop of step-26. |
| 213 |
* |
| 214 |
* See the general documentation of this namespace for more information. |
| 215 |
*/ |
| 216 |
template <int dim, int spacedim, typename MatrixType> |
| 217 |
void |
| 218 |
create_mass_matrix( |
| 219 |
const Mapping<dim, spacedim> &mapping, |
| 220 |
const DoFHandler<dim, spacedim> &dof, |
| 221 |
const Quadrature<dim> &q, |
| 222 |
MatrixType &matrix, |
| 223 |
const Function<spacedim, typename MatrixType::value_type> *const a = |
| 224 |
nullptr, |
| 225 |
const AffineConstraints<typename MatrixType::value_type> &constraints = |
| 226 |
AffineConstraints<typename MatrixType::value_type>()); |
| 227 |
|
| 228 |
/** |
| 229 |
* Call the create_mass_matrix() function, see above, with |
| 230 |
* <tt>mapping=MappingQ@<dim@>(1)</tt>. |
| 231 |
*/ |
| 232 |
template <int dim, int spacedim, typename MatrixType> |
| 233 |
void |
| 234 |
create_mass_matrix( |
| 235 |
const DoFHandler<dim, spacedim> &dof, |
| 236 |
const Quadrature<dim> &q, |
| 237 |
MatrixType &matrix, |
| 238 |
const Function<spacedim, typename MatrixType::value_type> *const a = |
| 239 |
nullptr, |
| 240 |
const AffineConstraints<typename MatrixType::value_type> &constraints = |
| 241 |
AffineConstraints<typename MatrixType::value_type>()); |
| 242 |
|
| 243 |
/** |
| 244 |
* Assemble the @ref GlossMassMatrix "mass matrix" and a right hand side vector. If no coefficient |
| 245 |
* is given (i.e., if the pointer to a function object is zero as it is by |
| 246 |
* default), the coefficient is taken as being constant and equal to one. |
| 247 |
* In case you want to specify @p constraints and use the default argument |
| 248 |
* for the coefficient you have to specify the (unused) coefficient argument |
| 249 |
* as <code>(const Function <spacedim,number> *const)nullptr</code>. |
| 250 |
* |
| 251 |
* If the library is configured to use multithreading, this function works |
| 252 |
* in parallel. |
| 253 |
* |
| 254 |
* The optional argument @p constraints allows to apply constraints on the |
| 255 |
* resulting matrix directly. Note, however, that this becomes difficult |
| 256 |
* when you have inhomogeneous constraints and later want to add several |
| 257 |
* such matrices, for example in time dependent settings such as the main |
| 258 |
* loop of step-26. |
| 259 |
* |
| 260 |
* See the general documentation of this namespace for more information. |
| 261 |
*/ |
| 262 |
template <int dim, int spacedim, typename MatrixType> |
| 263 |
void |
| 264 |
create_mass_matrix( |
| 265 |
const Mapping<dim, spacedim> &mapping, |
| 266 |
const DoFHandler<dim, spacedim> &dof, |
| 267 |
const Quadrature<dim> &q, |
| 268 |
MatrixType &matrix, |
| 269 |
const Function<spacedim, typename MatrixType::value_type> &rhs, |
| 270 |
Vector<typename MatrixType::value_type> &rhs_vector, |
| 271 |
const Function<spacedim, typename MatrixType::value_type> *const a = |
| 272 |
nullptr, |
| 273 |
const AffineConstraints<typename MatrixType::value_type> &constraints = |
| 274 |
AffineConstraints<typename MatrixType::value_type>()); |
| 275 |
|
| 276 |
/** |
| 277 |
* Call the create_mass_matrix() function, see above, with |
| 278 |
* <tt>mapping=MappingQ@<dim@>(1)</tt>. |
| 279 |
*/ |
| 280 |
template <int dim, int spacedim, typename MatrixType> |
| 281 |
void |
| 282 |
create_mass_matrix( |
| 283 |
const DoFHandler<dim, spacedim> &dof, |
| 284 |
const Quadrature<dim> &q, |
| 285 |
MatrixType &matrix, |
| 286 |
const Function<spacedim, typename MatrixType::value_type> &rhs, |
| 287 |
Vector<typename MatrixType::value_type> &rhs_vector, |
| 288 |
const Function<spacedim, typename MatrixType::value_type> *const a = |
| 289 |
nullptr, |
| 290 |
const AffineConstraints<typename MatrixType::value_type> &constraints = |
| 291 |
AffineConstraints<typename MatrixType::value_type>()); |
| 292 |
|
| 293 |
/** |
| 294 |
* Same function as above, but for hp-objects. |
| 295 |
*/ |
| 296 |
template <int dim, int spacedim, typename MatrixType> |
| 297 |
void |
| 298 |
create_mass_matrix( |
| 299 |
const hp::MappingCollection<dim, spacedim> &mapping, |
| 300 |
const DoFHandler<dim, spacedim> &dof, |
| 301 |
const hp::QCollection<dim> &q, |
| 302 |
MatrixType &matrix, |
| 303 |
const Function<spacedim, typename MatrixType::value_type> *const a = |
| 304 |
nullptr, |
| 305 |
const AffineConstraints<typename MatrixType::value_type> &constraints = |
| 306 |
AffineConstraints<typename MatrixType::value_type>()); |
| 307 |
|
| 308 |
/** |
| 309 |
* Same function as above, but for hp-objects. |
| 310 |
*/ |
| 311 |
template <int dim, int spacedim, typename MatrixType> |
| 312 |
void |
| 313 |
create_mass_matrix( |
| 314 |
const DoFHandler<dim, spacedim> &dof, |
| 315 |
const hp::QCollection<dim> &q, |
| 316 |
MatrixType &matrix, |
| 317 |
const Function<spacedim, typename MatrixType::value_type> *const a = |
| 318 |
nullptr, |
| 319 |
const AffineConstraints<typename MatrixType::value_type> &constraints = |
| 320 |
AffineConstraints<typename MatrixType::value_type>()); |
| 321 |
|
| 322 |
/** |
| 323 |
* Same function as above, but for hp-objects. |
| 324 |
*/ |
| 325 |
template <int dim, int spacedim, typename MatrixType> |
| 326 |
void |
| 327 |
create_mass_matrix( |
| 328 |
const hp::MappingCollection<dim, spacedim> &mapping, |
| 329 |
const DoFHandler<dim, spacedim> &dof, |
| 330 |
const hp::QCollection<dim> &q, |
| 331 |
MatrixType &matrix, |
| 332 |
const Function<spacedim, typename MatrixType::value_type> &rhs, |
| 333 |
Vector<typename MatrixType::value_type> &rhs_vector, |
| 334 |
const Function<spacedim, typename MatrixType::value_type> *const a = |
| 335 |
nullptr, |
| 336 |
const AffineConstraints<typename MatrixType::value_type> &constraints = |
| 337 |
AffineConstraints<typename MatrixType::value_type>()); |
| 338 |
|
| 339 |
/** |
| 340 |
* Same function as above, but for hp-objects. |
| 341 |
*/ |
| 342 |
template <int dim, int spacedim, typename MatrixType> |
| 343 |
void |
| 344 |
create_mass_matrix( |
| 345 |
const DoFHandler<dim, spacedim> &dof, |
| 346 |
const hp::QCollection<dim> &q, |
| 347 |
MatrixType &matrix, |
| 348 |
const Function<spacedim, typename MatrixType::value_type> &rhs, |
| 349 |
Vector<typename MatrixType::value_type> &rhs_vector, |
| 350 |
const Function<spacedim, typename MatrixType::value_type> *const a = |
| 351 |
nullptr, |
| 352 |
const AffineConstraints<typename MatrixType::value_type> &constraints = |
| 353 |
AffineConstraints<typename MatrixType::value_type>()); |
| 354 |
|
| 355 |
|
| 356 |
/** |
| 357 |
* Assemble the @ref GlossMassMatrix "mass matrix" and a right hand side vector along the boundary. |
| 358 |
* |
| 359 |
* The matrix is assumed to already be initialized with a suiting sparsity |
| 360 |
* pattern (the DoFHandler provides an appropriate function). |
| 361 |
* |
| 362 |
* If the library is configured to use multithreading, this function works |
| 363 |
* in parallel. |
| 364 |
* |
| 365 |
* @arg @p weight: an optional weight for the computation of the mass |
| 366 |
* matrix. If no weight is given, it is set to one. |
| 367 |
* In case you want to specify @p component_mapping and use the default argument |
| 368 |
* for the coefficient you have to specify the (unused) coefficient argument |
| 369 |
* as <code>(const Function <spacedim,number> *const)nullptr</code>. |
| 370 |
* |
| 371 |
* @arg @p component_mapping: if the components in @p boundary_functions and |
| 372 |
* @p dof do not coincide, this vector allows them to be remapped. If the |
| 373 |
* vector is not empty, it has to have one entry for each component in @p |
| 374 |
* dof. This entry is the component number in @p boundary_functions that |
| 375 |
* should be used for this component in @p dof. By default, no remapping is |
| 376 |
* applied. |
| 377 |
* |
| 378 |
* @todo This function does not work for finite elements with cell-dependent |
| 379 |
* shape functions. |
| 380 |
*/ |
| 381 |
template <int dim, int spacedim, typename number> |
| 382 |
void |
| 383 |
create_boundary_mass_matrix( |
| 384 |
const Mapping<dim, spacedim> &mapping, |
| 385 |
const DoFHandler<dim, spacedim> &dof, |
| 386 |
const Quadrature<dim - 1> &q, |
| 387 |
SparseMatrix<number> &matrix, |
| 388 |
const std::map<types::boundary_id, const Function<spacedim, number> *> |
| 389 |
&boundary_functions, |
| 390 |
Vector<number> &rhs_vector, |
| 391 |
std::vector<types::global_dof_index> &dof_to_boundary_mapping, |
| 392 |
const Function<spacedim, number> *const weight = 0, |
| 393 |
std::vector<unsigned int> component_mapping = {}); |
| 394 |
|
| 395 |
|
| 396 |
/** |
| 397 |
* Call the create_boundary_mass_matrix() function, see above, with |
| 398 |
* <tt>mapping=MappingQ@<dim@>(1)</tt>. |
| 399 |
*/ |
| 400 |
template <int dim, int spacedim, typename number> |
| 401 |
void |
| 402 |
create_boundary_mass_matrix( |
| 403 |
const DoFHandler<dim, spacedim> &dof, |
| 404 |
const Quadrature<dim - 1> &q, |
| 405 |
SparseMatrix<number> &matrix, |
| 406 |
const std::map<types::boundary_id, const Function<spacedim, number> *> |
| 407 |
&boundary_functions, |
| 408 |
Vector<number> &rhs_vector, |
| 409 |
std::vector<types::global_dof_index> &dof_to_boundary_mapping, |
| 410 |
const Function<spacedim, number> *const a = nullptr, |
| 411 |
std::vector<unsigned int> component_mapping = {}); |
| 412 |
|
| 413 |
/** |
| 414 |
* Same function as above, but for hp-objects. |
| 415 |
*/ |
| 416 |
template <int dim, int spacedim, typename number> |
| 417 |
void |
| 418 |
create_boundary_mass_matrix( |
| 419 |
const hp::MappingCollection<dim, spacedim> &mapping, |
| 420 |
const DoFHandler<dim, spacedim> &dof, |
| 421 |
const hp::QCollection<dim - 1> &q, |
| 422 |
SparseMatrix<number> &matrix, |
| 423 |
const std::map<types::boundary_id, const Function<spacedim, number> *> |
| 424 |
&boundary_functions, |
| 425 |
Vector<number> &rhs_vector, |
| 426 |
std::vector<types::global_dof_index> &dof_to_boundary_mapping, |
| 427 |
const Function<spacedim, number> *const a = nullptr, |
| 428 |
std::vector<unsigned int> component_mapping = {}); |
| 429 |
|
| 430 |
/** |
| 431 |
* Same function as above, but for hp-objects. |
| 432 |
*/ |
| 433 |
template <int dim, int spacedim, typename number> |
| 434 |
void |
| 435 |
create_boundary_mass_matrix( |
| 436 |
const DoFHandler<dim, spacedim> &dof, |
| 437 |
const hp::QCollection<dim - 1> &q, |
| 438 |
SparseMatrix<number> &matrix, |
| 439 |
const std::map<types::boundary_id, const Function<spacedim, number> *> |
| 440 |
&boundary_functions, |
| 441 |
Vector<number> &rhs_vector, |
| 442 |
std::vector<types::global_dof_index> &dof_to_boundary_mapping, |
| 443 |
const Function<spacedim, number> *const a = nullptr, |
| 444 |
std::vector<unsigned int> component_mapping = {}); |
| 445 |
|
| 446 |
/** |
| 447 |
* Assemble the Laplace matrix. If no coefficient is given (i.e., if the |
| 448 |
* pointer to a function object is zero as it is by default), the |
| 449 |
* coefficient is taken as being constant and equal to one. |
| 450 |
* In case you want to specify @p constraints and use the default argument |
| 451 |
* for the coefficient you have to specify the (unused) coefficient argument |
| 452 |
* as <code>(const Function<spacedim> *const)nullptr</code>. |
| 453 |
* |
| 454 |
* If the library is configured to use multithreading, this function works |
| 455 |
* in parallel. |
| 456 |
* |
| 457 |
* The optional argument @p constraints allows to apply constraints on the |
| 458 |
* resulting matrix directly. Note, however, that this becomes difficult |
| 459 |
* when you have inhomogeneous constraints and later want to add several |
| 460 |
* such matrices, for example in time dependent settings such as the main |
| 461 |
* loop of step-26. |
| 462 |
* |
| 463 |
* See the general documentation of this namespace for more information. |
| 464 |
*/ |
| 465 |
template <int dim, int spacedim, typename MatrixType> |
| 466 |
void |
| 467 |
create_laplace_matrix( |
| 468 |
const Mapping<dim, spacedim> &mapping, |
| 469 |
const DoFHandler<dim, spacedim> &dof, |
| 470 |
const Quadrature<dim> &q, |
| 471 |
MatrixType &matrix, |
| 472 |
const Function<spacedim, typename MatrixType::value_type> *const a = |
| 473 |
nullptr, |
| 474 |
const AffineConstraints<typename MatrixType::value_type> &constraints = |
| 475 |
AffineConstraints<typename MatrixType::value_type>()); |
| 476 |
|
| 477 |
/** |
| 478 |
* Call the create_laplace_matrix() function, see above, with |
| 479 |
* <tt>mapping=MappingQ@<dim@>(1)</tt>. |
| 480 |
*/ |
| 481 |
template <int dim, int spacedim, typename MatrixType> |
| 482 |
void |
| 483 |
create_laplace_matrix( |
| 484 |
const DoFHandler<dim, spacedim> &dof, |
| 485 |
const Quadrature<dim> &q, |
| 486 |
MatrixType &matrix, |
| 487 |
const Function<spacedim, typename MatrixType::value_type> *const a = |
| 488 |
nullptr, |
| 489 |
const AffineConstraints<typename MatrixType::value_type> &constraints = |
| 490 |
AffineConstraints<typename MatrixType::value_type>()); |
| 491 |
|
| 492 |
/** |
| 493 |
* Assemble the Laplace matrix and a right hand side vector. If no |
| 494 |
* coefficient is given, it is assumed to be constant one. |
| 495 |
* In case you want to specify @p constraints and use the default argument |
| 496 |
* for the coefficient you have to specify the (unused) coefficient argument |
| 497 |
* as <code>(const Function<spacedim> *const)nullptr</code>. |
| 498 |
* |
| 499 |
* If the library is configured to use multithreading, this function works |
| 500 |
* in parallel. |
| 501 |
* |
| 502 |
* The optional argument @p constraints allows to apply constraints on the |
| 503 |
* resulting matrix directly. Note, however, that this becomes difficult |
| 504 |
* when you have inhomogeneous constraints and later want to add several |
| 505 |
* such matrices, for example in time dependent settings such as the main |
| 506 |
* loop of step-26. |
| 507 |
* |
| 508 |
* See the general documentation of this namespace for more information. |
| 509 |
*/ |
| 510 |
template <int dim, int spacedim, typename MatrixType> |
| 511 |
void |
| 512 |
create_laplace_matrix( |
| 513 |
const Mapping<dim, spacedim> &mapping, |
| 514 |
const DoFHandler<dim, spacedim> &dof, |
| 515 |
const Quadrature<dim> &q, |
| 516 |
MatrixType &matrix, |
| 517 |
const Function<spacedim, typename MatrixType::value_type> &rhs, |
| 518 |
Vector<typename MatrixType::value_type> &rhs_vector, |
| 519 |
const Function<spacedim, typename MatrixType::value_type> *const a = |
| 520 |
nullptr, |
| 521 |
const AffineConstraints<typename MatrixType::value_type> &constraints = |
| 522 |
AffineConstraints<typename MatrixType::value_type>()); |
| 523 |
|
| 524 |
/** |
| 525 |
* Call the create_laplace_matrix() function, see above, with |
| 526 |
* <tt>mapping=MappingQ@<dim@>(1)</tt>. |
| 527 |
*/ |
| 528 |
template <int dim, int spacedim, typename MatrixType> |
| 529 |
void |
| 530 |
create_laplace_matrix( |
| 531 |
const DoFHandler<dim, spacedim> &dof, |
| 532 |
const Quadrature<dim> &q, |
| 533 |
MatrixType &matrix, |
| 534 |
const Function<spacedim, typename MatrixType::value_type> &rhs, |
| 535 |
Vector<typename MatrixType::value_type> &rhs_vector, |
| 536 |
const Function<spacedim, typename MatrixType::value_type> *const a = |
| 537 |
nullptr, |
| 538 |
const AffineConstraints<typename MatrixType::value_type> &constraints = |
| 539 |
AffineConstraints<typename MatrixType::value_type>()); |
| 540 |
|
| 541 |
/** |
| 542 |
* Like the functions above, but for hp-objects. |
| 543 |
*/ |
| 544 |
template <int dim, int spacedim, typename MatrixType> |
| 545 |
void |
| 546 |
create_laplace_matrix( |
| 547 |
const hp::MappingCollection<dim, spacedim> &mapping, |
| 548 |
const DoFHandler<dim, spacedim> &dof, |
| 549 |
const hp::QCollection<dim> &q, |
| 550 |
MatrixType &matrix, |
| 551 |
const Function<spacedim, typename MatrixType::value_type> *const a = |
| 552 |
nullptr, |
| 553 |
const AffineConstraints<typename MatrixType::value_type> &constraints = |
| 554 |
AffineConstraints<typename MatrixType::value_type>()); |
| 555 |
|
| 556 |
/** |
| 557 |
* Like the functions above, but for hp-objects. |
| 558 |
*/ |
| 559 |
template <int dim, int spacedim, typename MatrixType> |
| 560 |
void |
| 561 |
create_laplace_matrix( |
| 562 |
const DoFHandler<dim, spacedim> &dof, |
| 563 |
const hp::QCollection<dim> &q, |
| 564 |
MatrixType &matrix, |
| 565 |
const Function<spacedim, typename MatrixType::value_type> *const a = |
| 566 |
nullptr, |
| 567 |
const AffineConstraints<typename MatrixType::value_type> &constraints = |
| 568 |
AffineConstraints<typename MatrixType::value_type>()); |
| 569 |
|
| 570 |
/** |
| 571 |
* Like the functions above, but for hp-objects. |
| 572 |
*/ |
| 573 |
template <int dim, int spacedim, typename MatrixType> |
| 574 |
void |
| 575 |
create_laplace_matrix( |
| 576 |
const hp::MappingCollection<dim, spacedim> &mapping, |
| 577 |
const DoFHandler<dim, spacedim> &dof, |
| 578 |
const hp::QCollection<dim> &q, |
| 579 |
MatrixType &matrix, |
| 580 |
const Function<spacedim, typename MatrixType::value_type> &rhs, |
| 581 |
Vector<typename MatrixType::value_type> &rhs_vector, |
| 582 |
const Function<spacedim, typename MatrixType::value_type> *const a = |
| 583 |
nullptr, |
| 584 |
const AffineConstraints<typename MatrixType::value_type> &constraints = |
| 585 |
AffineConstraints<typename MatrixType::value_type>()); |
| 586 |
|
| 587 |
/** |
| 588 |
* Like the functions above, but for hp-objects. |
| 589 |
*/ |
| 590 |
template <int dim, int spacedim, typename MatrixType> |
| 591 |
void |
| 592 |
create_laplace_matrix( |
| 593 |
const DoFHandler<dim, spacedim> &dof, |
| 594 |
const hp::QCollection<dim> &q, |
| 595 |
MatrixType &matrix, |
| 596 |
const Function<spacedim, typename MatrixType::value_type> &rhs, |
| 597 |
Vector<typename MatrixType::value_type> &rhs_vector, |
| 598 |
const Function<spacedim, typename MatrixType::value_type> *const a = |
| 599 |
nullptr, |
| 600 |
const AffineConstraints<typename MatrixType::value_type> &constraints = |
| 601 |
AffineConstraints<typename MatrixType::value_type>()); |
| 602 |
|
| 603 |
/** |
| 604 |
* Exception |
| 605 |
*/ |
| 606 |
DeclExceptionMsg(ExcComponentMismatch, |
| 607 |
"You are providing either a right hand side function or a " |
| 608 |
"coefficient with a number of vector components that is " |
| 609 |
"inconsistent with the rest of the arguments. If you do " |
| 610 |
"provide a coefficient or right hand side function, then " |
| 611 |
"it either needs to have as many components as the finite " |
| 612 |
"element in use, or only a single vector component. In " |
| 613 |
"the latter case, the same value will be taken for " |
| 614 |
"each vector component of the finite element."); |
| 615 |
} // namespace MatrixCreator |
| 616 |
|
| 617 |
|
| 618 |
DEAL_II_NAMESPACE_CLOSE |
| 619 |
|
| 620 |
#endif |