67 const word& modelType,
90 coeffs_.readEntry(
"max", max_);
91 coeffs_.readIfPresent(
"U", UName_);
94 fieldNames_.resize(1, UName_);
104 if (canWriteHeader())
106 writeFileHeader(file());
116 const scalar maxSqrU =
sqr(max_);
120 label nCellsAbove(0);
125 for (
const label celli : cells_)
127 auto& Uval = Uif[celli];
129 const scalar magSqrUi =
magSqr(Uval);
131 if (magSqrUi > maxSqrU)
133 Uval *=
sqrt(maxSqrU/magSqrUi);
140 label nFacesAbove(0);
147 if (!Up.fixesValue())
150 nTotFaces += Up.size();
152 for (
auto& Uval : Up)
154 const scalar magSqrUi =
magSqr(Uval);
156 if (magSqrUi > maxSqrU)
158 Uval *=
sqrt(maxSqrU/magSqrUi);
167 const auto percent = [](scalar num, label denom) -> scalar
169 return (denom ? 1
e-2*round(1e4*num/denom) : 0);
173 reduce(nCellsAbove, sumOp<label>());
175 const scalar nCellsAbovePercent = percent(nCellsAbove, nTotCells);
178 Info<<
type() <<
' ' << name_ <<
" Limited ";
180 Info<< nCellsAbove <<
" (" 181 << nCellsAbovePercent
184 reduce(nTotFaces, sumOp<label>());
185 reduce(nFacesAbove, sumOp<label>());
186 scalar nFacesAbovePercent(0);
189 nFacesAbovePercent = percent(nFacesAbove, nTotFaces);
191 Info<<
", " << nFacesAbove <<
" (" 192 << nFacesAbovePercent
195 Info<<
", with max limit " << max_ <<
endl;
197 if (nCellsAbove || nFacesAbove)
201 U.correctBoundaryConditions();
205 if (canWriteToFile())
208 << mesh_.time().timeOutputValue() <<
token::TAB 212 << nFacesAbovePercent
Corrects velocity field (i.e. T) within a specified region by applying a given maximum velocity magni...
fvPatchField< vector > fvPatchVectorField
A list of keyword definitions, which are a keyword followed by a number of values (eg...
defineTypeNameAndDebug(atmAmbientTurbSource, 0)
dimensionedSymmTensor sqr(const dimensionedVector &dv)
dimensionedScalar sqrt(const dimensionedScalar &ds)
Ostream & endl(Ostream &os)
Add newline and flush stream.
virtual bool read(const dictionary &dict)
Read source dictionary.
bool writtenHeader_
Flag to identify whether the header has been written.
T returnReduce(const T &value, const BinaryOp &bop, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm)
Perform reduction on a copy, using specified binary operation.
virtual bool read(const dictionary &dict)
Read dictionary.
Macros for easy insertion into run-time selection tables.
bool read(const char *buf, int32_t &val)
Same as readInt32.
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
virtual void writeCommented(Ostream &os, const string &str) const
Write a commented string to stream.
const dimensionedScalar e
Elementary charge.
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.
void writeFileHeader(Ostream &os)
Write file header information.
addToRunTimeSelectionTable(option, atmAmbientTurbSource, dictionary)
void writeHeaderValue(Ostream &os, const string &property, const Type &value) const
Write a (commented) header property and value pair.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
OBJstream os(runTime.globalPath()/outputName)
scalar max_
Maximum velocity magnitude.
Mesh data needed to do the Finite Volume discretisation.
void resetApplied()
Resize/reset applied flag list for all fieldNames_ entries.
messageStream Info
Information stream (stdout output on master, null elsewhere)
Intermediate abstract class for handling cell-set options for the derived fvOptions.
limitVelocity(const word &name, const word &modelType, const dictionary &dict, const fvMesh &mesh)
Construct from components.
bool useSubMesh() const noexcept
True if sub-selection should be used.
virtual void correct(volVectorField &U)
Correct the velocity field.
void reduce(T &value, const BinaryOp &bop, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm)
Reduce inplace (cf. MPI Allreduce) using linear/tree communication schedule.
dimensioned< typename typeOfMag< Type >::type > magSqr(const dimensioned< Type > &dt)
Base abstract class for handling finite volume options (i.e. fvOption).
virtual void writeTabbed(Ostream &os, const string &str) const
Write a tabbed string to stream.