Lethe Open-Source Library version 1.2.0
Developer Guide
Loading...
Searching...
No Matches
mortar_coupling_manager.cc
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) 2025-2026 The Lethe Authors
2// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
3
4#include <deal.II/base/config.h>
5
7
8#include <deal.II/base/exceptions.h>
9#include <deal.II/base/mpi_noncontiguous_partitioner.templates.h>
10
11#include <deal.II/fe/fe_nothing.h>
12
13#include <algorithm>
14
16 InterfaceRadiusTolerance,
17 double,
18 << "The computed radius of the rotor mesh has a variation of " << arg1
19 << " along the interface boundary, which exceeds the prescribed tolerance.");
20
21/*-------------- MortarManagerBase -------------------------------*/
22
23template <int dim>
24bool
26{
27 AssertThrow(dim != 1, ExcInternalError());
28
29 // Angle variation within each cell (in radians)
30 const double delta_0 = 2 * numbers::PI / n_subdivisions[0];
31 // Tolerance to verify the mesh alignment in the real space
32 const double tolerance = 1e-8 * delta_0;
33
34 return std::abs(rotation_angle / delta_0 -
35 std::round(rotation_angle / delta_0)) < tolerance;
36}
37
38template <int dim>
39unsigned int
41{
42 if constexpr (dim == 1)
43 return 1;
44
45 // Total number of subdivisions (in 2D, this is equivalent to the number of
46 // cells at the interface)
47 unsigned int n_total_subdivisions = n_subdivisions[0];
48
49 // In 3D, besides the subdivisions in the plane perpendicular to the rotation
50 // axis, we also need to account for the number of subdivisions along the
51 // rotation axis direction
52 if constexpr (dim == 3)
53 n_total_subdivisions *= n_subdivisions[1];
54
55 if (this->is_mesh_aligned()) // aligned
56 return n_total_subdivisions;
57 else // inside/outside
58 return 2 * n_total_subdivisions;
59}
60
61template <int dim>
62unsigned int
64{
65 if constexpr (dim == 1)
66 return 1;
67
68 if (this->is_mesh_aligned()) // aligned
69 return 1;
70 else // inside/outside
71 return 2;
72}
73
74template <int dim>
75std::vector<unsigned int>
76MortarManagerBase<dim>::get_mortar_indices(const Point<dim> &face_center,
77 const bool is_inner) const
78{
79 if constexpr (dim == 1)
80 return std::vector<unsigned int>{0};
81
82 // Mesh alignment type and cell indexes
83 const auto [type, id_in_plane, id_out_plane] =
84 get_config(face_center, is_inner);
85
86 if (type == 0) // aligned
87 {
88 std::vector<unsigned int> indices;
89
90 const unsigned int index = id_in_plane;
91
92 AssertIndexRange(index, n_subdivisions[0]);
93
94 indices.emplace_back(index + n_subdivisions[0] * id_out_plane);
95
96 return indices;
97 }
98 else if (type == 1) // inside
99 {
100 std::vector<unsigned int> indices;
101
102 for (unsigned int q = 0; q < 2; ++q)
103 {
104 // Index of the mortar cell in the rotor side
105 const unsigned int index =
106 (id_in_plane * 2 + 1 + q) % (n_subdivisions[0] * 2);
107 // Assert that the index is within the valid range of mortar cells
108 AssertIndexRange(index, n_subdivisions[0] * 2);
109
110 indices.emplace_back(index + 2 * n_subdivisions[0] * id_out_plane);
111 }
112
113 return indices;
114 }
115 else // outside
116 {
117 std::vector<unsigned int> indices;
118
119 for (unsigned int q = 0; q < 2; ++q)
120 {
121 // Index of the mortar cell in the stator side
122 const unsigned int index = id_in_plane * 2 + q;
123 // Assert that the index is within the valid range of mortar cells
124 AssertIndexRange(index, n_subdivisions[0] * 2);
125
126 indices.emplace_back(index + 2 * n_subdivisions[0] * id_out_plane);
127 }
128
129 return indices;
130 }
131}
132
133template <int dim>
134unsigned int
136{
137 if constexpr (dim == 1)
138 return 1;
139
141}
142
143template <int dim>
144unsigned int
146{
147 if constexpr (dim == 1)
148 return 1;
149
151}
152
153template <int dim>
154std::vector<Point<dim>>
155MortarManagerBase<dim>::get_points(const Point<dim> &face_center,
156 const bool is_inner) const
157{
158 if constexpr (dim == 1)
159 return std::vector<Point<dim>>{face_center};
160
161 // Mesh alignment type and cell index
162 const auto [type, id_in_plane, id_out_plane] =
163 get_config(face_center, is_inner);
164 // Angle span of each cell (in radians)
165 const double delta_0 = 2 * numbers::PI / n_subdivisions[0];
166 // Height of the cell in the direction of the rotation axis (in units of
167 // length) in 3D cases. In 2D, the default is 1.0
168 double delta_1 = 1.0;
169
170 if constexpr (dim == 3)
171 delta_1 = stage_heights[id_out_plane + 1] - stage_heights[id_out_plane];
172
173 if (type == 0) // aligned
174 {
175 std::vector<Point<dim>> points;
176
177 for (unsigned int q = 0; q < n_quadrature_points; ++q)
178 {
179 // Convert quadrature point in reference space to real space
180 Point<dim> x =
181 from_1D((id_in_plane + quadrature.point(q)[0]) * delta_0);
182
183 if constexpr (dim == 3)
184 x[this->rotation_axis_direction] =
185 stage_heights[id_out_plane] + quadrature.point(q)[1] * delta_1;
186
187 points.emplace_back(x);
188 }
189
190 return points;
191 }
192 else // Point at the inner boundary lies somewhere in the face of the outer
193 // boundary cell
194 {
195 // Location of the vertices of the inner and outer cells in the real space
196 // rad_0: first cell vertex
197 // rad_1: intersection between the cell of the opposite interface side
198 // into the cell of the current interface side
199 // rad_2: last cell vertex
200 // This is an example for the case where the current cell is the outside
201 // cell
202 // |----------| outside cell
203 // rad0 rad2
204 // |----------| inside cell
205 // rad1
206
207 double rad_0, rad_1, rad_2;
208 // Minimum rotation angle between two vertices in the rotor and stator
209 // sides (if rot_min=0, the meshes are aligned)
210 double rot_min =
211 rotation_angle - std::floor(rotation_angle / delta_0) * delta_0;
212
213 if (type == 2) // outside
214 {
215 rad_0 = id_in_plane * delta_0;
216 rad_1 = id_in_plane * delta_0 + rot_min;
217 rad_2 = (id_in_plane + 1) * delta_0;
218 }
219 else // inside
220 {
221 rad_0 = id_in_plane * delta_0 + rot_min;
222 rad_1 = (id_in_plane + 1) * delta_0;
223 rad_2 = (id_in_plane + 1) * delta_0 + rot_min;
224 }
225
226 std::vector<Point<dim>> points;
227
228 // Store points for the segment rad_0 to rad_1
229 for (unsigned int q = 0; q < n_quadrature_points; ++q)
230 {
231 // Convert quadrature point in reference space to real space
232 Point<dim> x =
233 from_1D(rad_0 + quadrature.point(q)[0] * (rad_1 - rad_0));
234
235 if constexpr (dim == 3)
236 x[this->rotation_axis_direction] =
237 stage_heights[id_out_plane] + quadrature.point(q)[1] * delta_1;
238
239 points.emplace_back(x);
240 }
241
242 // Store points for the segment rad_1 to rad_2
243 for (unsigned int q = 0; q < n_quadrature_points; ++q)
244 {
245 // Convert quadrature point in reference space to real space
246 Point<dim> x =
247 from_1D(rad_1 + quadrature.point(q)[0] * (rad_2 - rad_1));
248
249 if constexpr (dim == 3)
250 x[this->rotation_axis_direction] =
251 stage_heights[id_out_plane] + quadrature.point(q)[1] * delta_1;
252
253 points.emplace_back(x);
254 }
255
256 return points;
257 }
258}
259
260template <int dim>
261std::vector<Point<std::max(1, dim - 1)>>
262MortarManagerBase<dim>::get_points_ref(const Point<dim> &face_center,
263 const bool is_inner) const
264{
265 if (dim == 1)
266 return std::vector<Point<std::max(1, dim - 1)>>{
267 Point<std::max(1, dim - 1)>()};
268
269 // Mesh alignment
270 const auto [type, _, __] = get_config(face_center, is_inner);
271 // Angle span of each cell (in radians)
272 const double delta_0 = 2 * numbers::PI / n_subdivisions[0];
273
274 if (type == 0) // aligned
275 {
276 std::vector<Point<std::max(1, dim - 1)>> points;
277 points.reserve(n_quadrature_points);
278
279 for (unsigned int q = 0; q < n_quadrature_points; ++q)
280 points.emplace_back(quadrature.point(q));
281
282 return points;
283 }
284 else // inside/outside
285 {
286 // Location of the vertices of the inner and outer cells in the reference
287 // space
288 // rad_0: first cell vertex
289 // rad_1: intersection between the cell of the opposite interface side
290 // into the cell of the current interface side
291 // rad_2: last cell vertex
292 double rad_0, rad_1, rad_2;
293 // Minimum rotation angle
294 double rot_min =
295 (rotation_angle - std::floor(rotation_angle / delta_0) * delta_0) /
296 delta_0;
297
298 if (type == 2) // outside
299 {
300 rad_0 = 0.0;
301 rad_1 = rot_min;
302 rad_2 = 1.0;
303 }
304 else // inside
305 {
306 rad_0 = 0.0;
307 rad_1 = 1.0 - rot_min;
308 rad_2 = 1.0;
309 }
310
311 std::vector<Point<std::max(1, dim - 1)>> points;
312 points.reserve(2 * n_quadrature_points);
313
314 // Store points for the segment rad_0 to rad_1
315 for (unsigned int q = 0; q < n_quadrature_points; ++q)
316 {
317 const double x = rad_0 + quadrature.point(q)[0] * (rad_1 - rad_0);
318
319 if (dim == 2)
320 points.emplace_back(x);
321 else
322 points.emplace_back(x, quadrature.point(q)[1]);
323 }
324
325 // Store points for the segment rad_1 to rad_2
326 for (unsigned int q = 0; q < n_quadrature_points; ++q)
327 {
328 const double x = rad_1 + quadrature.point(q)[0] * (rad_2 - rad_1);
329
330 if (dim == 2)
331 points.emplace_back(x);
332 else
333 points.emplace_back(x, quadrature.point(q)[1]);
334 }
335
336 return points;
337 }
338}
339
340template <int dim>
341std::vector<double>
342MortarManagerBase<dim>::get_weights(const Point<dim> &face_center,
343 const bool is_inner) const
344{
345 if (dim == 1)
346 return std::vector<double>{1.0};
347
348 // Mesh alignment type and cell index
349 const auto [type, id_in_plane, id_out_plane] =
350 get_config(face_center, is_inner);
351 // Angle span of each cell (in radians)
352 const double delta_0 = 2 * numbers::PI / n_subdivisions[0];
353 double delta_1 = 1.0;
354
355 if (dim == 3)
356 delta_1 = stage_heights[id_out_plane + 1] - stage_heights[id_out_plane];
357
358 if (type == 0) // aligned
359 {
360 std::vector<double> weights;
361 weights.reserve(n_quadrature_points);
362
363 // Mapping weight of the quadrature points from the reference space to the
364 // real space, where the Jacobian is given by the product between the
365 // angular length of the cell in the plane perpendicular to the rotation
366 // axis (radius * delta_0) and the height of the cell in the direction of
367 // the rotation axis (delta_1)
368 for (unsigned int q = 0; q < n_quadrature_points; ++q)
369 weights.emplace_back(interface_dimensions[0] * quadrature.weight(q) *
370 delta_0 * delta_1);
371
372 return weights;
373 }
374 else // inside/outside
375 {
376 // Location of the vertices of the inner and outer cells in the reference
377 // space
378 // rad_0: first cell vertex
379 // rad_1: intersection between the cell of the opposite interface side
380 // into the cell of the current interface side
381 // rad_2: last cell vertex
382 double rad_0, rad_1, rad_2;
383
384 double rot_min =
385 rotation_angle - std::floor(rotation_angle / delta_0) * delta_0;
386
387 if (type == 2) // outside
388 {
389 rad_0 = id_in_plane * delta_0;
390 rad_1 = id_in_plane * delta_0 + rot_min;
391 rad_2 = (id_in_plane + 1) * delta_0;
392 }
393 else // inside
394 {
395 rad_0 = id_in_plane * delta_0 + rot_min;
396 rad_1 = (id_in_plane + 1) * delta_0;
397 rad_2 = (id_in_plane + 1) * delta_0 + rot_min;
398 }
399
400 // Store weights for both segments, mapping the quadrature points from the
401 // reference space to the real space (same logic as in the aigned case)
402 std::vector<double> weights;
403 weights.reserve(2 * n_quadrature_points);
404
405 // Store weights for the segment rad_0 to rad_1
406 for (unsigned int q = 0; q < n_quadrature_points; ++q)
407 weights.emplace_back(interface_dimensions[0] * quadrature.weight(q) *
408 (rad_1 - rad_0) * delta_1);
409
410 // Store weights for the segment rad_1 to rad_2
411 for (unsigned int q = 0; q < n_quadrature_points; ++q)
412 weights.emplace_back(interface_dimensions[0] * quadrature.weight(q) *
413 (rad_2 - rad_1) * delta_1);
414
415 return weights;
416 }
417}
418
419template <int dim>
420std::vector<Tensor<1, dim, double>>
421MortarManagerBase<dim>::get_normals(const Point<dim> &face_center,
422 const bool is_inner) const
423{
424 // Coordinates of cell quadrature points in the real space
425 const auto points = get_points(face_center, is_inner);
426
427 std::vector<Tensor<1, dim, double>> result;
428
429 result.reserve(points.size());
430
431 for (const auto &point : points)
432 result.emplace_back(get_normal(point));
433
434 return result;
435}
436
437template <int dim>
438std::tuple<unsigned int, unsigned int, unsigned int>
439MortarManagerBase<dim>::get_config(const Point<dim> &face_center,
440 const bool is_inner) const
441{
442 const auto angle_cell_center = to_1D(face_center);
443
444 // Angular variation in each cell
445 const double delta_0 = 2 * numbers::PI / n_subdivisions[0];
446 // Minimum rotation angle
447 const double rot_min =
448 rotation_angle - std::floor(rotation_angle / delta_0) * delta_0;
449
450 AssertThrow(rot_min <= delta_0, ExcInternalError());
451
452 // Point position in the cell
453 const double segment = (angle_cell_center - delta_0 / 2) / delta_0;
454 // Point position after rotation
455 const double segment_rot =
456 (angle_cell_center - delta_0 / 2 - rot_min) / delta_0;
457 // Cell index in the direction of the rotation axis
458 unsigned int id_out_plane = 0;
459
460 if constexpr (dim == 3)
461 {
462 // Return the iterator of the first element in stage_heights that is
463 // greater than the face center height
464 auto upper_height_iterator =
465 std::upper_bound(stage_heights.begin(),
466 stage_heights.end(),
467 face_center[this->rotation_axis_direction]);
468 // The id_out_plane of the cell can be obtained with the distance between
469 // the iterator obtained and the lowest stage height iterator
470 id_out_plane =
471 std::distance(stage_heights.begin(), upper_height_iterator) - 1;
472 }
473
474 if (this->is_mesh_aligned())
475 {
476 // Case 1: mesh is aligned
477 return {0, static_cast<unsigned int>(std::round(segment)), id_out_plane};
478 }
479 else
480 {
481 // Case 2: mesh is not aligned
482 if (!is_inner)
483 // outer (fixed) domain
484 return {2,
485 static_cast<unsigned int>(std::round(segment)),
486 id_out_plane};
487 else
488 // inner (rotated) domain
489 return {1,
490 (static_cast<unsigned int>(std::round(segment_rot)) +
491 2 * n_subdivisions[0]) %
492 (2 * n_subdivisions[0]),
493 id_out_plane};
494 }
495}
496
497
498/*-------------- Auxiliary Functions -------------------------------*/
499template <int dim>
500std::vector<unsigned int>
501compute_number_interface_cells(const Triangulation<dim> &triangulation,
502 const Parameters::Mortar<dim> &mortar_parameters)
503{
504 // Number of subdivisions per process
505 unsigned int n_subdivisions_local = 0;
506 // Number of subdivisions in the radial direction per process
507 unsigned int n_subdivisions_plane_local = 0;
508 // Tolerance for rotor radius computation
509 const double radius_tolerance = mortar_parameters.radius_tolerance;
510 // Direction of the rotation axis
511 const unsigned int rotation_axis_direction =
512 mortar_parameters.rotation_axis_direction;
513
514 // Coordinate of the reference cell for computation of the number of
515 // subdivisions in the radial direction. Used in 3D case
516 double coord_ref_local = std::numeric_limits<double>::max();
517
518 if constexpr (dim == 3)
519 {
520 // To compute the number of subdivisions in the radial direction, we will
521 // use a reference cell. Its coordinate in the direction of the rotation
522 // axis is stored; then, all the cells at the same plane will be counted
523 // as an "in-plane" (radial direction) subdivision
524 for (const auto &cell : triangulation.active_cell_iterators())
525 {
526 if (cell->is_locally_owned())
527 {
528 for (const auto face_no : cell->face_indices())
529 {
530 const auto face = cell->face(face_no);
531
532 if (face->at_boundary() &&
533 face->boundary_id() ==
534 mortar_parameters.rotor_boundary_id)
535 coord_ref_local =
536 std::min(coord_ref_local,
537 cell->center()[rotation_axis_direction]);
538 }
539 }
540 }
541 }
542
543 // Coordinate of reference cell at all processes
544 const double coord_ref =
545 Utilities::MPI::min(coord_ref_local, triangulation.get_mpi_communicator());
546
547 // Check number of faces and vertices at the rotor-stator interface
548 for (const auto &cell : triangulation.active_cell_iterators())
549 {
550 if (cell->is_locally_owned())
551 {
552 for (const auto face_no : cell->face_indices())
553 {
554 const auto face = cell->face(face_no);
555
556 if (face->at_boundary())
557 {
558 if (face->boundary_id() ==
559 mortar_parameters.rotor_boundary_id)
560 {
561 n_subdivisions_local++;
562
563 // Store the number of subdivisions in the radial
564 // direction
565 if constexpr (dim == 3)
566 {
567 // Check if the current cell is contained in the same
568 // plane as the reference cell
569 if (std::abs(cell->center()[rotation_axis_direction] -
570 coord_ref) < radius_tolerance)
571 n_subdivisions_plane_local++;
572 }
573 else
574 n_subdivisions_plane_local++;
575 }
576 }
577 }
578 }
579 }
580
581 // Total number of faces
582 const unsigned int n_subdivisions =
583 Utilities::MPI::sum(n_subdivisions_local,
584 triangulation.get_mpi_communicator());
585
586 // Total number of faces at the radial direction
587 const unsigned int n_subdivisions_plane =
588 Utilities::MPI::sum(n_subdivisions_plane_local,
589 triangulation.get_mpi_communicator());
590
591 return {n_subdivisions_plane, n_subdivisions / n_subdivisions_plane};
592}
593
594template <int dim>
595std::tuple<std::vector<double>, double>
597 const Triangulation<dim> &triangulation,
598 const Mapping<dim> &mapping,
599 const Parameters::Mortar<dim> &mortar_parameters)
600{
601 // Tolerance for rotor radius computation
602 const double radius_tolerance = mortar_parameters.radius_tolerance;
603 // Min and max values for rotor radius computation
604 double radius_min = std::numeric_limits<double>::max();
605 double radius_max = 0;
606 // Minimum rotation angle in initial mesh configuration
607 double pre_rotation_min = std::numeric_limits<double>::max();
608
609 // Direction of the rotation axis
610 const unsigned int rotation_axis_direction =
611 mortar_parameters.rotation_axis_direction;
612 // Create rotation axis vector for distance computation in 3D cases
613 Tensor<1, dim> rotation_axis;
614 if constexpr (dim == 3)
615 rotation_axis[rotation_axis_direction] = 1.0;
616
617 // Min and max vertex coordinates for length computation in the axial
618 // direction. Used in 3D cases
619 double vertex_min = std::numeric_limits<double>::max();
620 double vertex_max = std::numeric_limits<double>::lowest();
621
622 // Check number of faces and vertices at the rotor-stator interface
623 for (const auto &cell : triangulation.active_cell_iterators())
624 {
625 if (cell->is_locally_owned())
626 {
627 for (const auto face_no : cell->face_indices())
628 {
629 const auto face = cell->face(face_no);
630
631 if (face->at_boundary())
632 {
633 if (face->boundary_id() ==
634 mortar_parameters.rotor_boundary_id)
635 {
636 const auto vertices = mapping.get_vertices(cell, face_no);
637
638 for (unsigned int vertex_index = 0;
639 vertex_index < face->n_vertices();
640 vertex_index++)
641 {
642 const auto v = vertices[vertex_index];
643 double radius_current =
644 v.distance(mortar_parameters.center_of_rotation);
645
646 // In 3D, the interface radius is computed as the
647 // minimum distance between the current vertex and the
648 // rotation axis, assuming that the center of rotation
649 // point is contained within the rotation axis line
650 if constexpr (dim == 3)
651 {
652 vertex_min = std::min(vertex_min,
653 v[rotation_axis_direction]);
654 vertex_max = std::max(vertex_max,
655 v[rotation_axis_direction]);
656
657 radius_current =
659 mortar_parameters.center_of_rotation,
660 rotation_axis,
661 v);
662 }
663
664 radius_min = std::min(radius_min, radius_current);
665 radius_max = std::max(radius_max, radius_current);
666 }
667 }
668 // Obtain the minimum initial rotation angle based on the
669 // stator interface
670 else if (face->boundary_id() ==
671 mortar_parameters.stator_boundary_id)
672 {
673 const auto vertices = mapping.get_vertices(cell, face_no);
674
675 for (unsigned int vertex_index = 0;
676 vertex_index < face->n_vertices();
677 vertex_index++)
678 {
679 const auto v = vertices[vertex_index];
680
681 pre_rotation_min = std::min(
682 pre_rotation_min,
684 mortar_parameters.center_of_rotation,
685 rotation_axis_direction));
686 }
687 }
688 }
689 }
690 }
691 }
692
693 // Min and max values over all processes
694 radius_min =
695 Utilities::MPI::min(radius_min, triangulation.get_mpi_communicator());
696 radius_max =
697 Utilities::MPI::max(radius_max, triangulation.get_mpi_communicator());
698
699 pre_rotation_min =
700 Utilities::MPI::min(pre_rotation_min, triangulation.get_mpi_communicator());
701
702 vertex_min =
703 Utilities::MPI::min(vertex_min, triangulation.get_mpi_communicator());
704 vertex_max =
705 Utilities::MPI::max(vertex_max, triangulation.get_mpi_communicator());
706
707 // Radius variation
708 const auto radius_diff = std::abs(radius_max - radius_min);
709
710 // Check if variation is withing the prescribed tolerance
711 AssertThrow(radius_diff < radius_tolerance,
712 InterfaceRadiusTolerance(radius_diff));
713
714 // Final radius value
715 const double radius = radius_min;
716 // Length along the axial direction
717 const double length_rot_axis = dim == 3 ? vertex_max - vertex_min : 0;
718
719 return {{radius, length_rot_axis}, pre_rotation_min};
720}
721
722template <int dim>
723std::pair<double, double>
725 const Triangulation<dim> &triangulation,
726 const Mapping<dim> &mapping,
727 const Parameters::Mortar<dim> &mortar_parameters)
728{
729 // y coordinates of the interface limits
730 // We assume that the mortar interface is always parallel to the y axis
731 double coord_min = std::numeric_limits<double>::max();
732 double coord_max = 0;
733
734 for (const auto &cell : triangulation.active_cell_iterators())
735 {
736 if (cell->is_locally_owned())
737 {
738 for (const auto face_no : cell->face_indices())
739 {
740 const auto face = cell->face(face_no);
741
742 if (face->at_boundary())
743 {
744 if (face->boundary_id() ==
745 mortar_parameters.rotor_boundary_id)
746 {
747 const auto vertices = mapping.get_vertices(cell, face_no);
748
749 for (unsigned int vertex_index = 0;
750 vertex_index < face->n_vertices();
751 vertex_index++)
752 {
753 const auto v = vertices[vertex_index];
754 coord_min = std::min(coord_min, v[1]);
755 coord_max = std::max(coord_max, v[1]);
756 }
757 }
758 }
759 }
760 }
761 }
762
763 // Min and max values over all processes
764 coord_min =
765 Utilities::MPI::min(coord_min, triangulation.get_mpi_communicator());
766 coord_max =
767 Utilities::MPI::max(coord_max, triangulation.get_mpi_communicator());
768
769 return {coord_min, coord_max};
770}
771
772template <int dim>
773Quadrature<dim>
774construct_quadrature(const Quadrature<dim> &quadrature,
775 const Parameters::Mortar<dim> &mortar_parameters)
776{
777 const int oversampling_factor =
778 static_cast<int>(mortar_parameters.oversampling_factor);
779
780 for (unsigned int i = 1; i <= 10; ++i)
781 if (quadrature == QGauss<dim>(i))
782 return QGauss<dim>(i * oversampling_factor);
783
784 AssertThrow(false, ExcNotImplemented());
785
786 return quadrature;
787}
788
789template <int dim>
790std::vector<double>
791compute_stage_heights(const Triangulation<dim> &triangulation,
792 const Parameters::Mortar<dim> &mortar_parameters)
793{
794 if constexpr (dim == 3)
795 {
796 // Direction of the rotation axis
797 const unsigned int rotation_axis_direction =
798 mortar_parameters.rotation_axis_direction;
799 // Container storing all vertex coordinates in the rotation axis direction
800 // for the local cells at the mortar boundary
801 std::vector<double> stage_heights_local;
802 // Smallest mortar cell face diameter, used to set the tolerance for
803 // height comparison
804 double minimum_face_diameter_local = std::numeric_limits<double>::max();
805
806 // Loop over the cells to store the vertex coordinates in the rotation
807 // axis direction
808 for (const auto &cell : triangulation.active_cell_iterators())
809 {
810 if (cell->is_locally_owned())
811 {
812 for (const auto face_no : cell->face_indices())
813 {
814 const auto face = cell->face(face_no);
815
816 // Check if the face is at the boundary and belongs to the
817 // stator boundary
818 // The choice of the stator boundary is arbitrary
819 if (face->at_boundary() &&
820 face->boundary_id() ==
821 mortar_parameters.stator_boundary_id)
822 {
823 minimum_face_diameter_local =
824 std::min(minimum_face_diameter_local, face->diameter());
825
826 for (const auto vertex_no : face->vertex_indices())
827 stage_heights_local.push_back(
828 face->vertex(vertex_no)[rotation_axis_direction]);
829 }
830 }
831 }
832 }
833 // Set the minimum face size over all processes
834 double minimum_face_diameter =
835 Utilities::MPI::min(minimum_face_diameter_local,
836 triangulation.get_mpi_communicator());
837
838 // Store the vertex coordinates in the rotation axis direction from all
839 // processes
840 const auto stage_heights_all =
841 Utilities::MPI::all_gather(triangulation.get_mpi_communicator(),
842 stage_heights_local);
843 std::vector<double> stage_heights;
844 for (const auto &heights_per_process : stage_heights_all)
845 stage_heights.insert(stage_heights.end(),
846 heights_per_process.begin(),
847 heights_per_process.end());
848
849 // Set the tolerance for height comparison based on the minimum face size
850 const double height_tolerance = minimum_face_diameter * 1e-8;
851
852 // Remove duplicate heights within the specified tolerance
853 std::ranges::sort(stage_heights);
854 auto result =
855 std::ranges::unique(stage_heights,
856 [height_tolerance](const double a, const double b) {
857 return std::abs(a - b) <= height_tolerance;
858 });
859 stage_heights.erase(result.begin(), result.end());
860
861 return stage_heights;
862 }
863 else
864 return {0.0};
865}
866
867template <int dim>
868void
869mortar_workload_imbalance(const Triangulation<dim> &triangulation,
870 const Parameters::Mortar<dim> &mortar_parameters,
871 const ConditionalOStream &pcout)
872{
873 unsigned int n_mortar_cells = 0;
874
875 // Identify number of cells in each process (local workload)
876 for (const auto &cell : triangulation.active_cell_iterators())
877 if (cell->is_locally_owned())
878 for (const auto face_no : cell->face_indices())
879 {
880 const auto face = cell->face(face_no);
881
882 if (face->at_boundary() &&
883 (face->boundary_id() == mortar_parameters.rotor_boundary_id ||
884 face->boundary_id() == mortar_parameters.stator_boundary_id))
885 ++n_mortar_cells;
886 }
887
888 // Compute minimum, maximum, and summation of cells over all processes
889 const auto [n_mortar_cells_sum,
890 n_mortar_cells_min,
891 n_mortar_cells_max,
892 _,
893 __,
894 ___] =
895 Utilities::MPI::min_max_avg(n_mortar_cells,
896 triangulation.get_mpi_communicator());
897
898 const unsigned int n_proc =
899 Utilities::MPI::n_mpi_processes(triangulation.get_mpi_communicator());
900
901 // Ideal work: same number of cells per process
902 const double ideal_work = n_mortar_cells_sum / static_cast<double>(n_proc);
903
904 // Workload imbalance (the closest to 1.0, the better)
905 const double workload_imbalance = n_mortar_cells_max / ideal_work;
906
907 pcout << "Workload imbalance: " << workload_imbalance << std::endl;
908 pcout << std::defaultfloat;
909 pcout << "Number of cells per process - Min.: " << n_mortar_cells_min
910 << std::endl;
911 pcout << " Max.: " << n_mortar_cells_max
912 << std::endl;
913 pcout << std::scientific;
914}
915
916/*-------------- MortarManagerCircle -------------------------------*/
917template <int dim>
918Point<dim>
919MortarManagerCircle<dim>::from_1D(const double angle_rad) const
920{
922 angle_rad + pre_rotation_angle,
923 this->center_of_rotation,
925}
926
927template <int dim>
928double
929MortarManagerCircle<dim>::to_1D(const Point<dim> &point) const
930{
931 return std::fmod(point_to_angle(point,
932 this->center_of_rotation,
934 pre_rotation_angle + 2 * numbers::PI,
935 2 * numbers::PI);
936}
937
938template <int dim>
939Tensor<1, dim, double>
940MortarManagerCircle<dim>::get_normal(const Point<dim> &point) const
941{
942 Tensor<1, dim, double> radial = point - this->center_of_rotation;
943 if constexpr (dim == 3)
944 radial[this->rotation_axis_direction] = 0.0;
945
946 return radial / radial.norm();
947}
948
949
950/*-------------- MortarManagerLinear -------------------------------*/
951template <int dim>
952Point<dim>
953MortarManagerLinear<dim>::from_1D(const double angle_rad) const
954{
955 return Point<dim>(0.5,
956 angle_rad / (2.0 * numbers::PI) * (coord_max - coord_min) +
957 coord_min);
958}
959
960template <int dim>
961double
962MortarManagerLinear<dim>::to_1D(const Point<dim> &point) const
963{
964 return (2.0 * numbers::PI) * (point[1] - coord_min) / (coord_max - coord_min);
965}
966
967template <int dim>
968Tensor<1, dim, double>
970{
971 return Point<dim>(1.0, 0.0);
972}
973
974/*-------------- CouplingOperator -------------------------------*/
975template <int dim, typename Number>
977 const Mapping<dim> &mapping,
978 const DoFHandler<dim> &dof_handler,
979 const AffineConstraints<Number> &constraints,
980 const std::shared_ptr<CouplingEvaluationBase<dim, Number>> &evaluator,
981 const std::shared_ptr<MortarManagerBase<dim>> &mortar_manager,
982 const unsigned int bid_m,
983 const unsigned int bid_p,
984 const double sip_factor)
987 , bid_m(bid_m)
988 , bid_p(bid_p)
991{
992 this->q_data_size = evaluator->data_size();
993 this->relevant_dof_indices = evaluator->get_relevant_dof_indices();
994 this->n_dofs_per_cell = this->relevant_dof_indices.size();
995
996 data.penalty_factor =
997 compute_penalty_factor(dof_handler.get_fe().degree, sip_factor);
998
999 // Number of cells
1000 const unsigned int n_sub_cells = mortar_manager->get_n_total_mortars();
1001
1002 std::vector<types::global_dof_index> is_local_cell;
1003 std::vector<types::global_dof_index> is_ghost_cell;
1004
1005#ifdef DEBUG
1006 std::vector<double> vec_local_cells(n_sub_cells * 2, 0.0);
1007 std::vector<double> vec_ghost_cells(n_sub_cells * 2, 0.0);
1008#endif
1009
1010 for (const auto &cell : dof_handler.active_cell_iterators())
1011 if (cell->is_locally_owned())
1012 for (const auto face_no : cell->face_indices())
1013 if ((cell->face(face_no)->boundary_id() == bid_m) ||
1014 (cell->face(face_no)->boundary_id() == bid_p))
1015 {
1016 const auto face = cell->face(face_no);
1017
1018 const auto center = get_face_center(cell, face);
1019
1020 // Indices of mortars on face of cell.
1021 const auto indices = mortar_manager->get_mortar_indices(
1022 center, cell->face(face_no)->boundary_id() == bid_m);
1023
1024 const auto local_dofs = this->get_dof_indices(cell);
1025
1026 // Loop over the mortar indices at the rotor-stator
1027 // interface. The logic of local (rotor) and ghost (stator) is the
1028 // same as in the previous loop.
1029 for (unsigned int ii = 0; ii < indices.size(); ++ii)
1030 {
1031 const unsigned int i = indices[ii];
1032 unsigned int id_local = 0, id_ghost = 0;
1033
1034 if (face->boundary_id() == bid_m)
1035 {
1036 id_local = i;
1037 id_ghost = i + n_sub_cells;
1038 }
1039 else if (face->boundary_id() == bid_p)
1040 {
1041 id_local = i + n_sub_cells;
1042 id_ghost = i;
1043 }
1044
1045#ifdef DEBUG
1046 vec_local_cells[id_local] += 1.0;
1047 vec_ghost_cells[id_ghost] += 1.0;
1048#endif
1049 is_local_cell.emplace_back(id_local);
1050 is_ghost_cell.emplace_back(id_ghost);
1051
1052 for (const auto l_dof : local_dofs)
1053 dof_indices.emplace_back(l_dof);
1054 }
1055
1056 // Weights of quadrature points
1057 const auto weights =
1058 mortar_manager->get_weights(get_face_center(cell, face),
1059 cell->face(face_no)->boundary_id() ==
1060 bid_m);
1061 data.all_weights.insert(data.all_weights.end(),
1062 weights.begin(),
1063 weights.end());
1064
1065 // Normals of quadrature points
1066 if constexpr (dim == 3)
1067 {
1068 const auto points = mortar_manager->get_points(
1069 get_face_center(cell, face),
1070 cell->face(face_no)->boundary_id() == bid_m);
1071 std::vector<Point<dim, Number>> points_ref(points.size());
1072 mapping.transform_points_real_to_unit_cell(cell,
1073 points,
1074 points_ref);
1075 all_points_ref.insert(all_points_ref.end(),
1076 points_ref.begin(),
1077 points_ref.end());
1078
1079 std::vector<Point<dim - 1>> quad;
1080
1081 for (const auto &p : points_ref)
1082 {
1083 Point<dim - 1> temp;
1084 // Axis perpendicular to the current face in the reference
1085 // cell
1086 const unsigned int axis = face_no / 2;
1087
1088 // 'temp' stores the coordinates of the quadrature point
1089 // on the face, hence the loop over the remaining 2 axes of
1090 // the reference cell
1091 for (int t = 0; t < dim - 1; ++t)
1092 temp[t] = p[(axis + 1 + t) % dim];
1093
1094 quad.emplace_back(temp);
1095 }
1096
1097 FEFaceValues<dim> fe_face_values(mapping,
1098 cell->get_fe(),
1099 quad,
1100 update_normal_vectors);
1101
1102 fe_face_values.reinit(cell, face_no);
1103
1104 data.all_normals.insert(
1105 data.all_normals.end(),
1106 fe_face_values.get_normal_vectors().begin(),
1107 fe_face_values.get_normal_vectors().end());
1108 }
1109 else
1110 {
1111 auto normals = mortar_manager->get_normals(
1112 get_face_center(cell, face),
1113 cell->face(face_no)->boundary_id() == bid_m);
1114 // Invert normal vector orientation when the face is in the
1115 // "positive" domain
1116 if (face->boundary_id() == bid_p)
1117 for (auto &normal : normals)
1118 normal *= -1.0;
1119 data.all_normals.insert(data.all_normals.end(),
1120 normals.begin(),
1121 normals.end());
1122
1123 if constexpr (dim == 1)
1124 {
1125 if (face_no == 0)
1126 all_points_ref.emplace_back(0.0);
1127 else if (face_no == 1)
1128 all_points_ref.emplace_back(1.0);
1129 else
1130 AssertThrow(false, ExcNotImplemented());
1131 }
1132 else if constexpr (dim == 2)
1133 {
1134 auto points = mortar_manager->get_points_ref(
1135 get_face_center(cell, face),
1136 cell->face(face_no)->boundary_id() == bid_m);
1137
1138 // Verify the orientation of the face vertices (clockwise vs
1139 // counter-clockwise)
1140 const bool flip =
1141 (face->vertex(0)[0] * face->vertex(1)[1] -
1142 face->vertex(0)[1] * face->vertex(1)[0]) < 0.0;
1143
1144 // For consistency, flip orientation of quadrature points if
1145 // clockwise
1146 if (flip)
1147 for (auto &p : points)
1148 p[0] = 1.0 - p[0];
1149
1150 if (face_no / 2 == 0)
1151 {
1152 for (auto &p : points)
1153 all_points_ref.emplace_back(face_no % 2, p[0]);
1154 }
1155 else if (face_no / 2 == 1)
1156 {
1157 for (auto &p : points)
1158 all_points_ref.emplace_back(p[0], face_no % 2);
1159 }
1160 else
1161 {
1162 AssertThrow(false, ExcNotImplemented());
1163 }
1164 }
1165 else if constexpr (dim == 3)
1166 {
1167 AssertThrow(false, ExcNotImplemented()); // TODO
1168 }
1169 else
1170 AssertThrow(false, ExcNotImplemented());
1171 }
1172
1173 // Penalty parameter
1174 const Number penalty_parameter = compute_penalty_parameter(cell);
1175
1176 // Store penalty parameter for all quadrature points
1177 for (unsigned int i = 0; i < mortar_manager->get_n_points(); ++i)
1178 data.all_penalty_parameter.emplace_back(penalty_parameter);
1179 }
1180
1181#ifdef DEBUG
1182 Utilities::MPI::sum(vec_local_cells,
1183 dof_handler.get_mpi_communicator(),
1184 vec_local_cells);
1185 Utilities::MPI::sum(vec_ghost_cells,
1186 dof_handler.get_mpi_communicator(),
1187 vec_ghost_cells);
1188
1189 std::set<unsigned int> vec_local_cells_0;
1190 std::set<unsigned int> vec_local_cells_2;
1191
1192 if (Utilities::MPI::this_mpi_process(dof_handler.get_mpi_communicator()) == 0)
1193 {
1194 for (unsigned int i = 0; i < vec_local_cells.size(); ++i)
1195 {
1196 if (vec_local_cells[i] == 0)
1197 vec_local_cells_0.insert(i);
1198 if (vec_local_cells[i] > 1)
1199 vec_local_cells_2.insert(i);
1200 }
1201
1202 std::set<unsigned int> vec_ghost_cells_0;
1203 std::set<unsigned int> vec_ghost_cells_2;
1204
1205 for (unsigned int i = 0; i < vec_ghost_cells.size(); ++i)
1206 {
1207 if (vec_ghost_cells[i] == 0)
1208 vec_ghost_cells_0.insert(i);
1209 if (vec_ghost_cells[i] > 1)
1210 vec_ghost_cells_2.insert(i);
1211 }
1212
1213 if (!(vec_local_cells_0.empty() && vec_local_cells_2.empty() &&
1214 vec_ghost_cells_0.empty() && vec_ghost_cells_2.empty()))
1215 {
1216 std::cout << "CouplingOperator mortar matching failed:" << std::endl;
1217
1218 if (!vec_local_cells_0.empty())
1219 {
1220 std::cout << " - some local cells are not owned: ";
1221 for (const auto &i : vec_local_cells_0)
1222 std::cout << i << " ";
1223 std::cout << std::endl;
1224 }
1225 if (!vec_local_cells_2.empty())
1226 {
1227 std::cout << " - some local cells are owned multiple times: ";
1228 for (const auto &i : vec_local_cells_2)
1229 std::cout << i << " ";
1230 std::cout << std::endl;
1231 }
1232 if (!vec_ghost_cells_0.empty())
1233 {
1234 std::cout << " - some ghost cells are not owned: ";
1235 for (const auto &i : vec_ghost_cells_0)
1236 std::cout << i << " ";
1237 std::cout << std::endl;
1238 }
1239 if (!vec_ghost_cells_2.empty())
1240 {
1241 std::cout << " - some ghost cells are owned multiple times: ";
1242 for (const auto &i : vec_ghost_cells_2)
1243 std::cout << i << " ";
1244 std::cout << std::endl;
1245 }
1246
1247 MPI_Barrier(dof_handler.get_mpi_communicator());
1248
1249 AssertThrow(false, ExcInternalError());
1250 }
1251 }
1252#endif
1253
1254 // Setup communication
1255 partitioner.reinit(is_local_cell,
1256 is_ghost_cell,
1257 dof_handler.get_mpi_communicator());
1258
1259 // Finalized penalty parameters
1260 const unsigned n_q_points =
1261 mortar_manager->get_n_points() / mortar_manager->get_n_mortars();
1262 std::vector<Number> all_penalty_parameter_ghost(
1263 data.all_penalty_parameter.size());
1264 partitioner.export_to_ghosted_array<Number, 0>(data.all_penalty_parameter,
1265 all_penalty_parameter_ghost,
1266 n_q_points);
1267 for (unsigned int i = 0; i < data.all_penalty_parameter.size(); ++i)
1268 data.all_penalty_parameter[i] =
1269 std::max(data.all_penalty_parameter[i], all_penalty_parameter_ghost[i]);
1270
1271 // Finalize DoF indices and update constraints
1272 dof_indices_ghost.resize(dof_indices.size());
1273 partitioner.export_to_ghosted_array<types::global_dof_index, 0>(
1275
1276 {
1277 auto locally_owned_dofs = constraints.get_locally_owned_indices();
1278 auto constraints_to_make_consistent = constraints.get_local_lines();
1279
1280
1281 for (unsigned int i = 0; i < dof_indices.size(); ++i)
1282 {
1283 constraints_to_make_consistent.add_index(dof_indices[i]);
1284 constraints_to_make_consistent.add_index(dof_indices_ghost[i]);
1285 }
1286
1287 constraints_extended.reinit(locally_owned_dofs,
1288 constraints_to_make_consistent);
1290 constraints,
1291 AffineConstraints<Number>::MergeConflictBehavior::no_conflicts_allowed,
1292 true);
1293
1294 constraints_extended.make_consistent_in_parallel(
1295 locally_owned_dofs,
1296 constraints_to_make_consistent,
1297 dof_handler.get_mpi_communicator());
1298
1299 partitioner_extended = std::make_shared<const Utilities::MPI::Partitioner>(
1300 locally_owned_dofs,
1301 constraints_extended.get_local_lines(),
1302 dof_handler.get_mpi_communicator());
1303 }
1304}
1305
1306template <int dim, typename Number>
1307const AffineConstraints<Number> &
1312
1313template <int dim, typename Number>
1314Number
1316 const Number factor)
1317{
1318 return factor * (degree + 1.0) * (degree + 1.0);
1319}
1320
1321template <int dim, typename Number>
1322Number
1324 const typename Triangulation<dim>::cell_iterator &cell) const
1325{
1326 const unsigned int degree = dof_handler.get_fe().degree;
1327
1328 FE_Nothing<dim> fe_nothing;
1329
1330 dealii::QGauss<dim> quadrature(degree + 1);
1331 dealii::FEValues<dim> fe_values(mapping,
1332 fe_nothing,
1333 quadrature,
1334 dealii::update_JxW_values);
1335
1336 dealii::QGauss<dim - 1> face_quadrature(degree + 1);
1337 dealii::FEFaceValues<dim> fe_face_values(mapping,
1338 fe_nothing,
1339 face_quadrature,
1340 dealii::update_JxW_values);
1341
1342 fe_values.reinit(cell);
1343
1344 Number volume = 0;
1345 for (unsigned int q = 0; q < quadrature.size(); ++q)
1346 volume += fe_values.JxW(q);
1347
1348 Number surface_area = 0;
1349 for (const auto f : cell->face_indices())
1350 {
1351 fe_face_values.reinit(cell, f);
1352
1353 const Number factor =
1354 (cell->at_boundary(f) && !cell->has_periodic_neighbor(f) &&
1355 (cell->face(f)->boundary_id() != bid_m &&
1356 cell->face(f)->boundary_id() != bid_p)) ?
1357 1. :
1358 0.5;
1359
1360 for (unsigned int q = 0; q < face_quadrature.size(); ++q)
1361 surface_area += fe_face_values.JxW(q) * factor;
1362 }
1363
1364 return surface_area / volume;
1365}
1366
1367template <int dim, typename Number>
1368Point<dim>
1370 const typename Triangulation<dim>::cell_iterator &cell,
1371 const typename Triangulation<dim>::face_iterator &face) const
1372{
1373 return mapping.transform_unit_to_real_cell(
1374 cell, MappingQ1<dim>().transform_real_to_unit_cell(cell, face->center()));
1375}
1376
1377template <int dim, typename Number>
1378std::vector<types::global_dof_index>
1380 const typename DoFHandler<dim>::active_cell_iterator &cell) const
1381{
1382 std::vector<types::global_dof_index> local_dofs_all(
1383 dof_handler.get_fe().n_dofs_per_cell());
1384 cell->get_dof_indices(local_dofs_all);
1385
1386 std::vector<types::global_dof_index> local_dofs(n_dofs_per_cell);
1387
1388 for (unsigned int i = 0; i < n_dofs_per_cell; ++i)
1389 local_dofs[i] = local_dofs_all[relevant_dof_indices[i]];
1390
1391 return local_dofs;
1392}
1393
1394template <int dim, typename Number>
1395template <typename VectorType>
1396void
1398 const VectorType &src) const
1399{
1400 VectorType dst_internal;
1401
1402 if constexpr (std::is_same_v<VectorType, TrilinosWrappers::MPI::Vector>)
1403 {
1404 dst_internal.reinit(this->partitioner_extended->locally_owned_range(),
1405 this->partitioner_extended->get_mpi_communicator());
1406 }
1407 else
1408 dst_internal.reinit(this->partitioner_extended);
1409
1410 VectorType src_internal;
1411 if constexpr (std::is_same_v<VectorType, TrilinosWrappers::MPI::Vector>)
1412 src_internal.reinit(this->partitioner_extended->locally_owned_range(),
1413 this->partitioner_extended->ghost_indices(),
1414 this->partitioner_extended->get_mpi_communicator());
1415 else
1416 src_internal.reinit(this->partitioner_extended);
1417 src_internal = src;
1418 src_internal.update_ghost_values();
1419
1420 // 1) Evaluate
1421 unsigned int ptr_q = 0;
1422
1423 Vector<Number> buffer;
1424
1425 std::vector<Number> all_values_local(data.all_normals.size() * q_data_size);
1426 std::vector<Number> all_values_ghost(data.all_normals.size() * q_data_size);
1427
1428 for (const auto &cell : dof_handler.active_cell_iterators())
1429 if (cell->is_locally_owned())
1430 for (const auto &face : cell->face_iterators())
1431 if ((face->boundary_id() == bid_m) || (face->boundary_id() == bid_p))
1432 {
1433 // Quadrature points at the current face. Note: we process
1434 // all mortars of the face together here.
1435 const unsigned int n_q_points = mortar_manager->get_n_points();
1436
1437 evaluator->local_reinit(
1438 cell,
1439 ArrayView<const Point<dim, Number>>(all_points_ref.data() + ptr_q,
1440 n_q_points));
1441
1442 buffer.reinit(n_dofs_per_cell);
1443
1444 const auto local_dofs = this->get_dof_indices(cell);
1445
1446 for (unsigned int i = 0; i < local_dofs.size(); ++i)
1447 buffer[i] = src_internal[local_dofs[i]];
1448
1449 evaluator->local_evaluate(data,
1450 buffer,
1451 ptr_q,
1452 1,
1453 all_values_local.data() +
1454 ptr_q * q_data_size);
1455
1456 ptr_q += n_q_points;
1457 }
1458
1459 // 2) Communicate
1460 const unsigned n_q_points =
1461 mortar_manager->get_n_points() / mortar_manager->get_n_mortars();
1462 partitioner.export_to_ghosted_array<Number, 0>(
1463 ArrayView<const Number>(reinterpret_cast<Number *>(all_values_local.data()),
1464 all_values_local.size()),
1465 ArrayView<Number>(reinterpret_cast<Number *>(all_values_ghost.data()),
1466 all_values_ghost.size()),
1467 n_q_points * q_data_size);
1468
1469 // 3) Integrate
1470 ptr_q = 0;
1471 for (const auto &cell : dof_handler.active_cell_iterators())
1472 if (cell->is_locally_owned())
1473 for (const auto &face : cell->face_iterators())
1474 if ((face->boundary_id() == bid_m) || (face->boundary_id() == bid_p))
1475 {
1476 // Quadrature points at the current face. Note: we process
1477 // all mortars of the face together here.
1478 const unsigned int total_n_q_points =
1479 mortar_manager->get_n_points();
1480
1481 evaluator->local_reinit(
1482 cell,
1483 ArrayView<const Point<dim, Number>>(all_points_ref.data() + ptr_q,
1484 total_n_q_points));
1485
1486 buffer.reinit(n_dofs_per_cell);
1487 evaluator->local_integrate(data,
1488 buffer,
1489 ptr_q,
1490 1,
1491 all_values_local.data() +
1492 ptr_q * q_data_size,
1493 all_values_ghost.data() +
1494 ptr_q * q_data_size);
1495
1496 const auto local_dofs = this->get_dof_indices(cell);
1497 constraints_extended.distribute_local_to_global(buffer,
1498 local_dofs,
1499 dst_internal);
1500
1501 ptr_q += total_n_q_points;
1502 }
1503
1504 dst_internal.compress(VectorOperation::add);
1505 dst.add(1.0, dst_internal);
1506}
1507
1508template <int dim, typename Number>
1509template <typename VectorType>
1510void
1512{
1513 VectorType diagonal_internal;
1514
1515 if constexpr (std::is_same_v<VectorType, TrilinosWrappers::MPI::Vector>)
1516 {
1517 diagonal_internal.reinit(
1518 this->partitioner_extended->locally_owned_range(),
1519 this->partitioner_extended->get_mpi_communicator());
1520 }
1521 else
1522 diagonal_internal.reinit(this->partitioner_extended);
1523
1524 unsigned int ptr_q = 0;
1525
1526 Vector<Number> buffer, diagonal_local;
1527 std::vector<Number> all_values_local, all_values_ghost;
1528
1529 for (const auto &cell : dof_handler.active_cell_iterators())
1530 if (cell->is_locally_owned())
1531 for (const auto &face : cell->face_iterators())
1532 if ((face->boundary_id() == bid_m) || (face->boundary_id() == bid_p))
1533 {
1534 // Quadrature points at the current face. Note: we process
1535 // all mortars of the face together here.
1536 const unsigned int n_q_points = mortar_manager->get_n_points();
1537
1538 evaluator->local_reinit(
1539 cell,
1540 ArrayView<const Point<dim, Number>>(all_points_ref.data() + ptr_q,
1541 n_q_points));
1542
1543 buffer.reinit(n_dofs_per_cell);
1544 diagonal_local.reinit(n_dofs_per_cell);
1545 all_values_local.resize(n_q_points * q_data_size);
1546 all_values_ghost.resize(n_q_points * q_data_size);
1547
1548 for (unsigned int i = 0; i < n_dofs_per_cell; ++i)
1549 {
1550 // Create i-th basis vector
1551 for (unsigned int j = 0; j < n_dofs_per_cell; ++j)
1552 buffer[j] = static_cast<Number>(i == j);
1553
1554 // Interpolate i-th basis vector to the quadrature points
1555 evaluator->local_evaluate(
1556 data, buffer, ptr_q, 1, all_values_local.data());
1557
1558 buffer.reinit(n_dofs_per_cell);
1559
1560 // integrate the coupling terms of the mortar using the
1561 // interpolated information from the cell
1562 evaluator->local_integrate(data,
1563 buffer,
1564 ptr_q,
1565 1,
1566 all_values_local.data(),
1567 all_values_ghost.data());
1568
1569 diagonal_local[i] = buffer[i];
1570 }
1571
1572 const auto local_dofs = this->get_dof_indices(cell);
1573 constraints_extended.distribute_local_to_global(diagonal_local,
1574 local_dofs,
1575 diagonal_internal);
1576
1577 ptr_q += n_q_points;
1578 }
1579
1580 diagonal_internal.compress(VectorOperation::add);
1581 diagonal.add(1.0, diagonal_internal);
1582}
1583
1584template <int dim, typename Number>
1585void
1587 SparsityPatternBase &dsp) const
1588{
1589 for (unsigned int i = 0; i < dof_indices.size(); i += n_dofs_per_cell)
1590 {
1591 std::vector<types::global_dof_index> a(dof_indices.begin() + i,
1592 dof_indices.begin() + i +
1594 std::vector<types::global_dof_index> b(dof_indices_ghost.begin() + i,
1595 dof_indices_ghost.begin() + i +
1597
1598 constraints_extended.add_entries_local_to_global(a, b, dsp);
1599 constraints_extended.add_entries_local_to_global(b, a, dsp);
1600 }
1601}
1602
1603template <int dim, typename Number>
1604void
1606 TrilinosWrappers::SparseMatrix &system_matrix) const
1607{
1608 std::vector<Number> all_values_local(data.all_normals.size() *
1610 std::vector<Number> all_values_ghost(data.all_normals.size() *
1612
1613 unsigned int ptr_q = 0;
1614
1615 Vector<Number> buffer;
1616
1617 // 1) Evaluate
1618 for (const auto &cell : dof_handler.active_cell_iterators())
1619 if (cell->is_locally_owned())
1620 for (const auto &face : cell->face_iterators())
1621 if ((face->boundary_id() == bid_m) || (face->boundary_id() == bid_p))
1622 {
1623 // Quadrature points at the current face. Note: we process
1624 // all mortars of the face together here.
1625 const unsigned int n_q_points = mortar_manager->get_n_points();
1626
1627 // Initialize coupling evaluator with the current cell and
1628 // the relevant quadrature points
1629 evaluator->local_reinit(
1630 cell,
1631 ArrayView<const Point<dim, Number>>(all_points_ref.data() + ptr_q,
1632 n_q_points));
1633
1634 // Initialize buffer to store information at dof level
1635 buffer.reinit(n_dofs_per_cell);
1636
1637 for (unsigned int i = 0; i < n_dofs_per_cell; ++i)
1638 {
1639 // Create i-th basis vector
1640 for (unsigned int j = 0; j < n_dofs_per_cell; ++j)
1641 buffer[j] = static_cast<Number>(i == j);
1642
1643 // Interpolate i-th basis vector to the quadrature points
1644 evaluator->local_evaluate(data,
1645 buffer,
1646 ptr_q,
1648 all_values_local.data() +
1649 (ptr_q * n_dofs_per_cell + i) *
1650 q_data_size);
1651 }
1652
1653 ptr_q += n_q_points;
1654 }
1655
1656 const unsigned n_q_points =
1657 mortar_manager->get_n_points() / mortar_manager->get_n_mortars();
1658
1659 // 2) Communicate: export data from local to ghost side
1660 partitioner.export_to_ghosted_array<Number, 0>(
1661 ArrayView<const Number>(reinterpret_cast<Number *>(all_values_local.data()),
1662 all_values_local.size()),
1663 ArrayView<Number>(reinterpret_cast<Number *>(all_values_ghost.data()),
1664 all_values_ghost.size()),
1665 n_dofs_per_cell * n_q_points * q_data_size);
1666
1667
1668 ptr_q = 0;
1669 unsigned int ptr_dofs = 0;
1670
1671 // 3) Integrate
1672 for (const auto &cell : dof_handler.active_cell_iterators())
1673 if (cell->is_locally_owned())
1674 for (const auto &face : cell->face_iterators())
1675 if ((face->boundary_id() == bid_m) || (face->boundary_id() == bid_p))
1676 {
1677 // Number of mortars attached to the current cell (i.e. 1 for
1678 // aligned rotor-stator meshes and 2 for non-aligned case)
1679 const unsigned int n_mortars = mortar_manager->get_n_mortars();
1680
1681 // Loop over mortars
1682 for (unsigned int m = 0; m < n_mortars; ++m)
1683 {
1684 evaluator->local_reinit(cell,
1685 ArrayView<const Point<dim, Number>>(
1686 all_points_ref.data() + ptr_q,
1687 n_q_points));
1688
1689 // Loop over local and ghost cells attached the mortar
1690 for (unsigned int b = 0; b < 2; ++b)
1691 {
1692 FullMatrix<Number> cell_matrix(n_dofs_per_cell,
1694
1695 // Loop over cell dofs and integrate the coupling terms of
1696 // the mortar using the interpolated information from the
1697 // cell
1698 for (unsigned int i = 0; i < n_dofs_per_cell; ++i)
1699 {
1700 buffer.reinit(n_dofs_per_cell);
1701 if (b == 0) // local cell
1702 evaluator->local_integrate(
1703 data,
1704 buffer,
1705 ptr_q,
1707 all_values_local.data() +
1708 (ptr_q * n_dofs_per_cell + i) * q_data_size,
1709 nullptr);
1710 else // ghost cell
1711 evaluator->local_integrate(
1712 data,
1713 buffer,
1714 ptr_q,
1716 nullptr,
1717 all_values_ghost.data() +
1718 (ptr_q * n_dofs_per_cell + i) * q_data_size);
1719
1720 // Copy data from buffer to cell matrix
1721 for (unsigned int j = 0; j < n_dofs_per_cell; ++j)
1722 cell_matrix[j][i] = buffer[j];
1723 }
1724
1725 // Vector of local dof indices from the cell in the negative
1726 // ('mortar') side
1727 std::vector<types::global_dof_index> local_dof_indices(
1728 dof_indices.begin() + ptr_dofs,
1729 dof_indices.begin() + ptr_dofs + n_dofs_per_cell);
1730
1731 if (b == 0) // local cell -> local-local block
1732 {
1733 constraints_extended.distribute_local_to_global(
1734 cell_matrix, local_dof_indices, system_matrix);
1735 }
1736 else // ghost cell -> local-ghost block
1737 {
1738 std::vector<types::global_dof_index>
1739 local_dof_indices_ghost(dof_indices_ghost.begin() +
1740 ptr_dofs,
1741 dof_indices_ghost.begin() +
1742 ptr_dofs + n_dofs_per_cell);
1743
1744 constraints_extended.distribute_local_to_global(
1745 cell_matrix,
1746 local_dof_indices,
1747 local_dof_indices_ghost,
1748 system_matrix);
1749 }
1750 }
1751
1752 ptr_dofs += n_dofs_per_cell;
1753
1754 ptr_q += n_q_points;
1755 }
1756 }
1757
1758 AssertDimension(ptr_q, data.all_normals.size());
1759 AssertDimension(ptr_dofs, dof_indices.size());
1760}
1761
1762
1763/*-------------- ScalarCouplingEvaluationSIPG -------------------------------*/
1764template <int dim, int n_components, typename Number>
1766 ScalarCouplingEvaluationSIPG(const Mapping<dim> &mapping,
1767 const DoFHandler<dim> &dof_handler,
1768 const unsigned int first_selected_component)
1769 : fe_sub(dof_handler.get_fe().base_element(
1770 dof_handler.get_fe()
1771 .component_to_base_index(first_selected_component)
1772 .first),
1773 n_components)
1774 , phi_m(mapping, fe_sub, update_values | update_gradients)
1775{
1776 for (unsigned int i = 0; i < dof_handler.get_fe().n_dofs_per_cell(); ++i)
1777 if ((first_selected_component <=
1778 dof_handler.get_fe().system_to_component_index(i).first) &&
1779 (dof_handler.get_fe().system_to_component_index(i).first <
1780 first_selected_component + n_components))
1781 relevant_dof_indices.push_back(i);
1782}
1783
1784template <int dim, int n_components, typename Number>
1785unsigned int
1787{
1788 return n_components * 2;
1789}
1790
1791template <int dim, int n_components, typename Number>
1792const std::vector<unsigned int> &
1798
1799template <int dim, int n_components, typename Number>
1800void
1802 const typename Triangulation<dim>::cell_iterator &cell,
1803 const ArrayView<const Point<dim, Number>> &points) const
1804{
1805 this->phi_m.reinit(cell, points);
1806}
1807
1808template <int dim, int n_components, typename Number>
1809void
1812 const Vector<Number> &buffer,
1813 const unsigned int ptr_q,
1814 const unsigned int q_stride,
1815 Number *all_values_m) const
1816{
1817 this->phi_m.evaluate(buffer,
1818 EvaluationFlags::values | EvaluationFlags::gradients);
1819
1820 for (const auto q : this->phi_m.quadrature_point_indices())
1821 {
1822 // Quadrature point index ('global' index within the rotor-stator
1823 // interface)
1824 const unsigned int q_index = ptr_q + q;
1825
1826 // Normal, value, and gradient referring to the quadrature point
1827 const auto normal = data.all_normals[q_index];
1828 const auto value_m = this->phi_m.get_value(q);
1829 const auto gradient_m = contract(this->phi_m.get_gradient(q), normal);
1830
1831 // Initialize buffer for 'negative' side of the interface (i.e. rotor),
1832 // where information is evaluated
1833 BufferRW<Number> buffer_m(all_values_m, q * 2 * n_components * q_stride);
1834 // Store values and gradients at the created buffer
1835 buffer_m.write(value_m);
1836 buffer_m.write(gradient_m);
1837 }
1838}
1839
1840template <int dim, int n_components, typename Number>
1841void
1844 Vector<Number> &buffer,
1845 const unsigned int ptr_q,
1846 const unsigned int q_stride,
1847 Number *all_values_m,
1848 Number *all_values_p) const
1849{
1850 for (const auto q : this->phi_m.quadrature_point_indices())
1851 {
1852 const unsigned int q_index = ptr_q + q;
1853 // Initialize buffer for both 'mortar' and 'non-mortar' sides of the
1854 // interface
1855 BufferRW<Number> buffer_m(all_values_m, q * 2 * n_components * q_stride);
1856 BufferRW<Number> buffer_p(all_values_p, q * 2 * n_components * q_stride);
1857 // Read shape functions values and gradients stored in the buffer
1858 const auto value_m = buffer_m.template read<value_type>();
1859 const auto value_p = buffer_p.template read<value_type>();
1860 const auto normal_gradient_m = buffer_m.template read<value_type>();
1861 const auto normal_gradient_p = buffer_p.template read<value_type>();
1862
1863 const auto JxW = data.all_weights[q_index];
1864 const auto penalty_parameter = data.all_penalty_parameter[q_index];
1865 const auto normal = data.all_normals[q_index];
1866
1867 // The expression for the jump on the mortar interface is
1868 // jump(u) = u_m * normal_m + u_p * normal_p. Since we are accessing only
1869 // the value of normal_m, we use a minus sign here because normal_p = -
1870 // normal_m
1871 const auto value_jump = outer((value_m - value_p), normal);
1872
1873 // The expression for the average on the mortar interface is
1874 // avg(∇u).n = (∇u_m.normal_m + ∇u_p.normal_p) * 0.5. For the same reason
1875 // above, we include the negative sign here
1876 const auto gradient_normal_avg =
1877 (normal_gradient_m - normal_gradient_p) * 0.5;
1878
1879 // SIPG penalty parameter
1880 const double sigma = penalty_parameter * data.penalty_factor;
1881
1882 // - (n avg(∇v), jump(u))
1883 this->phi_m.submit_gradient(-value_jump * 0.5 * JxW, q);
1884
1885 // + (jump(v), σ jump(u) - avg(∇u) n)
1886 this->phi_m.submit_value(
1887 (contract(value_jump, normal) * sigma - gradient_normal_avg) * JxW, q);
1888 }
1889 // Multiply previous terms by respective test functions values/gradients
1890 this->phi_m.test_and_sum(buffer,
1891 EvaluationFlags::values |
1892 EvaluationFlags::gradients);
1893}
1894
1895
1896/*----------- NavierStokesCouplingEvaluationSIPG -------------------------*/
1897
1898template <int dim, typename Number>
1900 NavierStokesCouplingEvaluationSIPG(const Mapping<dim> &mapping,
1901 const DoFHandler<dim> &dof_handler,
1902 const double kinematic_viscosity)
1903 : fe_sub_u(dof_handler.get_fe().base_element(
1904 dof_handler.get_fe().component_to_base_index(0).first),
1905 dim)
1906 , fe_sub_p(dof_handler.get_fe().base_element(
1907 dof_handler.get_fe().component_to_base_index(dim).first),
1908 1)
1909 , phi_u_m(mapping, fe_sub_u, update_values | update_gradients)
1910 , phi_p_m(mapping, fe_sub_p, update_values)
1912{
1913 for (unsigned int i = 0; i < dof_handler.get_fe().n_dofs_per_cell(); ++i)
1914 if (dof_handler.get_fe().system_to_component_index(i).first < dim)
1915 relevant_dof_indices.push_back(i);
1916
1917 for (unsigned int i = 0; i < dof_handler.get_fe().n_dofs_per_cell(); ++i)
1918 if (dof_handler.get_fe().system_to_component_index(i).first == dim)
1919 relevant_dof_indices.push_back(i);
1920
1921 AssertDimension(dof_handler.get_fe().n_dofs_per_cell(),
1922 relevant_dof_indices.size());
1923}
1924
1925template <int dim, typename Number>
1926unsigned int
1928{
1929 return 4 * dim;
1930}
1931
1932template <int dim, typename Number>
1933const std::vector<unsigned int> &
1939
1940template <int dim, typename Number>
1941void
1943 const typename Triangulation<dim>::cell_iterator &cell,
1944 const ArrayView<const Point<dim, Number>> &points) const
1945{
1946 this->phi_u_m.reinit(cell, points);
1947 this->phi_p_m.reinit(cell, points);
1948}
1949
1950template <int dim, typename Number>
1951void
1954 const Vector<Number> &buffer,
1955 const unsigned int ptr_q,
1956 const unsigned int q_stride,
1957 Number *all_values_m) const
1958{
1959 AssertDimension(buffer.size(),
1960 fe_sub_u.n_dofs_per_cell() + fe_sub_p.n_dofs_per_cell());
1961
1962 ArrayView<const Number> buffer_u(buffer.data() + 0,
1963 fe_sub_u.n_dofs_per_cell());
1964 ArrayView<const Number> buffer_p(buffer.data() + fe_sub_u.n_dofs_per_cell(),
1965 fe_sub_p.n_dofs_per_cell());
1966
1967 this->phi_u_m.evaluate(buffer_u,
1968 EvaluationFlags::values | EvaluationFlags::gradients);
1969 this->phi_p_m.evaluate(buffer_p, EvaluationFlags::values);
1970
1971 for (const auto q : this->phi_u_m.quadrature_point_indices())
1972 {
1973 // Quadrature point index ('global' index within the rotor-stator
1974 // interface)
1975 const unsigned int q_index = ptr_q + q;
1976
1977 // Normal, value, and gradient referring to the quadrature point
1978 const auto normal = data.all_normals[q_index];
1979
1980 const auto u_value = this->phi_u_m.get_value(q);
1981 const auto u_grad_normal =
1982 contract(this->phi_u_m.get_gradient(q), normal);
1983 const auto p_value_normal = this->phi_p_m.get_value(q) * normal;
1984
1985 // Initialize buffer for local side of the interface (i.e. rotor),
1986 // where information is evaluated
1987 BufferRW<Number> buffer_m(all_values_m, q * 4 * dim * q_stride);
1988
1989 // Store values and gradients at the created buffer
1990 buffer_m.write(u_value);
1991 buffer_m.write(u_grad_normal);
1992 buffer_m.write(p_value_normal);
1993 }
1994}
1995
1996template <int dim, typename Number>
1997void
2000 Vector<Number> &buffer,
2001 const unsigned int ptr_q,
2002 const unsigned int q_stride,
2003 Number *all_values_m,
2004 Number *all_values_p) const
2005{
2006 for (const auto q : this->phi_u_m.quadrature_point_indices())
2007 {
2008 const unsigned int q_index = ptr_q + q;
2009
2010 // Initialize buffer for both local and ghost sides
2011 BufferRW<Number> buffer_m(all_values_m, q * 4 * dim * q_stride);
2012 BufferRW<Number> buffer_p(all_values_p, q * 4 * dim * q_stride);
2013
2014 // Read shape functions values and gradients stored in the buffer
2015 const auto u_value_m = buffer_m.template read<u_value_type>();
2016 const auto u_value_p = buffer_p.template read<u_value_type>();
2017 const auto u_grad_normal_m = buffer_m.template read<u_value_type>();
2018 const auto u_grad_normal_p = buffer_p.template read<u_value_type>();
2019 const auto p_value_normal_m = buffer_m.template read<u_value_type>();
2020 const auto p_value_normal_p = buffer_p.template read<u_value_type>();
2021
2022 const auto JxW = data.all_weights[q_index];
2023 const auto penalty_parameter = data.all_penalty_parameter[q_index];
2024 const auto normal = data.all_normals[q_index];
2025
2026 // jump(u) = u_m - u_p
2027 const auto u_value_jump = u_value_m - u_value_p;
2028
2029 // The expression for the average on the mortar interface is
2030 // avg(∇u).n = (∇u_m.normal_m + ∇u_p.normal_p) * 0.5. Since we are
2031 // accessing only the value of normal_m, we use a minus sign here because
2032 // normal_p = - normal_m
2033 const auto u_grad_avg = (u_grad_normal_m - u_grad_normal_p) * 0.5;
2034
2035 // {{p}} = (p_m + p_p)/2
2036 const auto p_value_avg = (p_value_normal_m - p_value_normal_p) * 0.5;
2037
2038 typename FEPointIntegratorU::value_type u_grad_result = {};
2039 typename FEPointIntegratorU::value_type u_value_result = {};
2040 typename FEPointIntegratorP::value_type p_value_result = {};
2041
2042 // SIPG penalty parameter
2043 const double sigma = penalty_parameter * data.penalty_factor;
2044
2045 /* Contributions from viscous term */
2046 // - (n avg(∇v), jump(u))
2047 u_grad_result -= u_value_jump;
2048 // - (jump(v), ν avg(∇δu) n)
2049 u_value_result -= u_grad_avg * this->kinematic_viscosity;
2050 // + (jump(v), ν σ jump(δu))
2051 u_value_result += sigma * this->kinematic_viscosity * u_value_jump;
2052
2053 /* Contribution from pressure gradient term */
2054 // + (jump(v), avg(δp) n)
2055 u_value_result += p_value_avg;
2056
2057 /* Contribution from velocity divergence term */
2058 // - (avg(q), jump(u) n)
2059 p_value_result -= 0.5 * contract(u_value_jump, normal);
2060
2061 // - (n avg(∇v), ν/2 jump(δu))
2062 phi_u_m.submit_gradient(outer(u_grad_result, normal) *
2063 this->kinematic_viscosity * 0.5 * JxW,
2064 q);
2065 phi_u_m.submit_value(u_value_result * JxW, q);
2066 phi_p_m.submit_value(p_value_result * JxW, q);
2067 }
2068
2069 AssertDimension(buffer.size(),
2070 fe_sub_u.n_dofs_per_cell() + fe_sub_p.n_dofs_per_cell());
2071
2072 ArrayView<Number> buffer_u(buffer.data() + 0, fe_sub_u.n_dofs_per_cell());
2073 ArrayView<Number> buffer_p(buffer.data() + fe_sub_u.n_dofs_per_cell(),
2074 fe_sub_p.n_dofs_per_cell());
2075
2076 this->phi_u_m.test_and_sum(buffer_u,
2077 EvaluationFlags::values |
2078 EvaluationFlags::gradients);
2079 this->phi_p_m.test_and_sum(buffer_p, EvaluationFlags::values);
2080}
2081
2082
2083/*-------------- Explicit Instantiations -------------------------------*/
2084template class MortarManagerBase<1>;
2085template class MortarManagerBase<2>;
2086template class MortarManagerBase<3>;
2087
2088template class MortarManagerCircle<1>;
2089template class MortarManagerCircle<2>;
2090template class MortarManagerCircle<3>;
2091
2092template class MortarManagerLinear<1>;
2093template class MortarManagerLinear<2>;
2094template class MortarManagerLinear<3>;
2095
2096template class CouplingOperator<1, double>;
2097template class CouplingOperator<2, double>;
2098template class CouplingOperator<3, double>;
2099
2100template void
2102 LinearAlgebra::distributed::Vector<double> &,
2103 const LinearAlgebra::distributed::Vector<double> &) const;
2104template void
2106 LinearAlgebra::distributed::Vector<double> &,
2107 const LinearAlgebra::distributed::Vector<double> &) const;
2108template void
2110 LinearAlgebra::distributed::Vector<double> &,
2111 const LinearAlgebra::distributed::Vector<double> &) const;
2112
2113template void
2115 TrilinosWrappers::MPI::Vector &,
2116 const TrilinosWrappers::MPI::Vector &) const;
2117template void
2119 TrilinosWrappers::MPI::Vector &,
2120 const TrilinosWrappers::MPI::Vector &) const;
2121template void
2123 TrilinosWrappers::MPI::Vector &,
2124 const TrilinosWrappers::MPI::Vector &) const;
2125
2126template void
2128 LinearAlgebra::distributed::Vector<float> &,
2129 const LinearAlgebra::distributed::Vector<float> &) const;
2130
2131template void
2133 LinearAlgebra::distributed::Vector<float> &,
2134 const LinearAlgebra::distributed::Vector<float> &) const;
2135
2136template void
2138 LinearAlgebra::distributed::Vector<double> &) const;
2139template void
2141 LinearAlgebra::distributed::Vector<double> &) const;
2142template void
2144 LinearAlgebra::distributed::Vector<double> &) const;
2145
2146template void
2148 LinearAlgebra::distributed::Vector<float> &) const;
2149template void
2151 LinearAlgebra::distributed::Vector<float> &) const;
2152
2161
2164
2165template std::vector<unsigned int>
2167 const Triangulation<2> &triangulation,
2168 const Parameters::Mortar<2> &mortar_parameters);
2169
2170template std::vector<unsigned int>
2172 const Triangulation<3> &triangulation,
2173 const Parameters::Mortar<3> &mortar_parameters);
2174
2175template std::tuple<std::vector<double>, double>
2177 const Triangulation<2> &triangulation,
2178 const Mapping<2> &mapping,
2179 const Parameters::Mortar<2> &mortar_parameters);
2180
2181template std::tuple<std::vector<double>, double>
2183 const Triangulation<3> &triangulation,
2184 const Mapping<3> &mapping,
2185 const Parameters::Mortar<3> &mortar_parameters);
2186
2187template std::pair<double, double>
2189 const Triangulation<2> &triangulation,
2190 const Mapping<2> &mapping,
2191 const Parameters::Mortar<2> &mortar_parameters);
2192
2193template std::pair<double, double>
2195 const Triangulation<3> &triangulation,
2196 const Mapping<3> &mapping,
2197 const Parameters::Mortar<3> &mortar_parameters);
2198
2199template Quadrature<2>
2200construct_quadrature(const Quadrature<2> &quadrature,
2201 const Parameters::Mortar<2> &mortar_parameters);
2202
2203template Quadrature<3>
2204construct_quadrature(const Quadrature<3> &quadrature,
2205 const Parameters::Mortar<3> &mortar_parameters);
2206
2207template std::vector<double>
2208compute_stage_heights<2>(const Triangulation<2> &triangulation,
2209 const Parameters::Mortar<2> &mortar_parameters);
2210
2211template std::vector<double>
2212compute_stage_heights<3>(const Triangulation<3> &triangulation,
2213 const Parameters::Mortar<3> &mortar_parameters);
2214
2215template void
2216mortar_workload_imbalance(const Triangulation<2> &triangulation,
2217 const Parameters::Mortar<2> &mortar_parameters,
2218 const ConditionalOStream &pcout);
2219
2220template void
2221mortar_workload_imbalance(const Triangulation<3> &triangulation,
2222 const Parameters::Mortar<3> &mortar_parameters,
2223 const ConditionalOStream &pcout);
Create a temporary vector where mortar evaluation data is stored before being passed to the system ma...
void write(const T &in)
Base class for coupling evaluation routines.
Base class for the Coupling Operator Base.
std::shared_ptr< CouplingEvaluationBase< dim, Number > > evaluator
CouplingEvaluationData< dim, Number > data
CouplingOperator(const Mapping< dim > &mapping, const DoFHandler< dim > &dof_handler, const AffineConstraints< Number > &constraints, const std::shared_ptr< CouplingEvaluationBase< dim, Number > > &evaluator, const std::shared_ptr< MortarManagerBase< dim > > &mortar_manager, const unsigned int bid_m, const unsigned int bid_p, const double sip_factor)
Mortar coupling operator constructor.
void add_diagonal_entries(VectorType &diagonal) const
Add mortar coupling terms in diagonal entries.
const DoFHandler< dim > & dof_handler
DoFHandler associated to the triangulation.
const AffineConstraints< Number > & get_affine_constraints() const
Return object containing problem constraints.
static Number compute_penalty_factor(const unsigned int degree, const Number factor)
Compute penalty factor used in weak imposition of coupling at the rotor-stator interface.
std::vector< types::global_dof_index > dof_indices
unsigned int q_data_size
Number of data points per quadrature point.
void vmult_add(VectorType &dst, const VectorType &src) const
Add matrix-vector multiplication.
const unsigned int bid_m
std::shared_ptr< const Utilities::MPI::Partitioner > partitioner_extended
const Mapping< dim > & mapping
Mapping associated to the domain.
void add_system_matrix_entries(TrilinosWrappers::SparseMatrix &system_matrix) const
Add mortar coupling terms in the system matrix.
std::vector< types::global_dof_index > dof_indices_ghost
AffineConstraints< Number > constraints_extended
Constraints extended according to mortar entries.
Point< dim > get_face_center(const typename Triangulation< dim >::cell_iterator &cell, const typename Triangulation< dim >::face_iterator &face) const
Returns the point corresponding to the cell center.
void add_sparsity_pattern_entries(SparsityPatternBase &dsp) const
Add mortar coupling terms in the sparsity pattern.
std::shared_ptr< MortarManagerBase< dim > > mortar_manager
std::vector< types::global_dof_index > get_dof_indices(const typename DoFHandler< dim >::active_cell_iterator &cell) const
Returns dof indices.
Utilities::MPI::NoncontiguousPartitioner partitioner
Number compute_penalty_parameter(const typename Triangulation< dim >::cell_iterator &cell) const
Compute penalty parameter in a cell.
std::vector< Point< dim, Number > > all_points_ref
std::vector< unsigned int > relevant_dof_indices
List of relevant DoF indices per cell.
unsigned int n_dofs_per_cell
Number of DoFs per cell.
const unsigned int bid_p
Base class for the mortar manager.
const unsigned int n_quadrature_points
Number of quadrature points per cell.
virtual double to_1D(const Point< dim > &point) const =0
Convert quadrature point in real space to angle (in radians).
unsigned int get_n_mortars() const
Returns the number of mortar cells connecting rotor-stator regular cells at the interface 1 = rotor-s...
std::vector< Point< std::max(1, dim - 1)> > get_points_ref(const Point< dim > &face_center, const bool is_inner) const
Returns the coordinates of the quadrature points at both sides of the interface in the reference spac...
bool is_mesh_aligned() const
Verify if cells of the inner and outer domains are aligned.
const unsigned int rotation_axis_direction
Direction of the rotation axis (x=0, y=1, z=2).
virtual Tensor< 1, dim, double > get_normal(const Point< dim > &point) const =0
Return the normal for a given quadrature point.
const double rotation_angle
Rotation angle for the inner domain.
const std::vector< double > stage_heights
std::vector< unsigned int > n_subdivisions
Number of cells at the interface between inner and outer domains.
unsigned int get_n_points() const
Returns the number of quadrature points at the mortar cells connected to a given cell.
std::vector< double > get_weights(const Point< dim > &face_center, const bool is_inner) const
Returns the weights of the quadrature points at both sides of the interface.
std::tuple< unsigned int, unsigned int, unsigned int > get_config(const Point< dim > &face_center, const bool is_inner) const
Returns the mesh alignment type and cell index.
Quadrature< std::max(1, dim - 1)> quadrature
Mortar quadrature.
std::vector< double > interface_dimensions
std::vector< Point< dim > > get_points(const Point< dim > &face_center, const bool is_inner) const
Returns the coordinates of the quadrature points at both sides of the interface in the real space.
std::vector< Tensor< 1, dim, double > > get_normals(const Point< dim > &face_center, const bool is_inner) const
Returns the normal vector for the quadrature points.
std::vector< unsigned int > get_mortar_indices(const Point< dim > &face_center, const bool is_inner) const
Returns the indices of all mortars at both sides of the interface.
virtual Point< dim > from_1D(const double angle_rad) const =0
Convert angle (in radians) to quadrature point in real space.
unsigned int get_n_total_points() const
Returns the total number of quadrature points at all mortar cells.
unsigned int get_n_total_mortars() const
Returns the total number of mortars.
Mortar manager class for circular interface.
Point< dim > from_1D(const double angle_rad) const override
Convert angle (in radians) to quadrature point in real space.
const Point< dim > center_of_rotation
Center of rotation of the inner domain.
double to_1D(const Point< dim > &point) const override
Convert quadrature point in real space to angle (in radians).
Tensor< 1, dim, double > get_normal(const Point< dim > &point) const override
Return the normal for a given quadrature point.
Mortar manager class for linear interface.
double to_1D(const Point< dim > &point) const override
Convert quadrature point in real space to angle (in radians).
double coord_min
Minimum y coordinate of interface nodes.
Tensor< 1, dim, double > get_normal(const Point< dim > &) const override
Return the normal for a given quadrature point.
Point< dim > from_1D(const double angle_rad) const override
Convert angle (in radians) to quadrature point in real space.
double coord_max
Maximum y coordinate of interface nodes.
void local_reinit(const typename Triangulation< dim >::cell_iterator &cell, const ArrayView< const Point< dim, Number > > &points) const override
Set up mapping information.
NavierStokesCouplingEvaluationSIPG(const Mapping< dim > &mapping, const DoFHandler< dim > &dof_handler, const double kinematic_viscosity)
Class constructor.
const std::vector< unsigned int > & get_relevant_dof_indices() const override
Return relevant dof indices.
void local_integrate(const CouplingEvaluationData< dim, Number > &data, Vector< Number > &buffer, const unsigned int ptr_q, const unsigned int q_stride, Number *all_values_m, Number *all_values_p) const override
Perform integral of mortar elements at the rotor-stator interface.
FEPointIntegratorU phi_u_m
Interface to the evaluation of mortar coupling interpolated solution.
void local_evaluate(const CouplingEvaluationData< dim, Number > &data, const Vector< Number > &buffer, const unsigned int ptr_q, const unsigned int q_stride, Number *all_values_local) const override
Evaluate values and gradients at the coupling entries.
const double kinematic_viscosity
Kinematic viscosity.
std::vector< unsigned int > relevant_dof_indices
Relevant dof indices.
void local_integrate(const CouplingEvaluationData< dim, Number > &data, Vector< Number > &buffer, const unsigned int ptr_q, const unsigned int q_stride, Number *all_value_m, Number *all_value_p) const override
Perform integral of mortar elements at the rotor-stator interface.
std::vector< unsigned int > relevant_dof_indices
Relevant dof indices.
const std::vector< unsigned int > & get_relevant_dof_indices() const override
Return relevant dof indices.
void local_reinit(const typename Triangulation< dim >::cell_iterator &cell, const ArrayView< const Point< dim, Number > > &points) const override
Set up mapping information.
unsigned int data_size() const override
ScalarCouplingEvaluationSIPG(const Mapping< dim > &mapping, const DoFHandler< dim > &dof_handler, const unsigned int first_selected_component=0)
FEPointIntegrator phi_m
Interface to the evaluation of mortar coupling interpolated solution.
void local_evaluate(const CouplingEvaluationData< dim, Number > &data, const Vector< Number > &buffer, const unsigned int ptr_q, const unsigned int q_stride, Number *all_value_m) const override
Evaluate values and gradients at the coupling entries.
double point_to_angle(const Point< dim > &point, const Point< dim > &center_of_rotation=Point< dim >(), const unsigned int rotation_axis_direction=2)
Converts point to angle (in radians) based on rotation axis.
Definition utilities.h:1234
Point< dim > radius_to_point(const double radius, const double angle_rad, const Point< dim > &center_of_rotation=Point< dim >(), const unsigned int rotation_axis_direction=2)
Converts radius to point in cartesian coordinates based on rotation axis.
Definition utilities.h:1266
template std::tuple< std::vector< double >, double > compute_interface_dimensions_circular< 3 >(const Triangulation< 3 > &triangulation, const Mapping< 3 > &mapping, const Parameters::Mortar< 3 > &mortar_parameters)
template std::pair< double, double > compute_interface_dimensions_linear< 2 >(const Triangulation< 2 > &triangulation, const Mapping< 2 > &mapping, const Parameters::Mortar< 2 > &mortar_parameters)
std::vector< unsigned int > compute_number_interface_cells(const Triangulation< dim > &triangulation, const Parameters::Mortar< dim > &mortar_parameters)
Compute the number of cells located at the mortar interface.
DeclException1(InterfaceRadiusTolerance, double,<< "The computed radius of the rotor mesh has a variation of "<< arg1<< " along the interface boundary, which exceeds the prescribed tolerance.")
template std::pair< double, double > compute_interface_dimensions_linear< 3 >(const Triangulation< 3 > &triangulation, const Mapping< 3 > &mapping, const Parameters::Mortar< 3 > &mortar_parameters)
template std::vector< double > compute_stage_heights< 3 >(const Triangulation< 3 > &triangulation, const Parameters::Mortar< 3 > &mortar_parameters)
template std::vector< unsigned int > compute_number_interface_cells< 2 >(const Triangulation< 2 > &triangulation, const Parameters::Mortar< 2 > &mortar_parameters)
std::pair< double, double > compute_interface_dimensions_linear(const Triangulation< dim > &triangulation, const Mapping< dim > &mapping, const Parameters::Mortar< dim > &mortar_parameters)
Compute linear mortar interface dimensions.
std::vector< double > compute_stage_heights(const Triangulation< dim > &triangulation, const Parameters::Mortar< dim > &mortar_parameters)
Compute the stage heights in the direction of the rotation axis at the mortar interface....
template std::vector< double > compute_stage_heights< 2 >(const Triangulation< 2 > &triangulation, const Parameters::Mortar< 2 > &mortar_parameters)
template std::vector< unsigned int > compute_number_interface_cells< 3 >(const Triangulation< 3 > &triangulation, const Parameters::Mortar< 3 > &mortar_parameters)
void mortar_workload_imbalance(const Triangulation< dim > &triangulation, const Parameters::Mortar< dim > &mortar_parameters, const ConditionalOStream &pcout)
Compute workload imbalance of mortar cells.
std::tuple< std::vector< double >, double > compute_interface_dimensions_circular(const Triangulation< dim > &triangulation, const Mapping< dim > &mapping, const Parameters::Mortar< dim > &mortar_parameters)
Compute circular mortar interface dimensions and the rotor mesh pre-rotation angle.
Quadrature< dim > construct_quadrature(const Quadrature< dim > &quadrature, const Parameters::Mortar< dim > &mortar_parameters)
Construct oversampled quadrature.
template std::tuple< std::vector< double >, double > compute_interface_dimensions_circular< 2 >(const Triangulation< 2 > &triangulation, const Mapping< 2 > &mapping, const Parameters::Mortar< 2 > &mortar_parameters)
Tensor< 1, dim, Number > outer(const Number &value, const Tensor< 1, dim, Number > &normal)
Compute outer product.
Number contract(const Tensor< 1, dim, Number > &grad, const Tensor< 1, dim, Number > &normal)
Compute inner product.
double find_point_line_distance(const Point< dim > &line_origin, const Tensor< 1, dim > &line_direction, const Point< dim > &point)
Calculate the minimum distance between a point and a line (defined using its orign and direction)....
std::vector< Tensor< 1, dim, Number > > all_normals
Number penalty_factor
Penalty factor (akin to penalty factor in SIPG).
std::vector< Number > all_weights
Weights of quadrature points.
std::vector< Number > all_penalty_parameter
Penalty parameter in symmetric interior penalty Galerkin (SIPG) method.
Mortar - Defines parameters used to construct mortar elements.
Point< dim > center_of_rotation
Center of rotation of the rotor domain.
unsigned int stator_boundary_id
Boundary ID # of the stator at the rotor-stator interface.
unsigned int rotor_boundary_id
Boundary ID # of the rotor at the rotor-stator interface.
unsigned int rotation_axis_direction
Rotation axis direction.
unsigned int oversampling_factor
Oversampling factor for quadrature points.
double radius_tolerance
Tolerance used for rotor-stator interface radius computation.
GlobalVectorType VectorType