Skip to content

Commit

Permalink
messageStream: Added 'Log' macro which outputs to 'Info' if 'log' is …
Browse files Browse the repository at this point in the history
…true

regionFunctionObject: moved 'log_' to public 'log' to support the 'Log' macro
  • Loading branch information
Henry Weller committed May 25, 2016
1 parent 608da26 commit 48e5817
Show file tree
Hide file tree
Showing 23 changed files with 80 additions and 89 deletions.
5 changes: 5 additions & 0 deletions src/OpenFOAM/db/error/messageStream.H
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -109,7 +109,7 @@ Foam::functionObjects::regionFunctionObject::regionFunctionObject
dict.lookupOrDefault("region", polyMesh::defaultRegion)
)
),
log_(true)
log(true)
{}


Expand All @@ -123,7 +123,7 @@ Foam::functionObjects::regionFunctionObject::regionFunctionObject
functionObject(name),
time_(obr.time()),
obr_(obr),
log_(true)
log(true)
{}


Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -118,6 +115,9 @@ public:
//- Runtime type information
TypeName("regionFunctionObject");

//- Switch write log to Info
Switch log;


// Constructors

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -134,7 +134,7 @@ void Foam::functionObjects::fieldAverage::calcAverages()
periodIndex_++;
}

if (log_) Info
Log
<< type() << " " << name() << " output:" << nl
<< " Calculating averages" << nl;

Expand All @@ -156,21 +156,21 @@ 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>();
writeFields<sphericalTensor>();
writeFields<symmTensor>();
writeFields<tensor>();

if (log_) Info<< endl;
Log << endl;
}


Expand Down Expand Up @@ -200,7 +200,7 @@ void Foam::functionObjects::fieldAverage::writeAveragingProperties() const

propsDict.regIOobject::write();

if (log_) Info<< endl;
Log << endl;
}


Expand All @@ -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;
Expand All @@ -232,7 +232,7 @@ void Foam::functionObjects::fieldAverage::readAveragingProperties()

if (!propsDictHeader.headerOk())
{
if (log_) Info
Log
<< " Starting averaging at time "
<< obr_.time().timeName() << nl;

Expand All @@ -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)
{
Expand All @@ -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;
Expand Down Expand Up @@ -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_);
Expand All @@ -316,7 +316,7 @@ bool Foam::functionObjects::fieldAverage::read(const dictionary& dict)

readAveragingProperties();

if (log_) Info<< endl;
Log << endl;

return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,15 @@ 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))
{
// do nothing
}
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;

Expand Down Expand Up @@ -112,17 +111,15 @@ 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))
{
// do nothing
}
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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -163,7 +163,7 @@ bool Foam::functionObjects::fieldMinMax::write(const bool postProcess)
}

if (!location_) file()<< endl;
if (log_) Info<< endl;
Log << endl;

return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -322,7 +322,7 @@ bool Foam::functionObjects::fieldValues::cellSource::write
file()<< endl;
}

if (log_) Info<< endl;
Log << endl;

return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -791,7 +791,7 @@ bool Foam::functionObjects::fieldValues::faceSource::write
file()<< endl;
}

if (log_) Info<< endl;
Log << endl;

return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -193,16 +193,13 @@ bool Foam::functionObjects::fieldValues::fieldValueDelta::write
file()<< endl;
}

if (log_)
if (!found)
{
if (!found)
{
Info<< " none" << endl;
}
else
{
Info<< endl;
}
Log << " none" << endl;
}
else
{
Log << endl;
}

return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Loading

0 comments on commit 48e5817

Please sign in to comment.