/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2016-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
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 .
\*---------------------------------------------------------------------------*/
#include "particleDistribution.H"
#include "addToRunTimeSelectionTable.H"
#include "general.H"
#include "fvMesh.H"
#include "cloud.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
defineTypeNameAndDebug(particleDistribution, 0);
addToRunTimeSelectionTable
(
functionObject,
particleDistribution,
dictionary
);
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::particleDistribution::particleDistribution
(
const word& name,
const Time& runTime,
const dictionary& dict
)
:
fvMeshFunctionObject(name, runTime, dict),
writeFile(runTime, name),
cloudName_("unknown-cloudName"),
tagFieldName_("none"),
rndGen_(),
nameVsBinWidth_(),
writerPtr_(nullptr)
{
read(dict);
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::functionObjects::particleDistribution::read(const dictionary& dict)
{
if (fvMeshFunctionObject::read(dict) && writeFile::read(dict))
{
dict.readEntry("cloud", cloudName_);
dict.readIfPresent("tagField", tagFieldName_);
dict.readEntry("nameVsBinWidth", nameVsBinWidth_);
const word setFormat(dict.get("setFormat"));
writerPtr_ = coordSetWriter::New
(
setFormat,
dict.subOrEmptyDict("formatOptions").optionalSubDict(setFormat)
);
Info<< type() << " " << name() << " output:" << nl
<< " Processing cloud : " << cloudName_ << nl
<< endl;
return true;
}
return false;
}
bool Foam::functionObjects::particleDistribution::execute()
{
return true;
}
bool Foam::functionObjects::particleDistribution::write()
{
Log << type() << " " << name() << " output:" << endl;
if (!mesh_.foundObject(cloudName_))
{
WarningInFunction
<< "Unable to find cloud " << cloudName_
<< " in the mesh database. Available clouds include:"
<< flatOutput(mesh_.sortedNames()) << endl;
return false;
}
const cloud& c = mesh_.lookupObject(cloudName_);
objectRegistry cloudObr
(
IOobject
(
scopedName("CloudRegistry"),
mesh_.time().timeName(),
cloud::prefix,
mesh_.time(),
IOobject::NO_READ,
IOobject::NO_WRITE
)
);
c.writeObjects(cloudObr);
List> tagAddr;
if
(
tagFieldName_ != "none"
&& cloudObr.foundObject>(tagFieldName_)
)
{
// Tag field present - generate distribution per tag
const IOField