Skip to content
Snippets Groups Projects
Commit 4c7c03e1 authored by mattijs's avatar mattijs
Browse files

ENH: interpolationWeights: added weightedSum helper

parent 69ee818c
Branches
Tags
No related merge requests found
......@@ -131,6 +131,15 @@ public:
scalarField& weights
) const = 0;
//- Helper: weighted sum
template<class ListType1, class ListType2>
static typename outerProduct
<
typename ListType1::value_type,
typename ListType2::value_type
>::type
weightedSum(const ListType1& f1, const ListType2& f2);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......@@ -139,6 +148,12 @@ public:
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
# include "interpolationWeightsTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //
......@@ -36,135 +36,38 @@ namespace Foam
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
//template<class GeoField>
//void interpolationWeights::readFields
//(
// const word& fieldName,
// const typename GeoField::Mesh& mesh,
// const wordList& timeNames,
// objectRegistry& fieldsCache
//)
//{
// // Collect all times that are no longer used
// {
// HashSet<word> usedTimes(timeNames);
//
// DynamicList<word> unusedTimes(fieldsCache.size());
//
// forAllIter(objectRegistry, fieldsCache, timeIter)
// {
// const word& tm = timeIter.key();
// if (!usedTimes.found(tm))
// {
// unusedTimes.append(tm);
// }
// }
//
// //Info<< "Unloading times " << unusedTimes << endl;
//
// forAll(unusedTimes, i)
// {
// objectRegistry& timeCache = const_cast<objectRegistry&>
// (
// fieldsCache.lookupObject<objectRegistry>(unusedTimes[i])
// );
// fieldsCache.checkOut(timeCache);
// }
// }
//
//
// // Load any new fields
// forAll(timeNames, i)
// {
// const word& tm = timeNames[i];
//
// // Create if not found
// if (!fieldsCache.found(tm))
// {
// //Info<< "Creating registry for time " << tm << endl;
//
// // Create objectRegistry if not found
// objectRegistry* timeCachePtr = new objectRegistry
// (
// IOobject
// (
// tm,
// tm,
// fieldsCache,
// IOobject::NO_READ,
// IOobject::NO_WRITE
// )
// );
// timeCachePtr->store();
// }
//
// // Obtain cache for current time
// const objectRegistry& timeCache =
// fieldsCache.lookupObject<objectRegistry>
// (
// tm
// );
//
// // Store field if not found
// if (!timeCache.found(fieldName))
// {
// //Info<< "Loading field " << fieldName
// // << " for time " << tm << endl;
//
// GeoField loadedFld
// (
// IOobject
// (
// fieldName,
// tm,
// mesh.thisDb(),
// IOobject::MUST_READ,
// IOobject::NO_WRITE,
// false
// ),
// mesh
// );
//
// // Transfer to timeCache (new objectRegistry and store flag)
// GeoField* fldPtr = new GeoField
// (
// IOobject
// (
// fieldName,
// tm,
// timeCache,
// IOobject::NO_READ,
// IOobject::NO_WRITE
// ),
// loadedFld
// );
// fldPtr->store();
// }
// }
//}
//
//
//template<class GeoField>
//void interpolationWeights::readFields
//(
// const word& fieldName,
// const typename GeoField::Mesh& mesh,
// const wordList& timeNames,
// const word& registryName
//)
//{
// readFields<GeoField>
// (
// fieldName,
// mesh,
// timeNames,
// //registry(mesh.thisDb(), registryName)
// const_cast<objectRegistry&>
// (
// mesh.thisDb().subRegistry(registryName, true)
// )
// );
//}
template<class ListType1, class ListType2>
typename Foam::outerProduct
<
typename ListType1::value_type,
typename ListType2::value_type
>::type
Foam::interpolationWeights::weightedSum
(
const ListType1& f1,
const ListType2& f2
)
{
typedef typename outerProduct
<
typename ListType1::value_type,
typename ListType2::value_type
>::type returnType;
if (f1.size())
{
returnType SumProd = f1[0]*f2[0];
for (label i = 1; i < f1.size(); ++i)
{
SumProd += f1[i]*f2[i];
}
return SumProd;
}
else
{
return pTraits<returnType>::zero;
}
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......
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