mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: forces/forceCoeffs FOs updated follwing changes to functionObjectFile
This commit is contained in:
@ -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-2015 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -28,6 +28,9 @@ License
|
|||||||
#include "Time.H"
|
#include "Time.H"
|
||||||
#include "Pstream.H"
|
#include "Pstream.H"
|
||||||
#include "IOmanip.H"
|
#include "IOmanip.H"
|
||||||
|
#include "fvMesh.H"
|
||||||
|
#include "dimensionedTypes.H"
|
||||||
|
#include "volFields.H"
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||||
|
|
||||||
@ -39,81 +42,157 @@ namespace Foam
|
|||||||
|
|
||||||
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
|
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
|
||||||
|
|
||||||
void Foam::forceCoeffs::writeFileHeader(const label i)
|
void Foam::forceCoeffs::createFiles()
|
||||||
{
|
{
|
||||||
if (i == 0)
|
// Note: Only possible to create bin files after bins have been initialised
|
||||||
|
|
||||||
|
if (writeToFile() && !coeffFilePtr_.valid())
|
||||||
{
|
{
|
||||||
// force coeff data
|
coeffFilePtr_ = createFile("coefficient");
|
||||||
|
writeIntegratedHeader("Coefficients", coeffFilePtr_());
|
||||||
|
|
||||||
writeHeader(file(i), "Force coefficients");
|
if (nBin_ > 1)
|
||||||
writeHeaderValue(file(i), "liftDir", liftDir_);
|
|
||||||
writeHeaderValue(file(i), "dragDir", dragDir_);
|
|
||||||
writeHeaderValue(file(i), "pitchAxis", pitchAxis_);
|
|
||||||
writeHeaderValue(file(i), "magUInf", magUInf_);
|
|
||||||
writeHeaderValue(file(i), "lRef", lRef_);
|
|
||||||
writeHeaderValue(file(i), "Aref", Aref_);
|
|
||||||
writeHeaderValue(file(i), "CofR", coordSys_.origin());
|
|
||||||
writeCommented(file(i), "Time");
|
|
||||||
writeTabbed(file(i), "Cm");
|
|
||||||
writeTabbed(file(i), "Cd");
|
|
||||||
writeTabbed(file(i), "Cl");
|
|
||||||
writeTabbed(file(i), "Cl(f)");
|
|
||||||
writeTabbed(file(i), "Cl(r)");
|
|
||||||
file(i)
|
|
||||||
<< tab << "Cm" << tab << "Cd" << tab << "Cl" << tab << "Cl(f)"
|
|
||||||
<< tab << "Cl(r)";
|
|
||||||
}
|
|
||||||
else if (i == 1)
|
|
||||||
{
|
|
||||||
// bin coeff data
|
|
||||||
|
|
||||||
writeHeader(file(i), "Force coefficient bins");
|
|
||||||
writeHeaderValue(file(i), "bins", nBin_);
|
|
||||||
writeHeaderValue(file(i), "start", binMin_);
|
|
||||||
writeHeaderValue(file(i), "delta", binDx_);
|
|
||||||
writeHeaderValue(file(i), "direction", binDir_);
|
|
||||||
|
|
||||||
vectorField binPoints(nBin_);
|
|
||||||
writeCommented(file(i), "x co-ords :");
|
|
||||||
forAll(binPoints, pointI)
|
|
||||||
{
|
{
|
||||||
binPoints[pointI] = (binMin_ + (pointI + 1)*binDx_)*binDir_;
|
CmBinFilePtr_ = createFile("CmBin");
|
||||||
file(i) << tab << binPoints[pointI].x();
|
writeBinHeader("Moment coefficient bins", CmBinFilePtr_());
|
||||||
}
|
CdBinFilePtr_ = createFile("CdBin");
|
||||||
file(i) << nl;
|
writeBinHeader("Drag coefficient bins", CdBinFilePtr_());
|
||||||
|
ClBinFilePtr_ = createFile("ClBin");
|
||||||
writeCommented(file(i), "y co-ords :");
|
writeBinHeader("Lift coefficient bins", ClBinFilePtr_());
|
||||||
forAll(binPoints, pointI)
|
|
||||||
{
|
|
||||||
file(i) << tab << binPoints[pointI].y();
|
|
||||||
}
|
|
||||||
file(i) << nl;
|
|
||||||
|
|
||||||
writeCommented(file(i), "z co-ords :");
|
|
||||||
forAll(binPoints, pointI)
|
|
||||||
{
|
|
||||||
file(i) << tab << binPoints[pointI].z();
|
|
||||||
}
|
|
||||||
file(i) << nl;
|
|
||||||
|
|
||||||
writeCommented(file(i), "Time");
|
|
||||||
|
|
||||||
for (label j = 0; j < nBin_; j++)
|
|
||||||
{
|
|
||||||
const word jn('(' + Foam::name(j) + ')');
|
|
||||||
writeTabbed(file(i), "Cm" + jn);
|
|
||||||
writeTabbed(file(i), "Cd" + jn);
|
|
||||||
writeTabbed(file(i), "Cl" + jn);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Foam::forceCoeffs::writeIntegratedHeader
|
||||||
|
(
|
||||||
|
const word& header,
|
||||||
|
Ostream& os
|
||||||
|
) const
|
||||||
|
{
|
||||||
|
writeHeader(os, "Force coefficients");
|
||||||
|
writeHeaderValue(os, "liftDir", liftDir_);
|
||||||
|
writeHeaderValue(os, "dragDir", dragDir_);
|
||||||
|
writeHeaderValue(os, "pitchAxis", pitchAxis_);
|
||||||
|
writeHeaderValue(os, "magUInf", magUInf_);
|
||||||
|
writeHeaderValue(os, "lRef", lRef_);
|
||||||
|
writeHeaderValue(os, "Aref", Aref_);
|
||||||
|
writeHeaderValue(os, "CofR", coordSys_.origin());
|
||||||
|
writeHeader(os, "");
|
||||||
|
writeCommented(os, "Time");
|
||||||
|
writeTabbed(os, "Cm");
|
||||||
|
writeTabbed(os, "Cd");
|
||||||
|
writeTabbed(os, "Cl");
|
||||||
|
writeTabbed(os, "Cl(f)");
|
||||||
|
writeTabbed(os, "Cl(r)");
|
||||||
|
os << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Foam::forceCoeffs::writeBinHeader
|
||||||
|
(
|
||||||
|
const word& header,
|
||||||
|
Ostream& os
|
||||||
|
) const
|
||||||
|
{
|
||||||
|
writeHeader(os, header);
|
||||||
|
writeHeaderValue(os, "bins", nBin_);
|
||||||
|
writeHeaderValue(os, "start", binMin_);
|
||||||
|
writeHeaderValue(os, "delta", binDx_);
|
||||||
|
writeHeaderValue(os, "direction", binDir_);
|
||||||
|
|
||||||
|
vectorField binPoints(nBin_);
|
||||||
|
writeCommented(os, "x co-ords :");
|
||||||
|
forAll(binPoints, pointI)
|
||||||
{
|
{
|
||||||
FatalErrorIn("void Foam::forces::writeFileHeader(const label)")
|
binPoints[pointI] = (binMin_ + (pointI + 1)*binDx_)*binDir_;
|
||||||
<< "Unhandled file index: " << i
|
os << tab << binPoints[pointI].x();
|
||||||
<< abort(FatalError);
|
}
|
||||||
|
os << nl;
|
||||||
|
|
||||||
|
writeCommented(os, "y co-ords :");
|
||||||
|
forAll(binPoints, pointI)
|
||||||
|
{
|
||||||
|
os << tab << binPoints[pointI].y();
|
||||||
|
}
|
||||||
|
os << nl;
|
||||||
|
|
||||||
|
writeCommented(os, "z co-ords :");
|
||||||
|
forAll(binPoints, pointI)
|
||||||
|
{
|
||||||
|
os << tab << binPoints[pointI].z();
|
||||||
|
}
|
||||||
|
os << nl;
|
||||||
|
|
||||||
|
writeHeader(os, "");
|
||||||
|
writeCommented(os, "Time");
|
||||||
|
|
||||||
|
for (label j = 0; j < nBin_; j++)
|
||||||
|
{
|
||||||
|
word jn(Foam::name(j) + ':');
|
||||||
|
writeTabbed(os, jn + "total");
|
||||||
|
writeTabbed(os, jn + "pressure");
|
||||||
|
writeTabbed(os, jn + "viscous");
|
||||||
|
|
||||||
|
if (porosity_)
|
||||||
|
{
|
||||||
|
writeTabbed(os, jn + "porous");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
file(i)<< endl;
|
os << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Foam::forceCoeffs::writeIntegratedData
|
||||||
|
(
|
||||||
|
const word& title,
|
||||||
|
const List<Field<scalar> >& coeff
|
||||||
|
) const
|
||||||
|
{
|
||||||
|
scalar pressure = sum(coeff[0]);
|
||||||
|
scalar viscous = sum(coeff[1]);
|
||||||
|
scalar porous = sum(coeff[2]);
|
||||||
|
scalar total = pressure + viscous + porous;
|
||||||
|
|
||||||
|
if (log_)
|
||||||
|
{
|
||||||
|
Info<< " " << title << " : " << total << token::TAB
|
||||||
|
<< "("
|
||||||
|
<< "pressure: " << pressure << token::TAB
|
||||||
|
<< "viscous: " << viscous;
|
||||||
|
|
||||||
|
if (porosity_)
|
||||||
|
{
|
||||||
|
Info<< token::TAB << "porous: " << porous;
|
||||||
|
}
|
||||||
|
|
||||||
|
Info<< ")" << endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Foam::forceCoeffs::writeBinData
|
||||||
|
(
|
||||||
|
const List<Field<scalar> > coeffs,
|
||||||
|
Ostream& os
|
||||||
|
) const
|
||||||
|
{
|
||||||
|
os << obr_.time().value();
|
||||||
|
|
||||||
|
for (label binI = 0; binI < nBin_; binI++)
|
||||||
|
{
|
||||||
|
scalar total = coeffs[0][binI] + coeffs[1][binI] + coeffs[2][binI];
|
||||||
|
|
||||||
|
os << tab << total << tab << coeffs[0][binI] << tab << coeffs[1][binI];
|
||||||
|
|
||||||
|
if (porosity_)
|
||||||
|
{
|
||||||
|
os << tab << coeffs[2][binI];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
os << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -124,7 +203,8 @@ Foam::forceCoeffs::forceCoeffs
|
|||||||
const word& name,
|
const word& name,
|
||||||
const objectRegistry& obr,
|
const objectRegistry& obr,
|
||||||
const dictionary& dict,
|
const dictionary& dict,
|
||||||
const bool loadFromFiles
|
const bool loadFromFiles,
|
||||||
|
const bool readFields
|
||||||
)
|
)
|
||||||
:
|
:
|
||||||
forces(name, obr, dict, loadFromFiles, false),
|
forces(name, obr, dict, loadFromFiles, false),
|
||||||
@ -133,11 +213,17 @@ Foam::forceCoeffs::forceCoeffs
|
|||||||
pitchAxis_(vector::zero),
|
pitchAxis_(vector::zero),
|
||||||
magUInf_(0.0),
|
magUInf_(0.0),
|
||||||
lRef_(0.0),
|
lRef_(0.0),
|
||||||
Aref_(0.0)
|
Aref_(0.0),
|
||||||
|
coeffFilePtr_(),
|
||||||
|
CmBinFilePtr_(),
|
||||||
|
CdBinFilePtr_(),
|
||||||
|
ClBinFilePtr_()
|
||||||
{
|
{
|
||||||
read(dict);
|
if (readFields)
|
||||||
|
{
|
||||||
Info<< endl;
|
read(dict);
|
||||||
|
if (log_) Info << endl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -151,115 +237,216 @@ Foam::forceCoeffs::~forceCoeffs()
|
|||||||
|
|
||||||
void Foam::forceCoeffs::read(const dictionary& dict)
|
void Foam::forceCoeffs::read(const dictionary& dict)
|
||||||
{
|
{
|
||||||
if (active_)
|
if (!active_)
|
||||||
{
|
{
|
||||||
forces::read(dict);
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Directions for lift and drag forces, and pitch moment
|
forces::read(dict);
|
||||||
dict.lookup("liftDir") >> liftDir_;
|
|
||||||
dict.lookup("dragDir") >> dragDir_;
|
|
||||||
dict.lookup("pitchAxis") >> pitchAxis_;
|
|
||||||
|
|
||||||
// Free stream velocity magnitude
|
// Directions for lift and drag forces, and pitch moment
|
||||||
dict.lookup("magUInf") >> magUInf_;
|
dict.lookup("liftDir") >> liftDir_;
|
||||||
|
dict.lookup("dragDir") >> dragDir_;
|
||||||
|
dict.lookup("pitchAxis") >> pitchAxis_;
|
||||||
|
|
||||||
// Reference length and area scales
|
// Free stream velocity magnitude
|
||||||
dict.lookup("lRef") >> lRef_;
|
dict.lookup("magUInf") >> magUInf_;
|
||||||
dict.lookup("Aref") >> Aref_;
|
|
||||||
|
// Reference length and area scales
|
||||||
|
dict.lookup("lRef") >> lRef_;
|
||||||
|
dict.lookup("Aref") >> Aref_;
|
||||||
|
|
||||||
|
if (writeFields_)
|
||||||
|
{
|
||||||
|
const fvMesh& mesh = refCast<const fvMesh>(obr_);
|
||||||
|
|
||||||
|
tmp<volVectorField> tforceCoeff
|
||||||
|
(
|
||||||
|
new volVectorField
|
||||||
|
(
|
||||||
|
IOobject
|
||||||
|
(
|
||||||
|
fieldName("forceCoeff"),
|
||||||
|
mesh.time().timeName(),
|
||||||
|
mesh,
|
||||||
|
IOobject::NO_READ,
|
||||||
|
IOobject::NO_WRITE
|
||||||
|
),
|
||||||
|
mesh,
|
||||||
|
dimensionedVector("0", dimless, vector::zero)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
obr_.store(tforceCoeff.ptr());
|
||||||
|
|
||||||
|
tmp<volVectorField> tmomentCoeff
|
||||||
|
(
|
||||||
|
new volVectorField
|
||||||
|
(
|
||||||
|
IOobject
|
||||||
|
(
|
||||||
|
fieldName("momentCoeff"),
|
||||||
|
mesh.time().timeName(),
|
||||||
|
mesh,
|
||||||
|
IOobject::NO_READ,
|
||||||
|
IOobject::NO_WRITE
|
||||||
|
),
|
||||||
|
mesh,
|
||||||
|
dimensionedVector("0", dimless, vector::zero)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
obr_.store(tmomentCoeff.ptr());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Foam::forceCoeffs::execute()
|
void Foam::forceCoeffs::execute()
|
||||||
{
|
{
|
||||||
// Do nothing - only valid on write
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Foam::forceCoeffs::end()
|
|
||||||
{
|
|
||||||
// Do nothing - only valid on write
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Foam::forceCoeffs::timeSet()
|
|
||||||
{
|
|
||||||
// Do nothing - only valid on write
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Foam::forceCoeffs::write()
|
|
||||||
{
|
|
||||||
forces::calcForcesMoment();
|
|
||||||
|
|
||||||
if (!active_)
|
if (!active_)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Pstream::master())
|
forces::calcForcesMoment();
|
||||||
|
|
||||||
|
createFiles();
|
||||||
|
|
||||||
|
scalar pDyn = 0.5*rhoRef_*magUInf_*magUInf_;
|
||||||
|
|
||||||
|
// Storage for pressure, viscous and porous contributions to coeffs
|
||||||
|
List<Field<scalar> > momentCoeffs(3);
|
||||||
|
List<Field<scalar> > dragCoeffs(3);
|
||||||
|
List<Field<scalar> > liftCoeffs(3);
|
||||||
|
forAll(liftCoeffs, i)
|
||||||
{
|
{
|
||||||
functionObjectFile::write();
|
momentCoeffs[i].setSize(nBin_);
|
||||||
|
dragCoeffs[i].setSize(nBin_);
|
||||||
|
liftCoeffs[i].setSize(nBin_);
|
||||||
|
}
|
||||||
|
|
||||||
scalar pDyn = 0.5*rhoRef_*magUInf_*magUInf_;
|
// Calculate coefficients
|
||||||
|
scalar CmTot = 0;
|
||||||
|
scalar CdTot = 0;
|
||||||
|
scalar ClTot = 0;
|
||||||
|
forAll(liftCoeffs, i)
|
||||||
|
{
|
||||||
|
momentCoeffs[i] = (moment_[i] & pitchAxis_)/(Aref_*pDyn*lRef_);
|
||||||
|
dragCoeffs[i] = (force_[i] & dragDir_)/(Aref_*pDyn);
|
||||||
|
liftCoeffs[i] = (force_[i] & liftDir_)/(Aref_*pDyn);
|
||||||
|
|
||||||
Field<vector> totForce(force_[0] + force_[1] + force_[2]);
|
CmTot += sum(momentCoeffs[i]);
|
||||||
Field<vector> totMoment(moment_[0] + moment_[1] + moment_[2]);
|
CdTot += sum(dragCoeffs[i]);
|
||||||
|
ClTot += sum(liftCoeffs[i]);
|
||||||
|
}
|
||||||
|
|
||||||
List<Field<scalar> > coeffs(3);
|
scalar ClfTot = ClTot/2.0 + CmTot;
|
||||||
coeffs[0].setSize(nBin_);
|
scalar ClrTot = ClTot/2.0 - CmTot;
|
||||||
coeffs[1].setSize(nBin_);
|
|
||||||
coeffs[2].setSize(nBin_);
|
|
||||||
|
|
||||||
// lift, drag and moment
|
if (log_)
|
||||||
coeffs[0] = (totForce & liftDir_)/(Aref_*pDyn);
|
{
|
||||||
coeffs[1] = (totForce & dragDir_)/(Aref_*pDyn);
|
Info<< type() << " " << name_ << " output:" << nl
|
||||||
coeffs[2] = (totMoment & pitchAxis_)/(Aref_*lRef_*pDyn);
|
<< " Coefficients" << nl;
|
||||||
|
}
|
||||||
|
writeIntegratedData("Cm", momentCoeffs);
|
||||||
|
writeIntegratedData("Cd", dragCoeffs);
|
||||||
|
writeIntegratedData("Cl", liftCoeffs);
|
||||||
|
if (log_)
|
||||||
|
{
|
||||||
|
Info<< " Cl(f) : " << ClfTot << nl
|
||||||
|
<< " Cl(r) : " << ClrTot << nl
|
||||||
|
<< endl;
|
||||||
|
}
|
||||||
|
|
||||||
scalar Cl = sum(coeffs[0]);
|
if (writeToFile())
|
||||||
scalar Cd = sum(coeffs[1]);
|
{
|
||||||
scalar Cm = sum(coeffs[2]);
|
coeffFilePtr_()
|
||||||
|
<< obr_.time().value() << tab << CmTot << tab << CdTot
|
||||||
|
<< tab << ClTot << tab << ClfTot << tab << ClrTot << endl;
|
||||||
|
|
||||||
scalar Clf = Cl/2.0 + Cm;
|
|
||||||
scalar Clr = Cl/2.0 - Cm;
|
|
||||||
|
|
||||||
file(0)
|
|
||||||
<< obr_.time().value() << tab << Cm << tab << Cd
|
|
||||||
<< tab << Cl << tab << Clf << tab << Clr << endl;
|
|
||||||
|
|
||||||
if (log_) Info<< type() << " " << name_ << " output:" << nl
|
|
||||||
<< " Cm = " << Cm << nl
|
|
||||||
<< " Cd = " << Cd << nl
|
|
||||||
<< " Cl = " << Cl << nl
|
|
||||||
<< " Cl(f) = " << Clf << nl
|
|
||||||
<< " Cl(r) = " << Clr << endl;
|
|
||||||
|
|
||||||
if (nBin_ > 1)
|
if (nBin_ > 1)
|
||||||
{
|
{
|
||||||
if (binCumulative_)
|
if (binCumulative_)
|
||||||
{
|
{
|
||||||
for (label i = 1; i < coeffs[0].size(); i++)
|
forAll(liftCoeffs, i)
|
||||||
{
|
{
|
||||||
coeffs[0][i] += coeffs[0][i-1];
|
for (label binI = 1; binI < nBin_; binI++)
|
||||||
coeffs[1][i] += coeffs[1][i-1];
|
{
|
||||||
coeffs[2][i] += coeffs[2][i-1];
|
liftCoeffs[i][binI] += liftCoeffs[i][binI-1];
|
||||||
|
dragCoeffs[i][binI] += dragCoeffs[i][binI-1];
|
||||||
|
momentCoeffs[i][binI] += momentCoeffs[i][binI-1];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
file(1)<< obr_.time().value();
|
writeBinData(dragCoeffs, CdBinFilePtr_());
|
||||||
|
writeBinData(liftCoeffs, ClBinFilePtr_());
|
||||||
forAll(coeffs[0], i)
|
writeBinData(momentCoeffs, CmBinFilePtr_());
|
||||||
{
|
|
||||||
file(1)
|
|
||||||
<< tab << coeffs[2][i]
|
|
||||||
<< tab << coeffs[1][i]
|
|
||||||
<< tab << coeffs[0][i];
|
|
||||||
}
|
|
||||||
|
|
||||||
file(1) << endl;
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (log_) Info<< endl;
|
if (writeFields_)
|
||||||
|
{
|
||||||
|
const volVectorField& force =
|
||||||
|
obr_.lookupObject<volVectorField>(fieldName("force"));
|
||||||
|
|
||||||
|
const volVectorField& moment =
|
||||||
|
obr_.lookupObject<volVectorField>(fieldName("moment"));
|
||||||
|
|
||||||
|
volVectorField& forceCoeff =
|
||||||
|
const_cast<volVectorField&>
|
||||||
|
(
|
||||||
|
obr_.lookupObject<volVectorField>(fieldName("forceCoeff"))
|
||||||
|
);
|
||||||
|
|
||||||
|
volVectorField& momentCoeff =
|
||||||
|
const_cast<volVectorField&>
|
||||||
|
(
|
||||||
|
obr_.lookupObject<volVectorField>(fieldName("momentCoeff"))
|
||||||
|
);
|
||||||
|
|
||||||
|
dimensionedScalar f0("f0", dimForce, Aref_*pDyn);
|
||||||
|
dimensionedScalar m0("m0", dimForce*dimLength, Aref_*lRef_*pDyn);
|
||||||
|
|
||||||
|
forceCoeff == force/f0;
|
||||||
|
momentCoeff == moment/m0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Foam::forceCoeffs::end()
|
||||||
|
{
|
||||||
|
if (active_)
|
||||||
|
{
|
||||||
|
execute();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Foam::forceCoeffs::timeSet()
|
||||||
|
{
|
||||||
|
// Do nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Foam::forceCoeffs::write()
|
||||||
|
{
|
||||||
|
if (!active_)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (writeFields_)
|
||||||
|
{
|
||||||
|
const volVectorField& forceCoeff =
|
||||||
|
obr_.lookupObject<volVectorField>(fieldName("forceCoeff"));
|
||||||
|
|
||||||
|
const volVectorField& momentCoeff =
|
||||||
|
obr_.lookupObject<volVectorField>(fieldName("momentCoeff"));
|
||||||
|
|
||||||
|
forceCoeff.write();
|
||||||
|
momentCoeff.write();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -2,8 +2,8 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / 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-2013 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -32,6 +32,19 @@ Description
|
|||||||
lift, drag and moment coefficients. The data can optionally be output into
|
lift, drag and moment coefficients. The data can optionally be output into
|
||||||
bins, defined in a given direction.
|
bins, defined in a given direction.
|
||||||
|
|
||||||
|
The binned data provides the total and consitituentcomponents per bin:
|
||||||
|
- total coefficient
|
||||||
|
- pressure coefficient contribution
|
||||||
|
- viscous coefficient contribution
|
||||||
|
- porous coefficient contribution
|
||||||
|
|
||||||
|
Data is written into multiple files in the
|
||||||
|
postProcessing/\<functionObjectName\> directory:
|
||||||
|
- coefficient.dat : integrated coefficients over all geometries
|
||||||
|
- CmBin.dat : moment coefficient bins
|
||||||
|
- CdBin.dat : drag coefficient bins
|
||||||
|
- ClBin.dat : lift coefficient bins
|
||||||
|
|
||||||
Example of function object specification:
|
Example of function object specification:
|
||||||
\verbatim
|
\verbatim
|
||||||
forceCoeffs1
|
forceCoeffs1
|
||||||
@ -40,6 +53,7 @@ Description
|
|||||||
functionObjectLibs ("libforces.so");
|
functionObjectLibs ("libforces.so");
|
||||||
...
|
...
|
||||||
log yes;
|
log yes;
|
||||||
|
writeFields yes;
|
||||||
patches (walls);
|
patches (walls);
|
||||||
liftDir (0 1 0);
|
liftDir (0 1 0);
|
||||||
dragDir (-1 0 0);
|
dragDir (-1 0 0);
|
||||||
@ -62,6 +76,7 @@ Description
|
|||||||
Property | Description | Required | Default value
|
Property | Description | Required | Default value
|
||||||
type | type name: forces | yes |
|
type | type name: forces | yes |
|
||||||
log | write force data to standard output | no | no
|
log | write force data to standard output | no | no
|
||||||
|
writeFields | write the force and moment coefficient fields | no | no
|
||||||
patches | patches included in the forces calculation | yes |
|
patches | patches included in the forces calculation | yes |
|
||||||
liftDir | lift direction | yes |
|
liftDir | lift direction | yes |
|
||||||
dragDir | drag direction | yes |
|
dragDir | drag direction | yes |
|
||||||
@ -137,6 +152,21 @@ class forceCoeffs
|
|||||||
scalar Aref_;
|
scalar Aref_;
|
||||||
|
|
||||||
|
|
||||||
|
// File streams
|
||||||
|
|
||||||
|
//- Integrated coefficients
|
||||||
|
autoPtr<OFstream> coeffFilePtr_;
|
||||||
|
|
||||||
|
//- Moment coefficient
|
||||||
|
autoPtr<OFstream> CmBinFilePtr_;
|
||||||
|
|
||||||
|
//- Drag coefficient
|
||||||
|
autoPtr<OFstream> CdBinFilePtr_;
|
||||||
|
|
||||||
|
//- Lift coefficient
|
||||||
|
autoPtr<OFstream> ClBinFilePtr_;
|
||||||
|
|
||||||
|
|
||||||
// Private Member Functions
|
// Private Member Functions
|
||||||
|
|
||||||
//- Disallow default bitwise copy construct
|
//- Disallow default bitwise copy construct
|
||||||
@ -148,8 +178,26 @@ class forceCoeffs
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
//- Output file header information
|
// Protected Member Functions
|
||||||
virtual void writeFileHeader(const label i);
|
|
||||||
|
//- Create the output files
|
||||||
|
void createFiles();
|
||||||
|
|
||||||
|
//- Write header for integrated data
|
||||||
|
void writeIntegratedHeader(const word& header, Ostream& os) const;
|
||||||
|
|
||||||
|
//- Write header for binned data
|
||||||
|
void writeBinHeader(const word& header, Ostream& os) const;
|
||||||
|
|
||||||
|
//- Write integrated data
|
||||||
|
void writeIntegratedData
|
||||||
|
(
|
||||||
|
const word& title,
|
||||||
|
const List<Field<scalar> >& coeff
|
||||||
|
) const;
|
||||||
|
|
||||||
|
//- Write binned data
|
||||||
|
void writeBinData(const List<Field<scalar> > coeffs, Ostream& os) const;
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -167,7 +215,8 @@ public:
|
|||||||
const word& name,
|
const word& name,
|
||||||
const objectRegistry&,
|
const objectRegistry&,
|
||||||
const dictionary&,
|
const dictionary&,
|
||||||
const bool loadFromFiles = false
|
const bool loadFromFiles = false,
|
||||||
|
const bool readFields = true
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@ -2,8 +2,8 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / 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-2013 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -29,11 +29,24 @@ Group
|
|||||||
|
|
||||||
Description
|
Description
|
||||||
This function object calculates the forces and moments by integrating the
|
This function object calculates the forces and moments by integrating the
|
||||||
pressure and skin-friction forces over a given list of patches.
|
pressure and skin-friction forces over a given list of patches, and
|
||||||
|
the resistance from porous zones.
|
||||||
|
|
||||||
Member function forces::write() calculates the forces/moments and
|
Forces and moments are calculated, with optional co-ordinate system and
|
||||||
writes the forces/moments into the file \<timeDir\>/forces.dat and bin
|
writing of binned data, where force and moment contributions are collected
|
||||||
data (if selected) to the file \<timeDir\>/forces_bin.dat
|
into a user-defined number of bins that span the input geometries for a
|
||||||
|
user-defined direction vector.
|
||||||
|
|
||||||
|
Data is written into multiple files in the
|
||||||
|
postProcessing/\<functionObjectName\> directory:
|
||||||
|
- force.dat : forces in global Cartesian co-ordinate system
|
||||||
|
- moment.dat : moments in global Cartesian co-ordinate system
|
||||||
|
- forceBin.dat : force bins in global Cartesian co-ordinate system
|
||||||
|
- momentBin.dat : moment bins in global Cartesian co-ordinate system
|
||||||
|
- localForce.dat : forces in local co-ordinate system
|
||||||
|
- localMoment.dat : moments in local co-ordinate system
|
||||||
|
- localForceBin.dat : force bins in local co-ordinate system
|
||||||
|
- localMomentBin.dat : moment bins in local co-ordinate system
|
||||||
|
|
||||||
Example of function object specification:
|
Example of function object specification:
|
||||||
\verbatim
|
\verbatim
|
||||||
@ -43,6 +56,7 @@ Description
|
|||||||
functionObjectLibs ("libforces.so");
|
functionObjectLibs ("libforces.so");
|
||||||
...
|
...
|
||||||
log yes;
|
log yes;
|
||||||
|
writeFields yes;
|
||||||
patches (walls);
|
patches (walls);
|
||||||
|
|
||||||
binData
|
binData
|
||||||
@ -59,6 +73,7 @@ Description
|
|||||||
Property | Description | Required | Default value
|
Property | Description | Required | Default value
|
||||||
type | type name: forces | yes |
|
type | type name: forces | yes |
|
||||||
log | write force data to standard output | no | no
|
log | write force data to standard output | no | no
|
||||||
|
writeFields | write the force and moment fields | no | no
|
||||||
patches | patches included in the forces calculation | yes |
|
patches | patches included in the forces calculation | yes |
|
||||||
pName | pressure field name | no | p
|
pName | pressure field name | no | p
|
||||||
UName | velocity field name | no | U
|
UName | velocity field name | no | U
|
||||||
@ -101,6 +116,7 @@ Note
|
|||||||
|
|
||||||
SeeAlso
|
SeeAlso
|
||||||
Foam::functionObject
|
Foam::functionObject
|
||||||
|
Foam::functionObjectFile
|
||||||
Foam::OutputFilterFunctionObject
|
Foam::OutputFilterFunctionObject
|
||||||
Foam::forceCoeffs
|
Foam::forceCoeffs
|
||||||
|
|
||||||
@ -122,7 +138,6 @@ SourceFiles
|
|||||||
#include "Tuple2.H"
|
#include "Tuple2.H"
|
||||||
#include "OFstream.H"
|
#include "OFstream.H"
|
||||||
#include "Switch.H"
|
#include "Switch.H"
|
||||||
#include "writer.H"
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
@ -165,6 +180,32 @@ protected:
|
|||||||
//- Pressure, viscous and porous moment per bin
|
//- Pressure, viscous and porous moment per bin
|
||||||
List<Field<vector> > moment_;
|
List<Field<vector> > moment_;
|
||||||
|
|
||||||
|
// File streams
|
||||||
|
|
||||||
|
//- Forces
|
||||||
|
autoPtr<OFstream> forceFilePtr_;
|
||||||
|
|
||||||
|
//- Moments
|
||||||
|
autoPtr<OFstream> momentFilePtr_;
|
||||||
|
|
||||||
|
//- Force bins
|
||||||
|
autoPtr<OFstream> forceBinFilePtr_;
|
||||||
|
|
||||||
|
//- Moment bins
|
||||||
|
autoPtr<OFstream> momentBinFilePtr_;
|
||||||
|
|
||||||
|
//- Local force
|
||||||
|
autoPtr<OFstream> localForceFilePtr_;
|
||||||
|
|
||||||
|
//- Local moment
|
||||||
|
autoPtr<OFstream> localMomentFilePtr_;
|
||||||
|
|
||||||
|
//- Local force bins
|
||||||
|
autoPtr<OFstream> localForceBinFilePtr_;
|
||||||
|
|
||||||
|
//- Local moment bins
|
||||||
|
autoPtr<OFstream> localMomentBinFilePtr_;
|
||||||
|
|
||||||
|
|
||||||
// Read from dictionary
|
// Read from dictionary
|
||||||
|
|
||||||
@ -223,21 +264,36 @@ protected:
|
|||||||
bool binCumulative_;
|
bool binCumulative_;
|
||||||
|
|
||||||
|
|
||||||
|
//- Write fields flag
|
||||||
|
bool writeFields_;
|
||||||
|
|
||||||
//- Initialised flag
|
//- Initialised flag
|
||||||
bool initialised_;
|
bool initialised_;
|
||||||
|
|
||||||
|
|
||||||
// Protected Member Functions
|
// Protected Member Functions
|
||||||
|
|
||||||
//- Create file names for forces and bins
|
//- Create a field name
|
||||||
wordList createFileNames(const dictionary& dict) const;
|
word fieldName(const word& name) const;
|
||||||
|
|
||||||
//- Output file header information
|
//- Create the output files
|
||||||
virtual void writeFileHeader(const label i);
|
void createFiles();
|
||||||
|
|
||||||
|
//- Write header for integrated data
|
||||||
|
void writeIntegratedHeader(const word& header, Ostream& os) const;
|
||||||
|
|
||||||
|
//- Write header for binned data
|
||||||
|
void writeBinHeader(const word& header, Ostream& os) const;
|
||||||
|
|
||||||
//- Initialise the fields
|
//- Initialise the fields
|
||||||
void initialise();
|
void initialise();
|
||||||
|
|
||||||
|
//- Initialise the collection bins
|
||||||
|
void initialiseBins();
|
||||||
|
|
||||||
|
//- Reset the fields prior to accumulation of force/moments
|
||||||
|
void resetFields();
|
||||||
|
|
||||||
//- Return the effective viscous stress (laminar + turbulent).
|
//- Return the effective viscous stress (laminar + turbulent).
|
||||||
tmp<volSymmTensorField> devRhoReff() const;
|
tmp<volSymmTensorField> devRhoReff() const;
|
||||||
|
|
||||||
@ -261,10 +317,47 @@ protected:
|
|||||||
const vectorField& d
|
const vectorField& d
|
||||||
);
|
);
|
||||||
|
|
||||||
//- Helper function to write force data
|
//- Add patch contributions to force and moment fields
|
||||||
|
void addToFields
|
||||||
|
(
|
||||||
|
const label patchI,
|
||||||
|
const vectorField& Md,
|
||||||
|
const vectorField& fN,
|
||||||
|
const vectorField& fT,
|
||||||
|
const vectorField& fP
|
||||||
|
);
|
||||||
|
|
||||||
|
//- Add cell contributions to force and moment fields
|
||||||
|
void addToFields
|
||||||
|
(
|
||||||
|
const labelList& cellIDs,
|
||||||
|
const vectorField& Md,
|
||||||
|
const vectorField& fN,
|
||||||
|
const vectorField& fT,
|
||||||
|
const vectorField& fP
|
||||||
|
);
|
||||||
|
|
||||||
|
//- Helper function to write integrated forces and moments
|
||||||
|
void writeIntegratedForceMoment
|
||||||
|
(
|
||||||
|
const string& descriptor,
|
||||||
|
const vectorField& fm0,
|
||||||
|
const vectorField& fm1,
|
||||||
|
const vectorField& fm2,
|
||||||
|
autoPtr<OFstream>& osPtr
|
||||||
|
) const;
|
||||||
|
|
||||||
|
//- Write force data
|
||||||
void writeForces();
|
void writeForces();
|
||||||
|
|
||||||
//- Helper function to write bin data
|
//- Helper function to write binned forces and moments
|
||||||
|
void writeBinnedForceMoment
|
||||||
|
(
|
||||||
|
const List<Field<vector> >& fm,
|
||||||
|
autoPtr<OFstream>& osPtr
|
||||||
|
) const;
|
||||||
|
|
||||||
|
//- Write binned data
|
||||||
void writeBins();
|
void writeBins();
|
||||||
|
|
||||||
//- Disallow default bitwise copy construct
|
//- Disallow default bitwise copy construct
|
||||||
|
|||||||
Reference in New Issue
Block a user