Commit 65f3faa2 authored by Andrew Heather's avatar Andrew Heather
Browse files

WIP: Refactored forces/Coeffs to always use a co-ord system and simplified inputs [UNCHECKED]

parent 0581a9d8
......@@ -47,32 +47,6 @@ namespace functionObjects
}
// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
namespace Foam
{
// Read vector and normalise if present, or set default
inline vector readVectorOrDefault
(
const dictionary& dict,
const word& key,
const vector::components axis
)
{
vector vec(Zero); // Zero initialise!
if (dict.readIfPresent(key, vec))
{
return normalised(vec);
}
vec[axis] = 1;
return vec;
}
} // End namespace Foam
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
void Foam::functionObjects::forceCoeffs::createFiles()
......@@ -88,14 +62,19 @@ void Foam::functionObjects::forceCoeffs::createFiles()
{
CdBinFilePtr_ = createFile("CdBin");
writeBinHeader("Drag coefficient bins", CdBinFilePtr_());
CsBinFilePtr_ = createFile("CsBin");
writeBinHeader("Side coefficient bins", CsBinFilePtr_());
ClBinFilePtr_ = createFile("ClBin");
writeBinHeader("Lift coefficient bins", ClBinFilePtr_());
CmRollBinFilePtr_ = createFile("CmRollBin");
writeBinHeader("Roll moment coefficient bins", CmRollBinFilePtr_());
CmPitchBinFilePtr_ = createFile("CmPitchBin");
writeBinHeader("Moment coefficient bins", CmPitchBinFilePtr_());
CmYawBinFilePtr_ = createFile("CmYawBin");
writeBinHeader("Yaw moment coefficient bins", CmYawBinFilePtr_());
}
......@@ -110,12 +89,12 @@ void Foam::functionObjects::forceCoeffs::writeIntegratedHeader
) const
{
writeHeader(os, "Force coefficients");
writeHeaderValue(os, "dragDir", dragDir_);
writeHeaderValue(os, "sideDir", sideDir_);
writeHeaderValue(os, "liftDir", liftDir_);
writeHeaderValue(os, "rollAxis", rollAxis_);
writeHeaderValue(os, "pitchAxis", pitchAxis_);
writeHeaderValue(os, "yawAxis", yawAxis_);
writeHeaderValue(os, "dragDir", coordSys_.e1());
writeHeaderValue(os, "sideDir", coordSys_.e2());
writeHeaderValue(os, "liftDir", coordSys_.e3());
writeHeaderValue(os, "rollAxis", coordSys_.e1());
writeHeaderValue(os, "pitchAxis", coordSys_.e2());
writeHeaderValue(os, "yawAxis", coordSys_.e3());
writeHeaderValue(os, "magUInf", magUInf_);
writeHeaderValue(os, "lRef", lRef_);
writeHeaderValue(os, "Aref", Aref_);
......@@ -257,12 +236,6 @@ Foam::functionObjects::forceCoeffs::forceCoeffs
)
:
forces(name, runTime, dict),
dragDir_(Zero),
sideDir_(Zero),
liftDir_(Zero),
rollAxis_(Zero),
pitchAxis_(Zero),
yawAxis_(Zero),
magUInf_(Zero),
lRef_(Zero),
Aref_(Zero),
......@@ -275,6 +248,7 @@ Foam::functionObjects::forceCoeffs::forceCoeffs
CmYawBinFilePtr_()
{
read(dict);
setCoordinateSystem(dict, "liftDir", "dragDir");
Info<< endl;
}
......@@ -285,15 +259,6 @@ bool Foam::functionObjects::forceCoeffs::read(const dictionary& dict)
{
forces::read(dict);
// Standard (default) definitions
dragDir_ = readVectorOrDefault(dict, "dragDir", vector::X);
sideDir_ = readVectorOrDefault(dict, "sideDir", vector::Y);
liftDir_ = readVectorOrDefault(dict, "liftDir", vector::Z);
rollAxis_ = readVectorOrDefault(dict, "rollAxis", vector::X);
pitchAxis_ = readVectorOrDefault(dict, "pitchAxis", vector::Y);
yawAxis_ = readVectorOrDefault(dict, "yawAxis", vector::Z);
// Free stream velocity magnitude
dict.readEntry("magUInf", magUInf_);
......@@ -387,18 +352,22 @@ bool Foam::functionObjects::forceCoeffs::execute()
scalar CmYawTot = 0;
const scalar pDyn = 0.5*rhoRef_*sqr(magUInf_);
// Avoid divide by zero in 2D cases
const scalar momentScaling = 1.0/(Aref_*pDyn*lRef_ + SMALL);
const scalar forceScaling = 1.0/(Aref_*pDyn + SMALL);
forAll(liftCoeffs, i)
{
dragCoeffs[i] = forceScaling*(force_[i] & dragDir_);
sideCoeffs[i] = forceScaling*(force_[i] & sideDir_);
liftCoeffs[i] = forceScaling*(force_[i] & liftDir_);
rollMomentCoeffs[i] = momentScaling*(moment_[i] & rollAxis_);
pitchMomentCoeffs[i] = momentScaling*(moment_[i] & pitchAxis_);
yawMomentCoeffs[i] = momentScaling*(moment_[i] & yawAxis_);
const Field<vector> localForce(coordSys_.localVector(force_[i]));
const Field<vector> localMoment(coordSys_.localVector(moment_[i]));
dragCoeffs[i] = forceScaling*(localForce.component(0));
sideCoeffs[i] = forceScaling*(localForce.component(1));
liftCoeffs[i] = forceScaling*(localForce.component(2));
rollMomentCoeffs[i] = momentScaling*(localMoment.component(0));
pitchMomentCoeffs[i] = momentScaling*(localMoment.component(1));
yawMomentCoeffs[i] = momentScaling*(localMoment.component(2));
CdTot += sum(dragCoeffs[i]);
CsTot += sum(sideCoeffs[i]);
......@@ -408,7 +377,7 @@ bool Foam::functionObjects::forceCoeffs::execute()
CmYawTot += sum(yawMomentCoeffs[i]);
}
// Single contributions to the front and rear axles
// Single contributions to the front and rear
const scalar CdfTot = 0.5*CdTot + CmRollTot;
const scalar CdrTot = 0.5*CdTot - CmRollTot;
const scalar CsfTot = 0.5*CsTot + CmYawTot;
......
......@@ -62,12 +62,14 @@ Usage
log yes;
writeFields yes;
patches (walls);
dragDir (1 0 0);
sideDir (0 1 0);
liftDir (0 0 1);
rollAxis (1 0 0);
pitchAxis (0 1 0);
yawAxis (0 0 1);
coordinateSystem
{
type xxx;
dragDir (1 0 0);
liftDir (0 0 1);
}
magUInf 100;
lRef 3.5;
Aref 2.2;
......@@ -140,27 +142,6 @@ class forceCoeffs
{
// Private data
// Force coefficient geometry in global Cartesian coordinate system
//- Drag force direction
vector dragDir_;
//- Side force direction
vector sideDir_;
//- Lift force direction
vector liftDir_;
//- Roll axis direction
vector rollAxis_;
//- Pitch axis direction
vector pitchAxis_;
//- Yaw axis direction
vector yawAxis_;
// Free-stream conditions
//- Free-stream velocity magnitude
......
......@@ -71,22 +71,6 @@ void Foam::functionObjects::forces::createFiles()
momentBinFilePtr_ = createFile("momentBin");
writeBinHeader("Moment", momentBinFilePtr_());
}
if (localSystem_)
{
localForceFilePtr_ = createFile("localForce");
writeIntegratedHeader("Force", localForceFilePtr_());
localMomentFilePtr_ = createFile("localMoment");
writeIntegratedHeader("Moment", localMomentFilePtr_());
if (nBin_ > 1)
{
localForceBinFilePtr_ = createFile("localForceBin");
writeBinHeader("Force", localForceBinFilePtr_());
localMomentBinFilePtr_ = createFile("localMomentBin");
writeBinHeader("Moment", localMomentBinFilePtr_());
}
}
}
}
......@@ -169,6 +153,49 @@ void Foam::functionObjects::forces::writeBinHeader
}
void Foam::functionObjects::forces::setCoordinateSystem
(
const dictionary& dict,
const word& e3Name,
const word& e1Name
)
{
coordSys_.clear();
if (dict.readIfPresent<point>("CofR", coordSys_.origin()))
{
const vector e3 = e3Name == word::null ?
vector(0, 0, 1) : dict.get<vector>(e3Name);
const vector e1 = e1Name == word::null ?
vector(1, 0, 0) : dict.get<vector>(e1Name);
coordSys_ =
coordSystem::cartesian(coordSys_.origin(), e3, e1);
}
else
{
// The 'coordinateSystem' sub-dictionary is optional,
// but enforce use of a cartesian system if not found.
if (dict.found(coordinateSystem::typeName_()))
{
// New() for access to indirect (global) coordinate system
coordSys_ =
coordinateSystem::New
(
obr_,
dict,
coordinateSystem::typeName_()
);
}
else
{
coordSys_ = coordSystem::cartesian(dict);
}
}
}
void Foam::functionObjects::forces::initialise()
{
......@@ -586,42 +613,21 @@ void Foam::functionObjects::forces::writeForces()
writeIntegratedForceMoment
(
"forces",
force_[0],
force_[1],
force_[2],
coordSys_.localVector(force_[0]),
coordSys_.localVector(force_[1]),
coordSys_.localVector(force_[2]),
forceFilePtr_
);
writeIntegratedForceMoment
(
"moments",
moment_[0],
moment_[1],
moment_[2],
coordSys_.localVector(moment_[0]),
coordSys_.localVector(moment_[1]),
coordSys_.localVector(moment_[2]),
momentFilePtr_
);
if (localSystem_)
{
writeIntegratedForceMoment
(
"local forces",
coordSys_.localVector(force_[0]),
coordSys_.localVector(force_[1]),
coordSys_.localVector(force_[2]),
localForceFilePtr_
);
writeIntegratedForceMoment
(
"local moments",
coordSys_.localVector(moment_[0]),
coordSys_.localVector(moment_[1]),
coordSys_.localVector(moment_[2]),
localMomentFilePtr_
);
}
Log << endl;
}
......@@ -673,23 +679,17 @@ void Foam::functionObjects::forces::writeBinnedForceMoment
void Foam::functionObjects::forces::writeBins()
{
writeBinnedForceMoment(force_, forceBinFilePtr_);
writeBinnedForceMoment(moment_, momentBinFilePtr_);
if (localSystem_)
{
List<Field<vector>> lf(3);
List<Field<vector>> lm(3);
lf[0] = coordSys_.localVector(force_[0]);
lf[1] = coordSys_.localVector(force_[1]);
lf[2] = coordSys_.localVector(force_[2]);
lm[0] = coordSys_.localVector(moment_[0]);
lm[1] = coordSys_.localVector(moment_[1]);
lm[2] = coordSys_.localVector(moment_[2]);
writeBinnedForceMoment(lf, localForceBinFilePtr_);
writeBinnedForceMoment(lm, localMomentBinFilePtr_);
}
List<Field<vector>> lf(3);
List<Field<vector>> lm(3);
lf[0] = coordSys_.localVector(force_[0]);
lf[1] = coordSys_.localVector(force_[1]);
lf[2] = coordSys_.localVector(force_[2]);
lm[0] = coordSys_.localVector(moment_[0]);
lm[1] = coordSys_.localVector(moment_[1]);
lm[2] = coordSys_.localVector(moment_[2]);
writeBinnedForceMoment(lf, forceBinFilePtr_);
writeBinnedForceMoment(lm, momentBinFilePtr_);
}
......@@ -711,10 +711,6 @@ Foam::functionObjects::forces::forces
momentFilePtr_(),
forceBinFilePtr_(),
momentBinFilePtr_(),
localForceFilePtr_(),
localMomentFilePtr_(),
localForceBinFilePtr_(),
localMomentBinFilePtr_(),
patchSet_(),
pName_(word::null),
UName_(word::null),
......@@ -724,7 +720,6 @@ Foam::functionObjects::forces::forces
rhoRef_(VGREAT),
pRef_(0),
coordSys_(),
localSystem_(false),
porosity_(false),
nBin_(1),
binDir_(Zero),
......@@ -738,6 +733,7 @@ Foam::functionObjects::forces::forces
if (readFields)
{
read(dict);
setCoordinateSystem(dict);
Log << endl;
}
}
......@@ -759,10 +755,6 @@ Foam::functionObjects::forces::forces
momentFilePtr_(),
forceBinFilePtr_(),
momentBinFilePtr_(),
localForceFilePtr_(),
localMomentFilePtr_(),
localForceBinFilePtr_(),
localMomentBinFilePtr_(),
patchSet_(),
pName_(word::null),
UName_(word::null),
......@@ -772,7 +764,6 @@ Foam::functionObjects::forces::forces
rhoRef_(VGREAT),
pRef_(0),
coordSys_(),
localSystem_(false),
porosity_(false),
nBin_(1),
binDir_(Zero),
......@@ -786,6 +777,7 @@ Foam::functionObjects::forces::forces
if (readFields)
{
read(dict);
setCoordinateSystem(dict);
Log << endl;
}
......@@ -843,32 +835,6 @@ bool Foam::functionObjects::forces::read(const dictionary& dict)
Info<< " Reference pressure (pRef) set to " << pRef_ << endl;
}
coordSys_.clear();
localSystem_ = false;
// Centre of rotation for moment calculations
// specified directly, from coordinate system, or implicitly (0 0 0)
if (!dict.readIfPresent<point>("CofR", coordSys_.origin()))
{
// The 'coordinateSystem' sub-dictionary is optional,
// but enforce use of a cartesian system.
if (dict.found(coordinateSystem::typeName_()))
{
// New() for access to indirect (global) coordinate system
coordSys_ =
coordinateSystem::New
(
obr_, dict, coordinateSystem::typeName_()
);
}
else
{
coordSys_ = coordSystem::cartesian(dict);
}
localSystem_ = true;
}
dict.readIfPresent("porosity", porosity_);
if (porosity_)
......
......@@ -192,18 +192,6 @@ protected:
//- 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
......@@ -234,9 +222,6 @@ protected:
//- Coordinate system used when evaluting forces/moments
coordSystem::cartesian coordSys_;
//- Flag to indicate whether we are using a local coordinates
bool localSystem_;
//- Flag to include porosity effects
bool porosity_;
......@@ -283,6 +268,14 @@ protected:
//- Write header for binned data
void writeBinHeader(const word& header, Ostream& os) const;
//- Set the co-ordinate system from dictionary and axes names
void setCoordinateSystem
(
const dictionary& dict,
const word& e3Name = word::null,
const word& e1Name = word::null
);
//- Initialise the fields
void initialise();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment