ENH: add rpmToRads() convenience functions

- simplifies conversion of RPM to radians/sec for const variables
This commit is contained in:
Mark Olesen
2018-07-23 22:20:26 +02:00
parent ec318a95d1
commit fe808e24e7
10 changed files with 86 additions and 85 deletions

View File

@ -42,6 +42,8 @@ int main(int argc, char *argv[])
Info<< "degToRad(30): " << degToRad(30) << nl; Info<< "degToRad(30): " << degToRad(30) << nl;
Info<< "cos(30_deg): " << ::cos(30_deg) << 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; return 0;
} }

View File

@ -33,7 +33,7 @@ Description
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "fvCFD.H" #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 b1 = j1(swirlProfile).value();
scalar b2 = 2.0*b1/swirlProfile.value() - j0(swirlProfile).value(); scalar b2 = 2.0*b1/swirlProfile.value() - j0(swirlProfile).value();

View File

@ -65,6 +65,32 @@ inline constexpr scalar radToDeg() noexcept
return (180.0/M_PI); 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 //- Conversion from atm to Pa
inline constexpr scalar atmToPa(const scalar atm) noexcept inline constexpr scalar atmToPa(const scalar atm) noexcept
{ {

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -25,7 +25,7 @@ License
#include "rpm.H" #include "rpm.H"
#include "addToRunTimeSelectionTable.H" #include "addToRunTimeSelectionTable.H"
#include "mathematicalConstants.H" #include "unitConversion.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
@ -46,43 +46,30 @@ namespace Foam
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::SRF::rpm::rpm Foam::SRF::rpm::rpm(const volVectorField& U)
(
const volVectorField& U
)
: :
SRFModel(typeName, U), SRFModel(typeName, U),
rpm_(readScalar(SRFModelCoeffs_.lookup("rpm"))) rpm_(SRFModelCoeffs_.get<scalar>("rpm"))
{ {
// Initialise the angular velocity // The angular velocity
omega_.value() = axis_*rpm_*constant::mathematical::twoPi/60.0; omega_.value() = axis_*rpmToRads(rpm_);
} }
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::SRF::rpm::~rpm()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::SRF::rpm::read() bool Foam::SRF::rpm::read()
{ {
if (SRFModel::read()) if (SRFModel::read())
{ {
// Re-read rpm rpm_ = SRFModelCoeffs_.get<scalar>("rpm");
SRFModelCoeffs_.lookup("rpm") >> rpm_;
// Update angular velocity omega_.value() = axis_*rpmToRads(rpm_);
omega_.value() = axis_*rpm_*(constant::mathematical::twoPi/60.0);
return true; return true;
} }
else
{ return false;
return false;
}
} }

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -82,14 +82,13 @@ public:
//- Destructor //- Destructor
~rpm(); ~rpm() = default;
// Member functions // Member functions
// I-O //- Read coefficients
bool read();
//- Read
bool read();
}; };

View File

@ -28,7 +28,7 @@ License
#include "addToRunTimeSelectionTable.H" #include "addToRunTimeSelectionTable.H"
#include "fvPatchFieldMapper.H" #include "fvPatchFieldMapper.H"
#include "surfaceFields.H" #include "surfaceFields.H"
#include "mathematicalConstants.H" #include "unitConversion.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
@ -126,7 +126,7 @@ void Foam::cylindricalInletVelocityFvPatchVectorField::updateCoeffs()
const scalar t = this->db().time().timeOutputValue(); const scalar t = this->db().time().timeOutputValue();
const scalar axialVelocity = axialVelocity_->value(t); const scalar axialVelocity = axialVelocity_->value(t);
const scalar radialVelocity = radialVelocity_->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_); const vector axisHat = axis_/mag(axis_);
@ -135,7 +135,7 @@ void Foam::cylindricalInletVelocityFvPatchVectorField::updateCoeffs()
tmp<vectorField> tangVel tmp<vectorField> tangVel
( (
(rpm*constant::mathematical::pi/30.0)*(axisHat) ^ d (omega * axisHat) ^ d
); );
operator==(tangVel + axisHat*axialVelocity + radialVelocity*d/mag(d)); operator==(tangVel + axisHat*axialVelocity + radialVelocity*d/mag(d));

View File

@ -28,6 +28,7 @@ License
#include "fvPatchFieldMapper.H" #include "fvPatchFieldMapper.H"
#include "volFields.H" #include "volFields.H"
#include "surfaceFields.H" #include "surfaceFields.H"
#include "unitConversion.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
@ -79,10 +80,7 @@ void Foam::swirlFanVelocityFvPatchField::calcFanJump()
if (rMag > rInner_ && rMag < rOuter_) if (rMag > rInner_ && rMag < rOuter_)
{ {
magTangU[i] = magTangU[i] =
deltaP[i] deltaP[i]/rMag/fanEff_/rpmToRads(rpm_);
/rMag
/fanEff_
/(rpm_*constant::mathematical::pi/30.0);
} }
} }
} }
@ -96,7 +94,7 @@ void Foam::swirlFanVelocityFvPatchField::calcFanJump()
<< exit(FatalError); << exit(FatalError);
} }
magTangU = magTangU =
deltaP/rEff_/fanEff_/(rpm_*constant::mathematical::pi/30.0); deltaP/rEff_/fanEff_/rpmToRads(rpm_);
} }
// Calculate the tangential velocity // Calculate the tangential velocity

