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.
219 lines
6.1 KiB
C++
219 lines
6.1 KiB
C++
/*---------------------------------------------------------------------------*\
|
|
========= |
|
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
|
\\ / O peration | Website: https://openfoam.org
|
|
\\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation
|
|
\\/ M anipulation |
|
|
-------------------------------------------------------------------------------
|
|
License
|
|
This file is part of OpenFOAM.
|
|
|
|
OpenFOAM is free software: you can redistribute it and/or modify it
|
|
under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
\*---------------------------------------------------------------------------*/
|
|
|
|
#include "boundaryRandom.H"
|
|
#include "sampledSet.H"
|
|
#include "meshSearch.H"
|
|
#include "DynamicList.H"
|
|
#include "polyMesh.H"
|
|
#include "addToRunTimeSelectionTable.H"
|
|
#include "word.H"
|
|
#include "Random.H"
|
|
#include "SubField.H"
|
|
#include "barycentric2D.H"
|
|
#include "triPointRef.H"
|
|
#include "tetIndices.H"
|
|
|
|
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
|
|
|
namespace Foam
|
|
{
|
|
namespace sampledSets
|
|
{
|
|
defineTypeNameAndDebug(boundaryRandom, 0);
|
|
addToRunTimeSelectionTable(sampledSet, boundaryRandom, word);
|
|
}
|
|
}
|
|
|
|
|
|
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
|
|
|
void Foam::sampledSets::boundaryRandom::calcSamples
|
|
(
|
|
DynamicList<point>& samplingPositions,
|
|
DynamicList<label>& samplingSegments,
|
|
DynamicList<label>& samplingCells,
|
|
DynamicList<label>& samplingFaces
|
|
) const
|
|
{
|
|
// Get the patch IDs
|
|
const labelList patchIDs(mesh().boundaryMesh().patchSet(patches_).toc());
|
|
|
|
// Triangulate the patch faces
|
|
DynamicList<label> triFaces, triTetPts;
|
|
forAll(patchIDs, patchi)
|
|
{
|
|
const polyPatch& patch = mesh().boundaryMesh()[patchIDs[patchi]];
|
|
|
|
forAll(patch, patchFacei)
|
|
{
|
|
const face& f = patch[patchFacei];
|
|
const label facei = patchFacei + patch.start();
|
|
|
|
for (label tetPti = 1; tetPti < f.size() - 1; ++ tetPti)
|
|
{
|
|
triFaces.append(facei);
|
|
triTetPts.append(tetPti);
|
|
}
|
|
}
|
|
}
|
|
|
|
// Generate the fractions which select the processor, patch and triangle
|
|
scalarField trisFraction(triFaces.size() + 1, 0);
|
|
forAll(triFaces, trii)
|
|
{
|
|
const tetIndices tetIs
|
|
(
|
|
mesh().faceOwner()[triFaces[trii]],
|
|
triFaces[trii],
|
|
triTetPts[trii]
|
|
);
|
|
|
|
trisFraction[trii + 1] =
|
|
trisFraction[trii] + tetIs.faceTri(mesh()).mag();
|
|
}
|
|
|
|
scalarField procsFraction(Pstream::nProcs() + 1, 0);
|
|
{
|
|
scalarField procsArea(Pstream::nProcs(), 0);
|
|
procsArea[Pstream::myProcNo()] = trisFraction.last();
|
|
Pstream::listCombineGather(procsArea, maxEqOp<scalar>());
|
|
Pstream::listCombineScatter(procsArea);
|
|
for(label proci = 0; proci < Pstream::nProcs(); ++ proci)
|
|
{
|
|
procsFraction[proci + 1] = procsFraction[proci] + procsArea[proci];
|
|
}
|
|
}
|
|
|
|
if (triFaces.size())
|
|
{
|
|
trisFraction /= trisFraction.last();
|
|
}
|
|
|
|
if (procsFraction.last() != 0)
|
|
{
|
|
procsFraction /= procsFraction.last();
|
|
}
|
|
|
|
// Generate the samples
|
|
Random rndGen(261782);
|
|
const label proci = Pstream::myProcNo();
|
|
for (label i = 0; i < nPoints_; ++ i)
|
|
{
|
|
// Request all random numbers simultaneously on all processors so that
|
|
// the generator state stays consistent
|
|
|
|
const scalar rProc = rndGen.scalar01();
|
|
const scalar rTri = rndGen.scalar01();
|
|
const barycentric2D r2D = barycentric2D01(rndGen);
|
|
|
|
if (procsFraction[proci] < rProc && rProc <= procsFraction[proci + 1])
|
|
{
|
|
label trii = 0;
|
|
while (rTri > trisFraction[trii + 1])
|
|
{
|
|
++ trii;
|
|
}
|
|
|
|
const tetIndices tetIs
|
|
(
|
|
mesh().faceOwner()[triFaces[trii]],
|
|
triFaces[trii],
|
|
triTetPts[trii]
|
|
);
|
|
|
|
const barycentric r3D
|
|
(
|
|
rootSmall,
|
|
(1 - rootSmall)*r2D.a(),
|
|
(1 - rootSmall)*r2D.b(),
|
|
(1 - rootSmall)*r2D.c()
|
|
);
|
|
|
|
samplingPositions.append(tetIs.tet(mesh()).barycentricToPoint(r3D));
|
|
samplingSegments.append(i);
|
|
samplingCells.append(tetIs.cell());
|
|
samplingFaces.append(tetIs.face());
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
void Foam::sampledSets::boundaryRandom::genSamples()
|
|
{
|
|
DynamicList<point> samplingPositions;
|
|
DynamicList<label> samplingSegments;
|
|
DynamicList<label> samplingCells;
|
|
DynamicList<label> samplingFaces;
|
|
|
|
calcSamples
|
|
(
|
|
samplingPositions,
|
|
samplingSegments,
|
|
samplingCells,
|
|
samplingFaces
|
|
);
|
|
|
|
samplingPositions.shrink();
|
|
samplingSegments.shrink();
|
|
samplingCells.shrink();
|
|
samplingFaces.shrink();
|
|
|
|
setSamples
|
|
(
|
|
samplingPositions,
|
|
samplingSegments,
|
|
samplingCells,
|
|
samplingFaces
|
|
);
|
|
}
|
|
|
|
|
|
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
|
|
|
Foam::sampledSets::boundaryRandom::boundaryRandom
|
|
(
|
|
const word& name,
|
|
const polyMesh& mesh,
|
|
const meshSearch& searchEngine,
|
|
const dictionary& dict
|
|
)
|
|
:
|
|
sampledSet(name, mesh, searchEngine, dict),
|
|
patches_(dict.lookup("patches")),
|
|
nPoints_(dict.lookup<label>("nPoints"))
|
|
{
|
|
genSamples();
|
|
}
|
|
|
|
|
|
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
|
|
|
Foam::sampledSets::boundaryRandom::~boundaryRandom()
|
|
{}
|
|
|
|
|
|
// ************************************************************************* //
|