sampledSets, streamlines: Various improvements

Sampled sets and streamlines now write all their fields to the same
file. This prevents excessive duplication of the geometry and makes
post-processing tasks more convenient.

"axis" entries are now optional in sampled sets and streamlines. When
omitted, a default entry will be used, which is chosen appropriately for
the coordinate set and the write format. Some combinations are not
supported. For example, a scalar ("x", "y", "z" or "distance") axis
cannot be used to write in the vtk format, as vtk requires 3D locations
with which to associate data. Similarly, a point ("xyz") axis cannot be
used with the gnuplot format, as gnuplot needs a single scalar to
associate with the x-axis.

Streamlines can now write out fields of any type, not just scalars and
vectors, and there is no longer a strict requirement for velocity to be
one of the fields.

Streamlines now output to postProcessing/<functionName>/time/<file> in
the same way as other functions. The additional "sets" subdirectory has
been removed.

The raw set writer now aligns columns correctly.

The handling of segments in coordSet and sampledSet has been
fixed/completed. Segments mean that a coordinate set can represent a
number of contiguous lines, disconnected points, or some combination
thereof. This works in parallel; segments remain contiguous across
processor boundaries. Set writers now only need one write method, as the
previous "writeTracks" functionality is now handled by streamlines
providing the writer with the appropriate segment structure.

Coordinate sets and set writers now have a convenient programmatic
interface. To write a graph of A and B against some coordinate X, in
gnuplot format, we can call the following:

    setWriter::New("gnuplot")->write
    (
        directoryName,
        graphName,
        coordSet(true, "X", X), // <-- "true" indicates a contiguous
        "A",                    //     line, "false" would mean
        A,                      //     disconnected points
        "B",
        B
    );

This write function is variadic. It supports any number of
field-name-field pairs, and they can be of any primitive type.

Support for Jplot and Xmgrace formats has been removed. Raw, CSV,
Gnuplot, VTK and Ensight formats are all still available.

The old "graph" functionality has been removed from the code, with the
exception of the randomProcesses library and associated applications
(noise, DNSFoam and boxTurb). The intention is that these should also
eventually be converted to use the setWriters. For now, so that it is
clear that the "graph" functionality is not to be used elsewhere, it has
been moved into a subdirectory of the randomProcesses library.
This commit is contained in:
Will Bainbridge
2021-11-25 09:42:19 +00:00
parent 50fb2477bd
commit 25a6d068f0
185 changed files with 4727 additions and 6308 deletions

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -30,8 +30,9 @@ Description
\*---------------------------------------------------------------------------*/
#include "fvCFD.H"
#include "writeCellGraph.H"
#include "OSspecific.H"
#include "setWriter.H"
#include "writeFile.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -73,8 +74,20 @@ int main(int argc, char *argv[])
if (runTime.writeTime())
{
writeCellGraph(V, runTime.graphFormat());
writeCellGraph(delta, runTime.graphFormat());
setWriter::New(runTime.graphFormat())->write
(
runTime.globalPath()
/functionObjects::writeFile::outputPrefix
/args.executable()
/runTime.timeName(),
args.executable(),
coordSet(true, word::null, mesh.C().primitiveField(), "x"),
"V", V.primitiveField(),
"delta", delta.primitiveField()
);
}
Info<< "ExecutionTime = " << runTime.elapsedCpuTime() << " s"

View File

