mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: Updated forces and forceCoeffs so that p and U fields need not exist on construction
This commit is contained in:
@ -156,10 +156,13 @@ void Foam::forceCoeffs::timeSet()
|
||||
|
||||
void Foam::forceCoeffs::write()
|
||||
{
|
||||
if (active_)
|
||||
{
|
||||
forces::calcForcesMoment();
|
||||
|
||||
if (!active_)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (Pstream::master())
|
||||
{
|
||||
functionObjectFile::write();
|
||||
@ -231,7 +234,6 @@ void Foam::forceCoeffs::write()
|
||||
Info<< endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -130,6 +130,55 @@ void Foam::forces::writeFileHeader(const label i)
|
||||
}
|
||||
|
||||
|
||||
void Foam::forces::initialise()
|
||||
{
|
||||
if (initialised_ || !active_)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (directForceDensity_)
|
||||
{
|
||||
if (!obr_.foundObject<volVectorField>(fDName_))
|
||||
{
|
||||
active_ = false;
|
||||
WarningIn("void Foam::forces::initialise()")
|
||||
<< "Could not find " << fDName_ << " in database." << nl
|
||||
<< " De-activating forces."
|
||||
<< endl;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if
|
||||
(
|
||||
!obr_.foundObject<volVectorField>(UName_)
|
||||
|| !obr_.foundObject<volScalarField>(pName_)
|
||||
|| (
|
||||
rhoName_ != "rhoInf"
|
||||
&& !obr_.foundObject<volScalarField>(rhoName_)
|
||||
)
|
||||
)
|
||||
{
|
||||
active_ = false;
|
||||
|
||||
WarningIn("void Foam::forces::initialise()")
|
||||
<< "Could not find " << UName_ << ", " << pName_;
|
||||
|
||||
if (rhoName_ != "rhoInf")
|
||||
{
|
||||
Info<< " or " << rhoName_;
|
||||
}
|
||||
|
||||
Info<< " in database." << nl
|
||||
<< " De-activating forces." << endl;
|
||||
}
|
||||
}
|
||||
|
||||
initialised_ = true;
|
||||
}
|
||||
|
||||
|
||||
Foam::tmp<Foam::volSymmTensorField> Foam::forces::devRhoReff() const
|
||||
{
|
||||
typedef compressible::turbulenceModel cmpTurbModel;
|
||||
@ -474,7 +523,8 @@ Foam::forces::forces
|
||||
binMin_(GREAT),
|
||||
binPoints_(),
|
||||
binFormat_("undefined"),
|
||||
binCumulative_(true)
|
||||
binCumulative_(true),
|
||||
initialised_(false)
|
||||
{
|
||||
// Check if the available mesh is an fvMesh otherise deactivate
|
||||
if (!isA<fvMesh>(obr_))
|
||||
@ -534,7 +584,8 @@ Foam::forces::forces
|
||||
binMin_(GREAT),
|
||||
binPoints_(),
|
||||
binFormat_("undefined"),
|
||||
binCumulative_(true)
|
||||
binCumulative_(true),
|
||||
initialised_(false)
|
||||
{
|
||||
forAll(force_, i)
|
||||
{
|
||||
@ -556,6 +607,8 @@ void Foam::forces::read(const dictionary& dict)
|
||||
{
|
||||
if (active_)
|
||||
{
|
||||
initialised_ = false;
|
||||
|
||||
log_ = dict.lookupOrDefault<Switch>("log", false);
|
||||
directForceDensity_ = dict.lookupOrDefault("directForceDensity", false);
|
||||
|
||||
@ -568,19 +621,6 @@ void Foam::forces::read(const dictionary& dict)
|
||||
{
|
||||
// Optional entry for fDName
|
||||
fDName_ = dict.lookupOrDefault<word>("fDName", "fD");
|
||||
|
||||
// Check whether fDName exists, if not deactivate forces
|
||||
if
|
||||
(
|
||||
!obr_.foundObject<volVectorField>(fDName_)
|
||||
)
|
||||
{
|
||||
active_ = false;
|
||||
WarningIn("void forces::read(const dictionary&)")
|
||||
<< "Could not find " << fDName_ << " in database." << nl
|
||||
<< " De-activating forces."
|
||||
<< endl;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -589,32 +629,6 @@ void Foam::forces::read(const dictionary& dict)
|
||||
UName_ = dict.lookupOrDefault<word>("UName", "U");
|
||||
rhoName_ = dict.lookupOrDefault<word>("rhoName", "rho");
|
||||
|
||||
// Check whether UName, pName and rhoName exists,
|
||||
// if not deactivate forces
|
||||
if
|
||||
(
|
||||
!obr_.foundObject<volVectorField>(UName_)
|
||||
|| !obr_.foundObject<volScalarField>(pName_)
|
||||
|| (
|
||||
rhoName_ != "rhoInf"
|
||||
&& !obr_.foundObject<volScalarField>(rhoName_)
|
||||
)
|
||||
)
|
||||
{
|
||||
active_ = false;
|
||||
|
||||
WarningIn("void forces::read(const dictionary&)")
|
||||
<< "Could not find " << UName_ << ", " << pName_;
|
||||
|
||||
if (rhoName_ != "rhoInf")
|
||||
{
|
||||
Info<< " or " << rhoName_;
|
||||
}
|
||||
|
||||
Info<< " in database." << nl
|
||||
<< " De-activating forces." << endl;
|
||||
}
|
||||
|
||||
// Reference density needed for incompressible calculations
|
||||
rhoRef_ = readScalar(dict.lookup("rhoInf"));
|
||||
|
||||
@ -745,13 +759,13 @@ void Foam::forces::timeSet()
|
||||
|
||||
void Foam::forces::write()
|
||||
{
|
||||
calcForcesMoment();
|
||||
|
||||
if (!active_)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
calcForcesMoment();
|
||||
|
||||
if (Pstream::master())
|
||||
{
|
||||
functionObjectFile::write();
|
||||
@ -770,6 +784,13 @@ void Foam::forces::write()
|
||||
|
||||
void Foam::forces::calcForcesMoment()
|
||||
{
|
||||
initialise();
|
||||
|
||||
if (!active_)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
force_[0] = vector::zero;
|
||||
force_[1] = vector::zero;
|
||||
force_[2] = vector::zero;
|
||||
|
||||
@ -32,7 +32,8 @@ Description
|
||||
pressure and skin-friction forces over a given list of patches.
|
||||
|
||||
Member function forces::write() calculates the forces/moments and
|
||||
writes the forces/moments into the file \<timeDir\>/forces.dat
|
||||
writes the forces/moments into the file \<timeDir\>/forces.dat and bin
|
||||
data (if selected) to the file \<timeDir\>/forces_bin.dat
|
||||
|
||||
Example of function object specification:
|
||||
\verbatim
|
||||
@ -45,7 +46,6 @@ Description
|
||||
patches (walls);
|
||||
nBin 20;
|
||||
binDir (1 0 0);
|
||||
binFormat gnuplot;
|
||||
}
|
||||
\endverbatim
|
||||
|
||||
@ -57,7 +57,6 @@ Description
|
||||
patches | patches included in the forces calculation | yes |
|
||||
nBin | number of data bins | no |
|
||||
binDir | direction along which bins are defined | no |
|
||||
binFormat | output format for bin data | no |
|
||||
pName | pressure field name | no | p
|
||||
UName | velocity field name | no | U
|
||||
rhoName | density field name (see below) | no | rho
|
||||
@ -216,6 +215,10 @@ protected:
|
||||
bool binCumulative_;
|
||||
|
||||
|
||||
//- Initialised flag
|
||||
bool initialised_;
|
||||
|
||||
|
||||
// Protected Member Functions
|
||||
|
||||
//- Create file names for forces and bins
|
||||
@ -224,6 +227,9 @@ protected:
|
||||
//- Output file header information
|
||||
virtual void writeFileHeader(const label i);
|
||||
|
||||
//- Initialise the fields
|
||||
void initialise();
|
||||
|
||||
//- Return the effective viscous stress (laminar + turbulent).
|
||||
tmp<volSymmTensorField> devRhoReff() const;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user