40 namespace functionObjects
50 void Foam::functionObjects::momentum::purgeFields()
58 template<
class GeoField>
60 Foam::functionObjects::momentum::newField
85 void Foam::functionObjects::momentum::calc()
98 autoPtr<volVectorField> tmomentum, tAngularMom, tAngularVel;
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];
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_;
357 volRegion(fvMeshFunctionObject::mesh_,
dict),
358 writeFile(mesh_,
name, typeName,
dict),
360 sumAngularMom_(
Zero),
367 writeMomentum_(false),
368 writeVelocity_(false),
369 writePosition_(false),
388 fvMeshFunctionObject(
name, obr,
dict),
389 volRegion(fvMeshFunctionObject::mesh_,
dict),
390 writeFile(mesh_,
name, typeName,
dict),
392 sumAngularMom_(
Zero),
399 writeMomentum_(false),
400 writeVelocity_(false),
401 writePosition_(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)
556 const polyBoundaryMesh&
pbm = mesh_.boundaryMesh();
560 if (isA<emptyPolyPatch>(
pbm[patchi]))
565 const auto&
pts =
pbm[patchi].faceCentres();
566 const label len =
pts.size();
568 UList<scalar>& r = cyl_r->boundaryFieldRef(
false)[patchi];
569 UList<scalar>& t = cyl_t->boundaryFieldRef(
false)[patchi];
570 UList<scalar>& z = cyl_z->boundaryFieldRef(
false)[patchi];
572 for (label i=0; i < len; ++i)
const polyBoundaryMesh & pbm
defineTypeNameAndDebug(ObukhovLength, 0)
static bool initialised_(false)
static void writeHeader(Ostream &os, const word &fieldName)
dimensionedScalar log(const dimensionedScalar &ds)
A cylindrical coordinate system (r-theta-z). The coordinate system angle theta is always in radians...
errorManipArg< error, int > exit(error &err, const int errNo=1)
momentum(const word &name, const Time &runTime, const dictionary &dict, const bool readFields=true)
Construct from Time and dictionary.
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
A list of keyword definitions, which are a keyword followed by a number of values (eg...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
virtual bool read(const dictionary &dict)
Read from dictionary.
virtual void movePoints(const polyMesh &)
Update for mesh point-motion.
constexpr char nl
The newline '\n' character (0x0a)
Ostream & endl(Ostream &os)
Add newline and flush stream.
virtual bool execute()
Calculate and report the integral momentum.
constexpr char tab
The tab '\t' character(0x09)
virtual void updateMesh(const mapPolyMesh &)
Update for changes of mesh.
bool checkOut(regIOobject *io) const
Remove a regIOobject from registry and free memory if the object is ownedByRegistry. A nullptr is ignored.
Generic dimensioned Type class.
Ignore writing from objectRegistry::writeObject()
const dimensionSet dimless
Dimensionless.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
bool useAllCells() const noexcept
Use all cells, not the cellIDs.
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Macros for easy insertion into run-time selection tables.
#define forAll(list, i)
Loop across all elements in list.
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Dimension set for the base types, which can be used to implement rigorous dimension checking for alge...
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
void readFields(const typename GeoFieldType::Mesh &mesh, const IOobjectList &objects, const NameMatchPredicate &selectedFields, DynamicList< regIOobject *> &storedObjects)
Read the selected GeometricFields of the templated type and store on the objectRegistry.
A class for handling words, derived from Foam::string.
void writeValues(Ostream &os)
Write momentum data.
virtual bool write(const bool writeOnProc=true) const
Write using setting from DB.
const dimensionSet dimPressure
void initialise()
Initialise the fields.
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
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.
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
OBJstream os(runTime.globalPath()/outputName)
addToRunTimeSelectionTable(functionObject, ObukhovLength, dictionary)
virtual bool read(const dictionary &dict)
Read.
const dimensionSet dimDensity
vector point
Point is a vector.
Info<< "Reading mechanical properties\"<< 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
const dimensionSet dimLength(0, 1, 0, 0, 0, 0, 0)
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
bool update()
Update the cached values as required.
static bool master(const label communicator=worldComm)
True if process corresponds to the master rank in the communicator.
const objectRegistry & obr_
Reference to the region objectRegistry.
virtual bool write()
Write the momentum, possibly angular momentum and velocity.
void reduce(const List< UPstream::commsStruct > &comms, T &value, const BinaryOp &bop, const int tag, const label comm)
Reduce inplace (cf. MPI Allreduce) using specified communication schedule.
messageStream Info
Information stream (stdout output on master, null elsewhere)
virtual bool read(const dictionary &dict)
Read optional controls.
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
virtual void updateMesh(const mapPolyMesh &)
Update for changes of mesh.
Mesh consisting of general polyhedral cells.
virtual bool read(const dictionary &)
Read the momentum data.
const dimensionSet dimMass(1, 0, 0, 0, 0, 0, 0)
virtual void writeFileHeader(Ostream &os)
Output file header information.
Registry of regIOobjects.
static autoPtr< T > New(Args &&... args)
Construct autoPtr with forwarding arguments.
Defines the attributes of an object for which implicit objectRegistry management is supported...
word scopedName(const word &name) const
Return a scoped (prefixed) name.
virtual void movePoints(const polyMesh &)
Update for mesh point-motion.
static constexpr const zero Zero
Global zero (0)
const dimensionSet dimVelocity