ENH: Updated forces and forceCoeffs so that p and U fields need not exist on construction

This commit is contained in:
andy
2013-07-26 16:08:05 +01:00
parent d1b98c0d23
commit 2952c7c150
3 changed files with 138 additions and 109 deletions

View File

@ -155,11 +155,14 @@ void Foam::forceCoeffs::timeSet()
void Foam::forceCoeffs::write() void Foam::forceCoeffs::write()
{
if (active_)
{ {
forces::calcForcesMoment(); forces::calcForcesMoment();
if (!active_)
{
return;
}
if (Pstream::master()) if (Pstream::master())
{ {
functionObjectFile::write(); functionObjectFile::write();
@ -232,7 +235,6 @@ void Foam::forceCoeffs::write()
} }
} }
} }
}
// ************************************************************************* // // ************************************************************************* //

View File

@ -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 Foam::tmp<Foam::volSymmTensorField> Foam::forces::devRhoReff() const
{ {
typedef compressible::turbulenceModel cmpTurbModel; typedef compressible::turbulenceModel cmpTurbModel;
@ -474,7 +523,8 @@ Foam::forces::forces
binMin_(GREAT), binMin_(GREAT),
binPoints_(), binPoints_(),
binFormat_("undefined"), binFormat_("undefined"),
binCumulative_(true) binCumulative_(true),
initialised_(false)
{ {
// Check if the available mesh is an fvMesh otherise deactivate // Check if the available mesh is an fvMesh otherise deactivate
if (!isA<fvMesh>(obr_)) if (!isA<fvMesh>(obr_))
@ -534,7 +584,8 @@ Foam::forces::forces
binMin_(GREAT), binMin_(GREAT),
binPoints_(), binPoints_(),
binFormat_("undefined"), binFormat_("undefined"),
binCumulative_(true) binCumulative_(true),
initialised_(false)
{ {
forAll(force_, i) forAll(force_, i)
{ {
@ -556,6 +607,8 @@ void Foam::forces::read(const dictionary& dict)
{ {
if (active_) if (active_)
{ {
initialised_ = false;
log_ = dict.lookupOrDefault<Switch>("log", false); log_ = dict.lookupOrDefault<Switch>("log", false);
directForceDensity_ = dict.lookupOrDefault("directForceDensity", false); directForceDensity_ = dict.lookupOrDefault("directForceDensity", false);
@ -568,19 +621,6 @@ void Foam::forces::read(const dictionary& dict)
{ {
// Optional entry for fDName // Optional entry for fDName
fDName_ = dict.lookupOrDefault<word>("fDName", "fD"); 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 else
{ {
@ -589,32 +629,6 @@ void Foam::forces::read(const dictionary& dict)
UName_ = dict.lookupOrDefault<word>("UName", "U"); UName_ = dict.lookupOrDefault<word>("UName", "U");
rhoName_ = dict.lookupOrDefault<word>("rhoName", "rho"); 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 // Reference density needed for incompressible calculations
rhoRef_ = readScalar(dict.lookup("rhoInf")); rhoRef_ = readScalar(dict.lookup("rhoInf"));
@ -745,13 +759,13 @@ void Foam::forces::timeSet()
void Foam::forces::write() void Foam::forces::write()
{ {
calcForcesMoment();
if (!active_) if (!active_)
{ {
return; return;
} }
calcForcesMoment();
if (Pstream::master()) if (Pstream::master())
{ {
functionObjectFile::write(); functionObjectFile::write();
@ -770,6 +784,13 @@ void Foam::forces::write()
void Foam::forces::calcForcesMoment() void Foam::forces::calcForcesMoment()
{ {
initialise();
if (!active_)
{
return;
}
force_[0] = vector::zero; force_[0] = vector::zero;
force_[1] = vector::zero; force_[1] = vector::zero;
force_[2] = vector::zero; force_[2] = vector::zero;

View File

@ -32,7 +32,8 @@ Description
pressure and skin-friction forces over a given list of patches. pressure and skin-friction forces over a given list of patches.
Member function forces::write() calculates the forces/moments and 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: Example of function object specification:
\verbatim \verbatim
@ -45,7 +46,6 @@ Description
patches (walls); patches (walls);
nBin 20; nBin 20;
binDir (1 0 0); binDir (1 0 0);
binFormat gnuplot;
} }
\endverbatim \endverbatim
@ -57,7 +57,6 @@ Description
patches | patches included in the forces calculation | yes | patches | patches included in the forces calculation | yes |
nBin | number of data bins | no | nBin | number of data bins | no |
binDir | direction along which bins are defined | no | binDir | direction along which bins are defined | no |
binFormat | output format for bin data | no |
pName | pressure field name | no | p pName | pressure field name | no | p
UName | velocity field name | no | U UName | velocity field name | no | U
rhoName | density field name (see below) | no | rho rhoName | density field name (see below) | no | rho
@ -216,6 +215,10 @@ protected:
bool binCumulative_; bool binCumulative_;
//- Initialised flag
bool initialised_;
// Protected Member Functions // Protected Member Functions
//- Create file names for forces and bins //- Create file names for forces and bins
@ -224,6 +227,9 @@ protected:
//- Output file header information //- Output file header information
virtual void writeFileHeader(const label i); virtual void writeFileHeader(const label i);
//- Initialise the fields
void initialise();
//- Return the effective viscous stress (laminar + turbulent). //- Return the effective viscous stress (laminar + turbulent).
tmp<volSymmTensorField> devRhoReff() const; tmp<volSymmTensorField> devRhoReff() const;