/
mapping_q_cache.cc
766 lines (639 loc) · 27.3 KB
/
mapping_q_cache.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
// ---------------------------------------------------------------------
//
// Copyright (C) 2019 - 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/memory_consumption.h>
#include <deal.II/base/utilities.h>
#include <deal.II/base/work_stream.h>
#include <deal.II/dofs/dof_tools.h>
#include <deal.II/fe/fe_dgq.h>
#include <deal.II/fe/fe_nothing.h>
#include <deal.II/fe/fe_q.h>
#include <deal.II/fe/fe_tools.h>
#include <deal.II/fe/fe_values.h>
#include <deal.II/fe/mapping_q1.h>
#include <deal.II/fe/mapping_q_cache.h>
#include <deal.II/lac/la_parallel_vector.h>
#include <deal.II/lac/la_vector.h>
#include <deal.II/lac/petsc_vector.h>
#include <deal.II/lac/trilinos_vector.h>
#include <functional>
DEAL_II_NAMESPACE_OPEN
template <int dim, int spacedim>
MappingQCache<dim, spacedim>::MappingQCache(
const unsigned int polynomial_degree)
: MappingQ<dim, spacedim>(polynomial_degree)
, uses_level_info(false)
{}
template <int dim, int spacedim>
MappingQCache<dim, spacedim>::MappingQCache(
const MappingQCache<dim, spacedim> &mapping)
: MappingQ<dim, spacedim>(mapping)
, support_point_cache(mapping.support_point_cache)
, uses_level_info(mapping.uses_level_info)
{}
template <int dim, int spacedim>
MappingQCache<dim, spacedim>::~MappingQCache()
{
// When this object goes out of scope, we want the cache to get cleared and
// free its memory before the signal is disconnected in order to not work on
// invalid memory that has been left back by freeing an object of this
// class.
support_point_cache.reset();
clear_signal.disconnect();
}
template <int dim, int spacedim>
std::unique_ptr<Mapping<dim, spacedim>>
MappingQCache<dim, spacedim>::clone() const
{
return std::make_unique<MappingQCache<dim, spacedim>>(*this);
}
template <int dim, int spacedim>
bool
MappingQCache<dim, spacedim>::preserves_vertex_locations() const
{
return false;
}
template <int dim, int spacedim>
void
MappingQCache<dim, spacedim>::initialize(
const Mapping<dim, spacedim> & mapping,
const Triangulation<dim, spacedim> &triangulation)
{
// FE and FEValues in the case they are needed
FE_Nothing<dim, spacedim> fe;
Threads::ThreadLocalStorage<std::unique_ptr<FEValues<dim, spacedim>>>
fe_values_all;
this->initialize(
triangulation,
[&](const typename Triangulation<dim, spacedim>::cell_iterator &cell) {
const auto mapping_q =
dynamic_cast<const MappingQ<dim, spacedim> *>(&mapping);
if (mapping_q != nullptr && this->get_degree() == mapping_q->get_degree())
{
return mapping_q->compute_mapping_support_points(cell);
}
else
{
// get FEValues (thread-safe); in the case that this thread has not
// created a an FEValues object yet, this helper-function also
// creates one with the right quadrature rule
auto &fe_values = fe_values_all.get();
if (fe_values.get() == nullptr)
{
QGaussLobatto<dim> quadrature_gl(this->polynomial_degree + 1);
std::vector<Point<dim>> quadrature_points;
for (const auto i :
FETools::hierarchic_to_lexicographic_numbering<dim>(
this->polynomial_degree))
quadrature_points.push_back(quadrature_gl.point(i));
Quadrature<dim> quadrature(quadrature_points);
fe_values = std::make_unique<FEValues<dim, spacedim>>(
mapping, fe, quadrature, update_quadrature_points);
}
fe_values->reinit(cell);
return fe_values->get_quadrature_points();
}
});
}
template <int dim, int spacedim>
void
MappingQCache<dim, spacedim>::initialize(
const Triangulation<dim, spacedim> &triangulation,
const MappingQ<dim, spacedim> & mapping)
{
this->initialize(mapping, triangulation);
}
template <int dim, int spacedim>
void
MappingQCache<dim, spacedim>::initialize(
const Triangulation<dim, spacedim> &triangulation,
const std::function<std::vector<Point<spacedim>>(
const typename Triangulation<dim, spacedim>::cell_iterator &)>
&compute_points_on_cell)
{
clear_signal.disconnect();
clear_signal = triangulation.signals.any_change.connect(
[&]() -> void { this->support_point_cache.reset(); });
support_point_cache =
std::make_shared<std::vector<std::vector<std::vector<Point<spacedim>>>>>(
triangulation.n_levels());
for (unsigned int l = 0; l < triangulation.n_levels(); ++l)
(*support_point_cache)[l].resize(triangulation.n_raw_cells(l));
WorkStream::run(
triangulation.begin(),
triangulation.end(),
[&](const typename Triangulation<dim, spacedim>::cell_iterator &cell,
void *,
void *) {
(*support_point_cache)[cell->level()][cell->index()] =
compute_points_on_cell(cell);
AssertDimension(
(*support_point_cache)[cell->level()][cell->index()].size(),
Utilities::pow(this->get_degree() + 1, dim));
},
/* copier */ std::function<void(void *)>(),
/* scratch_data */ nullptr,
/* copy_data */ nullptr,
2 * MultithreadInfo::n_threads(),
/* chunk_size = */ 1);
uses_level_info = true;
}
template <int dim, int spacedim>
void
MappingQCache<dim, spacedim>::initialize(
const Mapping<dim, spacedim> & mapping,
const Triangulation<dim, spacedim> &tria,
const std::function<Point<spacedim>(
const typename Triangulation<dim, spacedim>::cell_iterator &,
const Point<spacedim> &)> & transformation_function,
const bool function_describes_relative_displacement)
{
// FE and FEValues in the case they are needed
FE_Nothing<dim, spacedim> fe;
Threads::ThreadLocalStorage<std::unique_ptr<FEValues<dim, spacedim>>>
fe_values_all;
this->initialize(
tria,
[&](const typename Triangulation<dim, spacedim>::cell_iterator &cell) {
std::vector<Point<spacedim>> points;
const auto mapping_q =
dynamic_cast<const MappingQ<dim, spacedim> *>(&mapping);
if (mapping_q != nullptr && this->get_degree() == mapping_q->get_degree())
{
points = mapping_q->compute_mapping_support_points(cell);
}
else
{
// get FEValues (thread-safe); in the case that this thread has not
// created a an FEValues object yet, this helper-function also
// creates one with the right quadrature rule
auto &fe_values = fe_values_all.get();
if (fe_values.get() == nullptr)
{
QGaussLobatto<dim> quadrature_gl(this->polynomial_degree + 1);
std::vector<Point<dim>> quadrature_points;
for (const auto i :
FETools::hierarchic_to_lexicographic_numbering<dim>(
this->polynomial_degree))
quadrature_points.push_back(quadrature_gl.point(i));
Quadrature<dim> quadrature(quadrature_points);
fe_values = std::make_unique<FEValues<dim, spacedim>>(
mapping, fe, quadrature, update_quadrature_points);
}
fe_values->reinit(cell);
points = fe_values->get_quadrature_points();
}
for (auto &p : points)
if (function_describes_relative_displacement)
p += transformation_function(cell, p);
else
p = transformation_function(cell, p);
return points;
});
uses_level_info = true;
}
template <int dim, int spacedim>
void
MappingQCache<dim, spacedim>::initialize(
const Mapping<dim, spacedim> & mapping,
const Triangulation<dim, spacedim> &tria,
const Function<spacedim> & transformation_function,
const bool function_describes_relative_displacement)
{
AssertDimension(transformation_function.n_components, spacedim);
this->initialize(mapping,
tria,
[&](const auto &, const auto &point) {
Point<spacedim> new_point;
for (int c = 0; c < spacedim; ++c)
new_point[c] = transformation_function.value(point, c);
return new_point;
},
function_describes_relative_displacement);
uses_level_info = true;
}
namespace
{
template <typename VectorType>
void
copy_locally_owned_data_from(
const VectorType &vector,
LinearAlgebra::distributed::Vector<typename VectorType::value_type>
&vector_ghosted)
{
LinearAlgebra::ReadWriteVector<typename VectorType::value_type> temp;
temp.reinit(vector.locally_owned_elements());
temp.import(vector, VectorOperation::insert);
vector_ghosted.import(temp, VectorOperation::insert);
}
} // namespace
template <int dim, int spacedim>
template <typename VectorType>
void
MappingQCache<dim, spacedim>::initialize(
const Mapping<dim, spacedim> & mapping,
const DoFHandler<dim, spacedim> &dof_handler,
const VectorType & vector,
const bool vector_describes_relative_displacement)
{
AssertDimension(dof_handler.get_fe_collection().size(), 1);
const FiniteElement<dim, spacedim> &fe = dof_handler.get_fe();
AssertDimension(fe.n_base_elements(), 1);
AssertDimension(fe.element_multiplicity(0), spacedim);
const unsigned int is_fe_q =
dynamic_cast<const FE_Q<dim, spacedim> *>(&fe.base_element(0)) != nullptr;
const unsigned int is_fe_dgq =
dynamic_cast<const FE_DGQ<dim, spacedim> *>(&fe.base_element(0)) != nullptr;
const auto lexicographic_to_hierarchic_numbering =
Utilities::invert_permutation(
FETools::hierarchic_to_lexicographic_numbering<spacedim>(
this->get_degree()));
// Step 1: copy global vector so that the ghost values are such that the
// cache can be set up for all ghost cells
LinearAlgebra::distributed::Vector<typename VectorType::value_type>
vector_ghosted;
IndexSet locally_relevant_dofs;
DoFTools::extract_locally_relevant_dofs(dof_handler, locally_relevant_dofs);
vector_ghosted.reinit(dof_handler.locally_owned_dofs(),
locally_relevant_dofs,
dof_handler.get_communicator());
copy_locally_owned_data_from(vector, vector_ghosted);
vector_ghosted.update_ghost_values();
// FE and FEValues in the case they are needed
FE_Nothing<dim, spacedim> fe_nothing;
Threads::ThreadLocalStorage<std::unique_ptr<FEValues<dim, spacedim>>>
fe_values_all;
// Interpolation of values is needed if we cannot just read off locations
// from the solution vectors (as in the case of FE_Q and FE_DGQ with the
// same polynomial degree as this class has).
const bool interpolation_of_values_is_needed =
((is_fe_q || is_fe_dgq) && fe.degree == this->get_degree()) == false;
// Step 2: loop over all cells
this->initialize(
dof_handler.get_triangulation(),
[&](const typename Triangulation<dim, spacedim>::cell_iterator &cell_tria)
-> std::vector<Point<spacedim>> {
const bool is_active_non_artificial_cell =
(cell_tria->is_active() == true) &&
(cell_tria->is_artificial() == false);
const typename DoFHandler<dim, spacedim>::cell_iterator cell_dofs(
&cell_tria->get_triangulation(),
cell_tria->level(),
cell_tria->index(),
&dof_handler);
const auto mapping_q =
dynamic_cast<const MappingQ<dim, spacedim> *>(&mapping);
// Step 2a) set up and reinit FEValues (if needed)
if (
((vector_describes_relative_displacement ||
(is_active_non_artificial_cell == false)) &&
((mapping_q != nullptr &&
this->get_degree() == mapping_q->get_degree()) ==
false)) /*condition 1: points need to be computed via FEValues*/
||
(is_active_non_artificial_cell && interpolation_of_values_is_needed) /*condition 2: interpolation of values is needed*/)
{
// get FEValues (thread-safe); in the case that this thread has
// not created a an FEValues object yet, this helper-function also
// creates one with the right quadrature rule
auto &fe_values = fe_values_all.get();
if (fe_values.get() == nullptr)
{
QGaussLobatto<dim> quadrature_gl(this->polynomial_degree + 1);
std::vector<Point<dim>> quadrature_points;
for (const auto i :
FETools::hierarchic_to_lexicographic_numbering<dim>(
this->polynomial_degree))
quadrature_points.push_back(quadrature_gl.point(i));
Quadrature<dim> quadrature(quadrature_points);
fe_values = std::make_unique<FEValues<dim, spacedim>>(
mapping,
interpolation_of_values_is_needed ?
fe :
static_cast<const FiniteElement<dim, spacedim> &>(fe_nothing),
quadrature,
update_quadrature_points | update_values);
}
if (interpolation_of_values_is_needed)
fe_values->reinit(cell_dofs);
else
fe_values->reinit(cell_tria);
}
std::vector<Point<spacedim>> result;
// Step 2b) read of quadrature points in the relative displacement case
// note: we also take this path for non-active or artificial cells so that
// these cells are filled with some useful data
if (vector_describes_relative_displacement ||
is_active_non_artificial_cell == false)
{
if (mapping_q != nullptr &&
this->get_degree() == mapping_q->get_degree())
result = mapping_q->compute_mapping_support_points(cell_tria);
else
result = fe_values_all.get()->get_quadrature_points();
// for non-active or artificial cells we are done here and return
// the absolute positions, since the provided vector cannot contain
// any useful information for these cells
if (is_active_non_artificial_cell == false)
return result;
}
else
{
result.resize(
Utilities::pow<unsigned int>(this->get_degree() + 1, dim));
}
// Step 2c) read global vector and adjust points accordingly
if (interpolation_of_values_is_needed == false)
{
// case 1: FE_Q or FE_DGQ with same degree as this class has; this
// is the simple case since no interpolation is needed
std::vector<types::global_dof_index> dof_indices(
fe.n_dofs_per_cell());
cell_dofs->get_dof_indices(dof_indices);
for (unsigned int i = 0; i < dof_indices.size(); ++i)
{
const auto id = fe.system_to_component_index(i);
if (is_fe_q)
{
// case 1a: FE_Q
if (vector_describes_relative_displacement)
result[id.second][id.first] +=
vector_ghosted(dof_indices[i]);
else
result[id.second][id.first] =
vector_ghosted(dof_indices[i]);
}
else
{
// case 1b: FE_DGQ
if (vector_describes_relative_displacement)
result[lexicographic_to_hierarchic_numbering[id.second]]
[id.first] += vector_ghosted(dof_indices[i]);
else
result[lexicographic_to_hierarchic_numbering[id.second]]
[id.first] = vector_ghosted(dof_indices[i]);
}
}
}
else
{
// case 2: general case; interpolation is needed
// note: the following code could be optimized for tensor-product
// elements via application of sum factorization as is done on
// MatrixFree/FEEvaluation
auto &fe_values = fe_values_all.get();
std::vector<Vector<typename VectorType::value_type>> values(
fe_values->n_quadrature_points,
Vector<typename VectorType::value_type>(spacedim));
fe_values->get_function_values(vector_ghosted, values);
for (unsigned int q = 0; q < fe_values->n_quadrature_points; ++q)
for (unsigned int c = 0; c < spacedim; ++c)
if (vector_describes_relative_displacement)
result[q][c] += values[q][c];
else
result[q][c] = values[q][c];
}
return result;
});
uses_level_info = false;
}
template <int dim, int spacedim>
template <typename VectorType>
void
MappingQCache<dim, spacedim>::initialize(
const Mapping<dim, spacedim> & mapping,
const DoFHandler<dim, spacedim> &dof_handler,
const MGLevelObject<VectorType> &vectors,
const bool vector_describes_relative_displacement)
{
AssertDimension(dof_handler.get_fe_collection().size(), 1);
const FiniteElement<dim, spacedim> &fe = dof_handler.get_fe();
AssertDimension(fe.n_base_elements(), 1);
AssertDimension(fe.element_multiplicity(0), spacedim);
AssertDimension(0, vectors.min_level());
AssertDimension(dof_handler.get_triangulation().n_global_levels() - 1,
vectors.max_level());
const unsigned int is_fe_q =
dynamic_cast<const FE_Q<dim, spacedim> *>(&fe.base_element(0)) != nullptr;
const unsigned int is_fe_dgq =
dynamic_cast<const FE_DGQ<dim, spacedim> *>(&fe.base_element(0)) != nullptr;
const auto lexicographic_to_hierarchic_numbering =
Utilities::invert_permutation(
FETools::hierarchic_to_lexicographic_numbering<spacedim>(
this->get_degree()));
// Step 1: copy global vector so that the ghost values are such that the
// cache can be set up for all ghost cells
MGLevelObject<
LinearAlgebra::distributed::Vector<typename VectorType::value_type>>
vectors_ghosted(vectors.min_level(), vectors.max_level());
for (unsigned int l = vectors.min_level(); l <= vectors.max_level(); ++l)
{
IndexSet locally_relevant_dofs;
DoFTools::extract_locally_relevant_level_dofs(dof_handler,
l,
locally_relevant_dofs);
vectors_ghosted[l].reinit(dof_handler.locally_owned_mg_dofs(l),
locally_relevant_dofs,
dof_handler.get_communicator());
copy_locally_owned_data_from(vectors[l], vectors_ghosted[l]);
vectors_ghosted[l].update_ghost_values();
}
// FE and FEValues in the case they are needed
FE_Nothing<dim, spacedim> fe_nothing;
Threads::ThreadLocalStorage<std::unique_ptr<FEValues<dim, spacedim>>>
fe_values_all;
// Interpolation of values is needed if we cannot just read off locations
// from the solution vectors (as in the case of FE_Q and FE_DGQ with the
// same polynomial degree as this class has).
const bool interpolation_of_values_is_needed =
((is_fe_q || is_fe_dgq) && fe.degree == this->get_degree()) == false;
// Step 2: loop over all cells
this->initialize(
dof_handler.get_triangulation(),
[&](const typename Triangulation<dim, spacedim>::cell_iterator &cell_tria)
-> std::vector<Point<spacedim>> {
const bool is_non_artificial_cell =
cell_tria->level_subdomain_id() != numbers::artificial_subdomain_id;
const typename DoFHandler<dim, spacedim>::level_cell_iterator cell_dofs(
&cell_tria->get_triangulation(),
cell_tria->level(),
cell_tria->index(),
&dof_handler);
const auto mapping_q =
dynamic_cast<const MappingQ<dim, spacedim> *>(&mapping);
// Step 2a) set up and reinit FEValues (if needed)
if (
((vector_describes_relative_displacement ||
(is_non_artificial_cell == false)) &&
((mapping_q != nullptr &&
this->get_degree() == mapping_q->get_degree()) ==
false)) /*condition 1: points need to be computed via FEValues*/
||
(is_non_artificial_cell == true && interpolation_of_values_is_needed) /*condition 2: interpolation of values is needed*/)
{
// get FEValues (thread-safe); in the case that this thread has
// not created a an FEValues object yet, this helper-function also
// creates one with the right quadrature rule
auto &fe_values = fe_values_all.get();
if (fe_values.get() == nullptr)
{
QGaussLobatto<dim> quadrature_gl(this->polynomial_degree + 1);
std::vector<Point<dim>> quadrature_points;
for (const auto i :
FETools::hierarchic_to_lexicographic_numbering<dim>(
this->polynomial_degree))
quadrature_points.push_back(quadrature_gl.point(i));
Quadrature<dim> quadrature(quadrature_points);
fe_values = std::make_unique<FEValues<dim, spacedim>>(
mapping,
interpolation_of_values_is_needed ?
fe :
static_cast<const FiniteElement<dim, spacedim> &>(fe_nothing),
quadrature,
update_quadrature_points | update_values);
}
if (interpolation_of_values_is_needed)
fe_values->reinit(cell_dofs);
else
fe_values->reinit(cell_tria);
}
std::vector<Point<spacedim>> result;
// Step 2b) read of quadrature points in the relative displacement case
// note: we also take this path for non-active or artificial cells so that
// these cells are filled with some useful data
if (vector_describes_relative_displacement ||
(is_non_artificial_cell == false))
{
if (mapping_q != nullptr &&
this->get_degree() == mapping_q->get_degree())
result = mapping_q->compute_mapping_support_points(cell_tria);
else
result = fe_values_all.get()->get_quadrature_points();
// for non-active or artificial cells we are done here and return
// the absolute positions, since the provided vector cannot contain
// any useful information for these cells
if (is_non_artificial_cell == false)
return result;
}
else
{
result.resize(
Utilities::pow<unsigned int>(this->get_degree() + 1, dim));
}
// Step 2c) read global vector and adjust points accordingly
if (interpolation_of_values_is_needed == false)
{
// case 1: FE_Q or FE_DGQ with same degree as this class has; this
// is the simple case since no interpolation is needed
std::vector<types::global_dof_index> dof_indices(
fe.n_dofs_per_cell());
cell_dofs->get_mg_dof_indices(dof_indices);
for (unsigned int i = 0; i < dof_indices.size(); ++i)
{
const auto id = fe.system_to_component_index(i);
if (is_fe_q)
{
// case 1a: FE_Q
if (vector_describes_relative_displacement)
result[id.second][id.first] +=
vectors_ghosted[cell_tria->level()](dof_indices[i]);
else
result[id.second][id.first] =
vectors_ghosted[cell_tria->level()](dof_indices[i]);
}
else
{
// case 1b: FE_DGQ
if (vector_describes_relative_displacement)
result[lexicographic_to_hierarchic_numbering[id.second]]
[id.first] +=
vectors_ghosted[cell_tria->level()](dof_indices[i]);
else
result[lexicographic_to_hierarchic_numbering[id.second]]
[id.first] =
vectors_ghosted[cell_tria->level()](dof_indices[i]);
}
}
}
else
{
// case 2: general case; interpolation is needed
// note: the following code could be optimized for tensor-product
// elements via application of sum factorization as is done on
// MatrixFree/FEEvaluation
auto &fe_values = fe_values_all.get();
std::vector<types::global_dof_index> dof_indices(
fe.n_dofs_per_cell());
cell_dofs->get_mg_dof_indices(dof_indices);
std::vector<typename VectorType::value_type> dof_values(
fe.n_dofs_per_cell());
for (unsigned int i = 0; i < fe.n_dofs_per_cell(); ++i)
dof_values[i] = vectors_ghosted[cell_tria->level()](dof_indices[i]);
for (unsigned int c = 0; c < spacedim; ++c)
for (unsigned int i = 0; i < fe.n_dofs_per_cell(); ++i)
for (unsigned int q = 0; q < fe_values->n_quadrature_points; ++q)
if (vector_describes_relative_displacement == false && i == 0)
result[q][c] =
dof_values[i] * fe_values->shape_value_component(i, q, c);
else
result[q][c] +=
dof_values[i] * fe_values->shape_value_component(i, q, c);
}
return result;
});
uses_level_info = true;
}
template <int dim, int spacedim>
std::size_t
MappingQCache<dim, spacedim>::memory_consumption() const
{
if (support_point_cache.get() != nullptr)
return sizeof(*this) +
MemoryConsumption::memory_consumption(*support_point_cache);
else
return sizeof(*this);
}
template <int dim, int spacedim>
std::vector<Point<spacedim>>
MappingQCache<dim, spacedim>::compute_mapping_support_points(
const typename Triangulation<dim, spacedim>::cell_iterator &cell) const
{
Assert(support_point_cache.get() != nullptr,
ExcMessage("Must call MappingQCache::initialize() before "
"using it or after mesh has changed!"));
Assert(uses_level_info || cell->is_active(), ExcInternalError());
AssertIndexRange(cell->level(), support_point_cache->size());
AssertIndexRange(cell->index(), (*support_point_cache)[cell->level()].size());
return (*support_point_cache)[cell->level()][cell->index()];
}
template <int dim, int spacedim>
boost::container::small_vector<Point<spacedim>,
GeometryInfo<dim>::vertices_per_cell>
MappingQCache<dim, spacedim>::get_vertices(
const typename Triangulation<dim, spacedim>::cell_iterator &cell) const
{
Assert(support_point_cache.get() != nullptr,
ExcMessage("Must call MappingQCache::initialize() before "
"using it or after mesh has changed!"));
Assert(uses_level_info || cell->is_active(), ExcInternalError());
AssertIndexRange(cell->level(), support_point_cache->size());
AssertIndexRange(cell->index(), (*support_point_cache)[cell->level()].size());
const auto ptr = (*support_point_cache)[cell->level()][cell->index()].begin();
return boost::container::small_vector<Point<spacedim>,
GeometryInfo<dim>::vertices_per_cell>(
ptr, ptr + cell->n_vertices());
}
//--------------------------- Explicit instantiations -----------------------
#include "mapping_q_cache.inst"
DEAL_II_NAMESPACE_CLOSE