mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: relocate findMinData/findMaxData to FieldOps namespace
This commit is contained in:
@ -26,66 +26,9 @@ License
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "exprDriver.H"
|
||||
#include "Tuple2.H"
|
||||
#include "FieldOps.H"
|
||||
#include "Random.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
//! \cond file-scope
|
||||
|
||||
template<class T1, class T2>
|
||||
static Foam::Tuple2<T1,T2> findMinData
|
||||
(
|
||||
const Field<T1>& vals,
|
||||
const Field<T2>& data
|
||||
)
|
||||
{
|
||||
typedef Tuple2<T1,T2> retType;
|
||||
|
||||
retType result(pTraits<T1>::max, Zero);
|
||||
|
||||
const label i = findMin(vals);
|
||||
if (i != -1)
|
||||
{
|
||||
result.first() = vals[i];
|
||||
result.second() = data[i];
|
||||
}
|
||||
|
||||
Foam::combineReduce(result, minFirstEqOp<T1>());
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
template<class T1, class T2>
|
||||
static Foam::Tuple2<T1,T2> findMaxData
|
||||
(
|
||||
const Field<T1>& vals,
|
||||
const Field<T2>& data
|
||||
)
|
||||
{
|
||||
typedef Tuple2<T1,T2> retType;
|
||||
|
||||
retType result(pTraits<T1>::min, Zero);
|
||||
|
||||
const label i = findMax(vals);
|
||||
if (i != -1)
|
||||
{
|
||||
result.first() = vals[i];
|
||||
result.second() = data[i];
|
||||
}
|
||||
|
||||
Foam::combineReduce(result, maxFirstEqOp<T1>());
|
||||
return result;
|
||||
}
|
||||
|
||||
//! \endcond
|
||||
} // End namespace Foam
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
void Foam::expressions::exprDriver::fill_random
|
||||
@ -98,13 +41,11 @@ void Foam::expressions::exprDriver::fill_random
|
||||
if (gaussian)
|
||||
{
|
||||
Random::gaussianGeneratorOp<scalar> gen(seed);
|
||||
|
||||
FieldOps::assign(field, field, gen);
|
||||
}
|
||||
else
|
||||
{
|
||||
Random::uniformGeneratorOp<scalar> gen(seed);
|
||||
|
||||
FieldOps::assign(field, field, gen);
|
||||
}
|
||||
}
|
||||
@ -116,7 +57,7 @@ Foam::point Foam::expressions::exprDriver::getPositionOfMinimum
|
||||
const pointField& locs
|
||||
)
|
||||
{
|
||||
return findMinData(vals, locs).second();
|
||||
return FieldOps::findMinData(vals, locs).second();
|
||||
}
|
||||
|
||||
|
||||
@ -126,7 +67,7 @@ Foam::point Foam::expressions::exprDriver::getPositionOfMaximum
|
||||
const pointField& locs
|
||||
)
|
||||
{
|
||||
return findMaxData(vals, locs).second();
|
||||
return FieldOps::findMaxData(vals, locs).second();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -25,6 +25,7 @@ License
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "PstreamCombineReduceOps.H"
|
||||
#include <algorithm>
|
||||
|
||||
// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
|
||||
@ -154,4 +155,46 @@ void Foam::FieldOps::ternarySelect
|
||||
}
|
||||
|
||||
|
||||
template<class T1, class T2>
|
||||
Foam::Tuple2<T1,T2> Foam::FieldOps::findMinData
|
||||
(
|
||||
const Field<T1>& vals,
|
||||
const Field<T2>& data
|
||||
)
|
||||
{
|
||||
Tuple2<T1,T2> result(pTraits<T1>::max, Zero);
|
||||
|
||||
const label i = findMin(vals);
|
||||
if (i != -1)
|
||||
{
|
||||
result.first() = vals[i];
|
||||
result.second() = data[i];
|
||||
}
|
||||
|
||||
Foam::combineReduce(result, minFirstEqOp<T1>());
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
template<class T1, class T2>
|
||||
Foam::Tuple2<T1,T2> Foam::FieldOps::findMaxData
|
||||
(
|
||||
const Field<T1>& vals,
|
||||
const Field<T2>& data
|
||||
)
|
||||
{
|
||||
Tuple2<T1,T2> result(pTraits<T1>::min, Zero);
|
||||
|
||||
const label i = findMax(vals);
|
||||
if (i != -1)
|
||||
{
|
||||
result.first() = vals[i];
|
||||
result.second() = data[i];
|
||||
}
|
||||
|
||||
Foam::combineReduce(result, maxFirstEqOp<T1>());
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
|
||||
@ -39,6 +39,7 @@ SourceFiles
|
||||
|
||||
#include "flipOp.H"
|
||||
#include "ListOps.H"
|
||||
#include "Tuple2.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
@ -189,6 +190,26 @@ void ternarySelect
|
||||
}
|
||||
|
||||
|
||||
//- Locate the min value in a field and return it and associated data
|
||||
// This can be used, for example, to return a value/position combination.
|
||||
template<class T1, class T2>
|
||||
Tuple2<T1,T2> findMinData
|
||||
(
|
||||
const Field<T1>& vals,
|
||||
const Field<T2>& data
|
||||
);
|
||||
|
||||
|
||||
//- Locate the max value in a field and return it and associated data
|
||||
// This can be used, for example, to return a value/position combination.
|
||||
template<class T1, class T2>
|
||||
Tuple2<T1,T2> findMaxData
|
||||
(
|
||||
const Field<T1>& vals,
|
||||
const Field<T2>& data
|
||||
);
|
||||
|
||||
|
||||
} // End namespace FieldOps
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
Reference in New Issue
Block a user