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-2020 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 coordinateSystems_H
63 #define 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 valid = true);
88 
89  //- Attempt read if MUST_READ.., or READ_IF_PRESENT and has header
90  // \return False if no read should have been attempted
91  bool readObject(const IOobject& io);
92 
93 
94  //- No copy construct
95  coordinateSystems(const coordinateSystems&) = delete;
96 
97  //- No copy assignment
98  void operator=(const coordinateSystems&) = delete;
99 
100 
101 public:
102 
103  //- Declare type-name, virtual type (without debug switch)
104  TypeNameNoDebug("coordinateSystems");
105 
106 
107  // Constructors
108 
109  //- Read construct from IOobject
110  explicit coordinateSystems(const IOobject& io);
111 
112  //- Construct from IOobject and PtrList content
114  (
115  const IOobject& io,
116  const PtrList<coordinateSystem>& content
117  );
118 
119  //- Construct from IOobject and transferring PtrList content
121  (
122  const IOobject& io,
123  PtrList<coordinateSystem>&& content
124  );
125 
126 
127  // Selectors
128 
129  //- Return previously registered or read construct from "constant"
130  static const coordinateSystems& New(const objectRegistry& obr);
131 
132 
133  // Member Functions
134 
135  //- Find and return indices for all matches
136  // A no-op (returns empty list) for an empty key
137  labelList indices(const keyType& key) const;
138 
139  //- Find and return indices for all matches
140  // A no-op (returns empty list) for an empty matcher
141  labelList indices(const wordRes& matcher) const;
142 
143  //- Find and return index for the first match, return -1 if not found
144  // A no-op (returns -1) for an empty key
145  label findIndex(const keyType& key) const;
146 
147  //- Find and return index for the first match, return -1 if not found
148  // A no-op (returns -1) for an empty matcher
149  label findIndex(const wordRes& matcher) const;
150 
151  //- Search if given key exists
152  bool found(const keyType& key) const;
153 
154  //- Return pointer to named coordinateSystem or nullptr on error
155  const coordinateSystem* cfind(const word& name) const;
156 
157  //- Return reference to named coordinateSystem or FatalErrror
158  const coordinateSystem& lookup(const word& name) const;
159 
160  //- A list of the coordinate-system names
161  wordList names() const;
162 
163  //- A list of the coordinate-system names satisfying the input matcher
164  wordList names(const keyType& key) const;
165 
166  //- A list of the coordinate-system names satisfying the input matcher
167  wordList names(const wordRe& matcher) const;
168 
169  //- A list of the coordinate-system names satisfying the input matcher
170  wordList names(const wordRes& matcher) const;
171 
172  //- Identical to names()
173  inline wordList toc() const
174  {
175  return names();
176  }
177 
178 
179  // IO
180 
181  //- Write data
182  bool writeData(Ostream& os) const;
183 
184  //- Write using stream options
185  virtual bool writeObject
186  (
187  IOstreamOption streamOpt,
188  const bool valid = true
189  ) const;
190 
191 
192  // Housekeeping
193 
194  //- Identical to the indices() method (AUG-2018)
195  FOAM_DEPRECATED_FOR(2018-08, "indices() method")
196  labelList findIndices(const keyType& key) const
197  {
198  return this->indices(key);
199  }
200 
201  //- Deprecated(2020-03) find named coordinateSystem or nullptr
202  //
203  // \deprecated(2020-03) - use cfind() method
204  FOAM_DEPRECATED_FOR(2020-03, "cfind() method")
205  const coordinateSystem* lookupPtr(const word& name) const
206  {
207  return this->cfind(name);
208  }
209 };
210 
211 
212 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
213 
214 } // End namespace Foam
215 
216 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
217 
218 #endif
219 
220 // ************************************************************************* //
regIOobject.H
wordRes.H
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:104
Foam::coordinateSystems::findIndex
label findIndex(const keyType &key) const
Find and return index for the first match, return -1 if not found.
Definition: coordinateSystems.C:302
Foam::IOobject::name
const word & name() const
Return name.
Definition: IOobjectI.H:70
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::coordinateSystems::indices
labelList indices(const keyType &key) const
Find and return indices for all matches.
Definition: coordinateSystems.C:271
Foam::wordRe
A wordRe is a Foam::word, but can contain a regular expression for matching words or strings.
Definition: wordRe.H:72
coordinateSystem.H
Foam::coordinateSystems::lookup
const coordinateSystem & lookup(const word &name) const
Return reference to named coordinateSystem or FatalErrror.
Definition: coordinateSystems.C:362
Foam::coordinateSystems::TypeNameNoDebug
TypeNameNoDebug("coordinateSystems")
Declare type-name, virtual type (without debug switch)
Foam::objectRegistry
Registry of regIOobjects.
Definition: objectRegistry.H:60
Foam::keyType
A class for handling keywords in dictionaries.
Definition: keyType.H:60
Foam::IOstreamOption
The IOstreamOption is a simple container for options an IOstream can normally have.
Definition: IOstreamOption.H:63
Foam::PtrList
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
Definition: List.H:62
Foam::coordinateSystems::writeData
bool writeData(Ostream &os) const
Write data.
Definition: coordinateSystems.C:434
Foam::coordinateSystems
A centralized collection of named coordinate systems.
Definition: coordinateSystems.H:78
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::coordinateSystems::writeObject
virtual bool writeObject(IOstreamOption streamOpt, const bool valid=true) const
Write using stream options.
Definition: coordinateSystems.C:453
Foam::coordinateSystems::lookupPtr
const coordinateSystem * lookupPtr(const word &name) const
Deprecated(2020-03) find named coordinateSystem or nullptr.
Definition: coordinateSystems.H:204
Foam::coordinateSystems::findIndices
labelList findIndices(const keyType &key) const
Identical to the indices() method (AUG-2018)
Definition: coordinateSystems.H:195
Foam::regIOobject
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:71
Foam::coordinateSystems::toc
wordList toc() const
Identical to names()
Definition: coordinateSystems.H:172
Foam::List< label >
Foam::coordinateSystems::names
wordList names() const
A list of the coordinate-system names.
Definition: coordinateSystems.C:385
Foam::wordRes
A List of wordRe with additional matching capabilities.
Definition: wordRes.H:51
Foam::FOAM_DEPRECATED_FOR
class FOAM_DEPRECATED_FOR(2017-05, "Foam::Enum") NamedEnum
Definition: NamedEnum.H:69
PtrList.H
Foam::coordinateSystems::cfind
const coordinateSystem * cfind(const word &name) const
Return pointer to named coordinateSystem or nullptr on error.
Definition: coordinateSystems.C:341
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::coordinateSystems::New
static const coordinateSystems & New(const objectRegistry &obr)
Return previously registered or read construct from "constant".
Definition: coordinateSystems.C:238
Foam::coordinateSystems::found
bool found(const keyType &key) const
Search if given key exists.
Definition: coordinateSystems.C:334
Foam::coordinateSystem
Base class for coordinate system specification, the default coordinate system type is cartesian .
Definition: coordinateSystem.H:122