View File

@ -28,7 +28,7 @@ License
#include "addToRunTimeSelectionTable.H" #include "addToRunTimeSelectionTable.H"
#include "fvPatchFieldMapper.H" #include "fvPatchFieldMapper.H"
#include "surfaceFields.H" #include "surfaceFields.H"
#include "mathematicalConstants.H" #include "unitConversion.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
@ -151,18 +151,16 @@ void Foam::swirlFlowRateInletVelocityFvPatchVectorField::updateCoeffs()
{ {
const scalar t = this->db().time().timeOutputValue(); const scalar t = this->db().time().timeOutputValue();
const scalar flowRate = flowRate_->value(t); 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 scalar avgU = -flowRate/totArea;
const vector axisHat = axis_/mag(axis_); const vector axisHat = axis_/mag(axis_);
// Update angular velocity - convert [rpm] to [rad/s] // Update angular velocity
tmp<vectorField> tangentialVelocity tmp<vectorField> tangentialVelocity
( (
axisHat axisHat ^ omega*(patch().Cf() - origin_)
^(rpm*constant::mathematical::pi/30.0)
*(patch().Cf() - origin_)
); );
tmp<vectorField> n = patch().nf(); tmp<vectorField> n = patch().nf();

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -29,6 +29,7 @@ License
#include "fvMatrices.H" #include "fvMatrices.H"
#include "geometricOneField.H" #include "geometricOneField.H"
#include "syncTools.H" #include "syncTools.H"
#include "unitConversion.H"
using namespace Foam::constant; using namespace Foam::constant;
@ -84,15 +85,12 @@ void Foam::fv::rotorDiskSource::checkData()
{ {
case ifFixed: case ifFixed:
{ {
coeffs_.lookup("inletVelocity") >> inletVelocity_; coeffs_.read("inletVelocity", inletVelocity_);
break; break;
} }
case ifSurfaceNormal: case ifSurfaceNormal:
{ {
scalar UIn scalar UIn(coeffs_.get<scalar>("inletNormalVelocity"));
(
readScalar(coeffs_.lookup("inletNormalVelocity"))
);
inletVelocity_ = -coordSys_.R().e3()*UIn; inletVelocity_ = -coordSys_.R().e3()*UIn;
break; break;
} }
@ -263,7 +261,7 @@ void Foam::fv::rotorDiskSource::setFaceArea(vector& axis, const bool correct)
void Foam::fv::rotorDiskSource::createCoordinateSystem() void Foam::fv::rotorDiskSource::createCoordinateSystem()
{ {
// Construct the local rotor co-ordinate system // Construct the local rotor coordinate system
vector origin(Zero); vector origin(Zero);
vector axis(Zero); vector axis(Zero);
vector refDir(Zero); vector refDir(Zero);
@ -324,7 +322,7 @@ void Foam::fv::rotorDiskSource::createCoordinateSystem()
// Correct the axis direction using a point above the rotor // Correct the axis direction using a point above the rotor
{ {
vector pointAbove(coeffs_.lookup("pointAbove")); vector pointAbove(coeffs_.get<vector>("pointAbove"));
vector dir = pointAbove - origin; vector dir = pointAbove - origin;
dir /= mag(dir); dir /= mag(dir);
if ((dir & axis) < 0) if ((dir & axis) < 0)
@ -333,7 +331,7 @@ void Foam::fv::rotorDiskSource::createCoordinateSystem()
} }
} }
coeffs_.lookup("refDirection") >> refDir; coeffs_.read("refDirection", refDir);
cylindrical_.reset cylindrical_.reset
( (
@ -354,9 +352,9 @@ void Foam::fv::rotorDiskSource::createCoordinateSystem()
} }
case gmSpecified: case gmSpecified:
{ {
coeffs_.lookup("origin") >> origin; coeffs_.read("origin", origin);
coeffs_.lookup("axis") >> axis; coeffs_.read("axis", axis);
coeffs_.lookup("refDirection") >> refDir; coeffs_.read("refDirection", refDir);
cylindrical_.reset cylindrical_.reset
( (
@ -407,7 +405,7 @@ void Foam::fv::rotorDiskSource::constructGeometry()
{ {
const label celli = cells_[i]; const label celli = cells_[i];
// Position in (planar) rotor co-ordinate system // Position in (planar) rotor coordinate system
x_[i] = coordSys_.localPosition(C[celli]); x_[i] = coordSys_.localPosition(C[celli]);
// Cache max radius // Cache max radius
@ -523,7 +521,7 @@ void Foam::fv::rotorDiskSource::addSup
); );
// Read the reference density for incompressible flow // Read the reference density for incompressible flow
coeffs_.lookup("rhoRef") >> rhoRef_; coeffs_.read("rhoRef", rhoRef_);
const vectorField Uin(inflowVelocity(eqn.psi())); const vectorField Uin(inflowVelocity(eqn.psi()));
trim_->correct(Uin, force); trim_->correct(Uin, force);
@ -576,32 +574,28 @@ bool Foam::fv::rotorDiskSource::read(const dictionary& dict)
{ {
if (cellSetOption::read(dict)) if (cellSetOption::read(dict))
{ {
coeffs_.lookup("fields") >> fieldNames_; coeffs_.read("fields", fieldNames_);
applied_.setSize(fieldNames_.size(), false); applied_.setSize(fieldNames_.size(), false);
// Read co-ordinate system/geometry invariant properties // Read coordinate system/geometry invariant properties
scalar rpm(readScalar(coeffs_.lookup("rpm"))); omega_ = rpmToRads(coeffs_.get<scalar>("rpm"));
omega_ = rpm/60.0*mathematical::twoPi;
coeffs_.lookup("nBlades") >> nBlades_; coeffs_.read("nBlades", nBlades_);
inletFlow_ = inletFlowTypeNames_.lookup("inletFlowType", coeffs_); inletFlow_ = inletFlowTypeNames_.lookup("inletFlowType", coeffs_);
coeffs_.lookup("tipEffect") >> tipEffect_; coeffs_.read("tipEffect", tipEffect_);
const dictionary& flapCoeffs(coeffs_.subDict("flapCoeffs")); const dictionary& flapCoeffs(coeffs_.subDict("flapCoeffs"));
flapCoeffs.lookup("beta0") >> flap_.beta0; flap_.beta0 = degToRad(flapCoeffs.get<scalar>("beta0"));
flapCoeffs.lookup("beta1c") >> flap_.beta1c; flap_.beta1c = degToRad(flapCoeffs.get<scalar>("beta1c"));
flapCoeffs.lookup("beta2s") >> flap_.beta2s; flap_.beta2s = degToRad(flapCoeffs.get<scalar>("beta2s"));
flap_.beta0 = degToRad(flap_.beta0);
flap_.beta1c = degToRad(flap_.beta1c);
flap_.beta2s = degToRad(flap_.beta2s);
// Create co-ordinate system // Create coordinate system
createCoordinateSystem(); createCoordinateSystem();
// Read co-ordinate system dependent properties // Read coordinate system dependent properties
checkData(); checkData();
constructGeometry(); constructGeometry();
@ -616,10 +610,8 @@ bool Foam::fv::rotorDiskSource::read(const dictionary& dict)
return true; return true;
} }
else
{ return false;
return false;
}
} }

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -78,8 +78,8 @@ Usage
Where: Where:
Valid options for the \c geometryMode entry include: Valid options for the \c geometryMode entry include:
- auto : determine rototor co-ord system from cells - auto : determine rotor coordinate system from cells
- specified : specified co-ord system - specified : specified coordinate system
Valid options for the \c inletFlowType entry include: Valid options for the \c inletFlowType entry include:
- fixed : specified velocity - fixed : specified velocity
@ -113,7 +113,7 @@ SourceFiles
namespace Foam namespace Foam
{ {
// Forward declaration of classes // Forward declarations
class trimModel; class trimModel;
namespace fv namespace fv
@ -196,7 +196,7 @@ protected:
//- Area [m2] //- Area [m2]
List<scalar> area_; List<scalar> area_;
//- Rotor local cylindrical co-ordinate system (r, theta, z) //- Rotor local cylindrical coordinate system (r, theta, z)
cylindricalCS coordSys_; cylindricalCS coordSys_;
//- Rotor transformation co-ordinate system //- Rotor transformation co-ordinate system
@ -223,7 +223,7 @@ protected:
//- Set the face areas per cell, and optionally correct the rotor axis //- Set the face areas per cell, and optionally correct the rotor axis
void setFaceArea(vector& axis, const bool correct); void setFaceArea(vector& axis, const bool correct);
//- Create the co-ordinate system //- Create the coordinate system
void createCoordinateSystem(); void createCoordinateSystem();
//- Construct geometry //- Construct geometry
@ -250,7 +250,6 @@ public:
// Constructors // Constructors
//- Construct from components //- Construct from components
rotorDiskSource rotorDiskSource
( (
@ -280,7 +279,7 @@ public:
// (Cylindrical r, theta, z) // (Cylindrical r, theta, z)
inline const List<point>& x() const; inline const List<point>& x() const;
//- Return the rotor co-ordinate system (r, theta, z) //- Return the rotor coordinate system (r, theta, z)
inline const cylindricalCS& coordSys() const; inline const cylindricalCS& coordSys() const;