28#include <boost/container/small_vector.hpp>
37template <
int dim,
int spacedim>
49template <
int dim,
int spacedim>
55 const std::array<Point<spacedim>, 2>
vertices{{p1, p2}};
57 w * p2 + (1 - w) * p1);
62template <
int dim,
int spacedim>
68 const double tol = 1
e-10;
69 const unsigned int n_points = surrounding_points.size();
75 "There should be as many surrounding points as weights given."));
79 ExcMessage(
"The weights for the individual points should sum to 1!"));
84 boost::container::small_vector<unsigned int, 100> permutation(n_points);
85 std::iota(permutation.begin(), permutation.end(), 0u);
86 std::sort(permutation.begin(),
88 [&weights](
const std::size_t a,
const std::size_t b) {
89 return weights[a] < weights[b];
94 double w = weights[permutation[0]];
96 for (
unsigned int i = 1; i < n_points; ++i)
99 if (
std::abs(weights[permutation[i]] + w) < tol)
102 weight =
w / (weights[permutation[i]] +
w);
106 p = get_intermediate_point(p,
107 surrounding_points[permutation[i]],
112 p = surrounding_points[permutation[i]];
114 w += weights[permutation[i]];
122template <
int dim,
int spacedim>
131 for (
unsigned int row = 0; row < weights.size(0); ++row)
135 surrounding_points.end()),
147 const int spacedim = 2;
152 ((p - face->vertex(0)).norm_square() > (p - face->vertex(1)).norm_square() ?
153 -get_tangent_vector(p, face->vertex(0)) :
154 get_tangent_vector(p, face->vertex(1)));
158 return normal / normal.
norm();
168 const int spacedim = 3;
170 const std::array<Point<spacedim>, 4>
vertices{
171 {face->vertex(0), face->vertex(1), face->vertex(2), face->vertex(3)}};
177 std::max(distances[2], distances[3]));
185 double abs_cos_angle = std::numeric_limits<double>::max();
188 for (
unsigned int i = 0; i < 3; ++i)
189 if (distances[i] > 1e-8 * max_distance)
190 for (
unsigned int j = i + 1; j < 4; ++j)
191 if (distances[j] > 1e-8 * max_distance)
194 (distances[i] * distances[j]);
197 if (
std::abs(new_angle) < 0.999 * abs_cos_angle)
199 abs_cos_angle =
std::abs(new_angle);
205 ExcMessage(
"The search for possible directions did not succeed."));
213 normal.
norm_square() > 1e4 * std::numeric_limits<double>::epsilon() *
216 "Manifold::normal_vector was unable to find a suitable combination "
217 "of vertices to compute a normal on this face. We chose the secants "
218 "that are as orthogonal as possible, but tangents appear to be "
219 "linearly dependent. Check for distorted faces in your triangulation."));
228 if (reference_normal * normal < 0.0)
231 return normal / normal.
norm();
236template <
int dim,
int spacedim>
254 n[0] =
cross_product_2d(get_tangent_vector(face->vertex(0), face->vertex(1)));
258 for (
unsigned int i = 0; i < 2; ++i)
262 "computed normals have "
276 n[0] =
cross_product_3d(get_tangent_vector(face->vertex(0), face->vertex(1)),
277 get_tangent_vector(face->vertex(0), face->vertex(2)));
279 n[1] =
cross_product_3d(get_tangent_vector(face->vertex(1), face->vertex(3)),
280 get_tangent_vector(face->vertex(1), face->vertex(0)));
282 n[2] =
cross_product_3d(get_tangent_vector(face->vertex(2), face->vertex(0)),
283 get_tangent_vector(face->vertex(2), face->vertex(3)));
285 n[3] =
cross_product_3d(get_tangent_vector(face->vertex(3), face->vertex(2)),
286 get_tangent_vector(face->vertex(3), face->vertex(1)));
288 for (
unsigned int i = 0; i < 4; ++i)
292 "computed normals have "
300template <
int dim,
int spacedim>
304 FaceVertexNormals & n)
const
306 for (
unsigned int v = 0; v < face->reference_cell().n_vertices(); ++v)
308 n[v] = normal_vector(face, face->vertex(v));
315template <
int dim,
int spacedim>
322 points_weights.first.end()),
324 points_weights.second.end()));
329template <
int dim,
int spacedim>
336 points_weights.first.end()),
338 points_weights.second.end()));
343template <
int dim,
int spacedim>
353 return get_new_point_on_line(face);
355 return get_new_point_on_quad(face);
363template <
int dim,
int spacedim>
371 return get_new_point_on_line(cell);
373 return get_new_point_on_quad(cell);
375 return get_new_point_on_hex(cell);
449template <
int dim,
int spacedim>
465 const auto points_weights =
468 points_weights.first.end()),
470 points_weights.second.end()));
475template <
int dim,
int spacedim>
480 const double epsilon = 1e-8;
482 const std::array<Point<spacedim>, 2> points{{x1, x2}};
487 return (neighbor_point - x1) /
epsilon;
497 normalized_alternating_product(
const Tensor<1, 3> (&)[1])
509 normalized_alternating_product(
const Tensor<1, 3> (&basis_vectors)[2])
512 return tmp / tmp.
norm();
518template <
int dim,
int spacedim>
521 const double tolerance)
522 : periodicity(periodicity)
523 , tolerance(tolerance)
528template <
int dim,
int spacedim>
529std::unique_ptr<Manifold<dim, spacedim>>
532 return std::make_unique<FlatManifold<dim, spacedim>>(periodicity, tolerance);
537template <
int dim,
int spacedim>
545 ExcMessage(
"The weights for the individual points should sum to 1!"));
552 for (
unsigned int i = 0; i < surrounding_points.size(); ++i)
553 p += surrounding_points[i] * weights[i];
559 for (
unsigned int d = 0;
d < spacedim; ++
d)
560 if (periodicity[d] > 0)
561 for (
unsigned int i = 0; i < surrounding_points.size(); ++i)
563 minP[
d] =
std::min(minP[d], surrounding_points[i][d]);
564 Assert((surrounding_points[i][d] <
565 periodicity[d] + tolerance * periodicity[d]) ||
566 (surrounding_points[i][d] >=
567 -tolerance * periodicity[d]),
568 ExcPeriodicBox(d, surrounding_points[i], periodicity[d]));
573 for (
unsigned int i = 0; i < surrounding_points.size(); ++i)
576 for (
unsigned int d = 0;
d < spacedim; ++
d)
577 if (periodicity[d] > 0)
579 ((surrounding_points[i][
d] - minP[
d]) > periodicity[d] / 2.0 ?
583 p += (surrounding_points[i] + dp) * weights[i];
587 for (
unsigned int d = 0;
d < spacedim; ++
d)
588 if (periodicity[d] > 0)
590 p[
d] += periodicity[
d];
593 return project_to_manifold(surrounding_points, p);
598template <
int dim,
int spacedim>
606 if (weights.size(0) == 0)
609 const std::size_t n_points = surrounding_points.size();
612 for (
unsigned int d = 0;
d < spacedim; ++
d)
613 if (periodicity[d] > 0)
614 for (
unsigned int i = 0; i < n_points; ++i)
616 minP[
d] =
std::min(minP[d], surrounding_points[i][d]);
617 Assert((surrounding_points[i][d] <
618 periodicity[d] + tolerance * periodicity[d]) ||
619 (surrounding_points[i][d] >= -tolerance * periodicity[d]),
620 ExcPeriodicBox(d, surrounding_points[i], periodicity[i]));
625 const Point<spacedim> *surrounding_points_start = surrounding_points.data();
627 boost::container::small_vector<Point<spacedim>, 200> modified_points;
628 bool adjust_periodicity =
false;
629 for (
unsigned int d = 0;
d < spacedim; ++
d)
630 if (periodicity[d] > 0)
631 for (
unsigned int i = 0; i < n_points; ++i)
632 if ((surrounding_points[i][d] - minP[d]) > periodicity[d] / 2.0)
634 adjust_periodicity =
true;
637 if (adjust_periodicity ==
true)
639 modified_points.resize(surrounding_points.size());
640 std::copy(surrounding_points.begin(),
641 surrounding_points.end(),
642 modified_points.begin());
643 for (
unsigned int d = 0;
d < spacedim; ++
d)
644 if (periodicity[d] > 0)
645 for (
unsigned int i = 0; i < n_points; ++i)
646 if ((surrounding_points[i][d] - minP[d]) > periodicity[d] / 2.0)
647 modified_points[i][
d] -= periodicity[
d];
648 surrounding_points_start = modified_points.data();
652 for (
unsigned int row = 0; row < weights.size(0); ++row)
656 std::accumulate(&weights(row, 0), &weights(row, 0) + n_points, 0.0) -
658 ExcMessage(
"The weights for the individual points should sum to 1!"));
660 for (
unsigned int p = 0; p < n_points; ++p)
661 new_point += surrounding_points_start[p] * weights(row, p);
664 for (
unsigned int d = 0;
d < spacedim; ++
d)
665 if (periodicity[d] > 0)
666 if (new_point[d] < 0)
667 new_point[
d] += periodicity[
d];
673 surrounding_points.end()),
680template <
int dim,
int spacedim>
691template <
int dim,
int spacedim>
700template <
int dim,
int spacedim>
711 for (
unsigned int d = 0;
d < spacedim; ++
d)
712 if (periodicity[d] > tolerance)
714 if (direction[d] < -periodicity[d] / 2)
715 direction[
d] += periodicity[
d];
716 else if (direction[d] > periodicity[d] / 2)
717 direction[
d] -= periodicity[
d];
764 const Tensor<1, 2> tangent = face->vertex(1) - face->vertex(0);
768 face_vertex_normals[vertex] =
Tensor<1, 2>({tangent[1], -tangent[0]});
792 static const unsigned int neighboring_vertices[4][2] = {{1, 2},
796 for (
unsigned int vertex = 0; vertex < vertices_per_face; ++vertex)
801 face->vertex(neighboring_vertices[vertex][0]) - face->vertex(vertex),
802 face->vertex(neighboring_vertices[vertex][1]) - face->vertex(vertex)};
858template <
int dim,
int spacedim>
894 const unsigned int facedim = dim - 1;
898 const auto face_reference_cell = face->reference_cell();
900 if (face_reference_cell == ReferenceCells::get_hypercube<facedim>())
902 for (
unsigned int i = 0; i < facedim; ++i)
907 for (
unsigned int i = 0; i < facedim; ++i)
911 const double eps = 1
e-12;
913 unsigned int iteration = 0;
917 for (
const unsigned int v : face->vertex_indices())
919 face->vertex(v) * face_reference_cell.d_linear_shape_function(xi, v);
921 for (
unsigned int i = 0; i < facedim; ++i)
924 for (
const unsigned int v : face->vertex_indices())
927 face_reference_cell.d_linear_shape_function_gradient(xi, v)[i];
931 for (
unsigned int i = 0; i < facedim; ++i)
932 for (
unsigned int j = 0; j < spacedim; ++j)
933 J[i] += grad_F[i][j] * (F - p)[j];
936 for (
unsigned int i = 0; i < facedim; ++i)
937 for (
unsigned int j = 0; j < facedim; ++j)
938 for (
unsigned int k = 0; k < spacedim; ++k)
939 H[i][j] += grad_F[i][k] * grad_F[j][k];
946 ExcMessage(
"The Newton iteration to find the reference point "
947 "did not converge in 10 iterations. Do you have a "
948 "deformed cell? (See the glossary for a definition "
949 "of what a deformed cell is. You may want to output "
950 "the vertices of your cell."));
959 const double normalized_delta_world = (F - p).norm() / face->diameter();
961 if (delta_xi.
norm() < eps || normalized_delta_world < eps)
969 return internal::normalized_alternating_product(grad_F);
974template <
int dim,
int spacedim,
int chartdim>
977 : sub_manifold(periodicity)
982template <
int dim,
int spacedim,
int chartdim>
987 const double w)
const
989 const std::array<Point<spacedim>, 2> points{{p1, p2}};
990 const std::array<double, 2> weights{{1. - w, w}};
997template <
int dim,
int spacedim,
int chartdim>
1003 const std::size_t n_points = surrounding_points.size();
1005 boost::container::small_vector<Point<chartdim>, 200> chart_points(n_points);
1007 for (
unsigned int i = 0; i < n_points; ++i)
1008 chart_points[i] = pull_back(surrounding_points[i]);
1013 return push_forward(p_chart);
1018template <
int dim,
int spacedim,
int chartdim>
1028 const std::size_t n_points = surrounding_points.size();
1030 boost::container::small_vector<Point<chartdim>, 200> chart_points(n_points);
1031 for (std::size_t i = 0; i < n_points; ++i)
1032 chart_points[i] = pull_back(surrounding_points[i]);
1034 boost::container::small_vector<Point<chartdim>, 200> new_points_on_chart(
1036 sub_manifold.get_new_points(
1039 make_array_view(new_points_on_chart.begin(), new_points_on_chart.end()));
1041 for (std::size_t row = 0; row < weights.size(0); ++row)
1042 new_points[row] = push_forward(new_points_on_chart[row]);
1047template <
int dim,
int spacedim,
int chartdim>
1060template <
int dim,
int spacedim,
int chartdim>
1067 push_forward_gradient(pull_back(x1));
1076 1e-12 * F_prime.
norm(),
1078 "The derivative of a chart function must not be singular."));
1081 sub_manifold.get_tangent_vector(pull_back(x1), pull_back(x2));
1084 for (
unsigned int i = 0; i < spacedim; ++i)
1085 result[i] += F_prime[i] * delta;
1092template <
int dim,
int spacedim,
int chartdim>
1096 return sub_manifold.get_periodicity();
1100#include "manifold.inst"
ArrayView< typename std::remove_reference< typename std::iterator_traits< Iterator >::reference >::type, MemorySpaceType > make_array_view(const Iterator begin, const Iterator end)
ChartManifold(const Tensor< 1, chartdim > &periodicity=Tensor< 1, chartdim >())
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 Tensor< 1, spacedim > get_tangent_vector(const Point< spacedim > &x1, const Point< spacedim > &x2) const override
virtual DerivativeForm< 1, chartdim, spacedim > push_forward_gradient(const Point< chartdim > &chart_point) const
const Tensor< 1, chartdim > & get_periodicity() const
virtual Point< spacedim > get_intermediate_point(const Point< spacedim > &p1, const Point< spacedim > &p2, const double w) const override
virtual Point< spacedim > get_new_point(const ArrayView< const Point< spacedim > > &surrounding_points, const ArrayView< const double > &weights) const override
virtual Tensor< 1, spacedim > normal_vector(const typename Triangulation< dim, spacedim >::face_iterator &face, const Point< spacedim > &p) 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
virtual Tensor< 1, spacedim > get_tangent_vector(const Point< spacedim > &x1, const Point< spacedim > &x2) const override
virtual Point< spacedim > project_to_manifold(const ArrayView< const Point< spacedim > > &points, const Point< spacedim > &candidate) const override
const Tensor< 1, spacedim > & get_periodicity() const
virtual std::unique_ptr< Manifold< dim, spacedim > > clone() const override
virtual Point< spacedim > get_new_point(const ArrayView< const Point< spacedim > > &surrounding_points, const ArrayView< const double > &weights) const override
FlatManifold(const Tensor< 1, spacedim > &periodicity=Tensor< 1, spacedim >(), const double tolerance=1e-10)
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_on_hex(const typename Triangulation< dim, spacedim >::hex_iterator &hex) const
virtual Point< spacedim > get_new_point_on_line(const typename Triangulation< dim, spacedim >::line_iterator &line) const
virtual Point< spacedim > project_to_manifold(const ArrayView< const Point< spacedim > > &surrounding_points, const Point< spacedim > &candidate) const
virtual void get_new_points(const ArrayView< const Point< spacedim > > &surrounding_points, const Table< 2, double > &weights, ArrayView< Point< spacedim > > new_points) const
virtual void get_normals_at_vertices(const typename Triangulation< dim, spacedim >::face_iterator &face, FaceVertexNormals &face_vertex_normals) const
virtual Tensor< 1, spacedim > get_tangent_vector(const Point< spacedim > &x1, const Point< spacedim > &x2) const
std::array< Tensor< 1, spacedim >, GeometryInfo< dim >::vertices_per_face > FaceVertexNormals
virtual Point< spacedim > get_intermediate_point(const Point< spacedim > &p1, const Point< spacedim > &p2, const double w) const
Point< spacedim > get_new_point_on_face(const typename Triangulation< dim, spacedim >::face_iterator &face) const
virtual Point< spacedim > get_new_point_on_quad(const typename Triangulation< dim, spacedim >::quad_iterator &quad) const
virtual Tensor< 1, spacedim > normal_vector(const typename Triangulation< dim, spacedim >::face_iterator &face, const Point< spacedim > &p) const
Point< spacedim > get_new_point_on_cell(const typename Triangulation< dim, spacedim >::cell_iterator &cell) const
virtual Point< spacedim > get_new_point(const ArrayView< const Point< spacedim > > &surrounding_points, const ArrayView< const double > &weights) const
numbers::NumberTraits< Number >::real_type distance(const Point< dim, Number > &p) const
numbers::NumberTraits< Number >::real_type norm() const
constexpr numbers::NumberTraits< Number >::real_type norm_square() const
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_DISABLE_EXTRA_DIAGNOSTICS
#define DEAL_II_NAMESPACE_CLOSE
static ::ExceptionBase & ExcNotImplemented()
static ::ExceptionBase & ExcEmptyObject()
#define Assert(cond, exc)
static ::ExceptionBase & ExcImpossibleInDim(int arg1)
#define AssertDimension(dim1, dim2)
static ::ExceptionBase & ExcPureFunctionCalled()
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcMessage(std::string arg1)
typename IteratorSelector::hex_iterator hex_iterator
typename IteratorSelector::quad_iterator quad_iterator
typename IteratorSelector::line_iterator line_iterator
std::pair< std::array< Point< MeshIteratorType::AccessorType::space_dimension >, n_default_points_per_cell< MeshIteratorType >()>, std::array< double, n_default_points_per_cell< MeshIteratorType >()> > get_default_points_and_weights(const MeshIteratorType &iterator, const bool with_interpolation=false)
Tensor< 2, dim, Number > w(const Tensor< 2, dim, Number > &F, const Tensor< 2, dim, Number > &dF_dt)
SymmetricTensor< 2, dim, Number > e(const Tensor< 2, dim, Number > &F)
SymmetricTensor< 2, dim, Number > d(const Tensor< 2, dim, Number > &F, const Tensor< 2, dim, Number > &dF_dt)
SymmetricTensor< 2, dim, Number > epsilon(const Tensor< 2, dim, Number > &Grad_u)
Tensor< 2, dim, Number > F(const Tensor< 2, dim, Number > &Grad_u)
constexpr const ReferenceCell Line
static const unsigned int invalid_unsigned_int
::VectorizedArray< Number, width > min(const ::VectorizedArray< Number, width > &, const ::VectorizedArray< Number, width > &)
::VectorizedArray< Number, width > max(const ::VectorizedArray< Number, width > &, const ::VectorizedArray< Number, width > &)
::VectorizedArray< Number, width > pow(const ::VectorizedArray< Number, width > &, const Number p)
::VectorizedArray< Number, width > abs(const ::VectorizedArray< Number, width > &)
constexpr SymmetricTensor< 2, dim, Number > invert(const SymmetricTensor< 2, dim, Number > &)
constexpr Tensor< 1, dim, Number > cross_product_2d(const Tensor< 1, dim, Number > &src)
constexpr Tensor< 1, dim, typename ProductType< Number1, Number2 >::type > cross_product_3d(const Tensor< 1, dim, Number1 > &src1, const Tensor< 1, dim, Number2 > &src2)