ENH: Created log output for yPlusRAS/LES function objects

This commit is contained in:
andy 2012-03-20 16:14:13 +00:00
parent ce7a93a847
commit b78e8b6e51
4 changed files with 239 additions and 55 deletions

View File

@ -39,12 +39,57 @@ defineTypeNameAndDebug(Foam::yPlusLES, 0);
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::yPlusLES::makeFile()
{
// Create the output file if not already created
if (outputFilePtr_.empty())
{
if (debug)
{
Info<< "Creating output file." << endl;
}
// File update
if (Pstream::master())
{
fileName outputDir;
word startTimeName =
obr_.time().timeName(obr_.time().startTime().value());
if (Pstream::parRun())
{
// Put in undecomposed case (Note: gives problems for
// distributed data running)
outputDir =
obr_.time().path()/".."/name_/startTimeName;
}
else
{
outputDir = obr_.time().path()/name_/startTimeName;
}
// Create directory if does not exist
mkDir(outputDir);
// Open new file at start up
outputFilePtr_.reset(new OFstream(outputDir/(type() + ".dat")));
// Add headers to output data
outputFilePtr_() << "# y+ (LES)" << nl
<< "# time " << token::TAB << "patch" << token::TAB
<< "min" << token::TAB << "max" << token::TAB << "average"
<< endl;
}
}
}
void Foam::yPlusLES::calcIncompressibleYPlus void Foam::yPlusLES::calcIncompressibleYPlus
( (
const fvMesh& mesh, const fvMesh& mesh,
const volVectorField& U, const volVectorField& U,
volScalarField& yPlus volScalarField& yPlus
) const )
{ {
const incompressible::LESModel& model = const incompressible::LESModel& model =
mesh.lookupObject<incompressible::LESModel>("LESProperties"); mesh.lookupObject<incompressible::LESModel>("LESProperties");
@ -56,8 +101,6 @@ void Foam::yPlusLES::calcIncompressibleYPlus
const volScalarField nuLam(model.nu()); const volScalarField nuLam(model.nu());
Info<< type() << " output:" << nl;
bool foundPatch = false; bool foundPatch = false;
forAll(patches, patchI) forAll(patches, patchI)
{ {
@ -77,13 +120,28 @@ void Foam::yPlusLES::calcIncompressibleYPlus
const scalarField& Yp = yPlus.boundaryField()[patchI]; const scalarField& Yp = yPlus.boundaryField()[patchI];
Info<< " patch " << currPatch.name() scalar minYp = min(Yp);
<< " y+ : min = " << min(Yp) << ", max = " << max(Yp) scalar maxYp = max(Yp);
<< ", average = " << average(Yp) << nl; scalar avgYp = average(Yp);
if (log_)
{
Info<< " patch " << currPatch.name()
<< " y+ : min = " << min(Yp) << ", max = " << max(Yp)
<< ", average = " << average(Yp) << nl;
}
if (Pstream::master())
{
outputFilePtr_() << obr_.time().value() << token::TAB
<< currPatch.name() << token::TAB
<< minYp << token::TAB << maxYp << token::TAB
<< avgYp << endl;
}
} }
} }
if (!foundPatch) if (log_ && !foundPatch)
{ {
Info<< " no " << wallFvPatch::typeName << " patches" << endl; Info<< " no " << wallFvPatch::typeName << " patches" << endl;
} }
@ -95,7 +153,7 @@ void Foam::yPlusLES::calcCompressibleYPlus
const fvMesh& mesh, const fvMesh& mesh,
const volVectorField& U, const volVectorField& U,
volScalarField& yPlus volScalarField& yPlus
) const )
{ {
const compressible::LESModel& model = const compressible::LESModel& model =
mesh.lookupObject<compressible::LESModel>("LESProperties"); mesh.lookupObject<compressible::LESModel>("LESProperties");
@ -128,13 +186,28 @@ void Foam::yPlusLES::calcCompressibleYPlus
const scalarField& Yp = yPlus.boundaryField()[patchI]; const scalarField& Yp = yPlus.boundaryField()[patchI];
Info<< " patch " << currPatch.name() scalar minYp = min(Yp);
<< " y+ : min = " << min(Yp) << ", max = " << max(Yp) scalar maxYp = max(Yp);
<< ", average = " << average(Yp) << nl; scalar avgYp = average(Yp);
}
if (log_)
{
Info<< " patch " << currPatch.name()
<< " y+ : min = " << min(Yp) << ", max = " << max(Yp)
<< ", average = " << average(Yp) << nl;
}
if (Pstream::master())
{
outputFilePtr_() << obr_.time().value() << token::TAB
<< currPatch.name() << token::TAB
<< minYp << token::TAB << maxYp << token::TAB
<< avgYp << endl;
}
}
} }
if (!foundPatch) if (log_ && !foundPatch)
{ {
Info<< " no " << wallFvPatch::typeName << " patches" << endl; Info<< " no " << wallFvPatch::typeName << " patches" << endl;
} }
@ -154,8 +227,10 @@ Foam::yPlusLES::yPlusLES
name_(name), name_(name),
obr_(obr), obr_(obr),
active_(true), active_(true),
log_(false),
phiName_("phi"), phiName_("phi"),
UName_("U") UName_("U"),
outputFilePtr_(NULL)
{ {
// Check if the available mesh is an fvMesh, otherwise deactivate // Check if the available mesh is an fvMesh, otherwise deactivate
if (!isA<fvMesh>(obr_)) if (!isA<fvMesh>(obr_))
@ -173,6 +248,8 @@ Foam::yPlusLES::yPlusLES
) << "No fvMesh available, deactivating." << nl ) << "No fvMesh available, deactivating." << nl
<< endl; << endl;
} }
makeFile();
} }
@ -188,6 +265,7 @@ void Foam::yPlusLES::read(const dictionary& dict)
{ {
if (active_) if (active_)
{ {
log_ = dict.lookupOrDefault<Switch>("log", false);
phiName_ = dict.lookupOrDefault<word>("phiName", "phi"); phiName_ = dict.lookupOrDefault<word>("phiName", "phi");
} }
} }
@ -229,6 +307,11 @@ void Foam::yPlusLES::write()
dimensionedScalar("0", dimless, 0.0) dimensionedScalar("0", dimless, 0.0)
); );
if (log_)
{
Info<< type() << " output:" << nl;
}
if (phi.dimensions() == dimMass/dimTime) if (phi.dimensions() == dimMass/dimTime)
{ {
calcCompressibleYPlus(mesh, U, yPlusLES); calcCompressibleYPlus(mesh, U, yPlusLES);
@ -238,7 +321,10 @@ void Foam::yPlusLES::write()
calcIncompressibleYPlus(mesh, U, yPlusLES); calcIncompressibleYPlus(mesh, U, yPlusLES);
} }
Info<< endl; if (log_)
{
Info<< endl;
}
yPlusLES.write(); yPlusLES.write();
} }

