streamLine: Added option to track in both directions

Streamlines can now be tracked in both directions from the set of
initial locations. The keyword controlling this behaviour is
"direction", which can be set to "forward", "backward" or "both".

This new keyword superseeds the "trackForward" entry, which has been
retained for backwards compatibility.
This commit is contained in:
Will Bainbridge
2018-04-06 16:46:12 +01:00
parent 7ea428af52
commit 8dcfc9e9f8
8 changed files with 66 additions and 16 deletions

View File

@ -13,7 +13,7 @@ executeControl writeTime;
writeControl writeTime; writeControl writeTime;
setFormat vtk; setFormat vtk;
trackForward true; direction forward;
lifeTime 10000; lifeTime 10000;
nSubCycle 5; nSubCycle 5;

View File

@ -45,6 +45,13 @@ namespace functionObjects
{ {
defineTypeNameAndDebug(streamLine, 0); defineTypeNameAndDebug(streamLine, 0);
addToRunTimeSelectionTable(functionObject, streamLine, dictionary); addToRunTimeSelectionTable(functionObject, streamLine, dictionary);
template<>
const char* NamedEnum<streamLine::trackDirection, 3>::names[] =
{"forward", "backward", "both"};
const NamedEnum<streamLine::trackDirection, 3>
streamLine::trackDirectionNames_;
} }
} }
@ -257,7 +264,9 @@ void Foam::functionObjects::streamLine::track()
vsInterp, vsInterp,
vvInterp, vvInterp,
UIndex, // index of U in vvInterp UIndex, // index of U in vvInterp
trackForward_, // track in +u direction?
trackDirection_ == trackDirection::FORWARD,
nSubCycle_, // automatic track control:step through cells in steps? nSubCycle_, // automatic track control:step through cells in steps?
trackLength_, // fixed track length trackLength_, // fixed track length
@ -266,13 +275,24 @@ void Foam::functionObjects::streamLine::track()
allVectors_ allVectors_
); );
// Set very large dt. Note: cannot use great since 1/great is small // Set very large dt. Note: cannot use great since 1/great is small
// which is a trigger value for the tracking... // which is a trigger value for the tracking...
const scalar trackTime = Foam::sqrt(great); const scalar trackTime = Foam::sqrt(great);
// Track // Track
if (trackDirection_ == trackDirection::BOTH)
{
initialParticles = particles;
}
particles.move(particles, td, trackTime); particles.move(particles, td, trackTime);
if (trackDirection_ == trackDirection::BOTH)
{
particles.IDLList<streamLineParticle>::operator=(initialParticles);
td.trackForward_ = !td.trackForward_;
particles.move(particles, td, trackTime);
}
} }
@ -321,8 +341,19 @@ bool Foam::functionObjects::streamLine::read(const dictionary& dict)
<< exit(FatalIOError); << exit(FatalIOError);
} }
// The trackForward entry is maintained here for backwards compatibility
if (!dict.found("direction") && dict.found("trackForward"))
{
trackDirection_ =
dict.lookupType<bool>("trackForward")
? trackDirection::FORWARD
: trackDirection::BACKWARD;
}
else
{
trackDirection_ = trackDirectionNames_[word(dict.lookup("direction"))];
}
dict.lookup("trackForward") >> trackForward_;
dict.lookup("lifeTime") >> lifeTime_; dict.lookup("lifeTime") >> lifeTime_;
if (lifeTime_ < 1) if (lifeTime_ < 1)
{ {

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -112,6 +112,7 @@ SourceFiles
#include "vectorList.H" #include "vectorList.H"
#include "writer.H" #include "writer.H"
#include "indirectPrimitivePatch.H" #include "indirectPrimitivePatch.H"
#include "NamedEnum.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -133,6 +134,24 @@ class streamLine
: :
public fvMeshFunctionObject public fvMeshFunctionObject
{ {
public:
// Public data types
//- Track direction enumerations
enum trackDirection
{
FORWARD,
BACKWARD,
BOTH
};
//- Track direction enumeration names
static const NamedEnum<trackDirection, 3> trackDirectionNames_;
private:
// Private data // Private data
//- Input dictionary //- Input dictionary
@ -147,8 +166,8 @@ class streamLine
//- Interpolation scheme to use //- Interpolation scheme to use
word interpolationScheme_; word interpolationScheme_;
//- Whether to use +u or -u //- The direction in which to track
bool trackForward_; trackDirection trackDirection_;
//- Maximum lifetime (= number of cells) of particle //- Maximum lifetime (= number of cells) of particle
label lifeTime_; label lifeTime_;

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -77,7 +77,7 @@ public:
const label UIndex_; const label UIndex_;
const bool trackForward_; bool trackForward_;
const label nSubCycle_; const label nSubCycle_;

View File

@ -54,7 +54,7 @@ functions
type streamLine; type streamLine;
writeControl writeTime; writeControl writeTime;
setFormat vtk; setFormat vtk;
trackForward true; direction forward;
fields (p U); fields (p U);
lifeTime 10000; lifeTime 10000;
nSubCycle 5; nSubCycle 5;

View File

@ -16,8 +16,8 @@ streamLines
setFormat vtk; //gnuplot; //xmgr; //raw; //jplot; //csv; //ensight; setFormat vtk; //gnuplot; //xmgr; //raw; //jplot; //csv; //ensight;
// Tracked forwards (+U) or backwards (-U) // Track forward (+U) or backward (-U) or both
trackForward true; direction forward;
// Names of fields to sample. Should contain above velocity field! // Names of fields to sample. Should contain above velocity field!
fields (p U); fields (p U);

View File

@ -19,8 +19,8 @@ streamLines
setFormat vtk; //gnuplot; //xmgr; //raw; //jplot; //csv; //ensight; setFormat vtk; //gnuplot; //xmgr; //raw; //jplot; //csv; //ensight;
// Tracked forwards (+U) or backwards (-U) // Track forward (+U) or backward (-U) or both
trackForward true; direction forward;
// Names of fields to sample. Should contain above velocity field! // Names of fields to sample. Should contain above velocity field!
fields (p U k); fields (p U k);

View File

@ -60,8 +60,8 @@ functions
setFormat vtk; //gnuplot;//xmgr;//raw;//jplot;//csv;//ensight; setFormat vtk; //gnuplot;//xmgr;//raw;//jplot;//csv;//ensight;
// Tracked forwards (+U) or backwards (-U) // Track forward (+U) or backward (-U) or both
trackForward true; direction forward;
// Names of fields to sample. Should contain above velocity field! // Names of fields to sample. Should contain above velocity field!
fields (p k U); fields (p k U);