deal.II version GIT relicensing-6839-g338455934c 2026-10-02 12:10: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
vector_relations.h
Go to the documentation of this file.
1// -----------------------------------------------------------------------------
2//
3// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
4// Copyright (C) 2021 - 2022 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#ifndef dealii_vector_relations_h
14#define dealii_vector_relations_h
15
16#include <deal.II/base/config.h>
17
18#include <deal.II/base/tensor.h>
19
20#include <cmath>
21#include <limits>
22
24
25
26namespace Physics
27{
31 namespace VectorRelations
32 {
42 template <int spacedim, typename Number>
43 Number
46
74 template <int spacedim, typename Number>
75 Number
78 const Tensor<1, spacedim, Number> &axis);
79 } // namespace VectorRelations
80} // namespace Physics
81
82
83
84#ifndef DOXYGEN
85
86
87
88template <int spacedim, typename Number>
89inline Number
92{
93 const Number a_norm = a.norm();
94 const Number b_norm = b.norm();
95 Assert(a_norm > 1.e-12 * b_norm && a_norm > 1.e-12 * b_norm,
96 ExcMessage("Both vectors need to be non-zero!"));
97
98 Number argument = (a * b) / a_norm / b_norm;
99
100 // std::acos returns nan if argument is out of domain [-1,+1].
101 // if argument slightly overshoots these bounds, set it to the bound.
102 // allow for 8*eps as a tolerance.
103 if ((1. - std::abs(argument)) < 8. * std::numeric_limits<Number>::epsilon())
104 argument = std::copysign(1., argument);
105
106 return std::acos(argument);
107}
108
109
110
111template <int spacedim, typename Number>
112inline Number
115 const Tensor<1, spacedim, Number> &axis)
116{
117 Assert(spacedim == 3,
118 ExcMessage("This function can only be used with spacedim==3!"));
119
120 Assert(std::abs(axis.norm() - 1.) < 1.e-12,
121 ExcMessage("The axial vector is not a unit vector."));
122 Assert(std::abs(axis * a) < 1.e-12 * a.norm() &&
123 std::abs(axis * b) < 1.e-12 * b.norm(),
124 ExcMessage("The vectors are not perpendicular to the axial vector."));
125
126 const Number dot = a * b;
127 const Number det = axis * cross_product_3d(a, b);
128
129 return std::atan2(det, dot);
130}
131
132
133
134#endif // DOXYGEN
135
137
138#endif
numbers::NumberTraits< Number >::real_type norm() const
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:38
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:39
#define Assert(cond, exc)
static ::ExceptionBase & ExcMessage(std::string arg1)
SymmetricTensor< 2, dim, Number > b(const Tensor< 2, dim, Number > &F)
Number signed_angle(const Tensor< 1, spacedim, Number > &a, const Tensor< 1, spacedim, Number > &b, const Tensor< 1, spacedim, Number > &axis)
Number angle(const Tensor< 1, spacedim, Number > &a, const Tensor< 1, spacedim, Number > &b)
*  *  *  RotationFunction< dim, Number >::RotationFunction Number(dim)
::VectorizedArray< Number, width > abs(const ::VectorizedArray< Number, width > &)
inline ::VectorizedArray< Number, width > acos(const ::VectorizedArray< Number, width > &x)