coordinateSystems.H
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-2016 OpenFOAM Foundation
9  Copyright (C) 2018-2022 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 Class
28  Foam::coordinateSystems
29 
30 Description
31  A centralized collection of named coordinate systems.
32 
33 Note
34  Mixing normal constructors and the coordinateSystems::New constructor
35  may yield unexpected results.
36 
37  \verbatim
38  cat1
39  {
40  coordinateSystem
41  {
42  type indirect;
43  name _10;
44  }
45  porosity 0.781;
46  Darcy
47  {
48  d d [0 -2 0 0 0] (-1000 -1000 0.50753e+08);
49  f f [0 -1 0 0 0] (-1000 -1000 12.83);
50  }
51  }
52  \endverbatim
53 
54  For this to work correctly, the coordinateSystem constructor must be
55  supplied with an objectRegistry as well as the dictionary.
56 
57 SourceFiles
58  coordinateSystems.C
59 
60 \*---------------------------------------------------------------------------*/
61 
62 #ifndef Foam_coordinateSystems_H
63 #define Foam_coordinateSystems_H
64 
65 #include "regIOobject.H"
66 #include "PtrList.H"
67 #include "coordinateSystem.H"
68 #include "wordRes.H"
69 
70 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
71 
72 namespace Foam
73 {
74 
75 /*---------------------------------------------------------------------------*\
76  Class coordinateSystems Declaration
77 \*---------------------------------------------------------------------------*/
78 
80 :
81  public regIOobject,
82  public PtrList<coordinateSystem>
83 {
84  // Private Member Functions
85 
86  //- Read "coordinateSystems" or older "IOPtrList<coordinateSystem>"
87  void readFromStream(const bool readOnProc = true);
88 
89  //- Read if IOobject flags set. Return true if read.
90  bool readContents();
91 
92  //- No copy construct
93  coordinateSystems(const coordinateSystems&) = delete;
94 
95  //- No copy assignment
96  void operator=(const coordinateSystems&) = delete;
97 
98 
99 public:
100 
101  //- Declare type-name, virtual type (without debug switch)
102  TypeNameNoDebug("coordinateSystems");
103 
104 
105  // Constructors
106 
107  //- Read construct from IOobject
108  explicit coordinateSystems(const IOobject& io);
109 
110  //- Read construct "coordinateSystems" from "constant"
111  //- using given registry
112  explicit coordinateSystems(const objectRegistry& obr);
113 
114  //- Construct from IOobject and PtrList content
116  (
117  const IOobject& io,
118  const PtrList<coordinateSystem>& content
119  );
120 
121  //- Construct from IOobject and transferring PtrList content
123  (
124  const IOobject& io,
125  PtrList<coordinateSystem>&& content
126  );
127 
128 
129  // Selectors
130 
131  //- Return previously registered or read construct from "constant"
132  static const coordinateSystems& New(const objectRegistry& obr);
133 
134 
135  // Member Functions
136 
137  //- Find and return indices for all matches
138  // A no-op (returns empty list) for an empty key
139  labelList indices(const wordRe& key) const;
140 
141  //- Find and return indices for all matches
142  // A no-op (returns empty list) for an empty matcher
143  labelList indices(const wordRes& matcher) const;
144 
145  //- Find and return index for the first match, return -1 if not found
146  // A no-op (returns -1) for an empty key
147  label findIndex(const wordRe& key) const;
148 
149  //- Find and return index for the first match, return -1 if not found
150  // A no-op (returns -1) for an empty matcher
151  label findIndex(const wordRes& matcher) const;
152 
153  //- Search if given key exists
154  bool found(const wordRe& key) const;
155 
156  //- Return pointer to named coordinateSystem or nullptr on error
157  const coordinateSystem* cfind(const word& name) const;
158 
159  //- Return reference to named coordinateSystem or FatalErrror
160  const coordinateSystem& lookup(const word& name) const;
161 
162  //- A list of the coordinate-system names
163  wordList names() const;
164 
165  //- A list of the coordinate-system names satisfying the input matcher
166  wordList names(const wordRe& key) const;
167 
168  //- A list of the coordinate-system names satisfying the input matcher
169  wordList names(const wordRes& matcher) const;
170 
171  //- Identical to names()
172  inline wordList toc() const
173  {
174  return names();
175  }
176 
177 
178  // IO
179 
180  //- Write data
181  bool writeData(Ostream& os) const;
182 
183  //- Write using stream options
184  virtual bool writeObject
185  (
186  IOstreamOption streamOpt,
187  const bool writeOnProc = true
188  ) const;
189 
190 
191  // Housekeeping
192 
193  //- Identical to the indices() method (AUG-2018)
194  FOAM_DEPRECATED_FOR(2018-08, "indices() method")
195  labelList findIndices(const wordRe& key) const
196  {
197  return this->indices(key);
198  }
199 
200  //- Deprecated(2020-03) find named coordinateSystem or nullptr
201  //
202  // \deprecated(2020-03) - use cfind() method
203  FOAM_DEPRECATED_FOR(2020-03, "cfind() method")
204  const coordinateSystem* lookupPtr(const word& name) const
205  {
206  return this->cfind(name);
207  }
208 };
209 
210 
211 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
212 
213 //- Global file type for coordinateSystems - same content for all ranks
214 template<>
215 struct is_globalIOobject<coordinateSystems> : std::true_type {};
216 
217 
218 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
219 
220 } // End namespace Foam
221 
222 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
223 
224 #endif
225 
226 // ************************************************************************* //
Base class for coordinate system specification, the default coordinate system type is cartesian ...
wordList names() const
A list of the coordinate-system names.
labelList findIndices(const wordRe &key) const
Identical to the indices() method (AUG-2018)
const word & name() const noexcept
Return the object name.
Definition: IOobjectI.H:195
TypeNameNoDebug("coordinateSystems")
Declare type-name, virtual type (without debug switch)
A centralized collection of named coordinate systems.
Trait for specifying global vs. local file types.
Definition: IOobject.H:981
const coordinateSystem * lookupPtr(const word &name) const
Deprecated(2020-03) find named coordinateSystem or nullptr.
FOAM_DEPRECATED_FOR(2022-09, "get(), set() or test() methods") const T *operator()(const label i) const
Deprecated(2022-09) - same as get()
Definition: UPtrList.H:492
A simple container for options an IOstream can normally have.
wordList toc() const
Identical to names()
label findIndex(const wordRe &key) const
Find and return index for the first match, return -1 if not found.
A class for handling words, derived from Foam::string.
Definition: word.H:63
A List of wordRe with additional matching capabilities.
Definition: wordRes.H:53
A wordRe is a Foam::word, but can contain a regular expression for matching words or strings...
Definition: wordRe.H:78
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
OBJstream os(runTime.globalPath()/outputName)
const coordinateSystem & lookup(const word &name) const
Return reference to named coordinateSystem or FatalErrror.
auto key(const Type &t) -> typename std::enable_if< std::is_enum< Type >::value, typename std::underlying_type< Type >::type >::type
Definition: foamGltfBase.H:103
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers...
Definition: List.H:55
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:66
virtual bool writeObject(IOstreamOption streamOpt, const bool writeOnProc=true) const
Write using stream options.
const coordinateSystem * cfind(const word &name) const
Return pointer to named coordinateSystem or nullptr on error.
bool found(const wordRe &key) const
Search if given key exists.
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, IOobject::NO_REGISTER)
Registry of regIOobjects.
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:172
static const coordinateSystems & New(const objectRegistry &obr)
Return previously registered or read construct from "constant".
bool writeData(Ostream &os) const
Write data.
labelList indices(const wordRe &key) const
Find and return indices for all matches.
Namespace for OpenFOAM.