40namespace functionObjects
50void Foam::functionObjects::momentum::purgeFields()
58template<
class GeoField>
85void 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]));
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
Defines the attributes of an object for which implicit objectRegistry management is supported,...
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
virtual bool read()
Re-read model coefficients if they have changed.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
static autoPtr< Time > New()
Construct (dummy) Time - no functionObjects or libraries.
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
const complexVectorField & newField()
label size() const noexcept
The number of elements in the list.
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
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,...
Dimension set for the base types, which can be used to implement rigorous dimension checking for alge...
Generic dimensioned Type class.
Abstract base-class for Time/database function objects.
word scopedName(const word &name) const
Return a scoped (prefixed) name.
Specialization of Foam::functionObject for an Foam::fvMesh, providing a reference to the Foam::fvMesh...
Computes the natural logarithm of an input volScalarField.
Computes linear/angular momentum, reporting integral values and optionally writing the fields.
void initialise()
Initialise the fields.
void writeValues(Ostream &os)
Write momentum data.
virtual void writeFileHeader(Ostream &os)
Output file header information.
virtual bool execute()
Calculate and report the integral momentum.
virtual bool write()
Write the momentum, possibly angular momentum and velocity.
virtual bool read(const dictionary &)
Read the momentum data.
Reads fields from the time directories and adds them to the mesh database for further post-processing...
const objectRegistry & obr_
Reference to the region objectRegistry.
Volume (cell) region selection class.
bool useAllCells() const noexcept
Use all cells, not the cellIDs.
scalar V() const
Return total volume of the selected region.
bool update()
Update the cached values as required.
Base class for writing single files from the function objects.
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
void movePoints()
Update for new mesh geometry.
void updateMesh()
Update for new mesh topology.
Registry of regIOobjects.
bool checkOut(regIOobject *io) const
A polyBoundaryMesh is a polyPatch list with additional search methods and registered IO.
Mesh consisting of general polyhedral cells.
virtual bool write(const bool valid=true) const
Write using setting from DB.
splitCell * master() const
A class for handling words, derived from Foam::string.
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
OBJstream os(runTime.globalPath()/outputName)
const dimensionSet dimPressure
const dimensionSet dimless
Dimensionless.
const dimensionSet dimLength(0, 1, 0, 0, 0, 0, 0)
static void writeHeader(Ostream &os, const word &fieldName)
const dimensionSet dimVelocity
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.
Ostream & endl(Ostream &os)
Add newline and flush stream.
void reduce(const List< UPstream::commsStruct > &comms, T &value, const BinaryOp &bop, const int tag, const label comm)
static constexpr const zero Zero
Global zero (0)
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
const dimensionSet dimDensity
errorManipArg< error, int > exit(error &err, const int errNo=1)
const dimensionSet dimMass(1, 0, 0, 0, 0, 0, 0)
constexpr char nl
The newline '\n' character (0x0a)
constexpr char tab
The tab '\t' character(0x09)
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
#define forAll(list, i)
Loop across all elements in list.