Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a postprocessing util to get time series. #592

Merged
merged 1 commit into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/utilities/postProcessing/getTimeSeries/Make/files
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
getTimeSeries.C

EXE = $(DAFOAM_ROOT_PATH)/OpenFOAM/sharedBins/getTimeSeries
12 changes: 12 additions & 0 deletions src/utilities/postProcessing/getTimeSeries/Make/options
Original file line number Diff line number Diff line change
@@ -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

143 changes: 143 additions & 0 deletions src/utilities/postProcessing/getTimeSeries/getTimeSeries.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
/*---------------------------------------------------------------------------*\

DAFoam : Discrete Adjoint with OpenFOAM
Version : v3

Description:
Extract time-series data 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(
"coords",
"'(0 0 1)'",
"probe point coordinates");

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(
"outputName",
"VarTimeSeries",
"name of the output file (optional)");

#include "setRootCase.H"
#include "createTime.H"
#include "createMesh.H"

word outputName = "VarTimeSeries";
if (args.optionFound("outputName"))
{
outputName = word(args.optionLookup("outputName")());
}

List<scalar> coords;
if (args.optionFound("coords"))
{
coords = scalarList(args.optionLookup("coords")());
}
else
{
Info << "Error: coords not set! Exit." << endl;
return 1;
}
point coordPoint = {coords[0], coords[1], coords[2]};
label probeCellI = mesh.findCell(coordPoint);

word varName;
if (args.optionFound("varName"))
{
varName = word(args.optionLookup("varName")());
}
else
{
Info << "Error: varName not set! Exit." << endl;
return 1;
}

word varType;
if (args.optionFound("varType"))
{
varType = word(args.optionLookup("varType")());
}
else
{
Info << "Error: varType not set! Exit." << endl;
return 1;
}

if (probeCellI < 0)
{
Info << "Error: coords " << coords << " are not within a cell! Exit." << endl;
return 1;
}

if (varType != "scalar" && varType != "vector")
{
Info << "Error: varType = " << varType << " is not supported. The options are either scalar or vector " << endl;
}

OFstream f(outputName + ".txt");

scalar endTime = runTime.endTime().value();
scalar deltaT = runTime.deltaT().value();
label nSteps = round(endTime / deltaT);

for (label i = 0; i < nSteps; i++)
{
word timeName = Foam::name(i * deltaT);

if (varType == "vector")
{
volVectorField var(
IOobject(
varName,
timeName,
mesh,
IOobject::MUST_READ,
IOobject::NO_WRITE),
mesh);

f << var[probeCellI][0] << " " << var[probeCellI][1] << " " << var[probeCellI][2] << endl;
}
else if (varType == "scalar")
{
volScalarField var(
IOobject(
varName,
timeName,
mesh,
IOobject::MUST_READ,
IOobject::NO_WRITE),
mesh);

f << var[probeCellI] << endl;
}
}

Info << "Done! " << endl;

return 0;
}

// ************************************************************************* //
Loading