18 template <
class T,
unsigned M>
19 T
norm(Vector<T,M>
const& a)
28 r(0) = a(1)*b(2) - a(2)*b(1);
29 r(1) = a(2)*b(0) - a(0)*b(2);
30 r(2) = a(0)*b(1) - a(1)*b(0);
44 template <
class T,
unsigned N>
47 return b*((a*b)/(b*b));
50 template <
class T,
unsigned N>
56 template <
class T,
unsigned M,
unsigned N>
60 unsigned m = a.
cols();
61 unsigned n = a.
rows();
63 for (
unsigned i=0; i < m; ++i)
64 for (
unsigned j=0; j < n; ++j)
71 return a(0,0)*a(1,1) - a(1,0)*a(0,1);
78 a(0,0) * (a(1,1)*a(2,2) - a(2,1)*a(1,2)) -
79 a(0,1) * (a(1,0)*a(2,2) - a(2,0)*a(1,2)) +
80 a(0,2) * (a(1,0)*a(2,1) - a(2,0)*a(1,1));
87 r(0,0) = a(1,1); r(0,1) = -a(0,1);
88 r(1,0) = -a(1,0); r(1,1) = a(0,0);
97 r[0] =
cross(x[1], x[2]);
98 r[1] =
cross(x[2], x[0]);
99 r[2] =
cross(x[0], x[1]);
106 unsigned dim = a.
dim();
108 for (
unsigned i=1; i < dim; ++i)
117 for (
unsigned i=0; i < a.
dim(); ++i)
118 for (
unsigned j=0; j < a.
dim(); ++j)
124 T det2x2(Tensor<T>
const& a)
126 return a(0,0)*a(1,1) - a(1,0)*a(0,1);
130 T det3x3(Tensor<T>
const& a)
133 a(0,0) * (a(1,1)*a(2,2) - a(2,1)*a(1,2)) -
134 a(0,1) * (a(1,0)*a(2,2) - a(2,0)*a(1,2)) +
135 a(0,2) * (a(1,0)*a(2,1) - a(2,0)*a(1,1));
158 for (
unsigned i=0; i < a.
dim(); ++i)
159 for (
unsigned j=0; j < a.
dim(); ++j)
164 void inverse2x2(Tensor<T>
const& a, Tensor<T>& r)
166 r(0,0) = a(1,1); r(0,1) = -a(0,1);
167 r(1,0) = -a(1,0); r(1,1) = a(0,0);
172 void inverse3x3(Tensor<T>
const& a, Tensor<T>& r)
174 r(0,0) = a(2,2)*a(1,1) - a(2,1)*a(1,2);
175 r(0,1) = a(2,1)*a(0,2) - a(2,2)*a(0,1);
176 r(0,2) = a(1,2)*a(0,1) - a(1,1)*a(0,2);
177 r(1,0) = a(2,0)*a(1,2) - a(2,2)*a(1,0);
178 r(1,1) = a(2,2)*a(0,0) - a(2,0)*a(0,2);
179 r(1,2) = a(1,0)*a(0,2) - a(1,2)*a(0,0);
180 r(2,0) = a(2,1)*a(1,0) - a(2,0)*a(1,1);
181 r(2,1) = a(2,0)*a(0,1) - a(2,1)*a(0,0);
182 r(2,2) = a(1,1)*a(0,0) - a(1,0)*a(0,1);
202 void deviatoric(Tensor<T>
const& a, Tensor<T>& r)
205 T p =
trace(a) / a.dim();
206 for (
unsigned i=0; i < a.dim(); ++i)
215 for (
unsigned i=0; i < d; ++i)
220 template <
class T,
unsigned M,
unsigned N>
221 void multiply(Matrix<T,M,N>
const& a, Vector<T,N>
const& b,
224 unsigned m = a.rows();
225 unsigned n = a.cols();
227 for (
unsigned i = 0; i < m; ++i) {
229 for (
unsigned j = 0; j < n; ++j)
230 c(i) += a(i,j) * b(j);
234 template <
class T,
unsigned M,
unsigned N,
unsigned O>
235 void multiply(Matrix<T,M,O>
const& a, Matrix<T,O,N>
const& b,
238 unsigned m = a.rows();
239 unsigned n = b.cols();
240 unsigned o = a.cols();
242 for (
unsigned i = 0; i < m; ++i)
243 for (
unsigned j = 0; j < n; ++j) {
245 for (
unsigned l = 0; l < o; ++l)
246 c(i,j) += a(i,l) * b(l,j);
convenience wrapper over Matrix<T,3,3>
compile-time (static) matrix
unsigned rows() const
get the number of rows
unsigned cols() const
get the number of columns
run-time (dynamic) tensor
void resize(unsigned d)
resize this tensor to dimension d
unsigned dim() const
get the dimension of this tensor
convenience wrapper over apf::Vector<3>
All MTH functions are contained in this namespace.
Vector3< T > cross(Vector< T, 3 > const &a, Vector< T, 3 > const &b)
returns vector cross product
Matrix< T, 2, 2 > inverse(Matrix< T, 2, 2 > const &a)
invert a 2 by 2 matrix
double sqrt(double A)
wrapper for standard sqrt function
Vector< T, N > reject(Vector< T, N > const &a, Vector< T, N > const &b)
vector rejection
T trace(Tensor< T > const &a)
trace of a tensor
T norm(Tensor< T > const &a)
Frobenius norm of a tensor.
T determinant(Matrix< T, 2, 2 > const &a)
determinant of a 2 by 2 matrix
void transpose(Matrix< T, M, N > const &a, Matrix< T, N, M > &b)
transpose of a static matrix
Tensor< T > eye(unsigned d)
identity tensor
Vector< T, N > project(Vector< T, N > const &a, Vector< T, N > const &b)
returns vector a projected onto vector b