messageStream: Added 'Log' macro which outputs to 'Info' if 'log' is true

regionFunctionObject: moved 'log_' to public 'log' to support the 'Log' macro
This commit is contained in:
Henry Weller
2016-05-25 18:19:46 +01:00
parent 82ca430a02
commit ee462f8241
23 changed files with 80 additions and 89 deletions

View File

@ -313,6 +313,11 @@ extern messageStream Info;
<< #var " " << var << ::Foam::endl
//- Report write to Foam::Info if the local log switch is true
#define Log \
if (log) Info
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif

View File

@ -49,7 +49,7 @@ bool Foam::functionObjects::regionFunctionObject::writeObject
{
const regIOobject& field = obr_.lookupObject<regIOobject>(fieldName);
if (log_)
if (log)
{
Info<< "functionObjects::" << type() << " " << name()
<< " writing field: " << field.name() << endl;
@ -109,7 +109,7 @@ Foam::functionObjects::regionFunctionObject::regionFunctionObject
dict.lookupOrDefault("region", polyMesh::defaultRegion)
)
),
log_(true)
log(true)
{}
@ -123,7 +123,7 @@ Foam::functionObjects::regionFunctionObject::regionFunctionObject
functionObject(name),
time_(obr.time()),
obr_(obr),
log_(true)
log(true)
{}
@ -137,7 +137,7 @@ Foam::functionObjects::regionFunctionObject::~regionFunctionObject()
bool Foam::functionObjects::regionFunctionObject::read(const dictionary& dict)
{
log_ = dict.lookupOrDefault<Switch>("log", true);
log = dict.lookupOrDefault<Switch>("log", true);
return true;
}

View File

@ -72,9 +72,6 @@ protected:
//- Reference to the region objectRegistry
const objectRegistry& obr_;
//- Switch to send output to Info as well as to file
Switch log_;
// Protected member functions
@ -118,6 +115,9 @@ public:
//- Runtime type information
TypeName("regionFunctionObject");
//- Switch write log to Info
Switch log;
// Constructors

View File

