version GIT relicensing-7316-g6bacdb5935 2026-12-03 00:30:01+00:00
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
Loading...
Searching...
No Matches
manifold_lib.cc
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) 2014 - 2025 by the deal.II authors
5//
6// This file is part of the deal.II library.
7//
8// Detailed license information governing the source code and contributions
9// can be found in LICENSE.md and CONTRIBUTING.md at the top level directory.
10//
11// -----------------------------------------------------------------------------
12
13#include <deal.II/base/table.h>
14#include <deal.II/base/tensor.h>
15
16#include <deal.II/fe/mapping.h>
18
20#include <deal.II/grid/tria.h>
23
24#include <deal.II/lac/vector.h>
25
27
28#include <boost/container/small_vector.hpp>
29
30#include <cmath>
31#include <limits>
32#include <memory>
33
35
36
37namespace internal
38{
39 // The pull_back function fails regularly in the compute_chart_points
40 // method, and, instead of throwing an exception, returns a point outside
41 // the unit cell. The individual coordinates of that point are given by the
42 // value below.
43 static constexpr double invalid_pull_back_coordinate = 20.0;
44
45 // Rotate a given unit vector u around the axis dir
46 // where the angle is given by the length of dir.
47 // This is the exponential map for a sphere.
50 {
51 const double theta = dir.norm();
52 if (theta < 1.e-10)
53 {
54 return u;
55 }
56 else
57 {
58 const Tensor<1, 3> dirUnit = dir / theta;
59 const Tensor<1, 3> tmp =
60 std::cos(theta) * u + std::sin(theta) * dirUnit;
61 return tmp / tmp.norm();
62 }
63 }
64
65 // Returns the direction to go from v to u
66 // projected to the plane perpendicular to the unit vector v.
67 // This one is more stable when u and v are nearly equal.
70 {
71 Tensor<1, 3> ans = u - v;
72 ans -= (ans * v) * v;
73 return ans; // ans = (u-v) - ((u-v)*v)*v
74 }
75
76 // helper function to compute a vector orthogonal to a given one.
77 // does nothing unless spacedim == 3.
78 template <int spacedim>
81 bool /*normalize*/ = false)
82 {
83 return {};
84 }
85
87 compute_normal(const Tensor<1, 3> &vector, bool normalize = false)
88 {
89 Assert(vector.norm_square() != 0.,
90 ExcMessage("The direction parameter must not be zero!"));
91 Point<3> normal;
92 if (std::abs(vector[0]) >= std::abs(vector[1]) &&
93 std::abs(vector[0]) >= std::abs(vector[2]))
94 {
95 normal[1] = -1.;
96 normal[2] = -1.;
97 normal[0] = (vector[1] + vector[2]) / vector[0];
98 }
99 else if (std::abs(vector[1]) >= std::abs(vector[0]) &&
100 std::abs(vector[1]) >= std::abs(vector[2]))
101 {
102 normal[0] = -1.;
103 normal[2] = -1.;
104 normal[1] = (vector[0] + vector[2]) / vector[1];
105 }
106 else
107 {
108 normal[0] = -1.;
109 normal[1] = -1.;
110 normal[2] = (vector[0] + vector[1]) / vector[2];
111 }
112 if (normalize)
113 normal /= normal.norm();
114 return normal;
115 }
116} // namespace internal
117
118
119
120// ============================================================
121// PolarManifold
122// ============================================================
123
125template <int dim, int spacedim>
127 : ChartManifold<dim, spacedim, spacedim>(
128 PolarManifold<dim, spacedim>::get_periodicity())
129 , center(center)
130 , p_center(center)
131{}
133
134
135
136template <int dim, int spacedim>
137std::unique_ptr<Manifold<dim, spacedim>>
139{
140 return std::make_unique<PolarManifold<dim, spacedim>>(*this);
141}
142
143
144
145template <int dim, int spacedim>
148{
149 Tensor<1, spacedim> periodicity;
150 // In two dimensions, theta is periodic.
151 // In three dimensions things are a little more complicated, since the only
152 // variable that is truly periodic is phi, while theta should be bounded
153 // between 0 and pi. There is currently no way to enforce this, so here we
154 // only fix periodicity for the last variable, corresponding to theta in 2d
155 // and phi in 3d.
156 periodicity[spacedim - 1] = 2 * numbers::PI;
157 return periodicity;
158}
159
160
161
162template <int dim, int spacedim>
165 const Point<spacedim> &spherical_point) const
166{
167 Assert(spherical_point[0] >= 0.0,
168 ExcMessage("Negative radius for given point."));
169 const double rho = spherical_point[0];
170 const double theta = spherical_point[1];
171
173 if (rho > 1e-10)
174 switch (spacedim)
175 {
176 case 2:
177 p[0] = rho * std::cos(theta);
178 p[1] = rho * std::sin(theta);
179 break;
180 case 3:
181 {
182 const double phi = spherical_point[2];
183 p[0] = rho * std::sin(theta) * std::cos(phi);
184 p[1] = rho * std::sin(theta) * std::sin(phi);
185 p[2] = rho * std::cos(theta);
186 break;
187 }
188 default:
190 }
191 return p + p_center;
192}
193
194
195
196template <int dim, int spacedim>
199 const Point<spacedim> &space_point) const
200{
201 const Tensor<1, spacedim> R = space_point - p_center;
202 const double rho = R.norm();
203
205 p[0] = rho;
206
207 switch (spacedim)
208 {
209 case 2:
210 {
211 p[1] = std::atan2(R[1], R[0]);
212 if (p[1] < 0)
213 p[1] += 2 * numbers::PI;
214 break;
215 }
216
217 case 3:
218 {
219 const double z = R[2];
220 p[2] = std::atan2(R[1], R[0]); // phi
221 if (p[2] < 0)
222 p[2] += 2 * numbers::PI; // phi is periodic
223 p[1] = std::atan2(std::sqrt(R[0] * R[0] + R[1] * R[1]), z); // theta
224 break;
225 }
226
227 default:
229 }
230 return p;
231}
232
233
234
235template <int dim, int spacedim>
238 const Point<spacedim> &spherical_point) const
239{
240 Assert(spherical_point[0] >= 0.0,
241 ExcMessage("Negative radius for given point."));
242 const double rho = spherical_point[0];
243 const double theta = spherical_point[1];
244
246 if (rho > 1e-10)
247 switch (spacedim)
248 {
249 case 2:
250 {
251 DX[0][0] = std::cos(theta);
252 DX[0][1] = -rho * std::sin(theta);
253 DX[1][0] = std::sin(theta);
254 DX[1][1] = rho * std::cos(theta);
255 break;
256 }
257
258 case 3:
259 {
260 const double phi = spherical_point[2];
261 DX[0][0] = std::sin(theta) * std::cos(phi);
262 DX[0][1] = rho * std::cos(theta) * std::cos(phi);
263 DX[0][2] = -rho * std::sin(theta) * std::sin(phi);
264
265 DX[1][0] = std::sin(theta) * std::sin(phi);
266 DX[1][1] = rho * std::cos(theta) * std::sin(phi);
267 DX[1][2] = rho * std::sin(theta) * std::cos(phi);
268
269 DX[2][0] = std::cos(theta);
270 DX[2][1] = -rho * std::sin(theta);
271 DX[2][2] = 0;
272 break;
273 }
274
275 default:
277 }
278 return DX;
279}
280
281
282
283namespace
284{
285 template <int dim, int spacedim>
286 bool
287 spherical_face_is_horizontal(
289 const Point<spacedim> &manifold_center)
290 {
291 // We test whether a face is horizontal by checking that the vertices
292 // all have roughly the same distance from the center: If the
293 // maximum deviation for the distances from the vertices to the
294 // center is less than 1.e-5 of the distance between vertices (as
295 // measured by the minimum distance from any of the other vertices
296 // to the first vertex), then we call this a horizontal face.
297 constexpr unsigned int n_vertices =
299 std::array<double, n_vertices> sqr_distances_to_center;
300 std::array<double, n_vertices - 1> sqr_distances_to_first_vertex;
301 sqr_distances_to_center[0] =
302 (face->vertex(0) - manifold_center).norm_square();
303 for (unsigned int i = 1; i < n_vertices; ++i)
304 {
305 sqr_distances_to_center[i] =
306 (face->vertex(i) - manifold_center).norm_square();
307 sqr_distances_to_first_vertex[i - 1] =
308 (face->vertex(i) - face->vertex(0)).norm_square();
309 }
310 const auto minmax_sqr_distance =
311 std::minmax_element(sqr_distances_to_center.begin(),
312 sqr_distances_to_center.end());
313 const auto min_sqr_distance_to_first_vertex =
314 std::min_element(sqr_distances_to_first_vertex.begin(),
315 sqr_distances_to_first_vertex.end());
316
317 return (*minmax_sqr_distance.second - *minmax_sqr_distance.first <
318 1.e-10 * *min_sqr_distance_to_first_vertex);
319 }
320} // namespace
321
322
323
324template <int dim, int spacedim>
328 const Point<spacedim> &p) const
329{
330 // Let us first test whether we are on a "horizontal" face
331 // (tangential to the sphere). In this case, the normal vector is
332 // easy to compute since it is proportional to the vector from the
333 // center to the point 'p'.
334 if (spherical_face_is_horizontal<dim, spacedim>(face, p_center))
335 {
336 // So, if this is a "horizontal" face, then just compute the normal
337 // vector as the one from the center to the point 'p', adequately
338 // scaled.
339 const Tensor<1, spacedim> unnormalized_spherical_normal = p - p_center;
340 const Tensor<1, spacedim> normalized_spherical_normal =
341 unnormalized_spherical_normal / unnormalized_spherical_normal.norm();
342 return normalized_spherical_normal;
343 }
344 else
345 // If it is not a horizontal face, just use the machinery of the
346 // base class.
348
349 return Tensor<1, spacedim>();
350}
351
352
353
354// ============================================================
355// SphericalManifold
356// ============================================================
357
359template <int dim, int spacedim>
361 const Point<spacedim> center)
362 : center(center)
363 , p_center(center)
364 , polar_manifold(center)
365{}
367
368
369
370template <int dim, int spacedim>
371std::unique_ptr<Manifold<dim, spacedim>>
373{
374 return std::make_unique<SphericalManifold<dim, spacedim>>(*this);
375}
376
377
378
379template <int dim, int spacedim>
382 const Point<spacedim> &p1,
383 const Point<spacedim> &p2,
384 const double w) const
385{
386 const double tol = 1e-10;
387
388 if ((p1 - p2).norm_square() < tol * tol || std::abs(w) < tol)
389 return p1;
390 else if (std::abs(w - 1.0) < tol)
391 return p2;
392
393 // If the points are one dimensional then there is no need for anything but
394 // a linear combination.
395 if (spacedim == 1)
396 return Point<spacedim>(w * p2 + (1 - w) * p1);
397
398 const Tensor<1, spacedim> v1 = p1 - p_center;
399 const Tensor<1, spacedim> v2 = p2 - p_center;
400 const double r1 = v1.norm();
401 const double r2 = v2.norm();
402
403 Assert(r1 > tol && r2 > tol,
404 ExcMessage("p1 and p2 cannot coincide with the center."));
405
406 const Tensor<1, spacedim> e1 = v1 / r1;
407 const Tensor<1, spacedim> e2 = v2 / r2;
408
409 // Find the cosine of the angle gamma described by v1 and v2.
410 const double cosgamma = e1 * e2;
411
412 // Points are collinear with the center (allow for 8*eps as a tolerance)
413 if (cosgamma < -1 + 8. * std::numeric_limits<double>::epsilon())
414 return p_center;
415
416 // Points are along a line, in which case e1 and e2 are essentially the same.
417 if (cosgamma > 1 - 8. * std::numeric_limits<double>::epsilon())
418 return Point<spacedim>(p_center + w * v2 + (1 - w) * v1);
419
420 // Find the angle sigma that corresponds to arclength equal to w. acos
421 // should never be undefined because we have ruled out the two special cases
422 // above.
423 const double sigma = w * std::acos(cosgamma);
424
425 // Normal to v1 in the plane described by v1,v2,and the origin.
426 // Since p1 and p2 do not coincide n is not zero and well defined.
427 Tensor<1, spacedim> n = v2 - (v2 * e1) * e1;
428 const double n_norm = n.norm();
429 Assert(n_norm > 0,
430 ExcInternalError("n should be different from the null vector. "
431 "Probably, this means v1==v2 or v2==0."));
432
433 n /= n_norm;
434
435 // Find the point Q along O,v1 such that
436 // P1,V,P2 has measure sigma.
437 const Tensor<1, spacedim> P = std::cos(sigma) * e1 + std::sin(sigma) * n;
438
439 // Project this point on the manifold.
440 return Point<spacedim>(p_center + (w * r2 + (1.0 - w) * r1) * P);
441}
442
443
444
445template <int dim, int spacedim>
448 const Point<spacedim> &p1,
449 const Point<spacedim> &p2) const
450{
451 const double tol = 1e-10;
452
453 Assert(p1 != p2, ExcMessage("p1 and p2 should not concide."));
454
455 const Tensor<1, spacedim> v1 = p1 - p_center;
456 const Tensor<1, spacedim> v2 = p2 - p_center;
457 const double r1 = v1.norm();
458 const double r2 = v2.norm();
459
460 Assert(r1 > tol, ExcMessage("p1 cannot coincide with the center."));
461
462 Assert(r2 > tol, ExcMessage("p2 cannot coincide with the center."));
463
464 const Tensor<1, spacedim> e1 = v1 / r1;
465 const Tensor<1, spacedim> e2 = v2 / r2;
466
467 // Find the cosine of the angle gamma described by v1 and v2.
468 const double cosgamma = e1 * e2;
469
470 Assert(cosgamma > -1 + 8. * std::numeric_limits<double>::epsilon(),
471 ExcMessage("p1 and p2 cannot lie on the same diameter and be opposite "
472 "respect to the center."));
473
474 if (cosgamma > 1 - 8. * std::numeric_limits<double>::epsilon())
475 return v2 - v1;
476
477 // Normal to v1 in the plane described by v1,v2,and the origin.
478 // Since p1 and p2 do not coincide n is not zero and well defined.
479 Tensor<1, spacedim> n = v2 - (v2 * e1) * e1;
480 const double n_norm = n.norm();
481 Assert(n_norm > 0,
482 ExcInternalError("n should be different from the null vector. "
483 "Probably, this means v1==v2 or v2==0."));
484
485 n /= n_norm;
486
487 // this is the derivative of the geodesic in get_intermediate_point
488 // derived with respect to w and inserting w=0.
489 const double gamma = std::acos(cosgamma);
490 return (r2 - r1) * e1 + r1 * gamma * n;
491}
492
493
494
495template <int dim, int spacedim>
499 const Point<spacedim> &p) const
500{
501 // Let us first test whether we are on a "horizontal" face
502 // (tangential to the sphere). In this case, the normal vector is
503 // easy to compute since it is proportional to the vector from the
504 // center to the point 'p'.
505 if (spherical_face_is_horizontal<dim, spacedim>(face, p_center))
506 {
507 // So, if this is a "horizontal" face, then just compute the normal
508 // vector as the one from the center to the point 'p', adequately
509 // scaled.
510 const Tensor<1, spacedim> unnormalized_spherical_normal = p - p_center;
511 const Tensor<1, spacedim> normalized_spherical_normal =
512 unnormalized_spherical_normal / unnormalized_spherical_normal.norm();
513 return normalized_spherical_normal;
514 }
515 else
516 // If it is not a horizontal face, just use the machinery of the
517 // base class.
519
520 return Tensor<1, spacedim>();
521}
522
523
524
525template <>
526void
533
534
535
536template <>
537void
544
545
546
547template <int dim, int spacedim>
548void
551 typename Manifold<dim, spacedim>::FaceVertexNormals &face_vertex_normals)
552 const
553{
554 // Let us first test whether we are on a "horizontal" face
555 // (tangential to the sphere). In this case, the normal vector is
556 // easy to compute since it is proportional to the vector from the
557 // center to the point 'p'.
558 if (spherical_face_is_horizontal<dim, spacedim>(face, p_center))
559 {
560 // So, if this is a "horizontal" face, then just compute the normal
561 // vector as the one from the center to the point 'p', adequately
562 // scaled.
563 for (unsigned int vertex = 0;
564 vertex < GeometryInfo<spacedim>::vertices_per_face;
565 ++vertex)
566 face_vertex_normals[vertex] = face->vertex(vertex) - p_center;
567 }
568 else
569 Manifold<dim, spacedim>::get_normals_at_vertices(face, face_vertex_normals);
570}
571
572
573
574template <int dim, int spacedim>
575void
577 const ArrayView<const Point<spacedim>> &surrounding_points,
578 const Table<2, double> &weights,
579 ArrayView<Point<spacedim>> new_points) const
580{
581 AssertDimension(new_points.size(), weights.size(0));
582 AssertDimension(surrounding_points.size(), weights.size(1));
583
584 do_get_new_points(surrounding_points, make_array_view(weights), new_points);
585
586 return;
587}
588
589
590
591template <int dim, int spacedim>
594 const ArrayView<const Point<spacedim>> &vertices,
595 const ArrayView<const double> &weights) const
596{
597 // To avoid duplicating all of the logic in get_new_points, simply call it
598 // for one position.
599 Point<spacedim> new_point;
600 do_get_new_points(vertices,
601 weights,
602 make_array_view(&new_point, &new_point + 1));
603
604 return new_point;
605}
606
607
608
609namespace internal
610{
612 {
613 namespace
614 {
615 template <int spacedim>
617 do_get_new_point(
618 const ArrayView<const Tensor<1, spacedim>> & /*directions*/,
619 const ArrayView<const double> & /*distances*/,
620 const ArrayView<const double> & /*weights*/,
621 const Point<spacedim> & /*candidate_point*/)
622 {
624 return {};
625 }
626
627 template <>
629 do_get_new_point(const ArrayView<const Tensor<1, 3>> &directions,
630 const ArrayView<const double> &distances,
631 const ArrayView<const double> &weights,
632 const Point<3> &candidate_point)
633 {
634 AssertDimension(directions.size(), distances.size());
635 AssertDimension(directions.size(), weights.size());
636
637 Point<3> candidate = candidate_point;
638 const unsigned int n_merged_points = directions.size();
639 const double tolerance = 1e-10;
640 const int max_iterations = 10;
641
642 {
643 // If the candidate happens to coincide with a normalized
644 // direction, we return it. Otherwise, the Hessian would be singular.
645 for (unsigned int i = 0; i < n_merged_points; ++i)
646 {
647 const double squared_distance =
648 (candidate - directions[i]).norm_square();
649 if (squared_distance < tolerance * tolerance)
650 return candidate;
651 }
652
653 // check if we only have two points now, in which case we can use the
654 // get_intermediate_point function
655 if (n_merged_points == 2)
656 {
657 static const ::SphericalManifold<3, 3> unit_manifold;
658 Assert(std::abs(weights[0] + weights[1] - 1.0) < 1e-13,
659 ExcMessage("Weights do not sum up to 1"));
660 const Point<3> intermediate =
661 unit_manifold.get_intermediate_point(Point<3>(directions[0]),
662 Point<3>(directions[1]),
663 weights[1]);
664 return intermediate;
665 }
666
667 Tensor<1, 3> vPerp;
668 Tensor<2, 2> Hessian;
670 Tensor<1, 2> gradlocal;
671
672 // On success we exit the loop early.
673 // Otherwise, we just take the result after max_iterations steps.
674 for (unsigned int i = 0; i < max_iterations; ++i)
675 {
676 // Step 2a: Find new descent direction
677
678 // Get local basis for the estimate candidate
679 const Tensor<1, 3> Clocalx = internal::compute_normal(candidate);
680 const Tensor<1, 3> Clocaly = cross_product_3d(candidate, Clocalx);
681
682 // For each vertices vector, compute the tangent vector from
683 // candidate towards the vertices vector -- its length is the
684 // spherical length from candidate to the vertices vector. Then
685 // compute its contribution to the Hessian.
686 gradient = 0.;
687 Hessian = 0.;
688 for (unsigned int i = 0; i < n_merged_points; ++i)
689 if (std::abs(weights[i]) > 1.e-15)
690 {
691 vPerp =
692 internal::projected_direction(directions[i], candidate);
693 const double sinthetaSq = vPerp.norm_square();
694 const double sintheta = std::sqrt(sinthetaSq);
695 if (sintheta < tolerance)
696 {
697 Hessian[0][0] += weights[i];
698 Hessian[1][1] += weights[i];
699 }
700 else
701 {
702 const double costheta = (directions[i]) * candidate;
703 const double theta = std::atan2(sintheta, costheta);
704 const double sincthetaInv = theta / sintheta;
705
706 const double cosphi = vPerp * Clocalx;
707 const double sinphi = vPerp * Clocaly;
708
709 gradlocal[0] = cosphi;
710 gradlocal[1] = sinphi;
711 gradient += (weights[i] * sincthetaInv) * gradlocal;
712
713 const double wt = weights[i] / sinthetaSq;
714 const double sinphiSq = sinphi * sinphi;
715 const double cosphiSq = cosphi * cosphi;
716 const double tt = sincthetaInv * costheta;
717 const double offdiag =
718 cosphi * sinphi * wt * (1.0 - tt);
719 Hessian[0][0] += wt * (cosphiSq + tt * sinphiSq);
720 Hessian[0][1] += offdiag;
721 Hessian[1][0] += offdiag;
722 Hessian[1][1] += wt * (sinphiSq + tt * cosphiSq);
723 }
724 }
725
726 Assert(determinant(Hessian) > tolerance, ExcInternalError());
727
728 const Tensor<2, 2> inverse_Hessian = invert(Hessian);
729
730 const Tensor<1, 2> xDisplocal = inverse_Hessian * gradient;
731 const Tensor<1, 3> xDisp =
732 xDisplocal[0] * Clocalx + xDisplocal[1] * Clocaly;
733
734 // Step 2b: rotate candidate in direction xDisp for a new
735 // candidate.
736 const Point<3> candidateOld = candidate;
737 candidate =
738 Point<3>(internal::apply_exponential_map(candidate, xDisp));
739
740 // Step 2c: return the new candidate if we didn't move
741 if ((candidate - candidateOld).norm_square() <
742 tolerance * tolerance)
743 break;
744 }
745 }
746 return candidate;
747 }
748 } // namespace
749 } // namespace SphericalManifold
750} // namespace internal
751
752
753
754template <int dim, int spacedim>
755void
757 const ArrayView<const Point<spacedim>> &surrounding_points,
758 const ArrayView<const double> &weights,
759 ArrayView<Point<spacedim>> new_points) const
760{
761 AssertDimension(weights.size(),
762 new_points.size() * surrounding_points.size());
763 const unsigned int weight_rows = new_points.size();
764 const unsigned int weight_columns = surrounding_points.size();
765
766 if (surrounding_points.size() == 2)
767 {
768 for (unsigned int row = 0; row < weight_rows; ++row)
769 new_points[row] =
771 surrounding_points[0],
772 surrounding_points[1],
773 weights[row * weight_columns + 1]);
774 return;
775 }
776
777 boost::container::small_vector<std::pair<double, Tensor<1, spacedim>>, 100>
778 new_candidates(new_points.size());
779 boost::container::small_vector<Tensor<1, spacedim>, 100> directions(
780 surrounding_points.size(), Point<spacedim>());
781 boost::container::small_vector<double, 100> distances(
782 surrounding_points.size(), 0.0);
783 double max_distance = 0.;
784 for (unsigned int i = 0; i < surrounding_points.size(); ++i)
785 {
786 directions[i] = surrounding_points[i] - p_center;
787 distances[i] = directions[i].norm();
788
789 if (distances[i] != 0.)
790 directions[i] /= distances[i];
791 else
792 Assert(false,
793 ExcMessage("One of the vertices coincides with the center. "
794 "This is not allowed!"));
795
796 // Check if an estimate is good enough,
797 // this is often the case for sufficiently refined meshes.
798 for (unsigned int k = 0; k < i; ++k)
799 {
800 const double squared_distance =
801 (directions[i] - directions[k]).norm_square();
802 max_distance = std::max(max_distance, squared_distance);
803 }
804 }
805
806 // Step 1: Check for some special cases, create simple linear guesses
807 // otherwise.
808 const double tolerance = 1e-10;
809 boost::container::small_vector<bool, 100> accurate_point_was_found(
810 new_points.size(), false);
811 const ArrayView<const Tensor<1, spacedim>> array_directions =
812 make_array_view(directions.begin(), directions.end());
813 const ArrayView<const double> array_distances =
814 make_array_view(distances.begin(), distances.end());
815 for (unsigned int row = 0; row < weight_rows; ++row)
816 {
817 new_candidates[row] =
818 guess_new_point(array_directions,
819 array_distances,
820 ArrayView<const double>(&weights[row * weight_columns],
821 weight_columns));
822
823 // If the candidate is the center, mark it as found to avoid entering
824 // the Newton iteration in step 2, which would crash.
825 if (new_candidates[row].first == 0.0)
826 {
827 new_points[row] = p_center;
828 accurate_point_was_found[row] = true;
829 continue;
830 }
831
832 // If not in 3d, just use the implementation from PolarManifold
833 // after we verified that the candidate is not the center.
834 if (spacedim < 3)
835 new_points[row] = polar_manifold.get_new_point(
836 surrounding_points,
837 ArrayView<const double>(&weights[row * weight_columns],
838 weight_columns));
839 }
840
841 // In this case, we treated the case that the candidate is the center and
842 // obtained the new locations from the PolarManifold object otherwise.
843 if constexpr (spacedim < 3)
844 return;
845 else
846 {
847 // If all the points are close to each other, we expect the estimate to
848 // be good enough. This tolerance was chosen such that the first iteration
849 // for a at least three time refined HyperShell mesh with radii .5 and 1.
850 // doesn't already succeed.
851 if (max_distance < 2e-2)
852 {
853 for (unsigned int row = 0; row < weight_rows; ++row)
854 new_points[row] =
855 p_center + new_candidates[row].first * new_candidates[row].second;
856
857 return;
858 }
859
860 // Step 2:
861 // Do more expensive Newton-style iterations to improve the estimate.
862
863 // Search for duplicate directions and merge them to minimize the cost of
864 // the get_new_point function call below.
865 boost::container::small_vector<double, 1000> merged_weights(
866 weights.size());
867 boost::container::small_vector<Tensor<1, spacedim>, 100>
868 merged_directions(surrounding_points.size(), Point<spacedim>());
869 boost::container::small_vector<double, 100> merged_distances(
870 surrounding_points.size(), 0.0);
871
872 unsigned int n_unique_directions = 0;
873 for (unsigned int i = 0; i < surrounding_points.size(); ++i)
874 {
875 bool found_duplicate = false;
876
877 // This inner loop is of @f$O(N^2)@f$ complexity, but
878 // surrounding_points.size() is usually at most 8 points large.
879 for (unsigned int j = 0; j < n_unique_directions; ++j)
880 {
881 const double squared_distance =
882 (directions[i] - directions[j]).norm_square();
883 if (!found_duplicate && squared_distance < 1e-28)
884 {
885 found_duplicate = true;
886 for (unsigned int row = 0; row < weight_rows; ++row)
887 merged_weights[row * weight_columns + j] +=
888 weights[row * weight_columns + i];
889 }
890 }
891
892 if (found_duplicate == false)
893 {
894 merged_directions[n_unique_directions] = directions[i];
895 merged_distances[n_unique_directions] = distances[i];
896 for (unsigned int row = 0; row < weight_rows; ++row)
897 merged_weights[row * weight_columns + n_unique_directions] =
898 weights[row * weight_columns + i];
899
900 ++n_unique_directions;
901 }
902 }
903
904 // Search for duplicate weight rows and merge them to minimize the cost of
905 // the get_new_point function call below.
906 boost::container::small_vector<unsigned int, 100> merged_weights_index(
907 new_points.size(), numbers::invalid_unsigned_int);
908 for (unsigned int row = 0; row < weight_rows; ++row)
909 {
910 for (unsigned int existing_row = 0; existing_row < row;
911 ++existing_row)
912 {
913 bool identical_weights = true;
914
915 for (unsigned int weight_index = 0;
916 weight_index < n_unique_directions;
917 ++weight_index)
918 if (std::abs(
919 merged_weights[row * weight_columns + weight_index] -
920 merged_weights[existing_row * weight_columns +
921 weight_index]) > tolerance)
922 {
923 identical_weights = false;
924 break;
925 }
926
927 if (identical_weights)
928 {
929 merged_weights_index[row] = existing_row;
930 break;
931 }
932 }
933 }
934
935 // Note that we only use the n_unique_directions first entries in the
936 // ArrayView
937 const ArrayView<const Tensor<1, spacedim>> array_merged_directions =
938 make_array_view(merged_directions.begin(),
939 merged_directions.begin() + n_unique_directions);
940 const ArrayView<const double> array_merged_distances =
941 make_array_view(merged_distances.begin(),
942 merged_distances.begin() + n_unique_directions);
943
944 for (unsigned int row = 0; row < weight_rows; ++row)
945 if (!accurate_point_was_found[row])
946 {
947 if (merged_weights_index[row] == numbers::invalid_unsigned_int)
948 {
949 const ArrayView<const double> array_merged_weights(
950 &merged_weights[row * weight_columns], n_unique_directions);
951 new_candidates[row].second =
952 internal::SphericalManifold::do_get_new_point(
953 array_merged_directions,
954 array_merged_distances,
955 array_merged_weights,
956 Point<spacedim>(new_candidates[row].second));
957 }
958 else
959 new_candidates[row].second =
960 new_candidates[merged_weights_index[row]].second;
961
962 new_points[row] =
963 p_center + new_candidates[row].first * new_candidates[row].second;
964 }
965 }
966}
967
968
969
970template <int dim, int spacedim>
971std::pair<double, Tensor<1, spacedim>>
973 const ArrayView<const Tensor<1, spacedim>> &directions,
974 const ArrayView<const double> &distances,
975 const ArrayView<const double> &weights) const
976{
977 const double tolerance = 1e-10;
978 double rho = 0.;
979 Tensor<1, spacedim> candidate;
980
981 // Perform a simple average ...
982 double total_weights = 0.;
983 for (unsigned int i = 0; i < directions.size(); ++i)
984 {
985 // if one weight is one, return its direction
986 if (std::abs(1 - weights[i]) < tolerance)
987 return std::make_pair(distances[i], directions[i]);
988
989 rho += distances[i] * weights[i];
990 candidate += directions[i] * weights[i];
991 total_weights += weights[i];
992 }
993
994 // ... and normalize if the candidate is different from the origin.
995 const double norm = candidate.norm();
996 if (norm == 0.)
997 return std::make_pair(0.0, Point<spacedim>());
998 candidate /= norm;
999 rho /= total_weights;
1000
1001 return std::make_pair(rho, candidate);
1002}
1003
1004
1005
1006// ============================================================
1007// CylindricalManifold
1008// ============================================================
1009template <int dim, int spacedim>
1011 const double tolerance)
1012 : CylindricalManifold<dim, spacedim>(Point<spacedim>::unit_vector(axis),
1013 Point<spacedim>(),
1014 tolerance)
1015{
1016 // do not use static_assert to make dimension-independent programming
1017 // easier.
1018 Assert(spacedim == 3,
1019 ExcMessage("CylindricalManifold can only be used for spacedim==3!"));
1020}
1021
1022
1023
1024template <int dim, int spacedim>
1026 const Tensor<1, spacedim> &direction,
1027 const Point<spacedim> &point_on_axis,
1028 const double tolerance)
1029 : ChartManifold<dim, spacedim, 3>(Tensor<1, 3>({0, 2. * numbers::PI, 0}))
1030 , normal_direction(internal::compute_normal(direction, true))
1031 , direction(direction / direction.norm())
1032 , point_on_axis(point_on_axis)
1033 , tolerance(tolerance)
1034 , dxn(cross_product_3d(this->direction, normal_direction))
1035{
1036 // do not use static_assert to make dimension-independent programming
1037 // easier.
1038 Assert(spacedim == 3,
1039 ExcMessage("CylindricalManifold can only be used for spacedim==3!"));
1040}
1041
1042
1043
1044template <int dim, int spacedim>
1045std::unique_ptr<Manifold<dim, spacedim>>
1047{
1048 return std::make_unique<CylindricalManifold<dim, spacedim>>(*this);
1049}
1050
1051
1052
1053template <int dim, int spacedim>
1056 const ArrayView<const Point<spacedim>> &surrounding_points,
1057 const ArrayView<const double> &weights) const
1058{
1059 Assert(spacedim == 3,
1060 ExcMessage("CylindricalManifold can only be used for spacedim==3!"));
1061
1062 // First check if the average in space lies on the axis.
1063 Point<spacedim> middle;
1064 double average_length = 0.;
1065 for (unsigned int i = 0; i < surrounding_points.size(); ++i)
1066 {
1067 middle += surrounding_points[i] * weights[i];
1068 average_length += surrounding_points[i].square() * weights[i];
1069 }
1070 middle -= point_on_axis;
1071 const double lambda = middle * direction;
1072
1073 if ((middle - direction * lambda).square() < tolerance * average_length)
1074 return point_on_axis + direction * lambda;
1075 else // If not, using the ChartManifold should yield valid results.
1076 return ChartManifold<dim, spacedim, 3>::get_new_point(surrounding_points,
1077 weights);
1078}
1079
1080
1081
1082template <int dim, int spacedim>
1085 const Point<spacedim> &space_point) const
1086{
1087 Assert(spacedim == 3,
1088 ExcMessage("CylindricalManifold can only be used for spacedim==3!"));
1089
1090 // First find the projection of the given point to the axis.
1091 const Tensor<1, spacedim> normalized_point = space_point - point_on_axis;
1092 const double lambda = normalized_point * direction;
1093 const Point<spacedim> projection = point_on_axis + direction * lambda;
1094 const Tensor<1, spacedim> p_diff = space_point - projection;
1095
1096 // Then compute the angle between the projection direction and
1097 // another vector orthogonal to the direction vector.
1098 const double phi = Physics::VectorRelations::signed_angle(normal_direction,
1099 p_diff,
1100 /*axis=*/direction);
1101
1102 // Return distance from the axis, angle and signed distance on the axis.
1103 return Point<3>(p_diff.norm(), phi, lambda);
1104}
1105
1106
1107
1108template <int dim, int spacedim>
1111 const Point<3> &chart_point) const
1112{
1113 Assert(spacedim == 3,
1114 ExcMessage("CylindricalManifold can only be used for spacedim==3!"));
1115
1116 // Rotate the orthogonal direction by the given angle
1117 const double sine_r = std::sin(chart_point[1]) * chart_point[0];
1118 const double cosine_r = std::cos(chart_point[1]) * chart_point[0];
1119 const Tensor<1, spacedim> intermediate =
1120 normal_direction * cosine_r + dxn * sine_r;
1121
1122 // Finally, put everything together.
1123 return point_on_axis + direction * chart_point[2] + intermediate;
1124}
1125
1126
1127
1128template <int dim, int spacedim>
1131 const Point<3> &chart_point) const
1132{
1133 Assert(spacedim == 3,
1134 ExcMessage("CylindricalManifold can only be used for spacedim==3!"));
1135
1136 Tensor<2, 3> derivatives;
1137
1138 // Rotate the orthogonal direction by the given angle
1139 const double sine = std::sin(chart_point[1]);
1140 const double cosine = std::cos(chart_point[1]);
1141 const Tensor<1, spacedim> intermediate =
1142 normal_direction * cosine + dxn * sine;
1143
1144 // avoid compiler warnings
1145 constexpr int s0 = 0 % spacedim;
1146 constexpr int s1 = 1 % spacedim;
1147 constexpr int s2 = 2 % spacedim;
1148
1149 // derivative w.r.t the radius
1150 derivatives[s0][s0] = intermediate[s0];
1151 derivatives[s1][s0] = intermediate[s1];
1152 derivatives[s2][s0] = intermediate[s2];
1153
1154 // derivatives w.r.t the angle: push_forward() scales the rotated direction
1155 // by the radius chart_point[0], so does its derivative
1156 const double sine_r = sine * chart_point[0];
1157 const double cosine_r = cosine * chart_point[0];
1158
1159 derivatives[s0][s1] = -normal_direction[s0] * sine_r + dxn[s0] * cosine_r;
1160 derivatives[s1][s1] = -normal_direction[s1] * sine_r + dxn[s1] * cosine_r;
1161 derivatives[s2][s1] = -normal_direction[s2] * sine_r + dxn[s2] * cosine_r;
1162
1163 // derivatives w.r.t the direction of the axis
1164 derivatives[s0][s2] = direction[s0];
1165 derivatives[s1][s2] = direction[s1];
1166 derivatives[s2][s2] = direction[s2];
1167
1168 return derivatives;
1169}
1170
1171
1172
1173namespace
1174{
1175 template <int dim>
1177 check_and_normalize(const Tensor<1, dim> &t)
1178 {
1179 const double norm = t.norm();
1180 Assert(norm > 0.0, ExcMessage("The major axis must have a positive norm."));
1181 return t / norm;
1182 }
1183} // namespace
1184
1185
1186
1187// ============================================================
1188// EllipticalManifold
1189// ============================================================
1190template <int dim, int spacedim>
1192 const Point<spacedim> &center,
1193 const Tensor<1, spacedim> &major_axis_direction,
1194 const double eccentricity)
1195 : ChartManifold<dim, spacedim, spacedim>(
1196 EllipticalManifold<dim, spacedim>::get_periodicity())
1197 , direction(check_and_normalize(major_axis_direction))
1198 , center(center)
1199 , eccentricity(eccentricity)
1200 , cosh_u(1.0 / eccentricity)
1201 , sinh_u(std::sqrt(cosh_u * cosh_u - 1.0))
1202{
1203 // Throws an exception if dim!=2 || spacedim!=2.
1204 Assert(dim == 2 && spacedim == 2, ExcNotImplemented());
1205 // Throws an exception if eccentricity is not in range.
1206 Assert(std::signbit(cosh_u * cosh_u - 1.0) == false,
1207 ExcMessage(
1208 "Invalid eccentricity: It must satisfy 0 < eccentricity < 1."));
1209}
1210
1211
1212
1213template <int dim, int spacedim>
1214std::unique_ptr<Manifold<dim, spacedim>>
1216{
1217 return std::make_unique<EllipticalManifold<dim, spacedim>>(*this);
1218}
1219
1220
1221
1222template <int dim, int spacedim>
1225{
1226 Tensor<1, spacedim> periodicity;
1227 // The second elliptical coordinate is periodic, while the first is not.
1228 // Enforce periodicity on the last variable.
1229 periodicity[spacedim - 1] = 2.0 * numbers::PI;
1230 return periodicity;
1231}
1232
1233
1234
1235template <int dim, int spacedim>
1242
1243
1244
1245template <>
1248{
1249 const double cs = std::cos(chart_point[1]);
1250 const double sn = std::sin(chart_point[1]);
1251 // Coordinates in the reference frame (i.e. major axis direction is
1252 // x-axis)
1253 const double x = chart_point[0] * cosh_u * cs;
1254 const double y = chart_point[0] * sinh_u * sn;
1255 // Rotate them according to the major axis direction
1256 const Point<2> p(direction[0] * x - direction[1] * y,
1257 direction[1] * x + direction[0] * y);
1258 return p + center;
1259}
1260
1261
1262
1263template <int dim, int spacedim>
1270
1271
1272
1273template <>
1276{
1277 // Moving space_point in the reference coordinate system.
1278 const double x0 = space_point[0] - center[0];
1279 const double y0 = space_point[1] - center[1];
1280 const double x = direction[0] * x0 + direction[1] * y0;
1281 const double y = -direction[1] * x0 + direction[0] * y0;
1282 const double pt0 =
1283 std::sqrt((x * x) / (cosh_u * cosh_u) + (y * y) / (sinh_u * sinh_u));
1284 // If the radius is exactly zero, the point coincides with the origin.
1285 if (pt0 == 0.0)
1286 {
1287 return center;
1288 }
1289 double cos_eta = x / (pt0 * cosh_u);
1290 if (cos_eta < -1.0)
1291 {
1292 cos_eta = -1.0;
1293 }
1294 if (cos_eta > 1.0)
1295 {
1296 cos_eta = 1.0;
1297 }
1298 const double eta = std::acos(cos_eta);
1299 const double pt1 = (std::signbit(y) ? 2.0 * numbers::PI - eta : eta);
1300 return {pt0, pt1};
1301}
1302
1303
1304
1305template <int dim, int spacedim>
1313
1314
1315
1316template <>
1319 const Point<2> &chart_point) const
1320{
1321 const double cs = std::cos(chart_point[1]);
1322 const double sn = std::sin(chart_point[1]);
1323 Tensor<2, 2> dX;
1324 dX[0][0] = cosh_u * cs;
1325 dX[0][1] = -chart_point[0] * cosh_u * sn;
1326 dX[1][0] = sinh_u * sn;
1327 dX[1][1] = chart_point[0] * sinh_u * cs;
1328
1329 // rotate according to the major axis direction
1331 {{+direction[0], -direction[1]}, {direction[1], direction[0]}}};
1332
1333 return rot * dX;
1334}
1335
1336
1337
1338// ============================================================
1339// FunctionManifold
1340// ============================================================
1341template <int dim, int spacedim, int chartdim>
1343 const Function<chartdim> &push_forward_function,
1344 const Function<spacedim> &pull_back_function,
1345 const Tensor<1, chartdim> &periodicity,
1346 const double tolerance)
1347 : ChartManifold<dim, spacedim, chartdim>(periodicity)
1348 , const_map()
1349 , push_forward_function(&push_forward_function)
1350 , pull_back_function(&pull_back_function)
1351 , tolerance(tolerance)
1352 , owns_pointers(false)
1353 , finite_difference_step(0)
1354{
1355 AssertDimension(push_forward_function.n_components, spacedim);
1356 AssertDimension(pull_back_function.n_components, chartdim);
1357}
1358
1359
1360
1361template <int dim, int spacedim, int chartdim>
1363 std::unique_ptr<Function<chartdim>> push_forward,
1364 std::unique_ptr<Function<spacedim>> pull_back,
1365 const Tensor<1, chartdim> &periodicity,
1366 const double tolerance)
1367 : ChartManifold<dim, spacedim, chartdim>(periodicity)
1368 , const_map()
1369 , push_forward_function(push_forward.release())
1370 , pull_back_function(pull_back.release())
1371 , tolerance(tolerance)
1372 , owns_pointers(true)
1373 , finite_difference_step(0)
1374{
1375 AssertDimension(push_forward_function->n_components, spacedim);
1376 AssertDimension(pull_back_function->n_components, chartdim);
1377}
1378
1379
1380
1381template <int dim, int spacedim, int chartdim>
1383 const std::string push_forward_expression,
1384 const std::string pull_back_expression,
1385 const Tensor<1, chartdim> &periodicity,
1386 const typename FunctionParser<spacedim>::ConstMap const_map,
1387 const std::string chart_vars,
1388 const std::string space_vars,
1389 const double tolerance,
1390 const double h)
1391 : ChartManifold<dim, spacedim, chartdim>(periodicity)
1392 , const_map(const_map)
1393 , tolerance(tolerance)
1394 , owns_pointers(true)
1395 , push_forward_expression(push_forward_expression)
1396 , pull_back_expression(pull_back_expression)
1397 , chart_vars(chart_vars)
1398 , space_vars(space_vars)
1399 , finite_difference_step(h)
1400{
1401 FunctionParser<chartdim> *pf = new FunctionParser<chartdim>(spacedim, 0.0, h);
1402 FunctionParser<spacedim> *pb = new FunctionParser<spacedim>(chartdim, 0.0, h);
1406 pull_back_function = pb;
1407}
1408
1409
1410
1411template <int dim, int spacedim, int chartdim>
1413{
1414 if (owns_pointers == true)
1415 {
1416 const Function<chartdim> *pf = push_forward_function;
1417 push_forward_function = nullptr;
1418 delete pf;
1419
1420 const Function<spacedim> *pb = pull_back_function;
1421 pull_back_function = nullptr;
1422 delete pb;
1423 }
1424}
1425
1426
1427
1428template <int dim, int spacedim, int chartdim>
1429std::unique_ptr<Manifold<dim, spacedim>>
1431{
1432 // This manifold can be constructed either by providing an expression for the
1433 // push forward and the pull back charts, or by providing two Function
1434 // objects. In the first case, the push_forward and pull_back functions are
1435 // created internally in FunctionManifold, and destroyed when this object is
1436 // deleted. In the second case, the function objects are destroyed if they
1437 // are passed as pointers upon construction.
1438 // We need to make sure that our cloned object is constructed in the
1439 // same way this class was constructed, and that its internal Function
1440 // pointers point either to the same Function objects used to construct this
1441 // function or that the newly generated manifold creates internally the
1442 // push_forward and pull_back functions using the same expressions that were
1443 // used to construct this class.
1444 if (!(push_forward_expression.empty() && pull_back_expression.empty()))
1445 {
1446 return std::make_unique<FunctionManifold<dim, spacedim, chartdim>>(
1447 push_forward_expression,
1448 pull_back_expression,
1449 this->get_periodicity(),
1450 const_map,
1451 chart_vars,
1452 space_vars,
1453 tolerance,
1454 finite_difference_step);
1455 }
1456 else
1457 {
1458 return std::make_unique<FunctionManifold<dim, spacedim, chartdim>>(
1459 *push_forward_function,
1460 *pull_back_function,
1461 this->get_periodicity(),
1462 tolerance);
1463 }
1464}
1465
1466
1467
1468template <int dim, int spacedim, int chartdim>
1471 const Point<chartdim> &chart_point) const
1472{
1473 Vector<double> pf(spacedim);
1474 Point<spacedim> result;
1475 push_forward_function->vector_value(chart_point, pf);
1476 for (unsigned int i = 0; i < spacedim; ++i)
1477 result[i] = pf[i];
1478
1479 if constexpr (running_in_debug_mode())
1480 {
1481 Vector<double> pb(chartdim);
1482 pull_back_function->vector_value(result, pb);
1483 for (unsigned int i = 0; i < chartdim; ++i)
1484 Assert(
1485 (chart_point.norm() > tolerance &&
1486 (std::abs(pb[i] - chart_point[i]) <
1487 tolerance * chart_point.norm())) ||
1488 (std::abs(pb[i] - chart_point[i]) < tolerance),
1489 ExcMessage(
1490 "The push forward is not the inverse of the pull back! Bailing out."));
1491 }
1492
1493 return result;
1494}
1495
1496
1497
1498template <int dim, int spacedim, int chartdim>
1501 const Point<chartdim> &chart_point) const
1502{
1504 for (unsigned int i = 0; i < spacedim; ++i)
1505 {
1506 const auto gradient = push_forward_function->gradient(chart_point, i);
1507 for (unsigned int j = 0; j < chartdim; ++j)
1508 DF[i][j] = gradient[j];
1509 }
1510 return DF;
1511}
1512
1513
1514
1515template <int dim, int spacedim, int chartdim>
1518 const Point<spacedim> &space_point) const
1519{
1520 Vector<double> pb(chartdim);
1521 Point<chartdim> result;
1522 pull_back_function->vector_value(space_point, pb);
1523 for (unsigned int i = 0; i < chartdim; ++i)
1524 result[i] = pb[i];
1525 return result;
1526}
1527
1528
1529
1530// ============================================================
1531// TorusManifold
1532// ============================================================
1533template <int dim>
1536{
1537 double x = p[0];
1538 double z = p[1];
1539 double y = p[2];
1540 double phi = std::atan2(y, x);
1541 double theta = std::atan2(z, std::sqrt(x * x + y * y) - centerline_radius);
1542 double w =
1543 std::sqrt(Utilities::fixed_power<2>(y - std::sin(phi) * centerline_radius) +
1544 Utilities::fixed_power<2>(x - std::cos(phi) * centerline_radius) +
1545 z * z) /
1546 inner_radius;
1547 return {phi, theta, w};
1548}
1549
1550
1551
1552template <int dim>
1555{
1556 double phi = chart_point[0];
1557 double theta = chart_point[1];
1558 double w = chart_point[2];
1559
1560 return {std::cos(phi) * centerline_radius +
1561 inner_radius * w * std::cos(theta) * std::cos(phi),
1562 inner_radius * w * std::sin(theta),
1563 std::sin(phi) * centerline_radius +
1564 inner_radius * w * std::cos(theta) * std::sin(phi)};
1565}
1566
1567
1568
1569template <int dim>
1570TorusManifold<dim>::TorusManifold(const double centerline_radius,
1571 const double inner_radius)
1572 : ChartManifold<dim, 3, 3>(Point<3>(2 * numbers::PI, 2 * numbers::PI, 0.0))
1573 , centerline_radius(centerline_radius)
1574 , inner_radius(inner_radius)
1575{
1577 ExcMessage("The centerline radius must be greater than the "
1578 "inner radius."));
1579 Assert(inner_radius > 0.0, ExcMessage("The inner radius must be positive."));
1580}
1581
1582
1583
1584template <int dim>
1585std::unique_ptr<Manifold<dim, 3>>
1587{
1588 return std::make_unique<TorusManifold<dim>>(centerline_radius, inner_radius);
1589}
1590
1591
1592
1593template <int dim>
1596{
1598
1599 double phi = chart_point[0];
1600 double theta = chart_point[1];
1601 double w = chart_point[2];
1602
1603 DX[0][0] = -std::sin(phi) * centerline_radius -
1604 inner_radius * w * std::cos(theta) * std::sin(phi);
1605 DX[0][1] = -inner_radius * w * std::sin(theta) * std::cos(phi);
1606 DX[0][2] = inner_radius * std::cos(theta) * std::cos(phi);
1607
1608 DX[1][0] = 0;
1609 DX[1][1] = inner_radius * w * std::cos(theta);
1610 DX[1][2] = inner_radius * std::sin(theta);
1611
1612 DX[2][0] = std::cos(phi) * centerline_radius +
1613 inner_radius * w * std::cos(theta) * std::cos(phi);
1614 DX[2][1] = -inner_radius * w * std::sin(theta) * std::sin(phi);
1615 DX[2][2] = inner_radius * std::cos(theta) * std::sin(phi);
1616
1617 return DX;
1618}
1619
1620
1621
1622// ============================================================
1623// TransfiniteInterpolationManifold
1624// ============================================================
1625template <int dim, int spacedim>
1628 : triangulation(nullptr)
1629 , level_coarse(-1)
1630{
1631 AssertThrow(dim > 1, ExcNotImplemented());
1632}
1633
1634
1635
1636template <int dim, int spacedim>
1638 spacedim>::~TransfiniteInterpolationManifold()
1639{
1640 if (clear_signal.connected())
1641 clear_signal.disconnect();
1642}
1643
1644
1645
1646template <int dim, int spacedim>
1647std::unique_ptr<Manifold<dim, spacedim>>
1649{
1651 if (triangulation)
1652 ptr->initialize(*triangulation);
1653 return std::unique_ptr<Manifold<dim, spacedim>>(ptr);
1654}
1655
1656
1657
1658template <int dim, int spacedim>
1659void
1661 const Triangulation<dim, spacedim> &triangulation)
1662{
1663 this->triangulation = &triangulation;
1664 // In case the triangulation is cleared, remove the pointers by a signal:
1665 clear_signal.disconnect();
1666 clear_signal = triangulation.signals.clear.connect([&]() -> void {
1667 this->triangulation = nullptr;
1668 this->level_coarse = -1;
1669 });
1670 level_coarse = triangulation.last()->level();
1671 coarse_cell_is_flat.resize(triangulation.n_cells(level_coarse), false);
1672 quadratic_approximation.clear();
1673
1674 // In case of dim == spacedim we perform a quadratic approximation in
1675 // InverseQuadraticApproximation(), thus initialize the unit_points
1676 // vector with one subdivision to get 3^dim unit_points.
1677 //
1678 // In the co-dimension one case (meaning dim < spacedim) we have to fall
1679 // back to a simple GridTools::affine_cell_approximation<dim>() which
1680 // requires 2^dim points, instead. Thus, initialize the QIterated
1681 // quadrature with no subdivisions.
1682 const std::vector<Point<dim>> unit_points =
1683 QIterated<dim>(QTrapezoid<1>(), (dim == spacedim ? 2 : 1)).get_points();
1684 std::vector<Point<spacedim>> real_points(unit_points.size());
1685
1686 for (const auto &cell : triangulation.active_cell_iterators())
1687 {
1688 bool cell_is_flat = true;
1689 for (const auto l : cell->line_indices())
1690 if (cell->line(l)->manifold_id() != cell->manifold_id() &&
1691 cell->line(l)->manifold_id() != numbers::flat_manifold_id)
1692 cell_is_flat = false;
1693 if constexpr (dim > 2)
1694 for (const auto q : cell->face_indices())
1695 if (cell->quad(q)->manifold_id() != cell->manifold_id() &&
1696 cell->quad(q)->manifold_id() != numbers::flat_manifold_id)
1697 cell_is_flat = false;
1698 AssertIndexRange(static_cast<unsigned int>(cell->index()),
1699 coarse_cell_is_flat.size());
1700 coarse_cell_is_flat[cell->index()] = cell_is_flat;
1701
1702 // build quadratic interpolation
1703 for (unsigned int i = 0; i < unit_points.size(); ++i)
1704 real_points[i] = push_forward(cell, unit_points[i]);
1705 quadratic_approximation.emplace_back(real_points, unit_points);
1706 }
1707}
1708
1709
1710
1711namespace
1712{
1713 // version for 1d
1714 template <typename AccessorType>
1716 compute_transfinite_interpolation(const AccessorType &cell,
1717 const Point<1> &chart_point,
1718 const bool /*cell_is_flat*/)
1719 {
1720 return cell.vertex(0) * (1. - chart_point[0]) +
1721 cell.vertex(1) * chart_point[0];
1722 }
1723
1724 // version for 2d
1725 template <typename AccessorType>
1727 compute_transfinite_interpolation(const AccessorType &cell,
1728 const Point<2> &chart_point,
1729 const bool cell_is_flat)
1730 {
1731 const unsigned int dim = AccessorType::dimension;
1732 const unsigned int spacedim = AccessorType::space_dimension;
1733 const types::manifold_id my_manifold_id = cell.manifold_id();
1735
1736 // formula see wikipedia
1737 // https://en.wikipedia.org/wiki/Transfinite_interpolation
1738 // S(u,v) = (1-v)c_1(u)+v c_3(u) + (1-u)c_2(v) + u c_4(v) -
1739 // [(1-u)(1-v)P_0 + u(1-v) P_1 + (1-u)v P_2 + uv P_3]
1740 const std::array<Point<spacedim>, 4> vertices{
1741 {cell.vertex(0), cell.vertex(1), cell.vertex(2), cell.vertex(3)}};
1742
1743 // this evaluates all bilinear shape functions because we need them
1744 // repeatedly. we will update this values in the complicated case with
1745 // curved lines below
1746 std::array<double, 4> weights_vertices{
1747 {(1. - chart_point[0]) * (1. - chart_point[1]),
1748 chart_point[0] * (1. - chart_point[1]),
1749 (1. - chart_point[0]) * chart_point[1],
1750 chart_point[0] * chart_point[1]}};
1751
1752 Point<spacedim> new_point;
1753 if (cell_is_flat)
1754 for (const unsigned int v : GeometryInfo<2>::vertex_indices())
1755 new_point += weights_vertices[v] * vertices[v];
1756 else
1757 {
1758 // The second line in the formula tells us to subtract the
1759 // contribution of the vertices. If a line employs the same manifold
1760 // as the cell, we can merge the weights of the line with the weights
1761 // of the vertex with a negative sign while going through the faces
1762 // (this is a bit artificial in 2d but it becomes clear in 3d where we
1763 // avoid looking at the faces' orientation and other complications).
1764
1765 // add the contribution from the lines around the cell (first line in
1766 // formula)
1767 std::array<double, GeometryInfo<2>::vertices_per_face> weights;
1768 std::array<Point<spacedim>, GeometryInfo<2>::vertices_per_face> points;
1769 // note that the views are immutable, but the arrays are not
1770 const auto weights_view =
1771 make_array_view(weights.begin(), weights.end());
1772 const auto points_view = make_array_view(points.begin(), points.end());
1773
1774 for (unsigned int line = 0; line < GeometryInfo<2>::lines_per_cell;
1775 ++line)
1776 {
1777 const double my_weight =
1778 (line % 2) ? chart_point[line / 2] : 1 - chart_point[line / 2];
1779 const double line_point = chart_point[1 - line / 2];
1780
1781 // Same manifold or invalid id which will go back to the same
1782 // class -> contribution should be added for the final point,
1783 // which means that we subtract the current weight from the
1784 // negative weight applied to the vertex
1785 const types::manifold_id line_manifold_id =
1786 cell.line(line)->manifold_id();
1787 if (line_manifold_id == my_manifold_id ||
1788 line_manifold_id == numbers::flat_manifold_id)
1789 {
1790 weights_vertices[GeometryInfo<2>::line_to_cell_vertices(line,
1791 0)] -=
1792 my_weight * (1. - line_point);
1793 weights_vertices[GeometryInfo<2>::line_to_cell_vertices(line,
1794 1)] -=
1795 my_weight * line_point;
1796 }
1797 else
1798 {
1799 points[0] =
1800 vertices[GeometryInfo<2>::line_to_cell_vertices(line, 0)];
1801 points[1] =
1802 vertices[GeometryInfo<2>::line_to_cell_vertices(line, 1)];
1803 weights[0] = 1. - line_point;
1804 weights[1] = line_point;
1805 new_point +=
1806 my_weight * tria.get_manifold(line_manifold_id)
1807 .get_new_point(points_view, weights_view);
1808 }
1809 }
1810
1811 // subtract contribution from the vertices (second line in formula)
1812 for (const unsigned int v : GeometryInfo<2>::vertex_indices())
1813 new_point -= weights_vertices[v] * vertices[v];
1814 }
1815
1816 return new_point;
1817 }
1818
1819 // this is replicated from GeometryInfo::face_to_cell_vertices since we need
1820 // it very often in compute_transfinite_interpolation and the function is
1821 // performance critical
1822 static constexpr unsigned int face_to_cell_vertices_3d[6][4] = {{0, 2, 4, 6},
1823 {1, 3, 5, 7},
1824 {0, 4, 1, 5},
1825 {2, 6, 3, 7},
1826 {0, 1, 2, 3},
1827 {4, 5, 6, 7}};
1828
1829 // this is replicated from GeometryInfo::face_to_cell_lines since we need it
1830 // very often in compute_transfinite_interpolation and the function is
1831 // performance critical
1832 static constexpr unsigned int face_to_cell_lines_3d[6][4] = {{8, 10, 0, 4},
1833 {9, 11, 1, 5},
1834 {2, 6, 8, 9},
1835 {3, 7, 10, 11},
1836 {0, 1, 2, 3},
1837 {4, 5, 6, 7}};
1838
1839 // version for 3d
1840 template <typename AccessorType>
1842 compute_transfinite_interpolation(const AccessorType &cell,
1843 const Point<3> &chart_point,
1844 const bool cell_is_flat)
1845 {
1846 const unsigned int dim = AccessorType::dimension;
1847 const unsigned int spacedim = AccessorType::space_dimension;
1848 const types::manifold_id my_manifold_id = cell.manifold_id();
1850
1851 // Same approach as in 2d, but adding the faces, subtracting the edges, and
1852 // adding the vertices
1853 const std::array<Point<spacedim>, 8> vertices{{cell.vertex(0),
1854 cell.vertex(1),
1855 cell.vertex(2),
1856 cell.vertex(3),
1857 cell.vertex(4),
1858 cell.vertex(5),
1859 cell.vertex(6),
1860 cell.vertex(7)}};
1861
1862 // store the components of the linear shape functions because we need them
1863 // repeatedly. we allow for 10 such shape functions to wrap around the
1864 // first four once again for easier face access.
1865 double linear_shapes[10];
1866 for (unsigned int d = 0; d < 3; ++d)
1867 {
1868 linear_shapes[2 * d] = 1. - chart_point[d];
1869 linear_shapes[2 * d + 1] = chart_point[d];
1870 }
1871
1872 // wrap linear shape functions around for access in face loop
1873 for (unsigned int d = 6; d < 10; ++d)
1874 linear_shapes[d] = linear_shapes[d - 6];
1875
1876 std::array<double, 8> weights_vertices;
1877 for (unsigned int i2 = 0, v = 0; i2 < 2; ++i2)
1878 for (unsigned int i1 = 0; i1 < 2; ++i1)
1879 for (unsigned int i0 = 0; i0 < 2; ++i0, ++v)
1880 weights_vertices[v] =
1881 (linear_shapes[4 + i2] * linear_shapes[2 + i1]) * linear_shapes[i0];
1882
1883 Point<spacedim> new_point;
1884 if (cell_is_flat)
1885 for (unsigned int v = 0; v < 8; ++v)
1886 new_point += weights_vertices[v] * vertices[v];
1887 else
1888 {
1889 // identify the weights for the lines to be accumulated (vertex
1890 // weights are set outside and coincide with the flat manifold case)
1891
1892 std::array<double, GeometryInfo<3>::lines_per_cell> weights_lines;
1893 std::fill(weights_lines.begin(), weights_lines.end(), 0.0);
1894
1895 // start with the contributions of the faces
1896 std::array<double, GeometryInfo<2>::vertices_per_cell> weights;
1897 std::array<Point<spacedim>, GeometryInfo<2>::vertices_per_cell> points;
1898 // note that the views are immutable, but the arrays are not
1899 const auto weights_view =
1900 make_array_view(weights.begin(), weights.end());
1901 const auto points_view = make_array_view(points.begin(), points.end());
1902
1903 for (const unsigned int face : GeometryInfo<3>::face_indices())
1904 {
1905 const double my_weight = linear_shapes[face];
1906 const unsigned int face_even = face - face % 2;
1907
1908 if (std::abs(my_weight) < 1e-13)
1909 continue;
1910
1911 // same manifold or invalid id which will go back to the same class
1912 // -> face will interpolate from the surrounding lines and vertices
1913 const types::manifold_id face_manifold_id =
1914 cell.face(face)->manifold_id();
1915 if (face_manifold_id == my_manifold_id ||
1916 face_manifold_id == numbers::flat_manifold_id)
1917 {
1918 for (unsigned int line = 0;
1919 line < GeometryInfo<2>::lines_per_cell;
1920 ++line)
1921 {
1922 const double line_weight =
1923 linear_shapes[face_even + 2 + line];
1924 weights_lines[face_to_cell_lines_3d[face][line]] +=
1925 my_weight * line_weight;
1926 }
1927 // as to the indices inside linear_shapes: we use the index
1928 // wrapped around at 2*d, ensuring the correct orientation of
1929 // the face's coordinate system with respect to the
1930 // lexicographic indices
1931 weights_vertices[face_to_cell_vertices_3d[face][0]] -=
1932 linear_shapes[face_even + 2] *
1933 (linear_shapes[face_even + 4] * my_weight);
1934 weights_vertices[face_to_cell_vertices_3d[face][1]] -=
1935 linear_shapes[face_even + 3] *
1936 (linear_shapes[face_even + 4] * my_weight);
1937 weights_vertices[face_to_cell_vertices_3d[face][2]] -=
1938 linear_shapes[face_even + 2] *
1939 (linear_shapes[face_even + 5] * my_weight);
1940 weights_vertices[face_to_cell_vertices_3d[face][3]] -=
1941 linear_shapes[face_even + 3] *
1942 (linear_shapes[face_even + 5] * my_weight);
1943 }
1944 else
1945 {
1946 for (const unsigned int v : GeometryInfo<2>::vertex_indices())
1947 points[v] = vertices[face_to_cell_vertices_3d[face][v]];
1948 weights[0] =
1949 linear_shapes[face_even + 2] * linear_shapes[face_even + 4];
1950 weights[1] =
1951 linear_shapes[face_even + 3] * linear_shapes[face_even + 4];
1952 weights[2] =
1953 linear_shapes[face_even + 2] * linear_shapes[face_even + 5];
1954 weights[3] =
1955 linear_shapes[face_even + 3] * linear_shapes[face_even + 5];
1956 new_point +=
1957 my_weight * tria.get_manifold(face_manifold_id)
1958 .get_new_point(points_view, weights_view);
1959 }
1960 }
1961
1962 // next subtract the contributions of the lines
1963 const auto weights_view_line =
1964 make_array_view(weights.begin(), weights.begin() + 2);
1965 const auto points_view_line =
1966 make_array_view(points.begin(), points.begin() + 2);
1967 for (unsigned int line = 0; line < GeometryInfo<3>::lines_per_cell;
1968 ++line)
1969 {
1970 const double line_point =
1971 (line < 8 ? chart_point[1 - (line % 4) / 2] : chart_point[2]);
1972 double my_weight = 0.;
1973 if (line < 8)
1974 my_weight = linear_shapes[line % 4] * linear_shapes[4 + line / 4];
1975 else
1976 {
1977 const unsigned int subline = line - 8;
1978 my_weight =
1979 linear_shapes[subline % 2] * linear_shapes[2 + subline / 2];
1980 }
1981 my_weight -= weights_lines[line];
1982
1983 if (std::abs(my_weight) < 1e-13)
1984 continue;
1985
1986 const types::manifold_id line_manifold_id =
1987 cell.line(line)->manifold_id();
1988 if (line_manifold_id == my_manifold_id ||
1989 line_manifold_id == numbers::flat_manifold_id)
1990 {
1991 weights_vertices[GeometryInfo<3>::line_to_cell_vertices(line,
1992 0)] -=
1993 my_weight * (1. - line_point);
1994 weights_vertices[GeometryInfo<3>::line_to_cell_vertices(line,
1995 1)] -=
1996 my_weight * (line_point);
1997 }
1998 else
1999 {
2000 points[0] =
2001 vertices[GeometryInfo<3>::line_to_cell_vertices(line, 0)];
2002 points[1] =
2003 vertices[GeometryInfo<3>::line_to_cell_vertices(line, 1)];
2004 weights[0] = 1. - line_point;
2005 weights[1] = line_point;
2006 new_point -= my_weight * tria.get_manifold(line_manifold_id)
2007 .get_new_point(points_view_line,
2008 weights_view_line);
2009 }
2010 }
2011
2012 // finally add the contribution of the
2013 for (const unsigned int v : GeometryInfo<dim>::vertex_indices())
2014 new_point += weights_vertices[v] * vertices[v];
2015 }
2016 return new_point;
2017 }
2018} // namespace
2019
2020
2021
2022template <int dim, int spacedim>
2026 const Point<dim> &chart_point) const
2027{
2028 AssertDimension(cell->level(), level_coarse);
2029
2030 // check that the point is in the unit cell which is the current chart
2031 // Tolerance 5e-4 chosen that the method also works with manifolds
2032 // that have some discretization error like SphericalManifold
2034 ExcMessage("chart_point is not in unit interval"));
2035
2036 return compute_transfinite_interpolation(*cell,
2037 chart_point,
2038 coarse_cell_is_flat[cell->index()]);
2039}
2040
2041
2042
2043template <int dim, int spacedim>
2047 const Point<dim> &chart_point,
2048 const Point<spacedim> &pushed_forward_chart_point) const
2049{
2050 // compute the derivative with the help of finite differences
2052 for (unsigned int d = 0; d < dim; ++d)
2053 {
2054 Point<dim> modified = chart_point;
2055 const double step = chart_point[d] > 0.5 ? -1e-8 : 1e-8;
2056
2057 // avoid checking outside of the unit interval
2058 modified[d] += step;
2059 Tensor<1, spacedim> difference =
2060 compute_transfinite_interpolation(*cell,
2061 modified,
2062 coarse_cell_is_flat[cell->index()]) -
2063 pushed_forward_chart_point;
2064 for (unsigned int e = 0; e < spacedim; ++e)
2065 grad[e][d] = difference[e] / step;
2066 }
2067 return grad;
2068}
2069
2070
2071
2072template <int dim, int spacedim>
2076 const Point<spacedim> &point,
2077 const Point<dim> &initial_guess) const
2078{
2079 Point<dim> outside;
2080 for (unsigned int d = 0; d < dim; ++d)
2082
2083 // project the user-given input to unit cell
2084 Point<dim> chart_point = cell->reference_cell().closest_point(initial_guess);
2085
2086 // run quasi-Newton iteration with a combination of finite differences for
2087 // the exact Jacobian and "Broyden's good method". As opposed to the various
2088 // mapping implementations, this class does not throw exception upon failure
2089 // as those are relatively expensive and failure occurs quite regularly in
2090 // the implementation of the compute_chart_points method.
2091 Tensor<1, spacedim> residual =
2092 point -
2093 compute_transfinite_interpolation(*cell,
2094 chart_point,
2095 coarse_cell_is_flat[cell->index()]);
2096 const double tolerance = 1e-21 * Utilities::fixed_power<2>(cell->diameter());
2097 double residual_norm_square = residual.norm_square();
2099 bool must_recompute_jacobian = true;
2100 for (unsigned int i = 0; i < 100; ++i)
2101 {
2102 if (residual_norm_square < tolerance)
2103 {
2104 // do a final update of the point with the last available Jacobian
2105 // information. The residual is close to zero due to the check
2106 // above, but me might improve some of the last digits by a final
2107 // Newton-like step with step length 1
2108 Tensor<1, dim> update;
2109 for (unsigned int d = 0; d < spacedim; ++d)
2110 for (unsigned int e = 0; e < dim; ++e)
2111 update[e] += inv_grad[d][e] * residual[d];
2112 return chart_point + update;
2113 }
2114
2115 // every 9 iterations, including the first time around, we create an
2116 // approximation of the Jacobian with finite differences. Broyden's
2117 // method usually does not need more than 5-8 iterations, but sometimes
2118 // we might have had a bad initial guess and then we can accelerate
2119 // convergence considerably with getting the actual Jacobian rather than
2120 // using secant-like methods (one gradient calculation in 3d costs as
2121 // much as 3 more iterations). this usually happens close to convergence
2122 // and one more step with the finite-differenced Jacobian leads to
2123 // convergence
2124 if (must_recompute_jacobian || i % 9 == 0)
2125 {
2126 // if the determinant is zero or negative, the mapping is either not
2127 // invertible or already has inverted and we are outside the valid
2128 // chart region. Note that the Jacobian here represents the
2129 // derivative of the forward map and should have a positive
2130 // determinant since we use properly oriented meshes.
2132 push_forward_gradient(cell,
2133 chart_point,
2134 Point<spacedim>(point - residual));
2135 if (grad.determinant() <= 0.0)
2136 return outside;
2137 inv_grad = grad.covariant_form();
2138 must_recompute_jacobian = false;
2139 }
2140 Tensor<1, dim> update;
2141 for (unsigned int d = 0; d < spacedim; ++d)
2142 for (unsigned int e = 0; e < dim; ++e)
2143 update[e] += inv_grad[d][e] * residual[d];
2144
2145 // Line search, accept step if the residual has decreased
2146 double alpha = 1.;
2147
2148 // check if point is inside 1.2 times the unit cell to avoid
2149 // hitting points very far away from valid ones in the manifolds
2150 while (
2151 !GeometryInfo<dim>::is_inside_unit_cell(chart_point + alpha * update,
2152 0.2) &&
2153 alpha > 1e-7)
2154 alpha *= 0.5;
2155
2156 const Tensor<1, spacedim> old_residual = residual;
2157 while (alpha > 1e-4)
2158 {
2159 Point<dim> guess = chart_point + alpha * update;
2160 const Tensor<1, spacedim> residual_guess =
2161 point - compute_transfinite_interpolation(
2162 *cell, guess, coarse_cell_is_flat[cell->index()]);
2163 const double residual_norm_new = residual_guess.norm_square();
2164 if (residual_norm_new < residual_norm_square)
2165 {
2166 residual = residual_guess;
2167 residual_norm_square = residual_norm_new;
2168 chart_point += alpha * update;
2169 break;
2170 }
2171 else
2172 alpha *= 0.5;
2173 }
2174 // If alpha got very small, it is likely due to a bad Jacobian
2175 // approximation with Broyden's method (relatively far away from the
2176 // zero), which can be corrected by the outer loop when a Newton update
2177 // is recomputed. The second case is when the Jacobian is actually bad
2178 // and we should fail as early as possible. Since we cannot really
2179 // distinguish the two, we must continue here in any case.
2180 if (alpha <= 1e-4)
2181 must_recompute_jacobian = true;
2182
2183 // update the inverse Jacobian with "Broyden's good method" and
2184 // Sherman-Morrison formula for the update of the inverse, see
2185 // https://en.wikipedia.org/wiki/Broyden%27s_method
2186 // J^{-1}_n = J^{-1}_{n-1} + (delta x_n - J^{-1}_{n-1} delta f_n) /
2187 // (delta x_n^T J_{-1}_{n-1} delta f_n) delta x_n^T J^{-1}_{n-1}
2188
2189 // switch sign in residual as compared to the formula above because we
2190 // use a negative definition of the residual with respect to the
2191 // Jacobian
2192 const Tensor<1, spacedim> delta_f = old_residual - residual;
2193
2194 Tensor<1, dim> Jinv_deltaf;
2195 for (unsigned int d = 0; d < spacedim; ++d)
2196 for (unsigned int e = 0; e < dim; ++e)
2197 Jinv_deltaf[e] += inv_grad[d][e] * delta_f[d];
2198
2199 const Tensor<1, dim> delta_x = alpha * update;
2200
2201 // prevent division by zero. This number should be scale-invariant
2202 // because Jinv_deltaf carries no units and x is in reference
2203 // coordinates.
2204 if (std::abs(delta_x * Jinv_deltaf) > 1e-12 && !must_recompute_jacobian)
2205 {
2206 const Tensor<1, dim> factor =
2207 (delta_x - Jinv_deltaf) / (delta_x * Jinv_deltaf);
2208 Tensor<1, spacedim> jac_update;
2209 for (unsigned int d = 0; d < spacedim; ++d)
2210 for (unsigned int e = 0; e < dim; ++e)
2211 jac_update[d] += delta_x[e] * inv_grad[d][e];
2212 for (unsigned int d = 0; d < spacedim; ++d)
2213 for (unsigned int e = 0; e < dim; ++e)
2214 inv_grad[d][e] += factor[e] * jac_update[d];
2215 }
2216 }
2217 return outside;
2218}
2219
2220
2221
2222template <int dim, int spacedim>
2223std::array<unsigned int, 20>
2226 const ArrayView<const Point<spacedim>> &points) const
2227{
2228 // The methods to identify cells around points in GridTools are all written
2229 // for the active cells, but we are here looking at some cells at the coarse
2230 // level.
2231 Assert(triangulation != nullptr, ExcNotInitialized());
2232 Assert(triangulation->begin_active()->level() >= level_coarse,
2233 ExcMessage("The manifold was initialized with level " +
2234 std::to_string(level_coarse) + " but there are now" +
2235 "active cells on a lower level. Coarsening the mesh is " +
2236 "currently not supported"));
2237
2238 // This computes the distance of the surrounding points transformed to the
2239 // unit cell from the unit cell.
2241 triangulation->begin(
2242 level_coarse),
2243 endc =
2244 triangulation->end(
2245 level_coarse);
2246 boost::container::small_vector<std::pair<double, unsigned int>, 200>
2247 distances_and_cells;
2248 for (; cell != endc; ++cell)
2249 {
2250 // only consider cells where the current manifold is attached
2251 if (&cell->get_manifold() != this)
2252 continue;
2253
2254 std::array<Point<spacedim>, GeometryInfo<dim>::vertices_per_cell>
2255 vertices;
2256 for (const unsigned int vertex_n : GeometryInfo<dim>::vertex_indices())
2257 {
2258 vertices[vertex_n] = cell->vertex(vertex_n);
2259 }
2260
2261 // cheap check: if any of the points is not inside a circle around the
2262 // center of the loop, we can skip the expensive part below (this assumes
2263 // that the manifold does not deform the grid too much)
2264 Point<spacedim> center;
2265 for (const unsigned int v : GeometryInfo<dim>::vertex_indices())
2266 center += vertices[v];
2268 double radius_square = 0.;
2269 for (const unsigned int v : GeometryInfo<dim>::vertex_indices())
2270 radius_square =
2271 std::max(radius_square, (center - vertices[v]).norm_square());
2272 bool inside_circle = true;
2273 for (unsigned int i = 0; i < points.size(); ++i)
2274 if ((center - points[i]).norm_square() > radius_square * 1.5)
2275 {
2276 inside_circle = false;
2277 break;
2278 }
2279 if (inside_circle == false)
2280 continue;
2281
2282 // slightly more expensive search
2283 double current_distance = 0;
2284 for (unsigned int i = 0; i < points.size(); ++i)
2285 {
2286 Point<dim> point =
2287 quadratic_approximation[cell->index()].compute(points[i]);
2288 current_distance += GeometryInfo<dim>::distance_to_unit_cell(point);
2289 }
2290 distances_and_cells.push_back(
2291 std::make_pair(current_distance, cell->index()));
2292 }
2293 // no coarse cell could be found -> transformation failed
2294 AssertThrow(distances_and_cells.size() > 0,
2296 std::sort(distances_and_cells.begin(), distances_and_cells.end());
2297 std::array<unsigned int, 20> cells;
2299 for (unsigned int i = 0; i < distances_and_cells.size() && i < cells.size();
2300 ++i)
2301 cells[i] = distances_and_cells[i].second;
2302
2303 return cells;
2304}
2305
2306
2307
2308template <int dim, int spacedim>
2311 const ArrayView<const Point<spacedim>> &surrounding_points,
2312 ArrayView<Point<dim>> chart_points) const
2313{
2314 Assert(surrounding_points.size() == chart_points.size(),
2315 ExcMessage("The chart points array view must be as large as the "
2316 "surrounding points array view."));
2317
2318 std::array<unsigned int, 20> nearby_cells =
2319 get_possible_cells_around_points(surrounding_points);
2320
2321 // This function is nearly always called to place new points on a cell or
2322 // cell face. In this case, the general structure of the surrounding points
2323 // is known (i.e., if there are eight surrounding points, then they will
2324 // almost surely be either eight points around a quadrilateral or the eight
2325 // vertices of a cube). Hence, making this assumption, we use two
2326 // optimizations (one for structdim == 2 and one for structdim == 3) that
2327 // guess the locations of some of the chart points more efficiently than the
2328 // affine map approximation. The affine map approximation is used whenever
2329 // we don't have a cheaper guess available.
2330
2331 // Function that can guess the location of a chart point by assuming that
2332 // the eight surrounding points are points on a two-dimensional object
2333 // (either a cell in 2d or the face of a hexahedron in 3d), arranged like
2334 //
2335 // 2 - 7 - 3
2336 // | |
2337 // 4 5
2338 // | |
2339 // 0 - 6 - 1
2340 //
2341 // This function assumes that the first three chart points have been
2342 // computed since there is no effective way to guess them.
2343 auto guess_chart_point_structdim_2 = [&](const unsigned int i) -> Point<dim> {
2344 Assert(surrounding_points.size() == 8 && 2 < i && i < 8,
2345 ExcMessage("This function assumes that there are eight surrounding "
2346 "points around a two-dimensional object. It also assumes "
2347 "that the first three chart points have already been "
2348 "computed."));
2349 switch (i)
2350 {
2351 case 0:
2352 case 1:
2353 case 2:
2355 break;
2356 case 3:
2357 return chart_points[1] + (chart_points[2] - chart_points[0]);
2358 case 4:
2359 return 0.5 * (chart_points[0] + chart_points[2]);
2360 case 5:
2361 return 0.5 * (chart_points[1] + chart_points[3]);
2362 case 6:
2363 return 0.5 * (chart_points[0] + chart_points[1]);
2364 case 7:
2365 return 0.5 * (chart_points[2] + chart_points[3]);
2366 default:
2368 }
2369
2370 return {};
2371 };
2372
2373 // Function that can guess the location of a chart point by assuming that
2374 // the eight surrounding points form the vertices of a hexahedron, arranged
2375 // like
2376 //
2377 // 6-------7
2378 // /| /|
2379 // / / |
2380 // / | / |
2381 // 4-------5 |
2382 // | 2- -|- -3
2383 // | / | /
2384 // | | /
2385 // |/ |/
2386 // 0-------1
2387 //
2388 // (where vertex 2 is the back left vertex) we can estimate where chart
2389 // points 5 - 7 are by computing the height (in chart coordinates) as c4 -
2390 // c0 and then adding that onto the appropriate bottom vertex.
2391 //
2392 // This function assumes that the first five chart points have been computed
2393 // since there is no effective way to guess them.
2394 auto guess_chart_point_structdim_3 = [&](const unsigned int i) -> Point<dim> {
2395 Assert(surrounding_points.size() == 8 && 4 < i && i < 8,
2396 ExcMessage("This function assumes that there are eight surrounding "
2397 "points around a three-dimensional object. It also "
2398 "assumes that the first five chart points have already "
2399 "been computed."));
2400 return chart_points[i - 4] + (chart_points[4] - chart_points[0]);
2401 };
2402
2403 // Check if we can use the two chart point shortcuts above before we start:
2404 bool use_structdim_2_guesses = false;
2405 bool use_structdim_3_guesses = false;
2406 // note that in the structdim 2 case: 0 - 6 and 2 - 7 should be roughly
2407 // parallel, while in the structdim 3 case, 0 - 6 and 2 - 7 should be roughly
2408 // orthogonal. Use the angle between these two vectors to figure out if we
2409 // should turn on either structdim optimization.
2410 if (surrounding_points.size() == 8)
2411 {
2412 const Tensor<1, spacedim> v06 =
2413 surrounding_points[6] - surrounding_points[0];
2414 const Tensor<1, spacedim> v27 =
2415 surrounding_points[7] - surrounding_points[2];
2416
2417 // note that we can save a call to sqrt() by rearranging
2418 const double cosine = scalar_product(v06, v27) /
2419 std::sqrt(v06.norm_square() * v27.norm_square());
2420 if (0.707 < cosine)
2421 // the angle is less than pi/4, so these vectors are roughly parallel:
2422 // enable the structdim 2 optimization
2423 use_structdim_2_guesses = true;
2424 else if (spacedim == 3)
2425 // otherwise these vectors are roughly orthogonal: enable the
2426 // structdim 3 optimization if we are in 3d
2427 use_structdim_3_guesses = true;
2428 }
2429 // we should enable at most one of the optimizations
2430 Assert((!use_structdim_2_guesses && !use_structdim_3_guesses) ||
2431 (use_structdim_2_guesses ^ use_structdim_3_guesses),
2433
2434
2435
2436 auto compute_chart_point =
2437 [&](const typename Triangulation<dim, spacedim>::cell_iterator &cell,
2438 const unsigned int point_index) {
2439 Point<dim> guess;
2440 // an optimization: keep track of whether or not we used the quadratic
2441 // approximation so that we don't call pull_back with the same
2442 // initial guess twice (i.e., if pull_back fails the first time,
2443 // don't try again with the same function arguments).
2444 bool used_quadratic_approximation = false;
2445 // if we have already computed three points, we can guess the fourth
2446 // to be the missing corner point of a rectangle
2447 if (point_index == 3 && surrounding_points.size() >= 8)
2448 guess = chart_points[1] + (chart_points[2] - chart_points[0]);
2449 else if (use_structdim_2_guesses && 3 < point_index)
2450 guess = guess_chart_point_structdim_2(point_index);
2451 else if (use_structdim_3_guesses && 4 < point_index)
2452 guess = guess_chart_point_structdim_3(point_index);
2453 else if (dim == 3 && point_index > 7 && surrounding_points.size() == 26)
2454 {
2455 if (point_index < 20)
2456 guess =
2457 0.5 * (chart_points[GeometryInfo<dim>::line_to_cell_vertices(
2458 point_index - 8, 0)] +
2460 point_index - 8, 1)]);
2461 else
2462 guess =
2463 0.25 * (chart_points[GeometryInfo<dim>::face_to_cell_vertices(
2464 point_index - 20, 0)] +
2466 point_index - 20, 1)] +
2468 point_index - 20, 2)] +
2470 point_index - 20, 3)]);
2471 }
2472 else
2473 {
2474 guess = quadratic_approximation[cell->index()].compute(
2475 surrounding_points[point_index]);
2476 used_quadratic_approximation = true;
2477 }
2478 chart_points[point_index] =
2479 pull_back(cell, surrounding_points[point_index], guess);
2480
2481 // the initial guess may not have been good enough: if applicable,
2482 // try again with the affine approximation (which is more accurate
2483 // than the cheap methods used above)
2484 if (chart_points[point_index][0] ==
2486 !used_quadratic_approximation)
2487 {
2488 guess = quadratic_approximation[cell->index()].compute(
2489 surrounding_points[point_index]);
2490 chart_points[point_index] =
2491 pull_back(cell, surrounding_points[point_index], guess);
2492 }
2493
2494 if (chart_points[point_index][0] ==
2496 {
2497 for (unsigned int d = 0; d < dim; ++d)
2498 guess[d] = 0.5;
2499 chart_points[point_index] =
2500 pull_back(cell, surrounding_points[point_index], guess);
2501 }
2502 };
2503
2504 // check whether all points are inside the unit cell of the current chart
2505 for (unsigned int c = 0; c < nearby_cells.size(); ++c)
2506 {
2508 triangulation, level_coarse, nearby_cells[c]);
2509 bool inside_unit_cell = true;
2510 for (unsigned int i = 0; i < surrounding_points.size(); ++i)
2511 {
2512 compute_chart_point(cell, i);
2513
2514 // Tolerance 5e-4 chosen that the method also works with manifolds
2515 // that have some discretization error like SphericalManifold
2516 if (GeometryInfo<dim>::is_inside_unit_cell(chart_points[i], 5e-4) ==
2517 false)
2518 {
2519 inside_unit_cell = false;
2520 break;
2521 }
2522 }
2523 if (inside_unit_cell == true)
2524 {
2525 return cell;
2526 }
2527
2528 // if we did not find a point and this was the last valid cell (the next
2529 // iterate being the end of the array or an invalid tag), we must stop
2530 if (c == nearby_cells.size() - 1 ||
2531 nearby_cells[c + 1] == numbers::invalid_unsigned_int)
2532 {
2533 // generate additional information to help debugging why we did not
2534 // get a point
2535 std::ostringstream message;
2536 for (unsigned int b = 0; b <= c; ++b)
2537 {
2539 triangulation, level_coarse, nearby_cells[b]);
2540 message << "Looking at cell " << cell->id()
2541 << " with vertices: " << std::endl;
2542 for (const unsigned int v : GeometryInfo<dim>::vertex_indices())
2543 message << cell->vertex(v) << " ";
2544 message << std::endl;
2545 message << "Transformation to chart coordinates: " << std::endl;
2546 for (unsigned int i = 0; i < surrounding_points.size(); ++i)
2547 {
2548 compute_chart_point(cell, i);
2549 message << surrounding_points[i] << " -> " << chart_points[i]
2550 << std::endl;
2551 }
2552 }
2553
2554 AssertThrow(false,
2556 message.str())));
2557 }
2558 }
2559
2560 // a valid inversion should have returned a point above. an invalid
2561 // inversion should have triggered the assertion, so we should never end up
2562 // here
2565}
2566
2567
2568
2569template <int dim, int spacedim>
2572 const ArrayView<const Point<spacedim>> &surrounding_points,
2573 const ArrayView<const double> &weights) const
2574{
2575 boost::container::small_vector<Point<dim>, 100> chart_points(
2576 surrounding_points.size());
2577 ArrayView<Point<dim>> chart_points_view =
2578 make_array_view(chart_points.begin(), chart_points.end());
2579 const auto cell = compute_chart_points(surrounding_points, chart_points_view);
2580
2581 const Point<dim> p_chart =
2582 chart_manifold.get_new_point(chart_points_view, weights);
2583
2584 return push_forward(cell, p_chart);
2585}
2586
2587
2588
2589template <int dim, int spacedim>
2590void
2592 const ArrayView<const Point<spacedim>> &surrounding_points,
2593 const Table<2, double> &weights,
2594 ArrayView<Point<spacedim>> new_points) const
2595{
2596 Assert(weights.size(0) > 0, ExcEmptyObject());
2597 AssertDimension(surrounding_points.size(), weights.size(1));
2598
2599 boost::container::small_vector<Point<dim>, 100> chart_points(
2600 surrounding_points.size());
2601 ArrayView<Point<dim>> chart_points_view =
2602 make_array_view(chart_points.begin(), chart_points.end());
2603 const auto cell = compute_chart_points(surrounding_points, chart_points_view);
2604
2605 boost::container::small_vector<Point<dim>, 100> new_points_on_chart(
2606 weights.size(0));
2607 chart_manifold.get_new_points(chart_points_view,
2608 weights,
2609 make_array_view(new_points_on_chart.begin(),
2610 new_points_on_chart.end()));
2611
2612 for (unsigned int row = 0; row < weights.size(0); ++row)
2613 new_points[row] = push_forward(cell, new_points_on_chart[row]);
2614}
2615
2616
2617
2618// explicit instantiations
2619#include "grid/manifold_lib.inst"
2620
ArrayView< std::remove_reference_t< typename std::iterator_traits< Iterator >::reference >, MemorySpaceType > make_array_view(const Iterator begin, const Iterator end)
std::size_t size() const
Definition array_view.h:737
virtual Point< spacedim > get_new_point(const ArrayView< const Point< spacedim > > &surrounding_points, const ArrayView< const double > &weights) const override
Definition manifold.cc:1035
virtual Point< spacedim > push_forward(const Point< 3 > &chart_point) const override
virtual DerivativeForm< 1, 3, spacedim > push_forward_gradient(const Point< 3 > &chart_point) const override
virtual Point< spacedim > get_new_point(const ArrayView< const Point< spacedim > > &surrounding_points, const ArrayView< const double > &weights) const override
virtual std::unique_ptr< Manifold< dim, spacedim > > clone() const override
CylindricalManifold(const unsigned int axis=0, const double tolerance=1e-10)
virtual Point< 3 > pull_back(const Point< spacedim > &space_point) const override
Number determinant() const
DerivativeForm< 1, dim, spacedim, Number > covariant_form() const
virtual std::unique_ptr< Manifold< dim, spacedim > > clone() const override
virtual Point< spacedim > push_forward(const Point< spacedim > &chart_point) const override
EllipticalManifold(const Point< spacedim > &center, const Tensor< 1, spacedim > &major_axis_direction, const double eccentricity)
virtual DerivativeForm< 1, spacedim, spacedim > push_forward_gradient(const Point< spacedim > &chart_point) const override
virtual Point< spacedim > pull_back(const Point< spacedim > &space_point) const override
static Tensor< 1, spacedim > get_periodicity()
const double cosh_u
const FunctionParser< spacedim >::ConstMap const_map
const std::string chart_vars
const std::string pull_back_expression
virtual DerivativeForm< 1, chartdim, spacedim > push_forward_gradient(const Point< chartdim > &chart_point) const override
const std::string space_vars
virtual Point< spacedim > push_forward(const Point< chartdim > &chart_point) const override
FunctionManifold(const Function< chartdim > &push_forward_function, const Function< spacedim > &pull_back_function, const Tensor< 1, chartdim > &periodicity=Tensor< 1, chartdim >(), const double tolerance=1e-10)
virtual std::unique_ptr< Manifold< dim, spacedim > > clone() const override
const std::string push_forward_expression
virtual Point< chartdim > pull_back(const Point< spacedim > &space_point) const override
ObserverPointer< const Function< chartdim >, FunctionManifold< dim, spacedim, chartdim > > push_forward_function
ObserverPointer< const Function< spacedim >, FunctionManifold< dim, spacedim, chartdim > > pull_back_function
virtual ~FunctionManifold() override
virtual void initialize(const std::string &vars, const std::vector< std::string > &expressions, const ConstMap &constants, const bool time_dependent=false) override
std::map< std::string, double > ConstMap
virtual void get_normals_at_vertices(const typename Triangulation< dim, spacedim >::face_iterator &face, FaceVertexNormals &face_vertex_normals) const
std::array< Tensor< 1, spacedim >, GeometryInfo< dim >::vertices_per_face > FaceVertexNormals
Definition manifold.h:304
virtual Tensor< 1, spacedim > normal_vector(const typename Triangulation< dim, spacedim >::face_iterator &face, const Point< spacedim > &p) const
virtual Point< spacedim > get_new_point(const ArrayView< const Point< spacedim > > &surrounding_points, const ArrayView< const double > &weights) const
Abstract base class for mapping classes.
Definition mapping.h:318
Definition point.h:111
PolarManifold(const Point< spacedim > center=Point< spacedim >())
static Tensor< 1, spacedim > get_periodicity()
virtual std::unique_ptr< Manifold< dim, spacedim > > clone() const override
virtual DerivativeForm< 1, spacedim, spacedim > push_forward_gradient(const Point< spacedim > &chart_point) const override
virtual Tensor< 1, spacedim > normal_vector(const typename Triangulation< dim, spacedim >::face_iterator &face, const Point< spacedim > &p) const override
virtual Point< spacedim > push_forward(const Point< spacedim > &chart_point) const override
virtual Point< spacedim > pull_back(const Point< spacedim > &space_point) const override
virtual Point< spacedim > get_new_point(const ArrayView< const Point< spacedim > > &vertices, const ArrayView< const double > &weights) const override
virtual std::unique_ptr< Manifold< dim, spacedim > > clone() const override
virtual Point< spacedim > get_intermediate_point(const Point< spacedim > &p1, const Point< spacedim > &p2, const double w) const override
virtual void get_normals_at_vertices(const typename Triangulation< dim, spacedim >::face_iterator &face, typename Manifold< dim, spacedim >::FaceVertexNormals &face_vertex_normals) const override
std::pair< double, Tensor< 1, spacedim > > guess_new_point(const ArrayView< const Tensor< 1, spacedim > > &directions, const ArrayView< const double > &distances, const ArrayView< const double > &weights) const
virtual void get_new_points(const ArrayView< const Point< spacedim > > &surrounding_points, const Table< 2, double > &weights, ArrayView< Point< spacedim > > new_points) const override
SphericalManifold(const Point< spacedim > center=Point< spacedim >())
virtual Tensor< 1, spacedim > get_tangent_vector(const Point< spacedim > &x1, const Point< spacedim > &x2) const override
virtual Tensor< 1, spacedim > normal_vector(const typename Triangulation< dim, spacedim >::face_iterator &face, const Point< spacedim > &p) const override
void do_get_new_points(const ArrayView< const Point< spacedim > > &surrounding_points, const ArrayView< const double > &weights, ArrayView< Point< spacedim > > new_points) const
numbers::NumberTraits< Number >::real_type norm() const
constexpr numbers::NumberTraits< Number >::real_type norm_square() const
virtual Point< 3 > pull_back(const Point< 3 > &p) const override
double inner_radius
virtual DerivativeForm< 1, 3, 3 > push_forward_gradient(const Point< 3 > &chart_point) const override
virtual Point< 3 > push_forward(const Point< 3 > &chart_point) const override
double centerline_radius
TorusManifold(const double centerline_radius, const double inner_radius)
virtual std::unique_ptr< Manifold< dim, 3 > > clone() const override
DerivativeForm< 1, dim, spacedim > push_forward_gradient(const typename Triangulation< dim, spacedim >::cell_iterator &cell, const Point< dim > &chart_point, const Point< spacedim > &pushed_forward_chart_point) const
void initialize(const Triangulation< dim, spacedim > &triangulation)
Triangulation< dim, spacedim >::cell_iterator compute_chart_points(const ArrayView< const Point< spacedim > > &surrounding_points, ArrayView< Point< dim > > chart_points) const
std::array< unsigned int, 20 > get_possible_cells_around_points(const ArrayView< const Point< spacedim > > &surrounding_points) const
Point< dim > pull_back(const typename Triangulation< dim, spacedim >::cell_iterator &cell, const Point< spacedim > &p, const Point< dim > &initial_guess) const
virtual void get_new_points(const ArrayView< const Point< spacedim > > &surrounding_points, const Table< 2, double > &weights, ArrayView< Point< spacedim > > new_points) const override
virtual Point< spacedim > get_new_point(const ArrayView< const Point< spacedim > > &surrounding_points, const ArrayView< const double > &weights) const override
Point< spacedim > push_forward(const typename Triangulation< dim, spacedim >::cell_iterator &cell, const Point< dim > &chart_point) const
virtual std::unique_ptr< Manifold< dim, spacedim > > clone() const override
cell_iterator last() const
unsigned int n_cells() const
Triangulation< dim, spacedim > & get_triangulation()
Signals signals
Definition tria.h:2606
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:38
#define DEAL_II_DISABLE_EXTRA_DIAGNOSTICS
Definition config.h:636
constexpr bool running_in_debug_mode()
Definition config.h:76
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:39
#define DEAL_II_ENABLE_EXTRA_DIAGNOSTICS
Definition config.h:680
#define DEAL_II_ASSERT_UNREACHABLE()
#define DEAL_II_NOT_IMPLEMENTED()
Point< 2 > second
Definition grid_out.cc:4640
Point< 2 > first
Definition grid_out.cc:4639
unsigned int vertex_indices[2]
const unsigned int v1
IteratorRange< active_cell_iterator > active_cell_iterators() const
static ::ExceptionBase & ExcNotImplemented()
static ::ExceptionBase & ExcEmptyObject()
#define Assert(cond, exc)
static ::ExceptionBase & ExcImpossibleInDim(int arg1)
#define AssertDimension(dim1, dim2)
#define AssertIndexRange(index, range)
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcNotInitialized()
static ::ExceptionBase & ExcMessage(std::string arg1)
#define AssertThrow(cond, exc)
TriaIterator< CellAccessor< dim, spacedim > > cell_iterator
Definition tria.h:1639
const Manifold< dim, spacedim > & get_manifold(const types::manifold_id number) const
SymmetricTensor< 2, dim, Number > d(const Tensor< 2, dim, Number > &F, const Tensor< 2, dim, Number > &dF_dt)
Number signed_angle(const Tensor< 1, spacedim, Number > &a, const Tensor< 1, spacedim, Number > &b, const Tensor< 1, spacedim, Number > &axis)
Tensor< 1, 3 > projected_direction(const Tensor< 1, 3 > &u, const Tensor< 1, 3 > &v)
Tensor< 1, 3 > apply_exponential_map(const Tensor< 1, 3 > &u, const Tensor< 1, 3 > &dir)
static constexpr double invalid_pull_back_coordinate
Point< spacedim > compute_normal(const Tensor< 1, spacedim > &, bool=false)
constexpr double PI
Definition numbers.h:246
constexpr unsigned int invalid_unsigned_int
Definition types.h:228
constexpr types::manifold_id flat_manifold_id
Definition types.h:332
STL namespace.
::VectorizedArray< Number, width > max(const ::VectorizedArray< Number, width > &, const ::VectorizedArray< Number, width > &)
::VectorizedArray< Number, width > cos(const ::VectorizedArray< Number, width > &)
::VectorizedArray< Number, width > sin(const ::VectorizedArray< Number, width > &)
::VectorizedArray< Number, width > sqrt(const ::VectorizedArray< Number, width > &)
::VectorizedArray< Number, width > abs(const ::VectorizedArray< Number, width > &)
inline ::VectorizedArray< Number, width > acos(const ::VectorizedArray< Number, width > &x)
static double distance_to_unit_cell(const Point< dim > &p)
static unsigned int face_to_cell_vertices(const unsigned int face, const unsigned int vertex, const bool face_orientation=true, const bool face_flip=false, const bool face_rotation=false)
static unsigned int line_to_cell_vertices(const unsigned int line, const unsigned int vertex)
static std_cxx20::ranges::iota_view< unsigned int, unsigned int > vertex_indices()
boost::signals2::signal< void()> clear
Definition tria.h:2467
constexpr Number determinant(const SymmetricTensor< 2, dim, Number > &)
constexpr SymmetricTensor< 2, dim, Number > invert(const SymmetricTensor< 2, dim, Number > &)