regionSizeDistribution.H 10.9 KB
Newer Older
Henry's avatar
Henry committed
1
2
3
4
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     |
5
    \\  /    A nd           | Copyright (C) 2013-2016 OpenFOAM Foundation
6
     \\/     M anipulation  | Copyright (C) 2016 OpenCFD Ltd.
Henry's avatar
Henry committed
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
-------------------------------------------------------------------------------
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/>.

Class
25
    Foam::functionObjects::regionSizeDistribution
Henry's avatar
Henry committed
26
27
28
29
30

Group
    grpFieldFunctionObjects

Description
31
32
    Creates a size distribution via interrogating a continuous phase fraction
    field.
Henry's avatar
Henry committed
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55

    Looks up a phase-fraction (alpha) field and splits the mesh into regions
    based on where the field is below the threshold value.  These
    regions ("droplets") can now be analysed.

    Regions:
    - print the regions connected to a user-defined set of patches.
      (in spray calculation these form the liquid core)
    - print the regions with too large volume.  These are the 'background'
      regions.
    - (debug) write regions as a volScalarField
    - (debug) print for all regions the sum of volume and alpha*volume

    Output (volume scalar) fields include:
    - alpha_liquidCore : alpha with outside liquid core set to 0
    - alpha_background : alpha with outside background set to 0.

    %Histogram:
    - determine histogram of diameter (given minDiameter, maxDiameter, nBins)
    - write graph of number of droplets per bin
    - write graph of sum, average and deviation of droplet volume per bin
    - write graph of sum, average and deviation of user-defined fields.  For
      volVectorFields these are those of the 3 components and the magnitude.
56
57
58
    - (optional) write graph of histogram of centroids on iso planes
      downstream of the injector determined by origin, direction and maxDiameter
      up to maxDownstream
Henry's avatar
Henry committed
59

Andrew Heather's avatar
Andrew Heather committed
60
Usage
Henry's avatar
Henry committed
61
62
63
64
65
    Example of function object specification:
    \verbatim
    regionSizeDistribution1
    {
        type            regionSizeDistribution;
66
        libs            ("libfieldFunctionObjects.so");
Henry's avatar
Henry committed
67
68
69
70
71
72
73
74
75
        ...
        field           alpha;
        patches         (inlet);
        threshold       0.4;
        fields          (p U);
        nBins           100;
        maxDiameter     0.5e-4;
        minDiameter     0;
        setFormat       gnuplot;
Prashant Sonakar's avatar
Prashant Sonakar committed
76
77
        origin          (0 0 0);
        coordinateRoation
Henry's avatar
Henry committed
78
79
80
81
82
        {
            type            cartesian;
            e3              (0 1 1);
            e1              (1 0 0);
        }
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100

        // Optional downstream iso-plane bins.
        isoPlanes       true;

            // Plane normal and point definition
            direction       (1 0 1);
            origin          (1e-4 0 5e-4);

            // Maximum diameter of the cylinder formed by the origin point
            // and direction
            maxDiameter     3e-4;

            // Maximum downstream distance
            maxDownstream   6e-4;

            // Number of iso-plane bins
            nDownstreamBins 20;

Henry's avatar
Henry committed
101
102
103
    }
    \endverbatim

Andrew Heather's avatar
Andrew Heather committed
104
    Where the entries comprise:
Henry's avatar
Henry committed
105
106
107
108
109
110
111
112
113
114
115
    \table
        Property     | Description             | Required    | Default value
        type         | type name: regionSizeDistribution |yes|
        field        | phase field to interrogate | yes      |
        patches      | patches from which the liquid core is identified | yes|
        threshold    | phase fraction applied to delimit regions | yes |
        fields       | fields to sample        | yes         |
        nBins        | number of bins for histogram | yes    |
        maxDiameter  | maximum region equivalent diameter | yes |
        minDiameter  | minimum region equivalent diameter | no  | 0
        setFormat    | writing format          | yes         |
Prashant Sonakar's avatar
Prashant Sonakar committed
116
        origin       | origin of local co-ordinate system | yes    |
117
        coordinateRoation | orientation of local co-ordinate system | no
118
        log          | Log to standard output  | no          | yes
119
120
121
122
123
124
125
126
        isoPlanes    | switch for isoPlanes    | no          | false
        origin       | origin of the plane when isoPlanes is used | no | none
        direction    | direction of the plane when isoPlanes is used | no | none
        maxDiameter  | maximum diameter of the sampling cylinder when
                       isoPlanes is used | no | none
        nDownstreamBins  | number of bins when isoPlanes is used | no | none
        maxDownstream  | maximum distance from origin when isoPlanes is used
                       | no | none
Henry's avatar
Henry committed
127
128
    \endtable

129
See also
Henry's avatar
Henry committed
130
    Foam::functionObject
131
    Foam::functionObjects::fvMeshFunctionObject
132
    Foam::functionObjects::writeFile
Henry's avatar
Henry committed
133
134
135
136
137
138

SourceFiles
    regionSizeDistribution.C

\*---------------------------------------------------------------------------*/

139
140
#ifndef functionObjects_regionSizeDistribution_H
#define functionObjects_regionSizeDistribution_H
Henry's avatar
Henry committed
141

