Commit df58135f authored by Nghia Truong's avatar Nghia Truong
Browse files

STYLE: Rename functions

parent 5d87e9d3
......@@ -19,7 +19,6 @@
=========================================================================*/
#pragma once
#include <atomic>
......@@ -33,7 +32,7 @@ namespace ParallelUtils
/// \brief Perform an atomic operation: target = f(target, operand)
///
template<class T, class Function>
void imstk_atomic_op(T& target, const T operand, Function&& f)
void atomicOp(T& target, const T operand, Function&& f)
{
std::atomic<T>& tgt = *(static_cast<std::atomic<T>*>(&target));
......@@ -50,48 +49,47 @@ void imstk_atomic_op(T& target, const T operand, Function&& f)
/// \brief Atomic addition for scalar numbers: target = target + operand
///
template<class T>
void imstk_atomic_add(T& target, const T operand)
void atomicAdd(T& target, const T operand)
{
imstk_atomic_op(target, operand, [](T a, T b) { return a + b; });
atomicOp(target, operand, [](T a, T b) { return a + b; });
}
///
/// \brief Atomic subtraction for scalar numbers: target = target - operand
///
template<class T>
void imstk_atomic_subtract(T& target, const T operand)
void atomicSubtract(T& target, const T operand)
{
imstk_atomic_op(target, operand, [](T a, T b) { return a - b; });
atomicOp(target, operand, [](T a, T b) { return a - b; });
}
///
/// \brief Atomic multiplication for scalar numbers: target = target * operand
///
template<class T>
void imstk_atomic_multiply(T& target, const T operand)
void atomicMultiply(T& target, const T operand)
{
imstk_atomic_op(target, operand, [](T a, T b) { return a * b; });
atomicOp(target, operand, [](T a, T b) { return a * b; });
}
///
/// \brief Atomic division for scalar numbers: target = target / operand
///
template<class T>
void imstk_atomic_divide(T& target, const T operand)
void atomicDivide(T& target, const T operand)
{
imstk_atomic_op(target, operand, [](T a, T b) { return a / b; });
atomicOp(target, operand, [](T a, T b) { return a / b; });
}
///
/// \brief Atomic addition for two vectors: target = target + operand
///
template<class T, int N>
void imstk_atomic_add(Eigen::Matrix<T, N, 1>& target, const Eigen::Matrix<T, N, 1>& operand)
void atomicAdd(Eigen::Matrix<T, N, 1>& target, const Eigen::Matrix<T, N, 1>& operand)
{
for(int i = 0; i < N; ++i)
{
imstk_atomic_add(target[i], operand[i]);
atomicAdd(target[i], operand[i]);
}
}
......@@ -99,11 +97,11 @@ void imstk_atomic_add(Eigen::Matrix<T, N, 1>& target, const Eigen::Matrix<T, N,
/// \brief Atomic subtraction for two vectors: target = target - operand
///
template<class T, int N>
void imstk_atomic_subtract(Eigen::Matrix<T, N, 1>& target, const Eigen::Matrix<T, N, 1>& operand)
void atomicSubtract(Eigen::Matrix<T, N, 1>& target, const Eigen::Matrix<T, N, 1>& operand)
{
for(int i = 0; i < N; ++i)
{
imstk_atomic_subtract(target[i], operand[i]);
atomicSubtract(target[i], operand[i]);
}
}
......@@ -111,11 +109,11 @@ void imstk_atomic_subtract(Eigen::Matrix<T, N, 1>& target, const Eigen::Matrix<T
/// \brief Atomic multiplication for a vector and a scalar number: target = target * operand
///
template<class T, int N>
void imstk_atomic_multiply(Eigen::Matrix<T, N, 1>& target, const T operand)
void atomicMultiply(Eigen::Matrix<T, N, 1>& target, const T operand)
{
for(int i = 0; i < N; ++i)
{
imstk_atomic_multiply(target[i], operand);
atomicMultiply(target[i], operand);
}
}
......@@ -123,11 +121,11 @@ void imstk_atomic_multiply(Eigen::Matrix<T, N, 1>& target, const T operand)
/// \brief Atomic division for a vector and a scalar number: target = target / operand
///
template<class T, int N>
void imstk_atomic_divide(Eigen::Matrix<T, N, 1>& target, const T operand)
void atomicDivide(Eigen::Matrix<T, N, 1>& target, const T operand)
{
for(int i = 0; i < N; ++i)
{
imstk_atomic_divide(target[i], operand);
atomicDivide(target[i], operand);
}
}
}// end namespace namespace ParallelUtils
......
......@@ -19,7 +19,6 @@
=========================================================================*/
#pragma once
#include "imstkMath.h"
......@@ -42,11 +41,11 @@ class ParallelReduce
/// \brief Private helper class, providing operator() using in std::parallel_reduce
/// for finding max L2 norm of an array of Vec3r
///
class ParallelMaxNorm
class MaxL2NormFunctor
{
public:
ParallelMaxNorm(const StdVectorOfVec3r& data) : m_Data(data) {}
ParallelMaxNorm(ParallelMaxNorm& pObj, tbb::split) : m_Data(pObj.m_Data) {}
MaxL2NormFunctor(const StdVectorOfVec3r& data) : m_Data(data) {}
MaxL2NormFunctor(MaxL2NormFunctor& pObj, tbb::split) : m_Data(pObj.m_Data) {}
void operator()(const tbb::blocked_range<size_t>& r)
{
......@@ -57,7 +56,7 @@ public:
}
}
void join(ParallelMaxNorm& pObj) { m_Result = m_Result > pObj.m_Result ? m_Result : pObj.m_Result; }
void join(MaxL2NormFunctor& pObj) { m_Result = m_Result > pObj.m_Result ? m_Result : pObj.m_Result; }
Real getResult() const noexcept { return std::sqrt(m_Result); }
private:
......@@ -69,11 +68,11 @@ private:
/// \brief Private helper class, providing operator() using in std::parallel_reduce
/// for finding axis-aligned bounding box of a point set
///
class ParallelAABB
class AABBFunctor
{
public:
ParallelAABB(const StdVectorOfVec3r& data) : m_Data(data) { if(data.size() > 0) { m_UpperCorner = data[0]; } }
ParallelAABB(ParallelAABB& pObj, tbb::split) : m_Data(pObj.m_Data) {}
AABBFunctor(const StdVectorOfVec3r& data) : m_Data(data) { if(data.size() > 0) { m_UpperCorner = data[0]; } }
AABBFunctor(AABBFunctor& pObj, tbb::split) : m_Data(pObj.m_Data) {}
void operator()(const tbb::blocked_range<size_t>& r)
{
......@@ -88,7 +87,7 @@ public:
}
}
void join(ParallelAABB& pObj)
void join(AABBFunctor& pObj)
{
for(int j = 0; j < 3; ++j)
{
......@@ -114,9 +113,9 @@ public:
///
/// \brief Find the maximum value of L2 norm from the input data array
///
static Real getMaxL2Norm(const StdVectorOfVec3r& data)
static Real findMaxL2Norm(const StdVectorOfVec3r& data)
{
ParallelMaxNorm pObj(data);
MaxL2NormFunctor pObj(data);
tbb::parallel_reduce(tbb::blocked_range<size_t>(0, data.size()), pObj);
return pObj.getResult();
}
......@@ -126,7 +125,7 @@ public:
///
static void findAABB(const StdVectorOfVec3r& points, Vec3r& lowerCorner, Vec3r& upperCorner)
{
ParallelAABB pObj(points);
AABBFunctor pObj(points);
tbb::parallel_reduce(tbb::blocked_range<size_t>(0, points.size()), pObj);
lowerCorner = pObj.getLowerCorner();
upperCorner = pObj.getUpperCorner();
......
......@@ -96,7 +96,7 @@ void SPHModel::computeTimeStepSize()
Real SPHModel::computeCFLTimeStepSize()
{
auto maxVel = ParallelUtils::ParallelReduce::getMaxL2Norm(getState().getVelocities());
auto maxVel = ParallelUtils::ParallelReduce::findMaxL2Norm(getState().getVelocities());
// dt = CFL * 2r / max{|| v ||}
Real timestep = maxVel > Real(1e-6) ? m_Parameters->m_CFLFactor * (Real(2.0) * m_Parameters->m_ParticleRadius / maxVel) : m_Parameters->m_MaxTimestep;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment