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 -------------------------------------------------------------------------------
10 License
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 
34 namespace Foam
35 {
36  defineTypeNameAndDebug(binModel, 0);
37  defineRunTimeSelectionTable(binModel, dictionary);
38 }
39 
40 
41 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
42 
43 template<>
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  {
107  coordSysPtr_.reset(new coordSystem::cartesian(dict));
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  }
183  setCoordinateSystem(dict);
184 
185  return true;
186 }
187 
188 
190 {}
191 
192 
193 void Foam::binModel::movePoints(const polyMesh& mesh)
194 {}
195 
196 
197 // ************************************************************************* //
List< ReturnType > get(const UPtrList< T > &list, const AccessOp &aop)
List of values generated by applying the access operation to each list item.
const polyBoundaryMesh & pbm
dictionary dict
const labelIOList & zoneIDs
Definition: correctPhi.H:59
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; header text and sta...
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:598
void append(const T &val)
Append an element at the end of the list.
Definition: List.H:517
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:56
labelHashSet patchSet(const UList< wordRe > &select, const bool warnNotFound=true, const bool useGroups=true) const
Return the set of patch IDs corresponding to the given names.
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
bool decomposePatchValues_
Decompose patch values into normal and tangential components.
Definition: binModel.H:73
T get(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a T. FatalIOError if not found, or if the number of tokens is incorrect.
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:157
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
dynamicFvMesh & mesh
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
A class for handling words, derived from Foam::string.
Definition: word.H:63
binModel(const dictionary &dict, const fvMesh &mesh, const word &outputPrefix)
Construct from components.
Definition: binModel.C:108
virtual void updateMesh(const mapPolyMesh &mpm)
Update for changes of mesh.
Definition: binModel.C:182
Vector< scalar > vector
Definition: vector.H:57
HashSet< word, Hash< word > > wordHashSet
A HashSet of words, uses string hasher.
Definition: HashSet.H:73
errorManip< error > abort(error &err)
Definition: errorManip.H:139
A polyBoundaryMesh is a polyPatch list with additional search methods and registered IO...
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
defineRunTimeSelectionTable(reactionRateFlameArea, dictionary)
bool readIfPresent(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX) const
Find an entry if present, and assign to T val. FatalIOError if it is found and the number of tokens i...
defineTypeNameAndDebug(combustionModel, 0)
virtual bool read(const dictionary &dict)
Read.
Definition: writeFile.C:241
#define WarningInFunction
Report a warning using Foam::Warning.
List< Key > sortedToc() const
The table of contents (the keys) in sorted order.
Definition: HashTable.C:139
virtual bool read(const dictionary &dict)
Read the dictionary.
Definition: binModel.C:125
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.
List< label > sortedToc(const UList< bool > &bools)
Return the (sorted) values corresponding to &#39;true&#39; entries.
Definition: BitOps.C:195
messageStream Info
Information stream (stdout output on master, null elsewhere)
label n
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...
List< label > labelList
A List of labels.
Definition: List.H:62
virtual void movePoints(const polyMesh &mesh)
Update for changes of mesh.
Definition: binModel.C:186
Namespace for OpenFOAM.
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:127