View File

@ -39,7 +39,8 @@ SourceFiles
#include "volFieldsFwd.H" #include "volFieldsFwd.H"
#include "pointFieldFwd.H" #include "pointFieldFwd.H"
#include "fvMesh.H" #include "Switch.H"
#include "OFstream.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -50,6 +51,7 @@ namespace Foam
class objectRegistry; class objectRegistry;
class dictionary; class dictionary;
class mapPolyMesh; class mapPolyMesh;
class fvMesh;
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class yPlusLES Declaration Class yPlusLES Declaration
@ -67,22 +69,31 @@ class yPlusLES
//- on/off switch //- on/off switch
bool active_; bool active_;
//- Switch to send output to Info as well as to file
Switch log_;
//- Name of mass/volume flux field (optional, default = phi) //- Name of mass/volume flux field (optional, default = phi)
word phiName_; word phiName_;
//- Name of velocity field //- Name of velocity field
word UName_; word UName_;
//- Output file pointer
autoPtr<OFstream> outputFilePtr_;
// Private Member Functions // Private Member Functions
//- Make the output file
virtual void makeFile();
//- Calculate incompressible form of y+ //- Calculate incompressible form of y+
void calcIncompressibleYPlus void calcIncompressibleYPlus
( (
const fvMesh& mesh, const fvMesh& mesh,
const volVectorField& U, const volVectorField& U,
volScalarField& yPlus volScalarField& yPlus
) const; );
//- Calculate compressible form of y+ //- Calculate compressible form of y+
void calcCompressibleYPlus void calcCompressibleYPlus
@ -90,7 +101,7 @@ class yPlusLES
const fvMesh& mesh, const fvMesh& mesh,
const volVectorField& U, const volVectorField& U,
volScalarField& yPlus volScalarField& yPlus
) const; );
//- Disallow default bitwise copy construct //- Disallow default bitwise copy construct
yPlusLES(const yPlusLES&); yPlusLES(const yPlusLES&);

View File

