-
Notifications
You must be signed in to change notification settings - Fork 707
/
fe_evaluation.h
8325 lines (7446 loc) · 314 KB
/
fe_evaluation.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// ---------------------------------------------------------------------
//
// Copyright (C) 2011 - 2021 by the deal.II authors
//
// This file is part of the deal.II library.
//
// The deal.II library is free software; you can use it, redistribute
// it, and/or modify it under the terms of the GNU Lesser General
// Public License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
// The full text of the license can be found in the file LICENSE.md at
// the top level directory of deal.II.
//
// ---------------------------------------------------------------------
#ifndef dealii_matrix_free_fe_evaluation_h
#define dealii_matrix_free_fe_evaluation_h
#include <deal.II/base/config.h>
#include <deal.II/base/array_view.h>
#include <deal.II/base/exceptions.h>
#include <deal.II/base/smartpointer.h>
#include <deal.II/base/symmetric_tensor.h>
#include <deal.II/base/template_constraints.h>
#include <deal.II/base/vectorization.h>
#include <deal.II/lac/vector_operation.h>
#include <deal.II/matrix_free/evaluation_flags.h>
#include <deal.II/matrix_free/evaluation_kernels.h>
#include <deal.II/matrix_free/evaluation_selector.h>
#include <deal.II/matrix_free/evaluation_template_factory.h>
#include <deal.II/matrix_free/fe_evaluation_data.h>
#include <deal.II/matrix_free/mapping_data_on_the_fly.h>
#include <deal.II/matrix_free/matrix_free.h>
#include <deal.II/matrix_free/shape_info.h>
#include <deal.II/matrix_free/tensor_product_kernels.h>
#include <deal.II/matrix_free/type_traits.h>
#include <deal.II/matrix_free/vector_access_internal.h>
#include <type_traits>
DEAL_II_NAMESPACE_OPEN
/**
* This is the base class for the FEEvaluation classes. This class needs
* usually not be called in user code and does not have any public
* constructor. The usage is through the class FEEvaluation instead. It
* implements a reinit method that is used to set pointers so that operations
* on quadrature points can be performed quickly, access functions to vectors
* for the FEEvaluationBase::read_dof_values(),
* FEEvaluationBase::set_dof_values(), and
* FEEvaluationBase::distribute_local_to_global() functions, as well as
* methods to access values and gradients of finite element functions. It also
* inherits the geometry access functions provided by the class
* FEEvaluationData.
*
* This class has five template arguments:
*
* @tparam dim Dimension in which this class is to be used
*
* @tparam n_components Number of vector components when solving a system of
* PDEs. If the same operation is applied to several components of a PDE (e.g.
* a vector Laplace equation), they can be applied simultaneously with one
* call (and often more efficiently)
*
* @tparam Number Number format, usually @p double or @p float
*
* @tparam is_face Whether the class is used for a cell integrator (with
* quadrature dimension the same as the space dimension) or for a face
* integrator (with quadrature dimension one less)
*
* @tparam VectorizedArrayType Type of array to be woked on in a vectorized
* fashion, defaults to VectorizedArray<Number>
*
* @note Currently only VectorizedArray<Number, width> is supported as
* VectorizedArrayType.
*
*
* @ingroup matrixfree
*/
template <int dim,
int n_components_,
typename Number,
bool is_face,
typename VectorizedArrayType>
class FEEvaluationBase
: public FEEvaluationData<dim, VectorizedArrayType, is_face>
{
public:
using number_type = Number;
using value_type = Tensor<1, n_components_, VectorizedArrayType>;
using gradient_type =
Tensor<1, n_components_, Tensor<1, dim, VectorizedArrayType>>;
using hessian_type =
Tensor<1, n_components_, Tensor<2, dim, VectorizedArrayType>>;
static constexpr unsigned int dimension = dim;
static constexpr unsigned int n_components = n_components_;
/**
* @name 1: Reading from and writing to vectors
*/
//@{
/**
* For the vector @p src, read out the values on the degrees of freedom of
* the current cell, and store them internally. Similar functionality as the
* function DoFAccessor::get_interpolated_dof_values when no constraints are
* present, but it also includes constraints from hanging nodes, so one can
* see it as a similar function to AffineConstraints::read_dof_values as
* well. Note that if vectorization is enabled, the DoF values for several
* cells are set.
*
* If some constraints on the vector are inhomogeneous, use the function
* read_dof_values_plain instead and provide the vector with useful data
* also in constrained positions by calling AffineConstraints::distribute.
* When accessing vector entries during the solution of linear systems, the
* temporary solution should always have homogeneous constraints and this
* method is the correct one.
*
* If the given vector template class is a block vector (determined through
* the template function 'IsBlockVector<VectorType>::value', which checks
* for vectors derived from dealii::BlockVectorBase) or an
* std::vector<VectorType> or std::vector<VectorType *>, this function reads
* @p n_components blocks from the block vector starting at the index
* @p first_index. For non-block vectors, @p first_index is ignored.
*
* @note If this class was constructed without a MatrixFree object and the
* information is acquired on the fly through a
* DoFHandler<dim>::cell_iterator, only one single cell is used by this
* class and this function extracts the values of the underlying components
* on the given cell. This call is slower than the ones done through a
* MatrixFree object and lead to a structure that does not effectively use
* vectorization in the evaluate routines based on these values (instead,
* VectorizedArray::size() same copies are worked on).
*/
template <typename VectorType>
void
read_dof_values(const VectorType & src,
const unsigned int first_index = 0,
const std::bitset<VectorizedArrayType::size()> &mask =
std::bitset<VectorizedArrayType::size()>().flip());
/**
* For the vector @p src, read out the values on the degrees of freedom of
* the current cell, and store them internally. Similar functionality as the
* function DoFAccessor::get_interpolated_dof_values. As opposed to the
* read_dof_values function, this function reads out the plain entries from
* vectors, without taking stored constraints into account. This way of
* access is appropriate when the constraints have been distributed on the
* vector by a call to AffineConstraints::distribute previously. This
* function is also necessary when inhomogeneous constraints are to be used,
* as MatrixFree can only handle homogeneous constraints. Note that if
* vectorization is enabled, the DoF values for several cells are set.
*
* If the given vector template class is a block vector (determined through
* the template function 'IsBlockVector<VectorType>::value', which checks
* for vectors derived from dealii::BlockVectorBase) or an
* std::vector<VectorType> or std::vector<VectorType *>, this function reads
* @p n_components blocks from the block vector starting at the index
* @p first_index. For non-block vectors, @p first_index is ignored.
*
* @note If this class was constructed without a MatrixFree object and the
* information is acquired on the fly through a
* DoFHandler<dim>::cell_iterator, only one single cell is used by this
* class and this function extracts the values of the underlying components
* on the given cell. This call is slower than the ones done through a
* MatrixFree object and lead to a structure that does not effectively use
* vectorization in the evaluate routines based on these values (instead,
* VectorizedArray::size() same copies are worked on).
*/
template <typename VectorType>
void
read_dof_values_plain(const VectorType & src,
const unsigned int first_index = 0,
const std::bitset<VectorizedArrayType::size()> &mask =
std::bitset<VectorizedArrayType::size()>().flip());
/**
* Takes the values stored internally on dof values of the current cell and
* sums them into the vector @p dst. The function also applies constraints
* during the write operation. The functionality is hence similar to the
* function AffineConstraints::distribute_local_to_global. If vectorization
* is enabled, the DoF values for several cells are used.
*
* If the given vector template class is a block vector (determined through
* the template function 'IsBlockVector<VectorType>::value', which checks
* for vectors derived from dealii::BlockVectorBase) or an
* std::vector<VectorType> or std::vector<VectorType *>, this function
* writes to @p n_components blocks of the block vector starting at the
* index @p first_index. For non-block vectors, @p first_index is ignored.
*
* The @p mask can be used to suppress the write access for some of the
* cells contained in the current cell vectorization batch, e.g. in case of
* local time stepping, where some cells are excluded from a call. A value
* of `true` in the bitset means that the respective lane index will be
* processed, whereas a value of `false` skips this index. The default
* setting is a bitset that contains all ones, which will write the
* accumulated integrals to all cells in the batch.
*
* @note If this class was constructed without a MatrixFree object and the
* information is acquired on the fly through a
* DoFHandler<dim>::cell_iterator, only one single cell is used by this
* class and this function extracts the values of the underlying components
* on the given cell. This call is slower than the ones done through a
* MatrixFree object and lead to a structure that does not effectively use
* vectorization in the evaluate routines based on these values (instead,
* VectorizedArray::size() same copies are worked on).
*/
template <typename VectorType>
void
distribute_local_to_global(
VectorType & dst,
const unsigned int first_index = 0,
const std::bitset<VectorizedArrayType::size()> &mask =
std::bitset<VectorizedArrayType::size()>().flip()) const;
/**
* Takes the values stored internally on dof values of the current cell and
* writes them into the vector @p dst. The function skips the degrees of
* freedom which are constrained. As opposed to the
* distribute_local_to_global method, the old values at the position given
* by the current cell are overwritten. Thus, if a degree of freedom is
* associated to more than one cell (as usual in continuous finite
* elements), the values will be overwritten and only the value written last
* is retained. Please note that in a parallel context this function might
* also touch degrees of freedom owned by other MPI processes, so that a
* subsequent update or accumulation of ghost values as done by
* MatrixFree::loop() might invalidate the degrees of freedom set by this
* function.
*
* If the given vector template class is a block vector (determined through
* the template function 'IsBlockVector<VectorType>::value', which checks
* for vectors derived from dealii::BlockVectorBase) or an
* std::vector<VectorType> or std::vector<VectorType *>, this function
* writes to @p n_components blocks of the block vector starting at the
* index @p first_index. For non-block vectors, @p first_index is ignored.
*
* The @p mask can be used to suppress the write access for some
* of the cells contained in the current cell vectorization batch, e.g. in
* case of local time stepping, where some cells are excluded from a call.
* A value of `true` in the bitset means that the respective lane index will
* be processed, whereas a value of `false` skips this index. The default
* setting is a bitset that contains all ones, which will write the
* accumulated integrals to all cells in the batch.
*
* @note If this class was constructed without a MatrixFree object and the
* information is acquired on the fly through a
* DoFHandler<dim>::cell_iterator, only one single cell is used by this
* class and this function extracts the values of the underlying components
* on the given cell. This call is slower than the ones done through a
* MatrixFree object and lead to a structure that does not effectively use
* vectorization in the evaluate routines based on these values (instead,
* VectorizedArray::size() same copies are worked on).
*/
template <typename VectorType>
void
set_dof_values(VectorType & dst,
const unsigned int first_index = 0,
const std::bitset<VectorizedArrayType::size()> &mask =
std::bitset<VectorizedArrayType::size()>().flip()) const;
/**
* Same as set_dof_values(), but without resolving constraints.
*/
template <typename VectorType>
void
set_dof_values_plain(
VectorType & dst,
const unsigned int first_index = 0,
const std::bitset<VectorizedArrayType::size()> &mask =
std::bitset<VectorizedArrayType::size()>().flip()) const;
//@}
/**
* @name 2: Access to data at quadrature points or the gather vector data
*/
//@{
/**
* Return the value stored for the local degree of freedom with index @p
* dof. If the object is vector-valued, a vector-valued return argument is
* given. Thus, the argument @p dof can at most run until @p
* dofs_per_component rather than @p dofs_per_cell since the different
* components of a vector-valued FE are return together. Note that when
* vectorization is enabled, values from several cells are grouped
* together. If @p set_dof_values was called last, the value corresponds to
* the one set there. If @p integrate was called last, it instead
* corresponds to the value of the integrated function with the test
* function of the given index.
*
* Note that the derived class FEEvaluationAccess overloads this operation
* with specializations for the scalar case (n_components == 1) and for the
* vector-valued case (n_components == dim).
*/
value_type
get_dof_value(const unsigned int dof) const;
/**
* Write a value to the field containing the degrees of freedom with
* component @p dof. Writes to the same field as is accessed through @p
* get_dof_value. Therefore, the original data that was read from a vector
* is overwritten as soon as a value is submitted.
*
* Note that the derived class FEEvaluationAccess overloads this operation
* with specializations for the scalar case (n_components == 1) and for the
* vector-valued case (n_components == dim).
*/
void
submit_dof_value(const value_type val_in, const unsigned int dof);
/**
* Return the value of a finite element function at quadrature point number
* @p q_point after a call to FEEvaluation::evaluate() with
* EvaluationFlags::values set, or the value that has been stored there with
* a call to FEEvaluationBase::submit_value(). If the object is
* vector-valued, a vector-valued return argument is given. Note that when
* vectorization is enabled, values from several cells are grouped together.
*
* Note that the derived class FEEvaluationAccess overloads this operation
* with specializations for the scalar case (n_components == 1) and for the
* vector-valued case (n_components == dim).
*/
value_type
get_value(const unsigned int q_point) const;
/**
* Write a value to the field containing the values on quadrature points
* with component @p q_point. Access to the same field as through
* get_value(). If applied before the function FEEvaluation::integrate()
* with EvaluationFlags::values set is called, this specifies the value
* which is tested by all basis function on the current cell and integrated
* over.
*
* Note that the derived class FEEvaluationAccess overloads this operation
* with specializations for the scalar case (n_components == 1) and for the
* vector-valued case (n_components == dim).
*/
void
submit_value(const value_type val_in, const unsigned int q_point);
/**
* Return the gradient of a finite element function at quadrature point
* number @p q_point after a call to FEEvaluation::evaluate() with
* EvaluationFlags::gradients, or the value that has been stored there with
* a call to FEEvaluationBase::submit_gradient().
*
* Note that the derived class FEEvaluationAccess overloads this operation
* with specializations for the scalar case (n_components == 1) and for the
* vector-valued case (n_components == dim).
*/
gradient_type
get_gradient(const unsigned int q_point) const;
/**
* Return the derivative of a finite element function at quadrature point
* number @p q_point after a call to
* FEEvaluation::evaluate(EvaluationFlags::gradients) the direction normal
* to the face: $\boldsymbol \nabla u(\mathbf x_q) \cdot \mathbf n(\mathbf
* x_q)$
*
* This call is equivalent to calling get_gradient() * get_normal_vector()
* but will use a more efficient internal representation of data.
*
* Note that the derived class FEEvaluationAccess overloads this operation
* with specializations for the scalar case (n_components == 1) and for the
* vector-valued case (n_components == dim).
*/
value_type
get_normal_derivative(const unsigned int q_point) const;
/**
* Write a contribution that is tested by the gradient to the field
* containing the values on quadrature points with component @p q_point.
* Access to the same field as through get_gradient(). If applied before the
* function FEEvaluation::integrate(EvaluationFlags::gradients) is called,
* this specifies what is tested by all basis function gradients on the
* current cell and integrated over.
*
* Note that the derived class FEEvaluationAccess overloads this operation
* with specializations for the scalar case (n_components == 1) and for the
* vector-valued case (n_components == dim).
*/
void
submit_gradient(const gradient_type grad_in, const unsigned int q_point);
/**
* Write a contribution that is tested by the gradient to the field
* containing the values on quadrature points with component @p
* q_point. Access to the same field as through get_gradient() or
* get_normal_derivative(). If applied before the function
* FEEvaluation::integrate(EvaluationFlags::gradients) is called, this
* specifies what is tested by all basis function gradients on the current
* cell and integrated over.
*
* @note This operation writes the data to the same field as
* submit_gradient(). As a consequence, only one of these two can be
* used. Usually, the contribution of a potential call to this function must
* be added into the contribution for submit_gradient().
*
* @note The derived class FEEvaluationAccess overloads this operation
* with specializations for the scalar case (n_components == 1) and for the
* vector-valued case (n_components == dim).
*/
void
submit_normal_derivative(const value_type grad_in,
const unsigned int q_point);
/**
* Write a contribution that is tested by the Hessian to the field
* containing the values at quadrature points with component @p q_point.
* Access to the same field as through get_hessian(). If applied before the
* function FEEvaluation::integrate(EvaluationFlags::hessians) is called,
* this specifies what is tested by the Hessians of all basis functions on the
* current cell and integrated over.
*
* Note that the derived class FEEvaluationAccess overloads this operation
* with specializations for the scalar case (n_components == 1) and for the
* vector-valued case (n_components == dim).
*/
void
submit_hessian(const hessian_type hessian_in, const unsigned int q_point);
/**
* Return the Hessian of a finite element function at quadrature point
* number @p q_point after a call to
* FEEvaluation::evaluate(EvaluationFlags::hessians). If only the diagonal
* or even the trace of the Hessian, the Laplacian, is needed, use the other
* functions below.
*
* Note that the derived class FEEvaluationAccess overloads this operation
* with specializations for the scalar case (n_components == 1) and for the
* vector-valued case (n_components == dim).
*/
Tensor<1, n_components_, Tensor<2, dim, VectorizedArrayType>>
get_hessian(const unsigned int q_point) const;
/**
* Return the diagonal of the Hessian of a finite element function at
* quadrature point number @p q_point after a call to
* FEEvaluation::evaluate(EvaluationFlags::hessians).
*
* Note that the derived class FEEvaluationAccess overloads this operation
* with specializations for the scalar case (n_components == 1) and for the
* vector-valued case (n_components == dim).
*/
gradient_type
get_hessian_diagonal(const unsigned int q_point) const;
/**
* Return the Laplacian (i.e., the trace of the Hessian) of a finite element
* function at quadrature point number @p q_point after a call to
* FEEvaluation::evaluate(EvaluationFlags::hessians). Compared to the case
* when computing the full Hessian, some operations can be saved when only
* the Laplacian is requested.
*
* Note that the derived class FEEvaluationAccess overloads this operation
* with specializations for the scalar case (n_components == 1) and for the
* vector-valued case (n_components == dim).
*/
value_type
get_laplacian(const unsigned int q_point) const;
#ifdef DOXYGEN
// doxygen does not anyhow mention functions coming from partial template
// specialization of the base class, in this case FEEvaluationAccess<dim,dim>.
// For now, hack in those functions manually only to fix documentation:
/**
* Return the divergence of a vector-valued finite element at quadrature
* point number @p q_point after a call to @p evaluate(...,true,...).
*
* @note Only available for n_components_==dim.
*/
VectorizedArrayType
get_divergence(const unsigned int q_point) const;
/**
* Return the symmetric gradient of a vector-valued finite element at
* quadrature point number @p q_point after a call to @p
* evaluate(...,true,...). It corresponds to <tt>0.5
* (grad+grad<sup>T</sup>)</tt>.
*
* @note Only available for n_components_==dim.
*/
SymmetricTensor<2, dim, VectorizedArrayType>
get_symmetric_gradient(const unsigned int q_point) const;
/**
* Return the curl of the vector field, $\nabla \times v$ after a call to @p
* evaluate(...,true,...).
*
* @note Only available for n_components_==dim.
*/
Tensor<1, (dim == 2 ? 1 : dim), VectorizedArrayType>
get_curl(const unsigned int q_point) const;
/**
* Write a contribution that is tested by the divergence to the field
* containing the values on quadrature points with component @p q_point.
* Access to the same field as through @p get_gradient. If applied before
* the function @p integrate(...,true) is called, this specifies what is
* tested by all basis function gradients on the current cell and integrated
* over.
*
* @note Only available for n_components_==dim.
*
* @note This operation writes the data to the same field as
* submit_gradient(). As a consequence, only one of these two can be
* used. Usually, the contribution of a potential call to this function must
* be added into the diagonal of the contribution for submit_gradient().
*/
void
submit_divergence(const VectorizedArrayType div_in,
const unsigned int q_point);
/**
* Write a contribution that is tested by the symmetric gradient to the field
* containing the values on quadrature points with component @p q_point.
* Access to the same field as through @p get_symmetric_gradient. If applied before
* the function @p integrate(...,true) is called, this specifies the
* symmetric gradient which is tested by all basis function symmetric
* gradients on the current cell and integrated over.
*
* @note Only available for n_components_==dim.
*
* @note This operation writes the data to the same field as
* submit_gradient(). As a consequence, only one of these two can be
* used. Usually, the contribution of a potential call to this function must
* be added to the respective entries of the rank-2 tensor for
* submit_gradient().
*/
void
submit_symmetric_gradient(
const SymmetricTensor<2, dim, VectorizedArrayType> grad_in,
const unsigned int q_point);
/**
* Write the components of a curl containing the values on quadrature point
* @p q_point. Access to the same data field as through @p get_gradient.
*
* @note Only available for n_components_==dim.
*
* @note This operation writes the data to the same field as
* submit_gradient(). As a consequence, only one of these two can be
* used. Usually, the contribution of a potential call to this function must
* be added to the respective entries of the rank-2 tensor for
* submit_gradient().
*/
void
submit_curl(const Tensor<1, dim == 2 ? 1 : dim, VectorizedArrayType> curl_in,
const unsigned int q_point);
#endif
/**
* Takes values at quadrature points, multiplies by the Jacobian determinant
* and quadrature weights (JxW) and sums the values for all quadrature
* points on the cell. The result is a scalar, representing the integral
* over the function over the cell. If a vector-element is used, the
* resulting components are still separated. Moreover, if vectorization is
* enabled, the integral values of several cells are contained in the slots
* of the returned VectorizedArray field.
*
* @note In case the FEEvaluation object is initialized with a batch of
* cells where not all lanes in the SIMD vector VectorizedArray are
* representing actual data, this method performs computations on dummy data
* (that is copied from the last valid lane) that will not make sense. Thus,
* the user needs to make sure that it is not used in any computation
* explicitly, like when summing the results of several cells.
*/
value_type
integrate_value() const;
//@}
/**
* Provides a unified interface to access data in a vector of
* VectorizedArray fields of length MatrixFree::n_cell_batches() +
* MatrixFree::n_ghost_cell_batches() for both cells (plain read) and faces
* (indirect addressing).
*/
VectorizedArrayType
read_cell_data(const AlignedVector<VectorizedArrayType> &array) const;
/**
* Provides a unified interface to set data in a vector of
* VectorizedArray fields of length MatrixFree::n_cell_batches() +
* MatrixFree::n_ghost_cell_batches() for both cells (plain read) and faces
* (indirect addressing).
*/
void
set_cell_data(AlignedVector<VectorizedArrayType> &array,
const VectorizedArrayType & value) const;
/**
* The same as above, just for std::array of length of VectorizedArrayType for
* arbitrary data type.
*/
template <typename T>
std::array<T, VectorizedArrayType::size()>
read_cell_data(const AlignedVector<std::array<T, VectorizedArrayType::size()>>
&array) const;
/**
* The same as above, just for std::array of length of VectorizedArrayType for
* arbitrary data type.
*/
template <typename T>
void
set_cell_data(
AlignedVector<std::array<T, VectorizedArrayType::size()>> &array,
const std::array<T, VectorizedArrayType::size()> & value) const;
/**
* Return the underlying MatrixFree object.
*/
const MatrixFree<dim, Number, VectorizedArrayType> &
get_matrix_free() const;
protected:
/**
* Constructor. Made protected to prevent users from directly using this
* class. Takes all data stored in MatrixFree. If applied to problems with
* more than one finite element or more than one quadrature formula selected
* during construction of @p matrix_free, @p dof_no, @p
* first_selected_component and @p quad_no allow to select the appropriate
* components.
*/
FEEvaluationBase(
const MatrixFree<dim, Number, VectorizedArrayType> &matrix_free,
const unsigned int dof_no,
const unsigned int first_selected_component,
const unsigned int quad_no,
const unsigned int fe_degree,
const unsigned int n_q_points,
const bool is_interior_face,
const unsigned int active_fe_index,
const unsigned int active_quad_index,
const unsigned int face_type);
/**
* Constructor that comes with reduced functionality and works similar as
* FEValues. The arguments are similar to the ones passed to the constructor
* of FEValues, with the notable difference that FEEvaluation expects a
* one-dimensional
* quadrature formula, Quadrature<1>, instead of a @p dim
* dimensional one. The finite element can be both scalar or vector valued,
* but this method always only selects a scalar base element at a time (with
* @p n_components copies as specified by the class template argument). For
* vector-valued elements, the optional argument @p first_selected_component
* allows to specify the index of the base element to be used for
* evaluation. Note that the internal data structures always assume that the
* base element is primitive, non-primitive are not supported currently.
*
* As known from FEValues, a call to the reinit method with a
* Triangulation::cell_iterator is necessary to make the geometry and
* degrees of freedom of the current class known. If the iterator includes
* DoFHandler information (i.e., it is a DoFHandler::cell_iterator or
* similar), the initialization allows to also read from or write to vectors
* in the standard way for DoFHandler::active_cell_iterator types for one
* cell at a time. However, this approach is much slower than the path with
* MatrixFree with MPI since index translation has to be done. As only one
* cell at a time is used, this method does not vectorize over several
* elements (which is most efficient for vector operations), but only
* possibly within the element if the evaluate/integrate routines are
* combined inside user code (e.g. for computing cell matrices).
*
* The optional FEEvaluationData object allows several
* FEEvaluation objects to share the geometry evaluation, i.e., the
* underlying mapping and quadrature points do only need to be evaluated
* once. This only works if the quadrature formulas are the same. Otherwise,
* a new evaluation object is created. Make sure to not pass an optional
* object around when you intend to use the FEEvaluation object in %parallel
* with another one because otherwise the intended sharing may create race
* conditions.
*/
FEEvaluationBase(
const Mapping<dim> & mapping,
const FiniteElement<dim> &fe,
const Quadrature<1> & quadrature,
const UpdateFlags update_flags,
const unsigned int first_selected_component,
const FEEvaluationData<dim, VectorizedArrayType, is_face> *other);
/**
* Copy constructor. If FEEvaluationBase was constructed from a mapping, fe,
* quadrature, and update flags, the underlying geometry evaluation based on
* FEValues will be deep-copied in order to allow for using in parallel with
* threads.
*/
FEEvaluationBase(const FEEvaluationBase &other);
/**
* Copy assignment operator. If FEEvaluationBase was constructed from a
* mapping, fe, quadrature, and update flags, the underlying geometry
* evaluation based on FEValues will be deep-copied in order to allow for
* using in parallel with threads.
*/
FEEvaluationBase &
operator=(const FEEvaluationBase &other);
/**
* Destructor.
*/
~FEEvaluationBase();
/**
* A unified function to read from and write into vectors based on the given
* template operation. It can perform the operation for @p read_dof_values,
* @p distribute_local_to_global, and @p set_dof_values. It performs the
* operation for several vectors at a time.
*/
template <typename VectorType, typename VectorOperation>
void
read_write_operation(
const VectorOperation & operation,
const std::array<VectorType *, n_components_> &vectors,
const std::array<
const std::vector<ArrayView<const typename VectorType::value_type>> *,
n_components_> & vectors_sm,
const std::bitset<VectorizedArrayType::size()> &mask,
const bool apply_constraints = true) const;
/**
* A unified function to read from and write into vectors based on the given
* template operation for DG-type schemes where all degrees of freedom on
* cells are contiguous. It can perform the operation for read_dof_values(),
* distribute_local_to_global(), and set_dof_values() for several vectors at
* a time, depending on n_components.
*/
template <typename VectorType, typename VectorOperation>
void
read_write_operation_contiguous(
const VectorOperation & operation,
const std::array<VectorType *, n_components_> &vectors,
const std::array<
const std::vector<ArrayView<const typename VectorType::value_type>> *,
n_components_> & vectors_sm,
const std::bitset<VectorizedArrayType::size()> &mask) const;
/**
* A unified function to read from and write into vectors based on the given
* template operation for the case when we do not have an underlying
* MatrixFree object. It can perform the operation for @p read_dof_values,
* @p distribute_local_to_global, and @p set_dof_values. It performs the
* operation for several vectors at a time, depending on n_components.
*/
template <typename VectorType, typename VectorOperation>
void
read_write_operation_global(
const VectorOperation & operation,
const std::array<VectorType *, n_components_> &vectors) const;
/**
* Apply hanging-node constraints.
*/
void
apply_hanging_node_constraints(const bool transpose) const;
/**
* This is the general array for all data fields.
*/
AlignedVector<VectorizedArrayType> *scratch_data_array;
/**
* A pointer to the underlying data.
*/
const MatrixFree<dim, Number, VectorizedArrayType> *matrix_free;
/**
* A temporary data structure necessary to read degrees of freedom when no
* MatrixFree object was given at initialization.
*/
mutable std::vector<types::global_dof_index> local_dof_indices;
};
/**
* This class provides access to the data fields of the FEEvaluation classes.
* Generic access is achieved through the base class, and specializations for
* scalar and vector-valued elements are defined separately.
*
* @ingroup matrixfree
*/
template <int dim,
int n_components_,
typename Number,
bool is_face,
typename VectorizedArrayType = VectorizedArray<Number>>
class FEEvaluationAccess : public FEEvaluationBase<dim,
n_components_,
Number,
is_face,
VectorizedArrayType>
{
static_assert(
std::is_same<Number, typename VectorizedArrayType::value_type>::value,
"Type of Number and of VectorizedArrayType do not match.");
public:
using number_type = Number;
using value_type = Tensor<1, n_components_, VectorizedArrayType>;
using gradient_type =
Tensor<1, n_components_, Tensor<1, dim, VectorizedArrayType>>;
static constexpr unsigned int dimension = dim;
static constexpr unsigned int n_components = n_components_;
using BaseClass =
FEEvaluationBase<dim, n_components_, Number, is_face, VectorizedArrayType>;
protected:
/**
* Constructor. Made protected to prevent initialization in user code. Takes
* all data stored in MatrixFree. If applied to problems with more than one
* finite element or more than one quadrature formula selected during
* construction of @p matrix_free, @p first_selected_component and @p
* quad_no allow to select the appropriate components.
*/
FEEvaluationAccess(
const MatrixFree<dim, Number, VectorizedArrayType> &matrix_free,
const unsigned int dof_no,
const unsigned int first_selected_component,
const unsigned int quad_no,
const unsigned int fe_degree,
const unsigned int n_q_points,
const bool is_interior_face = true,
const unsigned int active_fe_index = numbers::invalid_unsigned_int,
const unsigned int active_quad_index = numbers::invalid_unsigned_int,
const unsigned int face_type = numbers::invalid_unsigned_int);
/**
* Constructor with reduced functionality for similar usage of FEEvaluation
* as FEValues, including matrix assembly.
*/
FEEvaluationAccess(
const Mapping<dim> & mapping,
const FiniteElement<dim> &fe,
const Quadrature<1> & quadrature,
const UpdateFlags update_flags,
const unsigned int first_selected_component,
const FEEvaluationData<dim, VectorizedArrayType, is_face> *other);
/**
* Copy constructor
*/
FEEvaluationAccess(const FEEvaluationAccess &other);
/**
* Copy assignment operator
*/
FEEvaluationAccess &
operator=(const FEEvaluationAccess &other);
};
/**
* This class provides access to the data fields of the FEEvaluation classes.
* Partial specialization for scalar fields that defines access with simple
* data fields, i.e., scalars for the values and Tensor<1,dim> for the
* gradients.
*
* @ingroup matrixfree
*/
template <int dim, typename Number, bool is_face, typename VectorizedArrayType>
class FEEvaluationAccess<dim, 1, Number, is_face, VectorizedArrayType>
: public FEEvaluationBase<dim, 1, Number, is_face, VectorizedArrayType>
{
static_assert(
std::is_same<Number, typename VectorizedArrayType::value_type>::value,
"Type of Number and of VectorizedArrayType do not match.");
public:
using number_type = Number;
using value_type = VectorizedArrayType;
using gradient_type = Tensor<1, dim, VectorizedArrayType>;
using hessian_type = Tensor<2, dim, VectorizedArrayType>;
static constexpr unsigned int dimension = dim;
using BaseClass =
FEEvaluationBase<dim, 1, Number, is_face, VectorizedArrayType>;
/**
* @copydoc FEEvaluationBase<dim,1,Number,is_face>::get_dof_value()
*/
value_type
get_dof_value(const unsigned int dof) const;
/**
* @copydoc FEEvaluationBase<dim,1,Number,is_face>::submit_dof_value()
*/
void
submit_dof_value(const value_type val_in, const unsigned int dof);
/**
* @copydoc FEEvaluationBase<dim,1,Number,is_face>::get_value()
*/
value_type
get_value(const unsigned int q_point) const;
/**
* @copydoc FEEvaluationBase<dim,1,Number,is_face>::submit_value()
*/
void
submit_value(const value_type val_in, const unsigned int q_point);
/**
* @copydoc FEEvaluationBase<dim,1,Number,is_face>::submit_value()
*/
void
submit_value(const Tensor<1, 1, VectorizedArrayType> val_in,
const unsigned int q_point);
/**
* @copydoc FEEvaluationBase<dim,1,Number,is_face>::get_gradient()
*/
gradient_type
get_gradient(const unsigned int q_point) const;
/**
* @copydoc FEEvaluationBase<dim,1,Number,is_face>::get_normal_derivative()
*/
value_type
get_normal_derivative(const unsigned int q_point) const;
/**
* @copydoc FEEvaluationBase<dim,1,Number,is_face>::submit_gradient()
*/
void
submit_gradient(const gradient_type grad_in, const unsigned int q_point);
/**
* @copydoc FEEvaluationBase<dim,1,Number,is_face>::submit_normal_derivative()
*/
void
submit_normal_derivative(const value_type grad_in,
const unsigned int q_point);
/**
* @copydoc FEEvaluationBase<dim,1,Number,is_face>::get_hessian()
*/
hessian_type
get_hessian(unsigned int q_point) const;
/**
* @copydoc FEEvaluationBase<dim,1,Number,is_face>::get_hessian_diagonal()
*/
gradient_type
get_hessian_diagonal(const unsigned int q_point) const;
/**
* @copydoc FEEvaluationBase<dim,1,Number,is_face>::submit_hessian()
*/
void
submit_hessian(const hessian_type hessian_in, const unsigned int q_point);
/**
* @copydoc FEEvaluationBase<dim,1,Number,is_face>::get_laplacian()
*/
value_type
get_laplacian(const unsigned int q_point) const;
/**
* @copydoc FEEvaluationBase<dim,1,Number,is_face>::integrate_value()
*/
value_type
integrate_value() const;
protected:
/**
* Constructor. Made protected to avoid initialization in user code. Takes
* all data stored in MatrixFree. If applied to problems with more than one
* finite element or more than one quadrature formula selected during
* construction of @p matrix_free, @p first_selected_component and @p
* quad_no allow to select the appropriate components.
*/
FEEvaluationAccess(
const MatrixFree<dim, Number, VectorizedArrayType> &matrix_free,
const unsigned int dof_no,
const unsigned int first_selected_component,
const unsigned int quad_no,
const unsigned int fe_degree,
const unsigned int n_q_points,
const bool is_interior_face = true,
const unsigned int active_fe_index = numbers::invalid_unsigned_int,
const unsigned int active_quad_index = numbers::invalid_unsigned_int,
const unsigned int face_type = numbers::invalid_unsigned_int);
/**
* Constructor with reduced functionality for similar usage of FEEvaluation
* as FEValues, including matrix assembly.
*/
FEEvaluationAccess(
const Mapping<dim> & mapping,
const FiniteElement<dim> &fe,