@ -95,7 +95,7 @@ void Foam::functionObjects::fieldAverage::initialize()
void Foam::functionObjects::fieldAverage::restart()
{
if (log_) Info
Log
<< " Restarting averaging at time " << obr_.time().timeName()
<< nl << endl;
@ -134,7 +134,7 @@ void Foam::functionObjects::fieldAverage::calcAverages()
periodIndex_++;
}
if (log_) Info
Log
<< type() << " " << name() << " output:" << nl
<< " Calculating averages" << nl;
@ -156,13 +156,13 @@ void Foam::functionObjects::fieldAverage::calcAverages()
totalTime_[fieldi] += obr_.time().deltaTValue();
}
if (log_) Info<< endl;
Log << endl;
}
void Foam::functionObjects::fieldAverage::writeAverages() const
{
if (log_) Info<< " Writing average fields" << endl;
Log << " Writing average fields" << endl;
writeFields<scalar>();
writeFields<vector>();
@ -170,7 +170,7 @@ void Foam::functionObjects::fieldAverage::writeAverages() const
writeFields<symmTensor>();
writeFields<tensor>();
if (log_) Info<< endl;
Log << endl;
}
@ -200,7 +200,7 @@ void Foam::functionObjects::fieldAverage::writeAveragingProperties() const
propsDict.regIOobject::write();
if (log_) Info<< endl;
Log << endl;
}
@ -212,7 +212,7 @@ void Foam::functionObjects::fieldAverage::readAveragingProperties()
totalTime_.clear();
totalTime_.setSize(faItems_.size(), obr_.time().deltaTValue());
if ((restartOnRestart_ || restartOnOutput_) && log_)
if ((restartOnRestart_ || restartOnOutput_) && log)
{
Info<< " Starting averaging at time " << obr_.time().timeName()
<< nl;
@ -232,7 +232,7 @@ void Foam::functionObjects::fieldAverage::readAveragingProperties()
if (!propsDictHeader.headerOk())
{
if (log_) Info
Log
<< " Starting averaging at time "
<< obr_.time().timeName() << nl;
@ -241,7 +241,7 @@ void Foam::functionObjects::fieldAverage::readAveragingProperties()
IOdictionary propsDict(propsDictHeader);
if (log_) Info<< " Restarting averaging for fields:" << nl;
Log << " Restarting averaging for fields:" << nl;
forAll(faItems_, fieldi)
{
@ -253,7 +253,7 @@ void Foam::functionObjects::fieldAverage::readAveragingProperties()
totalIter_[fieldi] = readLabel(fieldDict.lookup("totalIter"));
totalTime_[fieldi] = readScalar(fieldDict.lookup("totalTime"));
if (log_) Info
Log
<< " " << fieldName
<< " iters = " << totalIter_[fieldi]
<< " time = " << totalTime_[fieldi] << nl;
@ -302,7 +302,7 @@ bool Foam::functionObjects::fieldAverage::read(const dictionary& dict)
initialised_ = false;
if (log_) Info<< type() << " " << name() << ":" << nl;
Log << type() << " " << name() << ":" << nl;
dict.readIfPresent("restartOnRestart", restartOnRestart_);
dict.readIfPresent("restartOnOutput", restartOnOutput_);
@ -316,7 +316,7 @@ bool Foam::functionObjects::fieldAverage::read(const dictionary& dict)
readAveragingProperties();
if (log_) Info<< endl;
Log << endl;
return true;
}

View File

@ -36,7 +36,7 @@ void Foam::functionObjects::fieldAverage::addMeanFieldType(const label fieldi)
const word& fieldName = faItems_[fieldi].fieldName();
const word& meanFieldName = faItems_[fieldi].meanFieldName();
if (log_) Info<< " Reading/initialising field " << meanFieldName << endl;
Log << " Reading/initialising field " << meanFieldName << endl;
if (obr_.foundObject<Type>(meanFieldName))
{
@ -44,8 +44,7 @@ void Foam::functionObjects::fieldAverage::addMeanFieldType(const label fieldi)
}
else if (obr_.found(meanFieldName))
{
if (log_) Info
<< " Cannot allocate average field " << meanFieldName
Log << " Cannot allocate average field " << meanFieldName
<< " since an object with that name already exists."
<< " Disabling averaging for field." << endl;
@ -112,8 +111,7 @@ void Foam::functionObjects::fieldAverage::addPrime2MeanFieldType
const word& meanFieldName = faItems_[fieldi].meanFieldName();
const word& prime2MeanFieldName = faItems_[fieldi].prime2MeanFieldName();
if (log_) Info
<< " Reading/initialising field " << prime2MeanFieldName << nl;
Log << " Reading/initialising field " << prime2MeanFieldName << nl;
if (obr_.foundObject<Type2>(prime2MeanFieldName))
{
@ -121,8 +119,7 @@ void Foam::functionObjects::fieldAverage::addPrime2MeanFieldType
}
else if (obr_.found(prime2MeanFieldName))
{
if (log_) Info
<< " Cannot allocate average field " << prime2MeanFieldName
Log << " Cannot allocate average field " << prime2MeanFieldName
<< " since an object with that name already exists."
<< " Disabling averaging for field." << nl;

View File

@ -60,8 +60,7 @@ fieldCoordinateSystemTransform
{
read(dict);
if (log_) Info
<< type() << " " << name << ":" << nl
Log << type() << " " << name << ":" << nl
<< " Applying transformation from global Cartesian to local "
<< coordSys_ << nl << endl;
}

View File

@ -151,7 +151,7 @@ bool Foam::functionObjects::fieldMinMax::write(const bool postProcess)
writeFiles::write();
if (!location_) writeTime(file());
if (log_) Info<< type() << " " << name() << " output:" << nl;
Log << type() << " " << name() << " output:" << nl;
forAll(fieldSet_, fieldi)
{
@ -163,7 +163,7 @@ bool Foam::functionObjects::fieldMinMax::write(const bool postProcess)
}
if (!location_) file()<< endl;
if (log_) Info<< endl;
Log << endl;
return true;
}

View File

@ -67,34 +67,31 @@ void Foam::functionObjects::fieldMinMax::output
file<< endl;
if (log_) Info
<< " min(" << outputName << ") = " << minValue
Log << " min(" << outputName << ") = " << minValue
<< " at location " << minC;
if (Pstream::parRun())
{
if (log_) Info<< " on processor " << minProci;
Log << " on processor " << minProci;
}
if (log_) Info
<< nl << " max(" << outputName << ") = " << maxValue
Log << nl << " max(" << outputName << ") = " << maxValue
<< " at location " << maxC;
if (Pstream::parRun())
{
if (log_) Info<< " on processor " << maxProci;
Log << " on processor " << maxProci;
}
}
else
{
file<< token::TAB << minValue << token::TAB << maxValue;
if (log_) Info
<< " min/max(" << outputName << ") = "
Log << " min/max(" << outputName << ") = "
<< minValue << ' ' << maxValue;
}
if (log_) Info<< endl;
Log << endl;
}

View File

@ -294,7 +294,7 @@ bool Foam::functionObjects::fieldValues::cellSource::write
{
file() << tab << volume_;
}
if (log_) Info<< " total volume = " << volume_ << endl;
Log << " total volume = " << volume_ << endl;
}
forAll(fields_, i)
@ -322,7 +322,7 @@ bool Foam::functionObjects::fieldValues::cellSource::write
file()<< endl;
}
if (log_) Info<< endl;
Log << endl;
return true;
}

