Commit e7c1d469 authored by Mark Olesen's avatar Mark Olesen
Browse files

ENH: avoid raw dictionary lookup in fvOptions (issue #762)

Style changes:
    - use lookupObjectRef instead of using const_cast
    - use tmp::New factory
parent de2eed3e
......@@ -461,7 +461,7 @@ void Foam::Time::readDict()
(
IOstreamOption::versionNumber
(
controlDict_.lookup("writeVersion")
controlDict_.get<float>("writeVersion")
)
);
}
......
cellSetOption/cellSetOption.C
cellSetOption/cellSetOptionIO.C
interRegionOption/interRegionOption.C
interRegionOption/interRegionOptionIO.C
/* Sources */
......@@ -14,18 +10,13 @@ $(generalSources)/semiImplicitSource/semiImplicitSource.C
derivedSources=sources/derived
$(derivedSources)/acousticDampingSource/acousticDampingSource.C
$(derivedSources)/actuationDiskSource/actuationDiskSource.C
$(derivedSources)/buoyancyForce/buoyancyForce.C
$(derivedSources)/buoyancyForce/buoyancyForceIO.C
$(derivedSources)/buoyancyEnergy/buoyancyEnergy.C
$(derivedSources)/buoyancyEnergy/buoyancyEnergyIO.C
$(derivedSources)/buoyancyForce/buoyancyForce.C
$(derivedSources)/directionalPressureGradientExplicitSource/directionalPressureGradientExplicitSource.C
$(derivedSources)/directionalPressureGradientExplicitSource/directionalPressureGradientExplicitSourceIO.C
$(derivedSources)/effectivenessHeatExchangerSource/effectivenessHeatExchangerSource.C
$(derivedSources)/explicitPorositySource/explicitPorositySource.C
$(derivedSources)/jouleHeatingSource/jouleHeatingSource.C
$(derivedSources)/jouleHeatingSource/jouleHeatingSourceIO.C
$(derivedSources)/meanVelocityForce/meanVelocityForce.C
$(derivedSources)/meanVelocityForce/meanVelocityForceIO.C
$(derivedSources)/meanVelocityForce/patchMeanVelocityForce/patchMeanVelocityForce.C
$(derivedSources)/phaseLimitStabilization/phaseLimitStabilization.C
$(derivedSources)/radialActuationDiskSource/radialActuationDiskSource.C
......@@ -40,14 +31,12 @@ $(derivedSources)/rotorDiskSource/trimModel/trimModel/trimModelNew.C
$(derivedSources)/rotorDiskSource/trimModel/fixed/fixedTrim.C
$(derivedSources)/rotorDiskSource/trimModel/targetCoeff/targetCoeffTrim.C
$(derivedSources)/solidificationMeltingSource/solidificationMeltingSource.C
$(derivedSources)/solidificationMeltingSource/solidificationMeltingSourceIO.C
$(derivedSources)/tabulatedAccelerationSource/tabulatedAccelerationSource.C
$(derivedSources)/tabulatedAccelerationSource/tabulated6DoFAcceleration/tabulated6DoFAcceleration.C
$(derivedSources)/viscousDissipation/viscousDissipation.C
interRegion = sources/interRegion
$(interRegion)/interRegionHeatTransfer/interRegionHeatTransferModel/interRegionHeatTransferModel.C
$(interRegion)/interRegionHeatTransfer/interRegionHeatTransferModel/interRegionHeatTransferModelIO.C
$(interRegion)/interRegionHeatTransfer/constantHeatTransfer/constantHeatTransfer.C
$(interRegion)/interRegionHeatTransfer/tabulatedHeatTransfer/tabulatedHeatTransfer.C
$(interRegion)/interRegionHeatTransfer/tabulatedNTUHeatTransfer/tabulatedNTUHeatTransfer.C
......
......@@ -58,17 +58,17 @@ void Foam::fv::cellSetOption::setSelection(const dictionary& dict)
{
case smPoints:
{
dict.lookup("points") >> points_;
dict.readEntry("points", points_);
break;
}
case smCellSet:
{
dict.lookup("cellSet") >> cellSetName_;
dict.readEntry("cellSet", cellSetName_);
break;
}
case smCellZone:
{
dict.lookup("cellZone") >> cellSetName_;
dict.readEntry("cellZone", cellSetName_);
break;
}
case smAll:
......@@ -90,16 +90,17 @@ void Foam::fv::cellSetOption::setSelection(const dictionary& dict)
void Foam::fv::cellSetOption::setVol()
{
scalar VOld = V_;
// Set volume information
V_ = 0.0;
forAll(cells_, i)
scalar sumVol = 0.0;
for (const label celli : cells_)
{
V_ += mesh_.V()[cells_[i]];
sumVol += mesh_.V()[celli];
}
reduce(V_, sumOp<scalar>());
reduce(sumVol, sumOp<scalar>());
const scalar VOld = V_;
V_ = sumVol;
// Convert both volumes to representation using current writeprecision
word VOldName(Time::timeName(VOld, IOstream::defaultPrecision()));
......@@ -142,8 +143,7 @@ void Foam::fv::cellSetOption::setCellSet()
}
cells_ = selectedCells.toc();
cells_ = selectedCells.sortedToc();
break;
}
case smCellSet:
......@@ -151,9 +151,7 @@ void Foam::fv::cellSetOption::setCellSet()
Info<< indent
<< "- selecting cells using cellSet " << cellSetName_ << endl;
cellSet selectedCells(mesh_, cellSetName_);
cells_ = selectedCells.toc();
cells_ = cellSet(mesh_, cellSetName_).sortedToc();
break;
}
case smCellZone:
......@@ -169,15 +167,15 @@ void Foam::fv::cellSetOption::setCellSet()
<< "Valid cellZones are " << mesh_.cellZones().names()
<< exit(FatalError);
}
cells_ = mesh_.cellZones()[zoneID];
cells_ = mesh_.cellZones()[zoneID];
break;
}
case smAll:
{
Info<< indent << "- selecting all cells" << endl;
cells_ = identity(mesh_.nCells());
cells_ = identity(mesh_.nCells());
break;
}
default:
......@@ -222,12 +220,6 @@ Foam::fv::cellSetOption::cellSetOption
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::fv::cellSetOption::~cellSetOption()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::fv::cellSetOption::isActive()
......@@ -255,10 +247,22 @@ bool Foam::fv::cellSetOption::isActive()
return true;
}
else
return false;
}
bool Foam::fv::cellSetOption::read(const dictionary& dict)
{
if (option::read(dict))
{
return false;
if (coeffs_.readIfPresent("timeStart", timeStart_))
{
coeffs_.readEntry("duration", duration_);
}
}
return true;
}
......
......@@ -101,7 +101,7 @@ protected:
//- Cell selection mode
selectionModeType selectionMode_;
//- Name of cell set for "cellSet" and "cellZone" selectionMode
//- Name of set/zone for "cellSet" and "cellZone" selectionMode
word cellSetName_;
//- List of points for "points" selectionMode
......@@ -145,7 +145,7 @@ public:
//- Destructor
virtual ~cellSetOption();
virtual ~cellSetOption() = default;
// Member Functions
......
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "cellSetOption.H"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::fv::cellSetOption::read(const dictionary& dict)
{
if (option::read(dict))
{
if (coeffs_.readIfPresent("timeStart", timeStart_))
{
coeffs_.lookup("duration") >> duration_;
}
}
return true;
}
// ************************************************************************* //
......@@ -160,10 +160,8 @@ bool Foam::fv::fixedTemperatureConstraint::read(const dictionary& dict)
return true;
}
else
{
return false;
}
return false;
}
......
......@@ -78,7 +78,6 @@ class fixedTemperatureConstraint
:
public cellSetOption
{
public:
//- Temperature mode
......@@ -137,8 +136,7 @@ public:
//- Destructor
virtual ~fixedTemperatureConstraint()
{}
virtual ~fixedTemperatureConstraint() = default;
// Member Functions
......
......@@ -70,7 +70,7 @@ void Foam::fv::velocityDampingConstraint::addDamping(fvMatrix<vector>& eqn)
diag[cellI] += scale*(magU-UMax_);
nDamped++;
++nDamped;
}
}
......@@ -104,7 +104,7 @@ Foam::fv::velocityDampingConstraint::velocityDampingConstraint
void Foam::fv::velocityDampingConstraint::constrain
(
fvMatrix<vector>& eqn,
const label fieldI
const label fieldi
)
{
addDamping(eqn);
......@@ -122,7 +122,7 @@ bool Foam::fv::velocityDampingConstraint::read(const dictionary& dict)
{
if (cellSetOption::read(dict))
{
UMax_ = readScalar(coeffs_.lookup("UMax"));
UMax_ = coeffs_.get<scalar>("UMax");
if (!coeffs_.readIfPresent("UNames", fieldNames_))
{
......
......@@ -46,7 +46,8 @@ Description
UMax 100;
// Optional: name of velocity field (default: U)
//UName U;
//U U;
//UNames (U);
}
......@@ -68,7 +69,7 @@ namespace fv
{
/*---------------------------------------------------------------------------*\
Class velocityDampingConstraint Declaration
Class velocityDampingConstraint Declaration
\*---------------------------------------------------------------------------*/
class velocityDampingConstraint
......@@ -127,13 +128,13 @@ public:
// Set values directly
//- Constrain vector matrix
virtual void constrain(fvMatrix<vector>& eqn, const label fieldI);
virtual void constrain(fvMatrix<vector>& eqn, const label fieldi);
// I-O
//- Write data
virtual void writeData(Ostream&) const;
virtual void writeData(Ostream& os) const;
//- Read dictionary
virtual bool read(const dictionary& dict);
......
......@@ -61,18 +61,16 @@ bool Foam::fv::FixedValueConstraint<Type>::read(const dictionary& dict)
forAllConstIter(dictionary, fieldValuesDict, iter)
{
fieldNames_[i] = iter().keyword();
fieldValuesDict.lookup(iter().keyword()) >> fieldValues_[i];
i++;
fieldValuesDict.readEntry(iter().keyword(), fieldValues_[i]);
++i;
}
applied_.setSize(fieldNames_.size(), false);
return true;
}
else
{
return false;
}
return false;
}
......
......@@ -56,8 +56,8 @@ Foam::fv::limitTemperature::limitTemperature
)
:
cellSetOption(name, modelType, dict, mesh),
Tmin_(readScalar(coeffs_.lookup("min"))),
Tmax_(readScalar(coeffs_.lookup("max"))),
Tmin_(coeffs_.get<scalar>("min")),
Tmax_(coeffs_.get<scalar>("max")),
phase_(coeffs_.lookupOrDefault<word>("phase", word::null))
{
// Set the field name to that of the energy field from which the temperature
......@@ -80,15 +80,13 @@ bool Foam::fv::limitTemperature::read(const dictionary& dict)
{
if (cellSetOption::read(dict))
{
coeffs_.lookup("min") >> Tmin_;
coeffs_.lookup("max") >> Tmax_;
coeffs_.readEntry("min", Tmin_);
coeffs_.readEntry("max", Tmax_);
return true;
}
else
{
return false;
}
return false;
}
......@@ -110,7 +108,7 @@ void Foam::fv::limitTemperature::correct(volScalarField& he)
forAll(cells_, i)
{
label celli = cells_[i];
const label celli = cells_[i];
hec[celli]= max(min(hec[celli], heMax[i]), heMin[i]);
}
......
......@@ -71,7 +71,6 @@ class limitTemperature
:
public cellSetOption
{
protected:
// Protected data
......@@ -116,8 +115,7 @@ public:
//- Destructor
virtual ~limitTemperature()
{}
virtual ~limitTemperature() = default;
// Member Functions
......
......@@ -56,7 +56,7 @@ Foam::fv::limitVelocity::limitVelocity
:
cellSetOption(name, modelType, dict, mesh),
UName_(coeffs_.lookupOrDefault<word>("U", "U")),
max_(readScalar(coeffs_.lookup("max")))
max_(coeffs_.get<scalar>("max"))
{
fieldNames_.setSize(1, UName_);
applied_.setSize(1, false);
......@@ -69,14 +69,12 @@ bool Foam::fv::limitVelocity::read(const dictionary& dict)
{
if (cellSetOption::read(dict))
{
coeffs_.lookup("max") >> max_;
coeffs_.readEntry("max", max_);
return true;
}
else
{
return false;
}
return false;
}
......@@ -86,10 +84,8 @@ void Foam::fv::limitVelocity::correct(volVectorField& U)
vectorField& Uif = U.primitiveFieldRef();
forAll(cells_, i)
for (const label celli : cells_)
{
const label celli = cells_[i];
const scalar magSqrUi = magSqr(Uif[celli]);
if (magSqrUi > maxSqrU)
......
......@@ -65,7 +65,6 @@ class limitVelocity
:
public cellSetOption
{
protected:
// Protected data
......@@ -107,8 +106,7 @@ public:
//- Destructor
virtual ~limitVelocity()
{}
virtual ~limitVelocity() = default;
// Member Functions
......
......@@ -110,7 +110,7 @@ Foam::fv::interRegionOption::interRegionOption
mesh
),
master_(coeffs_.lookupOrDefault("master", true)),
nbrRegionName_(coeffs_.lookup("nbrRegion")),
nbrRegionName_(coeffs_.get<word>("nbrRegion")),
meshInterpPtr_()
{
if (active())
......@@ -126,4 +126,17 @@ Foam::fv::interRegionOption::~interRegionOption()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::fv::interRegionOption::read(const dictionary& dict)
{
if (option::read(dict))
{
return true;
}
return false;
}
// ************************************************************************* //
......@@ -46,5 +46,4 @@ Foam::fv::interRegionOption::meshInterp() const
}
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "interRegionOption.H"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::fv::interRegionOption::read(const dictionary& dict)
{
if (option::read(dict))
{
return true;
}
else
{
return false;
}
}
// ************************************************************************* //
......@@ -187,11 +187,11 @@ bool Foam::fv::acousticDampingSource::read(const dictionary& dict)
applied_.setSize(fieldNames_.size(), false);
coeffs_.lookup("frequency") >> frequency_.value();
coeffs_.lookup("URef") >> URefName_;
coeffs_.lookup("centre") >> x0_;
coeffs_.lookup("radius1") >> r1_;
coeffs_.lookup("radius2") >> r2_;
coeffs_.readEntry("frequency", frequency_.value());
coeffs_.readEntry("URef", URefName_);
coeffs_.readEntry("centre", x0_);
coeffs_.readEntry("radius1", r1_);
coeffs_.readEntry("radius2", r2_);
if (coeffs_.readIfPresent("w", w_))
{
......
......@@ -137,37 +137,33 @@ public:
// Member Functions
// Add explicit and implicit contributions
//- Add implicit contribution to momentum equation
virtual void addSup
(
fvMatrix<vector>& eqn,
const label fieldI
);
//- Add implicit contribution to compressible momentum equation
virtual void addSup
(
const volScalarField& rho,
fvMatrix<vector>& eqn,
const label fieldI
);
//- Add implicit contribution to phase momentum equation
virtual void addSup
(
const volScalarField& alpha,
const volScalarField& rho,
fvMatrix<vector>& eqn,
const label fieldI
);
// IO
//- Read dictionary
virtual bool read(const dictionary& dict);
//- Add implicit contribution to momentum equation
virtual void addSup
(
fvMatrix<vector>& eqn,
const label fieldI
);
//- Add implicit contribution to compressible momentum equation