# PhasicFlow: src/phasicFlow/containers/Vector/VectorMath.hpp Source File
PhasicFlow is an open-source parallel DEM (discrete element method) package for simulating granular flow. It is developed in C++ and can be exectued on both GPU (like CUDA) and CPU.

VectorMath.hpp
Go to the documentation of this file.
/*------------------------------- phasicFlow ---------------------------------
O C enter of
O O E ngineering and
O O M ultiscale modeling of
OOOOOOO F luid flow
------------------------------------------------------------------------------
Copyright (C): www.cemf.ir
email: hamid.r.norouzi AT gmail.com
------------------------------------------------------------------------------
Licence:
This file is part of phasicFlow code. It is a free software for simulating
granular and multiphase flows. You can redistribute it and/or modify it under
the terms of GNU General Public License v3 or any other later versions.
phasicFlow is distributed to help others in their research in the field of
granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-----------------------------------------------------------------------------*/
namespace pFlow
{
#define VecFunc(fnName) \
template<typename T, typename Allocator> \
inline Vector<T, Allocator> fnName(const Vector<T,Allocator>& v) \
{ \
Vector<T, Allocator> res(v.name(), v.capacity(), 0 ,RESERVE()); \
for(auto& e:v) \
{ \
res.push_back( fnName(e) ); \
} \
return std::move(res); \
} \
template<typename T, typename Allocator, typename indexFunc> \
inline Vector<T, Allocator> fnName(const Vector<T, Allocator>& v, indexFunc iFn) \
{ \
Vector<T, Allocator> res(v.name(), v.capacity(), 0, RESERVE()); \
for(size_t i=0; i<v.size(); i++) \
{ \
if( iFn(i) ) \
res.push_back(fnName(v[i])); \
else \
res.push_back(v[i]); \
} \
return std::move(res); \
}
#define VecFunc2(fnName) \
template<typename T, typename Allocator> \
inline Vector<T, Allocator> fnName(const Vector<T, Allocator>& v1, const Vector<T, Allocator>& v2) \
{ \
Vector<T, Allocator> res(v1.name(), v1.capacity(), 0 ,RESERVE()); \
for(size_t i=0; i<v1.size(); i++) \
{ \
res.push_back( fnName(v1[i], v2[i])); \
} \
return std::move(res); \
} \
template<typename T, typename Allocator, typename indexFunc> \
inline Vector<T, Allocator> fnName(const Vector<T, Allocator>& v1, const Vector<T, Allocator>& v2, indexFunc iFn) \
{ \
Vector<T, Allocator> res(v1.name(), v1.capacity(), 0 ,RESERVE()); \
for(size_t i=0; i<v1.size(); i++) \
{ \
if( iFn(i) ) \
res.push_back(fnName(v1[i], v2[i])); \
else \
res.push_back(v1[i]); \
} \
return std::move(res); \
}
//* * * * * * * * * * * List of functinos * * * * * * * * //
// abs, mod, exp, log, log10, pow, sqrt, cbrt
// sin, cos, tan, asin, acos, atan, atan2
// sinh, cosh, tanh, asinh, acosh, atanh
// min, max
//* * * * * * * * * * * * * * * * * * * * * * * * * * * * //
VecFunc(abs);
VecFunc2(mod);
VecFunc(exp);
VecFunc(log);
VecFunc(log10);
VecFunc2(pow);
VecFunc(sqrt);
VecFunc(cbrt);
VecFunc(sin);
VecFunc(cos);
VecFunc(tan);
VecFunc(asin);
VecFunc(acos);
VecFunc(atan);
VecFunc2(atan2);
VecFunc(sinh);
VecFunc(cosh);
VecFunc(tanh);
VecFunc(asinh);
VecFunc(acosh);
VecFunc(atanh);
#undef VecFunc
}
namespace pFlow
{
template<typename T, typename Allocator>
inline Vector<T, Allocator> pow(const Vector<T, Allocator>& v, T e)
{
Vector<T, Allocator> res(v.name(), v.capacity(), 0 ,RESERVE());
for(auto& elm:v)
{
res.push_back(pow(elm,e));
}
return std::move(res);
}
template<typename T, typename Allocator, typename indexFunc>
inline Vector<T,Allocator> pow(const Vector<T,Allocator>& v, T e, indexFunc iFn)
{
Vector<T, Allocator> res(v.name(), v.capacity(), 0 ,RESERVE());
for(size_t i=0; i<v.size(); i++)
{
if(iFn(i))
{
res.push_back(pow(v[i],e));
}
else
{
res.push_back(v[i]);
}
}
return std::move(res);
}
template<typename T, typename Allocator>
inline T min(const Vector<T, Allocator>& v)
{
T minVal(largestPositive<T>());
for(auto& elm:v)
{
minVal = min(elm, minVal);
}
return minVal;
}
template<typename T, typename Allocator, typename indexFunc>
inline T min(const Vector<T, Allocator>& v, indexFunc iFn)
{
T minVal(largestPositive<T>());
for(size_t i=0; i<v.size(); i++)
{
if(iFn(i))
{
minVal = min(v[i], minVal);
}
}
return minVal;
}
template<typename T, typename Allocator>
inline T max(const Vector<T, Allocator>& v)
{
T maxVal(largestNegative<T>());
for(auto& elm:v)
{
maxVal = max(elm, maxVal);
}
return maxVal;
}
template<typename T, typename Allocator ,typename indexFunc>
inline T max(const Vector<T, Allocator>& v, indexFunc iFn)
{
T maxVal(largestNegative<T>());
for(size_t i=0; i<v.size(); i++)
{
if(iFn(i))
{
maxVal = max(v[i], maxVal);
}
}
return maxVal;
}
template<typename T, typename Allocator>
inline T sum(const Vector<T, Allocator>& v)
{
T s = static_cast<T>(0);
for(auto& elm:v)
{
s += elm;
}
return s;
}
template<typename T, typename Allocator, typename indexFunc>
inline T sum(const Vector<T, Allocator>& v, indexFunc iFn)
{
T s = static_cast<T>(0);
for(size_t i=0; i<v.size(); ++i)
{
if(iFn(i))
s += v[i];
}
return s;
}
}
pFlow::exp
Vector< T, Allocator > exp(const Vector< T, Allocator > &v)
Definition: VectorMath.hpp:86
pFlow::atan
Vector< T, Allocator > atan(const Vector< T, Allocator > &v)
Definition: VectorMath.hpp:97
pFlow::asin
Vector< T, Allocator > asin(const Vector< T, Allocator > &v)
Definition: VectorMath.hpp:95
pFlow::cbrt
Vector< T, Allocator > cbrt(const Vector< T, Allocator > &v)
Definition: VectorMath.hpp:91
VecFunc
#define VecFunc(fnName)
Definition: VectorMath.hpp:24
pFlow::sinh
Vector< T, Allocator > sinh(const Vector< T, Allocator > &v)
Definition: VectorMath.hpp:99
pFlow::pow
Vector< T, Allocator > pow(const Vector< T, Allocator > &v1, const Vector< T, Allocator > &v2)
Definition: VectorMath.hpp:89
pFlow::sqrt
Vector< T, Allocator > sqrt(const Vector< T, Allocator > &v)
Definition: VectorMath.hpp:90
pFlow::cosh
Vector< T, Allocator > cosh(const Vector< T, Allocator > &v)
Definition: VectorMath.hpp:100
pFlow::cos
Vector< T, Allocator > cos(const Vector< T, Allocator > &v)
Definition: VectorMath.hpp:93
pFlow::max
T max(const internalField< T, MemorySpace > &iField)
Definition: internalFieldAlgorithms.hpp:79
pFlow::Vector::size
auto size() const
Size of the vector.
Definition: Vector.hpp:265
pFlow
Definition: demGeometry.hpp:27
pFlow::asinh
Vector< T, Allocator > asinh(const Vector< T, Allocator > &v)
Definition: VectorMath.hpp:102
RESERVE
Definition: Vector.hpp:40
pFlow::log10
Vector< T, Allocator > log10(const Vector< T, Allocator > &v)
Definition: VectorMath.hpp:88
pFlow::Vector::capacity
auto capacity() const
Capacity of the vector.
Definition: Vector.hpp:271
pFlow::log
Vector< T, Allocator > log(const Vector< T, Allocator > &v)
Definition: VectorMath.hpp:87
pFlow::mod
Vector< T, Allocator > mod(const Vector< T, Allocator > &v1, const Vector< T, Allocator > &v2)
Definition: VectorMath.hpp:85
VecFunc2
#define VecFunc2(fnName)
Definition: VectorMath.hpp:49
pFlow::abs
Vector< T, Allocator > abs(const Vector< T, Allocator > &v)
Definition: VectorMath.hpp:84
pFlow::min
T min(const internalField< T, MemorySpace > &iField)
Definition: internalFieldAlgorithms.hpp:28
pFlow::sum
T sum(const Vector< T, Allocator > &v)
Definition: VectorMath.hpp:197
pFlow::sin
Vector< T, Allocator > sin(const Vector< T, Allocator > &v)
Definition: VectorMath.hpp:92
pFlow::Vector::name
const word & name() const
Name of the vector.
Definition: Vector.hpp:259
pFlow::atanh
Vector< T, Allocator > atanh(const Vector< T, Allocator > &v)
Definition: VectorMath.hpp:104
pFlow::tanh
Vector< T, Allocator > tanh(const Vector< T, Allocator > &v)
Definition: VectorMath.hpp:101
pFlow::atan2
Vector< T, Allocator > atan2(const Vector< T, Allocator > &v1, const Vector< T, Allocator > &v2)
Definition: VectorMath.hpp:98
pFlow::Vector
Definition: Vector.hpp:48
pFlow::tan
Vector< T, Allocator > tan(const Vector< T, Allocator > &v)
Definition: VectorMath.hpp:94
pFlow::acosh
Vector< T, Allocator > acosh(const Vector< T, Allocator > &v)
Definition: VectorMath.hpp:103
pFlow::acos
Vector< T, Allocator > acos(const Vector< T, Allocator > &v)
Definition: VectorMath.hpp:96