uniformBinTemplates.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// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
29
30template<class Type>
32(
34) const
35{
36 writeHeader(os, "bins");
37
38 const tensor& R = coordSysPtr_->R();
39 for (direction i = 0; i < vector::nComponents; ++i)
40 {
41 writeHeaderValue(os, "e" + Foam::name(i) + " bins", nBins_[i]);
42 writeHeaderValue(os, " start", binMinMax_[i][0]);
43 writeHeaderValue(os, " end", binMinMax_[i][1]);
44 writeHeaderValue(os, " delta", binW_[i]);
45 writeHeaderValue(os, " direction", R.col(i));
46 }
47 writeCommented(os, "bin end co-ordinates:");
48 os << nl;
49
50 // Compute and print bin end points in binning directions
51 for (direction i = 0; i < vector::nComponents; ++i)
52 {
53 scalar binEnd = binMinMax_[i][0];
54
55 writeCommented(os, "e"+Foam::name(i)+" co-ords :");
56 for (label j = 0; j < nBins_[i]; ++j)
57 {
58 binEnd += binW_[i];
59 os << tab << binEnd;
60 }
61 os << nl;
62 }
63
64 writeHeader(os, "");
65 writeCommented(os, "Time");
66
67 for (label i = 0; i < nBin_; ++i)
68 {
69 const word ibin(Foam::name(i) + ':');
70 writeTabbed(os, writeComponents<Type>("total" + ibin));
71 writeTabbed(os, writeComponents<Type>("internal" + ibin));
72
74 {
75 writeTabbed(os, writeComponents<Type>("normal" + ibin));
76 writeTabbed(os, writeComponents<Type>("tangential" + ibin));
77 }
78 else
79 {
80 writeTabbed(os, writeComponents<Type>("patch" + ibin));
81 }
82 }
83
84 os << endl;
85}
86
87template<class Type>
89{
90 const word& fieldName = fieldNames_[fieldi];
91
93
94 const VolFieldType* fieldPtr = mesh_.findObject<VolFieldType>(fieldName);
95
96 if (!fieldPtr)
97 {
98 return false;
99 }
100
101 if (Pstream::master() && !writtenHeader_)
102 {
103 writeFileHeader<Type>(filePtrs_[fieldi]);
104 }
105
106 const VolFieldType& fld = *fieldPtr;
107
108 // Total number of fields
109 //
110 // 0: internal
111 // 1: patch total
112 //
113 // OR
114 //
115 // 0: internal
116 // 1: patch normal
117 // 2: patch tangential
118 label nField = 2;
119 if (decomposePatchValues_)
120 {
121 nField += 1;
122 }
123
124 List<List<Type>> data(nField);
125 for (auto& binList : data)
126 {
127 binList.setSize(nBin_, Zero);
128 }
129
130 for (const label zonei : cellZoneIDs_)
131 {
132 const cellZone& cZone = mesh_.cellZones()[zonei];
133
134 for (const label celli : cZone)
135 {
136 const label bini = cellToBin_[celli];
137
138 if (bini != -1)
139 {
140 data[0][bini] += fld[celli];
141 }
142 }
143 }
144
145 forAllIters(patchSet_, iter)
146 {
147 const label patchi = iter();
148 const polyPatch& pp = mesh_.boundaryMesh()[patchi];
149 const vectorField np(mesh_.boundary()[patchi].nf());
150
151 forAll(pp, facei)
152 {
153 const label localFacei =
154 pp.start() - mesh_.nInternalFaces() + facei;
155 const label bini = faceToBin_[localFacei];
156
157 if (bini != -1)
158 {
159 const Type& v = fld.boundaryField()[patchi][facei];
160
161 if (!decomposePatchValues(data, bini, v, np[facei]))
162 {
163 data[1][bini] += v;
164 }
165 }
166 }
167 }
168
169 if (Pstream::master())
170 {
171 writeBinnedData(data, filePtrs_[fieldi]);
172 }
173
174 return true;
175}
176
177
178// ************************************************************************* //
#define R(A, B, C, D, E, F, K, M)
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
autoPtr< coordinateSystem > coordSysPtr_
Local coordinate system of bins.
Definition: binModel.H:80
bool decomposePatchValues_
Decompose patch values into normal and tangential components.
Definition: binModel.H:73
void writeFileHeader(OFstream &os) const
Write header for an binned-data file.
Vector< vector2D > binMinMax_
Min-max bounds of bins in binning directions.
Definition: uniformBin.H:176
bool processField(const label fieldi)
Apply the binning to field fieldi.
vector binW_
Equidistant bin widths in binning directions.
Definition: uniformBin.H:173
Vector< label > nBins_
Numbers of bins in binning directions.
Definition: uniformBin.H:170
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
static constexpr direction nComponents
Number of components in bool is 1.
Definition: bool.H:98
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:75
label start() const
Return start label of this patch in the polyMesh face list.
Definition: polyPatch.H:364
const polyBoundaryMesh & boundaryMesh() const
Return boundaryMesh reference.
Definition: polyPatch.C:315
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)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
uint8_t direction
Definition: direction.H:56
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