From e8fcd1d351dd9f04657341c64c29b9ae1be00eb7 Mon Sep 17 00:00:00 2001 From: Mark Olesen <Mark.Olesen@esi-group.com> Date: Thu, 5 Jul 2018 11:00:16 +0200 Subject: [PATCH] STYLE: enforce dictionary read length for read UNames/epsilonNames entry --- .../explicitPorositySource.C | 14 ++------ .../multiphaseMangrovesSource.C | 14 ++------ .../multiphaseMangrovesTurbulenceModel.C | 35 +++++++++---------- 3 files changed, 23 insertions(+), 40 deletions(-) diff --git a/src/fvOptions/sources/derived/explicitPorositySource/explicitPorositySource.C b/src/fvOptions/sources/derived/explicitPorositySource/explicitPorositySource.C index a90b1903b38..3c7cb43b266 100644 --- a/src/fvOptions/sources/derived/explicitPorositySource/explicitPorositySource.C +++ b/src/fvOptions/sources/derived/explicitPorositySource/explicitPorositySource.C @@ -119,18 +119,10 @@ bool Foam::fv::explicitPorositySource::read(const dictionary& dict) { if (cellSetOption::read(dict)) { - if (coeffs_.found("UNames")) + if (!coeffs_.readIfPresent("UNames", fieldNames_)) { - coeffs_.lookup("UNames") >> fieldNames_; - } - else if (coeffs_.found("U")) - { - word UName(coeffs_.lookup("U")); - fieldNames_ = wordList(1, UName); - } - else - { - fieldNames_ = wordList(1, "U"); + fieldNames_.resize(1); + fieldNames_.first() = coeffs_.lookupOrDefault<word>("U", "U"); } applied_.setSize(fieldNames_.size(), false); diff --git a/src/waveModels/fvOptions/multiphaseMangrovesSource/multiphaseMangrovesSource.C b/src/waveModels/fvOptions/multiphaseMangrovesSource/multiphaseMangrovesSource.C index 883d52b0024..0c9198a40fc 100644 --- a/src/waveModels/fvOptions/multiphaseMangrovesSource/multiphaseMangrovesSource.C +++ b/src/waveModels/fvOptions/multiphaseMangrovesSource/multiphaseMangrovesSource.C @@ -207,18 +207,10 @@ bool Foam::fv::multiphaseMangrovesSource::read(const dictionary& dict) { if (option::read(dict)) { - if (coeffs_.found("UNames")) + if (!coeffs_.readIfPresent("UNames", fieldNames_)) { - coeffs_.lookup("UNames") >> fieldNames_; - } - else if (coeffs_.found("U")) - { - word UName(coeffs_.lookup("U")); - fieldNames_ = wordList(1, UName); - } - else - { - fieldNames_ = wordList(1, "U"); + fieldNames_.resize(1); + fieldNames_.first() = coeffs_.lookupOrDefault<word>("U", "U"); } applied_.setSize(fieldNames_.size(), false); diff --git a/src/waveModels/fvOptions/multiphaseMangrovesTurbulenceModel/multiphaseMangrovesTurbulenceModel.C b/src/waveModels/fvOptions/multiphaseMangrovesTurbulenceModel/multiphaseMangrovesTurbulenceModel.C index 59f50d3a302..039904c85f1 100644 --- a/src/waveModels/fvOptions/multiphaseMangrovesTurbulenceModel/multiphaseMangrovesTurbulenceModel.C +++ b/src/waveModels/fvOptions/multiphaseMangrovesTurbulenceModel/multiphaseMangrovesTurbulenceModel.C @@ -205,19 +205,19 @@ void Foam::fv::multiphaseMangrovesTurbulenceModel::addSup if (eqn.psi().name() == epsilonName_) { - fvMatrix<scalar> epsilonEqn - ( + fvMatrix<scalar> epsilonEqn + ( - fvm::Sp(rho*epsilonCoeff(U), eqn.psi()) ); eqn += epsilonEqn; } else if (eqn.psi().name() == kName_) { - fvMatrix<scalar> kEqn - ( + fvMatrix<scalar> kEqn + ( - fvm::Sp(rho*kCoeff(U), eqn.psi()) ); - eqn += kEqn; + eqn += kEqn; } } @@ -226,20 +226,19 @@ bool Foam::fv::multiphaseMangrovesTurbulenceModel::read(const dictionary& dict) { if (option::read(dict)) { - if (coeffs_.found("epsilonNames")) + if (!coeffs_.readIfPresent("epsilonNames", fieldNames_)) { - coeffs_.lookup("epsilonNames") >> fieldNames_; - } - else if (coeffs_.found("epsilon")) - { - word UName(coeffs_.lookup("epsilon")); - fieldNames_ = wordList(1, UName); - } - else - { - fieldNames_.setSize(2); - fieldNames_[0] = "epsilon"; - fieldNames_[1] = "k"; + if (coeffs_.found("epsilon")) + { + fieldNames_.resize(1); + coeffs_.read("epsilon", fieldNames_.first()); + } + else + { + fieldNames_.resize(2); + fieldNames_[0] = "epsilon"; + fieldNames_[1] = "k"; + } } applied_.setSize(fieldNames_.size(), false); -- GitLab