cellZone.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) 2011 OpenFOAM Foundation
9  Copyright (C) 2017-2023 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "cellZone.H"
31 #include "cellZoneMesh.H"
32 #include "polyMesh.H"
33 #include "primitiveMesh.H"
34 #include "IOstream.H"
35 
36 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
37 
38 namespace Foam
39 {
40  defineTypeNameAndDebug(cellZone, 0);
41  defineRunTimeSelectionTable(cellZone, dictionary);
42  addToRunTimeSelectionTable(cellZone, cellZone, dictionary);
43 }
44 
45 const char * const Foam::cellZone::labelsName = "cellLabels";
46 
47 
48 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
49 
51 :
52  cellZone(word::null, 0, zm)
53 {}
54 
55 
57 (
58  const word& name,
59  const label index,
60  const cellZoneMesh& zm
61 )
62 :
63  zone(name, index),
64  zoneMesh_(zm)
65 {}
66 
67 
69 (
70  const word& name,
71  const labelUList& addr,
72  const label index,
73  const cellZoneMesh& zm
74 )
75 :
76  zone(name, addr, index),
77  zoneMesh_(zm)
78 {}
79 
80 
82 (
83  const word& name,
84  labelList&& addr,
85  const label index,
86  const cellZoneMesh& zm
87 )
88 :
89  zone(name, std::move(addr), index),
90  zoneMesh_(zm)
91 {}
92 
93 
95 (
96  const word& name,
97  const dictionary& dict,
98  const label index,
99  const cellZoneMesh& zm
100 )
101 :
102  zone(name, dict, this->labelsName, index),
103  zoneMesh_(zm)
104 {}
105 
106 
108 (
109  const cellZone& originalZone,
110  const Foam::zero,
111  const cellZoneMesh& zm,
112  const label newIndex
113 )
114 :
115  zone(originalZone, labelList(), newIndex),
116  zoneMesh_(zm)
117 {}
118 
119 
121 (
122  const cellZone& originalZone,
123  const Foam::zero,
124  const label index,
125  const cellZoneMesh& zm
126 )
127 :
128  zone(originalZone, labelList(), index),
129  zoneMesh_(zm)
130 {}
131 
132 
134 (
135  const cellZone& originalZone,
136  const labelUList& addr,
137  const label index,
138  const cellZoneMesh& zm
139 )
140 :
141  cellZone(originalZone, Foam::zero{}, index, zm)
142 {
143  labelList::operator=(addr);
144 }
145 
146 
148 (
149  const cellZone& originalZone,
150  labelList&& addr,
151  const label index,
152  const cellZoneMesh& zm
153 )
154 :
155  cellZone(originalZone, Foam::zero{}, index, zm)
156 {
157  labelList::transfer(addr);
158 }
159 
160 
161 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
163 Foam::label Foam::cellZone::whichCell(const label globalCellID) const
164 {
165  return zone::localID(globalCellID);
166 }
167 
169 bool Foam::cellZone::checkDefinition(const bool report) const
170 {
171  return zone::checkDefinition(zoneMesh_.mesh().nCells(), report);
172 }
173 
174 
176 {
177  os.beginBlock(name());
178 
179  os.writeEntry("type", type());
181  writeEntry(this->labelsName, os);
182 
183  os.endBlock();
184 }
185 
186 
188 {
189  if (this == &zn)
190  {
191  return; // Self-assignment is a no-op
192  }
194  clearAddressing();
195  labelList::transfer(static_cast<labelList&>(zn));
196  zn.clearAddressing();
197 }
198 
199 
201 {
202  if (this == &zn)
203  {
204  return; // Self-assignment is a no-op
205  }
206 
207  clearAddressing();
208  labelList::operator=(static_cast<const labelList&>(zn));
209 }
210 
211 
213 {
214  clearAddressing();
215  labelList::operator=(addr);
216 }
217 
218 
220 {
221  clearAddressing();
222  labelList::transfer(addr);
223 }
224 
225 
226 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
227 
228 void Foam::cellZone::operator=(const cellZone& zn)
229 {
230  if (this == &zn)
231  {
232  return; // Self-assignment is a no-op
233  }
234 
235  clearAddressing();
236  labelList::operator=(static_cast<const labelList&>(zn));
237 }
238 
239 
241 {
242  clearAddressing();
243  labelList::operator=(addr);
244 }
245 
246 
248 {
249  clearAddressing();
250  labelList::transfer(addr);
251 }
252 
253 
254 // * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * //
255 
256 Foam::Ostream& Foam::operator<<(Ostream& os, const cellZone& zn)
257 {
258  zn.write(os);
260  return os;
261 }
262 
263 
264 // ************************************************************************* //
label whichCell(const label globalCellID) const
Helper function to re-direct to zone::localID(...)
Definition: cellZone.C:156
dictionary dict
label localID(const label globalID) const
Lookup local address in zone for given global index.
Definition: zone.C:140
virtual void resetAddressing(cellZone &&zn)
Move reset addressing from another zone.
Definition: cellZone.C:180
void transfer(List< label > &list)
Transfer the contents of the argument List into this list and annul the argument list.
Definition: List.C:326
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:45
void operator=(const cellZone &zn)
Assign addressing, clearing demand-driven data.
Definition: cellZone.C:221
virtual bool checkDefinition(const bool report=false) const
Check zone definition. Return true if in error.
Definition: cellZone.C:162
Ostream & writeEntry(const keyType &key, const T &value)
Write a keyword/value entry.
Definition: Ostream.H:321
Macros for easy insertion into run-time selection tables.
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: POSIX.C:799
Foam::cellZoneMesh.
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition: exprTraits.C:127
void operator=(const UList< label > &list)
Assignment to UList operator. Takes linear time.
Definition: List.C:360
Base class for mesh zones.
Definition: zone.H:59
A class for handling words, derived from Foam::string.
Definition: word.H:63
virtual Ostream & endBlock()
Write end block group.
Definition: Ostream.C:108
virtual bool checkDefinition(const bool report=false) const =0
Check zone definition. Return true if in error.
virtual bool write(const token &tok)=0
Write token to stream or otherwise handle it.
void write(Ostream &os) const
Write (physicalType, inGroups) dictionary entries (without surrounding braces)
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
defineRunTimeSelectionTable(reactionRateFlameArea, dictionary)
OBJstream os(runTime.globalPath()/outputName)
#define FUNCTION_NAME
defineTypeNameAndDebug(combustionModel, 0)
cellZone(const cellZone &)=delete
No copy construct.
A subset of mesh cells.
Definition: cellZone.H:58
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:77
virtual Ostream & beginBlock(const keyType &kw)
Write begin block group with the given name.
Definition: Ostream.C:90
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition: zero.H:57
static const char *const labelsName
The name associated with the zone-labels dictionary entry ("cellLabels")
Definition: cellZone.H:78
virtual void writeDict(Ostream &os) const
Write dictionary.
Definition: cellZone.C:168
List< label > labelList
A List of labels.
Definition: List.H:62
ZoneMesh< cellZone, polyMesh > cellZoneMesh
A ZoneMesh with the type cellZone.
Namespace for OpenFOAM.
addToRunTimeSelectionTable(functionObject, pointHistory, dictionary)