diff --git a/src/OpenFOAM/primitives/functions/Function1/CSV/CSV.C b/src/OpenFOAM/primitives/functions/Function1/CSV/CSV.C index 9d2d8581744257db01d59e0f56e0f717ac34a068..b82b4d30102d192a255567e8364dd29222a41829 100644 --- a/src/OpenFOAM/primitives/functions/Function1/CSV/CSV.C +++ b/src/OpenFOAM/primitives/functions/Function1/CSV/CSV.C @@ -204,7 +204,8 @@ Foam::Function1Types::CSV<Type>::CSV ( const word& entryName, const dictionary& dict, - const word& ext + const word& ext, + const fileName& fName ) : TableBase<Type>(entryName, dict.subDict(entryName + ext)), @@ -214,7 +215,7 @@ Foam::Function1Types::CSV<Type>::CSV componentColumns_(coeffs_.lookup("componentColumns")), separator_(coeffs_.lookupOrDefault<string>("separator", string(","))[0]), mergeSeparators_(readBool(coeffs_.lookup("mergeSeparators"))), - fName_(coeffs_.lookup("fileName")) + fName_(fName != fileName::null ? fName : coeffs_.lookup("fileName")) { if (componentColumns_.size() != pTraits<Type>::nComponents) { diff --git a/src/OpenFOAM/primitives/functions/Function1/CSV/CSV.H b/src/OpenFOAM/primitives/functions/Function1/CSV/CSV.H index 97e0047a2b70a422c3f4e5b59aeaafa050b3c515..ddba48afa5ed32519fa9d56e588eea5b828cff62 100644 --- a/src/OpenFOAM/primitives/functions/Function1/CSV/CSV.H +++ b/src/OpenFOAM/primitives/functions/Function1/CSV/CSV.H @@ -122,7 +122,8 @@ public: ( const word& entryName, const dictionary& dict, - const word& ext = "Coeffs" + const word& ext = "Coeffs", + const fileName& fName = fileName::null ); //- Copy constructor diff --git a/src/conversion/ensight/part/ensightPartFaces.C b/src/conversion/ensight/part/ensightPartFaces.C index 4875b19cfbfcce79779f6666f37bf012f5ba8cf2..576032482650fe119270ca4c84fd4b5932c3f53c 100644 --- a/src/conversion/ensight/part/ensightPartFaces.C +++ b/src/conversion/ensight/part/ensightPartFaces.C @@ -48,10 +48,10 @@ Foam::ensightPart::localPoints Foam::ensightPartFaces::calcLocalPoints() const labelList& usedPoints = ptList.list; label nPoints = 0; - // add all points from faces + // Add all points from faces const labelUList& idList = this->faceIds(); - // add all points from faces + // Add all points from faces forAll(idList, i) { const label id = idList[i] + start_; @@ -67,7 +67,7 @@ Foam::ensightPart::localPoints Foam::ensightPartFaces::calcLocalPoints() const } - // this is not absolutely necessary, but renumber anyhow + // This is not absolutely necessary, but renumber anyhow nPoints = 0; forAll(usedPoints, ptI) { @@ -101,7 +101,7 @@ Foam::ensightPartFaces::ensightPartFaces points_(points), contiguousPoints_(contiguousPoints) { - // classify the face shapes + // Classify the face shapes classify(faces); } @@ -121,7 +121,7 @@ Foam::ensightPartFaces::ensightPartFaces points_(mesh.points()), contiguousPoints_(false) { - // classify the face shapes + // Classify the face shapes classify(patch); } @@ -149,10 +149,10 @@ void Foam::ensightPartFaces::writeConnectivity os.write(idList.size()); os.newline(); - // write (polygon) face sizes + // Write (polygon) face sizes if (key == "nsided") { - // write the number of points per face + // Write the number of points per face forAll(idList, i) { const label id = idList[i] + start_; @@ -163,13 +163,13 @@ void Foam::ensightPartFaces::writeConnectivity } } - // write the points describing the face + // Write the points describing the face forAll(idList, i) { const label id = idList[i] + start_; const face& f = faces[id]; - // convert global -> local index + // Convert global -> local index // (note: Ensight indices start with 1) forAll(f, fp) { @@ -205,7 +205,7 @@ void Foam::ensightPartFaces::write const pointField& points ) const { - if (ensightPart::size()) + if (size()) { const localPoints ptList = calcLocalPoints(); const labelUList& pointMap = ptList.list; diff --git a/src/conversion/ensight/part/ensightPartFaces.H b/src/conversion/ensight/part/ensightPartFaces.H index 974ca68a055783cb702077a64320b59becbe9ff2..bdb6c062c8b4824d8fc0a70c603e5822e49c193c 100644 --- a/src/conversion/ensight/part/ensightPartFaces.H +++ b/src/conversion/ensight/part/ensightPartFaces.H @@ -138,44 +138,43 @@ public: // Member Functions - // Access + // Access - //- Part index (0-based) - virtual label index() const - { - return ensightFaces::index(); - } + //- Part index (0-based) + virtual label index() const + { + return ensightFaces::index(); + } - //- Number of elements in this part - virtual label size() const - { - return ensightFaces::size(); - } + //- Number of elements in this part + virtual label size() const + { + return ensightFaces::size(); + } - //- Return the patch index, -1 when not in use. - inline label patchIndex() const - { - return patchIndex_; - } + //- Return the patch index, -1 when not in use. + inline label patchIndex() const + { + return patchIndex_; + } - // Output + // Output - //- Write summary information about the object - virtual void writeSummary(Ostream&) const; + //- Write summary information about the object + virtual void writeSummary(Ostream&) const; - //- Write geometry - virtual void write(ensightGeoFile&) const; + //- Write geometry + virtual void write(ensightGeoFile&) const; - //- Helper: write geometry given the pointField - virtual void write(ensightGeoFile&, const pointField&) const; + //- Helper: write geometry given the pointField + virtual void write(ensightGeoFile&, const pointField&) const; - //- Print various types of debugging information - virtual void dumpInfo(Ostream&) const; - + //- Print various types of debugging information + virtual void dumpInfo(Ostream&) const; }; diff --git a/src/fileFormats/ensight/part/ensightFaces.H b/src/fileFormats/ensight/part/ensightFaces.H index dfb16859c0732da4edb5efa1b54231da46978a46..ddce1410d818f55fe4c4893d156155252d935f6d 100644 --- a/src/fileFormats/ensight/part/ensightFaces.H +++ b/src/fileFormats/ensight/part/ensightFaces.H @@ -132,83 +132,82 @@ public: // Member Functions - // Access + // Access - //- The index in a list. - inline label index() const; + //- The index in a list. + inline label index() const; - //- The index in a list, non-const access. - inline label& index(); + //- The index in a list, non-const access. + inline label& index(); - //- The processor local size of all elements. - inline label size() const; + //- The processor local size of all elements. + inline label size() const; - //- The global number of the specified element type. - // This value is only meaningful after a reduce operation. - inline label total(const enum elemType) const; + //- The global number of the specified element type. + // This value is only meaningful after a reduce operation. + inline label total(const enum elemType) const; - //- The global number of all element types. - // This value is only meaningful after a reduce operation. - label total() const; + //- The global number of all element types. + // This value is only meaningful after a reduce operation. + label total() const; - //- The processor local sizes per element type. - FixedList<label, 3> sizes() const; + //- The processor local sizes per element type. + FixedList<label, 3> sizes() const; - //- The global numbers per element type. - // This value is only meaningful after a reduce operation. - const FixedList<label, 3>& totals() const; + //- The global numbers per element type. + // This value is only meaningful after a reduce operation. + const FixedList<label, 3>& totals() const; - //- Return the (local) face ids of the specified element type - inline const labelUList& faceIds(const enum elemType) const; + //- Return the (local) face ids of the specified element type + inline const labelUList& faceIds(const enum elemType) const; - //- Return the face ids of all elements - inline const labelUList& faceIds() const; + //- Return the face ids of all elements + inline const labelUList& faceIds() const; - //- Return the flip-map of all elements - inline const boolList& flipMap() const; + //- Return the flip-map of all elements + inline const boolList& flipMap() const; - //- Starting offset of element type. - label offset(const enum elemType what) const; + //- Starting offset of element type. + label offset(const enum elemType what) const; - // Edit + // Edit - //- Classify the face types, set element list. - void classify(const faceList& faces); + //- Classify the face types, set element list. + void classify(const faceList& faces); - //- Classify the face types, set element list. - // The indirect addressing can be used when classifying groups of - // face (eg, from a faceZone etc) with an optional flipMap. - // The optional exclude marker can be used to skip faces on particular - // boundary types or regions. - void classify - ( - const faceList& faces, - const labelUList& addressing, - const boolList& flipMap = boolList(), - const PackedBoolList& exclude = PackedBoolList() - ); + //- Classify the face types, set element list. + // The indirect addressing can be used when classifying groups of + // face (eg, from a faceZone etc) with an optional flipMap. + // The optional exclude marker can be used to skip faces on particular + // boundary types or regions. + void classify + ( + const faceList& faces, + const labelUList& addressing, + const boolList& flipMap = boolList(), + const PackedBoolList& exclude = PackedBoolList() + ); - //- Set addressable sizes to zero, free up addressing memory. - void clear(); + //- Set addressable sizes to zero, free up addressing memory. + void clear(); - //- Sum element counts across all processes. - void reduce(); + //- Sum element counts across all processes. + void reduce(); - //- Sort element lists numerically. - void sort(); + //- Sort element lists numerically. + void sort(); // Member operators //- Return element from linear-list. inline label operator[](const label i) const; - }; diff --git a/src/randomProcesses/noise/noiseModels/noiseModel/noiseModel.C b/src/randomProcesses/noise/noiseModels/noiseModel/noiseModel.C index 21d52bb3dd8bf6eaf58f391e38d1c47bdd58e169..ae80887fe89f8d15fff01d275f050dd86d837e3b 100644 --- a/src/randomProcesses/noise/noiseModels/noiseModel/noiseModel.C +++ b/src/randomProcesses/noise/noiseModels/noiseModel/noiseModel.C @@ -94,17 +94,41 @@ Foam::label Foam::noiseModel::findStartTimeIndex // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // -Foam::noiseModel::noiseModel(const dictionary& dict) +Foam::noiseModel::noiseModel(const dictionary& dict, const bool readFields) : dict_(dict), - rhoRef_(dict.lookupOrDefault<scalar>("rhoRef", 1)), - nSamples_(dict.lookupOrDefault<label>("N", 65536)), - fLower_(dict.lookupOrDefault<scalar>("fl", 25)), - fUpper_(dict.lookupOrDefault<scalar>("fu", 10000)), - startTime_(dict.lookupOrDefault<scalar>("startTime", 0)), - windowModelPtr_(windowModel::New(dict, nSamples_)), - graphFormat_(dict.lookupOrDefault<word>("graphFormat", "raw")) + rhoRef_(1), + nSamples_(65536), + fLower_(25), + fUpper_(10000), + startTime_(0), + windowModelPtr_(), + graphFormat_("raw") { + if (readFields) + { + read(dict); + } +} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +Foam::noiseModel::~noiseModel() +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +bool Foam::noiseModel::read(const dictionary& dict) +{ + dict.readIfPresent("rhoRef", rhoRef_); + dict.readIfPresent("N", nSamples_); + dict.readIfPresent("fl", fLower_); + dict.readIfPresent("fu", fUpper_); + dict.readIfPresent("startTime", startTime_); + dict.readIfPresent("graphFormat", graphFormat_); + // Check number of samples - must be a power of 2 for our FFT bool powerOf2 = ((nSamples_ != 0) && !(nSamples_ & (nSamples_ - 1))); if (!powerOf2) @@ -139,13 +163,11 @@ Foam::noiseModel::noiseModel(const dictionary& dict) << exit(FatalIOError); } -} + windowModelPtr_ = windowModel::New(dict, nSamples_); -// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // - -Foam::noiseModel::~noiseModel() -{} + return true; +} // ************************************************************************* // diff --git a/src/randomProcesses/noise/noiseModels/noiseModel/noiseModel.H b/src/randomProcesses/noise/noiseModels/noiseModel/noiseModel.H index 28643cbf564fe1c48bc670ac7e4aaa5e5dbd5707..89c41edb84c927554f505235f19fe83668d1ced5 100644 --- a/src/randomProcesses/noise/noiseModels/noiseModel/noiseModel.H +++ b/src/randomProcesses/noise/noiseModels/noiseModel/noiseModel.H @@ -124,7 +124,7 @@ protected: scalar checkUniformTimeStep ( const scalarList& times - ) const; + ) const; //- Find and return start time index label findStartTimeIndex @@ -139,7 +139,7 @@ public: //- Runtime type information TypeName("noiseModel"); - //- Run time selection table + //- Run time selection table declareRunTimeSelectionTable ( autoPtr, @@ -155,7 +155,7 @@ public: static autoPtr<noiseModel> New(const dictionary& dict); //- Constructor - noiseModel(const dictionary& dict); + noiseModel(const dictionary& dict, const bool readFields = true); //- Destructor virtual ~noiseModel(); @@ -163,6 +163,9 @@ public: // Public Member Functions + //- Read from dictionary + virtual bool read(const dictionary& dict); + //- Abstract call to calculate virtual void calculate() = 0; }; diff --git a/src/randomProcesses/noise/noiseModels/pointNoise/pointNoise.C b/src/randomProcesses/noise/noiseModels/pointNoise/pointNoise.C index fc03d0300330d2ff6bee5c98593cf154e69358f1..9838f7176cda9578697c786e7d4ed7ea685482a1 100644 --- a/src/randomProcesses/noise/noiseModels/pointNoise/pointNoise.C +++ b/src/randomProcesses/noise/noiseModels/pointNoise/pointNoise.C @@ -43,14 +43,12 @@ addToRunTimeSelectionTable(noiseModel, pointNoise, dictionary); void pointNoise::filterTimeData ( - const Function1Types::CSV<scalar>& pData, + const scalarField& t0, + const scalarField& p0, scalarField& t, scalarField& p -) +) const { - const scalarField t0(pData.x()); - const scalarField p0(pData.y()); - DynamicList<scalar> tf(t0.size()); DynamicList<scalar> pf(t0.size()); @@ -68,23 +66,15 @@ void pointNoise::filterTimeData } -// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // - -void pointNoise::calculate() +void pointNoise::processData(const Function1Types::CSV<scalar>& data) { - // Point data only handled by master - if (!Pstream::master()) - { - return; - } + Info<< "Reading data file " << data.fName() << endl; - Info<< "Reading data file" << endl; - - Function1Types::CSV<scalar> pData("pressure", dict_, "Data"); + const fileName fNameBase = data.fName().name(true); // Time and pressure history data scalarField t, p; - filterTimeData(pData, t, p); + filterTimeData(data.x(), data.y(), t, p); p *= rhoRef_; Info<< " read " << t.size() << " values" << nl << endl; @@ -96,7 +86,7 @@ void pointNoise::calculate() windowModelPtr_->validate(t.size()); const windowModel& win = windowModelPtr_(); const scalar deltaf = 1.0/(deltaT*win.nSamples()); - fileName outDir(fileName("postProcessing")/"noise"/typeName); + fileName outDir(fileName("postProcessing")/"noise"/typeName/fNameBase); // Create the fft noiseFFT nfft(deltaT, p); @@ -185,12 +175,45 @@ void pointNoise::calculate() } +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +void pointNoise::calculate() +{ + // Point data only handled by master + if (!Pstream::master()) + { + return; + } + + + if (inputFileNames_.size()) + { + forAll(inputFileNames_, i) + { + const fileName fName = inputFileNames_[i].expand(); + Function1Types::CSV<scalar> data("pressure", dict_, "Data", fName); + processData(data); + } + } + else + { + Function1Types::CSV<scalar> data("pressure", dict_, "Data"); + processData(data); + } +} + + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // -pointNoise::pointNoise(const dictionary& dict) +pointNoise::pointNoise(const dictionary& dict, const bool readFields) : noiseModel(dict) -{} +{ + if (readFields) + { + read(dict); + } +} // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // @@ -199,6 +222,18 @@ pointNoise::~pointNoise() {} +bool pointNoise::read(const dictionary& dict) +{ + if (noiseModel::read(dict)) + { + dict.readIfPresent("inputFiles", inputFileNames_); + return true; + } + + return false; +} + + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } // End namespace noiseModels diff --git a/src/randomProcesses/noise/noiseModels/pointNoise/pointNoise.H b/src/randomProcesses/noise/noiseModels/pointNoise/pointNoise.H index 30bc669ae96433c3ba8cf689afb9304a79a21067..374678487f5089f83ec31bcdd7009a5372cf77de 100644 --- a/src/randomProcesses/noise/noiseModels/pointNoise/pointNoise.H +++ b/src/randomProcesses/noise/noiseModels/pointNoise/pointNoise.H @@ -76,8 +76,8 @@ SeeAlso \*---------------------------------------------------------------------------*/ -#ifndef pointNoise_H -#define pointNoise_H +#ifndef noiseModels_pointNoise_H +#define noiseModels_pointNoise_H #include "noiseModel.H" #include "CSV.H" @@ -100,14 +100,24 @@ class pointNoise protected: + // Protected data + + //- Input file names - optional + List<fileName> inputFileNames_; + + // Protected Member Functions void filterTimeData ( - const Function1Types::CSV<scalar>& pData, + const scalarField& t0, + const scalarField& p0, scalarField& t, scalarField& p - ); + ) const; + + //- Process the CSV data + void processData(const Function1Types::CSV<scalar>& data); public: @@ -116,7 +126,7 @@ public: TypeName("pointNoise"); //- Constructor - pointNoise(const dictionary& dict); + pointNoise(const dictionary& dict, const bool readFields = true); //- Destructor virtual ~pointNoise(); @@ -124,6 +134,9 @@ public: // Public Member Functions + //- Read from dictionary + virtual bool read(const dictionary& dict); + //- Calculate virtual void calculate(); diff --git a/src/randomProcesses/noise/noiseModels/surfaceNoise/surfaceNoise.C b/src/randomProcesses/noise/noiseModels/surfaceNoise/surfaceNoise.C index 69cb1713c10267e95901c9dd5e889a2143cda64d..1ff7e53ee74de1eca1632815ee6463abef8ee5d3 100644 --- a/src/randomProcesses/noise/noiseModels/surfaceNoise/surfaceNoise.C +++ b/src/randomProcesses/noise/noiseModels/surfaceNoise/surfaceNoise.C @@ -44,12 +44,9 @@ addToRunTimeSelectionTable(noiseModel, surfaceNoise, dictionary); // * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * // -void surfaceNoise::initialise(const dictionary& dict) +void surfaceNoise::initialise(const fileName& fName) { - dict.lookup("inputFile") >> inputFileName_; - inputFileName_.expand(); - - dict.readIfPresent("fftWriteInterval", fftWriteInterval_); + Info<< "Reading data file " << fName << endl; label nAvailableTimes = 0; @@ -57,17 +54,15 @@ void surfaceNoise::initialise(const dictionary& dict) if (Pstream::master()) { // Create the surface reader - const word readerType(dict.lookup("reader")); - readerPtr_.reset(surfaceReader::New(readerType, inputFileName_).ptr()); + readerPtr_ = surfaceReader::New(readerType_, fName); // Find the index of the pressure data - const word pName(dict.lookupOrDefault<word>("p", "p")); const List<word> fieldNames(readerPtr_->fieldNames(0)); - pIndex_ = findIndex(fieldNames, pName); + pIndex_ = findIndex(fieldNames, pName_); if (pIndex_ == -1) { FatalErrorInFunction - << "Unable to find pressure field name " << pName + << "Unable to find pressure field name " << pName_ << " in list of available fields: " << fieldNames << exit(FatalError); } @@ -76,12 +71,6 @@ void surfaceNoise::initialise(const dictionary& dict) // - Could be done later, but since this utility can process a lot of // data we can ensure that the user-input is correct prior to doing // the heavy lifting - const word writerType(dict.lookup("writer")); - dictionary optDict - ( - dict.subOrEmptyDict("writeOptions").subOrEmptyDict(writerType) - ); - writerPtr_.reset(surfaceWriter::New(writerType, optDict).ptr()); // Set the time range const instantList allTimes = readerPtr_->times(); @@ -404,18 +393,25 @@ Foam::scalar surfaceNoise::surfaceAverage // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // -surfaceNoise::surfaceNoise(const dictionary& dict) +surfaceNoise::surfaceNoise(const dictionary& dict, const bool readFields) : - noiseModel(dict), - inputFileName_("unknown-inputFile"), + noiseModel(dict, false), + inputFileNames_(), + pName_("p"), pIndex_(0), times_(), deltaT_(0), startTimeIndex_(0), nFace_(0), - fftWriteInterval_(1) + fftWriteInterval_(1), + readerType_(word::null), + readerPtr_(nullptr), + writerPtr_(nullptr) { - initialise(dict); + if (readFields) + { + read(dict); + } } @@ -427,271 +423,316 @@ surfaceNoise::~surfaceNoise() // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -void surfaceNoise::calculate() +bool surfaceNoise::read(const dictionary& dict) { - // Container for pressure time history data per face - List<scalarField> pData; - - // Processor procFaceOffsets - labelList procFaceOffset; - if (Pstream::parRun()) + if (noiseModel::read(dict)) { - const label nProcs = Pstream::nProcs(); - const label nFacePerProc = floor(nFace_/nProcs) + 1; - - procFaceOffset.setSize(nProcs + 1, 0); - for (label i = 1; i < procFaceOffset.size(); i++) + if (dict.found("inputFile")) { - procFaceOffset[i] = min(i*nFacePerProc, nFace_); + inputFileNames_.setSize(1); + dict.lookup("inputFile") >> inputFileNames_[0]; + } + else + { + dict.lookup("inputFiles") >> inputFileNames_; } - } - else - { - procFaceOffset.setSize(1, nFace_); - } - // Read pressure data from file - readSurfaceData(procFaceOffset, pData); + dict.readIfPresent("fftWriteInterval", fftWriteInterval_); + dict.readIfPresent("p", pName_); - // Process the pressure data, and store results as surface values per - // frequency so that it can be output using the surface writer + dict.lookup("reader") >> readerType_; - Info<< "Creating noise FFTs" << endl; + word writerType(dict.lookup("writer")); + dictionary optDict + ( + dict.subOrEmptyDict("writeOptions").subOrEmptyDict(writerType) + ); - // Storage for FFT data - const label nLocalFace = pData.size(); - const scalarField freq1(noiseFFT::frequencies(nSamples_, deltaT_)); - const label nFFT = freq1.size()/fftWriteInterval_; - List<scalarField> surfPrmsf(nFFT); - List<scalarField> surfPSDf(nFFT); - forAll(surfPrmsf, freqI) - { - surfPrmsf[freqI].setSize(nLocalFace); - surfPSDf[freqI].setSize(nLocalFace); + writerPtr_ = surfaceWriter::New(writerType, optDict); + + return true; } - // Storage for 1/3 octave data - labelList octave13BandIDs; - scalarField octave13FreqCentre; - noiseFFT::octaveBandInfo - ( - freq1, - fLower_, - fUpper_, - 3, - octave13BandIDs, - octave13FreqCentre - ); + return false; +} - label bandSize = 0; - if (octave13BandIDs.empty()) - { - WarningInFunction - << "Ocatve band calculation failed (zero sized). " - << "please check your input data" - << endl; - } - else - { - bandSize = octave13BandIDs.size() - 1; - } - List<scalarField> surfPSD13f(bandSize); - List<scalarField> surfPrms13f2(bandSize); - forAll(surfPSD13f, freqI) +void surfaceNoise::calculate() +{ + forAll(inputFileNames_, i) { - surfPSD13f[freqI].setSize(nLocalFace); - surfPrms13f2[freqI].setSize(nLocalFace); - } + fileName fName = inputFileNames_[i]; - const windowModel& win = windowModelPtr_(); + initialise(fName.expand()); - forAll(pData, faceI) - { - const scalarField& p = pData[faceI]; + // Container for pressure time history data per face + List<scalarField> pData; - noiseFFT nfft(deltaT_, p); - graph Prmsf(nfft.RMSmeanPf(win)); - graph PSDf(nfft.PSDf(win)); + // Processor procFaceOffsets + labelList procFaceOffset; + if (Pstream::parRun()) + { + const label nProcs = Pstream::nProcs(); + const label nFacePerProc = floor(nFace_/nProcs) + 1; - // Store the frequency results in slot for face of surface - forAll(surfPrmsf, i) + procFaceOffset.setSize(nProcs + 1, 0); + for (label i = 1; i < procFaceOffset.size(); i++) + { + procFaceOffset[i] = min(i*nFacePerProc, nFace_); + } + } + else { - label freqI = (i + 1)*fftWriteInterval_ - 1; - surfPrmsf[i][faceI] = Prmsf.y()[freqI]; - surfPSDf[i][faceI] = PSDf.y()[freqI]; + procFaceOffset.setSize(1, nFace_); } - // PSD [Pa^2/Hz] - graph PSD13f(nfft.octaves(PSDf, octave13BandIDs, false)); + // Read pressure data from file + readSurfaceData(procFaceOffset, pData); - // Integrated PSD = P(rms)^2 [Pa^2] - graph Prms13f2(nfft.octaves(PSDf, octave13BandIDs, true)); + // Process the pressure data, and store results as surface values per + // frequency so that it can be output using the surface writer - // Store the 1/3 octave results in slot for face of surface - forAll(surfPSD13f, freqI) + Info<< "Creating noise FFTs" << endl; + + // Storage for FFT data + const label nLocalFace = pData.size(); + const scalarField freq1(noiseFFT::frequencies(nSamples_, deltaT_)); + const label nFFT = freq1.size()/fftWriteInterval_; + List<scalarField> surfPrmsf(nFFT); + List<scalarField> surfPSDf(nFFT); + forAll(surfPrmsf, freqI) { - surfPSD13f[freqI][faceI] = PSD13f.y()[freqI]; - surfPrms13f2[freqI][faceI] = Prms13f2.y()[freqI]; + surfPrmsf[freqI].setSize(nLocalFace); + surfPSDf[freqI].setSize(nLocalFace); } - } - - // Output directory for graphs - fileName outDir(fileName("postProcessing")/"noise"/typeName); - const scalar deltaf = 1.0/(deltaT_*win.nSamples()); - Info<< "Writing fft surface data" << endl; - { - scalarField PrmsfAve(surfPrmsf.size(), 0); - scalarField PSDfAve(surfPrmsf.size(), 0); - scalarField fOut(surfPrmsf.size(), 0); + // Storage for 1/3 octave data + labelList octave13BandIDs; + scalarField octave13FreqCentre; + noiseFFT::octaveBandInfo + ( + freq1, + fLower_, + fUpper_, + 3, + octave13BandIDs, + octave13FreqCentre + ); - forAll(surfPrmsf, i) + label bandSize = 0; + if (octave13BandIDs.empty()) { - label freqI = i*fftWriteInterval_; - fOut[i] = freq1[freqI]; - const word& fName = inputFileName_.name(true); - const word gName = "fft"; - PrmsfAve[i] = writeSurfaceData - ( - fName, - gName, - "Prmsf", - freq1[freqI], - surfPrmsf[i], - procFaceOffset - ); + WarningInFunction + << "Ocatve band calculation failed (zero sized). " + << "please check your input data" + << endl; + } + else + { + bandSize = octave13BandIDs.size() - 1; + } - PSDfAve[i] = writeSurfaceData - ( - fName, - gName, - "PSDf", - freq1[freqI], - surfPSDf[i], - procFaceOffset - ); - writeSurfaceData - ( - fName, - gName, - "PSD", - freq1[freqI], - noiseFFT::PSD(surfPSDf[i]), - procFaceOffset - ); - writeSurfaceData - ( - fName, - gName, - "SPL", - freq1[freqI], - noiseFFT::SPL(surfPSDf[i]*deltaf), - procFaceOffset - ); + List<scalarField> surfPSD13f(bandSize); + List<scalarField> surfPrms13f2(bandSize); + forAll(surfPSD13f, freqI) + { + surfPSD13f[freqI].setSize(nLocalFace); + surfPrms13f2[freqI].setSize(nLocalFace); } - graph Prmsfg - ( - "Average Prms(f)", - "f [Hz]", - "P(f) [Pa]", - fOut, - PrmsfAve - ); - Prmsfg.write(outDir, graph::wordify(Prmsfg.title()), graphFormat_); + const windowModel& win = windowModelPtr_(); - graph PSDfg - ( - "Average PSD_f(f)", - "f [Hz]", - "PSD(f) [PaPa_Hz]", - fOut, - PSDfAve - ); - PSDfg.write(outDir, graph::wordify(PSDfg.title()), graphFormat_); + forAll(pData, faceI) + { + const scalarField& p = pData[faceI]; - graph PSDg - ( - "Average PSD_dB_Hz(f)", - "f [Hz]", - "PSD(f) [dB_Hz]", - fOut, - noiseFFT::PSD(PSDfAve) - ); - PSDg.write(outDir, graph::wordify(PSDg.title()), graphFormat_); + noiseFFT nfft(deltaT_, p); + graph Prmsf(nfft.RMSmeanPf(win)); + graph PSDf(nfft.PSDf(win)); - graph SPLg + // Store the frequency results in slot for face of surface + forAll(surfPrmsf, i) + { + label freqI = (i + 1)*fftWriteInterval_ - 1; + surfPrmsf[i][faceI] = Prmsf.y()[freqI]; + surfPSDf[i][faceI] = PSDf.y()[freqI]; + } + + // PSD [Pa^2/Hz] + graph PSD13f(nfft.octaves(PSDf, octave13BandIDs, false)); + + // Integrated PSD = P(rms)^2 [Pa^2] + graph Prms13f2(nfft.octaves(PSDf, octave13BandIDs, true)); + + // Store the 1/3 octave results in slot for face of surface + forAll(surfPSD13f, freqI) + { + surfPSD13f[freqI][faceI] = PSD13f.y()[freqI]; + surfPrms13f2[freqI][faceI] = Prms13f2.y()[freqI]; + } + } + + const word& fNameBase = fName.name(true); + + // Output directory for graphs + fileName outDir ( - "Average SPL_dB(f)", - "f [Hz]", - "SPL(f) [dB]", - fOut, - noiseFFT::SPL(PSDfAve*deltaf) + fileName("postProcessing")/"noise"/typeName/fNameBase ); - SPLg.write(outDir, graph::wordify(SPLg.title()), graphFormat_); - } + const scalar deltaf = 1.0/(deltaT_*win.nSamples()); + Info<< "Writing fft surface data" << endl; + { + scalarField PrmsfAve(surfPrmsf.size(), 0); + scalarField PSDfAve(surfPrmsf.size(), 0); + scalarField fOut(surfPrmsf.size(), 0); - Info<< "Writing one-third octave surface data" << endl; - { - scalarField PSDfAve(surfPSD13f.size(), 0); - scalarField Prms13f2Ave(surfPSD13f.size(), 0); + forAll(surfPrmsf, i) + { + label freqI = i*fftWriteInterval_; + fOut[i] = freq1[freqI]; + const word gName = "fft"; + PrmsfAve[i] = writeSurfaceData + ( + fNameBase, + gName, + "Prmsf", + freq1[freqI], + surfPrmsf[i], + procFaceOffset + ); + + PSDfAve[i] = writeSurfaceData + ( + fNameBase, + gName, + "PSDf", + freq1[freqI], + surfPSDf[i], + procFaceOffset + ); + writeSurfaceData + ( + fNameBase, + gName, + "PSD", + freq1[freqI], + noiseFFT::PSD(surfPSDf[i]), + procFaceOffset + ); + writeSurfaceData + ( + fNameBase, + gName, + "SPL", + freq1[freqI], + noiseFFT::SPL(surfPSDf[i]*deltaf), + procFaceOffset + ); + } - forAll(surfPSD13f, i) - { - const word& fName = inputFileName_.name(true); - const word gName = "oneThirdOctave"; - PSDfAve[i] = writeSurfaceData + graph Prmsfg ( - fName, - gName, - "PSD13f", - octave13FreqCentre[i], - surfPSD13f[i], - procFaceOffset + "Average Prms(f)", + "f [Hz]", + "P(f) [Pa]", + fOut, + PrmsfAve ); - writeSurfaceData + Prmsfg.write(outDir, graph::wordify(Prmsfg.title()), graphFormat_); + + graph PSDfg ( - fName, - gName, - "PSD13", - octave13FreqCentre[i], - noiseFFT::PSD(surfPSD13f[i]), - procFaceOffset + "Average PSD_f(f)", + "f [Hz]", + "PSD(f) [PaPa_Hz]", + fOut, + PSDfAve ); - writeSurfaceData + PSDfg.write(outDir, graph::wordify(PSDfg.title()), graphFormat_); + + graph PSDg ( - fName, - gName, - "SPL13", - octave13FreqCentre[i], - noiseFFT::SPL(surfPrms13f2[i]), - procFaceOffset + "Average PSD_dB_Hz(f)", + "f [Hz]", + "PSD(f) [dB_Hz]", + fOut, + noiseFFT::PSD(PSDfAve) ); + PSDg.write(outDir, graph::wordify(PSDg.title()), graphFormat_); - Prms13f2Ave[i] = surfaceAverage(surfPrms13f2[i], procFaceOffset); + graph SPLg + ( + "Average SPL_dB(f)", + "f [Hz]", + "SPL(f) [dB]", + fOut, + noiseFFT::SPL(PSDfAve*deltaf) + ); + SPLg.write(outDir, graph::wordify(SPLg.title()), graphFormat_); } - graph PSD13g - ( - "Average PSD13_dB_Hz(fm)", - "fm [Hz]", - "PSD(fm) [dB_Hz]", - octave13FreqCentre, - noiseFFT::PSD(PSDfAve) - ); - PSD13g.write(outDir, graph::wordify(PSD13g.title()), graphFormat_); - graph SPL13g - ( - "Average SPL13_dB(fm)", - "fm [Hz]", - "SPL(fm) [dB]", - octave13FreqCentre, - noiseFFT::SPL(Prms13f2Ave) - ); - SPL13g.write(outDir, graph::wordify(SPL13g.title()), graphFormat_); + Info<< "Writing one-third octave surface data" << endl; + { + scalarField PSDfAve(surfPSD13f.size(), 0); + scalarField Prms13f2Ave(surfPSD13f.size(), 0); + + forAll(surfPSD13f, i) + { + const word gName = "oneThirdOctave"; + PSDfAve[i] = writeSurfaceData + ( + fNameBase, + gName, + "PSD13f", + octave13FreqCentre[i], + surfPSD13f[i], + procFaceOffset + ); + writeSurfaceData + ( + fNameBase, + gName, + "PSD13", + octave13FreqCentre[i], + noiseFFT::PSD(surfPSD13f[i]), + procFaceOffset + ); + writeSurfaceData + ( + fNameBase, + gName, + "SPL13", + octave13FreqCentre[i], + noiseFFT::SPL(surfPrms13f2[i]), + procFaceOffset + ); + + Prms13f2Ave[i] = + surfaceAverage(surfPrms13f2[i], procFaceOffset); + } + + graph PSD13g + ( + "Average PSD13_dB_Hz(fm)", + "fm [Hz]", + "PSD(fm) [dB_Hz]", + octave13FreqCentre, + noiseFFT::PSD(PSDfAve) + ); + PSD13g.write(outDir, graph::wordify(PSD13g.title()), graphFormat_); + + graph SPL13g + ( + "Average SPL13_dB(fm)", + "fm [Hz]", + "SPL(fm) [dB]", + octave13FreqCentre, + noiseFFT::SPL(Prms13f2Ave) + ); + SPL13g.write(outDir, graph::wordify(SPL13g.title()), graphFormat_); + } } } diff --git a/src/randomProcesses/noise/noiseModels/surfaceNoise/surfaceNoise.H b/src/randomProcesses/noise/noiseModels/surfaceNoise/surfaceNoise.H index 054944a1589765e455b203e958fb4a199842d58b..165a1cefd77963b882d10c4d44285eaa79c6258e 100644 --- a/src/randomProcesses/noise/noiseModels/surfaceNoise/surfaceNoise.H +++ b/src/randomProcesses/noise/noiseModels/surfaceNoise/surfaceNoise.H @@ -53,7 +53,7 @@ Description } // Input file - inputFile "postProcessing/faceSource1/surface/patch/patch.case"; + inputFiles ("postProcessing/faceSource1/surface/patch/patch.case"); // Write interval for FFT data, default = 1 fftWriteInterval 100; @@ -83,8 +83,8 @@ SeeAlso \*---------------------------------------------------------------------------*/ -#ifndef surfaceNoise_H -#define surfaceNoise_H +#ifndef noiseModels_surfaceNoise_H +#define noiseModels_surfaceNoise_H #include "noiseModel.H" #include "labelList.H" @@ -115,8 +115,11 @@ protected: // Protected Data - //- Input file name - fileName inputFileName_; + //- Input file names + List<fileName> inputFileNames_; + + //- Name of pressure field + word pName_; //- Index of pressure field in reader field list label pIndex_; @@ -138,17 +141,20 @@ protected: // result in a very large number of output files (1 per frequency) label fftWriteInterval_; + //- Reader type + word readerType_; + //- Pointer to the surface reader mutable autoPtr<surfaceReader> readerPtr_; //- Pointer to the surface writer - autoPtr<surfaceWriter> writerPtr_; + mutable autoPtr<surfaceWriter> writerPtr_; // Protected Member Functions //- Initialise - void initialise(const dictionary& dict); + void initialise(const fileName& fName); //- Read surface data void readSurfaceData @@ -183,7 +189,7 @@ public: TypeName("surfaceNoise"); //- Constructor - surfaceNoise(const dictionary& dict); + surfaceNoise(const dictionary& dict, const bool readFields = true); //- Destructor virtual ~surfaceNoise(); @@ -191,6 +197,9 @@ public: // Public Member Functions + //- Read from dictionary + virtual bool read(const dictionary& dict); + //- Calculate virtual void calculate(); };