@ -41,7 +41,8 @@ Description
#include "fvModels.H"
#include "fvConstraints.H"
#include "wallFvPatch.H"
#include "makeGraph.H"
#include "setWriter.H"
#include "writeFile.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -13,21 +13,32 @@ volSymmTensorField R
runTime.write();
const word& gFormat = runTime.graphFormat();
setWriter::New(runTime.graphFormat())->write
(
runTime.globalPath()
/functionObjects::writeFile::outputPrefix
/args.executable()
/runTime.timeName(),
makeGraph(y, flowDirection & U, "Uf", gFormat);
args.executable(),
makeGraph(y, turbulence->nu(), gFormat);
makeGraph(y, turbulence->k(), gFormat);
makeGraph(y, turbulence->epsilon(), gFormat);
coordSet(true, "y", y),
makeGraph(y, flowDirection & R & flowDirection, "Rff", gFormat);
makeGraph(y, wallNormal & R & wallNormal, "Rww", gFormat);
makeGraph(y, flowDirection & R & wallNormal, "Rfw", gFormat);
"Uf", (flowDirection & U)().primitiveField(),
makeGraph(y, sqrt(mag(R.component(symmTensor::XX))), "u", gFormat);
makeGraph(y, sqrt(mag(R.component(symmTensor::YY))), "v", gFormat);
makeGraph(y, sqrt(mag(R.component(symmTensor::ZZ))), "w", gFormat);
makeGraph(y, R.component(symmTensor::XY), "uv", gFormat);
"nu", turbulence->nu()().primitiveField(),
"k", turbulence->nu()().primitiveField(),
"epsilon", turbulence->nu()().primitiveField(),
makeGraph(y, mag(fvc::grad(U)), "gammaDot", gFormat);
"Rff", (flowDirection & R & flowDirection)().primitiveField(),
"Rww", (wallNormal & R & wallNormal)().primitiveField(),
"Rfw", (flowDirection & R & wallNormal)().primitiveField(),
"u", sqrt(mag(R.component(symmTensor::XX)))().primitiveField(),
"v", sqrt(mag(R.component(symmTensor::YY)))().primitiveField(),
"w", sqrt(mag(R.component(symmTensor::ZZ)))().primitiveField(),
"uv", R.component(symmTensor::XY)().primitiveField(),
"gammaDot", mag(fvc::grad(U))().primitiveField()
);

View File

