66 auto* ptr = mesh_.getObjectPtr<
volVectorField>(scopedName(
"forceCoeff"));
74 scopedName(
"forceCoeff"),
94 auto* ptr = mesh_.getObjectPtr<
volVectorField>(scopedName(
"momentCoeff"));
102 scopedName(
"momentCoeff"),
135 coeffs.
insert(
"Cd", coeffDesc(
"Drag force",
"Cd", 0, 0));
136 coeffs.
insert(
"Cs", coeffDesc(
"Side force",
"Cs", 1, 2));
137 coeffs.
insert(
"Cl", coeffDesc(
"Lift force",
"Cl", 2, 1));
140 const auto frontRearCoeffs(coeffs);
143 const auto& fr = iter.val();
144 coeffs.
insert(fr.frontName(), fr.front());
145 coeffs.
insert(fr.rearName(), fr.rear());
149 coeffs.
insert(
"CmRoll", coeffDesc(
"Roll moment",
"CmRoll", 0, -1));
160 const scalar
pDyn = 0.5*rhoRef_*
sqr(magUInf_);
164 scalar(1)/(Aref_*
pDyn + SMALL)
167 const auto& coordSys = coordSysPtr_();
170 forceCoeff() = forceScaling*force();
184 const scalar
pDyn = 0.5*rhoRef_*
sqr(magUInf_);
188 scalar(1)/(Aref_*
pDyn*lRef_ + SMALL)
191 const auto& coordSys = coordSysPtr_();
194 momentCoeff() = momentScaling*moment();
221 const auto& coordSys = coordSysPtr_();
224 writeHeaderValue(
os,
"dragDir", coordSys.e1());
225 writeHeaderValue(
os,
"sideDir", coordSys.e2());
226 writeHeaderValue(
os,
"liftDir", coordSys.e3());
227 writeHeaderValue(
os,
"rollAxis", coordSys.e1());
228 writeHeaderValue(
os,
"pitchAxis", coordSys.e2());
229 writeHeaderValue(
os,
"yawAxis", coordSys.e3());
230 writeHeaderValue(
os,
"magUInf", magUInf_);
231 writeHeaderValue(
os,
"lRef", lRef_);
232 writeHeaderValue(
os,
"Aref", Aref_);
233 writeHeaderValue(
os,
"CofR", coordSys.origin());
235 writeCommented(
os,
"Time");
237 for (
const auto& iter : coeffs_.csorted())
239 const auto& coeff = iter.val();
241 if (!coeff.active_)
continue;
254 writeCurrentTime(
os);
256 for (
const auto& iter : coeffs_.csorted())
258 const auto& coeff = iter.val();
260 if (!coeff.active_)
continue;
262 const vector coeffValue = coeff.value(Cf_, Cm_);
264 os <<
tab << (coeffValue.
x() + coeffValue.
y() + coeffValue.
z());
267 coeffFilePtr_() <<
endl;
311 dict.readEntry(
"magUInf", magUInf_);
312 dict.readEntry(
"lRef", lRef_);
313 dict.readEntry(
"Aref", Aref_);
318 if (rhoName_ !=
"rhoInf")
320 dict.readEntry(
"rhoInf", rhoRef_);
323 Info<<
" magUInf: " << magUInf_ <<
nl
324 <<
" lRef : " << lRef_ <<
nl
325 <<
" Aref : " << Aref_ <<
nl
326 <<
" rhoInf : " << rhoRef_ <<
endl;
328 if (
min(magUInf_, rhoRef_) < SMALL ||
min(lRef_, Aref_) < SMALL)
331 <<
"Non-zero values are required for reference scales"
337 if (!
dict.found(
"coefficients"))
339 Info<<
" Selecting all coefficients" <<
nl;
341 coeffs_ = selectCoeffs();
343 for (
auto& iter : coeffs_.sorted())
345 auto& coeff = iter.val();
346 coeff.active_ =
true;
347 Info<<
" - " << coeff <<
nl;
354 coeffs_ = selectCoeffs();
356 Info<<
" Selecting coefficients:" <<
nl;
358 for (
const word& key : coeffs)
360 auto iter = coeffs_.find(key);
365 <<
"Unknown coefficient type " <<
key
366 <<
" . Valid entries are : " << coeffs_.sortedToc()
369 auto& coeff = iter.val();
370 coeff.active_ =
true;
371 Info<<
" - " << coeff <<
nl;
391 <<
" " <<
"Coefficient"
405 <<
tab << coeff.x() + coeff.y() + coeff.z()
413 for (
const auto& iter : coeffs_.csorted())
415 const word& coeffName = iter.key();
416 const auto& coeff = iter.val();
419 const vector coeffValue = coeff.value(Cf_, Cm_);
421 if (
log && coeff.active_)
423 logValues(coeffName, coeffValue,
Info);
426 setResult(coeffName, coeffValue.
x() + coeffValue.
y() + coeffValue.
z());
427 setResult(coeffName &
"pressure", coeffValue.
x());
428 setResult(coeffName &
"viscous", coeffValue.
y());
429 setResult(coeffName &
"internal", coeffValue.
z());
442 Log <<
" writing force and moment coefficient files." <<
endl;
444 createIntegratedDataFile();
446 writeIntegratedDataFile();
451 forceCoeff().write();
452 momentCoeff().write();
Istream and Ostream manipulators taking arguments.
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
A HashTable similar to std::unordered_map.
bool insert(const Key &key, const T &obj)
Copy insert a new entry, not overwriting existing entries.
@ REGISTER
Request registration (bool: true).
@ NO_READ
Nothing to be read.
@ NO_WRITE
Ignore writing from objectRegistry::writeObject().
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Output to file stream as an OSstream, normally using std::ofstream for the actual output.
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
const Cmpt & x() const noexcept
Access to the vector x component.
const Cmpt & z() const noexcept
Access to the vector z component.
const Cmpt & y() const noexcept
Access to the vector y component.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
const Type & value() const noexcept
Return const reference to value.
Abstract base-class for Time/database function objects.
word scopedName(const word &name) const
Return a scoped (prefixed) name.
Computes force and moment coefficients over a given list of patches, and optionally over given porous...
volVectorField & momentCoeff()
Return access to the moment coefficients field.
void calcMomentCoeffs()
Calculate moment coefficients.
HashTable< coeffDesc > selectCoeffs() const
Return the operand coefficients.
void writeIntegratedDataFileHeader(const word &header, OFstream &os) const
Write header to the integrated-coefficient file.
void initialise()
Initialise containers and fields.
void calcForceCoeffs()
Calculate force coefficients.
void reset()
Reset containers and fields.
void createIntegratedDataFile()
Create the integrated-coefficient file.
virtual bool execute()
Execute the function-object operations.
virtual bool write()
Write the function-object results.
forceCoeffs(const word &name, const Time &runTime, const dictionary &dict, const bool readFields=true)
Construct from name, Time and dictionary.
virtual bool read(const dictionary &)
Read the function-object dictionary.
void writeIntegratedDataFile()
Write integrated coefficients to the integrated-coefficient file.
volVectorField & forceCoeff()
Return access to the force coefficients field.
Computes forces and moments over a given list of patches by integrating pressure and viscous forces a...
virtual void calcForcesMoments()
Calculate forces and moments.
scalar rhoRef_
Reference density needed for incompressible calculations.
vector sumPatchForcesV_
Sum of patch viscous forces.
vector sumPatchForcesP_
Sum of patch pressure forces.
vector sumInternalMoments_
Sum of internal moments.
volVectorField & moment()
Return access to the moment field.
vector sumPatchMomentsV_
Sum of patch viscous moments.
vector sumInternalForces_
Sum of internal forces.
forces(const word &name, const Time &runTime, const dictionary &dict, const bool readFields=true)
Construct from name, Time and dictionary.
autoPtr< coordinateSystem > coordSysPtr_
Coordinate system used when evaluating forces and moments.
vector sumPatchMomentsP_
Sum of patch pressure moments.
word rhoName_
Name of density field.
bool writeFields_
Flag to write force and moment fields.
volVectorField & force()
Return access to the force field.
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.
virtual bool read(const dictionary &)
Read the function-object dictionary.
const fvMesh & mesh_
Reference to the fvMesh.
Computes the natural logarithm of an input volScalarField.
Reads fields from the time directories and adds them to the mesh database for further post-processing...
void setResult(const word &entryName, const Type &value)
Add result.
const Time & time_
Reference to the time database.
virtual autoPtr< OFstream > newFileAtStartTime(const word &name) const
Return autoPtr to a new file using the simulation start time.
virtual void writeTabbed(Ostream &os, const string &str) const
Write a tabbed string to stream.
void writeHeaderValue(Ostream &os, const string &property, const Type &value) const
Write a (commented) header property and value pair.
virtual void writeCommented(Ostream &os, const string &str) const
Write a commented string to stream.
virtual void writeCurrentTime(Ostream &os) const
Write the current time to stream.
virtual bool writeToFile() const
Flag to allow writing to file.
bool store()
Register object with its registry and transfer ownership to the registry.
A class for handling words, derived from Foam::string.
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
limits reset(1/(limits.max()+VSMALL), 1/(limits.min()+VSMALL))
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
OBJstream os(runTime.globalPath()/outputName)
Function objects are OpenFOAM utilities to ease workflow configurations and enhance workflows.
constexpr auto key(const Type &t) noexcept
Helper function to return the enum value.
GeometricField< vector, fvPatchField, volMesh > volVectorField
const dimensionSet dimless
Dimensionless.
HashSet< word, Hash< word > > wordHashSet
A HashSet of words, uses string hasher.
dimensionedSymmTensor sqr(const dimensionedVector &dv)
const dimensionSet dimLength(0, 1, 0, 0, 0, 0, 0)
static void writeHeader(Ostream &os, const word &fieldName)
messageStream Info
Information stream (stdout output on master, null elsewhere).
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
dimensionedScalar log(const dimensionedScalar &ds)
Ostream & endl(Ostream &os)
Add newline and flush stream.
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
const dimensionSet dimForce
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).
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
errorManipArg< error, int > exit(error &err, const int errNo=1)
dimensioned< vector > dimensionedVector
Dimensioned vector obtained from generic dimensioned type.
constexpr char nl
The newline '\n' character (0x0a).
constexpr char tab
The tab '\t' character(0x09).
static bool initialised_(false)
volScalarField pDyn(IOobject("pDyn", runTime.timeName(), mesh, IOobject::NO_READ, IOobject::AUTO_WRITE), mesh, dimensionedScalar(dimPressure, Zero))
#define forAllConstIters(container, iter)
Iterate across all elements of the container object with const access.
Coefficients description.