ENH: Re-homed helper list and combine classes

This commit is contained in:
andy
2012-11-21 17:11:24 +00:00
parent 37f3793b7a
commit c7604c8a7e
4 changed files with 110 additions and 96 deletions

View File

@ -245,6 +245,15 @@ template<class Container, class T, int nRows, int nColumns>
List<Container> initListList(const T[nRows][nColumns]);
//- Helper class for list to append y onto the end of x
template<class T>
class ListAppendEqOp
{
public:
void operator()(List<T>& x, const List<T>& y) const;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam

View File

@ -684,4 +684,26 @@ Foam::List<Container> Foam::initListList(const T elems[nRows][nColumns])
}
template<class T>
void Foam::ListAppendEqOp<T>::operator()(List<T>& x, const List<T>& y) const
{
if (y.size())
{
if (x.size())
{
label sz = x.size();
x.setSize(sz + y.size());
forAll(y, i)
{
x[sz++] = y[i];
}
}
else
{
x = y;
}
}
}
// ************************************************************************* //

View File

@ -90,40 +90,68 @@ EqOp(nopEq, (void)x)
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#define Op(opName, op) \
\
template<class T, class T1, class T2> \
class opName##Op3 \
{ \
public: \
\
T operator()(const T1& x, const T2& y) const \
{ \
return op; \
} \
}; \
\
template<class T1, class T2> \
class opName##Op2 \
{ \
public: \
\
T1 operator()(const T1& x, const T2& y) const \
{ \
return op; \
} \
}; \
\
template<class T> \
class opName##Op \
{ \
public: \
\
T operator()(const T& x, const T& y) const \
{ \
return op; \
} \
};
#define Op(opName, op) \
\
template<class T, class T1, class T2> \
class opName##Op3 \
{ \
public: \
\
T operator()(const T1& x, const T2& y) const \
{ \
return op; \
} \
}; \
\
template<class T1, class T2> \
class opName##Op2 \
{ \
public: \
\
T1 operator()(const T1& x, const T2& y) const \
{ \
return op; \
} \
}; \
\
template<class T> \
class opName##Op \
{ \
public: \
\
T operator()(const T& x, const T& y) const \
{ \
return op; \
} \
};
#define weightedOp(opName, op) \
\
template<class Type, class CombineOp> \
class opName##WeightedOp \
{ \
const CombineOp& cop_; \
\
public: \
\
opName##WeightedOp(const CombineOp& cop) \
: \
cop_(cop) \
{} \
\
void operator() \
( \
Type& x, \
const label index, \
const Type& y, \
const scalar weight \
) const \
{ \
cop_(x, op); \
} \
}; \
Op(sum, x + y)
@ -147,6 +175,8 @@ Op(lessEq, x <= y)
Op(greater, x > y)
Op(greaterEq, x >= y)
weightedOp(multiply, weight * y)
#undef Op

View File

@ -27,63 +27,6 @@ License
#include "meshTools.H"
#include "mapDistribute.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
//- Helper class for list
template<class T>
class ListPlusEqOp
{
public:
void operator()(List<T>& x, const List<T> y) const
{
if (y.size())
{
if (x.size())
{
label sz = x.size();
x.setSize(sz + y.size());
forAll(y, i)
{
x[sz++] = y[i];
}
}
else
{
x = y;
}
}
}
};
//- Combine operator for interpolateToSource/Target
template<class Type, class CombineOp>
class combineBinaryOp
{
const CombineOp& cop_;
public:
combineBinaryOp(const CombineOp& cop)
:
cop_(cop)
{}
void operator()
(
Type& x,
const label faceI,
const Type& y,
const scalar weight
) const
{
cop_(x, weight*y);
}
};
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
template<class SourcePatch, class TargetPatch>
@ -1550,7 +1493,7 @@ void Foam::AMIInterpolation<SourcePatch, TargetPatch>::update
}
// send data back to originating procs. Note that contributions
// from different processors get added (ListPlusEqOp)
// from different processors get added (ListAppendEqOp)
mapDistribute::distribute
(
@ -1560,7 +1503,7 @@ void Foam::AMIInterpolation<SourcePatch, TargetPatch>::update
map.constructMap(),
map.subMap(),
tgtAddress_,
ListPlusEqOp<label>(),
ListAppendEqOp<label>(),
labelList()
);
@ -1572,7 +1515,7 @@ void Foam::AMIInterpolation<SourcePatch, TargetPatch>::update
map.constructMap(),
map.subMap(),
tgtWeights_,
ListPlusEqOp<scalar>(),
ListAppendEqOp<scalar>(),
scalarList()
);
@ -1787,7 +1730,12 @@ Foam::AMIInterpolation<SourcePatch, TargetPatch>::interpolateToSource
)
);
interpolateToSource(fld, combineBinaryOp<Type, CombineOp>(cop), tresult());
interpolateToSource
(
fld,
multiplyWeightedOp<Type, CombineOp>(cop),
tresult()
);
return tresult;
}
@ -1824,7 +1772,12 @@ Foam::AMIInterpolation<SourcePatch, TargetPatch>::interpolateToTarget
)
);
interpolateToTarget(fld, combineBinaryOp<Type, CombineOp>(cop), tresult());
interpolateToTarget
(
fld,
multiplyWeightedOp<Type, CombineOp>(cop),
tresult()
);
return tresult;
}