ENH: Added position output to fieldMinMax function object

This commit is contained in:
andy
2012-03-21 09:17:47 +00:00
parent b78e8b6e51
commit d1a4239478
3 changed files with 109 additions and 72 deletions

View File

@ -156,7 +156,9 @@ void Foam::fieldMinMax::writeFileHeader()
if (fieldMinMaxFilePtr_.valid()) if (fieldMinMaxFilePtr_.valid())
{ {
fieldMinMaxFilePtr_() fieldMinMaxFilePtr_()
<< "# Time" << tab << "field" << tab << "min" << tab << "max" << "# Time" << token::TAB << "field" << token::TAB
<< "min" << token::TAB << "position(min)" << token::TAB
<< "max" << token::TAB << "position(max)" << token::TAB
<< endl; << endl;
} }
} }
@ -184,50 +186,27 @@ void Foam::fieldMinMax::write()
makeFile(); makeFile();
} }
if (log_)
{
Info<< type() << " output:" << nl;
}
forAll(fieldSet_, fieldI) forAll(fieldSet_, fieldI)
{ {
calcMinMaxFields<scalar>(fieldSet_[fieldI]); calcMinMaxFields<scalar>(fieldSet_[fieldI], mdCmpt);
calcMinMaxFields<vector>(fieldSet_[fieldI]); calcMinMaxFields<vector>(fieldSet_[fieldI], mode_);
calcMinMaxFields<sphericalTensor>(fieldSet_[fieldI]); calcMinMaxFields<sphericalTensor>(fieldSet_[fieldI], mode_);
calcMinMaxFields<symmTensor>(fieldSet_[fieldI]); calcMinMaxFields<symmTensor>(fieldSet_[fieldI], mode_);
calcMinMaxFields<tensor>(fieldSet_[fieldI]); calcMinMaxFields<tensor>(fieldSet_[fieldI], mode_);
} }
}
}
if (log_)
template<>
void Foam::fieldMinMax::calcMinMaxFields<Foam::scalar>
(
const word& fieldName
)
{
if (obr_.foundObject<volScalarField>(fieldName))
{
const volScalarField& field =
obr_.lookupObject<volScalarField>(fieldName);
const scalar minValue = min(field).value();
const scalar maxValue = max(field).value();
if (Pstream::master())
{ {
if (write_) Info<< endl;
{
fieldMinMaxFilePtr_()
<< obr_.time().value() << tab
<< fieldName << tab << minValue << tab << maxValue << endl;
}
if (log_)
{
Info<< "fieldMinMax output:" << nl
<< " min(" << fieldName << ") = " << minValue << nl
<< " max(" << fieldName << ") = " << maxValue << nl
<< endl;
}
} }
} }
} }
// ************************************************************************* // // ************************************************************************* //

View File

@ -163,7 +163,11 @@ public:
//- Calculate the field min/max //- Calculate the field min/max
template<class Type> template<class Type>
void calcMinMaxFields(const word& fieldName); void calcMinMaxFields
(
const word& fieldName,
const modeType& mode
);
//- Write the fieldMinMax //- Write the fieldMinMax
virtual void write(); virtual void write();
@ -178,11 +182,6 @@ public:
}; };
// Template specialisation for scalar fields
template<>
void fieldMinMax::calcMinMaxFields<scalar>(const word& fieldName);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam } // End namespace Foam

View File