142
#include "fvMeshFunctionObject.H"
143
#include "writeFile.H"
Henry's avatar
Henry committed
144
145
146
147
148
#include "writer.H"
#include "Map.H"
#include "volFieldsFwd.H"
#include "wordReList.H"
#include "coordinateSystem.H"
149
#include "Switch.H"
Henry's avatar
Henry committed
150
151
152
153
154
155
156
157
158

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

namespace Foam
{

// Forward declaration of classes
class regionSplit;

159
160
namespace functionObjects
{
Henry's avatar
Henry committed
161
162
163
164
165
166
167

/*---------------------------------------------------------------------------*\
                   Class regionSizeDistribution Declaration
\*---------------------------------------------------------------------------*/

class regionSizeDistribution
:
168
169
    public fvMeshFunctionObject,
    public writeFile
Henry's avatar
Henry committed
170
171
172
173
174
175
176
177
178
{
    // Private data

        //- Name of field
        word alphaName_;

        //- Patches to walk from
        wordReList patchNames_;

179
180
181
        //- Switch to send output to Info as well as to file
        Switch log_;

Henry's avatar
Henry committed
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
        //- Clip value
        scalar threshold_;

        //- Maximum droplet diameter
        scalar maxDiam_;

        //- Minimum droplet diameter
        scalar minDiam_;

        //- Mumber of bins
        label nBins_;

        //- Names of fields to sample on regions
        wordReList fields_;

        //- Output formatter to write
198
        autoPtr<writer<scalar>> formatterPtr_;
Henry's avatar
Henry committed
199
200
201
202

        //- Optional coordinate system
        autoPtr<coordinateSystem> coordSysPtr_;

203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
        // Optional extra definition of bins on planes downstream to the origin
        // point and maximum diameter

            //- Switch to enable iso-planes sampling
            bool isoPlanes_;

            //- Optional origin point
            vector origin_;

            //- Optional plane normal direction
            vector direction_;

            //- Optional maximum diameter on plane
            scalar maxDiameter_;

            //- Optional number of bins for
            scalar nDownstreamBins_;

            //- Optional maximum downstream coordinate from origin
            scalar maxDownstream_;

Henry's avatar
Henry committed
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252

    // Private Member Functions

        template<class Type>
        Map<Type> regionSum(const regionSplit&, const Field<Type>&) const;

        //- Get data in order
        template<class Type>
        List<Type> extractData(const UList<label>& keys, const Map<Type>&)
        const;

        void writeGraph
        (
            const coordSet& coords,
            const word& valueName,
            const scalarField& values
        ) const;

        //- Write volfields with the parts of alpha which are not
        //  droplets (liquidCore, backGround)
        void writeAlphaFields
        (
            const regionSplit& regions,
            const Map<label>& keepRegions,
            const Map<scalar>& regionVolume,
            const volScalarField& alpha
        ) const;

        //- Mark all regions starting at patches
253
        Map<label> findPatchRegions(const regionSplit&) const;
Henry's avatar
Henry committed
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302

        //- Helper: divide if denom != 0
        static tmp<scalarField> divide(const scalarField&, const scalarField&);

        //- Given per-region data calculate per-bin average/deviation and graph
        void writeGraphs
        (
            const word& fieldName,              // name of field
            const labelList& indices,           // index of bin for each region
            const scalarField& sortedField,     // per region field data
            const scalarField& binCount,        // per bin number of regions
            const coordSet& coords              // graph data for bins
        ) const;

        //- Given per-cell data calculate per-bin average/deviation and graph
        void writeGraphs
        (
            const word& fieldName,              // name of field
            const scalarField& cellField,       // per cell field data

            const regionSplit& regions,         // per cell the region(=droplet)
            const labelList& sortedRegions,     // valid regions in sorted order
            const scalarField& sortedNormalisation,

            const labelList& indices,           // index of bin for each region
            const scalarField& binCount,        // per bin number of regions
            const coordSet& coords              // graph data for bins
        ) const;

        //- Disallow default bitwise copy construct
        regionSizeDistribution(const regionSizeDistribution&);

        //- Disallow default bitwise assignment
        void operator=(const regionSizeDistribution&);


public:

    //- Runtime type information
    TypeName("regionSizeDistribution");


    // Constructors

        //- Construct for given objectRegistry and dictionary.
        //  Allow the possibility to load fields from files
        regionSizeDistribution
        (
            const word& name,
303
304
            const Time& runTime,
            const dictionary&
Henry's avatar
Henry committed
305
306
307
308
309
310
311
312
313
314
315
        );


    // Destructor

        virtual ~regionSizeDistribution();


    // Member Functions

        //- Read the regionSizeDistribution data
316
        virtual bool read(const dictionary&);
Henry's avatar
Henry committed
317

318
        //- Do nothing
319
        virtual bool execute();
Henry's avatar
Henry committed
320
321

        //- Calculate the regionSizeDistribution and write
322
        virtual bool write();
Henry's avatar
Henry committed
323
324
325
326
327
};


// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

328
} // End namespace functionObjects
Henry's avatar
Henry committed
329
330
331
332
333
} // End namespace Foam

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

#ifdef NoRepository
334
    #include "regionSizeDistributionTemplates.C"
Henry's avatar
Henry committed
335
336
337
338
339
340
341
#endif

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

#endif

// ************************************************************************* //