View File

@ -205,7 +205,7 @@ bool Foam::functionObjects::fieldValues::cellSource::writeValues
file()<< tab << result;
if (log_) Info<< " " << operationTypeNames_[operation_]
Log << " " << operationTypeNames_[operation_]
<< "(" << sourceName_ << ") of " << fieldName
<< " = " << result << endl;
}

View File

@ -744,7 +744,7 @@ bool Foam::functionObjects::fieldValues::faceSource::write
{
file() << tab << totalArea_;
}
if (log_) Info<< " total area = " << totalArea_ << endl;
Log << " total area = " << totalArea_ << endl;
}
// construct weight field. Note: zero size means weight = 1
@ -791,7 +791,7 @@ bool Foam::functionObjects::fieldValues::faceSource::write
file()<< endl;
}
if (log_) Info<< endl;
Log << endl;
return true;
}

View File

@ -344,7 +344,7 @@ bool Foam::functionObjects::fieldValues::faceSource::writeValues
file()<< tab << result;
if (log_) Info<< " " << operationTypeNames_[operation_]
Log << " " << operationTypeNames_[operation_]
<< "(" << sourceName_ << ") of " << fieldName
<< " = " << result << endl;
}

View File

@ -110,7 +110,7 @@ bool Foam::functionObjects::fieldValue::write(const bool postProcess)
{
writeFiles::write();
if (log_) Info<< type() << " " << name() << " output:" << nl;
Log << type() << " " << name() << " output:" << nl;
return true;
}

View File

@ -179,7 +179,7 @@ bool Foam::functionObjects::fieldValues::fieldValueDelta::write
writeTime(file());
}
if (log_) Info<< type() << " " << name() << " output:" << endl;
Log << type() << " " << name() << " output:" << endl;
bool found = false;
processFields<scalar>(found);
@ -193,16 +193,13 @@ bool Foam::functionObjects::fieldValues::fieldValueDelta::write
file()<< endl;
}
if (log_)
{
if (!found)
{
Info<< " none" << endl;
Log << " none" << endl;
}
else
{
Info<< endl;
}
Log << endl;
}
return true;

View File

@ -110,7 +110,7 @@ void Foam::functionObjects::fieldValues::fieldValueDelta::processFields
Type result = applyOperation(r1, r2);
if (log_) Info<< " " << operationTypeNames_[operation_]
Log << " " << operationTypeNames_[operation_]
<< "(" << fieldName << ") = " << result
<< endl;

View File

