Go to the documentation of this file.
40 namespace functionObjects
50 void Foam::functionObjects::momentum::purgeFields()
58 template<
class GeoField>
60 Foam::functionObjects::momentum::newField
85 void Foam::functionObjects::momentum::calc()
102 const auto&
U = lookupObject<volVectorField>(UName_);
103 const auto*
rhoPtr = findObject<volScalarField>(rhoName_);
121 auto* pmomentum = getObjectPtr<volVectorField>(scopedName(
"momentum"));
126 pmomentum = tmomentum.
get();
128 auto& momentum = *pmomentum;
132 momentum.ref() = (
U * mesh_.V() * (*rhoPtr));
136 momentum.ref() = (
U * mesh_.V() * rhoRef);
138 momentum.correctBoundaryConditions();
145 getObjectPtr<volVectorField>(scopedName(
"angularMomentum"));
147 if (hasCsys_ && !pAngularMom)
151 pAngularMom = tAngularMom.
get();
153 else if (!pAngularMom)
157 pAngularMom = pmomentum;
159 auto& angularMom = *pAngularMom;
166 getObjectPtr<volVectorField>(scopedName(
"angularVelocity"));
173 newField<volVectorField>(
"angularVelocity",
dimVelocity);
174 pAngularVel = tAngularVel.
get();
176 auto& angularVel = *pAngularVel;
181 angularVel.primitiveFieldRef() =
182 csys_.invTransform(mesh_.cellCentres(),
U.internalField());
184 angularVel.correctBoundaryConditions();
188 angularMom.ref() = (angularVel * mesh_.V() * (*rhoPtr));
192 angularMom.ref() = (angularVel * mesh_.V() * rhoRef);
195 angularMom.correctBoundaryConditions();
202 sumAngularMom_ =
Zero;
206 for (label celli=0; celli < mesh_.nCells(); ++celli)
208 sumMomentum_ += momentum[celli];
209 sumAngularMom_ += angularMom[celli];
214 for (
const label celli : cellIDs())
216 sumMomentum_ += momentum[celli];
217 sumAngularMom_ += angularMom[celli];
221 reduce(sumMomentum_, sumOp<vector>());
222 reduce(sumAngularMom_, sumOp<vector>());
230 if (!writeToFile() || writtenHeader_)
238 writeHeaderValue(
os,
"origin", csys_.origin());
239 writeHeaderValue(
os,
"axis", csys_.e3());
251 "Selection " + regionTypeNames_[regionType_]
252 +
" = " + regionName_
257 writeCommented(
os,
"Time");
258 writeTabbed(
os,
"(momentum_x momentum_y momentum_z)");
262 writeTabbed(
os,
"(momentum_r momentum_rtheta momentum_axis)");
265 writeTabbed(
os,
"volume");
268 writtenHeader_ =
true;
279 if (!foundObject<volVectorField>(UName_))
282 <<
"Could not find U: " << UName_ <<
" in database"
287 const auto* pPtr = cfindObject<volScalarField>(pName_);
293 if (!foundObject<volScalarField>(rhoName_))
296 <<
"Could not find rho:" << rhoName_
311 Info<<
" Sum of Momentum";
315 Info<<
' ' << regionTypeNames_[regionType_]
316 <<
' ' << regionName_;
320 <<
" linear : " << sumMomentum_ <<
nl;
324 Info<<
" angular : " << sumAngularMom_ <<
nl;
332 writeCurrentTime(
os);
334 os <<
tab << sumMomentum_;
338 os <<
tab << sumAngularMom_;
360 sumAngularMom_(
Zero),
367 writeMomentum_(
false),
368 writeVelocity_(
false),
369 writePosition_(
false),
392 sumAngularMom_(
Zero),
399 writeMomentum_(
false),
400 writeVelocity_(
false),
401 writePosition_(
false),
420 initialised_ =
false;
425 UName_ =
dict.getOrDefault<
word>(
"U",
"U");
426 pName_ =
dict.getOrDefault<
word>(
"p",
"p");
427 rhoName_ =
dict.getOrDefault<
word>(
"rho",
"rho");
428 rhoRef_ =
dict.getOrDefault<scalar>(
"rhoRef", 1.0);
429 hasCsys_ =
dict.getOrDefault(
"cylindrical",
false);
436 writeMomentum_ =
dict.getOrDefault(
"writeMomentum",
false);
437 writeVelocity_ =
dict.getOrDefault(
"writeVelocity",
false);
438 writePosition_ =
dict.getOrDefault(
"writePosition",
false);
440 Info<<
"Integrating for selection: "
441 << regionTypeNames_[regionType_]
442 <<
" (" << regionName_ <<
")" <<
nl;
446 Info<<
" Momentum fields will be written" <<
endl;
448 mesh_.objectRegistry::store
455 mesh_.objectRegistry::store
466 Info<<
" Angular velocity will be written" <<
endl;
468 mesh_.objectRegistry::store
470 newField<volVectorField>(
"angularVelocity",
dimVelocity)
476 Info<<
" Angular position will be written" <<
endl;
490 writeFileHeader(file());
498 setResult(
"momentum_x", sumMomentum_[0]);
499 setResult(
"momentum_y", sumMomentum_[1]);
500 setResult(
"momentum_z", sumMomentum_[2]);
502 setResult(
"momentum_r", sumAngularMom_[0]);
503 setResult(
"momentum_rtheta", sumAngularMom_[1]);
504 setResult(
"momentum_axis", sumAngularMom_[2]);
512 if (writeMomentum_ || (hasCsys_ && (writeVelocity_ || writePosition_)))
514 Log <<
"Writing fields" <<
nl;
518 fieldPtr = findObject<volVectorField>(scopedName(
"momentum"));
519 if (fieldPtr) fieldPtr->write();
521 fieldPtr = findObject<volVectorField>(scopedName(
"angularMomentum"));
522 if (fieldPtr) fieldPtr->write();
524 fieldPtr = findObject<volVectorField>(scopedName(
"angularVelocity"));
525 if (fieldPtr) fieldPtr->write();
527 if (hasCsys_ && writePosition_)
532 auto cyl_r = newField<volScalarField>(
"cyl_r",
dimLength);
533 auto cyl_t = newField<volScalarField>(
"cyl_theta",
dimless);
534 auto cyl_z = newField<volScalarField>(
"cyl_z",
dimLength);
538 const auto& pts = mesh_.cellCentres();
539 const label len = pts.size();
545 for (label i=0; i < len; ++i)
547 point p(csys_.localPosition(pts[i]));
560 if (isA<emptyPolyPatch>(pbm[patchi]))
565 const auto& pts = pbm[patchi].faceCentres();
566 const label len = pts.size();
572 for (label i=0; i < len; ++i)
574 point p(csys_.localPosition(pts[i]));
virtual void updateMesh(const mapPolyMesh &)
Update for changes of mesh.
static autoPtr< T > New(Args &&... args)
Construct autoPtr of T with forwarding arguments.
virtual bool read(const dictionary &)
Read the momentum data.
const dimensionSet dimPressure
Defines the attributes of an object for which implicit objectRegistry management is supported,...
const objectRegistry & obr_
Reference to the region objectRegistry.
virtual bool write()
Write the momentum, possibly angular momentum and velocity.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
A class for handling words, derived from Foam::string.
bool update()
Update the cached values as required.
A polyBoundaryMesh is a polyPatch list with additional search methods and registered IO.
const dimensionSet dimLength(0, 1, 0, 0, 0, 0, 0)
Volume (cell) region selection class.
static constexpr const zero Zero
Global zero (0)
const dimensionSet dimVelocity
const dimensionSet dimDensity
bool read(const char *buf, int32_t &val)
Same as readInt32.
static bool master(const label communicator=worldComm)
Am I the master process.
Ostream & endl(Ostream &os)
Add newline and flush stream.
momentum(const word &name, const Time &runTime, const dictionary &dict, const bool readFields=true)
Construct from Time and dictionary.
static void writeHeader(Ostream &os, const word &fieldName)
Dimension set for the base types, which can be used to implement rigorous dimension checking for alge...
Specialization of Foam::functionObject for an Foam::fvMesh, providing a reference to the Foam::fvMesh...
virtual void updateMesh(const mapPolyMesh &)
Update for changes of mesh.
Mesh consisting of general polyhedral cells.
#define forAll(list, i)
Loop across all elements in list.
Info<< "Reading mechanical properties\n"<< endl;IOdictionary mechanicalProperties(IOobject("mechanicalProperties", runTime.constant(), mesh, IOobject::MUST_READ_IF_MODIFIED, IOobject::NO_WRITE));const dictionary &rhoDict(mechanicalProperties.subDict("rho"));word rhoType(rhoDict.get< word >"type"));autoPtr< volScalarField > rhoPtr
virtual bool read(const dictionary &dict)
Read from dictionary.
Registry of regIOobjects.
virtual bool read(const dictionary &dict)
Read.
void reduce(const List< UPstream::commsStruct > &comms, T &Value, const BinaryOp &bop, const int tag, const label comm)
virtual bool execute()
Calculate and report the integral momentum.
messageStream Info
Information stream (stdout output on master, null elsewhere)
T * get() noexcept
Return pointer to managed object without nullptr checking.
A cylindrical coordinate system (r-theta-z). The coordinate system angle theta is always in radians.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
virtual bool read(const dictionary &dict)
Read optional controls.
OBJstream os(runTime.globalPath()/outputName)
Macros for easy insertion into run-time selection tables.
Generic dimensioned Type class.
const dimensionSet dimMass(1, 0, 0, 0, 0, 0, 0)
virtual void writeFileHeader(Ostream &os)
Output file header information.
bool useAllCells() const noexcept
Use all cells, not the cellIDs.
errorManipArg< error, int > exit(error &err, const int errNo=1)
word scopedName(const word &name) const
Return a scoped (prefixed) name.
virtual void movePoints(const polyMesh &)
Update for mesh point-motion.
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
void initialise()
Initialise the fields.
addToRunTimeSelectionTable(functionObject, ObukhovLength, dictionary)
virtual void movePoints(const polyMesh &)
Update for mesh point-motion.
void writeValues(Ostream &os)
Write momentum data.
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
const fvMesh & mesh_
Reference to the fvMesh.
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
defineTypeNameAndDebug(ObukhovLength, 0)
Reads fields from the time directories and adds them to the mesh database for further post-processing...
bool checkOut(regIOobject *io) const
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Computes the natural logarithm of an input volScalarField.
Base class for writing single files from the function objects.
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
scalar V() const
Return total volume of the selected region.
const dimensionSet dimless
Dimensionless.