ENH: streamline improvements

- barycentric coordinates in interpolation (instead of x/y/z)

- ease U (velocity) requirement.
  Needn't be named in the sampled fields.

- default tracking direction is 'forward'
This commit is contained in:
Mark Olesen
2022-07-05 16:01:17 +02:00
parent 71246b94b7
commit f16f3da645
24 changed files with 360 additions and 391 deletions

View File

@ -139,17 +139,16 @@ Foam::functionObjects::streamLineBase::wallPatch() const
}
void Foam::functionObjects::streamLineBase::initInterpolations
Foam::refPtr<Foam::interpolation<Foam::vector>>
Foam::functionObjects::streamLineBase::initInterpolations
(
const label nSeeds,
label& UIndex,
PtrList<volScalarField>& vsFlds,
PtrList<interpolation<scalar>>& vsInterp,
PtrList<volVectorField>& vvFlds,
PtrList<interpolation<vector>>& vvInterp
)
{
// Read fields
refPtr<interpolation<vector>> UInterp;
label nScalar = 0;
label nVector = 0;
@ -166,7 +165,7 @@ void Foam::functionObjects::streamLineBase::initInterpolations
else
{
FatalErrorInFunction
<< "Cannot find field " << fieldName << nl
<< "Cannot find scalar/vector field " << fieldName << nl
<< "Valid scalar fields: "
<< flatOutput(mesh_.sortedNames<volScalarField>()) << nl
<< "Valid vector fields: "
@ -174,9 +173,9 @@ void Foam::functionObjects::streamLineBase::initInterpolations
<< exit(FatalError);
}
}
vsInterp.setSize(nScalar);
vsInterp.resize(nScalar);
vvInterp.resize(nVector);
nScalar = 0;
vvInterp.setSize(nVector);
nVector = 0;
for (const word& fieldName : fields_)
@ -186,76 +185,77 @@ void Foam::functionObjects::streamLineBase::initInterpolations
const volScalarField& f = lookupObject<volScalarField>(fieldName);
vsInterp.set
(
nScalar++,
interpolation<scalar>::New
(
interpolationScheme_,
f
)
nScalar,
interpolation<scalar>::New(interpolationScheme_, f)
);
++nScalar;
}
else if (foundObject<volVectorField>(fieldName))
{
const volVectorField& f = lookupObject<volVectorField>(fieldName);
if (f.name() == UName_)
{
UIndex = nVector;
}
vvInterp.set
(
nVector++,
interpolation<vector>::New
(
interpolationScheme_,
f
)
nVector,
interpolation<vector>::New(interpolationScheme_, f)
);
if (f.name() == UName_)
{
// Velocity is part of sampled velocity fields
UInterp.cref(vvInterp[nVector]);
}
++nVector;
}
}
if (!UInterp)
{
// Velocity was not in sampled velocity fields
UInterp.reset
(
interpolation<vector>::New
(
interpolationScheme_,
// Fatal if missing
lookupObject<volVectorField>(UName_)
)
);
}
// Store the names
scalarNames_.setSize(vsInterp.size());
scalarNames_.resize(vsInterp.size());
forAll(vsInterp, i)
{
scalarNames_[i] = vsInterp[i].psi().name();
}
vectorNames_.setSize(vvInterp.size());
vectorNames_.resize(vvInterp.size());
forAll(vvInterp, i)
{
vectorNames_[i] = vvInterp[i].psi().name();
}
// Check that we know the index of U in the interpolators.
if (UIndex == -1)
{
FatalErrorInFunction
<< "Cannot find field to move particles with : " << UName_ << nl
<< "This field has to be present in the sampled fields " << fields_
<< " and in the objectRegistry."
<< exit(FatalError);
}
// Sampled data
// ~~~~~~~~~~~~
// Size to maximum expected sizes.
allTracks_.clear();
allTracks_.setCapacity(nSeeds);
allScalars_.setSize(vsInterp.size());
allScalars_.resize(vsInterp.size());
forAll(allScalars_, i)
{
allScalars_[i].clear();
allScalars_[i].setCapacity(nSeeds);
}
allVectors_.setSize(vvInterp.size());
allVectors_.resize(vvInterp.size());
forAll(allVectors_, i)
{
allVectors_[i].clear();
allVectors_[i].setCapacity(nSeeds);
}
return UInterp;
}
@ -877,22 +877,13 @@ bool Foam::functionObjects::streamLineBase::read(const dictionary& dict)
Info<< type() << " " << name() << ":" << nl;
UName_ = dict.getOrDefault<word>("U", "U");
Info<< " Employing velocity field " << UName_ << endl;
if (fields_.empty())
{
dict.readEntry("fields", fields_);
if (!fields_.found(UName_))
{
FatalIOErrorInFunction(dict)
<< "Velocity field for tracking " << UName_
<< " should be present in the list of fields " << fields_
<< exit(FatalIOError);
}
}
Info<< " Employing velocity field " << UName_ << endl;
bool trackForward;
if (dict.readIfPresent("trackForward", trackForward))
{
@ -912,7 +903,12 @@ bool Foam::functionObjects::streamLineBase::read(const dictionary& dict)
}
else
{
trackDir_ = trackDirTypeNames.get("direction", dict);
trackDir_ = trackDirTypeNames.getOrDefault
(
"direction",
dict,
trackDirType::FORWARD
);
}
dict.readEntry("lifeTime", lifeTime_);
if (lifeTime_ < 1)