Debian Codegraph @

include/deal.II/fe/fe_values_views.h

raw
1 // ------------------------------------------------------------------------
2 //
3 // SPDX-License-Identifier: LGPL-2.1-or-later
4 // Copyright (C) 2023 - 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_fe_values_views_h
16 #define dealii_fe_values_views_h
17
18 #include <deal.II/base/config.h>
19
20 #include <deal.II/base/exceptions.h>
21 #include <deal.II/base/lazy.h>
22 #include <deal.II/base/observer_pointer.h>
23 #include <deal.II/base/symmetric_tensor.h>
24 #include <deal.II/base/tensor.h>
25
26 #include <deal.II/fe/fe_update_flags.h>
27 #include <deal.II/fe/fe_values_extractors.h>
28
29 #include <deal.II/lac/read_vector.h>
30
31 #include <type_traits>
32 #include <vector>
33
34 DEAL_II_NAMESPACE_OPEN
35
36 // Forward declaration
37 #ifndef DOXYGEN
38 template <int dim, int spacedim = dim>
39 class FEValuesBase;
40 #endif
41
42 namespace internal
43 {
44 /**
45 * A class whose specialization is used to define what type the curl of a
46 * vector valued function corresponds to.
47 */
48 template <int dim, typename NumberType = double>
49 struct CurlType;
50
51 /**
52 * A class whose specialization is used to define what type the curl of a
53 * vector valued function corresponds to.
54 *
55 * In 1d, the curl is a scalar.
56 */
57 template <typename NumberType>
58 struct CurlType<1, NumberType>
59 {
60 using type = Tensor<1, 1, NumberType>;
61 };
62
63 /**
64 * A class whose specialization is used to define what type the curl of a
65 * vector valued function corresponds to.
66 *
67 * In 2d, the curl is a scalar.
68 */
69 template <typename NumberType>
70 struct CurlType<2, NumberType>
71 {
72 using type = Tensor<1, 1, NumberType>;
73 };
74
75 /**
76 * A class whose specialization is used to define what type the curl of a
77 * vector valued function corresponds to.
78 *
79 * In 3d, the curl is a vector.
80 */
81 template <typename NumberType>
82 struct CurlType<3, NumberType>
83 {
84 using type = Tensor<1, 3, NumberType>;
85 };
86 } // namespace internal
87
88
89
90 /**
91 * A namespace for "views" on a FEValues, FEFaceValues, or FESubfaceValues
92 * object. A view represents only a certain part of the whole: whereas the
93 * FEValues object represents <i>all</i> values, gradients, or second
94 * derivatives of all components of a vector-valued element, views restrict
95 * the attention to only a single component or a subset of components. You
96 * typically get objects of classes defined in this namespace by applying
97 * FEValuesExtractors objects to a FEValues, FEFaceValues or FESubfaceValues
98 * objects using the square bracket operator.
99 *
100 * There are classes that present views for single scalar components, vector
101 * components consisting of <code>dim</code> elements, and symmetric second
102 * order tensor components consisting of <code>(dim*dim + dim)/2</code>
103 * elements
104 *
105 * See the description of the
106 * @ref vector_valued
107 * topic for examples how to use the features of this namespace.
108 *
109 * @ingroup feaccess vector_valued
110 */
111 namespace FEValuesViews
112 {
113 /**
114 * A class representing a view to a single scalar component of a possibly
115 * vector-valued finite element. Views are discussed in the
116 * @ref vector_valued
117 * topic.
118 *
119 * You get an object of this type if you apply a FEValuesExtractors::Scalar
120 * to an FEValues, FEFaceValues or FESubfaceValues object.
121 *
122 * @ingroup feaccess vector_valued
123 */
124 template <int dim, int spacedim = dim>
125 class Scalar
126 {
127 public:
128 /**
129 * An alias for the data type of values of the view this class
130 * represents. Since we deal with a single components, the value type is a
131 * scalar double.
132 */
133 using value_type = double;
134
135 /**
136 * An alias for the type of gradients of the view this class represents.
137 * Here, for a scalar component of the finite element, the gradient is a
138 * <code>Tensor@<1,dim@></code>.
139 */
140 using gradient_type = dealii::Tensor<1, spacedim>;
141
142 /**
143 * An alias for the type of second derivatives of the view this class
144 * represents. Here, for a scalar component of the finite element, the
145 * Hessian is a <code>Tensor@<2,dim@></code>.
146 */
147 using hessian_type = dealii::Tensor<2, spacedim>;
148
149 /**
150 * An alias for the type of third derivatives of the view this class
151 * represents. Here, for a scalar component of the finite element, the
152 * Third derivative is a <code>Tensor@<3,dim@></code>.
153 */
154 using third_derivative_type = dealii::Tensor<3, spacedim>;
155
156 /**
157 * An alias for the data type of the product of a @p Number and the
158 * values of the view this class provides. This is the data type of
159 * scalar components of a finite element field whose degrees of
160 * freedom are described by a vector with elements of type @p Number.
161 */
162 template <typename Number>
163 using solution_value_type = typename ProductType<Number, value_type>::type;
164
165 /**
166 * An alias for the data type of the product of a @p Number and the
167 * gradients of the view this class provides. This is the data type of
168 * scalar components of a finite element field whose degrees of
169 * freedom are described by a vector with elements of type @p Number.
170 */
171 template <typename Number>
172 using solution_gradient_type =
173 typename ProductType<Number, gradient_type>::type;
174
175 /**
176 * An alias for the data type of the product of a @p Number and the
177 * laplacians of the view this class provides. This is the data type of
178 * scalar components of a finite element field whose degrees of
179 * freedom are described by a vector with elements of type @p Number.
180 */
181 template <typename Number>
182 using solution_laplacian_type =
183 typename ProductType<Number, value_type>::type;
184
185 /**
186 * An alias for the data type of the product of a @p Number and the
187 * hessians of the view this class provides. This is the data type of
188 * scalar components of a finite element field whose degrees of
189 * freedom are described by a vector with elements of type @p Number.
190 */
191 template <typename Number>
192 using solution_hessian_type =
193 typename ProductType<Number, hessian_type>::type;
194
195 /**
196 * An alias for the data type of the product of a @p Number and the
197 * third derivatives of the view this class provides. This is the data type
198 * of scalar components of a finite element field whose degrees of
199 * freedom are described by a vector with elements of type @p Number.
200 */
201 template <typename Number>
202 using solution_third_derivative_type =
203 typename ProductType<Number, third_derivative_type>::type;
204
205 /**
206 * A structure where for each shape function we pre-compute a bunch of
207 * data that will make later accesses much cheaper.
208 */
209 struct ShapeFunctionData
210 {
211 /**
212 * For each shape function, store whether the selected vector component
213 * may be nonzero. For primitive shape functions we know for sure
214 * whether a certain scalar component of a given shape function is
215 * nonzero, whereas for non-primitive shape functions this may not be
216 * entirely clear (e.g. for RT elements it depends on the shape of a
217 * cell).
218 */
219 bool is_nonzero_shape_function_component;
220
221 /**
222 * For each shape function, store the row index within the shape_values,
223 * shape_gradients, and shape_hessians tables (the column index is the
224 * quadrature point index). If the shape function is primitive, then we
225 * can get this information from the shape_function_to_row_table of the
226 * FEValues object; otherwise, we have to work a bit harder to compute
227 * this information.
228 */
229 unsigned int row_index;
230 };
231
232 /**
233 * Default constructor. Creates an invalid object.
234 */
235 Scalar();
236
237 /**
238 * Constructor for an object that represents a single scalar component of
239 * a FEValuesBase object (or of one of the classes derived from
240 * FEValuesBase).
241 */
242 Scalar(const FEValuesBase<dim, spacedim> &fe_values_base,
243 const unsigned int component);
244
245 /**
246 * Copy constructor. This is not a lightweight object so we don't allow
247 * copying and generate a compile-time error if this function is called.
248 */
249 Scalar(const Scalar<dim, spacedim> &) = delete;
250
251 /**
252 * Move constructor.
253 */
254 // NOLINTNEXTLINE OSX does not compile with noexcept
255 Scalar(Scalar<dim, spacedim> &&) = default;
256
257 /**
258 * Destructor.
259 */
260 ~Scalar() = default;
261
262 /**
263 * Copy operator. This is not a lightweight object so we don't allow
264 * copying and generate a compile-time error if this function is called.
265 */
266 Scalar &
267 operator=(const Scalar<dim, spacedim> &) = delete;
268
269 /**
270 * Move assignment operator.
271 */
272 Scalar &
273 operator=(Scalar<dim, spacedim> &&) noexcept = default;
274
275 /**
276 * Return the value of the vector component selected by this view, for the
277 * shape function and quadrature point selected by the arguments.
278 *
279 * @param shape_function Number of the shape function to be evaluated.
280 * Note that this number runs from zero to dofs_per_cell, even in the case
281 * of an FEFaceValues or FESubfaceValues object.
282 *
283 * @param q_point Number of the quadrature point at which function is to
284 * be evaluated.
285 *
286 * @dealiiRequiresUpdateFlags{update_values}
287 */
288 value_type
289 value(const unsigned int shape_function, const unsigned int q_point) const;
290
291 /**
292 * Return the gradient (a tensor of rank 1) of the vector component
293 * selected by this view, for the shape function and quadrature point
294 * selected by the arguments.
295 *
296 * @note The meaning of the arguments is as documented for the value()
297 * function.
298 *
299 * @dealiiRequiresUpdateFlags{update_gradients}
300 */
301 gradient_type
302 gradient(const unsigned int shape_function,
303 const unsigned int q_point) const;
304
305 /**
306 * Return the Hessian (the tensor of rank 2 of all second derivatives) of
307 * the vector component selected by this view, for the shape function and
308 * quadrature point selected by the arguments.
309 *
310 * @note The meaning of the arguments is as documented for the value()
311 * function.
312 *
313 * @dealiiRequiresUpdateFlags{update_hessians}
314 */
315 hessian_type
316 hessian(const unsigned int shape_function,
317 const unsigned int q_point) const;
318
319 /**
320 * Return the tensor of rank 3 of all third derivatives of the vector
321 * component selected by this view, for the shape function and quadrature
322 * point selected by the arguments.
323 *
324 * @note The meaning of the arguments is as documented for the value()
325 * function.
326 *
327 * @dealiiRequiresUpdateFlags{update_third_derivatives}
328 */
329 third_derivative_type
330 third_derivative(const unsigned int shape_function,
331 const unsigned int q_point) const;
332
333 /**
334 * Return the values of the selected scalar component of the finite
335 * element function characterized by <tt>fe_function</tt> at the
336 * quadrature points of the cell, face or subface selected the last time
337 * the <tt>reinit</tt> function of the FEValues object was called.
338 *
339 * This function is the equivalent of the
340 * FEValuesBase::get_function_values function but it only works on the
341 * selected scalar component.
342 *
343 * The data type stored by the output vector must be what you get when you
344 * multiply the values of shape functions (i.e., @p value_type) times the
345 * type used to store the values of the unknowns $U_j$ of your finite
346 * element vector $U$ (represented by the @p fe_function argument).
347 *
348 * @dealiiRequiresUpdateFlags{update_values}
349 */
350 template <typename Number>
351 void
352 get_function_values(const ReadVector<Number> &fe_function,
353 std::vector<solution_value_type<Number>> &values) const;
354
355 /**
356 * Same as above, but using a vector of local degree-of-freedom values. In
357 * other words, instead of extracting the nodal values of the degrees of
358 * freedom located on the current cell from a global vector associated with
359 * a DoFHandler object (as the function above does), this function instead
360 * takes these local nodal values through its first argument. A typical
361 * way to obtain such a vector is by calling code such as
362 * @code
363 * cell->get_dof_values (dof_values, local_dof_values);
364 * @endcode
365 * (See DoFCellAccessor::get_dof_values() for more information on this
366 * function.) The point of the current function is then that one could
367 * modify these local values first, for example by applying a limiter
368 * or by ensuring that all nodal values are positive, before evaluating
369 * the finite element field that corresponds to these local values on the
370 * current cell. Another application is where one wants to postprocess
371 * the solution on a cell into a different finite element space on every
372 * cell, without actually creating a corresponding DoFHandler -- in that
373 * case, all one would compute is a local representation of that
374 * postprocessed function, characterized by its nodal values; this function
375 * then allows the evaluation of that representation at quadrature points.
376 *
377 * @param[in] dof_values A vector of local nodal values. This vector must
378 * have a length equal to number of DoFs on the current cell, and must
379 * be ordered in the same order as degrees of freedom are numbered on
380 * the reference cell.
381 *
382 * @param[out] values A vector of values of the given finite element field,
383 * at the quadrature points on the current object.
384 *
385 * @tparam InputVector The @p InputVector type must allow creation
386 * of an ArrayView object from it; this is satisfied by the
387 * `std::vector` class, among others.
388 */
389 template <class InputVector>
390 void
391 get_function_values_from_local_dof_values(
392 const InputVector &dof_values,
393 std::vector<solution_value_type<typename InputVector::value_type>>
394 &values) const;
395
396 /**
397 * Return the gradients of the selected scalar component of the finite
398 * element function characterized by <tt>fe_function</tt> at the
399 * quadrature points of the cell, face or subface selected the last time
400 * the <tt>reinit</tt> function of the FEValues object was called.
401 *
402 * This function is the equivalent of the
403 * FEValuesBase::get_function_gradients function but it only works on the
404 * selected scalar component.
405 *
406 * The data type stored by the output vector must be what you get when you
407 * multiply the gradients of shape functions (i.e., @p gradient_type)
408 * times the type used to store the values of the unknowns $U_j$ of your
409 * finite element vector $U$ (represented by the @p fe_function argument).
410 *
411 * @dealiiRequiresUpdateFlags{update_gradients}
412 */
413 template <typename Number>
414 void
415 get_function_gradients(
416 const ReadVector<Number> &fe_function,
417 std::vector<solution_gradient_type<Number>> &gradients) const;
418
419 /**
420 * This function relates to get_function_gradients() in the same way
421 * as get_function_values_from_local_dof_values() relates to
422 * get_function_values(). See the documentation of
423 * get_function_values_from_local_dof_values() for more information.
424 */
425 template <class InputVector>
426 void
427 get_function_gradients_from_local_dof_values(
428 const InputVector &dof_values,
429 std::vector<solution_gradient_type<typename InputVector::value_type>>
430 &gradients) const;
431
432 /**
433 * Return the Hessians of the selected scalar component of the finite
434 * element function characterized by <tt>fe_function</tt> at the
435 * quadrature points of the cell, face or subface selected the last time
436 * the <tt>reinit</tt> function of the FEValues object was called.
437 *
438 * This function is the equivalent of the
439 * FEValuesBase::get_function_hessians function but it only works on the
440 * selected scalar component.
441 *
442 * The data type stored by the output vector must be what you get when you
443 * multiply the Hessians of shape functions (i.e., @p hessian_type) times
444 * the type used to store the values of the unknowns $U_j$ of your finite
445 * element vector $U$ (represented by the @p fe_function argument).
446 *
447 * @dealiiRequiresUpdateFlags{update_hessians}
448 */
449 template <typename Number>
450 void
451 get_function_hessians(
452 const ReadVector<Number> &fe_function,
453 std::vector<solution_hessian_type<Number>> &hessians) const;
454
455 /**
456 * This function relates to get_function_hessians() in the same way
457 * as get_function_values_from_local_dof_values() relates to
458 * get_function_values(). See the documentation of
459 * get_function_values_from_local_dof_values() for more information.
460 */
461 template <class InputVector>
462 void
463 get_function_hessians_from_local_dof_values(
464 const InputVector &dof_values,
465 std::vector<solution_hessian_type<typename InputVector::value_type>>
466 &hessians) const;
467
468
469 /**
470 * Return the Laplacians of the selected scalar component of the finite
471 * element function characterized by <tt>fe_function</tt> at the
472 * quadrature points of the cell, face or subface selected the last time
473 * the <tt>reinit</tt> function of the FEValues object was called. The
474 * Laplacians are the trace of the Hessians.
475 *
476 * This function is the equivalent of the
477 * FEValuesBase::get_function_laplacians function but it only works on the
478 * selected scalar component.
479 *
480 * The data type stored by the output vector must be what you get when you
481 * multiply the Laplacians of shape functions (i.e., @p value_type) times
482 * the type used to store the values of the unknowns $U_j$ of your finite
483 * element vector $U$ (represented by the @p fe_function argument).
484 *
485 * @dealiiRequiresUpdateFlags{update_hessians}
486 */
487 template <typename Number>
488 void
489 get_function_laplacians(
490 const ReadVector<Number> &fe_function,
491 std::vector<solution_laplacian_type<Number>> &laplacians) const;
492
493 /**
494 * This function relates to get_function_laplacians() in the same way
495 * as get_function_values_from_local_dof_values() relates to
496 * get_function_values(). See the documentation of
497 * get_function_values_from_local_dof_values() for more information.
498 */
499 template <class InputVector>
500 void
501 get_function_laplacians_from_local_dof_values(
502 const InputVector &dof_values,
503 std::vector<solution_laplacian_type<typename InputVector::value_type>>
504 &laplacians) const;
505
506
507 /**
508 * Return the third derivatives of the selected scalar component of the
509 * finite element function characterized by <tt>fe_function</tt> at the
510 * quadrature points of the cell, face or subface selected the last time
511 * the <tt>reinit</tt> function of the FEValues object was called.
512 *
513 * This function is the equivalent of the
514 * FEValuesBase::get_function_third_derivatives function but it only works
515 * on the selected scalar component.
516 *
517 * The data type stored by the output vector must be what you get when you
518 * multiply the third derivatives of shape functions (i.e., @p
519 * third_derivative_type) times the type used to store the values of the
520 * unknowns $U_j$ of your finite element vector $U$ (represented by the @p
521 * fe_function argument).
522 *
523 * @dealiiRequiresUpdateFlags{update_third_derivatives}
524 */
525 template <typename Number>
526 void
527 get_function_third_derivatives(
528 const ReadVector<Number> &fe_function,
529 std::vector<solution_third_derivative_type<Number>> &third_derivatives)
530 const;
531
532 /**
533 * This function relates to get_function_third_derivatives() in the same way
534 * as get_function_values_from_local_dof_values() relates to
535 * get_function_values(). See the documentation of
536 * get_function_values_from_local_dof_values() for more information.
537 */
538 template <class InputVector>
539 void
540 get_function_third_derivatives_from_local_dof_values(
541 const InputVector &dof_values,
542 std::vector<
543 solution_third_derivative_type<typename InputVector::value_type>>
544 &third_derivatives) const;
545
546
547 private:
548 /**
549 * A pointer to the FEValuesBase object we operate on.
550 */
551 ObserverPointer<const FEValuesBase<dim, spacedim>> fe_values;
552
553 /**
554 * The single scalar component this view represents of the FEValuesBase
555 * object.
556 */
557 unsigned int component;
558
559 /**
560 * Store the data about shape functions.
561 */
562 std::vector<ShapeFunctionData> shape_function_data;
563 };
564
565
566
567 /**
568 * A class representing a view to a set of <code>spacedim</code> components
569 * forming a vector part of a vector-valued finite element. Views are
570 * discussed in the
571 * @ref vector_valued
572 * topic.
573 *
574 * Note that in the current context, a vector is meant in the sense physics
575 * uses it: it has <code>spacedim</code> components that behave in specific
576 * ways under coordinate system transformations. Examples include velocity
577 * or displacement fields. This is opposed to how mathematics uses the word
578 * "vector" (and how we use this word in other contexts in the library, for
579 * example in the Vector class), where it really stands for a collection of
580 * numbers. An example of this latter use of the word could be the set of
581 * concentrations of chemical species in a flame; however, these are really
582 * just a collection of scalar variables, since they do not change if the
583 * coordinate system is rotated, unlike the components of a velocity vector,
584 * and consequently, this class should not be used for this context.
585 *
586 * This class allows to query the value, gradient and divergence of
587 * (components of) shape functions and solutions representing vectors. The
588 * gradient of a vector $d_{k}, 0\le k<\text{dim}$ is defined as $S_{ij} =
589 * \frac{\partial d_{i}}{\partial x_j}, 0\le i,j<\text{dim}$.
590 *
591 * You get an object of this type if you apply a FEValuesExtractors::Vector
592 * to an FEValues, FEFaceValues or FESubfaceValues object.
593 *
594 * @ingroup feaccess vector_valued
595 */
596 template <int dim, int spacedim = dim>
597 class Vector
598 {
599 public:
600 /**
601 * An alias for the data type of values of the view this class
602 * represents. Since we deal with a set of <code>dim</code> components,
603 * the value type is a Tensor<1,spacedim>.
604 */
605 using value_type = dealii::Tensor<1, spacedim>;
606
607 /**
608 * An alias for the type of gradients of the view this class represents.
609 * Here, for a set of <code>dim</code> components of the finite element,
610 * the gradient is a <code>Tensor@<2,spacedim@></code>.
611 *
612 * See the general documentation of this class for how exactly the
613 * gradient of a vector is defined.
614 */
615 using gradient_type = dealii::Tensor<2, spacedim>;
616
617 /**
618 * An alias for the type of symmetrized gradients of the view this class
619 * represents. Here, for a set of <code>dim</code> components of the
620 * finite element, the symmetrized gradient is a
621 * <code>SymmetricTensor@<2,spacedim@></code>.
622 *
623 * The symmetric gradient of a vector field $\mathbf v$ is defined as
624 * $\varepsilon(\mathbf v)=\frac 12 (\nabla \mathbf v + \nabla \mathbf
625 * v^T)$.
626 */
627 using symmetric_gradient_type = dealii::SymmetricTensor<2, spacedim>;
628
629 /**
630 * An alias for the type of the divergence of the view this class
631 * represents. Here, for a set of <code>dim</code> components of the
632 * finite element, the divergence of course is a scalar.
633 */
634 using divergence_type = double;
635
636 /**
637 * An alias for the type of the curl of the view this class represents.
638 * Here, for a set of <code>spacedim=2</code> components of the finite
639 * element, the curl is a <code>Tensor@<1, 1@></code>. For
640 * <code>spacedim=3</code> it is a <code>Tensor@<1, dim@></code>.
641 */
642 using curl_type = typename dealii::internal::CurlType<spacedim>::type;
643
644 /**
645 * An alias for the type of second derivatives of the view this class
646 * represents. Here, for a set of <code>dim</code> components of the
647 * finite element, the Hessian is a <code>Tensor@<3,dim@></code>.
648 */
649 using hessian_type = dealii::Tensor<3, spacedim>;
650
651 /**
652 * An alias for the type of third derivatives of the view this class
653 * represents. Here, for a set of <code>dim</code> components of the
654 * finite element, the third derivative is a <code>Tensor@<4,dim@></code>.
655 */
656 using third_derivative_type = dealii::Tensor<4, spacedim>;
657
658 /**
659 * An alias for the data type of the product of a @p Number and the
660 * values of the view this class provides. This is the data type of
661 * vector components of a finite element field whose degrees of
662 * freedom are described by a vector with elements of type @p Number.
663 */
664 template <typename Number>
665 using solution_value_type = typename ProductType<Number, value_type>::type;
666
667 /**
668 * An alias for the data type of the product of a @p Number and the
669 * gradients of the view this class provides. This is the data type of
670 * vector components of a finite element field whose degrees of
671 * freedom are described by a vector with elements of type @p Number.
672 */
673 template <typename Number>
674 using solution_gradient_type =
675 typename ProductType<Number, gradient_type>::type;
676
677 /**
678 * An alias for the data type of the product of a @p Number and the
679 * symmetric gradients of the view this class provides. This is the data
680 * type of vector components of a finite element field whose degrees of
681 * freedom are described by a vector with elements of type @p Number.
682 */
683 template <typename Number>
684 using solution_symmetric_gradient_type =
685 typename ProductType<Number, symmetric_gradient_type>::type;
686
687 /**
688 * An alias for the data type of the product of a @p Number and the
689 * divergences of the view this class provides. This is the data type of
690 * vector components of a finite element field whose degrees of
691 * freedom are described by a vector with elements of type @p Number.
692 */
693 template <typename Number>
694 using solution_divergence_type =
695 typename ProductType<Number, divergence_type>::type;
696
697 /**
698 * An alias for the data type of the product of a @p Number and the
699 * laplacians of the view this class provides. This is the data type of
700 * vector components of a finite element field whose degrees of
701 * freedom are described by a vector with elements of type @p Number.
702 */
703 template <typename Number>
704 using solution_laplacian_type =
705 typename ProductType<Number, value_type>::type;
706
707 /**
708 * An alias for the data type of the product of a @p Number and the
709 * curls of the view this class provides. This is the data type of
710 * vector components of a finite element field whose degrees of
711 * freedom are described by a vector with elements of type @p Number.
712 */
713 template <typename Number>
714 using solution_curl_type = typename ProductType<Number, curl_type>::type;
715
716 /**
717 * An alias for the data type of the product of a @p Number and the
718 * hessians of the view this class provides. This is the data type of
719 * vector components of a finite element field whose degrees of
720 * freedom are described by a vector with elements of type @p Number.
721 */
722 template <typename Number>
723 using solution_hessian_type =
724 typename ProductType<Number, hessian_type>::type;
725
726 /**
727 * An alias for the data type of the product of a @p Number and the
728 * third derivatives of the view this class provides. This is the data type
729 * of vector components of a finite element field whose degrees of
730 * freedom are described by a vector with elements of type @p Number.
731 */
732 template <typename Number>
733 using solution_third_derivative_type =
734 typename ProductType<Number, third_derivative_type>::type;
735
736 /**
737 * A structure where for each shape function we pre-compute a bunch of
738 * data that will make later accesses much cheaper.
739 */
740 struct ShapeFunctionData
741 {
742 /**
743 * For each pair (shape function,component within vector), store whether
744 * the selected vector component may be nonzero. For primitive shape
745 * functions we know for sure whether a certain scalar component of a
746 * given shape function is nonzero, whereas for non-primitive shape
747 * functions this may not be entirely clear (e.g. for RT elements it
748 * depends on the shape of a cell).
749 */
750 bool is_nonzero_shape_function_component[spacedim];
751
752 /**
753 * For each pair (shape function, component within vector), store the
754 * row index within the shape_values, shape_gradients, and
755 * shape_hessians tables (the column index is the quadrature point
756 * index). If the shape function is primitive, then we can get this
757 * information from the shape_function_to_row_table of the FEValues
758 * object; otherwise, we have to work a bit harder to compute this
759 * information.
760 */
761 unsigned int row_index[spacedim];
762
763 /**
764 * For each shape function say the following: if only a single entry in
765 * is_nonzero_shape_function_component for this shape function is
766 * nonzero, then store the corresponding value of row_index and
767 * single_nonzero_component_index represents the index between 0 and dim
768 * for which it is attained. If multiple components are nonzero, then
769 * store -1. If no components are nonzero then store -2.
770 */
771 int single_nonzero_component;
772 unsigned int single_nonzero_component_index;
773 };
774
775 /**
776 * Default constructor. Creates an invalid object.
777 */
778 Vector();
779
780 /**
781 * Constructor for an object that represents dim components of a
782 * FEValuesBase object (or of one of the classes derived from
783 * FEValuesBase), representing a vector-valued variable.
784 *
785 * The second argument denotes the index of the first component of the
786 * selected vector.
787 */
788 Vector(const FEValuesBase<dim, spacedim> &fe_values_base,
789 const unsigned int first_vector_component);
790
791 /**
792 * Copy constructor. This is not a lightweight object so we don't allow
793 * copying and generate a compile-time error if this function is called.
794 */
795 Vector(const Vector<dim, spacedim> &) = delete;
796
797 /**
798 * Move constructor.
799 */
800 // NOLINTNEXTLINE OSX does not compile with noexcept
801 Vector(Vector<dim, spacedim> &&) = default;
802
803 /**
804 * Destructor.
805 */
806 ~Vector() = default;
807
808 /**
809 * Copy operator. This is not a lightweight object so we don't allow
810 * copying and generate a compile-time error if this function is called.
811 */
812 Vector &
813 operator=(const Vector<dim, spacedim> &) = delete;
814
815 /**
816 * Move assignment operator.
817 */
818 // NOLINTNEXTLINE OSX does not compile with noexcept
819 Vector &
820 operator=(Vector<dim, spacedim> &&) = default; // NOLINT
821
822 /**
823 * Return the value of the vector components selected by this view, for
824 * the shape function and quadrature point selected by the arguments.
825 * Here, since the view represents a vector-valued part of the FEValues
826 * object with <code>dim</code> components, the return type is a tensor of
827 * rank 1 with <code>dim</code> components.
828 *
829 * @param shape_function Number of the shape function to be evaluated.
830 * Note that this number runs from zero to dofs_per_cell, even in the case
831 * of an FEFaceValues or FESubfaceValues object.
832 *
833 * @param q_point Number of the quadrature point at which function is to
834 * be evaluated.
835 *
836 * @dealiiRequiresUpdateFlags{update_values}
837 */
838 value_type
839 value(const unsigned int shape_function, const unsigned int q_point) const;
840
841 /**
842 * Return the gradient (a tensor of rank 2) of the vector component
843 * selected by this view, for the shape function and quadrature point
844 * selected by the arguments.
845 *
846 * See the general documentation of this class for how exactly the
847 * gradient of a vector is defined.
848 *
849 * @note The meaning of the arguments is as documented for the value()
850 * function.
851 *
852 * @dealiiRequiresUpdateFlags{update_gradients}
853 */
854 gradient_type
855 gradient(const unsigned int shape_function,
856 const unsigned int q_point) const;
857
858 /**
859 * Return the symmetric gradient (a symmetric tensor of rank 2) of the
860 * vector component selected by this view, for the shape function and
861 * quadrature point selected by the arguments.
862 *
863 * The symmetric gradient is defined as $\frac 12 [(\nabla \phi_i(x_q)) +
864 * (\nabla \phi_i(x_q))^T]$, where $\phi_i$ represents the
865 * <code>dim</code> components selected from the FEValuesBase object, and
866 * $x_q$ is the location of the $q$-th quadrature point.
867 *
868 * @note The meaning of the arguments is as documented for the value()
869 * function.
870 *
871 * @dealiiRequiresUpdateFlags{update_gradients}
872 */
873 symmetric_gradient_type
874 symmetric_gradient(const unsigned int shape_function,
875 const unsigned int q_point) const;
876
877 /**
878 * Return the scalar divergence of the vector components selected by this
879 * view, for the shape function and quadrature point selected by the
880 * arguments.
881 *
882 * @note The meaning of the arguments is as documented for the value()
883 * function.
884 *
885 * @dealiiRequiresUpdateFlags{update_gradients}
886 */
887 divergence_type
888 divergence(const unsigned int shape_function,
889 const unsigned int q_point) const;
890
891 /**
892 * Return the vector curl of the vector components selected by this view,
893 * for the shape function and quadrature point selected by the arguments.
894 * For 1d this function does not make any sense. Thus it is not
895 * implemented for <code>spacedim=1</code>. In 2d the curl is defined as
896 * @f{equation*}{
897 * \operatorname{curl}(u) \dealcoloneq \frac{du_2}{dx} -\frac{du_1}{dy},
898 * @f}
899 * whereas in 3d it is given by
900 * @f{equation*}{
901 * \operatorname{curl}(u) \dealcoloneq \left( \begin{array}{c}
902 * \frac{du_3}{dy}-\frac{du_2}{dz}\\ \frac{du_1}{dz}-\frac{du_3}{dx}\\
903 * \frac{du_2}{dx}-\frac{du_1}{dy} \end{array} \right).
904 * @f}
905 *
906 * @note The meaning of the arguments is as documented for the value()
907 * function.
908 *
909 * @dealiiRequiresUpdateFlags{update_gradients}
910 */
911 curl_type
912 curl(const unsigned int shape_function, const unsigned int q_point) const;
913
914 /**
915 * Return the Hessian (the tensor of rank 2 of all second derivatives) of
916 * the vector components selected by this view, for the shape function and
917 * quadrature point selected by the arguments.
918 *
919 * @note The meaning of the arguments is as documented for the value()
920 * function.
921 *
922 * @dealiiRequiresUpdateFlags{update_hessians}
923 */
924 hessian_type
925 hessian(const unsigned int shape_function,
926 const unsigned int q_point) const;
927
928 /**
929 * Return the tensor of rank 3 of all third derivatives of the vector
930 * components selected by this view, for the shape function and quadrature
931 * point selected by the arguments.
932 *
933 * @note The meaning of the arguments is as documented for the value()
934 * function.
935 *
936 * @dealiiRequiresUpdateFlags{update_3rd_derivatives}
937 */
938 third_derivative_type
939 third_derivative(const unsigned int shape_function,
940 const unsigned int q_point) const;
941
942 /**
943 * Return the values of the selected vector components of the finite
944 * element function characterized by <tt>fe_function</tt> at the
945 * quadrature points of the cell, face or subface selected the last time
946 * the <tt>reinit</tt> function of the FEValues object was called.
947 *
948 * This function is the equivalent of the
949 * FEValuesBase::get_function_values function but it only works on the
950 * selected vector components.
951 *
952 * The data type stored by the output vector must be what you get when you
953 * multiply the values of shape functions (i.e., @p value_type) times the
954 * type used to store the values of the unknowns $U_j$ of your finite
955 * element vector $U$ (represented by the @p fe_function argument).
956 *
957 * @dealiiRequiresUpdateFlags{update_values}
958 */
959 template <typename Number>
960 void
961 get_function_values(const ReadVector<Number> &fe_function,
962 std::vector<solution_value_type<Number>> &values) const;
963
964 /**
965 * Same as above, but using a vector of local degree-of-freedom values. In
966 * other words, instead of extracting the nodal values of the degrees of
967 * freedom located on the current cell from a global vector associated with
968 * a DoFHandler object (as the function above does), this function instead
969 * takes these local nodal values through its first argument. A typical
970 * way to obtain such a vector is by calling code such as
971 * @code
972 * cell->get_dof_values (dof_values, local_dof_values);
973 * @endcode
974 * (See DoFCellAccessor::get_dof_values() for more information on this
975 * function.) The point of the current function is then that one could
976 * modify these local values first, for example by applying a limiter
977 * or by ensuring that all nodal values are positive, before evaluating
978 * the finite element field that corresponds to these local values on the
979 * current cell. Another application is where one wants to postprocess
980 * the solution on a cell into a different finite element space on every
981 * cell, without actually creating a corresponding DoFHandler -- in that
982 * case, all one would compute is a local representation of that
983 * postprocessed function, characterized by its nodal values; this function
984 * then allows the evaluation of that representation at quadrature points.
985 *
986 * @param[in] dof_values A vector of local nodal values. This vector must
987 * have a length equal to number of DoFs on the current cell, and must
988 * be ordered in the same order as degrees of freedom are numbered on
989 * the reference cell.
990 *
991 * @param[out] values A vector of values of the given finite element field,
992 * at the quadrature points on the current object.
993 *
994 * @tparam InputVector The @p InputVector type must allow creation
995 * of an ArrayView object from it; this is satisfied by the
996 * `std::vector` class, among others.
997 */
998 template <class InputVector>
999 void
1000 get_function_values_from_local_dof_values(
1001 const InputVector &dof_values,
1002 std::vector<solution_value_type<typename InputVector::value_type>>
1003 &values) const;
1004
1005 /**
1006 * Return the gradients of the selected vector components of the finite
1007 * element function characterized by <tt>fe_function</tt> at the
1008 * quadrature points of the cell, face or subface selected the last time
1009 * the <tt>reinit</tt> function of the FEValues object was called.
1010 *
1011 * This function is the equivalent of the
1012 * FEValuesBase::get_function_gradients function but it only works on the
1013 * selected vector components.
1014 *
1015 * The data type stored by the output vector must be what you get when you
1016 * multiply the gradients of shape functions (i.e., @p gradient_type)
1017 * times the type used to store the values of the unknowns $U_j$ of your
1018 * finite element vector $U$ (represented by the @p fe_function argument).
1019 *
1020 * @dealiiRequiresUpdateFlags{update_gradients}
1021 */
1022 template <typename Number>
1023 void
1024 get_function_gradients(
1025 const ReadVector<Number> &fe_function,
1026 std::vector<solution_gradient_type<Number>> &gradients) const;
1027
1028 /**
1029 * This function relates to get_function_gradients() in the same way
1030 * as get_function_values_from_local_dof_values() relates to
1031 * get_function_values(). See the documentation of
1032 * get_function_values_from_local_dof_values() for more information.
1033 */
1034 template <class InputVector>
1035 void
1036 get_function_gradients_from_local_dof_values(
1037 const InputVector &dof_values,
1038 std::vector<solution_gradient_type<typename InputVector::value_type>>
1039 &gradients) const;
1040
1041 /**
1042 * Return the symmetrized gradients of the selected vector components of
1043 * the finite element function characterized by <tt>fe_function</tt> at
1044 * the quadrature points of the cell, face or subface selected the last
1045 * time the <tt>reinit</tt> function of the FEValues object was called.
1046 *
1047 * The symmetric gradient of a vector field $\mathbf v$ is defined as
1048 * $\varepsilon(\mathbf v)=\frac 12 (\nabla \mathbf v + \nabla \mathbf
1049 * v^T)$.
1050 *
1051 * @note There is no equivalent function such as
1052 * FEValuesBase::get_function_symmetric_gradients in the FEValues classes
1053 * but the information can be obtained from
1054 * FEValuesBase::get_function_gradients, of course.
1055 *
1056 * The data type stored by the output vector must be what you get when you
1057 * multiply the symmetric gradients of shape functions (i.e., @p
1058 * symmetric_gradient_type) times the type used to store the values of the
1059 * unknowns $U_j$ of your finite element vector $U$ (represented by the @p
1060 * fe_function argument).
1061 *
1062 * @dealiiRequiresUpdateFlags{update_gradients}
1063 */
1064 template <typename Number>
1065 void
1066 get_function_symmetric_gradients(
1067 const ReadVector<Number> &fe_function,
1068 std::vector<solution_symmetric_gradient_type<Number>>
1069 &symmetric_gradients) const;
1070
1071 /**
1072 * This function relates to get_function_symmetric_gradients() in the same
1073 * way as get_function_values_from_local_dof_values() relates to
1074 * get_function_values(). See the documentation of
1075 * get_function_values_from_local_dof_values() for more information.
1076 */
1077 template <class InputVector>
1078 void
1079 get_function_symmetric_gradients_from_local_dof_values(
1080 const InputVector &dof_values,
1081 std::vector<
1082 solution_symmetric_gradient_type<typename InputVector::value_type>>
1083 &symmetric_gradients) const;
1084
1085 /**
1086 * Return the divergence of the selected vector components of the finite
1087 * element function characterized by <tt>fe_function</tt> at the
1088 * quadrature points of the cell, face or subface selected the last time
1089 * the <tt>reinit</tt> function of the FEValues object was called.
1090 *
1091 * There is no equivalent function such as
1092 * FEValuesBase::get_function_divergences in the FEValues classes but the
1093 * information can be obtained from FEValuesBase::get_function_gradients,
1094 * of course.
1095 *
1096 * The data type stored by the output vector must be what you get when you
1097 * multiply the divergences of shape functions (i.e., @p divergence_type)
1098 * times the type used to store the values of the unknowns $U_j$ of your
1099 * finite element vector $U$ (represented by the @p fe_function argument).
1100 *
1101 * @dealiiRequiresUpdateFlags{update_gradients}
1102 */
1103 template <typename Number>
1104 void
1105 get_function_divergences(
1106 const ReadVector<Number> &fe_function,
1107 std::vector<solution_divergence_type<Number>> &divergences) const;
1108
1109 /**
1110 * This function relates to get_function_divergences() in the same way
1111 * as get_function_values_from_local_dof_values() relates to
1112 * get_function_values(). See the documentation of
1113 * get_function_values_from_local_dof_values() for more information.
1114 */
1115 template <class InputVector>
1116 void
1117 get_function_divergences_from_local_dof_values(
1118 const InputVector &dof_values,
1119 std::vector<solution_divergence_type<typename InputVector::value_type>>
1120 &divergences) const;
1121
1122 /**
1123 * Return the curl of the selected vector components of the finite element
1124 * function characterized by <tt>fe_function</tt> at the quadrature points
1125 * of the cell, face or subface selected the last time the <tt>reinit</tt>
1126 * function of the FEValues object was called.
1127 *
1128 * There is no equivalent function such as
1129 * FEValuesBase::get_function_curls in the FEValues classes but the
1130 * information can be obtained from FEValuesBase::get_function_gradients,
1131 * of course.
1132 *
1133 * The data type stored by the output vector must be what you get when you
1134 * multiply the curls of shape functions (i.e., @p curl_type) times the
1135 * type used to store the values of the unknowns $U_j$ of your finite
1136 * element vector $U$ (represented by the @p fe_function argument).
1137 *
1138 * @dealiiRequiresUpdateFlags{update_gradients}
1139 */
1140 template <typename Number>
1141 void
1142 get_function_curls(const ReadVector<Number> &fe_function,
1143 std::vector<solution_curl_type<Number>> &curls) const;
1144
1145 /**
1146 * This function relates to get_function_curls() in the same way
1147 * as get_function_values_from_local_dof_values() relates to
1148 * get_function_values(). See the documentation of
1149 * get_function_values_from_local_dof_values() for more information.
1150 */
1151 template <class InputVector>
1152 void
1153 get_function_curls_from_local_dof_values(
1154 const InputVector &dof_values,
1155 std::vector<solution_curl_type<typename InputVector::value_type>> &curls)
1156 const;
1157
1158 /**
1159 * Return the Hessians of the selected vector components of the finite
1160 * element function characterized by <tt>fe_function</tt> at the
1161 * quadrature points of the cell, face or subface selected the last time
1162 * the <tt>reinit</tt> function of the FEValues object was called.
1163 *
1164 * This function is the equivalent of the
1165 * FEValuesBase::get_function_hessians function but it only works on the
1166 * selected vector components.
1167 *
1168 * The data type stored by the output vector must be what you get when you
1169 * multiply the Hessians of shape functions (i.e., @p hessian_type) times
1170 * the type used to store the values of the unknowns $U_j$ of your finite
1171 * element vector $U$ (represented by the @p fe_function argument).
1172 *
1173 * @dealiiRequiresUpdateFlags{update_hessians}
1174 */
1175 template <typename Number>
1176 void
1177 get_function_hessians(
1178 const ReadVector<Number> &fe_function,
1179 std::vector<solution_hessian_type<Number>> &hessians) const;
1180
1181 /**
1182 * This function relates to get_function_hessians() in the same way
1183 * as get_function_values_from_local_dof_values() relates to
1184 * get_function_values(). See the documentation of
1185 * get_function_values_from_local_dof_values() for more information.
1186 */
1187 template <class InputVector>
1188 void
1189 get_function_hessians_from_local_dof_values(
1190 const InputVector &dof_values,
1191 std::vector<solution_hessian_type<typename InputVector::value_type>>
1192 &hessians) const;
1193
1194 /**
1195 * Return the Laplacians of the selected vector components of the finite
1196 * element function characterized by <tt>fe_function</tt> at the
1197 * quadrature points of the cell, face or subface selected the last time
1198 * the <tt>reinit</tt> function of the FEValues object was called. The
1199 * Laplacians are the trace of the Hessians.
1200 *
1201 * This function is the equivalent of the
1202 * FEValuesBase::get_function_laplacians function but it only works on the
1203 * selected vector components.
1204 *
1205 * The data type stored by the output vector must be what you get when you
1206 * multiply the Laplacians of shape functions (i.e., @p laplacian_type)
1207 * times the type used to store the values of the unknowns $U_j$ of your
1208 * finite element vector $U$ (represented by the @p fe_function argument).
1209 *
1210 * @dealiiRequiresUpdateFlags{update_hessians}
1211 */
1212 template <typename Number>
1213 void
1214 get_function_laplacians(
1215 const ReadVector<Number> &fe_function,
1216 std::vector<solution_laplacian_type<Number>> &laplacians) const;
1217
1218 /**
1219 * This function relates to get_function_laplacians() in the same way
1220 * as get_function_values_from_local_dof_values() relates to
1221 * get_function_values(). See the documentation of
1222 * get_function_values_from_local_dof_values() for more information.
1223 */
1224 template <class InputVector>
1225 void
1226 get_function_laplacians_from_local_dof_values(
1227 const InputVector &dof_values,
1228 std::vector<solution_laplacian_type<typename InputVector::value_type>>
1229 &laplacians) const;
1230
1231 /**
1232 * Return the third derivatives of the selected scalar component of the
1233 * finite element function characterized by <tt>fe_function</tt> at the
1234 * quadrature points of the cell, face or subface selected the last time
1235 * the <tt>reinit</tt> function of the FEValues object was called.
1236 *
1237 * This function is the equivalent of the
1238 * FEValuesBase::get_function_third_derivatives function but it only works
1239 * on the selected scalar component.
1240 *
1241 * The data type stored by the output vector must be what you get when you
1242 * multiply the third derivatives of shape functions (i.e., @p
1243 * third_derivative_type) times the type used to store the values of the
1244 * unknowns $U_j$ of your finite element vector $U$ (represented by the @p
1245 * fe_function argument).
1246 *
1247 * @dealiiRequiresUpdateFlags{update_third_derivatives}
1248 */
1249 template <typename Number>
1250 void
1251 get_function_third_derivatives(
1252 const ReadVector<Number> &fe_function,
1253 std::vector<solution_third_derivative_type<Number>> &third_derivatives)
1254 const;
1255
1256 /**
1257 * This function relates to get_function_third_derivatives() in the same way
1258 * as get_function_values_from_local_dof_values() relates to
1259 * get_function_values(). See the documentation of
1260 * get_function_values_from_local_dof_values() for more information.
1261 */
1262 template <class InputVector>
1263 void
1264 get_function_third_derivatives_from_local_dof_values(
1265 const InputVector &dof_values,
1266 std::vector<
1267 solution_third_derivative_type<typename InputVector::value_type>>
1268 &third_derivatives) const;
1269
1270 private:
1271 /**
1272 * A pointer to the FEValuesBase object we operate on.
1273 */
1274 ObserverPointer<const FEValuesBase<dim, spacedim>> fe_values;
1275
1276 /**
1277 * The first component of the vector this view represents of the
1278 * FEValuesBase object.
1279 */
1280 unsigned int first_vector_component;
1281
1282 /**
1283 * Store the data about shape functions.
1284 */
1285 std::vector<ShapeFunctionData> shape_function_data;
1286 };
1287
1288
1289 template <int rank, int dim, int spacedim = dim>
1290 class SymmetricTensor;
1291
1292 /**
1293 * A class representing a view to a set of <code>(dim*dim + dim)/2</code>
1294 * components forming a symmetric second-order tensor from a vector-valued
1295 * finite element. Views are discussed in the
1296 * @ref vector_valued
1297 * topic.
1298 *
1299 * This class allows to query the value and divergence of (components of)
1300 * shape functions and solutions representing symmetric tensors. The
1301 * divergence of a symmetric tensor $S_{ij}, 0\le i,j<\text{dim}$ is defined
1302 * as $d_i = \sum_j \frac{\partial S_{ij}}{\partial x_j}, 0\le
1303 * i<\text{dim}$, which due to the symmetry of the tensor is also $d_i =
1304 * \sum_j \frac{\partial S_{ji}}{\partial x_j}$. In other words, it due to
1305 * the symmetry of $S$ it does not matter whether we apply the nabla
1306 * operator by row or by column to get the divergence.
1307 *
1308 * You get an object of this type if you apply a
1309 * FEValuesExtractors::SymmetricTensor to an FEValues, FEFaceValues or
1310 * FESubfaceValues object.
1311 *
1312 * @ingroup feaccess vector_valued
1313 */
1314 template <int dim, int spacedim>
1315 class SymmetricTensor<2, dim, spacedim>
1316 {
1317 public:
1318 /**
1319 * An alias for the data type of values of the view this class
1320 * represents. Since we deal with a set of <code>(dim*dim + dim)/2</code>
1321 * components (i.e. the unique components of a symmetric second-order
1322 * tensor), the value type is a SymmetricTensor<2,spacedim>.
1323 */
1324 using value_type = dealii::SymmetricTensor<2, spacedim>;
1325
1326 /**
1327 * An alias for the type of the divergence of the view this class
1328 * represents. Here, for a set of <code>(dim*dim + dim)/2</code> unique
1329 * components of the finite element representing a symmetric second-order
1330 * tensor, the divergence of course is a * <code>Tensor@<1,dim@></code>.
1331 *
1332 * See the general discussion of this class for a definition of the
1333 * divergence.
1334 */
1335 using divergence_type = dealii::Tensor<1, spacedim>;
1336
1337 /**
1338 * An alias for the data type of the product of a @p Number and the
1339 * values of the view this class provides. This is the data type of
1340 * vector components of a finite element field whose degrees of
1341 * freedom are described by a vector with elements of type @p Number.
1342 */
1343 template <typename Number>
1344 using solution_value_type = typename ProductType<Number, value_type>::type;
1345
1346 /**
1347 * An alias for the data type of the product of a @p Number and the
1348 * divergences of the view this class provides. This is the data type of
1349 * vector components of a finite element field whose degrees of
1350 * freedom are described by a vector with elements of type @p Number.
1351 */
1352 template <typename Number>
1353 using solution_divergence_type =
1354 typename ProductType<Number, divergence_type>::type;
1355
1356
1357 /**
1358 * A structure where for each shape function we pre-compute a bunch of
1359 * data that will make later accesses much cheaper.
1360 */
1361 struct ShapeFunctionData
1362 {
1363 /**
1364 * For each pair (shape function,component within vector), store whether
1365 * the selected vector component may be nonzero. For primitive shape
1366 * functions we know for sure whether a certain scalar component of a
1367 * given shape function is nonzero, whereas for non-primitive shape
1368 * functions this may not be entirely clear (e.g. for RT elements it
1369 * depends on the shape of a cell).
1370 */
1371 bool is_nonzero_shape_function_component
1372 [value_type::n_independent_components];
1373
1374 /**
1375 * For each pair (shape function, component within vector), store the
1376 * row index within the shape_values, shape_gradients, and
1377 * shape_hessians tables (the column index is the quadrature point
1378 * index). If the shape function is primitive, then we can get this
1379 * information from the shape_function_to_row_table of the FEValues
1380 * object; otherwise, we have to work a bit harder to compute this
1381 * information.
1382 */
1383 unsigned int row_index[value_type::n_independent_components];
1384
1385 /**
1386 * For each shape function say the following: if only a single entry in
1387 * is_nonzero_shape_function_component for this shape function is
1388 * nonzero, then store the corresponding value of row_index and
1389 * single_nonzero_component_index represents the index between 0 and
1390 * (dim^2 + dim)/2 for which it is attained. If multiple components are
1391 * nonzero, then store -1. If no components are nonzero then store -2.
1392 */
1393 int single_nonzero_component;
1394
1395 /**
1396 * Index of the @p single_nonzero_component .
1397 */
1398 unsigned int single_nonzero_component_index;
1399 };
1400
1401 /**
1402 * Default constructor. Creates an invalid object.
1403 */
1404 SymmetricTensor();
1405
1406 /**
1407 * Constructor for an object that represents <code>(dim*dim +
1408 * dim)/2</code> components of a FEValuesBase object (or of one of the
1409 * classes derived from FEValuesBase), representing the unique components
1410 * comprising a symmetric second- order tensor valued variable.
1411 *
1412 * The second argument denotes the index of the first component of the
1413 * selected symmetric second order tensor.
1414 */
1415 SymmetricTensor(const FEValuesBase<dim, spacedim> &fe_values_base,
1416 const unsigned int first_tensor_component);
1417
1418 /**
1419 * Copy constructor. This is not a lightweight object so we don't allow
1420 * copying and generate a compile-time error if this function is called.
1421 */
1422 SymmetricTensor(const SymmetricTensor<2, dim, spacedim> &) = delete;
1423
1424 /**
1425 * Move constructor.
1426 */
1427 // NOLINTNEXTLINE OSX does not compile with noexcept
1428 SymmetricTensor(SymmetricTensor<2, dim, spacedim> &&) = default;
1429
1430 /**
1431 * Copy operator. This is not a lightweight object so we don't allow
1432 * copying and generate a compile-time error if this function is called.
1433 */
1434 SymmetricTensor &
1435 operator=(const SymmetricTensor<2, dim, spacedim> &) = delete;
1436
1437 /**
1438 * Move assignment operator.
1439 */
1440 SymmetricTensor &
1441 operator=(SymmetricTensor<2, dim, spacedim> &&) noexcept = default;
1442
1443 /**
1444 * Return the value of the vector components selected by this view, for
1445 * the shape function and quadrature point selected by the arguments.
1446 * Here, since the view represents a vector-valued part of the FEValues
1447 * object with <code>(dim*dim + dim)/2</code> components (the unique
1448 * components of a symmetric second-order tensor), the return type is a
1449 * symmetric tensor of rank 2.
1450 *
1451 * @param shape_function Number of the shape function to be evaluated.
1452 * Note that this number runs from zero to dofs_per_cell, even in the case
1453 * of an FEFaceValues or FESubfaceValues object.
1454 *
1455 * @param q_point Number of the quadrature point at which function is to
1456 * be evaluated.
1457 *
1458 * @dealiiRequiresUpdateFlags{update_values}
1459 */
1460 value_type
1461 value(const unsigned int shape_function, const unsigned int q_point) const;
1462
1463 /**
1464 * Return the vector divergence of the vector components selected by this
1465 * view, for the shape function and quadrature point selected by the
1466 * arguments.
1467 *
1468 * See the general discussion of this class for a definition of the
1469 * divergence.
1470 *
1471 * @note The meaning of the arguments is as documented for the value()
1472 * function.
1473 *
1474 * @dealiiRequiresUpdateFlags{update_gradients}
1475 */
1476 divergence_type
1477 divergence(const unsigned int shape_function,
1478 const unsigned int q_point) const;
1479
1480 /**
1481 * Return the values of the selected vector components of the finite
1482 * element function characterized by <tt>fe_function</tt> at the
1483 * quadrature points of the cell, face or subface selected the last time
1484 * the <tt>reinit</tt> function of the FEValues object was called.
1485 *
1486 * This function is the equivalent of the
1487 * FEValuesBase::get_function_values function but it only works on the
1488 * selected vector components.
1489 *
1490 * The data type stored by the output vector must be what you get when you
1491 * multiply the values of shape functions (i.e., @p value_type) times the
1492 * type used to store the values of the unknowns $U_j$ of your finite
1493 * element vector $U$ (represented by the @p fe_function argument).
1494 *
1495 * @dealiiRequiresUpdateFlags{update_values}
1496 */
1497 template <typename Number>
1498 void
1499 get_function_values(const ReadVector<Number> &fe_function,
1500 std::vector<solution_value_type<Number>> &values) const;
1501
1502 /**
1503 * Same as above, but using a vector of local degree-of-freedom values. In
1504 * other words, instead of extracting the nodal values of the degrees of
1505 * freedom located on the current cell from a global vector associated with
1506 * a DoFHandler object (as the function above does), this function instead
1507 * takes these local nodal values through its first argument. A typical
1508 * way to obtain such a vector is by calling code such as
1509 * @code
1510 * cell->get_dof_values (dof_values, local_dof_values);
1511 * @endcode
1512 * (See DoFCellAccessor::get_dof_values() for more information on this
1513 * function.) The point of the current function is then that one could
1514 * modify these local values first, for example by applying a limiter
1515 * or by ensuring that all nodal values are positive, before evaluating
1516 * the finite element field that corresponds to these local values on the
1517 * current cell. Another application is where one wants to postprocess
1518 * the solution on a cell into a different finite element space on every
1519 * cell, without actually creating a corresponding DoFHandler -- in that
1520 * case, all one would compute is a local representation of that
1521 * postprocessed function, characterized by its nodal values; this function
1522 * then allows the evaluation of that representation at quadrature points.
1523 *
1524 * @param[in] dof_values A vector of local nodal values. This vector must
1525 * have a length equal to number of DoFs on the current cell, and must
1526 * be ordered in the same order as degrees of freedom are numbered on
1527 * the reference cell.
1528 *
1529 * @param[out] values A vector of values of the given finite element field,
1530 * at the quadrature points on the current object.
1531 *
1532 * @tparam InputVector The @p InputVector type must allow creation
1533 * of an ArrayView object from it; this is satisfied by the
1534 * `std::vector` class, among others.
1535 */
1536 template <class InputVector>
1537 void
1538 get_function_values_from_local_dof_values(
1539 const InputVector &dof_values,
1540 std::vector<solution_value_type<typename InputVector::value_type>>
1541 &values) const;
1542
1543 /**
1544 * Return the divergence of the selected vector components of the finite
1545 * element function characterized by <tt>fe_function</tt> at the
1546 * quadrature points of the cell, face or subface selected the last time
1547 * the <tt>reinit</tt> function of the FEValues object was called.
1548 *
1549 * There is no equivalent function such as
1550 * FEValuesBase::get_function_divergences in the FEValues classes but the
1551 * information can be obtained from FEValuesBase::get_function_gradients,
1552 * of course.
1553 *
1554 * See the general discussion of this class for a definition of the
1555 * divergence.
1556 *
1557 * The data type stored by the output vector must be what you get when you
1558 * multiply the divergences of shape functions (i.e., @p divergence_type)
1559 * times the type used to store the values of the unknowns $U_j$ of your
1560 * finite element vector $U$ (represented by the @p fe_function argument).
1561 *
1562 * @dealiiRequiresUpdateFlags{update_gradients}
1563 */
1564 template <typename Number>
1565 void
1566 get_function_divergences(
1567 const ReadVector<Number> &fe_function,
1568 std::vector<solution_divergence_type<Number>> &divergences) const;
1569
1570 /**
1571 * This function relates to get_function_divergences() in the same way
1572 * as get_function_values_from_local_dof_values() relates to
1573 * get_function_values(). See the documentation of
1574 * get_function_values_from_local_dof_values() for more information.
1575 */
1576 template <class InputVector>
1577 void
1578 get_function_divergences_from_local_dof_values(
1579 const InputVector &dof_values,
1580 std::vector<solution_divergence_type<typename InputVector::value_type>>
1581 &divergences) const;
1582
1583 private:
1584 /**
1585 * A pointer to the FEValuesBase object we operate on.
1586 */
1587 ObserverPointer<const FEValuesBase<dim, spacedim>> fe_values;
1588
1589 /**
1590 * The first component of the vector this view represents of the
1591 * FEValuesBase object.
1592 */
1593 unsigned int first_tensor_component;
1594
1595 /**
1596 * Store the data about shape functions.
1597 */
1598 std::vector<ShapeFunctionData> shape_function_data;
1599 };
1600
1601
1602 template <int rank, int dim, int spacedim = dim>
1603 class Tensor;
1604
1605 /**
1606 * A class representing a view to a set of <code>dim*dim</code> components
1607 * forming a second-order tensor from a vector-valued finite element. Views
1608 * are discussed in the
1609 * @ref vector_valued
1610 * topic.
1611 *
1612 * This class allows to query the value, gradient and divergence of
1613 * (components of) shape functions and solutions representing tensors. The
1614 * divergence of a tensor $T_{ij},\, 0\le i,j<\text{dim}$ is defined as $d_i =
1615 * \sum_j \frac{\partial T_{ij}}{\partial x_j}, \, 0\le i<\text{dim}$, whereas
1616 * its gradient is $G_{ijk} = \frac{\partial T_{ij}}{\partial x_k}$.
1617 *
1618 * You get an object of this type if you apply a FEValuesExtractors::Tensor
1619 * to an FEValues, FEFaceValues or FESubfaceValues object.
1620 *
1621 * @ingroup feaccess vector_valued
1622 */
1623 template <int dim, int spacedim>
1624 class Tensor<2, dim, spacedim>
1625 {
1626 public:
1627 /**
1628 * Data type for what you get when you apply an extractor of this kind to
1629 * a vector-valued finite element.
1630 */
1631 using value_type = dealii::Tensor<2, spacedim>;
1632
1633 /**
1634 * Data type for taking the divergence of a tensor: a vector.
1635 */
1636 using divergence_type = dealii::Tensor<1, spacedim>;
1637
1638 /**
1639 * Data type for taking the gradient of a second order tensor: a third order
1640 * tensor.
1641 */
1642 using gradient_type = dealii::Tensor<3, spacedim>;
1643
1644 /**
1645 * An alias for the data type of the product of a @p Number and the
1646 * values of the view this class provides. This is the data type of
1647 * vector components of a finite element field whose degrees of
1648 * freedom are described by a vector with elements of type @p Number.
1649 */
1650 template <typename Number>
1651 using solution_value_type = typename ProductType<Number, value_type>::type;
1652
1653 /**
1654 * An alias for the data type of the product of a @p Number and the
1655 * divergences of the view this class provides. This is the data type of
1656 * vector components of a finite element field whose degrees of
1657 * freedom are described by a vector with elements of type @p Number.
1658 */
1659 template <typename Number>
1660 using solution_divergence_type =
1661 typename ProductType<Number, divergence_type>::type;
1662
1663 /**
1664 * An alias for the data type of the product of a @p Number and the
1665 * gradient of the view this class provides. This is the data type of
1666 * vector components of a finite element field whose degrees of
1667 * freedom are described by a vector with elements of type @p Number.
1668 */
1669 template <typename Number>
1670 using solution_gradient_type =
1671 typename ProductType<Number, gradient_type>::type;
1672
1673
1674 /**
1675 * A structure where for each shape function we pre-compute a bunch of
1676 * data that will make later accesses much cheaper.
1677 */
1678 struct ShapeFunctionData
1679 {
1680 /**
1681 * For each pair (shape function,component within vector), store whether
1682 * the selected vector component may be nonzero. For primitive shape
1683 * functions we know for sure whether a certain scalar component of a
1684 * given shape function is nonzero, whereas for non-primitive shape
1685 * functions this may not be entirely clear (e.g. for RT elements it
1686 * depends on the shape of a cell).
1687 */
1688 bool is_nonzero_shape_function_component
1689 [value_type::n_independent_components];
1690
1691 /**
1692 * For each pair (shape function, component within vector), store the
1693 * row index within the shape_values, shape_gradients, and
1694 * shape_hessians tables (the column index is the quadrature point
1695 * index). If the shape function is primitive, then we can get this
1696 * information from the shape_function_to_row_table of the FEValues
1697 * object; otherwise, we have to work a bit harder to compute this
1698 * information.
1699 */
1700 unsigned int row_index[value_type::n_independent_components];
1701
1702 /**
1703 * For each shape function say the following: if only a single entry in
1704 * is_nonzero_shape_function_component for this shape function is
1705 * nonzero, then store the corresponding value of row_index and
1706 * single_nonzero_component_index represents the index between 0 and
1707 * (dim^2) for which it is attained. If multiple components are nonzero,
1708 * then store -1. If no components are nonzero then store -2.
1709 */
1710 int single_nonzero_component;
1711
1712 /**
1713 * Index of the @p single_nonzero_component .
1714 */
1715 unsigned int single_nonzero_component_index;
1716 };
1717
1718 /**
1719 * Default constructor. Creates an invalid object.
1720 */
1721 Tensor();
1722
1723 /**
1724 * Copy constructor. This is not a lightweight object so we don't allow
1725 * copying and generate a compile-time error if this function is called.
1726 */
1727 Tensor(const Tensor<2, dim, spacedim> &) = delete;
1728
1729 /**
1730 * Move constructor.
1731 */
1732 // NOLINTNEXTLINE OSX does not compile with noexcept
1733 Tensor(Tensor<2, dim, spacedim> &&) = default;
1734
1735 /**
1736 * Destructor.
1737 */
1738 ~Tensor() = default;
1739
1740 /**
1741 * Constructor for an object that represents <code>(dim*dim)</code>
1742 * components of a FEValuesBase object (or of one of the classes derived
1743 * from FEValuesBase), representing the unique components comprising a
1744 * second-order tensor valued variable.
1745 *
1746 * The second argument denotes the index of the first component of the
1747 * selected symmetric second order tensor.
1748 */
1749 Tensor(const FEValuesBase<dim, spacedim> &fe_values_base,
1750 const unsigned int first_tensor_component);
1751
1752
1753 /**
1754 * Copy operator. This is not a lightweight object so we don't allow
1755 * copying and generate a compile-time error if this function is called.
1756 */
1757 Tensor &
1758 operator=(const Tensor<2, dim, spacedim> &) = delete;
1759
1760 /**
1761 * Move assignment operator.
1762 */
1763 Tensor &
1764 operator=(Tensor<2, dim, spacedim> &&) = default; // NOLINT
1765
1766 /**
1767 * Return the value of the vector components selected by this view, for
1768 * the shape function and quadrature point selected by the arguments.
1769 * Here, since the view represents a vector-valued part of the FEValues
1770 * object with <code>(dim*dim)</code> components (the unique components of
1771 * a second-order tensor), the return type is a tensor of rank 2.
1772 *
1773 * @param shape_function Number of the shape function to be evaluated.
1774 * Note that this number runs from zero to dofs_per_cell, even in the case
1775 * of an FEFaceValues or FESubfaceValues object.
1776 *
1777 * @param q_point Number of the quadrature point at which function is to
1778 * be evaluated.
1779 *
1780 * @dealiiRequiresUpdateFlags{update_values}
1781 */
1782 value_type
1783 value(const unsigned int shape_function, const unsigned int q_point) const;
1784
1785 /**
1786 * Return the vector divergence of the vector components selected by this
1787 * view, for the shape function and quadrature point selected by the
1788 * arguments.
1789 *
1790 * See the general discussion of this class for a definition of the
1791 * divergence.
1792 *
1793 * @note The meaning of the arguments is as documented for the value()
1794 * function.
1795 *
1796 * @dealiiRequiresUpdateFlags{update_gradients}
1797 */
1798 divergence_type
1799 divergence(const unsigned int shape_function,
1800 const unsigned int q_point) const;
1801
1802 /**
1803 * Return the gradient (3-rd order tensor) of the vector components selected
1804 * by this view, for the shape function and quadrature point selected by the
1805 * arguments.
1806 *
1807 * See the general discussion of this class for a definition of the
1808 * gradient.
1809 *
1810 * @note The meaning of the arguments is as documented for the value()
1811 * function.
1812 *
1813 * @dealiiRequiresUpdateFlags{update_gradients}
1814 */
1815 gradient_type
1816 gradient(const unsigned int shape_function,
1817 const unsigned int q_point) const;
1818
1819 /**
1820 * Return the values of the selected vector components of the finite
1821 * element function characterized by <tt>fe_function</tt> at the
1822 * quadrature points of the cell, face or subface selected the last time
1823 * the <tt>reinit</tt> function of the FEValues object was called.
1824 *
1825 * This function is the equivalent of the
1826 * FEValuesBase::get_function_values function but it only works on the
1827 * selected vector components.
1828 *
1829 * The data type stored by the output vector must be what you get when you
1830 * multiply the values of shape functions (i.e., @p value_type) times the
1831 * type used to store the values of the unknowns $U_j$ of your finite
1832 * element vector $U$ (represented by the @p fe_function argument).
1833 *
1834 * @dealiiRequiresUpdateFlags{update_values}
1835 */
1836 template <typename Number>
1837 void
1838 get_function_values(const ReadVector<Number> &fe_function,
1839 std::vector<solution_value_type<Number>> &values) const;
1840
1841 /**
1842 * Same as above, but using a vector of local degree-of-freedom values. In
1843 * other words, instead of extracting the nodal values of the degrees of
1844 * freedom located on the current cell from a global vector associated with
1845 * a DoFHandler object (as the function above does), this function instead
1846 * takes these local nodal values through its first argument. A typical
1847 * way to obtain such a vector is by calling code such as
1848 * @code
1849 * cell->get_dof_values (dof_values, local_dof_values);
1850 * @endcode
1851 * (See DoFCellAccessor::get_dof_values() for more information on this
1852 * function.) The point of the current function is then that one could
1853 * modify these local values first, for example by applying a limiter
1854 * or by ensuring that all nodal values are positive, before evaluating
1855 * the finite element field that corresponds to these local values on the
1856 * current cell. Another application is where one wants to postprocess
1857 * the solution on a cell into a different finite element space on every
1858 * cell, without actually creating a corresponding DoFHandler -- in that
1859 * case, all one would compute is a local representation of that
1860 * postprocessed function, characterized by its nodal values; this function
1861 * then allows the evaluation of that representation at quadrature points.
1862 *
1863 * @param[in] dof_values A vector of local nodal values. This vector must
1864 * have a length equal to number of DoFs on the current cell, and must
1865 * be ordered in the same order as degrees of freedom are numbered on
1866 * the reference cell.
1867 *
1868 * @param[out] values A vector of values of the given finite element field,
1869 * at the quadrature points on the current object.
1870 *
1871 * @tparam InputVector The @p InputVector type must allow creation
1872 * of an ArrayView object from it; this is satisfied by the
1873 * `std::vector` class, among others.
1874 */
1875 template <class InputVector>
1876 void
1877 get_function_values_from_local_dof_values(
1878 const InputVector &dof_values,
1879 std::vector<solution_value_type<typename InputVector::value_type>>
1880 &values) const;
1881
1882 /**
1883 * Return the divergence of the selected vector components of the finite
1884 * element function characterized by <tt>fe_function</tt> at the
1885 * quadrature points of the cell, face or subface selected the last time
1886 * the <tt>reinit</tt> function of the FEValues object was called.
1887 *
1888 * There is no equivalent function such as
1889 * FEValuesBase::get_function_divergences in the FEValues classes but the
1890 * information can be obtained from FEValuesBase::get_function_gradients,
1891 * of course.
1892 *
1893 * See the general discussion of this class for a definition of the
1894 * divergence.
1895 *
1896 * The data type stored by the output vector must be what you get when you
1897 * multiply the divergences of shape functions (i.e., @p divergence_type)
1898 * times the type used to store the values of the unknowns $U_j$ of your
1899 * finite element vector $U$ (represented by the @p fe_function argument).
1900 *
1901 * @dealiiRequiresUpdateFlags{update_gradients}
1902 */
1903 template <typename Number>
1904 void
1905 get_function_divergences(
1906 const ReadVector<Number> &fe_function,
1907 std::vector<solution_divergence_type<Number>> &divergences) const;
1908
1909 /**
1910 * This function relates to get_function_divergences() in the same way
1911 * as get_function_values_from_local_dof_values() relates to
1912 * get_function_values(). See the documentation of
1913 * get_function_values_from_local_dof_values() for more information.
1914 */
1915 template <class InputVector>
1916 void
1917 get_function_divergences_from_local_dof_values(
1918 const InputVector &dof_values,
1919 std::vector<solution_divergence_type<typename InputVector::value_type>>
1920 &divergences) const;
1921
1922 /**
1923 * Return the gradient of the selected vector components of the finite
1924 * element function characterized by <tt>fe_function</tt> at the
1925 * quadrature points of the cell, face or subface selected the last time
1926 * the <tt>reinit</tt> function of the FEValues object was called.
1927 *
1928 * See the general discussion of this class for a definition of the
1929 * gradient.
1930 *
1931 * The data type stored by the output vector must be what you get when you
1932 * multiply the gradients of shape functions (i.e., @p gradient_type)
1933 * times the type used to store the values of the unknowns $U_j$ of your
1934 * finite element vector $U$ (represented by the @p fe_function argument).
1935 *
1936 * @dealiiRequiresUpdateFlags{update_gradients}
1937 */
1938 template <typename Number>
1939 void
1940 get_function_gradients(
1941 const ReadVector<Number> &fe_function,
1942 std::vector<solution_gradient_type<Number>> &gradients) const;
1943
1944 /**
1945 * This function relates to get_function_gradients() in the same way
1946 * as get_function_values_from_local_dof_values() relates to
1947 * get_function_values(). See the documentation of
1948 * get_function_values_from_local_dof_values() for more information.
1949 */
1950 template <class InputVector>
1951 void
1952 get_function_gradients_from_local_dof_values(
1953 const InputVector &dof_values,
1954 std::vector<solution_gradient_type<typename InputVector::value_type>>
1955 &gradients) const;
1956
1957 private:
1958 /**
1959 * A pointer to the FEValuesBase object we operate on.
1960 */
1961 ObserverPointer<const FEValuesBase<dim, spacedim>> fe_values;
1962
1963 /**
1964 * The first component of the vector this view represents of the
1965 * FEValuesBase object.
1966 */
1967 unsigned int first_tensor_component;
1968
1969 /**
1970 * Store the data about shape functions.
1971 */
1972 std::vector<ShapeFunctionData> shape_function_data;
1973 };
1974
1975 } // namespace FEValuesViews
1976
1977
1978 namespace internal
1979 {
1980 namespace FEValuesViews
1981 {
1982 /**
1983 * A class whose specialization is used to define what FEValuesViews
1984 * object corresponds to the given FEValuesExtractors object.
1985 */
1986 template <int dim, int spacedim, typename Extractor>
1987 struct ViewType
1988 {};
1989
1990 /**
1991 * A class whose specialization is used to define what FEValuesViews
1992 * object corresponds to the given FEValuesExtractors object.
1993 *
1994 * When using FEValuesExtractors::Scalar, the corresponding view is an
1995 * FEValuesViews::Scalar<dim, spacedim>.
1996 */
1997 template <int dim, int spacedim>
1998 struct ViewType<dim, spacedim, FEValuesExtractors::Scalar>
1999 {
2000 using type = typename dealii::FEValuesViews::Scalar<dim, spacedim>;
2001 };
2002
2003 /**
2004 * A class whose specialization is used to define what FEValuesViews
2005 * object corresponds to the given FEValuesExtractors object.
2006 *
2007 * When using FEValuesExtractors::Vector, the corresponding view is an
2008 * FEValuesViews::Vector<dim, spacedim>.
2009 */
2010 template <int dim, int spacedim>
2011 struct ViewType<dim, spacedim, FEValuesExtractors::Vector>
2012 {
2013 using type = typename dealii::FEValuesViews::Vector<dim, spacedim>;
2014 };
2015
2016 /**
2017 * A class whose specialization is used to define what FEValuesViews
2018 * object corresponds to the given FEValuesExtractors object.
2019 *
2020 * When using FEValuesExtractors::Tensor<rank>, the corresponding view is an
2021 * FEValuesViews::Tensor<rank, dim, spacedim>.
2022 */
2023 template <int dim, int spacedim, int rank>
2024 struct ViewType<dim, spacedim, FEValuesExtractors::Tensor<rank>>
2025 {
2026 using type = typename dealii::FEValuesViews::Tensor<rank, dim, spacedim>;
2027 };
2028
2029 /**
2030 * A class whose specialization is used to define what FEValuesViews
2031 * object corresponds to the given FEValuesExtractors object.
2032 *
2033 * When using FEValuesExtractors::SymmetricTensor<rank>, the corresponding
2034 * view is an FEValuesViews::SymmetricTensor<rank, dim, spacedim>.
2035 */
2036 template <int dim, int spacedim, int rank>
2037 struct ViewType<dim, spacedim, FEValuesExtractors::SymmetricTensor<rank>>
2038 {
2039 using type =
2040 typename dealii::FEValuesViews::SymmetricTensor<rank, dim, spacedim>;
2041 };
2042
2043 /**
2044 * A class objects of which store a collection of FEValuesViews::Scalar,
2045 * FEValuesViews::Vector, etc object. The FEValuesBase class uses it to
2046 * generate all possible Views classes upon construction time; we do this
2047 * at construction time since the Views classes cache some information and
2048 * are therefore relatively expensive to create.
2049 */
2050 template <int dim, int spacedim>
2051 struct Cache
2052 {
2053 /**
2054 * Caches for scalar and vector, and symmetric second-order tensor
2055 * valued views.
2056 */
2057 std::vector<Lazy<dealii::FEValuesViews::Scalar<dim, spacedim>>> scalars;
2058 std::vector<Lazy<dealii::FEValuesViews::Vector<dim, spacedim>>> vectors;
2059 std::vector<
2060 Lazy<dealii::FEValuesViews::SymmetricTensor<2, dim, spacedim>>>
2061 symmetric_second_order_tensors;
2062 std::vector<Lazy<dealii::FEValuesViews::Tensor<2, dim, spacedim>>>
2063 second_order_tensors;
2064
2065 /**
2066 * Constructor.
2067 */
2068 Cache(const FEValuesBase<dim, spacedim> &fe_values);
2069 };
2070 } // namespace FEValuesViews
2071 } // namespace internal
2072
2073 namespace FEValuesViews
2074 {
2075 /**
2076 * A templated alias that associates to a given Extractor class
2077 * the corresponding view in FEValuesViews.
2078 */
2079 template <int dim, int spacedim, typename Extractor>
2080 using View = typename dealii::internal::FEValuesViews::
2081 ViewType<dim, spacedim, Extractor>::type;
2082 } // namespace FEValuesViews
2083
2084 #ifndef DOXYGEN
2085
2086 /*---------------- Inline functions: namespace FEValuesViews -----------------*/
2087
2088 namespace FEValuesViews
2089 {
2090 template <int dim, int spacedim>
2091 inline typename Scalar<dim, spacedim>::value_type
2092 Scalar<dim, spacedim>::value(const unsigned int shape_function,
2093 const unsigned int q_point) const
2094 {
2095 AssertIndexRange(shape_function, fe_values->fe->n_dofs_per_cell());
2096 Assert(
2097 fe_values->update_flags & update_values,
2098 ((typename FEValuesBase<dim, spacedim>::ExcAccessToUninitializedField(
2099 "update_values"))));
2100
2101 // an adaptation of the FEValuesBase::shape_value_component function
2102 // except that here we know the component as fixed and we have
2103 // pre-computed and cached a bunch of information. See the comments there.
2104 if (shape_function_data[shape_function].is_nonzero_shape_function_component)
2105 return fe_values->finite_element_output.shape_values(
2106 shape_function_data[shape_function].row_index, q_point);
2107 else
2108 return 0;
2109 }
2110
2111
2112
2113 template <int dim, int spacedim>
2114 inline typename Scalar<dim, spacedim>::gradient_type
2115 Scalar<dim, spacedim>::gradient(const unsigned int shape_function,
2116 const unsigned int q_point) const
2117 {
2118 AssertIndexRange(shape_function, fe_values->fe->n_dofs_per_cell());
2119 Assert(fe_values->update_flags & update_gradients,
2120 (typename FEValuesBase<dim, spacedim>::ExcAccessToUninitializedField(
2121 "update_gradients")));
2122
2123 // an adaptation of the FEValuesBase::shape_grad_component
2124 // function except that here we know the component as fixed and we have
2125 // pre-computed and cached a bunch of information. See the comments there.
2126 if (shape_function_data[shape_function].is_nonzero_shape_function_component)
2127 return fe_values->finite_element_output
2128 .shape_gradients[shape_function_data[shape_function].row_index]
2129 [q_point];
2130 else
2131 return gradient_type();
2132 }
2133
2134
2135
2136 template <int dim, int spacedim>
2137 inline typename Scalar<dim, spacedim>::hessian_type
2138 Scalar<dim, spacedim>::hessian(const unsigned int shape_function,
2139 const unsigned int q_point) const
2140 {
2141 AssertIndexRange(shape_function, fe_values->fe->n_dofs_per_cell());
2142 Assert(fe_values->update_flags & update_hessians,
2143 (typename FEValuesBase<dim, spacedim>::ExcAccessToUninitializedField(
2144 "update_hessians")));
2145
2146 // an adaptation of the FEValuesBase::shape_hessian_component
2147 // function except that here we know the component as fixed and we have
2148 // pre-computed and cached a bunch of information. See the comments there.
2149 if (shape_function_data[shape_function].is_nonzero_shape_function_component)
2150 return fe_values->finite_element_output
2151 .shape_hessians[shape_function_data[shape_function].row_index][q_point];
2152 else
2153 return hessian_type();
2154 }
2155
2156
2157
2158 template <int dim, int spacedim>
2159 inline typename Scalar<dim, spacedim>::third_derivative_type
2160 Scalar<dim, spacedim>::third_derivative(const unsigned int shape_function,
2161 const unsigned int q_point) const
2162 {
2163 AssertIndexRange(shape_function, fe_values->fe->n_dofs_per_cell());
2164 Assert(fe_values->update_flags & update_3rd_derivatives,
2165 (typename FEValuesBase<dim, spacedim>::ExcAccessToUninitializedField(
2166 "update_3rd_derivatives")));
2167
2168 // an adaptation of the FEValuesBase::shape_3rdderivative_component
2169 // function except that here we know the component as fixed and we have
2170 // pre-computed and cached a bunch of information. See the comments there.
2171 if (shape_function_data[shape_function].is_nonzero_shape_function_component)
2172 return fe_values->finite_element_output
2173 .shape_3rd_derivatives[shape_function_data[shape_function].row_index]
2174 [q_point];
2175 else
2176 return third_derivative_type();
2177 }
2178
2179
2180
2181 template <int dim, int spacedim>
2182 inline typename Vector<dim, spacedim>::value_type
2183 Vector<dim, spacedim>::value(const unsigned int shape_function,
2184 const unsigned int q_point) const
2185 {
2186 AssertIndexRange(shape_function, fe_values->fe->n_dofs_per_cell());
2187 Assert(fe_values->update_flags & update_values,
2188 (typename FEValuesBase<dim, spacedim>::ExcAccessToUninitializedField(
2189 "update_values")));
2190
2191 // same as for the scalar case except that we have one more index
2192 const int snc =
2193 shape_function_data[shape_function].single_nonzero_component;
2194 if (snc == -2)
2195 return value_type();
2196 else if (snc != -1)
2197 {
2198 value_type return_value;
2199 return_value[shape_function_data[shape_function]
2200 .single_nonzero_component_index] =
2201 fe_values->finite_element_output.shape_values(snc, q_point);
2202 return return_value;
2203 }
2204 else
2205 {
2206 value_type return_value;
2207 for (unsigned int d = 0; d < dim; ++d)
2208 if (shape_function_data[shape_function]
2209 .is_nonzero_shape_function_component[d])
2210 return_value[d] = fe_values->finite_element_output.shape_values(
2211 shape_function_data[shape_function].row_index[d], q_point);
2212
2213 return return_value;
2214 }
2215 }
2216
2217
2218
2219 template <int dim, int spacedim>
2220 inline typename Vector<dim, spacedim>::gradient_type
2221 Vector<dim, spacedim>::gradient(const unsigned int shape_function,
2222 const unsigned int q_point) const
2223 {
2224 AssertIndexRange(shape_function, fe_values->fe->n_dofs_per_cell());
2225 Assert(fe_values->update_flags & update_gradients,
2226 (typename FEValuesBase<dim, spacedim>::ExcAccessToUninitializedField(
2227 "update_gradients")));
2228
2229 // same as for the scalar case except that we have one more index
2230 const int snc =
2231 shape_function_data[shape_function].single_nonzero_component;
2232 if (snc == -2)
2233 return gradient_type();
2234 else if (snc != -1)
2235 {
2236 gradient_type return_value;
2237 return_value[shape_function_data[shape_function]
2238 .single_nonzero_component_index] =
2239 fe_values->finite_element_output.shape_gradients[snc][q_point];
2240 return return_value;
2241 }
2242 else
2243 {
2244 gradient_type return_value;
2245 for (unsigned int d = 0; d < dim; ++d)
2246 if (shape_function_data[shape_function]
2247 .is_nonzero_shape_function_component[d])
2248 return_value[d] =
2249 fe_values->finite_element_output.shape_gradients
2250 [shape_function_data[shape_function].row_index[d]][q_point];
2251
2252 return return_value;
2253 }
2254 }
2255
2256
2257
2258 template <int dim, int spacedim>
2259 inline typename Vector<dim, spacedim>::divergence_type
2260 Vector<dim, spacedim>::divergence(const unsigned int shape_function,
2261 const unsigned int q_point) const
2262 {
2263 // this function works like in the case above
2264 AssertIndexRange(shape_function, fe_values->fe->n_dofs_per_cell());
2265 Assert(fe_values->update_flags & update_gradients,
2266 (typename FEValuesBase<dim, spacedim>::ExcAccessToUninitializedField(
2267 "update_gradients")));
2268
2269 // same as for the scalar case except that we have one more index
2270 const int snc =
2271 shape_function_data[shape_function].single_nonzero_component;
2272 if (snc == -2)
2273 return divergence_type();
2274 else if (snc != -1)
2275 return fe_values->finite_element_output
2276 .shape_gradients[snc][q_point][shape_function_data[shape_function]
2277 .single_nonzero_component_index];
2278 else
2279 {
2280 divergence_type return_value = 0;
2281 for (unsigned int d = 0; d < dim; ++d)
2282 if (shape_function_data[shape_function]
2283 .is_nonzero_shape_function_component[d])
2284 return_value +=
2285 fe_values->finite_element_output.shape_gradients
2286 [shape_function_data[shape_function].row_index[d]][q_point][d];
2287
2288 return return_value;
2289 }
2290 }
2291
2292
2293
2294 template <int dim, int spacedim>
2295 inline typename Vector<dim, spacedim>::curl_type
2296 Vector<dim, spacedim>::curl(const unsigned int shape_function,
2297 const unsigned int q_point) const
2298 {
2299 // this function works like in the case above
2300
2301 AssertIndexRange(shape_function, fe_values->fe->n_dofs_per_cell());
2302 Assert(fe_values->update_flags & update_gradients,
2303 (typename FEValuesBase<dim, spacedim>::ExcAccessToUninitializedField(
2304 "update_gradients")));
2305 // same as for the scalar case except that we have one more index
2306 const int snc =
2307 shape_function_data[shape_function].single_nonzero_component;
2308
2309 if (snc == -2)
2310 return curl_type();
2311
2312 else
2313 switch (dim)
2314 {
2315 case 1:
2316 {
2317 Assert(false,
2318 ExcMessage(
2319 "Computing the curl in 1d is not a useful operation"));
2320 return curl_type();
2321 }
2322
2323 case 2:
2324 {
2325 if (snc != -1)
2326 {
2327 curl_type return_value;
2328
2329 // the single nonzero component can only be zero or one in 2d
2330 if (shape_function_data[shape_function]
2331 .single_nonzero_component_index == 0)
2332 return_value[0] =
2333 -1.0 * fe_values->finite_element_output
2334 .shape_gradients[snc][q_point][1];
2335 else
2336 return_value[0] = fe_values->finite_element_output
2337 .shape_gradients[snc][q_point][0];
2338
2339 return return_value;
2340 }
2341
2342 else
2343 {
2344 curl_type return_value;
2345
2346 return_value[0] = 0.0;
2347
2348 if (shape_function_data[shape_function]
2349 .is_nonzero_shape_function_component[0])
2350 return_value[0] -=
2351 fe_values->finite_element_output
2352 .shape_gradients[shape_function_data[shape_function]
2353 .row_index[0]][q_point][1];
2354
2355 if (shape_function_data[shape_function]
2356 .is_nonzero_shape_function_component[1])
2357 return_value[0] +=
2358 fe_values->finite_element_output
2359 .shape_gradients[shape_function_data[shape_function]
2360 .row_index[1]][q_point][0];
2361
2362 return return_value;
2363 }
2364 }
2365
2366 case 3:
2367 {
2368 if (snc != -1)
2369 {
2370 curl_type return_value;
2371
2372 switch (shape_function_data[shape_function]
2373 .single_nonzero_component_index)
2374 {
2375 case 0:
2376 {
2377 return_value[0] = 0;
2378 return_value[1] = fe_values->finite_element_output
2379 .shape_gradients[snc][q_point][2];
2380 return_value[2] =
2381 -1.0 * fe_values->finite_element_output
2382 .shape_gradients[snc][q_point][1];
2383 return return_value;
2384 }
2385
2386 case 1:
2387 {
2388 return_value[0] =
2389 -1.0 * fe_values->finite_element_output
2390 .shape_gradients[snc][q_point][2];
2391 return_value[1] = 0;
2392 return_value[2] = fe_values->finite_element_output
2393 .shape_gradients[snc][q_point][0];
2394 return return_value;
2395 }
2396
2397 default:
2398 {
2399 return_value[0] = fe_values->finite_element_output
2400 .shape_gradients[snc][q_point][1];
2401 return_value[1] =
2402 -1.0 * fe_values->finite_element_output
2403 .shape_gradients[snc][q_point][0];
2404 return_value[2] = 0;
2405 return return_value;
2406 }
2407 }
2408 }
2409
2410 else
2411 {
2412 curl_type return_value;
2413
2414 for (unsigned int i = 0; i < dim; ++i)
2415 return_value[i] = 0.0;
2416
2417 if (shape_function_data[shape_function]
2418 .is_nonzero_shape_function_component[0])
2419 {
2420 return_value[1] +=
2421 fe_values->finite_element_output
2422 .shape_gradients[shape_function_data[shape_function]
2423 .row_index[0]][q_point][2];
2424 return_value[2] -=
2425 fe_values->finite_element_output
2426 .shape_gradients[shape_function_data[shape_function]
2427 .row_index[0]][q_point][1];
2428 }
2429
2430 if (shape_function_data[shape_function]
2431 .is_nonzero_shape_function_component[1])
2432 {
2433 return_value[0] -=
2434 fe_values->finite_element_output
2435 .shape_gradients[shape_function_data[shape_function]
2436 .row_index[1]][q_point][2];
2437 return_value[2] +=
2438 fe_values->finite_element_output
2439 .shape_gradients[shape_function_data[shape_function]
2440 .row_index[1]][q_point][0];
2441 }
2442
2443 if (shape_function_data[shape_function]
2444 .is_nonzero_shape_function_component[2])
2445 {
2446 return_value[0] +=
2447 fe_values->finite_element_output
2448 .shape_gradients[shape_function_data[shape_function]
2449 .row_index[2]][q_point][1];
2450 return_value[1] -=
2451 fe_values->finite_element_output
2452 .shape_gradients[shape_function_data[shape_function]
2453 .row_index[2]][q_point][0];
2454 }
2455
2456 return return_value;
2457 }
2458 }
2459 }
2460 // should not end up here
2461 DEAL_II_ASSERT_UNREACHABLE();
2462 return curl_type();
2463 }
2464
2465
2466
2467 template <int dim, int spacedim>
2468 inline typename Vector<dim, spacedim>::hessian_type
2469 Vector<dim, spacedim>::hessian(const unsigned int shape_function,
2470 const unsigned int q_point) const
2471 {
2472 // this function works like in the case above
2473 AssertIndexRange(shape_function, fe_values->fe->n_dofs_per_cell());
2474 Assert(fe_values->update_flags & update_hessians,
2475 (typename FEValuesBase<dim, spacedim>::ExcAccessToUninitializedField(
2476 "update_hessians")));
2477
2478 // same as for the scalar case except that we have one more index
2479 const int snc =
2480 shape_function_data[shape_function].single_nonzero_component;
2481 if (snc == -2)
2482 return hessian_type();
2483 else if (snc != -1)
2484 {
2485 hessian_type return_value;
2486 return_value[shape_function_data[shape_function]
2487 .single_nonzero_component_index] =
2488 fe_values->finite_element_output.shape_hessians[snc][q_point];
2489 return return_value;
2490 }
2491 else
2492 {
2493 hessian_type return_value;
2494 for (unsigned int d = 0; d < dim; ++d)
2495 if (shape_function_data[shape_function]
2496 .is_nonzero_shape_function_component[d])
2497 return_value[d] =
2498 fe_values->finite_element_output.shape_hessians
2499 [shape_function_data[shape_function].row_index[d]][q_point];
2500
2501 return return_value;
2502 }
2503 }
2504
2505
2506
2507 template <int dim, int spacedim>
2508 inline typename Vector<dim, spacedim>::third_derivative_type
2509 Vector<dim, spacedim>::third_derivative(const unsigned int shape_function,
2510 const unsigned int q_point) const
2511 {
2512 // this function works like in the case above
2513 AssertIndexRange(shape_function, fe_values->fe->n_dofs_per_cell());
2514 Assert(fe_values->update_flags & update_3rd_derivatives,
2515 (typename FEValuesBase<dim, spacedim>::ExcAccessToUninitializedField(
2516 "update_3rd_derivatives")));
2517
2518 // same as for the scalar case except that we have one more index
2519 const int snc =
2520 shape_function_data[shape_function].single_nonzero_component;
2521 if (snc == -2)
2522 return third_derivative_type();
2523 else if (snc != -1)
2524 {
2525 third_derivative_type return_value;
2526 return_value[shape_function_data[shape_function]
2527 .single_nonzero_component_index] =
2528 fe_values->finite_element_output.shape_3rd_derivatives[snc][q_point];
2529 return return_value;
2530 }
2531 else
2532 {
2533 third_derivative_type return_value;
2534 for (unsigned int d = 0; d < dim; ++d)
2535 if (shape_function_data[shape_function]
2536 .is_nonzero_shape_function_component[d])
2537 return_value[d] =
2538 fe_values->finite_element_output.shape_3rd_derivatives
2539 [shape_function_data[shape_function].row_index[d]][q_point];
2540
2541 return return_value;
2542 }
2543 }
2544
2545
2546
2547 namespace internal
2548 {
2549 /**
2550 * Return the symmetrized version of a tensor whose n'th row equals the
2551 * second argument, with all other rows equal to zero.
2552 */
2553 inline dealii::SymmetricTensor<2, 1>
2554 symmetrize_single_row(const unsigned int n, const dealii::Tensor<1, 1> &t)
2555 {
2556 AssertIndexRange(n, 1);
2557 (void)n;
2558
2559 return {{t[0]}};
2560 }
2561
2562
2563
2564 inline dealii::SymmetricTensor<2, 2>
2565 symmetrize_single_row(const unsigned int n, const dealii::Tensor<1, 2> &t)
2566 {
2567 switch (n)
2568 {
2569 case 0:
2570 {
2571 return {{t[0], 0, t[1] / 2}};
2572 }
2573 case 1:
2574 {
2575 return {{0, t[1], t[0] / 2}};
2576 }
2577 default:
2578 {
2579 AssertIndexRange(n, 2);
2580 return {};
2581 }
2582 }
2583 }
2584
2585
2586
2587 inline dealii::SymmetricTensor<2, 3>
2588 symmetrize_single_row(const unsigned int n, const dealii::Tensor<1, 3> &t)
2589 {
2590 switch (n)
2591 {
2592 case 0:
2593 {
2594 return {{t[0], 0, 0, t[1] / 2, t[2] / 2, 0}};
2595 }
2596 case 1:
2597 {
2598 return {{0, t[1], 0, t[0] / 2, 0, t[2] / 2}};
2599 }
2600 case 2:
2601 {
2602 return {{0, 0, t[2], 0, t[0] / 2, t[1] / 2}};
2603 }
2604 default:
2605 {
2606 AssertIndexRange(n, 3);
2607 return {};
2608 }
2609 }
2610 }
2611 } // namespace internal
2612
2613
2614
2615 template <int dim, int spacedim>
2616 inline typename Vector<dim, spacedim>::symmetric_gradient_type
2617 Vector<dim, spacedim>::symmetric_gradient(const unsigned int shape_function,
2618 const unsigned int q_point) const
2619 {
2620 AssertIndexRange(shape_function, fe_values->fe->n_dofs_per_cell());
2621 Assert(fe_values->update_flags & update_gradients,
2622 (typename FEValuesBase<dim, spacedim>::ExcAccessToUninitializedField(
2623 "update_gradients")));
2624
2625 // same as for the scalar case except that we have one more index
2626 const int snc =
2627 shape_function_data[shape_function].single_nonzero_component;
2628 if (snc == -2)
2629 return symmetric_gradient_type();
2630 else if (snc != -1)
2631 return internal::symmetrize_single_row(
2632 shape_function_data[shape_function].single_nonzero_component_index,
2633 fe_values->finite_element_output.shape_gradients[snc][q_point]);
2634 else
2635 {
2636 gradient_type return_value;
2637 for (unsigned int d = 0; d < dim; ++d)
2638 if (shape_function_data[shape_function]
2639 .is_nonzero_shape_function_component[d])
2640 return_value[d] =
2641 fe_values->finite_element_output.shape_gradients
2642 [shape_function_data[shape_function].row_index[d]][q_point];
2643
2644 return symmetrize(return_value);
2645 }
2646 }
2647
2648
2649
2650 template <int dim, int spacedim>
2651 inline typename SymmetricTensor<2, dim, spacedim>::value_type
2652 SymmetricTensor<2, dim, spacedim>::value(const unsigned int shape_function,
2653 const unsigned int q_point) const
2654 {
2655 AssertIndexRange(shape_function, fe_values->fe->n_dofs_per_cell());
2656 Assert(fe_values->update_flags & update_values,
2657 (typename FEValuesBase<dim, spacedim>::ExcAccessToUninitializedField(
2658 "update_values")));
2659
2660 // similar to the vector case where we have more then one index and we need
2661 // to convert between unrolled and component indexing for tensors
2662 const int snc =
2663 shape_function_data[shape_function].single_nonzero_component;
2664
2665 if (snc == -2)
2666 {
2667 // shape function is zero for the selected components
2668 return value_type();
2669 }
2670 else if (snc != -1)
2671 {
2672 value_type return_value;
2673 const unsigned int comp =
2674 shape_function_data[shape_function].single_nonzero_component_index;
2675 return_value[value_type::unrolled_to_component_indices(comp)] =
2676 fe_values->finite_element_output.shape_values(snc, q_point);
2677 return return_value;
2678 }
2679 else
2680 {
2681 value_type return_value;
2682 for (unsigned int d = 0; d < value_type::n_independent_components; ++d)
2683 if (shape_function_data[shape_function]
2684 .is_nonzero_shape_function_component[d])
2685 return_value[value_type::unrolled_to_component_indices(d)] =
2686 fe_values->finite_element_output.shape_values(
2687 shape_function_data[shape_function].row_index[d], q_point);
2688 return return_value;
2689 }
2690 }
2691
2692
2693
2694 template <int dim, int spacedim>
2695 inline typename SymmetricTensor<2, dim, spacedim>::divergence_type
2696 SymmetricTensor<2, dim, spacedim>::divergence(
2697 const unsigned int shape_function,
2698 const unsigned int q_point) const
2699 {
2700 AssertIndexRange(shape_function, fe_values->fe->n_dofs_per_cell());
2701 Assert(fe_values->update_flags & update_gradients,
2702 (typename FEValuesBase<dim, spacedim>::ExcAccessToUninitializedField(
2703 "update_gradients")));
2704
2705 const int snc =
2706 shape_function_data[shape_function].single_nonzero_component;
2707
2708 if (snc == -2)
2709 {
2710 // shape function is zero for the selected components
2711 return divergence_type();
2712 }
2713 else if (snc != -1)
2714 {
2715 // we have a single non-zero component when the symmetric tensor is
2716 // represented in unrolled form. this implies we potentially have
2717 // two non-zero components when represented in component form! we
2718 // will only have one non-zero entry if the non-zero component lies on
2719 // the diagonal of the tensor.
2720 //
2721 // the divergence of a second-order tensor is a first order tensor.
2722 //
2723 // assume the second-order tensor is A with components A_{ij}. then
2724 // A_{ij} = A_{ji} and there is only one (if diagonal) or two non-zero
2725 // entries in the tensorial representation. define the
2726 // divergence as:
2727 // b_i \dealcoloneq \dfrac{\partial phi_{ij}}{\partial x_j}.
2728 // (which is incidentally also
2729 // b_j \dealcoloneq \dfrac{\partial phi_{ij}}{\partial x_i}).
2730 // In both cases, a sum is implied.
2731 //
2732 // Now, we know the nonzero component in unrolled form: it is indicated
2733 // by 'snc'. we can figure out which tensor components belong to this:
2734 const unsigned int comp =
2735 shape_function_data[shape_function].single_nonzero_component_index;
2736 const unsigned int ii =
2737 value_type::unrolled_to_component_indices(comp)[0];
2738 const unsigned int jj =
2739 value_type::unrolled_to_component_indices(comp)[1];
2740
2741 // given the form of the divergence above, if ii=jj there is only a
2742 // single nonzero component of the full tensor and the gradient
2743 // equals
2744 // b_ii \dealcoloneq \dfrac{\partial phi_{ii,ii}}{\partial x_ii}.
2745 // all other entries of 'b' are zero
2746 //
2747 // on the other hand, if ii!=jj, then there are two nonzero entries in
2748 // the full tensor and
2749 // b_ii \dealcoloneq \dfrac{\partial phi_{ii,jj}}{\partial x_ii}.
2750 // b_jj \dealcoloneq \dfrac{\partial phi_{ii,jj}}{\partial x_jj}.
2751 // again, all other entries of 'b' are zero
2752 const dealii::Tensor<1, spacedim> &phi_grad =
2753 fe_values->finite_element_output.shape_gradients[snc][q_point];
2754
2755 divergence_type return_value;
2756 return_value[ii] = phi_grad[jj];
2757
2758 if (ii != jj)
2759 return_value[jj] = phi_grad[ii];
2760
2761 return return_value;
2762 }
2763 else
2764 {
2765 DEAL_II_NOT_IMPLEMENTED();
2766 divergence_type return_value;
2767 return return_value;
2768 }
2769 }
2770
2771
2772
2773 template <int dim, int spacedim>
2774 inline typename Tensor<2, dim, spacedim>::value_type
2775 Tensor<2, dim, spacedim>::value(const unsigned int shape_function,
2776 const unsigned int q_point) const
2777 {
2778 AssertIndexRange(shape_function, fe_values->fe->n_dofs_per_cell());
2779 Assert(fe_values->update_flags & update_values,
2780 (typename FEValuesBase<dim, spacedim>::ExcAccessToUninitializedField(
2781 "update_values")));
2782
2783 // similar to the vector case where we have more then one index and we need
2784 // to convert between unrolled and component indexing for tensors
2785 const int snc =
2786 shape_function_data[shape_function].single_nonzero_component;
2787
2788 if (snc == -2)
2789 {
2790 // shape function is zero for the selected components
2791 return value_type();
2792 }
2793 else if (snc != -1)
2794 {
2795 value_type return_value;
2796 const unsigned int comp =
2797 shape_function_data[shape_function].single_nonzero_component_index;
2798 const TableIndices<2> indices =
2799 dealii::Tensor<2, spacedim>::unrolled_to_component_indices(comp);
2800 return_value[indices] =
2801 fe_values->finite_element_output.shape_values(snc, q_point);
2802 return return_value;
2803 }
2804 else
2805 {
2806 value_type return_value;
2807 for (unsigned int d = 0; d < dim * dim; ++d)
2808 if (shape_function_data[shape_function]
2809 .is_nonzero_shape_function_component[d])
2810 {
2811 const TableIndices<2> indices =
2812 dealii::Tensor<2, spacedim>::unrolled_to_component_indices(d);
2813 return_value[indices] =
2814 fe_values->finite_element_output.shape_values(
2815 shape_function_data[shape_function].row_index[d], q_point);
2816 }
2817 return return_value;
2818 }
2819 }
2820
2821
2822
2823 template <int dim, int spacedim>
2824 inline typename Tensor<2, dim, spacedim>::divergence_type
2825 Tensor<2, dim, spacedim>::divergence(const unsigned int shape_function,
2826 const unsigned int q_point) const
2827 {
2828 AssertIndexRange(shape_function, fe_values->fe->n_dofs_per_cell());
2829 Assert(fe_values->update_flags & update_gradients,
2830 (typename FEValuesBase<dim, spacedim>::ExcAccessToUninitializedField(
2831 "update_gradients")));
2832
2833 const int snc =
2834 shape_function_data[shape_function].single_nonzero_component;
2835
2836 if (snc == -2)
2837 {
2838 // shape function is zero for the selected components
2839 return divergence_type();
2840 }
2841 else if (snc != -1)
2842 {
2843 // we have a single non-zero component when the tensor is
2844 // represented in unrolled form.
2845 //
2846 // the divergence of a second-order tensor is a first order tensor.
2847 //
2848 // assume the second-order tensor is A with components A_{ij},
2849 // then divergence is d_i := \frac{\partial A_{ij}}{\partial x_j}
2850 //
2851 // Now, we know the nonzero component in unrolled form: it is indicated
2852 // by 'snc'. we can figure out which tensor components belong to this:
2853 const unsigned int comp =
2854 shape_function_data[shape_function].single_nonzero_component_index;
2855 const TableIndices<2> indices =
2856 dealii::Tensor<2, spacedim>::unrolled_to_component_indices(comp);
2857 const unsigned int ii = indices[0];
2858 const unsigned int jj = indices[1];
2859
2860 const dealii::Tensor<1, spacedim> &phi_grad =
2861 fe_values->finite_element_output.shape_gradients[snc][q_point];
2862
2863 divergence_type return_value;
2864 // note that we contract \nabla from the right
2865 return_value[ii] = phi_grad[jj];
2866
2867 return return_value;
2868 }
2869 else
2870 {
2871 DEAL_II_NOT_IMPLEMENTED();
2872 divergence_type return_value;
2873 return return_value;
2874 }
2875 }
2876
2877
2878
2879 template <int dim, int spacedim>
2880 inline typename Tensor<2, dim, spacedim>::gradient_type
2881 Tensor<2, dim, spacedim>::gradient(const unsigned int shape_function,
2882 const unsigned int q_point) const
2883 {
2884 AssertIndexRange(shape_function, fe_values->fe->n_dofs_per_cell());
2885 Assert(fe_values->update_flags & update_gradients,
2886 (typename FEValuesBase<dim, spacedim>::ExcAccessToUninitializedField(
2887 "update_gradients")));
2888
2889 const int snc =
2890 shape_function_data[shape_function].single_nonzero_component;
2891
2892 if (snc == -2)
2893 {
2894 // shape function is zero for the selected components
2895 return gradient_type();
2896 }
2897 else if (snc != -1)
2898 {
2899 // we have a single non-zero component when the tensor is
2900 // represented in unrolled form.
2901 //
2902 // the gradient of a second-order tensor is a third order tensor.
2903 //
2904 // assume the second-order tensor is A with components A_{ij},
2905 // then gradient is B_{ijk} := \frac{\partial A_{ij}}{\partial x_k}
2906 //
2907 // Now, we know the nonzero component in unrolled form: it is indicated
2908 // by 'snc'. we can figure out which tensor components belong to this:
2909 const unsigned int comp =
2910 shape_function_data[shape_function].single_nonzero_component_index;
2911 const TableIndices<2> indices =
2912 dealii::Tensor<2, spacedim>::unrolled_to_component_indices(comp);
2913 const unsigned int ii = indices[0];
2914 const unsigned int jj = indices[1];
2915
2916 const dealii::Tensor<1, spacedim> &phi_grad =
2917 fe_values->finite_element_output.shape_gradients[snc][q_point];
2918
2919 gradient_type return_value;
2920 return_value[ii][jj] = phi_grad;
2921
2922 return return_value;
2923 }
2924 else
2925 {
2926 DEAL_II_NOT_IMPLEMENTED();
2927 gradient_type return_value;
2928 return return_value;
2929 }
2930 }
2931 } // namespace FEValuesViews
2932
2933 #endif
2934
2935 DEAL_II_NAMESPACE_CLOSE
2936
2937 #endif