singleDirectionUniformBinTemplates.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) 2021-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
28
29template<class Type>
31(
33) const
34{
35 writeHeaderValue(os, "bins", nBin_);
36 writeHeaderValue(os, "start", binMin_);
38 writeHeaderValue(os, "delta", binDx_);
39 writeHeaderValue(os, "direction", binDir_);
40
41 // Compute and print bin end points in the binning direction
42 vectorField binPoints(nBin_);
43 writeCommented(os, "x co-ords :");
44 forAll(binPoints, pointi)
45 {
46 binPoints[pointi] = (binMin_ + (pointi + 1)*binDx_)*binDir_;
47 os << tab << binPoints[pointi].x();
48 }
49 os << nl;
50
51 writeCommented(os, "y co-ords :");
52 forAll(binPoints, pointi)
53 {
54 os << tab << binPoints[pointi].y();
55 }
56 os << nl;
57
58 writeCommented(os, "z co-ords :");
59 forAll(binPoints, pointi)
60 {
61 os << tab << binPoints[pointi].z();
62 }
63 os << nl;
64
65 writeHeader(os, "");
66 writeCommented(os, "Time");
67
68 for (label i = 0; i < nBin_; ++i)
69 {
70 const word ibin("_" + Foam::name(i));
71 writeTabbed(os, writeComponents<Type>("total" + ibin));
72 writeTabbed(os, writeComponents<Type>("internal" + ibin));
73
75 {
76 writeTabbed(os, writeComponents<Type>("normal" + ibin));
77 writeTabbed(os, writeComponents<Type>("tangenial" + ibin));
78 }
79 else
80 {
81 writeTabbed(os, writeComponents<Type>("patch" + ibin));
82 }
83
84 }
85
86 os << endl;
87}
88
89
90template<class Type>
92(
93 const label fieldi
94)
95{
96 const word& fieldName = fieldNames_[fieldi];
97
99
100 const VolFieldType* fieldPtr = mesh_.findObject<VolFieldType>(fieldName);
101
102 if (!fieldPtr)
103 {
104 return false;
105 }
106
107 if (Pstream::master() && !writtenHeader_)
108 {
109 writeFileHeader<Type>(filePtrs_[fieldi]);
110 }
111
112 const VolFieldType& fld = *fieldPtr;
113
114 // Total number of fields
115 //
116 // 0: internal
117 // 1: patch total
118 //
119 // OR
120 //
121 // 0: internal
122 // 1: patch normal
123 // 2: patch tangential
124 label nField = 2;
125 if (decomposePatchValues_)
126 {
127 nField += 1;
128 }
129
130 List<List<Type>> data(nField);
131 for (auto& binList : data)
132 {
133 binList.setSize(nBin_, Zero);
134 }
135
136 for (const label zonei : cellZoneIDs_)
137 {
138 const cellZone& cZone = mesh_.cellZones()[zonei];
139
140 for (const label celli : cZone)
141 {
142 const scalar dd = mesh_.C()[celli] & binDir_;
143
144 if (dd < binMin_ || dd > binMax_)
145 {
146 continue;
147 }
148
149 // Find the bin division corresponding to the cell
150 const label bini =
151 min(max(floor((dd - binMin_)/binDx_), 0), nBin_ - 1);
152
153 data[0][bini] += fld[celli];
154 }
155 }
156
157 forAllIters(patchSet_, iter)
158 {
159 const label patchi = iter();
160 const polyPatch& pp = mesh_.boundaryMesh()[patchi];
161 const vectorField np(mesh_.boundary()[patchi].nf());
162
163 const scalarField dd(pp.faceCentres() & binDir_);
164
165 forAll(dd, facei)
166 {
167 // Avoid faces outside of the bin
168 if (dd[facei] < binMin_ || dd[facei] > binMax_)
169 {
170 continue;
171 }
172
173 // Find the bin division corresponding to the face
174 const label bini =
175 min(max(floor((dd[facei] - binMin_)/binDx_), 0), nBin_ - 1);
176
177 const Type& v = fld.boundaryField()[patchi][facei];
178
179 if (!decomposePatchValues(data, bini, v, np[facei]))
180 {
181 data[1][bini] += v;
182 }
183 }
184 }
185
186 if (Pstream::master())
187 {
188 writeBinnedData(data, filePtrs_[fieldi]);
189 }
190
191 return true;
192}
193
194
195// ************************************************************************* //
Info<< nl<< "Wrote faMesh in vtk format: "<< writer.output().name()<< nl;}{ vtk::lineWriter writer(aMesh.points(), aMesh.edges(), fileName(aMesh.mesh().time().globalPath()/"finiteArea-edges"));writer.writeGeometry();writer.beginCellData(4);writer.writeProcIDs();{ Field< scalar > fld(faMeshTools::flattenEdgeField(aMesh.magLe(), true))
Generic GeometricField class.
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
Output to file stream, using an OSstream.
Definition: OFstream.H:57
label nBin_
Total number of bins.
Definition: binModel.H:83
bool decomposePatchValues_
Decompose patch values into normal and tangential components.
Definition: binModel.H:73
void writeFileHeader(OFstream &os) const
Write header for a binned-data file.
bool processField(const label fieldi)
Apply the binning to field fieldi.
scalar binDx_
Distance between bin divisions.
A subset of mesh cells.
Definition: cellZone.H:65
Database for solution data, solver performance and other reduced data.
Definition: data.H:58
virtual void writeTabbed(Ostream &os, const string &str) const
Write a tabbed string to stream.
Definition: writeFile.C:285
void writeHeaderValue(Ostream &os, const string &property, const Type &value) const
Write a (commented) header property and value pair.
virtual void writeHeader(Ostream &os, const string &str) const
Write a commented header to stream.
Definition: writeFile.C:295
virtual void writeCommented(Ostream &os, const string &str) const
Write a commented string to stream.
Definition: writeFile.C:269
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:75
const polyBoundaryMesh & boundaryMesh() const
Return boundaryMesh reference.
Definition: polyPatch.C:315
const vectorField::subField faceCentres() const
Return face centres.
Definition: polyPatch.C:321
splitCell * master() const
Definition: splitCell.H:113
A class for handling words, derived from Foam::string.
Definition: word.H:68
OBJstream os(runTime.globalPath()/outputName)
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:47
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:33
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
constexpr char tab
The tab '\t' character(0x09)
Definition: Ostream.H:52
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333
#define forAllIters(container, iter)
Iterate across all elements in the container object.
Definition: stdFoam.H:260