STYLE: add namespace qualifiers to interpolationWeights

This commit is contained in:
Mark Olesen
2019-05-16 14:06:40 +01:00
committed by Andrew Heather
parent e6a2083281
commit 29e6c81af8
7 changed files with 78 additions and 115 deletions

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | \\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
| Copyright (C) 2012-2015 OpenFOAM Foundation | Copyright (C) 2012-2015 OpenFOAM Foundation
@ -33,9 +33,9 @@ License
namespace Foam namespace Foam
{ {
defineTypeNameAndDebug(interpolationWeights, 0); defineTypeNameAndDebug(interpolationWeights, 0);
defineRunTimeSelectionTable(interpolationWeights, word); defineRunTimeSelectionTable(interpolationWeights, word);
} } // End namespace Foam
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
@ -77,10 +77,4 @@ Foam::autoPtr<Foam::interpolationWeights> Foam::interpolationWeights::New
} }
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::interpolationWeights::~interpolationWeights()
{}
// ************************************************************************* // // ************************************************************************* //

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | \\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
| Copyright (C) 2012-2016 OpenFOAM Foundation | Copyright (C) 2012-2016 OpenFOAM Foundation
@ -57,10 +57,14 @@ class objectRegistry;
class interpolationWeights class interpolationWeights
{ {
protected:
private: // Protected Data
// Private Member Functions const scalarField& samples_;
// Protected Member Functions
//- No copy construct //- No copy construct
interpolationWeights(const interpolationWeights&) = delete; interpolationWeights(const interpolationWeights&) = delete;
@ -68,9 +72,6 @@ private:
//- No copy assignment //- No copy assignment
void operator=(const interpolationWeights&) = delete; void operator=(const interpolationWeights&) = delete;
protected:
const scalarField& samples_;
public: public:
@ -95,7 +96,7 @@ public:
// Constructors // Constructors
//- Construct from components //- Construct from components
interpolationWeights(const scalarField& samples); explicit interpolationWeights(const scalarField& samples);
// Selectors // Selectors
@ -109,7 +110,7 @@ public:
//- Destructor //- Destructor
virtual ~interpolationWeights(); virtual ~interpolationWeights() = default;
// Member Functions // Member Functions

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | \\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
| Copyright (C) 2012-2016 OpenFOAM Foundation | Copyright (C) 2012-2016 OpenFOAM Foundation
@ -26,15 +26,7 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "interpolationWeights.H" #include "interpolationWeights.H"
#include "ListOps.H" #include "products.H"
#include "IOobject.H"
#include "HashSet.H"
#include "objectRegistry.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
@ -56,24 +48,19 @@ Foam::interpolationWeights::weightedSum
typename ListType2::value_type typename ListType2::value_type
>::type returnType; >::type returnType;
if (f1.size()) const label len = f1.size();
if (len)
{ {
returnType SumProd = f1[0]*f2[0]; returnType SumProd = f1[0]*f2[0];
for (label i = 1; i < f1.size(); ++i) for (label i = 1; i < len; ++i)
{ {
SumProd += f1[i]*f2[i]; SumProd += f1[i]*f2[i];
} }
return SumProd; return SumProd;
} }
else
{ return Zero;
return Zero;
}
} }
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* // // ************************************************************************* //

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | \\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
| Copyright (C) 2012-2015 OpenFOAM Foundation | Copyright (C) 2012-2015 OpenFOAM Foundation
@ -30,25 +30,23 @@ License
#include "ListOps.H" #include "ListOps.H"
#include "Pair.H" #include "Pair.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam namespace Foam
{ {
defineTypeNameAndDebug(linearInterpolationWeights, 0);
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // addToRunTimeSelectionTable
(
defineTypeNameAndDebug(linearInterpolationWeights, 0); interpolationWeights,
addToRunTimeSelectionTable linearInterpolationWeights,
( word
interpolationWeights, );
linearInterpolationWeights, } // End namespace Foam
word
);
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
Foam::Pair<Foam::scalar> linearInterpolationWeights::integrationWeights Foam::Pair<Foam::scalar> Foam::linearInterpolationWeights::integrationWeights
( (
const label i, const label i,
const scalar t const scalar t
@ -56,7 +54,7 @@ Foam::Pair<Foam::scalar> linearInterpolationWeights::integrationWeights
{ {
// t is in range samples_[i] .. samples_[i+1] // t is in range samples_[i] .. samples_[i+1]
scalar s = (t-samples_[i])/(samples_[i+1]-samples_[i]); const scalar s = (t-samples_[i])/(samples_[i+1]-samples_[i]);
if (s < -SMALL || s > 1+SMALL) if (s < -SMALL || s > 1+SMALL)
{ {
@ -66,7 +64,7 @@ Foam::Pair<Foam::scalar> linearInterpolationWeights::integrationWeights
<< exit(FatalError); << exit(FatalError);
} }
scalar d = samples_[i+1]-t; const scalar d = samples_[i+1]-t;
return Pair<scalar>(d*0.5*(1-s), d*0.5*(1+s)); return Pair<scalar>(d*0.5*(1-s), d*0.5*(1+s));
} }
@ -74,7 +72,7 @@ Foam::Pair<Foam::scalar> linearInterpolationWeights::integrationWeights
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
linearInterpolationWeights::linearInterpolationWeights Foam::linearInterpolationWeights::linearInterpolationWeights
( (
const scalarField& samples const scalarField& samples
) )
@ -86,7 +84,7 @@ linearInterpolationWeights::linearInterpolationWeights
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool linearInterpolationWeights::valueWeights bool Foam::linearInterpolationWeights::valueWeights
( (
const scalar t, const scalar t,
labelList& indices, labelList& indices,
@ -153,7 +151,7 @@ bool linearInterpolationWeights::valueWeights
} }
bool linearInterpolationWeights::integrationWeights bool Foam::linearInterpolationWeights::integrationWeights
( (
const scalar t1, const scalar t1,
const scalar t2, const scalar t2,
@ -172,9 +170,10 @@ bool linearInterpolationWeights::integrationWeights
// Currently no fancy logic on cached index like in value // Currently no fancy logic on cached index like in value
//- Find lower or equal index //- Find lower or equal index
label i1 = findLower(samples_, t1, 0, lessEqOp<scalar>()); const label i1 = findLower(samples_, t1, 0, lessEqOp<scalar>());
//- Find lower index //- Find lower index
label i2 = findLower(samples_, t2); const label i2 = findLower(samples_, t2);
// For now just fail if any outside table // For now just fail if any outside table
if (i1 == -1 || i2 == samples_.size()-1) if (i1 == -1 || i2 == samples_.size()-1)
@ -185,7 +184,7 @@ bool linearInterpolationWeights::integrationWeights
<< " t1:" << t1 << " t2:" << t2 << exit(FatalError); << " t1:" << t1 << " t2:" << t2 << exit(FatalError);
} }
label nIndices = i2-i1+2; const label nIndices = i2-i1+2;
// Determine if indices already correct // Determine if indices already correct
@ -218,7 +217,7 @@ bool linearInterpolationWeights::integrationWeights
// Sum from i1+1 to i2+1 // Sum from i1+1 to i2+1
for (label i = i1+1; i <= i2; i++) for (label i = i1+1; i <= i2; i++)
{ {
scalar d = samples_[i+1]-samples_[i]; const scalar d = samples_[i+1]-samples_[i];
indices[i-i1] = i; indices[i-i1] = i;
weights[i-i1] += 0.5*d; weights[i-i1] += 0.5*d;
indices[i+1-i1] = i+1; indices[i+1-i1] = i+1;
@ -227,19 +226,19 @@ bool linearInterpolationWeights::integrationWeights
// Add from i1 to t1 // Add from i1 to t1
{ {
Pair<scalar> i1Tot1 = integrationWeights(i1, t1); const Pair<scalar> i1Tot1 = integrationWeights(i1, t1);
indices[0] = i1; indices[0] = i1;
weights[0] += i1Tot1.first();
indices[1] = i1+1; indices[1] = i1+1;
weights[0] += i1Tot1.first();
weights[1] += i1Tot1.second(); weights[1] += i1Tot1.second();
} }
// Subtract from t2 to i2+1 // Subtract from t2 to i2+1
{ {
Pair<scalar> wghts = integrationWeights(i2, t2); const Pair<scalar> wghts = integrationWeights(i2, t2);
indices[i2-i1] = i2; indices[i2-i1] = i2;
weights[i2-i1] += -wghts.first();
indices[i2-i1+1] = i2+1; indices[i2-i1+1] = i2+1;
weights[i2-i1] += -wghts.first();
weights[i2-i1+1] += -wghts.second(); weights[i2-i1+1] += -wghts.second();
} }
@ -247,8 +246,4 @@ bool linearInterpolationWeights::integrationWeights
} }
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* // // ************************************************************************* //

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | \\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
| Copyright (C) 2012 OpenFOAM Foundation | Copyright (C) 2012 OpenFOAM Foundation
@ -51,47 +51,39 @@ class linearInterpolationWeights
: :
public interpolationWeights public interpolationWeights
{ {
// Private Data
private:
// Private data
//- Cached index in samples from previous invocation //- Cached index in samples from previous invocation
mutable label index_; mutable label index_;
// Private Member Functions // Private Member Functions
//- Get weights of i and i+1 to calculate integration from t to //- Get weights of i and i+1 to calculate integration from t to
// samples_[i+1] //- samples_[i+1]
Pair<scalar> integrationWeights Pair<scalar> integrationWeights(const label i, const scalar t) const;
(
const label i,
const scalar t
) const;
public: public:
//- Runtime type information //- Runtime type information
TypeName("linear"); TypeName("linear");
// Constructors // Constructors
//- Construct from components //- Construct from components
linearInterpolationWeights explicit linearInterpolationWeights(const scalarField& samples);
(
const scalarField& samples
);
//- Destructor //- Destructor
virtual ~linearInterpolationWeights() virtual ~linearInterpolationWeights() = default;
{}
// Member Functions // Member Functions
//- Calculate weights and indices to calculate t from samples. //- Calculate weights and indices to calculate t from samples.
// Returns true if indices changed. // \return true if indices changed.
virtual bool valueWeights virtual bool valueWeights
( (
const scalar t, const scalar t,
@ -100,7 +92,8 @@ public:
) const; ) const;
//- Calculate weights and indices to calculate integrand of t1..t2 //- Calculate weights and indices to calculate integrand of t1..t2
// from samples. Returns true if indices changed. //- from samples.
// \return true if indices changed.
virtual bool integrationWeights virtual bool integrationWeights
( (
const scalar t1, const scalar t1,

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | \\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
| Copyright (C) 2012-2015 OpenFOAM Foundation | Copyright (C) 2012-2015 OpenFOAM Foundation
@ -30,25 +30,23 @@ License
#include "ListOps.H" #include "ListOps.H"
#include "linearInterpolationWeights.H" #include "linearInterpolationWeights.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam namespace Foam
{ {
defineTypeNameAndDebug(splineInterpolationWeights, 0);
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // addToRunTimeSelectionTable
(
defineTypeNameAndDebug(splineInterpolationWeights, 0); interpolationWeights,
addToRunTimeSelectionTable splineInterpolationWeights,
( word
interpolationWeights, );
splineInterpolationWeights, } // End namespace Foam
word
);
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
splineInterpolationWeights::splineInterpolationWeights Foam::splineInterpolationWeights::splineInterpolationWeights
( (
const scalarField& samples, const scalarField& samples,
const bool checkEqualDistance const bool checkEqualDistance
@ -80,7 +78,7 @@ splineInterpolationWeights::splineInterpolationWeights
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool splineInterpolationWeights::valueWeights bool Foam::splineInterpolationWeights::valueWeights
( (
const scalar t, const scalar t,
labelList& indices, labelList& indices,
@ -220,8 +218,4 @@ bool splineInterpolationWeights::valueWeights
} }
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* // // ************************************************************************* //

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | \\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
| Copyright (C) 2012-2015 OpenFOAM Foundation | Copyright (C) 2012-2015 OpenFOAM Foundation
@ -52,24 +52,23 @@ class splineInterpolationWeights
: :
public interpolationWeights public interpolationWeights
{ {
// Private Data
private:
// Private data
//- Cached index in samples from previous invocation //- Cached index in samples from previous invocation
mutable label index_; mutable label index_;
public: public:
//- Runtime type information //- Runtime type information
TypeName("spline"); TypeName("spline");
// Constructors // Constructors
//- Construct from components. By default make sure samples are //- Construct from components. By default make sure samples are
// equidistant. // equidistant.
splineInterpolationWeights explicit splineInterpolationWeights
( (
const scalarField& samples, const scalarField& samples,
const bool checkEqualDistance = true const bool checkEqualDistance = true
@ -77,14 +76,13 @@ public:
//- Destructor //- Destructor
virtual ~splineInterpolationWeights() virtual ~splineInterpolationWeights() = default;
{}
// Member Functions // Member Functions
//- Calculate weights and indices to calculate t from samples. //- Calculate weights and indices to calculate t from samples.
// Returns true if indices changed. // \return true if indices changed.
virtual bool valueWeights virtual bool valueWeights
( (
const scalar t, const scalar t,
@ -93,7 +91,8 @@ public:
) const; ) const;
//- Calculate weights and indices to calculate integrand of t1..t2 //- Calculate weights and indices to calculate integrand of t1..t2
// from samples. Returns true if indices changed. //- from samples.
// \return true if indices changed.
virtual bool integrationWeights virtual bool integrationWeights
( (
const scalar t1, const scalar t1,