particleDistribution.C
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ========= |
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4 \\ / O peration |
5 \\ / A nd | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2016-2022 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM.
12
13 OpenFOAM is free software: you can redistribute it and/or modify it
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25
26\*---------------------------------------------------------------------------*/
27
30#include "general.H"
31#include "fvMesh.H"
32#include "cloud.H"
33
34// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35
36namespace Foam
37{
38namespace functionObjects
39{
42 (
46 );
47}
48}
49
50
51// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
52
54(
55 const word& name,
56 const Time& runTime,
57 const dictionary& dict
58)
59:
62 cloudName_("unknown-cloudName"),
63 tagFieldName_("none"),
64 rndGen_(),
65 nameVsBinWidth_(),
66 writerPtr_(nullptr)
67{
68 read(dict);
69}
70
71
72// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
73
75{
77 {
78 dict.readEntry("cloud", cloudName_);
79 dict.readIfPresent("tagField", tagFieldName_);
80 dict.readEntry("nameVsBinWidth", nameVsBinWidth_);
81
82 const word setFormat(dict.get<word>("setFormat"));
83 writerPtr_ = coordSetWriter::New
84 (
86 dict.subOrEmptyDict("formatOptions").optionalSubDict(setFormat)
87 );
88
89 Info<< type() << " " << name() << " output:" << nl
90 << " Processing cloud : " << cloudName_ << nl
91 << endl;
92
93 return true;
94 }
95
96 return false;
97}
98
99
101{
102 return true;
103}
104
105
107{
108 Log << type() << " " << name() << " output:" << endl;
109
110 if (!mesh_.foundObject<cloud>(cloudName_))
111 {
113 << "Unable to find cloud " << cloudName_
114 << " in the mesh database. Available clouds include:"
115 << flatOutput(mesh_.sortedNames<cloud>()) << endl;
116
117 return false;
118 }
119
120 const cloud& c = mesh_.lookupObject<cloud>(cloudName_);
121
122 objectRegistry cloudObr
123 (
125 (
126 scopedName("CloudRegistry"),
127 mesh_.time().timeName(),
129 mesh_.time(),
132 )
133 );
134
135 c.writeObjects(cloudObr);
136
138 if
139 (
140 tagFieldName_ != "none"
141 && cloudObr.foundObject<IOField<scalar>>(tagFieldName_)
142 )
143 {
144 // Tag field present - generate distribution per tag
145 const IOField<label>& tag =
146 cloudObr.lookupObject<IOField<label>>(tagFieldName_);
147 const labelHashSet tagMap(tag);
148 const label tagMax = tagMap.size();
149
150 List<DynamicList<label>> tagAddr(tagMax);
151 forAll(tag, i)
152 {
153 label newTag = tagMap[tag[i]];
154 tagAddr[newTag].append(i);
155 }
156 }
157
158
159 forAll(nameVsBinWidth_, i)
160 {
161 const bool ok
162 (
163 processField<scalar>(cloudObr, i, tagAddr)
164 || processField<vector>(cloudObr, i, tagAddr)
165 || processField<tensor>(cloudObr, i, tagAddr)
166 || processField<sphericalTensor>(cloudObr, i, tagAddr)
167 || processField<symmTensor>(cloudObr, i, tagAddr)
168 || processField<tensor>(cloudObr, i, tagAddr)
169 );
170
171 if (log && !ok)
172 {
174 << "Unable to find field " << nameVsBinWidth_[i].first()
175 << " in the " << cloudName_ << " cloud database" << endl;
176 }
177 }
178
179 return true;
180}
181
182
184(
185 const word& fieldName,
186 const scalarField& field,
187 const scalar binWidth,
188 const label tag
189)
190{
191 if (field.empty())
192 {
193 return;
194 }
195
196 word fldName(fieldName);
197 if (tag != -1)
198 {
199 fldName += '_' + Foam::name(tag);
200 }
201
203 (
204 field,
205 binWidth,
206 rndGen_
207 );
208
209 Field<scalar> distX(distribution.x());
210 Field<scalar> distY(distribution.y());
211
212 pointField xBin(distX.size(), Zero);
213 xBin.replace(vector::X, distX);
214
215 const coordSet coords(fldName, "x", std::move(xBin), std::move(distX));
216
217 writerPtr_->open(coords, baseTimeDir() / fldName);
218 fileName outFile = writerPtr_->write(fldName, distY);
219 writerPtr_->close(true);
220
221 Log << " Wrote distribution of " << fieldName
222 << " to " << time_.relativePath(outFile) << endl;
223}
224
225
226// ************************************************************************* //
#define Log
Definition: PDRblock.C:35
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
void replace(const direction, const UList< cmptType > &)
Replace a component field of the field.
Definition: Field.C:557
A primitive field of type <T> with automated input and output.
Definition: IOField.H:58
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:170
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: List.H:77
void append(const T &val)
Append an element at the end of the list.
Definition: ListI.H:175
virtual bool read()
Re-read model coefficients if they have changed.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:80
static autoPtr< Time > New()
Construct (dummy) Time - no functionObjects or libraries.
Definition: Time.C:717
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
A cloud is a registry collection of lagrangian particles.
Definition: cloud.H:60
static const word prefix
The prefix to local: lagrangian.
Definition: cloud.H:87
Holds list of sampling positions.
Definition: coordSet.H:56
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
Particle-size distribution model wherein random samples are drawn from a given arbitrary probability ...
Definition: general.H:176
Accumulating histogram of values. Specified bin resolution automatic generation of bins.
Definition: distribution.H:64
A class for handling file names.
Definition: fileName.H:76
Abstract base-class for Time/database function objects.
Specialization of Foam::functionObject for an Foam::fvMesh, providing a reference to the Foam::fvMesh...
Computes the natural logarithm of an input volScalarField.
Definition: log.H:230
Generates a particle distribution for lagrangian data at a given time.
void generateDistribution(const word &fieldName, const scalarField &field, const scalar binWidth, const label tag=-1)
Generate the distribution.
virtual bool execute()
Execute, currently does nothing.
virtual bool write()
Write the particleDistribution.
virtual bool read(const dictionary &)
Read the particleDistribution data.
Base class for writing single files from the function objects.
Definition: writeFile.H:120
Registry of regIOobjects.
A class for handling words, derived from Foam::string.
Definition: word.H:68
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition: className.H:121
rDeltaTY field()
engineTime & runTime
#define WarningInFunction
Report a warning using Foam::Warning.
Namespace for OpenFOAM.
messageStream Info
Information stream (stdout output on master, null elsewhere)
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: MSwindows.C:598
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
FlatOutput::OutputAdaptor< Container, Delimiters > flatOutput(const Container &obj, Delimiters delim)
Global flatOutput() function with specified output delimiters.
Definition: FlatOutput.H:215
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
dictionary dict
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333
word setFormat(propsDict.getOrDefault< word >("setFormat", "vtk"))