43 namespace functionObjects
75 scopedName(
"forceCoeff"),
86 mesh_.objectRegistry::store(coeffPtr);
104 scopedName(
"momentCoeff"),
115 mesh_.objectRegistry::store(coeffPtr);
137 coeffs.insert(
"Cd", coeffDesc(
"Drag force",
"Cd", 0, 0));
138 coeffs.insert(
"Cs", coeffDesc(
"Side force",
"Cs", 1, 2));
139 coeffs.insert(
"Cl", coeffDesc(
"Lift force",
"Cl", 2, 1));
142 const auto frontRearCoeffs(coeffs);
145 const auto& fr = iter.val();
146 coeffs.insert(fr.frontName(), fr.front());
147 coeffs.insert(fr.rearName(), fr.rear());
151 coeffs.insert(
"CmRoll", coeffDesc(
"Roll moment",
"CmRoll", 0, -1));
152 coeffs.insert(
"CmPitch",
coeffDesc(
"Pitch moment",
"CmPitch", 1, -1));
153 coeffs.insert(
"CmYaw",
coeffDesc(
"Yaw moment",
"CmYaw", 2, -1));
162 const scalar
pDyn = 0.5*rhoRef_*
sqr(magUInf_);
166 scalar(1)/(Aref_*
pDyn + SMALL)
169 const auto& coordSys = coordSysPtr_();
172 forceCoeff() = forceScaling*force();
176 forceScaling.
value()*coordSys.localVector(sumPatchForcesP_),
177 forceScaling.
value()*coordSys.localVector(sumPatchForcesV_),
178 forceScaling.
value()*coordSys.localVector(sumInternalForces_)
186 const scalar
pDyn = 0.5*rhoRef_*
sqr(magUInf_);
190 scalar(1)/(Aref_*
pDyn*lRef_ + SMALL)
193 const auto& coordSys = coordSysPtr_();
196 momentCoeff() = momentScaling*moment();
200 momentScaling.
value()*coordSys.localVector(sumPatchMomentsP_),
201 momentScaling.
value()*coordSys.localVector(sumPatchMomentsV_),
202 momentScaling.
value()*coordSys.localVector(sumInternalMoments_)
211 coeffFilePtr_ = newFileAtStartTime(
"coefficient");
212 writeIntegratedDataFileHeader(
"Coefficients", coeffFilePtr_());
223 const auto& coordSys = coordSysPtr_();
226 writeHeaderValue(
os,
"dragDir", coordSys.e1());
227 writeHeaderValue(
os,
"sideDir", coordSys.e2());
228 writeHeaderValue(
os,
"liftDir", coordSys.e3());
229 writeHeaderValue(
os,
"rollAxis", coordSys.e1());
230 writeHeaderValue(
os,
"pitchAxis", coordSys.e2());
231 writeHeaderValue(
os,
"yawAxis", coordSys.e3());
232 writeHeaderValue(
os,
"magUInf", magUInf_);
233 writeHeaderValue(
os,
"lRef", lRef_);
234 writeHeaderValue(
os,
"Aref", Aref_);
235 writeHeaderValue(
os,
"CofR", coordSys.origin());
237 writeCommented(
os,
"Time");
239 for (
const auto& iter : coeffs_.csorted())
241 const auto& coeff = iter.val();
243 if (!coeff.active_)
continue;
245 writeTabbed(
os, coeff.name_);
256 writeCurrentTime(
os);
258 for (
const auto& iter : coeffs_.csorted())
260 const auto& coeff = iter.val();
262 if (!coeff.active_)
continue;
264 const vector coeffValue = coeff.value(Cf_, Cm_);
266 os <<
tab << (coeffValue.x() + coeffValue.y() + coeffValue.z());
313 dict.readEntry(
"magUInf", magUInf_);
314 dict.readEntry(
"lRef", lRef_);
315 dict.readEntry(
"Aref", Aref_);
320 if (rhoName_ !=
"rhoInf")
322 dict.readEntry(
"rhoInf", rhoRef_);
325 Info<<
" magUInf: " << magUInf_ <<
nl 326 <<
" lRef : " << lRef_ <<
nl 327 <<
" Aref : " << Aref_ <<
nl 328 <<
" rhoInf : " << rhoRef_ <<
endl;
330 if (
min(magUInf_, rhoRef_) < SMALL ||
min(lRef_, Aref_) < SMALL)
333 <<
"Non-zero values are required for reference scales" 339 if (!
dict.found(
"coefficients"))
341 Info<<
" Selecting all coefficients" <<
nl;
343 coeffs_ = selectCoeffs();
345 for (
auto& iter : coeffs_.sorted())
347 auto& coeff = iter.val();
348 coeff.active_ =
true;
349 Info<<
" - " << coeff <<
nl;
356 coeffs_ = selectCoeffs();
358 Info<<
" Selecting coefficients:" <<
nl;
360 for (
const word&
key : coeffs)
362 auto iter = coeffs_.find(
key);
367 <<
"Unknown coefficient type " <<
key 368 <<
" . Valid entries are : " << coeffs_.sortedToc()
371 auto& coeff = iter.val();
372 coeff.active_ =
true;
373 Info<<
" - " << coeff <<
nl;
393 <<
" " <<
"Coefficient" 407 <<
tab << coeff.x() + coeff.y() + coeff.z()
415 for (
const auto& iter : coeffs_.csorted())
417 const word& coeffName = iter.key();
418 const auto& coeff = iter.val();
421 const vector coeffValue = coeff.value(Cf_, Cm_);
423 if (
log && coeff.active_)
425 logValues(coeffName, coeffValue,
Info);
428 setResult(coeffName, coeffValue.x() + coeffValue.y() + coeffValue.z());
429 setResult(coeffName &
"pressure", coeffValue.x());
430 setResult(coeffName &
"viscous", coeffValue.y());
431 setResult(coeffName &
"internal", coeffValue.z());
444 Log <<
" writing force and moment coefficient files." <<
endl;
446 createIntegratedDataFile();
448 writeIntegratedDataFile();
453 forceCoeff().write();
454 momentCoeff().write();
const Type & value() const noexcept
Return const reference to value.
defineTypeNameAndDebug(ObukhovLength, 0)
void calcForceCoeffs()
Calculate force coefficients.
static bool initialised_(false)
virtual bool write()
Write to data files/fields and to streams.
static void writeHeader(Ostream &os, const word &fieldName)
dimensionedScalar log(const dimensionedScalar &ds)
errorManipArg< error, int > exit(error &err, const int errNo=1)
A list of keyword definitions, which are a keyword followed by a number of values (eg...
dimensionedSymmTensor sqr(const dimensionedVector &dv)
Output to file stream, using an OSstream.
constexpr char nl
The newline '\n' character (0x0a)
dimensioned< vector > dimensionedVector
Dimensioned vector obtained from generic dimensioned type.
Ostream & endl(Ostream &os)
Add newline and flush stream.
constexpr char tab
The tab '\t' character(0x09)
void writeIntegratedDataFile()
Write integrated coefficients to the integrated-coefficient file.
Ignore writing from objectRegistry::writeObject()
const dimensionSet dimless
Dimensionless.
volVectorField & momentCoeff()
Return access to the moment coefficients field.
Abstract base-class for Time/database function objects.
GeometricField< vector, fvPatchField, volMesh > volVectorField
HashTable< coeffDesc > selectCoeffs() const
Return the operand coefficients.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
forceCoeffs(const word &name, const Time &runTime, const dictionary &dict, const bool readFields=true)
Construct from Time and dictionary.
virtual bool read(const dictionary &dict)
Read the dictionary.
Macros for easy insertion into run-time selection tables.
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
virtual void calcForcesMoments()
Calculate forces and moments.
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
A class for handling words, derived from Foam::string.
volScalarField pDyn(IOobject("pDyn", runTime.timeName(), mesh, IOobject::NO_READ, IOobject::AUTO_WRITE), mesh, dimensionedScalar(dimPressure, Zero))
HashSet< word, Hash< word > > wordHashSet
A HashSet of words, uses string hasher.
void initialise()
Initialise containers and fields.
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
void reset()
Reset containers and fields.
void calcMomentCoeffs()
Calculate moment coefficients.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
virtual bool read(const dictionary &dict)
Read the dictionary.
Istream and Ostream manipulators taking arguments.
const dimensionSet dimForce
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
Reads fields from the time directories and adds them to the mesh database for further post-processing...
OBJstream os(runTime.globalPath()/outputName)
volVectorField & forceCoeff()
Return access to the force coefficients field.
addToRunTimeSelectionTable(functionObject, ObukhovLength, dictionary)
void setCoordinateSystem(const dictionary &dict, const word &e3Name=word::null, const word &e1Name=word::null)
Set the co-ordinate system from dictionary and axes names.
Computes force and moment coefficients over a given list of patches, and optionally over given porous...
void writeIntegratedDataFileHeader(const word &header, OFstream &os) const
Write header to the integrated-coefficient file.
const dimensionSet dimLength(0, 1, 0, 0, 0, 0, 0)
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
auto key(const Type &t) -> typename std::enable_if< std::is_enum< Type >::value, typename std::underlying_type< Type >::type >::type
messageStream Info
Information stream (stdout output on master, null elsewhere)
Computes forces and moments over a given list of patches by integrating pressure and viscous forces a...
Coefficients description.
void createIntegratedDataFile()
Create the integrated-coefficient file.
Defines the attributes of an object for which implicit objectRegistry management is supported...
Request registration (bool: true)
virtual bool execute()
Execute the function object.
forAllConstIters(mixture.phases(), phase)
IOerror FatalIOError
Error stream (stdout output on all processes), with additional 'FOAM FATAL IO ERROR' header text and ...
static constexpr const zero Zero
Global zero (0)