Skip to content
Snippets Groups Projects
Commit 2e7f8c0d authored by Andrew Heather's avatar Andrew Heather
Browse files

ENH: forces/forceCoeffs FOs updated follwing changes to functionObjectFile

parent 0babca95
No related branches found
No related tags found
No related merge requests found
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -28,6 +28,9 @@ License
#include "Time.H"
#include "Pstream.H"
#include "IOmanip.H"
#include "fvMesh.H"
#include "dimensionedTypes.H"
#include "volFields.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
......@@ -39,81 +42,157 @@ namespace Foam
// * * * * * * * * * * * * 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())
{
coeffFilePtr_ = createFile("coefficient");
writeIntegratedHeader("Coefficients", coeffFilePtr_());
if (nBin_ > 1)
{
CmBinFilePtr_ = createFile("CmBin");
writeBinHeader("Moment coefficient bins", CmBinFilePtr_());
CdBinFilePtr_ = createFile("CdBin");
writeBinHeader("Drag coefficient bins", CdBinFilePtr_());
ClBinFilePtr_ = createFile("ClBin");
writeBinHeader("Lift coefficient bins", ClBinFilePtr_());
}
}
}
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)
{
// force coeff data
writeHeader(file(i), "Force coefficients");
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)";
binPoints[pointI] = (binMin_ + (pointI + 1)*binDx_)*binDir_;
os << tab << binPoints[pointI].x();
}
else if (i == 1)
os << nl;
writeCommented(os, "y co-ords :");
forAll(binPoints, pointI)
{
// bin coeff data
os << tab << binPoints[pointI].y();
}
os << nl;
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_);
writeCommented(os, "z co-ords :");
forAll(binPoints, pointI)
{
os << tab << binPoints[pointI].z();
}
os << nl;
vectorField binPoints(nBin_);
writeCommented(file(i), "x co-ords :");
forAll(binPoints, pointI)
{
binPoints[pointI] = (binMin_ + (pointI + 1)*binDx_)*binDir_;
file(i) << tab << binPoints[pointI].x();
}
file(i) << nl;
writeHeader(os, "");
writeCommented(os, "Time");
writeCommented(file(i), "y co-ords :");
forAll(binPoints, pointI)
{
file(i) << tab << binPoints[pointI].y();
}
file(i) << nl;
for (label j = 0; j < nBin_; j++)
{
word jn(Foam::name(j) + ':');
writeTabbed(os, jn + "total");
writeTabbed(os, jn + "pressure");
writeTabbed(os, jn + "viscous");
writeCommented(file(i), "z co-ords :");
forAll(binPoints, pointI)
if (porosity_)
{
file(i) << tab << binPoints[pointI].z();
writeTabbed(os, jn + "porous");
}
file(i) << nl;
}
os << endl;
}
writeCommented(file(i), "Time");
for (label j = 0; j < nBin_; j++)
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_)
{
const word jn('(' + Foam::name(j) + ')');
writeTabbed(file(i), "Cm" + jn);
writeTabbed(file(i), "Cd" + jn);
writeTabbed(file(i), "Cl" + jn);
Info<< token::TAB << "porous: " << porous;
}
Info<< ")" << endl;
}
else
}
void Foam::forceCoeffs::writeBinData
(
const List<Field<scalar> > coeffs,
Ostream& os
) const
{
os << obr_.time().value();
for (label binI = 0; binI < nBin_; binI++)
{
FatalErrorIn("void Foam::forces::writeFileHeader(const label)")
<< "Unhandled file index: " << i
<< abort(FatalError);
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];
}
}
file(i)<< endl;
os << endl;
}
......@@ -124,7 +203,8 @@ Foam::forceCoeffs::forceCoeffs
const word& name,
const objectRegistry& obr,
const dictionary& dict,
const bool loadFromFiles
const bool loadFromFiles,
const bool readFields
)
:
forces(name, obr, dict, loadFromFiles, false),
......@@ -133,11 +213,17 @@ Foam::forceCoeffs::forceCoeffs
pitchAxis_(vector::zero),
magUInf_(0.0),
lRef_(0.0),
Aref_(0.0)
Aref_(0.0),
coeffFilePtr_(),
CmBinFilePtr_(),
CdBinFilePtr_(),
ClBinFilePtr_()
{
read(dict);
Info<< endl;
if (readFields)
{
read(dict);
if (log_) Info << endl;
}
}
......@@ -151,115 +237,216 @@ Foam::forceCoeffs::~forceCoeffs()
void Foam::forceCoeffs::read(const dictionary& dict)
{
if (active_)
if (!active_)
{
forces::read(dict);
// Directions for lift and drag forces, and pitch moment
dict.lookup("liftDir") >> liftDir_;
dict.lookup("dragDir") >> dragDir_;
dict.lookup("pitchAxis") >> pitchAxis_;
// Free stream velocity magnitude
dict.lookup("magUInf") >> magUInf_;
// Reference length and area scales
dict.lookup("lRef") >> lRef_;
dict.lookup("Aref") >> Aref_;
return;
}
}
void Foam::forceCoeffs::execute()
{
// Do nothing - only valid on write
}
forces::read(dict);
// Directions for lift and drag forces, and pitch moment
dict.lookup("liftDir") >> liftDir_;
dict.lookup("dragDir") >> dragDir_;
dict.lookup("pitchAxis") >> pitchAxis_;
void Foam::forceCoeffs::end()
{
// Do nothing - only valid on write
}
// Free stream velocity magnitude
dict.lookup("magUInf") >> magUInf_;
// Reference length and area scales
dict.lookup("lRef") >> lRef_;
dict.lookup("Aref") >> Aref_;
void Foam::forceCoeffs::timeSet()
{
// Do nothing - only valid on write
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::write()
void Foam::forceCoeffs::execute()
{
forces::calcForcesMoment();
if (!active_)
{
return;
}
if (Pstream::master())
{
functionObjectFile::write();
forces::calcForcesMoment();
createFiles();
scalar pDyn = 0.5*rhoRef_*magUInf_*magUInf_;
scalar pDyn = 0.5*rhoRef_*magUInf_*magUInf_;
Field<vector> totForce(force_[0] + force_[1] + force_[2]);
Field<vector> totMoment(moment_[0] + moment_[1] + moment_[2]);
// 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)
{
momentCoeffs[i].setSize(nBin_);
dragCoeffs[i].setSize(nBin_);
liftCoeffs[i].setSize(nBin_);
}
List<Field<scalar> > coeffs(3);
coeffs[0].setSize(nBin_);
coeffs[1].setSize(nBin_);
coeffs[2].setSize(nBin_);
// 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);
// lift, drag and moment
coeffs[0] = (totForce & liftDir_)/(Aref_*pDyn);
coeffs[1] = (totForce & dragDir_)/(Aref_*pDyn);
coeffs[2] = (totMoment & pitchAxis_)/(Aref_*lRef_*pDyn);
CmTot += sum(momentCoeffs[i]);
CdTot += sum(dragCoeffs[i]);
ClTot += sum(liftCoeffs[i]);
}
scalar Cl = sum(coeffs[0]);
scalar Cd = sum(coeffs[1]);
scalar Cm = sum(coeffs[2]);
scalar ClfTot = ClTot/2.0 + CmTot;
scalar ClrTot = ClTot/2.0 - CmTot;
scalar Clf = Cl/2.0 + Cm;
scalar Clr = Cl/2.0 - Cm;
if (log_)
{
Info<< type() << " " << name_ << " output:" << nl
<< " Coefficients" << nl;
}
writeIntegratedData("Cm", momentCoeffs);
writeIntegratedData("Cd", dragCoeffs);
writeIntegratedData("Cl", liftCoeffs);
if (log_)
{
Info<< " Cl(f) : " << ClfTot << nl
<< " Cl(r) : " << ClrTot << nl
<< endl;
}
file(0)
<< obr_.time().value() << tab << Cm << tab << Cd
<< tab << Cl << tab << Clf << tab << Clr << endl;
if (writeToFile())
{
coeffFilePtr_()
<< obr_.time().value() << tab << CmTot << tab << CdTot
<< tab << ClTot << tab << ClfTot << tab << ClrTot << 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 (binCumulative_)
{
for (label i = 1; i < coeffs[0].size(); i++)
forAll(liftCoeffs, i)
{
coeffs[0][i] += coeffs[0][i-1];
coeffs[1][i] += coeffs[1][i-1];
coeffs[2][i] += coeffs[2][i-1];
for (label binI = 1; binI < nBin_; binI++)
{
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_());
writeBinData(momentCoeffs, CmBinFilePtr_());
}
}
forAll(coeffs[0], i)
{
file(1)
<< tab << coeffs[2][i]
<< tab << coeffs[1][i]
<< tab << coeffs[0][i];
}
if (writeFields_)
{
const volVectorField& force =
obr_.lookupObject<volVectorField>(fieldName("force"));
file(1) << endl;
}
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"));
if (log_) Info<< endl;
forceCoeff.write();
momentCoeff.write();
}
}
......
......@@ -2,8 +2,8 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
\\/ M anipulation |
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -32,6 +32,19 @@ Description
lift, drag and moment coefficients. The data can optionally be output into
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:
\verbatim
forceCoeffs1
......@@ -40,6 +53,7 @@ Description
functionObjectLibs ("libforces.so");
...
log yes;
writeFields yes;
patches (walls);
liftDir (0 1 0);
dragDir (-1 0 0);
......@@ -62,6 +76,7 @@ Description
Property | Description | Required | Default value
type | type name: forces | yes |
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 |
liftDir | lift direction | yes |
dragDir | drag direction | yes |
......@@ -137,6 +152,21 @@ class forceCoeffs
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
//- Disallow default bitwise copy construct
......@@ -148,8 +178,26 @@ class forceCoeffs
protected:
//- Output file header information
virtual void writeFileHeader(const label i);
// Protected Member Functions
//- 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:
......@@ -167,7 +215,8 @@ public:
const word& name,
const objectRegistry&,
const dictionary&,
const bool loadFromFiles = false
const bool loadFromFiles = false,
const bool readFields = true
);
......
This diff is collapsed.
......@@ -2,8 +2,8 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
\\/ M anipulation |
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -29,11 +29,24 @@ Group
Description
This function object calculates the forces and moments by integrating the
pressure and skin-friction forces over a given list of patches.
Member function forces::write() calculates the forces/moments and
writes the forces/moments into the file \<timeDir\>/forces.dat and bin
data (if selected) to the file \<timeDir\>/forces_bin.dat
pressure and skin-friction forces over a given list of patches, and
the resistance from porous zones.
Forces and moments are calculated, with optional co-ordinate system and
writing of binned data, where force and moment contributions are collected
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:
\verbatim
......@@ -43,6 +56,7 @@ Description
functionObjectLibs ("libforces.so");
...
log yes;
writeFields yes;
patches (walls);
binData
......@@ -59,6 +73,7 @@ Description
Property | Description | Required | Default value
type | type name: forces | yes |
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 |
pName | pressure field name | no | p
UName | velocity field name | no | U
......@@ -101,6 +116,7 @@ Note
SeeAlso
Foam::functionObject
Foam::functionObjectFile
Foam::OutputFilterFunctionObject
Foam::forceCoeffs
......@@ -122,7 +138,6 @@ SourceFiles
#include "Tuple2.H"
#include "OFstream.H"
#include "Switch.H"
#include "writer.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......@@ -165,6 +180,32 @@ protected:
//- Pressure, viscous and porous moment per bin
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
......@@ -223,21 +264,36 @@ protected:
bool binCumulative_;
//- Write fields flag
bool writeFields_;
//- Initialised flag
bool initialised_;
// Protected Member Functions
//- Create file names for forces and bins
wordList createFileNames(const dictionary& dict) const;
//- Create a field name
word fieldName(const word& name) const;
//- Create the output files
void createFiles();
//- Output file header information
virtual void writeFileHeader(const label i);
//- 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
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).
tmp<volSymmTensorField> devRhoReff() const;
......@@ -261,10 +317,47 @@ protected:
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();
//- 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();
//- Disallow default bitwise copy construct
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment