/
fe_nedelec.cc
4132 lines (3667 loc) · 187 KB
/
fe_nedelec.cc
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) 2013 - 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.
//
// ---------------------------------------------------------------------
#include <deal.II/base/logstream.h>
#include <deal.II/base/qprojector.h>
#include <deal.II/base/quadrature.h>
#include <deal.II/base/quadrature_lib.h>
#include <deal.II/base/utilities.h>
#include <deal.II/dofs/dof_accessor.h>
#include <deal.II/fe/fe_nedelec.h>
#include <deal.II/fe/fe_nothing.h>
#include <deal.II/fe/fe_tools.h>
#include <deal.II/fe/fe_values.h>
#include <deal.II/fe/mapping.h>
#include <deal.II/grid/tria.h>
#include <deal.II/grid/tria_iterator.h>
#include <deal.II/lac/full_matrix.h>
#include <deal.II/lac/vector.h>
#include <iostream>
#include <memory>
#include <sstream>
DEAL_II_NAMESPACE_OPEN
//#define DEBUG_NEDELEC
namespace internal
{
namespace FE_Nedelec
{
namespace
{
double
get_embedding_computation_tolerance(const unsigned int p)
{
// This heuristic was computed by monitoring the worst residual
// resulting from the least squares computation when computing
// the face embedding matrices in the FE_Nedelec constructor.
// The residual growth is exponential, but is bounded by this
// function up to degree 12.
return 1.e-15 * std::exp(std::pow(p, 1.075));
}
} // namespace
} // namespace FE_Nedelec
} // namespace internal
// TODO: implement the adjust_quad_dof_index_for_face_orientation_table and
// adjust_line_dof_index_for_line_orientation_table fields, and write tests
// similar to bits/face_orientation_and_fe_q_*
template <int dim>
FE_Nedelec<dim>::FE_Nedelec(const unsigned int order)
: FE_PolyTensor<dim>(
PolynomialsNedelec<dim>(order),
FiniteElementData<dim>(get_dpo_vector(order),
dim,
order + 1,
FiniteElementData<dim>::Hcurl),
std::vector<bool>(PolynomialsNedelec<dim>::n_polynomials(order), true),
std::vector<ComponentMask>(PolynomialsNedelec<dim>::n_polynomials(order),
std::vector<bool>(dim, true)))
{
#ifdef DEBUG_NEDELEC
deallog << get_name() << std::endl;
#endif
Assert(dim >= 2, ExcImpossibleInDim(dim));
const unsigned int n_dofs = this->n_dofs_per_cell();
this->mapping_kind = {mapping_nedelec};
// First, initialize the
// generalized support points and
// quadrature weights, since they
// are required for interpolation.
initialize_support_points(order);
this->inverse_node_matrix.reinit(n_dofs, n_dofs);
this->inverse_node_matrix.fill(FullMatrix<double>(IdentityMatrix(n_dofs)));
// From now on, the shape functions
// will be the correct ones, not
// the raw shape functions anymore.
// do not initialize embedding and restriction here. these matrices are
// initialized on demand in get_restriction_matrix and
// get_prolongation_matrix
#ifdef DEBUG_NEDELEC
deallog << "Face Embedding" << std::endl;
#endif
FullMatrix<double> face_embeddings[GeometryInfo<dim>::max_children_per_face];
// TODO: the implementation makes the assumption that all faces have the
// same number of dofs
AssertDimension(this->n_unique_faces(), 1);
const unsigned int face_no = 0;
for (unsigned int i = 0; i < GeometryInfo<dim>::max_children_per_face; ++i)
face_embeddings[i].reinit(this->n_dofs_per_face(face_no),
this->n_dofs_per_face(face_no));
FETools::compute_face_embedding_matrices<dim, double>(
*this,
face_embeddings,
0,
0,
internal::FE_Nedelec::get_embedding_computation_tolerance(order));
switch (dim)
{
case 1:
{
this->interface_constraints.reinit(0, 0);
break;
}
case 2:
{
this->interface_constraints.reinit(2 * this->n_dofs_per_face(face_no),
this->n_dofs_per_face(face_no));
for (unsigned int i = 0; i < GeometryInfo<2>::max_children_per_face;
++i)
for (unsigned int j = 0; j < this->n_dofs_per_face(face_no); ++j)
for (unsigned int k = 0; k < this->n_dofs_per_face(face_no); ++k)
this->interface_constraints(i * this->n_dofs_per_face(face_no) +
j,
k) = face_embeddings[i](j, k);
break;
}
case 3:
{
this->interface_constraints.reinit(
4 * (this->n_dofs_per_face(face_no) - this->degree),
this->n_dofs_per_face(face_no));
unsigned int target_row = 0;
for (unsigned int i = 0; i < 2; ++i)
for (unsigned int j = this->degree; j < 2 * this->degree;
++j, ++target_row)
for (unsigned int k = 0; k < this->n_dofs_per_face(face_no); ++k)
this->interface_constraints(target_row, k) =
face_embeddings[2 * i](j, k);
for (unsigned int i = 0; i < 2; ++i)
for (unsigned int j = 3 * this->degree;
j < GeometryInfo<3>::lines_per_face * this->degree;
++j, ++target_row)
for (unsigned int k = 0; k < this->n_dofs_per_face(face_no); ++k)
this->interface_constraints(target_row, k) =
face_embeddings[i](j, k);
for (unsigned int i = 0; i < 2; ++i)
for (unsigned int j = 0; j < 2; ++j)
for (unsigned int k = i * this->degree;
k < (i + 1) * this->degree;
++k, ++target_row)
for (unsigned int l = 0; l < this->n_dofs_per_face(face_no);
++l)
this->interface_constraints(target_row, l) =
face_embeddings[i + 2 * j](k, l);
for (unsigned int i = 0; i < 2; ++i)
for (unsigned int j = 0; j < 2; ++j)
for (unsigned int k = (i + 2) * this->degree;
k < (i + 3) * this->degree;
++k, ++target_row)
for (unsigned int l = 0; l < this->n_dofs_per_face(face_no);
++l)
this->interface_constraints(target_row, l) =
face_embeddings[2 * i + j](k, l);
for (unsigned int i = 0; i < GeometryInfo<3>::max_children_per_face;
++i)
for (unsigned int j =
GeometryInfo<3>::lines_per_face * this->degree;
j < this->n_dofs_per_face(face_no);
++j, ++target_row)
for (unsigned int k = 0; k < this->n_dofs_per_face(face_no); ++k)
this->interface_constraints(target_row, k) =
face_embeddings[i](j, k);
break;
}
default:
Assert(false, ExcNotImplemented());
}
// We need to initialize the dof permutation table and the one for the sign
// change.
initialize_quad_dof_index_permutation_and_sign_change();
}
template <int dim>
void
FE_Nedelec<dim>::initialize_quad_dof_index_permutation_and_sign_change()
{
// for 1D and 2D, do nothing
if (dim < 3)
return;
// TODO: Implement this for this class
return;
}
template <int dim>
std::string
FE_Nedelec<dim>::get_name() const
{
// note that the
// FETools::get_fe_by_name
// function depends on the
// particular format of the string
// this function returns, so they
// have to be kept in synch
std::ostringstream namebuf;
namebuf << "FE_Nedelec<" << dim << ">(" << this->degree - 1 << ")";
return namebuf.str();
}
template <int dim>
std::unique_ptr<FiniteElement<dim, dim>>
FE_Nedelec<dim>::clone() const
{
return std::make_unique<FE_Nedelec<dim>>(*this);
}
//---------------------------------------------------------------------------
// Auxiliary and internal functions
//---------------------------------------------------------------------------
// Set the generalized support
// points and precompute the
// parts of the projection-based
// interpolation, which does
// not depend on the interpolated
// function.
template <>
void
FE_Nedelec<1>::initialize_support_points(const unsigned int)
{
Assert(false, ExcNotImplemented());
}
template <>
void
FE_Nedelec<2>::initialize_support_points(const unsigned int order)
{
const int dim = 2;
// TODO: the implementation makes the assumption that all faces have the
// same number of dofs
AssertDimension(this->n_unique_faces(), 1);
const unsigned int face_no = 0;
// Create polynomial basis.
const std::vector<Polynomials::Polynomial<double>> &lobatto_polynomials =
Polynomials::Lobatto::generate_complete_basis(order + 1);
std::vector<Polynomials::Polynomial<double>> lobatto_polynomials_grad(order +
1);
for (unsigned int i = 0; i < lobatto_polynomials_grad.size(); ++i)
lobatto_polynomials_grad[i] = lobatto_polynomials[i + 1].derivative();
// Initialize quadratures to obtain
// quadrature points later on.
const QGauss<dim - 1> reference_edge_quadrature(order + 1);
const unsigned int n_edge_points = reference_edge_quadrature.size();
const unsigned int n_boundary_points =
GeometryInfo<dim>::lines_per_cell * n_edge_points;
const Quadrature<dim> edge_quadrature =
QProjector<dim>::project_to_all_faces(this->reference_cell(),
reference_edge_quadrature);
this->generalized_face_support_points[face_no].resize(n_edge_points);
// Create face support points.
for (unsigned int q_point = 0; q_point < n_edge_points; ++q_point)
this->generalized_face_support_points[face_no][q_point] =
reference_edge_quadrature.point(q_point);
if (order > 0)
{
// If the polynomial degree is positive
// we have support points on the faces
// and in the interior of a cell.
const QGauss<dim> quadrature(order + 1);
const unsigned int n_interior_points = quadrature.size();
this->generalized_support_points.resize(n_boundary_points +
n_interior_points);
boundary_weights.reinit(n_edge_points, order);
for (unsigned int q_point = 0; q_point < n_edge_points; ++q_point)
{
for (unsigned int line = 0; line < GeometryInfo<dim>::lines_per_cell;
++line)
this->generalized_support_points[line * n_edge_points + q_point] =
edge_quadrature.point(
QProjector<dim>::DataSetDescriptor::face(this->reference_cell(),
line,
true,
false,
false,
n_edge_points) +
q_point);
for (unsigned int i = 0; i < order; ++i)
boundary_weights(q_point, i) =
reference_edge_quadrature.weight(q_point) *
lobatto_polynomials_grad[i + 1].value(
this->generalized_face_support_points[face_no][q_point](0));
}
for (unsigned int q_point = 0; q_point < n_interior_points; ++q_point)
this->generalized_support_points[q_point + n_boundary_points] =
quadrature.point(q_point);
}
else
{
// In this case we only need support points
// on the faces of a cell.
this->generalized_support_points.resize(n_boundary_points);
for (unsigned int line = 0; line < GeometryInfo<dim>::lines_per_cell;
++line)
for (unsigned int q_point = 0; q_point < n_edge_points; ++q_point)
this->generalized_support_points[line * n_edge_points + q_point] =
edge_quadrature.point(
QProjector<dim>::DataSetDescriptor::face(this->reference_cell(),
line,
true,
false,
false,
n_edge_points) +
q_point);
}
}
template <>
void
FE_Nedelec<3>::initialize_support_points(const unsigned int order)
{
const int dim = 3;
// TODO: the implementation makes the assumption that all faces have the
// same number of dofs
AssertDimension(this->n_unique_faces(), 1);
const unsigned int face_no = 0;
// Create polynomial basis.
const std::vector<Polynomials::Polynomial<double>> &lobatto_polynomials =
Polynomials::Lobatto::generate_complete_basis(order + 1);
std::vector<Polynomials::Polynomial<double>> lobatto_polynomials_grad(order +
1);
for (unsigned int i = 0; i < lobatto_polynomials_grad.size(); ++i)
lobatto_polynomials_grad[i] = lobatto_polynomials[i + 1].derivative();
// Initialize quadratures to obtain
// quadrature points later on.
const QGauss<1> reference_edge_quadrature(order + 1);
const unsigned int n_edge_points = reference_edge_quadrature.size();
const Quadrature<dim - 1> &edge_quadrature =
QProjector<dim - 1>::project_to_all_faces(
ReferenceCells::get_hypercube<dim - 1>(), reference_edge_quadrature);
if (order > 0)
{
// If the polynomial order is positive
// we have support points on the edges,
// faces and in the interior of a cell.
const QGauss<dim - 1> reference_face_quadrature(order + 1);
const unsigned int n_face_points = reference_face_quadrature.size();
const unsigned int n_boundary_points =
GeometryInfo<dim>::lines_per_cell * n_edge_points +
GeometryInfo<dim>::faces_per_cell * n_face_points;
const QGauss<dim> quadrature(order + 1);
const unsigned int n_interior_points = quadrature.size();
boundary_weights.reinit(n_edge_points + n_face_points,
2 * (order + 1) * order);
this->generalized_face_support_points[face_no].resize(4 * n_edge_points +
n_face_points);
this->generalized_support_points.resize(n_boundary_points +
n_interior_points);
// Create support points on edges.
for (unsigned int q_point = 0; q_point < n_edge_points; ++q_point)
{
for (unsigned int line = 0;
line < GeometryInfo<dim - 1>::lines_per_cell;
++line)
this
->generalized_face_support_points[face_no][line * n_edge_points +
q_point] =
edge_quadrature.point(
QProjector<dim - 1>::DataSetDescriptor::face(
ReferenceCells::get_hypercube<dim - 1>(),
line,
true,
false,
false,
n_edge_points) +
q_point);
for (unsigned int i = 0; i < 2; ++i)
for (unsigned int j = 0; j < 2; ++j)
{
this->generalized_support_points[q_point +
(i + 4 * j) * n_edge_points] =
Point<dim>(i, reference_edge_quadrature.point(q_point)(0), j);
this->generalized_support_points[q_point + (i + 4 * j + 2) *
n_edge_points] =
Point<dim>(reference_edge_quadrature.point(q_point)(0), i, j);
this->generalized_support_points[q_point + (i + 2 * (j + 4)) *
n_edge_points] =
Point<dim>(i, j, reference_edge_quadrature.point(q_point)(0));
}
for (unsigned int i = 0; i < order; ++i)
boundary_weights(q_point, i) =
reference_edge_quadrature.weight(q_point) *
lobatto_polynomials_grad[i + 1].value(
this->generalized_face_support_points[face_no][q_point](1));
}
// Create support points on faces.
for (unsigned int q_point = 0; q_point < n_face_points; ++q_point)
{
this->generalized_face_support_points[face_no]
[q_point + 4 * n_edge_points] =
reference_face_quadrature.point(q_point);
for (unsigned int i = 0; i <= order; ++i)
for (unsigned int j = 0; j < order; ++j)
{
boundary_weights(q_point + n_edge_points, 2 * (i * order + j)) =
reference_face_quadrature.weight(q_point) *
lobatto_polynomials_grad[i].value(
this->generalized_face_support_points
[face_no][q_point + 4 * n_edge_points](0)) *
lobatto_polynomials[j + 2].value(
this->generalized_face_support_points
[face_no][q_point + 4 * n_edge_points](1));
boundary_weights(q_point + n_edge_points,
2 * (i * order + j) + 1) =
reference_face_quadrature.weight(q_point) *
lobatto_polynomials_grad[i].value(
this->generalized_face_support_points
[face_no][q_point + 4 * n_edge_points](1)) *
lobatto_polynomials[j + 2].value(
this->generalized_face_support_points
[face_no][q_point + 4 * n_edge_points](0));
}
}
const Quadrature<dim> &face_quadrature =
QProjector<dim>::project_to_all_faces(this->reference_cell(),
reference_face_quadrature);
for (const unsigned int face : GeometryInfo<dim>::face_indices())
for (unsigned int q_point = 0; q_point < n_face_points; ++q_point)
{
this->generalized_support_points[face * n_face_points + q_point +
GeometryInfo<dim>::lines_per_cell *
n_edge_points] =
face_quadrature.point(
QProjector<dim>::DataSetDescriptor::face(this->reference_cell(),
face,
true,
false,
false,
n_face_points) +
q_point);
}
// Create support points in the interior.
for (unsigned int q_point = 0; q_point < n_interior_points; ++q_point)
this->generalized_support_points[q_point + n_boundary_points] =
quadrature.point(q_point);
}
else
{
this->generalized_face_support_points[face_no].resize(4 * n_edge_points);
this->generalized_support_points.resize(
GeometryInfo<dim>::lines_per_cell * n_edge_points);
for (unsigned int q_point = 0; q_point < n_edge_points; ++q_point)
{
for (unsigned int line = 0;
line < GeometryInfo<dim - 1>::lines_per_cell;
++line)
this
->generalized_face_support_points[face_no][line * n_edge_points +
q_point] =
edge_quadrature.point(
QProjector<dim - 1>::DataSetDescriptor::face(
ReferenceCells::get_hypercube<dim - 1>(),
line,
true,
false,
false,
n_edge_points) +
q_point);
for (unsigned int i = 0; i < 2; ++i)
for (unsigned int j = 0; j < 2; ++j)
{
this->generalized_support_points[q_point +
(i + 4 * j) * n_edge_points] =
Point<dim>(i, reference_edge_quadrature.point(q_point)(0), j);
this->generalized_support_points[q_point + (i + 4 * j + 2) *
n_edge_points] =
Point<dim>(reference_edge_quadrature.point(q_point)(0), i, j);
this->generalized_support_points[q_point + (i + 2 * (j + 4)) *
n_edge_points] =
Point<dim>(i, j, reference_edge_quadrature.point(q_point)(0));
}
}
}
}
// Set the restriction matrices.
template <>
void
FE_Nedelec<1>::initialize_restriction()
{
// there is only one refinement case in 1d,
// which is the isotropic one
for (unsigned int i = 0; i < GeometryInfo<1>::max_children_per_cell; ++i)
this->restriction[0][i].reinit(0, 0);
}
// Restriction operator
template <int dim>
void
FE_Nedelec<dim>::initialize_restriction()
{
// This function does the same as the
// function interpolate further below.
// But since the functions, which we
// interpolate here, are discontinuous
// we have to use more quadrature
// points as in interpolate.
const QGauss<1> edge_quadrature(2 * this->degree);
const std::vector<Point<1>> &edge_quadrature_points =
edge_quadrature.get_points();
const unsigned int n_edge_quadrature_points = edge_quadrature.size();
const unsigned int index = RefinementCase<dim>::isotropic_refinement - 1;
switch (dim)
{
case 2:
{
// First interpolate the shape
// functions of the child cells
// to the lowest order shape
// functions of the parent cell.
for (unsigned int dof = 0; dof < this->n_dofs_per_cell(); ++dof)
for (unsigned int q_point = 0; q_point < n_edge_quadrature_points;
++q_point)
{
const double weight = 2.0 * edge_quadrature.weight(q_point);
if (edge_quadrature_points[q_point](0) < 0.5)
{
Point<dim> quadrature_point(
0.0, 2.0 * edge_quadrature_points[q_point](0));
this->restriction[index][0](0, dof) +=
weight *
this->shape_value_component(dof, quadrature_point, 1);
quadrature_point(0) = 1.0;
this->restriction[index][1](this->degree, dof) +=
weight *
this->shape_value_component(dof, quadrature_point, 1);
quadrature_point(0) = quadrature_point(1);
quadrature_point(1) = 0.0;
this->restriction[index][0](2 * this->degree, dof) +=
weight *
this->shape_value_component(dof, quadrature_point, 0);
quadrature_point(1) = 1.0;
this->restriction[index][2](3 * this->degree, dof) +=
weight *
this->shape_value_component(dof, quadrature_point, 0);
}
else
{
Point<dim> quadrature_point(
0.0, 2.0 * edge_quadrature_points[q_point](0) - 1.0);
this->restriction[index][2](0, dof) +=
weight *
this->shape_value_component(dof, quadrature_point, 1);
quadrature_point(0) = 1.0;
this->restriction[index][3](this->degree, dof) +=
weight *
this->shape_value_component(dof, quadrature_point, 1);
quadrature_point(0) = quadrature_point(1);
quadrature_point(1) = 0.0;
this->restriction[index][1](2 * this->degree, dof) +=
weight *
this->shape_value_component(dof, quadrature_point, 0);
quadrature_point(1) = 1.0;
this->restriction[index][3](3 * this->degree, dof) +=
weight *
this->shape_value_component(dof, quadrature_point, 0);
}
}
// Then project the shape functions
// of the child cells to the higher
// order shape functions of the
// parent cell.
if (this->degree > 1)
{
const unsigned int deg = this->degree - 1;
const std::vector<Polynomials::Polynomial<double>>
&legendre_polynomials =
Polynomials::Legendre::generate_complete_basis(deg);
FullMatrix<double> system_matrix_inv(deg, deg);
{
FullMatrix<double> assembling_matrix(deg,
n_edge_quadrature_points);
for (unsigned int q_point = 0;
q_point < n_edge_quadrature_points;
++q_point)
{
const double weight =
std::sqrt(edge_quadrature.weight(q_point));
for (unsigned int i = 0; i < deg; ++i)
assembling_matrix(i, q_point) =
weight * legendre_polynomials[i + 1].value(
edge_quadrature_points[q_point](0));
}
FullMatrix<double> system_matrix(deg, deg);
assembling_matrix.mTmult(system_matrix, assembling_matrix);
system_matrix_inv.invert(system_matrix);
}
FullMatrix<double> solution(this->degree - 1, 4);
FullMatrix<double> system_rhs(this->degree - 1, 4);
Vector<double> tmp(4);
for (unsigned int dof = 0; dof < this->n_dofs_per_cell(); ++dof)
for (unsigned int i = 0; i < 2; ++i)
{
system_rhs = 0.0;
for (unsigned int q_point = 0;
q_point < n_edge_quadrature_points;
++q_point)
{
const double weight = edge_quadrature.weight(q_point);
const Point<dim> quadrature_point_0(
i, edge_quadrature_points[q_point](0));
const Point<dim> quadrature_point_1(
edge_quadrature_points[q_point](0), i);
if (edge_quadrature_points[q_point](0) < 0.5)
{
Point<dim> quadrature_point_2(
i, 2.0 * edge_quadrature_points[q_point](0));
tmp(0) =
weight *
(2.0 * this->shape_value_component(
dof, quadrature_point_2, 1) -
this->restriction[index][i](i * this->degree,
dof) *
this->shape_value_component(i * this->degree,
quadrature_point_0,
1));
tmp(1) =
-1.0 * weight *
this->restriction[index][i + 2](i * this->degree,
dof) *
this->shape_value_component(i * this->degree,
quadrature_point_0,
1);
quadrature_point_2 = Point<dim>(
2.0 * edge_quadrature_points[q_point](0), i);
tmp(2) =
weight *
(2.0 * this->shape_value_component(
dof, quadrature_point_2, 0) -
this->restriction[index][2 * i]((i + 2) *
this->degree,
dof) *
this->shape_value_component((i + 2) *
this->degree,
quadrature_point_1,
0));
tmp(3) =
-1.0 * weight *
this->restriction[index][2 * i + 1](
(i + 2) * this->degree, dof) *
this->shape_value_component(
(i + 2) * this->degree, quadrature_point_1, 0);
}
else
{
tmp(0) =
-1.0 * weight *
this->restriction[index][i](i * this->degree,
dof) *
this->shape_value_component(i * this->degree,
quadrature_point_0,
1);
Point<dim> quadrature_point_2(
i,
2.0 * edge_quadrature_points[q_point](0) - 1.0);
tmp(1) =
weight *
(2.0 * this->shape_value_component(
dof, quadrature_point_2, 1) -
this->restriction[index][i + 2](i * this->degree,
dof) *
this->shape_value_component(i * this->degree,
quadrature_point_0,
1));
tmp(2) =
-1.0 * weight *
this->restriction[index][2 * i]((i + 2) *
this->degree,
dof) *
this->shape_value_component(
(i + 2) * this->degree, quadrature_point_1, 0);
quadrature_point_2 = Point<dim>(
2.0 * edge_quadrature_points[q_point](0) - 1.0,
i);
tmp(3) =
weight *
(2.0 * this->shape_value_component(
dof, quadrature_point_2, 0) -
this->restriction[index][2 * i + 1](
(i + 2) * this->degree, dof) *
this->shape_value_component((i + 2) *
this->degree,
quadrature_point_1,
0));
}
for (unsigned int j = 0; j < this->degree - 1; ++j)
{
const double L_j =
legendre_polynomials[j + 1].value(
edge_quadrature_points[q_point](0));
for (unsigned int k = 0; k < tmp.size(); ++k)
system_rhs(j, k) += tmp(k) * L_j;
}
}
system_matrix_inv.mmult(solution, system_rhs);
for (unsigned int j = 0; j < this->degree - 1; ++j)
for (unsigned int k = 0; k < 2; ++k)
{
if (std::abs(solution(j, k)) > 1e-14)
this->restriction[index][i + 2 * k](
i * this->degree + j + 1, dof) = solution(j, k);
if (std::abs(solution(j, k + 2)) > 1e-14)
this->restriction[index][2 * i + k](
(i + 2) * this->degree + j + 1, dof) =
solution(j, k + 2);
}
}
const QGauss<dim> quadrature(2 * this->degree);
const std::vector<Point<dim>> &quadrature_points =
quadrature.get_points();
const std::vector<Polynomials::Polynomial<double>>
&lobatto_polynomials =
Polynomials::Lobatto::generate_complete_basis(this->degree);
const unsigned int n_boundary_dofs =
GeometryInfo<dim>::faces_per_cell * this->degree;
const unsigned int n_quadrature_points = quadrature.size();
{
FullMatrix<double> assembling_matrix((this->degree - 1) *
this->degree,
n_quadrature_points);
for (unsigned int q_point = 0; q_point < n_quadrature_points;
++q_point)
{
const double weight = std::sqrt(quadrature.weight(q_point));
for (unsigned int i = 0; i < this->degree; ++i)
{
const double L_i =
weight * legendre_polynomials[i].value(
quadrature_points[q_point](0));
for (unsigned int j = 0; j < this->degree - 1; ++j)
assembling_matrix(i * (this->degree - 1) + j,
q_point) =
L_i * lobatto_polynomials[j + 2].value(
quadrature_points[q_point](1));
}
}
FullMatrix<double> system_matrix(assembling_matrix.m(),
assembling_matrix.m());
assembling_matrix.mTmult(system_matrix, assembling_matrix);
system_matrix_inv.reinit(system_matrix.m(), system_matrix.m());
system_matrix_inv.invert(system_matrix);
}
solution.reinit(system_matrix_inv.m(), 8);
system_rhs.reinit(system_matrix_inv.m(), 8);
tmp.reinit(8);
for (unsigned int dof = 0; dof < this->n_dofs_per_cell(); ++dof)
{
system_rhs = 0.0;
for (unsigned int q_point = 0; q_point < n_quadrature_points;
++q_point)
{
tmp = 0.0;
if (quadrature_points[q_point](0) < 0.5)
{
if (quadrature_points[q_point](1) < 0.5)
{
const Point<dim> quadrature_point(
2.0 * quadrature_points[q_point](0),
2.0 * quadrature_points[q_point](1));
tmp(0) += 2.0 * this->shape_value_component(
dof, quadrature_point, 0);
tmp(1) += 2.0 * this->shape_value_component(
dof, quadrature_point, 1);
}
else
{
const Point<dim> quadrature_point(
2.0 * quadrature_points[q_point](0),
2.0 * quadrature_points[q_point](1) - 1.0);
tmp(4) += 2.0 * this->shape_value_component(
dof, quadrature_point, 0);
tmp(5) += 2.0 * this->shape_value_component(
dof, quadrature_point, 1);
}
}
else if (quadrature_points[q_point](1) < 0.5)
{
const Point<dim> quadrature_point(
2.0 * quadrature_points[q_point](0) - 1.0,
2.0 * quadrature_points[q_point](1));
tmp(2) +=
2.0 * this->shape_value_component(dof,
quadrature_point,
0);
tmp(3) +=
2.0 * this->shape_value_component(dof,
quadrature_point,
1);
}
else
{
const Point<dim> quadrature_point(
2.0 * quadrature_points[q_point](0) - 1.0,
2.0 * quadrature_points[q_point](1) - 1.0);
tmp(6) +=
2.0 * this->shape_value_component(dof,
quadrature_point,
0);
tmp(7) +=
2.0 * this->shape_value_component(dof,
quadrature_point,
1);
}
for (unsigned int i = 0; i < 2; ++i)
for (unsigned int j = 0; j < this->degree; ++j)
{
tmp(2 * i) -=
this->restriction[index][i](j + 2 * this->degree,
dof) *
this->shape_value_component(
j + 2 * this->degree,
quadrature_points[q_point],
0);
tmp(2 * i + 1) -=
this->restriction[index][i](i * this->degree + j,
dof) *
this->shape_value_component(
i * this->degree + j,
quadrature_points[q_point],
1);
tmp(2 * (i + 2)) -= this->restriction[index][i + 2](
j + 3 * this->degree, dof) *
this->shape_value_component(
j + 3 * this->degree,
quadrature_points[q_point],
0);
tmp(2 * i + 5) -= this->restriction[index][i + 2](
i * this->degree + j, dof) *
this->shape_value_component(
i * this->degree + j,
quadrature_points[q_point],
1);
}
tmp *= quadrature.weight(q_point);
for (unsigned int i = 0; i < this->degree; ++i)
{
const double L_i_0 = legendre_polynomials[i].value(
quadrature_points[q_point](0));
const double L_i_1 = legendre_polynomials[i].value(
quadrature_points[q_point](1));
for (unsigned int j = 0; j < this->degree - 1; ++j)
{
const double l_j_0 =
L_i_0 * lobatto_polynomials[j + 2].value(
quadrature_points[q_point](1));
const double l_j_1 =
L_i_1 * lobatto_polynomials[j + 2].value(
quadrature_points[q_point](0));
for (unsigned int k = 0; k < 4; ++k)
{
system_rhs(i * (this->degree - 1) + j,
2 * k) += tmp(2 * k) * l_j_0;
system_rhs(i * (this->degree - 1) + j,
2 * k + 1) +=
tmp(2 * k + 1) * l_j_1;
}
}
}
}
system_matrix_inv.mmult(solution, system_rhs);
for (unsigned int i = 0; i < this->degree; ++i)
for (unsigned int j = 0; j < this->degree - 1; ++j)
for (unsigned int k = 0; k < 4; ++k)
{
if (std::abs(solution(i * (this->degree - 1) + j,