@ -57,8 +57,7 @@ void Foam::functionObjects::histogram::writeGraph
outputPath/formatterPtr_().getFileName(coords, fieldNames)
);
if (log_) Info
<< " Writing histogram of " << fieldName
Log << " Writing histogram of " << fieldName
<< " to " << graphFile.name() << endl;
List<const scalarField*> yPtrs(1);
@ -118,18 +117,18 @@ bool Foam::functionObjects::histogram::execute(const bool postProcess)
bool Foam::functionObjects::histogram::write(const bool postProcess)
{
if (log_) Info<< type() << " " << name() << " output:" << nl;
Log << type() << " " << name() << " output:" << nl;
const fvMesh& mesh = refCast<const fvMesh>(obr_);
autoPtr<volScalarField> fieldPtr;
if (obr_.foundObject<volScalarField>(fieldName_))
{
if (log_) Info<< " Looking up field " << fieldName_ << endl;
Log << " Looking up field " << fieldName_ << endl;
}
else
{
if (log_) Info<< " Reading field " << fieldName_ << endl;
Log << " Reading field " << fieldName_ << endl;
fieldPtr.reset
(
new volScalarField

View File

@ -276,7 +276,7 @@ bool Foam::functionObjects::nearWallFields::read(const dictionary& dict)
reverseFieldMap_.insert(sampleFldName, fldName);
}
if (log_) Info << type() << " " << name()
Log << type() << " " << name()
<< ": Sampling " << fieldMap_.size() << " fields" << endl;
// Do analysis
@ -300,7 +300,7 @@ bool Foam::functionObjects::nearWallFields::execute(const bool postProcess)
&& vtf_.empty()
)
{
if (log_) Info<< type() << " " << name()
Log << type() << " " << name()
<< ": Creating " << fieldMap_.size() << " fields" << endl;
createFields(vsf_);
@ -309,10 +309,10 @@ bool Foam::functionObjects::nearWallFields::execute(const bool postProcess)
createFields(vSymmtf_);
createFields(vtf_);
if (log_) Info<< endl;
Log << endl;
}
if (log_) Info<< type() << " " << name()
Log << type() << " " << name()
<< " output:" << nl
<< " Sampling fields to " << time_.timeName()
<< endl;
@ -331,7 +331,7 @@ bool Foam::functionObjects::nearWallFields::write(const bool postProcess)
{
DebugInFunction << endl;
if (log_) Info<< " Writing sampled fields to " << time_.timeName()
Log << " Writing sampled fields to " << time_.timeName()
<< endl;
forAll(vsf_, i)
@ -355,7 +355,7 @@ bool Foam::functionObjects::nearWallFields::write(const bool postProcess)
vtf_[i].write();
}
if (log_) Info<< endl;
Log << endl;
return true;
}

View File

@ -47,7 +47,7 @@ void Foam::functionObjects::nearWallFields::createFields
if (obr_.found(sampleFldName))
{
if (log_) Info<< " a field " << sampleFldName
Log << " a field " << sampleFldName
<< " already exists on the mesh."
<< endl;
}
@ -63,7 +63,7 @@ void Foam::functionObjects::nearWallFields::createFields
sflds.set(sz, new VolFieldType(io, fld));
if (log_) Info<< " created " << sflds[sz].name()
Log << " created " << sflds[sz].name()
<< " to sample " << fld.name() << endl;
}
}

View File

@ -71,7 +71,7 @@ void Foam::functionObjects::readFields::loadField
)
{
// Store field locally
if (log_) Info<< " Reading " << fieldName << endl;
Log << " Reading " << fieldName << endl;
label sz = vflds.size();
vflds.setSize(sz+1);
@ -84,7 +84,7 @@ void Foam::functionObjects::readFields::loadField
)
{
// Store field locally
if (log_) Info<< " Reading " << fieldName << endl;
Log << " Reading " << fieldName << endl;
label sz = sflds.size();
sflds.setSize(sz+1);

View File

@ -208,7 +208,7 @@ bool Foam::functionObjects::forceCoeffs::write(const bool postProcess)
<< tab << Cm << tab << Cd
<< tab << Cl << tab << Clf << tab << Clr << endl;
if (log_) Info<< type() << " " << name() << " output:" << nl
Log << type() << " " << name() << " output:" << nl
<< " Cm = " << Cm << nl
<< " Cd = " << Cd << nl
<< " Cl = " << Cl << nl
@ -240,7 +240,7 @@ bool Foam::functionObjects::forceCoeffs::write(const bool postProcess)
file(1) << endl;
}
if (log_) Info<< endl;
Log << endl;
}
return true;

