diff --git a/src/utilities/postProcessing/getFieldRefStdTimeSeries/Make/files b/src/utilities/postProcessing/getFieldRefStdTimeSeries/Make/files new file mode 100755 index 00000000..f55b668d --- /dev/null +++ b/src/utilities/postProcessing/getFieldRefStdTimeSeries/Make/files @@ -0,0 +1,3 @@ +getFieldRefStdTimeSeries.C + +EXE = $(DAFOAM_ROOT_PATH)/OpenFOAM/sharedBins/getFieldRefStdTimeSeries diff --git a/src/utilities/postProcessing/getTimeSeries/Make/options b/src/utilities/postProcessing/getFieldRefStdTimeSeries/Make/options similarity index 100% rename from src/utilities/postProcessing/getTimeSeries/Make/options rename to src/utilities/postProcessing/getFieldRefStdTimeSeries/Make/options diff --git a/src/utilities/postProcessing/getFieldRefStdTimeSeries/getFieldRefStdTimeSeries.C b/src/utilities/postProcessing/getFieldRefStdTimeSeries/getFieldRefStdTimeSeries.C new file mode 100755 index 00000000..0cda729f --- /dev/null +++ b/src/utilities/postProcessing/getFieldRefStdTimeSeries/getFieldRefStdTimeSeries.C @@ -0,0 +1,257 @@ +/*---------------------------------------------------------------------------*\ + + DAFoam : Discrete Adjoint with OpenFOAM + Version : v3 + + Description: + Extract time-series data at a given probe point for unsteady simulations + +\*---------------------------------------------------------------------------*/ + +#include "fvCFD.H" +#include "argList.H" +#include "Time.H" +#include "fvMesh.H" +#include "OFstream.H" + +using namespace Foam; + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +int main(int argc, char* argv[]) +{ + + argList::addOption( + "varName", + "U", + "name of the variable to get time-series from"); + + argList::addOption( + "varType", + "vector", + "type of the variable, can be either scalar or vector"); + + argList::addOption( + "fieldType", + "volume", + "type of the field variable, can be either volume or surface"); + + argList::addOption( + "patchName", + "wing", + "if the fieldType=surface, we need to prescribe the name of the patch"); + + argList::addOption( + "outputName", + "fieldRefStdTimeSeries", + "name of the output file (optional)"); + + argList::addOption( + "deltaT", + "-1", + "Use user-prescribed deltaT to extract time series, otherwise, use the deltaT in controlDict"); + +#include "setRootCase.H" +#include "createTime.H" +#include "createMesh.H" + + word outputName = "fieldRefStdTimeSeries"; + if (args.optionFound("outputName")) + { + outputName = word(args.optionLookup("outputName")()); + } + + word varName; + if (args.optionFound("varName")) + { + varName = word(args.optionLookup("varName")()); + } + else + { + Info << "Error: varName not set! Exit." << endl; + return 1; + } + + word varRefName = varName + "Data"; + + word varType; + if (args.optionFound("varType")) + { + varType = word(args.optionLookup("varType")()); + } + else + { + Info << "Error: varType not set! Exit." << endl; + return 1; + } + + word fieldType; + if (args.optionFound("fieldType")) + { + fieldType = word(args.optionLookup("fieldType")()); + } + else + { + Info << "Error: fieldType not set! Exit." << endl; + return 1; + } + + word patchName; + if (fieldType == "surface") + { + if (args.optionFound("patchName")) + { + patchName = word(args.optionLookup("patchName")()); + } + else + { + Info << "Error: patchName not set! Exit." << endl; + return 1; + } + } + + OFstream f(outputName + ".txt"); + + scalar endTime = runTime.endTime().value(); + scalar deltaT = runTime.deltaT().value(); + + if (args.optionFound("deltaT")) + { + deltaT = readScalar(args.optionLookup("deltaT")()); + } + Info << "Extracting " << fieldType << " time series for " << varName << endl; + + label nSteps = round(endTime / deltaT); + + for (label i = 0; i < nSteps; i++) + { + word timeName = Foam::name((i + 1) * deltaT); + + if (varType == "vector") + { + volVectorField var( + IOobject( + varName, + timeName, + mesh, + IOobject::MUST_READ, + IOobject::NO_WRITE), + mesh); + + volVectorField varRef( + IOobject( + varRefName, + timeName, + mesh, + IOobject::MUST_READ, + IOobject::NO_WRITE), + mesh); + + vector std = vector::zero; + + if (fieldType == "volume") + { + + forAll(var, cellI) + { + for (label compI = 0; compI < 3; compI++) + { + std[compI] += (var[cellI][compI] - varRef[cellI][compI]) * (var[cellI][compI] - varRef[cellI][compI]); + } + } + + for (label compI = 0; compI < 3; compI++) + { + std[compI] = Foam::sqrt(std[compI] / mesh.nCells()); + } + } + else if (fieldType == "surface") + { + label patchI = mesh.boundaryMesh().findPatchID(patchName); + if (patchI < 0) + { + Info << "Error. The prescribed patchName " << patchName << " not found in constant/polyMesh/boundary" << endl; + } + label nFaces = var.boundaryField()[patchI].size(); + forAll(var.boundaryField()[patchI], faceI) + { + vector varBC = var.boundaryField()[patchI][faceI]; + vector varRefBC = varRef.boundaryField()[patchI][faceI]; + + for (label compI = 0; compI < 3; compI++) + { + std[compI] += (varBC[compI] - varRefBC[compI]) * (varBC[compI] - varRefBC[compI]); + } + } + + for (label compI = 0; compI < 3; compI++) + { + std[compI] = Foam::sqrt(std[compI] / nFaces); + } + } + + f << std[0] << " " << std[1] << " " << std[2] << endl; + } + else if (varType == "scalar") + { + volScalarField var( + IOobject( + varName, + timeName, + mesh, + IOobject::MUST_READ, + IOobject::NO_WRITE), + mesh); + + volScalarField varRef( + IOobject( + varRefName, + timeName, + mesh, + IOobject::MUST_READ, + IOobject::NO_WRITE), + mesh); + + scalar std = 0.0; + + if (fieldType == "volume") + { + forAll(var, cellI) + { + std += (var[cellI] - varRef[cellI]) * (var[cellI] - varRef[cellI]); + } + + std = Foam::sqrt(std / mesh.nCells()); + } + else if (fieldType == "surface") + { + label patchI = mesh.boundaryMesh().findPatchID(patchName); + if (patchI < 0) + { + Info << "Error. The prescribed patchName " << patchName << " not found in constant/polyMesh/boundary" << endl; + } + label nFaces = var.boundaryField()[patchI].size(); + forAll(var.boundaryField()[patchI], faceI) + { + scalar varBC = var.boundaryField()[patchI][faceI]; + scalar varRefBC = varRef.boundaryField()[patchI][faceI]; + std += (varBC - varRefBC) * (varBC - varRefBC); + } + + std = Foam::sqrt(std / nFaces); + } + + f << std << endl; + } + else + { + Info << "Error: varType not valid. Can be either scalar or vector! Exit." << endl; + } + } + + Info << "Done! " << endl; + + return 0; +} + +// ************************************************************************* // diff --git a/src/utilities/postProcessing/getProbeTimeSeries/Make/files b/src/utilities/postProcessing/getProbeTimeSeries/Make/files new file mode 100755 index 00000000..f778a83e --- /dev/null +++ b/src/utilities/postProcessing/getProbeTimeSeries/Make/files @@ -0,0 +1,3 @@ +getProbeTimeSeries.C + +EXE = $(DAFOAM_ROOT_PATH)/OpenFOAM/sharedBins/getProbeTimeSeries diff --git a/src/utilities/postProcessing/getProbeTimeSeries/Make/options b/src/utilities/postProcessing/getProbeTimeSeries/Make/options new file mode 100755 index 00000000..fcd18e59 --- /dev/null +++ b/src/utilities/postProcessing/getProbeTimeSeries/Make/options @@ -0,0 +1,12 @@ +EXE_INC = \ + -std=c++11 \ + -Wno-old-style-cast \ + -Wno-conversion-null \ + -Wno-deprecated-copy \ + -I$(LIB_SRC)/finiteVolume/lnInclude \ + -I$(LIB_SRC)/meshTools/lnInclude + +EXE_LIBS = \ + -lfiniteVolume \ + -lmeshTools + diff --git a/src/utilities/postProcessing/getTimeSeries/getTimeSeries.C b/src/utilities/postProcessing/getProbeTimeSeries/getProbeTimeSeries.C similarity index 89% rename from src/utilities/postProcessing/getTimeSeries/getTimeSeries.C rename to src/utilities/postProcessing/getProbeTimeSeries/getProbeTimeSeries.C index 783c98e0..bd54e52d 100755 --- a/src/utilities/postProcessing/getTimeSeries/getTimeSeries.C +++ b/src/utilities/postProcessing/getProbeTimeSeries/getProbeTimeSeries.C @@ -4,7 +4,7 @@ Version : v3 Description: - Extract time-series data for unsteady simulations + Extract time-series data at a given probe point for unsteady simulations \*---------------------------------------------------------------------------*/ @@ -41,6 +41,11 @@ int main(int argc, char* argv[]) "VarTimeSeries", "name of the output file (optional)"); + argList::addOption( + "deltaT", + "-1", + "Use user-prescribed deltaT to extract time series, otherwise, use the deltaT in controlDict"); + #include "setRootCase.H" #include "createTime.H" #include "createMesh.H" @@ -101,6 +106,13 @@ int main(int argc, char* argv[]) scalar endTime = runTime.endTime().value(); scalar deltaT = runTime.deltaT().value(); + + if (args.optionFound("deltaT")) + { + deltaT = readScalar(args.optionLookup("deltaT")()); + } + Info << "Extracting " << varName << " time series" << endl; + label nSteps = round(endTime / deltaT); for (label i = 0; i < nSteps; i++) diff --git a/src/utilities/postProcessing/getTimeSeries/Make/files b/src/utilities/postProcessing/getTimeSeries/Make/files deleted file mode 100755 index f6568c96..00000000 --- a/src/utilities/postProcessing/getTimeSeries/Make/files +++ /dev/null @@ -1,3 +0,0 @@ -getTimeSeries.C - -EXE = $(DAFOAM_ROOT_PATH)/OpenFOAM/sharedBins/getTimeSeries