Loading...
Searching...
No Matches
binModel.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-2023 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#include "binModel.H"
29#include "fvMesh.H"
30#include "cartesianCS.H"
31
32// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33
34namespace Foam
35{
38}
39
40
41// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
42
43template<>
45(
46 List<List<vector>>& data,
47 const label bini,
48 const vector& v,
49 const vector& n
50) const
51{
53 {
54 return false;
55 }
56
57 #ifdef FULLDEBUG
58 if (data.size() != 3)
59 {
61 << "Inconsistent data list size - expect size 3"
62 << abort(FatalError);
63 }
64 #endif
65
66 data[1][bini] += n*(v & n);
67 data[2][bini] += v - n*(v & n);
68
69 return true;
70}
71
72
74(
75 const dictionary& dict,
76 const word& e3Name,
77 const word& e1Name
78)
79{
80 point origin(Zero);
81
82 coordSysPtr_ = coordinateSystem::NewIfPresent(dict);
83
84 if (coordSysPtr_)
85 {
86 Info<< "Setting co-ordinate system:" << nl
87 << " - type : " << coordSysPtr_->name() << nl
88 << " - origin : " << coordSysPtr_->origin() << nl
89 << " - e3 : " << coordSysPtr_->e3() << nl
90 << " - e1 : " << coordSysPtr_->e1() << endl;
91 }
92 else if (dict.readIfPresent("CofR", origin))
93 {
94 const vector e3
95 (
96 e3Name.empty() ? vector(0, 0, 1) : dict.get<vector>(e3Name)
97 );
98 const vector e1
99 (
100 e1Name.empty() ? vector(1, 0, 0) : dict.get<vector>(e1Name)
101 );
102
103 coordSysPtr_.reset(new coordSystem::cartesian(origin, e3, e1));
104 }
105 else
106 {
108 }
109}
110
111
112// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
113
115(
116 const dictionary& dict,
117 const fvMesh& mesh,
118 const word& outputPrefix
119)
120:
121 writeFile(mesh, outputPrefix),
122 mesh_(mesh),
123 decomposePatchValues_(false),
124 cumulative_(false),
125 coordSysPtr_(nullptr),
126 nBin_(1)
127{}
128
129
130// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
131
133{
134 const polyBoundaryMesh& pbm = mesh_.boundaryMesh();
135
137 {
138 return false;
139 }
140
141 // Can also use pbm.indices(), but no warnings...
142 patchIDs_ = pbm.patchSet(dict.get<wordRes>("patches")).sortedToc();
143 fieldNames_ = dict.get<wordHashSet>("fields").sortedToc();
144
145 wordRes zoneNames;
146 if (dict.readIfPresent("cellZones", zoneNames))
147 {
148 DynamicList<label> zoneIDs;
149 DynamicList<wordRe> czUnmatched;
150 for (const auto& cz : zoneNames)
151 {
152 const labelList czi(mesh_.cellZones().indices(cz));
153
154 if (czi.empty())
155 {
156 czUnmatched.append(cz);
157 }
158 else
159 {
160 zoneIDs.append(czi);
161 }
162 }
163
164 if (czUnmatched.size())
165 {
167 << "Unable to find zone(s): " << czUnmatched << nl
168 << "Valid cellZones are : " << mesh_.cellZones().sortedNames()
169 << endl;
170 }
171
172 cellZoneIDs_.transfer(zoneIDs);
173 }
174
175 decomposePatchValues_ = dict.getOrDefault("decomposePatchValues", false);
176
177 filePtrs_.resize(fieldNames_.size());
178 forAll(filePtrs_, i)
179 {
180 filePtrs_.set(i, newFileAtStartTime(fieldNames_[i] + "Bin"));
181 }
184
185 return true;
187
188
190{}
191
192
193void Foam::binModel::movePoints(const polyMesh& mesh)
194{}
195
196
197// ************************************************************************* //
label n
const polyBoundaryMesh & pbm
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition DynamicList.H:68
void append(const T &val)
Copy append an element to the end of this list.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition List.H:72
void append(const T &val)
Append an element at the end of the list.
Definition List.H:497
bool empty() const noexcept
True if List is empty (ie, size() is zero).
Definition UList.H:701
void size(const label n)
Older name for setAddressableSize.
Definition UList.H:118
Base class for bin models to handle general bin characteristics.
Definition binModel.H:60
const fvMesh & mesh_
Reference to the mesh.
Definition binModel.H:68
PtrList< OFstream > filePtrs_
List of file pointers; 1 file per field.
Definition binModel.H:109
wordList fieldNames_
Names of operand fields.
Definition binModel.H:99
label nBin_
Total number of bins.
Definition binModel.H:89
bool decomposePatchValues(List< List< Type > > &data, const label bini, const Type &v, const vector &n) const
Helper function to decompose patch values into normal and tangential components.
virtual void movePoints(const polyMesh &mesh)
Update for changes of mesh.
Definition binModel.C:186
virtual bool read(const dictionary &dict)
Read the function-object dictionary.
Definition binModel.C:125
autoPtr< coordinateSystem > coordSysPtr_
Local coordinate system of bins.
Definition binModel.H:84
bool decomposePatchValues_
Decompose patch values into normal and tangential components.
Definition binModel.H:73
virtual void updateMesh(const mapPolyMesh &mpm)
Update for changes of mesh.
Definition binModel.C:182
labelList cellZoneIDs_
Indices of operand cell zones.
Definition binModel.H:104
bool cumulative_
Flag to accumulate bin data with increasing distance in binning direction.
Definition binModel.H:79
binModel(const dictionary &dict, const fvMesh &mesh, const word &outputPrefix)
Construct from components.
Definition binModel.C:108
void setCoordinateSystem(const dictionary &dict, const word &e3Name=word::null, const word &e1Name=word::null)
Set the co-ordinate system from dictionary and axes names.
Definition binModel.C:67
labelList patchIDs_
Indices of operand patches.
Definition binModel.H:94
A Cartesian coordinate system.
Definition cartesianCS.H:68
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
T getOrDefault(const word &keyword, const T &deflt, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a T, or return the given default value. FatalIOError if it is found and the number of...
virtual autoPtr< OFstream > newFileAtStartTime(const word &name) const
Return autoPtr to a new file using the simulation start time.
Definition writeFile.C:156
writeFile(const objectRegistry &obr, const fileName &prefix, const word &name="undefined", const bool writeToFile=true, const string &ext=".dat")
Construct from objectRegistry, prefix, fileName.
Definition writeFile.C:200
virtual bool read(const dictionary &dict)
Read.
Definition writeFile.C:240
Mesh data needed to do the Finite Volume discretisation.
Definition fvMesh.H:85
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
A polyBoundaryMesh is a polyPatch list with registered IO, a reference to the associated polyMesh,...
Mesh consisting of general polyhedral cells.
Definition polyMesh.H:79
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
A List of wordRe with additional matching capabilities.
Definition wordRes.H:56
A class for handling words, derived from Foam::string.
Definition word.H:66
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition className.H:142
dynamicFvMesh & mesh
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition error.H:600
const labelIOList & zoneIDs
Definition correctPhi.H:59
#define WarningInFunction
Report a warning using Foam::Warning.
Namespace for OpenFOAM.
HashSet< word, Hash< word > > wordHashSet
A HashSet of words, uses string hasher.
Definition HashSet.H:80
List< label > labelList
A List of labels.
Definition List.H:62
messageStream Info
Information stream (stdout output on master, null elsewhere).
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
errorManip< error > abort(error &err)
Definition errorManip.H:139
vector point
Point is a vector.
Definition point.H:37
static constexpr const zero Zero
Global zero (0).
Definition zero.H:127
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
Vector< scalar > vector
Definition vector.H:57
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50
#define defineRunTimeSelectionTable(baseType, argNames)
Define run-time selection table.
dictionary dict
#define forAll(list, i)
Loop across all elements in list.
Definition stdFoam.H:299