@ -130,16 +130,10 @@ void Foam::functionObjects::sizeDistribution::correctVolAverages()
}
N_[i] = gSum(V*Ni)/this->V();
V_[i] = fi.x().value();
a_[i] = gSum(V*ai)/this->V();
d_[i] = gSum(V*di)/this->V();
}
forAll(bins_, i)
{
const Foam::diameterModels::sizeGroup& fi = popBal_.sizeGroups()[i];
bins_[i] = point(fi.x().value(), a_[i], d_[i]);
}
}
@ -154,13 +148,15 @@ void Foam::functionObjects::sizeDistribution::writeMoments()
writeTime(file());
}
const scalarField& bin = this->bin();
for (label k = 0; k <= maxOrder_; k++)
{
scalar result = 0;
forAll(N_, i)
{
result += pow(bins_[i][binCmpt_], k)*N_[i];
result += pow(bin[i], k)*N_[i];
}
if (Pstream::master())
@ -192,23 +188,25 @@ void Foam::functionObjects::sizeDistribution::writeStdDev()
scalar mean = 0;
scalar var = 0;
if(sum(N_) != 0)
const scalarField& bin = this->bin();
if (sum(N_) != 0)
{
if (geometric_)
{
mean = exp(sum(Foam::log(bins_.component(binCmpt_))*N_/sum(N_)));
mean = exp(sum(Foam::log(bin)*N_/sum(N_)));
var =
sum(sqr(Foam::log(bins_.component(binCmpt_)) - Foam::log(mean))
sum(sqr(Foam::log(bin) - Foam::log(mean))
*N_/sum(N_));
stdDev = exp(sqrt(var));
}
else
{
mean = sum(bins_.component(binCmpt_)*N_/sum(N_));
mean = sum(bin*N_/sum(N_));
var = sum(sqr(bins_.component(binCmpt_) - mean)*N_/sum(N_));
var = sum(sqr(bin - mean)*N_/sum(N_));
stdDev = sqrt(var);
}
@ -225,6 +223,8 @@ void Foam::functionObjects::sizeDistribution::writeDistribution()
{
scalarField result(N_);
const scalarField& bin = this->bin();
switch (functionType_)
{
case ftNumber:
@ -239,7 +239,7 @@ void Foam::functionObjects::sizeDistribution::writeDistribution()
Log << " writing volume distribution. "
<< endl;
result *= bins_.component(0);
result *= V_;
break;
}
@ -263,12 +263,12 @@ void Foam::functionObjects::sizeDistribution::writeDistribution()
{
List<scalar> bndrs(N_.size() + 1);
bndrs.first() = bins_.first()[binCmpt_];
bndrs.last() = bins_.last()[binCmpt_];
bndrs.first() = bin.first();
bndrs.last() = bin.last();
for (label i = 1; i < N_.size(); i++)
{
bndrs[i] = (bins_[i][binCmpt_] + bins_[i-1][binCmpt_])/2.0;
bndrs[i] = (bin[i]+ bin[i-1])/2.0;
}
forAll(result, i)
@ -287,15 +287,19 @@ void Foam::functionObjects::sizeDistribution::writeDistribution()
if (Pstream::master())
{
const coordSet coords
formatterPtr_->write
(
"sizeDistribution",
"xyz",
bins_,
mag(bins_)
file_.baseTimeDir(),
name(),
coordSet(true, "volume", V_),
"area",
a_,
"diameter",
d_,
word(functionTypeNames_[functionType_])
+ (densityFunction_ ? "Density" : "Concentration"),
result
);
writeGraph(coords, functionTypeNames_[functionType_], result);
}
}
@ -347,44 +351,6 @@ void Foam::functionObjects::sizeDistribution::writeFileHeader
}
void Foam::functionObjects::sizeDistribution::writeGraph
(
const coordSet& coords,
const word& functionTypeName,
const scalarField& values
)
{
const wordList functionTypeNames(1, functionTypeName);
fileName outputPath = file_.baseTimeDir();
mkDir(outputPath);
OFstream graphFile
(
outputPath/(this->name() + ".dat")
);
volRegion::writeFileHeader(file_, graphFile);
file_.writeCommented(graphFile, "Volume area diameter " + functionTypeName);
if (densityFunction_)
{
graphFile << "Density";
}
else
{
graphFile << "Concentration";
}
graphFile << endl;
List<const scalarField*> yPtrs(1);
yPtrs[0] = &values;
scalarFormatter_().write(coords, functionTypeNames, yPtrs, graphFile);
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::sizeDistribution::sizeDistribution
@ -409,42 +375,11 @@ Foam::functionObjects::sizeDistribution::sizeDistribution
functionType_(functionTypeNames_.read(dict.lookup("functionType"))),
coordinateType_(coordinateTypeNames_.read(dict.lookup("coordinateType"))),
N_(popBal_.sizeGroups().size(), 0),
V_(popBal_.sizeGroups().size(), 0),
a_(popBal_.sizeGroups().size(), 0),
d_(popBal_.sizeGroups().size(), 0),
bins_(N_.size()),
binCmpt_(0)
d_(popBal_.sizeGroups().size(), 0)
{
read(dict);
switch (coordinateType_)
{
case ctVolume:
{
binCmpt_ = 0;
break;
}
case ctArea:
{
binCmpt_ = 1;
break;
}
case ctDiameter:
{
binCmpt_ = 2;
break;
}
case ctProjectedAreaDiameter:
{
binCmpt_ = 2;
break;
}
}
scalarFormatter_ = setWriter<scalar>::New("raw");
}
@ -465,6 +400,8 @@ bool Foam::functionObjects::sizeDistribution::read(const dictionary& dict)
geometric_ = dict.lookupOrDefault<Switch>("geometric", false);
maxOrder_ = dict.lookupOrDefault("maxOrder", 3);
formatterPtr_ = setWriter::New(dict.lookup("setFormat"), dict);
resetName(name());
return false;

View File

@ -134,8 +134,8 @@ protected:
//- File containing data for all functionTypes except moments
writeFile file_;
//- Output formatter, set to raw
autoPtr<setWriter<scalar>> scalarFormatter_;
//- Output formatter
autoPtr<setWriter> formatterPtr_;
//- Reference to populationBalanceModel
const Foam::diameterModels::populationBalanceModel& popBal_;
@ -149,6 +149,9 @@ protected:
//- List of volume-averaged number concentrations
scalarField N_;
//- ???
scalarField V_;
//- List of volume-averaged surface areas
scalarField a_;
@ -167,18 +170,29 @@ protected:
//- Highest moment order
label maxOrder_;
//- Bins (representative volume/area/diameter)
pointField bins_;
//- Bin component used according to chosen coordinate type
label binCmpt_;
// Protected Member Functions
//- Filter field according to cellIds
tmp<scalarField> filterField(const scalarField& field) const;
//- Bin component used according to chosen coordinate type
inline const scalarField& bin() const
{
switch (coordinateType_)
{
case ctVolume:
return V_;
case ctArea:
return a_;
case ctDiameter:
return d_;
case ctProjectedAreaDiameter:
return d_;
}
return scalarField::null();
}
//- Correct volume averages
void correctVolAverages();
@ -194,14 +208,6 @@ protected:
//- Output file header information for functionType moments
virtual void writeFileHeader(const label i);
//- Output function for all functionType number/volume
void writeGraph
(
const coordSet& coords,
const word& functionTypeName,
const scalarField& values
);
public: