24#ifndef VECTOR_HELPERS_H
25#define VECTOR_HELPERS_H
40template<
typename T,
unsigned Size>
class Vector;
44template <
class T,
unsigned DIM>
class ADf;
46template <
class T,
unsigned DIM>
inline ADf<T,DIM>
sqrt (
const ADf<T,DIM>& a);
58 T EPSILON = std::numeric_limits<T>::epsilon();
59 if (a > -EPSILON && a < EPSILON) {
70 if (a > -epsilon && a < epsilon) {
78template<
typename T,
typename U=T,
typename W=T>
84 return nearZero<T>(a - b, epsilon);
87template<
typename T,
typename U=T>
96 T EPSILON = std::numeric_limits<T>::epsilon()*4.*
util::fabs(a);
103 for (
unsigned i=0; i<dim; i++) {
108template <
class S,
class T>
111 for (
unsigned i=0; i<dim; i++) {
117inline void copy3(T c[],
const T a[])
119 for (
unsigned i=0; i<3; i++) {
149 for (
unsigned iD=0; iD<a.size(); iD++) {
161 for (
unsigned iD=0; iD<a.size(); iD++) {
171 return a[0]*b[0] + a[1]*b[1] + a[2]*b[2];
178 return a[0]*b[0] + a[1]*b[1];
182template <
typename T,
unsigned D>
192template <
typename T,
unsigned D>
202 std::vector<T> out(a);
205 for (
unsigned int iDim=0; iDim<a.size(); iDim++) {
212template <
typename T,
unsigned Size>
216 for (
unsigned int iDim=0; iDim < Size; ++iDim) {
223template <
typename T,
unsigned Size>
227 for (
unsigned int iDim=0; iDim < Size; ++iDim) {
234template <
typename T,
typename S,
unsigned Size>
238 for (
unsigned int iDim=0; iDim < Size; ++iDim) {
245template <
typename T,
unsigned Size>
249 for (
unsigned int iDim=1; iDim < Size; ++iDim) {
256template <
typename T,
unsigned Size>
260 for (
unsigned int iDim=1; iDim < Size; ++iDim) {
261 max = std::max(
max,a[iDim]);
267template <
typename T,
unsigned Size>
271 for (
unsigned int iDim=1; iDim < Size; ++iDim) {
272 min = std::min(
min,a[iDim]);
278template <
typename T,
unsigned Size>
282 for (
unsigned int iDim=1; iDim < Size; ++iDim) {
283 if (a[iDim]>a[maxPos]){
291template <
typename T,
unsigned Size>
295 for (
unsigned int iDim=1; iDim < Size; ++iDim) {
296 if (a[iDim]<a[minPos]){
304template <
typename T,
unsigned Size>
308 for (
unsigned int iDim=1; iDim < Size; ++iDim) {
309 if (
abs(a[iDim])>
abs(maxAbs)){
317template <
typename T,
unsigned Size>
320 unsigned maxAbsPos = 0;
321 for (
unsigned int iDim=1; iDim < Size; ++iDim) {
322 if (
abs(a[iDim])>
abs(a[maxAbsPos])){
330template <
typename T,
bool ensureAngularBounds=true>
333 if constexpr(ensureAngularBounds){
334 return std::fmod(
util::atan2(b[1]*a[0]-b[0]*a[1], a[0]*b[0]+a[1]*b[1]),
M_PI);
336 return util::atan2(b[1]*a[0]-b[0]*a[1], a[0]*b[0]+a[1]*b[1]);
341template <
typename T,
bool ensureAngularBounds=true>
355bool triangleIntersectionWithNormalDirection(const std::vector<T>& point0,
356 const std::vector<T>& point1, const std::vector<T>& point2,
357 const std::vector<T>& origin, const std::vector<T>& normalDirection,
360 T EPSILON = std::numeric_limits<T>::epsilon();
361 std::vector<T> e1, e2;
362 std::vector<T> P, Q, TT;
365 e1 = point1 - point0;
366 e2 = point2 - point0;
367 P = crossProduct3D(normalDirection, e2);
368 det = dotProduct3D(P, e1);
369 if (det > -EPSILON && det < EPSILON) {
372 inv_det = T(1) / det;
373 TT = origin - point0;
374 u = dotProduct3D(TT, P)*inv_det;
375 if (u < T() || u > T(1)) {
378 Q = crossProduct3D(TT, e1);
379 v = dotProduct3D(normalDirection, Q) * inv_det;
380 if (v < T() || u + v > T(1)) {
383 t = dotProduct3D(e2, Q)*inv_det;
392bool 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)
394 std::vector<T> normalDirection(normalize(direction) );
395 return triangleIntersectionWithNormalDirection(point0, point1, point2, origin, normalDirection, distance );
420 const char delimiter=
',')
422 static_assert(!std::is_integral<U>::value && !std::is_floating_point<U>::value,
"passed integral or floating_point value to function print()");
424 clout << name <<
" = ";
426 for (
auto& element : data ) {
427 clout << std::fixed << element << delimiter <<
' ';
434template<
typename C,
typename U>
436 return (std::find(c.begin(), c.end(),
object) != c.end());
446 using C = std::vector<T>;
453template<
typename T, std::
size_t SIZE>
455 using C = std::array<T,SIZE>;
463template<
typename T,
unsigned SIZE>
The description of a algoritmic differentiation data type using the forward method – header file.
class for marking output with some text
cpu::simd::Pack< T > sqrt(cpu::simd::Pack< T > value)
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)
cpu::simd::Pack< T > min(cpu::simd::Pack< T > rhs, cpu::simd::Pack< T > lhs)
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 average(const Vector< T, Size > &a)
computes the average of all elements
std::vector< T > fromVector2(const Vector< T, 2 > &vec)
bool approxEqual(T a, U b, W epsilon)
T max_element(const Vector< T, Size > &a)
finds maximum element of all elements
cpu::simd::Pack< T > max(cpu::simd::Pack< T > rhs, cpu::simd::Pack< T > lhs)
T min_element(const Vector< T, Size > &a)
finds minimum element of all elements
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
cpu::simd::Pack< T > fabs(cpu::simd::Pack< T > value)
T dotProduct3D(const Vector< T, 3 > &a, const Vector< T, 3 > &b)
dot product, only valid in 3d
T norm2(const std::vector< T > &a)
l2 norm to the power of 2 of a vector of arbitrary length
Vector< T, D > normalize(const Vector< T, D > &a)
bool nearZero(const ADf< T, DIM > &a)
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.
#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