Commit 9f0a80a6 authored by Mark Olesen's avatar Mark Olesen
Browse files

STYLE: avoid unrestricted dictionary lookup in randomProcesses, waveModels

- ref issue #762

STYLE: consistency in file vs files for pointNoise and surfaceNoise

- use "files" when available, fallback to "file" otherwise.
parent 18b13431
......@@ -144,8 +144,8 @@ Foam::fft::realTransform1D(const scalarField& field)
fftw_execute(plan);
// field[0] = DC component
tmp<complexField> tresult(new complexField(nBy2 + 1));
complexField& result = tresult.ref();
auto tresult = tmp<complexField>::New(nBy2 + 1);
auto& result = tresult.ref();
result[0].Re() = out[0];
result[nBy2].Re() = out[nBy2];
......@@ -237,7 +237,7 @@ Foam::tmp<Foam::complexField> Foam::fft::forwardTransform
const UList<int>& nn
)
{
tmp<complexField> tresult(new complexField(tfield));
auto tresult = tmp<complexField>::New(tfield);
transform(tresult.ref(), nn, FORWARD_TRANSFORM);
......@@ -253,7 +253,7 @@ Foam::tmp<Foam::complexField> Foam::fft::reverseTransform
const UList<int>& nn
)
{
tmp<complexField> tresult(new complexField(tfield));
auto tresult = tmp<complexField>::New(tfield);
transform(tresult.ref(), nn, REVERSE_TRANSFORM);
......
......@@ -43,10 +43,10 @@ Foam::tmp<Foam::scalarField> Foam::noiseFFT::frequencies
const scalar deltaT
)
{
tmp<scalarField> tf(new scalarField(N/2, 0));
scalarField& f = tf.ref();
auto tf = tmp<scalarField>::New(N/2, Zero);
auto& f = tf.ref();
scalar deltaf = 1.0/(N*deltaT);
const scalar deltaf = 1.0/(N*deltaT);
forAll(f, i)
{
f[i] = i*deltaf;
......@@ -297,8 +297,8 @@ Foam::tmp<Foam::scalarField> Foam::noiseFFT::Pf
const label n = planInfo_.windowSize;
const label nBy2 = n/2;
tmp<scalarField> tresult(new scalarField(nBy2 + 1));
scalarField& result = tresult.ref();
auto tresult = tmp<scalarField>::New(nBy2 + 1);
auto& result = tresult.ref();
// 0 th value = DC component
// nBy2 th value = real only if n is even
......@@ -312,10 +312,8 @@ Foam::tmp<Foam::scalarField> Foam::noiseFFT::Pf
return tresult;
}
else
{
return mag(fft::realTransform1D(tpn));
}
return mag(fft::realTransform1D(tpn));
}
......
......@@ -109,7 +109,7 @@ public:
//- Construct from pressure field
noiseFFT(const scalar deltaT, const label windowSize = -1);
//- Destructor
//- Destructor. Cleanup/destroy plan
~noiseFFT();
......
......@@ -183,12 +183,6 @@ Foam::noiseModel::noiseModel(const dictionary& dict, const bool readFields)
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::noiseModel::~noiseModel()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::noiseModel::read(const dictionary& dict)
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2015-2017 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2015-2018 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -66,7 +66,6 @@ Description
writeOctaves | Write octaves data | no | yes
\endtable
SourceFiles
noiseModel.C
......@@ -92,18 +91,6 @@ namespace Foam
class noiseModel
{
private:
// Private Member Functions
//- No copy construct
noiseModel(const noiseModel&) = delete;
//- No copy assignment
void operator=(const noiseModel&) = delete;
protected:
// Protected Data
......@@ -196,6 +183,13 @@ protected:
fileName baseFileDir(const label dataseti) const;
//- No copy construct
noiseModel(const noiseModel&) = delete;
//- No copy assignment
void operator=(const noiseModel&) = delete;
public:
//- Runtime type information
......@@ -220,7 +214,7 @@ public:
noiseModel(const dictionary& dict, const bool readFields = true);
//- Destructor
virtual ~noiseModel();
virtual ~noiseModel() = default;
// Public Member Functions
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2016-2018 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -29,7 +29,7 @@ License
Foam::autoPtr<Foam::noiseModel> Foam::noiseModel::New(const dictionary& dict)
{
const word modelType(dict.lookup("noiseModel"));
const word modelType(dict.get<word>("noiseModel"));
Info<< "Selecting noiseModel " << modelType << endl;
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2015-2017 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2015-2018 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -226,12 +226,6 @@ pointNoise::pointNoise(const dictionary& dict, const bool readFields)
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
pointNoise::~pointNoise()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void pointNoise::calculate()
......@@ -242,7 +236,6 @@ void pointNoise::calculate()
return;
}
forAll(inputFileNames_, filei)
{
fileName fName = inputFileNames_[filei];
......@@ -264,10 +257,10 @@ bool pointNoise::read(const dictionary& dict)
{
if (!dict.readIfPresent("files", inputFileNames_))
{
inputFileNames_.setSize(1);
inputFileNames_.resize(1);
// Note: lookup uses same keyword as used by the CSV constructor
dict.lookup("file") >> inputFileNames_[0];
dict.read("file", inputFileNames_.first());
}
return true;
......
......@@ -130,7 +130,7 @@ public:
pointNoise(const dictionary& dict, const bool readFields = true);
//- Destructor
virtual ~pointNoise();
virtual ~pointNoise() = default;
// Public Member Functions
......
......@@ -428,22 +428,18 @@ bool surfaceNoise::read(const dictionary& dict)
{
if (noiseModel::read(dict))
{
if (dict.found("file"))
if (!dict.readIfPresent("files", inputFileNames_))
{
inputFileNames_.setSize(1);
dict.lookup("file") >> inputFileNames_[0];
}
else
{
dict.lookup("files") >> inputFileNames_;
inputFileNames_.resize(1);
dict.read("file", inputFileNames_.first());
}
dict.readIfPresent("fftWriteInterval", fftWriteInterval_);
dict.readIfPresent("p", pName_);
dict.lookup("reader") >> readerType_;
dict.read("reader", readerType_);
word writerType(dict.lookup("writer"));
const word writerType(dict.get<word>("writer"));
dictionary optDict
(
dict.subOrEmptyDict("writeOptions").subOrEmptyDict(writerType)
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2015-2017 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2015-2018 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......
......@@ -63,10 +63,10 @@ UOprocess::UOprocess
RootDeltaT(sqrt(DeltaT)),
UOfield(Mesh.size()),
Alpha(readScalar(UOdict.lookup("UOalpha"))),
Sigma(readScalar(UOdict.lookup("UOsigma"))),
Kupper(readScalar(UOdict.lookup("UOKupper"))),
Klower(readScalar(UOdict.lookup("UOKlower"))),
Alpha(UOdict.get<scalar>("UOalpha")),
Sigma(UOdict.get<scalar>("UOsigma")),
Kupper(UOdict.get<scalar>("UOKupper")),
Klower(UOdict.get<scalar>("UOKlower")),
Scale((Kupper - Klower)*pow(scalar(Mesh.size()), 1.0/vector::dim))
{
const vectorField& K = Mesh;
......
......@@ -45,13 +45,13 @@ addToRunTimeSelectionTable(windowModel, Hanning, dictionary);
Hanning::Hanning(const dictionary& dict, const label nSamples)
:
windowModel(dict, nSamples),
symmetric_(readBool(dict.lookup("symmetric"))),
extended_(readBool(dict.lookup("extended"))),
symmetric_(dict.get<bool>("symmetric")),
extended_(dict.get<bool>("extended")),
alpha_(dict.lookupOrDefault("alpha", 0.5)) // Hamming = 0.54
{
// Extend range if required
label offset = extended_ ? 1 : 0;
scalar m = nSamples - 1 + 2*offset;
const label offset = extended_ ? 1 : 0;
const scalar m = nSamples - 1 + 2*offset;
scalarField t(nSamples);
forAll(t, i)
......@@ -81,19 +81,13 @@ Hanning::Hanning(const dictionary& dict, const label nSamples)
}
}
scalar sumSqr = sum(sqr(wf));
const scalar sumSqr = sum(sqr(wf));
// Normalisation
wf *= sqrt(nSamples/sumSqr);
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Hanning::~Hanning()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Hanning::symmetric() const
......
......@@ -97,7 +97,7 @@ public:
Hanning(const dictionary& dict, const label nSamples);
//- Destructor
virtual ~Hanning();
virtual ~Hanning() = default;
// Public Member Functions
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2016-2018 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -45,19 +45,13 @@ addToRunTimeSelectionTable(windowModel, uniform, dictionary);
uniform::uniform(const dictionary& dict, const label nSamples)
:
windowModel(dict, nSamples),
value_(readScalar(dict.lookup("value")))
value_(dict.get<scalar>("value"))
{
scalarField& wf = *this;
wf = value_;
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
uniform::~uniform()
{}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace windowModels
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2016-2018 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -73,7 +73,7 @@ public:
uniform(const dictionary& dict, const label nSamples);
//- Destructor
virtual ~uniform();
virtual ~uniform() = default;
};
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2015-2016 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2015-2018 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -42,17 +42,13 @@ Foam::windowModel::windowModel(const dictionary& dict, const label nSamples)
nOverlapSamples_(0),
nWindow_(dict.lookupOrDefault("nWindow", -1))
{
scalar prc = readScalar(dict.lookup("overlapPercent"));
nOverlapSamples_ = floor(prc/scalar(100)*nSamples);
nOverlapSamples_ = floor
(
dict.get<scalar>("overlapPercent")/scalar(100)*nSamples
);
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::windowModel::~windowModel()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::label Foam::windowModel::nSamples() const
......@@ -87,7 +83,7 @@ Foam::label Foam::windowModel::validate(const label nSamplesTotal)
<< exit(FatalError);
}
label nWindowAvailable = nWindowsTotal(nSamplesTotal);
const label nWindowAvailable = nWindowsTotal(nSamplesTotal);
if (nWindow_ == -1)
{
......@@ -107,7 +103,7 @@ Foam::label Foam::windowModel::validate(const label nSamplesTotal)
<< exit(FatalError);
}
label nRequiredSamples =
const label nRequiredSamples =
nWindow_*nSamples - (nWindow_ - 1)*nOverlapSamples_;
Info<< "Windowing:" << nl
......
......@@ -2,8 +2,8 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2016-2018 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -98,7 +98,7 @@ public:
//- Destructor
virtual ~windowModel();
virtual ~windowModel() = default;
// Public Member Functions
......
......@@ -33,7 +33,7 @@ Foam::autoPtr<Foam::windowModel> Foam::windowModel::New
const label nSamples
)
{
const word modelType(dict.lookup("windowModel"));
const word modelType(dict.get<word>("windowModel"));
Info<< "Selecting windowModel " << modelType << endl;
......@@ -53,7 +53,6 @@ Foam::autoPtr<Foam::windowModel> Foam::windowModel::New
(
cstrIter()(dict.subDict(modelType + "Coeffs"), nSamples)
);
}
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2015-2016 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2015-2018 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -48,8 +48,8 @@ Foam::tmp<Foam::Field<Type>> Foam::windowModel::apply
}
tmp<Field<Type>> tresult(new Field<Type>(nSamples, pTraits<Type>::zero));
Field<Type>& result = tresult.ref();
auto tresult = tmp<Field<Type>>::New(nSamples, Zero);
auto& result = tresult.ref();
label nWindow = nWindowsTotal(fld.size());
if (windowI >= nWindow)
......
......@@ -53,7 +53,7 @@ namespace fv
Foam::tmp<Foam::volScalarField>
Foam::fv::multiphaseMangrovesSource::dragCoeff(const volVectorField& U) const
{
tmp<volScalarField> tdragCoeff = tmp<volScalarField>::New
auto tdragCoeff = tmp<volScalarField>::New
(
IOobject
(
......@@ -66,8 +66,7 @@ Foam::fv::multiphaseMangrovesSource::dragCoeff(const volVectorField& U) const
mesh_,
dimensionedScalar(dimless/dimTime, Zero)
);
volScalarField& dragCoeff = tdragCoeff.ref();
auto& dragCoeff = tdragCoeff.ref();
forAll(zoneIDs_, i)
{
......@@ -99,7 +98,7 @@ Foam::fv::multiphaseMangrovesSource::dragCoeff(const volVectorField& U) const
Foam::tmp<Foam::volScalarField>
Foam::fv::multiphaseMangrovesSource::inertiaCoeff() const
{
tmp<volScalarField> tinertiaCoeff = tmp<volScalarField>::New
auto tinertiaCoeff = tmp<volScalarField>::New
(
IOobject
(
......@@ -112,8 +111,7 @@ Foam::fv::multiphaseMangrovesSource::inertiaCoeff() const
mesh_,
dimensionedScalar(dimless, Zero)
);
volScalarField& inertiaCoeff = tinertiaCoeff.ref();
auto& inertiaCoeff = tinertiaCoeff.ref();
const scalar pi = constant::mathematical::pi;
......@@ -229,7 +227,7 @@ bool Foam::fv::multiphaseMangrovesSource::read(const dictionary& dict)
const word& regionName = regionNames[i];
const dictionary& modelDict = regionsDict.subDict(regionName);
const word& zoneName = modelDict.lookup("cellZone");
const word zoneName(modelDict.get<word>("cellZone"));
zoneIDs_[i] = mesh_.cellZones().findIndices(zoneName);
if (zoneIDs_[i].empty())
{
......@@ -239,18 +237,16 @@ bool Foam::fv::multiphaseMangrovesSource::read(const dictionary& dict)
<< exit(FatalError);
}
modelDict.lookup("a") >> aZone_[i];
modelDict.lookup("N") >> NZone_[i];
modelDict.lookup("Cm") >> CmZone_[i];
modelDict.lookup("Cd") >> CdZone_[i];
modelDict.read("a", aZone_[i]);
modelDict.read("N", NZone_[i]);
modelDict.read("Cm", CmZone_[i]);
modelDict.read("Cd", CdZone_[i]);
}
return true;
}
else
{
return false;
}
return false;
}
......
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