@ -41,11 +41,56 @@ defineTypeNameAndDebug(Foam::yPlusRAS, 0);
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::yPlusRAS::makeFile()
{
// Create the output file if not already created
if (outputFilePtr_.empty())
{
if (debug)
{
Info<< "Creating output file." << endl;
}
// File update
if (Pstream::master())
{
fileName outputDir;
word startTimeName =
obr_.time().timeName(obr_.time().startTime().value());
if (Pstream::parRun())
{
// Put in undecomposed case (Note: gives problems for
// distributed data running)
outputDir =
obr_.time().path()/".."/name_/startTimeName;
}
else
{
outputDir = obr_.time().path()/name_/startTimeName;
}
// Create directory if does not exist
mkDir(outputDir);
// Open new file at start up
outputFilePtr_.reset(new OFstream(outputDir/(type() + ".dat")));
// Add headers to output data
outputFilePtr_() << "# y+ (RAS)" << nl
<< "# time " << token::TAB << "patch" << token::TAB
<< "min" << token::TAB << "max" << token::TAB << "average"
<< endl;
}
}
}
void Foam::yPlusRAS::calcIncompressibleYPlus void Foam::yPlusRAS::calcIncompressibleYPlus
( (
const fvMesh& mesh, const fvMesh& mesh,
volScalarField& yPlus volScalarField& yPlus
) const )
{ {
typedef incompressible::RASModels::nutkWallFunctionFvPatchScalarField typedef incompressible::RASModels::nutkWallFunctionFvPatchScalarField
wallFunctionPatchField; wallFunctionPatchField;
@ -57,28 +102,41 @@ void Foam::yPlusRAS::calcIncompressibleYPlus
const volScalarField::GeometricBoundaryField& nutPatches = const volScalarField::GeometricBoundaryField& nutPatches =
nut.boundaryField(); nut.boundaryField();
Info<< type() << " output:" << nl;
bool foundPatch = false; bool foundPatch = false;
forAll(nutPatches, patchi) forAll(nutPatches, patchI)
{ {
if (isA<wallFunctionPatchField>(nutPatches[patchi])) if (isA<wallFunctionPatchField>(nutPatches[patchI]))
{ {
foundPatch = true; foundPatch = true;
const wallFunctionPatchField& nutPw = const wallFunctionPatchField& nutPw =
dynamic_cast<const wallFunctionPatchField&>(nutPatches[patchi]); dynamic_cast<const wallFunctionPatchField&>(nutPatches[patchI]);
yPlus.boundaryField()[patchi] = nutPw.yPlus(); yPlus.boundaryField()[patchI] = nutPw.yPlus();
const scalarField& Yp = yPlus.boundaryField()[patchi]; const scalarField& Yp = yPlus.boundaryField()[patchI];
Info<< " patch " << nutPw.patch().name() scalar minYp = min(Yp);
<< " y+ : min = " << min(Yp) << ", max = " << max(Yp) scalar maxYp = max(Yp);
<< ", average = " << average(Yp) << nl; scalar avgYp = average(Yp);
if (log_)
{
Info<< " patch " << nutPw.patch().name()
<< " y+ : min = " << minYp << ", max = " << maxYp
<< ", average = " << avgYp << nl;
}
if (Pstream::master())
{
outputFilePtr_() << obr_.time().value() << token::TAB
<< nutPw.patch().name() << token::TAB
<< minYp << token::TAB << maxYp << token::TAB
<< avgYp << endl;
}
} }
} }
if (!foundPatch) if (log_ && !foundPatch)
{ {
Info<< " no " << wallFunctionPatchField::typeName << " patches" Info<< " no " << wallFunctionPatchField::typeName << " patches"
<< endl; << endl;
@ -90,7 +148,7 @@ void Foam::yPlusRAS::calcCompressibleYPlus
( (
const fvMesh& mesh, const fvMesh& mesh,
volScalarField& yPlus volScalarField& yPlus
) const )
{ {
typedef compressible::RASModels::mutkWallFunctionFvPatchScalarField typedef compressible::RASModels::mutkWallFunctionFvPatchScalarField
wallFunctionPatchField; wallFunctionPatchField;
@ -102,28 +160,41 @@ void Foam::yPlusRAS::calcCompressibleYPlus
const volScalarField::GeometricBoundaryField& mutPatches = const volScalarField::GeometricBoundaryField& mutPatches =
mut.boundaryField(); mut.boundaryField();
Info<< type() << " output:" << nl;
bool foundPatch = false; bool foundPatch = false;
forAll(mutPatches, patchi) forAll(mutPatches, patchI)
{ {
if (isA<wallFunctionPatchField>(mutPatches[patchi])) if (isA<wallFunctionPatchField>(mutPatches[patchI]))
{ {
foundPatch = true; foundPatch = true;
const wallFunctionPatchField& mutPw = const wallFunctionPatchField& mutPw =
dynamic_cast<const wallFunctionPatchField&>(mutPatches[patchi]); dynamic_cast<const wallFunctionPatchField&>(mutPatches[patchI]);
yPlus.boundaryField()[patchi] = mutPw.yPlus(); yPlus.boundaryField()[patchI] = mutPw.yPlus();
const scalarField& Yp = yPlus.boundaryField()[patchi]; const scalarField& Yp = yPlus.boundaryField()[patchI];
Info<< " patch " << mutPw.patch().name() scalar minYp = min(Yp);
<< " y+ : min = " << min(Yp) << ", max = " << max(Yp) scalar maxYp = max(Yp);
<< ", average = " << average(Yp) << nl; scalar avgYp = average(Yp);
if (log_)
{
Info<< " patch " << mutPw.patch().name()
<< " y+ : min = " << minYp << ", max = " << maxYp
<< ", average = " << avgYp << nl;
}
if (Pstream::master())
{
outputFilePtr_() << obr_.time().value() << token::TAB
<< mutPw.patch().name() << token::TAB
<< minYp << token::TAB << maxYp << token::TAB
<< avgYp << endl;
}
} }
} }
if (!foundPatch) if (log_ && !foundPatch)
{ {
Info<< " no " << wallFunctionPatchField::typeName << " patches" Info<< " no " << wallFunctionPatchField::typeName << " patches"
<< endl; << endl;
@ -144,7 +215,9 @@ Foam::yPlusRAS::yPlusRAS
name_(name), name_(name),
obr_(obr), obr_(obr),
active_(true), active_(true),
phiName_("phi") log_(false),
phiName_("phi"),
outputFilePtr_(NULL)
{ {
// Check if the available mesh is an fvMesh, otherwise deactivate // Check if the available mesh is an fvMesh, otherwise deactivate
if (!isA<fvMesh>(obr_)) if (!isA<fvMesh>(obr_))
@ -162,6 +235,8 @@ Foam::yPlusRAS::yPlusRAS
) << "No fvMesh available, deactivating." << nl ) << "No fvMesh available, deactivating." << nl
<< endl; << endl;
} }
makeFile();
} }
@ -177,6 +252,7 @@ void Foam::yPlusRAS::read(const dictionary& dict)
{ {
if (active_) if (active_)
{ {
log_ = dict.lookupOrDefault<Switch>("log", false);
phiName_ = dict.lookupOrDefault<word>("phiName", "phi"); phiName_ = dict.lookupOrDefault<word>("phiName", "phi");
} }
} }
@ -216,6 +292,11 @@ void Foam::yPlusRAS::write()
dimensionedScalar("0", dimless, 0.0) dimensionedScalar("0", dimless, 0.0)
); );
if (log_)
{
Info<< type() << " output:" << nl;
}
if (phi.dimensions() == dimMass/dimTime) if (phi.dimensions() == dimMass/dimTime)
{ {
calcCompressibleYPlus(mesh, yPlusRAS); calcCompressibleYPlus(mesh, yPlusRAS);
@ -225,7 +306,10 @@ void Foam::yPlusRAS::write()
calcIncompressibleYPlus(mesh, yPlusRAS); calcIncompressibleYPlus(mesh, yPlusRAS);
} }
Info<< endl; if (log_)
{
Info<< endl;
}
yPlusRAS.write(); yPlusRAS.write();
} }

