BUG: parallel blocking writing surface noise output (fixes #2663)

- old logic (v2206 and earlier) always disabled writing on non-master,
  but other parts of the code were more recently updated to use lazy
  evaluation of surface data (with parallel communication)

- now retain full write/no-write logic identically on all ranks. Take
  care of master/non-master at the final output stage.
This commit is contained in:
Mark Olesen
2022-12-19 16:05:12 +01:00
parent 0a01492397
commit aebd79ff59
4 changed files with 47 additions and 45 deletions

View File

@ -157,30 +157,28 @@ namespace Foam
} }
// * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * // // * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
void Foam::noiseModel::readWriteOption namespace Foam
{
// Get bool option (eg, read/write) and provide Info feedback
static void readWriteOption
( (
const dictionary& dict, const dictionary& dict,
const word& lookup, const word& lookup,
bool& option bool& option
) const )
{ {
dict.readIfPresent(lookup, option); dict.readIfPresent(lookup, option);
// Only writing on the master process Info<< " " << lookup << ": " << (option ? "yes" : "no") << endl;
option = option && Pstream::master();
if (option)
{
Info<< " " << lookup << ": " << "yes" << endl;
}
else
{
Info<< " " << lookup << ": " << "no" << endl;
}
} }
} // End namespace Foam
// * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * //
Foam::scalar Foam::noiseModel::checkUniformTimeStep Foam::scalar Foam::noiseModel::checkUniformTimeStep
( (
@ -255,7 +253,7 @@ void Foam::noiseModel::writeFileHeader
Ostream& os, Ostream& os,
const string& x, const string& x,
const string& y, const string& y,
const List<Tuple2<string, token>>& headerValues const UList<Tuple2<string, token>>& headerValues
) const ) const
{ {
writeHeader(os, x + " vs " + y); writeHeader(os, x + " vs " + y);

View File

@ -76,8 +76,8 @@ SourceFiles
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#ifndef noiseModel_H #ifndef Foam_noiseModel_H
#define noiseModel_H #define Foam_noiseModel_H
#include "writeFile.H" #include "writeFile.H"
#include "dictionary.H" #include "dictionary.H"
@ -220,14 +220,6 @@ protected:
// Protected Member Functions // Protected Member Functions
//- Helper function to read write options and provide info feedback
void readWriteOption
(
const dictionary& dict,
const word& lookup,
bool& option
) const;
//- Check and return uniform time step //- Check and return uniform time step
scalar checkUniformTimeStep scalar checkUniformTimeStep
( (
@ -257,7 +249,7 @@ protected:
Ostream& os, Ostream& os,
const string& x, const string& x,
const string& y, const string& y,
const List<Tuple2<string, token>>& headerValues = {} const UList<Tuple2<string, token>>& headerValues = {}
) const; ) const;
// Write frequency-based data to file // Write frequency-based data to file

View File

@ -74,6 +74,14 @@ void pointNoise::processData
const Function1Types::CSV<scalar>& data const Function1Types::CSV<scalar>& data
) )
{ {
if (!Pstream::master())
{
// Only ever called on master, report if we have odd logic...
WarningInFunction
<< "Currently only to be called from master process..." << endl;
return;
}
Info<< "Reading data file: " Info<< "Reading data file: "
<< fileObr_.time().relativePath(data.fName()) << endl; << fileObr_.time().relativePath(data.fName()) << endl;
@ -131,7 +139,7 @@ void pointNoise::processData
auto filePtr = newFile(outDir/"PSD_f"); auto filePtr = newFile(outDir/"PSD_f");
auto& os = filePtr(); auto& os = filePtr();
Info<< " Writing " << os.name() << endl; Info<< " Writing " << os.relativeName() << endl;
writeFileHeader(os, "f [Hz]", "PSD(f) [PaPa_Hz]"); writeFileHeader(os, "f [Hz]", "PSD(f) [PaPa_Hz]");
writeFreqDataToFile(os, f, PSDf); writeFreqDataToFile(os, f, PSDf);
@ -143,7 +151,7 @@ void pointNoise::processData
auto filePtr = newFile(outDir/"PSD_dB_Hz_f"); auto filePtr = newFile(outDir/"PSD_dB_Hz_f");
auto& os = filePtr(); auto& os = filePtr();
Info<< " Writing " << os.name() << endl; Info<< " Writing " << os.relativeName() << endl;
writeFileHeader(os, "f [Hz]", "PSD(f) [dB_Hz]"); writeFileHeader(os, "f [Hz]", "PSD(f) [dB_Hz]");
writeFreqDataToFile(os, f, PSD(PSDf)); writeFreqDataToFile(os, f, PSD(PSDf));
@ -155,7 +163,7 @@ void pointNoise::processData
auto filePtr = newFile(outDir/"SPL_dB_f"); auto filePtr = newFile(outDir/"SPL_dB_f");
auto& os = filePtr(); auto& os = filePtr();
Info<< " Writing " << os.name() << endl; Info<< " Writing " << os.relativeName() << endl;
writeFileHeader writeFileHeader
( (
@ -190,7 +198,7 @@ void pointNoise::processData
auto filePtr = newFile(outDir/"SPL13_dB_fm"); auto filePtr = newFile(outDir/"SPL13_dB_fm");
auto& os = filePtr(); auto& os = filePtr();
Info<< " Writing " << os.name() << endl; Info<< " Writing " << os.relativeName() << endl;
writeFileHeader writeFileHeader
( (

View File

@ -362,7 +362,7 @@ scalar surfaceNoise::writeSurfaceData
areaAverage = sum(allData)/(allData.size() + ROOTVSMALL); areaAverage = sum(allData)/(allData.size() + ROOTVSMALL);
} }
if (writeSurface) // (writeSurface == true)
{ {
// Time-aware, with time spliced into the output path // Time-aware, with time spliced into the output path
writerPtr_->beginTime(freqInst); writerPtr_->beginTime(freqInst);
@ -397,7 +397,7 @@ scalar surfaceNoise::writeSurfaceData
areaAverage = sum(data)/(data.size() + ROOTVSMALL); areaAverage = sum(data)/(data.size() + ROOTVSMALL);
} }
if (writeSurface) // (writeSurface == true)
{ {
// Time-aware, with time spliced into the output path // Time-aware, with time spliced into the output path
writerPtr_->beginTime(freqInst); writerPtr_->beginTime(freqInst);
@ -693,15 +693,19 @@ void surfaceNoise::calculate()
surfArea = sum(surf.magSf()); surfArea = sum(surf.magSf());
surfSize = surf.size(); surfSize = surf.size();
} }
Pstream::broadcast(surfArea); Pstream::broadcasts
Pstream::broadcast(surfSize); (
UPstream::worldComm,
surfArea,
surfSize
);
List<Tuple2<string, token>> commonInfo = List<Tuple2<string, token>> commonInfo
{ ({
{"Area average", token(word(Switch::name(areaAverage_)))}, {"Area average", token(word(Switch::name(areaAverage_)))},
{"Area sum", token(surfArea)}, {"Area sum", token(surfArea)},
{"Number of faces", token(surfSize)} {"Number of faces", token(surfSize)}
}; });
{ {
fileName outDir(outDirBase/"fft"); fileName outDir(outDirBase/"fft");
@ -782,7 +786,7 @@ void surfaceNoise::calculate()
auto filePtr = newFile(outDir/"Average_Prms_f"); auto filePtr = newFile(outDir/"Average_Prms_f");
auto& os = filePtr(); auto& os = filePtr();
Info<< " Writing " << os.name() << endl; Info<< " Writing " << os.relativeName() << endl;
writeFileHeader(os, "f [Hz]", "P(f) [Pa]", commonInfo); writeFileHeader(os, "f [Hz]", "P(f) [Pa]", commonInfo);
writeFreqDataToFile(os, fOut, PrmsfAve); writeFreqDataToFile(os, fOut, PrmsfAve);
@ -791,7 +795,7 @@ void surfaceNoise::calculate()
auto filePtr = newFile(outDir/"Average_PSD_f_f"); auto filePtr = newFile(outDir/"Average_PSD_f_f");
auto& os = filePtr(); auto& os = filePtr();
Info<< " Writing " << os.name() << endl; Info<< " Writing " << os.relativeName() << endl;
writeFileHeader writeFileHeader
( (
@ -806,7 +810,7 @@ void surfaceNoise::calculate()
auto filePtr = newFile(outDir/"Average_PSD_dB_Hz_f"); auto filePtr = newFile(outDir/"Average_PSD_dB_Hz_f");
auto& os = filePtr(); auto& os = filePtr();
Info<< " Writing " << os.name() << endl; Info<< " Writing " << os.relativeName() << endl;
writeFileHeader writeFileHeader
( (
@ -821,7 +825,7 @@ void surfaceNoise::calculate()
auto filePtr = newFile(outDir/"Average_SPL_dB_f"); auto filePtr = newFile(outDir/"Average_SPL_dB_f");
auto& os = filePtr(); auto& os = filePtr();
Info<< " Writing " << os.name() << endl; Info<< " Writing " << os.relativeName() << endl;
writeFileHeader writeFileHeader
( (
@ -866,7 +870,7 @@ void surfaceNoise::calculate()
auto filePtr = newFile(outDir/"Average_SPL13_dB_fm"); auto filePtr = newFile(outDir/"Average_SPL13_dB_fm");
auto& os = filePtr(); auto& os = filePtr();
Info<< " Writing " << os.name() << endl; Info<< " Writing " << os.relativeName() << endl;
writeFileHeader writeFileHeader
( (