View File

@ -393,8 +393,7 @@ void Foam::functionObjects::forces::applyBins
void Foam::functionObjects::forces::writeForces()
{
if (log_) Info
<< type() << " " << name() << " output:" << nl
Log << type() << " " << name() << " output:" << nl
<< " sum of forces:" << nl
<< " pressure : " << sum(force_[0]) << nl
<< " viscous : " << sum(force_[1]) << nl
@ -612,7 +611,7 @@ bool Foam::functionObjects::forces::read(const dictionary& dict)
initialised_ = false;
if (log_) Info<< type() << " " << name() << ":" << nl;
Log << type() << " " << name() << ":" << nl;
directForceDensity_ = dict.lookupOrDefault("directForceDensity", false);
@ -653,11 +652,11 @@ bool Foam::functionObjects::forces::read(const dictionary& dict)
dict.readIfPresent("porosity", porosity_);
if (porosity_)
{
if (log_) Info<< " Including porosity effects" << endl;
Log << " Including porosity effects" << endl;
}
else
{
if (log_) Info<< " Not including porosity effects" << endl;
Log << " Not including porosity effects" << endl;
}
if (dict.found("binData"))
@ -908,7 +907,7 @@ bool Foam::functionObjects::forces::write(const bool postProcess)
writeBins();
if (log_) Info<< endl;
Log << endl;
}
return true;

View File

@ -88,7 +88,7 @@ void Foam::functionObjects::wallShearStress::calcShearStress
<< endl;
}
if (log_) Info<< " min/max(" << pp.name() << ") = "
Log << " min/max(" << pp.name() << ") = "
<< minSsp << ", " << maxSsp << endl;
}
}
@ -222,7 +222,7 @@ bool Foam::functionObjects::wallShearStress::execute(const bool postProcess)
mesh.lookupObject<volVectorField>(type())
);
if (log_) Info<< type() << " " << name() << " output:" << nl;
Log << type() << " " << name() << " output:" << nl;
tmp<volSymmTensorField> Reff;
@ -260,7 +260,7 @@ bool Foam::functionObjects::wallShearStress::write(const bool postProcess)
const volVectorField& wallShearStress =
obr_.lookupObject<volVectorField>(type());
if (log_) Info<< type() << " " << name() << " output:" << nl
Log << type() << " " << name() << " output:" << nl
<< " writing field " << wallShearStress.name() << nl
<< endl;

View File

@ -106,8 +106,7 @@ void Foam::functionObjects::yPlus::calcYPlus
if (Pstream::master())
{
if (log_) Info
<< " patch " << patch.name()
Log << " patch " << patch.name()
<< " y+ : min = " << minYplus << ", max = " << maxYplus
<< ", average = " << avgYplus << nl;
@ -137,8 +136,7 @@ void Foam::functionObjects::yPlus::calcYPlus
if (Pstream::master())
{
if (log_) Info
<< " patch " << patch.name()
Log << " patch " << patch.name()
<< " y+ : min = " << minYplus << ", max = " << maxYplus
<< ", average = " << avgYplus << nl;
@ -227,7 +225,7 @@ bool Foam::functionObjects::yPlus::execute(const bool postProcess)
mesh.lookupObject<volScalarField>(type())
);
if (log_) Info<< type() << " " << name() << " output:" << nl;
Log << type() << " " << name() << " output:" << nl;
if (mesh.foundObject<turbulenceModel>(turbulenceModel::propertiesName))
{
@ -254,7 +252,7 @@ bool Foam::functionObjects::yPlus::write(const bool postProcess)
const volScalarField& yPlus =
obr_.lookupObject<volScalarField>(type());
if (log_) Info<< " writing field " << yPlus.name() << endl;
Log << " writing field " << yPlus.name() << endl;
yPlus.write();