View File

@ -39,7 +39,8 @@ SourceFiles
#include "volFieldsFwd.H" #include "volFieldsFwd.H"
#include "pointFieldFwd.H" #include "pointFieldFwd.H"
#include "fvMesh.H" #include "Switch.H"
#include "OFstream.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -50,6 +51,7 @@ namespace Foam
class objectRegistry; class objectRegistry;
class dictionary; class dictionary;
class mapPolyMesh; class mapPolyMesh;
class fvMesh;
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class yPlusRAS Declaration Class yPlusRAS Declaration
@ -67,25 +69,26 @@ class yPlusRAS
//- on/off switch //- on/off switch
bool active_; bool active_;
//- Switch to send output to Info as well as to file
Switch log_;
//- Name of mass/volume flux field (optional, default = phi) //- Name of mass/volume flux field (optional, default = phi)
word phiName_; word phiName_;
//- Output file pointer
autoPtr<OFstream> outputFilePtr_;
// Private Member Functions // Private Member Functions
//- Make the output file
virtual void makeFile();
//- Calculate incompressible form of y+ //- Calculate incompressible form of y+
void calcIncompressibleYPlus void calcIncompressibleYPlus(const fvMesh& mesh, volScalarField& yPlus);
(
const fvMesh& mesh,
volScalarField& yPlus
) const;
//- Calculate compressible form of y+ //- Calculate compressible form of y+
void calcCompressibleYPlus void calcCompressibleYPlus(const fvMesh& mesh, volScalarField& yPlus);
(
const fvMesh& mesh,
volScalarField& yPlus
) const;
//- Disallow default bitwise copy construct //- Disallow default bitwise copy construct
yPlusRAS(const yPlusRAS&); yPlusRAS(const yPlusRAS&);