diff --git a/applications/test/unitConversion/Test-unitConversion.C b/applications/test/unitConversion/Test-unitConversion.C index 869007ec40..000f8198f6 100644 --- a/applications/test/unitConversion/Test-unitConversion.C +++ b/applications/test/unitConversion/Test-unitConversion.C @@ -42,6 +42,8 @@ int main(int argc, char *argv[]) Info<< "degToRad(30): " << degToRad(30) << nl; Info<< "cos(30_deg): " << ::cos(30_deg) << nl; + Info<< "1000 rpm = " << rpmToRads(1000) << " 1/s" << nl; + Info<< "100 1/s = " << radsToRpm(100) << " rpm" << nl; return 0; } diff --git a/applications/utilities/preProcessing/engineSwirl/engineSwirl.C b/applications/utilities/preProcessing/engineSwirl/engineSwirl.C index 200d04f759..c781b81c71 100644 --- a/applications/utilities/preProcessing/engineSwirl/engineSwirl.C +++ b/applications/utilities/preProcessing/engineSwirl/engineSwirl.C @@ -33,7 +33,7 @@ Description \*---------------------------------------------------------------------------*/ #include "fvCFD.H" -#include "mathematicalConstants.H" +#include "unitConversion.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -47,7 +47,7 @@ int main(int argc, char *argv[]) // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - scalar Vphi = (constant::mathematical::pi*swirlRPMRatio*rpm/30).value(); + scalar Vphi = (swirlRPMRatio * rpm * rpmToRads()).value(); scalar b1 = j1(swirlProfile).value(); scalar b2 = 2.0*b1/swirlProfile.value() - j0(swirlProfile).value(); diff --git a/src/OpenFOAM/global/unitConversion/unitConversion.H b/src/OpenFOAM/global/unitConversion/unitConversion.H index 1308947e2d..a5d10a9ec2 100644 --- a/src/OpenFOAM/global/unitConversion/unitConversion.H +++ b/src/OpenFOAM/global/unitConversion/unitConversion.H @@ -65,6 +65,32 @@ inline constexpr scalar radToDeg() noexcept return (180.0/M_PI); } + +//- Conversion from revolutions/minute to radians/sec +inline constexpr scalar rpmToRads(const scalar rpm) noexcept +{ + return (rpm*M_PI/30.0); +} + +//- Conversion from radians/sec to revolutions/minute +inline constexpr scalar radsToRpm(const scalar rads) noexcept +{ + return (rads*30.0/M_PI); +} + +//- Multiplication factor for revolutions/minute to radians/sec +inline constexpr scalar rpmToRads() noexcept +{ + return (M_PI/30.0); +} + +//- Multiplication factor for radians/sec to revolutions/minute +inline constexpr scalar radsToRpm() noexcept +{ + return (30.0/M_PI); +} + + //- Conversion from atm to Pa inline constexpr scalar atmToPa(const scalar atm) noexcept { diff --git a/src/finiteVolume/cfdTools/general/SRF/SRFModel/rpm/rpm.C b/src/finiteVolume/cfdTools/general/SRF/SRFModel/rpm/rpm.C index ecd7955949..4f9f090641 100644 --- a/src/finiteVolume/cfdTools/general/SRF/SRFModel/rpm/rpm.C +++ b/src/finiteVolume/cfdTools/general/SRF/SRFModel/rpm/rpm.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -25,7 +25,7 @@ License #include "rpm.H" #include "addToRunTimeSelectionTable.H" -#include "mathematicalConstants.H" +#include "unitConversion.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // @@ -46,43 +46,30 @@ namespace Foam // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // -Foam::SRF::rpm::rpm -( - const volVectorField& U -) +Foam::SRF::rpm::rpm(const volVectorField& U) : SRFModel(typeName, U), - rpm_(readScalar(SRFModelCoeffs_.lookup("rpm"))) + rpm_(SRFModelCoeffs_.get("rpm")) { - // Initialise the angular velocity - omega_.value() = axis_*rpm_*constant::mathematical::twoPi/60.0; + // The angular velocity + omega_.value() = axis_*rpmToRads(rpm_); } -// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // - -Foam::SRF::rpm::~rpm() -{} - - // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // bool Foam::SRF::rpm::read() { if (SRFModel::read()) { - // Re-read rpm - SRFModelCoeffs_.lookup("rpm") >> rpm_; + rpm_ = SRFModelCoeffs_.get("rpm"); - // Update angular velocity - omega_.value() = axis_*rpm_*(constant::mathematical::twoPi/60.0); + omega_.value() = axis_*rpmToRads(rpm_); return true; } - else - { - return false; - } + + return false; } diff --git a/src/finiteVolume/cfdTools/general/SRF/SRFModel/rpm/rpm.H b/src/finiteVolume/cfdTools/general/SRF/SRFModel/rpm/rpm.H index 658c4d0bf4..611e75cc97 100644 --- a/src/finiteVolume/cfdTools/general/SRF/SRFModel/rpm/rpm.H +++ b/src/finiteVolume/cfdTools/general/SRF/SRFModel/rpm/rpm.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -82,14 +82,13 @@ public: //- Destructor - ~rpm(); + ~rpm() = default; + // Member functions - // I-O - - //- Read - bool read(); + //- Read coefficients + bool read(); }; diff --git a/src/finiteVolume/fields/fvPatchFields/derived/cylindricalInletVelocity/cylindricalInletVelocityFvPatchVectorField.C b/src/finiteVolume/fields/fvPatchFields/derived/cylindricalInletVelocity/cylindricalInletVelocityFvPatchVectorField.C index 43a6e2b0b3..87e782dc4b 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/cylindricalInletVelocity/cylindricalInletVelocityFvPatchVectorField.C +++ b/src/finiteVolume/fields/fvPatchFields/derived/cylindricalInletVelocity/cylindricalInletVelocityFvPatchVectorField.C @@ -28,7 +28,7 @@ License #include "addToRunTimeSelectionTable.H" #include "fvPatchFieldMapper.H" #include "surfaceFields.H" -#include "mathematicalConstants.H" +#include "unitConversion.H" // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // @@ -126,7 +126,7 @@ void Foam::cylindricalInletVelocityFvPatchVectorField::updateCoeffs() const scalar t = this->db().time().timeOutputValue(); const scalar axialVelocity = axialVelocity_->value(t); const scalar radialVelocity = radialVelocity_->value(t); - const scalar rpm = rpm_->value(t); + const scalar omega = rpmToRads(rpm_->value(t)); const vector axisHat = axis_/mag(axis_); @@ -135,7 +135,7 @@ void Foam::cylindricalInletVelocityFvPatchVectorField::updateCoeffs() tmp tangVel ( - (rpm*constant::mathematical::pi/30.0)*(axisHat) ^ d + (omega * axisHat) ^ d ); operator==(tangVel + axisHat*axialVelocity + radialVelocity*d/mag(d)); diff --git a/src/finiteVolume/fields/fvPatchFields/derived/swirlFanVelocity/swirlFanVelocityFvPatchField.C b/src/finiteVolume/fields/fvPatchFields/derived/swirlFanVelocity/swirlFanVelocityFvPatchField.C index 2f95522a5c..67d1d62467 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/swirlFanVelocity/swirlFanVelocityFvPatchField.C +++ b/src/finiteVolume/fields/fvPatchFields/derived/swirlFanVelocity/swirlFanVelocityFvPatchField.C @@ -28,6 +28,7 @@ License #include "fvPatchFieldMapper.H" #include "volFields.H" #include "surfaceFields.H" +#include "unitConversion.H" // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // @@ -79,10 +80,7 @@ void Foam::swirlFanVelocityFvPatchField::calcFanJump() if (rMag > rInner_ && rMag < rOuter_) { magTangU[i] = - deltaP[i] - /rMag - /fanEff_ - /(rpm_*constant::mathematical::pi/30.0); + deltaP[i]/rMag/fanEff_/rpmToRads(rpm_); } } } @@ -96,7 +94,7 @@ void Foam::swirlFanVelocityFvPatchField::calcFanJump() << exit(FatalError); } magTangU = - deltaP/rEff_/fanEff_/(rpm_*constant::mathematical::pi/30.0); + deltaP/rEff_/fanEff_/rpmToRads(rpm_); } // Calculate the tangential velocity diff --git a/src/finiteVolume/fields/fvPatchFields/derived/swirlFlowRateInletVelocity/swirlFlowRateInletVelocityFvPatchVectorField.C b/src/finiteVolume/fields/fvPatchFields/derived/swirlFlowRateInletVelocity/swirlFlowRateInletVelocityFvPatchVectorField.C index 89c1ce0008..42e4b588ea 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/swirlFlowRateInletVelocity/swirlFlowRateInletVelocityFvPatchVectorField.C +++ b/src/finiteVolume/fields/fvPatchFields/derived/swirlFlowRateInletVelocity/swirlFlowRateInletVelocityFvPatchVectorField.C @@ -28,7 +28,7 @@ License #include "addToRunTimeSelectionTable.H" #include "fvPatchFieldMapper.H" #include "surfaceFields.H" -#include "mathematicalConstants.H" +#include "unitConversion.H" // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // @@ -151,18 +151,16 @@ void Foam::swirlFlowRateInletVelocityFvPatchVectorField::updateCoeffs() { const scalar t = this->db().time().timeOutputValue(); const scalar flowRate = flowRate_->value(t); - const scalar rpm = rpm_->value(t); + const scalar omega = rpmToRads(rpm_->value(t)); const scalar avgU = -flowRate/totArea; const vector axisHat = axis_/mag(axis_); - // Update angular velocity - convert [rpm] to [rad/s] + // Update angular velocity tmp tangentialVelocity ( - axisHat - ^(rpm*constant::mathematical::pi/30.0) - *(patch().Cf() - origin_) + axisHat ^ omega*(patch().Cf() - origin_) ); tmp n = patch().nf(); diff --git a/src/fvOptions/sources/derived/rotorDiskSource/rotorDiskSource.C b/src/fvOptions/sources/derived/rotorDiskSource/rotorDiskSource.C index ba2b264d52..3c31bdac84 100644 --- a/src/fvOptions/sources/derived/rotorDiskSource/rotorDiskSource.C +++ b/src/fvOptions/sources/derived/rotorDiskSource/rotorDiskSource.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -29,6 +29,7 @@ License #include "fvMatrices.H" #include "geometricOneField.H" #include "syncTools.H" +#include "unitConversion.H" using namespace Foam::constant; @@ -84,15 +85,12 @@ void Foam::fv::rotorDiskSource::checkData() { case ifFixed: { - coeffs_.lookup("inletVelocity") >> inletVelocity_; + coeffs_.read("inletVelocity", inletVelocity_); break; } case ifSurfaceNormal: { - scalar UIn - ( - readScalar(coeffs_.lookup("inletNormalVelocity")) - ); + scalar UIn(coeffs_.get("inletNormalVelocity")); inletVelocity_ = -coordSys_.R().e3()*UIn; break; } @@ -263,7 +261,7 @@ void Foam::fv::rotorDiskSource::setFaceArea(vector& axis, const bool correct) void Foam::fv::rotorDiskSource::createCoordinateSystem() { - // Construct the local rotor co-ordinate system + // Construct the local rotor coordinate system vector origin(Zero); vector axis(Zero); vector refDir(Zero); @@ -324,7 +322,7 @@ void Foam::fv::rotorDiskSource::createCoordinateSystem() // Correct the axis direction using a point above the rotor { - vector pointAbove(coeffs_.lookup("pointAbove")); + vector pointAbove(coeffs_.get("pointAbove")); vector dir = pointAbove - origin; dir /= mag(dir); if ((dir & axis) < 0) @@ -333,7 +331,7 @@ void Foam::fv::rotorDiskSource::createCoordinateSystem() } } - coeffs_.lookup("refDirection") >> refDir; + coeffs_.read("refDirection", refDir); cylindrical_.reset ( @@ -354,9 +352,9 @@ void Foam::fv::rotorDiskSource::createCoordinateSystem() } case gmSpecified: { - coeffs_.lookup("origin") >> origin; - coeffs_.lookup("axis") >> axis; - coeffs_.lookup("refDirection") >> refDir; + coeffs_.read("origin", origin); + coeffs_.read("axis", axis); + coeffs_.read("refDirection", refDir); cylindrical_.reset ( @@ -407,7 +405,7 @@ void Foam::fv::rotorDiskSource::constructGeometry() { const label celli = cells_[i]; - // Position in (planar) rotor co-ordinate system + // Position in (planar) rotor coordinate system x_[i] = coordSys_.localPosition(C[celli]); // Cache max radius @@ -523,7 +521,7 @@ void Foam::fv::rotorDiskSource::addSup ); // Read the reference density for incompressible flow - coeffs_.lookup("rhoRef") >> rhoRef_; + coeffs_.read("rhoRef", rhoRef_); const vectorField Uin(inflowVelocity(eqn.psi())); trim_->correct(Uin, force); @@ -576,32 +574,28 @@ bool Foam::fv::rotorDiskSource::read(const dictionary& dict) { if (cellSetOption::read(dict)) { - coeffs_.lookup("fields") >> fieldNames_; + coeffs_.read("fields", fieldNames_); applied_.setSize(fieldNames_.size(), false); - // Read co-ordinate system/geometry invariant properties - scalar rpm(readScalar(coeffs_.lookup("rpm"))); - omega_ = rpm/60.0*mathematical::twoPi; + // Read coordinate system/geometry invariant properties + omega_ = rpmToRads(coeffs_.get("rpm")); - coeffs_.lookup("nBlades") >> nBlades_; + coeffs_.read("nBlades", nBlades_); inletFlow_ = inletFlowTypeNames_.lookup("inletFlowType", coeffs_); - coeffs_.lookup("tipEffect") >> tipEffect_; + coeffs_.read("tipEffect", tipEffect_); const dictionary& flapCoeffs(coeffs_.subDict("flapCoeffs")); - flapCoeffs.lookup("beta0") >> flap_.beta0; - flapCoeffs.lookup("beta1c") >> flap_.beta1c; - flapCoeffs.lookup("beta2s") >> flap_.beta2s; - flap_.beta0 = degToRad(flap_.beta0); - flap_.beta1c = degToRad(flap_.beta1c); - flap_.beta2s = degToRad(flap_.beta2s); + flap_.beta0 = degToRad(flapCoeffs.get("beta0")); + flap_.beta1c = degToRad(flapCoeffs.get("beta1c")); + flap_.beta2s = degToRad(flapCoeffs.get("beta2s")); - // Create co-ordinate system + // Create coordinate system createCoordinateSystem(); - // Read co-ordinate system dependent properties + // Read coordinate system dependent properties checkData(); constructGeometry(); @@ -616,10 +610,8 @@ bool Foam::fv::rotorDiskSource::read(const dictionary& dict) return true; } - else - { - return false; - } + + return false; } diff --git a/src/fvOptions/sources/derived/rotorDiskSource/rotorDiskSource.H b/src/fvOptions/sources/derived/rotorDiskSource/rotorDiskSource.H index 2414d0a703..4799c4705b 100644 --- a/src/fvOptions/sources/derived/rotorDiskSource/rotorDiskSource.H +++ b/src/fvOptions/sources/derived/rotorDiskSource/rotorDiskSource.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -78,8 +78,8 @@ Usage Where: Valid options for the \c geometryMode entry include: - - auto : determine rototor co-ord system from cells - - specified : specified co-ord system + - auto : determine rotor coordinate system from cells + - specified : specified coordinate system Valid options for the \c inletFlowType entry include: - fixed : specified velocity @@ -113,7 +113,7 @@ SourceFiles namespace Foam { -// Forward declaration of classes +// Forward declarations class trimModel; namespace fv @@ -196,7 +196,7 @@ protected: //- Area [m2] List area_; - //- Rotor local cylindrical co-ordinate system (r, theta, z) + //- Rotor local cylindrical coordinate system (r, theta, z) cylindricalCS coordSys_; //- Rotor transformation co-ordinate system @@ -223,7 +223,7 @@ protected: //- Set the face areas per cell, and optionally correct the rotor axis void setFaceArea(vector& axis, const bool correct); - //- Create the co-ordinate system + //- Create the coordinate system void createCoordinateSystem(); //- Construct geometry @@ -250,7 +250,6 @@ public: // Constructors - //- Construct from components rotorDiskSource ( @@ -280,7 +279,7 @@ public: // (Cylindrical r, theta, z) inline const List& x() const; - //- Return the rotor co-ordinate system (r, theta, z) + //- Return the rotor coordinate system (r, theta, z) inline const cylindricalCS& coordSys() const;