25#ifndef VECTOR_HELPERS_H
26#define VECTOR_HELPERS_H
41template<
typename T,
unsigned Size>
class Vector;
45template <
class T,
unsigned DIM>
class ADf;
55 for (
unsigned i=0; i<dim; i++) {
60template <
class S,
class T>
63 for (
unsigned i=0; i<dim; i++) {
69inline void copy3(T c[],
const T a[])
71 for (
unsigned i=0; i<3; i++) {
97T
norm2(
const T* a,
unsigned size)
100 for (
unsigned iD=0; iD<size; ++iD) {
110 return norm2(a.data(), a.size());
115T
norm(
const T* a,
unsigned size)
124 return norm(a.data(), a.size());
131 return a[0]*b[0] + a[1]*b[1] + a[2]*b[2];
138 return a[0]*b[0] + a[1]*b[1];
142template <
typename T,
unsigned D>
152template <
typename T,
unsigned D>
162 std::vector<T> out(a);
165 for (
unsigned int iDim=0; iDim<a.size(); iDim++) {
172template <
typename T,
unsigned Size>
176 for (
unsigned int iDim=0; iDim < Size; ++iDim) {
183template <
typename T,
unsigned Size>
187 for (
unsigned int iDim=0; iDim < Size; ++iDim) {
194template <
typename T,
typename S,
unsigned Size>
198 for (
unsigned int iDim=0; iDim < Size; ++iDim) {
205template <
typename T,
unsigned Size>
209 for (
unsigned int iDim=1; iDim < Size; ++iDim) {
216template <
typename T,
unsigned Size>
220 for (
unsigned int iDim=1; iDim < Size; ++iDim) {
221 max = std::max(max,a[iDim]);
227template <
typename T,
unsigned Size>
231 for (
unsigned int iDim=1; iDim < Size; ++iDim) {
232 min = std::min(min,a[iDim]);
238template <
typename T,
unsigned Size>
242 for (
unsigned int iDim=1; iDim < Size; ++iDim) {
243 if (a[iDim]>a[maxPos]){
251template <
typename T,
unsigned Size>
255 for (
unsigned int iDim=1; iDim < Size; ++iDim) {
256 if (a[iDim]<a[minPos]){
264template <
typename T,
unsigned Size>
268 for (
unsigned int iDim=1; iDim < Size; ++iDim) {
269 if (
abs(a[iDim])>
abs(maxAbs)){
277template <
typename T,
unsigned Size>
280 unsigned maxAbsPos = 0;
281 for (
unsigned int iDim=1; iDim < Size; ++iDim) {
282 if (
abs(a[iDim])>
abs(a[maxAbsPos])){
290template <
typename T,
bool ensureAngularBounds=true>
293 if constexpr(ensureAngularBounds){
294 return std::fmod(
util::atan2(b[1]*a[0]-b[0]*a[1], a[0]*b[0]+a[1]*b[1]),
M_PI);
296 return util::atan2(b[1]*a[0]-b[0]*a[1], a[0]*b[0]+a[1]*b[1]);
301template <
typename T,
bool ensureAngularBounds=true>
321 return v0[0]*v1[1]*v2[2] + v1[0]*v2[1]*v0[2] + v2[0]*v0[1]*v1[2]
322 - v0[2]*v1[1]*v2[0] - v1[2]*v2[1]*v0[0] - v2[2]*v0[1]*v1[0];
367bool triangleIntersectionWithNormalDirection(const std::vector<T>& point0,
368 const std::vector<T>& point1, const std::vector<T>& point2,
369 const std::vector<T>& origin, const std::vector<T>& normalDirection,
372 T EPSILON = std::numeric_limits<T>::epsilon();
373 std::vector<T> e1, e2;
374 std::vector<T> P, Q, TT;
377 e1 = point1 - point0;
378 e2 = point2 - point0;
379 P = crossProduct3D(normalDirection, e2);
380 det = dotProduct3D(P, e1);
381 if (det > -EPSILON && det < EPSILON) {
384 inv_det = T(1) / det;
385 TT = origin - point0;
386 u = dotProduct3D(TT, P)*inv_det;
387 if (u < T() || u > T(1)) {
390 Q = crossProduct3D(TT, e1);
391 v = dotProduct3D(normalDirection, Q) * inv_det;
392 if (v < T() || u + v > T(1)) {
395 t = dotProduct3D(e2, Q)*inv_det;
404bool triangleIntersection(const std::vector<T>& point0, const std::vector<T>& point1, const std::vector<T>& point2, const std::vector<T>& origin, const std::vector<T>& direction, T& distance)
406 std::vector<T> normalDirection(normalize(direction) );
407 return triangleIntersectionWithNormalDirection(point0, point1, point2, origin, normalDirection, distance );
432 const char delimiter=
',')
434 static_assert(!std::is_integral<U>::value && !std::is_floating_point<U>::value,
"passed integral or floating_point value to function print()");
436 clout << name <<
" = ";
438 for (
auto& element : data ) {
439 clout << std::fixed << element << delimiter <<
' ';
446template<
typename C,
typename U>
448 return (std::find(c.begin(), c.end(),
object) != c.end());
458 using C = std::vector<T>;
465template<
typename T, std::
size_t SIZE>
467 using C = std::array<T,SIZE>;
475template<
typename T,
unsigned SIZE>
490template<
unsigned DIM>
495 if constexpr (DIM==2) {
498 else if constexpr (DIM==3) {
499 const unsigned res = i+j;
500 if ((i>0) && (j>0)) {
The description of a algoritmic differentiation data type using the forward method – header file.
class for marking output with some text
Definition of a description of a algoritmic differentiation data type using the forward method.
Vector< T, 3 > solveLinearSystem_help(const Vector< T, 3 > &a0, const Vector< T, 3 > &a1, const Vector< T, 3 > &a2, const Vector< T, 3 > &rhs, T det)
ADf< T, DIM > abs(const ADf< T, DIM > &a)
ADf< T, DIM > ceil(const ADf< T, DIM > &a)
ADf< T, DIM > floor(const ADf< T, DIM > &a)
std::vector< T > fromVector3(const Vector< T, 3 > &vec)
std::vector< S, std::allocator< S > > StdVector
ADf< T, DIM > fmod(const ADf< T, DIM > &a, const ADf< T, DIM > &b)
auto solveLinearSystem(const Matrix< T, 2, 2 > &a, const Vector< T, 2 > &rhs)
Solve a * x = rhs.
ADf< T, DIM > atan2(const T &y, const ADf< T, DIM > &x)
bool isContained(const C &c, U object)
Check, if object is contained in iteratable container c.
void copyN(T c[], const T a[], const unsigned dim) any_platform
T angleBetweenVectors(const Vector< T, 2 > &a, const Vector< T, 2 > &b)
Calculates angles between two 2D vectors.
T norm2(const T *a, unsigned size)
l2 norm to the power of 2 of a vector of arbitrary length
T average(const Vector< T, Size > &a)
computes the average of all elements
std::vector< T > fromVector2(const Vector< T, 2 > &vec)
T max_element(const Vector< T, Size > &a)
finds maximum element of all elements
T min_element(const Vector< T, Size > &a)
finds minimum element of all elements
constexpr auto determinant(const Matrix< T, 2, 2 > &m)
T dotProduct(const Vector< T, D > &a, const Vector< T, D > &b)
dot product
T maxElementAbs(const Vector< T, Size > &a)
finds maximum element of all absolute elements
unsigned maxElementAbsPos(const Vector< T, Size > &a)
finds position of maximum element of all absolute elements
T norm(const std::vector< T > &a)
l2 norm of a vector of arbitrary length
unsigned minElementPos(const Vector< T, Size > &a)
finds position of minimum element of all elements
unsigned maxElementPos(const Vector< T, Size > &a)
finds position of maximum element of all elements
T dotProduct3D(const Vector< T, 3 > &a, const Vector< T, 3 > &b)
dot product, only valid in 3d
Vector< T, D > normalize(const Vector< T, D > &a)
unsigned serialSymmetricTensorIndex(unsigned i, unsigned j) any_platform
Compute serial index of symmetric tensor.
void print(U data, const std::string &name="", OstreamManager clout=OstreamManager(std::cout,"print"), const char delimiter=',')
std::vector< T > assign(T a, T b)
T dotProduct2D(const Vector< T, 2 > &a, const Vector< T, 2 > &b)
dot product, only valid in 2d
void copy3(T c[], const T a[])
Top level namespace for all of OpenLB.
constexpr T crossProduct2D(const ScalarVector< T, 2, IMPL > &a, const ScalarVector< T, 2, IMPL_ > &b)
#define OLB_PRECONDITION(COND)
static constexpr C create(std::size_t size)
static constexpr C create(std::size_t size)
static constexpr C create(std::size_t size)
Creates a container of type C.
efficient implementation of a vector class