-
Notifications
You must be signed in to change notification settings - Fork 708
/
evaluation_kernels.h
2526 lines (2277 loc) · 105 KB
/
evaluation_kernels.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) 2017 - 2023 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_evaluation_kernels_h
#define dealii_matrix_free_evaluation_kernels_h
#include <deal.II/base/config.h>
#include <deal.II/base/utilities.h>
#include <deal.II/base/vectorization.h>
#include <deal.II/matrix_free/evaluation_flags.h>
#include <deal.II/matrix_free/fe_evaluation_data.h>
#include <deal.II/matrix_free/shape_info.h>
#include <deal.II/matrix_free/tensor_product_kernels.h>
DEAL_II_NAMESPACE_OPEN
namespace internal
{
// Select evaluator type from element shape function type
template <MatrixFreeFunctions::ElementType element, bool is_long>
struct EvaluatorSelector
{};
template <bool is_long>
struct EvaluatorSelector<MatrixFreeFunctions::tensor_general, is_long>
{
static const EvaluatorVariant variant = evaluate_general;
};
template <>
struct EvaluatorSelector<MatrixFreeFunctions::tensor_symmetric, false>
{
static const EvaluatorVariant variant = evaluate_symmetric;
};
template <>
struct EvaluatorSelector<MatrixFreeFunctions::tensor_symmetric, true>
{
static const EvaluatorVariant variant = evaluate_evenodd;
};
template <bool is_long>
struct EvaluatorSelector<MatrixFreeFunctions::truncated_tensor, is_long>
{
static const EvaluatorVariant variant = evaluate_general;
};
template <>
struct EvaluatorSelector<MatrixFreeFunctions::tensor_symmetric_plus_dg0,
false>
{
static const EvaluatorVariant variant = evaluate_general;
};
template <>
struct EvaluatorSelector<MatrixFreeFunctions::tensor_symmetric_plus_dg0, true>
{
static const EvaluatorVariant variant = evaluate_evenodd;
};
template <bool is_long>
struct EvaluatorSelector<MatrixFreeFunctions::tensor_symmetric_collocation,
is_long>
{
static const EvaluatorVariant variant = evaluate_evenodd;
};
/**
* This struct performs the evaluation of function values and gradients for
* tensor-product finite elements. The operation is used for both the
* symmetric and non-symmetric case, which use different apply functions
* 'values', 'gradients' in the individual coordinate directions. The apply
* functions for values are provided through one of the template classes
* EvaluatorTensorProduct which in turn are selected from the
* MatrixFreeFunctions::ElementType template argument.
*
* There are two specialized implementation classes
* FEEvaluationImplCollocation (for Gauss-Lobatto elements where the nodal
* points and the quadrature points coincide and the 'values' operation is
* identity) and FEEvaluationImplTransformToCollocation (which can be
* transformed to a collocation space and can then use the identity in these
* spaces), which both allow for shorter code.
*
* @note Hessians of the solution are handled in the general
* FEEvaluationImplSelector struct below, because they can be implemented
* with the only two code paths for all supported cases, including the
* specialized cases below.
*/
template <MatrixFreeFunctions::ElementType type,
int dim,
int fe_degree,
int n_q_points_1d,
typename Number>
struct FEEvaluationImpl
{
static const EvaluatorVariant variant =
EvaluatorSelector<type, (fe_degree + n_q_points_1d > 4)>::variant;
using Number2 =
typename FEEvaluationData<dim, Number, false>::shape_info_number_type;
using Eval = EvaluatorTensorProduct<variant,
dim,
fe_degree + 1,
n_q_points_1d,
Number,
Number2>;
static void
evaluate(const unsigned int n_components,
const EvaluationFlags::EvaluationFlags evaluation_flag,
const Number *values_dofs_actual,
FEEvaluationData<dim, Number, false> &fe_eval);
static void
integrate(const unsigned int n_components,
const EvaluationFlags::EvaluationFlags integration_flag,
Number *values_dofs_actual,
FEEvaluationData<dim, Number, false> &fe_eval,
const bool add_into_values_array);
static Eval
create_evaluator_tensor_product(
const MatrixFreeFunctions::UnivariateShapeData<Number2>
*univariate_shape_data)
{
if (variant == evaluate_evenodd)
return Eval(univariate_shape_data->shape_values_eo,
univariate_shape_data->shape_gradients_eo,
univariate_shape_data->shape_hessians_eo,
univariate_shape_data->fe_degree + 1,
univariate_shape_data->n_q_points_1d);
else
return Eval(univariate_shape_data->shape_values,
univariate_shape_data->shape_gradients,
univariate_shape_data->shape_hessians,
univariate_shape_data->fe_degree + 1,
univariate_shape_data->n_q_points_1d);
}
};
/**
* Specialization for MatrixFreeFunctions::tensor_none, which cannot use the
* sum-factorization kernels.
*/
template <int dim, int fe_degree, int n_q_points_1d, typename Number>
struct FEEvaluationImpl<MatrixFreeFunctions::tensor_none,
dim,
fe_degree,
n_q_points_1d,
Number>
{
static void
evaluate(const unsigned int n_components,
const EvaluationFlags::EvaluationFlags evaluation_flag,
const Number *values_dofs_actual,
FEEvaluationData<dim, Number, false> &fe_eval);
static void
integrate(const unsigned int n_components,
const EvaluationFlags::EvaluationFlags integration_flag,
Number *values_dofs_actual,
FEEvaluationData<dim, Number, false> &fe_eval,
const bool add_into_values_array);
};
template <MatrixFreeFunctions::ElementType type,
int dim,
int fe_degree,
int n_q_points_1d,
typename Number>
inline void
FEEvaluationImpl<type, dim, fe_degree, n_q_points_1d, Number>::evaluate(
const unsigned int n_components,
const EvaluationFlags::EvaluationFlags evaluation_flag,
const Number *values_dofs_actual,
FEEvaluationData<dim, Number, false> &fe_eval)
{
if (evaluation_flag == EvaluationFlags::nothing)
return;
std::array<const MatrixFreeFunctions::UnivariateShapeData<Number2> *, 3>
univariate_shape_data;
const auto &shape_data = fe_eval.get_shape_info().data;
univariate_shape_data.fill(&shape_data.front());
if (shape_data.size() == dim)
for (int i = 1; i < dim; ++i)
univariate_shape_data[i] = &shape_data[i];
Eval eval0 = create_evaluator_tensor_product(univariate_shape_data[0]);
Eval eval1 = create_evaluator_tensor_product(univariate_shape_data[1]);
Eval eval2 = create_evaluator_tensor_product(univariate_shape_data[2]);
const unsigned int temp_size =
Eval::n_rows_of_product == numbers::invalid_unsigned_int ?
0 :
(Eval::n_rows_of_product > Eval::n_columns_of_product ?
Eval::n_rows_of_product :
Eval::n_columns_of_product);
Number *temp1 = fe_eval.get_scratch_data().begin();
Number *temp2;
if (temp_size == 0)
{
temp2 = temp1 + std::max(Utilities::fixed_power<dim>(
shape_data.front().fe_degree + 1),
Utilities::fixed_power<dim>(
shape_data.front().n_q_points_1d));
}
else
{
temp2 = temp1 + temp_size;
}
const std::size_t n_q_points = temp_size == 0 ?
fe_eval.get_shape_info().n_q_points :
Eval::n_columns_of_product;
const std::size_t dofs_per_comp =
(type == MatrixFreeFunctions::truncated_tensor) ?
Utilities::pow(shape_data.front().fe_degree + 1, dim) :
fe_eval.get_shape_info().dofs_per_component_on_cell;
const Number *values_dofs = values_dofs_actual;
if (type == MatrixFreeFunctions::truncated_tensor)
{
const std::size_t n_dofs_per_comp =
fe_eval.get_shape_info().dofs_per_component_on_cell;
Number *values_dofs_tmp =
temp1 + 2 * (std::max(n_dofs_per_comp, n_q_points));
const int degree =
fe_degree != -1 ? fe_degree : shape_data.front().fe_degree;
for (unsigned int c = 0; c < n_components; ++c)
for (int i = 0, count_p = 0, count_q = 0;
i < (dim > 2 ? degree + 1 : 1);
++i)
{
for (int j = 0; j < (dim > 1 ? degree + 1 - i : 1); ++j)
{
for (int k = 0; k < degree + 1 - j - i;
++k, ++count_p, ++count_q)
values_dofs_tmp[c * dofs_per_comp + count_q] =
values_dofs_actual[c * n_dofs_per_comp + count_p];
for (int k = degree + 1 - j - i; k < degree + 1;
++k, ++count_q)
values_dofs_tmp[c * dofs_per_comp + count_q] = Number();
}
for (int j = degree + 1 - i; j < degree + 1; ++j)
for (int k = 0; k < degree + 1; ++k, ++count_q)
values_dofs_tmp[c * dofs_per_comp + count_q] = Number();
}
values_dofs = values_dofs_tmp;
}
Number *values_quad = fe_eval.begin_values();
Number *gradients_quad = fe_eval.begin_gradients();
switch (dim)
{
case 1:
for (unsigned int c = 0; c < n_components; ++c)
{
if (evaluation_flag & EvaluationFlags::values)
eval0.template values<0, true, false>(values_dofs, values_quad);
if (evaluation_flag & EvaluationFlags::gradients)
eval0.template gradients<0, true, false>(values_dofs,
gradients_quad);
// advance the next component in 1d array
values_dofs += dofs_per_comp;
values_quad += n_q_points;
gradients_quad += n_q_points;
}
break;
case 2:
for (unsigned int c = 0; c < n_components; ++c)
{
// grad x
if (evaluation_flag & EvaluationFlags::gradients)
{
eval0.template gradients<0, true, false>(values_dofs, temp1);
eval1.template values<1, true, false, 2>(temp1,
gradients_quad);
}
// grad y
eval0.template values<0, true, false>(values_dofs, temp1);
if (evaluation_flag & EvaluationFlags::gradients)
eval1.template gradients<1, true, false, 2>(temp1,
gradients_quad + 1);
// val: can use values applied in x
if (evaluation_flag & EvaluationFlags::values)
eval1.template values<1, true, false>(temp1, values_quad);
// advance to the next component in 1d array
values_dofs += dofs_per_comp;
values_quad += n_q_points;
gradients_quad += 2 * n_q_points;
}
break;
case 3:
for (unsigned int c = 0; c < n_components; ++c)
{
if (evaluation_flag & EvaluationFlags::gradients)
{
// grad x
eval0.template gradients<0, true, false>(values_dofs, temp1);
eval1.template values<1, true, false>(temp1, temp2);
eval2.template values<2, true, false, 3>(temp2,
gradients_quad);
}
// grad y
eval0.template values<0, true, false>(values_dofs, temp1);
if (evaluation_flag & EvaluationFlags::gradients)
{
eval1.template gradients<1, true, false>(temp1, temp2);
eval2.template values<2, true, false, 3>(temp2,
gradients_quad + 1);
}
// grad z: can use the values applied in x direction stored in
// temp1
eval1.template values<1, true, false>(temp1, temp2);
if (evaluation_flag & EvaluationFlags::gradients)
eval2.template gradients<2, true, false, 3>(temp2,
gradients_quad + 2);
// val: can use the values applied in x & y direction stored in
// temp2
if (evaluation_flag & EvaluationFlags::values)
eval2.template values<2, true, false>(temp2, values_quad);
// advance to the next component in 1d array
values_dofs += dofs_per_comp;
values_quad += n_q_points;
gradients_quad += 3 * n_q_points;
}
break;
default:
AssertThrow(false, ExcNotImplemented());
}
// case additional dof for FE_Q_DG0: add values; gradients and second
// derivatives evaluate to zero
if (type == MatrixFreeFunctions::tensor_symmetric_plus_dg0 &&
(evaluation_flag & EvaluationFlags::values))
{
values_quad -= n_components * n_q_points;
values_dofs -= n_components * dofs_per_comp;
for (std::size_t c = 0; c < n_components; ++c)
for (std::size_t q = 0; q < n_q_points; ++q)
values_quad[c * n_q_points + q] +=
values_dofs[(c + 1) * dofs_per_comp - 1];
}
}
template <MatrixFreeFunctions::ElementType type,
int dim,
int fe_degree,
int n_q_points_1d,
typename Number>
inline void
FEEvaluationImpl<type, dim, fe_degree, n_q_points_1d, Number>::integrate(
const unsigned int n_components,
const EvaluationFlags::EvaluationFlags integration_flag,
Number *values_dofs_actual,
FEEvaluationData<dim, Number, false> &fe_eval,
const bool add_into_values_array)
{
std::array<const MatrixFreeFunctions::UnivariateShapeData<Number2> *, 3>
univariate_shape_data;
const auto &shape_data = fe_eval.get_shape_info().data;
univariate_shape_data.fill(&shape_data.front());
if (shape_data.size() == dim)
for (int i = 1; i < dim; ++i)
univariate_shape_data[i] = &shape_data[i];
Eval eval0 = create_evaluator_tensor_product(univariate_shape_data[0]);
Eval eval1 = create_evaluator_tensor_product(univariate_shape_data[1]);
Eval eval2 = create_evaluator_tensor_product(univariate_shape_data[2]);
const unsigned int temp_size =
Eval::n_rows_of_product == numbers::invalid_unsigned_int ?
0 :
(Eval::n_rows_of_product > Eval::n_columns_of_product ?
Eval::n_rows_of_product :
Eval::n_columns_of_product);
Number *temp1 = fe_eval.get_scratch_data().begin();
Number *temp2;
if (temp_size == 0)
{
temp2 = temp1 + std::max(Utilities::fixed_power<dim>(
shape_data.front().fe_degree + 1),
Utilities::fixed_power<dim>(
shape_data.front().n_q_points_1d));
}
else
{
temp2 = temp1 + temp_size;
}
const std::size_t n_q_points = temp_size == 0 ?
fe_eval.get_shape_info().n_q_points :
Eval::n_columns_of_product;
const unsigned int dofs_per_comp =
(type == MatrixFreeFunctions::truncated_tensor) ?
Utilities::fixed_power<dim>(shape_data.front().fe_degree + 1) :
fe_eval.get_shape_info().dofs_per_component_on_cell;
// expand dof_values to tensor product for truncated tensor products
Number *values_dofs =
(type == MatrixFreeFunctions::truncated_tensor) ?
temp1 + 2 * (std::max<std::size_t>(
fe_eval.get_shape_info().dofs_per_component_on_cell,
n_q_points)) :
values_dofs_actual;
Number *values_quad = fe_eval.begin_values();
Number *gradients_quad = fe_eval.begin_gradients();
switch (dim)
{
case 1:
for (unsigned int c = 0; c < n_components; ++c)
{
if (integration_flag & EvaluationFlags::values)
{
if (add_into_values_array == false)
eval0.template values<0, false, false>(values_quad,
values_dofs);
else
eval0.template values<0, false, true>(values_quad,
values_dofs);
}
if (integration_flag & EvaluationFlags::gradients)
{
if (integration_flag & EvaluationFlags::values ||
add_into_values_array == true)
eval0.template gradients<0, false, true>(gradients_quad,
values_dofs);
else
eval0.template gradients<0, false, false>(gradients_quad,
values_dofs);
}
// advance to the next component in 1d array
values_dofs += dofs_per_comp;
values_quad += n_q_points;
gradients_quad += n_q_points;
}
break;
case 2:
for (unsigned int c = 0; c < n_components; ++c)
{
if ((integration_flag & EvaluationFlags::values) &&
!(integration_flag & EvaluationFlags::gradients))
{
eval1.template values<1, false, false>(values_quad, temp1);
if (add_into_values_array == false)
eval0.template values<0, false, false>(temp1, values_dofs);
else
eval0.template values<0, false, true>(temp1, values_dofs);
}
if (integration_flag & EvaluationFlags::gradients)
{
eval1.template gradients<1, false, false, 2>(gradients_quad +
1,
temp1);
if (integration_flag & EvaluationFlags::values)
eval1.template values<1, false, true>(values_quad, temp1);
if (add_into_values_array == false)
eval0.template values<0, false, false>(temp1, values_dofs);
else
eval0.template values<0, false, true>(temp1, values_dofs);
eval1.template values<1, false, false, 2>(gradients_quad,
temp1);
eval0.template gradients<0, false, true>(temp1, values_dofs);
}
// advance to the next component in 1d array
values_dofs += dofs_per_comp;
values_quad += n_q_points;
gradients_quad += 2 * n_q_points;
}
break;
case 3:
for (unsigned int c = 0; c < n_components; ++c)
{
if ((integration_flag & EvaluationFlags::values) &&
!(integration_flag & EvaluationFlags::gradients))
{
eval2.template values<2, false, false>(values_quad, temp1);
eval1.template values<1, false, false>(temp1, temp2);
if (add_into_values_array == false)
eval0.template values<0, false, false>(temp2, values_dofs);
else
eval0.template values<0, false, true>(temp2, values_dofs);
}
if (integration_flag & EvaluationFlags::gradients)
{
eval2.template gradients<2, false, false, 3>(gradients_quad +
2,
temp1);
if (integration_flag & EvaluationFlags::values)
eval2.template values<2, false, true>(values_quad, temp1);
eval1.template values<1, false, false>(temp1, temp2);
eval2.template values<2, false, false, 3>(gradients_quad + 1,
temp1);
eval1.template gradients<1, false, true>(temp1, temp2);
if (add_into_values_array == false)
eval0.template values<0, false, false>(temp2, values_dofs);
else
eval0.template values<0, false, true>(temp2, values_dofs);
eval2.template values<2, false, false, 3>(gradients_quad,
temp1);
eval1.template values<1, false, false>(temp1, temp2);
eval0.template gradients<0, false, true>(temp2, values_dofs);
}
// advance to the next component in 1d array
values_dofs += dofs_per_comp;
values_quad += n_q_points;
gradients_quad += 3 * n_q_points;
}
break;
default:
AssertThrow(false, ExcNotImplemented());
}
// case FE_Q_DG0: add values, gradients and second derivatives are zero
if (type == MatrixFreeFunctions::tensor_symmetric_plus_dg0)
{
values_dofs -= n_components * dofs_per_comp - dofs_per_comp + 1;
values_quad -= n_components * n_q_points;
if (integration_flag & EvaluationFlags::values)
for (unsigned int c = 0; c < n_components; ++c)
{
values_dofs[0] = values_quad[0];
for (unsigned int q = 1; q < n_q_points; ++q)
values_dofs[0] += values_quad[q];
values_dofs += dofs_per_comp;
values_quad += n_q_points;
}
else
{
for (unsigned int c = 0; c < n_components; ++c)
values_dofs[c * dofs_per_comp] = Number();
values_dofs += n_components * dofs_per_comp;
}
}
if (type == MatrixFreeFunctions::truncated_tensor)
{
const std::size_t n_dofs_per_comp =
fe_eval.get_shape_info().dofs_per_component_on_cell;
values_dofs -= dofs_per_comp * n_components;
const int degree =
fe_degree != -1 ? fe_degree : shape_data.front().fe_degree;
for (unsigned int c = 0; c < n_components; ++c)
for (int i = 0, count_p = 0, count_q = 0;
i < (dim > 2 ? degree + 1 : 1);
++i)
{
for (int j = 0; j < (dim > 1 ? degree + 1 - i : 1); ++j)
{
for (int k = 0; k < degree + 1 - j - i;
++k, ++count_p, ++count_q)
values_dofs_actual[c * n_dofs_per_comp + count_p] =
values_dofs[c * dofs_per_comp + count_q];
count_q += j + i;
}
count_q += i * (degree + 1);
}
}
}
template <int dim, int fe_degree, int n_q_points_1d, typename Number>
inline void
FEEvaluationImpl<
MatrixFreeFunctions::tensor_none,
dim,
fe_degree,
n_q_points_1d,
Number>::evaluate(const unsigned int n_components,
const EvaluationFlags::EvaluationFlags evaluation_flag,
const Number *values_dofs_actual,
FEEvaluationData<dim, Number, false> &fe_eval)
{
Assert(!(evaluation_flag & EvaluationFlags::hessians), ExcNotImplemented());
const std::size_t n_dofs =
fe_eval.get_shape_info().dofs_per_component_on_cell;
const std::size_t n_q_points = fe_eval.get_shape_info().n_q_points;
const auto &shape_data = fe_eval.get_shape_info().data;
using Number2 =
typename FEEvaluationData<dim, Number, false>::shape_info_number_type;
using Eval =
EvaluatorTensorProduct<evaluate_general, 1, 0, 0, Number, Number2>;
if (evaluation_flag & EvaluationFlags::values)
{
const auto *const shape_values = shape_data.front().shape_values.data();
auto *values_quad_ptr = fe_eval.begin_values();
const auto *values_dofs_actual_ptr = values_dofs_actual;
Eval eval(shape_values, nullptr, nullptr, n_dofs, n_q_points);
for (unsigned int c = 0; c < n_components; ++c)
{
eval.template values<0, true, false>(values_dofs_actual_ptr,
values_quad_ptr);
values_quad_ptr += n_q_points;
values_dofs_actual_ptr += n_dofs;
}
}
if (evaluation_flag & EvaluationFlags::gradients)
{
const auto *const shape_gradients =
shape_data.front().shape_gradients.data();
auto *gradients_quad_ptr = fe_eval.begin_gradients();
const auto *values_dofs_actual_ptr = values_dofs_actual;
for (unsigned int c = 0; c < n_components; ++c)
{
for (unsigned int d = 0; d < dim; ++d)
{
Eval eval(nullptr,
shape_gradients + n_q_points * n_dofs * d,
nullptr,
n_dofs,
n_q_points);
eval.template gradients<0, true, false, dim>(
values_dofs_actual_ptr, gradients_quad_ptr + d);
}
gradients_quad_ptr += n_q_points * dim;
values_dofs_actual_ptr += n_dofs;
}
}
}
template <int dim, int fe_degree, int n_q_points_1d, typename Number>
inline void
FEEvaluationImpl<
MatrixFreeFunctions::tensor_none,
dim,
fe_degree,
n_q_points_1d,
Number>::integrate(const unsigned int n_components,
const EvaluationFlags::EvaluationFlags integration_flag,
Number *values_dofs_actual,
FEEvaluationData<dim, Number, false> &fe_eval,
const bool add_into_values_array)
{
Assert(!(integration_flag & EvaluationFlags::hessians),
ExcNotImplemented());
const std::size_t n_dofs =
fe_eval.get_shape_info().dofs_per_component_on_cell;
const std::size_t n_q_points = fe_eval.get_shape_info().n_q_points;
const auto &shape_data = fe_eval.get_shape_info().data;
using Number2 =
typename FEEvaluationData<dim, Number, false>::shape_info_number_type;
using Eval =
EvaluatorTensorProduct<evaluate_general, 1, 0, 0, Number, Number2>;
if (integration_flag & EvaluationFlags::values)
{
const auto *const shape_values = shape_data.front().shape_values.data();
auto *values_quad_ptr = fe_eval.begin_values();
auto *values_dofs_actual_ptr = values_dofs_actual;
Eval eval(shape_values, nullptr, nullptr, n_dofs, n_q_points);
for (unsigned int c = 0; c < n_components; ++c)
{
if (add_into_values_array == false)
eval.template values<0, false, false>(values_quad_ptr,
values_dofs_actual_ptr);
else
eval.template values<0, false, true>(values_quad_ptr,
values_dofs_actual_ptr);
values_quad_ptr += n_q_points;
values_dofs_actual_ptr += n_dofs;
}
}
if (integration_flag & EvaluationFlags::gradients)
{
const auto *const shape_gradients =
shape_data.front().shape_gradients.data();
auto *gradients_quad_ptr = fe_eval.begin_gradients();
auto *values_dofs_actual_ptr = values_dofs_actual;
for (unsigned int c = 0; c < n_components; ++c)
{
for (unsigned int d = 0; d < dim; ++d)
{
Eval eval(nullptr,
shape_gradients + n_q_points * n_dofs * d,
nullptr,
n_dofs,
n_q_points);
if ((add_into_values_array == false &&
!(integration_flag & EvaluationFlags::values)) &&
d == 0)
eval.template gradients<0, false, false, dim>(
gradients_quad_ptr + d, values_dofs_actual_ptr);
else
eval.template gradients<0, false, true, dim>(
gradients_quad_ptr + d, values_dofs_actual_ptr);
}
gradients_quad_ptr += n_q_points * dim;
values_dofs_actual_ptr += n_dofs;
}
}
}
/**
* This struct implements the change between two different bases. This is an
* ingredient in the FEEvaluationImplTransformToCollocation class where we
* first transform to the appropriate basis where we can compute the
* derivative through collocation techniques.
*
* This class allows for dimension-independent application of the operation,
* implemented by template recursion. It has been tested up to 6d.
*/
template <EvaluatorVariant variant,
EvaluatorQuantity quantity,
int dim,
int basis_size_1,
int basis_size_2>
struct FEEvaluationImplBasisChange
{
static_assert(basis_size_1 == 0 || basis_size_1 <= basis_size_2,
"The second dimension must not be smaller than the first");
/**
* This applies the transformation that contracts over the rows of the
* coefficient array, generating values along the columns of the
* coefficient array.
*
* @param n_components The number of vector components.
* @param transformation_matrix The coefficient matrix handed in as a
* vector, using @p basis_size_1 rows and @p basis_size_2
* columns if interpreted as a matrix.
* @param values_in The array of the input of size basis_size_1^dim. It
* may alias with values_out
* @param values_out The array of size basis_size_2^dim where the results
* of the transformation are stored. It may alias with
* the values_in array.
* @param basis_size_1_variable In case the template argument
* @p basis_size_1 is zero, the size of the first basis can alternatively
* be passed in as a run time argument. The template argument takes
* precedence in case it is nonzero for efficiency reasons.
* @param basis_size_2_variable In case the template argument
* @p basis_size_1 is zero, the size of the second basis can alternatively
* be passed in as a run time argument.
*/
template <typename Number, typename Number2>
#ifndef DEBUG
DEAL_II_ALWAYS_INLINE
#endif
static void
do_forward(const unsigned int n_components,
const AlignedVector<Number2> &transformation_matrix,
const Number *values_in,
Number *values_out,
const unsigned int basis_size_1_variable =
numbers::invalid_unsigned_int,
const unsigned int basis_size_2_variable =
numbers::invalid_unsigned_int)
{
Assert(
basis_size_1 != 0 || basis_size_1_variable <= basis_size_2_variable,
ExcMessage("The second dimension must not be smaller than the first"));
Assert(quantity == EvaluatorQuantity::value, ExcInternalError());
// we do recursion until dim==1 or dim==2 and we have
// basis_size_1==basis_size_2. The latter optimization increases
// optimization possibilities for the compiler but does only work for
// aliased pointers if the sizes are equal.
constexpr int next_dim = (dim == 1 || (dim == 2 && basis_size_1 > 0 &&
basis_size_1 == basis_size_2)) ?
dim :
dim - 1;
EvaluatorTensorProduct<variant,
dim,
basis_size_1,
(basis_size_1 == 0 ? 0 : basis_size_2),
Number,
Number2>
eval_val(transformation_matrix,
{},
{},
basis_size_1_variable,
basis_size_2_variable);
const unsigned int np_1 =
basis_size_1 > 0 ? basis_size_1 : basis_size_1_variable;
const unsigned int np_2 =
basis_size_1 > 0 ? basis_size_2 : basis_size_2_variable;
Assert(np_1 > 0 && np_1 != numbers::invalid_unsigned_int,
ExcMessage("Cannot transform with 0-point basis"));
Assert(np_2 > 0 && np_2 != numbers::invalid_unsigned_int,
ExcMessage("Cannot transform with 0-point basis"));
// run loop backwards to ensure correctness if values_in aliases with
// values_out in case with basis_size_1 < basis_size_2
values_in = values_in + n_components * Utilities::fixed_power<dim>(np_1);
values_out =
values_out + n_components * Utilities::fixed_power<dim>(np_2);
for (unsigned int c = n_components; c != 0; --c)
{
values_in -= Utilities::fixed_power<dim>(np_1);
values_out -= Utilities::fixed_power<dim>(np_2);
if (next_dim < dim)
for (unsigned int q = np_1; q != 0; --q)
FEEvaluationImplBasisChange<variant,
quantity,
next_dim,
basis_size_1,
basis_size_2>::
do_forward(1,
transformation_matrix,
values_in +
(q - 1) * Utilities::fixed_power<next_dim>(np_1),
values_out +
(q - 1) * Utilities::fixed_power<next_dim>(np_2),
basis_size_1_variable,
basis_size_2_variable);
// the recursion stops if dim==1 or if dim==2 and
// basis_size_1==basis_size_2 (the latter is used because the
// compiler generates nicer code)
if (basis_size_1 > 0 && basis_size_2 == basis_size_1 && dim == 2)
{
eval_val.template values<0, true, false>(values_in, values_out);
eval_val.template values<1, true, false>(values_out, values_out);
}
else if (dim == 1)
eval_val.template values<dim - 1, true, false>(values_in,
values_out);
else
eval_val.template values<dim - 1, true, false>(values_out,
values_out);
}
}
/**
* This applies the transformation that contracts over the columns of the
* coefficient array, generating values along the rows of the coefficient
* array.
*
* @param n_components The number of vector components.
* @param transformation_matrix The coefficient matrix handed in as a
* vector, using @p basis_size_1 rows and @p basis_size_2
* columns if interpreted as a matrix.
* @param add_into_result Define whether the result should be added into the
* array @p values_out (if true) or overwrite the
* previous content. The result is undefined in case
* values_in and values_out point to the same array and
* @p add_into_result is true, in which case an
* exception is thrown.
* @param values_in The array of the input of size basis_size_2^dim. It
* may alias with values_out. Note that the previous
* content of @p values_in is overwritten within the
* function.
* @param values_out The array of size basis_size_1^dim where the results
* of the transformation are stored. It may alias with
* the @p values_in array.
* @param basis_size_1_variable In case the template argument
* @p basis_size_1 is zero, the size of the first basis can alternatively
* be passed in as a run time argument. The template argument takes
* precedence in case it is nonzero for efficiency reasons.
* @param basis_size_2_variable In case the template argument
* @p basis_size_1 is zero, the size of the second basis can alternatively
* be passed in as a run time argument.
*/
template <typename Number, typename Number2>
#ifndef DEBUG
DEAL_II_ALWAYS_INLINE
#endif
static void
do_backward(const unsigned int n_components,
const AlignedVector<Number2> &transformation_matrix,
const bool add_into_result,
Number *values_in,
Number *values_out,
const unsigned int basis_size_1_variable =
numbers::invalid_unsigned_int,
const unsigned int basis_size_2_variable =
numbers::invalid_unsigned_int)
{
Assert(
basis_size_1 != 0 || basis_size_1_variable <= basis_size_2_variable,
ExcMessage("The second dimension must not be smaller than the first"));
Assert(add_into_result == false || values_in != values_out,
ExcMessage(
"Input and output cannot alias with each other when "
"adding the result of the basis change to existing data"));
Assert(quantity == EvaluatorQuantity::value ||
quantity == EvaluatorQuantity::hessian,
ExcInternalError());
constexpr int next_dim =
(dim > 2 ||
((basis_size_1 == 0 || basis_size_2 > basis_size_1) && dim > 1)) ?
dim - 1 :
dim;
EvaluatorTensorProduct<variant,
dim,
basis_size_1,
(basis_size_1 == 0 ? 0 : basis_size_2),
Number,
Number2>
eval_val(transformation_matrix,
transformation_matrix,
transformation_matrix,
basis_size_1_variable,
basis_size_2_variable);
const unsigned int np_1 =
basis_size_1 > 0 ? basis_size_1 : basis_size_1_variable;
const unsigned int np_2 =
basis_size_1 > 0 ? basis_size_2 : basis_size_2_variable;
Assert(np_1 > 0 && np_1 != numbers::invalid_unsigned_int,
ExcMessage("Cannot transform with 0-point basis"));
Assert(np_2 > 0 && np_2 != numbers::invalid_unsigned_int,
ExcMessage("Cannot transform with 0-point basis"));
for (unsigned int c = 0; c < n_components; ++c)
{
if (basis_size_1 > 0 && basis_size_2 == basis_size_1 && dim == 2)
{
if (quantity == EvaluatorQuantity::value)
eval_val.template values<1, false, false>(values_in, values_in);
else
eval_val.template hessians<1, false, false>(values_in,
values_in);
if (add_into_result)
{
if (quantity == EvaluatorQuantity::value)
eval_val.template values<0, false, true>(values_in,
values_out);
else
eval_val.template hessians<0, false, true>(values_in,
values_out);
}
else
{
if (quantity == EvaluatorQuantity::value)
eval_val.template values<0, false, false>(values_in,