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<< "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;
}

View File

@ -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();

View File

@ -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
{

View File

@ -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<scalar>("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<scalar>("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;
}

View File

@ -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();
};

View File

@ -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<vectorField> tangVel
(
(rpm*constant::mathematical::pi/30.0)*(axisHat) ^ d
(omega * axisHat) ^ d
);
operator==(tangVel + axisHat*axialVelocity + radialVelocity*d/mag(d));

View File

@ -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

View File

@ -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<vectorField> tangentialVelocity
(
axisHat
^(rpm*constant::mathematical::pi/30.0)
*(patch().Cf() - origin_)
axisHat ^ omega*(patch().Cf() - origin_)
);
tmp<vectorField> n = patch().nf();

View File

@ -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<scalar>("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<vector>("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<scalar>("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<scalar>("beta0"));
flap_.beta1c = degToRad(flapCoeffs.get<scalar>("beta1c"));
flap_.beta2s = degToRad(flapCoeffs.get<scalar>("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;
}

View File

@ -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<scalar> 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<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;