ENH: Refactored function objects to make use of new base class

This commit is contained in:
andy
2012-10-15 17:59:38 +01:00
parent d8321469e9
commit 72d49281ce
27 changed files with 225 additions and 612 deletions

View File

@ -35,49 +35,13 @@ License
defineTypeNameAndDebug(Foam::DESModelRegions, 0);
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
// * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * //
void Foam::DESModelRegions::makeFile()
void Foam::DESModelRegions::writeFileHeader(const label i)
{
// 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_() << "# DES model region coverage (% volume)" << nl
<< "# time " << token::TAB << "LES" << token::TAB << "RAS"
<< endl;
}
}
file() << "# DES model region coverage (% volume)" << nl
<< "# time " << token::TAB << "LES" << token::TAB << "RAS"
<< endl;
}
@ -91,11 +55,11 @@ Foam::DESModelRegions::DESModelRegions
const bool loadFromFiles
)
:
functionObjectFile(obr, name, typeName),
name_(name),
obr_(obr),
active_(true),
log_(false),
outputFilePtr_(NULL)
log_(false)
{
// Check if the available mesh is an fvMesh, otherwise deactivate
if (!isA<fvMesh>(obr_))
@ -114,8 +78,6 @@ Foam::DESModelRegions::DESModelRegions
<< endl;
}
makeFile();
read(dict);
}
@ -159,6 +121,8 @@ void Foam::DESModelRegions::write()
if (active_)
{
functionObjectFile::write();
const fvMesh& mesh = refCast<const fvMesh>(obr_);
if (log_)
@ -203,7 +167,7 @@ void Foam::DESModelRegions::write()
if (Pstream::master())
{
outputFilePtr_() << obr_.time().timeName() << token::TAB
file() << obr_.time().timeName() << token::TAB
<< prc << token::TAB << 100.0 - prc << endl;
}

View File

@ -43,6 +43,7 @@ SourceFiles
#ifndef DESModelRegions_H
#define DESModelRegions_H
#include "functionObjectFile.H"
#include "volFieldsFwd.H"
#include "pointFieldFwd.H"
#include "Switch.H"
@ -64,8 +65,12 @@ class fvMesh;
\*---------------------------------------------------------------------------*/
class DESModelRegions
:
public functionObjectFile
{
// Private data
protected:
// Protected data
//- Name of this set of DESModelRegions object
word name_;
@ -78,14 +83,11 @@ class DESModelRegions
//- Switch to send output to Info as well as to file
Switch log_;
//- Output file pointer
autoPtr<OFstream> outputFilePtr_;
// Protected Member Functions
// Private Member Functions
//- Make the output file
virtual void makeFile();
//- File header information
virtual void writeFileHeader(const label i);
//- Disallow default bitwise copy construct
DESModelRegions(const DESModelRegions&);

View File

@ -35,49 +35,14 @@ License
defineTypeNameAndDebug(Foam::wallShearStress, 0);
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
// * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * //
void Foam::wallShearStress::makeFile()
void Foam::wallShearStress::writeFileHeader(const label i)
{
// 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_() << "# Wall shear stress" << nl
<< "# time " << token::TAB << "patch" << token::TAB
<< "min" << token::TAB << "max" << endl;
}
}
// Add headers to output data
file() << "# Wall shear stress" << nl
<< "# time " << token::TAB << "patch" << token::TAB
<< "min" << token::TAB << "max" << endl;
}
@ -104,7 +69,7 @@ void Foam::wallShearStress::calcShearStress
vector minSsp = min(ssp);
vector maxSsp = max(ssp);
outputFilePtr_() << mesh.time().timeName() << token::TAB
file() << mesh.time().timeName() << token::TAB
<< pp.name() << token::TAB << minSsp
<< token::TAB << maxSsp << endl;
@ -128,12 +93,12 @@ Foam::wallShearStress::wallShearStress
const bool loadFromFiles
)
:
functionObjectFile(obr, name, typeName),
name_(name),
obr_(obr),
active_(true),
log_(false),
phiName_("phi"),
outputFilePtr_(NULL)
phiName_("phi")
{
// Check if the available mesh is an fvMesh, otherwise deactivate
if (!isA<fvMesh>(obr_))
@ -152,8 +117,6 @@ Foam::wallShearStress::wallShearStress
<< endl;
}
makeFile();
read(dict);
}
@ -195,6 +158,8 @@ void Foam::wallShearStress::write()
if (active_)
{
functionObjectFile::write();
const fvMesh& mesh = refCast<const fvMesh>(obr_);
volVectorField wallShearStress

View File

@ -54,6 +54,7 @@ SourceFiles
#ifndef wallShearStress_H
#define wallShearStress_H
#include "functionObjectFile.H"
#include "volFieldsFwd.H"
#include "pointFieldFwd.H"
#include "Switch.H"
@ -75,8 +76,12 @@ class fvMesh;
\*---------------------------------------------------------------------------*/
class wallShearStress
:
public functionObjectFile
{
// Private data
protected:
// Protected data
//- Name of this set of wallShearStress object
word name_;
@ -92,14 +97,11 @@ class wallShearStress
//- Name of mass/volume flux field (optional, default = phi)
word phiName_;
//- Output file pointer
autoPtr<OFstream> outputFilePtr_;
// Protected Member Functions
// Private Member Functions
//- Make the output file
virtual void makeFile();
//- File header information
virtual void writeFileHeader(const label i);
//- Calculate the shear stress
void calcShearStress

View File

@ -39,48 +39,12 @@ defineTypeNameAndDebug(Foam::yPlusLES, 0);
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::yPlusLES::makeFile()
void Foam::yPlusLES::writeFileHeader(const label i)
{
// 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;
}
}
file() << "# y+ (LES)" << nl
<< "# time " << token::TAB << "patch" << token::TAB
<< "min" << token::TAB << "max" << token::TAB << "average"
<< endl;
}
@ -133,7 +97,7 @@ void Foam::yPlusLES::calcIncompressibleYPlus
if (Pstream::master())
{
outputFilePtr_() << obr_.time().value() << token::TAB
file() << obr_.time().value() << token::TAB
<< currPatch.name() << token::TAB
<< minYp << token::TAB << maxYp << token::TAB
<< avgYp << endl;
@ -199,7 +163,7 @@ void Foam::yPlusLES::calcCompressibleYPlus
if (Pstream::master())
{
outputFilePtr_() << obr_.time().value() << token::TAB
file() << obr_.time().value() << token::TAB
<< currPatch.name() << token::TAB
<< minYp << token::TAB << maxYp << token::TAB
<< avgYp << endl;
@ -224,13 +188,13 @@ Foam::yPlusLES::yPlusLES
const bool loadFromFiles
)
:
functionObjectFile(obr, name, typeName),
name_(name),
obr_(obr),
active_(true),
log_(false),
phiName_("phi"),
UName_("U"),
outputFilePtr_(NULL)
UName_("U")
{
// Check if the available mesh is an fvMesh, otherwise deactivate
if (!isA<fvMesh>(obr_))
@ -248,8 +212,6 @@ Foam::yPlusLES::yPlusLES
) << "No fvMesh available, deactivating." << nl
<< endl;
}
makeFile();
}
@ -287,6 +249,8 @@ void Foam::yPlusLES::write()
{
if (active_)
{
functionObjectFile::write();
const surfaceScalarField& phi =
obr_.lookupObject<surfaceScalarField>(phiName_);

View File

@ -40,6 +40,7 @@ SourceFiles
#ifndef yPlusLES_H
#define yPlusLES_H
#include "functionObjectFile.H"
#include "volFieldsFwd.H"
#include "pointFieldFwd.H"
#include "Switch.H"
@ -61,6 +62,8 @@ class fvMesh;
\*---------------------------------------------------------------------------*/
class yPlusLES
:
public functionObjectFile
{
// Private data
@ -81,14 +84,11 @@ class yPlusLES
//- Name of velocity field
word UName_;
//- Output file pointer
autoPtr<OFstream> outputFilePtr_;
// Private Member Functions
//- Make the output file
virtual void makeFile();
//- File header information
virtual void writeFileHeader(const label i);
//- Calculate incompressible form of y+
void calcIncompressibleYPlus

View File

@ -41,48 +41,12 @@ defineTypeNameAndDebug(Foam::yPlusRAS, 0);
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::yPlusRAS::makeFile()
void Foam::yPlusRAS::writeFileHeader(const label i)
{
// 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;
}
}
file() << "# y+ (RAS)" << nl
<< "# time " << token::TAB << "patch" << token::TAB
<< "min" << token::TAB << "max" << token::TAB << "average"
<< endl;
}
@ -128,7 +92,7 @@ void Foam::yPlusRAS::calcIncompressibleYPlus
if (Pstream::master())
{
outputFilePtr_() << obr_.time().value() << token::TAB
file() << obr_.time().value() << token::TAB
<< nutPw.patch().name() << token::TAB
<< minYp << token::TAB << maxYp << token::TAB
<< avgYp << endl;
@ -186,7 +150,7 @@ void Foam::yPlusRAS::calcCompressibleYPlus
if (Pstream::master())
{
outputFilePtr_() << obr_.time().value() << token::TAB
file() << obr_.time().value() << token::TAB
<< mutPw.patch().name() << token::TAB
<< minYp << token::TAB << maxYp << token::TAB
<< avgYp << endl;
@ -212,12 +176,12 @@ Foam::yPlusRAS::yPlusRAS
const bool loadFromFiles
)
:
functionObjectFile(obr, name, typeName),
name_(name),
obr_(obr),
active_(true),
log_(false),
phiName_("phi"),
outputFilePtr_(NULL)
phiName_("phi")
{
// Check if the available mesh is an fvMesh, otherwise deactivate
if (!isA<fvMesh>(obr_))
@ -235,8 +199,6 @@ Foam::yPlusRAS::yPlusRAS
) << "No fvMesh available, deactivating." << nl
<< endl;
}
makeFile();
}
@ -274,6 +236,8 @@ void Foam::yPlusRAS::write()
{
if (active_)
{
functionObjectFile::write();
const surfaceScalarField& phi =
obr_.lookupObject<surfaceScalarField>(phiName_);

View File

@ -40,6 +40,7 @@ SourceFiles
#ifndef yPlusRAS_H
#define yPlusRAS_H
#include "functionObjectFile.H"
#include "volFieldsFwd.H"
#include "pointFieldFwd.H"
#include "Switch.H"
@ -61,6 +62,8 @@ class fvMesh;
\*---------------------------------------------------------------------------*/
class yPlusRAS
:
public functionObjectFile
{
// Private data
@ -78,14 +81,11 @@ class yPlusRAS
//- Name of mass/volume flux field (optional, default = phi)
word phiName_;
//- Output file pointer
autoPtr<OFstream> outputFilePtr_;
// Private Member Functions
//- Make the output file
virtual void makeFile();
//- File header information
virtual void writeFileHeader(const label i);
//- Calculate incompressible form of y+
void calcIncompressibleYPlus(const fvMesh& mesh, volScalarField& yPlus);