From 39aa4f3a4e17000c4d8657dcce600a756d4e9fdd Mon Sep 17 00:00:00 2001 From: andy Date: Thu, 25 Feb 2016 12:54:17 +0000 Subject: [PATCH] ENH: Added new pointNoise model to process point data to replicate old behaviour --- .../noise/noiseModels/pointNoise/pointNoise.C | 151 ++++++++++++++++++ .../noise/noiseModels/pointNoise/pointNoise.H | 148 +++++++++++++++++ 2 files changed, 299 insertions(+) create mode 100644 src/randomProcesses/noise/noiseModels/pointNoise/pointNoise.C create mode 100644 src/randomProcesses/noise/noiseModels/pointNoise/pointNoise.H diff --git a/src/randomProcesses/noise/noiseModels/pointNoise/pointNoise.C b/src/randomProcesses/noise/noiseModels/pointNoise/pointNoise.C new file mode 100644 index 0000000000..2014d721e3 --- /dev/null +++ b/src/randomProcesses/noise/noiseModels/pointNoise/pointNoise.C @@ -0,0 +1,151 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2015-2016 OpenCFD Ltd. + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +\*---------------------------------------------------------------------------*/ + +#include "pointNoise.H" +#include "noiseFFT.H" +#include "addToRunTimeSelectionTable.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ +namespace noiseModels +{ + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +defineTypeNameAndDebug(pointNoise, 0); +addToRunTimeSelectionTable(noiseModel, pointNoise, dictionary); + +// * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * // + +void pointNoise::filterTimeData +( + const CSV& pData, + scalarField& t, + scalarField& p +) +{ + const scalarField t0(pData.x()); + const scalarField p0(pData.y()); + + DynamicList tf(t0.size()); + DynamicList pf(t0.size()); + + forAll(t0, timeI) + { + if (t0[timeI] >= startTime_) + { + tf.append(t0[timeI]); + pf.append(p0[timeI]); + } + } + + t.transfer(tf); + p.transfer(pf); +} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +void pointNoise::calculate() +{ + // Point data only handled by master + if (!Pstream::master()) + { + return; + } + + Info<< "Reading data file" << endl; + + CSV pData("pressure", dict_, "Data"); + fileName baseFileName(pData.fName().lessExt()); + + // Time and pressure history data + scalarField t, p; + filterTimeData(pData, t, p); + Info<< " read " << t.size() << " values" << nl << endl; + + Info<< "Creating noise FFT" << endl; + const scalar deltaT = checkUniformTimeStep(t); + + // Determine the windowing + windowModelPtr_->validate(t.size()); + + // Create the fft + noiseFFT nfft(deltaT, p); + + nfft -= pRef_; + + graph Pf(nfft.RMSmeanPf(windowModelPtr_())); + Info<< " Creating graph for " << Pf.title() << endl; + Pf.write(baseFileName + graph::wordify(Pf.title()), graphFormat_); + + graph Lf(nfft.Lf(Pf)); + Info<< " Creating graph for " << Lf.title() << endl; + Lf.write(baseFileName + graph::wordify(Lf.title()), graphFormat_); + + graph PSDf(nfft.PSDf(windowModelPtr_())); + Info<< " Creating graph for " << PSDf.title() << endl; + PSDf.write(baseFileName + graph::wordify(PSDf.title()), graphFormat_); + + graph PSD(nfft.PSD(PSDf)); + Info<< " Creating graph for " << PSD.title() << endl; + PSD.write(baseFileName + graph::wordify(PSD.title()), graphFormat_); + + labelList octave13BandIDs; + noiseFFT::octaveFrequenciesIDs(Pf.x(), fLower_, fUpper_, 3, octave13BandIDs); + + graph Ldelta(nfft.Ldelta(Lf, octave13BandIDs)); + Info<< " Creating graph for " << Ldelta.title() << endl; + Ldelta.write(baseFileName + graph::wordify(Ldelta.title()), graphFormat_); + + graph Pdelta(nfft.Pdelta(Pf, octave13BandIDs)); + Info<< " Creating graph for " << Pdelta.title() << endl; + Pdelta.write(baseFileName + graph::wordify(Pdelta.title()), graphFormat_); +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +pointNoise::pointNoise(const dictionary& dict) +: + noiseModel(dict), + graphFormat_(dict.lookupOrDefault("graphFormat", "raw")) +{} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +pointNoise::~pointNoise() +{} + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace noiseModels +} // End namespace Foam + +// ************************************************************************* // diff --git a/src/randomProcesses/noise/noiseModels/pointNoise/pointNoise.H b/src/randomProcesses/noise/noiseModels/pointNoise/pointNoise.H new file mode 100644 index 0000000000..020e462238 --- /dev/null +++ b/src/randomProcesses/noise/noiseModels/pointNoise/pointNoise.H @@ -0,0 +1,148 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2015-2016 OpenCFD Ltd. + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +Class + Foam::noiseModels::pointNoise + +Description + Perform noise analysis on point-based pressure data. + + Input data is read from a dictionary, e.g. + + \verbatim + // Pressure reference + pRef 0; + + // Number of samples in sampling window + // Must be a power of 2, default = 2^16 (=65536) + N 4096; + + // Lower frequency bounds + fl 25; + + // Upper frequency bounds + fu 25; + + // Start time + startTime 0; + + windowModel + Coeffs + { + ... + } + + // Pressure data supplied in CSV file format + csvFileData + { + fileName "pressureData"; + nHeaderLine 1; + refColumn 0; + componentColumns (1); + separator " "; + mergeSeparators yes; + } + + graphFormat raw; + + \endverbatim + +SourceFiles + pointNoise.C + +SeeAlso + noiseModel.H + windowModel.H + +\*---------------------------------------------------------------------------*/ + +#ifndef pointNoise_H +#define pointNoise_H + +#include "noiseModel.H" +#include "CSV.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ +namespace noiseModels +{ + +/*---------------------------------------------------------------------------*\ + Class pointNoise Declaration +\*---------------------------------------------------------------------------*/ + +class pointNoise +: + public noiseModel +{ + +protected: + + // Protected data + + //- Graph format + word graphFormat_; + + + // Protected Member Functions + + void filterTimeData + ( + const CSV& pData, + scalarField& t, + scalarField& p + ); + + +public: + + //- Runtime type information + TypeName("pointNoise"); + + //- Constructor + pointNoise(const dictionary& dict); + + //- Destructor + virtual ~pointNoise(); + + + // Public Member Functions + + //- Calculate + virtual void calculate(); + +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace noiseModels +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* //