@ -27,81 +27,140 @@ License
#include "volFields.H" #include "volFields.H"
#include "dictionary.H" #include "dictionary.H"
#include "Time.H" #include "Time.H"
#include "ListOps.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<class Type> template<class Type>
void Foam::fieldMinMax::calcMinMaxFields(const word& fieldName) void Foam::fieldMinMax::calcMinMaxFields
(
const word& fieldName,
const modeType& mode
)
{ {
typedef GeometricField<Type, fvPatchField, volMesh> fieldType; typedef GeometricField<Type, fvPatchField, volMesh> fieldType;
if (obr_.foundObject<fieldType>(fieldName)) if (obr_.foundObject<fieldType>(fieldName))
{ {
const label procI = Pstream::myProcNo();
const fieldType& field = obr_.lookupObject<fieldType>(fieldName); const fieldType& field = obr_.lookupObject<fieldType>(fieldName);
switch (mode_) switch (mode)
{ {
case mdMag: case mdMag:
{ {
const scalar minValue = min(mag(field)).value(); const scalarField magField(mag(field));
const scalar maxValue = max(mag(field)).value();
labelList minIs(Pstream::nProcs());
scalarList minVs(Pstream::nProcs());
List<vector> minCs(Pstream::nProcs());
minIs[procI] = findMin(magField);
minVs[procI] = magField[minIs[procI]];
minCs[procI] = field.mesh().C()[minIs[procI]];
Pstream::gatherList(minIs);
Pstream::gatherList(minVs);
Pstream::gatherList(minCs);
labelList maxIs(Pstream::nProcs());
scalarList maxVs(Pstream::nProcs());
List<vector> maxCs(Pstream::nProcs());
maxIs[procI] = findMax(magField);
maxVs[procI] = magField[maxIs[procI]];
maxCs[procI] = field.mesh().C()[maxIs[procI]];
Pstream::gatherList(maxIs);
Pstream::gatherList(maxVs);
Pstream::gatherList(maxCs);
label minI = findMin(minVs);
scalar minValue = minVs[minI];
const vector& minC = minCs[minI];
label maxI = findMax(maxVs);
scalar maxValue = maxVs[maxI];
const vector& maxC = maxCs[maxI];
if (Pstream::master()) if (Pstream::master())
{ {
if (write_) if (write_)
{ {
fieldMinMaxFilePtr_() fieldMinMaxFilePtr_()
<< obr_.time().value() << tab << obr_.time().value() << token::TAB
<< fieldName << tab << minValue << tab << maxValue << fieldName << token::TAB
<< endl; << minValue << token::TAB << minC << token::TAB
<< maxValue << token::TAB << maxC << endl;
} }
if (log_) if (log_)
{ {
Info<< "fieldMinMax output:" << nl Info<< " min(mag(" << fieldName << ")) = "
<< " min(mag(" << fieldName << ")) = " << minValue << " at position " << minC << nl
<< minValue << nl
<< " max(mag(" << fieldName << ")) = " << " max(mag(" << fieldName << ")) = "
<< maxValue << nl << maxValue << " at position " << maxC << nl;
<< endl;
} }
} }
break; break;
} }
case mdCmpt: case mdCmpt:
{ {
const Type minValue = min(field).value(); List<Type> minVs(Pstream::nProcs());
const Type maxValue = max(field).value(); labelList minIs(Pstream::nProcs());
List<vector> minCs(Pstream::nProcs());
minIs[procI] = findMin(field);
minVs[procI] = field[minIs[procI]];
minCs[procI] = field.mesh().C()[minIs[procI]];
Pstream::gatherList(minIs);
Pstream::gatherList(minVs);
Pstream::gatherList(minCs);
List<Type> maxVs(Pstream::nProcs());
labelList maxIs(Pstream::nProcs());
List<vector> maxCs(Pstream::nProcs());
maxIs[procI] = findMax(field);
maxVs[procI] = field[maxIs[procI]];
maxCs[procI] = field.mesh().C()[maxIs[procI]];
Pstream::gatherList(maxIs);
Pstream::gatherList(maxVs);
Pstream::gatherList(maxCs);
label minI = findMin(minVs);
Type minValue = minVs[minI];
const vector& minC = minCs[minI];
label maxI = findMax(maxVs);
Type maxValue = maxVs[maxI];
const vector& maxC = maxCs[maxI];
if (Pstream::master()) if (Pstream::master())
{ {
if (write_) if (write_)
{ {
fieldMinMaxFilePtr_() fieldMinMaxFilePtr_()
<< obr_.time().value() << tab << obr_.time().value() << token::TAB
<< fieldName << tab << minValue << tab << maxValue << fieldName << token::TAB
<< endl; << minValue << token::TAB << minC << token::TAB
<< maxValue << token::TAB << maxC << endl;
} }
if (log_) if (log_)
{ {
Info<< "fieldMinMax output:" << nl Info<< " min(" << fieldName << ") = "
<< " cmptMin(" << fieldName << ") = " << minValue << " at position " << minC << nl
<< minValue << nl << " max(" << fieldName << ") = "
<< " cmptMax(" << fieldName << ") = " << maxValue << " at position " << maxC << nl;
<< maxValue << nl
<< endl;
} }
} }
break; break;
} }
default: default:
{ {
FatalErrorIn FatalErrorIn("Foam::fieldMinMax::calcMinMaxFields(const word&)")
( << "Unknown min/max mode: " << modeTypeNames_[mode_]
"Foam::fieldMinMax::calcMinMaxFields" << exit(FatalError);
"(const word& fieldName)"
)<< "Unknown min/max mode: " << modeTypeNames_[mode_]
<< exit(FatalError);
} }
} }
} }