PolyDEAL
Loading...
Searching...
No Matches
utils.h
Go to the documentation of this file.
1// -----------------------------------------------------------------------------
2//
3// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
4// Copyright (C) XXXX - YYYY by the polyDEAL authors
5//
6// This file is part of the polyDEAL library.
7//
8// Detailed license information governing the source code
9// can be found in LICENSE.md at the top level directory.
10//
11// -----------------------------------------------------------------------------
12
13
14#ifndef utils_h
15#define utils_h
16
17#include <deal.II/base/point.h>
19
21
29
33
35
36#include <multigrid_amg.h>
37
38
39
40template <int dim, typename RtreeType>
42template <int, int>
44
45
46
47namespace Utils
48{
49 template <typename T>
50 inline constexpr T
51 constexpr_pow(T num, unsigned int pow)
52 {
53 return (pow >= sizeof(unsigned int) * 8) ? 0 :
54 pow == 0 ? 1 :
55 num * constexpr_pow(num, pow - 1);
56 }
57
58
59
64 struct Graph
65 {
66 std::vector<types::global_cell_index> nodes;
67 std::vector<std::vector<types::global_cell_index>> adjacency;
68
69 void
71 {
72 std::cout << "Graph information" << std::endl;
73 for (const auto &node : nodes)
74 {
75 std::cout << "Neighbors for node " << node << std::endl;
76 for (const auto &neigh_node : adjacency[node])
77 std::cout << neigh_node << std::endl;
78 }
79 }
80 };
81
82
83
96 template <int dim, int spacedim, typename MatrixType>
97 void
100 SparsityPattern &sp,
101 MatrixType &matrix)
102 {
103 using NumberType = typename MatrixType::value_type;
104 // First, check that we support the matrix types
105 static constexpr bool is_trilinos_matrix =
106 std::is_same_v<TrilinosWrappers::SparseMatrix, MatrixType>;
107 static constexpr bool is_serial_matrix =
108 std::is_same_v<SparseMatrix<NumberType>, MatrixType>;
109 static constexpr bool is_supported_matrix =
110 is_trilinos_matrix || is_serial_matrix;
111 static_assert(is_supported_matrix);
112 if constexpr (is_trilinos_matrix)
113 Assert(matrix.m() == 0, ExcInternalError());
114 if constexpr (is_serial_matrix)
115 Assert(sp.empty() && matrix.empty(),
116 ExcMessage(
117 "The destination matrix and its sparsity pattern must the empty "
118 "upon calling this function."));
119
120 Assert(coarse_ah.n_dofs() < fine_ah.n_dofs(), ExcInternalError());
121 AssertDimension(dim, spacedim);
122
123 // Get information from the handlers
124 const DoFHandler<dim, spacedim> &coarse_agglo_dh = coarse_ah.agglo_dh;
125 const DoFHandler<dim, spacedim> &fine_agglo_dh = fine_ah.agglo_dh;
126
127 const Mapping<dim, spacedim> &mapping = fine_ah.get_mapping();
128 const FiniteElement<dim, spacedim> &fe = coarse_ah.get_fe();
129 const Triangulation<dim, spacedim> &tria = coarse_ah.get_triangulation();
130 const auto &fine_bboxes = fine_ah.get_local_bboxes();
131 const auto &coarse_bboxes = coarse_ah.get_local_bboxes();
132
133 const IndexSet &locally_owned_dofs_fine =
134 fine_agglo_dh.locally_owned_dofs();
135 const IndexSet locally_relevant_dofs_fine =
137
138 const IndexSet &locally_owned_dofs_coarse =
139 coarse_agglo_dh.locally_owned_dofs();
140
141 std::conditional_t<is_trilinos_matrix,
144 dsp;
145
146 if constexpr (is_trilinos_matrix)
147 dsp.reinit(locally_owned_dofs_fine,
148 locally_owned_dofs_coarse,
149 tria.get_mpi_communicator());
150 else
151 dsp.reinit(fine_agglo_dh.n_dofs(),
152 coarse_agglo_dh.n_dofs(),
153 locally_relevant_dofs_fine);
154
155 const unsigned int dofs_per_cell = fe.dofs_per_cell;
156 std::vector<types::global_dof_index> agglo_dof_indices(dofs_per_cell);
157 std::vector<types::global_dof_index> standard_dof_indices(dofs_per_cell);
158 std::vector<types::global_dof_index> output_dof_indices(dofs_per_cell);
159
160 const std::vector<Point<dim>> &unit_support_points =
162 Quadrature<dim> quad(unit_support_points);
163 FEValues<dim, spacedim> output_fe_values(mapping,
164 fe,
165 quad,
167
168 std::vector<types::global_dof_index> local_dof_indices_coarse(
169 dofs_per_cell);
170 std::vector<types::global_dof_index> local_dof_indices_child(dofs_per_cell);
171
172 for (const auto &polytope : coarse_ah.polytope_iterators())
173 if (polytope->is_locally_owned())
174 {
175 polytope->get_dof_indices(local_dof_indices_coarse);
176
177 // Get local children and their DoFs
178 const auto &children_polytopes = polytope->children();
179 for (const types::global_cell_index child_idx : children_polytopes)
180 {
181 const typename DoFHandler<dim>::active_cell_iterator &child_dh =
182 fine_ah.polytope_to_dh_iterator(child_idx);
183 child_dh->get_dof_indices(local_dof_indices_child);
184 for (const auto row : local_dof_indices_child)
185 dsp.add_entries(row,
186 local_dof_indices_coarse.begin(),
187 local_dof_indices_coarse.end());
188 }
189 }
190
191 const auto assemble_injection_matrix = [&]() {
192 FullMatrix<NumberType> local_matrix(dofs_per_cell, dofs_per_cell);
193 std::vector<Point<dim>> reference_q_points(dofs_per_cell);
194
195 // Dummy AffineConstraints, only needed for loc2glb
197 c.close();
198
199 for (const auto &polytope : coarse_ah.polytope_iterators())
200 if (polytope->is_locally_owned())
201 {
202 polytope->get_dof_indices(local_dof_indices_coarse);
203 const BoundingBox<dim> &coarse_bbox =
204 coarse_bboxes[polytope->index()];
205
206 // Get local children of the present polytope
207 const auto &children_polytopes = polytope->children();
208 for (const types::global_cell_index child_idx : children_polytopes)
209 {
210 const BoundingBox<dim> &fine_bbox = fine_bboxes[child_idx];
211 const typename DoFHandler<dim>::active_cell_iterator &child_dh =
212 fine_ah.polytope_to_dh_iterator(child_idx);
213 child_dh->get_dof_indices(local_dof_indices_child);
214
215 local_matrix = 0.;
216
217 // compute real location of support points
218 std::vector<Point<dim>> real_qpoints;
219 real_qpoints.reserve(unit_support_points.size());
220 for (const Point<dim> &p : unit_support_points)
221 real_qpoints.push_back(fine_bbox.unit_to_real(p));
222
223 for (unsigned int i = 0; i < local_dof_indices_coarse.size();
224 ++i)
225 {
226 const auto &p = coarse_bbox.real_to_unit(real_qpoints[i]);
227 for (unsigned int j = 0; j < local_dof_indices_child.size();
228 ++j)
229 {
230 local_matrix(i, j) = fe.shape_value(j, p);
231 }
232 }
233
234 c.distribute_local_to_global(local_matrix,
235 local_dof_indices_child,
236 local_dof_indices_coarse,
237 matrix);
238 }
239 }
240 };
241
242
243 if constexpr (is_trilinos_matrix)
244 {
245 dsp.compress();
246 matrix.reinit(dsp);
247 assemble_injection_matrix();
248 }
249 else if constexpr (is_serial_matrix)
250 {
251 sp.copy_from(dsp);
252 matrix.reinit(sp);
253 assemble_injection_matrix();
254 }
255 else
256 {
257 // PETSc types not implemented.
258 (void)coarse_ah;
259 (void)fine_ah;
260 (void)sp;
261 (void)matrix;
262 AssertThrow(false,
263 ExcNotImplemented(
264 "This injection does not support PETSc types."));
265 }
266
267 // If tria is distributed
268 if (dynamic_cast<const parallel::TriangulationBase<dim, spacedim> *>(
269 &tria) != nullptr)
270 matrix.compress(VectorOperation::add);
271 }
272
273
274
287 template <typename VectorType, typename MatrixType, typename SolverType>
288 class MGCoarseDirect : public MGCoarseGridBase<VectorType>
289 {
290 public:
291 explicit MGCoarseDirect(const MatrixType &matrix)
292 : direct_solver(TrilinosWrappers::SolverDirect::AdditionalData())
293 , coarse_matrix(matrix)
294 {
295 // Check if matrix types are supported
296 static constexpr bool is_serial_matrix =
297 std::is_same_v<SolverType, SparseDirectUMFPACK>;
298 static constexpr bool is_trilinos_matrix =
299 std::is_same_v<SolverType, TrilinosWrappers::SolverDirect>;
300 [[maybe_unused]] static constexpr bool is_matrix_type_supported =
301 is_serial_matrix || is_trilinos_matrix;
302 Assert(is_matrix_type_supported, ExcNotImplemented());
303
304 // Check on the vector types: standard deal.II vectors, LA::d::V, or
305 // Trilinos vectors.
306 if constexpr (is_serial_matrix)
307 {
308 [[maybe_unused]] static constexpr bool is_serial_vector =
309 std::is_same_v<VectorType,
310 dealii::Vector<typename MatrixType::value_type>>;
311 Assert(is_serial_vector, ExcNotImplemented());
312 }
313 else if constexpr (is_trilinos_matrix)
314 {
315 [[maybe_unused]] static constexpr bool is_supported_parallel_vector =
316 std::is_same_v<VectorType,
318 typename MatrixType::value_type>> ||
319 std::is_same_v<VectorType, TrilinosWrappers::MPI::Vector>;
320 Assert(is_supported_parallel_vector, ExcNotImplemented());
321 }
322 else
323 {
324 AssertThrow(false, ExcNotImplemented());
325 // DEAL_II_NOT_IMPLEMENTED(); //not available in older releases
326 }
327
328
329 // regardless of UMFPACK or Trilinos, both direct solvers need a call
330 // to `initialize()`.
331 direct_solver.initialize(coarse_matrix);
332 }
333
334
335 void
336 operator()(const unsigned int,
337 VectorType &dst,
338 const VectorType &src) const override
339 {
340 AssertDimension(coarse_matrix.n(), src.size());
341 AssertDimension(coarse_matrix.m(), dst.size());
342 const_cast<SolverType &>(direct_solver).solve(dst, src);
343 }
344
345
346 ~MGCoarseDirect() = default;
347
348 private:
349 SolverType direct_solver;
350 const MatrixType &coarse_matrix;
351 };
352
353
354
355 namespace Physics
356 {
357
358 enum class TimeStepping
359 {
362 };
363
365 {
366 double dt = 1e-4;
367 double penalty_constant = 10.;
368 double chi = 1e5;
369 double Cm = 1e-2;
370 double sigma = 12e-2;
371 double sigma_l = 0.;
372 double sigma_t = 0.;
373 double sigma_n = 0.;
374 bool use_fibers = false;
376 };
377
378 } // namespace Physics
379
381 {
388 template <int dim,
389 int degree,
390 int n_q_points,
391 int n_components,
392 typename number = double>
393 class LaplaceOperatorDG : public Subscriptor
394 {
395 public:
396 using value_type = number;
399
400
402
403 void
404 reinit(const Mapping<dim> &mapping,
405 const DoFHandler<dim> &dof_handler,
406 const unsigned int level = numbers::invalid_unsigned_int)
407 {
408 fe_degree = dof_handler.get_fe().degree;
409
410 const QGauss<1> quad(n_q_points);
411 typename MatrixFree<dim, number>::AdditionalData addit_data;
412 addit_data.tasks_parallel_scheme =
414 addit_data.tasks_block_size = 3;
415 addit_data.mg_level = level;
420 constraints.close();
421
422 data.reinit(mapping, dof_handler, constraints, quad, addit_data);
423
425 }
426
427 void
430 {
431 dst = 0;
432 vmult_add(dst, src);
433 }
434
435 void
438 {
439 dst = 0;
440 vmult_add(dst, src);
441 }
442
443 void
449
450 void
453 {
455 *data.get_dof_info(0).vector_partitioner))
456 {
458 src_copy.reinit(data.get_dof_info().vector_partitioner);
459 src_copy = src;
461 src_copy);
462 }
464 *data.get_dof_info(0).vector_partitioner))
465 {
467 dst_copy.reinit(data.get_dof_info().vector_partitioner);
468 dst_copy = dst;
469 dst.swap(dst_copy);
470 }
475 this,
476 dst,
477 src);
478 }
479
481 m() const
482 {
483 return data.get_vector_partitioner()->size();
484 }
485
487 n() const
488 {
489 return data.get_vector_partitioner()->size();
490 }
491
492 number
493 el(const unsigned int row, const unsigned int col) const
494 {
495 (void)row;
496 (void)col;
497 AssertThrow(false,
498 ExcMessage("Matrix-free does not allow for entry access"));
499 return number();
500 }
501
502 void
505 {
506 data.initialize_dof_vector(vector);
507 }
508
509
510 const DoFHandler<dim> &
512 {
513 return data.get_dof_handler();
514 }
515
516
517 const Triangulation<dim> &
519 {
520 return data.get_dof_handler().get_triangulation();
521 }
522
528
529
532 {
533 return &data;
534 }
535
536
537
540 {
541 // Boilerplate for SIP-DG form. TODO: unify interface.
543 const auto cell_operation = [&](auto &phi) {
544 phi.evaluate(EvaluationFlags::gradients);
545 for (unsigned int q = 0; q < phi.n_q_points; ++q)
546 phi.submit_gradient(phi.get_gradient(q), q);
547 phi.integrate(EvaluationFlags::gradients);
548 };
549
550 const auto face_operation = [&](auto &phi_m, auto &phi_p) {
553
554 VectorizedArrayType sigmaF =
555 (std::abs(
556 (phi_m.normal_vector(0) * phi_m.inverse_jacobian(0))[dim - 1]) +
557 std::abs(
558 (phi_m.normal_vector(0) * phi_p.inverse_jacobian(0))[dim - 1])) *
559 (number)(std::max(fe_degree, 1) * (fe_degree + 1.0));
560
561 for (unsigned int q = 0; q < phi_m.n_q_points; ++q)
562 {
563 VectorizedArrayType jump_value =
564 (phi_m.get_value(q) - phi_p.get_value(q)) * 0.5;
565 VectorizedArrayType average_valgrad =
566 phi_m.get_normal_derivative(q) + phi_p.get_normal_derivative(q);
567 average_valgrad =
568 jump_value * 2. * sigmaF - average_valgrad * 0.5;
569 phi_m.submit_normal_derivative(-jump_value, q);
570 phi_p.submit_normal_derivative(-jump_value, q);
571 phi_m.submit_value(average_valgrad, q);
572 phi_p.submit_value(-average_valgrad, q);
573 }
576 };
577
578 const auto boundary_operation = [&](auto &phi_m) {
580 VectorizedArrayType sigmaF =
581 std::abs(
582 (phi_m.normal_vector(0) * phi_m.inverse_jacobian(0))[dim - 1]) *
583 number(std::max(fe_degree, 1) * (fe_degree + 1.0)) * 2.0;
584
585 for (unsigned int q = 0; q < phi_m.n_q_points; ++q)
586 {
587 VectorizedArrayType jump_value = phi_m.get_value(q);
588 VectorizedArrayType average_valgrad =
589 -phi_m.get_normal_derivative(q);
590 average_valgrad += jump_value * sigmaF * 2.0;
591 phi_m.submit_normal_derivative(-jump_value, q);
592 phi_m.submit_value(average_valgrad, q);
593 }
594
596 };
597
598
600
601
602 // Check if matrix has already been set up.
603 if (system_matrix.m() == 0 && system_matrix.n() == 0)
604 {
605 // Set up sparsity pattern of system matrix.
606 const auto &dof_handler = data.get_dof_handler();
607
609 data.get_mg_level() != numbers::invalid_unsigned_int ?
610 dof_handler.locally_owned_mg_dofs(data.get_mg_level()) :
611 dof_handler.locally_owned_dofs(),
612 data.get_task_info().communicator);
613
614 if (data.get_mg_level() != numbers::invalid_unsigned_int)
616 dsp,
617 data.get_mg_level(),
619 else
621 dsp,
623
624 dsp.compress();
626
627 // Assemble system matrix. Notice that degree 1 has been hardcoded.
628
630 degree,
631 n_q_points,
632 n_components,
633 number,
635 data,
638 cell_operation,
639 face_operation,
640 boundary_operation);
641 }
642
643 return system_matrix;
644 }
645
646
647
648 void
650 {
651 // Boilerplate for SIP-DG form. TODO: unify interface.
653 const auto cell_operation = [&](auto &phi) {
654 phi.evaluate(EvaluationFlags::gradients);
655 for (unsigned int q = 0; q < phi.n_q_points; ++q)
656 phi.submit_gradient(phi.get_gradient(q), q);
657 phi.integrate(EvaluationFlags::gradients);
658 };
659
660 const auto face_operation = [&](auto &phi_m, auto &phi_p) {
663
664 VectorizedArrayType sigmaF =
665 (std::abs(
666 (phi_m.normal_vector(0) * phi_m.inverse_jacobian(0))[dim - 1]) +
667 std::abs(
668 (phi_m.normal_vector(0) * phi_p.inverse_jacobian(0))[dim - 1])) *
669 (number)(std::max(fe_degree, 1) * (fe_degree + 1.0));
670
671 for (unsigned int q = 0; q < phi_m.n_q_points; ++q)
672 {
673 VectorizedArrayType jump_value =
674 (phi_m.get_value(q) - phi_p.get_value(q)) * 0.5;
675 VectorizedArrayType average_valgrad =
676 phi_m.get_normal_derivative(q) + phi_p.get_normal_derivative(q);
677 average_valgrad =
678 jump_value * 2. * sigmaF - average_valgrad * 0.5;
679 phi_m.submit_normal_derivative(-jump_value, q);
680 phi_p.submit_normal_derivative(-jump_value, q);
681 phi_m.submit_value(average_valgrad, q);
682 phi_p.submit_value(-average_valgrad, q);
683 }
686 };
687
688 const auto boundary_operation = [&](auto &phi_m) {
690 VectorizedArrayType sigmaF =
691 std::abs(
692 (phi_m.normal_vector(0) * phi_m.inverse_jacobian(0))[dim - 1]) *
693 number(std::max(fe_degree, 1) * (fe_degree + 1.0)) * 2.0;
694
695 for (unsigned int q = 0; q < phi_m.n_q_points; ++q)
696 {
697 VectorizedArrayType jump_value = phi_m.get_value(q);
698 VectorizedArrayType average_valgrad =
699 -phi_m.get_normal_derivative(q);
700 average_valgrad += jump_value * sigmaF * 2.0;
701 phi_m.submit_normal_derivative(-jump_value, q);
702 phi_m.submit_value(average_valgrad, q);
703 }
704
706 };
707
708
710
711 // Check if matrix has already been set up.
712 AssertThrow((mg_matrix.m() == 0 && mg_matrix.n() == 0),
713 ExcInternalError());
714
715 // Set up sparsity pattern of system matrix.
716 const DoFHandler<dim> &dof_handler = data.get_dof_handler();
717
718 const IndexSet &system_partitioning = dof_handler.locally_owned_dofs();
719 const IndexSet system_relevant_set =
721
722
723 DynamicSparsityPattern dsp(dof_handler.n_dofs(),
724 dof_handler.n_dofs(),
725 system_relevant_set);
726 DoFTools::make_flux_sparsity_pattern(dof_handler, dsp);
727
729 dsp,
730 system_partitioning,
731 data.get_task_info().communicator,
732 system_relevant_set);
733 mg_matrix.reinit(system_partitioning,
734 dsp,
735 data.get_task_info().communicator);
736
737 // Assemble system matrix.
739 degree,
740 n_q_points,
741 n_components,
742 number,
744 data,
746 mg_matrix,
747 cell_operation,
748 face_operation,
749 boundary_operation);
750 }
751
752
753
754 void
756 {
757 const int dummy = 0;
758
759
760 data
761 .template cell_loop<LinearAlgebra::distributed::Vector<number>, int>(
762 [](const auto &matrix_free,
763 auto &dst,
764 const auto &,
765 const auto cells) {
766 FEEvaluation<dim, -1, 0, n_components, number> phi(matrix_free,
767 cells);
768 for (unsigned int cell = cells.first; cell < cells.second; ++cell)
769 {
770 phi.reinit(cell);
771 for (unsigned int q = 0; q < phi.n_q_points; ++q)
772 {
773 if constexpr (n_components == 1)
774 {
775 phi.submit_value(1.0, q);
776 }
777 else
778 {
780 for (unsigned int v = 0;
781 v < VectorizedArray<number>::size();
782 ++v)
783 {
784 for (unsigned int i = 0; i < n_components; i++)
785 temp[i][v] = 1.;
786 }
787 phi.submit_value(temp, q);
788 }
789 }
790
791 phi.integrate_scatter(EvaluationFlags::values, dst);
792 }
793 },
794 b,
795 dummy,
796 true);
797 }
798
799
800
801 void
820
821
822 private:
823 void
827 const std::pair<unsigned int, unsigned int> &cell_range) const
828 {
829 FEEvaluation<dim, -1, 0, 1, number> phi(data);
830
831 for (unsigned int cell = cell_range.first; cell < cell_range.second;
832 ++cell)
833 {
834 phi.reinit(cell);
835 phi.read_dof_values(src);
836 phi.evaluate(EvaluationFlags::gradients);
837 for (unsigned int q = 0; q < phi.n_q_points; ++q)
838 phi.submit_gradient(phi.get_gradient(q), q);
839 phi.integrate(EvaluationFlags::gradients);
840 phi.distribute_local_to_global(dst);
841 }
842 }
843
844 void
849 const std::pair<unsigned int, unsigned int> &face_range) const
850 {
851 FEFaceEvaluation<dim, -1, 0, 1, number> fe_eval(data, true);
852 FEFaceEvaluation<dim, -1, 0, 1, number> fe_eval_neighbor(data, false);
853
854 for (unsigned int face = face_range.first; face < face_range.second;
855 ++face)
856 {
857 fe_eval.reinit(face);
858 fe_eval_neighbor.reinit(face);
859
860 fe_eval.read_dof_values(src);
861 fe_eval.evaluate(EvaluationFlags::values |
863 fe_eval_neighbor.read_dof_values(src);
864 fe_eval_neighbor.evaluate(EvaluationFlags::values |
867 (std::abs((fe_eval.normal_vector(0) *
868 fe_eval.inverse_jacobian(0))[dim - 1]) +
869 std::abs((fe_eval.normal_vector(0) *
870 fe_eval_neighbor.inverse_jacobian(0))[dim - 1])) *
871 (number)(std::max(fe_degree, 1) * (fe_degree + 1.0));
872
873 for (unsigned int q = 0; q < fe_eval.n_q_points; ++q)
874 {
875 VectorizedArray<number> jump_value =
876 (fe_eval.get_value(q) - fe_eval_neighbor.get_value(q)) * 0.5;
877 VectorizedArray<number> average_valgrad =
878 fe_eval.get_normal_derivative(q) +
879 fe_eval_neighbor.get_normal_derivative(q);
880 average_valgrad =
881 jump_value * 2. * sigmaF - average_valgrad * 0.5;
882 fe_eval.submit_normal_derivative(-jump_value, q);
883 fe_eval_neighbor.submit_normal_derivative(-jump_value, q);
884 fe_eval.submit_value(average_valgrad, q);
885 fe_eval_neighbor.submit_value(-average_valgrad, q);
886 }
887 fe_eval.integrate(EvaluationFlags::values |
889 fe_eval.distribute_local_to_global(dst);
890 fe_eval_neighbor.integrate(EvaluationFlags::values |
892 fe_eval_neighbor.distribute_local_to_global(dst);
893 }
894 }
895
896 void
901 const std::pair<unsigned int, unsigned int> &face_range) const
902 {
903 FEFaceEvaluation<dim, -1, 0, 1, number> fe_eval(data, true);
904 for (unsigned int face = face_range.first; face < face_range.second;
905 ++face)
906 {
907 fe_eval.reinit(face);
908 fe_eval.read_dof_values(src);
909 fe_eval.evaluate(EvaluationFlags::values |
912 std::abs((fe_eval.normal_vector(0) *
913 fe_eval.inverse_jacobian(0))[dim - 1]) *
914 number(std::max(fe_degree, 1) * (fe_degree + 1.0)) * 2.0;
915
916 for (unsigned int q = 0; q < fe_eval.n_q_points; ++q)
917 {
918 VectorizedArray<number> jump_value = fe_eval.get_value(q);
919 VectorizedArray<number> average_valgrad =
920 -fe_eval.get_normal_derivative(q);
921 average_valgrad += jump_value * sigmaF * 2.0;
922 fe_eval.submit_normal_derivative(-jump_value, q);
923 fe_eval.submit_value(average_valgrad, q);
924 }
925
926 fe_eval.integrate(EvaluationFlags::values |
928 fe_eval.distribute_local_to_global(dst);
929 }
930 }
931
932
933 void
937 const unsigned int &,
938 const std::pair<unsigned int, unsigned int> &cell_range) const
939 {
940 FEEvaluation<dim, -1, 0, 1, number> phi(data);
941 AlignedVector<VectorizedArray<number>> local_diagonal_vector(
942 phi.dofs_per_cell);
943
944 for (unsigned int cell = cell_range.first; cell < cell_range.second;
945 ++cell)
946 {
947 phi.reinit(cell);
948
949 for (unsigned int i = 0; i < phi.dofs_per_cell; ++i)
950 {
951 for (unsigned int j = 0; j < phi.dofs_per_cell; ++j)
952 phi.begin_dof_values()[j] = VectorizedArray<number>();
953 phi.begin_dof_values()[i] = 1.;
954 phi.evaluate(EvaluationFlags::gradients);
955 for (unsigned int q = 0; q < phi.n_q_points; ++q)
956 phi.submit_gradient(phi.get_gradient(q), q);
957 phi.integrate(EvaluationFlags::gradients);
958 local_diagonal_vector[i] = phi.begin_dof_values()[i];
959 }
960 for (unsigned int i = 0; i < phi.dofs_per_cell; ++i)
961 phi.begin_dof_values()[i] = local_diagonal_vector[i];
962 phi.distribute_local_to_global(dst);
963 }
964 }
965
966 void
970 const unsigned int &,
971 const std::pair<unsigned int, unsigned int> &face_range) const
972 {
973 FEFaceEvaluation<dim, -1, 0, 1, number> phi(data, true);
974 FEFaceEvaluation<dim, -1, 0, 1, number> phi_outer(data, false);
975 AlignedVector<VectorizedArray<number>> local_diagonal_vector(
976 phi.dofs_per_cell);
977
978 for (unsigned int face = face_range.first; face < face_range.second;
979 ++face)
980 {
981 phi.reinit(face);
982 phi_outer.reinit(face);
983
985 (std::abs(
986 (phi.normal_vector(0) * phi.inverse_jacobian(0))[dim - 1]) +
987 std::abs((phi.normal_vector(0) *
988 phi_outer.inverse_jacobian(0))[dim - 1])) *
989 (number)(std::max(fe_degree, 1) * (fe_degree + 1.0));
990
991 // Compute phi part
992 for (unsigned int j = 0; j < phi.dofs_per_cell; ++j)
993 phi_outer.begin_dof_values()[j] = VectorizedArray<number>();
994 phi_outer.evaluate(EvaluationFlags::values |
996 for (unsigned int i = 0; i < phi.dofs_per_cell; ++i)
997 {
998 for (unsigned int j = 0; j < phi.dofs_per_cell; ++j)
999 phi.begin_dof_values()[j] = VectorizedArray<number>();
1000 phi.begin_dof_values()[i] = 1.;
1001 phi.evaluate(EvaluationFlags::values |
1003
1004 for (unsigned int q = 0; q < phi.n_q_points; ++q)
1005 {
1006 VectorizedArray<number> jump_value =
1007 (phi.get_value(q) - phi_outer.get_value(q)) * 0.5;
1008 VectorizedArray<number> average_valgrad =
1009 phi.get_normal_derivative(q) +
1010 phi_outer.get_normal_derivative(q);
1011 average_valgrad =
1012 jump_value * 2. * sigmaF - average_valgrad * 0.5;
1013 phi.submit_normal_derivative(-jump_value, q);
1014 phi.submit_value(average_valgrad, q);
1015 }
1016 phi.integrate(EvaluationFlags::values |
1018 local_diagonal_vector[i] = phi.begin_dof_values()[i];
1019 }
1020 for (unsigned int i = 0; i < phi.dofs_per_cell; ++i)
1021 phi.begin_dof_values()[i] = local_diagonal_vector[i];
1022 phi.distribute_local_to_global(dst);
1023
1024 // Compute phi_outer part
1025 for (unsigned int j = 0; j < phi.dofs_per_cell; ++j)
1026 phi.begin_dof_values()[j] = VectorizedArray<number>();
1028 for (unsigned int i = 0; i < phi.dofs_per_cell; ++i)
1029 {
1030 for (unsigned int j = 0; j < phi.dofs_per_cell; ++j)
1031 phi_outer.begin_dof_values()[j] = VectorizedArray<number>();
1032 phi_outer.begin_dof_values()[i] = 1.;
1033 phi_outer.evaluate(EvaluationFlags::values |
1035
1036 for (unsigned int q = 0; q < phi.n_q_points; ++q)
1037 {
1038 VectorizedArray<number> jump_value =
1039 (phi.get_value(q) - phi_outer.get_value(q)) * 0.5;
1040 VectorizedArray<number> average_valgrad =
1041 phi.get_normal_derivative(q) +
1042 phi_outer.get_normal_derivative(q);
1043 average_valgrad =
1044 jump_value * 2. * sigmaF - average_valgrad * 0.5;
1045 phi_outer.submit_normal_derivative(-jump_value, q);
1046 phi_outer.submit_value(-average_valgrad, q);
1047 }
1048 phi_outer.integrate(EvaluationFlags::values |
1050 local_diagonal_vector[i] = phi_outer.begin_dof_values()[i];
1051 }
1052 for (unsigned int i = 0; i < phi.dofs_per_cell; ++i)
1053 phi_outer.begin_dof_values()[i] = local_diagonal_vector[i];
1054 phi_outer.distribute_local_to_global(dst);
1055 }
1056 }
1057
1058 void
1062 const unsigned int &,
1063 const std::pair<unsigned int, unsigned int> &face_range) const
1064 {
1065 FEFaceEvaluation<dim, -1, 0, 1, number> phi(data);
1066 AlignedVector<VectorizedArray<number>> local_diagonal_vector(
1067 phi.dofs_per_cell);
1068
1069 for (unsigned int face = face_range.first; face < face_range.second;
1070 ++face)
1071 {
1072 phi.reinit(face);
1073
1075 std::abs(
1076 (phi.normal_vector(0) * phi.inverse_jacobian(0))[dim - 1]) *
1077 number(std::max(fe_degree, 1) * (fe_degree + 1.0)) * 2.0;
1078
1079 for (unsigned int i = 0; i < phi.dofs_per_cell; ++i)
1080 {
1081 for (unsigned int j = 0; j < phi.dofs_per_cell; ++j)
1082 phi.begin_dof_values()[j] = VectorizedArray<number>();
1083 phi.begin_dof_values()[i] = 1.;
1084 phi.evaluate(EvaluationFlags::values |
1086
1087 for (unsigned int q = 0; q < phi.n_q_points; ++q)
1088 {
1089 VectorizedArray<number> jump_value = phi.get_value(q);
1090 VectorizedArray<number> average_valgrad =
1091 -phi.get_normal_derivative(q);
1092 average_valgrad += jump_value * sigmaF * 2.0;
1093 phi.submit_normal_derivative(-jump_value, q);
1094 phi.submit_value(average_valgrad, q);
1095 }
1096
1097 phi.integrate(EvaluationFlags::values |
1099 local_diagonal_vector[i] = phi.begin_dof_values()[i];
1100 }
1101 for (unsigned int i = 0; i < phi.dofs_per_cell; ++i)
1102 phi.begin_dof_values()[i] = local_diagonal_vector[i];
1103 phi.distribute_local_to_global(dst);
1104 }
1105 }
1106
1107
1108
1114 };
1115
1116
1117
1121 template <int dim,
1122 int degree,
1123 int n_q_points,
1124 int n_components,
1125 typename number = double>
1126 class MonodomainOperatorDG : public Subscriptor
1127 {
1128 public:
1129 using value_type = number;
1133
1144
1145 void
1146 reinit(const Mapping<dim> &mapping,
1147 const DoFHandler<dim> &dof_handler,
1148 const unsigned int level = numbers::invalid_unsigned_int)
1149 {
1150 Assert(
1151 degree == dof_handler.get_fe().degree,
1152 ExcMessage(
1153 "Degree of the operator must match the degree of the DoFHandler"));
1154 fe_degree = dof_handler.get_fe().degree;
1155
1156 const QGauss<1> quad(n_q_points);
1157 typename MatrixFree<dim, number>::AdditionalData addit_data;
1158 addit_data.tasks_parallel_scheme =
1160 addit_data.tasks_block_size = 3;
1161 addit_data.mg_level = level;
1162 addit_data.mapping_update_flags =
1168 constraints.close();
1169
1170 data.reinit(mapping, dof_handler, constraints, quad, addit_data);
1171
1173 }
1174
1180 void
1181 reinit(const Mapping<dim> &mapping,
1182 const DoFHandler<dim> &dof_handler,
1183 const DoFHandler<dim> &fiber_dof_handler,
1184 const unsigned int level = numbers::invalid_unsigned_int)
1185 {
1186 Assert(
1187 degree == dof_handler.get_fe().degree,
1188 ExcMessage(
1189 "Degree of the operator must match the degree of the DoFHandler"));
1190 fe_degree = dof_handler.get_fe().degree;
1191
1192 const QGauss<1> quad(n_q_points);
1193 typename MatrixFree<dim, number>::AdditionalData addit_data;
1194 addit_data.tasks_parallel_scheme =
1196 addit_data.tasks_block_size = 3;
1197 addit_data.mg_level = level;
1198 addit_data.mapping_update_flags =
1204 constraints.close();
1205
1206 AffineConstraints<number> fiber_constraints;
1207 fiber_constraints.close();
1208
1209 data.reinit(mapping,
1210 std::vector<const DoFHandler<dim> *>{&dof_handler,
1211 &fiber_dof_handler},
1212 std::vector<const AffineConstraints<number> *>{
1213 &constraints, &fiber_constraints},
1214 quad,
1215 addit_data);
1216
1218 }
1219
1220
1228 void
1232 {
1233 // FEEvaluation for the fiber FESystem (dof_handler_index = 1).
1234 // Degree 1 is hardcoded for FE_Q(1) fibers; n_q_points from the
1235 // scalar operator is reused (over-integration is harmless).
1237 const unsigned int n_q = phi_fiber.n_q_points;
1238 const unsigned int n_batches = data.n_cell_batches();
1239
1240 fiber_f_data.resize(n_batches * n_q);
1241 fiber_s_data.resize(n_batches * n_q);
1242 fiber_n_data.resize(n_batches * n_q);
1243
1244 for (unsigned int cell = 0; cell < n_batches; ++cell)
1245 {
1246 phi_fiber.reinit(cell);
1247 const unsigned int base = cell * n_q;
1248
1249 // Read all three fiber fields for this cell batch
1250 phi_fiber.read_dof_values_plain(f0);
1252 for (unsigned int q = 0; q < n_q; ++q)
1253 fiber_f_data[base + q] = phi_fiber.get_value(q);
1254
1255 phi_fiber.read_dof_values_plain(s0);
1257 for (unsigned int q = 0; q < n_q; ++q)
1258 fiber_s_data[base + q] = phi_fiber.get_value(q);
1259
1260 phi_fiber.read_dof_values_plain(n0);
1262 for (unsigned int q = 0; q < n_q; ++q)
1263 fiber_n_data[base + q] = phi_fiber.get_value(q);
1264
1265 // Gram-Schmidt orthonormalization at each quadrature point
1266 for (unsigned int q = 0; q < n_q; ++q)
1267 {
1268 auto &fq = fiber_f_data[base + q];
1269 auto &sq = fiber_s_data[base + q];
1270 auto &nq = fiber_n_data[base + q];
1271
1272 fq /= fq.norm();
1273 sq -= (fq * sq) * fq;
1274 sq /= sq.norm();
1275 nq -= (fq * nq) * fq;
1276 nq -= (sq * nq) * sq;
1277 nq /= nq.norm();
1278 }
1279 }
1280
1281 // Precompute fiber directions at inner face quadrature points.
1282 // Since the fiber field is in continuous FE_Q(1), we can evaluate
1283 // from the interior side; the trace is unique.
1284 {
1286 true,
1287 1);
1288 const unsigned int n_fq = phi_face.n_q_points;
1289 const unsigned int n_f_inner = data.n_inner_face_batches();
1290
1291 fiber_f_face_data.resize(n_f_inner * n_fq);
1292 fiber_s_face_data.resize(n_f_inner * n_fq);
1293 fiber_n_face_data.resize(n_f_inner * n_fq);
1294
1295 for (unsigned int face = 0; face < n_f_inner; ++face)
1296 {
1297 phi_face.reinit(face);
1298 const unsigned int fbase = face * n_fq;
1299
1300 // Read all three fiber fields for this face batch
1301 phi_face.read_dof_values_plain(f0);
1303 for (unsigned int q = 0; q < n_fq; ++q)
1304 fiber_f_face_data[fbase + q] = phi_face.get_value(q);
1305
1306 phi_face.read_dof_values_plain(s0);
1308 for (unsigned int q = 0; q < n_fq; ++q)
1309 fiber_s_face_data[fbase + q] = phi_face.get_value(q);
1310
1311 phi_face.read_dof_values_plain(n0);
1313 for (unsigned int q = 0; q < n_fq; ++q)
1314 fiber_n_face_data[fbase + q] = phi_face.get_value(q);
1315
1316 // Gram-Schmidt orthonormalization at each face quadrature point
1317 for (unsigned int q = 0; q < n_fq; ++q)
1318 {
1319 auto &fq = fiber_f_face_data[fbase + q];
1320 auto &sq = fiber_s_face_data[fbase + q];
1321 auto &nq = fiber_n_face_data[fbase + q];
1322
1323 fq /= fq.norm();
1324 sq -= (fq * sq) * fq;
1325 sq /= sq.norm();
1326 nq -= (fq * nq) * fq;
1327 nq -= (sq * nq) * sq;
1328 nq /= nq.norm();
1329 }
1330 }
1331 }
1332 }
1333
1334 void
1337 {
1338 dst = 0;
1339 vmult_add(dst, src);
1340 }
1341
1342 void
1345 {
1346 dst = 0;
1347 vmult_add(dst, src);
1348 }
1349
1350 void
1356
1357 void
1360 {
1361 // When the operator is used inside a multigrid V-cycle the
1362 // smoother may hand us vectors whose partitioner comes from the
1363 // DoFHandler (locally_owned_dofs) rather than from the MatrixFree
1364 // object. In that case we transparently re-partition.
1366 *data.get_dof_info(0).vector_partitioner))
1367 {
1369 src_copy.reinit(data.get_dof_info(0).vector_partitioner);
1370 src_copy.copy_locally_owned_data_from(src);
1371 src_copy.update_ghost_values();
1373 src_copy);
1374 }
1376 *data.get_dof_info(0).vector_partitioner))
1377 {
1379 dst_copy.reinit(data.get_dof_info(0).vector_partitioner);
1380 dst_copy.copy_locally_owned_data_from(dst);
1381 dst.swap(dst_copy);
1382 }
1387 this,
1388 dst,
1389 src,
1390 /*zero_dst =*/false,
1393 }
1394
1396 m() const
1397 {
1398 return data.get_vector_partitioner()->size();
1399 }
1400
1402 n() const
1403 {
1404 return data.get_vector_partitioner()->size();
1405 }
1406
1407 number
1408 el(const unsigned int row, const unsigned int col) const
1409 {
1410 (void)row;
1411 (void)col;
1412 AssertThrow(false,
1413 ExcMessage("Matrix-free does not allow for entry access"));
1414 return number();
1415 }
1416
1417 void
1420 {
1421 data.initialize_dof_vector(vector);
1422 }
1423
1424
1425 const DoFHandler<dim> &
1427 {
1428 return data.get_dof_handler();
1429 }
1430
1431
1432 const Triangulation<dim> &
1434 {
1435 return data.get_dof_handler().get_triangulation();
1436 }
1437
1440 {
1442 }
1443
1444
1447 {
1448 return &data;
1449 }
1450
1451
1452
1455 {
1456 static_assert(dim != 3,
1457 "get_system_matrix() uses isotropic sigma and is only "
1458 "meant for the 2D example. Use the matrix-based "
1459 "assembly in monodomain_DG3D instead.");
1460
1461 // Boilerplate for SIP-DG form. TODO: unify interface.
1463
1464 const auto cell_operation = [&](auto &phi) {
1466 for (unsigned int q = 0; q < phi.n_q_points; ++q)
1467 {
1468 // chi*Cm/dt M
1469 phi.submit_value(phi.get_value(q) * factor, q);
1470 // sigma K
1471 phi.submit_gradient(phi.get_gradient(q) * parameters.sigma, q);
1472 }
1474 };
1475
1476 const auto face_operation = [&](auto &phi_m, auto &phi_p) {
1479
1480 VectorizedArrayType sigmaF =
1481 (std::abs(
1482 (phi_m.normal_vector(0) * phi_m.inverse_jacobian(0))[dim - 1]) +
1483 std::abs(
1484 (phi_m.normal_vector(0) * phi_p.inverse_jacobian(0))[dim - 1])) *
1485 (number)(std::max(fe_degree, 1) * (fe_degree + 1.0));
1486
1487 for (unsigned int q = 0; q < phi_m.n_q_points; ++q)
1488 {
1489 VectorizedArrayType jump_value =
1490 (phi_m.get_value(q) - phi_p.get_value(q)) * 0.5;
1491 VectorizedArrayType average_valgrad =
1492 phi_m.get_normal_derivative(q) + phi_p.get_normal_derivative(q);
1493 average_valgrad =
1494 jump_value * 2. * sigmaF - average_valgrad * 0.5;
1495 phi_m.submit_normal_derivative(-parameters.sigma * jump_value, q);
1496 phi_p.submit_normal_derivative(-parameters.sigma * jump_value, q);
1497 phi_m.submit_value(parameters.sigma * average_valgrad, q);
1498 phi_p.submit_value(-parameters.sigma * average_valgrad, q);
1499 }
1502 };
1503
1504 // const auto boundary_operation = [&](auto &phi_m) {
1505 // (void)phi_m;
1506 // AssertThrow(
1507 // false,
1508 // ExcMessage(
1509 // "We have Neumann BCs only, so this should never be called."));
1510 // // Do nothing since we have homogeneous Neumann BCs
1511 // };
1512
1513
1515
1516
1517 // Check if matrix has already been set up.
1518 if (system_matrix.m() == 0 && system_matrix.n() == 0)
1519 {
1520 // Set up sparsity pattern of system matrix.
1521 const auto &dof_handler = data.get_dof_handler();
1522
1524 data.get_mg_level() != numbers::invalid_unsigned_int ?
1525 dof_handler.locally_owned_mg_dofs(data.get_mg_level()) :
1526 dof_handler.locally_owned_dofs(),
1527 data.get_task_info().communicator);
1528
1529 if (data.get_mg_level() != numbers::invalid_unsigned_int)
1531 dsp,
1532 data.get_mg_level(),
1533 constraints);
1534 else
1536 dsp,
1537 constraints);
1538
1539 dsp.compress();
1540 system_matrix.reinit(dsp);
1541
1542 // Assemble system matrix. Notice that degree 1 has been hardcoded.
1543
1545 degree,
1546 n_q_points,
1547 n_components,
1548 number,
1550 data,
1553 cell_operation,
1554 face_operation,
1555 nullptr /*boundary_operation*/);
1556 }
1557
1558 return system_matrix;
1559 }
1560
1561
1562
1563 void
1565 {
1566 static_assert(dim != 3,
1567 "get_system_matrix() uses isotropic sigma and is only "
1568 "meant for the 2D example. Use the matrix-based "
1569 "assembly in monodomain_DG3D instead.");
1570
1571 // Boilerplate for SIP-DG form. TODO: unify interface.
1573
1574 const auto cell_operation = [&](auto &phi) {
1576 for (unsigned int q = 0; q < phi.n_q_points; ++q)
1577 {
1578 phi.submit_value(phi.get_value(q) * factor, q);
1579 phi.submit_gradient(phi.get_gradient(q) * parameters.sigma, q);
1580 }
1582 };
1583
1584 const auto face_operation = [&](auto &phi_m, auto &phi_p) {
1587
1588 VectorizedArrayType sigmaF =
1589 (std::abs(
1590 (phi_m.normal_vector(0) * phi_m.inverse_jacobian(0))[dim - 1]) +
1591 std::abs(
1592 (phi_m.normal_vector(0) * phi_p.inverse_jacobian(0))[dim - 1])) *
1593 (number)(std::max(fe_degree, 1) * (fe_degree + 1.0));
1594
1595 for (unsigned int q = 0; q < phi_m.n_q_points; ++q)
1596 {
1597 VectorizedArrayType jump_value =
1598 (phi_m.get_value(q) - phi_p.get_value(q)) * 0.5;
1599 VectorizedArrayType average_valgrad =
1600 phi_m.get_normal_derivative(q) + phi_p.get_normal_derivative(q);
1601 average_valgrad =
1602 jump_value * 2. * sigmaF - average_valgrad * 0.5;
1603 phi_m.submit_normal_derivative(-parameters.sigma * jump_value, q);
1604 phi_p.submit_normal_derivative(-parameters.sigma * jump_value, q);
1605 phi_m.submit_value(parameters.sigma * average_valgrad, q);
1606 phi_p.submit_value(-parameters.sigma * average_valgrad, q);
1607 }
1610 };
1611
1612
1614
1615 // Check if matrix has already been set up.
1616 AssertThrow((mg_matrix.m() == 0 && mg_matrix.n() == 0),
1617 ExcInternalError());
1618
1619 // Set up sparsity pattern of system matrix.
1620 const DoFHandler<dim> &dof_handler = data.get_dof_handler();
1621
1622 const IndexSet &system_partitioning = dof_handler.locally_owned_dofs();
1623 const IndexSet system_relevant_set =
1625
1626
1627 DynamicSparsityPattern dsp(dof_handler.n_dofs(),
1628 dof_handler.n_dofs(),
1629 system_relevant_set);
1630 DoFTools::make_flux_sparsity_pattern(dof_handler, dsp);
1631
1633 dsp,
1634 system_partitioning,
1635 data.get_task_info().communicator,
1636 system_relevant_set);
1637 mg_matrix.reinit(system_partitioning,
1638 dsp,
1639 data.get_task_info().communicator);
1640
1641 // Assemble system matrix.
1643 degree,
1644 n_q_points,
1645 n_components,
1646 number,
1648 data,
1650 mg_matrix,
1651 cell_operation,
1652 face_operation,
1653 nullptr /*boundary_operation*/);
1654 }
1655
1656
1657 void
1659 {
1660 data.initialize_dof_vector(inverse_diagonal_entries);
1661 unsigned int dummy = 0;
1665 this,
1667 dummy);
1668
1669 for (unsigned int i = 0;
1671 ++i)
1675 }
1676
1677
1678
1679 void
1683 {
1685
1686 for (unsigned int cell = 0; cell < data.n_cell_batches(); ++cell)
1687 {
1688 phi.reinit(cell);
1689 phi.read_dof_values(src);
1691 for (unsigned int q = 0; q < phi.n_q_points; ++q)
1692 phi.submit_value(phi.get_value(q) * factor, q);
1695 }
1697 }
1698
1699
1700
1701 void
1703 const LinearAlgebra::distributed::Vector<number> &solution_minus_ion,
1704 const Function<dim> &Iext) const
1705 {
1707
1708 for (unsigned int cell = 0; cell < data.n_cell_batches(); ++cell)
1709 {
1710 phi.reinit(cell);
1711 phi.read_dof_values(solution_minus_ion);
1713 for (unsigned int q = 0; q < phi.n_q_points; ++q)
1714 {
1716 phi.quadrature_point(q);
1717 // evaluate the external current for each component in
1718 // VectorizedArray
1719 VectorizedArray<number> applied_current_value = 0.0;
1720 for (unsigned int v = 0; v < VectorizedArray<number>::size();
1721 ++v)
1722 {
1723 Point<dim> p;
1724 for (unsigned int d = 0; d < dim; ++d)
1725 p[d] = p_vect[d][v];
1726 applied_current_value[v] = Iext.value(p);
1727 }
1728
1729 // reaction_term = (parameters.chi * phi.get_value(q)) +
1730 // applied_current_value;
1731 phi.submit_value((parameters.chi * phi.get_value(q)) +
1732 applied_current_value,
1733 q);
1734 }
1737 }
1739 }
1740
1741
1742
1743 private:
1744 void
1748 const std::pair<unsigned int, unsigned int> &cell_range) const
1749 {
1751
1752 for (unsigned int cell = cell_range.first; cell < cell_range.second;
1753 ++cell)
1754 {
1755 phi.reinit(cell);
1756 phi.read_dof_values(src);
1758 for (unsigned int q = 0; q < phi.n_q_points; ++q)
1759 {
1760 phi.submit_value(phi.get_value(q) * factor, q);
1761 phi.submit_gradient(
1762 apply_diffusion(phi.get_gradient(q), cell, q), q);
1763 }
1766 }
1767 }
1768
1769 void
1774 const std::pair<unsigned int, unsigned int> &face_range) const
1775 {
1777 data, true);
1779 fe_eval_neighbor(data, false);
1780
1781 for (unsigned int face = face_range.first; face < face_range.second;
1782 ++face)
1783 {
1784 fe_eval.reinit(face);
1785 fe_eval_neighbor.reinit(face);
1786
1787 fe_eval.read_dof_values(src);
1790 fe_eval_neighbor.read_dof_values(src);
1791 fe_eval_neighbor.evaluate(EvaluationFlags::values |
1794 (std::abs((fe_eval.normal_vector(0) *
1795 fe_eval.inverse_jacobian(0))[dim - 1]) +
1796 std::abs((fe_eval.normal_vector(0) *
1797 fe_eval_neighbor.inverse_jacobian(0))[dim - 1])) *
1798 (number)(std::max(fe_degree, 1) * (fe_degree + 1.0));
1799
1800 const number sigma_f = face_sigma();
1801 for (unsigned int q = 0; q < fe_eval.n_q_points; ++q)
1802 {
1803 const auto u_plus = fe_eval.get_value(q);
1804 const auto u_minus = fe_eval_neighbor.get_value(q);
1805 const auto jump_u = (u_plus - u_minus) * 0.5;
1806 const auto normal = fe_eval.normal_vector(q);
1807
1808 // Apply D to gradients from both sides and dot with normal
1809 // → {D gradu * n} = 0.5*(D gradu_plus*n + D gradu_minus*n)
1810 const auto D_grad_plus =
1811 apply_diffusion_face(fe_eval.get_gradient(q), face, q);
1812 const auto D_grad_minus =
1813 apply_diffusion_face(fe_eval_neighbor.get_gradient(q),
1814 face,
1815 q);
1816 const auto avg_D_grad_n =
1817 (D_grad_plus * normal + D_grad_minus * normal) * 0.5;
1818
1819 // D·n for the symmetry term:
1820 // -[u]*{D grad v*n} = -[u]*v*(Dn) (D is symmetric)
1821 const auto Dn = apply_diffusion_face(normal, face, q);
1822
1823 // Consistency: −{D gradu*n}[v]
1824 // Penalty: sigma_pen [u][v], sigma_pen = sigma_f * sigmaF
1825 const auto penalty_val = sigma_f * sigmaF * jump_u * 2.;
1826 fe_eval.submit_value(penalty_val - avg_D_grad_n, q);
1827 fe_eval_neighbor.submit_value(-penalty_val + avg_D_grad_n, q);
1828
1829 // Symmetry: −{D gradv*n}[u] = -grad v*(Dn) [u]/2
1830 fe_eval.submit_gradient(Dn * (-jump_u), q);
1831 fe_eval_neighbor.submit_gradient(Dn * (-jump_u), q);
1832 }
1835 fe_eval.distribute_local_to_global(dst);
1836 fe_eval_neighbor.integrate(EvaluationFlags::values |
1838 fe_eval_neighbor.distribute_local_to_global(dst);
1839 }
1840 }
1841
1842 void
1847 const std::pair<unsigned int, unsigned int> &face_range) const
1848 {
1849 (void)data;
1850 (void)dst;
1851 (void)src;
1852 (void)face_range;
1853 // Do nothing since we have homogeneous Neumann BCs
1854 }
1855
1856
1857 void
1861 const unsigned int &,
1862 const std::pair<unsigned int, unsigned int> &cell_range) const
1863 {
1865 AlignedVector<VectorizedArray<number>> local_diagonal_vector(
1866 phi.dofs_per_cell);
1867
1868 for (unsigned int cell = cell_range.first; cell < cell_range.second;
1869 ++cell)
1870 {
1871 phi.reinit(cell);
1872
1873 for (unsigned int i = 0; i < phi.dofs_per_cell; ++i)
1874 {
1875 for (unsigned int j = 0; j < phi.dofs_per_cell; ++j)
1877 phi.begin_dof_values()[i] = 1.;
1880 for (unsigned int q = 0; q < phi.n_q_points; ++q)
1881 {
1882 phi.submit_value(phi.get_value(q) * factor, q);
1883 phi.submit_gradient(
1884 apply_diffusion(phi.get_gradient(q), cell, q), q);
1885 }
1888 local_diagonal_vector[i] = phi.begin_dof_values()[i];
1889 }
1890 for (unsigned int i = 0; i < phi.dofs_per_cell; ++i)
1891 phi.begin_dof_values()[i] = local_diagonal_vector[i];
1893 }
1894 }
1895
1896 void
1900 const unsigned int &,
1901 const std::pair<unsigned int, unsigned int> &face_range) const
1902 {
1904 data, true);
1906 phi_outer(data, false);
1907 AlignedVector<VectorizedArray<number>> local_diagonal_vector(
1908 phi.dofs_per_cell);
1909
1910 for (unsigned int face = face_range.first; face < face_range.second;
1911 ++face)
1912 {
1913 phi.reinit(face);
1914 phi_outer.reinit(face);
1915
1917 (std::abs(
1918 (phi.normal_vector(0) * phi.inverse_jacobian(0))[dim - 1]) +
1919 std::abs((phi.normal_vector(0) *
1920 phi_outer.inverse_jacobian(0))[dim - 1])) *
1921 (number)(std::max(fe_degree, 1) * (fe_degree + 1.0));
1922
1923 const number sigma_f = face_sigma();
1924
1925 // Compute phi part (u_plus = phi_i, u_minus = 0)
1926 for (unsigned int j = 0; j < phi.dofs_per_cell; ++j)
1927 phi_outer.begin_dof_values()[j] = VectorizedArray<number>();
1930 for (unsigned int i = 0; i < phi.dofs_per_cell; ++i)
1931 {
1932 for (unsigned int j = 0; j < phi.dofs_per_cell; ++j)
1934 phi.begin_dof_values()[i] = 1.;
1937
1938 for (unsigned int q = 0; q < phi.n_q_points; ++q)
1939 {
1940 const auto u_plus = phi.get_value(q);
1941 const auto u_minus = phi_outer.get_value(q);
1942 const auto jump_u = (u_plus - u_minus) * 0.5;
1943 const auto normal = phi.normal_vector(q);
1944
1945 const auto D_grad_plus =
1946 apply_diffusion_face(phi.get_gradient(q), face, q);
1947 const auto D_grad_minus =
1948 apply_diffusion_face(phi_outer.get_gradient(q), face, q);
1949 const auto avg_D_grad_n =
1950 (D_grad_plus * normal + D_grad_minus * normal) * 0.5;
1951
1952 const auto Dn = apply_diffusion_face(normal, face, q);
1953
1954 const auto penalty_val = sigma_f * sigmaF * jump_u * 2.;
1955 phi.submit_value(penalty_val - avg_D_grad_n, q);
1956 phi.submit_gradient(Dn * (-jump_u), q);
1957 }
1960 local_diagonal_vector[i] = phi.begin_dof_values()[i];
1961 }
1962 for (unsigned int i = 0; i < phi.dofs_per_cell; ++i)
1963 phi.begin_dof_values()[i] = local_diagonal_vector[i];
1965
1966 // Compute phi_outer part (u_plus = 0, u_minus = phi_i)
1967 for (unsigned int j = 0; j < phi.dofs_per_cell; ++j)
1970 for (unsigned int i = 0; i < phi.dofs_per_cell; ++i)
1971 {
1972 for (unsigned int j = 0; j < phi.dofs_per_cell; ++j)
1973 phi_outer.begin_dof_values()[j] = VectorizedArray<number>();
1974 phi_outer.begin_dof_values()[i] = 1.;
1977
1978 for (unsigned int q = 0; q < phi.n_q_points; ++q)
1979 {
1980 const auto u_plus = phi.get_value(q);
1981 const auto u_minus = phi_outer.get_value(q);
1982 const auto jump_u = (u_plus - u_minus) * 0.5;
1983 const auto normal = phi.normal_vector(q);
1984
1985 const auto D_grad_plus =
1986 apply_diffusion_face(phi.get_gradient(q), face, q);
1987 const auto D_grad_minus =
1988 apply_diffusion_face(phi_outer.get_gradient(q), face, q);
1989 const auto avg_D_grad_n =
1990 (D_grad_plus * normal + D_grad_minus * normal) * 0.5;
1991
1992 const auto Dn = apply_diffusion_face(normal, face, q);
1993
1994 const auto penalty_val = sigma_f * sigmaF * jump_u * 2.;
1995 phi_outer.submit_value(-penalty_val + avg_D_grad_n, q);
1996 phi_outer.submit_gradient(Dn * (-jump_u), q);
1997 }
2000 local_diagonal_vector[i] = phi_outer.begin_dof_values()[i];
2001 }
2002 for (unsigned int i = 0; i < phi.dofs_per_cell; ++i)
2003 phi_outer.begin_dof_values()[i] = local_diagonal_vector[i];
2004 phi_outer.distribute_local_to_global(dst);
2005 }
2006 }
2007
2008 void
2012 const unsigned int &,
2013 const std::pair<unsigned int, unsigned int> &face_range) const
2014 {
2015 (void)data;
2016 (void)dst;
2017 (void)face_range;
2018 // Do nothing since we have homogeneous Neumann BCs
2019 }
2020
2021
2022
2023 // Total quadrature points per cell (compile-time constant)
2024 static constexpr unsigned int n_q_points_total =
2025 constexpr_pow(static_cast<unsigned int>(n_q_points),
2026 static_cast<unsigned int>(dim));
2027
2028 // Total quadrature points per face (compile-time constant)
2029 static constexpr unsigned int n_face_q_points_total =
2030 constexpr_pow(static_cast<unsigned int>(n_q_points),
2031 static_cast<unsigned int>(dim - 1));
2032
2041 const unsigned int cell,
2042 const unsigned int q) const
2043 {
2045 {
2046 const unsigned int idx = cell * n_q_points_total + q;
2047 const auto &f = fiber_f_data[idx];
2048 const auto &s = fiber_s_data[idx];
2049 const auto &nv = fiber_n_data[idx];
2050 return VectorizedArrayType(parameters.sigma_l) * (f * grad) * f +
2051 VectorizedArrayType(parameters.sigma_t) * (s * grad) * s +
2052 VectorizedArrayType(parameters.sigma_n) * (nv * grad) * nv;
2053 }
2054 else
2055 {
2056 return grad * VectorizedArrayType(parameters.sigma);
2057 }
2058 }
2059
2068 number
2075
2083 const unsigned int face,
2084 const unsigned int q) const
2085 {
2087 {
2088 const unsigned int idx = face * n_face_q_points_total + q;
2089 const auto &f = fiber_f_face_data[idx];
2090 const auto &s = fiber_s_face_data[idx];
2091 const auto &nv = fiber_n_face_data[idx];
2092 return VectorizedArrayType(parameters.sigma_l) * (f * vec) * f +
2093 VectorizedArrayType(parameters.sigma_t) * (s * vec) * s +
2094 VectorizedArrayType(parameters.sigma_n) * (nv * vec) * nv;
2095 }
2096 else
2097 {
2098 return vec * VectorizedArrayType(parameters.sigma);
2099 }
2100 }
2101
2102
2109 double factor;
2110
2111 // Precomputed fiber directions at cell quadrature points
2115
2116 // Precomputed fiber directions at inner face quadrature points
2120 };
2121
2122
2123
2124 } // namespace MatrixFreeOperators
2125
2126
2127
2132 get_index(const std::vector<types::global_cell_index> &v,
2133 const types::global_cell_index index)
2134 {
2135 return std::distance(v.begin(), std::find(v.begin(), v.end(), index));
2136 }
2137
2138
2139
2140 template <int dim>
2141 void
2143 const std::vector<typename Triangulation<dim>::active_cell_iterator> &cells,
2144 Graph &g)
2145 {
2146 Assert(cells.size() > 0, ExcMessage("No cells to be agglomerated."));
2147 const unsigned int n_faces = cells[0]->n_faces();
2148
2149 std::vector<types::global_cell_index> vec_cells(cells.size());
2150 for (size_t i = 0; i < cells.size(); i++)
2151 vec_cells[i] = cells[i]->active_cell_index();
2152
2153 g.adjacency.resize(cells.size());
2154 for (const auto &cell : cells)
2155 {
2156 // std::cout << "Cell idx: " << cell->active_cell_index() <<
2157 // std::endl; std::cout << "new idx: "
2158 // << get_index(vec_cells, cell->active_cell_index())
2159 // << std::endl;
2160 g.nodes.push_back(get_index(vec_cells, cell->active_cell_index()));
2161 for (unsigned int f = 0; f < n_faces; ++f)
2162 {
2163 const auto &neigh = cell->neighbor(f);
2164 if (neigh.state() == IteratorState::IteratorStates::valid &&
2165 std::find(cells.begin(), cells.end(), neigh) != std::end(cells))
2166 g.adjacency[get_index(vec_cells, cell->active_cell_index())]
2167 .push_back(get_index(vec_cells, neigh->active_cell_index()));
2168 }
2169 }
2170 }
2171
2172
2173
2174 inline void
2175 dfs(std::vector<types::global_cell_index> &comp,
2176 std::vector<bool> &visited,
2177 const Graph &g,
2179 {
2180 visited[v] = true;
2181 comp.push_back(v);
2182 for (const types::global_cell_index u : g.adjacency[v])
2183 {
2184 if (!visited[u])
2185 dfs(comp, visited, g, u);
2186 }
2187 }
2188
2189
2190
2191 void
2193 Graph &g,
2194 std::vector<std::vector<types::global_cell_index>> &connected_components)
2195 {
2196 Assert(g.nodes.size() > 0, ExcMessage("No nodes in this graph."));
2197 Assert(
2198 connected_components.size() == 0,
2199 ExcMessage(
2200 "Connected components have to be computed by the present function."));
2201
2202 std::vector<bool> visited(g.nodes.size()); // register visited node
2203 std::fill(visited.begin(), visited.end(), 0);
2204
2205
2207 {
2208 if (!visited[v])
2209 {
2210 connected_components.emplace_back();
2211 dfs(connected_components.back(), visited, g, v);
2212 }
2213 }
2214 }
2215
2216
2217} // namespace Utils
2218
2219
2220
2221#endif
void distribute_local_to_global(const InVector &local_vector, const std::vector< size_type > &local_dof_indices, OutVector &global_vector) const
bool empty() const
void resize(const size_type new_size)
Point< spacedim, Number > real_to_unit(const Point< spacedim, Number > &point) const
Point< spacedim, Number > unit_to_real(const Point< spacedim, Number > &point) const
const FiniteElement< dim, spacedim > & get_fe(const types::fe_index index=0) const
const IndexSet & locally_owned_dofs() const
types::global_dof_index n_dofs() const
void reinit(const size_type m, const size_type n, const IndexSet &rowset=IndexSet())
gradient_type get_gradient(const unsigned int q_point) const
void submit_gradient(const gradient_type grad_in, const unsigned int q_point)
void submit_value(const value_type val_in, const unsigned int q_point)
void distribute_local_to_global(VectorType &dst, const unsigned int first_index=0, const std::bitset< n_lanes > &mask=std::bitset< n_lanes >().flip()) const
void read_dof_values_plain(const VectorType &src, const unsigned int first_index=0, const std::bitset< n_lanes > &mask=std::bitset< n_lanes >().flip())
value_type get_value(const unsigned int q_point) const
void read_dof_values(const VectorType &src, const unsigned int first_index=0, const std::bitset< n_lanes > &mask=std::bitset< n_lanes >().flip())
Tensor< 2, dim, VectorizedArrayType > inverse_jacobian(const unsigned int q_point) const
Tensor< 1, dim, VectorizedArrayType > normal_vector(const unsigned int q_point) const
Point< dim, VectorizedArrayType > quadrature_point(const unsigned int q) const
const VectorizedArrayType * begin_dof_values() const
const unsigned int n_q_points
void reinit(const unsigned int cell_batch_index)
void evaluate(const EvaluationFlags::EvaluationFlags evaluation_flag)
const unsigned int dofs_per_cell
void integrate(const EvaluationFlags::EvaluationFlags integration_flag)
void reinit(const unsigned int face_batch_number)
const unsigned int n_q_points
const unsigned int dofs_per_cell
void evaluate(const EvaluationFlags::EvaluationFlags evaluation_flag)
void integrate(const EvaluationFlags::EvaluationFlags integration_flag, const bool sum_into_values=false)
const unsigned int degree
const unsigned int dofs_per_cell
const std::vector< Point< dim > > & get_unit_support_points() const
virtual double shape_value(const unsigned int i, const Point< dim > &p) const
virtual RangeNumberType value(const Point< dim > &p, const unsigned int component=0) const
Number local_element(const size_type local_index) const
size_type locally_owned_size() const
void swap(Vector< Number, MemorySpace > &v) noexcept
void compress(VectorOperation::values operation)
bool partitioners_are_globally_compatible(const Utilities::MPI::Partitioner &part) const
void copy_locally_owned_data_from(const Vector< Number2, MemorySpace > &src)
void reinit(const size_type size, const bool omit_zeroing_entries=false)
void copy_from(const size_type n_rows, const size_type n_cols, const ForwardIterator begin, const ForwardIterator end)
bool empty() const
virtual MPI_Comm get_mpi_communicator() const
void reinit(const SparsityPatternType &sparsity_pattern)
const DoFHandler< dim, spacedim >::active_cell_iterator polytope_to_dh_iterator(const types::global_cell_index polytope_index) const
types::global_dof_index n_dofs() const noexcept
const Triangulation< dim, spacedim > & get_triangulation() const
const Mapping< dim > & get_mapping() const
const std::vector< BoundingBox< dim > > & get_local_bboxes() const
const FiniteElement< dim, spacedim > & get_fe() const
IteratorRange< agglomeration_iterator > polytope_iterators() const
DoFHandler< dim, spacedim > agglo_dh
const MatrixType & coarse_matrix
Definition utils.h:350
MGCoarseDirect(const MatrixType &matrix)
Definition utils.h:291
void operator()(const unsigned int, VectorType &dst, const VectorType &src) const override
Definition utils.h:336
SolverType direct_solver
Definition utils.h:349
void Tvmult(LinearAlgebra::distributed::Vector< number > &dst, const LinearAlgebra::distributed::Vector< number > &src) const
Definition utils.h:436
LinearAlgebra::distributed::Vector< number > inverse_diagonal_entries
Definition utils.h:1110
AffineConstraints< number > constraints
Definition utils.h:1113
void rhs(LinearAlgebra::distributed::Vector< number > &b) const
Definition utils.h:755
void vmult_add(LinearAlgebra::distributed::Vector< number > &dst, const LinearAlgebra::distributed::Vector< number > &src) const
Definition utils.h:451
void local_diagonal_face(const MatrixFree< dim, number > &data, LinearAlgebra::distributed::Vector< number > &dst, const unsigned int &, const std::pair< unsigned int, unsigned int > &face_range) const
Definition utils.h:967
void local_diagonal_boundary(const MatrixFree< dim, number > &data, LinearAlgebra::distributed::Vector< number > &dst, const unsigned int &, const std::pair< unsigned int, unsigned int > &face_range) const
Definition utils.h:1059
TrilinosWrappers::SparseMatrix system_matrix
Definition utils.h:1112
number el(const unsigned int row, const unsigned int col) const
Definition utils.h:493
void initialize_dof_vector(LinearAlgebra::distributed::Vector< number > &vector) const
Definition utils.h:503
void reinit(const Mapping< dim > &mapping, const DoFHandler< dim > &dof_handler, const unsigned int level=numbers::invalid_unsigned_int)
Definition utils.h:404
VectorizedArray< number > VectorizedArrayType
Definition utils.h:397
const Triangulation< dim > & get_triangulation() const
Definition utils.h:518
const LinearAlgebra::distributed::Vector< number > & get_matrix_diagonal_inverse() const
Definition utils.h:524
const DoFHandler< dim > & get_dof_handler() const
Definition utils.h:511
const MatrixFree< dim, number > * get_matrix_free() const
Definition utils.h:531
void local_diagonal_cell(const MatrixFree< dim, number > &data, LinearAlgebra::distributed::Vector< number > &dst, const unsigned int &, const std::pair< unsigned int, unsigned int > &cell_range) const
Definition utils.h:934
void vmult(LinearAlgebra::distributed::Vector< number > &dst, const LinearAlgebra::distributed::Vector< number > &src) const
Definition utils.h:428
void get_system_matrix(TrilinosWrappers::SparseMatrix &mg_matrix) const
Definition utils.h:649
void local_apply_boundary(const MatrixFree< dim, number > &data, LinearAlgebra::distributed::Vector< number > &dst, const LinearAlgebra::distributed::Vector< number > &src, const std::pair< unsigned int, unsigned int > &face_range) const
Definition utils.h:897
types::global_dof_index n() const
Definition utils.h:487
const TrilinosWrappers::SparseMatrix & get_system_matrix() const
Definition utils.h:539
void Tvmult_add(LinearAlgebra::distributed::Vector< number > &dst, const LinearAlgebra::distributed::Vector< number > &src) const
Definition utils.h:444
LinearAlgebra::distributed::Vector< number > VectorType
Definition utils.h:398
types::global_dof_index m() const
Definition utils.h:481
void local_apply(const MatrixFree< dim, number > &data, LinearAlgebra::distributed::Vector< number > &dst, const LinearAlgebra::distributed::Vector< number > &src, const std::pair< unsigned int, unsigned int > &cell_range) const
Definition utils.h:824
void local_apply_face(const MatrixFree< dim, number > &data, LinearAlgebra::distributed::Vector< number > &dst, const LinearAlgebra::distributed::Vector< number > &src, const std::pair< unsigned int, unsigned int > &face_range) const
Definition utils.h:845
Tensor< 1, dim, VectorizedArrayType > apply_diffusion(const Tensor< 1, dim, VectorizedArrayType > &grad, const unsigned int cell, const unsigned int q) const
Definition utils.h:2040
Physics::BilinearFormParameters parameters
Definition utils.h:2108
AlignedVector< Tensor< 1, dim, VectorizedArrayType > > FiberArray
Definition utils.h:1132
void rhs(LinearAlgebra::distributed::Vector< number > &rhs, const LinearAlgebra::distributed::Vector< number > &solution_minus_ion, const Function< dim > &Iext) const
Definition utils.h:1702
MonodomainOperatorDG(const Physics::BilinearFormParameters &parameters_)
Definition utils.h:1134
const DoFHandler< dim > & get_dof_handler() const
Definition utils.h:1426
void reinit(const Mapping< dim > &mapping, const DoFHandler< dim > &dof_handler, const DoFHandler< dim > &fiber_dof_handler, const unsigned int level=numbers::invalid_unsigned_int)
Definition utils.h:1181
void local_apply_face(const MatrixFree< dim, number > &data, LinearAlgebra::distributed::Vector< number > &dst, const LinearAlgebra::distributed::Vector< number > &src, const std::pair< unsigned int, unsigned int > &face_range) const
Definition utils.h:1770
void local_apply(const MatrixFree< dim, number > &data, LinearAlgebra::distributed::Vector< number > &dst, const LinearAlgebra::distributed::Vector< number > &src, const std::pair< unsigned int, unsigned int > &cell_range) const
Definition utils.h:1745
Tensor< 1, dim, VectorizedArrayType > apply_diffusion_face(const Tensor< 1, dim, VectorizedArrayType > &vec, const unsigned int face, const unsigned int q) const
Definition utils.h:2082
const LinearAlgebra::distributed::Vector< number > & get_matrix_diagonal_inverse() const
Definition utils.h:1439
void local_diagonal_face(const MatrixFree< dim, number > &data, LinearAlgebra::distributed::Vector< number > &dst, const unsigned int &, const std::pair< unsigned int, unsigned int > &face_range) const
Definition utils.h:1897
const MatrixFree< dim, number > * get_matrix_free() const
Definition utils.h:1446
void reinit(const Mapping< dim > &mapping, const DoFHandler< dim > &dof_handler, const unsigned int level=numbers::invalid_unsigned_int)
Definition utils.h:1146
TrilinosWrappers::SparseMatrix system_matrix
Definition utils.h:2106
LinearAlgebra::distributed::Vector< number > inverse_diagonal_entries
Definition utils.h:2104
void local_diagonal_cell(const MatrixFree< dim, number > &data, LinearAlgebra::distributed::Vector< number > &dst, const unsigned int &, const std::pair< unsigned int, unsigned int > &cell_range) const
Definition utils.h:1858
VectorizedArray< number > VectorizedArrayType
Definition utils.h:1130
AffineConstraints< number > constraints
Definition utils.h:2107
void Tvmult_add(LinearAlgebra::distributed::Vector< number > &dst, const LinearAlgebra::distributed::Vector< number > &src) const
Definition utils.h:1351
static constexpr unsigned int n_face_q_points_total
Definition utils.h:2029
void apply_mass_term(LinearAlgebra::distributed::Vector< number > &dst, const LinearAlgebra::distributed::Vector< number > &src) const
Definition utils.h:1680
const TrilinosWrappers::SparseMatrix & get_system_matrix() const
Definition utils.h:1454
number el(const unsigned int row, const unsigned int col) const
Definition utils.h:1408
LinearAlgebra::distributed::Vector< number > VectorType
Definition utils.h:1131
types::global_dof_index m() const
Definition utils.h:1396
void local_apply_boundary(const MatrixFree< dim, number > &data, LinearAlgebra::distributed::Vector< number > &dst, const LinearAlgebra::distributed::Vector< number > &src, const std::pair< unsigned int, unsigned int > &face_range) const
Definition utils.h:1843
void precompute_fibers(const LinearAlgebra::distributed::Vector< number > &f0, const LinearAlgebra::distributed::Vector< number > &s0, const LinearAlgebra::distributed::Vector< number > &n0)
Definition utils.h:1229
void get_system_matrix(TrilinosWrappers::SparseMatrix &mg_matrix) const
Definition utils.h:1564
void local_diagonal_boundary(const MatrixFree< dim, number > &data, LinearAlgebra::distributed::Vector< number > &dst, const unsigned int &, const std::pair< unsigned int, unsigned int > &face_range) const
Definition utils.h:2009
void vmult_add(LinearAlgebra::distributed::Vector< number > &dst, const LinearAlgebra::distributed::Vector< number > &src) const
Definition utils.h:1358
void vmult(LinearAlgebra::distributed::Vector< number > &dst, const LinearAlgebra::distributed::Vector< number > &src) const
Definition utils.h:1335
types::global_dof_index n() const
Definition utils.h:1402
void initialize_dof_vector(LinearAlgebra::distributed::Vector< number > &vector) const
Definition utils.h:1418
void Tvmult(LinearAlgebra::distributed::Vector< number > &dst, const LinearAlgebra::distributed::Vector< number > &src) const
Definition utils.h:1343
static constexpr unsigned int n_q_points_total
Definition utils.h:2024
const Triangulation< dim > & get_triangulation() const
Definition utils.h:1433
#define DEAL_II_NOT_IMPLEMENTED()
unsigned int level
#define Assert(cond, exc)
#define AssertDimension(dim1, dim2)
#define AssertThrow(cond, exc)
TriaActiveIterator< CellAccessor< dim, spacedim > > active_cell_iterator
typename ActiveSelector::active_cell_iterator active_cell_iterator
void make_flux_sparsity_pattern(const DoFHandler< dim, spacedim > &dof_handler, SparsityPatternBase &sparsity_pattern)
update_values
update_JxW_values
update_gradients
update_quadrature_points
Expression pow(const Expression &base, const Expression &exponent)
IndexSet extract_locally_relevant_dofs(const DoFHandler< dim, spacedim > &dof_handler)
void make_flux_sparsity_pattern(const DoFHandler< dim, spacedim > &dof_handler, SparsityPatternBase &sparsity, const unsigned int level, const AffineConstraints< number > &constraints={}, const bool keep_constrained_dofs=true)
void compute_matrix(const MatrixFree< dim, Number, VectorizedArrayType > &matrix_free, const AffineConstraints< Number > &constraints, MatrixType &matrix, const std::function< void(FEEvaluation< dim, fe_degree, n_q_points_1d, n_components, Number, VectorizedArrayType > &)> &cell_operation, const unsigned int dof_handler_index=0, const unsigned int quadrature_index=0, const unsigned int first_selected_component=0)
SymmetricTensor< 2, dim, Number > e(const Tensor< 2, dim, Number > &F)
SymmetricTensor< 2, dim, Number > b(const Tensor< 2, dim, Number > &F)
SymmetricTensor< 2, dim, Number > d(const Tensor< 2, dim, Number > &F, const Tensor< 2, dim, Number > &dF_dt)
void distribute_sparsity_pattern(DynamicSparsityPattern &dsp, const IndexSet &locally_owned_rows, const MPI_Comm mpi_comm, const IndexSet &locally_relevant_rows)
Definition utils.h:48
void create_graph_from_agglomerate(const std::vector< typename Triangulation< dim >::active_cell_iterator > &cells, Graph &g)
Definition utils.h:2142
void dfs(std::vector< types::global_cell_index > &comp, std::vector< bool > &visited, const Graph &g, const types::global_cell_index v)
Definition utils.h:2175
constexpr T constexpr_pow(T num, unsigned int pow)
Definition utils.h:51
void fill_injection_matrix(const AgglomerationHandler< dim, spacedim > &coarse_ah, const AgglomerationHandler< dim, spacedim > &fine_ah, SparsityPattern &sp, MatrixType &matrix)
Definition utils.h:98
void compute_connected_components(Graph &g, std::vector< std::vector< types::global_cell_index > > &connected_components)
Definition utils.h:2192
types::global_cell_index get_index(const std::vector< types::global_cell_index > &v, const types::global_cell_index index)
Definition utils.h:2132
constexpr unsigned int invalid_unsigned_int
::VectorizedArray< Number, width > max(const ::VectorizedArray< Number, width > &, const ::VectorizedArray< Number, width > &)
::VectorizedArray< Number, width > abs(const ::VectorizedArray< Number, width > &)
unsigned int global_dof_index
unsigned int global_cell_index
void swap(ObserverPointer< T, P > &t1, ObserverPointer< T, Q > &t2)
TasksParallelScheme tasks_parallel_scheme
UpdateFlags mapping_update_flags_inner_faces
UpdateFlags mapping_update_flags_boundary_faces
UpdateFlags mapping_update_flags
void print_graph() const
Definition utils.h:70
std::vector< std::vector< types::global_cell_index > > adjacency
Definition utils.h:67
std::vector< types::global_cell_index > nodes
Definition utils.h:66